3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "FloatList.h"
21 #include "FuncStatus.h"
23 #include "buffer_funcs.h"
24 #include "bufferparams.h"
25 #include "BufferView.h"
27 #include "coordcache.h"
28 #include "CutAndPaste.h"
30 #include "dispatchresult.h"
32 #include "funcrequest.h"
36 #include "LyXAction.h"
41 #include "paragraph.h"
42 #include "paragraph_funcs.h"
43 #include "ParagraphParameters.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/LyXView.h"
50 #include "insets/insetcommand.h"
51 #include "insets/insetfloatlist.h"
52 #include "insets/insetnewline.h"
53 #include "insets/insetquotes.h"
54 #include "insets/insetspecialchar.h"
55 #include "insets/insettext.h"
57 #include "support/lstrings.h"
58 #include "support/lyxlib.h"
59 #include "support/convert.h"
60 #include "support/lyxtime.h"
62 #include "mathed/math_hullinset.h"
63 #include "mathed/math_macrotemplate.h"
65 #include <boost/current_function.hpp>
72 using lyx::cap::copySelection;
73 using lyx::cap::cutSelection;
74 using lyx::cap::pasteSelection;
75 using lyx::cap::replaceSelection;
77 using lyx::support::isStrUnsignedInt;
78 using lyx::support::token;
82 using std::istringstream;
85 extern string current_layout;
91 LyXFont freefont(LyXFont::ALL_IGNORE);
92 bool toggleall = false;
95 void toggleAndShow(LCursor & cur, LyXText * text,
96 LyXFont const & font, bool toggleall = true)
98 text->toggleFree(cur, font, toggleall);
100 if (font.language() != ignore_language ||
101 font.number() != LyXFont::IGNORE) {
102 Paragraph & par = cur.paragraph();
103 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
104 if (cur.boundary() !=
105 text->bidi.isBoundary(cur.buffer(), par,
107 text->real_current_font))
108 text->setCursor(cur, cur.pit(), cur.pos(),
109 false, !cur.boundary());
114 void moveCursor(LCursor & cur, bool selecting)
116 if (selecting || cur.mark())
118 if (!cur.selection())
119 cur.bv().haveSelection(false);
120 cur.bv().switchKeyMap();
124 void finishChange(LCursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 //lyxerr << "selection is: '" << sel << "'" << endl;
138 const int old_pos = cur.pos();
139 cur.insert(new MathHullInset);
140 BOOST_ASSERT(old_pos == cur.pos());
141 cur.nextInset()->edit(cur, true);
142 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
143 // don't do that also for LFUN_MATH_MODE
144 // unless you want end up with always changing
145 // to mathrm when opening an inlined inset --
146 // I really hate "LyXfunc overloading"...
148 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
149 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
151 // create a macro if we see "\\newcommand"
152 // somewhere, and an ordinary formula
154 cutSelection(cur, true, true);
155 if (sel.find("\\newcommand") == string::npos
156 && sel.find("\\def") == string::npos)
158 cur.insert(new MathHullInset);
159 cur.dispatch(FuncRequest(LFUN_RIGHT));
160 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
161 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
163 istringstream is(sel);
164 cur.insert(new MathMacroTemplate(is));
167 cur.message(N_("Math editor mode"));
176 string const freefont2string()
179 if (font2string(freefont, toggleall, data))
186 bool LyXText::cursorPrevious(LCursor & cur)
188 pos_type cpos = cur.pos();
189 lyx::pit_type cpar = cur.pit();
191 int x = cur.x_target();
193 setCursorFromCoordinates(cur, x, 0);
194 bool updated = cursorUp(cur);
196 if (cpar == cur.pit() && cpos == cur.pos()) {
197 // we have a row which is taller than the workarea. The
198 // simplest solution is to move to the previous row instead.
199 updated |= cursorUp(cur);
202 cur.bv().updateScrollbar();
208 bool LyXText::cursorNext(LCursor & cur)
210 pos_type cpos = cur.pos();
211 lyx::pit_type cpar = cur.pit();
213 int x = cur.x_target();
214 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
215 bool updated = cursorDown(cur);
217 if (cpar == cur.pit() && cpos == cur.pos()) {
218 // we have a row which is taller than the workarea. The
219 // simplest solution is to move to the next row instead.
220 updated |= cursorDown(cur);
223 cur.bv().updateScrollbar();
231 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
233 lyx::cap::replaceSelection(cur);
234 cur.insert(new InsetSpecialChar(kind));
239 bool doInsertInset(LCursor & cur, LyXText * text,
240 FuncRequest const & cmd, bool edit, bool pastesel)
242 InsetBase * inset = createInset(&cur.bv(), cmd);
248 if (cur.selection()) {
249 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
252 text->insertInset(cur, inset);
255 inset->edit(cur, true);
257 if (gotsel && pastesel)
258 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
263 void update(LCursor & cur)
265 //we don't call update(true, false) directly to save a metrics call
266 if (cur.bv().fitCursor())
267 cur.bv().update(Update::Force);
274 void LyXText::number(LCursor & cur)
276 LyXFont font(LyXFont::ALL_IGNORE);
277 font.setNumber(LyXFont::TOGGLE);
278 toggleAndShow(cur, this, font);
282 bool LyXText::isRTL(Paragraph const & par) const
284 return par.isRightToLeftPar(bv()->buffer()->params());
288 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
290 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
292 BOOST_ASSERT(cur.text() == this);
293 BufferView * bv = &cur.bv();
294 CursorSlice oldTopSlice = cur.top();
295 bool oldBoundary = cur.boundary();
296 bool sel = cur.selection();
297 bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
299 switch (cmd.action) {
301 case LFUN_APPENDIX: {
302 Paragraph & par = cur.paragraph();
303 bool start = !par.params().startOfAppendix();
306 #warning The code below only makes sense at top level.
307 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
309 // ensure that we have only one start_of_appendix in this document
310 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
311 if (pars_[tmp].params().startOfAppendix()) {
313 pars_[tmp].params().startOfAppendix(false);
319 par.params().startOfAppendix(start);
321 // we can set the refreshing parameters now
322 updateCounters(cur.buffer());
326 case LFUN_DELETE_WORD_FORWARD:
327 cur.clearSelection();
328 deleteWordForward(cur);
329 finishChange(cur, false);
332 case LFUN_DELETE_WORD_BACKWARD:
333 cur.clearSelection();
334 deleteWordBackward(cur);
335 finishChange(cur, false);
338 case LFUN_DELETE_LINE_FORWARD:
339 cur.clearSelection();
340 deleteLineForward(cur);
341 finishChange(cur, false);
346 cur.clearSelection();
347 if (isRTL(cur.paragraph()))
348 needsUpdate = cursorLeftOneWord(cur);
350 needsUpdate = cursorRightOneWord(cur);
351 finishChange(cur, false);
356 cur.clearSelection();
357 if (isRTL(cur.paragraph()))
358 needsUpdate = cursorRightOneWord(cur);
360 needsUpdate = cursorLeftOneWord(cur);
361 finishChange(cur, false);
364 case LFUN_BEGINNINGBUF:
365 if (cur.depth() == 1) {
367 cur.clearSelection();
369 finishChange(cur, false);
375 case LFUN_BEGINNINGBUFSEL:
376 if (cur.depth() == 1) {
377 if (!cur.selection())
380 finishChange(cur, true);
387 if (cur.depth() == 1) {
389 cur.clearSelection();
391 finishChange(cur, false);
398 if (cur.depth() == 1) {
399 if (!cur.selection())
402 finishChange(cur, true);
410 //lyxerr << BOOST_CURRENT_FUNCTION
411 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
412 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
413 if (isRTL(cur.paragraph()))
414 needsUpdate = cursorLeft(cur);
416 needsUpdate = cursorRight(cur);
418 if (!needsUpdate && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
420 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
426 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
427 cur.selHandle(cmd.action == LFUN_LEFTSEL);
428 if (isRTL(cur.paragraph()))
429 needsUpdate = cursorRight(cur);
431 needsUpdate = cursorLeft(cur);
432 if (oldTopSlice == cur.top()) {
434 cmd = FuncRequest(LFUN_FINISHED_LEFT);
441 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
442 cur.selHandle(cmd.action == LFUN_UPSEL);
443 needsUpdate = cursorUp(cur);
444 if (oldTopSlice == cur.top()) {
446 cmd = FuncRequest(LFUN_FINISHED_UP);
453 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
454 cur.selHandle(cmd.action == LFUN_DOWNSEL);
455 needsUpdate = cursorDown(cur);
456 if (oldTopSlice == cur.top()) {
458 cmd = FuncRequest(LFUN_FINISHED_DOWN);
462 case LFUN_UP_PARAGRAPH:
464 cur.clearSelection();
465 needsUpdate = cursorUpParagraph(cur);
466 finishChange(cur, false);
469 case LFUN_UP_PARAGRAPHSEL:
470 if (!cur.selection())
472 cursorUpParagraph(cur);
473 finishChange(cur, true);
476 case LFUN_DOWN_PARAGRAPH:
478 cur.clearSelection();
479 needsUpdate = cursorDownParagraph(cur);
480 finishChange(cur, false);
483 case LFUN_DOWN_PARAGRAPHSEL:
484 if (!cur.selection())
486 cursorDownParagraph(cur);
487 finishChange(cur, true);
492 if (!cur.selection())
495 finishChange(cur, true);
500 if (!cur.selection())
503 finishChange(cur, true);
508 if (!cur.selection())
511 finishChange(cur, true);
516 if (!cur.selection())
519 finishChange(cur, true);
522 case LFUN_WORDRIGHTSEL:
523 if (!cur.selection())
525 if (isRTL(cur.paragraph()))
526 cursorLeftOneWord(cur);
528 cursorRightOneWord(cur);
529 finishChange(cur, true);
532 case LFUN_WORDLEFTSEL:
533 if (!cur.selection())
535 if (isRTL(cur.paragraph()))
536 cursorRightOneWord(cur);
538 cursorLeftOneWord(cur);
539 finishChange(cur, true);
543 selectWord(cur, lyx::WHOLE_WORD);
544 finishChange(cur, true);
551 cur.clearSelection();
552 finishChange(cur, false);
553 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
555 cmd = FuncRequest(LFUN_FINISHED_UP);
557 needsUpdate = cursorPrevious(cur);
564 cur.clearSelection();
565 finishChange(cur, false);
566 if (cur.pit() == cur.lastpit()
567 && cur.textRow().endpos() == cur.lastpos()) {
569 cmd = FuncRequest(LFUN_FINISHED_DOWN);
571 needsUpdate = cursorNext(cur);
577 cur.clearSelection();
579 finishChange(cur, false);
584 cur.clearSelection();
586 finishChange(cur, false);
589 case LFUN_BREAKLINE: {
590 // Not allowed by LaTeX (labels or empty par)
591 if (cur.pos() > cur.paragraph().beginOfBody()) {
592 lyx::cap::replaceSelection(cur);
593 cur.insert(new InsetNewline);
595 moveCursor(cur, false);
601 if (!cur.selection()) {
604 // It is possible to make it a lot faster still
605 // just comment out the line below...
607 cutSelection(cur, true, false);
609 moveCursor(cur, false);
612 case LFUN_DELETE_SKIP:
613 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
614 if (!cur.selection()) {
615 if (cur.pos() == cur.lastpos()) {
622 cutSelection(cur, true, false);
628 if (!cur.selection()) {
629 if (bv->owner()->getIntl().getTransManager().backspace()) {
632 // It is possible to make it a lot faster still
633 // just comment out the line below...
636 cutSelection(cur, true, false);
641 case LFUN_BACKSPACE_SKIP:
642 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
643 if (!cur.selection()) {
647 //CursorSlice cur = cursor();
651 cutSelection(cur, true, false);
655 case LFUN_BREAKPARAGRAPH:
656 lyx::cap::replaceSelection(cur);
657 breakParagraph(cur, 0);
662 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
663 lyx::cap::replaceSelection(cur);
664 breakParagraph(cur, 1);
669 case LFUN_BREAKPARAGRAPH_SKIP: {
670 // When at the beginning of a paragraph, remove
671 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
672 lyx::cap::replaceSelection(cur);
674 cur.paragraph().params().labelWidthString(string());
676 breakParagraph(cur, 0);
682 case LFUN_PARAGRAPH_SPACING: {
683 Paragraph & par = cur.paragraph();
684 Spacing::Space cur_spacing = par.params().spacing().getSpace();
685 string cur_value = "1.0";
686 if (cur_spacing == Spacing::Other)
687 cur_value = par.params().spacing().getValueAsString();
689 istringstream is(cmd.argument);
692 Spacing::Space new_spacing = cur_spacing;
693 string new_value = cur_value;
695 lyxerr << "Missing argument to `paragraph-spacing'"
697 } else if (tmp == "single") {
698 new_spacing = Spacing::Single;
699 } else if (tmp == "onehalf") {
700 new_spacing = Spacing::Onehalf;
701 } else if (tmp == "double") {
702 new_spacing = Spacing::Double;
703 } else if (tmp == "other") {
704 new_spacing = Spacing::Other;
705 string tmpval = "0.0";
707 lyxerr << "new_value = " << tmpval << endl;
710 } else if (tmp == "default") {
711 new_spacing = Spacing::Default;
713 lyxerr << _("Unknown spacing argument: ")
714 << cmd.argument << endl;
716 if (cur_spacing != new_spacing || cur_value != new_value)
717 par.params().spacing(Spacing(new_spacing, new_value));
721 case LFUN_INSET_INSERT: {
723 InsetBase * inset = createInset(bv, cmd);
725 insertInset(cur, inset);
731 case LFUN_INSET_SETTINGS:
732 cur.inset().showInsetDialog(bv);
735 case LFUN_NEXT_INSET_TOGGLE: {
736 InsetBase * inset = cur.nextInset();
738 cur.clearSelection();
739 FuncRequest fr = cmd;
740 fr.action = LFUN_INSET_TOGGLE;
741 inset->dispatch(cur, fr);
746 case LFUN_KEYMAP_TOGGLE:
747 cur.clearSelection();
751 case LFUN_SPACE_INSERT:
752 if (cur.paragraph().layout()->free_spacing)
753 insertChar(cur, ' ');
755 doInsertInset(cur, this, cmd, false, false);
758 moveCursor(cur, false);
761 case LFUN_HYPHENATION:
762 specialChar(cur, InsetSpecialChar::HYPHENATION);
765 case LFUN_LIGATURE_BREAK:
766 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
770 specialChar(cur, InsetSpecialChar::LDOTS);
773 case LFUN_END_OF_SENTENCE:
774 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
777 case LFUN_MENU_SEPARATOR:
778 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
781 case LFUN_UPCASE_WORD:
782 changeCase(cur, LyXText::text_uppercase);
785 case LFUN_LOWCASE_WORD:
786 changeCase(cur, LyXText::text_lowercase);
789 case LFUN_CAPITALIZE_WORD:
790 changeCase(cur, LyXText::text_capitalization);
793 case LFUN_TRANSPOSE_CHARS:
798 cur.message(_("Paste"));
799 lyx::cap::replaceSelection(cur);
801 #warning FIXME Check if the arg is in the domain of available selections.
803 if (isStrUnsignedInt(cmd.argument))
804 pasteSelection(cur, convert<unsigned int>(cmd.argument));
806 pasteSelection(cur, 0);
807 cur.clearSelection(); // bug 393
813 cutSelection(cur, true, true);
814 cur.message(_("Cut"));
819 cur.message(_("Copy"));
823 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
824 + convert<string>(cursorY(cur.top(), cur.boundary())));
830 istringstream is(cmd.argument);
833 lyxerr << "SETXY: Could not parse coordinates in '"
834 << cmd.argument << std::endl;
836 setCursorFromCoordinates(cur, x, y);
841 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
843 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
850 cur.message(cur.paragraph().layout()->name());
854 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
855 << cmd.argument << endl;
857 // This is not the good solution to the empty argument
858 // problem, but it will hopefully suffice for 1.2.0.
859 // The correct solution would be to augument the
860 // function list/array with information about what
861 // functions needs arguments and their type.
862 if (cmd.argument.empty()) {
863 cur.errorMessage(_("LyX function 'layout' needs an argument."));
867 // Derive layout number from given argument (string)
868 // and current buffer's textclass (number)
869 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
870 bool hasLayout = tclass.hasLayout(cmd.argument);
871 string layout = cmd.argument;
873 // If the entry is obsolete, use the new one instead.
875 string const & obs = tclass[layout]->obsoleted_by();
881 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
886 bool change_layout = (current_layout != layout);
888 if (!change_layout && cur.selection() &&
889 cur.selBegin().pit() != cur.selEnd().pit())
891 pit_type spit = cur.selBegin().pit();
892 pit_type epit = cur.selEnd().pit() + 1;
893 while (spit != epit) {
894 if (pars_[spit].layout()->name() != current_layout) {
895 change_layout = true;
903 current_layout = layout;
904 setLayout(cur, layout);
905 bv->owner()->setLayout(layout);
911 case LFUN_PASTESELECTION: {
912 cur.clearSelection();
913 string const clip = bv->getClipboard();
915 if (cmd.argument == "paragraph")
916 insertStringAsParagraphs(cur, clip);
918 insertStringAsLines(cur, clip);
924 lyx::cap::replaceSelection(cur);
925 Paragraph & par = cur.paragraph();
926 lyx::pos_type pos = cur.pos();
930 else if (cur.prevInset() && cur.prevInset()->isSpace())
933 c = par.getChar(pos - 1);
935 LyXLayout_ptr const & style = par.layout();
937 BufferParams const & bufparams = bv->buffer()->params();
938 if (!style->pass_thru
939 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
940 string arg = cmd.argument;
942 cur.insert(new InsetQuotes(c,
943 bufparams.quotes_language,
944 InsetQuotes::SingleQ));
945 else if (arg == "double")
946 cur.insert(new InsetQuotes(c,
947 bufparams.quotes_language,
948 InsetQuotes::DoubleQ));
950 cur.insert(new InsetQuotes(c, bufparams));
954 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
958 case LFUN_DATE_INSERT:
959 if (cmd.argument.empty())
960 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
961 lyx::formatted_time(lyx::current_time())));
963 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
964 lyx::formatted_time(lyx::current_time(), cmd.argument)));
967 case LFUN_MOUSE_TRIPLE:
968 if (cmd.button() == mouse_button::button1) {
974 bv->haveSelection(cur.selection());
978 case LFUN_MOUSE_DOUBLE:
979 if (cmd.button() == mouse_button::button1) {
980 selectWord(cur, lyx::WHOLE_WORD_STRICT);
982 bv->haveSelection(cur.selection());
986 // Single-click on work area
987 case LFUN_MOUSE_PRESS: {
988 // Right click on a footnote flag opens float menu
989 if (cmd.button() == mouse_button::button3) {
990 cur.clearSelection();
994 // Middle button press pastes if we have a selection
995 // We do this here as if the selection was inside an inset
996 // it could get cleared on the unlocking of the inset so
997 // we have to check this first
998 bool paste_internally = false;
999 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1000 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1001 paste_internally = true;
1004 // Clear the selection
1005 cur.clearSelection();
1007 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1012 // Has the cursor just left the inset?
1013 if (bv->cursor().inMathed() && !cur.inMathed())
1014 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1019 // Insert primary selection with middle mouse
1020 // if there is a local selection in the current buffer,
1022 if (cmd.button() == mouse_button::button2) {
1023 if (paste_internally)
1024 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1026 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1032 case LFUN_MOUSE_MOTION: {
1033 // Only use motion with button 1
1034 //if (cmd.button() != mouse_button::button1)
1037 // ignore motions deeper nested than the real anchor
1038 LCursor & bvcur = cur.bv().cursor();
1039 if (bvcur.anchor_.hasPart(cur)) {
1040 CursorSlice old = bvcur.top();
1042 int const wh = bv->workHeight();
1043 int const y = std::max(0, std::min(wh - 1, cmd.y));
1045 setCursorFromCoordinates(cur, cmd.x, y);
1046 cur.x_target() = cmd.x;
1051 // This is to allow jumping over large insets
1052 if (cur.top() == old) {
1059 if (cur.top() == old)
1062 // don't set anchor_
1063 bvcur.setCursor(cur);
1064 bvcur.selection() = true;
1065 //lyxerr << "MOTION: " << bv->cursor() << endl;
1073 case LFUN_MOUSE_RELEASE: {
1074 if (cmd.button() == mouse_button::button2)
1078 if (cmd.button() == mouse_button::button1)
1079 bv->haveSelection(cur.selection());
1082 bv->owner()->updateMenubar();
1083 bv->owner()->updateToolbars();
1087 case LFUN_SELFINSERT: {
1088 if (cmd.argument.empty())
1091 // Automatically delete the currently selected
1092 // text and replace it with what is being
1093 // typed in now. Depends on lyxrc settings
1094 // "auto_region_delete", which defaults to
1097 if (lyxrc.auto_region_delete) {
1098 if (cur.selection())
1099 cutSelection(cur, false, false);
1100 bv->haveSelection(false);
1103 cur.clearSelection();
1104 LyXFont const old_font = real_current_font;
1106 // Prevents language turds in new lyxtexts under non-english
1107 BufferParams const & bufparams = cur.buffer().params();
1108 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1109 current_font.setLanguage(lang);
1110 real_current_font.setLanguage(lang);
1112 string::const_iterator cit = cmd.argument.begin();
1113 string::const_iterator end = cmd.argument.end();
1114 for (; cit != end; ++cit)
1115 bv->owner()->getIntl().getTransManager().
1116 TranslateAndInsert(*cit, this);
1119 moveCursor(cur, false);
1121 needsUpdate = redoParagraph(cur.pit());
1123 // update only this paragraph
1124 cur.bv().update(Update::SinglePar | Update::Force);
1127 bv->updateScrollbar();
1132 InsetCommandParams p("url");
1133 string const data = InsetCommandMailer::params2string("url", p);
1134 bv->owner()->getDialogs().show("url", data, 0);
1138 case LFUN_HTMLURL: {
1139 InsetCommandParams p("htmlurl");
1140 string const data = InsetCommandMailer::params2string("url", p);
1141 bv->owner()->getDialogs().show("url", data, 0);
1145 case LFUN_INSERT_LABEL: {
1146 // Try to generate a valid label
1147 string const contents = cmd.argument.empty() ?
1148 cur.getPossibleLabel() : cmd.argument;
1150 InsetCommandParams p("label", contents);
1151 string const data = InsetCommandMailer::params2string("label", p);
1153 if (cmd.argument.empty()) {
1154 bv->owner()->getDialogs().show("label", data, 0);
1156 FuncRequest fr(LFUN_INSET_INSERT, data);
1164 case LFUN_INSET_LIST:
1165 case LFUN_INSET_THEOREM:
1166 case LFUN_INSET_CAPTION:
1168 case LFUN_INSERT_NOTE:
1169 case LFUN_INSERT_CHARSTYLE:
1170 case LFUN_INSERT_BOX:
1171 case LFUN_INSERT_BRANCH:
1172 case LFUN_INSERT_BIBITEM:
1173 case LFUN_INSET_ERT:
1174 case LFUN_INSET_FOOTNOTE:
1175 case LFUN_INSET_MARGINAL:
1176 case LFUN_INSET_OPTARG:
1177 case LFUN_ENVIRONMENT_INSERT:
1178 // Open the inset, and move the current selection
1180 doInsertInset(cur, this, cmd, true, true);
1184 case LFUN_TABULAR_INSERT:
1185 // if there were no arguments, just open the dialog
1186 if (doInsertInset(cur, this, cmd, false, true))
1189 bv->owner()->getDialogs().show("tabularcreate");
1193 case LFUN_INSET_FLOAT:
1194 case LFUN_INSET_WIDE_FLOAT:
1195 case LFUN_INSET_WRAP:
1196 doInsertInset(cur, this, cmd, true, true);
1198 // FIXME: the "Caption" name should not be hardcoded,
1199 // but given by the float definition.
1200 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1203 case LFUN_INDEX_INSERT:
1204 // Just open the inset
1205 doInsertInset(cur, this, cmd, true, false);
1209 case LFUN_INDEX_PRINT:
1210 case LFUN_TOC_INSERT:
1212 case LFUN_INSERT_LINE:
1213 case LFUN_INSERT_PAGEBREAK:
1215 doInsertInset(cur, this, cmd, false, false);
1219 case LFUN_DEPTH_MIN:
1220 changeDepth(cur, DEC_DEPTH);
1223 case LFUN_DEPTH_PLUS:
1224 changeDepth(cur, INC_DEPTH);
1227 case LFUN_MATH_DISPLAY:
1228 mathDispatch(cur, cmd, true);
1231 case LFUN_MATH_IMPORT_SELECTION:
1232 case LFUN_MATH_MODE:
1233 if (cmd.argument == "on")
1234 // don't pass "on" as argument
1235 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1237 mathDispatch(cur, cmd, false);
1240 case LFUN_MATH_MACRO:
1241 if (cmd.argument.empty())
1242 cur.errorMessage(N_("Missing argument"));
1244 string s = cmd.argument;
1245 string const s1 = token(s, ' ', 1);
1246 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1247 string const s2 = token(s, ' ', 2);
1248 string const type = s2.empty() ? "newcommand" : s2;
1249 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1250 //cur.nextInset()->edit(cur, true);
1254 // passthrough hat and underscore outside mathed:
1255 case LFUN_SUBSCRIPT:
1256 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1258 case LFUN_SUPERSCRIPT:
1259 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1262 case LFUN_INSERT_MATH:
1263 case LFUN_INSERT_MATRIX:
1264 case LFUN_MATH_DELIM: {
1265 cur.insert(new MathHullInset);
1266 cur.dispatch(FuncRequest(LFUN_RIGHT));
1267 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1273 LyXFont font(LyXFont::ALL_IGNORE);
1274 font.setEmph(LyXFont::TOGGLE);
1275 toggleAndShow(cur, this, font);
1280 LyXFont font(LyXFont::ALL_IGNORE);
1281 font.setSeries(LyXFont::BOLD_SERIES);
1282 toggleAndShow(cur, this, font);
1287 LyXFont font(LyXFont::ALL_IGNORE);
1288 font.setNoun(LyXFont::TOGGLE);
1289 toggleAndShow(cur, this, font);
1294 LyXFont font(LyXFont::ALL_IGNORE);
1295 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1296 toggleAndShow(cur, this, font);
1301 LyXFont font(LyXFont::ALL_IGNORE);
1302 font.setFamily(LyXFont::SANS_FAMILY);
1303 toggleAndShow(cur, this, font);
1308 LyXFont font(LyXFont::ALL_IGNORE);
1309 font.setFamily(LyXFont::ROMAN_FAMILY);
1310 toggleAndShow(cur, this, font);
1314 case LFUN_DEFAULT: {
1315 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1316 toggleAndShow(cur, this, font);
1320 case LFUN_UNDERLINE: {
1321 LyXFont font(LyXFont::ALL_IGNORE);
1322 font.setUnderbar(LyXFont::TOGGLE);
1323 toggleAndShow(cur, this, font);
1327 case LFUN_FONT_SIZE: {
1328 LyXFont font(LyXFont::ALL_IGNORE);
1329 font.setLyXSize(cmd.argument);
1330 toggleAndShow(cur, this, font);
1334 case LFUN_LANGUAGE: {
1335 Language const * lang = languages.getLanguage(cmd.argument);
1338 LyXFont font(LyXFont::ALL_IGNORE);
1339 font.setLanguage(lang);
1340 toggleAndShow(cur, this, font);
1345 case LFUN_FREEFONT_APPLY:
1346 toggleAndShow(cur, this, freefont, toggleall);
1347 cur.message(_("Character set"));
1350 // Set the freefont using the contents of \param data dispatched from
1351 // the frontends and apply it at the current cursor location.
1352 case LFUN_FREEFONT_UPDATE: {
1355 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1358 toggleAndShow(cur, this, freefont, toggleall);
1359 cur.message(_("Character set"));
1364 case LFUN_FINISHED_LEFT:
1365 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1368 case LFUN_FINISHED_RIGHT:
1369 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1373 case LFUN_FINISHED_UP:
1374 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1378 case LFUN_FINISHED_DOWN:
1379 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1383 case LFUN_LAYOUT_PARAGRAPH: {
1385 params2string(cur.paragraph(), data);
1386 data = "show\n" + data;
1387 bv->owner()->getDialogs().show("paragraph", data);
1391 case LFUN_PARAGRAPH_UPDATE: {
1392 if (!bv->owner()->getDialogs().visible("paragraph"))
1395 params2string(cur.paragraph(), data);
1397 // Will the paragraph accept changes from the dialog?
1398 InsetBase & inset = cur.inset();
1399 bool const accept = !inset.forceDefaultParagraphs(&inset);
1401 data = "update " + convert<string>(accept) + '\n' + data;
1402 bv->owner()->getDialogs().update("paragraph", data);
1407 case LFUN_CIRCUMFLEX:
1417 case LFUN_SPECIAL_CARON:
1420 case LFUN_HUNG_UMLAUT:
1423 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1424 if (!cmd.argument.empty())
1425 bv->owner()->getIntl().getTransManager()
1426 .TranslateAndInsert(cmd.argument[0], this);
1429 case LFUN_FLOAT_LIST: {
1430 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1431 if (tclass.floats().typeExist(cmd.argument)) {
1432 // not quite sure if we want this...
1434 cur.clearSelection();
1435 breakParagraph(cur);
1437 if (cur.lastpos() != 0) {
1439 breakParagraph(cur);
1442 setLayout(cur, tclass.defaultLayoutName());
1443 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1444 insertInset(cur, new InsetFloatList(cmd.argument));
1447 lyxerr << "Non-existent float type: "
1448 << cmd.argument << endl;
1453 case LFUN_ACCEPT_CHANGE: {
1458 case LFUN_REJECT_CHANGE: {
1463 case LFUN_THESAURUS_ENTRY: {
1464 string arg = cmd.argument;
1466 arg = cur.selectionAsString(false);
1468 if (arg.size() > 100 || arg.empty()) {
1469 // Get word or selection
1470 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1471 arg = cur.selectionAsString(false);
1474 bv->owner()->getDialogs().show("thesaurus", arg);
1478 case LFUN_PARAGRAPH_APPLY: {
1479 // Given data, an encoding of the ParagraphParameters
1480 // generated in the Paragraph dialog, this function sets
1481 // the current paragraph appropriately.
1482 istringstream is(cmd.argument);
1485 ParagraphParameters params;
1490 params.labelWidthString(),
1492 cur.message(_("Paragraph layout set"));
1496 case LFUN_INSET_DIALOG_SHOW: {
1497 InsetBase * inset = cur.nextInset();
1499 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1500 inset->dispatch(cur, fr);
1506 if (cur.selection()) {
1507 cur.selection() = false;
1510 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1515 lyxerr << BOOST_CURRENT_FUNCTION
1516 << " Not DISPATCHED by LyXText" << endl;
1522 && &oldTopSlice.inset() == &cur.inset()
1523 && oldTopSlice.idx() == cur.idx()
1525 && !cur.selection())
1532 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1533 FuncStatus & flag) const
1535 BOOST_ASSERT(cur.text() == this);
1536 LyXFont const & font = real_current_font;
1539 switch (cmd.action) {
1541 case LFUN_DEPTH_MIN:
1542 enable = changeDepthAllowed(cur, DEC_DEPTH);
1545 case LFUN_DEPTH_PLUS:
1546 enable = changeDepthAllowed(cur, INC_DEPTH);
1549 case LFUN_INSET_OPTARG:
1550 enable = numberOfOptArgs(cur.paragraph())
1551 < cur.paragraph().layout()->optionalargs;
1555 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1558 case LFUN_INSERT_BIBITEM:
1559 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1563 // the functions which insert insets
1564 InsetBase::Code code = InsetBase::NO_CODE;
1565 switch (cmd.action) {
1566 case LFUN_DIALOG_SHOW_NEW_INSET:
1567 if (cmd.argument == "bibitem")
1568 code = InsetBase::BIBITEM_CODE;
1569 else if (cmd.argument == "bibtex")
1570 code = InsetBase::BIBTEX_CODE;
1571 else if (cmd.argument == "box")
1572 code = InsetBase::BOX_CODE;
1573 else if (cmd.argument == "branch")
1574 code = InsetBase::BRANCH_CODE;
1575 else if (cmd.argument == "citation")
1576 code = InsetBase::CITE_CODE;
1577 else if (cmd.argument == "ert")
1578 code = InsetBase::ERT_CODE;
1579 else if (cmd.argument == "external")
1580 code = InsetBase::EXTERNAL_CODE;
1581 else if (cmd.argument == "float")
1582 code = InsetBase::FLOAT_CODE;
1583 else if (cmd.argument == "graphics")
1584 code = InsetBase::GRAPHICS_CODE;
1585 else if (cmd.argument == "include")
1586 code = InsetBase::INCLUDE_CODE;
1587 else if (cmd.argument == "index")
1588 code = InsetBase::INDEX_CODE;
1589 else if (cmd.argument == "label")
1590 code = InsetBase::LABEL_CODE;
1591 else if (cmd.argument == "note")
1592 code = InsetBase::NOTE_CODE;
1593 else if (cmd.argument == "ref")
1594 code = InsetBase::REF_CODE;
1595 else if (cmd.argument == "toc")
1596 code = InsetBase::TOC_CODE;
1597 else if (cmd.argument == "url")
1598 code = InsetBase::URL_CODE;
1599 else if (cmd.argument == "vspace")
1600 code = InsetBase::VSPACE_CODE;
1601 else if (cmd.argument == "wrap")
1602 code = InsetBase::WRAP_CODE;
1605 case LFUN_INSET_ERT:
1606 code = InsetBase::ERT_CODE;
1608 case LFUN_INSET_FOOTNOTE:
1609 code = InsetBase::FOOT_CODE;
1611 case LFUN_TABULAR_INSERT:
1612 code = InsetBase::TABULAR_CODE;
1614 case LFUN_INSET_MARGINAL:
1615 code = InsetBase::MARGIN_CODE;
1617 case LFUN_INSET_FLOAT:
1618 case LFUN_INSET_WIDE_FLOAT:
1619 code = InsetBase::FLOAT_CODE;
1621 case LFUN_INSET_WRAP:
1622 code = InsetBase::WRAP_CODE;
1624 case LFUN_FLOAT_LIST:
1625 code = InsetBase::FLOAT_LIST_CODE;
1628 case LFUN_INSET_LIST:
1629 code = InsetBase::LIST_CODE;
1631 case LFUN_INSET_THEOREM:
1632 code = InsetBase::THEOREM_CODE;
1635 case LFUN_INSET_CAPTION:
1636 code = InsetBase::CAPTION_CODE;
1638 case LFUN_INSERT_NOTE:
1639 code = InsetBase::NOTE_CODE;
1641 case LFUN_INSERT_CHARSTYLE:
1642 code = InsetBase::CHARSTYLE_CODE;
1643 if (buf->params().getLyXTextClass().charstyles().empty())
1646 case LFUN_INSERT_BOX:
1647 code = InsetBase::BOX_CODE;
1649 case LFUN_INSERT_BRANCH:
1650 code = InsetBase::BRANCH_CODE;
1651 if (buf->params().branchlist().empty())
1654 case LFUN_INSERT_LABEL:
1655 code = InsetBase::LABEL_CODE;
1657 case LFUN_INSET_OPTARG:
1658 code = InsetBase::OPTARG_CODE;
1660 case LFUN_ENVIRONMENT_INSERT:
1661 code = InsetBase::BOX_CODE;
1663 case LFUN_INDEX_INSERT:
1664 code = InsetBase::INDEX_CODE;
1666 case LFUN_INDEX_PRINT:
1667 code = InsetBase::INDEX_PRINT_CODE;
1669 case LFUN_TOC_INSERT:
1670 code = InsetBase::TOC_CODE;
1674 code = InsetBase::URL_CODE;
1677 // always allow this, since we will inset a raw quote
1678 // if an inset is not allowed.
1680 case LFUN_HYPHENATION:
1681 case LFUN_LIGATURE_BREAK:
1683 case LFUN_MENU_SEPARATOR:
1685 case LFUN_END_OF_SENTENCE:
1686 code = InsetBase::SPECIALCHAR_CODE;
1688 case LFUN_SPACE_INSERT:
1689 // slight hack: we know this is allowed in math mode
1691 code = InsetBase::SPACE_CODE;
1693 case LFUN_INSET_DIALOG_SHOW: {
1694 InsetBase * inset = cur.nextInset();
1697 code = inset->lyxCode();
1698 if (!(code == InsetBase::INCLUDE_CODE
1699 || code == InsetBase::BIBTEX_CODE
1700 || code == InsetBase::FLOAT_LIST_CODE
1701 || code == InsetBase::TOC_CODE))
1710 if (code != InsetBase::NO_CODE
1711 && (cur.empty() || !cur.inset().insetAllowed(code)))
1716 case LFUN_DIALOG_SHOW_NEW_INSET:
1717 case LFUN_INSET_ERT:
1718 case LFUN_INSERT_BOX:
1719 case LFUN_INSERT_BRANCH:
1720 case LFUN_ENVIRONMENT_INSERT:
1721 case LFUN_INDEX_INSERT:
1722 case LFUN_INDEX_PRINT:
1723 case LFUN_TOC_INSERT:
1727 case LFUN_HYPHENATION:
1728 case LFUN_LIGATURE_BREAK:
1730 case LFUN_MENU_SEPARATOR:
1732 case LFUN_END_OF_SENTENCE:
1733 case LFUN_SPACE_INSERT:
1734 case LFUN_INSET_DIALOG_SHOW:
1737 case LFUN_INSET_MODIFY:
1738 // We need to disable this, because we may get called for a
1740 // InsetTabular::getStatus() -> InsetText::getStatus()
1741 // and we don't handle LFUN_INSET_MODIFY.
1746 flag.setOnOff(font.emph() == LyXFont::ON);
1750 flag.setOnOff(font.noun() == LyXFont::ON);
1754 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1758 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1762 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1766 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1769 case LFUN_DELETE_WORD_FORWARD:
1770 case LFUN_DELETE_WORD_BACKWARD:
1771 case LFUN_DELETE_LINE_FORWARD:
1772 case LFUN_WORDRIGHT:
1782 case LFUN_UP_PARAGRAPHSEL:
1783 case LFUN_DOWN_PARAGRAPHSEL:
1788 case LFUN_WORDRIGHTSEL:
1789 case LFUN_WORDLEFTSEL:
1791 case LFUN_UP_PARAGRAPH:
1792 case LFUN_DOWN_PARAGRAPH:
1797 case LFUN_BREAKLINE:
1799 case LFUN_DELETE_SKIP:
1800 case LFUN_BACKSPACE:
1801 case LFUN_BACKSPACE_SKIP:
1802 case LFUN_BREAKPARAGRAPH:
1803 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1804 case LFUN_BREAKPARAGRAPH_SKIP:
1805 case LFUN_PARAGRAPH_SPACING:
1806 case LFUN_INSET_INSERT:
1807 case LFUN_NEXT_INSET_TOGGLE:
1808 case LFUN_UPCASE_WORD:
1809 case LFUN_LOWCASE_WORD:
1810 case LFUN_CAPITALIZE_WORD:
1811 case LFUN_TRANSPOSE_CHARS:
1818 case LFUN_GETLAYOUT:
1820 case LFUN_PASTESELECTION:
1821 case LFUN_DATE_INSERT:
1822 case LFUN_SELFINSERT:
1823 case LFUN_INSERT_LABEL:
1824 case LFUN_INSERT_NOTE:
1825 case LFUN_INSERT_CHARSTYLE:
1826 case LFUN_INSET_FLOAT:
1827 case LFUN_INSET_FOOTNOTE:
1828 case LFUN_INSET_MARGINAL:
1829 case LFUN_INSET_WIDE_FLOAT:
1830 case LFUN_INSET_WRAP:
1831 case LFUN_TABULAR_INSERT:
1832 case LFUN_INSERT_LINE:
1833 case LFUN_INSERT_PAGEBREAK:
1834 case LFUN_MATH_DISPLAY:
1835 case LFUN_MATH_IMPORT_SELECTION:
1836 case LFUN_MATH_MODE:
1837 case LFUN_MATH_MACRO:
1838 case LFUN_INSERT_MATH:
1839 case LFUN_INSERT_MATRIX:
1840 case LFUN_MATH_DELIM:
1841 case LFUN_SUBSCRIPT:
1842 case LFUN_SUPERSCRIPT:
1844 case LFUN_UNDERLINE:
1845 case LFUN_FONT_SIZE:
1847 case LFUN_FREEFONT_APPLY:
1848 case LFUN_FREEFONT_UPDATE:
1849 case LFUN_LAYOUT_PARAGRAPH:
1850 case LFUN_PARAGRAPH_UPDATE:
1852 case LFUN_CIRCUMFLEX:
1862 case LFUN_SPECIAL_CARON:
1865 case LFUN_HUNG_UMLAUT:
1868 case LFUN_FLOAT_LIST:
1869 case LFUN_ACCEPT_CHANGE:
1870 case LFUN_REJECT_CHANGE:
1871 case LFUN_THESAURUS_ENTRY:
1872 case LFUN_PARAGRAPH_APPLY:
1874 case LFUN_KEYMAP_TOGGLE:
1876 case LFUN_BEGINNINGBUF:
1877 case LFUN_BEGINNINGBUFSEL:
1878 case LFUN_ENDBUFSEL:
1879 // these are handled in our dispatch()
1886 flag.enabled(enable);