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));
964 cur.insert(new InsetQuotes(c,
965 bufparams.quotes_language,
966 InsetQuotes::DoubleQ));
970 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
974 case LFUN_DATE_INSERT:
975 if (cmd.argument.empty())
976 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
977 lyx::formatted_time(lyx::current_time())));
979 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
980 lyx::formatted_time(lyx::current_time(), cmd.argument)));
983 case LFUN_MOUSE_TRIPLE:
984 if (cmd.button() == mouse_button::button1) {
990 bv->haveSelection(cur.selection());
994 case LFUN_MOUSE_DOUBLE:
995 if (cmd.button() == mouse_button::button1) {
996 selectWord(cur, lyx::WHOLE_WORD_STRICT);
998 bv->haveSelection(cur.selection());
1002 // Single-click on work area
1003 case LFUN_MOUSE_PRESS: {
1004 // Right click on a footnote flag opens float menu
1005 if (cmd.button() == mouse_button::button3) {
1006 cur.clearSelection();
1010 // Middle button press pastes if we have a selection
1011 // We do this here as if the selection was inside an inset
1012 // it could get cleared on the unlocking of the inset so
1013 // we have to check this first
1014 bool paste_internally = false;
1015 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1016 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1017 paste_internally = true;
1020 // Clear the selection
1021 cur.clearSelection();
1023 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1028 // Has the cursor just left the inset?
1029 if (bv->cursor().inMathed() && !cur.inMathed())
1030 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1035 // Insert primary selection with middle mouse
1036 // if there is a local selection in the current buffer,
1038 if (cmd.button() == mouse_button::button2) {
1039 if (paste_internally)
1040 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1042 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1048 case LFUN_MOUSE_MOTION: {
1049 // Only use motion with button 1
1050 //if (cmd.button() != mouse_button::button1)
1053 // ignore motions deeper nested than the real anchor
1054 LCursor & bvcur = cur.bv().cursor();
1055 if (bvcur.anchor_.hasPart(cur)) {
1056 CursorSlice old = bvcur.top();
1058 int const wh = bv->workHeight();
1059 int const y = std::max(0, std::min(wh - 1, cmd.y));
1061 setCursorFromCoordinates(cur, cmd.x, y);
1062 cur.x_target() = cmd.x;
1067 // This is to allow jumping over large insets
1068 if (cur.top() == old) {
1075 if (cur.top() == old)
1078 // don't set anchor_
1079 bvcur.setCursor(cur);
1080 bvcur.selection() = true;
1081 //lyxerr << "MOTION: " << bv->cursor() << endl;
1089 case LFUN_MOUSE_RELEASE: {
1090 if (cmd.button() == mouse_button::button2)
1094 if (cmd.button() == mouse_button::button1)
1095 bv->haveSelection(cur.selection());
1098 bv->owner()->updateMenubar();
1099 bv->owner()->updateToolbars();
1103 case LFUN_SELFINSERT: {
1104 if (cmd.argument.empty())
1107 // Automatically delete the currently selected
1108 // text and replace it with what is being
1109 // typed in now. Depends on lyxrc settings
1110 // "auto_region_delete", which defaults to
1113 if (lyxrc.auto_region_delete) {
1114 if (cur.selection())
1115 cutSelection(cur, false, false);
1116 bv->haveSelection(false);
1119 cur.clearSelection();
1120 LyXFont const old_font = real_current_font;
1122 // Prevents language turds in new lyxtexts under non-english
1123 BufferParams const & bufparams = cur.buffer().params();
1124 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1125 current_font.setLanguage(lang);
1126 real_current_font.setLanguage(lang);
1128 string::const_iterator cit = cmd.argument.begin();
1129 string::const_iterator end = cmd.argument.end();
1130 for (; cit != end; ++cit)
1131 bv->owner()->getIntl().getTransManager().
1132 TranslateAndInsert(*cit, this);
1135 moveCursor(cur, false);
1136 bv->updateScrollbar();
1141 InsetCommandParams p("url");
1142 string const data = InsetCommandMailer::params2string("url", p);
1143 bv->owner()->getDialogs().show("url", data, 0);
1147 case LFUN_HTMLURL: {
1148 InsetCommandParams p("htmlurl");
1149 string const data = InsetCommandMailer::params2string("url", p);
1150 bv->owner()->getDialogs().show("url", data, 0);
1154 case LFUN_INSERT_LABEL: {
1155 // Try to generate a valid label
1156 string const contents = cmd.argument.empty() ?
1157 cur.getPossibleLabel() : cmd.argument;
1159 InsetCommandParams p("label", contents);
1160 string const data = InsetCommandMailer::params2string("label", p);
1162 if (cmd.argument.empty()) {
1163 bv->owner()->getDialogs().show("label", data, 0);
1165 FuncRequest fr(LFUN_INSET_INSERT, data);
1173 case LFUN_INSET_LIST:
1174 case LFUN_INSET_THEOREM:
1175 case LFUN_INSET_CAPTION:
1177 case LFUN_INSERT_NOTE:
1178 case LFUN_INSERT_CHARSTYLE:
1179 case LFUN_INSERT_BOX:
1180 case LFUN_INSERT_BRANCH:
1181 case LFUN_INSERT_BIBITEM:
1182 case LFUN_INSET_ERT:
1183 case LFUN_INSET_FOOTNOTE:
1184 case LFUN_INSET_MARGINAL:
1185 case LFUN_INSET_OPTARG:
1186 case LFUN_ENVIRONMENT_INSERT:
1187 // Open the inset, and move the current selection
1189 doInsertInset(cur, this, cmd, true, true);
1193 case LFUN_TABULAR_INSERT:
1194 // if there were no arguments, just open the dialog
1195 if (doInsertInset(cur, this, cmd, false, true))
1198 bv->owner()->getDialogs().show("tabularcreate");
1202 case LFUN_INSET_FLOAT:
1203 case LFUN_INSET_WIDE_FLOAT:
1204 case LFUN_INSET_WRAP:
1205 doInsertInset(cur, this, cmd, true, true);
1207 // FIXME: the "Caption" name should not be hardcoded,
1208 // but given by the float definition.
1209 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1212 case LFUN_INDEX_INSERT:
1213 // Just open the inset
1214 doInsertInset(cur, this, cmd, true, false);
1218 case LFUN_INDEX_PRINT:
1219 case LFUN_TOC_INSERT:
1221 case LFUN_INSERT_LINE:
1222 case LFUN_INSERT_PAGEBREAK:
1224 doInsertInset(cur, this, cmd, false, false);
1228 case LFUN_DEPTH_MIN:
1229 changeDepth(cur, DEC_DEPTH);
1232 case LFUN_DEPTH_PLUS:
1233 changeDepth(cur, INC_DEPTH);
1236 case LFUN_MATH_DISPLAY:
1237 mathDispatch(cur, cmd, true);
1240 case LFUN_MATH_IMPORT_SELECTION:
1241 case LFUN_MATH_MODE:
1242 if (cmd.argument == "on")
1243 // don't pass "on" as argument
1244 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1246 mathDispatch(cur, cmd, false);
1249 case LFUN_MATH_MACRO:
1250 if (cmd.argument.empty())
1251 cur.errorMessage(N_("Missing argument"));
1253 string s = cmd.argument;
1254 string const s1 = token(s, ' ', 1);
1255 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1256 string const s2 = token(s, ' ', 2);
1257 string const type = s2.empty() ? "newcommand" : s2;
1258 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1259 //cur.nextInset()->edit(cur, true);
1263 // passthrough hat and underscore outside mathed:
1264 case LFUN_SUBSCRIPT:
1265 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1267 case LFUN_SUPERSCRIPT:
1268 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1271 case LFUN_INSERT_MATH:
1272 case LFUN_INSERT_MATRIX:
1273 case LFUN_MATH_DELIM: {
1274 cur.insert(new MathHullInset("simple"));
1275 cur.dispatch(FuncRequest(LFUN_RIGHT));
1281 LyXFont font(LyXFont::ALL_IGNORE);
1282 font.setEmph(LyXFont::TOGGLE);
1283 toggleAndShow(cur, this, font);
1288 LyXFont font(LyXFont::ALL_IGNORE);
1289 font.setSeries(LyXFont::BOLD_SERIES);
1290 toggleAndShow(cur, this, font);
1295 LyXFont font(LyXFont::ALL_IGNORE);
1296 font.setNoun(LyXFont::TOGGLE);
1297 toggleAndShow(cur, this, font);
1302 LyXFont font(LyXFont::ALL_IGNORE);
1303 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1304 toggleAndShow(cur, this, font);
1309 LyXFont font(LyXFont::ALL_IGNORE);
1310 font.setFamily(LyXFont::SANS_FAMILY);
1311 toggleAndShow(cur, this, font);
1316 LyXFont font(LyXFont::ALL_IGNORE);
1317 font.setFamily(LyXFont::ROMAN_FAMILY);
1318 toggleAndShow(cur, this, font);
1322 case LFUN_DEFAULT: {
1323 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1324 toggleAndShow(cur, this, font);
1328 case LFUN_UNDERLINE: {
1329 LyXFont font(LyXFont::ALL_IGNORE);
1330 font.setUnderbar(LyXFont::TOGGLE);
1331 toggleAndShow(cur, this, font);
1335 case LFUN_FONT_SIZE: {
1336 LyXFont font(LyXFont::ALL_IGNORE);
1337 font.setLyXSize(cmd.argument);
1338 toggleAndShow(cur, this, font);
1342 case LFUN_LANGUAGE: {
1343 Language const * lang = languages.getLanguage(cmd.argument);
1346 LyXFont font(LyXFont::ALL_IGNORE);
1347 font.setLanguage(lang);
1348 toggleAndShow(cur, this, font);
1353 case LFUN_FREEFONT_APPLY:
1354 toggleAndShow(cur, this, freefont, toggleall);
1355 cur.message(_("Character set"));
1358 // Set the freefont using the contents of \param data dispatched from
1359 // the frontends and apply it at the current cursor location.
1360 case LFUN_FREEFONT_UPDATE: {
1363 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1366 toggleAndShow(cur, this, freefont, toggleall);
1367 cur.message(_("Character set"));
1372 case LFUN_FINISHED_LEFT:
1373 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1376 case LFUN_FINISHED_RIGHT:
1377 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1381 case LFUN_FINISHED_UP:
1382 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1386 case LFUN_FINISHED_DOWN:
1387 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1391 case LFUN_LAYOUT_PARAGRAPH: {
1393 params2string(cur.paragraph(), data);
1394 data = "show\n" + data;
1395 bv->owner()->getDialogs().show("paragraph", data);
1399 case LFUN_PARAGRAPH_UPDATE: {
1400 if (!bv->owner()->getDialogs().visible("paragraph"))
1403 params2string(cur.paragraph(), data);
1405 // Will the paragraph accept changes from the dialog?
1406 InsetBase & inset = cur.inset();
1407 bool const accept = !inset.forceDefaultParagraphs(&inset);
1409 data = "update " + convert<string>(accept) + '\n' + data;
1410 bv->owner()->getDialogs().update("paragraph", data);
1415 case LFUN_CIRCUMFLEX:
1425 case LFUN_SPECIAL_CARON:
1428 case LFUN_HUNG_UMLAUT:
1431 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1432 if (!cmd.argument.empty())
1433 bv->owner()->getIntl().getTransManager()
1434 .TranslateAndInsert(cmd.argument[0], this);
1437 case LFUN_FLOAT_LIST: {
1438 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1439 if (tclass.floats().typeExist(cmd.argument)) {
1440 // not quite sure if we want this...
1442 cur.clearSelection();
1443 breakParagraph(cur);
1445 if (cur.lastpos() != 0) {
1447 breakParagraph(cur);
1450 setLayout(cur, tclass.defaultLayoutName());
1451 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1452 insertInset(cur, new InsetFloatList(cmd.argument));
1455 lyxerr << "Non-existent float type: "
1456 << cmd.argument << endl;
1461 case LFUN_ACCEPT_CHANGE: {
1466 case LFUN_REJECT_CHANGE: {
1471 case LFUN_THESAURUS_ENTRY: {
1472 string arg = cmd.argument;
1474 arg = cur.selectionAsString(false);
1476 if (arg.size() > 100 || arg.empty()) {
1477 // Get word or selection
1478 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1479 arg = cur.selectionAsString(false);
1482 bv->owner()->getDialogs().show("thesaurus", arg);
1486 case LFUN_PARAGRAPH_APPLY: {
1487 // Given data, an encoding of the ParagraphParameters
1488 // generated in the Paragraph dialog, this function sets
1489 // the current paragraph appropriately.
1490 istringstream is(cmd.argument);
1493 ParagraphParameters params;
1498 params.labelWidthString(),
1500 cur.message(_("Paragraph layout set"));
1504 case LFUN_INSET_DIALOG_SHOW: {
1505 InsetBase * inset = cur.nextInset();
1507 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1508 inset->dispatch(cur, fr);
1514 if (cur.selection()) {
1515 cur.selection() = false;
1518 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1523 lyxerr[Debug::ACTION]
1524 << BOOST_CURRENT_FUNCTION
1525 << ": Command " << cmd
1526 << " not DISPATCHED by LyXText" << endl;
1531 if (singleParUpdate)
1532 // Inserting characters does not change par height
1533 if (cur.paragraph().dim().asc == olddim.asc
1534 && cur.paragraph().dim().des == olddim.des) {
1535 // if so, update _only_ this paragraph
1536 cur.bv().update(Update::SinglePar | Update::Force);
1540 && &oldTopSlice.inset() == &cur.inset()
1541 && oldTopSlice.idx() == cur.idx()
1543 && !cur.selection())
1550 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1551 FuncStatus & flag) const
1553 BOOST_ASSERT(cur.text() == this);
1554 LyXFont const & font = real_current_font;
1557 switch (cmd.action) {
1559 case LFUN_DEPTH_MIN:
1560 enable = changeDepthAllowed(cur, DEC_DEPTH);
1563 case LFUN_DEPTH_PLUS:
1564 enable = changeDepthAllowed(cur, INC_DEPTH);
1567 case LFUN_INSET_OPTARG:
1568 enable = numberOfOptArgs(cur.paragraph())
1569 < cur.paragraph().layout()->optionalargs;
1573 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1576 case LFUN_INSERT_BIBITEM:
1577 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1581 // the functions which insert insets
1582 InsetBase::Code code = InsetBase::NO_CODE;
1583 switch (cmd.action) {
1584 case LFUN_DIALOG_SHOW_NEW_INSET:
1585 if (cmd.argument == "bibitem")
1586 code = InsetBase::BIBITEM_CODE;
1587 else if (cmd.argument == "bibtex")
1588 code = InsetBase::BIBTEX_CODE;
1589 else if (cmd.argument == "box")
1590 code = InsetBase::BOX_CODE;
1591 else if (cmd.argument == "branch")
1592 code = InsetBase::BRANCH_CODE;
1593 else if (cmd.argument == "citation")
1594 code = InsetBase::CITE_CODE;
1595 else if (cmd.argument == "ert")
1596 code = InsetBase::ERT_CODE;
1597 else if (cmd.argument == "external")
1598 code = InsetBase::EXTERNAL_CODE;
1599 else if (cmd.argument == "float")
1600 code = InsetBase::FLOAT_CODE;
1601 else if (cmd.argument == "graphics")
1602 code = InsetBase::GRAPHICS_CODE;
1603 else if (cmd.argument == "include")
1604 code = InsetBase::INCLUDE_CODE;
1605 else if (cmd.argument == "index")
1606 code = InsetBase::INDEX_CODE;
1607 else if (cmd.argument == "label")
1608 code = InsetBase::LABEL_CODE;
1609 else if (cmd.argument == "note")
1610 code = InsetBase::NOTE_CODE;
1611 else if (cmd.argument == "ref")
1612 code = InsetBase::REF_CODE;
1613 else if (cmd.argument == "toc")
1614 code = InsetBase::TOC_CODE;
1615 else if (cmd.argument == "url")
1616 code = InsetBase::URL_CODE;
1617 else if (cmd.argument == "vspace")
1618 code = InsetBase::VSPACE_CODE;
1619 else if (cmd.argument == "wrap")
1620 code = InsetBase::WRAP_CODE;
1623 case LFUN_INSET_ERT:
1624 code = InsetBase::ERT_CODE;
1626 case LFUN_INSET_FOOTNOTE:
1627 code = InsetBase::FOOT_CODE;
1629 case LFUN_TABULAR_INSERT:
1630 code = InsetBase::TABULAR_CODE;
1632 case LFUN_INSET_MARGINAL:
1633 code = InsetBase::MARGIN_CODE;
1635 case LFUN_INSET_FLOAT:
1636 case LFUN_INSET_WIDE_FLOAT:
1637 code = InsetBase::FLOAT_CODE;
1639 case LFUN_INSET_WRAP:
1640 code = InsetBase::WRAP_CODE;
1642 case LFUN_FLOAT_LIST:
1643 code = InsetBase::FLOAT_LIST_CODE;
1646 case LFUN_INSET_LIST:
1647 code = InsetBase::LIST_CODE;
1649 case LFUN_INSET_THEOREM:
1650 code = InsetBase::THEOREM_CODE;
1653 case LFUN_INSET_CAPTION:
1654 code = InsetBase::CAPTION_CODE;
1656 case LFUN_INSERT_NOTE:
1657 code = InsetBase::NOTE_CODE;
1659 case LFUN_INSERT_CHARSTYLE:
1660 code = InsetBase::CHARSTYLE_CODE;
1661 if (buf->params().getLyXTextClass().charstyles().empty())
1664 case LFUN_INSERT_BOX:
1665 code = InsetBase::BOX_CODE;
1667 case LFUN_INSERT_BRANCH:
1668 code = InsetBase::BRANCH_CODE;
1669 if (buf->params().branchlist().empty())
1672 case LFUN_INSERT_LABEL:
1673 code = InsetBase::LABEL_CODE;
1675 case LFUN_INSET_OPTARG:
1676 code = InsetBase::OPTARG_CODE;
1678 case LFUN_ENVIRONMENT_INSERT:
1679 code = InsetBase::BOX_CODE;
1681 case LFUN_INDEX_INSERT:
1682 code = InsetBase::INDEX_CODE;
1684 case LFUN_INDEX_PRINT:
1685 code = InsetBase::INDEX_PRINT_CODE;
1687 case LFUN_TOC_INSERT:
1688 code = InsetBase::TOC_CODE;
1692 code = InsetBase::URL_CODE;
1695 // always allow this, since we will inset a raw quote
1696 // if an inset is not allowed.
1698 case LFUN_HYPHENATION:
1699 case LFUN_LIGATURE_BREAK:
1701 case LFUN_MENU_SEPARATOR:
1703 case LFUN_END_OF_SENTENCE:
1704 code = InsetBase::SPECIALCHAR_CODE;
1706 case LFUN_SPACE_INSERT:
1707 // slight hack: we know this is allowed in math mode
1709 code = InsetBase::SPACE_CODE;
1711 case LFUN_INSET_DIALOG_SHOW: {
1712 InsetBase * inset = cur.nextInset();
1715 code = inset->lyxCode();
1716 if (!(code == InsetBase::INCLUDE_CODE
1717 || code == InsetBase::BIBTEX_CODE
1718 || code == InsetBase::FLOAT_LIST_CODE
1719 || code == InsetBase::TOC_CODE))
1728 if (code != InsetBase::NO_CODE
1729 && (cur.empty() || !cur.inset().insetAllowed(code)))
1734 case LFUN_DIALOG_SHOW_NEW_INSET:
1735 case LFUN_INSET_ERT:
1736 case LFUN_INSERT_BOX:
1737 case LFUN_INSERT_BRANCH:
1738 case LFUN_ENVIRONMENT_INSERT:
1739 case LFUN_INDEX_INSERT:
1740 case LFUN_INDEX_PRINT:
1741 case LFUN_TOC_INSERT:
1745 case LFUN_HYPHENATION:
1746 case LFUN_LIGATURE_BREAK:
1748 case LFUN_MENU_SEPARATOR:
1750 case LFUN_END_OF_SENTENCE:
1751 case LFUN_SPACE_INSERT:
1752 case LFUN_INSET_DIALOG_SHOW:
1755 case LFUN_INSET_MODIFY:
1756 // We need to disable this, because we may get called for a
1758 // InsetTabular::getStatus() -> InsetText::getStatus()
1759 // and we don't handle LFUN_INSET_MODIFY.
1764 flag.setOnOff(font.emph() == LyXFont::ON);
1768 flag.setOnOff(font.noun() == LyXFont::ON);
1772 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1776 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1780 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1784 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1787 case LFUN_DELETE_WORD_FORWARD:
1788 case LFUN_DELETE_WORD_BACKWARD:
1789 case LFUN_DELETE_LINE_FORWARD:
1790 case LFUN_WORDRIGHT:
1800 case LFUN_UP_PARAGRAPHSEL:
1801 case LFUN_DOWN_PARAGRAPHSEL:
1806 case LFUN_WORDRIGHTSEL:
1807 case LFUN_WORDLEFTSEL:
1809 case LFUN_UP_PARAGRAPH:
1810 case LFUN_DOWN_PARAGRAPH:
1815 case LFUN_BREAKLINE:
1817 case LFUN_DELETE_SKIP:
1818 case LFUN_BACKSPACE:
1819 case LFUN_BACKSPACE_SKIP:
1820 case LFUN_BREAKPARAGRAPH:
1821 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1822 case LFUN_BREAKPARAGRAPH_SKIP:
1823 case LFUN_PARAGRAPH_SPACING:
1824 case LFUN_INSET_INSERT:
1825 case LFUN_NEXT_INSET_TOGGLE:
1826 case LFUN_UPCASE_WORD:
1827 case LFUN_LOWCASE_WORD:
1828 case LFUN_CAPITALIZE_WORD:
1829 case LFUN_TRANSPOSE_CHARS:
1836 case LFUN_GETLAYOUT:
1838 case LFUN_PASTESELECTION:
1839 case LFUN_DATE_INSERT:
1840 case LFUN_SELFINSERT:
1841 case LFUN_INSERT_LABEL:
1842 case LFUN_INSERT_NOTE:
1843 case LFUN_INSERT_CHARSTYLE:
1844 case LFUN_INSET_FLOAT:
1845 case LFUN_INSET_FOOTNOTE:
1846 case LFUN_INSET_MARGINAL:
1847 case LFUN_INSET_WIDE_FLOAT:
1848 case LFUN_INSET_WRAP:
1849 case LFUN_TABULAR_INSERT:
1850 case LFUN_INSERT_LINE:
1851 case LFUN_INSERT_PAGEBREAK:
1852 case LFUN_MATH_DISPLAY:
1853 case LFUN_MATH_IMPORT_SELECTION:
1854 case LFUN_MATH_MODE:
1855 case LFUN_MATH_MACRO:
1856 case LFUN_INSERT_MATH:
1857 case LFUN_INSERT_MATRIX:
1858 case LFUN_MATH_DELIM:
1859 case LFUN_SUBSCRIPT:
1860 case LFUN_SUPERSCRIPT:
1862 case LFUN_UNDERLINE:
1863 case LFUN_FONT_SIZE:
1865 case LFUN_FREEFONT_APPLY:
1866 case LFUN_FREEFONT_UPDATE:
1867 case LFUN_LAYOUT_PARAGRAPH:
1868 case LFUN_PARAGRAPH_UPDATE:
1870 case LFUN_CIRCUMFLEX:
1880 case LFUN_SPECIAL_CARON:
1883 case LFUN_HUNG_UMLAUT:
1886 case LFUN_FLOAT_LIST:
1887 case LFUN_ACCEPT_CHANGE:
1888 case LFUN_REJECT_CHANGE:
1889 case LFUN_THESAURUS_ENTRY:
1890 case LFUN_PARAGRAPH_APPLY:
1892 case LFUN_KEYMAP_TOGGLE:
1894 case LFUN_BEGINNINGBUF:
1895 case LFUN_BEGINNINGBUFSEL:
1896 case LFUN_ENDBUFSEL:
1897 // these are handled in our dispatch()
1904 flag.enabled(enable);