From 60a085fb1ca08f534ba02143606d8393ade58b25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Fri, 16 Jun 2000 15:13:25 +0000 Subject: [PATCH] Changes to make text-inset work better (f.ex. cursor), and now we have multi paragraph text insets!!! git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@818 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 16 ++ po/POTFILES.in | 1 - src/BufferView_pimpl.C | 6 +- src/insets/insetcollapsable.C | 14 +- src/insets/insetcollapsable.h | 2 - src/insets/insettabular.C | 100 +++---- src/insets/insettabular.h | 6 +- src/insets/insettext.C | 490 +++++++++++++--------------------- src/insets/insettext.h | 11 +- src/insets/lyxinset.h | 2 + src/lyxfr1.C | 2 +- src/lyxfunc.C | 11 +- src/lyxtext.h | 3 +- src/text.C | 62 ++--- src/text2.C | 71 +++-- 15 files changed, 358 insertions(+), 439 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3438c8f82d..17d994b1b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2000-06-16 Juergen Vigna + + * src/insets/insettabular.C (UpdateLocal): + * src/insets/insettext.C (UpdateLocal): fixed mark_dirty problem. + (LocalDispatch): Changed all functions to use LyXText. + +2000-06-15 Juergen Vigna + + * src/text.C (SetHeightOfRow): call inset::update before requesting + any width/height. + + * src/insets/insettext.C (update): + * src/insets/insettabular.C (update): added implementation + + * src/insets/lyxinset.h: added update function + 2000-06-15 Jean-Marc Lasgouttes * src/text.C (SelectNextWord): protect against null pointers with diff --git a/po/POTFILES.in b/po/POTFILES.in index fc50126cfd..b80c5a8da6 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -17,7 +17,6 @@ src/BufferView_pimpl.C src/bullet_forms.C src/bullet_forms_cb.C src/Chktex.C -src/cite.C src/ColorHandler.C src/combox.C src/credits.C diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 731f4dd394..8613ee40b5 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -258,7 +258,7 @@ int BufferView::Pimpl::resizeCurrentBuffer() bv_->text->SetCursor(bv_, selstartpar, selstartpos); bv_->text->sel_cursor = bv_->text->cursor; bv_->text->SetCursor(bv_, selendpar, selendpos); - bv_->text->SetSelection(bv_); + bv_->text->SetSelection(); bv_->text->SetCursor(bv_, par, pos); } else { bv_->text->SetCursor(bv_, par, pos); @@ -507,7 +507,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state) if (!bv_->text->selection) update(BufferView::UPDATE); // Maybe an empty line was deleted - bv_->text->SetSelection(bv_); + bv_->text->SetSelection(); screen->ToggleToggle(); fitCursor(); screen->ShowCursor(); @@ -686,7 +686,7 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button) bv_->text->CursorHome(bv_); bv_->text->sel_cursor = bv_->text->cursor; bv_->text->CursorEnd(bv_); - bv_->text->SetSelection(bv_); + bv_->text->SetSelection(); screen->ToggleSelection(false); /* This will fit the cursor on the screen * if necessary */ diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 5648e3c1ec..68f12ab101 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -166,7 +166,7 @@ void InsetCollapsable::Edit(BufferView * bv, int x, int y, unsigned int button) { if (collapsed && autocollapse) { collapsed = false; - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); InsetText::Edit(bv, 0, 0, button); } else if (!collapsed) { InsetText::Edit(bv, x, y, button); @@ -188,13 +188,7 @@ void InsetCollapsable::InsetUnlock(BufferView * bv) collapsed = true; } InsetText::InsetUnlock(bv); - UpdateLocal(bv, false); -} - - -void InsetCollapsable::UpdateLocal(BufferView * bv, bool flag) -{ - InsetText::UpdateLocal(bv, flag); + UpdateLocal(bv, false, false); } @@ -214,10 +208,10 @@ void InsetCollapsable::InsetButtonRelease(BufferView * bv, if (collapsed) { collapsed = false; InsetText::InsetButtonRelease(bv, 0, 0, button); - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); } else { collapsed = true; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); bv->unlockInset(this); } } else if (!collapsed && (x >= button_length) && (y >= button_top_y)) { diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 604867de7d..bf21fb5506 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -85,8 +85,6 @@ protected: /// void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const; /// - void UpdateLocal(BufferView *, bool); - /// int getMaxTextWidth(Painter & pain, UpdatableInset const *) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 5a139487a1..8a0cac3fea 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -171,12 +171,12 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, UpdatableInset::draw(pain,font,baseline,x); if (init_inset || (top_x != int(x)) || (top_baseline != baseline)) { - int ox = top_x; +// int ox = top_x; init_inset = false; top_x = int(x); top_baseline = baseline; - if (ox != top_x) - recomputeTextInsets(pain, font); +// if (ox != top_x) +// recomputeTextInsets(pain, font); calculate_width_of_cells(pain, font); resetPos(pain); reinit = true; @@ -202,6 +202,13 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, } +void InsetTabular::update(BufferView * bv, LyXFont const & font) const +{ + if (init_inset) + recomputeTextInsets(bv, font); +} + + void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline, int row, int cell) const { @@ -292,7 +299,7 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button) if (InsetHit(bv, x, y)) { ActivateCellInset(bv, x, y, button); } - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); // bv->getOwner()->getPopups().updateFormTabular(); } @@ -308,19 +315,19 @@ void InsetTabular::InsetUnlock(BufferView * bv) if (hasSelection()) { sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); } no_selection = false; oldcell = -1; locked = false; } -void InsetTabular::UpdateLocal(BufferView * bv, bool flag) +void InsetTabular::UpdateLocal(BufferView * bv, bool what, bool mark_dirty) { - if (flag) + if (what) calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE)); - bv->updateInset(this, flag); - if (flag) + bv->updateInset(this, mark_dirty); + if (what) resetPos(bv->painter()); } @@ -385,7 +392,7 @@ bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset) return false; if (the_locking_inset != inset) return the_locking_inset->UpdateInsetInInset(bv, inset); - UpdateLocal(bv); + UpdateLocal(bv, true, false); return true; } @@ -449,7 +456,7 @@ void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button) { if (hasSelection()) { sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); } no_selection = false; @@ -497,7 +504,7 @@ void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button) sel_pos_end = cursor.pos(); sel_cell_end = actcell; if (old != sel_pos_end) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); #if 0 if (ocell != actcell) bview->getOwner()->getPopups().updateFormTabular(); @@ -544,7 +551,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, else if (result == DISPATCHED) { bool upd = SetCellDimensions(bv->painter(), actcell, actrow); the_locking_inset->ToggleInsetCursor(bv); - UpdateLocal(bv, upd); + UpdateLocal(bv, upd, false); the_locking_inset->ToggleInsetCursor(bv); return result; } else if (result == FINISHED) { @@ -579,14 +586,14 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, else sel_cell_end = actcell; } - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_RIGHT: result = moveRight(bv); sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; if (hs) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_LEFTSEL: if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos())) @@ -600,14 +607,14 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, else sel_cell_end = actcell-1; } - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_LEFT: result = moveLeft(bv); sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; if (hs) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_DOWNSEL: { @@ -619,7 +626,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_cell_end = tabular->GetCellBelow(sel_cell_end); else sel_cell_end = tabular->GetLastCellBelow(sel_cell_end); - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); } break; case LFUN_DOWN: @@ -627,7 +634,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; if (hs) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_UPSEL: { @@ -639,7 +646,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_cell_end = tabular->GetCellAbove(sel_cell_end); else sel_cell_end = tabular->GetLastCellAbove(sel_cell_end); - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); } break; case LFUN_UP: @@ -647,7 +654,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; if (hs) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_BACKSPACE: break; @@ -670,7 +677,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_pos_start = sel_pos_end = cursor.pos(); sel_cell_start = sel_cell_end = actcell; if (hs) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_LAYOUT_TABLE: { @@ -1059,7 +1066,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) bool update = (tabular->GetPWidth(actcell) != val); tabular->SetPWidth(actcell,val); if (update) - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); } break; case LyXTabular::SET_SPECIAL_COLUMN: @@ -1070,34 +1077,34 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) // append the row into the tabular UnlockInsetInInset(bv, the_locking_inset); tabular->AppendRow(actcell); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::APPEND_COLUMN: // append the column into the tabular tabular->AppendColumn(actcell); actcell = tabular->GetCellNumber(row, column); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::DELETE_ROW: tabular->DeleteRow(tabular->row_of_cell(actcell)); if ((row+1) > tabular->rows()) --row; actcell = tabular->GetCellNumber(row, column); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::DELETE_COLUMN: tabular->DeleteColumn(tabular->column_of_cell(actcell)); if ((column+1) > tabular->columns()) --column; actcell = tabular->GetCellNumber(row, column); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::TOGGLE_LINE_TOP: lineSet = !tabular->TopLine(actcell); for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::TOGGLE_LINE_BOTTOM: @@ -1105,7 +1112,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::TOGGLE_LINE_LEFT: @@ -1113,7 +1120,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::TOGGLE_LINE_RIGHT: @@ -1121,7 +1128,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::ALIGN_LEFT: case LyXTabular::ALIGN_RIGHT: @@ -1129,7 +1136,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetAlignment(tabular->GetCellNumber(i,j),setAlign); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::MULTICOLUMN: { @@ -1144,10 +1151,10 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) // check wether we are completly in a multicol if (tabular->IsMultiColumn(actcell)) { tabular->UnsetMultiColumn(actcell); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); } else { tabular->SetMultiColumn(actcell, 1); - UpdateLocal(bv, false); + UpdateLocal(bv, false, true); } return; } @@ -1168,7 +1175,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) cursor.pos(0); sel_cell_end = sel_cell_start; sel_pos_end = sel_pos_start; - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; } case LyXTabular::SET_ALL_LINES: @@ -1177,15 +1184,15 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) for(i=sel_row_start; i<=sel_row_end; ++i) for(j=sel_col_start; j<=sel_col_end; ++j) tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); break; case LyXTabular::SET_LONGTABULAR: tabular->SetLongTabular(true); - UpdateLocal(bv, true); // because this toggles displayed + UpdateLocal(bv, true, true); // because this toggles displayed break; case LyXTabular::UNSET_LONGTABULAR: tabular->SetLongTabular(false); - UpdateLocal(bv, true); // because this toggles displayed + UpdateLocal(bv, true, true); // because this toggles displayed break; case LyXTabular::SET_ROTATE_TABULAR: tabular->SetRotateTabular(true); @@ -1249,7 +1256,7 @@ bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button, inset->Edit(bv, x - inset_x, y - inset_y, button); if (!the_locking_inset) return false; - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); return true; } @@ -1300,22 +1307,23 @@ int InsetTabular::getMaxWidth(Painter & pain, return w; } -void InsetTabular::recomputeTextInsets(Painter & pain, const LyXFont & font) const +void InsetTabular::recomputeTextInsets(BufferView * bv, const LyXFont & font) const { InsetText * inset; - int cx, cell; + int cell; - cx = top_x; +// cx = top_x; for(int j= 0; j < tabular->columns(); ++j) { for(int i = 0; i < tabular->rows(); ++i) { if (tabular->IsPartOfMultiColumn(i,j)) continue; cell = tabular->GetCellNumber(i,j); inset = tabular->GetCellInset(cell); - inset->computeTextRows(pain); - tabular->SetWidthOfCell(cell, inset->width(pain, font)); + inset->update(bv, font); + inset->computeTextRows(bv->painter()); + tabular->SetWidthOfCell(cell, inset->width(bv->painter(), font)); } - cell = tabular->GetCellNumber(0, j); - cx += tabular->GetWidthOfColumn(cell); +// cell = tabular->GetCellNumber(0, j); +// cx += tabular->GetWidthOfColumn(cell); } } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 4175f2376f..7c5b1340da 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -82,13 +82,15 @@ public: /// void draw(Painter & pain, const LyXFont &, int , float &) const; /// + void update(BufferView *, LyXFont const &) const; + /// const char * EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int); /// void InsetUnlock(BufferView *); /// - void UpdateLocal(BufferView *, bool flag = true); + void UpdateLocal(BufferView *, bool what, bool mark_dirty); /// bool LockInsetInInset(BufferView *, UpdatableInset *); /// @@ -187,7 +189,7 @@ private: /// int GetMaxWidthOfCell(Painter &, int cell) const; /// - void recomputeTextInsets(Painter &, const LyXFont &) const; + void recomputeTextInsets(BufferView *, const LyXFont &) const; /// /// Private structures and variables diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e5eaf8902c..bf90dc2a14 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -43,6 +43,9 @@ #include "support/textutils.h" #include "support/LAssert.h" #include "lyxrow.h" +#include "lyxrc.h" +#include "intl.h" +#include "trans_mgr.h" using std::ostream; using std::ifstream; @@ -103,6 +106,7 @@ void InsetText::init(InsetText const * ins) selection_start_cursor = selection_end_cursor = cursor; frame_color = LColor::insetframe; locked = false; + old_par = 0; } @@ -162,6 +166,9 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex) return; } } + if (!return_par) + return_par = par; + par = return_par; if (token != "\\end_inset") { lex.printError("Missing \\end_inset at this point. " "Read: `$$Token'"); @@ -170,26 +177,16 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex) } -int InsetText::ascent(Painter & pain, LyXFont const & font) const +int InsetText::ascent(Painter &, LyXFont const &) const { - if (init_inset) { - text->init(current_view); - computeTextRows(pain); - init_inset = false; - } long int y_temp = 0; Row * row = text->GetRowNearY(y_temp); return row->ascent_of_text() + 2; } -int InsetText::descent(Painter & pain, LyXFont const & font) const +int InsetText::descent(Painter &, LyXFont const &) const { - if (init_inset) { - text->init(current_view); - computeTextRows(pain); - init_inset = false; - } long int y = 0; Row * row = text->GetRowNearY(y); return text->height - row->ascent_of_text() + 2; @@ -198,14 +195,8 @@ int InsetText::descent(Painter & pain, LyXFont const & font) const int InsetText::width(Painter & pain, LyXFont const &) const { - if (init_inset) { - text->init(current_view); - computeTextRows(pain); - init_inset = false; - } return std::max(static_cast(getMaxTextWidth(pain, this)), text->width); -// return insetWidth; } @@ -214,12 +205,14 @@ void InsetText::draw(Painter & pain, LyXFont const & f, { xpos = x; UpdatableInset::draw(pain, f, baseline, x); - + +#if 0 if (init_inset) { text->init(current_view); - computeTextRows(pain); - init_inset = false; - } + computeTextRows(pain); + init_inset = false; + } +#endif if ((baseline != top_baseline) || (top_x != int(x))) { top_baseline = baseline; top_x = int(x); @@ -227,8 +220,8 @@ void InsetText::draw(Painter & pain, LyXFont const & f, } if (the_locking_inset && (text->cursor.pos() == inset_pos)) { resetPos(pain); - inset_x = text->cursor.x() - top_x + drawTextXOffset; - inset_y = text->cursor.y() + drawTextYOffset; + inset_x = cx() - top_x + drawTextXOffset; + inset_y = cy() + drawTextYOffset; } if (drawLockedFrame && locked) { pain.rectangle(int(x), baseline - ascent(pain, f), width(pain, f), @@ -236,24 +229,9 @@ void InsetText::draw(Painter & pain, LyXFont const & f, } x += TEXT_TO_INSET_OFFSET; // place for border #if 1 - // Dump all rowinformation: - long y_dummy = 0; - Row * tmprow = text->GetRowNearY(y_dummy); - lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n"; - while (tmprow) { - lyxerr << tmprow->baseline() << '\t' - << tmprow->par() << '\t' - << tmprow->pos() << '\t' - << tmprow->height() << '\t' - << tmprow->ascent_of_text() << '\t' - << tmprow->fill() << '\n'; - tmprow = tmprow->next(); - } - lyxerr.flush(); long int y = 0; Row * row = text->GetRowNearY(y); y += baseline - row->ascent_of_text() + 1; - text->width = 0; while (row != 0) { text->GetVisibleRow(current_view, y, x, row, y); y += row->height(); @@ -270,6 +248,32 @@ void InsetText::draw(Painter & pain, LyXFont const & f, } +void InsetText::update(BufferView * bv, LyXFont const &) const +{ + if (init_inset) { + text->init(bv); + init_inset = false; +#if 0 + // Dump all rowinformation: + long y_dummy = 0; + Row * tmprow = text->GetRowNearY(y_dummy); + lyxerr << "Width = " << text->width << endl; + lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n"; + while (tmprow) { + lyxerr << tmprow->baseline() << '\t' + << tmprow->par() << '\t' + << tmprow->pos() << '\t' + << tmprow->height() << '\t' + << tmprow->ascent_of_text() << '\t' + << tmprow->fill() << '\n'; + tmprow = tmprow->next(); + } + lyxerr.flush(); +#endif + } +} + + void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos, int row, int baseline, float x) const { @@ -392,9 +396,9 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) setPos(bv->painter(), x, y); checkAndActivateInset(bv, x, y, button); selection_start_cursor = selection_end_cursor = cursor; - current_font = real_current_font =GetFont(bv->buffer(), par, cursor.pos()); + text->sel_cursor = text->cursor; bv->text->FinishUndo(); - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); } @@ -410,7 +414,7 @@ void InsetText::InsetUnlock(BufferView * bv) selection_start_cursor = selection_end_cursor = cursor; no_selection = false; locked = false; - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); } @@ -423,16 +427,16 @@ bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset) lyxerr[Debug::INSETS] << "OK" << endl; the_locking_inset = inset; resetPos(bv->painter()); - inset_x = text->cursor.x() - top_x + drawTextXOffset; - inset_y = text->cursor.y() + drawTextYOffset; + inset_x = cx() - top_x + drawTextXOffset; + inset_y = cy() + drawTextYOffset; inset_pos = text->cursor.pos(); return true; } else if (the_locking_inset && (the_locking_inset == inset)) { if (text->cursor.pos() == inset_pos) { lyxerr[Debug::INSETS] << "OK" << endl; resetPos(bv->painter()); - inset_x = text->cursor.x() - top_x + drawTextXOffset; - inset_y = text->cursor.y() + drawTextYOffset; + inset_x = cx() - top_x + drawTextXOffset; + inset_y = cy() + drawTextYOffset; } else { lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl; } @@ -469,10 +473,10 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) return the_locking_inset->UpdateInsetInInset(bv, inset); lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset << ")" << endl; - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); if (text->cursor.pos() == inset_pos) { - inset_x = text->cursor.x() - top_x + drawTextXOffset; - inset_y = text->cursor.y() + drawTextYOffset; + inset_x = cx() - top_x + drawTextXOffset; + inset_y = cy() + drawTextYOffset; } return true; } @@ -482,7 +486,7 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) { if (hasSelection()) { selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); } no_selection = false; setPos(bv->painter(), x, y); @@ -501,7 +505,7 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) inset_y = cursor.y() + drawTextYOffset; inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button); inset->Edit(bv, x - inset_x, y - inset_y, button); - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); return; } // otherwise only unlock the_locking_inset @@ -518,7 +522,7 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) inset_y = cursor.y() + drawTextYOffset; inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button); inset->Edit(bv, x - inset_x, y - inset_y, 0); - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); } } selection_start_cursor = selection_end_cursor = cursor; @@ -561,7 +565,7 @@ void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state) setPos(bv->painter(), x, y); selection_end_cursor = cursor; if (old != selection_end_cursor) - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); ShowInsetCursor(bv); } no_selection = false; @@ -602,7 +606,7 @@ InsetText::LocalDispatch(BufferView * bv, return result; else if (result == DISPATCHED) { the_locking_inset->ToggleInsetCursor(bv); - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); the_locking_inset->ToggleInsetCursor(bv); return result; } else if (result == FINISHED) { @@ -624,200 +628,140 @@ InsetText::LocalDispatch(BufferView * bv, switch (action) { // Normal chars case -1: - bv->text->SetUndo(bv->buffer(), Undo::INSERT, - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - cutSelection(bv->buffer()); - cursor = selection_start_cursor; - par->InsertChar(cursor.pos(), arg[0]); - SetCharFont(bv->buffer(), cursor.pos(), current_font); - cursor.pos(cursor.pos() + 1); - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, true); + if (bv->buffer()->isReadonly()) { + LyXBell(); +// setErrorMessage(N_("Document is read only")); + break; + } + if (!arg.empty()) { + /* Automatically delete the currently selected + * text and replace it with what is being + * typed in now. Depends on lyxrc settings + * "auto_region_delete", which defaults to + * true (on). */ + + bv->text->SetUndo(bv->buffer(), Undo::INSERT, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); + if (lyxrc.auto_region_delete) { + if (text->selection){ + text->CutSelection(bv, false); + } + } + text->ClearSelection(); + for (string::size_type i = 0; i < arg.length(); ++i) { + bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], text); + } + } + UpdateLocal(bv, true, true); break; // --- Cursor Movements --------------------------------------------- case LFUN_RIGHTSEL: bv->text->FinishUndo(); moveRight(bv, false); - selection_end_cursor = cursor; - UpdateLocal(bv, false); + text->SetSelection(); + UpdateLocal(bv, false, false); break; case LFUN_RIGHT: bv->text->FinishUndo(); result = moveRight(bv); - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); break; case LFUN_LEFTSEL: bv->text->FinishUndo(); moveLeft(bv, false); - selection_end_cursor = cursor; - UpdateLocal(bv, false); + text->SetSelection(); + UpdateLocal(bv, false, false); break; case LFUN_LEFT: bv->text->FinishUndo(); result= moveLeft(bv); - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); break; case LFUN_DOWNSEL: bv->text->FinishUndo(); moveDown(bv); selection_end_cursor = cursor; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_DOWN: bv->text->FinishUndo(); result = moveDown(bv); - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); break; case LFUN_UPSEL: bv->text->FinishUndo(); moveUp(bv); selection_end_cursor = cursor; - UpdateLocal(bv, false); + UpdateLocal(bv, false, false); break; case LFUN_UP: bv->text->FinishUndo(); result = moveUp(bv); - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); + break; + case LFUN_HOME: + bv->text->FinishUndo(); + text->CursorHome(bv); + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); + break; + case LFUN_END: + text->CursorEnd(bv); + text->sel_cursor = text->cursor; + UpdateLocal(bv, false, false); break; case LFUN_BACKSPACE: - if (!cursor.pos()) { - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } - break; - } - moveLeft(bv); + bv->text->SetUndo(bv->buffer(), Undo::DELETE, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); + text->Backspace(bv); + UpdateLocal(bv, true, true); + break; case LFUN_DELETE: - { - bv->text->SetUndo(bv->buffer(), Undo::DELETE, - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - bool ret = true; - if (hasSelection()) { - LyXParagraph::size_type i = selection_start_cursor.pos(); - for (; i < selection_end_cursor.pos(); ++i) { - par->Erase(selection_start_cursor.pos()); - } - } else - ret = Delete(); - if (ret) { // we need update - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, true); - } else if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } - } - resetPos(bv->painter()); - break; + bv->text->SetUndo(bv->buffer(), Undo::DELETE, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); + text->Delete(bv); + UpdateLocal(bv, true, true); + break; case LFUN_CUT: bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - - if (cutSelection(bv->buffer())) { - // we need update - cursor = selection_end_cursor = selection_start_cursor; - UpdateLocal(bv, true); - } else if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } - resetPos(bv->painter()); + text->CutSelection(bv); + UpdateLocal(bv, true, true); break; case LFUN_COPY: bv->text->FinishUndo(); - if (copySelection(bv->buffer())) { - // we need update - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, true); - } else if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } + text->CopySelection(bv); + UpdateLocal(bv, true, false); break; case LFUN_PASTE: - { bv->text->SetUndo(bv->buffer(), Undo::INSERT, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - if (pasteSelection(bv->buffer())) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, true); - } - } - resetPos(bv->painter()); - break; - case LFUN_HOME: - bv->text->FinishUndo(); - for(; cursor.pos() > rows[actrow].pos;) { - cursor.x(cursor.x() - SingleWidth(bv->painter(), par, cursor.pos())); - cursor.pos(cursor.pos() - 1); - } - - cursor.x(cursor.x() - SingleWidth(bv->painter(), par, cursor.pos())); - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } - resetPos(bv->painter()); + text->PasteSelection(bv); + UpdateLocal(bv, true, true); break; - case LFUN_END: - { - bv->text->FinishUndo(); - int checkpos = (int)rows[actrow + 1].pos; - if ((actrow + 2) < (int)rows.size()) - --checkpos; - for(; cursor.pos() < checkpos;) { - cursor.x(cursor.x() + SingleWidth(bv->painter(), par, cursor.pos())); - cursor.pos(cursor.pos() + 1); - } - if (hasSelection()) { - selection_start_cursor = selection_end_cursor = cursor; - UpdateLocal(bv, false); - } else { - selection_start_cursor = selection_end_cursor = cursor; - } - } - resetPos(bv->painter()); - break; case LFUN_BREAKPARAGRAPH: + if (!autoBreakRows) + return DISPATCHED; + text->BreakParagraph(bv, 0); + UpdateLocal(bv, true, true); + break; case LFUN_BREAKLINE: if (!autoBreakRows) return DISPATCHED; bv->text->SetUndo(bv->buffer(), Undo::INSERT, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - par->InsertChar(cursor.pos(),LyXParagraph::META_NEWLINE); - SetCharFont(bv->buffer(), cursor.pos(),current_font); - UpdateLocal(bv, true); - cursor.pos(cursor.pos() + 1); - selection_start_cursor = selection_end_cursor = cursor; - resetPos(bv->painter()); + text->InsertChar(bv, LyXParagraph::META_NEWLINE); + UpdateLocal(bv, true, true); break; case LFUN_LAYOUT: { @@ -850,7 +794,7 @@ InsetText::LocalDispatch(BufferView * bv, cur_layout = layout.second; text->SetLayout(bv, layout.second); bv->owner()->getToolbar()->combox->select(cursor.par()->GetLayout()+1); - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); } } break; @@ -1002,7 +946,7 @@ LyXFont InsetText::GetFont(Buffer const * buf, LyXParagraph * p, int pos) const // the font for drawing may be different from the real font LyXFont InsetText::GetDrawFont(Buffer const * buf, LyXParagraph * p, int pos) const { - return GetFont(buf, p, pos); + return text->GetFont(buf, p, pos); } @@ -1039,17 +983,15 @@ void InsetText::ToggleInsetCursor(BufferView * bv) return; } - LyXFont font = GetDrawFont(bv->buffer(), par, text->cursor.pos()); + LyXFont font = GetDrawFont(bv->buffer(), cpar(), cpos()); int asc = lyxfont::maxAscent(font); int desc = lyxfont::maxDescent(font); - asc = text->cursor.row()->ascent_of_text(); - desc = text->cursor.row()->height() - asc; if (cursor_visible) bv->hideLockedInsetCursor(); else - bv->showLockedInsetCursor(text->cursor.x(), text->cursor.y(), + bv->showLockedInsetCursor(cx(), cy(), asc, desc); cursor_visible = !cursor_visible; } @@ -1062,14 +1004,13 @@ void InsetText::ShowInsetCursor(BufferView * bv) return; } if (!cursor_visible) { - LyXFont font = GetDrawFont(bv->buffer(), par, cursor.pos()); + LyXFont font = GetDrawFont(bv->buffer(), cpar(), cpos()); int asc = lyxfont::maxAscent(font); int desc = lyxfont::maxDescent(font); - asc = text->cursor.row()->ascent_of_text(); - desc = text->cursor.row()->height() - asc; - bv->fitLockedInsetCursor(text->cursor.x(), text->cursor.y(), asc, desc); - bv->showLockedInsetCursor(text->cursor.x(), text->cursor.y(), asc, desc); + + bv->fitLockedInsetCursor(cx(), cy(), asc, desc); + bv->showLockedInsetCursor(cx(), cy(), asc, desc); cursor_visible = true; } } @@ -1153,14 +1094,13 @@ void InsetText::resetPos(Painter & pain) const UpdatableInset::RESULT InsetText::moveRight(BufferView * bv, bool activate_inset) { - if (cursor.pos() >= par->Last()) + if (!cpar()->next && (cpos() >= cpar()->Last())) return FINISHED; if (activate_inset && checkAndActivateInset(bv)) { return DISPATCHED; } - cursor.pos(cursor.pos() + 1); - resetPos(bv->painter()); - real_current_font = current_font =GetFont(bv->buffer(), par, cursor.pos()); + text->CursorRight(bv); +// real_current_font = current_font = GetFont(bv->buffer(), cpar(), cpos()); return DISPATCHED_NOUPDATE; } @@ -1168,10 +1108,9 @@ InsetText::moveRight(BufferView * bv, bool activate_inset) UpdatableInset::RESULT InsetText::moveLeft(BufferView * bv, bool activate_inset) { - if (cursor.pos() <= 0) + if (!cpar()->previous && (cpos() <= 0)) return FINISHED; - cursor.pos(cursor.pos() - 1); - resetPos(bv->painter()); + text->CursorLeft(bv); if (activate_inset) if (checkAndActivateInset(bv, -1, -1)) return DISPATCHED; @@ -1182,13 +1121,9 @@ InsetText::moveLeft(BufferView * bv, bool activate_inset) UpdatableInset::RESULT InsetText::moveUp(BufferView * bv) { - if (!actrow) + if (!crow()->previous()) return FINISHED; - cursor.y(rows[actrow - 1].baseline - top_baseline); - if (cursor.x_fix() < 0) - cursor.x_fix(cursor.x()); - setPos(bv->painter(), - cursor.x_fix() - top_x + drawTextXOffset, cursor.y()); + text->CursorUp(bv); return DISPATCHED_NOUPDATE; } @@ -1196,13 +1131,9 @@ InsetText::moveUp(BufferView * bv) UpdatableInset::RESULT InsetText::moveDown(BufferView * bv) { - if (actrow >= int(rows.size() - 2)) + if (!crow()->next()) return FINISHED; - cursor.y(rows[actrow + 1].baseline - top_baseline); - if (cursor.x_fix() < 0) - cursor.x_fix(cursor.x()); - setPos(bv->painter(), - cursor.x_fix() - top_x + drawTextXOffset, cursor.y()); + text->CursorDown(bv); return DISPATCHED_NOUPDATE; } @@ -1239,7 +1170,7 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset) } else { selection_start_cursor = selection_end_cursor = cursor; } - UpdateLocal(bv, true); + UpdateLocal(bv, true, true); static_cast(inset)->Edit(bv, 0, 0, 0); return true; } @@ -1263,74 +1194,7 @@ UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c) void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall) { - // if there is no selection just set the current_font - if (!hasSelection()) { - // Determine basis font - LyXFont layoutfont; - if (cursor.pos() < BeginningOfMainBody(bv->buffer(), par)) - layoutfont = GetFont(bv->buffer(), par, -2); - else - layoutfont = GetFont(bv->buffer(), par, -1); - - // Update current font - real_current_font.update(font, bv->buffer()->params.language_info, - toggleall); - - // Reduce to implicit settings - current_font = real_current_font; - current_font.reduce(layoutfont); - // And resolve it completely - real_current_font.realize(layoutfont); - return; - } - - int s_start, s_end; - if (selection_start_cursor.pos() > selection_end_cursor.pos()) { - s_start = selection_end_cursor.pos(); - s_end = selection_start_cursor.pos(); - } else { - s_start = selection_start_cursor.pos(); - s_end = selection_end_cursor.pos(); - } - LyXFont newfont; - while(s_start < s_end) { - newfont = GetFont(bv->buffer(), par,s_start); - newfont.update(font, bv->buffer()->params.language_info, toggleall); - SetCharFont(bv->buffer(), s_start, newfont); - ++s_start; - } - UpdateLocal(bv, true); -} - - -void InsetText::SetCharFont(Buffer const * buf, int pos, LyXFont const & f) // -{ - /* let the insets convert their font */ - LyXFont font(f); - - if (par->GetChar(pos) == LyXParagraph::META_INSET) { - if (par->GetInset(pos)) - font = par->GetInset(pos)->ConvertFont(font); - } - LyXLayout const & layout = - textclasslist.Style(buf->params.textclass,par->GetLayout()); - - // Get concrete layout font to reduce against - LyXFont layoutfont; - - if (pos < BeginningOfMainBody(buf, par)) - layoutfont = layout.labelfont; - else - layoutfont = layout.font; - - - layoutfont.realize((textclasslist.TextClass(buf->params.textclass). - defaultfont())); - - // Now, reduce font against full layout font - font.reduce(layoutfont); - - par->SetFont(pos, font); + text->SetFont(bv, font, toggleall); } @@ -1503,17 +1367,18 @@ void InsetText::computeBaselines(int baseline) const } -void InsetText::UpdateLocal(BufferView * bv, bool flag) +void InsetText::UpdateLocal(BufferView * bv, bool what, bool mark_dirty) { - if (flag) { + if (what) { text->FullRebreak(bv); - computeTextRows(bv->painter()); - computeBaselines(top_baseline); } - bv->updateInset(this, flag); - if (flag) - resetPos(bv->painter()); - bv->owner()->getToolbar()->combox->select(cursor.par()->GetLayout()+1); + bv->updateInset(this, mark_dirty); +// if (flag) +// resetPos(bv->painter()); + if (old_par != cpar()) { + bv->owner()->getToolbar()->combox->select(cpar()->GetLayout()+1); + old_par = cpar(); + } } @@ -1583,7 +1448,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, if (par->GetChar(cursor.pos()) == LyXParagraph::META_INSET) { UpdatableInset * inset = static_cast(par->GetInset(cursor.pos())); - LyXFont font = GetFont(bv->buffer(), par, cursor.pos()); + LyXFont font = text->GetFont(bv->buffer(), cpar(), cpos()); if (x < 0) x = inset->width(bv->painter(), font); if (y < 0) @@ -1593,7 +1458,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, inset->Edit(bv, x - inset_x, y - inset_y, button); if (!the_locking_inset) return false; - UpdateLocal(bv, true); + UpdateLocal(bv, true, false); return true; } return false; @@ -1639,3 +1504,30 @@ void InsetText::SetFrameColor(LColor::color col) init_inset = true; } } + +int InsetText::cx() const +{ + return text->cursor.x() + top_x + 1; +} + +int InsetText::cy() const +{ + long int y_dummy = 0; + Row * tmprow = text->GetRowNearY(y_dummy); + return text->cursor.y() - tmprow->baseline(); +} + +int InsetText::cpos() const +{ + return text->cursor.pos(); +} + +LyXParagraph * InsetText::cpar() const +{ + return text->cursor.par(); +} + +Row * InsetText::crow() const +{ + return text->cursor.row(); +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index e76ea919f0..36a32ebd46 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -64,6 +64,8 @@ public: /// void draw(Painter & pain, LyXFont const &, int , float &) const; /// + void update(BufferView *, LyXFont const &) const; + /// char const * EditMessage() const; /// void Edit(BufferView *, int, int, unsigned int); @@ -129,7 +131,7 @@ public: protected: /// - void UpdateLocal(BufferView *, bool); + void UpdateLocal(BufferView *, bool what, bool mark_dirty); /// void WriteParagraphData(Buffer const *, std::ostream &) const; /// @@ -211,6 +213,11 @@ private: /// bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0, int button = 0); + int cx() const; + int cy() const; + int cpos() const; + LyXParagraph * cpar() const; + Row * crow() const; /* Private structures and variables */ /// @@ -256,5 +263,7 @@ private: typedef std::vector RowList; /// mutable RowList rows; + /// + LyXParagraph * old_par; }; #endif diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index e6ecafbd90..a4fe8ad2b9 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -117,6 +117,8 @@ public: /// virtual void draw(Painter &, LyXFont const &, int baseline, float & x) const = 0; + /// update the inset representation + virtual void update(BufferView *, LyXFont const &) const {} /// virtual LyXFont ConvertFont(LyXFont font); /// what appears in the minibuffer when opening diff --git a/src/lyxfr1.C b/src/lyxfr1.C index b2282715aa..13c928b5b5 100644 --- a/src/lyxfr1.C +++ b/src/lyxfr1.C @@ -82,7 +82,7 @@ void SetSelectionOverLenChars(BufferView * bv, int len) bv->text->sel_cursor = bv->text->cursor; for (int i = 0; i < len; ++i) bv->text->CursorRight(bv); - bv->text->SetSelection(bv); + bv->text->SetSelection(); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 94d671f8ad..030c0d3a87 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -163,7 +163,7 @@ inline void LyXFunc::moveCursorUpdate(bool selecting) { if (selecting || owner->view()->text->mark_set) { - owner->view()->text->SetSelection(owner->view()); + owner->view()->text->SetSelection(); owner->view()->toggleToggle(); } owner->view()->update(BufferView::SELECT|BufferView::FITCUR); @@ -531,11 +531,10 @@ string LyXFunc::Dispatch(int ac, if (owner->view()->available() && owner->view()->the_locking_inset) { UpdatableInset::RESULT result; - if (action > 1 - || (action == LFUN_UNKNOWN_ACTION - && keyseq.length >= -1)) { - if (action == LFUN_UNKNOWN_ACTION - && argument.empty()) { + if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) && + (keyseq.length >= -1))) + { + if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){ argument = keyseq.getiso(); } // Undo/Redo pre 0.13 is a bit tricky for insets. diff --git a/src/lyxtext.h b/src/lyxtext.h index d2ea4a6a86..eb91ea29cb 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -189,6 +189,7 @@ public: */ Row * GetRow(LyXParagraph * par, LyXParagraph::size_type pos, long & y) const; + /** returns the height of a default row, needed for scrollbar */ int DefaultHeight() const; @@ -224,7 +225,7 @@ public: LyXCursor toggle_end_cursor; /// need the selection cursor: - void SetSelection(BufferView *); + void SetSelection(); /// void ClearSelection() const; /// diff --git a/src/text.C b/src/text.C index c16548a436..4f5519891b 100644 --- a/src/text.C +++ b/src/text.C @@ -246,11 +246,11 @@ int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par, font.decSize(); return lyxfont::width(fs, font); } else if (c == LyXParagraph::META_INSET) { - Inset * tmpinset= par->GetInset(pos); - if (tmpinset) - return par->GetInset(pos)->width(bview->painter(), - font); - else + Inset * tmpinset = par->GetInset(pos); + if (tmpinset) { + tmpinset->update(bview, font); + return tmpinset->width(bview->painter(), font); + } else return 0; } else if (IsSeparatorChar(c)) @@ -1424,25 +1424,26 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const int maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val); - int pos_end = RowLast(row_ptr); - int labeladdon = 0; + int maxwidth = 0; // Check if any insets are larger for (pos = row_ptr->pos(); pos <= pos_end; ++pos) { - if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) { - tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos); - tmpinset = row_ptr->par()->GetInset(pos); - if (tmpinset) { - asc = tmpinset->ascent(bview->painter(), tmpfont); - desc = tmpinset->descent(bview->painter(), tmpfont); - if (asc > maxasc) - maxasc = asc; - if (desc > maxdesc) - maxdesc = desc; - } - } + if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) { + tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos); + tmpinset = row_ptr->par()->GetInset(pos); + if (tmpinset) { + tmpinset->update(bview, tmpfont); + asc = tmpinset->ascent(bview->painter(), tmpfont); + desc = tmpinset->descent(bview->painter(), tmpfont); + maxwidth += tmpinset->width(bview->painter(), tmpfont); + maxasc = max(maxasc, asc); + maxdesc = max(maxdesc, desc); + } + } else { + maxwidth += SingleWidth(bview, row_ptr->par(), pos); + } } // Check if any custom fonts are larger (Asger) @@ -1678,6 +1679,7 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const row_ptr->baseline(maxasc + labeladdon); height += row_ptr->height(); + width = maxwidth; } @@ -3147,7 +3149,7 @@ void LyXText::SelectWord(BufferView * bview) SetCursor(bview, cursor.par(), cursor.pos() ); // finally set the selection - SetSelection(bview); + SetSelection(); } @@ -3282,7 +3284,7 @@ void LyXText::SelectSelectedWord(BufferView * bview) SetCursor(bview, cursor.par(), cursor.pos()); // finally set the selection - SetSelection(bview); + SetSelection(); } @@ -3299,7 +3301,7 @@ void LyXText::DeleteWordForward(BufferView * bview) SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); sel_cursor = cursor; cursor = tmpcursor; - SetSelection(bview); + SetSelection(); /* -----> Great, CutSelection() gets rid of multiple spaces. */ CutSelection(bview); @@ -3320,7 +3322,7 @@ void LyXText::DeleteWordBackward(BufferView * bview) SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); sel_cursor = cursor; cursor = tmpcursor; - SetSelection(bview); + SetSelection(); CutSelection(bview); } } @@ -3342,7 +3344,7 @@ void LyXText::DeleteLineForward(BufferView * bview) SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); sel_cursor = cursor; cursor = tmpcursor; - SetSelection(bview); + SetSelection(); // What is this test for ??? (JMarc) if (!selection) { DeleteWordForward(bview); @@ -3814,7 +3816,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, LColor::selection); } else if (sel_start_cursor.row() == row_ptr) { if (is_rtl) - pain.fillRectangle(0, y_offset, + pain.fillRectangle(x_offset, y_offset, sel_start_cursor.x(), row_ptr->height(), LColor::selection); @@ -3830,13 +3832,13 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, row_ptr->height(), LColor::selection); else - pain.fillRectangle(0, y_offset, + pain.fillRectangle(x_offset, y_offset, sel_end_cursor.x(), row_ptr->height(), LColor::selection); } else if (y > long(sel_start_cursor.y()) && y < long(sel_end_cursor.y())) { - pain.fillRectangle(0, y_offset, + pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height(), LColor::selection); } @@ -3844,7 +3846,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, sel_end_cursor.row() != row_ptr && y > long(sel_start_cursor.y()) && y < long(sel_end_cursor.y())) { - pain.fillRectangle(0, y_offset, ww, row_ptr->height(), + pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height(), LColor::selection); } else if (sel_start_cursor.row() == row_ptr || sel_end_cursor.row() == row_ptr) { @@ -3858,7 +3860,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, #endif if ( (sel_start_cursor.row() != row_ptr && !is_rtl) || (sel_end_cursor.row() != row_ptr && is_rtl)) - pain.fillRectangle(0, y_offset, + pain.fillRectangle(x_offset, y_offset, int(tmpx), row_ptr->height(), LColor::selection); @@ -4625,8 +4627,6 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, #ifndef NEW_TABULAR } #endif - // Jürgen!!! FIX This! (NOW!!!) (please) - width = max(x - x_offset, float(width)); } diff --git a/src/text2.C b/src/text2.C index 6ab5764b58..778e1dd368 100644 --- a/src/text2.C +++ b/src/text2.C @@ -68,7 +68,7 @@ void LyXText::init() lastrow = 0; number_of_rows = 0; refresh_y = 0; - height = 0; + height = width = 0; status = LyXText::UNCHANGED; // set cursor at the very top position selection = true; /* these setting is necessary @@ -132,6 +132,7 @@ void LyXText::init(BufferView * bview) #if 1 // Dump all rowinformation: Row * tmprow = firstrow; + lyxerr << "Width = " << width << endl; lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n"; while (tmprow) { lyxerr << tmprow->baseline() << '\t' @@ -681,7 +682,7 @@ void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout) false); UpdateCounters(bview, cursor.row()); ClearSelection(); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true); } @@ -767,7 +768,7 @@ void LyXText::IncDepth(BufferView * bview) SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); UpdateCounters(bview, cursor.row()); ClearSelection(); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -828,7 +829,7 @@ void LyXText::DecDepth(BufferView * bview) SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); UpdateCounters(bview, cursor.row()); ClearSelection(); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -898,7 +899,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall) sel_cursor = cursor; SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); ClearSelection(); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true, tmpcursor.boundary()); } @@ -1064,7 +1065,7 @@ bool LyXText::FullRebreak(BufferView * bview) * They also delete the corresponding row */ // need the selection cursor: -void LyXText::SetSelection(BufferView * bview) +void LyXText::SetSelection() { if (!selection) { last_sel_cursor = sel_cursor; @@ -1452,7 +1453,7 @@ void LyXText::SetParagraph(BufferView * bview, SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos()); sel_cursor = cursor; SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -1517,7 +1518,7 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type, SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos()); sel_cursor = cursor; SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); - SetSelection(bview); + SetSelection(); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -2020,26 +2021,6 @@ void LyXText::InsertInset(BufferView * bview, Inset *inset) } -#ifdef USE_OLD_CUT_AND_PASTE -// this is for the simple cut and paste mechanism -static LyXParagraph * simple_cut_buffer = 0; -static char simple_cut_buffer_textclass = 0; - -void DeleteSimpleCutBuffer() -{ - if (!simple_cut_buffer) - return; - LyXParagraph * tmppar; - - while (simple_cut_buffer) { - tmppar = simple_cut_buffer; - simple_cut_buffer = simple_cut_buffer()->next; - delete tmppar; - } - simple_cut_buffer = 0; -} -#endif - void LyXText::copyEnvironmentType() { copylayouttype = cursor.par()->GetLayout(); @@ -2054,7 +2035,6 @@ void LyXText::pasteEnvironmentType(BufferView * bview) void LyXText::CutSelection(BufferView * bview, bool doclear) { - // Stuff what we got on the clipboard. Even if there is no selection. // There is a problem with having the stuffing here in that the @@ -2101,7 +2081,6 @@ void LyXText::CutSelection(BufferView * bview, bool doclear) } /* table stuff -- end */ #endif - // make sure that the depth behind the selection are restored, too LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next(); LyXParagraph * undoendpar = endpar; @@ -2157,7 +2136,7 @@ void LyXText::CutSelection(BufferView * bview, bool doclear) sel_cursor = cursor; UpdateCounters(bview, cursor.row()); } - + void LyXText::CopySelection(BufferView * bview) { @@ -2249,7 +2228,7 @@ void LyXText::PasteSelection(BufferView * bview) sel_cursor = cursor; SetCursor(bview, actpar, pos); - SetSelection(bview); + SetSelection(); UpdateCounters(bview, cursor.row()); } @@ -2285,7 +2264,7 @@ void LyXText::SetSelectionOverString(BufferView * bview, char const * string) sel_cursor = cursor; for (int i = 0; string[i]; ++i) CursorRight(bview); - SetSelection(bview); + SetSelection(); } @@ -2496,7 +2475,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str) SetCursor(bview, cursor.par(), cursor.pos()); sel_cursor = cursor; SetCursor(bview, par, pos); - SetSelection(bview); + SetSelection(); } @@ -3364,6 +3343,8 @@ LyXParagraph * LyXText::GetParFromID(int id) // undo functions bool LyXText::TextUndo(BufferView * bview) { + if (inset_owner) + return false; // returns false if no undo possible Undo * undo = bview->buffer()->undostack.pop(); if (undo) { @@ -3380,6 +3361,8 @@ bool LyXText::TextUndo(BufferView * bview) bool LyXText::TextRedo(BufferView * bview) { + if (inset_owner) + return false; // returns false if no redo possible Undo * undo = bview->buffer()->redostack.pop(); if (undo) { @@ -3396,6 +3379,8 @@ bool LyXText::TextRedo(BufferView * bview) bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo) { + if (inset_owner) + return false; // returns false if no undo possible bool result = false; if (undo) { @@ -3514,6 +3499,8 @@ bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo) void LyXText::FinishUndo() { + if (inset_owner) + return; // makes sure the next operation will be stored undo_finished = true; } @@ -3521,6 +3508,8 @@ void LyXText::FinishUndo() void LyXText::FreezeUndo() { + if (inset_owner) + return; // this is dangerous and for internal use only undo_frozen = true; } @@ -3528,6 +3517,8 @@ void LyXText::FreezeUndo() void LyXText::UnFreezeUndo() { + if (inset_owner) + return; // this is dangerous and for internal use only undo_frozen = false; } @@ -3537,6 +3528,8 @@ void LyXText::SetUndo(Buffer * buf, Undo::undo_kind kind, LyXParagraph const * before, LyXParagraph const * behind) const { + if (inset_owner) + return; if (!undo_frozen) buf->undostack.push(CreateUndo(buf, kind, before, behind)); buf->redostack.clear(); @@ -3546,6 +3539,8 @@ void LyXText::SetUndo(Buffer * buf, Undo::undo_kind kind, void LyXText::SetRedo(Buffer * buf, Undo::undo_kind kind, LyXParagraph const * before, LyXParagraph const * behind) { + if (inset_owner) + return; buf->redostack.push(CreateUndo(buf, kind, before, behind)); } @@ -3554,6 +3549,9 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind, LyXParagraph const * before, LyXParagraph const * behind) const { + if (inset_owner) + return 0; + int before_number = -1; int behind_number = -1; if (before) @@ -3567,8 +3565,7 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind, // appear one by one when undoing. // EDIT is special since only layout information, not the // contents of a paragaph are stored. - if (!undo_finished && kind != Undo::EDIT && - kind != Undo::FINISH){ + if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)){ // check wether storing is needed if (!buf->undostack.empty() && buf->undostack.top()->kind == kind && @@ -3646,6 +3643,8 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind, void LyXText::SetCursorParUndo(Buffer * buf) { + if (inset_owner) + return; SetUndo(buf, Undo::FINISH, cursor.par()->ParFromPos(cursor.pos())->previous, cursor.par()->ParFromPos(cursor.pos())->next); -- 2.39.2