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"
61 #include "mathed/math_hullinset.h"
62 #include "mathed/math_macrotemplate.h"
69 using lyx::cap::copySelection;
70 using lyx::cap::cutSelection;
71 using lyx::cap::pasteSelection;
72 using lyx::cap::replaceSelection;
74 using lyx::support::isStrUnsignedInt;
75 using lyx::support::token;
79 using std::istringstream;
82 extern string current_layout;
88 LyXFont freefont(LyXFont::ALL_IGNORE);
89 bool toggleall = false;
92 void toggleAndShow(LCursor & cur, LyXText * text,
93 LyXFont const & font, bool toggleall = true)
95 text->toggleFree(cur, font, toggleall);
97 if (font.language() != ignore_language ||
98 font.number() != LyXFont::IGNORE) {
99 Paragraph & par = cur.paragraph();
100 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
101 if (cur.boundary() !=
102 text->bidi.isBoundary(cur.buffer(), par,
104 text->real_current_font))
105 text->setCursor(cur, cur.pit(), cur.pos(),
106 false, !cur.boundary());
111 void moveCursor(LCursor & cur, bool selecting)
113 if (selecting || cur.mark())
115 if (!cur.selection())
116 cur.bv().haveSelection(false);
117 cur.bv().switchKeyMap();
121 void finishChange(LCursor & cur, bool selecting)
124 moveCursor(cur, selecting);
128 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
131 string sel = cur.selectionAsString(false);
132 lyxerr << "selection is: '" << sel << "'" << endl;
135 const int old_pos = cur.pos();
136 cur.insert(new MathHullInset);
137 BOOST_ASSERT(old_pos == cur.pos());
138 cur.nextInset()->edit(cur, true);
139 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
140 // don't do that also for LFUN_MATH_MODE
141 // unless you want end up with always changing
142 // to mathrm when opening an inlined inset --
143 // I really hate "LyXfunc overloading"...
145 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
146 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
148 // create a macro if we see "\\newcommand"
149 // somewhere, and an ordinary formula
151 cutSelection(cur, true, true);
152 if (sel.find("\\newcommand") == string::npos
153 && sel.find("\\def") == string::npos)
155 cur.insert(new MathHullInset);
156 cur.dispatch(FuncRequest(LFUN_RIGHT));
157 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
158 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
160 istringstream is(sel);
161 cur.insert(new MathMacroTemplate(is));
164 cur.message(N_("Math editor mode"));
173 string const freefont2string()
176 if (font2string(freefont, toggleall, data))
183 bool LyXText::cursorPrevious(LCursor & cur)
185 pos_type cpos = cur.pos();
186 lyx::pit_type cpar = cur.pit();
188 int x = cur.x_target();
190 setCursorFromCoordinates(cur, x, 0);
191 bool updated = cursorUp(cur);
193 if (cpar == cur.pit() && cpos == cur.pos()) {
194 // we have a row which is taller than the workarea. The
195 // simplest solution is to move to the previous row instead.
196 updated |= cursorUp(cur);
199 cur.bv().updateScrollbar();
205 bool LyXText::cursorNext(LCursor & cur)
207 pos_type cpos = cur.pos();
208 lyx::pit_type cpar = cur.pit();
210 int x = cur.x_target();
211 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
212 bool updated = cursorDown(cur);
214 if (cpar == cur.pit() && cpos == cur.pos()) {
215 // we have a row which is taller than the workarea. The
216 // simplest solution is to move to the next row instead.
217 updated |= cursorDown(cur);
220 cur.bv().updateScrollbar();
228 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
230 lyx::cap::replaceSelection(cur);
231 cur.insert(new InsetSpecialChar(kind));
236 void doInsertInset(LCursor & cur, LyXText * text,
237 FuncRequest const & cmd, bool edit, bool pastesel)
239 InsetBase * inset = createInset(&cur.bv(), cmd);
245 if (cur.selection()) {
246 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
249 text->insertInset(cur, inset);
252 inset->edit(cur, true);
254 if (gotsel && pastesel)
255 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
259 void update(LCursor & cur)
261 //we don't call update(true, false) directly to save a metrics call
262 if (cur.bv().fitCursor())
263 cur.bv().update(false, true);
270 void LyXText::number(LCursor & cur)
272 LyXFont font(LyXFont::ALL_IGNORE);
273 font.setNumber(LyXFont::TOGGLE);
274 toggleAndShow(cur, this, font);
278 bool LyXText::isRTL(Paragraph const & par) const
280 return par.isRightToLeftPar(bv()->buffer()->params());
284 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
286 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
287 lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
289 BOOST_ASSERT(cur.text() == this);
290 BufferView * bv = &cur.bv();
291 CursorSlice oldTopSlice = cur.top();
292 bool sel = cur.selection();
293 bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
295 switch (cmd.action) {
297 case LFUN_APPENDIX: {
298 Paragraph & par = cur.paragraph();
299 bool start = !par.params().startOfAppendix();
302 #warning The code below only makes sense a top level.
303 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
305 // ensure that we have only one start_of_appendix in this document
306 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
307 if (pars_[tmp].params().startOfAppendix()) {
309 pars_[tmp].params().startOfAppendix(false);
315 par.params().startOfAppendix(start);
317 // we can set the refreshing parameters now
318 updateCounters(cur.buffer());
322 case LFUN_DELETE_WORD_FORWARD:
323 cur.clearSelection();
324 deleteWordForward(cur);
325 finishChange(cur, false);
328 case LFUN_DELETE_WORD_BACKWARD:
329 cur.clearSelection();
330 deleteWordBackward(cur);
331 finishChange(cur, false);
334 case LFUN_DELETE_LINE_FORWARD:
335 cur.clearSelection();
336 deleteLineForward(cur);
337 finishChange(cur, false);
342 cur.clearSelection();
343 if (isRTL(cur.paragraph()))
344 needsUpdate = cursorLeftOneWord(cur);
346 needsUpdate = cursorRightOneWord(cur);
347 finishChange(cur, false);
352 cur.clearSelection();
353 if (isRTL(cur.paragraph()))
354 needsUpdate = cursorRightOneWord(cur);
356 needsUpdate = cursorLeftOneWord(cur);
357 finishChange(cur, false);
360 case LFUN_BEGINNINGBUF:
361 if (cur.depth() == 1) {
363 cur.clearSelection();
365 finishChange(cur, false);
371 case LFUN_BEGINNINGBUFSEL:
372 if (cur.depth() == 1) {
373 if (!cur.selection())
376 finishChange(cur, true);
383 if (cur.depth() == 1) {
385 cur.clearSelection();
387 finishChange(cur, false);
394 if (cur.depth() == 1) {
395 if (!cur.selection())
398 finishChange(cur, true);
406 lyxerr << BOOST_CURRENT_FUNCTION
407 << " LFUN_RIGHT[SEL]:\n" << cur << endl;
408 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
409 if (isRTL(cur.paragraph()))
410 needsUpdate = cursorLeft(cur);
412 needsUpdate = cursorRight(cur);
413 if (!needsUpdate && oldTopSlice == cur.top()) {
415 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
421 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
422 cur.selHandle(cmd.action == LFUN_LEFTSEL);
423 if (isRTL(cur.paragraph()))
424 needsUpdate = cursorRight(cur);
426 needsUpdate = cursorLeft(cur);
427 if (oldTopSlice == cur.top()) {
429 cmd = FuncRequest(LFUN_FINISHED_LEFT);
436 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
437 cur.selHandle(cmd.action == LFUN_UPSEL);
438 needsUpdate = cursorUp(cur);
439 if (oldTopSlice == cur.top()) {
441 cmd = FuncRequest(LFUN_FINISHED_UP);
448 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
449 cur.selHandle(cmd.action == LFUN_DOWNSEL);
450 needsUpdate = cursorDown(cur);
451 if (oldTopSlice == cur.top()) {
453 cmd = FuncRequest(LFUN_FINISHED_DOWN);
457 case LFUN_UP_PARAGRAPH:
459 cur.clearSelection();
460 needsUpdate = cursorUpParagraph(cur);
461 finishChange(cur, false);
464 case LFUN_UP_PARAGRAPHSEL:
465 if (!cur.selection())
467 cursorUpParagraph(cur);
468 finishChange(cur, true);
471 case LFUN_DOWN_PARAGRAPH:
473 cur.clearSelection();
474 needsUpdate = cursorDownParagraph(cur);
475 finishChange(cur, false);
478 case LFUN_DOWN_PARAGRAPHSEL:
479 if (!cur.selection())
481 cursorDownParagraph(cur);
482 finishChange(cur, true);
487 if (!cur.selection())
490 finishChange(cur, true);
495 if (!cur.selection())
498 finishChange(cur, true);
503 if (!cur.selection())
506 finishChange(cur, true);
511 if (!cur.selection())
514 finishChange(cur, true);
517 case LFUN_WORDRIGHTSEL:
518 if (!cur.selection())
520 if (isRTL(cur.paragraph()))
521 cursorLeftOneWord(cur);
523 cursorRightOneWord(cur);
524 finishChange(cur, true);
527 case LFUN_WORDLEFTSEL:
528 if (!cur.selection())
530 if (isRTL(cur.paragraph()))
531 cursorRightOneWord(cur);
533 cursorLeftOneWord(cur);
534 finishChange(cur, true);
538 selectWord(cur, lyx::WHOLE_WORD);
539 finishChange(cur, true);
546 cur.clearSelection();
547 finishChange(cur, false);
548 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
550 cmd = FuncRequest(LFUN_FINISHED_UP);
552 needsUpdate = cursorPrevious(cur);
559 cur.clearSelection();
560 finishChange(cur, false);
561 if (cur.pit() == cur.lastpit()
562 && cur.textRow().endpos() == cur.lastpos()) {
564 cmd = FuncRequest(LFUN_FINISHED_DOWN);
566 needsUpdate = cursorNext(cur);
572 cur.clearSelection();
574 finishChange(cur, false);
579 cur.clearSelection();
581 finishChange(cur, false);
584 case LFUN_BREAKLINE: {
585 // Not allowed by LaTeX (labels or empty par)
586 if (cur.pos() > cur.paragraph().beginOfBody()) {
587 lyx::cap::replaceSelection(cur);
588 cur.insert(new InsetNewline);
590 moveCursor(cur, false);
596 if (!cur.selection()) {
599 // It is possible to make it a lot faster still
600 // just comment out the line below...
602 cutSelection(cur, true, false);
604 moveCursor(cur, false);
607 case LFUN_DELETE_SKIP:
608 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
609 if (!cur.selection()) {
610 if (cur.pos() == cur.lastpos()) {
617 cutSelection(cur, true, false);
623 if (!cur.selection()) {
624 if (bv->owner()->getIntl().getTransManager().backspace()) {
627 // It is possible to make it a lot faster still
628 // just comment out the line below...
631 cutSelection(cur, true, false);
636 case LFUN_BACKSPACE_SKIP:
637 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
638 if (!cur.selection()) {
642 //CursorSlice cur = cursor();
646 cutSelection(cur, true, false);
650 case LFUN_BREAKPARAGRAPH:
651 lyx::cap::replaceSelection(cur);
652 breakParagraph(cur, 0);
657 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
658 lyx::cap::replaceSelection(cur);
659 breakParagraph(cur, 1);
664 case LFUN_BREAKPARAGRAPH_SKIP: {
665 // When at the beginning of a paragraph, remove
666 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
667 lyx::cap::replaceSelection(cur);
669 cur.paragraph().params().labelWidthString(string());
671 breakParagraph(cur, 0);
677 case LFUN_PARAGRAPH_SPACING: {
678 Paragraph & par = cur.paragraph();
679 Spacing::Space cur_spacing = par.params().spacing().getSpace();
680 string cur_value = "1.0";
681 if (cur_spacing == Spacing::Other)
682 cur_value = par.params().spacing().getValueAsString();
684 istringstream is(cmd.argument);
687 Spacing::Space new_spacing = cur_spacing;
688 string new_value = cur_value;
690 lyxerr << "Missing argument to `paragraph-spacing'"
692 } else if (tmp == "single") {
693 new_spacing = Spacing::Single;
694 } else if (tmp == "onehalf") {
695 new_spacing = Spacing::Onehalf;
696 } else if (tmp == "double") {
697 new_spacing = Spacing::Double;
698 } else if (tmp == "other") {
699 new_spacing = Spacing::Other;
700 string tmpval = "0.0";
702 lyxerr << "new_value = " << tmpval << endl;
705 } else if (tmp == "default") {
706 new_spacing = Spacing::Default;
708 lyxerr << _("Unknown spacing argument: ")
709 << cmd.argument << endl;
711 if (cur_spacing != new_spacing || cur_value != new_value)
712 par.params().spacing(Spacing(new_spacing, new_value));
716 case LFUN_INSET_APPLY: {
717 string const name = cmd.getArg(0);
718 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
720 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
721 inset->dispatch(cur, fr);
723 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
729 case LFUN_INSET_INSERT: {
731 InsetBase * inset = createInset(bv, cmd);
733 insertInset(cur, inset);
739 case LFUN_INSET_SETTINGS:
740 if (cur.inset().asUpdatableInset())
741 cur.inset().asUpdatableInset()->showInsetDialog(bv);
744 case LFUN_NEXT_INSET_TOGGLE: {
745 InsetBase * inset = cur.nextInset();
747 cur.clearSelection();
748 FuncRequest fr = cmd;
749 fr.action = LFUN_INSET_TOGGLE;
750 inset->dispatch(cur, fr);
755 case LFUN_KEYMAP_TOGGLE:
756 cur.clearSelection();
760 case LFUN_SPACE_INSERT:
761 if (cur.paragraph().layout()->free_spacing)
762 insertChar(cur, ' ');
764 doInsertInset(cur, this, cmd, false, false);
767 moveCursor(cur, false);
770 case LFUN_HYPHENATION:
771 specialChar(cur, InsetSpecialChar::HYPHENATION);
774 case LFUN_LIGATURE_BREAK:
775 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
779 specialChar(cur, InsetSpecialChar::LDOTS);
782 case LFUN_END_OF_SENTENCE:
783 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
786 case LFUN_MENU_SEPARATOR:
787 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
790 case LFUN_UPCASE_WORD:
791 changeCase(cur, LyXText::text_uppercase);
794 case LFUN_LOWCASE_WORD:
795 changeCase(cur, LyXText::text_lowercase);
798 case LFUN_CAPITALIZE_WORD:
799 changeCase(cur, LyXText::text_capitalization);
802 case LFUN_TRANSPOSE_CHARS:
807 cur.message(_("Paste"));
808 lyx::cap::replaceSelection(cur);
810 #warning FIXME Check if the arg is in the domain of available selections.
812 if (isStrUnsignedInt(cmd.argument))
813 pasteSelection(cur, convert<unsigned int>(cmd.argument));
815 pasteSelection(cur, 0);
816 cur.clearSelection(); // bug 393
822 cutSelection(cur, true, true);
823 cur.message(_("Cut"));
828 cur.message(_("Copy"));
832 cur.message(convert<string>(cursorX(cur.top())) + ' '
833 + convert<string>(cursorY(cur.top())));
839 istringstream is(cmd.argument);
842 lyxerr << "SETXY: Could not parse coordinates in '"
843 << cmd.argument << std::endl;
845 setCursorFromCoordinates(cur, x, y);
850 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
852 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
859 cur.message(cur.paragraph().layout()->name());
863 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
864 << cmd.argument << endl;
866 // This is not the good solution to the empty argument
867 // problem, but it will hopefully suffice for 1.2.0.
868 // The correct solution would be to augument the
869 // function list/array with information about what
870 // functions needs arguments and their type.
871 if (cmd.argument.empty()) {
872 cur.errorMessage(_("LyX function 'layout' needs an argument."));
876 // Derive layout number from given argument (string)
877 // and current buffer's textclass (number)
878 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
879 bool hasLayout = tclass.hasLayout(cmd.argument);
880 string layout = cmd.argument;
882 // If the entry is obsolete, use the new one instead.
884 string const & obs = tclass[layout]->obsoleted_by();
890 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
895 bool change_layout = (current_layout != layout);
897 if (!change_layout && cur.selection() &&
898 cur.selBegin().pit() != cur.selEnd().pit())
900 pit_type spit = cur.selBegin().pit();
901 pit_type epit = cur.selEnd().pit() + 1;
902 while (spit != epit) {
903 if (pars_[spit].layout()->name() != current_layout) {
904 change_layout = true;
912 current_layout = layout;
913 setLayout(cur, layout);
914 bv->owner()->setLayout(layout);
920 case LFUN_PASTESELECTION: {
921 cur.clearSelection();
922 string const clip = bv->getClipboard();
924 if (cmd.argument == "paragraph")
925 insertStringAsParagraphs(cur, clip);
927 insertStringAsLines(cur, clip);
933 lyx::cap::replaceSelection(cur);
934 Paragraph & par = cur.paragraph();
935 lyx::pos_type pos = cur.pos();
939 else if (cur.prevInset() && cur.prevInset()->isSpace())
942 c = par.getChar(pos - 1);
944 LyXLayout_ptr const & style = par.layout();
946 BufferParams const & bufparams = bv->buffer()->params();
947 if (!style->pass_thru
948 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
949 string arg = cmd.argument;
951 cur.insert(new InsetQuotes(c,
952 bufparams.quotes_language,
953 InsetQuotes::SingleQ));
954 else if (arg == "double")
955 cur.insert(new InsetQuotes(c,
956 bufparams.quotes_language,
957 InsetQuotes::DoubleQ));
959 cur.insert(new InsetQuotes(c, bufparams));
963 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
967 case LFUN_DATE_INSERT: {
968 lyx::cap::replaceSelection(cur);
969 time_t now_time_t = time(NULL);
970 struct tm * now_tm = localtime(&now_time_t);
971 setlocale(LC_TIME, "");
973 if (!cmd.argument.empty())
976 arg = lyxrc.date_insert_format;
978 int const datetmp_len =
979 ::strftime(datetmp, 32, arg.c_str(), now_tm);
981 for (int i = 0; i < datetmp_len; i++)
982 insertChar(cur, datetmp[i]);
985 moveCursor(cur, false);
989 case LFUN_MOUSE_TRIPLE:
990 if (cmd.button() == mouse_button::button1) {
995 bv->haveSelection(cur.selection());
999 case LFUN_MOUSE_DOUBLE:
1000 if (cmd.button() == mouse_button::button1) {
1001 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1002 bv->haveSelection(cur.selection());
1006 // Single-click on work area
1007 case LFUN_MOUSE_PRESS: {
1008 // Right click on a footnote flag opens float menu
1009 if (cmd.button() == mouse_button::button3) {
1010 cur.clearSelection();
1014 // Middle button press pastes if we have a selection
1015 // We do this here as if the selection was inside an inset
1016 // it could get cleared on the unlocking of the inset so
1017 // we have to check this first
1018 bool paste_internally = false;
1019 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1020 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1021 paste_internally = true;
1024 // Clear the selection
1025 cur.clearSelection();
1027 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1032 // Has the cursor just left the inset?
1033 if (bv->cursor().inMathed() && !cur.inMathed())
1034 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1039 // Insert primary selection with middle mouse
1040 // if there is a local selection in the current buffer,
1042 if (cmd.button() == mouse_button::button2) {
1043 if (paste_internally)
1044 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1046 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1052 case LFUN_MOUSE_MOTION: {
1053 // Only use motion with button 1
1054 //if (cmd.button() != mouse_button::button1)
1057 // ignore motions deeper nested than the real anchor
1058 LCursor & bvcur = cur.bv().cursor();
1059 if (bvcur.anchor_.hasPart(cur)) {
1060 CursorSlice old = bvcur.top();
1062 int const wh = bv->workHeight();
1063 int const y = std::max(0, std::min(wh - 1, cmd.y));
1065 setCursorFromCoordinates(cur, cmd.x, y);
1066 cur.x_target() = cmd.x;
1071 // This is to allow jumping over large insets
1072 if (cur.top() == old) {
1079 if (cur.top() == old)
1082 // don't set anchor_
1083 bvcur.setCursor(cur);
1084 bvcur.selection() = true;
1085 lyxerr << "MOTION: " << bv->cursor() << endl;
1093 case LFUN_MOUSE_RELEASE: {
1094 if (cmd.button() == mouse_button::button2)
1098 if (cmd.button() == mouse_button::button1)
1099 bv->haveSelection(cur.selection());
1102 bv->owner()->updateMenubar();
1103 bv->owner()->updateToolbars();
1107 case LFUN_SELFINSERT: {
1108 if (cmd.argument.empty())
1111 // Automatically delete the currently selected
1112 // text and replace it with what is being
1113 // typed in now. Depends on lyxrc settings
1114 // "auto_region_delete", which defaults to
1117 if (lyxrc.auto_region_delete) {
1118 if (cur.selection())
1119 cutSelection(cur, false, false);
1120 bv->haveSelection(false);
1123 cur.clearSelection();
1124 LyXFont const old_font = real_current_font;
1126 string::const_iterator cit = cmd.argument.begin();
1127 string::const_iterator end = cmd.argument.end();
1128 for (; cit != end; ++cit)
1129 bv->owner()->getIntl().getTransManager().
1130 TranslateAndInsert(*cit, this);
1133 moveCursor(cur, false);
1135 // real_current_font.number can change so we need to
1136 // update the minibuffer
1137 if (old_font != real_current_font)
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_FLOAT:
1186 case LFUN_INSET_FOOTNOTE:
1187 case LFUN_INSET_MARGINAL:
1188 case LFUN_INSET_OPTARG:
1189 case LFUN_INSET_WIDE_FLOAT:
1190 case LFUN_INSET_WRAP:
1191 case LFUN_TABULAR_INSERT:
1192 case LFUN_ENVIRONMENT_INSERT:
1193 // Open the inset, and move the current selection
1195 doInsertInset(cur, this, cmd, true, true);
1199 case LFUN_INDEX_INSERT:
1200 // Just open the inset
1201 doInsertInset(cur, this, cmd, true, false);
1205 case LFUN_INDEX_PRINT:
1206 case LFUN_TOC_INSERT:
1208 case LFUN_INSERT_LINE:
1209 case LFUN_INSERT_PAGEBREAK:
1211 doInsertInset(cur, this, cmd, false, false);
1215 case LFUN_DEPTH_MIN:
1216 changeDepth(cur, DEC_DEPTH);
1219 case LFUN_DEPTH_PLUS:
1220 changeDepth(cur, INC_DEPTH);
1223 case LFUN_MATH_DISPLAY:
1224 mathDispatch(cur, cmd, true);
1227 case LFUN_MATH_IMPORT_SELECTION:
1228 case LFUN_MATH_MODE:
1229 if (cmd.argument == "on")
1230 // don't pass "on" as argument
1231 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1233 mathDispatch(cur, cmd, false);
1236 case LFUN_MATH_MACRO:
1237 if (cmd.argument.empty())
1238 cur.errorMessage(N_("Missing argument"));
1240 string s = cmd.argument;
1241 string const s1 = token(s, ' ', 1);
1242 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1243 string const s2 = token(s, ' ', 2);
1244 string const type = s2.empty() ? "newcommand" : s2;
1245 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1246 //cur.nextInset()->edit(cur, true);
1250 // passthrough hat and underscore outside mathed:
1251 case LFUN_SUBSCRIPT:
1252 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1254 case LFUN_SUPERSCRIPT:
1255 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1258 case LFUN_INSERT_MATH:
1259 case LFUN_INSERT_MATRIX:
1260 case LFUN_MATH_DELIM: {
1261 cur.insert(new MathHullInset);
1262 cur.dispatch(FuncRequest(LFUN_RIGHT));
1263 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1269 LyXFont font(LyXFont::ALL_IGNORE);
1270 font.setEmph(LyXFont::TOGGLE);
1271 toggleAndShow(cur, this, font);
1276 LyXFont font(LyXFont::ALL_IGNORE);
1277 font.setSeries(LyXFont::BOLD_SERIES);
1278 toggleAndShow(cur, this, font);
1283 LyXFont font(LyXFont::ALL_IGNORE);
1284 font.setNoun(LyXFont::TOGGLE);
1285 toggleAndShow(cur, this, font);
1290 LyXFont font(LyXFont::ALL_IGNORE);
1291 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1292 toggleAndShow(cur, this, font);
1297 LyXFont font(LyXFont::ALL_IGNORE);
1298 font.setFamily(LyXFont::SANS_FAMILY);
1299 toggleAndShow(cur, this, font);
1304 LyXFont font(LyXFont::ALL_IGNORE);
1305 font.setFamily(LyXFont::ROMAN_FAMILY);
1306 toggleAndShow(cur, this, font);
1310 case LFUN_DEFAULT: {
1311 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1312 toggleAndShow(cur, this, font);
1316 case LFUN_UNDERLINE: {
1317 LyXFont font(LyXFont::ALL_IGNORE);
1318 font.setUnderbar(LyXFont::TOGGLE);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_FONT_SIZE: {
1324 LyXFont font(LyXFont::ALL_IGNORE);
1325 font.setLyXSize(cmd.argument);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_LANGUAGE: {
1331 Language const * lang = languages.getLanguage(cmd.argument);
1334 LyXFont font(LyXFont::ALL_IGNORE);
1335 font.setLanguage(lang);
1336 toggleAndShow(cur, this, font);
1341 case LFUN_FREEFONT_APPLY:
1342 toggleAndShow(cur, this, freefont, toggleall);
1343 cur.message(_("Character set"));
1346 // Set the freefont using the contents of \param data dispatched from
1347 // the frontends and apply it at the current cursor location.
1348 case LFUN_FREEFONT_UPDATE: {
1351 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1354 toggleAndShow(cur, this, freefont, toggleall);
1355 cur.message(_("Character set"));
1360 case LFUN_FINISHED_LEFT:
1361 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1364 case LFUN_FINISHED_RIGHT:
1365 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1369 case LFUN_FINISHED_UP:
1370 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1374 case LFUN_FINISHED_DOWN:
1375 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1379 case LFUN_LAYOUT_PARAGRAPH: {
1381 params2string(cur.paragraph(), data);
1382 data = "show\n" + data;
1383 bv->owner()->getDialogs().show("paragraph", data);
1387 case LFUN_PARAGRAPH_UPDATE: {
1388 if (!bv->owner()->getDialogs().visible("paragraph"))
1391 params2string(cur.paragraph(), data);
1393 // Will the paragraph accept changes from the dialog?
1394 InsetBase & inset = cur.inset();
1395 bool const accept = !inset.forceDefaultParagraphs(&inset);
1397 data = "update " + convert<string>(accept) + '\n' + data;
1398 bv->owner()->getDialogs().update("paragraph", data);
1403 case LFUN_CIRCUMFLEX:
1413 case LFUN_SPECIAL_CARON:
1416 case LFUN_HUNG_UMLAUT:
1419 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1420 if (!cmd.argument.empty())
1421 bv->owner()->getIntl().getTransManager()
1422 .TranslateAndInsert(cmd.argument[0], this);
1425 case LFUN_FLOAT_LIST: {
1426 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1427 if (tclass.floats().typeExist(cmd.argument)) {
1428 // not quite sure if we want this...
1430 cur.clearSelection();
1431 breakParagraph(cur);
1433 if (cur.lastpos() != 0) {
1435 breakParagraph(cur);
1438 setLayout(cur, tclass.defaultLayoutName());
1439 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1440 insertInset(cur, new InsetFloatList(cmd.argument));
1443 lyxerr << "Non-existent float type: "
1444 << cmd.argument << endl;
1449 case LFUN_ACCEPT_CHANGE: {
1454 case LFUN_REJECT_CHANGE: {
1459 case LFUN_THESAURUS_ENTRY: {
1460 string arg = cmd.argument;
1462 arg = cur.selectionAsString(false);
1464 if (arg.size() > 100 || arg.empty()) {
1465 // Get word or selection
1466 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1467 arg = cur.selectionAsString(false);
1470 bv->owner()->getDialogs().show("thesaurus", arg);
1474 case LFUN_PARAGRAPH_APPLY: {
1475 // Given data, an encoding of the ParagraphParameters
1476 // generated in the Paragraph dialog, this function sets
1477 // the current paragraph appropriately.
1478 istringstream is(cmd.argument);
1481 ParagraphParameters params;
1486 params.labelWidthString(),
1488 cur.message(_("Paragraph layout set"));
1492 case LFUN_INSET_DIALOG_SHOW: {
1493 InsetBase * inset = cur.nextInset();
1495 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1496 inset->dispatch(cur, fr);
1502 if (cur.selection()) {
1503 cur.selection() = false;
1506 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1511 lyxerr << BOOST_CURRENT_FUNCTION
1512 << " Not DISPATCHED by LyXText" << endl;
1518 && &oldTopSlice.inset() == &cur.inset()
1519 && oldTopSlice.idx() == cur.idx()
1521 && !cur.selection())
1528 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1529 FuncStatus & flag) const
1531 BOOST_ASSERT(cur.text() == this);
1532 LyXFont const & font = real_current_font;
1535 switch (cmd.action) {
1537 case LFUN_DEPTH_MIN:
1538 enable = changeDepthAllowed(cur, DEC_DEPTH);
1541 case LFUN_DEPTH_PLUS:
1542 enable = changeDepthAllowed(cur, INC_DEPTH);
1545 case LFUN_INSET_OPTARG:
1546 enable = numberOfOptArgs(cur.paragraph())
1547 < cur.paragraph().layout()->optionalargs;
1551 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1555 // the functions which insert insets
1556 InsetBase::Code code = InsetBase::NO_CODE;
1557 switch (cmd.action) {
1558 case LFUN_DIALOG_SHOW_NEW_INSET:
1559 if (cmd.argument == "bibitem")
1560 code = InsetBase::BIBITEM_CODE;
1561 else if (cmd.argument == "bibtex")
1562 code = InsetBase::BIBTEX_CODE;
1563 else if (cmd.argument == "box")
1564 code = InsetBase::BOX_CODE;
1565 else if (cmd.argument == "branch")
1566 code = InsetBase::BRANCH_CODE;
1567 else if (cmd.argument == "citation")
1568 code = InsetBase::CITE_CODE;
1569 else if (cmd.argument == "ert")
1570 code = InsetBase::ERT_CODE;
1571 else if (cmd.argument == "external")
1572 code = InsetBase::EXTERNAL_CODE;
1573 else if (cmd.argument == "float")
1574 code = InsetBase::FLOAT_CODE;
1575 else if (cmd.argument == "graphics")
1576 code = InsetBase::GRAPHICS_CODE;
1577 else if (cmd.argument == "include")
1578 code = InsetBase::INCLUDE_CODE;
1579 else if (cmd.argument == "index")
1580 code = InsetBase::INDEX_CODE;
1581 else if (cmd.argument == "label")
1582 code = InsetBase::LABEL_CODE;
1583 else if (cmd.argument == "note")
1584 code = InsetBase::NOTE_CODE;
1585 else if (cmd.argument == "ref")
1586 code = InsetBase::REF_CODE;
1587 else if (cmd.argument == "toc")
1588 code = InsetBase::TOC_CODE;
1589 else if (cmd.argument == "url")
1590 code = InsetBase::URL_CODE;
1591 else if (cmd.argument == "vspace")
1592 code = InsetBase::VSPACE_CODE;
1593 else if (cmd.argument == "wrap")
1594 code = InsetBase::WRAP_CODE;
1597 case LFUN_INSET_ERT:
1598 code = InsetBase::ERT_CODE;
1600 case LFUN_INSET_FOOTNOTE:
1601 code = InsetBase::FOOT_CODE;
1603 case LFUN_TABULAR_INSERT:
1604 code = InsetBase::TABULAR_CODE;
1606 case LFUN_INSET_MARGINAL:
1607 code = InsetBase::MARGIN_CODE;
1609 case LFUN_INSET_FLOAT:
1610 case LFUN_INSET_WIDE_FLOAT:
1611 code = InsetBase::FLOAT_CODE;
1613 case LFUN_INSET_WRAP:
1614 code = InsetBase::WRAP_CODE;
1616 case LFUN_FLOAT_LIST:
1617 code = InsetBase::FLOAT_LIST_CODE;
1620 case LFUN_INSET_LIST:
1621 code = InsetBase::LIST_CODE;
1623 case LFUN_INSET_THEOREM:
1624 code = InsetBase::THEOREM_CODE;
1627 case LFUN_INSET_CAPTION:
1628 code = InsetBase::CAPTION_CODE;
1630 case LFUN_INSERT_NOTE:
1631 code = InsetBase::NOTE_CODE;
1633 case LFUN_INSERT_CHARSTYLE:
1634 code = InsetBase::CHARSTYLE_CODE;
1635 if (buf->params().getLyXTextClass().charstyles().empty())
1638 case LFUN_INSERT_BOX:
1639 code = InsetBase::BOX_CODE;
1641 case LFUN_INSERT_BRANCH:
1642 code = InsetBase::BRANCH_CODE;
1643 if (buf->params().branchlist().empty())
1646 case LFUN_INSERT_LABEL:
1647 code = InsetBase::LABEL_CODE;
1649 case LFUN_INSET_OPTARG:
1650 code = InsetBase::OPTARG_CODE;
1652 case LFUN_ENVIRONMENT_INSERT:
1653 code = InsetBase::BOX_CODE;
1655 case LFUN_INDEX_INSERT:
1656 code = InsetBase::INDEX_CODE;
1658 case LFUN_INDEX_PRINT:
1659 code = InsetBase::INDEX_PRINT_CODE;
1661 case LFUN_TOC_INSERT:
1662 code = InsetBase::TOC_CODE;
1666 code = InsetBase::URL_CODE;
1669 // always allow this, since we will inset a raw quote
1670 // if an inset is not allowed.
1672 case LFUN_HYPHENATION:
1673 case LFUN_LIGATURE_BREAK:
1675 case LFUN_MENU_SEPARATOR:
1677 case LFUN_END_OF_SENTENCE:
1678 code = InsetBase::SPECIALCHAR_CODE;
1680 case LFUN_SPACE_INSERT:
1681 // slight hack: we know this is allowed in math mode
1683 code = InsetBase::SPACE_CODE;
1685 case LFUN_INSET_DIALOG_SHOW: {
1686 InsetBase * inset = cur.nextInset();
1689 code = inset->lyxCode();
1690 if (!(code == InsetBase::INCLUDE_CODE
1691 || code == InsetBase::BIBTEX_CODE
1692 || code == InsetBase::FLOAT_LIST_CODE
1693 || code == InsetBase::TOC_CODE))
1702 if (code != InsetBase::NO_CODE
1703 && (cur.empty() || !cur.inset().insetAllowed(code)))
1708 case LFUN_DIALOG_SHOW_NEW_INSET:
1709 case LFUN_INSET_ERT:
1710 case LFUN_INSERT_BOX:
1711 case LFUN_INSERT_BRANCH:
1712 case LFUN_ENVIRONMENT_INSERT:
1713 case LFUN_INDEX_INSERT:
1714 case LFUN_INDEX_PRINT:
1715 case LFUN_TOC_INSERT:
1719 case LFUN_HYPHENATION:
1720 case LFUN_LIGATURE_BREAK:
1722 case LFUN_MENU_SEPARATOR:
1724 case LFUN_END_OF_SENTENCE:
1725 case LFUN_SPACE_INSERT:
1726 case LFUN_INSET_DIALOG_SHOW:
1730 flag.setOnOff(font.emph() == LyXFont::ON);
1734 flag.setOnOff(font.noun() == LyXFont::ON);
1738 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1742 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1746 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1750 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1753 case LFUN_DELETE_WORD_FORWARD:
1754 case LFUN_DELETE_WORD_BACKWARD:
1755 case LFUN_DELETE_LINE_FORWARD:
1756 case LFUN_WORDRIGHT:
1766 case LFUN_UP_PARAGRAPHSEL:
1767 case LFUN_DOWN_PARAGRAPHSEL:
1772 case LFUN_WORDRIGHTSEL:
1773 case LFUN_WORDLEFTSEL:
1775 case LFUN_UP_PARAGRAPH:
1776 case LFUN_DOWN_PARAGRAPH:
1781 case LFUN_BREAKLINE:
1783 case LFUN_DELETE_SKIP:
1784 case LFUN_BACKSPACE:
1785 case LFUN_BACKSPACE_SKIP:
1786 case LFUN_BREAKPARAGRAPH:
1787 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1788 case LFUN_BREAKPARAGRAPH_SKIP:
1789 case LFUN_PARAGRAPH_SPACING:
1790 case LFUN_INSET_APPLY:
1791 case LFUN_INSET_INSERT:
1792 case LFUN_NEXT_INSET_TOGGLE:
1793 case LFUN_UPCASE_WORD:
1794 case LFUN_LOWCASE_WORD:
1795 case LFUN_CAPITALIZE_WORD:
1796 case LFUN_TRANSPOSE_CHARS:
1803 case LFUN_GETLAYOUT:
1805 case LFUN_PASTESELECTION:
1806 case LFUN_DATE_INSERT:
1807 case LFUN_SELFINSERT:
1808 case LFUN_INSERT_LABEL:
1809 case LFUN_INSERT_NOTE:
1810 case LFUN_INSERT_CHARSTYLE:
1811 case LFUN_INSERT_BIBITEM:
1812 case LFUN_INSET_FLOAT:
1813 case LFUN_INSET_FOOTNOTE:
1814 case LFUN_INSET_MARGINAL:
1815 case LFUN_INSET_WIDE_FLOAT:
1816 case LFUN_INSET_WRAP:
1817 case LFUN_TABULAR_INSERT:
1818 case LFUN_INSERT_LINE:
1819 case LFUN_INSERT_PAGEBREAK:
1820 case LFUN_MATH_DISPLAY:
1821 case LFUN_MATH_IMPORT_SELECTION:
1822 case LFUN_MATH_MODE:
1823 case LFUN_MATH_MACRO:
1824 case LFUN_INSERT_MATH:
1825 case LFUN_INSERT_MATRIX:
1826 case LFUN_MATH_DELIM:
1827 case LFUN_SUBSCRIPT:
1828 case LFUN_SUPERSCRIPT:
1830 case LFUN_UNDERLINE:
1831 case LFUN_FONT_SIZE:
1833 case LFUN_FREEFONT_APPLY:
1834 case LFUN_FREEFONT_UPDATE:
1835 case LFUN_LAYOUT_PARAGRAPH:
1836 case LFUN_PARAGRAPH_UPDATE:
1838 case LFUN_CIRCUMFLEX:
1848 case LFUN_SPECIAL_CARON:
1851 case LFUN_HUNG_UMLAUT:
1854 case LFUN_FLOAT_LIST:
1855 case LFUN_ACCEPT_CHANGE:
1856 case LFUN_REJECT_CHANGE:
1857 case LFUN_THESAURUS_ENTRY:
1858 case LFUN_PARAGRAPH_APPLY:
1860 case LFUN_KEYMAP_TOGGLE:
1862 case LFUN_BEGINNINGBUF:
1863 case LFUN_BEGINNINGBUFSEL:
1864 case LFUN_ENDBUFSEL:
1865 // these are handled in our dispatch()
1872 flag.enabled(enable);