3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "bufferparams.h"
26 #include "BufferView.h"
28 #include "coordcache.h"
29 #include "CutAndPaste.h"
31 #include "dispatchresult.h"
33 #include "funcrequest.h"
37 #include "LyXAction.h"
42 #include "paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
48 #include "frontends/Dialogs.h"
49 #include "frontends/LyXView.h"
51 #include "insets/insetcommand.h"
52 #include "insets/insetfloatlist.h"
53 #include "insets/insetnewline.h"
54 #include "insets/insetquotes.h"
55 #include "insets/insetspecialchar.h"
56 #include "insets/insettext.h"
58 #include "support/lstrings.h"
59 #include "support/lyxlib.h"
60 #include "support/convert.h"
61 #include "support/lyxtime.h"
63 #include "mathed/math_hullinset.h"
64 #include "mathed/math_macrotemplate.h"
66 #include <boost/current_function.hpp>
73 using lyx::cap::copySelection;
74 using lyx::cap::cutSelection;
75 using lyx::cap::pasteSelection;
76 using lyx::cap::replaceSelection;
78 using lyx::support::isStrUnsignedInt;
79 using lyx::support::token;
83 using std::istringstream;
86 extern string current_layout;
92 LyXFont freefont(LyXFont::ALL_IGNORE);
93 bool toggleall = false;
96 void toggleAndShow(LCursor & cur, LyXText * text,
97 LyXFont const & font, bool toggleall = true)
99 text->toggleFree(cur, font, toggleall);
101 if (font.language() != ignore_language ||
102 font.number() != LyXFont::IGNORE) {
103 Paragraph & par = cur.paragraph();
104 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
105 if (cur.boundary() !=
106 text->bidi.isBoundary(cur.buffer(), par,
108 text->real_current_font))
109 text->setCursor(cur, cur.pit(), cur.pos(),
110 false, !cur.boundary());
115 void moveCursor(LCursor & cur, bool selecting)
117 if (selecting || cur.mark())
119 if (!cur.selection())
120 cur.bv().haveSelection(false);
121 cur.bv().switchKeyMap();
125 void finishChange(LCursor & cur, bool selecting)
128 moveCursor(cur, selecting);
132 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
135 string sel = cur.selectionAsString(false);
136 //lyxerr << "selection is: '" << sel << "'" << endl;
138 // It may happen that sel is empty but there is a selection
139 replaceSelection(cur);
142 const int old_pos = cur.pos();
143 cur.insert(new MathHullInset("simple"));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument.empty())
155 cur.dispatch(FuncRequest(LFUN_INSERT_MATH,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 istringstream is(sel);
162 if (sel.find("\\newcommand") == string::npos
163 && sel.find("\\def") == string::npos)
165 MathHullInset * formula = new MathHullInset;
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == "none")
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate("simple");
175 cur.insert(new MathMacroTemplate(is));
177 cur.message(N_("Math editor mode"));
186 string const freefont2string()
189 if (font2string(freefont, toggleall, data))
196 bool LyXText::cursorPrevious(LCursor & cur)
198 pos_type cpos = cur.pos();
199 lyx::pit_type cpar = cur.pit();
201 int x = cur.x_target();
203 bool updated = setCursorFromCoordinates(cur, x, 0);
206 updated |= cursorUp(cur);
208 if (cpar == cur.pit() && cpos == cur.pos()) {
209 // we have a row which is taller than the workarea. The
210 // simplest solution is to move to the previous row instead.
211 updated |= cursorUp(cur);
214 cur.bv().updateScrollbar();
220 bool LyXText::cursorNext(LCursor & cur)
222 pos_type cpos = cur.pos();
223 lyx::pit_type cpar = cur.pit();
225 int x = cur.x_target();
226 bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
229 updated |= cursorDown(cur);
231 if (cpar == cur.pit() && cpos == cur.pos()) {
232 // we have a row which is taller than the workarea. The
233 // simplest solution is to move to the next row instead.
234 updated |= cursorDown(cur);
237 cur.bv().updateScrollbar();
245 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
247 lyx::cap::replaceSelection(cur);
248 cur.insert(new InsetSpecialChar(kind));
253 bool doInsertInset(LCursor & cur, LyXText * text,
254 FuncRequest const & cmd, bool edit, bool pastesel)
256 InsetBase * inset = createInset(&cur.bv(), cmd);
262 if (cur.selection()) {
263 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
266 text->insertInset(cur, inset);
269 inset->edit(cur, true);
271 if (gotsel && pastesel)
272 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
277 void update(LCursor & cur)
279 //we don't call update(true, false) directly to save a metrics call
280 if (cur.bv().fitCursor())
281 cur.bv().update(Update::Force);
288 void LyXText::number(LCursor & cur)
290 LyXFont font(LyXFont::ALL_IGNORE);
291 font.setNumber(LyXFont::TOGGLE);
292 toggleAndShow(cur, this, font);
296 bool LyXText::isRTL(Paragraph const & par) const
298 return par.isRightToLeftPar(bv()->buffer()->params());
302 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
304 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
306 BOOST_ASSERT(cur.text() == this);
307 BufferView * bv = &cur.bv();
308 CursorSlice oldTopSlice = cur.top();
309 bool oldBoundary = cur.boundary();
310 bool sel = cur.selection();
311 // Signals that, even if needsUpdate == false, an update of the
312 // cursor paragraph is required
313 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
314 LyXAction::SingleParUpdate);
315 // Signals that a full-screen update is required
316 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
317 LyXAction::NoUpdate) || singleParUpdate);
318 // Remember the old paragraph metric (_outer_ paragraph!)
319 Dimension olddim = cur.bottom().paragraph().dim();
321 switch (cmd.action) {
323 case LFUN_APPENDIX: {
324 Paragraph & par = cur.paragraph();
325 bool start = !par.params().startOfAppendix();
328 #warning The code below only makes sense at top level.
329 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
331 // ensure that we have only one start_of_appendix in this document
332 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
333 if (pars_[tmp].params().startOfAppendix()) {
335 pars_[tmp].params().startOfAppendix(false);
341 par.params().startOfAppendix(start);
343 // we can set the refreshing parameters now
344 updateCounters(cur.buffer());
348 case LFUN_DELETE_WORD_FORWARD:
349 cur.clearSelection();
350 deleteWordForward(cur);
351 finishChange(cur, false);
354 case LFUN_DELETE_WORD_BACKWARD:
355 cur.clearSelection();
356 deleteWordBackward(cur);
357 finishChange(cur, false);
360 case LFUN_DELETE_LINE_FORWARD:
361 cur.clearSelection();
362 deleteLineForward(cur);
363 finishChange(cur, false);
368 cur.clearSelection();
369 if (isRTL(cur.paragraph()))
370 needsUpdate = cursorLeftOneWord(cur);
372 needsUpdate = cursorRightOneWord(cur);
373 finishChange(cur, false);
378 cur.clearSelection();
379 if (isRTL(cur.paragraph()))
380 needsUpdate = cursorRightOneWord(cur);
382 needsUpdate = cursorLeftOneWord(cur);
383 finishChange(cur, false);
386 case LFUN_BEGINNINGBUF:
387 if (cur.depth() == 1) {
389 cur.clearSelection();
391 finishChange(cur, false);
397 case LFUN_BEGINNINGBUFSEL:
398 if (cur.depth() == 1) {
399 if (!cur.selection())
402 finishChange(cur, true);
409 if (cur.depth() == 1) {
411 cur.clearSelection();
413 finishChange(cur, false);
420 if (cur.depth() == 1) {
421 if (!cur.selection())
424 finishChange(cur, true);
432 //lyxerr << BOOST_CURRENT_FUNCTION
433 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
434 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
435 if (isRTL(cur.paragraph()))
436 needsUpdate = cursorLeft(cur);
438 needsUpdate = cursorRight(cur);
440 if (!needsUpdate && oldTopSlice == cur.top()
441 && cur.boundary() == oldBoundary) {
443 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
449 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
450 cur.selHandle(cmd.action == LFUN_LEFTSEL);
451 if (isRTL(cur.paragraph()))
452 needsUpdate = cursorRight(cur);
454 needsUpdate = cursorLeft(cur);
456 if (!needsUpdate && oldTopSlice == cur.top()
457 && cur.boundary() == oldBoundary) {
459 cmd = FuncRequest(LFUN_FINISHED_LEFT);
466 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
467 cur.selHandle(cmd.action == LFUN_UPSEL);
469 needsUpdate = cursorUp(cur);
470 if (!needsUpdate && oldTopSlice == cur.top()
471 && cur.boundary() == oldBoundary) {
473 cmd = FuncRequest(LFUN_FINISHED_UP);
480 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
481 cur.selHandle(cmd.action == LFUN_DOWNSEL);
482 needsUpdate = cursorDown(cur);
483 if (!needsUpdate && oldTopSlice == cur.top() &&
484 cur.boundary() == oldBoundary)
487 cmd = FuncRequest(LFUN_FINISHED_DOWN);
491 case LFUN_UP_PARAGRAPH:
493 cur.clearSelection();
494 needsUpdate = cursorUpParagraph(cur);
495 finishChange(cur, false);
498 case LFUN_UP_PARAGRAPHSEL:
499 if (!cur.selection())
501 cursorUpParagraph(cur);
502 finishChange(cur, true);
505 case LFUN_DOWN_PARAGRAPH:
507 cur.clearSelection();
508 needsUpdate = cursorDownParagraph(cur);
509 finishChange(cur, false);
512 case LFUN_DOWN_PARAGRAPHSEL:
513 if (!cur.selection())
515 cursorDownParagraph(cur);
516 finishChange(cur, true);
521 if (!cur.selection())
524 finishChange(cur, true);
529 if (!cur.selection())
532 finishChange(cur, true);
537 if (!cur.selection())
540 finishChange(cur, true);
545 if (!cur.selection())
548 finishChange(cur, true);
551 case LFUN_WORDRIGHTSEL:
552 if (!cur.selection())
554 if (isRTL(cur.paragraph()))
555 cursorLeftOneWord(cur);
557 cursorRightOneWord(cur);
558 finishChange(cur, true);
561 case LFUN_WORDLEFTSEL:
562 if (!cur.selection())
564 if (isRTL(cur.paragraph()))
565 cursorRightOneWord(cur);
567 cursorLeftOneWord(cur);
568 finishChange(cur, true);
572 selectWord(cur, lyx::WHOLE_WORD);
573 finishChange(cur, true);
580 cur.clearSelection();
581 finishChange(cur, false);
582 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
584 cmd = FuncRequest(LFUN_FINISHED_UP);
586 needsUpdate = cursorPrevious(cur);
593 cur.clearSelection();
594 finishChange(cur, false);
595 if (cur.pit() == cur.lastpit()
596 && cur.textRow().endpos() == cur.lastpos()) {
598 cmd = FuncRequest(LFUN_FINISHED_DOWN);
600 needsUpdate = cursorNext(cur);
606 cur.clearSelection();
608 finishChange(cur, false);
613 cur.clearSelection();
615 finishChange(cur, false);
618 case LFUN_BREAKLINE: {
619 // Not allowed by LaTeX (labels or empty par)
620 if (cur.pos() > cur.paragraph().beginOfBody()) {
621 lyx::cap::replaceSelection(cur);
622 cur.insert(new InsetNewline);
624 moveCursor(cur, false);
630 if (!cur.selection()) {
631 if (cur.pos() == cur.paragraph().size())
632 // Par boundary, force full-screen update
633 singleParUpdate = false;
634 needsUpdate = Delete(cur);
636 // It is possible to make it a lot faster still
637 // just comment out the line below...
639 cutSelection(cur, true, false);
640 singleParUpdate = false;
642 moveCursor(cur, false);
645 case LFUN_DELETE_SKIP:
646 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
647 if (!cur.selection()) {
648 if (cur.pos() == cur.lastpos()) {
655 cutSelection(cur, true, false);
661 if (!cur.selection()) {
662 if (bv->owner()->getIntl().getTransManager().backspace()) {
663 // Par boundary, full-screen update
665 singleParUpdate = false;
666 needsUpdate = backspace(cur);
668 // It is possible to make it a lot faster still
669 // just comment out the line below...
672 cutSelection(cur, true, false);
673 singleParUpdate = false;
678 case LFUN_BACKSPACE_SKIP:
679 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
680 if (!cur.selection()) {
684 //CursorSlice cur = cursor();
688 cutSelection(cur, true, false);
692 case LFUN_BREAKPARAGRAPH:
693 lyx::cap::replaceSelection(cur);
694 breakParagraph(cur, 0);
699 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
700 lyx::cap::replaceSelection(cur);
701 breakParagraph(cur, 1);
706 case LFUN_BREAKPARAGRAPH_SKIP: {
707 // When at the beginning of a paragraph, remove
708 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
709 lyx::cap::replaceSelection(cur);
711 cur.paragraph().params().labelWidthString(string());
713 breakParagraph(cur, 0);
719 case LFUN_PARAGRAPH_SPACING: {
720 Paragraph & par = cur.paragraph();
721 Spacing::Space cur_spacing = par.params().spacing().getSpace();
722 string cur_value = "1.0";
723 if (cur_spacing == Spacing::Other)
724 cur_value = par.params().spacing().getValueAsString();
726 istringstream is(cmd.argument);
729 Spacing::Space new_spacing = cur_spacing;
730 string new_value = cur_value;
732 lyxerr << "Missing argument to `paragraph-spacing'"
734 } else if (tmp == "single") {
735 new_spacing = Spacing::Single;
736 } else if (tmp == "onehalf") {
737 new_spacing = Spacing::Onehalf;
738 } else if (tmp == "double") {
739 new_spacing = Spacing::Double;
740 } else if (tmp == "other") {
741 new_spacing = Spacing::Other;
742 string tmpval = "0.0";
744 lyxerr << "new_value = " << tmpval << endl;
747 } else if (tmp == "default") {
748 new_spacing = Spacing::Default;
750 lyxerr << _("Unknown spacing argument: ")
751 << cmd.argument << endl;
753 if (cur_spacing != new_spacing || cur_value != new_value)
754 par.params().spacing(Spacing(new_spacing, new_value));
758 case LFUN_INSET_INSERT: {
760 InsetBase * inset = createInset(bv, cmd);
762 insertInset(cur, inset);
768 case LFUN_INSET_SETTINGS:
769 cur.inset().showInsetDialog(bv);
772 case LFUN_NEXT_INSET_TOGGLE: {
773 InsetBase * inset = cur.nextInset();
774 // this is the real function we want to invoke
775 cmd = FuncRequest(LFUN_INSET_TOGGLE);
777 // if there is an inset at cursor, see whether it
780 LCursor tmpcur = cur;
781 tmpcur.pushLeft(*inset);
782 inset->dispatch(tmpcur, cmd);
783 if (tmpcur.result().dispatched()) {
784 cur.clearSelection();
788 // if it did not work, try the underlying inset.
789 if (!cur.result().dispatched())
790 cur.inset().dispatch(cur, cmd);
794 case LFUN_SPACE_INSERT:
795 if (cur.paragraph().layout()->free_spacing)
796 insertChar(cur, ' ');
798 doInsertInset(cur, this, cmd, false, false);
801 moveCursor(cur, false);
804 case LFUN_HYPHENATION:
805 specialChar(cur, InsetSpecialChar::HYPHENATION);
808 case LFUN_LIGATURE_BREAK:
809 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
813 specialChar(cur, InsetSpecialChar::LDOTS);
816 case LFUN_END_OF_SENTENCE:
817 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
820 case LFUN_MENU_SEPARATOR:
821 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
824 case LFUN_UPCASE_WORD:
825 changeCase(cur, LyXText::text_uppercase);
828 case LFUN_LOWCASE_WORD:
829 changeCase(cur, LyXText::text_lowercase);
832 case LFUN_CAPITALIZE_WORD:
833 changeCase(cur, LyXText::text_capitalization);
836 case LFUN_TRANSPOSE_CHARS:
841 cur.message(_("Paste"));
842 lyx::cap::replaceSelection(cur);
843 if (isStrUnsignedInt(cmd.argument))
844 pasteSelection(cur, convert<unsigned int>(cmd.argument));
846 pasteSelection(cur, 0);
847 cur.clearSelection(); // bug 393
853 cutSelection(cur, true, true);
854 cur.message(_("Cut"));
859 cur.message(_("Copy"));
863 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
864 + convert<string>(cursorY(cur.top(), cur.boundary())));
870 istringstream is(cmd.argument);
873 lyxerr << "SETXY: Could not parse coordinates in '"
874 << cmd.argument << std::endl;
876 setCursorFromCoordinates(cur, x, y);
881 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
883 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
890 cur.message(cur.paragraph().layout()->name());
894 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
895 << cmd.argument << endl;
897 // This is not the good solution to the empty argument
898 // problem, but it will hopefully suffice for 1.2.0.
899 // The correct solution would be to augument the
900 // function list/array with information about what
901 // functions needs arguments and their type.
902 if (cmd.argument.empty()) {
903 cur.errorMessage(_("LyX function 'layout' needs an argument."));
907 // Derive layout number from given argument (string)
908 // and current buffer's textclass (number)
909 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
910 bool hasLayout = tclass.hasLayout(cmd.argument);
911 string layout = cmd.argument;
913 // If the entry is obsolete, use the new one instead.
915 string const & obs = tclass[layout]->obsoleted_by();
921 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
926 bool change_layout = (current_layout != layout);
928 if (!change_layout && cur.selection() &&
929 cur.selBegin().pit() != cur.selEnd().pit())
931 pit_type spit = cur.selBegin().pit();
932 pit_type epit = cur.selEnd().pit() + 1;
933 while (spit != epit) {
934 if (pars_[spit].layout()->name() != current_layout) {
935 change_layout = true;
943 current_layout = layout;
944 setLayout(cur, layout);
945 bv->owner()->setLayout(layout);
951 case LFUN_PASTESELECTION: {
952 cur.clearSelection();
953 string const clip = bv->getClipboard();
956 if (cmd.argument == "paragraph")
957 insertStringAsParagraphs(cur, clip);
959 insertStringAsLines(cur, clip);
965 lyx::cap::replaceSelection(cur);
966 Paragraph & par = cur.paragraph();
967 lyx::pos_type pos = cur.pos();
971 else if (cur.prevInset() && cur.prevInset()->isSpace())
974 c = par.getChar(pos - 1);
976 LyXLayout_ptr const & style = par.layout();
978 BufferParams const & bufparams = bv->buffer()->params();
979 if (!style->pass_thru
980 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
981 string arg = cmd.argument;
983 cur.insert(new InsetQuotes(c,
984 bufparams.quotes_language,
985 InsetQuotes::SingleQ));
987 cur.insert(new InsetQuotes(c,
988 bufparams.quotes_language,
989 InsetQuotes::DoubleQ));
993 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
997 case LFUN_DATE_INSERT:
998 if (cmd.argument.empty())
999 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
1000 lyx::formatted_time(lyx::current_time())));
1002 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
1003 lyx::formatted_time(lyx::current_time(), cmd.argument)));
1006 case LFUN_MOUSE_TRIPLE:
1007 if (cmd.button() == mouse_button::button1) {
1013 bv->haveSelection(cur.selection());
1017 case LFUN_MOUSE_DOUBLE:
1018 if (cmd.button() == mouse_button::button1) {
1019 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1021 bv->haveSelection(cur.selection());
1025 // Single-click on work area
1026 case LFUN_MOUSE_PRESS: {
1027 // Right click on a footnote flag opens float menu
1028 if (cmd.button() == mouse_button::button3) {
1029 cur.clearSelection();
1033 // Middle button press pastes if we have a selection
1034 // We do this here as if the selection was inside an inset
1035 // it could get cleared on the unlocking of the inset so
1036 // we have to check this first
1037 bool paste_internally = false;
1038 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1039 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1040 paste_internally = true;
1043 bv->mouseSetCursor(cur);
1045 // Insert primary selection with middle mouse
1046 // if there is a local selection in the current buffer,
1048 if (cmd.button() == mouse_button::button2) {
1049 if (paste_internally)
1050 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1052 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1058 case LFUN_MOUSE_MOTION: {
1059 // Only use motion with button 1
1060 //if (cmd.button() != mouse_button::button1)
1063 // ignore motions deeper nested than the real anchor
1064 LCursor & bvcur = cur.bv().cursor();
1065 if (bvcur.anchor_.hasPart(cur)) {
1066 CursorSlice old = bvcur.top();
1068 int const wh = bv->workHeight();
1069 int const y = std::max(0, std::min(wh - 1, cmd.y));
1071 setCursorFromCoordinates(cur, cmd.x, y);
1072 cur.x_target() = cmd.x;
1077 // This is to allow jumping over large insets
1078 if (cur.top() == old) {
1085 if (cur.top() == old)
1088 // don't set anchor_
1089 bvcur.setCursor(cur);
1090 bvcur.selection() = true;
1091 //lyxerr << "MOTION: " << bv->cursor() << endl;
1099 case LFUN_MOUSE_RELEASE: {
1100 if (cmd.button() == mouse_button::button2)
1104 if (cmd.button() == mouse_button::button1)
1105 bv->haveSelection(cur.selection());
1108 bv->owner()->updateMenubar();
1109 bv->owner()->updateToolbars();
1113 case LFUN_SELFINSERT: {
1114 if (cmd.argument.empty())
1117 // Automatically delete the currently selected
1118 // text and replace it with what is being
1119 // typed in now. Depends on lyxrc settings
1120 // "auto_region_delete", which defaults to
1123 if (lyxrc.auto_region_delete) {
1124 if (cur.selection())
1125 cutSelection(cur, false, false);
1126 bv->haveSelection(false);
1129 cur.clearSelection();
1130 LyXFont const old_font = real_current_font;
1132 string::const_iterator cit = cmd.argument.begin();
1133 string::const_iterator end = cmd.argument.end();
1134 for (; cit != end; ++cit)
1135 bv->owner()->getIntl().getTransManager().
1136 TranslateAndInsert(*cit, this);
1139 moveCursor(cur, false);
1140 bv->updateScrollbar();
1145 InsetCommandParams p("url");
1146 string const data = InsetCommandMailer::params2string("url", p);
1147 bv->owner()->getDialogs().show("url", data, 0);
1151 case LFUN_HTMLURL: {
1152 InsetCommandParams p("htmlurl");
1153 string const data = InsetCommandMailer::params2string("url", p);
1154 bv->owner()->getDialogs().show("url", data, 0);
1158 case LFUN_INSERT_LABEL: {
1159 // Try to generate a valid label
1160 string const contents = cmd.argument.empty() ?
1161 cur.getPossibleLabel() : cmd.argument;
1163 InsetCommandParams p("label", contents);
1164 string const data = InsetCommandMailer::params2string("label", p);
1166 if (cmd.argument.empty()) {
1167 bv->owner()->getDialogs().show("label", data, 0);
1169 FuncRequest fr(LFUN_INSET_INSERT, data);
1177 case LFUN_INSET_LIST:
1178 case LFUN_INSET_THEOREM:
1179 case LFUN_INSET_CAPTION:
1181 case LFUN_INSERT_NOTE:
1182 case LFUN_INSERT_CHARSTYLE:
1183 case LFUN_INSERT_BOX:
1184 case LFUN_INSERT_BRANCH:
1185 case LFUN_INSERT_BIBITEM:
1186 case LFUN_INSET_ERT:
1187 case LFUN_INSET_FOOTNOTE:
1188 case LFUN_INSET_MARGINAL:
1189 case LFUN_INSET_OPTARG:
1190 case LFUN_ENVIRONMENT_INSERT:
1191 // Open the inset, and move the current selection
1193 doInsertInset(cur, this, cmd, true, true);
1197 case LFUN_TABULAR_INSERT:
1198 // if there were no arguments, just open the dialog
1199 if (doInsertInset(cur, this, cmd, false, true))
1202 bv->owner()->getDialogs().show("tabularcreate");
1206 case LFUN_INSET_FLOAT:
1207 case LFUN_INSET_WIDE_FLOAT:
1208 case LFUN_INSET_WRAP:
1209 doInsertInset(cur, this, cmd, true, true);
1211 // FIXME: the "Caption" name should not be hardcoded,
1212 // but given by the float definition.
1213 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1216 case LFUN_INDEX_INSERT: {
1217 InsetBase * inset = createInset(&cur.bv(), cmd);
1222 cur.clearSelection();
1223 insertInset(cur, inset);
1224 inset->edit(cur, true);
1229 case LFUN_INDEX_PRINT:
1230 case LFUN_TOC_INSERT:
1232 case LFUN_INSERT_LINE:
1233 case LFUN_INSERT_PAGEBREAK:
1235 doInsertInset(cur, this, cmd, false, false);
1239 case LFUN_DEPTH_MIN:
1240 changeDepth(cur, DEC_DEPTH);
1243 case LFUN_DEPTH_PLUS:
1244 changeDepth(cur, INC_DEPTH);
1247 case LFUN_MATH_DISPLAY:
1248 mathDispatch(cur, cmd, true);
1251 case LFUN_MATH_IMPORT_SELECTION:
1252 case LFUN_MATH_MODE:
1253 if (cmd.argument == "on")
1254 // don't pass "on" as argument
1255 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1257 mathDispatch(cur, cmd, false);
1260 case LFUN_MATH_MACRO:
1261 if (cmd.argument.empty())
1262 cur.errorMessage(N_("Missing argument"));
1264 string s = cmd.argument;
1265 string const s1 = token(s, ' ', 1);
1266 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1267 string const s2 = token(s, ' ', 2);
1268 string const type = s2.empty() ? "newcommand" : s2;
1269 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1270 //cur.nextInset()->edit(cur, true);
1274 // passthrough hat and underscore outside mathed:
1275 case LFUN_SUBSCRIPT:
1276 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1278 case LFUN_SUPERSCRIPT:
1279 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1282 case LFUN_INSERT_MATH:
1283 case LFUN_INSERT_MATRIX:
1284 case LFUN_MATH_DELIM: {
1285 cur.insert(new MathHullInset("simple"));
1286 cur.dispatch(FuncRequest(LFUN_RIGHT));
1292 LyXFont font(LyXFont::ALL_IGNORE);
1293 font.setEmph(LyXFont::TOGGLE);
1294 toggleAndShow(cur, this, font);
1299 LyXFont font(LyXFont::ALL_IGNORE);
1300 font.setSeries(LyXFont::BOLD_SERIES);
1301 toggleAndShow(cur, this, font);
1306 LyXFont font(LyXFont::ALL_IGNORE);
1307 font.setNoun(LyXFont::TOGGLE);
1308 toggleAndShow(cur, this, font);
1313 LyXFont font(LyXFont::ALL_IGNORE);
1314 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1315 toggleAndShow(cur, this, font);
1320 LyXFont font(LyXFont::ALL_IGNORE);
1321 font.setFamily(LyXFont::SANS_FAMILY);
1322 toggleAndShow(cur, this, font);
1327 LyXFont font(LyXFont::ALL_IGNORE);
1328 font.setFamily(LyXFont::ROMAN_FAMILY);
1329 toggleAndShow(cur, this, font);
1333 case LFUN_DEFAULT: {
1334 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1335 toggleAndShow(cur, this, font);
1339 case LFUN_UNDERLINE: {
1340 LyXFont font(LyXFont::ALL_IGNORE);
1341 font.setUnderbar(LyXFont::TOGGLE);
1342 toggleAndShow(cur, this, font);
1346 case LFUN_FONT_SIZE: {
1347 LyXFont font(LyXFont::ALL_IGNORE);
1348 font.setLyXSize(cmd.argument);
1349 toggleAndShow(cur, this, font);
1353 case LFUN_LANGUAGE: {
1354 Language const * lang = languages.getLanguage(cmd.argument);
1357 LyXFont font(LyXFont::ALL_IGNORE);
1358 font.setLanguage(lang);
1359 toggleAndShow(cur, this, font);
1364 case LFUN_FREEFONT_APPLY:
1365 toggleAndShow(cur, this, freefont, toggleall);
1366 cur.message(_("Character set"));
1369 // Set the freefont using the contents of \param data dispatched from
1370 // the frontends and apply it at the current cursor location.
1371 case LFUN_FREEFONT_UPDATE: {
1374 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1377 toggleAndShow(cur, this, freefont, toggleall);
1378 cur.message(_("Character set"));
1383 case LFUN_FINISHED_LEFT:
1384 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1387 case LFUN_FINISHED_RIGHT:
1388 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1392 case LFUN_FINISHED_UP:
1393 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1397 case LFUN_FINISHED_DOWN:
1398 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1402 case LFUN_LAYOUT_PARAGRAPH: {
1404 params2string(cur.paragraph(), data);
1405 data = "show\n" + data;
1406 bv->owner()->getDialogs().show("paragraph", data);
1410 case LFUN_PARAGRAPH_UPDATE: {
1411 if (!bv->owner()->getDialogs().visible("paragraph"))
1414 params2string(cur.paragraph(), data);
1416 // Will the paragraph accept changes from the dialog?
1417 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1419 data = "update " + convert<string>(accept) + '\n' + data;
1420 bv->owner()->getDialogs().update("paragraph", data);
1425 case LFUN_CIRCUMFLEX:
1435 case LFUN_SPECIAL_CARON:
1438 case LFUN_HUNG_UMLAUT:
1441 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1442 if (!cmd.argument.empty())
1443 bv->owner()->getIntl().getTransManager()
1444 .TranslateAndInsert(cmd.argument[0], this);
1447 case LFUN_FLOAT_LIST: {
1448 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1449 if (tclass.floats().typeExist(cmd.argument)) {
1450 // not quite sure if we want this...
1452 cur.clearSelection();
1453 breakParagraph(cur);
1455 if (cur.lastpos() != 0) {
1457 breakParagraph(cur);
1460 setLayout(cur, tclass.defaultLayoutName());
1461 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1462 insertInset(cur, new InsetFloatList(cmd.argument));
1465 lyxerr << "Non-existent float type: "
1466 << cmd.argument << endl;
1471 case LFUN_ACCEPT_CHANGE: {
1476 case LFUN_REJECT_CHANGE: {
1481 case LFUN_THESAURUS_ENTRY: {
1482 string arg = cmd.argument;
1484 arg = cur.selectionAsString(false);
1486 if (arg.size() > 100 || arg.empty()) {
1487 // Get word or selection
1488 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1489 arg = cur.selectionAsString(false);
1492 bv->owner()->getDialogs().show("thesaurus", arg);
1496 case LFUN_PARAGRAPH_APPLY: {
1497 // Given data, an encoding of the ParagraphParameters
1498 // generated in the Paragraph dialog, this function sets
1499 // the current paragraph appropriately.
1500 istringstream is(cmd.argument);
1503 ParagraphParameters params;
1508 params.labelWidthString(),
1510 cur.message(_("Paragraph layout set"));
1514 case LFUN_INSET_DIALOG_SHOW: {
1515 InsetBase * inset = cur.nextInset();
1517 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1518 inset->dispatch(cur, fr);
1524 if (cur.selection()) {
1525 cur.selection() = false;
1528 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1533 lyxerr[Debug::ACTION]
1534 << BOOST_CURRENT_FUNCTION
1535 << ": Command " << cmd
1536 << " not DISPATCHED by LyXText" << endl;
1541 if (singleParUpdate)
1542 // Inserting characters does not change par height
1543 if (cur.bottom().paragraph().dim().height()
1544 == olddim.height()) {
1545 // if so, update _only_ this paragraph
1546 cur.bv().update(Update::SinglePar |
1548 Update::MultiParSel);
1554 && &oldTopSlice.inset() == &cur.inset()
1555 && oldTopSlice.idx() == cur.idx()
1557 && !cur.selection())
1564 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1565 FuncStatus & flag) const
1567 BOOST_ASSERT(cur.text() == this);
1569 LyXFont const & font = real_current_font;
1571 InsetBase::Code code = InsetBase::NO_CODE;
1573 switch (cmd.action) {
1575 case LFUN_DEPTH_MIN:
1576 enable = changeDepthAllowed(cur, DEC_DEPTH);
1579 case LFUN_DEPTH_PLUS:
1580 enable = changeDepthAllowed(cur, INC_DEPTH);
1584 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1587 case LFUN_INSERT_BIBITEM:
1588 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1591 case LFUN_DIALOG_SHOW_NEW_INSET:
1592 if (cmd.argument == "bibitem")
1593 code = InsetBase::BIBITEM_CODE;
1594 else if (cmd.argument == "bibtex")
1595 code = InsetBase::BIBTEX_CODE;
1596 else if (cmd.argument == "box")
1597 code = InsetBase::BOX_CODE;
1598 else if (cmd.argument == "branch")
1599 code = InsetBase::BRANCH_CODE;
1600 else if (cmd.argument == "citation")
1601 code = InsetBase::CITE_CODE;
1602 else if (cmd.argument == "ert")
1603 code = InsetBase::ERT_CODE;
1604 else if (cmd.argument == "external")
1605 code = InsetBase::EXTERNAL_CODE;
1606 else if (cmd.argument == "float")
1607 code = InsetBase::FLOAT_CODE;
1608 else if (cmd.argument == "graphics")
1609 code = InsetBase::GRAPHICS_CODE;
1610 else if (cmd.argument == "include")
1611 code = InsetBase::INCLUDE_CODE;
1612 else if (cmd.argument == "index")
1613 code = InsetBase::INDEX_CODE;
1614 else if (cmd.argument == "label")
1615 code = InsetBase::LABEL_CODE;
1616 else if (cmd.argument == "note")
1617 code = InsetBase::NOTE_CODE;
1618 else if (cmd.argument == "ref")
1619 code = InsetBase::REF_CODE;
1620 else if (cmd.argument == "toc")
1621 code = InsetBase::TOC_CODE;
1622 else if (cmd.argument == "url")
1623 code = InsetBase::URL_CODE;
1624 else if (cmd.argument == "vspace")
1625 code = InsetBase::VSPACE_CODE;
1626 else if (cmd.argument == "wrap")
1627 code = InsetBase::WRAP_CODE;
1630 case LFUN_INSET_ERT:
1631 code = InsetBase::ERT_CODE;
1633 case LFUN_INSET_FOOTNOTE:
1634 code = InsetBase::FOOT_CODE;
1636 case LFUN_TABULAR_INSERT:
1637 code = InsetBase::TABULAR_CODE;
1639 case LFUN_INSET_MARGINAL:
1640 code = InsetBase::MARGIN_CODE;
1642 case LFUN_INSET_FLOAT:
1643 case LFUN_INSET_WIDE_FLOAT:
1644 code = InsetBase::FLOAT_CODE;
1646 case LFUN_INSET_WRAP:
1647 code = InsetBase::WRAP_CODE;
1649 case LFUN_FLOAT_LIST:
1650 code = InsetBase::FLOAT_LIST_CODE;
1653 case LFUN_INSET_LIST:
1654 code = InsetBase::LIST_CODE;
1656 case LFUN_INSET_THEOREM:
1657 code = InsetBase::THEOREM_CODE;
1660 case LFUN_INSET_CAPTION:
1661 code = InsetBase::CAPTION_CODE;
1663 case LFUN_INSERT_NOTE:
1664 code = InsetBase::NOTE_CODE;
1666 case LFUN_INSERT_CHARSTYLE:
1667 code = InsetBase::CHARSTYLE_CODE;
1668 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1671 case LFUN_INSERT_BOX:
1672 code = InsetBase::BOX_CODE;
1674 case LFUN_INSERT_BRANCH:
1675 code = InsetBase::BRANCH_CODE;
1676 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1679 case LFUN_INSERT_LABEL:
1680 code = InsetBase::LABEL_CODE;
1682 case LFUN_INSET_OPTARG:
1683 code = InsetBase::OPTARG_CODE;
1684 enable = numberOfOptArgs(cur.paragraph())
1685 < cur.paragraph().layout()->optionalargs;
1687 case LFUN_ENVIRONMENT_INSERT:
1688 code = InsetBase::BOX_CODE;
1690 case LFUN_INDEX_INSERT:
1691 code = InsetBase::INDEX_CODE;
1693 case LFUN_INDEX_PRINT:
1694 code = InsetBase::INDEX_PRINT_CODE;
1696 case LFUN_TOC_INSERT:
1697 code = InsetBase::TOC_CODE;
1701 code = InsetBase::URL_CODE;
1704 // always allow this, since we will inset a raw quote
1705 // if an inset is not allowed.
1707 case LFUN_HYPHENATION:
1708 case LFUN_LIGATURE_BREAK:
1710 case LFUN_MENU_SEPARATOR:
1712 case LFUN_END_OF_SENTENCE:
1713 code = InsetBase::SPECIALCHAR_CODE;
1715 case LFUN_SPACE_INSERT:
1716 // slight hack: we know this is allowed in math mode
1718 code = InsetBase::SPACE_CODE;
1721 #ifdef WITH_WARNINGS
1722 #warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
1725 case LFUN_INSET_DIALOG_SHOW: {
1726 InsetBase * inset = cur.nextInset();
1729 code = inset->lyxCode();
1730 if (!(code == InsetBase::INCLUDE_CODE
1731 || code == InsetBase::BIBTEX_CODE
1732 || code == InsetBase::FLOAT_LIST_CODE
1733 || code == InsetBase::TOC_CODE))
1740 case LFUN_INSET_MODIFY:
1741 // We need to disable this, because we may get called for a
1743 // InsetTabular::getStatus() -> InsetText::getStatus()
1744 // and we don't handle LFUN_INSET_MODIFY.
1749 flag.setOnOff(font.emph() == LyXFont::ON);
1753 flag.setOnOff(font.noun() == LyXFont::ON);
1757 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1761 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1765 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1769 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1774 enable = cur.selection();
1778 enable = lyx::cap::numberOfSelections() > 0;
1781 case LFUN_DELETE_WORD_FORWARD:
1782 case LFUN_DELETE_WORD_BACKWARD:
1783 case LFUN_DELETE_LINE_FORWARD:
1784 case LFUN_WORDRIGHT:
1794 case LFUN_UP_PARAGRAPHSEL:
1795 case LFUN_DOWN_PARAGRAPHSEL:
1800 case LFUN_WORDRIGHTSEL:
1801 case LFUN_WORDLEFTSEL:
1803 case LFUN_UP_PARAGRAPH:
1804 case LFUN_DOWN_PARAGRAPH:
1809 case LFUN_BREAKLINE:
1811 case LFUN_DELETE_SKIP:
1812 case LFUN_BACKSPACE:
1813 case LFUN_BACKSPACE_SKIP:
1814 case LFUN_BREAKPARAGRAPH:
1815 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1816 case LFUN_BREAKPARAGRAPH_SKIP:
1817 case LFUN_PARAGRAPH_SPACING:
1818 case LFUN_INSET_INSERT:
1819 case LFUN_NEXT_INSET_TOGGLE:
1820 case LFUN_UPCASE_WORD:
1821 case LFUN_LOWCASE_WORD:
1822 case LFUN_CAPITALIZE_WORD:
1823 case LFUN_TRANSPOSE_CHARS:
1827 case LFUN_GETLAYOUT:
1829 case LFUN_PASTESELECTION:
1830 case LFUN_DATE_INSERT:
1831 case LFUN_SELFINSERT:
1832 case LFUN_INSERT_LINE:
1833 case LFUN_INSERT_PAGEBREAK:
1834 case LFUN_MATH_DISPLAY:
1835 case LFUN_MATH_IMPORT_SELECTION:
1836 case LFUN_MATH_MODE:
1837 case LFUN_MATH_MACRO:
1838 case LFUN_INSERT_MATH:
1839 case LFUN_INSERT_MATRIX:
1840 case LFUN_MATH_DELIM:
1841 case LFUN_SUBSCRIPT:
1842 case LFUN_SUPERSCRIPT:
1844 case LFUN_UNDERLINE:
1845 case LFUN_FONT_SIZE:
1847 case LFUN_FREEFONT_APPLY:
1848 case LFUN_FREEFONT_UPDATE:
1849 case LFUN_LAYOUT_PARAGRAPH:
1850 case LFUN_PARAGRAPH_UPDATE:
1852 case LFUN_CIRCUMFLEX:
1862 case LFUN_SPECIAL_CARON:
1865 case LFUN_HUNG_UMLAUT:
1868 case LFUN_ACCEPT_CHANGE:
1869 case LFUN_REJECT_CHANGE:
1870 case LFUN_THESAURUS_ENTRY:
1871 case LFUN_PARAGRAPH_APPLY:
1874 case LFUN_BEGINNINGBUF:
1875 case LFUN_BEGINNINGBUFSEL:
1876 case LFUN_ENDBUFSEL:
1877 // these are handled in our dispatch()
1885 if (code != InsetBase::NO_CODE
1886 && (cur.empty() || !cur.inset().insetAllowed(code)))
1889 flag.enabled(enable);