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);
828 if (isStrUnsignedInt(cmd.argument))
829 pasteSelection(cur, convert<unsigned int>(cmd.argument));
831 pasteSelection(cur, 0);
832 cur.clearSelection(); // bug 393
838 cutSelection(cur, true, true);
839 cur.message(_("Cut"));
844 cur.message(_("Copy"));
848 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
849 + convert<string>(cursorY(cur.top(), cur.boundary())));
855 istringstream is(cmd.argument);
858 lyxerr << "SETXY: Could not parse coordinates in '"
859 << cmd.argument << std::endl;
861 setCursorFromCoordinates(cur, x, y);
866 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
868 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
875 cur.message(cur.paragraph().layout()->name());
879 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
880 << cmd.argument << endl;
882 // This is not the good solution to the empty argument
883 // problem, but it will hopefully suffice for 1.2.0.
884 // The correct solution would be to augument the
885 // function list/array with information about what
886 // functions needs arguments and their type.
887 if (cmd.argument.empty()) {
888 cur.errorMessage(_("LyX function 'layout' needs an argument."));
892 // Derive layout number from given argument (string)
893 // and current buffer's textclass (number)
894 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
895 bool hasLayout = tclass.hasLayout(cmd.argument);
896 string layout = cmd.argument;
898 // If the entry is obsolete, use the new one instead.
900 string const & obs = tclass[layout]->obsoleted_by();
906 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
911 bool change_layout = (current_layout != layout);
913 if (!change_layout && cur.selection() &&
914 cur.selBegin().pit() != cur.selEnd().pit())
916 pit_type spit = cur.selBegin().pit();
917 pit_type epit = cur.selEnd().pit() + 1;
918 while (spit != epit) {
919 if (pars_[spit].layout()->name() != current_layout) {
920 change_layout = true;
928 current_layout = layout;
929 setLayout(cur, layout);
930 bv->owner()->setLayout(layout);
936 case LFUN_PASTESELECTION: {
937 cur.clearSelection();
938 string const clip = bv->getClipboard();
941 if (cmd.argument == "paragraph")
942 insertStringAsParagraphs(cur, clip);
944 insertStringAsLines(cur, clip);
950 lyx::cap::replaceSelection(cur);
951 Paragraph & par = cur.paragraph();
952 lyx::pos_type pos = cur.pos();
956 else if (cur.prevInset() && cur.prevInset()->isSpace())
959 c = par.getChar(pos - 1);
961 LyXLayout_ptr const & style = par.layout();
963 BufferParams const & bufparams = bv->buffer()->params();
964 if (!style->pass_thru
965 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
966 string arg = cmd.argument;
968 cur.insert(new InsetQuotes(c,
969 bufparams.quotes_language,
970 InsetQuotes::SingleQ));
972 cur.insert(new InsetQuotes(c,
973 bufparams.quotes_language,
974 InsetQuotes::DoubleQ));
978 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
982 case LFUN_DATE_INSERT:
983 if (cmd.argument.empty())
984 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
985 lyx::formatted_time(lyx::current_time())));
987 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
988 lyx::formatted_time(lyx::current_time(), cmd.argument)));
991 case LFUN_MOUSE_TRIPLE:
992 if (cmd.button() == mouse_button::button1) {
998 bv->haveSelection(cur.selection());
1002 case LFUN_MOUSE_DOUBLE:
1003 if (cmd.button() == mouse_button::button1) {
1004 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1006 bv->haveSelection(cur.selection());
1010 // Single-click on work area
1011 case LFUN_MOUSE_PRESS: {
1012 // Right click on a footnote flag opens float menu
1013 if (cmd.button() == mouse_button::button3) {
1014 cur.clearSelection();
1018 // Middle button press pastes if we have a selection
1019 // We do this here as if the selection was inside an inset
1020 // it could get cleared on the unlocking of the inset so
1021 // we have to check this first
1022 bool paste_internally = false;
1023 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1024 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1025 paste_internally = true;
1028 bv->mouseSetCursor(cur);
1030 // Insert primary selection with middle mouse
1031 // if there is a local selection in the current buffer,
1033 if (cmd.button() == mouse_button::button2) {
1034 if (paste_internally)
1035 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1037 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1043 case LFUN_MOUSE_MOTION: {
1044 // Only use motion with button 1
1045 //if (cmd.button() != mouse_button::button1)
1048 // ignore motions deeper nested than the real anchor
1049 LCursor & bvcur = cur.bv().cursor();
1050 if (bvcur.anchor_.hasPart(cur)) {
1051 CursorSlice old = bvcur.top();
1053 int const wh = bv->workHeight();
1054 int const y = std::max(0, std::min(wh - 1, cmd.y));
1056 setCursorFromCoordinates(cur, cmd.x, y);
1057 cur.x_target() = cmd.x;
1062 // This is to allow jumping over large insets
1063 if (cur.top() == old) {
1070 if (cur.top() == old)
1073 // don't set anchor_
1074 bvcur.setCursor(cur);
1075 bvcur.selection() = true;
1076 //lyxerr << "MOTION: " << bv->cursor() << endl;
1084 case LFUN_MOUSE_RELEASE: {
1085 if (cmd.button() == mouse_button::button2)
1089 if (cmd.button() == mouse_button::button1)
1090 bv->haveSelection(cur.selection());
1093 bv->owner()->updateMenubar();
1094 bv->owner()->updateToolbars();
1098 case LFUN_SELFINSERT: {
1099 if (cmd.argument.empty())
1102 // Automatically delete the currently selected
1103 // text and replace it with what is being
1104 // typed in now. Depends on lyxrc settings
1105 // "auto_region_delete", which defaults to
1108 if (lyxrc.auto_region_delete) {
1109 if (cur.selection())
1110 cutSelection(cur, false, false);
1111 bv->haveSelection(false);
1114 cur.clearSelection();
1115 LyXFont const old_font = real_current_font;
1117 // Prevents language turds in new lyxtexts under non-english
1118 BufferParams const & bufparams = cur.buffer().params();
1119 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1120 current_font.setLanguage(lang);
1121 real_current_font.setLanguage(lang);
1123 string::const_iterator cit = cmd.argument.begin();
1124 string::const_iterator end = cmd.argument.end();
1125 for (; cit != end; ++cit)
1126 bv->owner()->getIntl().getTransManager().
1127 TranslateAndInsert(*cit, this);
1130 moveCursor(cur, false);
1131 bv->updateScrollbar();
1136 InsetCommandParams p("url");
1137 string const data = InsetCommandMailer::params2string("url", p);
1138 bv->owner()->getDialogs().show("url", data, 0);
1142 case LFUN_HTMLURL: {
1143 InsetCommandParams p("htmlurl");
1144 string const data = InsetCommandMailer::params2string("url", p);
1145 bv->owner()->getDialogs().show("url", data, 0);
1149 case LFUN_INSERT_LABEL: {
1150 // Try to generate a valid label
1151 string const contents = cmd.argument.empty() ?
1152 cur.getPossibleLabel() : cmd.argument;
1154 InsetCommandParams p("label", contents);
1155 string const data = InsetCommandMailer::params2string("label", p);
1157 if (cmd.argument.empty()) {
1158 bv->owner()->getDialogs().show("label", data, 0);
1160 FuncRequest fr(LFUN_INSET_INSERT, data);
1168 case LFUN_INSET_LIST:
1169 case LFUN_INSET_THEOREM:
1170 case LFUN_INSET_CAPTION:
1172 case LFUN_INSERT_NOTE:
1173 case LFUN_INSERT_CHARSTYLE:
1174 case LFUN_INSERT_BOX:
1175 case LFUN_INSERT_BRANCH:
1176 case LFUN_INSERT_BIBITEM:
1177 case LFUN_INSET_ERT:
1178 case LFUN_INSET_FOOTNOTE:
1179 case LFUN_INSET_MARGINAL:
1180 case LFUN_INSET_OPTARG:
1181 case LFUN_ENVIRONMENT_INSERT:
1182 // Open the inset, and move the current selection
1184 doInsertInset(cur, this, cmd, true, true);
1188 case LFUN_TABULAR_INSERT:
1189 // if there were no arguments, just open the dialog
1190 if (doInsertInset(cur, this, cmd, false, true))
1193 bv->owner()->getDialogs().show("tabularcreate");
1197 case LFUN_INSET_FLOAT:
1198 case LFUN_INSET_WIDE_FLOAT:
1199 case LFUN_INSET_WRAP:
1200 doInsertInset(cur, this, cmd, true, true);
1202 // FIXME: the "Caption" name should not be hardcoded,
1203 // but given by the float definition.
1204 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1207 case LFUN_INDEX_INSERT: {
1208 InsetBase * inset = createInset(&cur.bv(), cmd);
1213 cur.clearSelection();
1214 insertInset(cur, inset);
1215 inset->edit(cur, true);
1220 case LFUN_INDEX_PRINT:
1221 case LFUN_TOC_INSERT:
1223 case LFUN_INSERT_LINE:
1224 case LFUN_INSERT_PAGEBREAK:
1226 doInsertInset(cur, this, cmd, false, false);
1230 case LFUN_DEPTH_MIN:
1231 changeDepth(cur, DEC_DEPTH);
1234 case LFUN_DEPTH_PLUS:
1235 changeDepth(cur, INC_DEPTH);
1238 case LFUN_MATH_DISPLAY:
1239 mathDispatch(cur, cmd, true);
1242 case LFUN_MATH_IMPORT_SELECTION:
1243 case LFUN_MATH_MODE:
1244 if (cmd.argument == "on")
1245 // don't pass "on" as argument
1246 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1248 mathDispatch(cur, cmd, false);
1251 case LFUN_MATH_MACRO:
1252 if (cmd.argument.empty())
1253 cur.errorMessage(N_("Missing argument"));
1255 string s = cmd.argument;
1256 string const s1 = token(s, ' ', 1);
1257 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1258 string const s2 = token(s, ' ', 2);
1259 string const type = s2.empty() ? "newcommand" : s2;
1260 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1261 //cur.nextInset()->edit(cur, true);
1265 // passthrough hat and underscore outside mathed:
1266 case LFUN_SUBSCRIPT:
1267 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1269 case LFUN_SUPERSCRIPT:
1270 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1273 case LFUN_INSERT_MATH:
1274 case LFUN_INSERT_MATRIX:
1275 case LFUN_MATH_DELIM: {
1276 cur.insert(new MathHullInset("simple"));
1277 cur.dispatch(FuncRequest(LFUN_RIGHT));
1283 LyXFont font(LyXFont::ALL_IGNORE);
1284 font.setEmph(LyXFont::TOGGLE);
1285 toggleAndShow(cur, this, font);
1290 LyXFont font(LyXFont::ALL_IGNORE);
1291 font.setSeries(LyXFont::BOLD_SERIES);
1292 toggleAndShow(cur, this, font);
1297 LyXFont font(LyXFont::ALL_IGNORE);
1298 font.setNoun(LyXFont::TOGGLE);
1299 toggleAndShow(cur, this, font);
1304 LyXFont font(LyXFont::ALL_IGNORE);
1305 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1306 toggleAndShow(cur, this, font);
1311 LyXFont font(LyXFont::ALL_IGNORE);
1312 font.setFamily(LyXFont::SANS_FAMILY);
1313 toggleAndShow(cur, this, font);
1318 LyXFont font(LyXFont::ALL_IGNORE);
1319 font.setFamily(LyXFont::ROMAN_FAMILY);
1320 toggleAndShow(cur, this, font);
1324 case LFUN_DEFAULT: {
1325 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1326 toggleAndShow(cur, this, font);
1330 case LFUN_UNDERLINE: {
1331 LyXFont font(LyXFont::ALL_IGNORE);
1332 font.setUnderbar(LyXFont::TOGGLE);
1333 toggleAndShow(cur, this, font);
1337 case LFUN_FONT_SIZE: {
1338 LyXFont font(LyXFont::ALL_IGNORE);
1339 font.setLyXSize(cmd.argument);
1340 toggleAndShow(cur, this, font);
1344 case LFUN_LANGUAGE: {
1345 Language const * lang = languages.getLanguage(cmd.argument);
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setLanguage(lang);
1350 toggleAndShow(cur, this, font);
1355 case LFUN_FREEFONT_APPLY:
1356 toggleAndShow(cur, this, freefont, toggleall);
1357 cur.message(_("Character set"));
1360 // Set the freefont using the contents of \param data dispatched from
1361 // the frontends and apply it at the current cursor location.
1362 case LFUN_FREEFONT_UPDATE: {
1365 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1368 toggleAndShow(cur, this, freefont, toggleall);
1369 cur.message(_("Character set"));
1374 case LFUN_FINISHED_LEFT:
1375 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1378 case LFUN_FINISHED_RIGHT:
1379 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1383 case LFUN_FINISHED_UP:
1384 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1388 case LFUN_FINISHED_DOWN:
1389 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1393 case LFUN_LAYOUT_PARAGRAPH: {
1395 params2string(cur.paragraph(), data);
1396 data = "show\n" + data;
1397 bv->owner()->getDialogs().show("paragraph", data);
1401 case LFUN_PARAGRAPH_UPDATE: {
1402 if (!bv->owner()->getDialogs().visible("paragraph"))
1405 params2string(cur.paragraph(), data);
1407 // Will the paragraph accept changes from the dialog?
1408 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
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);
1556 LyXFont const & font = real_current_font;
1558 InsetBase::Code code = InsetBase::NO_CODE;
1560 switch (cmd.action) {
1562 case LFUN_DEPTH_MIN:
1563 enable = changeDepthAllowed(cur, DEC_DEPTH);
1566 case LFUN_DEPTH_PLUS:
1567 enable = changeDepthAllowed(cur, INC_DEPTH);
1571 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1574 case LFUN_INSERT_BIBITEM:
1575 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1578 case LFUN_DIALOG_SHOW_NEW_INSET:
1579 if (cmd.argument == "bibitem")
1580 code = InsetBase::BIBITEM_CODE;
1581 else if (cmd.argument == "bibtex")
1582 code = InsetBase::BIBTEX_CODE;
1583 else if (cmd.argument == "box")
1584 code = InsetBase::BOX_CODE;
1585 else if (cmd.argument == "branch")
1586 code = InsetBase::BRANCH_CODE;
1587 else if (cmd.argument == "citation")
1588 code = InsetBase::CITE_CODE;
1589 else if (cmd.argument == "ert")
1590 code = InsetBase::ERT_CODE;
1591 else if (cmd.argument == "external")
1592 code = InsetBase::EXTERNAL_CODE;
1593 else if (cmd.argument == "float")
1594 code = InsetBase::FLOAT_CODE;
1595 else if (cmd.argument == "graphics")
1596 code = InsetBase::GRAPHICS_CODE;
1597 else if (cmd.argument == "include")
1598 code = InsetBase::INCLUDE_CODE;
1599 else if (cmd.argument == "index")
1600 code = InsetBase::INDEX_CODE;
1601 else if (cmd.argument == "label")
1602 code = InsetBase::LABEL_CODE;
1603 else if (cmd.argument == "note")
1604 code = InsetBase::NOTE_CODE;
1605 else if (cmd.argument == "ref")
1606 code = InsetBase::REF_CODE;
1607 else if (cmd.argument == "toc")
1608 code = InsetBase::TOC_CODE;
1609 else if (cmd.argument == "url")
1610 code = InsetBase::URL_CODE;
1611 else if (cmd.argument == "vspace")
1612 code = InsetBase::VSPACE_CODE;
1613 else if (cmd.argument == "wrap")
1614 code = InsetBase::WRAP_CODE;
1617 case LFUN_INSET_ERT:
1618 code = InsetBase::ERT_CODE;
1620 case LFUN_INSET_FOOTNOTE:
1621 code = InsetBase::FOOT_CODE;
1623 case LFUN_TABULAR_INSERT:
1624 code = InsetBase::TABULAR_CODE;
1626 case LFUN_INSET_MARGINAL:
1627 code = InsetBase::MARGIN_CODE;
1629 case LFUN_INSET_FLOAT:
1630 case LFUN_INSET_WIDE_FLOAT:
1631 code = InsetBase::FLOAT_CODE;
1633 case LFUN_INSET_WRAP:
1634 code = InsetBase::WRAP_CODE;
1636 case LFUN_FLOAT_LIST:
1637 code = InsetBase::FLOAT_LIST_CODE;
1640 case LFUN_INSET_LIST:
1641 code = InsetBase::LIST_CODE;
1643 case LFUN_INSET_THEOREM:
1644 code = InsetBase::THEOREM_CODE;
1647 case LFUN_INSET_CAPTION:
1648 code = InsetBase::CAPTION_CODE;
1650 case LFUN_INSERT_NOTE:
1651 code = InsetBase::NOTE_CODE;
1653 case LFUN_INSERT_CHARSTYLE:
1654 code = InsetBase::CHARSTYLE_CODE;
1655 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1658 case LFUN_INSERT_BOX:
1659 code = InsetBase::BOX_CODE;
1661 case LFUN_INSERT_BRANCH:
1662 code = InsetBase::BRANCH_CODE;
1663 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1666 case LFUN_INSERT_LABEL:
1667 code = InsetBase::LABEL_CODE;
1669 case LFUN_INSET_OPTARG:
1670 code = InsetBase::OPTARG_CODE;
1671 enable = numberOfOptArgs(cur.paragraph())
1672 < cur.paragraph().layout()->optionalargs;
1674 case LFUN_ENVIRONMENT_INSERT:
1675 code = InsetBase::BOX_CODE;
1677 case LFUN_INDEX_INSERT:
1678 code = InsetBase::INDEX_CODE;
1680 case LFUN_INDEX_PRINT:
1681 code = InsetBase::INDEX_PRINT_CODE;
1683 case LFUN_TOC_INSERT:
1684 code = InsetBase::TOC_CODE;
1688 code = InsetBase::URL_CODE;
1691 // always allow this, since we will inset a raw quote
1692 // if an inset is not allowed.
1694 case LFUN_HYPHENATION:
1695 case LFUN_LIGATURE_BREAK:
1697 case LFUN_MENU_SEPARATOR:
1699 case LFUN_END_OF_SENTENCE:
1700 code = InsetBase::SPECIALCHAR_CODE;
1702 case LFUN_SPACE_INSERT:
1703 // slight hack: we know this is allowed in math mode
1705 code = InsetBase::SPACE_CODE;
1708 #ifdef WITH_WARNINGS
1709 #warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
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))
1727 case LFUN_INSET_MODIFY:
1728 // We need to disable this, because we may get called for a
1730 // InsetTabular::getStatus() -> InsetText::getStatus()
1731 // and we don't handle LFUN_INSET_MODIFY.
1736 flag.setOnOff(font.emph() == LyXFont::ON);
1740 flag.setOnOff(font.noun() == LyXFont::ON);
1744 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1748 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1752 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1756 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1761 enable = cur.selection();
1765 enable = lyx::cap::numberOfSelections() > 0;
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:
1814 case LFUN_GETLAYOUT:
1816 case LFUN_PASTESELECTION:
1817 case LFUN_DATE_INSERT:
1818 case LFUN_SELFINSERT:
1819 case LFUN_INSERT_LINE:
1820 case LFUN_INSERT_PAGEBREAK:
1821 case LFUN_MATH_DISPLAY:
1822 case LFUN_MATH_IMPORT_SELECTION:
1823 case LFUN_MATH_MODE:
1824 case LFUN_MATH_MACRO:
1825 case LFUN_INSERT_MATH:
1826 case LFUN_INSERT_MATRIX:
1827 case LFUN_MATH_DELIM:
1828 case LFUN_SUBSCRIPT:
1829 case LFUN_SUPERSCRIPT:
1831 case LFUN_UNDERLINE:
1832 case LFUN_FONT_SIZE:
1834 case LFUN_FREEFONT_APPLY:
1835 case LFUN_FREEFONT_UPDATE:
1836 case LFUN_LAYOUT_PARAGRAPH:
1837 case LFUN_PARAGRAPH_UPDATE:
1839 case LFUN_CIRCUMFLEX:
1849 case LFUN_SPECIAL_CARON:
1852 case LFUN_HUNG_UMLAUT:
1855 case LFUN_ACCEPT_CHANGE:
1856 case LFUN_REJECT_CHANGE:
1857 case LFUN_THESAURUS_ENTRY:
1858 case LFUN_PARAGRAPH_APPLY:
1861 case LFUN_BEGINNINGBUF:
1862 case LFUN_BEGINNINGBUFSEL:
1863 case LFUN_ENDBUFSEL:
1864 // these are handled in our dispatch()
1872 if (code != InsetBase::NO_CODE
1873 && (cur.empty() || !cur.inset().insetAllowed(code)))
1876 flag.enabled(enable);