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"
64 #include <boost/current_function.hpp>
71 using lyx::cap::copySelection;
72 using lyx::cap::cutSelection;
73 using lyx::cap::pasteSelection;
74 using lyx::cap::replaceSelection;
76 using lyx::support::isStrUnsignedInt;
77 using lyx::support::token;
81 using std::istringstream;
84 extern string current_layout;
90 LyXFont freefont(LyXFont::ALL_IGNORE);
91 bool toggleall = false;
94 void toggleAndShow(LCursor & cur, LyXText * text,
95 LyXFont const & font, bool toggleall = true)
97 text->toggleFree(cur, font, toggleall);
99 if (font.language() != ignore_language ||
100 font.number() != LyXFont::IGNORE) {
101 Paragraph & par = cur.paragraph();
102 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
103 if (cur.boundary() !=
104 text->bidi.isBoundary(cur.buffer(), par,
106 text->real_current_font))
107 text->setCursor(cur, cur.pit(), cur.pos(),
108 false, !cur.boundary());
113 void moveCursor(LCursor & cur, bool selecting)
115 if (selecting || cur.mark())
117 if (!cur.selection())
118 cur.bv().haveSelection(false);
119 cur.bv().switchKeyMap();
123 void finishChange(LCursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
133 string sel = cur.selectionAsString(false);
134 lyxerr << "selection is: '" << sel << "'" << endl;
137 const int old_pos = cur.pos();
138 cur.insert(new MathHullInset);
139 BOOST_ASSERT(old_pos == cur.pos());
140 cur.nextInset()->edit(cur, true);
141 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
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 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
150 // create a macro if we see "\\newcommand"
151 // somewhere, and an ordinary formula
153 cutSelection(cur, true, true);
154 if (sel.find("\\newcommand") == string::npos
155 && sel.find("\\def") == string::npos)
157 cur.insert(new MathHullInset);
158 cur.dispatch(FuncRequest(LFUN_RIGHT));
159 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
160 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
162 istringstream is(sel);
163 cur.insert(new MathMacroTemplate(is));
166 cur.message(N_("Math editor mode"));
175 string const freefont2string()
178 if (font2string(freefont, toggleall, data))
185 bool LyXText::cursorPrevious(LCursor & cur)
187 pos_type cpos = cur.pos();
188 lyx::pit_type cpar = cur.pit();
190 int x = cur.x_target();
192 setCursorFromCoordinates(cur, x, 0);
193 bool updated = cursorUp(cur);
195 if (cpar == cur.pit() && cpos == cur.pos()) {
196 // we have a row which is taller than the workarea. The
197 // simplest solution is to move to the previous row instead.
198 updated |= cursorUp(cur);
201 cur.bv().updateScrollbar();
207 bool LyXText::cursorNext(LCursor & cur)
209 pos_type cpos = cur.pos();
210 lyx::pit_type cpar = cur.pit();
212 int x = cur.x_target();
213 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
214 bool updated = cursorDown(cur);
216 if (cpar == cur.pit() && cpos == cur.pos()) {
217 // we have a row which is taller than the workarea. The
218 // simplest solution is to move to the next row instead.
219 updated |= cursorDown(cur);
222 cur.bv().updateScrollbar();
230 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
232 lyx::cap::replaceSelection(cur);
233 cur.insert(new InsetSpecialChar(kind));
238 void doInsertInset(LCursor & cur, LyXText * text,
239 FuncRequest const & cmd, bool edit, bool pastesel)
241 InsetBase * inset = createInset(&cur.bv(), cmd);
247 if (cur.selection()) {
248 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
251 text->insertInset(cur, inset);
254 inset->edit(cur, true);
256 if (gotsel && pastesel)
257 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
261 void update(LCursor & cur)
263 //we don't call update(true, false) directly to save a metrics call
264 if (cur.bv().fitCursor())
265 cur.bv().update(false, true);
272 void LyXText::number(LCursor & cur)
274 LyXFont font(LyXFont::ALL_IGNORE);
275 font.setNumber(LyXFont::TOGGLE);
276 toggleAndShow(cur, this, font);
280 bool LyXText::isRTL(Paragraph const & par) const
282 return par.isRightToLeftPar(bv()->buffer()->params());
286 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
288 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
289 lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
291 BOOST_ASSERT(cur.text() == this);
292 BufferView * bv = &cur.bv();
293 CursorSlice oldTopSlice = cur.top();
294 bool sel = cur.selection();
295 bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
297 switch (cmd.action) {
299 case LFUN_APPENDIX: {
300 Paragraph & par = cur.paragraph();
301 bool start = !par.params().startOfAppendix();
304 #warning The code below only makes sense at top level.
305 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
307 // ensure that we have only one start_of_appendix in this document
308 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
309 if (pars_[tmp].params().startOfAppendix()) {
311 pars_[tmp].params().startOfAppendix(false);
317 par.params().startOfAppendix(start);
319 // we can set the refreshing parameters now
320 updateCounters(cur.buffer());
324 case LFUN_DELETE_WORD_FORWARD:
325 cur.clearSelection();
326 deleteWordForward(cur);
327 finishChange(cur, false);
330 case LFUN_DELETE_WORD_BACKWARD:
331 cur.clearSelection();
332 deleteWordBackward(cur);
333 finishChange(cur, false);
336 case LFUN_DELETE_LINE_FORWARD:
337 cur.clearSelection();
338 deleteLineForward(cur);
339 finishChange(cur, false);
344 cur.clearSelection();
345 if (isRTL(cur.paragraph()))
346 needsUpdate = cursorLeftOneWord(cur);
348 needsUpdate = cursorRightOneWord(cur);
349 finishChange(cur, false);
354 cur.clearSelection();
355 if (isRTL(cur.paragraph()))
356 needsUpdate = cursorRightOneWord(cur);
358 needsUpdate = cursorLeftOneWord(cur);
359 finishChange(cur, false);
362 case LFUN_BEGINNINGBUF:
363 if (cur.depth() == 1) {
365 cur.clearSelection();
367 finishChange(cur, false);
373 case LFUN_BEGINNINGBUFSEL:
374 if (cur.depth() == 1) {
375 if (!cur.selection())
378 finishChange(cur, true);
385 if (cur.depth() == 1) {
387 cur.clearSelection();
389 finishChange(cur, false);
396 if (cur.depth() == 1) {
397 if (!cur.selection())
400 finishChange(cur, true);
408 lyxerr << BOOST_CURRENT_FUNCTION
409 << " LFUN_RIGHT[SEL]:\n" << cur << endl;
410 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
411 if (isRTL(cur.paragraph()))
412 needsUpdate = cursorLeft(cur);
414 needsUpdate = cursorRight(cur);
415 if (!needsUpdate && oldTopSlice == cur.top()) {
417 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
423 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
424 cur.selHandle(cmd.action == LFUN_LEFTSEL);
425 if (isRTL(cur.paragraph()))
426 needsUpdate = cursorRight(cur);
428 needsUpdate = cursorLeft(cur);
429 if (oldTopSlice == cur.top()) {
431 cmd = FuncRequest(LFUN_FINISHED_LEFT);
438 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
439 cur.selHandle(cmd.action == LFUN_UPSEL);
440 needsUpdate = cursorUp(cur);
441 if (oldTopSlice == cur.top()) {
443 cmd = FuncRequest(LFUN_FINISHED_UP);
450 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
451 cur.selHandle(cmd.action == LFUN_DOWNSEL);
452 needsUpdate = cursorDown(cur);
453 if (oldTopSlice == cur.top()) {
455 cmd = FuncRequest(LFUN_FINISHED_DOWN);
459 case LFUN_UP_PARAGRAPH:
461 cur.clearSelection();
462 needsUpdate = cursorUpParagraph(cur);
463 finishChange(cur, false);
466 case LFUN_UP_PARAGRAPHSEL:
467 if (!cur.selection())
469 cursorUpParagraph(cur);
470 finishChange(cur, true);
473 case LFUN_DOWN_PARAGRAPH:
475 cur.clearSelection();
476 needsUpdate = cursorDownParagraph(cur);
477 finishChange(cur, false);
480 case LFUN_DOWN_PARAGRAPHSEL:
481 if (!cur.selection())
483 cursorDownParagraph(cur);
484 finishChange(cur, true);
489 if (!cur.selection())
492 finishChange(cur, true);
497 if (!cur.selection())
500 finishChange(cur, true);
505 if (!cur.selection())
508 finishChange(cur, true);
513 if (!cur.selection())
516 finishChange(cur, true);
519 case LFUN_WORDRIGHTSEL:
520 if (!cur.selection())
522 if (isRTL(cur.paragraph()))
523 cursorLeftOneWord(cur);
525 cursorRightOneWord(cur);
526 finishChange(cur, true);
529 case LFUN_WORDLEFTSEL:
530 if (!cur.selection())
532 if (isRTL(cur.paragraph()))
533 cursorRightOneWord(cur);
535 cursorLeftOneWord(cur);
536 finishChange(cur, true);
540 selectWord(cur, lyx::WHOLE_WORD);
541 finishChange(cur, true);
548 cur.clearSelection();
549 finishChange(cur, false);
550 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
552 cmd = FuncRequest(LFUN_FINISHED_UP);
554 needsUpdate = cursorPrevious(cur);
561 cur.clearSelection();
562 finishChange(cur, false);
563 if (cur.pit() == cur.lastpit()
564 && cur.textRow().endpos() == cur.lastpos()) {
566 cmd = FuncRequest(LFUN_FINISHED_DOWN);
568 needsUpdate = cursorNext(cur);
574 cur.clearSelection();
576 finishChange(cur, false);
581 cur.clearSelection();
583 finishChange(cur, false);
586 case LFUN_BREAKLINE: {
587 // Not allowed by LaTeX (labels or empty par)
588 if (cur.pos() > cur.paragraph().beginOfBody()) {
589 lyx::cap::replaceSelection(cur);
590 cur.insert(new InsetNewline);
592 moveCursor(cur, false);
598 if (!cur.selection()) {
601 // It is possible to make it a lot faster still
602 // just comment out the line below...
604 cutSelection(cur, true, false);
606 moveCursor(cur, false);
609 case LFUN_DELETE_SKIP:
610 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
611 if (!cur.selection()) {
612 if (cur.pos() == cur.lastpos()) {
619 cutSelection(cur, true, false);
625 if (!cur.selection()) {
626 if (bv->owner()->getIntl().getTransManager().backspace()) {
629 // It is possible to make it a lot faster still
630 // just comment out the line below...
633 cutSelection(cur, true, false);
638 case LFUN_BACKSPACE_SKIP:
639 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
640 if (!cur.selection()) {
644 //CursorSlice cur = cursor();
648 cutSelection(cur, true, false);
652 case LFUN_BREAKPARAGRAPH:
653 lyx::cap::replaceSelection(cur);
654 breakParagraph(cur, 0);
659 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
660 lyx::cap::replaceSelection(cur);
661 breakParagraph(cur, 1);
666 case LFUN_BREAKPARAGRAPH_SKIP: {
667 // When at the beginning of a paragraph, remove
668 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
669 lyx::cap::replaceSelection(cur);
671 cur.paragraph().params().labelWidthString(string());
673 breakParagraph(cur, 0);
679 case LFUN_PARAGRAPH_SPACING: {
680 Paragraph & par = cur.paragraph();
681 Spacing::Space cur_spacing = par.params().spacing().getSpace();
682 string cur_value = "1.0";
683 if (cur_spacing == Spacing::Other)
684 cur_value = par.params().spacing().getValueAsString();
686 istringstream is(cmd.argument);
689 Spacing::Space new_spacing = cur_spacing;
690 string new_value = cur_value;
692 lyxerr << "Missing argument to `paragraph-spacing'"
694 } else if (tmp == "single") {
695 new_spacing = Spacing::Single;
696 } else if (tmp == "onehalf") {
697 new_spacing = Spacing::Onehalf;
698 } else if (tmp == "double") {
699 new_spacing = Spacing::Double;
700 } else if (tmp == "other") {
701 new_spacing = Spacing::Other;
702 string tmpval = "0.0";
704 lyxerr << "new_value = " << tmpval << endl;
707 } else if (tmp == "default") {
708 new_spacing = Spacing::Default;
710 lyxerr << _("Unknown spacing argument: ")
711 << cmd.argument << endl;
713 if (cur_spacing != new_spacing || cur_value != new_value)
714 par.params().spacing(Spacing(new_spacing, new_value));
718 case LFUN_INSET_INSERT: {
720 InsetBase * inset = createInset(bv, cmd);
722 insertInset(cur, inset);
728 case LFUN_INSET_SETTINGS:
729 if (cur.inset().asUpdatableInset())
730 cur.inset().asUpdatableInset()->showInsetDialog(bv);
733 case LFUN_NEXT_INSET_TOGGLE: {
734 InsetBase * inset = cur.nextInset();
736 cur.clearSelection();
737 FuncRequest fr = cmd;
738 fr.action = LFUN_INSET_TOGGLE;
739 inset->dispatch(cur, fr);
744 case LFUN_KEYMAP_TOGGLE:
745 cur.clearSelection();
749 case LFUN_SPACE_INSERT:
750 if (cur.paragraph().layout()->free_spacing)
751 insertChar(cur, ' ');
753 doInsertInset(cur, this, cmd, false, false);
756 moveCursor(cur, false);
759 case LFUN_HYPHENATION:
760 specialChar(cur, InsetSpecialChar::HYPHENATION);
763 case LFUN_LIGATURE_BREAK:
764 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
768 specialChar(cur, InsetSpecialChar::LDOTS);
771 case LFUN_END_OF_SENTENCE:
772 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
775 case LFUN_MENU_SEPARATOR:
776 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
779 case LFUN_UPCASE_WORD:
780 changeCase(cur, LyXText::text_uppercase);
783 case LFUN_LOWCASE_WORD:
784 changeCase(cur, LyXText::text_lowercase);
787 case LFUN_CAPITALIZE_WORD:
788 changeCase(cur, LyXText::text_capitalization);
791 case LFUN_TRANSPOSE_CHARS:
796 cur.message(_("Paste"));
797 lyx::cap::replaceSelection(cur);
799 #warning FIXME Check if the arg is in the domain of available selections.
801 if (isStrUnsignedInt(cmd.argument))
802 pasteSelection(cur, convert<unsigned int>(cmd.argument));
804 pasteSelection(cur, 0);
805 cur.clearSelection(); // bug 393
811 cutSelection(cur, true, true);
812 cur.message(_("Cut"));
817 cur.message(_("Copy"));
821 cur.message(convert<string>(cursorX(cur.top())) + ' '
822 + convert<string>(cursorY(cur.top())));
828 istringstream is(cmd.argument);
831 lyxerr << "SETXY: Could not parse coordinates in '"
832 << cmd.argument << std::endl;
834 setCursorFromCoordinates(cur, x, y);
839 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
841 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
848 cur.message(cur.paragraph().layout()->name());
852 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
853 << cmd.argument << endl;
855 // This is not the good solution to the empty argument
856 // problem, but it will hopefully suffice for 1.2.0.
857 // The correct solution would be to augument the
858 // function list/array with information about what
859 // functions needs arguments and their type.
860 if (cmd.argument.empty()) {
861 cur.errorMessage(_("LyX function 'layout' needs an argument."));
865 // Derive layout number from given argument (string)
866 // and current buffer's textclass (number)
867 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
868 bool hasLayout = tclass.hasLayout(cmd.argument);
869 string layout = cmd.argument;
871 // If the entry is obsolete, use the new one instead.
873 string const & obs = tclass[layout]->obsoleted_by();
879 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
884 bool change_layout = (current_layout != layout);
886 if (!change_layout && cur.selection() &&
887 cur.selBegin().pit() != cur.selEnd().pit())
889 pit_type spit = cur.selBegin().pit();
890 pit_type epit = cur.selEnd().pit() + 1;
891 while (spit != epit) {
892 if (pars_[spit].layout()->name() != current_layout) {
893 change_layout = true;
901 current_layout = layout;
902 setLayout(cur, layout);
903 bv->owner()->setLayout(layout);
909 case LFUN_PASTESELECTION: {
910 cur.clearSelection();
911 string const clip = bv->getClipboard();
913 if (cmd.argument == "paragraph")
914 insertStringAsParagraphs(cur, clip);
916 insertStringAsLines(cur, clip);
922 lyx::cap::replaceSelection(cur);
923 Paragraph & par = cur.paragraph();
924 lyx::pos_type pos = cur.pos();
928 else if (cur.prevInset() && cur.prevInset()->isSpace())
931 c = par.getChar(pos - 1);
933 LyXLayout_ptr const & style = par.layout();
935 BufferParams const & bufparams = bv->buffer()->params();
936 if (!style->pass_thru
937 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
938 string arg = cmd.argument;
940 cur.insert(new InsetQuotes(c,
941 bufparams.quotes_language,
942 InsetQuotes::SingleQ));
943 else if (arg == "double")
944 cur.insert(new InsetQuotes(c,
945 bufparams.quotes_language,
946 InsetQuotes::DoubleQ));
948 cur.insert(new InsetQuotes(c, bufparams));
952 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
956 case LFUN_DATE_INSERT: {
957 lyx::cap::replaceSelection(cur);
958 time_t now_time_t = time(NULL);
959 struct tm * now_tm = localtime(&now_time_t);
960 setlocale(LC_TIME, "");
962 if (!cmd.argument.empty())
965 arg = lyxrc.date_insert_format;
967 int const datetmp_len =
968 ::strftime(datetmp, 32, arg.c_str(), now_tm);
970 for (int i = 0; i < datetmp_len; i++)
971 insertChar(cur, datetmp[i]);
974 moveCursor(cur, false);
978 case LFUN_MOUSE_TRIPLE:
979 if (cmd.button() == mouse_button::button1) {
984 bv->haveSelection(cur.selection());
988 case LFUN_MOUSE_DOUBLE:
989 if (cmd.button() == mouse_button::button1) {
990 selectWord(cur, lyx::WHOLE_WORD_STRICT);
991 bv->haveSelection(cur.selection());
995 // Single-click on work area
996 case LFUN_MOUSE_PRESS: {
997 // Right click on a footnote flag opens float menu
998 if (cmd.button() == mouse_button::button3) {
999 cur.clearSelection();
1003 // Middle button press pastes if we have a selection
1004 // We do this here as if the selection was inside an inset
1005 // it could get cleared on the unlocking of the inset so
1006 // we have to check this first
1007 bool paste_internally = false;
1008 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1009 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1010 paste_internally = true;
1013 // Clear the selection
1014 cur.clearSelection();
1016 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1021 // Has the cursor just left the inset?
1022 if (bv->cursor().inMathed() && !cur.inMathed())
1023 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1028 // Insert primary selection with middle mouse
1029 // if there is a local selection in the current buffer,
1031 if (cmd.button() == mouse_button::button2) {
1032 if (paste_internally)
1033 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1035 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1041 case LFUN_MOUSE_MOTION: {
1042 // Only use motion with button 1
1043 //if (cmd.button() != mouse_button::button1)
1046 // ignore motions deeper nested than the real anchor
1047 LCursor & bvcur = cur.bv().cursor();
1048 if (bvcur.anchor_.hasPart(cur)) {
1049 CursorSlice old = bvcur.top();
1051 int const wh = bv->workHeight();
1052 int const y = std::max(0, std::min(wh - 1, cmd.y));
1054 setCursorFromCoordinates(cur, cmd.x, y);
1055 cur.x_target() = cmd.x;
1060 // This is to allow jumping over large insets
1061 if (cur.top() == old) {
1068 if (cur.top() == old)
1071 // don't set anchor_
1072 bvcur.setCursor(cur);
1073 bvcur.selection() = true;
1074 lyxerr << "MOTION: " << bv->cursor() << endl;
1082 case LFUN_MOUSE_RELEASE: {
1083 if (cmd.button() == mouse_button::button2)
1087 if (cmd.button() == mouse_button::button1)
1088 bv->haveSelection(cur.selection());
1091 bv->owner()->updateMenubar();
1092 bv->owner()->updateToolbars();
1096 case LFUN_SELFINSERT: {
1097 if (cmd.argument.empty())
1100 // Automatically delete the currently selected
1101 // text and replace it with what is being
1102 // typed in now. Depends on lyxrc settings
1103 // "auto_region_delete", which defaults to
1106 if (lyxrc.auto_region_delete) {
1107 if (cur.selection())
1108 cutSelection(cur, false, false);
1109 bv->haveSelection(false);
1112 cur.clearSelection();
1113 LyXFont const old_font = real_current_font;
1115 // Prevents language turds in new lyxtexts under non-english
1116 setCurrentFont(cur);
1118 string::const_iterator cit = cmd.argument.begin();
1119 string::const_iterator end = cmd.argument.end();
1120 for (; cit != end; ++cit)
1121 bv->owner()->getIntl().getTransManager().
1122 TranslateAndInsert(*cit, this);
1125 moveCursor(cur, false);
1127 // real_current_font.number can change so we need to
1128 // update the minibuffer
1129 if (old_font != real_current_font)
1130 bv->updateScrollbar();
1135 InsetCommandParams p("url");
1136 string const data = InsetCommandMailer::params2string("url", p);
1137 bv->owner()->getDialogs().show("url", data, 0);
1141 case LFUN_HTMLURL: {
1142 InsetCommandParams p("htmlurl");
1143 string const data = InsetCommandMailer::params2string("url", p);
1144 bv->owner()->getDialogs().show("url", data, 0);
1148 case LFUN_INSERT_LABEL: {
1149 // Try to generate a valid label
1150 string const contents = cmd.argument.empty() ?
1151 cur.getPossibleLabel() : cmd.argument;
1153 InsetCommandParams p("label", contents);
1154 string const data = InsetCommandMailer::params2string("label", p);
1156 if (cmd.argument.empty()) {
1157 bv->owner()->getDialogs().show("label", data, 0);
1159 FuncRequest fr(LFUN_INSET_INSERT, data);
1167 case LFUN_INSET_LIST:
1168 case LFUN_INSET_THEOREM:
1169 case LFUN_INSET_CAPTION:
1171 case LFUN_INSERT_NOTE:
1172 case LFUN_INSERT_CHARSTYLE:
1173 case LFUN_INSERT_BOX:
1174 case LFUN_INSERT_BRANCH:
1175 case LFUN_INSERT_BIBITEM:
1176 case LFUN_INSET_ERT:
1177 case LFUN_INSET_FLOAT:
1178 case LFUN_INSET_FOOTNOTE:
1179 case LFUN_INSET_MARGINAL:
1180 case LFUN_INSET_OPTARG:
1181 case LFUN_INSET_WIDE_FLOAT:
1182 case LFUN_INSET_WRAP:
1183 case LFUN_TABULAR_INSERT:
1184 case LFUN_ENVIRONMENT_INSERT:
1185 // Open the inset, and move the current selection
1187 doInsertInset(cur, this, cmd, true, true);
1191 case LFUN_INDEX_INSERT:
1192 // Just open the inset
1193 doInsertInset(cur, this, cmd, true, false);
1197 case LFUN_INDEX_PRINT:
1198 case LFUN_TOC_INSERT:
1200 case LFUN_INSERT_LINE:
1201 case LFUN_INSERT_PAGEBREAK:
1203 doInsertInset(cur, this, cmd, false, false);
1207 case LFUN_DEPTH_MIN:
1208 changeDepth(cur, DEC_DEPTH);
1211 case LFUN_DEPTH_PLUS:
1212 changeDepth(cur, INC_DEPTH);
1215 case LFUN_MATH_DISPLAY:
1216 mathDispatch(cur, cmd, true);
1219 case LFUN_MATH_IMPORT_SELECTION:
1220 case LFUN_MATH_MODE:
1221 if (cmd.argument == "on")
1222 // don't pass "on" as argument
1223 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1225 mathDispatch(cur, cmd, false);
1228 case LFUN_MATH_MACRO:
1229 if (cmd.argument.empty())
1230 cur.errorMessage(N_("Missing argument"));
1232 string s = cmd.argument;
1233 string const s1 = token(s, ' ', 1);
1234 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1235 string const s2 = token(s, ' ', 2);
1236 string const type = s2.empty() ? "newcommand" : s2;
1237 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1238 //cur.nextInset()->edit(cur, true);
1242 // passthrough hat and underscore outside mathed:
1243 case LFUN_SUBSCRIPT:
1244 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1246 case LFUN_SUPERSCRIPT:
1247 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1250 case LFUN_INSERT_MATH:
1251 case LFUN_INSERT_MATRIX:
1252 case LFUN_MATH_DELIM: {
1253 cur.insert(new MathHullInset);
1254 cur.dispatch(FuncRequest(LFUN_RIGHT));
1255 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1261 LyXFont font(LyXFont::ALL_IGNORE);
1262 font.setEmph(LyXFont::TOGGLE);
1263 toggleAndShow(cur, this, font);
1268 LyXFont font(LyXFont::ALL_IGNORE);
1269 font.setSeries(LyXFont::BOLD_SERIES);
1270 toggleAndShow(cur, this, font);
1275 LyXFont font(LyXFont::ALL_IGNORE);
1276 font.setNoun(LyXFont::TOGGLE);
1277 toggleAndShow(cur, this, font);
1282 LyXFont font(LyXFont::ALL_IGNORE);
1283 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1284 toggleAndShow(cur, this, font);
1289 LyXFont font(LyXFont::ALL_IGNORE);
1290 font.setFamily(LyXFont::SANS_FAMILY);
1291 toggleAndShow(cur, this, font);
1296 LyXFont font(LyXFont::ALL_IGNORE);
1297 font.setFamily(LyXFont::ROMAN_FAMILY);
1298 toggleAndShow(cur, this, font);
1302 case LFUN_DEFAULT: {
1303 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1304 toggleAndShow(cur, this, font);
1308 case LFUN_UNDERLINE: {
1309 LyXFont font(LyXFont::ALL_IGNORE);
1310 font.setUnderbar(LyXFont::TOGGLE);
1311 toggleAndShow(cur, this, font);
1315 case LFUN_FONT_SIZE: {
1316 LyXFont font(LyXFont::ALL_IGNORE);
1317 font.setLyXSize(cmd.argument);
1318 toggleAndShow(cur, this, font);
1322 case LFUN_LANGUAGE: {
1323 Language const * lang = languages.getLanguage(cmd.argument);
1326 LyXFont font(LyXFont::ALL_IGNORE);
1327 font.setLanguage(lang);
1328 toggleAndShow(cur, this, font);
1333 case LFUN_FREEFONT_APPLY:
1334 toggleAndShow(cur, this, freefont, toggleall);
1335 cur.message(_("Character set"));
1338 // Set the freefont using the contents of \param data dispatched from
1339 // the frontends and apply it at the current cursor location.
1340 case LFUN_FREEFONT_UPDATE: {
1343 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1346 toggleAndShow(cur, this, freefont, toggleall);
1347 cur.message(_("Character set"));
1352 case LFUN_FINISHED_LEFT:
1353 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1356 case LFUN_FINISHED_RIGHT:
1357 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1361 case LFUN_FINISHED_UP:
1362 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1366 case LFUN_FINISHED_DOWN:
1367 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1371 case LFUN_LAYOUT_PARAGRAPH: {
1373 params2string(cur.paragraph(), data);
1374 data = "show\n" + data;
1375 bv->owner()->getDialogs().show("paragraph", data);
1379 case LFUN_PARAGRAPH_UPDATE: {
1380 if (!bv->owner()->getDialogs().visible("paragraph"))
1383 params2string(cur.paragraph(), data);
1385 // Will the paragraph accept changes from the dialog?
1386 InsetBase & inset = cur.inset();
1387 bool const accept = !inset.forceDefaultParagraphs(&inset);
1389 data = "update " + convert<string>(accept) + '\n' + data;
1390 bv->owner()->getDialogs().update("paragraph", data);
1395 case LFUN_CIRCUMFLEX:
1405 case LFUN_SPECIAL_CARON:
1408 case LFUN_HUNG_UMLAUT:
1411 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1412 if (!cmd.argument.empty())
1413 bv->owner()->getIntl().getTransManager()
1414 .TranslateAndInsert(cmd.argument[0], this);
1417 case LFUN_FLOAT_LIST: {
1418 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1419 if (tclass.floats().typeExist(cmd.argument)) {
1420 // not quite sure if we want this...
1422 cur.clearSelection();
1423 breakParagraph(cur);
1425 if (cur.lastpos() != 0) {
1427 breakParagraph(cur);
1430 setLayout(cur, tclass.defaultLayoutName());
1431 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1432 insertInset(cur, new InsetFloatList(cmd.argument));
1435 lyxerr << "Non-existent float type: "
1436 << cmd.argument << endl;
1441 case LFUN_ACCEPT_CHANGE: {
1446 case LFUN_REJECT_CHANGE: {
1451 case LFUN_THESAURUS_ENTRY: {
1452 string arg = cmd.argument;
1454 arg = cur.selectionAsString(false);
1456 if (arg.size() > 100 || arg.empty()) {
1457 // Get word or selection
1458 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1459 arg = cur.selectionAsString(false);
1462 bv->owner()->getDialogs().show("thesaurus", arg);
1466 case LFUN_PARAGRAPH_APPLY: {
1467 // Given data, an encoding of the ParagraphParameters
1468 // generated in the Paragraph dialog, this function sets
1469 // the current paragraph appropriately.
1470 istringstream is(cmd.argument);
1473 ParagraphParameters params;
1478 params.labelWidthString(),
1480 cur.message(_("Paragraph layout set"));
1484 case LFUN_INSET_DIALOG_SHOW: {
1485 InsetBase * inset = cur.nextInset();
1487 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1488 inset->dispatch(cur, fr);
1494 if (cur.selection()) {
1495 cur.selection() = false;
1498 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1503 lyxerr << BOOST_CURRENT_FUNCTION
1504 << " Not DISPATCHED by LyXText" << endl;
1510 && &oldTopSlice.inset() == &cur.inset()
1511 && oldTopSlice.idx() == cur.idx()
1513 && !cur.selection())
1520 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1521 FuncStatus & flag) const
1523 BOOST_ASSERT(cur.text() == this);
1524 LyXFont const & font = real_current_font;
1527 switch (cmd.action) {
1529 case LFUN_DEPTH_MIN:
1530 enable = changeDepthAllowed(cur, DEC_DEPTH);
1533 case LFUN_DEPTH_PLUS:
1534 enable = changeDepthAllowed(cur, INC_DEPTH);
1537 case LFUN_INSET_OPTARG:
1538 enable = numberOfOptArgs(cur.paragraph())
1539 < cur.paragraph().layout()->optionalargs;
1543 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1547 // the functions which insert insets
1548 InsetBase::Code code = InsetBase::NO_CODE;
1549 switch (cmd.action) {
1550 case LFUN_DIALOG_SHOW_NEW_INSET:
1551 if (cmd.argument == "bibitem")
1552 code = InsetBase::BIBITEM_CODE;
1553 else if (cmd.argument == "bibtex")
1554 code = InsetBase::BIBTEX_CODE;
1555 else if (cmd.argument == "box")
1556 code = InsetBase::BOX_CODE;
1557 else if (cmd.argument == "branch")
1558 code = InsetBase::BRANCH_CODE;
1559 else if (cmd.argument == "citation")
1560 code = InsetBase::CITE_CODE;
1561 else if (cmd.argument == "ert")
1562 code = InsetBase::ERT_CODE;
1563 else if (cmd.argument == "external")
1564 code = InsetBase::EXTERNAL_CODE;
1565 else if (cmd.argument == "float")
1566 code = InsetBase::FLOAT_CODE;
1567 else if (cmd.argument == "graphics")
1568 code = InsetBase::GRAPHICS_CODE;
1569 else if (cmd.argument == "include")
1570 code = InsetBase::INCLUDE_CODE;
1571 else if (cmd.argument == "index")
1572 code = InsetBase::INDEX_CODE;
1573 else if (cmd.argument == "label")
1574 code = InsetBase::LABEL_CODE;
1575 else if (cmd.argument == "note")
1576 code = InsetBase::NOTE_CODE;
1577 else if (cmd.argument == "ref")
1578 code = InsetBase::REF_CODE;
1579 else if (cmd.argument == "toc")
1580 code = InsetBase::TOC_CODE;
1581 else if (cmd.argument == "url")
1582 code = InsetBase::URL_CODE;
1583 else if (cmd.argument == "vspace")
1584 code = InsetBase::VSPACE_CODE;
1585 else if (cmd.argument == "wrap")
1586 code = InsetBase::WRAP_CODE;
1589 case LFUN_INSET_ERT:
1590 code = InsetBase::ERT_CODE;
1592 case LFUN_INSET_FOOTNOTE:
1593 code = InsetBase::FOOT_CODE;
1595 case LFUN_TABULAR_INSERT:
1596 code = InsetBase::TABULAR_CODE;
1598 case LFUN_INSET_MARGINAL:
1599 code = InsetBase::MARGIN_CODE;
1601 case LFUN_INSET_FLOAT:
1602 case LFUN_INSET_WIDE_FLOAT:
1603 code = InsetBase::FLOAT_CODE;
1605 case LFUN_INSET_WRAP:
1606 code = InsetBase::WRAP_CODE;
1608 case LFUN_FLOAT_LIST:
1609 code = InsetBase::FLOAT_LIST_CODE;
1612 case LFUN_INSET_LIST:
1613 code = InsetBase::LIST_CODE;
1615 case LFUN_INSET_THEOREM:
1616 code = InsetBase::THEOREM_CODE;
1619 case LFUN_INSET_CAPTION:
1620 code = InsetBase::CAPTION_CODE;
1622 case LFUN_INSERT_NOTE:
1623 code = InsetBase::NOTE_CODE;
1625 case LFUN_INSERT_CHARSTYLE:
1626 code = InsetBase::CHARSTYLE_CODE;
1627 if (buf->params().getLyXTextClass().charstyles().empty())
1630 case LFUN_INSERT_BOX:
1631 code = InsetBase::BOX_CODE;
1633 case LFUN_INSERT_BRANCH:
1634 code = InsetBase::BRANCH_CODE;
1635 if (buf->params().branchlist().empty())
1638 case LFUN_INSERT_LABEL:
1639 code = InsetBase::LABEL_CODE;
1641 case LFUN_INSET_OPTARG:
1642 code = InsetBase::OPTARG_CODE;
1644 case LFUN_ENVIRONMENT_INSERT:
1645 code = InsetBase::BOX_CODE;
1647 case LFUN_INDEX_INSERT:
1648 code = InsetBase::INDEX_CODE;
1650 case LFUN_INDEX_PRINT:
1651 code = InsetBase::INDEX_PRINT_CODE;
1653 case LFUN_TOC_INSERT:
1654 code = InsetBase::TOC_CODE;
1658 code = InsetBase::URL_CODE;
1661 // always allow this, since we will inset a raw quote
1662 // if an inset is not allowed.
1664 case LFUN_HYPHENATION:
1665 case LFUN_LIGATURE_BREAK:
1667 case LFUN_MENU_SEPARATOR:
1669 case LFUN_END_OF_SENTENCE:
1670 code = InsetBase::SPECIALCHAR_CODE;
1672 case LFUN_SPACE_INSERT:
1673 // slight hack: we know this is allowed in math mode
1675 code = InsetBase::SPACE_CODE;
1677 case LFUN_INSET_DIALOG_SHOW: {
1678 InsetBase * inset = cur.nextInset();
1681 code = inset->lyxCode();
1682 if (!(code == InsetBase::INCLUDE_CODE
1683 || code == InsetBase::BIBTEX_CODE
1684 || code == InsetBase::FLOAT_LIST_CODE
1685 || code == InsetBase::TOC_CODE))
1694 if (code != InsetBase::NO_CODE
1695 && (cur.empty() || !cur.inset().insetAllowed(code)))
1700 case LFUN_DIALOG_SHOW_NEW_INSET:
1701 case LFUN_INSET_ERT:
1702 case LFUN_INSERT_BOX:
1703 case LFUN_INSERT_BRANCH:
1704 case LFUN_ENVIRONMENT_INSERT:
1705 case LFUN_INDEX_INSERT:
1706 case LFUN_INDEX_PRINT:
1707 case LFUN_TOC_INSERT:
1711 case LFUN_HYPHENATION:
1712 case LFUN_LIGATURE_BREAK:
1714 case LFUN_MENU_SEPARATOR:
1716 case LFUN_END_OF_SENTENCE:
1717 case LFUN_SPACE_INSERT:
1718 case LFUN_INSET_DIALOG_SHOW:
1721 case LFUN_INSET_MODIFY:
1722 // We need to disable this, because we may get called for a
1724 // InsetTabular::getStatus() -> InsetText::getStatus()
1725 // and we don't handle LFUN_INSET_MODIFY.
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_INSERT:
1791 case LFUN_NEXT_INSET_TOGGLE:
1792 case LFUN_UPCASE_WORD:
1793 case LFUN_LOWCASE_WORD:
1794 case LFUN_CAPITALIZE_WORD:
1795 case LFUN_TRANSPOSE_CHARS:
1802 case LFUN_GETLAYOUT:
1804 case LFUN_PASTESELECTION:
1805 case LFUN_DATE_INSERT:
1806 case LFUN_SELFINSERT:
1807 case LFUN_INSERT_LABEL:
1808 case LFUN_INSERT_NOTE:
1809 case LFUN_INSERT_CHARSTYLE:
1810 case LFUN_INSERT_BIBITEM:
1811 case LFUN_INSET_FLOAT:
1812 case LFUN_INSET_FOOTNOTE:
1813 case LFUN_INSET_MARGINAL:
1814 case LFUN_INSET_WIDE_FLOAT:
1815 case LFUN_INSET_WRAP:
1816 case LFUN_TABULAR_INSERT:
1817 case LFUN_INSERT_LINE:
1818 case LFUN_INSERT_PAGEBREAK:
1819 case LFUN_MATH_DISPLAY:
1820 case LFUN_MATH_IMPORT_SELECTION:
1821 case LFUN_MATH_MODE:
1822 case LFUN_MATH_MACRO:
1823 case LFUN_INSERT_MATH:
1824 case LFUN_INSERT_MATRIX:
1825 case LFUN_MATH_DELIM:
1826 case LFUN_SUBSCRIPT:
1827 case LFUN_SUPERSCRIPT:
1829 case LFUN_UNDERLINE:
1830 case LFUN_FONT_SIZE:
1832 case LFUN_FREEFONT_APPLY:
1833 case LFUN_FREEFONT_UPDATE:
1834 case LFUN_LAYOUT_PARAGRAPH:
1835 case LFUN_PARAGRAPH_UPDATE:
1837 case LFUN_CIRCUMFLEX:
1847 case LFUN_SPECIAL_CARON:
1850 case LFUN_HUNG_UMLAUT:
1853 case LFUN_FLOAT_LIST:
1854 case LFUN_ACCEPT_CHANGE:
1855 case LFUN_REJECT_CHANGE:
1856 case LFUN_THESAURUS_ENTRY:
1857 case LFUN_PARAGRAPH_APPLY:
1859 case LFUN_KEYMAP_TOGGLE:
1861 case LFUN_BEGINNINGBUF:
1862 case LFUN_BEGINNINGBUFSEL:
1863 case LFUN_ENDBUFSEL:
1864 // these are handled in our dispatch()
1871 flag.enabled(enable);