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 "bufferparams.h"
24 #include "BufferView.h"
26 #include "coordcache.h"
27 #include "CutAndPaste.h"
29 #include "dispatchresult.h"
31 #include "funcrequest.h"
35 #include "LyXAction.h"
40 #include "paragraph.h"
41 #include "paragraph_funcs.h"
42 #include "ParagraphParameters.h"
46 #include "frontends/Dialogs.h"
47 #include "frontends/LyXView.h"
49 #include "insets/insetcommand.h"
50 #include "insets/insetfloatlist.h"
51 #include "insets/insetnewline.h"
52 #include "insets/insetquotes.h"
53 #include "insets/insetspecialchar.h"
54 #include "insets/insettext.h"
56 #include "support/lstrings.h"
57 #include "support/lyxlib.h"
58 #include "support/convert.h"
60 #include "mathed/math_hullinset.h"
61 #include "mathed/math_macrotemplate.h"
68 using lyx::cap::copySelection;
69 using lyx::cap::cutSelection;
70 using lyx::cap::pasteSelection;
71 using lyx::cap::replaceSelection;
73 using lyx::support::isStrUnsignedInt;
74 using lyx::support::token;
78 using std::istringstream;
81 extern string current_layout;
87 LyXFont freefont(LyXFont::ALL_IGNORE);
88 bool toggleall = false;
91 void toggleAndShow(LCursor & cur, LyXText * text,
92 LyXFont const & font, bool toggleall = true)
94 text->toggleFree(cur, font, toggleall);
96 if (font.language() != ignore_language ||
97 font.number() != LyXFont::IGNORE) {
98 Paragraph & par = cur.paragraph();
99 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
100 if (cur.boundary() !=
101 text->bidi.isBoundary(cur.buffer(), par,
103 text->real_current_font))
104 text->setCursor(cur, cur.pit(), cur.pos(),
105 false, !cur.boundary());
110 void moveCursor(LCursor & cur, bool selecting)
112 if (selecting || cur.mark())
114 if (!cur.selection())
115 cur.bv().haveSelection(false);
116 cur.bv().switchKeyMap();
120 void finishChange(LCursor & cur, bool selecting)
123 moveCursor(cur, selecting);
127 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
130 string sel = cur.selectionAsString(false);
131 lyxerr << "selection is: '" << sel << "'" << endl;
134 const int old_pos = cur.pos();
135 cur.insert(new MathHullInset);
136 BOOST_ASSERT(old_pos == cur.pos());
137 cur.nextInset()->edit(cur, true);
138 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
139 // don't do that also for LFUN_MATH_MODE
140 // unless you want end up with always changing
141 // to mathrm when opening an inlined inset --
142 // I really hate "LyXfunc overloading"...
144 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
145 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
147 // create a macro if we see "\\newcommand"
148 // somewhere, and an ordinary formula
150 cutSelection(cur, true, true);
151 if (sel.find("\\newcommand") == string::npos
152 && sel.find("\\def") == string::npos)
154 cur.insert(new MathHullInset);
155 cur.dispatch(FuncRequest(LFUN_RIGHT));
156 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
157 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
159 istringstream is(sel);
160 cur.insert(new MathMacroTemplate(is));
163 cur.message(N_("Math editor mode"));
172 string const freefont2string()
175 if (font2string(freefont, toggleall, data))
182 bool LyXText::cursorPrevious(LCursor & cur)
184 pos_type cpos = cur.pos();
185 lyx::pit_type cpar = cur.pit();
187 int x = cur.x_target();
189 setCursorFromCoordinates(cur, x, 0);
190 bool updated = cursorUp(cur);
192 if (cpar == cur.pit() && cpos == cur.pos()) {
193 // we have a row which is taller than the workarea. The
194 // simplest solution is to move to the previous row instead.
195 updated |= cursorUp(cur);
198 cur.bv().updateScrollbar();
204 bool LyXText::cursorNext(LCursor & cur)
206 pos_type cpos = cur.pos();
207 lyx::pit_type cpar = cur.pit();
209 int x = cur.x_target();
210 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
211 bool updated = cursorDown(cur);
213 if (cpar == cur.pit() && cpos == cur.pos()) {
214 // we have a row which is taller than the workarea. The
215 // simplest solution is to move to the next row instead.
216 updated |= cursorDown(cur);
219 cur.bv().updateScrollbar();
227 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
229 lyx::cap::replaceSelection(cur);
230 cur.insert(new InsetSpecialChar(kind));
235 void doInsertInset(LCursor & cur, LyXText * text,
236 FuncRequest const & cmd, bool edit, bool pastesel)
238 InsetBase * inset = createInset(&cur.bv(), cmd);
244 if (cur.selection()) {
245 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
248 text->insertInset(cur, inset);
251 inset->edit(cur, true);
253 if (gotsel && pastesel)
254 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
258 void update(LCursor & cur)
260 //we don't call update(true, false) directly to save a metrics call
261 if (cur.bv().fitCursor())
262 cur.bv().update(false, true);
269 void LyXText::number(LCursor & cur)
271 LyXFont font(LyXFont::ALL_IGNORE);
272 font.setNumber(LyXFont::TOGGLE);
273 toggleAndShow(cur, this, font);
277 bool LyXText::isRTL(Paragraph const & par) const
279 return par.isRightToLeftPar(bv()->buffer()->params());
283 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
285 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
286 lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
288 BOOST_ASSERT(cur.text() == this);
289 BufferView * bv = &cur.bv();
290 CursorSlice oldTopSlice = cur.top();
291 bool sel = cur.selection();
292 bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
294 switch (cmd.action) {
296 case LFUN_APPENDIX: {
297 Paragraph & par = cur.paragraph();
298 bool start = !par.params().startOfAppendix();
300 // ensure that we have only one start_of_appendix in this document
301 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
302 if (pars_[tmp].params().startOfAppendix()) {
304 pars_[tmp].params().startOfAppendix(false);
310 par.params().startOfAppendix(start);
312 // we can set the refreshing parameters now
317 case LFUN_DELETE_WORD_FORWARD:
318 cur.clearSelection();
319 deleteWordForward(cur);
320 finishChange(cur, false);
323 case LFUN_DELETE_WORD_BACKWARD:
324 cur.clearSelection();
325 deleteWordBackward(cur);
326 finishChange(cur, false);
329 case LFUN_DELETE_LINE_FORWARD:
330 cur.clearSelection();
331 deleteLineForward(cur);
332 finishChange(cur, false);
337 cur.clearSelection();
338 if (isRTL(cur.paragraph()))
339 needsUpdate = cursorLeftOneWord(cur);
341 needsUpdate = cursorRightOneWord(cur);
342 finishChange(cur, false);
347 cur.clearSelection();
348 if (isRTL(cur.paragraph()))
349 needsUpdate = cursorRightOneWord(cur);
351 needsUpdate = cursorLeftOneWord(cur);
352 finishChange(cur, false);
355 case LFUN_BEGINNINGBUF:
356 if (cur.depth() == 1) {
358 cur.clearSelection();
360 finishChange(cur, false);
366 case LFUN_BEGINNINGBUFSEL:
367 if (cur.depth() == 1) {
368 if (!cur.selection())
371 finishChange(cur, true);
378 if (cur.depth() == 1) {
380 cur.clearSelection();
382 finishChange(cur, false);
389 if (cur.depth() == 1) {
390 if (!cur.selection())
393 finishChange(cur, true);
401 lyxerr << BOOST_CURRENT_FUNCTION
402 << " LFUN_RIGHT[SEL]:\n" << cur << endl;
403 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
404 if (isRTL(cur.paragraph()))
405 needsUpdate = cursorLeft(cur);
407 needsUpdate = cursorRight(cur);
408 if (!needsUpdate && oldTopSlice == cur.top()) {
410 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
416 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
417 cur.selHandle(cmd.action == LFUN_LEFTSEL);
418 if (isRTL(cur.paragraph()))
419 needsUpdate = cursorRight(cur);
421 needsUpdate = cursorLeft(cur);
422 if (oldTopSlice == cur.top()) {
424 cmd = FuncRequest(LFUN_FINISHED_LEFT);
431 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
432 cur.selHandle(cmd.action == LFUN_UPSEL);
433 needsUpdate = cursorUp(cur);
434 if (oldTopSlice == cur.top()) {
436 cmd = FuncRequest(LFUN_FINISHED_UP);
443 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
444 cur.selHandle(cmd.action == LFUN_DOWNSEL);
445 needsUpdate = cursorDown(cur);
446 if (oldTopSlice == cur.top()) {
448 cmd = FuncRequest(LFUN_FINISHED_DOWN);
452 case LFUN_UP_PARAGRAPH:
454 cur.clearSelection();
455 needsUpdate = cursorUpParagraph(cur);
456 finishChange(cur, false);
459 case LFUN_UP_PARAGRAPHSEL:
460 if (!cur.selection())
462 cursorUpParagraph(cur);
463 finishChange(cur, true);
466 case LFUN_DOWN_PARAGRAPH:
468 cur.clearSelection();
469 needsUpdate = cursorDownParagraph(cur);
470 finishChange(cur, false);
473 case LFUN_DOWN_PARAGRAPHSEL:
474 if (!cur.selection())
476 cursorDownParagraph(cur);
477 finishChange(cur, true);
482 if (!cur.selection())
485 finishChange(cur, true);
490 if (!cur.selection())
493 finishChange(cur, true);
498 if (!cur.selection())
501 finishChange(cur, true);
506 if (!cur.selection())
509 finishChange(cur, true);
512 case LFUN_WORDRIGHTSEL:
513 if (!cur.selection())
515 if (isRTL(cur.paragraph()))
516 cursorLeftOneWord(cur);
518 cursorRightOneWord(cur);
519 finishChange(cur, true);
522 case LFUN_WORDLEFTSEL:
523 if (!cur.selection())
525 if (isRTL(cur.paragraph()))
526 cursorRightOneWord(cur);
528 cursorLeftOneWord(cur);
529 finishChange(cur, true);
533 selectWord(cur, lyx::WHOLE_WORD);
534 finishChange(cur, true);
541 cur.clearSelection();
542 finishChange(cur, false);
543 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
545 cmd = FuncRequest(LFUN_FINISHED_UP);
547 needsUpdate = cursorPrevious(cur);
554 cur.clearSelection();
555 finishChange(cur, false);
556 if (cur.pit() == cur.lastpit()
557 && cur.textRow().endpos() == cur.lastpos()) {
559 cmd = FuncRequest(LFUN_FINISHED_DOWN);
561 needsUpdate = cursorNext(cur);
567 cur.clearSelection();
569 finishChange(cur, false);
574 cur.clearSelection();
576 finishChange(cur, false);
579 case LFUN_BREAKLINE: {
580 // Not allowed by LaTeX (labels or empty par)
581 if (cur.pos() > cur.paragraph().beginOfBody()) {
582 lyx::cap::replaceSelection(cur);
583 cur.insert(new InsetNewline);
585 moveCursor(cur, false);
591 if (!cur.selection()) {
594 // It is possible to make it a lot faster still
595 // just comment out the line below...
597 cutSelection(cur, true, false);
599 moveCursor(cur, false);
602 case LFUN_DELETE_SKIP:
603 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
604 if (!cur.selection()) {
605 if (cur.pos() == cur.lastpos()) {
612 cutSelection(cur, true, false);
618 if (!cur.selection()) {
619 if (bv->owner()->getIntl().getTransManager().backspace()) {
622 // It is possible to make it a lot faster still
623 // just comment out the line below...
626 cutSelection(cur, true, false);
631 case LFUN_BACKSPACE_SKIP:
632 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
633 if (!cur.selection()) {
637 //CursorSlice cur = cursor();
641 cutSelection(cur, true, false);
645 case LFUN_BREAKPARAGRAPH:
646 lyx::cap::replaceSelection(cur);
647 breakParagraph(cur, 0);
652 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
653 lyx::cap::replaceSelection(cur);
654 breakParagraph(cur, 1);
659 case LFUN_BREAKPARAGRAPH_SKIP: {
660 // When at the beginning of a paragraph, remove
661 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
662 lyx::cap::replaceSelection(cur);
664 cur.paragraph().params().labelWidthString(string());
666 breakParagraph(cur, 0);
672 case LFUN_PARAGRAPH_SPACING: {
673 Paragraph & par = cur.paragraph();
674 Spacing::Space cur_spacing = par.params().spacing().getSpace();
675 string cur_value = "1.0";
676 if (cur_spacing == Spacing::Other)
677 cur_value = par.params().spacing().getValueAsString();
679 istringstream is(cmd.argument);
682 Spacing::Space new_spacing = cur_spacing;
683 string new_value = cur_value;
685 lyxerr << "Missing argument to `paragraph-spacing'"
687 } else if (tmp == "single") {
688 new_spacing = Spacing::Single;
689 } else if (tmp == "onehalf") {
690 new_spacing = Spacing::Onehalf;
691 } else if (tmp == "double") {
692 new_spacing = Spacing::Double;
693 } else if (tmp == "other") {
694 new_spacing = Spacing::Other;
695 string tmpval = "0.0";
697 lyxerr << "new_value = " << tmpval << endl;
700 } else if (tmp == "default") {
701 new_spacing = Spacing::Default;
703 lyxerr << _("Unknown spacing argument: ")
704 << cmd.argument << endl;
706 if (cur_spacing != new_spacing || cur_value != new_value)
707 par.params().spacing(Spacing(new_spacing, new_value));
711 case LFUN_INSET_APPLY: {
712 string const name = cmd.getArg(0);
713 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
715 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
716 inset->dispatch(cur, fr);
718 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
724 case LFUN_INSET_INSERT: {
726 InsetBase * inset = createInset(bv, cmd);
728 insertInset(cur, inset);
734 case LFUN_INSET_SETTINGS:
735 if (cur.inset().asUpdatableInset())
736 cur.inset().asUpdatableInset()->showInsetDialog(bv);
739 case LFUN_NEXT_INSET_TOGGLE: {
740 InsetBase * inset = cur.nextInset();
742 cur.clearSelection();
743 FuncRequest fr = cmd;
744 fr.action = LFUN_INSET_TOGGLE;
745 inset->dispatch(cur, fr);
750 case LFUN_KEYMAP_TOGGLE:
751 cur.clearSelection();
755 case LFUN_SPACE_INSERT:
756 if (cur.paragraph().layout()->free_spacing)
757 insertChar(cur, ' ');
759 doInsertInset(cur, this, cmd, false, false);
762 moveCursor(cur, false);
765 case LFUN_HYPHENATION:
766 specialChar(cur, InsetSpecialChar::HYPHENATION);
769 case LFUN_LIGATURE_BREAK:
770 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
774 specialChar(cur, InsetSpecialChar::LDOTS);
777 case LFUN_END_OF_SENTENCE:
778 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
781 case LFUN_MENU_SEPARATOR:
782 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
785 case LFUN_UPCASE_WORD:
786 changeCase(cur, LyXText::text_uppercase);
789 case LFUN_LOWCASE_WORD:
790 changeCase(cur, LyXText::text_lowercase);
793 case LFUN_CAPITALIZE_WORD:
794 changeCase(cur, LyXText::text_capitalization);
797 case LFUN_TRANSPOSE_CHARS:
802 cur.message(_("Paste"));
803 lyx::cap::replaceSelection(cur);
805 #warning FIXME Check if the arg is in the domain of available selections.
807 if (isStrUnsignedInt(cmd.argument))
808 pasteSelection(cur, convert<unsigned int>(cmd.argument));
810 pasteSelection(cur, 0);
811 cur.clearSelection(); // bug 393
817 cutSelection(cur, true, true);
818 cur.message(_("Cut"));
823 cur.message(_("Copy"));
827 cur.message(convert<string>(cursorX(cur.top())) + ' '
828 + convert<string>(cursorY(cur.top())));
834 istringstream is(cmd.argument);
837 lyxerr << "SETXY: Could not parse coordinates in '"
838 << cmd.argument << std::endl;
840 setCursorFromCoordinates(cur, x, y);
845 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
847 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
854 cur.message(cur.paragraph().layout()->name());
858 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
859 << cmd.argument << endl;
861 // This is not the good solution to the empty argument
862 // problem, but it will hopefully suffice for 1.2.0.
863 // The correct solution would be to augument the
864 // function list/array with information about what
865 // functions needs arguments and their type.
866 if (cmd.argument.empty()) {
867 cur.errorMessage(_("LyX function 'layout' needs an argument."));
871 // Derive layout number from given argument (string)
872 // and current buffer's textclass (number)
873 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
874 bool hasLayout = tclass.hasLayout(cmd.argument);
875 string layout = cmd.argument;
877 // If the entry is obsolete, use the new one instead.
879 string const & obs = tclass[layout]->obsoleted_by();
885 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
890 bool change_layout = (current_layout != layout);
892 if (!change_layout && cur.selection() &&
893 cur.selBegin().pit() != cur.selEnd().pit())
895 pit_type spit = cur.selBegin().pit();
896 pit_type epit = cur.selEnd().pit() + 1;
897 while (spit != epit) {
898 if (pars_[spit].layout()->name() != current_layout) {
899 change_layout = true;
907 current_layout = layout;
908 setLayout(cur, layout);
909 bv->owner()->setLayout(layout);
915 case LFUN_PASTESELECTION: {
916 cur.clearSelection();
917 string const clip = bv->getClipboard();
919 if (cmd.argument == "paragraph")
920 insertStringAsParagraphs(cur, clip);
922 insertStringAsLines(cur, clip);
928 lyx::cap::replaceSelection(cur);
929 Paragraph & par = cur.paragraph();
930 lyx::pos_type pos = cur.pos();
934 else if (cur.prevInset() && cur.prevInset()->isSpace())
937 c = par.getChar(pos - 1);
939 LyXLayout_ptr const & style = par.layout();
941 BufferParams const & bufparams = bv->buffer()->params();
942 if (!style->pass_thru
943 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
944 string arg = cmd.argument;
946 cur.insert(new InsetQuotes(c,
947 bufparams.quotes_language,
948 InsetQuotes::SingleQ));
949 else if (arg == "double")
950 cur.insert(new InsetQuotes(c,
951 bufparams.quotes_language,
952 InsetQuotes::DoubleQ));
954 cur.insert(new InsetQuotes(c, bufparams));
958 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
962 case LFUN_DATE_INSERT: {
963 lyx::cap::replaceSelection(cur);
964 time_t now_time_t = time(NULL);
965 struct tm * now_tm = localtime(&now_time_t);
966 setlocale(LC_TIME, "");
968 if (!cmd.argument.empty())
971 arg = lyxrc.date_insert_format;
973 int const datetmp_len =
974 ::strftime(datetmp, 32, arg.c_str(), now_tm);
976 for (int i = 0; i < datetmp_len; i++)
977 insertChar(cur, datetmp[i]);
980 moveCursor(cur, false);
984 case LFUN_MOUSE_TRIPLE:
985 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);
997 bv->haveSelection(cur.selection());
1001 // Single-click on work area
1002 case LFUN_MOUSE_PRESS: {
1003 // Right click on a footnote flag opens float menu
1004 if (cmd.button() == mouse_button::button3) {
1005 cur.clearSelection();
1009 // Middle button press pastes if we have a selection
1010 // We do this here as if the selection was inside an inset
1011 // it could get cleared on the unlocking of the inset so
1012 // we have to check this first
1013 bool paste_internally = false;
1014 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1015 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1016 paste_internally = true;
1019 // Clear the selection
1020 cur.clearSelection();
1022 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1027 // Has the cursor just left the inset?
1028 if (bv->cursor().inMathed() && !cur.inMathed())
1029 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1034 // Insert primary selection with middle mouse
1035 // if there is a local selection in the current buffer,
1037 if (cmd.button() == mouse_button::button2) {
1038 if (paste_internally)
1039 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1041 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1047 case LFUN_MOUSE_MOTION: {
1048 // Only use motion with button 1
1049 //if (cmd.button() != mouse_button::button1)
1052 // ignore motions deeper nested than the real anchor
1053 LCursor & bvcur = cur.bv().cursor();
1054 if (bvcur.anchor_.hasPart(cur)) {
1055 CursorSlice old = bvcur.top();
1057 int const wh = bv->workHeight();
1058 int const y = std::max(0, std::min(wh - 1, cmd.y));
1060 setCursorFromCoordinates(cur, cmd.x, y);
1061 cur.x_target() = cmd.x;
1066 // This is to allow jumping over large insets
1067 if (cur.top() == old) {
1074 if (cur.top() == old)
1077 // don't set anchor_
1078 bvcur.setCursor(cur);
1079 bvcur.selection() = true;
1080 lyxerr << "MOTION: " << bv->cursor() << endl;
1088 case LFUN_MOUSE_RELEASE: {
1089 if (cmd.button() == mouse_button::button2)
1093 if (cmd.button() == mouse_button::button1)
1094 bv->haveSelection(cur.selection());
1097 bv->owner()->updateMenubar();
1098 bv->owner()->updateToolbars();
1102 case LFUN_SELFINSERT: {
1103 if (cmd.argument.empty())
1106 // Automatically delete the currently selected
1107 // text and replace it with what is being
1108 // typed in now. Depends on lyxrc settings
1109 // "auto_region_delete", which defaults to
1112 if (lyxrc.auto_region_delete) {
1113 if (cur.selection())
1114 cutSelection(cur, false, false);
1115 bv->haveSelection(false);
1118 cur.clearSelection();
1119 LyXFont const old_font = real_current_font;
1121 string::const_iterator cit = cmd.argument.begin();
1122 string::const_iterator end = cmd.argument.end();
1123 for (; cit != end; ++cit)
1124 bv->owner()->getIntl().getTransManager().
1125 TranslateAndInsert(*cit, this);
1128 moveCursor(cur, false);
1130 // real_current_font.number can change so we need to
1131 // update the minibuffer
1132 if (old_font != real_current_font)
1133 bv->updateScrollbar();
1138 InsetCommandParams p("url");
1139 string const data = InsetCommandMailer::params2string("url", p);
1140 bv->owner()->getDialogs().show("url", data, 0);
1144 case LFUN_HTMLURL: {
1145 InsetCommandParams p("htmlurl");
1146 string const data = InsetCommandMailer::params2string("url", p);
1147 bv->owner()->getDialogs().show("url", data, 0);
1151 case LFUN_INSERT_LABEL: {
1152 // Try to generate a valid label
1153 string const contents = cmd.argument.empty() ?
1154 cur.getPossibleLabel() : cmd.argument;
1156 InsetCommandParams p("label", contents);
1157 string const data = InsetCommandMailer::params2string("label", p);
1159 if (cmd.argument.empty()) {
1160 bv->owner()->getDialogs().show("label", data, 0);
1162 FuncRequest fr(LFUN_INSET_INSERT, data);
1170 case LFUN_INSET_LIST:
1171 case LFUN_INSET_THEOREM:
1172 case LFUN_INSET_CAPTION:
1174 case LFUN_INSERT_NOTE:
1175 case LFUN_INSERT_CHARSTYLE:
1176 case LFUN_INSERT_BOX:
1177 case LFUN_INSERT_BRANCH:
1178 case LFUN_INSERT_BIBITEM:
1179 case LFUN_INSET_ERT:
1180 case LFUN_INSET_FLOAT:
1181 case LFUN_INSET_FOOTNOTE:
1182 case LFUN_INSET_MARGINAL:
1183 case LFUN_INSET_OPTARG:
1184 case LFUN_INSET_WIDE_FLOAT:
1185 case LFUN_INSET_WRAP:
1186 case LFUN_TABULAR_INSERT:
1187 case LFUN_ENVIRONMENT_INSERT:
1188 // Open the inset, and move the current selection
1190 doInsertInset(cur, this, cmd, true, true);
1194 case LFUN_INDEX_INSERT:
1195 // Just open the inset
1196 doInsertInset(cur, this, cmd, true, false);
1200 case LFUN_INDEX_PRINT:
1201 case LFUN_TOC_INSERT:
1203 case LFUN_INSERT_LINE:
1204 case LFUN_INSERT_PAGEBREAK:
1206 doInsertInset(cur, this, cmd, false, false);
1210 case LFUN_DEPTH_MIN:
1211 changeDepth(cur, DEC_DEPTH);
1214 case LFUN_DEPTH_PLUS:
1215 changeDepth(cur, INC_DEPTH);
1218 case LFUN_MATH_DISPLAY:
1219 mathDispatch(cur, cmd, true);
1222 case LFUN_MATH_IMPORT_SELECTION:
1223 case LFUN_MATH_MODE:
1224 if (cmd.argument == "on")
1225 // don't pass "on" as argument
1226 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1228 mathDispatch(cur, cmd, false);
1231 case LFUN_MATH_MACRO:
1232 if (cmd.argument.empty())
1233 cur.errorMessage(N_("Missing argument"));
1235 string s = cmd.argument;
1236 string const s1 = token(s, ' ', 1);
1237 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1238 string const s2 = token(s, ' ', 2);
1239 string const type = s2.empty() ? "newcommand" : s2;
1240 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1241 //cur.nextInset()->edit(cur, true);
1245 // passthrough hat and underscore outside mathed:
1246 case LFUN_SUBSCRIPT:
1247 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1249 case LFUN_SUPERSCRIPT:
1250 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1253 case LFUN_INSERT_MATH:
1254 case LFUN_INSERT_MATRIX:
1255 case LFUN_MATH_DELIM: {
1256 cur.insert(new MathHullInset);
1257 cur.dispatch(FuncRequest(LFUN_RIGHT));
1258 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1264 LyXFont font(LyXFont::ALL_IGNORE);
1265 font.setEmph(LyXFont::TOGGLE);
1266 toggleAndShow(cur, this, font);
1271 LyXFont font(LyXFont::ALL_IGNORE);
1272 font.setSeries(LyXFont::BOLD_SERIES);
1273 toggleAndShow(cur, this, font);
1278 LyXFont font(LyXFont::ALL_IGNORE);
1279 font.setNoun(LyXFont::TOGGLE);
1280 toggleAndShow(cur, this, font);
1285 LyXFont font(LyXFont::ALL_IGNORE);
1286 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1287 toggleAndShow(cur, this, font);
1292 LyXFont font(LyXFont::ALL_IGNORE);
1293 font.setFamily(LyXFont::SANS_FAMILY);
1294 toggleAndShow(cur, this, font);
1299 LyXFont font(LyXFont::ALL_IGNORE);
1300 font.setFamily(LyXFont::ROMAN_FAMILY);
1301 toggleAndShow(cur, this, font);
1305 case LFUN_DEFAULT: {
1306 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1307 toggleAndShow(cur, this, font);
1311 case LFUN_UNDERLINE: {
1312 LyXFont font(LyXFont::ALL_IGNORE);
1313 font.setUnderbar(LyXFont::TOGGLE);
1314 toggleAndShow(cur, this, font);
1318 case LFUN_FONT_SIZE: {
1319 LyXFont font(LyXFont::ALL_IGNORE);
1320 font.setLyXSize(cmd.argument);
1321 toggleAndShow(cur, this, font);
1325 case LFUN_LANGUAGE: {
1326 Language const * lang = languages.getLanguage(cmd.argument);
1329 LyXFont font(LyXFont::ALL_IGNORE);
1330 font.setLanguage(lang);
1331 toggleAndShow(cur, this, font);
1336 case LFUN_FREEFONT_APPLY:
1337 toggleAndShow(cur, this, freefont, toggleall);
1338 cur.message(_("Character set"));
1341 // Set the freefont using the contents of \param data dispatched from
1342 // the frontends and apply it at the current cursor location.
1343 case LFUN_FREEFONT_UPDATE: {
1346 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1349 toggleAndShow(cur, this, freefont, toggleall);
1350 cur.message(_("Character set"));
1355 case LFUN_FINISHED_LEFT:
1356 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1359 case LFUN_FINISHED_RIGHT:
1360 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1364 case LFUN_FINISHED_UP:
1365 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1369 case LFUN_FINISHED_DOWN:
1370 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1374 case LFUN_LAYOUT_PARAGRAPH: {
1376 params2string(cur.paragraph(), data);
1377 data = "show\n" + data;
1378 bv->owner()->getDialogs().show("paragraph", data);
1382 case LFUN_PARAGRAPH_UPDATE: {
1383 if (!bv->owner()->getDialogs().visible("paragraph"))
1386 params2string(cur.paragraph(), data);
1388 // Will the paragraph accept changes from the dialog?
1389 InsetBase & inset = cur.inset();
1390 bool const accept = !inset.forceDefaultParagraphs(&inset);
1392 data = "update " + convert<string>(accept) + '\n' + data;
1393 bv->owner()->getDialogs().update("paragraph", data);
1398 case LFUN_CIRCUMFLEX:
1408 case LFUN_SPECIAL_CARON:
1411 case LFUN_HUNG_UMLAUT:
1414 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1415 if (!cmd.argument.empty())
1416 bv->owner()->getIntl().getTransManager()
1417 .TranslateAndInsert(cmd.argument[0], this);
1420 case LFUN_FLOAT_LIST: {
1421 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1422 if (tclass.floats().typeExist(cmd.argument)) {
1423 // not quite sure if we want this...
1425 cur.clearSelection();
1426 breakParagraph(cur);
1428 if (cur.lastpos() != 0) {
1430 breakParagraph(cur);
1433 setLayout(cur, tclass.defaultLayoutName());
1434 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1435 insertInset(cur, new InsetFloatList(cmd.argument));
1438 lyxerr << "Non-existent float type: "
1439 << cmd.argument << endl;
1444 case LFUN_ACCEPT_CHANGE: {
1449 case LFUN_REJECT_CHANGE: {
1454 case LFUN_THESAURUS_ENTRY: {
1455 string arg = cmd.argument;
1457 arg = cur.selectionAsString(false);
1459 if (arg.size() > 100 || arg.empty()) {
1460 // Get word or selection
1461 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1462 arg = cur.selectionAsString(false);
1465 bv->owner()->getDialogs().show("thesaurus", arg);
1469 case LFUN_PARAGRAPH_APPLY: {
1470 // Given data, an encoding of the ParagraphParameters
1471 // generated in the Paragraph dialog, this function sets
1472 // the current paragraph appropriately.
1473 istringstream is(cmd.argument);
1476 ParagraphParameters params;
1481 params.labelWidthString(),
1483 cur.message(_("Paragraph layout set"));
1487 case LFUN_INSET_DIALOG_SHOW: {
1488 InsetBase * inset = cur.nextInset();
1490 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1491 inset->dispatch(cur, fr);
1497 if (cur.selection()) {
1498 cur.selection() = false;
1501 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1506 lyxerr << BOOST_CURRENT_FUNCTION
1507 << " Not DISPATCHED by LyXText" << endl;
1513 && &oldTopSlice.inset() == &cur.inset()
1514 && oldTopSlice.idx() == cur.idx()
1516 && !cur.selection())
1523 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1524 FuncStatus & flag) const
1526 BOOST_ASSERT(cur.text() == this);
1527 LyXFont const & font = real_current_font;
1530 switch (cmd.action) {
1532 case LFUN_DEPTH_MIN:
1533 enable = changeDepthAllowed(cur, DEC_DEPTH);
1536 case LFUN_DEPTH_PLUS:
1537 enable = changeDepthAllowed(cur, INC_DEPTH);
1540 case LFUN_INSET_OPTARG:
1541 enable = numberOfOptArgs(cur.paragraph())
1542 < cur.paragraph().layout()->optionalargs;
1546 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1550 // the functions which insert insets
1551 InsetBase::Code code = InsetBase::NO_CODE;
1552 switch (cmd.action) {
1553 case LFUN_DIALOG_SHOW_NEW_INSET:
1554 if (cmd.argument == "bibitem")
1555 code = InsetBase::BIBITEM_CODE;
1556 else if (cmd.argument == "bibtex")
1557 code = InsetBase::BIBTEX_CODE;
1558 else if (cmd.argument == "box")
1559 code = InsetBase::BOX_CODE;
1560 else if (cmd.argument == "branch")
1561 code = InsetBase::BRANCH_CODE;
1562 else if (cmd.argument == "citation")
1563 code = InsetBase::CITE_CODE;
1564 else if (cmd.argument == "ert")
1565 code = InsetBase::ERT_CODE;
1566 else if (cmd.argument == "external")
1567 code = InsetBase::EXTERNAL_CODE;
1568 else if (cmd.argument == "float")
1569 code = InsetBase::FLOAT_CODE;
1570 else if (cmd.argument == "graphics")
1571 code = InsetBase::GRAPHICS_CODE;
1572 else if (cmd.argument == "include")
1573 code = InsetBase::INCLUDE_CODE;
1574 else if (cmd.argument == "index")
1575 code = InsetBase::INDEX_CODE;
1576 else if (cmd.argument == "label")
1577 code = InsetBase::LABEL_CODE;
1578 else if (cmd.argument == "note")
1579 code = InsetBase::NOTE_CODE;
1580 else if (cmd.argument == "ref")
1581 code = InsetBase::REF_CODE;
1582 else if (cmd.argument == "toc")
1583 code = InsetBase::TOC_CODE;
1584 else if (cmd.argument == "url")
1585 code = InsetBase::URL_CODE;
1586 else if (cmd.argument == "vspace")
1587 code = InsetBase::VSPACE_CODE;
1588 else if (cmd.argument == "wrap")
1589 code = InsetBase::WRAP_CODE;
1592 case LFUN_INSET_ERT:
1593 code = InsetBase::ERT_CODE;
1595 case LFUN_INSET_FOOTNOTE:
1596 code = InsetBase::FOOT_CODE;
1598 case LFUN_TABULAR_INSERT:
1599 code = InsetBase::TABULAR_CODE;
1601 case LFUN_INSET_MARGINAL:
1602 code = InsetBase::MARGIN_CODE;
1604 case LFUN_INSET_FLOAT:
1605 case LFUN_INSET_WIDE_FLOAT:
1606 code = InsetBase::FLOAT_CODE;
1608 case LFUN_INSET_WRAP:
1609 code = InsetBase::WRAP_CODE;
1611 case LFUN_FLOAT_LIST:
1612 code = InsetBase::FLOAT_LIST_CODE;
1615 case LFUN_INSET_LIST:
1616 code = InsetBase::LIST_CODE;
1618 case LFUN_INSET_THEOREM:
1619 code = InsetBase::THEOREM_CODE;
1622 case LFUN_INSET_CAPTION:
1623 code = InsetBase::CAPTION_CODE;
1625 case LFUN_INSERT_NOTE:
1626 code = InsetBase::NOTE_CODE;
1628 case LFUN_INSERT_CHARSTYLE:
1629 code = InsetBase::CHARSTYLE_CODE;
1630 if (buf->params().getLyXTextClass().charstyles().empty())
1633 case LFUN_INSERT_BOX:
1634 code = InsetBase::BOX_CODE;
1636 case LFUN_INSERT_BRANCH:
1637 code = InsetBase::BRANCH_CODE;
1638 if (buf->params().branchlist().empty())
1641 case LFUN_INSERT_LABEL:
1642 code = InsetBase::LABEL_CODE;
1644 case LFUN_INSET_OPTARG:
1645 code = InsetBase::OPTARG_CODE;
1647 case LFUN_ENVIRONMENT_INSERT:
1648 code = InsetBase::BOX_CODE;
1650 case LFUN_INDEX_INSERT:
1651 code = InsetBase::INDEX_CODE;
1653 case LFUN_INDEX_PRINT:
1654 code = InsetBase::INDEX_PRINT_CODE;
1656 case LFUN_TOC_INSERT:
1657 code = InsetBase::TOC_CODE;
1661 code = InsetBase::URL_CODE;
1664 // always allow this, since we will inset a raw quote
1665 // if an inset is not allowed.
1667 case LFUN_HYPHENATION:
1668 case LFUN_LIGATURE_BREAK:
1670 case LFUN_MENU_SEPARATOR:
1672 case LFUN_END_OF_SENTENCE:
1673 code = InsetBase::SPECIALCHAR_CODE;
1675 case LFUN_SPACE_INSERT:
1676 // slight hack: we know this is allowed in math mode
1678 code = InsetBase::SPACE_CODE;
1680 case LFUN_INSET_DIALOG_SHOW: {
1681 InsetBase * inset = cur.nextInset();
1684 code = inset->lyxCode();
1685 if (!(code == InsetBase::INCLUDE_CODE
1686 || code == InsetBase::BIBTEX_CODE
1687 || code == InsetBase::FLOAT_LIST_CODE
1688 || code == InsetBase::TOC_CODE))
1697 if (code != InsetBase::NO_CODE
1698 && (cur.empty() || !cur.inset().insetAllowed(code)))
1703 case LFUN_DIALOG_SHOW_NEW_INSET:
1704 case LFUN_INSET_ERT:
1705 case LFUN_INSERT_BOX:
1706 case LFUN_INSERT_BRANCH:
1707 case LFUN_ENVIRONMENT_INSERT:
1708 case LFUN_INDEX_INSERT:
1709 case LFUN_INDEX_PRINT:
1710 case LFUN_TOC_INSERT:
1714 case LFUN_HYPHENATION:
1715 case LFUN_LIGATURE_BREAK:
1717 case LFUN_MENU_SEPARATOR:
1719 case LFUN_END_OF_SENTENCE:
1720 case LFUN_SPACE_INSERT:
1721 case LFUN_INSET_DIALOG_SHOW:
1725 flag.setOnOff(font.emph() == LyXFont::ON);
1729 flag.setOnOff(font.noun() == LyXFont::ON);
1733 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1737 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1741 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1745 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1748 case LFUN_DELETE_WORD_FORWARD:
1749 case LFUN_DELETE_WORD_BACKWARD:
1750 case LFUN_DELETE_LINE_FORWARD:
1751 case LFUN_WORDRIGHT:
1761 case LFUN_UP_PARAGRAPHSEL:
1762 case LFUN_DOWN_PARAGRAPHSEL:
1767 case LFUN_WORDRIGHTSEL:
1768 case LFUN_WORDLEFTSEL:
1770 case LFUN_UP_PARAGRAPH:
1771 case LFUN_DOWN_PARAGRAPH:
1776 case LFUN_BREAKLINE:
1778 case LFUN_DELETE_SKIP:
1779 case LFUN_BACKSPACE:
1780 case LFUN_BACKSPACE_SKIP:
1781 case LFUN_BREAKPARAGRAPH:
1782 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1783 case LFUN_BREAKPARAGRAPH_SKIP:
1784 case LFUN_PARAGRAPH_SPACING:
1785 case LFUN_INSET_APPLY:
1786 case LFUN_INSET_INSERT:
1787 case LFUN_NEXT_INSET_TOGGLE:
1788 case LFUN_UPCASE_WORD:
1789 case LFUN_LOWCASE_WORD:
1790 case LFUN_CAPITALIZE_WORD:
1791 case LFUN_TRANSPOSE_CHARS:
1798 case LFUN_GETLAYOUT:
1800 case LFUN_PASTESELECTION:
1801 case LFUN_DATE_INSERT:
1802 case LFUN_SELFINSERT:
1803 case LFUN_INSERT_LABEL:
1804 case LFUN_INSERT_NOTE:
1805 case LFUN_INSERT_CHARSTYLE:
1806 case LFUN_INSERT_BIBITEM:
1807 case LFUN_INSET_FLOAT:
1808 case LFUN_INSET_FOOTNOTE:
1809 case LFUN_INSET_MARGINAL:
1810 case LFUN_INSET_WIDE_FLOAT:
1811 case LFUN_INSET_WRAP:
1812 case LFUN_TABULAR_INSERT:
1813 case LFUN_INSERT_LINE:
1814 case LFUN_INSERT_PAGEBREAK:
1815 case LFUN_MATH_DISPLAY:
1816 case LFUN_MATH_IMPORT_SELECTION:
1817 case LFUN_MATH_MODE:
1818 case LFUN_MATH_MACRO:
1819 case LFUN_INSERT_MATH:
1820 case LFUN_INSERT_MATRIX:
1821 case LFUN_MATH_DELIM:
1822 case LFUN_SUBSCRIPT:
1823 case LFUN_SUPERSCRIPT:
1825 case LFUN_UNDERLINE:
1826 case LFUN_FONT_SIZE:
1828 case LFUN_FREEFONT_APPLY:
1829 case LFUN_FREEFONT_UPDATE:
1830 case LFUN_LAYOUT_PARAGRAPH:
1831 case LFUN_PARAGRAPH_UPDATE:
1833 case LFUN_CIRCUMFLEX:
1843 case LFUN_SPECIAL_CARON:
1846 case LFUN_HUNG_UMLAUT:
1849 case LFUN_FLOAT_LIST:
1850 case LFUN_ACCEPT_CHANGE:
1851 case LFUN_REJECT_CHANGE:
1852 case LFUN_THESAURUS_ENTRY:
1853 case LFUN_PARAGRAPH_APPLY:
1855 case LFUN_KEYMAP_TOGGLE:
1857 case LFUN_BEGINNINGBUF:
1858 case LFUN_BEGINNINGBUFSEL:
1859 case LFUN_ENDBUFSEL:
1860 // these are handled in our dispatch()
1867 flag.enabled(enable);