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 "FloatList.h"
21 #include "FuncStatus.h"
23 #include "buffer_funcs.h"
24 #include "bufferparams.h"
25 #include "BufferView.h"
27 #include "coordcache.h"
28 #include "CutAndPaste.h"
30 #include "dispatchresult.h"
32 #include "funcrequest.h"
36 #include "LyXAction.h"
41 #include "paragraph.h"
42 #include "paragraph_funcs.h"
43 #include "ParagraphParameters.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/LyXView.h"
50 #include "insets/insetcommand.h"
51 #include "insets/insetfloatlist.h"
52 #include "insets/insetnewline.h"
53 #include "insets/insetquotes.h"
54 #include "insets/insetspecialchar.h"
55 #include "insets/insettext.h"
57 #include "support/lstrings.h"
58 #include "support/lyxlib.h"
59 #include "support/convert.h"
60 #include "support/lyxtime.h"
62 #include "mathed/math_hullinset.h"
63 #include "mathed/math_macrotemplate.h"
65 #include <boost/current_function.hpp>
72 using lyx::cap::copySelection;
73 using lyx::cap::cutSelection;
74 using lyx::cap::pasteSelection;
75 using lyx::cap::replaceSelection;
77 using lyx::support::isStrUnsignedInt;
78 using lyx::support::token;
82 using std::istringstream;
85 extern string current_layout;
91 LyXFont freefont(LyXFont::ALL_IGNORE);
92 bool toggleall = false;
95 void toggleAndShow(LCursor & cur, LyXText * text,
96 LyXFont const & font, bool toggleall = true)
98 text->toggleFree(cur, font, toggleall);
100 if (font.language() != ignore_language ||
101 font.number() != LyXFont::IGNORE) {
102 Paragraph & par = cur.paragraph();
103 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
104 if (cur.boundary() !=
105 text->bidi.isBoundary(cur.buffer(), par,
107 text->real_current_font))
108 text->setCursor(cur, cur.pit(), cur.pos(),
109 false, !cur.boundary());
114 void moveCursor(LCursor & cur, bool selecting)
116 if (selecting || cur.mark())
118 if (!cur.selection())
119 cur.bv().haveSelection(false);
120 cur.bv().switchKeyMap();
124 void finishChange(LCursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 //lyxerr << "selection is: '" << sel << "'" << endl;
138 const int old_pos = cur.pos();
139 cur.insert(new MathHullInset("simple"));
140 BOOST_ASSERT(old_pos == cur.pos());
141 cur.nextInset()->edit(cur, true);
142 // don't do that also for LFUN_MATH_MODE
143 // unless you want end up with always changing
144 // to mathrm when opening an inlined inset --
145 // I really hate "LyXfunc overloading"...
147 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
148 // Avoid an unnecessary undo step if cmd.argument
150 if (!cmd.argument.empty())
151 cur.dispatch(FuncRequest(LFUN_INSERT_MATH,
154 // create a macro if we see "\\newcommand"
155 // somewhere, and an ordinary formula
157 cutSelection(cur, true, true);
158 if (sel.find("\\newcommand") == string::npos
159 && sel.find("\\def") == string::npos)
161 cur.insert(new MathHullInset("simple"));
162 cur.dispatch(FuncRequest(LFUN_RIGHT));
163 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
165 istringstream is(sel);
166 cur.insert(new MathMacroTemplate(is));
169 cur.message(N_("Math editor mode"));
178 string const freefont2string()
181 if (font2string(freefont, toggleall, data))
188 bool LyXText::cursorPrevious(LCursor & cur)
190 pos_type cpos = cur.pos();
191 lyx::pit_type cpar = cur.pit();
193 int x = cur.x_target();
195 setCursorFromCoordinates(cur, x, 0);
196 bool updated = cursorUp(cur);
198 if (cpar == cur.pit() && cpos == cur.pos()) {
199 // we have a row which is taller than the workarea. The
200 // simplest solution is to move to the previous row instead.
201 updated |= cursorUp(cur);
204 cur.bv().updateScrollbar();
210 bool LyXText::cursorNext(LCursor & cur)
212 pos_type cpos = cur.pos();
213 lyx::pit_type cpar = cur.pit();
215 int x = cur.x_target();
216 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
217 bool updated = cursorDown(cur);
219 if (cpar == cur.pit() && cpos == cur.pos()) {
220 // we have a row which is taller than the workarea. The
221 // simplest solution is to move to the next row instead.
222 updated |= cursorDown(cur);
225 cur.bv().updateScrollbar();
233 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
235 lyx::cap::replaceSelection(cur);
236 cur.insert(new InsetSpecialChar(kind));
241 bool doInsertInset(LCursor & cur, LyXText * text,
242 FuncRequest const & cmd, bool edit, bool pastesel)
244 InsetBase * inset = createInset(&cur.bv(), cmd);
250 if (cur.selection()) {
251 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
254 text->insertInset(cur, inset);
257 inset->edit(cur, true);
259 if (gotsel && pastesel)
260 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
265 void update(LCursor & cur)
267 //we don't call update(true, false) directly to save a metrics call
268 if (cur.bv().fitCursor())
269 cur.bv().update(Update::Force);
276 void LyXText::number(LCursor & cur)
278 LyXFont font(LyXFont::ALL_IGNORE);
279 font.setNumber(LyXFont::TOGGLE);
280 toggleAndShow(cur, this, font);
284 bool LyXText::isRTL(Paragraph const & par) const
286 return par.isRightToLeftPar(bv()->buffer()->params());
290 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
292 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
294 BOOST_ASSERT(cur.text() == this);
295 BufferView * bv = &cur.bv();
296 CursorSlice oldTopSlice = cur.top();
297 bool oldBoundary = cur.boundary();
298 bool sel = cur.selection();
299 // Signals that, even if needsUpdate == false, an update of the
300 // cursor paragraph is required
301 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
302 LyXAction::SingleParUpdate);
303 // Signals that a full-screen update is required
304 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
305 LyXAction::NoUpdate) || singleParUpdate);
306 // Remember the old paragraph metric
307 Dimension olddim = cur.paragraph().dim();
309 switch (cmd.action) {
311 case LFUN_APPENDIX: {
312 Paragraph & par = cur.paragraph();
313 bool start = !par.params().startOfAppendix();
316 #warning The code below only makes sense at top level.
317 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
319 // ensure that we have only one start_of_appendix in this document
320 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
321 if (pars_[tmp].params().startOfAppendix()) {
323 pars_[tmp].params().startOfAppendix(false);
329 par.params().startOfAppendix(start);
331 // we can set the refreshing parameters now
332 updateCounters(cur.buffer());
336 case LFUN_DELETE_WORD_FORWARD:
337 cur.clearSelection();
338 deleteWordForward(cur);
339 finishChange(cur, false);
342 case LFUN_DELETE_WORD_BACKWARD:
343 cur.clearSelection();
344 deleteWordBackward(cur);
345 finishChange(cur, false);
348 case LFUN_DELETE_LINE_FORWARD:
349 cur.clearSelection();
350 deleteLineForward(cur);
351 finishChange(cur, false);
356 cur.clearSelection();
357 if (isRTL(cur.paragraph()))
358 needsUpdate = cursorLeftOneWord(cur);
360 needsUpdate = cursorRightOneWord(cur);
361 finishChange(cur, false);
366 cur.clearSelection();
367 if (isRTL(cur.paragraph()))
368 needsUpdate = cursorRightOneWord(cur);
370 needsUpdate = cursorLeftOneWord(cur);
371 finishChange(cur, false);
374 case LFUN_BEGINNINGBUF:
375 if (cur.depth() == 1) {
377 cur.clearSelection();
379 finishChange(cur, false);
385 case LFUN_BEGINNINGBUFSEL:
386 if (cur.depth() == 1) {
387 if (!cur.selection())
390 finishChange(cur, true);
397 if (cur.depth() == 1) {
399 cur.clearSelection();
401 finishChange(cur, false);
408 if (cur.depth() == 1) {
409 if (!cur.selection())
412 finishChange(cur, true);
420 //lyxerr << BOOST_CURRENT_FUNCTION
421 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
422 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
423 if (isRTL(cur.paragraph()))
424 needsUpdate = cursorLeft(cur);
426 needsUpdate = cursorRight(cur);
428 if (!needsUpdate && oldTopSlice == cur.top()
429 && cur.boundary() == oldBoundary) {
431 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
437 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
438 cur.selHandle(cmd.action == LFUN_LEFTSEL);
439 if (isRTL(cur.paragraph()))
440 needsUpdate = cursorRight(cur);
442 needsUpdate = cursorLeft(cur);
444 if (!needsUpdate && oldTopSlice == cur.top()
445 && cur.boundary() == oldBoundary) {
447 cmd = FuncRequest(LFUN_FINISHED_LEFT);
454 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
455 cur.selHandle(cmd.action == LFUN_UPSEL);
457 needsUpdate = cursorUp(cur);
458 if (!needsUpdate && oldTopSlice == cur.top()
459 && cur.boundary() == oldBoundary) {
461 cmd = FuncRequest(LFUN_FINISHED_UP);
468 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
469 cur.selHandle(cmd.action == LFUN_DOWNSEL);
470 needsUpdate = cursorDown(cur);
471 if (!needsUpdate && oldTopSlice == cur.top() &&
472 cur.boundary() == oldBoundary)
475 cmd = FuncRequest(LFUN_FINISHED_DOWN);
479 case LFUN_UP_PARAGRAPH:
481 cur.clearSelection();
482 needsUpdate = cursorUpParagraph(cur);
483 finishChange(cur, false);
486 case LFUN_UP_PARAGRAPHSEL:
487 if (!cur.selection())
489 cursorUpParagraph(cur);
490 finishChange(cur, true);
493 case LFUN_DOWN_PARAGRAPH:
495 cur.clearSelection();
496 needsUpdate = cursorDownParagraph(cur);
497 finishChange(cur, false);
500 case LFUN_DOWN_PARAGRAPHSEL:
501 if (!cur.selection())
503 cursorDownParagraph(cur);
504 finishChange(cur, true);
509 if (!cur.selection())
512 finishChange(cur, true);
517 if (!cur.selection())
520 finishChange(cur, true);
525 if (!cur.selection())
528 finishChange(cur, true);
533 if (!cur.selection())
536 finishChange(cur, true);
539 case LFUN_WORDRIGHTSEL:
540 if (!cur.selection())
542 if (isRTL(cur.paragraph()))
543 cursorLeftOneWord(cur);
545 cursorRightOneWord(cur);
546 finishChange(cur, true);
549 case LFUN_WORDLEFTSEL:
550 if (!cur.selection())
552 if (isRTL(cur.paragraph()))
553 cursorRightOneWord(cur);
555 cursorLeftOneWord(cur);
556 finishChange(cur, true);
560 selectWord(cur, lyx::WHOLE_WORD);
561 finishChange(cur, true);
568 cur.clearSelection();
569 finishChange(cur, false);
570 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
572 cmd = FuncRequest(LFUN_FINISHED_UP);
574 needsUpdate = cursorPrevious(cur);
581 cur.clearSelection();
582 finishChange(cur, false);
583 if (cur.pit() == cur.lastpit()
584 && cur.textRow().endpos() == cur.lastpos()) {
586 cmd = FuncRequest(LFUN_FINISHED_DOWN);
588 needsUpdate = cursorNext(cur);
594 cur.clearSelection();
596 finishChange(cur, false);
601 cur.clearSelection();
603 finishChange(cur, false);
606 case LFUN_BREAKLINE: {
607 // Not allowed by LaTeX (labels or empty par)
608 if (cur.pos() > cur.paragraph().beginOfBody()) {
609 lyx::cap::replaceSelection(cur);
610 cur.insert(new InsetNewline);
612 moveCursor(cur, false);
618 if (!cur.selection()) {
621 // It is possible to make it a lot faster still
622 // just comment out the line below...
624 cutSelection(cur, true, false);
626 moveCursor(cur, false);
629 case LFUN_DELETE_SKIP:
630 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
631 if (!cur.selection()) {
632 if (cur.pos() == cur.lastpos()) {
639 cutSelection(cur, true, false);
645 if (!cur.selection()) {
646 if (bv->owner()->getIntl().getTransManager().backspace()) {
649 // It is possible to make it a lot faster still
650 // just comment out the line below...
653 cutSelection(cur, true, false);
658 case LFUN_BACKSPACE_SKIP:
659 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
660 if (!cur.selection()) {
664 //CursorSlice cur = cursor();
668 cutSelection(cur, true, false);
672 case LFUN_BREAKPARAGRAPH:
673 lyx::cap::replaceSelection(cur);
674 breakParagraph(cur, 0);
679 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
680 lyx::cap::replaceSelection(cur);
681 breakParagraph(cur, 1);
686 case LFUN_BREAKPARAGRAPH_SKIP: {
687 // When at the beginning of a paragraph, remove
688 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
689 lyx::cap::replaceSelection(cur);
691 cur.paragraph().params().labelWidthString(string());
693 breakParagraph(cur, 0);
699 case LFUN_PARAGRAPH_SPACING: {
700 Paragraph & par = cur.paragraph();
701 Spacing::Space cur_spacing = par.params().spacing().getSpace();
702 string cur_value = "1.0";
703 if (cur_spacing == Spacing::Other)
704 cur_value = par.params().spacing().getValueAsString();
706 istringstream is(cmd.argument);
709 Spacing::Space new_spacing = cur_spacing;
710 string new_value = cur_value;
712 lyxerr << "Missing argument to `paragraph-spacing'"
714 } else if (tmp == "single") {
715 new_spacing = Spacing::Single;
716 } else if (tmp == "onehalf") {
717 new_spacing = Spacing::Onehalf;
718 } else if (tmp == "double") {
719 new_spacing = Spacing::Double;
720 } else if (tmp == "other") {
721 new_spacing = Spacing::Other;
722 string tmpval = "0.0";
724 lyxerr << "new_value = " << tmpval << endl;
727 } else if (tmp == "default") {
728 new_spacing = Spacing::Default;
730 lyxerr << _("Unknown spacing argument: ")
731 << cmd.argument << endl;
733 if (cur_spacing != new_spacing || cur_value != new_value)
734 par.params().spacing(Spacing(new_spacing, new_value));
738 case LFUN_INSET_INSERT: {
740 InsetBase * inset = createInset(bv, cmd);
742 insertInset(cur, inset);
748 case LFUN_INSET_SETTINGS:
749 cur.inset().showInsetDialog(bv);
752 case LFUN_NEXT_INSET_TOGGLE: {
753 InsetBase * inset = cur.nextInset();
755 cur.clearSelection();
756 FuncRequest fr = cmd;
757 fr.action = LFUN_INSET_TOGGLE;
758 inset->dispatch(cur, fr);
763 case LFUN_KEYMAP_TOGGLE:
764 cur.clearSelection();
768 case LFUN_SPACE_INSERT:
769 if (cur.paragraph().layout()->free_spacing)
770 insertChar(cur, ' ');
772 doInsertInset(cur, this, cmd, false, false);
775 moveCursor(cur, false);
778 case LFUN_HYPHENATION:
779 specialChar(cur, InsetSpecialChar::HYPHENATION);
782 case LFUN_LIGATURE_BREAK:
783 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
787 specialChar(cur, InsetSpecialChar::LDOTS);
790 case LFUN_END_OF_SENTENCE:
791 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
794 case LFUN_MENU_SEPARATOR:
795 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
798 case LFUN_UPCASE_WORD:
799 changeCase(cur, LyXText::text_uppercase);
802 case LFUN_LOWCASE_WORD:
803 changeCase(cur, LyXText::text_lowercase);
806 case LFUN_CAPITALIZE_WORD:
807 changeCase(cur, LyXText::text_capitalization);
810 case LFUN_TRANSPOSE_CHARS:
815 cur.message(_("Paste"));
816 lyx::cap::replaceSelection(cur);
818 #warning FIXME Check if the arg is in the domain of available selections.
820 if (isStrUnsignedInt(cmd.argument))
821 pasteSelection(cur, convert<unsigned int>(cmd.argument));
823 pasteSelection(cur, 0);
824 cur.clearSelection(); // bug 393
830 cutSelection(cur, true, true);
831 cur.message(_("Cut"));
836 cur.message(_("Copy"));
840 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
841 + convert<string>(cursorY(cur.top(), cur.boundary())));
847 istringstream is(cmd.argument);
850 lyxerr << "SETXY: Could not parse coordinates in '"
851 << cmd.argument << std::endl;
853 setCursorFromCoordinates(cur, x, y);
858 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
860 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
867 cur.message(cur.paragraph().layout()->name());
871 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
872 << cmd.argument << endl;
874 // This is not the good solution to the empty argument
875 // problem, but it will hopefully suffice for 1.2.0.
876 // The correct solution would be to augument the
877 // function list/array with information about what
878 // functions needs arguments and their type.
879 if (cmd.argument.empty()) {
880 cur.errorMessage(_("LyX function 'layout' needs an argument."));
884 // Derive layout number from given argument (string)
885 // and current buffer's textclass (number)
886 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
887 bool hasLayout = tclass.hasLayout(cmd.argument);
888 string layout = cmd.argument;
890 // If the entry is obsolete, use the new one instead.
892 string const & obs = tclass[layout]->obsoleted_by();
898 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
903 bool change_layout = (current_layout != layout);
905 if (!change_layout && cur.selection() &&
906 cur.selBegin().pit() != cur.selEnd().pit())
908 pit_type spit = cur.selBegin().pit();
909 pit_type epit = cur.selEnd().pit() + 1;
910 while (spit != epit) {
911 if (pars_[spit].layout()->name() != current_layout) {
912 change_layout = true;
920 current_layout = layout;
921 setLayout(cur, layout);
922 bv->owner()->setLayout(layout);
928 case LFUN_PASTESELECTION: {
929 cur.clearSelection();
930 string const clip = bv->getClipboard();
933 if (cmd.argument == "paragraph")
934 insertStringAsParagraphs(cur, clip);
936 insertStringAsLines(cur, clip);
942 lyx::cap::replaceSelection(cur);
943 Paragraph & par = cur.paragraph();
944 lyx::pos_type pos = cur.pos();
948 else if (cur.prevInset() && cur.prevInset()->isSpace())
951 c = par.getChar(pos - 1);
953 LyXLayout_ptr const & style = par.layout();
955 BufferParams const & bufparams = bv->buffer()->params();
956 if (!style->pass_thru
957 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
958 string arg = cmd.argument;
960 cur.insert(new InsetQuotes(c,
961 bufparams.quotes_language,
962 InsetQuotes::SingleQ));
963 else if (arg == "double")
964 cur.insert(new InsetQuotes(c,
965 bufparams.quotes_language,
966 InsetQuotes::DoubleQ));
968 cur.insert(new InsetQuotes(c, bufparams));
972 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
976 case LFUN_DATE_INSERT:
977 if (cmd.argument.empty())
978 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
979 lyx::formatted_time(lyx::current_time())));
981 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
982 lyx::formatted_time(lyx::current_time(), cmd.argument)));
985 case LFUN_MOUSE_TRIPLE:
986 if (cmd.button() == mouse_button::button1) {
992 bv->haveSelection(cur.selection());
996 case LFUN_MOUSE_DOUBLE:
997 if (cmd.button() == mouse_button::button1) {
998 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1000 bv->haveSelection(cur.selection());
1004 // Single-click on work area
1005 case LFUN_MOUSE_PRESS: {
1006 // Right click on a footnote flag opens float menu
1007 if (cmd.button() == mouse_button::button3) {
1008 cur.clearSelection();
1012 // Middle button press pastes if we have a selection
1013 // We do this here as if the selection was inside an inset
1014 // it could get cleared on the unlocking of the inset so
1015 // we have to check this first
1016 bool paste_internally = false;
1017 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1018 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1019 paste_internally = true;
1022 // Clear the selection
1023 cur.clearSelection();
1025 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1030 // Has the cursor just left the inset?
1031 if (bv->cursor().inMathed() && !cur.inMathed())
1032 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1037 // Insert primary selection with middle mouse
1038 // if there is a local selection in the current buffer,
1040 if (cmd.button() == mouse_button::button2) {
1041 if (paste_internally)
1042 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1044 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1050 case LFUN_MOUSE_MOTION: {
1051 // Only use motion with button 1
1052 //if (cmd.button() != mouse_button::button1)
1055 // ignore motions deeper nested than the real anchor
1056 LCursor & bvcur = cur.bv().cursor();
1057 if (bvcur.anchor_.hasPart(cur)) {
1058 CursorSlice old = bvcur.top();
1060 int const wh = bv->workHeight();
1061 int const y = std::max(0, std::min(wh - 1, cmd.y));
1063 setCursorFromCoordinates(cur, cmd.x, y);
1064 cur.x_target() = cmd.x;
1069 // This is to allow jumping over large insets
1070 if (cur.top() == old) {
1077 if (cur.top() == old)
1080 // don't set anchor_
1081 bvcur.setCursor(cur);
1082 bvcur.selection() = true;
1083 //lyxerr << "MOTION: " << bv->cursor() << endl;
1091 case LFUN_MOUSE_RELEASE: {
1092 if (cmd.button() == mouse_button::button2)
1096 if (cmd.button() == mouse_button::button1)
1097 bv->haveSelection(cur.selection());
1100 bv->owner()->updateMenubar();
1101 bv->owner()->updateToolbars();
1105 case LFUN_SELFINSERT: {
1106 if (cmd.argument.empty())
1109 // Automatically delete the currently selected
1110 // text and replace it with what is being
1111 // typed in now. Depends on lyxrc settings
1112 // "auto_region_delete", which defaults to
1115 if (lyxrc.auto_region_delete) {
1116 if (cur.selection())
1117 cutSelection(cur, false, false);
1118 bv->haveSelection(false);
1121 cur.clearSelection();
1122 LyXFont const old_font = real_current_font;
1124 // Prevents language turds in new lyxtexts under non-english
1125 BufferParams const & bufparams = cur.buffer().params();
1126 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1127 current_font.setLanguage(lang);
1128 real_current_font.setLanguage(lang);
1130 string::const_iterator cit = cmd.argument.begin();
1131 string::const_iterator end = cmd.argument.end();
1132 for (; cit != end; ++cit)
1133 bv->owner()->getIntl().getTransManager().
1134 TranslateAndInsert(*cit, this);
1137 moveCursor(cur, false);
1138 bv->updateScrollbar();
1143 InsetCommandParams p("url");
1144 string const data = InsetCommandMailer::params2string("url", p);
1145 bv->owner()->getDialogs().show("url", data, 0);
1149 case LFUN_HTMLURL: {
1150 InsetCommandParams p("htmlurl");
1151 string const data = InsetCommandMailer::params2string("url", p);
1152 bv->owner()->getDialogs().show("url", data, 0);
1156 case LFUN_INSERT_LABEL: {
1157 // Try to generate a valid label
1158 string const contents = cmd.argument.empty() ?
1159 cur.getPossibleLabel() : cmd.argument;
1161 InsetCommandParams p("label", contents);
1162 string const data = InsetCommandMailer::params2string("label", p);
1164 if (cmd.argument.empty()) {
1165 bv->owner()->getDialogs().show("label", data, 0);
1167 FuncRequest fr(LFUN_INSET_INSERT, data);
1175 case LFUN_INSET_LIST:
1176 case LFUN_INSET_THEOREM:
1177 case LFUN_INSET_CAPTION:
1179 case LFUN_INSERT_NOTE:
1180 case LFUN_INSERT_CHARSTYLE:
1181 case LFUN_INSERT_BOX:
1182 case LFUN_INSERT_BRANCH:
1183 case LFUN_INSERT_BIBITEM:
1184 case LFUN_INSET_ERT:
1185 case LFUN_INSET_FOOTNOTE:
1186 case LFUN_INSET_MARGINAL:
1187 case LFUN_INSET_OPTARG:
1188 case LFUN_ENVIRONMENT_INSERT:
1189 // Open the inset, and move the current selection
1191 doInsertInset(cur, this, cmd, true, true);
1195 case LFUN_TABULAR_INSERT:
1196 // if there were no arguments, just open the dialog
1197 if (doInsertInset(cur, this, cmd, false, true))
1200 bv->owner()->getDialogs().show("tabularcreate");
1204 case LFUN_INSET_FLOAT:
1205 case LFUN_INSET_WIDE_FLOAT:
1206 case LFUN_INSET_WRAP:
1207 doInsertInset(cur, this, cmd, true, true);
1209 // FIXME: the "Caption" name should not be hardcoded,
1210 // but given by the float definition.
1211 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1214 case LFUN_INDEX_INSERT:
1215 // Just open the inset
1216 doInsertInset(cur, this, cmd, true, false);
1220 case LFUN_INDEX_PRINT:
1221 case LFUN_TOC_INSERT:
1223 case LFUN_INSERT_LINE:
1224 case LFUN_INSERT_PAGEBREAK:
1226 doInsertInset(cur, this, cmd, false, false);
1230 case LFUN_DEPTH_MIN:
1231 changeDepth(cur, DEC_DEPTH);
1234 case LFUN_DEPTH_PLUS:
1235 changeDepth(cur, INC_DEPTH);
1238 case LFUN_MATH_DISPLAY:
1239 mathDispatch(cur, cmd, true);
1242 case LFUN_MATH_IMPORT_SELECTION:
1243 case LFUN_MATH_MODE:
1244 if (cmd.argument == "on")
1245 // don't pass "on" as argument
1246 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1248 mathDispatch(cur, cmd, false);
1251 case LFUN_MATH_MACRO:
1252 if (cmd.argument.empty())
1253 cur.errorMessage(N_("Missing argument"));
1255 string s = cmd.argument;
1256 string const s1 = token(s, ' ', 1);
1257 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1258 string const s2 = token(s, ' ', 2);
1259 string const type = s2.empty() ? "newcommand" : s2;
1260 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1261 //cur.nextInset()->edit(cur, true);
1265 // passthrough hat and underscore outside mathed:
1266 case LFUN_SUBSCRIPT:
1267 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1269 case LFUN_SUPERSCRIPT:
1270 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1273 case LFUN_INSERT_MATH:
1274 case LFUN_INSERT_MATRIX:
1275 case LFUN_MATH_DELIM: {
1276 cur.insert(new MathHullInset("simple"));
1277 cur.dispatch(FuncRequest(LFUN_RIGHT));
1283 LyXFont font(LyXFont::ALL_IGNORE);
1284 font.setEmph(LyXFont::TOGGLE);
1285 toggleAndShow(cur, this, font);
1290 LyXFont font(LyXFont::ALL_IGNORE);
1291 font.setSeries(LyXFont::BOLD_SERIES);
1292 toggleAndShow(cur, this, font);
1297 LyXFont font(LyXFont::ALL_IGNORE);
1298 font.setNoun(LyXFont::TOGGLE);
1299 toggleAndShow(cur, this, font);
1304 LyXFont font(LyXFont::ALL_IGNORE);
1305 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1306 toggleAndShow(cur, this, font);
1311 LyXFont font(LyXFont::ALL_IGNORE);
1312 font.setFamily(LyXFont::SANS_FAMILY);
1313 toggleAndShow(cur, this, font);
1318 LyXFont font(LyXFont::ALL_IGNORE);
1319 font.setFamily(LyXFont::ROMAN_FAMILY);
1320 toggleAndShow(cur, this, font);
1324 case LFUN_DEFAULT: {
1325 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_UNDERLINE: {
1331 LyXFont font(LyXFont::ALL_IGNORE);
1332 font.setUnderbar(LyXFont::TOGGLE);
1333 toggleAndShow(cur, this, font);
1337 case LFUN_FONT_SIZE: {
1338 LyXFont font(LyXFont::ALL_IGNORE);
1339 font.setLyXSize(cmd.argument);
1340 toggleAndShow(cur, this, font);
1344 case LFUN_LANGUAGE: {
1345 Language const * lang = languages.getLanguage(cmd.argument);
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setLanguage(lang);
1350 toggleAndShow(cur, this, font);
1355 case LFUN_FREEFONT_APPLY:
1356 toggleAndShow(cur, this, freefont, toggleall);
1357 cur.message(_("Character set"));
1360 // Set the freefont using the contents of \param data dispatched from
1361 // the frontends and apply it at the current cursor location.
1362 case LFUN_FREEFONT_UPDATE: {
1365 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1368 toggleAndShow(cur, this, freefont, toggleall);
1369 cur.message(_("Character set"));
1374 case LFUN_FINISHED_LEFT:
1375 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1378 case LFUN_FINISHED_RIGHT:
1379 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1383 case LFUN_FINISHED_UP:
1384 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1388 case LFUN_FINISHED_DOWN:
1389 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1393 case LFUN_LAYOUT_PARAGRAPH: {
1395 params2string(cur.paragraph(), data);
1396 data = "show\n" + data;
1397 bv->owner()->getDialogs().show("paragraph", data);
1401 case LFUN_PARAGRAPH_UPDATE: {
1402 if (!bv->owner()->getDialogs().visible("paragraph"))
1405 params2string(cur.paragraph(), data);
1407 // Will the paragraph accept changes from the dialog?
1408 InsetBase & inset = cur.inset();
1409 bool const accept = !inset.forceDefaultParagraphs(&inset);
1411 data = "update " + convert<string>(accept) + '\n' + data;
1412 bv->owner()->getDialogs().update("paragraph", data);
1417 case LFUN_CIRCUMFLEX:
1427 case LFUN_SPECIAL_CARON:
1430 case LFUN_HUNG_UMLAUT:
1433 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1434 if (!cmd.argument.empty())
1435 bv->owner()->getIntl().getTransManager()
1436 .TranslateAndInsert(cmd.argument[0], this);
1439 case LFUN_FLOAT_LIST: {
1440 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1441 if (tclass.floats().typeExist(cmd.argument)) {
1442 // not quite sure if we want this...
1444 cur.clearSelection();
1445 breakParagraph(cur);
1447 if (cur.lastpos() != 0) {
1449 breakParagraph(cur);
1452 setLayout(cur, tclass.defaultLayoutName());
1453 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1454 insertInset(cur, new InsetFloatList(cmd.argument));
1457 lyxerr << "Non-existent float type: "
1458 << cmd.argument << endl;
1463 case LFUN_ACCEPT_CHANGE: {
1468 case LFUN_REJECT_CHANGE: {
1473 case LFUN_THESAURUS_ENTRY: {
1474 string arg = cmd.argument;
1476 arg = cur.selectionAsString(false);
1478 if (arg.size() > 100 || arg.empty()) {
1479 // Get word or selection
1480 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1481 arg = cur.selectionAsString(false);
1484 bv->owner()->getDialogs().show("thesaurus", arg);
1488 case LFUN_PARAGRAPH_APPLY: {
1489 // Given data, an encoding of the ParagraphParameters
1490 // generated in the Paragraph dialog, this function sets
1491 // the current paragraph appropriately.
1492 istringstream is(cmd.argument);
1495 ParagraphParameters params;
1500 params.labelWidthString(),
1502 cur.message(_("Paragraph layout set"));
1506 case LFUN_INSET_DIALOG_SHOW: {
1507 InsetBase * inset = cur.nextInset();
1509 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1510 inset->dispatch(cur, fr);
1516 if (cur.selection()) {
1517 cur.selection() = false;
1520 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1525 lyxerr[Debug::ACTION]
1526 << BOOST_CURRENT_FUNCTION
1527 << ": Command " << cmd
1528 << " not DISPATCHED by LyXText" << endl;
1533 if (singleParUpdate)
1534 // Inserting characters does not change par height
1535 if (cur.paragraph().dim().asc == olddim.asc
1536 && cur.paragraph().dim().des == olddim.des) {
1537 // if so, update _only_ this paragraph
1538 cur.bv().update(Update::SinglePar | Update::Force);
1542 && &oldTopSlice.inset() == &cur.inset()
1543 && oldTopSlice.idx() == cur.idx()
1545 && !cur.selection())
1552 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1553 FuncStatus & flag) const
1555 BOOST_ASSERT(cur.text() == this);
1556 LyXFont const & font = real_current_font;
1559 switch (cmd.action) {
1561 case LFUN_DEPTH_MIN:
1562 enable = changeDepthAllowed(cur, DEC_DEPTH);
1565 case LFUN_DEPTH_PLUS:
1566 enable = changeDepthAllowed(cur, INC_DEPTH);
1569 case LFUN_INSET_OPTARG:
1570 enable = numberOfOptArgs(cur.paragraph())
1571 < cur.paragraph().layout()->optionalargs;
1575 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1578 case LFUN_INSERT_BIBITEM:
1579 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1583 // the functions which insert insets
1584 InsetBase::Code code = InsetBase::NO_CODE;
1585 switch (cmd.action) {
1586 case LFUN_DIALOG_SHOW_NEW_INSET:
1587 if (cmd.argument == "bibitem")
1588 code = InsetBase::BIBITEM_CODE;
1589 else if (cmd.argument == "bibtex")
1590 code = InsetBase::BIBTEX_CODE;
1591 else if (cmd.argument == "box")
1592 code = InsetBase::BOX_CODE;
1593 else if (cmd.argument == "branch")
1594 code = InsetBase::BRANCH_CODE;
1595 else if (cmd.argument == "citation")
1596 code = InsetBase::CITE_CODE;
1597 else if (cmd.argument == "ert")
1598 code = InsetBase::ERT_CODE;
1599 else if (cmd.argument == "external")
1600 code = InsetBase::EXTERNAL_CODE;
1601 else if (cmd.argument == "float")
1602 code = InsetBase::FLOAT_CODE;
1603 else if (cmd.argument == "graphics")
1604 code = InsetBase::GRAPHICS_CODE;
1605 else if (cmd.argument == "include")
1606 code = InsetBase::INCLUDE_CODE;
1607 else if (cmd.argument == "index")
1608 code = InsetBase::INDEX_CODE;
1609 else if (cmd.argument == "label")
1610 code = InsetBase::LABEL_CODE;
1611 else if (cmd.argument == "note")
1612 code = InsetBase::NOTE_CODE;
1613 else if (cmd.argument == "ref")
1614 code = InsetBase::REF_CODE;
1615 else if (cmd.argument == "toc")
1616 code = InsetBase::TOC_CODE;
1617 else if (cmd.argument == "url")
1618 code = InsetBase::URL_CODE;
1619 else if (cmd.argument == "vspace")
1620 code = InsetBase::VSPACE_CODE;
1621 else if (cmd.argument == "wrap")
1622 code = InsetBase::WRAP_CODE;
1625 case LFUN_INSET_ERT:
1626 code = InsetBase::ERT_CODE;
1628 case LFUN_INSET_FOOTNOTE:
1629 code = InsetBase::FOOT_CODE;
1631 case LFUN_TABULAR_INSERT:
1632 code = InsetBase::TABULAR_CODE;
1634 case LFUN_INSET_MARGINAL:
1635 code = InsetBase::MARGIN_CODE;
1637 case LFUN_INSET_FLOAT:
1638 case LFUN_INSET_WIDE_FLOAT:
1639 code = InsetBase::FLOAT_CODE;
1641 case LFUN_INSET_WRAP:
1642 code = InsetBase::WRAP_CODE;
1644 case LFUN_FLOAT_LIST:
1645 code = InsetBase::FLOAT_LIST_CODE;
1648 case LFUN_INSET_LIST:
1649 code = InsetBase::LIST_CODE;
1651 case LFUN_INSET_THEOREM:
1652 code = InsetBase::THEOREM_CODE;
1655 case LFUN_INSET_CAPTION:
1656 code = InsetBase::CAPTION_CODE;
1658 case LFUN_INSERT_NOTE:
1659 code = InsetBase::NOTE_CODE;
1661 case LFUN_INSERT_CHARSTYLE:
1662 code = InsetBase::CHARSTYLE_CODE;
1663 if (buf->params().getLyXTextClass().charstyles().empty())
1666 case LFUN_INSERT_BOX:
1667 code = InsetBase::BOX_CODE;
1669 case LFUN_INSERT_BRANCH:
1670 code = InsetBase::BRANCH_CODE;
1671 if (buf->params().branchlist().empty())
1674 case LFUN_INSERT_LABEL:
1675 code = InsetBase::LABEL_CODE;
1677 case LFUN_INSET_OPTARG:
1678 code = InsetBase::OPTARG_CODE;
1680 case LFUN_ENVIRONMENT_INSERT:
1681 code = InsetBase::BOX_CODE;
1683 case LFUN_INDEX_INSERT:
1684 code = InsetBase::INDEX_CODE;
1686 case LFUN_INDEX_PRINT:
1687 code = InsetBase::INDEX_PRINT_CODE;
1689 case LFUN_TOC_INSERT:
1690 code = InsetBase::TOC_CODE;
1694 code = InsetBase::URL_CODE;
1697 // always allow this, since we will inset a raw quote
1698 // if an inset is not allowed.
1700 case LFUN_HYPHENATION:
1701 case LFUN_LIGATURE_BREAK:
1703 case LFUN_MENU_SEPARATOR:
1705 case LFUN_END_OF_SENTENCE:
1706 code = InsetBase::SPECIALCHAR_CODE;
1708 case LFUN_SPACE_INSERT:
1709 // slight hack: we know this is allowed in math mode
1711 code = InsetBase::SPACE_CODE;
1713 case LFUN_INSET_DIALOG_SHOW: {
1714 InsetBase * inset = cur.nextInset();
1717 code = inset->lyxCode();
1718 if (!(code == InsetBase::INCLUDE_CODE
1719 || code == InsetBase::BIBTEX_CODE
1720 || code == InsetBase::FLOAT_LIST_CODE
1721 || code == InsetBase::TOC_CODE))
1730 if (code != InsetBase::NO_CODE
1731 && (cur.empty() || !cur.inset().insetAllowed(code)))
1736 case LFUN_DIALOG_SHOW_NEW_INSET:
1737 case LFUN_INSET_ERT:
1738 case LFUN_INSERT_BOX:
1739 case LFUN_INSERT_BRANCH:
1740 case LFUN_ENVIRONMENT_INSERT:
1741 case LFUN_INDEX_INSERT:
1742 case LFUN_INDEX_PRINT:
1743 case LFUN_TOC_INSERT:
1747 case LFUN_HYPHENATION:
1748 case LFUN_LIGATURE_BREAK:
1750 case LFUN_MENU_SEPARATOR:
1752 case LFUN_END_OF_SENTENCE:
1753 case LFUN_SPACE_INSERT:
1754 case LFUN_INSET_DIALOG_SHOW:
1757 case LFUN_INSET_MODIFY:
1758 // We need to disable this, because we may get called for a
1760 // InsetTabular::getStatus() -> InsetText::getStatus()
1761 // and we don't handle LFUN_INSET_MODIFY.
1766 flag.setOnOff(font.emph() == LyXFont::ON);
1770 flag.setOnOff(font.noun() == LyXFont::ON);
1774 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1778 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1782 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1786 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1789 case LFUN_DELETE_WORD_FORWARD:
1790 case LFUN_DELETE_WORD_BACKWARD:
1791 case LFUN_DELETE_LINE_FORWARD:
1792 case LFUN_WORDRIGHT:
1802 case LFUN_UP_PARAGRAPHSEL:
1803 case LFUN_DOWN_PARAGRAPHSEL:
1808 case LFUN_WORDRIGHTSEL:
1809 case LFUN_WORDLEFTSEL:
1811 case LFUN_UP_PARAGRAPH:
1812 case LFUN_DOWN_PARAGRAPH:
1817 case LFUN_BREAKLINE:
1819 case LFUN_DELETE_SKIP:
1820 case LFUN_BACKSPACE:
1821 case LFUN_BACKSPACE_SKIP:
1822 case LFUN_BREAKPARAGRAPH:
1823 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1824 case LFUN_BREAKPARAGRAPH_SKIP:
1825 case LFUN_PARAGRAPH_SPACING:
1826 case LFUN_INSET_INSERT:
1827 case LFUN_NEXT_INSET_TOGGLE:
1828 case LFUN_UPCASE_WORD:
1829 case LFUN_LOWCASE_WORD:
1830 case LFUN_CAPITALIZE_WORD:
1831 case LFUN_TRANSPOSE_CHARS:
1838 case LFUN_GETLAYOUT:
1840 case LFUN_PASTESELECTION:
1841 case LFUN_DATE_INSERT:
1842 case LFUN_SELFINSERT:
1843 case LFUN_INSERT_LABEL:
1844 case LFUN_INSERT_NOTE:
1845 case LFUN_INSERT_CHARSTYLE:
1846 case LFUN_INSET_FLOAT:
1847 case LFUN_INSET_FOOTNOTE:
1848 case LFUN_INSET_MARGINAL:
1849 case LFUN_INSET_WIDE_FLOAT:
1850 case LFUN_INSET_WRAP:
1851 case LFUN_TABULAR_INSERT:
1852 case LFUN_INSERT_LINE:
1853 case LFUN_INSERT_PAGEBREAK:
1854 case LFUN_MATH_DISPLAY:
1855 case LFUN_MATH_IMPORT_SELECTION:
1856 case LFUN_MATH_MODE:
1857 case LFUN_MATH_MACRO:
1858 case LFUN_INSERT_MATH:
1859 case LFUN_INSERT_MATRIX:
1860 case LFUN_MATH_DELIM:
1861 case LFUN_SUBSCRIPT:
1862 case LFUN_SUPERSCRIPT:
1864 case LFUN_UNDERLINE:
1865 case LFUN_FONT_SIZE:
1867 case LFUN_FREEFONT_APPLY:
1868 case LFUN_FREEFONT_UPDATE:
1869 case LFUN_LAYOUT_PARAGRAPH:
1870 case LFUN_PARAGRAPH_UPDATE:
1872 case LFUN_CIRCUMFLEX:
1882 case LFUN_SPECIAL_CARON:
1885 case LFUN_HUNG_UMLAUT:
1888 case LFUN_FLOAT_LIST:
1889 case LFUN_ACCEPT_CHANGE:
1890 case LFUN_REJECT_CHANGE:
1891 case LFUN_THESAURUS_ENTRY:
1892 case LFUN_PARAGRAPH_APPLY:
1894 case LFUN_KEYMAP_TOGGLE:
1896 case LFUN_BEGINNINGBUF:
1897 case LFUN_BEGINNINGBUFSEL:
1898 case LFUN_ENDBUFSEL:
1899 // these are handled in our dispatch()
1906 flag.enabled(enable);