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 "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "bufferparams.h"
26 #include "BufferView.h"
28 #include "coordcache.h"
29 #include "CutAndPaste.h"
31 #include "dispatchresult.h"
33 #include "funcrequest.h"
37 #include "LyXAction.h"
42 #include "paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
48 #include "frontends/Dialogs.h"
49 #include "frontends/LyXView.h"
51 #include "insets/insetcommand.h"
52 #include "insets/insetfloatlist.h"
53 #include "insets/insetnewline.h"
54 #include "insets/insetquotes.h"
55 #include "insets/insetspecialchar.h"
56 #include "insets/insettext.h"
58 #include "support/lstrings.h"
59 #include "support/lyxlib.h"
60 #include "support/convert.h"
61 #include "support/lyxtime.h"
63 #include "mathed/math_hullinset.h"
64 #include "mathed/math_macrotemplate.h"
66 #include <boost/current_function.hpp>
73 using lyx::cap::copySelection;
74 using lyx::cap::cutSelection;
75 using lyx::cap::pasteSelection;
76 using lyx::cap::replaceSelection;
78 using lyx::support::isStrUnsignedInt;
79 using lyx::support::token;
83 using std::istringstream;
86 extern string current_layout;
92 LyXFont freefont(LyXFont::ALL_IGNORE);
93 bool toggleall = false;
96 void toggleAndShow(LCursor & cur, LyXText * text,
97 LyXFont const & font, bool toggleall = true)
99 text->toggleFree(cur, font, toggleall);
101 if (font.language() != ignore_language ||
102 font.number() != LyXFont::IGNORE) {
103 Paragraph & par = cur.paragraph();
104 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
105 if (cur.boundary() !=
106 text->bidi.isBoundary(cur.buffer(), par,
108 text->real_current_font))
109 text->setCursor(cur, cur.pit(), cur.pos(),
110 false, !cur.boundary());
115 void moveCursor(LCursor & cur, bool selecting)
117 if (selecting || cur.mark())
119 if (!cur.selection())
120 cur.bv().haveSelection(false);
121 cur.bv().switchKeyMap();
125 void finishChange(LCursor & cur, bool selecting)
128 moveCursor(cur, selecting);
132 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
135 string sel = cur.selectionAsString(false);
136 //lyxerr << "selection is: '" << sel << "'" << endl;
139 const int old_pos = cur.pos();
140 cur.insert(new MathHullInset("simple"));
141 BOOST_ASSERT(old_pos == cur.pos());
142 cur.nextInset()->edit(cur, true);
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 // Avoid an unnecessary undo step if cmd.argument
151 if (!cmd.argument.empty())
152 cur.dispatch(FuncRequest(LFUN_INSERT_MATH,
155 // create a macro if we see "\\newcommand"
156 // somewhere, and an ordinary formula
158 cutSelection(cur, true, true);
159 if (sel.find("\\newcommand") == string::npos
160 && sel.find("\\def") == string::npos)
162 cur.insert(new MathHullInset("simple"));
163 cur.dispatch(FuncRequest(LFUN_RIGHT));
164 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
166 istringstream is(sel);
167 cur.insert(new MathMacroTemplate(is));
170 cur.message(N_("Math editor mode"));
179 string const freefont2string()
182 if (font2string(freefont, toggleall, data))
189 bool LyXText::cursorPrevious(LCursor & cur)
191 pos_type cpos = cur.pos();
192 lyx::pit_type cpar = cur.pit();
194 int x = cur.x_target();
196 bool updated = setCursorFromCoordinates(cur, x, 0);
199 updated |= cursorUp(cur);
201 if (cpar == cur.pit() && cpos == cur.pos()) {
202 // we have a row which is taller than the workarea. The
203 // simplest solution is to move to the previous row instead.
204 updated |= cursorUp(cur);
207 cur.bv().updateScrollbar();
213 bool LyXText::cursorNext(LCursor & cur)
215 pos_type cpos = cur.pos();
216 lyx::pit_type cpar = cur.pit();
218 int x = cur.x_target();
219 bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
222 updated |= cursorDown(cur);
224 if (cpar == cur.pit() && cpos == cur.pos()) {
225 // we have a row which is taller than the workarea. The
226 // simplest solution is to move to the next row instead.
227 updated |= cursorDown(cur);
230 cur.bv().updateScrollbar();
238 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
240 lyx::cap::replaceSelection(cur);
241 cur.insert(new InsetSpecialChar(kind));
246 bool doInsertInset(LCursor & cur, LyXText * text,
247 FuncRequest const & cmd, bool edit, bool pastesel)
249 InsetBase * inset = createInset(&cur.bv(), cmd);
255 if (cur.selection()) {
256 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
259 text->insertInset(cur, inset);
262 inset->edit(cur, true);
264 if (gotsel && pastesel)
265 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
270 void update(LCursor & cur)
272 //we don't call update(true, false) directly to save a metrics call
273 if (cur.bv().fitCursor())
274 cur.bv().update(Update::Force);
281 void LyXText::number(LCursor & cur)
283 LyXFont font(LyXFont::ALL_IGNORE);
284 font.setNumber(LyXFont::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool LyXText::isRTL(Paragraph const & par) const
291 return par.isRightToLeftPar(bv()->buffer()->params());
295 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
297 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
299 BOOST_ASSERT(cur.text() == this);
300 BufferView * bv = &cur.bv();
301 CursorSlice oldTopSlice = cur.top();
302 bool oldBoundary = cur.boundary();
303 bool sel = cur.selection();
304 // Signals that, even if needsUpdate == false, an update of the
305 // cursor paragraph is required
306 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
307 LyXAction::SingleParUpdate);
308 // Signals that a full-screen update is required
309 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
310 LyXAction::NoUpdate) || singleParUpdate);
311 // Remember the old paragraph metric
312 Dimension olddim = cur.paragraph().dim();
314 switch (cmd.action) {
316 case LFUN_APPENDIX: {
317 Paragraph & par = cur.paragraph();
318 bool start = !par.params().startOfAppendix();
321 #warning The code below only makes sense at top level.
322 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
324 // ensure that we have only one start_of_appendix in this document
325 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
326 if (pars_[tmp].params().startOfAppendix()) {
328 pars_[tmp].params().startOfAppendix(false);
334 par.params().startOfAppendix(start);
336 // we can set the refreshing parameters now
337 updateCounters(cur.buffer());
341 case LFUN_DELETE_WORD_FORWARD:
342 cur.clearSelection();
343 deleteWordForward(cur);
344 finishChange(cur, false);
347 case LFUN_DELETE_WORD_BACKWARD:
348 cur.clearSelection();
349 deleteWordBackward(cur);
350 finishChange(cur, false);
353 case LFUN_DELETE_LINE_FORWARD:
354 cur.clearSelection();
355 deleteLineForward(cur);
356 finishChange(cur, false);
361 cur.clearSelection();
362 if (isRTL(cur.paragraph()))
363 needsUpdate = cursorLeftOneWord(cur);
365 needsUpdate = cursorRightOneWord(cur);
366 finishChange(cur, false);
371 cur.clearSelection();
372 if (isRTL(cur.paragraph()))
373 needsUpdate = cursorRightOneWord(cur);
375 needsUpdate = cursorLeftOneWord(cur);
376 finishChange(cur, false);
379 case LFUN_BEGINNINGBUF:
380 if (cur.depth() == 1) {
382 cur.clearSelection();
384 finishChange(cur, false);
390 case LFUN_BEGINNINGBUFSEL:
391 if (cur.depth() == 1) {
392 if (!cur.selection())
395 finishChange(cur, true);
402 if (cur.depth() == 1) {
404 cur.clearSelection();
406 finishChange(cur, false);
413 if (cur.depth() == 1) {
414 if (!cur.selection())
417 finishChange(cur, true);
425 //lyxerr << BOOST_CURRENT_FUNCTION
426 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
427 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
428 if (isRTL(cur.paragraph()))
429 needsUpdate = cursorLeft(cur);
431 needsUpdate = cursorRight(cur);
433 if (!needsUpdate && oldTopSlice == cur.top()
434 && cur.boundary() == oldBoundary) {
436 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
442 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
443 cur.selHandle(cmd.action == LFUN_LEFTSEL);
444 if (isRTL(cur.paragraph()))
445 needsUpdate = cursorRight(cur);
447 needsUpdate = cursorLeft(cur);
449 if (!needsUpdate && oldTopSlice == cur.top()
450 && cur.boundary() == oldBoundary) {
452 cmd = FuncRequest(LFUN_FINISHED_LEFT);
459 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
460 cur.selHandle(cmd.action == LFUN_UPSEL);
462 needsUpdate = cursorUp(cur);
463 if (!needsUpdate && oldTopSlice == cur.top()
464 && cur.boundary() == oldBoundary) {
466 cmd = FuncRequest(LFUN_FINISHED_UP);
473 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
474 cur.selHandle(cmd.action == LFUN_DOWNSEL);
475 needsUpdate = cursorDown(cur);
476 if (!needsUpdate && oldTopSlice == cur.top() &&
477 cur.boundary() == oldBoundary)
480 cmd = FuncRequest(LFUN_FINISHED_DOWN);
484 case LFUN_UP_PARAGRAPH:
486 cur.clearSelection();
487 needsUpdate = cursorUpParagraph(cur);
488 finishChange(cur, false);
491 case LFUN_UP_PARAGRAPHSEL:
492 if (!cur.selection())
494 cursorUpParagraph(cur);
495 finishChange(cur, true);
498 case LFUN_DOWN_PARAGRAPH:
500 cur.clearSelection();
501 needsUpdate = cursorDownParagraph(cur);
502 finishChange(cur, false);
505 case LFUN_DOWN_PARAGRAPHSEL:
506 if (!cur.selection())
508 cursorDownParagraph(cur);
509 finishChange(cur, true);
514 if (!cur.selection())
517 finishChange(cur, true);
522 if (!cur.selection())
525 finishChange(cur, true);
530 if (!cur.selection())
533 finishChange(cur, true);
538 if (!cur.selection())
541 finishChange(cur, true);
544 case LFUN_WORDRIGHTSEL:
545 if (!cur.selection())
547 if (isRTL(cur.paragraph()))
548 cursorLeftOneWord(cur);
550 cursorRightOneWord(cur);
551 finishChange(cur, true);
554 case LFUN_WORDLEFTSEL:
555 if (!cur.selection())
557 if (isRTL(cur.paragraph()))
558 cursorRightOneWord(cur);
560 cursorLeftOneWord(cur);
561 finishChange(cur, true);
565 selectWord(cur, lyx::WHOLE_WORD);
566 finishChange(cur, true);
573 cur.clearSelection();
574 finishChange(cur, false);
575 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
577 cmd = FuncRequest(LFUN_FINISHED_UP);
579 needsUpdate = cursorPrevious(cur);
586 cur.clearSelection();
587 finishChange(cur, false);
588 if (cur.pit() == cur.lastpit()
589 && cur.textRow().endpos() == cur.lastpos()) {
591 cmd = FuncRequest(LFUN_FINISHED_DOWN);
593 needsUpdate = cursorNext(cur);
599 cur.clearSelection();
601 finishChange(cur, false);
606 cur.clearSelection();
608 finishChange(cur, false);
611 case LFUN_BREAKLINE: {
612 // Not allowed by LaTeX (labels or empty par)
613 if (cur.pos() > cur.paragraph().beginOfBody()) {
614 lyx::cap::replaceSelection(cur);
615 cur.insert(new InsetNewline);
617 moveCursor(cur, false);
623 if (!cur.selection()) {
626 // It is possible to make it a lot faster still
627 // just comment out the line below...
629 cutSelection(cur, true, false);
631 moveCursor(cur, false);
634 case LFUN_DELETE_SKIP:
635 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
636 if (!cur.selection()) {
637 if (cur.pos() == cur.lastpos()) {
644 cutSelection(cur, true, false);
650 if (!cur.selection()) {
651 if (bv->owner()->getIntl().getTransManager().backspace()) {
654 // It is possible to make it a lot faster still
655 // just comment out the line below...
658 cutSelection(cur, true, false);
663 case LFUN_BACKSPACE_SKIP:
664 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
665 if (!cur.selection()) {
669 //CursorSlice cur = cursor();
673 cutSelection(cur, true, false);
677 case LFUN_BREAKPARAGRAPH:
678 lyx::cap::replaceSelection(cur);
679 breakParagraph(cur, 0);
684 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
685 lyx::cap::replaceSelection(cur);
686 breakParagraph(cur, 1);
691 case LFUN_BREAKPARAGRAPH_SKIP: {
692 // When at the beginning of a paragraph, remove
693 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
694 lyx::cap::replaceSelection(cur);
696 cur.paragraph().params().labelWidthString(string());
698 breakParagraph(cur, 0);
704 case LFUN_PARAGRAPH_SPACING: {
705 Paragraph & par = cur.paragraph();
706 Spacing::Space cur_spacing = par.params().spacing().getSpace();
707 string cur_value = "1.0";
708 if (cur_spacing == Spacing::Other)
709 cur_value = par.params().spacing().getValueAsString();
711 istringstream is(cmd.argument);
714 Spacing::Space new_spacing = cur_spacing;
715 string new_value = cur_value;
717 lyxerr << "Missing argument to `paragraph-spacing'"
719 } else if (tmp == "single") {
720 new_spacing = Spacing::Single;
721 } else if (tmp == "onehalf") {
722 new_spacing = Spacing::Onehalf;
723 } else if (tmp == "double") {
724 new_spacing = Spacing::Double;
725 } else if (tmp == "other") {
726 new_spacing = Spacing::Other;
727 string tmpval = "0.0";
729 lyxerr << "new_value = " << tmpval << endl;
732 } else if (tmp == "default") {
733 new_spacing = Spacing::Default;
735 lyxerr << _("Unknown spacing argument: ")
736 << cmd.argument << endl;
738 if (cur_spacing != new_spacing || cur_value != new_value)
739 par.params().spacing(Spacing(new_spacing, new_value));
743 case LFUN_INSET_INSERT: {
745 InsetBase * inset = createInset(bv, cmd);
747 insertInset(cur, inset);
753 case LFUN_INSET_SETTINGS:
754 cur.inset().showInsetDialog(bv);
757 case LFUN_NEXT_INSET_TOGGLE: {
758 InsetBase * inset = cur.nextInset();
759 // this is the real function we want to invoke
760 cmd = FuncRequest(LFUN_INSET_TOGGLE);
762 // if there is an inset at cursor, see whether it
765 LCursor tmpcur = cur;
766 tmpcur.pushLeft(*inset);
767 inset->dispatch(tmpcur, cmd);
768 if (tmpcur.result().dispatched()) {
769 cur.clearSelection();
773 // if it did not work, try the underlying inset.
774 if (!cur.result().dispatched())
775 cur.inset().dispatch(cur, cmd);
779 case LFUN_SPACE_INSERT:
780 if (cur.paragraph().layout()->free_spacing)
781 insertChar(cur, ' ');
783 doInsertInset(cur, this, cmd, false, false);
786 moveCursor(cur, false);
789 case LFUN_HYPHENATION:
790 specialChar(cur, InsetSpecialChar::HYPHENATION);
793 case LFUN_LIGATURE_BREAK:
794 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
798 specialChar(cur, InsetSpecialChar::LDOTS);
801 case LFUN_END_OF_SENTENCE:
802 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
805 case LFUN_MENU_SEPARATOR:
806 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
809 case LFUN_UPCASE_WORD:
810 changeCase(cur, LyXText::text_uppercase);
813 case LFUN_LOWCASE_WORD:
814 changeCase(cur, LyXText::text_lowercase);
817 case LFUN_CAPITALIZE_WORD:
818 changeCase(cur, LyXText::text_capitalization);
821 case LFUN_TRANSPOSE_CHARS:
826 cur.message(_("Paste"));
827 lyx::cap::replaceSelection(cur);
829 #warning FIXME Check if the arg is in the domain of available selections.
831 if (isStrUnsignedInt(cmd.argument))
832 pasteSelection(cur, convert<unsigned int>(cmd.argument));
834 pasteSelection(cur, 0);
835 cur.clearSelection(); // bug 393
841 cutSelection(cur, true, true);
842 cur.message(_("Cut"));
847 cur.message(_("Copy"));
851 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
852 + convert<string>(cursorY(cur.top(), cur.boundary())));
858 istringstream is(cmd.argument);
861 lyxerr << "SETXY: Could not parse coordinates in '"
862 << cmd.argument << std::endl;
864 setCursorFromCoordinates(cur, x, y);
869 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
871 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
878 cur.message(cur.paragraph().layout()->name());
882 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
883 << cmd.argument << endl;
885 // This is not the good solution to the empty argument
886 // problem, but it will hopefully suffice for 1.2.0.
887 // The correct solution would be to augument the
888 // function list/array with information about what
889 // functions needs arguments and their type.
890 if (cmd.argument.empty()) {
891 cur.errorMessage(_("LyX function 'layout' needs an argument."));
895 // Derive layout number from given argument (string)
896 // and current buffer's textclass (number)
897 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
898 bool hasLayout = tclass.hasLayout(cmd.argument);
899 string layout = cmd.argument;
901 // If the entry is obsolete, use the new one instead.
903 string const & obs = tclass[layout]->obsoleted_by();
909 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
914 bool change_layout = (current_layout != layout);
916 if (!change_layout && cur.selection() &&
917 cur.selBegin().pit() != cur.selEnd().pit())
919 pit_type spit = cur.selBegin().pit();
920 pit_type epit = cur.selEnd().pit() + 1;
921 while (spit != epit) {
922 if (pars_[spit].layout()->name() != current_layout) {
923 change_layout = true;
931 current_layout = layout;
932 setLayout(cur, layout);
933 bv->owner()->setLayout(layout);
939 case LFUN_PASTESELECTION: {
940 cur.clearSelection();
941 string const clip = bv->getClipboard();
944 if (cmd.argument == "paragraph")
945 insertStringAsParagraphs(cur, clip);
947 insertStringAsLines(cur, clip);
953 lyx::cap::replaceSelection(cur);
954 Paragraph & par = cur.paragraph();
955 lyx::pos_type pos = cur.pos();
959 else if (cur.prevInset() && cur.prevInset()->isSpace())
962 c = par.getChar(pos - 1);
964 LyXLayout_ptr const & style = par.layout();
966 BufferParams const & bufparams = bv->buffer()->params();
967 if (!style->pass_thru
968 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
969 string arg = cmd.argument;
971 cur.insert(new InsetQuotes(c,
972 bufparams.quotes_language,
973 InsetQuotes::SingleQ));
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::DoubleQ));
981 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
985 case LFUN_DATE_INSERT:
986 if (cmd.argument.empty())
987 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
988 lyx::formatted_time(lyx::current_time())));
990 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
991 lyx::formatted_time(lyx::current_time(), cmd.argument)));
994 case LFUN_MOUSE_TRIPLE:
995 if (cmd.button() == mouse_button::button1) {
1001 bv->haveSelection(cur.selection());
1005 case LFUN_MOUSE_DOUBLE:
1006 if (cmd.button() == mouse_button::button1) {
1007 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1009 bv->haveSelection(cur.selection());
1013 // Single-click on work area
1014 case LFUN_MOUSE_PRESS: {
1015 // Right click on a footnote flag opens float menu
1016 if (cmd.button() == mouse_button::button3) {
1017 cur.clearSelection();
1021 // Middle button press pastes if we have a selection
1022 // We do this here as if the selection was inside an inset
1023 // it could get cleared on the unlocking of the inset so
1024 // we have to check this first
1025 bool paste_internally = false;
1026 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1027 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1028 paste_internally = true;
1031 // Clear the selection
1032 cur.clearSelection();
1034 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1039 // Has the cursor just left the inset?
1040 if (bv->cursor().inMathed() && !cur.inMathed())
1041 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1046 // Insert primary selection with middle mouse
1047 // if there is a local selection in the current buffer,
1049 if (cmd.button() == mouse_button::button2) {
1050 if (paste_internally)
1051 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1053 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1059 case LFUN_MOUSE_MOTION: {
1060 // Only use motion with button 1
1061 //if (cmd.button() != mouse_button::button1)
1064 // ignore motions deeper nested than the real anchor
1065 LCursor & bvcur = cur.bv().cursor();
1066 if (bvcur.anchor_.hasPart(cur)) {
1067 CursorSlice old = bvcur.top();
1069 int const wh = bv->workHeight();
1070 int const y = std::max(0, std::min(wh - 1, cmd.y));
1072 setCursorFromCoordinates(cur, cmd.x, y);
1073 cur.x_target() = cmd.x;
1078 // This is to allow jumping over large insets
1079 if (cur.top() == old) {
1086 if (cur.top() == old)
1089 // don't set anchor_
1090 bvcur.setCursor(cur);
1091 bvcur.selection() = true;
1092 //lyxerr << "MOTION: " << bv->cursor() << endl;
1100 case LFUN_MOUSE_RELEASE: {
1101 if (cmd.button() == mouse_button::button2)
1105 if (cmd.button() == mouse_button::button1)
1106 bv->haveSelection(cur.selection());
1109 bv->owner()->updateMenubar();
1110 bv->owner()->updateToolbars();
1114 case LFUN_SELFINSERT: {
1115 if (cmd.argument.empty())
1118 // Automatically delete the currently selected
1119 // text and replace it with what is being
1120 // typed in now. Depends on lyxrc settings
1121 // "auto_region_delete", which defaults to
1124 if (lyxrc.auto_region_delete) {
1125 if (cur.selection())
1126 cutSelection(cur, false, false);
1127 bv->haveSelection(false);
1130 cur.clearSelection();
1131 LyXFont const old_font = real_current_font;
1133 // Prevents language turds in new lyxtexts under non-english
1134 BufferParams const & bufparams = cur.buffer().params();
1135 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1136 current_font.setLanguage(lang);
1137 real_current_font.setLanguage(lang);
1139 string::const_iterator cit = cmd.argument.begin();
1140 string::const_iterator end = cmd.argument.end();
1141 for (; cit != end; ++cit)
1142 bv->owner()->getIntl().getTransManager().
1143 TranslateAndInsert(*cit, this);
1146 moveCursor(cur, false);
1147 bv->updateScrollbar();
1152 InsetCommandParams p("url");
1153 string const data = InsetCommandMailer::params2string("url", p);
1154 bv->owner()->getDialogs().show("url", data, 0);
1158 case LFUN_HTMLURL: {
1159 InsetCommandParams p("htmlurl");
1160 string const data = InsetCommandMailer::params2string("url", p);
1161 bv->owner()->getDialogs().show("url", data, 0);
1165 case LFUN_INSERT_LABEL: {
1166 // Try to generate a valid label
1167 string const contents = cmd.argument.empty() ?
1168 cur.getPossibleLabel() : cmd.argument;
1170 InsetCommandParams p("label", contents);
1171 string const data = InsetCommandMailer::params2string("label", p);
1173 if (cmd.argument.empty()) {
1174 bv->owner()->getDialogs().show("label", data, 0);
1176 FuncRequest fr(LFUN_INSET_INSERT, data);
1184 case LFUN_INSET_LIST:
1185 case LFUN_INSET_THEOREM:
1186 case LFUN_INSET_CAPTION:
1188 case LFUN_INSERT_NOTE:
1189 case LFUN_INSERT_CHARSTYLE:
1190 case LFUN_INSERT_BOX:
1191 case LFUN_INSERT_BRANCH:
1192 case LFUN_INSERT_BIBITEM:
1193 case LFUN_INSET_ERT:
1194 case LFUN_INSET_FOOTNOTE:
1195 case LFUN_INSET_MARGINAL:
1196 case LFUN_INSET_OPTARG:
1197 case LFUN_ENVIRONMENT_INSERT:
1198 // Open the inset, and move the current selection
1200 doInsertInset(cur, this, cmd, true, true);
1204 case LFUN_TABULAR_INSERT:
1205 // if there were no arguments, just open the dialog
1206 if (doInsertInset(cur, this, cmd, false, true))
1209 bv->owner()->getDialogs().show("tabularcreate");
1213 case LFUN_INSET_FLOAT:
1214 case LFUN_INSET_WIDE_FLOAT:
1215 case LFUN_INSET_WRAP:
1216 doInsertInset(cur, this, cmd, true, true);
1218 // FIXME: the "Caption" name should not be hardcoded,
1219 // but given by the float definition.
1220 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1223 case LFUN_INDEX_INSERT:
1224 // Just open the inset
1225 doInsertInset(cur, this, cmd, true, false);
1229 case LFUN_INDEX_PRINT:
1230 case LFUN_TOC_INSERT:
1232 case LFUN_INSERT_LINE:
1233 case LFUN_INSERT_PAGEBREAK:
1235 doInsertInset(cur, this, cmd, false, false);
1239 case LFUN_DEPTH_MIN:
1240 changeDepth(cur, DEC_DEPTH);
1243 case LFUN_DEPTH_PLUS:
1244 changeDepth(cur, INC_DEPTH);
1247 case LFUN_MATH_DISPLAY:
1248 mathDispatch(cur, cmd, true);
1251 case LFUN_MATH_IMPORT_SELECTION:
1252 case LFUN_MATH_MODE:
1253 if (cmd.argument == "on")
1254 // don't pass "on" as argument
1255 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1257 mathDispatch(cur, cmd, false);
1260 case LFUN_MATH_MACRO:
1261 if (cmd.argument.empty())
1262 cur.errorMessage(N_("Missing argument"));
1264 string s = cmd.argument;
1265 string const s1 = token(s, ' ', 1);
1266 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1267 string const s2 = token(s, ' ', 2);
1268 string const type = s2.empty() ? "newcommand" : s2;
1269 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1270 //cur.nextInset()->edit(cur, true);
1274 // passthrough hat and underscore outside mathed:
1275 case LFUN_SUBSCRIPT:
1276 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1278 case LFUN_SUPERSCRIPT:
1279 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1282 case LFUN_INSERT_MATH:
1283 case LFUN_INSERT_MATRIX:
1284 case LFUN_MATH_DELIM: {
1285 cur.insert(new MathHullInset("simple"));
1286 cur.dispatch(FuncRequest(LFUN_RIGHT));
1292 LyXFont font(LyXFont::ALL_IGNORE);
1293 font.setEmph(LyXFont::TOGGLE);
1294 toggleAndShow(cur, this, font);
1299 LyXFont font(LyXFont::ALL_IGNORE);
1300 font.setSeries(LyXFont::BOLD_SERIES);
1301 toggleAndShow(cur, this, font);
1306 LyXFont font(LyXFont::ALL_IGNORE);
1307 font.setNoun(LyXFont::TOGGLE);
1308 toggleAndShow(cur, this, font);
1313 LyXFont font(LyXFont::ALL_IGNORE);
1314 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1315 toggleAndShow(cur, this, font);
1320 LyXFont font(LyXFont::ALL_IGNORE);
1321 font.setFamily(LyXFont::SANS_FAMILY);
1322 toggleAndShow(cur, this, font);
1327 LyXFont font(LyXFont::ALL_IGNORE);
1328 font.setFamily(LyXFont::ROMAN_FAMILY);
1329 toggleAndShow(cur, this, font);
1333 case LFUN_DEFAULT: {
1334 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1335 toggleAndShow(cur, this, font);
1339 case LFUN_UNDERLINE: {
1340 LyXFont font(LyXFont::ALL_IGNORE);
1341 font.setUnderbar(LyXFont::TOGGLE);
1342 toggleAndShow(cur, this, font);
1346 case LFUN_FONT_SIZE: {
1347 LyXFont font(LyXFont::ALL_IGNORE);
1348 font.setLyXSize(cmd.argument);
1349 toggleAndShow(cur, this, font);
1353 case LFUN_LANGUAGE: {
1354 Language const * lang = languages.getLanguage(cmd.argument);
1357 LyXFont font(LyXFont::ALL_IGNORE);
1358 font.setLanguage(lang);
1359 toggleAndShow(cur, this, font);
1364 case LFUN_FREEFONT_APPLY:
1365 toggleAndShow(cur, this, freefont, toggleall);
1366 cur.message(_("Character set"));
1369 // Set the freefont using the contents of \param data dispatched from
1370 // the frontends and apply it at the current cursor location.
1371 case LFUN_FREEFONT_UPDATE: {
1374 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1377 toggleAndShow(cur, this, freefont, toggleall);
1378 cur.message(_("Character set"));
1383 case LFUN_FINISHED_LEFT:
1384 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1387 case LFUN_FINISHED_RIGHT:
1388 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1392 case LFUN_FINISHED_UP:
1393 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1397 case LFUN_FINISHED_DOWN:
1398 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1402 case LFUN_LAYOUT_PARAGRAPH: {
1404 params2string(cur.paragraph(), data);
1405 data = "show\n" + data;
1406 bv->owner()->getDialogs().show("paragraph", data);
1410 case LFUN_PARAGRAPH_UPDATE: {
1411 if (!bv->owner()->getDialogs().visible("paragraph"))
1414 params2string(cur.paragraph(), data);
1416 // Will the paragraph accept changes from the dialog?
1417 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1419 data = "update " + convert<string>(accept) + '\n' + data;
1420 bv->owner()->getDialogs().update("paragraph", data);
1425 case LFUN_CIRCUMFLEX:
1435 case LFUN_SPECIAL_CARON:
1438 case LFUN_HUNG_UMLAUT:
1441 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1442 if (!cmd.argument.empty())
1443 bv->owner()->getIntl().getTransManager()
1444 .TranslateAndInsert(cmd.argument[0], this);
1447 case LFUN_FLOAT_LIST: {
1448 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1449 if (tclass.floats().typeExist(cmd.argument)) {
1450 // not quite sure if we want this...
1452 cur.clearSelection();
1453 breakParagraph(cur);
1455 if (cur.lastpos() != 0) {
1457 breakParagraph(cur);
1460 setLayout(cur, tclass.defaultLayoutName());
1461 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1462 insertInset(cur, new InsetFloatList(cmd.argument));
1465 lyxerr << "Non-existent float type: "
1466 << cmd.argument << endl;
1471 case LFUN_ACCEPT_CHANGE: {
1476 case LFUN_REJECT_CHANGE: {
1481 case LFUN_THESAURUS_ENTRY: {
1482 string arg = cmd.argument;
1484 arg = cur.selectionAsString(false);
1486 if (arg.size() > 100 || arg.empty()) {
1487 // Get word or selection
1488 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1489 arg = cur.selectionAsString(false);
1492 bv->owner()->getDialogs().show("thesaurus", arg);
1496 case LFUN_PARAGRAPH_APPLY: {
1497 // Given data, an encoding of the ParagraphParameters
1498 // generated in the Paragraph dialog, this function sets
1499 // the current paragraph appropriately.
1500 istringstream is(cmd.argument);
1503 ParagraphParameters params;
1508 params.labelWidthString(),
1510 cur.message(_("Paragraph layout set"));
1514 case LFUN_INSET_DIALOG_SHOW: {
1515 InsetBase * inset = cur.nextInset();
1517 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1518 inset->dispatch(cur, fr);
1524 if (cur.selection()) {
1525 cur.selection() = false;
1528 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1533 lyxerr[Debug::ACTION]
1534 << BOOST_CURRENT_FUNCTION
1535 << ": Command " << cmd
1536 << " not DISPATCHED by LyXText" << endl;
1541 if (singleParUpdate)
1542 // Inserting characters does not change par height
1543 if (cur.paragraph().dim().asc == olddim.asc
1544 && cur.paragraph().dim().des == olddim.des) {
1545 // if so, update _only_ this paragraph
1546 cur.bv().update(Update::SinglePar | Update::Force);
1550 && &oldTopSlice.inset() == &cur.inset()
1551 && oldTopSlice.idx() == cur.idx()
1553 && !cur.selection())
1560 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1561 FuncStatus & flag) const
1563 BOOST_ASSERT(cur.text() == this);
1565 LyXFont const & font = real_current_font;
1567 InsetBase::Code code = InsetBase::NO_CODE;
1569 switch (cmd.action) {
1571 case LFUN_DEPTH_MIN:
1572 enable = changeDepthAllowed(cur, DEC_DEPTH);
1575 case LFUN_DEPTH_PLUS:
1576 enable = changeDepthAllowed(cur, INC_DEPTH);
1580 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1583 case LFUN_INSERT_BIBITEM:
1584 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1587 case LFUN_DIALOG_SHOW_NEW_INSET:
1588 if (cmd.argument == "bibitem")
1589 code = InsetBase::BIBITEM_CODE;
1590 else if (cmd.argument == "bibtex")
1591 code = InsetBase::BIBTEX_CODE;
1592 else if (cmd.argument == "box")
1593 code = InsetBase::BOX_CODE;
1594 else if (cmd.argument == "branch")
1595 code = InsetBase::BRANCH_CODE;
1596 else if (cmd.argument == "citation")
1597 code = InsetBase::CITE_CODE;
1598 else if (cmd.argument == "ert")
1599 code = InsetBase::ERT_CODE;
1600 else if (cmd.argument == "external")
1601 code = InsetBase::EXTERNAL_CODE;
1602 else if (cmd.argument == "float")
1603 code = InsetBase::FLOAT_CODE;
1604 else if (cmd.argument == "graphics")
1605 code = InsetBase::GRAPHICS_CODE;
1606 else if (cmd.argument == "include")
1607 code = InsetBase::INCLUDE_CODE;
1608 else if (cmd.argument == "index")
1609 code = InsetBase::INDEX_CODE;
1610 else if (cmd.argument == "label")
1611 code = InsetBase::LABEL_CODE;
1612 else if (cmd.argument == "note")
1613 code = InsetBase::NOTE_CODE;
1614 else if (cmd.argument == "ref")
1615 code = InsetBase::REF_CODE;
1616 else if (cmd.argument == "toc")
1617 code = InsetBase::TOC_CODE;
1618 else if (cmd.argument == "url")
1619 code = InsetBase::URL_CODE;
1620 else if (cmd.argument == "vspace")
1621 code = InsetBase::VSPACE_CODE;
1622 else if (cmd.argument == "wrap")
1623 code = InsetBase::WRAP_CODE;
1626 case LFUN_INSET_ERT:
1627 code = InsetBase::ERT_CODE;
1629 case LFUN_INSET_FOOTNOTE:
1630 code = InsetBase::FOOT_CODE;
1632 case LFUN_TABULAR_INSERT:
1633 code = InsetBase::TABULAR_CODE;
1635 case LFUN_INSET_MARGINAL:
1636 code = InsetBase::MARGIN_CODE;
1638 case LFUN_INSET_FLOAT:
1639 case LFUN_INSET_WIDE_FLOAT:
1640 code = InsetBase::FLOAT_CODE;
1642 case LFUN_INSET_WRAP:
1643 code = InsetBase::WRAP_CODE;
1645 case LFUN_FLOAT_LIST:
1646 code = InsetBase::FLOAT_LIST_CODE;
1649 case LFUN_INSET_LIST:
1650 code = InsetBase::LIST_CODE;
1652 case LFUN_INSET_THEOREM:
1653 code = InsetBase::THEOREM_CODE;
1656 case LFUN_INSET_CAPTION:
1657 code = InsetBase::CAPTION_CODE;
1659 case LFUN_INSERT_NOTE:
1660 code = InsetBase::NOTE_CODE;
1662 case LFUN_INSERT_CHARSTYLE:
1663 code = InsetBase::CHARSTYLE_CODE;
1664 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1667 case LFUN_INSERT_BOX:
1668 code = InsetBase::BOX_CODE;
1670 case LFUN_INSERT_BRANCH:
1671 code = InsetBase::BRANCH_CODE;
1672 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1675 case LFUN_INSERT_LABEL:
1676 code = InsetBase::LABEL_CODE;
1678 case LFUN_INSET_OPTARG:
1679 code = InsetBase::OPTARG_CODE;
1680 enable = numberOfOptArgs(cur.paragraph())
1681 < cur.paragraph().layout()->optionalargs;
1683 case LFUN_ENVIRONMENT_INSERT:
1684 code = InsetBase::BOX_CODE;
1686 case LFUN_INDEX_INSERT:
1687 code = InsetBase::INDEX_CODE;
1689 case LFUN_INDEX_PRINT:
1690 code = InsetBase::INDEX_PRINT_CODE;
1692 case LFUN_TOC_INSERT:
1693 code = InsetBase::TOC_CODE;
1697 code = InsetBase::URL_CODE;
1700 // always allow this, since we will inset a raw quote
1701 // if an inset is not allowed.
1703 case LFUN_HYPHENATION:
1704 case LFUN_LIGATURE_BREAK:
1706 case LFUN_MENU_SEPARATOR:
1708 case LFUN_END_OF_SENTENCE:
1709 code = InsetBase::SPECIALCHAR_CODE;
1711 case LFUN_SPACE_INSERT:
1712 // slight hack: we know this is allowed in math mode
1714 code = InsetBase::SPACE_CODE;
1717 #ifdef WITH_WARNINGS
1718 #warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
1721 case LFUN_INSET_DIALOG_SHOW: {
1722 InsetBase * inset = cur.nextInset();
1725 code = inset->lyxCode();
1726 if (!(code == InsetBase::INCLUDE_CODE
1727 || code == InsetBase::BIBTEX_CODE
1728 || code == InsetBase::FLOAT_LIST_CODE
1729 || code == InsetBase::TOC_CODE))
1736 case LFUN_INSET_MODIFY:
1737 // We need to disable this, because we may get called for a
1739 // InsetTabular::getStatus() -> InsetText::getStatus()
1740 // and we don't handle LFUN_INSET_MODIFY.
1745 flag.setOnOff(font.emph() == LyXFont::ON);
1749 flag.setOnOff(font.noun() == LyXFont::ON);
1753 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1757 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1761 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1765 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1768 case LFUN_DELETE_WORD_FORWARD:
1769 case LFUN_DELETE_WORD_BACKWARD:
1770 case LFUN_DELETE_LINE_FORWARD:
1771 case LFUN_WORDRIGHT:
1781 case LFUN_UP_PARAGRAPHSEL:
1782 case LFUN_DOWN_PARAGRAPHSEL:
1787 case LFUN_WORDRIGHTSEL:
1788 case LFUN_WORDLEFTSEL:
1790 case LFUN_UP_PARAGRAPH:
1791 case LFUN_DOWN_PARAGRAPH:
1796 case LFUN_BREAKLINE:
1798 case LFUN_DELETE_SKIP:
1799 case LFUN_BACKSPACE:
1800 case LFUN_BACKSPACE_SKIP:
1801 case LFUN_BREAKPARAGRAPH:
1802 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1803 case LFUN_BREAKPARAGRAPH_SKIP:
1804 case LFUN_PARAGRAPH_SPACING:
1805 case LFUN_INSET_INSERT:
1806 case LFUN_NEXT_INSET_TOGGLE:
1807 case LFUN_UPCASE_WORD:
1808 case LFUN_LOWCASE_WORD:
1809 case LFUN_CAPITALIZE_WORD:
1810 case LFUN_TRANSPOSE_CHARS:
1817 case LFUN_GETLAYOUT:
1819 case LFUN_PASTESELECTION:
1820 case LFUN_DATE_INSERT:
1821 case LFUN_SELFINSERT:
1822 case LFUN_INSERT_LINE:
1823 case LFUN_INSERT_PAGEBREAK:
1824 case LFUN_MATH_DISPLAY:
1825 case LFUN_MATH_IMPORT_SELECTION:
1826 case LFUN_MATH_MODE:
1827 case LFUN_MATH_MACRO:
1828 case LFUN_INSERT_MATH:
1829 case LFUN_INSERT_MATRIX:
1830 case LFUN_MATH_DELIM:
1831 case LFUN_SUBSCRIPT:
1832 case LFUN_SUPERSCRIPT:
1834 case LFUN_UNDERLINE:
1835 case LFUN_FONT_SIZE:
1837 case LFUN_FREEFONT_APPLY:
1838 case LFUN_FREEFONT_UPDATE:
1839 case LFUN_LAYOUT_PARAGRAPH:
1840 case LFUN_PARAGRAPH_UPDATE:
1842 case LFUN_CIRCUMFLEX:
1852 case LFUN_SPECIAL_CARON:
1855 case LFUN_HUNG_UMLAUT:
1858 case LFUN_ACCEPT_CHANGE:
1859 case LFUN_REJECT_CHANGE:
1860 case LFUN_THESAURUS_ENTRY:
1861 case LFUN_PARAGRAPH_APPLY:
1864 case LFUN_BEGINNINGBUF:
1865 case LFUN_BEGINNINGBUFSEL:
1866 case LFUN_ENDBUFSEL:
1867 // these are handled in our dispatch()
1875 if (code != InsetBase::NO_CODE
1876 && (cur.empty() || !cur.inset().insetAllowed(code)))
1879 flag.enabled(enable);