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 // Signals that, even if needsUpdate == false, an update of the
298 // cursor paragraph is required
299 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
300 LyXAction::SingleParUpdate);
301 // Signals that a full-screen update is required
302 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
303 LyXAction::NoUpdate) || singleParUpdate);
304 // Remember the old paragraph metric
305 Dimension olddim = cur.paragraph().dim();
307 switch (cmd.action) {
309 case LFUN_APPENDIX: {
310 Paragraph & par = cur.paragraph();
311 bool start = !par.params().startOfAppendix();
314 #warning The code below only makes sense at top level.
315 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
317 // ensure that we have only one start_of_appendix in this document
318 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
319 if (pars_[tmp].params().startOfAppendix()) {
321 pars_[tmp].params().startOfAppendix(false);
327 par.params().startOfAppendix(start);
329 // we can set the refreshing parameters now
330 updateCounters(cur.buffer());
334 case LFUN_DELETE_WORD_FORWARD:
335 cur.clearSelection();
336 deleteWordForward(cur);
337 finishChange(cur, false);
340 case LFUN_DELETE_WORD_BACKWARD:
341 cur.clearSelection();
342 deleteWordBackward(cur);
343 finishChange(cur, false);
346 case LFUN_DELETE_LINE_FORWARD:
347 cur.clearSelection();
348 deleteLineForward(cur);
349 finishChange(cur, false);
354 cur.clearSelection();
355 if (isRTL(cur.paragraph()))
356 needsUpdate = cursorLeftOneWord(cur);
358 needsUpdate = cursorRightOneWord(cur);
359 finishChange(cur, false);
364 cur.clearSelection();
365 if (isRTL(cur.paragraph()))
366 needsUpdate = cursorRightOneWord(cur);
368 needsUpdate = cursorLeftOneWord(cur);
369 finishChange(cur, false);
372 case LFUN_BEGINNINGBUF:
373 if (cur.depth() == 1) {
375 cur.clearSelection();
377 finishChange(cur, false);
383 case LFUN_BEGINNINGBUFSEL:
384 if (cur.depth() == 1) {
385 if (!cur.selection())
388 finishChange(cur, true);
395 if (cur.depth() == 1) {
397 cur.clearSelection();
399 finishChange(cur, false);
406 if (cur.depth() == 1) {
407 if (!cur.selection())
410 finishChange(cur, true);
418 //lyxerr << BOOST_CURRENT_FUNCTION
419 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
420 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
421 if (isRTL(cur.paragraph()))
422 needsUpdate = cursorLeft(cur);
424 needsUpdate = cursorRight(cur);
426 if (!needsUpdate && oldTopSlice == cur.top()
427 && cur.boundary() == oldBoundary) {
429 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
435 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
436 cur.selHandle(cmd.action == LFUN_LEFTSEL);
437 if (isRTL(cur.paragraph()))
438 needsUpdate = cursorRight(cur);
440 needsUpdate = cursorLeft(cur);
442 if (!needsUpdate && oldTopSlice == cur.top()
443 && cur.boundary() == oldBoundary) {
445 cmd = FuncRequest(LFUN_FINISHED_LEFT);
452 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
453 cur.selHandle(cmd.action == LFUN_UPSEL);
455 needsUpdate = cursorUp(cur);
456 if (!needsUpdate && oldTopSlice == cur.top()
457 && cur.boundary() == oldBoundary) {
459 cmd = FuncRequest(LFUN_FINISHED_UP);
466 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
467 cur.selHandle(cmd.action == LFUN_DOWNSEL);
468 needsUpdate = cursorDown(cur);
469 if (!needsUpdate && oldTopSlice == cur.top() &&
470 cur.boundary() == oldBoundary)
473 cmd = FuncRequest(LFUN_FINISHED_DOWN);
477 case LFUN_UP_PARAGRAPH:
479 cur.clearSelection();
480 needsUpdate = cursorUpParagraph(cur);
481 finishChange(cur, false);
484 case LFUN_UP_PARAGRAPHSEL:
485 if (!cur.selection())
487 cursorUpParagraph(cur);
488 finishChange(cur, true);
491 case LFUN_DOWN_PARAGRAPH:
493 cur.clearSelection();
494 needsUpdate = cursorDownParagraph(cur);
495 finishChange(cur, false);
498 case LFUN_DOWN_PARAGRAPHSEL:
499 if (!cur.selection())
501 cursorDownParagraph(cur);
502 finishChange(cur, true);
507 if (!cur.selection())
510 finishChange(cur, true);
515 if (!cur.selection())
518 finishChange(cur, true);
523 if (!cur.selection())
526 finishChange(cur, true);
531 if (!cur.selection())
534 finishChange(cur, true);
537 case LFUN_WORDRIGHTSEL:
538 if (!cur.selection())
540 if (isRTL(cur.paragraph()))
541 cursorLeftOneWord(cur);
543 cursorRightOneWord(cur);
544 finishChange(cur, true);
547 case LFUN_WORDLEFTSEL:
548 if (!cur.selection())
550 if (isRTL(cur.paragraph()))
551 cursorRightOneWord(cur);
553 cursorLeftOneWord(cur);
554 finishChange(cur, true);
558 selectWord(cur, lyx::WHOLE_WORD);
559 finishChange(cur, true);
566 cur.clearSelection();
567 finishChange(cur, false);
568 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
570 cmd = FuncRequest(LFUN_FINISHED_UP);
572 needsUpdate = cursorPrevious(cur);
579 cur.clearSelection();
580 finishChange(cur, false);
581 if (cur.pit() == cur.lastpit()
582 && cur.textRow().endpos() == cur.lastpos()) {
584 cmd = FuncRequest(LFUN_FINISHED_DOWN);
586 needsUpdate = cursorNext(cur);
592 cur.clearSelection();
594 finishChange(cur, false);
599 cur.clearSelection();
601 finishChange(cur, false);
604 case LFUN_BREAKLINE: {
605 // Not allowed by LaTeX (labels or empty par)
606 if (cur.pos() > cur.paragraph().beginOfBody()) {
607 lyx::cap::replaceSelection(cur);
608 cur.insert(new InsetNewline);
610 moveCursor(cur, false);
616 if (!cur.selection()) {
619 // It is possible to make it a lot faster still
620 // just comment out the line below...
622 cutSelection(cur, true, false);
624 moveCursor(cur, false);
627 case LFUN_DELETE_SKIP:
628 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
629 if (!cur.selection()) {
630 if (cur.pos() == cur.lastpos()) {
637 cutSelection(cur, true, false);
643 if (!cur.selection()) {
644 if (bv->owner()->getIntl().getTransManager().backspace()) {
647 // It is possible to make it a lot faster still
648 // just comment out the line below...
651 cutSelection(cur, true, false);
656 case LFUN_BACKSPACE_SKIP:
657 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
658 if (!cur.selection()) {
662 //CursorSlice cur = cursor();
666 cutSelection(cur, true, false);
670 case LFUN_BREAKPARAGRAPH:
671 lyx::cap::replaceSelection(cur);
672 breakParagraph(cur, 0);
677 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
678 lyx::cap::replaceSelection(cur);
679 breakParagraph(cur, 1);
684 case LFUN_BREAKPARAGRAPH_SKIP: {
685 // When at the beginning of a paragraph, remove
686 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
687 lyx::cap::replaceSelection(cur);
689 cur.paragraph().params().labelWidthString(string());
691 breakParagraph(cur, 0);
697 case LFUN_PARAGRAPH_SPACING: {
698 Paragraph & par = cur.paragraph();
699 Spacing::Space cur_spacing = par.params().spacing().getSpace();
700 string cur_value = "1.0";
701 if (cur_spacing == Spacing::Other)
702 cur_value = par.params().spacing().getValueAsString();
704 istringstream is(cmd.argument);
707 Spacing::Space new_spacing = cur_spacing;
708 string new_value = cur_value;
710 lyxerr << "Missing argument to `paragraph-spacing'"
712 } else if (tmp == "single") {
713 new_spacing = Spacing::Single;
714 } else if (tmp == "onehalf") {
715 new_spacing = Spacing::Onehalf;
716 } else if (tmp == "double") {
717 new_spacing = Spacing::Double;
718 } else if (tmp == "other") {
719 new_spacing = Spacing::Other;
720 string tmpval = "0.0";
722 lyxerr << "new_value = " << tmpval << endl;
725 } else if (tmp == "default") {
726 new_spacing = Spacing::Default;
728 lyxerr << _("Unknown spacing argument: ")
729 << cmd.argument << endl;
731 if (cur_spacing != new_spacing || cur_value != new_value)
732 par.params().spacing(Spacing(new_spacing, new_value));
736 case LFUN_INSET_INSERT: {
738 InsetBase * inset = createInset(bv, cmd);
740 insertInset(cur, inset);
746 case LFUN_INSET_SETTINGS:
747 cur.inset().showInsetDialog(bv);
750 case LFUN_NEXT_INSET_TOGGLE: {
751 InsetBase * inset = cur.nextInset();
753 cur.clearSelection();
754 FuncRequest fr = cmd;
755 fr.action = LFUN_INSET_TOGGLE;
756 inset->dispatch(cur, fr);
761 case LFUN_KEYMAP_TOGGLE:
762 cur.clearSelection();
766 case LFUN_SPACE_INSERT:
767 if (cur.paragraph().layout()->free_spacing)
768 insertChar(cur, ' ');
770 doInsertInset(cur, this, cmd, false, false);
773 moveCursor(cur, false);
776 case LFUN_HYPHENATION:
777 specialChar(cur, InsetSpecialChar::HYPHENATION);
780 case LFUN_LIGATURE_BREAK:
781 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
785 specialChar(cur, InsetSpecialChar::LDOTS);
788 case LFUN_END_OF_SENTENCE:
789 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
792 case LFUN_MENU_SEPARATOR:
793 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
796 case LFUN_UPCASE_WORD:
797 changeCase(cur, LyXText::text_uppercase);
800 case LFUN_LOWCASE_WORD:
801 changeCase(cur, LyXText::text_lowercase);
804 case LFUN_CAPITALIZE_WORD:
805 changeCase(cur, LyXText::text_capitalization);
808 case LFUN_TRANSPOSE_CHARS:
813 cur.message(_("Paste"));
814 lyx::cap::replaceSelection(cur);
816 #warning FIXME Check if the arg is in the domain of available selections.
818 if (isStrUnsignedInt(cmd.argument))
819 pasteSelection(cur, convert<unsigned int>(cmd.argument));
821 pasteSelection(cur, 0);
822 cur.clearSelection(); // bug 393
828 cutSelection(cur, true, true);
829 cur.message(_("Cut"));
834 cur.message(_("Copy"));
838 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
839 + convert<string>(cursorY(cur.top(), cur.boundary())));
845 istringstream is(cmd.argument);
848 lyxerr << "SETXY: Could not parse coordinates in '"
849 << cmd.argument << std::endl;
851 setCursorFromCoordinates(cur, x, y);
856 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
858 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
865 cur.message(cur.paragraph().layout()->name());
869 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
870 << cmd.argument << endl;
872 // This is not the good solution to the empty argument
873 // problem, but it will hopefully suffice for 1.2.0.
874 // The correct solution would be to augument the
875 // function list/array with information about what
876 // functions needs arguments and their type.
877 if (cmd.argument.empty()) {
878 cur.errorMessage(_("LyX function 'layout' needs an argument."));
882 // Derive layout number from given argument (string)
883 // and current buffer's textclass (number)
884 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
885 bool hasLayout = tclass.hasLayout(cmd.argument);
886 string layout = cmd.argument;
888 // If the entry is obsolete, use the new one instead.
890 string const & obs = tclass[layout]->obsoleted_by();
896 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
901 bool change_layout = (current_layout != layout);
903 if (!change_layout && cur.selection() &&
904 cur.selBegin().pit() != cur.selEnd().pit())
906 pit_type spit = cur.selBegin().pit();
907 pit_type epit = cur.selEnd().pit() + 1;
908 while (spit != epit) {
909 if (pars_[spit].layout()->name() != current_layout) {
910 change_layout = true;
918 current_layout = layout;
919 setLayout(cur, layout);
920 bv->owner()->setLayout(layout);
926 case LFUN_PASTESELECTION: {
927 cur.clearSelection();
928 string const clip = bv->getClipboard();
931 if (cmd.argument == "paragraph")
932 insertStringAsParagraphs(cur, clip);
934 insertStringAsLines(cur, clip);
940 lyx::cap::replaceSelection(cur);
941 Paragraph & par = cur.paragraph();
942 lyx::pos_type pos = cur.pos();
946 else if (cur.prevInset() && cur.prevInset()->isSpace())
949 c = par.getChar(pos - 1);
951 LyXLayout_ptr const & style = par.layout();
953 BufferParams const & bufparams = bv->buffer()->params();
954 if (!style->pass_thru
955 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
956 string arg = cmd.argument;
958 cur.insert(new InsetQuotes(c,
959 bufparams.quotes_language,
960 InsetQuotes::SingleQ));
961 else if (arg == "double")
962 cur.insert(new InsetQuotes(c,
963 bufparams.quotes_language,
964 InsetQuotes::DoubleQ));
966 cur.insert(new InsetQuotes(c, bufparams));
970 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
974 case LFUN_DATE_INSERT:
975 if (cmd.argument.empty())
976 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
977 lyx::formatted_time(lyx::current_time())));
979 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
980 lyx::formatted_time(lyx::current_time(), cmd.argument)));
983 case LFUN_MOUSE_TRIPLE:
984 if (cmd.button() == mouse_button::button1) {
990 bv->haveSelection(cur.selection());
994 case LFUN_MOUSE_DOUBLE:
995 if (cmd.button() == mouse_button::button1) {
996 selectWord(cur, lyx::WHOLE_WORD_STRICT);
998 bv->haveSelection(cur.selection());
1002 // Single-click on work area
1003 case LFUN_MOUSE_PRESS: {
1004 // Right click on a footnote flag opens float menu
1005 if (cmd.button() == mouse_button::button3) {
1006 cur.clearSelection();
1010 // Middle button press pastes if we have a selection
1011 // We do this here as if the selection was inside an inset
1012 // it could get cleared on the unlocking of the inset so
1013 // we have to check this first
1014 bool paste_internally = false;
1015 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1016 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1017 paste_internally = true;
1020 // Clear the selection
1021 cur.clearSelection();
1023 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1028 // Has the cursor just left the inset?
1029 if (bv->cursor().inMathed() && !cur.inMathed())
1030 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1035 // Insert primary selection with middle mouse
1036 // if there is a local selection in the current buffer,
1038 if (cmd.button() == mouse_button::button2) {
1039 if (paste_internally)
1040 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1042 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1048 case LFUN_MOUSE_MOTION: {
1049 // Only use motion with button 1
1050 //if (cmd.button() != mouse_button::button1)
1053 // ignore motions deeper nested than the real anchor
1054 LCursor & bvcur = cur.bv().cursor();
1055 if (bvcur.anchor_.hasPart(cur)) {
1056 CursorSlice old = bvcur.top();
1058 int const wh = bv->workHeight();
1059 int const y = std::max(0, std::min(wh - 1, cmd.y));
1061 setCursorFromCoordinates(cur, cmd.x, y);
1062 cur.x_target() = cmd.x;
1067 // This is to allow jumping over large insets
1068 if (cur.top() == old) {
1075 if (cur.top() == old)
1078 // don't set anchor_
1079 bvcur.setCursor(cur);
1080 bvcur.selection() = true;
1081 //lyxerr << "MOTION: " << bv->cursor() << endl;
1089 case LFUN_MOUSE_RELEASE: {
1090 if (cmd.button() == mouse_button::button2)
1094 if (cmd.button() == mouse_button::button1)
1095 bv->haveSelection(cur.selection());
1098 bv->owner()->updateMenubar();
1099 bv->owner()->updateToolbars();
1103 case LFUN_SELFINSERT: {
1104 if (cmd.argument.empty())
1107 // Automatically delete the currently selected
1108 // text and replace it with what is being
1109 // typed in now. Depends on lyxrc settings
1110 // "auto_region_delete", which defaults to
1113 if (lyxrc.auto_region_delete) {
1114 if (cur.selection())
1115 cutSelection(cur, false, false);
1116 bv->haveSelection(false);
1119 cur.clearSelection();
1120 LyXFont const old_font = real_current_font;
1122 // Prevents language turds in new lyxtexts under non-english
1123 BufferParams const & bufparams = cur.buffer().params();
1124 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1125 current_font.setLanguage(lang);
1126 real_current_font.setLanguage(lang);
1128 string::const_iterator cit = cmd.argument.begin();
1129 string::const_iterator end = cmd.argument.end();
1130 for (; cit != end; ++cit)
1131 bv->owner()->getIntl().getTransManager().
1132 TranslateAndInsert(*cit, this);
1135 moveCursor(cur, false);
1136 bv->updateScrollbar();
1141 InsetCommandParams p("url");
1142 string const data = InsetCommandMailer::params2string("url", p);
1143 bv->owner()->getDialogs().show("url", data, 0);
1147 case LFUN_HTMLURL: {
1148 InsetCommandParams p("htmlurl");
1149 string const data = InsetCommandMailer::params2string("url", p);
1150 bv->owner()->getDialogs().show("url", data, 0);
1154 case LFUN_INSERT_LABEL: {
1155 // Try to generate a valid label
1156 string const contents = cmd.argument.empty() ?
1157 cur.getPossibleLabel() : cmd.argument;
1159 InsetCommandParams p("label", contents);
1160 string const data = InsetCommandMailer::params2string("label", p);
1162 if (cmd.argument.empty()) {
1163 bv->owner()->getDialogs().show("label", data, 0);
1165 FuncRequest fr(LFUN_INSET_INSERT, data);
1173 case LFUN_INSET_LIST:
1174 case LFUN_INSET_THEOREM:
1175 case LFUN_INSET_CAPTION:
1177 case LFUN_INSERT_NOTE:
1178 case LFUN_INSERT_CHARSTYLE:
1179 case LFUN_INSERT_BOX:
1180 case LFUN_INSERT_BRANCH:
1181 case LFUN_INSERT_BIBITEM:
1182 case LFUN_INSET_ERT:
1183 case LFUN_INSET_FOOTNOTE:
1184 case LFUN_INSET_MARGINAL:
1185 case LFUN_INSET_OPTARG:
1186 case LFUN_ENVIRONMENT_INSERT:
1187 // Open the inset, and move the current selection
1189 doInsertInset(cur, this, cmd, true, true);
1193 case LFUN_TABULAR_INSERT:
1194 // if there were no arguments, just open the dialog
1195 if (doInsertInset(cur, this, cmd, false, true))
1198 bv->owner()->getDialogs().show("tabularcreate");
1202 case LFUN_INSET_FLOAT:
1203 case LFUN_INSET_WIDE_FLOAT:
1204 case LFUN_INSET_WRAP:
1205 doInsertInset(cur, this, cmd, true, true);
1207 // FIXME: the "Caption" name should not be hardcoded,
1208 // but given by the float definition.
1209 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1212 case LFUN_INDEX_INSERT:
1213 // Just open the inset
1214 doInsertInset(cur, this, cmd, true, false);
1218 case LFUN_INDEX_PRINT:
1219 case LFUN_TOC_INSERT:
1221 case LFUN_INSERT_LINE:
1222 case LFUN_INSERT_PAGEBREAK:
1224 doInsertInset(cur, this, cmd, false, false);
1228 case LFUN_DEPTH_MIN:
1229 changeDepth(cur, DEC_DEPTH);
1232 case LFUN_DEPTH_PLUS:
1233 changeDepth(cur, INC_DEPTH);
1236 case LFUN_MATH_DISPLAY:
1237 mathDispatch(cur, cmd, true);
1240 case LFUN_MATH_IMPORT_SELECTION:
1241 case LFUN_MATH_MODE:
1242 if (cmd.argument == "on")
1243 // don't pass "on" as argument
1244 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1246 mathDispatch(cur, cmd, false);
1249 case LFUN_MATH_MACRO:
1250 if (cmd.argument.empty())
1251 cur.errorMessage(N_("Missing argument"));
1253 string s = cmd.argument;
1254 string const s1 = token(s, ' ', 1);
1255 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1256 string const s2 = token(s, ' ', 2);
1257 string const type = s2.empty() ? "newcommand" : s2;
1258 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1259 //cur.nextInset()->edit(cur, true);
1263 // passthrough hat and underscore outside mathed:
1264 case LFUN_SUBSCRIPT:
1265 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1267 case LFUN_SUPERSCRIPT:
1268 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1271 case LFUN_INSERT_MATH:
1272 case LFUN_INSERT_MATRIX:
1273 case LFUN_MATH_DELIM: {
1274 cur.insert(new MathHullInset);
1275 cur.dispatch(FuncRequest(LFUN_RIGHT));
1276 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1282 LyXFont font(LyXFont::ALL_IGNORE);
1283 font.setEmph(LyXFont::TOGGLE);
1284 toggleAndShow(cur, this, font);
1289 LyXFont font(LyXFont::ALL_IGNORE);
1290 font.setSeries(LyXFont::BOLD_SERIES);
1291 toggleAndShow(cur, this, font);
1296 LyXFont font(LyXFont::ALL_IGNORE);
1297 font.setNoun(LyXFont::TOGGLE);
1298 toggleAndShow(cur, this, font);
1303 LyXFont font(LyXFont::ALL_IGNORE);
1304 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1305 toggleAndShow(cur, this, font);
1310 LyXFont font(LyXFont::ALL_IGNORE);
1311 font.setFamily(LyXFont::SANS_FAMILY);
1312 toggleAndShow(cur, this, font);
1317 LyXFont font(LyXFont::ALL_IGNORE);
1318 font.setFamily(LyXFont::ROMAN_FAMILY);
1319 toggleAndShow(cur, this, font);
1323 case LFUN_DEFAULT: {
1324 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1325 toggleAndShow(cur, this, font);
1329 case LFUN_UNDERLINE: {
1330 LyXFont font(LyXFont::ALL_IGNORE);
1331 font.setUnderbar(LyXFont::TOGGLE);
1332 toggleAndShow(cur, this, font);
1336 case LFUN_FONT_SIZE: {
1337 LyXFont font(LyXFont::ALL_IGNORE);
1338 font.setLyXSize(cmd.argument);
1339 toggleAndShow(cur, this, font);
1343 case LFUN_LANGUAGE: {
1344 Language const * lang = languages.getLanguage(cmd.argument);
1347 LyXFont font(LyXFont::ALL_IGNORE);
1348 font.setLanguage(lang);
1349 toggleAndShow(cur, this, font);
1354 case LFUN_FREEFONT_APPLY:
1355 toggleAndShow(cur, this, freefont, toggleall);
1356 cur.message(_("Character set"));
1359 // Set the freefont using the contents of \param data dispatched from
1360 // the frontends and apply it at the current cursor location.
1361 case LFUN_FREEFONT_UPDATE: {
1364 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1367 toggleAndShow(cur, this, freefont, toggleall);
1368 cur.message(_("Character set"));
1373 case LFUN_FINISHED_LEFT:
1374 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1377 case LFUN_FINISHED_RIGHT:
1378 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1382 case LFUN_FINISHED_UP:
1383 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1387 case LFUN_FINISHED_DOWN:
1388 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1392 case LFUN_LAYOUT_PARAGRAPH: {
1394 params2string(cur.paragraph(), data);
1395 data = "show\n" + data;
1396 bv->owner()->getDialogs().show("paragraph", data);
1400 case LFUN_PARAGRAPH_UPDATE: {
1401 if (!bv->owner()->getDialogs().visible("paragraph"))
1404 params2string(cur.paragraph(), data);
1406 // Will the paragraph accept changes from the dialog?
1407 InsetBase & inset = cur.inset();
1408 bool const accept = !inset.forceDefaultParagraphs(&inset);
1410 data = "update " + convert<string>(accept) + '\n' + data;
1411 bv->owner()->getDialogs().update("paragraph", data);
1416 case LFUN_CIRCUMFLEX:
1426 case LFUN_SPECIAL_CARON:
1429 case LFUN_HUNG_UMLAUT:
1432 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1433 if (!cmd.argument.empty())
1434 bv->owner()->getIntl().getTransManager()
1435 .TranslateAndInsert(cmd.argument[0], this);
1438 case LFUN_FLOAT_LIST: {
1439 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1440 if (tclass.floats().typeExist(cmd.argument)) {
1441 // not quite sure if we want this...
1443 cur.clearSelection();
1444 breakParagraph(cur);
1446 if (cur.lastpos() != 0) {
1448 breakParagraph(cur);
1451 setLayout(cur, tclass.defaultLayoutName());
1452 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1453 insertInset(cur, new InsetFloatList(cmd.argument));
1456 lyxerr << "Non-existent float type: "
1457 << cmd.argument << endl;
1462 case LFUN_ACCEPT_CHANGE: {
1467 case LFUN_REJECT_CHANGE: {
1472 case LFUN_THESAURUS_ENTRY: {
1473 string arg = cmd.argument;
1475 arg = cur.selectionAsString(false);
1477 if (arg.size() > 100 || arg.empty()) {
1478 // Get word or selection
1479 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1480 arg = cur.selectionAsString(false);
1483 bv->owner()->getDialogs().show("thesaurus", arg);
1487 case LFUN_PARAGRAPH_APPLY: {
1488 // Given data, an encoding of the ParagraphParameters
1489 // generated in the Paragraph dialog, this function sets
1490 // the current paragraph appropriately.
1491 istringstream is(cmd.argument);
1494 ParagraphParameters params;
1499 params.labelWidthString(),
1501 cur.message(_("Paragraph layout set"));
1505 case LFUN_INSET_DIALOG_SHOW: {
1506 InsetBase * inset = cur.nextInset();
1508 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1509 inset->dispatch(cur, fr);
1515 if (cur.selection()) {
1516 cur.selection() = false;
1519 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1524 lyxerr[Debug::ACTION]
1525 << BOOST_CURRENT_FUNCTION
1526 << ": Command " << cmd
1527 << " not DISPATCHED by LyXText" << endl;
1532 if (singleParUpdate)
1533 // Inserting characters does not change par height
1534 if (cur.paragraph().dim().asc == olddim.asc
1535 && cur.paragraph().dim().des == olddim.des) {
1536 // if so, update _only_ this paragraph
1537 cur.bv().update(Update::SinglePar | Update::Force);
1541 && &oldTopSlice.inset() == &cur.inset()
1542 && oldTopSlice.idx() == cur.idx()
1544 && !cur.selection())
1551 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1552 FuncStatus & flag) const
1554 BOOST_ASSERT(cur.text() == this);
1555 LyXFont const & font = real_current_font;
1558 switch (cmd.action) {
1560 case LFUN_DEPTH_MIN:
1561 enable = changeDepthAllowed(cur, DEC_DEPTH);
1564 case LFUN_DEPTH_PLUS:
1565 enable = changeDepthAllowed(cur, INC_DEPTH);
1568 case LFUN_INSET_OPTARG:
1569 enable = numberOfOptArgs(cur.paragraph())
1570 < cur.paragraph().layout()->optionalargs;
1574 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1577 case LFUN_INSERT_BIBITEM:
1578 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1582 // the functions which insert insets
1583 InsetBase::Code code = InsetBase::NO_CODE;
1584 switch (cmd.action) {
1585 case LFUN_DIALOG_SHOW_NEW_INSET:
1586 if (cmd.argument == "bibitem")
1587 code = InsetBase::BIBITEM_CODE;
1588 else if (cmd.argument == "bibtex")
1589 code = InsetBase::BIBTEX_CODE;
1590 else if (cmd.argument == "box")
1591 code = InsetBase::BOX_CODE;
1592 else if (cmd.argument == "branch")
1593 code = InsetBase::BRANCH_CODE;
1594 else if (cmd.argument == "citation")
1595 code = InsetBase::CITE_CODE;
1596 else if (cmd.argument == "ert")
1597 code = InsetBase::ERT_CODE;
1598 else if (cmd.argument == "external")
1599 code = InsetBase::EXTERNAL_CODE;
1600 else if (cmd.argument == "float")
1601 code = InsetBase::FLOAT_CODE;
1602 else if (cmd.argument == "graphics")
1603 code = InsetBase::GRAPHICS_CODE;
1604 else if (cmd.argument == "include")
1605 code = InsetBase::INCLUDE_CODE;
1606 else if (cmd.argument == "index")
1607 code = InsetBase::INDEX_CODE;
1608 else if (cmd.argument == "label")
1609 code = InsetBase::LABEL_CODE;
1610 else if (cmd.argument == "note")
1611 code = InsetBase::NOTE_CODE;
1612 else if (cmd.argument == "ref")
1613 code = InsetBase::REF_CODE;
1614 else if (cmd.argument == "toc")
1615 code = InsetBase::TOC_CODE;
1616 else if (cmd.argument == "url")
1617 code = InsetBase::URL_CODE;
1618 else if (cmd.argument == "vspace")
1619 code = InsetBase::VSPACE_CODE;
1620 else if (cmd.argument == "wrap")
1621 code = InsetBase::WRAP_CODE;
1624 case LFUN_INSET_ERT:
1625 code = InsetBase::ERT_CODE;
1627 case LFUN_INSET_FOOTNOTE:
1628 code = InsetBase::FOOT_CODE;
1630 case LFUN_TABULAR_INSERT:
1631 code = InsetBase::TABULAR_CODE;
1633 case LFUN_INSET_MARGINAL:
1634 code = InsetBase::MARGIN_CODE;
1636 case LFUN_INSET_FLOAT:
1637 case LFUN_INSET_WIDE_FLOAT:
1638 code = InsetBase::FLOAT_CODE;
1640 case LFUN_INSET_WRAP:
1641 code = InsetBase::WRAP_CODE;
1643 case LFUN_FLOAT_LIST:
1644 code = InsetBase::FLOAT_LIST_CODE;
1647 case LFUN_INSET_LIST:
1648 code = InsetBase::LIST_CODE;
1650 case LFUN_INSET_THEOREM:
1651 code = InsetBase::THEOREM_CODE;
1654 case LFUN_INSET_CAPTION:
1655 code = InsetBase::CAPTION_CODE;
1657 case LFUN_INSERT_NOTE:
1658 code = InsetBase::NOTE_CODE;
1660 case LFUN_INSERT_CHARSTYLE:
1661 code = InsetBase::CHARSTYLE_CODE;
1662 if (buf->params().getLyXTextClass().charstyles().empty())
1665 case LFUN_INSERT_BOX:
1666 code = InsetBase::BOX_CODE;
1668 case LFUN_INSERT_BRANCH:
1669 code = InsetBase::BRANCH_CODE;
1670 if (buf->params().branchlist().empty())
1673 case LFUN_INSERT_LABEL:
1674 code = InsetBase::LABEL_CODE;
1676 case LFUN_INSET_OPTARG:
1677 code = InsetBase::OPTARG_CODE;
1679 case LFUN_ENVIRONMENT_INSERT:
1680 code = InsetBase::BOX_CODE;
1682 case LFUN_INDEX_INSERT:
1683 code = InsetBase::INDEX_CODE;
1685 case LFUN_INDEX_PRINT:
1686 code = InsetBase::INDEX_PRINT_CODE;
1688 case LFUN_TOC_INSERT:
1689 code = InsetBase::TOC_CODE;
1693 code = InsetBase::URL_CODE;
1696 // always allow this, since we will inset a raw quote
1697 // if an inset is not allowed.
1699 case LFUN_HYPHENATION:
1700 case LFUN_LIGATURE_BREAK:
1702 case LFUN_MENU_SEPARATOR:
1704 case LFUN_END_OF_SENTENCE:
1705 code = InsetBase::SPECIALCHAR_CODE;
1707 case LFUN_SPACE_INSERT:
1708 // slight hack: we know this is allowed in math mode
1710 code = InsetBase::SPACE_CODE;
1712 case LFUN_INSET_DIALOG_SHOW: {
1713 InsetBase * inset = cur.nextInset();
1716 code = inset->lyxCode();
1717 if (!(code == InsetBase::INCLUDE_CODE
1718 || code == InsetBase::BIBTEX_CODE
1719 || code == InsetBase::FLOAT_LIST_CODE
1720 || code == InsetBase::TOC_CODE))
1729 if (code != InsetBase::NO_CODE
1730 && (cur.empty() || !cur.inset().insetAllowed(code)))
1735 case LFUN_DIALOG_SHOW_NEW_INSET:
1736 case LFUN_INSET_ERT:
1737 case LFUN_INSERT_BOX:
1738 case LFUN_INSERT_BRANCH:
1739 case LFUN_ENVIRONMENT_INSERT:
1740 case LFUN_INDEX_INSERT:
1741 case LFUN_INDEX_PRINT:
1742 case LFUN_TOC_INSERT:
1746 case LFUN_HYPHENATION:
1747 case LFUN_LIGATURE_BREAK:
1749 case LFUN_MENU_SEPARATOR:
1751 case LFUN_END_OF_SENTENCE:
1752 case LFUN_SPACE_INSERT:
1753 case LFUN_INSET_DIALOG_SHOW:
1756 case LFUN_INSET_MODIFY:
1757 // We need to disable this, because we may get called for a
1759 // InsetTabular::getStatus() -> InsetText::getStatus()
1760 // and we don't handle LFUN_INSET_MODIFY.
1765 flag.setOnOff(font.emph() == LyXFont::ON);
1769 flag.setOnOff(font.noun() == LyXFont::ON);
1773 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1777 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1781 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1785 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1788 case LFUN_DELETE_WORD_FORWARD:
1789 case LFUN_DELETE_WORD_BACKWARD:
1790 case LFUN_DELETE_LINE_FORWARD:
1791 case LFUN_WORDRIGHT:
1801 case LFUN_UP_PARAGRAPHSEL:
1802 case LFUN_DOWN_PARAGRAPHSEL:
1807 case LFUN_WORDRIGHTSEL:
1808 case LFUN_WORDLEFTSEL:
1810 case LFUN_UP_PARAGRAPH:
1811 case LFUN_DOWN_PARAGRAPH:
1816 case LFUN_BREAKLINE:
1818 case LFUN_DELETE_SKIP:
1819 case LFUN_BACKSPACE:
1820 case LFUN_BACKSPACE_SKIP:
1821 case LFUN_BREAKPARAGRAPH:
1822 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1823 case LFUN_BREAKPARAGRAPH_SKIP:
1824 case LFUN_PARAGRAPH_SPACING:
1825 case LFUN_INSET_INSERT:
1826 case LFUN_NEXT_INSET_TOGGLE:
1827 case LFUN_UPCASE_WORD:
1828 case LFUN_LOWCASE_WORD:
1829 case LFUN_CAPITALIZE_WORD:
1830 case LFUN_TRANSPOSE_CHARS:
1837 case LFUN_GETLAYOUT:
1839 case LFUN_PASTESELECTION:
1840 case LFUN_DATE_INSERT:
1841 case LFUN_SELFINSERT:
1842 case LFUN_INSERT_LABEL:
1843 case LFUN_INSERT_NOTE:
1844 case LFUN_INSERT_CHARSTYLE:
1845 case LFUN_INSET_FLOAT:
1846 case LFUN_INSET_FOOTNOTE:
1847 case LFUN_INSET_MARGINAL:
1848 case LFUN_INSET_WIDE_FLOAT:
1849 case LFUN_INSET_WRAP:
1850 case LFUN_TABULAR_INSERT:
1851 case LFUN_INSERT_LINE:
1852 case LFUN_INSERT_PAGEBREAK:
1853 case LFUN_MATH_DISPLAY:
1854 case LFUN_MATH_IMPORT_SELECTION:
1855 case LFUN_MATH_MODE:
1856 case LFUN_MATH_MACRO:
1857 case LFUN_INSERT_MATH:
1858 case LFUN_INSERT_MATRIX:
1859 case LFUN_MATH_DELIM:
1860 case LFUN_SUBSCRIPT:
1861 case LFUN_SUPERSCRIPT:
1863 case LFUN_UNDERLINE:
1864 case LFUN_FONT_SIZE:
1866 case LFUN_FREEFONT_APPLY:
1867 case LFUN_FREEFONT_UPDATE:
1868 case LFUN_LAYOUT_PARAGRAPH:
1869 case LFUN_PARAGRAPH_UPDATE:
1871 case LFUN_CIRCUMFLEX:
1881 case LFUN_SPECIAL_CARON:
1884 case LFUN_HUNG_UMLAUT:
1887 case LFUN_FLOAT_LIST:
1888 case LFUN_ACCEPT_CHANGE:
1889 case LFUN_REJECT_CHANGE:
1890 case LFUN_THESAURUS_ENTRY:
1891 case LFUN_PARAGRAPH_APPLY:
1893 case LFUN_KEYMAP_TOGGLE:
1895 case LFUN_BEGINNINGBUF:
1896 case LFUN_BEGINNINGBUFSEL:
1897 case LFUN_ENDBUFSEL:
1898 // these are handled in our dispatch()
1905 flag.enabled(enable);