From 0ca871014add94c501cb423d8dc65c1405f4d141 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Thu, 27 Nov 2003 09:22:41 +0000 Subject: [PATCH] setFont rework + some code simplification git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8140 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 9 +++ src/insets/ChangeLog | 8 +++ src/insets/inset.C | 4 -- src/insets/inset.h | 4 -- src/insets/insetcollapsable.C | 7 --- src/insets/insetcollapsable.h | 3 - src/insets/insetert.C | 13 ----- src/insets/insetert.h | 3 - src/insets/insettabular.C | 32 ----------- src/insets/insettabular.h | 3 - src/insets/insettext.C | 36 ++---------- src/text.C | 2 +- src/text2.C | 104 ++++++++-------------------------- 13 files changed, 45 insertions(+), 183 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ef775a8c4c..f804ed83aa 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ + +2003-11-27 Alfredo Braunstein + + * text2.C (setFont): rework using PosIterator (no more recursive) + (setCharFont): no more needed + (setLayout): no more selection cursors fiddling (done by redoCursor) + * text.C: cursorRight(bv)->cursorRight(true) (TODO: find and + destroy remaining ones) + 2003-11-26 Alfredo Braunstein * bufferview_funcs.[Ch]: split changeDepthAllowed from changeDepth diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index f608be8c95..e027610484 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2003-11-27 Alfredo Braunstein + + * insettext.[Ch]: + * inset.[Ch]: + * insetcollapsable.[Ch]: + * insetert.[Ch]: + * insettabular.[Ch]: remove setFont + 2003-11-25 Alfredo Braunstein * render_graphic.[Ch]: adjust comments diff --git a/src/insets/inset.C b/src/insets/inset.C index 6b523f82c0..cd9b7a2756 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -92,10 +92,6 @@ LColor_color InsetOld::backgroundColor() const } -void InsetOld::setFont(BufferView *, LyXFont const &, bool, bool) -{} - - bool InsetOld::forceDefaultParagraphs(InsetOld const * inset) const { if (owner()) diff --git a/src/insets/inset.h b/src/insets/inset.h index de97674da7..2d6a56a76e 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -239,10 +239,6 @@ public: /// check if the font of the char we want inserting is correct /// and modify it if it is not. virtual bool checkInsertChar(LyXFont &); - /// we need this here because collapsed insets are only EDITABLE - virtual void setFont(BufferView *, LyXFont const &, - bool toggleall = false, bool selectall = false); - // should this inset be handled like a normal charater virtual bool isChar() const { return false; } // is this equivalent to a letter? diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 4fa6d85db8..7f0cfe151f 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -337,13 +337,6 @@ void InsetCollapsable::getCursorPos(int & x, int & y) const } -void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font, - bool toggleall, bool selectall) -{ - inset.setFont(bv, font, toggleall, selectall); -} - - void InsetCollapsable::getLabelList(Buffer const & buffer, std::vector & list) const { diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index ff4f88458a..8fbd484168 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -79,9 +79,6 @@ public: /// get the screen x,y of the cursor void getCursorPos(int & x, int & y) const; /// - void setFont(BufferView *, LyXFont const &, bool toggleall = false, - bool selectall = false); - /// void setLabel(std::string const & l) const; /// void setLabelFont(LyXFont & f); diff --git a/src/insets/insetert.C b/src/insets/insetert.C index f8b3cde8f4..5c5a8b3e7f 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -224,19 +224,6 @@ bool InsetERT::insertInset(BufferView *, InsetOld *) } -void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall) -{ -#ifdef WITH_WARNINGS -#warning FIXME. More UI stupidity... -#endif - // if selectall is activated then the fontchange was an outside general - // fontchange and this messages is not needed - if (!selectall) - Alert::error(_("Cannot change font"), - _("You cannot change font settings inside TeX code.")); -} - - void InsetERT::updateStatus(bool swap) const { if (status_ != Inlined) { diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 4758c627e4..a49d5e470f 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -61,9 +61,6 @@ public: return code == InsetOld::NEWLINE_CODE; } /// - void setFont(BufferView *, LyXFont const &, - bool toggleall = false, bool selectall = false); - /// EDITABLE editable() const; /// int latex(Buffer const &, std::ostream &, diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 3f370893f5..654fbb4b5e 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1212,38 +1212,6 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock) } -void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall, - bool selectall) -{ - if (selectall) { - setSelection(0, tabular.getNumberOfCells() - 1); - } - if (hasSelection()) { - recordUndo(bv, Undo::ATOMIC); - bool const frozen = undo_frozen; - if (!frozen) - freezeUndo(); - // apply the fontchange on the whole selection - int sel_row_start; - int sel_row_end; - int sel_col_start; - int sel_col_end; - getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end); - for (int i = sel_row_start; i <= sel_row_end; ++i) - for (int j = sel_col_start; j <= sel_col_end; ++j) - tabular.getCellInset(i, j).setFont(bv, font, tall, true); - - if (!frozen) - unFreezeUndo(); - if (selectall) - clearSelection(); - updateLocal(bv); - } - if (the_locking_inset) - the_locking_inset->setFont(bv, font, tall); -} - - bool InsetTabular::tabularFeatures(BufferView * bv, string const & what) { LyXTabular::Feature action = LyXTabular::LAST_ACTION; diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index a342374341..763cc75d67 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -119,9 +119,6 @@ public: /// int getActCell() const { return actcell; } /// - void setFont(BufferView *, LyXFont const &, bool toggleall = false, - bool selectall = false); - /// void openLayoutDialog(BufferView *) const; /// bool showInsetDialog(BufferView *) const; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 61e4699de3..97e1582503 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -301,11 +301,11 @@ string const InsetText::editMessage() const void InsetText::sanitizeEmptyText(BufferView * bv) { if (paragraphs.size() == 1 - && paragraphs.begin()->empty() - && bv->getParentLanguage(this) != text_.current_font.language()) { + && paragraphs.begin()->empty() + && bv->getParentLanguage(this) != text_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); - setFont(bv, font, false); + text_.setFont(font, false); } } @@ -376,7 +376,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, paragraphs.size() == 1) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); - setFont(bv, font, false); + text_.setFont(font, false); } lyxerr << "InsetText::priv_dispatch (end)" << endl; @@ -489,34 +489,6 @@ void InsetText::getLabelList(Buffer const & buffer, } -void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, - bool selectall) -{ - if ((paragraphs.size() == 1 && paragraphs.begin()->empty()) - || cpar()->empty()) { - text_.setFont(font, toggleall); - return; - } - - if (text_.selection.set()) - text_.recUndo(text_.cursor.par()); - - if (selectall) { - text_.cursorTop(); - text_.selection.cursor = text_.cursor; - text_.cursorBottom(); - text_.setSelection(); - } - - text_.toggleFree(font, toggleall); - - if (selectall) - text_.clearSelection(); - - updateLocal(bv, true); -} - - void InsetText::markNew(bool track_changes) { ParagraphList::iterator pit = paragraphs.begin(); diff --git a/src/text.C b/src/text.C index d5e550d492..835c24a0ae 100644 --- a/src/text.C +++ b/src/text.C @@ -1281,7 +1281,7 @@ void LyXText::Delete() LyXCursor old_cursor = cursor; // just move to the right - cursorRight(bv()); + cursorRight(true); // if you had success make a backspace if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) { diff --git a/src/text2.C b/src/text2.C index c50e499cc7..58f6d3ff9a 100644 --- a/src/text2.C +++ b/src/text2.C @@ -43,6 +43,7 @@ #include "paragraph.h" #include "paragraph_funcs.h" #include "ParagraphParameters.h" +#include "PosIterator.h" #include "undo.h" #include "vspace.h" @@ -178,27 +179,6 @@ LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const } -void LyXText::setCharFont(ParagraphList::iterator pit, - pos_type pos, LyXFont const & fnt, - bool toggleall) -{ - BufferParams const & params = bv()->buffer()->params(); - LyXFont font = getFont(pit, pos); - font.update(fnt, params.language, toggleall); - // Let the insets convert their font - if (pit->isInset(pos)) { - InsetOld * inset = pit->getInset(pos); - if (isEditableInset(inset)) { - static_cast(inset) - ->setFont(bv(), fnt, toggleall, true); - } - } - - // Plug through to version below: - setCharFont(pit, pos, font); -} - - void LyXText::setCharFont( ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt) { @@ -349,14 +329,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur, // set layout over selection and make a total rebreak of those paragraphs void LyXText::setLayout(string const & layout) { - LyXCursor tmpcursor = cursor; // store the current cursor - - // if there is no selection just set the layout - // of the current paragraph - if (!selection.set()) { - selection.start = cursor; // dummy selection - selection.end = cursor; - } + setSelection(); // special handling of new environment insets BufferParams const & params = bv()->buffer()->params(); @@ -371,8 +344,7 @@ void LyXText::setLayout(string const & layout) if (bv()->insertInset(inset)) { //inset->edit(bv()); //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); - } - else + } else delete inset; return; } @@ -380,16 +352,8 @@ void LyXText::setLayout(string const & layout) ParagraphList::iterator endpit = setLayout(cursor, selection.start, selection.end, layout); redoParagraphs(getPar(selection.start), endpit); - - // we have to reset the selection, because the - // geometry could have changed - setCursor(selection.start.par(), selection.start.pos(), false); - selection.cursor = cursor; - setCursor(selection.end.par(), selection.end.pos(), false); updateCounters(); - clearSelection(); - setSelection(); - setCursor(tmpcursor.par(), tmpcursor.pos(), true); + redoCursor(); } @@ -499,39 +463,28 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) return; } - LyXCursor tmpcursor = cursor; // store the current cursor - - // ok we have a selection. This is always between sel_start_cursor - // and sel_end cursor - + // ok we have a selection. recUndo(selection.start.par(), selection.end.par()); freezeUndo(); - cursor = selection.start; - while (cursor.par() != selection.end.par() || - cursor.pos() < selection.end.pos()) - { - if (cursor.pos() < cursorPar()->size()) { - // an open footnote should behave like a closed one - setCharFont(cursorPar(), cursor.pos(), font, toggleall); - cursor.pos(cursor.pos() + 1); - } else { - cursor.pos(0); - cursor.par(cursor.par() + 1); - } + + ParagraphList::iterator beg = getPar(selection.start.par()); + ParagraphList::iterator end = getPar(selection.end.par()); + + PosIterator pos(&ownerParagraphs(), beg, selection.start.pos()); + PosIterator posend(&ownerParagraphs(), end, selection.end.pos()); + + BufferParams const & params = bv()->buffer()->params(); + + for (; pos != posend; ++pos) { + LyXFont f = getFont(pos.pit(), pos.pos()); + f.update(font, params.language, toggleall); + setCharFont(pos.pit(), pos.pos(), f); } + unFreezeUndo(); - redoParagraph(getPar(selection.start)); - - // we have to reset the selection, because the - // geometry could have changed, but we keep - // it for user convenience - setCursor(selection.start.par(), selection.start.pos()); - selection.cursor = cursor; - setCursor(selection.end.par(), selection.end.pos()); - setSelection(); - setCursor(tmpcursor.par(), tmpcursor.pos(), true, - tmpcursor.boundary()); + redoParagraphs(beg, ++end); + redoCursor(); } @@ -665,12 +618,7 @@ void LyXText::setParagraph(VSpace const & space_top, string const & labelwidthstring, bool noindent) { - LyXCursor tmpcursor = cursor; - if (!selection.set()) { - selection.start = cursor; - selection.end = cursor; - } - + setSelection(); // make sure that the depth behind the selection are restored, too ParagraphList::iterator endpit = boost::next(getPar(selection.end)); ParagraphList::iterator undoendpit = endpit; @@ -716,13 +664,7 @@ void LyXText::setParagraph(VSpace const & space_top, } redoParagraphs(getPar(selection.start), endpit); - - clearSelection(); - setCursor(selection.start.par(), selection.start.pos()); - selection.cursor = cursor; - setCursor(selection.end.par(), selection.end.pos()); - setSelection(); - setCursor(tmpcursor.par(), tmpcursor.pos()); + redoCursor(); } -- 2.39.2