From e07f7bcc50358fe9b7d68955de145b7249248c7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Fri, 23 Feb 2001 16:10:03 +0000 Subject: [PATCH] This moves all LyXText related LyXFuncs to BufferView::Dispatch so that they can also be called from inside the InsetText::LocalDispatch. Some small update and repaint fixes for InsetText. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1610 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 5 + src/BufferView.h | 3 + src/BufferView_pimpl.C | 1674 +++++++++++++++++++++++++++++++- src/BufferView_pimpl.h | 8 + src/ChangeLog | 15 + src/insets/ChangeLog | 19 + src/insets/inset.C | 2 +- src/insets/insetcollapsable.C | 2 +- src/insets/insetcollapsable.h | 3 +- src/insets/insettabular.C | 3 +- src/insets/insettabular.h | 3 +- src/insets/insettext.C | 20 +- src/insets/insettext.h | 2 +- src/insets/lyxinset.h | 3 +- src/lyxfunc.C | 1705 ++------------------------------- src/lyxfunc.h | 7 +- src/mathed/ChangeLog | 7 + src/mathed/formula.C | 3 +- src/mathed/formula.h | 2 +- src/mathed/formulamacro.C | 2 +- src/mathed/formulamacro.h | 2 +- 21 files changed, 1829 insertions(+), 1661 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 0eca845aeb..12ac9b7e02 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -291,3 +291,8 @@ BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1, return static_cast (static_cast(uc1) | static_cast(uc2)); } + +bool BufferView::Dispatch(kb_action action, string const & argument) +{ + return pimpl_->Dispatch(action, argument); +} diff --git a/src/BufferView.h b/src/BufferView.h index 3f20c3a089..611e0b546c 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -18,6 +18,7 @@ #include FORMS_H_LOCATION #include "undo.h" +#include "commandtags.h" #include class LyXView; @@ -249,6 +250,8 @@ public: void pasteClipboard(bool asPara); /// void stuffClipboard(string const &) const; + /// + bool Dispatch(kb_action action, string const & argument); private: struct Pimpl; /// diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 6bbd7838f3..9ee0f3a88a 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -20,13 +20,44 @@ #include "bufferview_funcs.h" #include "TextCache.h" #include "bufferlist.h" -#include "insets/insetbib.h" -#include "insets/insettext.h" #include "lyx_gui_misc.h" #include "lyxrc.h" #include "intl.h" #include "support/LAssert.h" #include "frontends/Dialogs.h" +#include "insets/insetbib.h" +#include "insets/insettext.h" +/// added for Dispatch functions +#include "lyx_cb.h" +#include "filedlg.h" +#include "lyx_main.h" +#include "FloatList.h" +#include "support/filetools.h" +#include "support/lyxfunctional.h" +#include "insets/inseturl.h" +#include "insets/insetlatexaccent.h" +#include "insets/insettoc.h" +#include "insets/insetref.h" +#include "insets/insetparent.h" +#include "insets/insetindex.h" +#include "insets/insetinclude.h" +#include "insets/insetcite.h" +#include "insets/insetert.h" +#include "insets/insetexternal.h" +#include "insets/insetgraphics.h" +#include "insets/insetfoot.h" +#include "insets/insetmarginal.h" +#include "insets/insetminipage.h" +#include "insets/insetfloat.h" +#include "insets/insetlist.h" +#include "insets/insettabular.h" +#include "insets/insettheorem.h" +#include "insets/insetcaption.h" +#include "mathed/formulamacro.h" +extern LyXTextClass::size_type current_layout; +extern void math_insert_symbol(BufferView *, string const &); +extern bool math_insert_greek(BufferView *, char); +extern int greek_kb_flag; #ifdef SIGC_CXX_NAMESPACES using SigC::slot; @@ -242,7 +273,7 @@ int BufferView::Pimpl::resizeCurrentBuffer() LyXParagraph * par = 0; LyXParagraph * selstartpar = 0; LyXParagraph * selendpar = 0; - UpdatableInset * the_locking_inset; + UpdatableInset * the_locking_inset = 0; int pos = 0; int selstartpos = 0; @@ -1340,3 +1371,1640 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const { workarea_->putClipboard(stuff); } + + +/* + * Dispatch functions for actions which can be valid for BufferView->text + * and/or InsetText->text!!! + */ +static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); } + +inline +void BufferView::Pimpl::moveCursorUpdate(bool selecting) +{ + if (selecting || TEXT(bv_)->mark_set) { + TEXT(bv_)->SetSelection(bv_); + if (TEXT(bv_)->bv_owner) + bv_->toggleToggle(); + } + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + showCursor(); + + /* ---> Everytime the cursor is moved, show the current font state. */ + // should this too me moved out of this func? + //owner->showState(); + bv_->setState(); +} + + +Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code) +{ + LyXCursor cursor = TEXT(bv_)->cursor; + Buffer::inset_iterator it = + find_if(Buffer::inset_iterator( + cursor.par(), cursor.pos()), + buffer_->inset_iterator_end(), + compare_memfun(&Inset::LyxCode, code) + ); + return it != buffer_->inset_iterator_end() ? (*it) : 0; +} + + +void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) +{ + string filename = filen; + + if (filename.empty()) { + // Launch a file browser + string initpath = lyxrc.document_path; + LyXFileDlg fileDlg; + + if (available()) { + string const trypath = owner_->buffer()->filepath; + // If directory is writeable, use this as default. + if (IsDirWriteable(trypath) == 1) + initpath = trypath; + } + + // launches dialog + ProhibitInput(bv_); + fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); + fileDlg.SetButton(1, _("Examples"), + AddPath(system_lyxdir, "examples")); + filename = fileDlg.Select(_("Select Document to Insert"), + initpath, "*.lyx"); + AllowInput(bv_); + + // check selected filename + if (filename.empty()) { + owner_->getMiniBuffer()->Set(_("Canceled.")); + return; + } + } + + // get absolute path of file and make sure the filename ends + // with .lyx + filename = MakeAbsPath(filename); + if (!IsLyXFilename(filename)) + filename += ".lyx"; + + // Inserts document + owner_->getMiniBuffer()->Set(_("Inserting document"), + MakeDisplayPath(filename), "..."); + bool const res = bv_->insertLyXFile(filename); + if (res) { + owner_->getMiniBuffer()->Set(_("Document"), + MakeDisplayPath(filename), + _("inserted.")); + } else { + owner_->getMiniBuffer()->Set(_("Could not insert document"), + MakeDisplayPath(filename)); + } +} + + +bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) +{ + switch (action) { + // --- Misc ------------------------------------------- + case LFUN_APPENDIX: + if (available()) { + TEXT(bv_)->toggleAppendix(bv_); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + break; + + case LFUN_TOC_INSERT: + case LFUN_LOA_INSERT: + case LFUN_LOF_INSERT: + case LFUN_LOT_INSERT: + { + InsetCommandParams p; + + if (action == LFUN_TOC_INSERT ) + p.setCmdName( "tableofcontents" ); + else if (action == LFUN_LOA_INSERT ) + p.setCmdName( "listofalgorithms" ); + else if (action == LFUN_LOF_INSERT ) + p.setCmdName( "listoffigures" ); + else + p.setCmdName( "listoftables" ); + + Inset * inset = new InsetTOC( p ); + if (!bv_->insertInset( inset, "Standard", true ) ) + delete inset; + break; + } + + case LFUN_TABULAR_FEATURE: + case LFUN_SCROLL_INSET: + // this is not handled here as this funktion is only aktive + // if we have a locking_inset and that one is (or contains) + // a tabular-inset + break; + + case LFUN_INSET_GRAPHICS: + { + Inset * new_inset = new InsetGraphics; + if (!bv_->insertInset(new_inset)) { + delete new_inset; + } else { + // this is need because you don't use a inset->Edit() + bv_->updateInset(new_inset, true); + new_inset->Edit(bv_, 0, 0, 0); + } + break; + } + + case LFUN_PASTE: + bv_->paste(); + setState(); + break; + + case LFUN_PASTESELECTION: + { + bool asPara = false; + if (argument == "paragraph") asPara = true; + pasteClipboard(asPara); + } + break; + + case LFUN_CUT: + bv_->cut(); + break; + + case LFUN_COPY: + bv_->copy(); + break; + + case LFUN_LAYOUT_COPY: + bv_->copyEnvironment(); + break; + + case LFUN_LAYOUT_PASTE: + bv_->pasteEnvironment(); + setState(); + break; + + case LFUN_GOTOERROR: + bv_->gotoInset(Inset::ERROR_CODE, false); + break; + + case LFUN_GOTONOTE: + bv_->gotoInset(Inset::IGNORE_CODE, false); + break; + + case LFUN_REFERENCE_GOTO: + { + vector tmp; + tmp.push_back(Inset::LABEL_CODE); + tmp.push_back(Inset::REF_CODE); + bv_->gotoInset(tmp, true); + break; + } + + case LFUN_HYPHENATION: + bv_->hyphenationPoint(); + break; + + case LFUN_LDOTS: + bv_->ldots(); + break; + + case LFUN_END_OF_SENTENCE: + bv_->endOfSentenceDot(); + break; + + case LFUN_MENU_SEPARATOR: + bv_->menuSeparator(); + break; + + case LFUN_HFILL: + bv_->hfill(); + break; + + case LFUN_DEPTH: + changeDepth(bv_, TEXT(bv_), 0); + break; + + case LFUN_DEPTH_MIN: + changeDepth(bv_, TEXT(bv_), -1); + break; + + case LFUN_DEPTH_PLUS: + changeDepth(bv_, TEXT(bv_), 1); + break; + + case LFUN_FREE: + Free(bv_); + setState(); + owner_->showState(); + break; + + case LFUN_TEX: + Tex(bv_); + setState(); + owner_->showState(); + break; + + case LFUN_FILE_INSERT: + { + MenuInsertLyXFile(argument); + } + break; + + case LFUN_FILE_INSERT_ASCII: + { + bool asPara = (argument == "paragraph"); + InsertAsciiFile(bv_, string(), asPara); + } + break; + + case LFUN_LAYOUT: + { + lyxerr.debug() << "LFUN_LAYOUT: (arg) " + << argument << endl; + + // Derive layout number from given argument (string) + // and current buffer's textclass (number). */ + LyXTextClassList::ClassList::size_type tclass = + buffer_->params.textclass; + pair layout = + textclasslist.NumberOfLayout(tclass, argument); + + // If the entry is obsolete, use the new one instead. + if (layout.first) { + string obs = textclasslist.Style(tclass,layout.second) + .obsoleted_by(); + if (!obs.empty()) + layout = + textclasslist.NumberOfLayout(tclass, obs); + } + + // see if we found the layout number: + if (!layout.first) { + owner_->getLyXFunc()->setErrorMessage( + string(N_("Layout ")) + argument + + N_(" not known")); + break; + } + + if (current_layout != layout.second) { + hideCursor(); + current_layout = layout.second; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->SetLayout(bv_, layout.second); + owner_->setLayout(layout.second); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + setState(); + } + } + break; + + case LFUN_LANGUAGE: + Lang(bv_, argument); + setState(); + owner_->showState(); + break; + + case LFUN_EMPH: + Emph(bv_); + owner_->showState(); + break; + + case LFUN_BOLD: + Bold(bv_); + owner_->showState(); + break; + + case LFUN_NOUN: + Noun(bv_); + owner_->showState(); + break; + + case LFUN_CODE: + Code(bv_); + owner_->showState(); + break; + + case LFUN_SANS: + Sans(bv_); + owner_->showState(); + break; + + case LFUN_ROMAN: + Roman(bv_); + owner_->showState(); + break; + + case LFUN_DEFAULT: + StyleReset(bv_); + owner_->showState(); + break; + + case LFUN_UNDERLINE: + Underline(bv_); + owner_->showState(); + break; + + case LFUN_FONT_SIZE: + FontSize(bv_, argument); + owner_->showState(); + break; + + case LFUN_FONT_STATE: + owner_->getLyXFunc()->setMessage(CurrentState(bv_)); + break; + + case LFUN_UPCASE_WORD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase); + if (TEXT(bv_)->inset_owner) + bv_->updateInset(TEXT(bv_)->inset_owner, true); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + break; + + case LFUN_LOWCASE_WORD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase); + if (TEXT(bv_)->inset_owner) + bv_->updateInset(TEXT(bv_)->inset_owner, true); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + break; + + case LFUN_CAPITALIZE_WORD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->ChangeWordCase(bv_, + LyXText::text_capitalization); + if (TEXT(bv_)->inset_owner) + bv_->updateInset(TEXT(bv_)->inset_owner, true); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + break; + + case LFUN_INSERT_LABEL: + MenuInsertLabel(bv_, argument); + break; + + case LFUN_REF_INSERT: + if (argument.empty()) { + InsetCommandParams p("ref"); + owner_->getDialogs()->createRef(p.getAsString()); + } else { + InsetCommandParams p; + p.setFromString(argument); + + InsetRef * inset = new InsetRef(p, *buffer_); + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset(inset, true); + } + break; + + case LFUN_BOOKMARK_SAVE: + savePosition(strToUnsignedInt(argument)); + break; + + case LFUN_BOOKMARK_GOTO: + restorePosition(strToUnsignedInt(argument)); + break; + + case LFUN_REF_GOTO: + { + string label(argument); + if (label.empty()) { + InsetRef * inset = + static_cast(getInsetByCode(Inset::REF_CODE)); + if (inset) { + label = inset->getContents(); + savePosition(0); + } + } + + if (!label.empty()) { + //bv_->savePosition(0); + if (!bv_->gotoLabel(label)) + WriteAlert(_("Error"), + _("Couldn't find this label"), + _("in current document.")); + } + } + break; + + // --- Cursor Movements ----------------------------- + case LFUN_RIGHT: + { + bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params); + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + if (is_rtl) + TEXT(bv_)->CursorLeft(bv_, false); + if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() + && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) + == LyXParagraph::META_INSET + && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) + && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){ + Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()); + owner_->getLyXFunc()->setMessage(tmpinset->EditMessage()); + int y = 0; + if (is_rtl) { + LyXFont font = + TEXT(bv_)->GetFont(buffer_, + TEXT(bv_)->cursor.par(), + TEXT(bv_)->cursor.pos()); + y = tmpinset->descent(bv_,font); + } + tmpinset->Edit(bv_, 0, y, 0); + break; + } + if (!is_rtl) + TEXT(bv_)->CursorRight(bv_, false); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + } + break; + + case LFUN_LEFT: + { + // This is soooo ugly. Isn`t it possible to make + // it simpler? (Lgb) + bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params); + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + LyXCursor cur = TEXT(bv_)->cursor; + if (!is_rtl) + TEXT(bv_)->CursorLeft(bv_, false); + if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved! + TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() && + (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) == + LyXParagraph::META_INSET) && + TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) && + (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() + == Inset::HIGHLY_EDITABLE)) + { + Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()); + owner_->getLyXFunc()->setMessage(tmpinset->EditMessage()); + LyXFont font = TEXT(bv_)->GetFont(buffer_, + TEXT(bv_)->cursor.par(), + TEXT(bv_)->cursor.pos()); + int y = is_rtl ? 0 + : tmpinset->descent(bv_,font); + tmpinset->Edit(bv_, + tmpinset->x() + + tmpinset->width(bv_,font), + y, 0); + break; + } + if (is_rtl) + TEXT(bv_)->CursorRight(bv_, false); + + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + } + break; + + case LFUN_UP: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + TEXT(bv_)->CursorUp(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_DOWN: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + TEXT(bv_)->CursorDown(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_UP_PARAGRAPH: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + TEXT(bv_)->CursorUpParagraph(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_DOWN_PARAGRAPH: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + TEXT(bv_)->CursorDownParagraph(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_PRIOR: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + cursorPrevious(TEXT(bv_)); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_NEXT: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::UPDATE); + cursorNext(TEXT(bv_)); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_HOME: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorHome(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_END: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorEnd(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_SHIFT_TAB: + case LFUN_TAB: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorTab(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_WORDRIGHT: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorLeftOneWord(bv_); + else + TEXT(bv_)->CursorRightOneWord(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_WORDLEFT: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorRightOneWord(bv_); + else + TEXT(bv_)->CursorLeftOneWord(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_BEGINNINGBUF: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorTop(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + case LFUN_ENDBUF: + if (!TEXT(bv_)->mark_set) + beforeChange(TEXT(bv_)); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorBottom(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(false); + owner_->showState(); + break; + + + /* cursor selection ---------------------------- */ + case LFUN_RIGHTSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorLeft(bv_); + else + TEXT(bv_)->CursorRight(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_LEFTSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorRight(bv_); + else + TEXT(bv_)->CursorLeft(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_UPSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorUp(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_DOWNSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorDown(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_UP_PARAGRAPHSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorUpParagraph(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_DOWN_PARAGRAPHSEL: + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorDownParagraph(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_PRIORSEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + cursorPrevious(TEXT(bv_)); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_NEXTSEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + cursorNext(TEXT(bv_)); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_HOMESEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorHome(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_ENDSEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorEnd(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_WORDRIGHTSEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorLeftOneWord(bv_); + else + TEXT(bv_)->CursorRightOneWord(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_WORDLEFTSEL: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params)) + TEXT(bv_)->CursorRightOneWord(bv_); + else + TEXT(bv_)->CursorLeftOneWord(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_BEGINNINGBUFSEL: + if (TEXT(bv_)->inset_owner) + break; + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorTop(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + case LFUN_ENDBUFSEL: + if (TEXT(bv_)->inset_owner) + break; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->CursorBottom(bv_); + TEXT(bv_)->FinishUndo(); + moveCursorUpdate(true); + owner_->showState(); + break; + + // --- text changing commands ------------------------ + case LFUN_BREAKLINE: + beforeChange(TEXT(bv_)); + TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + moveCursorUpdate(false); + break; + + case LFUN_PROTECTEDSPACE: + { + LyXLayout const & style = + textclasslist.Style(buffer_->params.textclass, + TEXT(bv_)->cursor.par()->GetLayout()); + + if (style.free_spacing) { + TEXT(bv_)->InsertChar(bv_, ' '); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } else { + bv_->protectedBlank(TEXT(bv_)); + } + moveCursorUpdate(false); + } + break; + + case LFUN_SETMARK: + if (TEXT(bv_)->mark_set) { + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + owner_->getLyXFunc()->setMessage(N_("Mark removed")); + } else { + beforeChange(TEXT(bv_)); + TEXT(bv_)->mark_set = 1; + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + owner_->getLyXFunc()->setMessage(N_("Mark set")); + } + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + break; + + case LFUN_DELETE: + if (!TEXT(bv_)->selection) { + TEXT(bv_)->Delete(bv_); + TEXT(bv_)->sel_cursor = + TEXT(bv_)->cursor; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + // It is possible to make it a lot faster still + // just comment out the line below... + showCursor(); + } else { + bv_->cut(); + } + moveCursorUpdate(false); + owner_->showState(); + setState(); + break; + + case LFUN_DELETE_SKIP: + { + // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP. + + LyXCursor cursor = TEXT(bv_)->cursor; + + if (!TEXT(bv_)->selection) { + if (cursor.pos() == cursor.par()->Last()) { + TEXT(bv_)->CursorRight(bv_); + cursor = TEXT(bv_)->cursor; + if (cursor.pos() == 0 + && !(cursor.par()->added_space_top + == VSpace (VSpace::NONE))) { + TEXT(bv_)->SetParagraph + (bv_, + cursor.par()->line_top, + cursor.par()->line_bottom, + cursor.par()->pagebreak_top, + cursor.par()->pagebreak_bottom, + VSpace(VSpace::NONE), + cursor.par()->added_space_bottom, + cursor.par()->align, + cursor.par()->labelwidthstring, 0); + TEXT(bv_)->CursorLeft(bv_); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } else { + TEXT(bv_)->CursorLeft(bv_); + TEXT(bv_)->Delete(bv_); + TEXT(bv_)->sel_cursor = + TEXT(bv_)->cursor; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } else { + TEXT(bv_)->Delete(bv_); + TEXT(bv_)->sel_cursor = + TEXT(bv_)->cursor; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } else { + bv_->cut(); + } + } + break; + + /* -------> Delete word forward. */ + case LFUN_DELETE_WORD_FORWARD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->DeleteWordForward(bv_); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + moveCursorUpdate(false); + owner_->showState(); + break; + + /* -------> Delete word backward. */ + case LFUN_DELETE_WORD_BACKWARD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->DeleteWordBackward(bv_); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + moveCursorUpdate(false); + owner_->showState(); + break; + + /* -------> Kill to end of line. */ + case LFUN_DELETE_LINE_FORWARD: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->DeleteLineForward(bv_); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + moveCursorUpdate(false); + break; + + /* -------> Set mark off. */ + case LFUN_MARK_OFF: + beforeChange(TEXT(bv_)); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + owner_->getLyXFunc()->setMessage(N_("Mark off")); + break; + + /* -------> Set mark on. */ + case LFUN_MARK_ON: + beforeChange(TEXT(bv_)); + TEXT(bv_)->mark_set = 1; + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + owner_->getLyXFunc()->setMessage(N_("Mark on")); + break; + + case LFUN_BACKSPACE: + { + if (!TEXT(bv_)->selection) { + if (owner_->getIntl()->getTrans().backspace()) { + TEXT(bv_)->Backspace(bv_); + TEXT(bv_)->sel_cursor = + TEXT(bv_)->cursor; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + // It is possible to make it a lot faster still + // just comment out the line below... + showCursor(); + } + } else { + bv_->cut(); + } + owner_->showState(); + setState(); + } + break; + + case LFUN_BACKSPACE_SKIP: + { + // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP. + + LyXCursor cursor = TEXT(bv_)->cursor; + + if (!TEXT(bv_)->selection) { + if (cursor.pos() == 0 + && !(cursor.par()->added_space_top + == VSpace (VSpace::NONE))) { + TEXT(bv_)->SetParagraph + (bv_, + cursor.par()->line_top, + cursor.par()->line_bottom, + cursor.par()->pagebreak_top, + cursor.par()->pagebreak_bottom, + VSpace(VSpace::NONE), cursor.par()->added_space_bottom, + cursor.par()->align, + cursor.par()->labelwidthstring, 0); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } else { + TEXT(bv_)->Backspace(bv_); + TEXT(bv_)->sel_cursor + = cursor; + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } else + bv_->cut(); + } + break; + + case LFUN_BREAKPARAGRAPH: + { + beforeChange(TEXT(bv_)); + TEXT(bv_)->BreakParagraph(bv_, 0); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + setState(); + owner_->showState(); + break; + } + + case LFUN_BREAKPARAGRAPHKEEPLAYOUT: + { + beforeChange(TEXT(bv_)); + TEXT(bv_)->BreakParagraph(bv_, 1); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + setState(); + owner_->showState(); + break; + } + + case LFUN_BREAKPARAGRAPH_SKIP: + { + // When at the beginning of a paragraph, remove + // indentation and add a "defskip" at the top. + // Otherwise, do the same as LFUN_BREAKPARAGRAPH. + + LyXCursor cursor = TEXT(bv_)->cursor; + + beforeChange(TEXT(bv_)); + if (cursor.pos() == 0) { + if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) { + TEXT(bv_)->SetParagraph + (bv_, + cursor.par()->line_top, + cursor.par()->line_bottom, + cursor.par()->pagebreak_top, + cursor.par()->pagebreak_bottom, + VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom, + cursor.par()->align, + cursor.par()->labelwidthstring, 1); + //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } + else { + TEXT(bv_)->BreakParagraph(bv_, 0); + //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + TEXT(bv_)->sel_cursor = cursor; + setState(); + owner_->showState(); + } + break; + + case LFUN_PARAGRAPH_SPACING: + { + LyXParagraph * par = TEXT(bv_)->cursor.par(); + Spacing::Space cur_spacing = par->spacing.getSpace(); + float cur_value = 1.0; + if (cur_spacing == Spacing::Other) { + cur_value = par->spacing.getValue(); + } + + istringstream istr(argument.c_str()); + + string tmp; + istr >> tmp; + Spacing::Space new_spacing = cur_spacing; + float new_value = cur_value; + if (tmp.empty()) { + lyxerr << "Missing argument to `paragraph-spacing'" + << endl; + } else if (tmp == "single") { + new_spacing = Spacing::Single; + } else if (tmp == "onehalf") { + new_spacing = Spacing::Onehalf; + } else if (tmp == "double") { + new_spacing = Spacing::Double; + } else if (tmp == "other") { + new_spacing = Spacing::Other; + float tmpval = 0.0; + istr >> tmpval; + lyxerr << "new_value = " << tmpval << endl; + if (tmpval != 0.0) + new_value = tmpval; + } else if (tmp == "default") { + new_spacing = Spacing::Default; + } else { + lyxerr << _("Unknown spacing argument: ") + << argument << endl; + } + if (cur_spacing != new_spacing || cur_value != new_value) { + par->spacing.set(new_spacing, new_value); + TEXT(bv_)->RedoParagraph(bv_); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } + break; + + case LFUN_QUOTE: + beforeChange(TEXT(bv_)); + TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + moveCursorUpdate(false); + break; + + case LFUN_HTMLURL: + case LFUN_URL: + { + InsetCommandParams p; + if (action == LFUN_HTMLURL) + p.setCmdName("htmlurl"); + else + p.setCmdName("url"); + owner_->getDialogs()->createUrl( p.getAsString() ); + } + break; + + case LFUN_INSERT_URL: + { + InsetCommandParams p; + p.setFromString( argument ); + + InsetUrl * inset = new InsetUrl( p ); + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset( inset, true ); + } + break; + + case LFUN_INSET_TEXT: + { + InsetText * new_inset = new InsetText; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_ERT: + { + InsetERT * new_inset = new InsetERT; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_EXTERNAL: + { + InsetExternal * new_inset = new InsetExternal; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_FOOTNOTE: + { + InsetFoot * new_inset = new InsetFoot; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_MARGINAL: + { + InsetMarginal * new_inset = new InsetMarginal; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_MINIPAGE: + { + InsetMinipage * new_inset = new InsetMinipage; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_FLOAT: + { + // check if the float type exist + if (floatList.typeExist(argument)) { + InsetFloat * new_inset = new InsetFloat(argument); + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } else { + lyxerr << "Non-existant float type: " + << argument << endl; + } + + } + break; + + case LFUN_INSET_LIST: + { + InsetList * new_inset = new InsetList; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_THEOREM: + { + InsetTheorem * new_inset = new InsetTheorem; + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + break; + + case LFUN_INSET_CAPTION: + { + // Do we have a locking inset... + if (bv_->theLockingInset()) { + lyxerr << "Locking inset code: " + << static_cast(bv_->theLockingInset()->LyxCode()); + InsetCaption * new_inset = new InsetCaption; + new_inset->setOwner(bv_->theLockingInset()); + new_inset->SetAutoBreakRows(true); + new_inset->SetDrawFrame(0, InsetText::LOCKED); + new_inset->SetFrameColor(0, LColor::footnoteframe); + if (bv_->insertInset(new_inset)) + new_inset->Edit(bv_, 0, 0, 0); + else + delete new_inset; + } + } + break; + + case LFUN_INSET_TABULAR: + { + int r = 2, c = 2; + if (!argument.empty()) + ::sscanf(argument.c_str(),"%d%d", &r, &c); + InsetTabular * new_inset = + new InsetTabular(*buffer_, r, c); + bool rtl = + TEXT(bv_)->real_current_font.isRightToLeft(); + if (!bv_->open_new_inset(new_inset, rtl)) + delete new_inset; + } + break; + + // --- lyxserver commands ---------------------------- + + case LFUN_CHARATCURSOR: + { + LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos(); + if (pos < TEXT(bv_)->cursor.par()->size()) + owner_->getLyXFunc()->setMessage( + tostr(TEXT(bv_)->cursor.par()->GetChar(pos))); + else + owner_->getLyXFunc()->setMessage("EOF"); + } + break; + + case LFUN_GETXY: + owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x()) + + ' ' + + tostr(TEXT(bv_)->cursor.y())); + break; + + case LFUN_SETXY: + { + int x; + int y; + ::sscanf(argument.c_str(), " %d %d", &x, &y); + TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y); + } + break; + + case LFUN_GETLAYOUT: + owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout)); + break; + + case LFUN_GETFONT: + { + LyXFont & font = TEXT(bv_)->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; + + case LFUN_GETLATEX: + { + LyXFont & font = TEXT(bv_)->current_font; + if (font.latex() == LyXFont::ON) + owner_->getLyXFunc()->setMessage("L"); + else + owner_->getLyXFunc()->setMessage("0"); + } + break; + + // --- accented characters --------------------------- + + case LFUN_UMLAUT: + case LFUN_CIRCUMFLEX: + case LFUN_GRAVE: + case LFUN_ACUTE: + case LFUN_TILDE: + case LFUN_CEDILLA: + case LFUN_MACRON: + case LFUN_DOT: + case LFUN_UNDERDOT: + case LFUN_UNDERBAR: + case LFUN_CARON: + case LFUN_SPECIAL_CARON: + case LFUN_BREVE: + case LFUN_TIE: + case LFUN_HUNG_UMLAUT: + case LFUN_CIRCLE: + case LFUN_OGONEK: + owner_->getLyXFunc()->handleKeyFunc(action); + break; + + // --- insert characters ---------------------------------------- + + case LFUN_MATH_DELIM: + case LFUN_INSERT_MATRIX: + { + if (available()) { + if (bv_->open_new_inset(new InsetFormula(false))) + { + bv_->theLockingInset() + ->LocalDispatch(bv_, action, argument); + } + } + } + break; + + case LFUN_INSERT_MATH: + { + math_insert_symbol(bv_, argument); + } + break; + + case LFUN_MATH_DISPLAY: + { + if (available()) + bv_->open_new_inset(new InsetFormula(true)); + break; + } + + case LFUN_MATH_MACRO: + { + if (available()) { + string s(argument); + if (s.empty()) + owner_->getLyXFunc()->setErrorMessage(N_("Missing argument")); + else { + string const s1 = token(s, ' ', 1); + int const na = s1.empty() ? 0 : lyx::atoi(s1); + bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na)); + } + } + } + break; + + case LFUN_MATH_MODE: // Open or create a math inset + { + if (available()) + bv_->open_new_inset(new InsetFormula); + owner_->getLyXFunc()->setMessage(N_("Math editor mode")); + } + break; + + case LFUN_CITATION_INSERT: + { + InsetCommandParams p; + p.setFromString( argument ); + + InsetCitation * inset = new InsetCitation( p ); + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset( inset, true ); + } + break; + + case LFUN_INSERT_BIBTEX: + { + // ale970405+lasgoutt970425 + // The argument can be up to two tokens separated + // by a space. The first one is the bibstyle. + string const db = token(argument, ' ', 0); + string bibstyle = token(argument, ' ', 1); + if (bibstyle.empty()) + bibstyle = "plain"; + + InsetCommandParams p( "BibTeX", db, bibstyle ); + InsetBibtex * inset = new InsetBibtex(p); + + if (bv_->insertInset(inset)) { + if (argument.empty()) + inset->Edit(bv_, 0, 0, 0); + } else + delete inset; + } + break; + + // BibTeX data bases + case LFUN_BIBDB_ADD: + { + InsetBibtex * inset = + static_cast(getInsetByCode(Inset::BIBTEX_CODE)); + if (inset) { + inset->addDatabase(argument); + } + } + break; + + case LFUN_BIBDB_DEL: + { + InsetBibtex * inset = + static_cast(getInsetByCode(Inset::BIBTEX_CODE)); + if (inset) { + inset->delDatabase(argument); + } + } + break; + + case LFUN_BIBTEX_STYLE: + { + InsetBibtex * inset = + static_cast(getInsetByCode(Inset::BIBTEX_CODE)); + if (inset) { + inset->setOptions(argument); + } + } + break; + + case LFUN_INDEX_CREATE: + { + InsetCommandParams p( "index" ); + + if (argument.empty()) { + // Get the word immediately preceding the cursor + LyXParagraph::size_type curpos = + TEXT(bv_)->cursor.pos() - 1; + + string curstring; + if (curpos >= 0 ) + curstring = TEXT(bv_) + ->cursor.par()->GetWord(curpos); + + p.setContents( curstring ); + } else { + p.setContents( argument ); + } + + owner_->getDialogs()->createIndex( p.getAsString() ); + } + break; + + case LFUN_INDEX_INSERT: + { + InsetCommandParams p; + p.setFromString(argument); + InsetIndex * inset = new InsetIndex(p); + + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset(inset, true); + } + break; + + case LFUN_INDEX_INSERT_LAST: + { + // Get word immediately preceding the cursor + LyXParagraph::size_type curpos = + TEXT(bv_)->cursor.pos() - 1; + // Can't do that at the beginning of a paragraph + if (curpos < 0) break; + + string const curstring(TEXT(bv_) + ->cursor.par()->GetWord(curpos)); + + InsetCommandParams p("index", curstring); + InsetIndex * inset = new InsetIndex(p); + + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset(inset, true); + } + break; + + case LFUN_INDEX_PRINT: + { + InsetCommandParams p("printindex"); + Inset * inset = new InsetPrintIndex(p); + if (!bv_->insertInset(inset, "Standard", true)) + delete inset; + } + break; + + case LFUN_PARENTINSERT: + { + lyxerr << "arg " << argument << endl; + InsetCommandParams p( "lyxparent", argument ); + Inset * inset = new InsetParent(p, *buffer_); + if (!bv_->insertInset(inset, "Standard", true)) + delete inset; + } + break; + + case LFUN_CHILD_INSERT: + { + InsetCommandParams p; + p.setFromString(argument); + + InsetInclude * inset = new InsetInclude(p, *buffer_); + if (!bv_->insertInset(inset)) + delete inset; + else + bv_->updateInset(inset, true); + } + break; + + case LFUN_INSERT_NOTE: + bv_->insertNote(); + break; + + case LFUN_SELFINSERT: + { + LyXFont const old_font(TEXT(bv_)->real_current_font); + for (string::size_type i = 0; i < argument.length(); ++i) { + TEXT(bv_)->InsertChar(bv_, argument[i]); + // This needs to be in the loop, or else we + // won't break lines correctly. (Asger) + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + moveCursorUpdate(false); + + // real_current_font.number can change so we need to + // update the minibuffer + if (old_font != TEXT(bv_)->real_current_font) + owner_->showState(); + } + break; + + case LFUN_DATE_INSERT: // jdblair: date-insert cmd + { + struct tm * now_tm; + + time_t now_time_t = time(NULL); + now_tm = localtime(&now_time_t); + setlocale(LC_TIME, ""); + string arg; + if (!argument.empty()) + arg = argument; + else + arg = lyxrc.date_insert_format; + char datetmp[32]; + int const datetmp_len = + ::strftime(datetmp, 32, arg.c_str(), now_tm); + for (int i = 0; i < datetmp_len; i++) { + TEXT(bv_)->InsertChar(bv_, datetmp[i]); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + moveCursorUpdate(false); + } + break; + + case LFUN_UNKNOWN_ACTION: + { + if (!buffer_) { + owner_->getLyXFunc()->setErrorMessage(N_("No document open")); + break; + } + + if (buffer_->isReadonly()) { + owner_->getLyXFunc()->setErrorMessage(N_("Document is read only")); + break; + } + if (!argument.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). */ + + if (lyxrc.auto_region_delete) { + if (TEXT(bv_)->selection){ + TEXT(bv_)->CutSelection(bv_, false); + update(TEXT(bv_), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + } + } + + beforeChange(TEXT(bv_)); + LyXFont const old_font(TEXT(bv_)->real_current_font); + for (string::size_type i = 0; + i < argument.length(); ++i) { + if (greek_kb_flag) { + if (!math_insert_greek(bv_, + argument[i])) + owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_)); + } else + owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_)); + } + + update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + + TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor; + moveCursorUpdate(false); + + // real_current_font.number can change so we need to + // update the minibuffer + if (old_font != TEXT(bv_)->real_current_font) + owner_->showState(); + } else { + // if we don't have an argument there was something + // strange going on so we just tell this to someone! + owner_->getLyXFunc()->setErrorMessage(N_("No argument givven")); + } + break; + } + default: + return false; + } // end of switch + + return true; +} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 58228577db..136e8209df 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -5,6 +5,7 @@ #include "BufferView.h" #include "UpdateInset.h" +#include "commandtags.h" #include "frontends/Timeout.h" #ifdef __GNUG__ @@ -118,6 +119,8 @@ struct BufferView::Pimpl : public Object { /// void center(); /// + bool Dispatch(kb_action action, string const & argument); + /// BufferView * bv_; /// LyXView * owner_; @@ -161,5 +164,10 @@ private: : filename(f), par_id(id), par_pos(pos) {} }; std::vector saved_positions; + + void moveCursorUpdate(bool selecting); + /// Get next inset of this class from current cursor position + Inset * getInsetByCode(Inset::Code code); + void MenuInsertLyXFile(string const & filen); }; #endif diff --git a/src/ChangeLog b/src/ChangeLog index 4ba8e35257..ee42d94a00 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2001-02-23 Juergen Vigna + + * lyxfunc.C (Dispatch): removed the whole part of the switch statement + which works with LyXText and putted it inside BufferView. Here now we + only call for that part the BufferView::Dispatch() function. + + * BufferView.C (Dispatch): added. + + * BufferView_pimpl.C (Dispatch): added! Here are now all dispatch + functions which needs to use a LyXText over from LyXFunc. + (MenuInsertLyXFile): added + (getInsetByCode): added + (moveCursorUpdate): added + (static TEXT): added + 2001-02-22 Juergen Vigna * BufferView_pimpl.C (update): call a status update to see if LyXText diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 99a65a6112..70387c1579 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,22 @@ +2001-02-23 Juergen Vigna + + * insettext.C (draw): some small repainting fixes. + (LocalDispatch): put the sel_cursor stuff after the insert of chars. + + * inset.C (LocalDispatch): changed action to be a kb_action (as it + should be) and not an int. + + * insettabular.C (LocalDispatch): ditto + + * insettext.C (LocalDispatch): ditto + + * insetcollapsable.C (LocalDispatch): ditto + +2001-02-22 Juergen Vigna + + * insettabular.C (LocalDispatch): return DISPATCHED if we cannot + DISPATCH it and we don't have a locking_inset. + 2001-02-21 Baruch Even * insetgraphics.[Ch]: Changed to use boost::shared_ptr diff --git a/src/insets/inset.C b/src/insets/inset.C index 7db87b30c6..95e69d2682 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -211,7 +211,7 @@ void UpdatableInset::scroll(BufferView * bv, int offset) const /// An updatable inset could handle lyx editing commands UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView * bv, - int action, string const & arg) + kb_action action, string const & arg) { if (!arg.empty() && (action==LFUN_SCROLL_INSET)) { if (arg.find('.') != arg.npos) { diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index e761262e05..e7cfe8b373 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -350,7 +350,7 @@ void InsetCollapsable::update(BufferView * bv, LyXFont const & font, UpdatableInset::RESULT -InsetCollapsable::LocalDispatch(BufferView * bv, int action, +InsetCollapsable::LocalDispatch(BufferView * bv, kb_action action, string const & arg) { UpdatableInset::RESULT result = inset->LocalDispatch(bv, action, arg); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 24a11528c0..39cbb27669 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -89,7 +89,8 @@ public: /// void InsetKeyPress(XKeyEvent *); /// - UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &); + UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, + string const &); /// int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index e3bbc85627..d31318d42b 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -714,7 +714,8 @@ void InsetTabular::InsetKeyPress(XKeyEvent * xke) } -UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, +UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, + kb_action action, string const & arg) { // We need to save the value of the_locking_inset as the call to diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 7648b2b1e9..58e77c0ec3 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -135,7 +135,8 @@ public: /// void InsetKeyPress(XKeyEvent *); /// - UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &); + UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, + string const &); /// int Latex(Buffer const *, std::ostream &, bool, bool) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index aec6572950..d450653315 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -273,7 +273,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, // no draw is necessary !!! if ((drawFrame == LOCKED) && !locked && !par->size()) { - if (!cleared && (need_update == CLEAR_FRAME)) { + if (!cleared && (need_update & CLEAR_FRAME)) { pain.rectangle(top_x + 1, baseline - insetAscent + 1, width(bv, f) - 1, insetAscent + insetDescent - 1, @@ -349,7 +349,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, if (y_offset < 0) y_offset = y; TEXT(bv)->first = first; - if (cleared || !locked || (need_update&FULL) || (need_update&INIT)) { + if (cleared) { // (need_update&FULL) || (need_update&INIT) int yf = y_offset; y = 0; while ((row != 0) && (yf < ph)) { @@ -359,6 +359,13 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, yf += row->height(); row = row->next(); } + } else if (!locked) { + if (need_update & CURSOR) { + bv->screen()->ToggleSelection(TEXT(bv), bv, true, y_offset,int(x)); + TEXT(bv)->ClearSelection(bv); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + } + bv->screen()->Update(TEXT(bv), bv, y_offset, int(x)); } else { locked = false; if (need_update & SELECTION) @@ -740,7 +747,7 @@ void InsetText::InsetKeyPress(XKeyEvent * xke) UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv, - int action, string const & arg) + kb_action action, string const & arg) { no_selection = false; UpdatableInset::RESULT @@ -778,6 +785,8 @@ InsetText::LocalDispatch(BufferView * bv, moveRightIntern(bv, false, false); dispatched = true; break; + default: + break; } the_locking_inset = 0; if (dispatched) @@ -815,7 +824,6 @@ InsetText::LocalDispatch(BufferView * bv, } } TEXT(bv)->ClearSelection(bv); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; for (string::size_type i = 0; i < arg.length(); ++i) { if (greek_kb_flag) { if (!math_insert_greek(bv, arg[i])) { @@ -828,6 +836,7 @@ InsetText::LocalDispatch(BufferView * bv, } } } + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR_PAR, true); result=DISPATCHED_NOUPDATE; break; @@ -1087,7 +1096,8 @@ InsetText::LocalDispatch(BufferView * bv, break; default: - result = UNDISPATCHED; + if (!bv->Dispatch(action, arg)) + result = UNDISPATCHED; break; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index b5c8bd4eb4..e14b164512 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -125,7 +125,7 @@ public: /// void InsetKeyPress(XKeyEvent *); /// - UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &); + UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, string const &); /// int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index ae6a873a55..a4804875bb 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -22,6 +22,7 @@ #include "gettext.h" #include "lyxfont.h" #include "lyxlex.h" +#include "commandtags.h" class BufferView; class Buffer; @@ -356,7 +357,7 @@ public: bool /*lr*/ = false) { return false; } /// An updatable inset could handle lyx editing commands - virtual RESULT LocalDispatch(BufferView *, int, string const &); + virtual RESULT LocalDispatch(BufferView *, kb_action, string const &); /// virtual bool isCursorVisible() const { return cursor_visible; } /// diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3e4ea34e7a..f6cd51de3f 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -154,6 +154,25 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting) } +void LyXFunc::handleKeyFunc(kb_action action) +{ + char c = 0; + + if (keyseq.length == -1 && keyseq.getiso() != 0) + c = keyseq.getiso(); + owner->getIntl()->getTrans() + .deadkey(c, get_accent(action).accent, TEXT(false)); + // Need to reset, in case the minibuffer calls these + // actions + keyseq.reset(); + keyseq.length = 0; + // copied verbatim from do_accent_char + owner->view()->update(TEXT(false), + BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + TEXT(false)->sel_cursor = TEXT(false)->cursor; +} + + int LyXFunc::processKeySym(KeySym keysym, unsigned int state) { string argument; @@ -708,7 +727,7 @@ string const LyXFunc::Dispatch(int ac, owner->view()->showCursor(); } break; - + case LFUN_PREFIX: { if (owner->view()->available()) { @@ -757,13 +776,6 @@ string const LyXFunc::Dispatch(int ac, owner->view()->center(); break; - case LFUN_APPENDIX: - if (owner->view()->available()) { - TEXT(false)->toggleAppendix(owner->view()); - owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); - } - break; - // --- Menus ----------------------------------------------- case LFUN_MENUNEW: MenuNew(false); @@ -858,56 +870,14 @@ string const LyXFunc::Dispatch(int ac, break; } - case LFUN_TOC_INSERT: - case LFUN_LOA_INSERT: - case LFUN_LOF_INSERT: - case LFUN_LOT_INSERT: - { - InsetCommandParams p; - - if (action == LFUN_TOC_INSERT ) - p.setCmdName( "tableofcontents" ); - else if (action == LFUN_LOA_INSERT ) - p.setCmdName( "listofalgorithms" ); - else if (action == LFUN_LOF_INSERT ) - p.setCmdName( "listoffigures" ); - else - p.setCmdName( "listoftables" ); - - Inset * inset = new InsetTOC( p ); - if (!owner->view()->insertInset( inset, "Standard", true ) ) - delete inset; - break; - } - case LFUN_DIALOG_TABULAR_INSERT: owner->getDialogs()->showTabularCreate(); break; - case LFUN_TABULAR_FEATURE: - case LFUN_SCROLL_INSET: - // this is not handled here as this funktion is only aktive - // if we have a locking_inset and that one is (or contains) - // a tabular-inset - break; - case LFUN_FIGURE: Figure(); break; - case LFUN_INSET_GRAPHICS: - { - Inset * new_inset = new InsetGraphics; - if (!owner->view()->insertInset(new_inset)) { - delete new_inset; - } else { - // this is need because you don't use a inset->Edit() - owner->view()->updateInset(new_inset, true); - new_inset->Edit(owner->view(), 0, 0, 0); - } - break; - } - case LFUN_AUTOSAVE: AutoSave(owner->view()); break; @@ -930,40 +900,6 @@ string const LyXFunc::Dispatch(int ac, } break; - case LFUN_PASTE: - owner->view()->paste(); - owner->view()->setState(); - break; - - case LFUN_PASTESELECTION: - { - bool asPara = false; - if (argument == "paragraph") asPara = true; - owner->view()->pasteClipboard(asPara); - } - break; - - case LFUN_CUT: - owner->view()->cut(); - break; - - case LFUN_COPY: - owner->view()->copy(); - break; - - case LFUN_LAYOUT_COPY: - owner->view()->copyEnvironment(); - break; - - case LFUN_LAYOUT_PASTE: - owner->view()->pasteEnvironment(); - owner->view()->setState(); - break; - - case LFUN_GOTOERROR: - owner->view()->gotoInset(Inset::ERROR_CODE, false); - break; - case LFUN_REMOVEERRORS: if (owner->view()->removeAutoInsets()) { owner->view()->redraw(); @@ -971,19 +907,6 @@ string const LyXFunc::Dispatch(int ac, } break; - case LFUN_GOTONOTE: - owner->view()->gotoInset(Inset::IGNORE_CODE, false); - break; - - case LFUN_REFERENCE_GOTO: - { - vector tmp; - tmp.push_back(Inset::LABEL_CODE); - tmp.push_back(Inset::REF_CODE); - owner->view()->gotoInset(tmp, true); - break; - } - #ifndef NEW_INSETS case LFUN_OPENSTUFF: owner->view()->openStuff(); @@ -1175,20 +1098,6 @@ string const LyXFunc::Dispatch(int ac, owner->view()->buffer(bufferlist.getBuffer(argument)); break; - - case LFUN_FILE_INSERT: - { - MenuInsertLyXFile(argument); - } - break; - - case LFUN_FILE_INSERT_ASCII: - { - bool asPara = (argument == "paragraph"); - InsertAsciiFile(owner->view(), string(), asPara); - } - break; - case LFUN_FILE_NEW: { // servercmd: argument must be :