From c69f29dda75751987a71ec3dccc9b62725006e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 20 Aug 2002 13:00:25 +0000 Subject: [PATCH] move half of BufferView_pimpl::dispatch() to LyXText::dispatch() which has its new home in text3.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5030 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 29 +- src/BufferView.h | 9 + src/BufferView2.C | 13 +- src/BufferView_pimpl.C | 818 +----------------- src/BufferView_pimpl.h | 6 +- src/ChangeLog | 8 + src/Makefile.am | 1 + .../controllers/ControlSpellchecker.C | 6 +- src/frontends/xforms/lyx_gui.C | 2 +- src/funcrequest.C | 29 + src/funcrequest.h | 8 + src/lyxtext.h | 14 +- src/mathed/formulabase.C | 5 +- src/mathed/math_inset.C | 6 - src/mathed/math_inset.h | 3 - src/text.C | 48 +- src/text3.C | 549 ++++++++++++ 17 files changed, 678 insertions(+), 876 deletions(-) create mode 100644 src/text3.C diff --git a/src/BufferView.C b/src/BufferView.C index 475720d1f2..0bb5f4609f 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -18,11 +18,12 @@ #include "lyxtext.h" #include "frontends/screen.h" #include "frontends/WorkArea.h" +#include "frontends/LyXView.h" -BufferView::BufferView(LyXView * o, int xpos, int ypos, +BufferView::BufferView(LyXView * owner, int xpos, int ypos, int width, int height) - : pimpl_(new Pimpl(this, o, xpos, ypos, width, height)) + : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height)) { text = 0; } @@ -47,6 +48,12 @@ LyXScreen & BufferView::screen() const } +WorkArea & BufferView::workarea() const +{ + return pimpl_->workarea(); +} + + LyXView * BufferView::owner() const { return pimpl_->owner_; @@ -139,6 +146,12 @@ void BufferView::beforeChange(LyXText * text) } +void BufferView::finishChange(bool fitcur) +{ + pimpl_->finishChange(fitcur); +} + + void BufferView::savePosition(unsigned int i) { pimpl_->savePosition(i); @@ -241,3 +254,15 @@ bool BufferView::dispatch(FuncRequest const & ev) { return pimpl_->dispatch(ev); } + + +void BufferView::moveCursorUpdate(bool selecting, bool fitcur = true) +{ + pimpl_->moveCursorUpdate(selecting, fitcur); +} + + +void BufferView::message(string const & msg) const +{ + owner()->message(msg); +} diff --git a/src/BufferView.h b/src/BufferView.h index 454dab6cf8..198da76e8a 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -30,6 +30,7 @@ class Language; class Painter; class UpdatableInset; class WordLangTuple; +class WorkArea; /// class BufferView : boost::noncopyable { @@ -56,6 +57,8 @@ public: Painter & painter() const; /// LyXScreen & screen() const; + /// return the work area for this bview + WorkArea & workarea() const; /// void buffer(Buffer * b); /// @@ -89,6 +92,8 @@ public: /// void beforeChange(LyXText *); /// + void finishChange(bool fitcur = false); + /// void savePosition(unsigned int i); /// void restorePosition(unsigned int i); @@ -129,6 +134,8 @@ public: /// bool gotoLabel(string const & label); /// + void message(string const & msg) const; + /// void paste(); /// void cut(bool realcut = true); @@ -203,6 +210,8 @@ public: void stuffClipboard(string const &) const; /// bool dispatch(FuncRequest const & argument); + /// + void moveCursorUpdate(bool selecting, bool fitcur = true); private: /// struct Pimpl; diff --git a/src/BufferView2.C b/src/BufferView2.C index 36bb14c6c3..6361c7e365 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -63,7 +63,8 @@ bool BufferView::insertLyXFile(string const & filen) // // Moved from lyx_cb.C (Lgb) { - if (filen.empty()) return false; + if (filen.empty()) + return false; string const fname = MakeAbsPath(filen); @@ -455,7 +456,8 @@ WordLangTuple const BufferView::nextWord(float & value) void BufferView::selectLastWord() { - if (!available()) return; + if (!available()) + return; LyXCursor cur = text->selection.cursor; hideCursor(); @@ -481,17 +483,18 @@ void BufferView::endOfSpellCheck() void BufferView::replaceWord(string const & replacestring) { - if (!available()) return; + if (!available()) + return; LyXText * tt = getLyXText(); hideCursor(); update(tt, BufferView::SELECT|BufferView::FITCUR); - /* clear the selection (if there is any) */ + // clear the selection (if there is any) toggleSelection(false); update(tt, BufferView::SELECT|BufferView::FITCUR); - /* clear the selection (if there is any) */ + // clear the selection (if there is any) toggleSelection(false); tt->replaceSelectionWithString(this, replacestring); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 9ac004e3d8..e0e28b1075 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -67,7 +67,6 @@ #endif #include "insets/insetcaption.h" #include "insets/insetfloatlist.h" -#include "insets/insetspecialchar.h" #include "mathed/formulabase.h" @@ -646,8 +645,7 @@ void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state bu } else { text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT); } - /* This will fit the cursor on the screen - * if necessary */ + // This will fit the cursor on the screen if necessary update(text, BufferView::SELECT|BufferView::FITCUR); workarea().haveSelection(bv_->getLyXText()->selection.set()); } @@ -676,8 +674,7 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state bu if (text->bv_owner) { screen().toggleSelection(text, bv_, false); } - /* This will fit the cursor on the screen - * if necessary */ + // This will fit the cursor on the screen if necessary update(text, BufferView::SELECT|BufferView::FITCUR); workarea().haveSelection(bv_->getLyXText()->selection.set()); } @@ -1210,6 +1207,14 @@ void BufferView::Pimpl::beforeChange(LyXText * text) } +void BufferView::Pimpl::finishChange(bool fitcur) +{ + finishUndo(); + moveCursorUpdate(fitcur); + bv_->owner()->view_state_changed(); +} + + void BufferView::Pimpl::savePosition(unsigned int i) { if (i >= saved_positions_num) @@ -1575,30 +1580,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) break; } - case LFUN_HYPHENATION: - specialChar(InsetSpecialChar::HYPHENATION); - break; - - case LFUN_LIGATURE_BREAK: - specialChar(InsetSpecialChar::LIGATURE_BREAK); - break; - - case LFUN_LDOTS: - specialChar(InsetSpecialChar::LDOTS); - break; - - case LFUN_END_OF_SENTENCE: - specialChar(InsetSpecialChar::END_OF_SENTENCE); - break; - - case LFUN_MENU_SEPARATOR: - specialChar(InsetSpecialChar::MENU_SEPARATOR); - break; - - case LFUN_HFILL: - hfill(); - break; - case LFUN_DEPTH_MIN: changeDepth(bv_, bv_->getLyXText(), -1); break; @@ -1744,69 +1725,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) owner_->getLyXFunc().setMessage(currentState(bv_)); break; - case LFUN_UPCASE_WORD: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT - | BufferView::FITCUR); - lt->changeCase(bv_, LyXText::text_uppercase); - if (lt->inset_owner) - updateInset(lt->inset_owner, true); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } - break; - - case LFUN_LOWCASE_WORD: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->changeCase(bv_, LyXText::text_lowercase); - if (lt->inset_owner) - updateInset(lt->inset_owner, true); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } - break; - - case LFUN_CAPITALIZE_WORD: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->changeCase(bv_, LyXText::text_capitalization); - if (lt->inset_owner) - updateInset(lt->inset_owner, true); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } - break; - - case LFUN_TRANSPOSE_CHARS: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->transposeChars(*bv_); - if (lt->inset_owner) - updateInset(lt->inset_owner, true); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } - break; - - case LFUN_INSERT_LABEL: MenuInsertLabel(bv_, ev.argument); break; @@ -1855,510 +1773,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) _("in current document.")); } } - break; - - // --- Cursor Movements ----------------------------- - case LFUN_RIGHT: - { - LyXText * lt = bv_->getLyXText(); - - bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params); - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - if (is_rtl) - lt->cursorLeft(bv_, false); - if (lt->cursor.pos() < lt->cursor.par()->size() - && lt->cursor.par()->isInset(lt->cursor.pos()) - && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) { - Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos()); - owner_->getLyXFunc().setMessage(tmpinset->editMessage()); - if (is_rtl) - tmpinset->edit(bv_, false); - else - tmpinset->edit(bv_); - break; - } - if (!is_rtl) - lt->cursorRight(bv_, false); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_LEFT: - { - // This is soooo ugly. Isn`t it possible to make - // it simpler? (Lgb) - LyXText * lt = bv_->getLyXText(); - bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params); - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - LyXCursor const cur = lt->cursor; - if (!is_rtl) - lt->cursorLeft(bv_, false); - if ((is_rtl || cur != lt->cursor) && // only if really moved! - lt->cursor.pos() < lt->cursor.par()->size() && - lt->cursor.par()->isInset(lt->cursor.pos()) && - isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) { - Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos()); - owner_->getLyXFunc().setMessage(tmpinset->editMessage()); - if (is_rtl) - tmpinset->edit(bv_); - else - tmpinset->edit(bv_, false); - break; - } - if (is_rtl) - lt->cursorRight(bv_, false); - - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_UP: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - lt->cursorUp(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_DOWN: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - lt->cursorDown(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_UP_PARAGRAPH: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - lt->cursorUpParagraph(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_DOWN_PARAGRAPH: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - lt->cursorDownParagraph(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_PRIOR: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - cursorPrevious(lt); - finishUndo(); - moveCursorUpdate(false, false); - owner_->view_state_changed(); - } - break; - - case LFUN_NEXT: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::UPDATE); - cursorNext(lt); - finishUndo(); - moveCursorUpdate(false, false); - owner_->view_state_changed(); - } - break; - - case LFUN_HOME: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->cursorHome(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_END: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorEnd(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_SHIFT_TAB: - case LFUN_TAB: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorTab(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_WORDRIGHT: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorLeftOneWord(bv_); - else - lt->cursorRightOneWord(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_WORDLEFT: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorRightOneWord(bv_); - else - lt->cursorLeftOneWord(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_BEGINNINGBUF: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorTop(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - case LFUN_ENDBUF: - { - LyXText * lt = bv_->getLyXText(); - - if (!lt->selection.mark()) - beforeChange(lt); - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorBottom(bv_); - finishUndo(); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - /* cursor selection ---------------------------- */ - case LFUN_RIGHTSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorLeft(bv_); - else - lt->cursorRight(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_LEFTSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorRight(bv_); - else - lt->cursorLeft(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_UPSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorUp(bv_, true); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_DOWNSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorDown(bv_, true); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_UP_PARAGRAPHSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorUpParagraph(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_DOWN_PARAGRAPHSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorDownParagraph(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_PRIORSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - cursorPrevious(lt); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_NEXTSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - cursorNext(lt); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_HOMESEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->cursorHome(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_ENDSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->cursorEnd(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_WORDRIGHTSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorLeftOneWord(bv_); - else - lt->cursorRightOneWord(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_WORDLEFTSEL: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) - lt->cursorRightOneWord(bv_); - else - lt->cursorLeftOneWord(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_BEGINNINGBUFSEL: - { - LyXText * lt = bv_->getLyXText(); - - if (lt->inset_owner) - break; - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->cursorTop(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - case LFUN_ENDBUFSEL: - { - LyXText * lt = bv_->getLyXText(); - - if (lt->inset_owner) - break; - update(lt, - BufferView::SELECT|BufferView::FITCUR); - lt->cursorBottom(bv_); - finishUndo(); - moveCursorUpdate(true); - owner_->view_state_changed(); - } - break; - - // --- text changing commands ------------------------ - case LFUN_BREAKLINE: - { - LyXText * lt = bv_->getLyXText(); - - beforeChange(lt); - lt->insertChar(bv_, Paragraph::META_NEWLINE); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos()); - moveCursorUpdate(false); - } - break; - - case LFUN_PROTECTEDSPACE: - { - LyXText * lt = bv_->getLyXText(); - LyXLayout_ptr const & style = lt->cursor.par()->layout(); - - if (style->free_spacing) { - lt->insertChar(bv_, ' '); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } else { - specialChar(InsetSpecialChar::PROTECTED_SEPARATOR); - } - moveCursorUpdate(false); - } - break; - - case LFUN_SETMARK: - { - LyXText * lt = bv_->getLyXText(); - - if (lt->selection.mark()) { - beforeChange(lt); - update(lt, - BufferView::SELECT - | BufferView::FITCUR); - owner_->getLyXFunc().setMessage(N_("Mark removed")); - } else { - beforeChange(lt); - lt->selection.mark(true); - update(lt, - BufferView::SELECT - | BufferView::FITCUR); - owner_->getLyXFunc().setMessage(N_("Mark set")); - } - lt->selection.cursor = lt->cursor; - } break; case LFUN_DELETE: @@ -2438,70 +1852,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; - /* -------> Delete word forward. */ - case LFUN_DELETE_WORD_FORWARD: - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv_->getLyXText()->deleteWordForward(bv_); - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); - moveCursorUpdate(false); - owner_->view_state_changed(); - break; - - /* -------> Delete word backward. */ - case LFUN_DELETE_WORD_BACKWARD: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->deleteWordBackward(bv_); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - moveCursorUpdate(false); - owner_->view_state_changed(); - } - break; - - /* -------> Kill to end of line. */ - case LFUN_DELETE_LINE_FORWARD: - { - LyXText * lt = bv_->getLyXText(); - - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->deleteLineForward(bv_); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - moveCursorUpdate(false); - } - break; - - /* -------> Set mark off. */ - case LFUN_MARK_OFF: - { - LyXText * lt = bv_->getLyXText(); - - beforeChange(lt); - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->selection.cursor = lt->cursor; - owner_->getLyXFunc().setMessage(N_("Mark off")); - } - break; - - /* -------> Set mark on. */ - case LFUN_MARK_ON: - { - LyXText * lt = bv_->getLyXText(); - - beforeChange(lt); - lt->selection.mark(true); - update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->selection.cursor = lt->cursor; - owner_->getLyXFunc().setMessage(N_("Mark on")); - } - break; case LFUN_BACKSPACE: { @@ -2699,6 +2049,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; + case LFUN_QUOTE: smartQuote(); break; @@ -2825,53 +2176,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; - // --- lyxserver commands ---------------------------- - - case LFUN_CHARATCURSOR: - { - pos_type pos = bv_->getLyXText()->cursor.pos(); - if (pos < bv_->getLyXText()->cursor.par()->size()) - owner_->getLyXFunc().setMessage( - tostr(bv_->getLyXText()->cursor.par()->getChar(pos))); - else - owner_->getLyXFunc().setMessage("EOF"); - } - break; - - case LFUN_GETXY: - owner_->getLyXFunc().setMessage(tostr(bv_->getLyXText()->cursor.x()) - + ' ' - + tostr(bv_->getLyXText()->cursor.y())); - break; - - case LFUN_SETXY: - { - int x = 0; - int y = 0; - if (::sscanf(ev.argument.c_str(), " %d %d", &x, &y) != 2) { - lyxerr << "SETXY: Could not parse coordinates in '" - << ev.argument << std::endl; - } - bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y); - } - break; - - case LFUN_GETLAYOUT: - owner_->getLyXFunc().setMessage(tostr(bv_->getLyXText()->cursor.par()->layout())); - break; - - case LFUN_GETFONT: - { - LyXFont & font = bv_->getLyXText()->current_font; - if (font.shape() == LyXFont::ITALIC_SHAPE) - owner_->getLyXFunc().setMessage("E"); - else if (font.shape() == LyXFont::SMALLCAPS_SHAPE) - owner_->getLyXFunc().setMessage("N"); - else - owner_->getLyXFunc().setMessage("0"); - - } - break; // --- accented characters --------------------------- @@ -3071,55 +2375,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; - case LFUN_SELFINSERT: - { - if (ev.argument.empty()) break; - - /* 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). */ - - LyXText * lt = bv_->getLyXText(); - - if (lyxrc.auto_region_delete) { - if (lt->selection.set()) { - lt->cutSelection(bv_, false, false); - bv_->update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } - workarea().haveSelection(false); - } - - beforeChange(lt); - LyXFont const old_font(lt->real_current_font); - - string::const_iterator cit = ev.argument.begin(); - string::const_iterator end = ev.argument.end(); - for (; cit != end; ++cit) { - owner_->getIntl().getTransManager(). - TranslateAndInsert(*cit, lt); - } - - bv_->update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - - lt->selection.cursor = lt->cursor; - moveCursorUpdate(false); - - // real_current_font.number can change so we need to - // update the minibuffer - if (old_font != lt->real_current_font) - owner_->view_state_changed(); - //return string(); - } - break; - case LFUN_DATE_INSERT: // jdblair: date-insert cmd { time_t now_time_t = time(NULL); @@ -3163,40 +2418,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } -void BufferView::Pimpl::hfill() -{ - if (available()) { - LyXText * lt = bv_->getLyXText(); - hideCursor(); - update(lt, - BufferView::SELECT - | BufferView::FITCUR); - lt->insertChar(bv_, Paragraph::META_HFILL); - update(lt, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - } -} - - -void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind) -{ - if (available()) { - LyXText * lt = bv_->getLyXText(); - - hideCursor(); - update(lt, BufferView::SELECT|BufferView::FITCUR); - InsetSpecialChar * new_inset = - new InsetSpecialChar(kind); - if (!insertInset(new_inset)) - delete new_inset; - else - updateInset(new_inset, true); - } -} - - void BufferView::Pimpl::smartQuote() { LyXText const * lt = bv_->getLyXText(); @@ -3211,7 +2432,6 @@ void BufferView::Pimpl::smartQuote() else c = par->getChar(pos - 1); - hideCursor(); LyXLayout_ptr const & style = par->layout(); @@ -3359,7 +2579,7 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty) // if yes do the update as always otherwise we have to update the // toplevel inset where this inset is inside Inset * tl_inset = inset; - while(tl_inset->owner()) + while (tl_inset->owner()) tl_inset = tl_inset->owner(); hideCursor(); if (tl_inset == inset) { @@ -3378,10 +2598,10 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty) } else if (static_cast(tl_inset) ->updateInsetInInset(bv_, inset)) { - if (bv_->text->updateInset(bv_, tl_inset)) { - update(); - updateScrollbar(); - } + if (bv_->text->updateInset(bv_, tl_inset)) { + update(); + updateScrollbar(); + } } } @@ -3431,3 +2651,9 @@ void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content) { gotoInset(vector(1, code), same_content); } + + +void BufferView::Pimpl::message(string const & msg) +{ + bv_->owner()->getLyXFunc().setMessage(msg); +} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 5522450a05..e3f86e44ba 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -100,6 +100,8 @@ struct BufferView::Pimpl : public boost::signals::trackable { /// void beforeChange(LyXText *); /// + void finishChange(bool fitcur); + /// void savePosition(unsigned int i); /// void restorePosition(unsigned int i); @@ -125,6 +127,8 @@ struct BufferView::Pimpl : public boost::signals::trackable { void updateInset(Inset * inset, bool mark_dirty); /// bool dispatch(FuncRequest const & ev); + /// + void message(string const & msg); private: /** * Return the on-screen dimensions of the inset at the cursor. @@ -143,8 +147,6 @@ private: /// open and lock an updatable inset bool open_new_inset(UpdatableInset * new_inset, bool behind = false); /// - void specialChar(InsetSpecialChar::Kind); - /// void hfill(); /// void smartQuote(); diff --git a/src/ChangeLog b/src/ChangeLog index dd83f5d67e..c479c620b1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -9,6 +9,14 @@ caption, make sure to recurse to parent insets (so that a caption in a minipage in a figure float works) (bug #568) +2002-08-20 André Pönitz + + * text3.C: new file for LyXText::dispatch() and helpers + + * BufferView.[Ch]: move text related stuff to LyXText::dispatch() + + * funcrequest.[Ch]: add message() do avoid direct access to LyXFunc + 2002-08-19 André Pönitz * lyxtext.h: diff --git a/src/Makefile.am b/src/Makefile.am index 128391e177..a03addb607 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -204,6 +204,7 @@ lyx_SOURCES = \ texrow.h \ text.C \ text2.C \ + text3.C \ toc.C \ toc.h \ trans.C \ diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 24c6f23b7c..4f0b6e9825 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -13,18 +13,14 @@ #endif #include "ControlSpellchecker.h" - #include "ViewBase.h" - #include "buffer.h" #include "BufferView.h" #include "gettext.h" #include "language.h" #include "lyxrc.h" #include "lyxtext.h" - #include "frontends/Alert.h" - #include "support/lstrings.h" #include "ispell.h" @@ -32,6 +28,7 @@ # include "pspell.h" #endif + ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), rtl_(false), newval_(0.0), oldval_(0), newvalue_(0), count_(0), @@ -192,7 +189,6 @@ void ControlSpellchecker::clearParams() message_ = tostr(count_); if (count_ != 1) { message_ += _(" words checked."); - } else { message_ += _(" word checked."); } diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index ca69abcd72..2082d46c06 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -173,7 +173,7 @@ void lyx_gui::parse_init(int & argc, char * argv[]) void lyx_gui::parse_lyxrc() { // FIXME !!!! - lyxrc.dpi = 95; + //lyxrc.dpi = 95; XformsColor::read(AddName(user_lyxdir, "preferences.xform")); diff --git a/src/funcrequest.C b/src/funcrequest.C index 13a5c12852..31c6409846 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -7,6 +7,11 @@ */ #include "funcrequest.h" +#include "BufferView.h" +#include "lyxfunc.h" // only for setMessage() +#include "frontends/LyXView.h" +#include "debug.h" + FuncRequest::FuncRequest() : view_(0), action(LFUN_UNKNOWN_ACTION) @@ -39,6 +44,13 @@ FuncRequest::FuncRequest {} + +FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg) + : view_(cmd.view_), action(cmd.action), argument(arg), + x(cmd.x), y(cmd.y), button_(cmd.button_) +{} + + BufferView * FuncRequest::view() const { return view_; @@ -56,3 +68,20 @@ mouse_button::state FuncRequest::button() const return button_; } + +void FuncRequest::message(string const & msg) const +{ + if (view_) + view_->owner()->getLyXFunc().setMessage(msg); + else + lyxerr << "Dropping message '" << msg << "'\n"; +} + + +void FuncRequest::errorMessage(string const & msg) const +{ + if (view_) + view_->owner()->getLyXFunc().setErrorMessage(msg); + else + lyxerr << "Dropping error message '" << msg << "'\n"; +} diff --git a/src/funcrequest.h b/src/funcrequest.h index ec39066059..a03d953081 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -34,6 +34,9 @@ public: /// for mouse events FuncRequest(BufferView * view, kb_action act, int x, int y, mouse_button::state button); + /// for changing requests a bit + FuncRequest(FuncRequest const & cmd, string const & arg); + /// access to the view BufferView * view() const; /// access to the view @@ -41,6 +44,11 @@ public: /// access to button mouse_button::state button() const; + /// output a message + void message(string const & msg) const; + /// output an error message + void errorMessage(string const & msg) const; + private: /// the BufferView we are talking to BufferView * view_; diff --git a/src/lyxtext.h b/src/lyxtext.h index 96de949c3d..f58f6de0d8 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -359,12 +359,6 @@ public: /// void backspace(BufferView *); /// - void deleteWordForward(BufferView *); - /// - void deleteWordBackward(BufferView *); - /// - void deleteLineForward(BufferView *); - /// bool selectWordWhenUnderCursor(BufferView *, word_location const); /// @@ -619,11 +613,17 @@ public: /** Updates all counters starting BEHIND the row. Changed paragraphs * with a dynamic left margin will be rebroken. */ void updateCounters(BufferView *) const; + /// + void update(BufferView * bv, bool changed = true); private: /// void setCounter(Buffer const *, Paragraph * par) const; /// - Inset::RESULT lfunAppendix(FuncRequest const & cmd); + void deleteWordForward(BufferView *); + /// + void deleteWordBackward(BufferView *); + /// + void deleteLineForward(BufferView *); /* * some low level functions diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 1bfab1f6c9..6914826429 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -28,7 +28,6 @@ #include "funcrequest.h" #include "BufferView.h" #include "lyxtext.h" -#include "lyxfunc.h" #include "gettext.h" #include "LaTeXFeatures.h" #include "debug.h" @@ -945,7 +944,7 @@ void mathDispatchCreation(FuncRequest const & cmd, bool display) bv->getLyXText()->cutSelection(bv); openNewInset(bv, f); } - bv->owner()->getLyXFunc().setMessage(N_("Math editor mode")); + cmd.message(N_("Math editor mode")); } @@ -971,7 +970,7 @@ void mathDispatch(FuncRequest const & cmd) case LFUN_MATH_MACRO: if (cmd.argument.empty()) - bv->owner()->getLyXFunc().setErrorMessage(N_("Missing argument")); + cmd.errorMessage(N_("Missing argument")); else { string s = cmd.argument; string const s1 = token(s, ' ', 1); diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 583252d84a..b31246e9d7 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -306,9 +306,3 @@ Dialogs & getDialogs() { return mathcursor->formula()->view()->owner()->getDialogs(); } - - -LyXFunc & getLyXFunc() -{ - return mathcursor->formula()->view()->owner()->getLyXFunc(); -} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 680955197d..e27813ff7e 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -314,9 +314,6 @@ void initMath(); /// here to ssave a few includes in the insets class Dialogs; -class LyXFunc; - Dialogs & getDialogs(); -LyXFunc & getLyXFunc(); #endif diff --git a/src/text.C b/src/text.C index 4568a03107..c662d63570 100644 --- a/src/text.C +++ b/src/text.C @@ -17,19 +17,20 @@ #include "bufferparams.h" #include "buffer.h" #include "debug.h" +#include "intl.h" #include "lyxrc.h" #include "encoding.h" #include "frontends/LyXView.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" #include "frontends/screen.h" +#include "frontends/WorkArea.h" #include "bufferview_funcs.h" #include "BufferView.h" #include "language.h" #include "ParagraphParameters.h" #include "undo_funcs.h" #include "WordLangTuple.h" -#include "funcrequest.h" #include "insets/insetbib.h" #include "insets/insettext.h" @@ -3949,48 +3950,3 @@ int LyXText::getDepth() const return cursor.par()->getDepth(); } - -Inset::RESULT LyXText::lfunAppendix(FuncRequest const & cmd) -{ - BufferView * bv = cmd.view(); - // what is this good for? - if (!bv->available()) - return Inset::UNDISPATCHED; - - Paragraph * par = cursor.par(); - bool start = !par->params().startOfAppendix(); - - // ensure that we have only one start_of_appendix in this document - Paragraph * tmp = ownerParagraph(); - for (; tmp; tmp = tmp->next()) { - tmp->params().startOfAppendix(false); - } - - par->params().startOfAppendix(start); - - // we can set the refreshing parameters now - status(cmd.view(), LyXText::NEED_MORE_REFRESH); - refresh_y = 0; - refresh_row = 0; // not needed for full update - updateCounters(cmd.view()); - setCursor(cmd.view(), cursor.par(), cursor.pos()); - bv->update(this, - BufferView::SELECT - | BufferView::FITCUR - | BufferView::CHANGE); - return Inset::DISPATCHED; -} - - -Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) -{ - switch (cmd.action) { - case LFUN_APPENDIX: - return lfunAppendix(cmd); - - default: - return Inset::UNDISPATCHED; - } - // shut up compiler - return Inset::UNDISPATCHED; -} diff --git a/src/text3.C b/src/text3.C new file mode 100644 index 0000000000..2a7c3ec47d --- /dev/null +++ b/src/text3.C @@ -0,0 +1,549 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2002 The LyX Team. + * + * ====================================================== */ + +#include + +#include "lyxtext.h" +#include "lyxrow.h" +#include "paragraph.h" +#include "BufferView.h" +#include "funcrequest.h" +#include "lyxrc.h" +#include "debug.h" +#include "bufferparams.h" +#include "buffer.h" +#include "ParagraphParameters.h" +#include "gettext.h" +#include "intl.h" +#include "support/lstrings.h" +#include "frontends/LyXView.h" +#include "frontends/WorkArea.h" +#include "insets/insetspecialchar.h" +#include "insets/insettext.h" + + +void LyXText::update(BufferView * bv, bool changed) +{ + BufferView::UpdateCodes c = BufferView::SELECT | BufferView::FITCUR; + if (changed) + bv->update(this, c | BufferView::CHANGE); + else + bv->update(this, c); +} + + +void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind) +{ + bv->hideCursor(); + lt->update(bv); + InsetSpecialChar * new_inset = new InsetSpecialChar(kind); + if (!bv->insertInset(new_inset)) + delete new_inset; + else + bv->updateInset(new_inset, true); +} + + +Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) +{ + BufferView * bv = cmd.view(); + + switch (cmd.action) { + + case LFUN_APPENDIX: { + Paragraph * par = cursor.par(); + bool start = !par->params().startOfAppendix(); + + // ensure that we have only one start_of_appendix in this document + Paragraph * tmp = ownerParagraph(); + for (; tmp; tmp = tmp->next()) + tmp->params().startOfAppendix(false); + + par->params().startOfAppendix(start); + + // we can set the refreshing parameters now + status(cmd.view(), LyXText::NEED_MORE_REFRESH); + refresh_y = 0; + refresh_row = 0; // not needed for full update + updateCounters(cmd.view()); + setCursor(cmd.view(), cursor.par(), cursor.pos()); + update(bv); + return Inset::DISPATCHED; + } + + case LFUN_DELETE_WORD_FORWARD: + bv->beforeChange(this); + update(bv, false); + deleteWordForward(bv); + update(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_DELETE_WORD_BACKWARD: + bv->beforeChange(this); + update(bv, false); + deleteWordBackward(bv); + update(bv, true); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_DELETE_LINE_FORWARD: + bv->beforeChange(this); + update(bv, false); + deleteLineForward(bv); + update(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_SHIFT_TAB: + case LFUN_TAB: + if (!selection.mark()) + bv->beforeChange(this); + update(bv, false); + cursorTab(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_WORDRIGHT: + if (!selection.mark()) + bv->beforeChange(this); + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorLeftOneWord(bv); + else + cursorRightOneWord(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_WORDLEFT: + if (!selection.mark()) + bv->beforeChange(this); + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorRightOneWord(bv); + else + cursorLeftOneWord(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_BEGINNINGBUF: + if (!selection.mark()) + bv->beforeChange(this); + update(bv, false); + cursorTop(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_ENDBUF: + if (selection.mark()) + bv->beforeChange(this); + update(bv, false); + cursorBottom(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_RIGHTSEL: + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorLeft(bv); + else + cursorRight(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_LEFTSEL: + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorRight(bv); + else + cursorLeft(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_UPSEL: + update(bv, false); + cursorUp(bv, true); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_DOWNSEL: + update(bv, false); + cursorDown(bv, true); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_UP_PARAGRAPHSEL: + update(bv, false); + cursorUpParagraph(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_DOWN_PARAGRAPHSEL: + update(bv, false); + cursorDownParagraph(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_PRIORSEL: + update(bv, false); + bv->cursorPrevious(this); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_NEXTSEL: + update(bv, false); + bv->cursorNext(this); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_HOMESEL: + update(bv, false); + cursorHome(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_ENDSEL: + update(bv, false); + cursorEnd(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_WORDRIGHTSEL: + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorLeftOneWord(bv); + else + cursorRightOneWord(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_WORDLEFTSEL: + update(bv, false); + if (cursor.par()->isRightToLeftPar(bv->buffer()->params)) + cursorRightOneWord(bv); + else + cursorLeftOneWord(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_RIGHT: { + bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params); + if (!selection.mark()) + bv->beforeChange(this); + update(bv); + if (is_rtl) + cursorLeft(bv, false); + if (cursor.pos() < cursor.par()->size() + && cursor.par()->isInset(cursor.pos()) + && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) { + Inset * tmpinset = cursor.par()->getInset(cursor.pos()); + cmd.message(tmpinset->editMessage()); + if (is_rtl) + tmpinset->edit(bv, false); + else + tmpinset->edit(bv); + return Inset::DISPATCHED; + } + if (!is_rtl) + cursorRight(bv, false); + bv->finishChange(false); + return Inset::DISPATCHED; + } + + case LFUN_LEFT: { + // This is soooo ugly. Isn`t it possible to make + // it simpler? (Lgb) + bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params); + if (!selection.mark()) + bv->beforeChange(this); + update(bv); + LyXCursor const cur = cursor; + if (!is_rtl) + cursorLeft(bv, false); + if ((is_rtl || cur != cursor) && // only if really moved! + cursor.pos() < cursor.par()->size() && + cursor.par()->isInset(cursor.pos()) && + isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) { + Inset * tmpinset = cursor.par()->getInset(cursor.pos()); + cmd.message(tmpinset->editMessage()); + if (is_rtl) + tmpinset->edit(bv); + else + tmpinset->edit(bv, false); + break; + return Inset::DISPATCHED; + } + if (is_rtl) + cursorRight(bv, false); + bv->finishChange(false); + return Inset::DISPATCHED; + } + + case LFUN_UP: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + cursorUp(bv); + bv->finishChange(false); + return Inset::DISPATCHED; + + case LFUN_DOWN: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + cursorDown(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_UP_PARAGRAPH: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + cursorUpParagraph(bv); + bv->finishChange(); + return Inset::DISPATCHED; + + case LFUN_DOWN_PARAGRAPH: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + cursorDownParagraph(bv); + bv->finishChange(false); + return Inset::DISPATCHED; + + case LFUN_PRIOR: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + bv->cursorPrevious(this); + bv->finishChange(false); + // was: + // finishUndo(); + // moveCursorUpdate(false, false); + // owner_->view_state_changed(); + return Inset::DISPATCHED; + + case LFUN_NEXT: + if (!selection.mark()) + bv->beforeChange(this); + bv->update(this, BufferView::UPDATE); + bv->cursorNext(this); + bv->finishChange(false); + return Inset::DISPATCHED; + + case LFUN_HOME: + if (!selection.mark()) + bv->beforeChange(this); + update(bv); + cursorHome(bv); + bv->finishChange(false); + return Inset::DISPATCHED; + + case LFUN_END: + if (!selection.mark()) + bv->beforeChange(this); + update(bv); + cursorEnd(bv); + bv->finishChange(false); + return Inset::DISPATCHED; + + case LFUN_BREAKLINE: + bv->beforeChange(this); + insertChar(bv, Paragraph::META_NEWLINE); + update(bv, true); + setCursor(bv, cursor.par(), cursor.pos()); + bv->moveCursorUpdate(false); + return Inset::DISPATCHED; + + case LFUN_PROTECTEDSPACE: + if (cursor.par()->layout()->free_spacing) { + insertChar(bv, ' '); + update(bv); + } else { + specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR); + } + bv->moveCursorUpdate(false); + return Inset::DISPATCHED; + + case LFUN_HYPHENATION: + specialChar(this, bv, InsetSpecialChar::HYPHENATION); + return Inset::DISPATCHED; + + case LFUN_LIGATURE_BREAK: + specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK); + return Inset::DISPATCHED; + + case LFUN_LDOTS: + specialChar(this, bv, InsetSpecialChar::LDOTS); + return Inset::DISPATCHED; + + case LFUN_HFILL: + bv->hideCursor(); + update(bv, false); + insertChar(bv, Paragraph::META_HFILL); + update(bv); + return Inset::DISPATCHED; + + case LFUN_END_OF_SENTENCE: + specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE); + return Inset::DISPATCHED; + + case LFUN_MENU_SEPARATOR: + specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR); + return Inset::DISPATCHED; + + case LFUN_MARK_OFF: + bv->beforeChange(this); + update(bv, false); + selection.cursor = cursor; + cmd.message(N_("Mark off")); + return Inset::DISPATCHED; + + case LFUN_MARK_ON: + bv->beforeChange(this); + selection.mark(true); + update(bv, false); + selection.cursor = cursor; + cmd.message(N_("Mark on")); + return Inset::DISPATCHED; + + case LFUN_SETMARK: + bv->beforeChange(this); + if (selection.mark()) { + update(bv); + cmd.message(N_("Mark removed")); + } else { + selection.mark(true); + update(bv); + cmd.message(N_("Mark set")); + } + selection.cursor = cursor; + return Inset::DISPATCHED; + + case LFUN_UPCASE_WORD: + update(bv, false); + changeCase(bv, LyXText::text_uppercase); + if (inset_owner) + bv->updateInset(inset_owner, true); + update(bv); + return Inset::DISPATCHED; + + case LFUN_LOWCASE_WORD: + update(bv, false); + changeCase(bv, LyXText::text_lowercase); + if (inset_owner) + bv->updateInset(inset_owner, true); + update(bv); + return Inset::DISPATCHED; + + case LFUN_CAPITALIZE_WORD: + update(bv, false); + changeCase(bv, LyXText::text_capitalization); + if (inset_owner) + bv->updateInset(inset_owner, true); + update(bv); + return Inset::DISPATCHED; + + case LFUN_TRANSPOSE_CHARS: + update(bv, false); + transposeChars(*bv); + if (inset_owner) + bv->updateInset(inset_owner, true); + update(bv); + return Inset::DISPATCHED; + + case LFUN_BEGINNINGBUFSEL: + if (inset_owner) + return Inset::UNDISPATCHED; + update(bv, false); + cursorTop(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_ENDBUFSEL: + if (inset_owner) + return Inset::UNDISPATCHED; + update(bv, false); + cursorBottom(bv); + bv->finishChange(true); + return Inset::DISPATCHED; + + case LFUN_GETXY: + cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y())); + return Inset::DISPATCHED; + + case LFUN_SETXY: { + int x = 0; + int y = 0; + if (::sscanf(cmd.argument.c_str(), " %d %d", &x, &y) != 2) + lyxerr << "SETXY: Could not parse coordinates in '" + << cmd.argument << std::endl; + setCursorFromCoordinates(bv, x, y); + return Inset::DISPATCHED; + } + + case LFUN_GETFONT: + if (current_font.shape() == LyXFont::ITALIC_SHAPE) + cmd.message("E"); + else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE) + cmd.message("N"); + else + cmd.message("0"); + return Inset::DISPATCHED; + + case LFUN_GETLAYOUT: + cmd.message(tostr(cursor.par()->layout())); + return Inset::DISPATCHED; + + case LFUN_SELFINSERT: { + if (cmd.argument.empty()) + return Inset::DISPATCHED; + + // 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). + + if (lyxrc.auto_region_delete) { + if (selection.set()) { + cutSelection(bv, false, false); + update(bv); + } + bv->workarea().haveSelection(false); + } + + bv->beforeChange(this); + LyXFont const old_font(real_current_font); + + string::const_iterator cit = cmd.argument.begin(); + string::const_iterator end = cmd.argument.end(); + for (; cit != end; ++cit) + bv->owner()->getIntl().getTransManager(). + TranslateAndInsert(*cit, this); + + update(bv); + selection.cursor = cursor; + bv->moveCursorUpdate(false); + + // real_current_font.number can change so we need to + // update the minibuffer + if (old_font != real_current_font) + bv->owner()->view_state_changed(); + return Inset::DISPATCHED; + } + + default: + return Inset::UNDISPATCHED; + } + + // shut up compiler + return Inset::UNDISPATCHED; +}