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"
47 #include "pariterator.h"
49 #include "frontends/Dialogs.h"
50 #include "frontends/Gui.h"
51 #include "frontends/LyXView.h"
52 #include "frontends/Clipboard.h"
53 #include "frontends/Selection.h"
55 #include "insets/insetcommand.h"
56 #include "insets/insetfloatlist.h"
57 #include "insets/insetnewline.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetspecialchar.h"
60 #include "insets/insettext.h"
62 #include "support/lstrings.h"
63 #include "support/lyxlib.h"
64 #include "support/convert.h"
65 #include "support/lyxtime.h"
67 #include "mathed/math_hullinset.h"
68 #include "mathed/math_macrotemplate.h"
70 #include <boost/current_function.hpp>
77 using lyx::cap::copySelection;
78 using lyx::cap::cutSelection;
79 using lyx::cap::pasteSelection;
80 using lyx::cap::replaceSelection;
82 using lyx::support::isStrUnsignedInt;
83 using lyx::support::token;
85 using lyx::frontend::Gui;
86 using lyx::frontend::Clipboard;
90 using std::istringstream;
91 using std::ostringstream;
94 extern string current_layout;
100 LyXFont freefont(LyXFont::ALL_IGNORE);
101 bool toggleall = false;
104 void toggleAndShow(LCursor & cur, LyXText * text,
105 LyXFont const & font, bool toggleall = true)
107 text->toggleFree(cur, font, toggleall);
109 if (font.language() != ignore_language ||
110 font.number() != LyXFont::IGNORE) {
111 Paragraph & par = cur.paragraph();
112 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
113 if (cur.boundary() !=
114 text->bidi.isBoundary(cur.buffer(), par,
116 text->real_current_font))
117 text->setCursor(cur, cur.pit(), cur.pos(),
118 false, !cur.boundary());
123 void moveCursor(LCursor & cur, bool selecting)
125 if (selecting || cur.mark())
127 if (!cur.selection())
128 cur.bv().owner()->gui().selection().haveSelection(false);
129 cur.bv().switchKeyMap();
133 void finishChange(LCursor & cur, bool selecting)
136 moveCursor(cur, selecting);
140 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
143 string sel = cur.selectionAsString(false);
144 //lyxerr << "selection is: '" << sel << "'" << endl;
146 // It may happen that sel is empty but there is a selection
147 replaceSelection(cur);
150 const int old_pos = cur.pos();
151 cur.insert(new MathHullInset("simple"));
152 BOOST_ASSERT(old_pos == cur.pos());
153 cur.nextInset()->edit(cur, true);
154 // don't do that also for LFUN_MATH_MODE
155 // unless you want end up with always changing
156 // to mathrm when opening an inlined inset --
157 // I really hate "LyXfunc overloading"...
159 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
160 // Avoid an unnecessary undo step if cmd.argument
162 if (!cmd.argument.empty())
163 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
166 // create a macro if we see "\\newcommand"
167 // somewhere, and an ordinary formula
169 istringstream is(sel);
170 if (sel.find("\\newcommand") == string::npos
171 && sel.find("\\def") == string::npos)
173 MathHullInset * formula = new MathHullInset;
176 formula->read(cur.buffer(), lex);
177 if (formula->getType() == "none")
178 // Don't create pseudo formulas if
179 // delimiters are left out
180 formula->mutate("simple");
183 cur.insert(new MathMacroTemplate(is));
185 cur.message(N_("Math editor mode"));
194 string const freefont2string()
197 if (font2string(freefont, toggleall, data))
204 bool LyXText::cursorPrevious(LCursor & cur)
206 pos_type cpos = cur.pos();
207 lyx::pit_type cpar = cur.pit();
209 int x = cur.x_target();
211 bool updated = setCursorFromCoordinates(cur, x, 0);
214 updated |= cursorUp(cur);
216 if (cpar == cur.pit() && cpos == cur.pos()) {
217 // we have a row which is taller than the workarea. The
218 // simplest solution is to move to the previous row instead.
219 updated |= cursorUp(cur);
227 bool LyXText::cursorNext(LCursor & cur)
229 pos_type cpos = cur.pos();
230 lyx::pit_type cpar = cur.pit();
232 int x = cur.x_target();
233 bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
236 updated |= cursorDown(cur);
238 if (cpar == cur.pit() && cpos == cur.pos()) {
239 // we have a row which is taller than the workarea. The
240 // simplest solution is to move to the next row instead.
241 updated |= cursorDown(cur);
251 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
253 lyx::cap::replaceSelection(cur);
254 cur.insert(new InsetSpecialChar(kind));
259 bool doInsertInset(LCursor & cur, LyXText * text,
260 FuncRequest const & cmd, bool edit, bool pastesel)
262 InsetBase * inset = createInset(&cur.bv(), cmd);
268 if (cur.selection()) {
269 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
272 text->insertInset(cur, inset);
275 inset->edit(cur, true);
277 if (gotsel && pastesel)
278 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
283 void update(LCursor & cur)
285 //we don't call update(true, false) directly to save a metrics call
286 if (cur.bv().fitCursor())
287 cur.bv().update(Update::Force);
294 void LyXText::number(LCursor & cur)
296 LyXFont font(LyXFont::ALL_IGNORE);
297 font.setNumber(LyXFont::TOGGLE);
298 toggleAndShow(cur, this, font);
302 bool LyXText::isRTL(Paragraph const & par) const
304 return par.isRightToLeftPar(bv()->buffer()->params());
308 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
310 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
312 BOOST_ASSERT(cur.text() == this);
313 BufferView * bv = &cur.bv();
314 CursorSlice oldTopSlice = cur.top();
315 bool oldBoundary = cur.boundary();
316 bool sel = cur.selection();
317 // Signals that, even if needsUpdate == false, an update of the
318 // cursor paragraph is required
319 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
320 LyXAction::SingleParUpdate);
321 // Signals that a full-screen update is required
322 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
323 LyXAction::NoUpdate) || singleParUpdate);
324 // Remember the old paragraph metric (_outer_ paragraph!)
325 Dimension olddim = cur.bottom().paragraph().dim();
327 switch (cmd.action) {
329 case LFUN_PARAGRAPH_MOVE_DOWN: {
330 pit_type const pit = cur.pit();
331 recUndo(pit, pit + 1);
333 std::swap(pars_[pit], pars_[pit + 1]);
335 ParIterator begin(cur);
337 ParIterator end = boost::next(ParIterator(cur));
338 updateLabels(cur.buffer(), begin, end);
344 case LFUN_PARAGRAPH_MOVE_UP: {
345 pit_type const pit = cur.pit();
346 recUndo(pit - 1, pit);
348 std::swap(pars_[pit], pars_[pit - 1]);
350 ParIterator end = boost::next(ParIterator(cur));
352 ParIterator begin(cur);
353 updateLabels(cur.buffer(), begin, end);
359 case LFUN_APPENDIX: {
360 Paragraph & par = cur.paragraph();
361 bool start = !par.params().startOfAppendix();
364 #warning The code below only makes sense at top level.
365 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
367 // ensure that we have only one start_of_appendix in this document
368 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
369 if (pars_[tmp].params().startOfAppendix()) {
371 pars_[tmp].params().startOfAppendix(false);
377 par.params().startOfAppendix(start);
379 // we can set the refreshing parameters now
380 updateLabels(cur.buffer());
384 case LFUN_WORD_DELETE_FORWARD:
385 cur.clearSelection();
386 deleteWordForward(cur);
387 finishChange(cur, false);
390 case LFUN_WORD_DELETE_BACKWARD:
391 cur.clearSelection();
392 deleteWordBackward(cur);
393 finishChange(cur, false);
396 case LFUN_LINE_DELETE:
397 cur.clearSelection();
398 deleteLineForward(cur);
399 finishChange(cur, false);
402 case LFUN_WORD_FORWARD:
404 cur.clearSelection();
405 if (isRTL(cur.paragraph()))
406 needsUpdate = cursorLeftOneWord(cur);
408 needsUpdate = cursorRightOneWord(cur);
409 finishChange(cur, false);
412 case LFUN_WORD_BACKWARD:
414 cur.clearSelection();
415 if (isRTL(cur.paragraph()))
416 needsUpdate = cursorRightOneWord(cur);
418 needsUpdate = cursorLeftOneWord(cur);
419 finishChange(cur, false);
422 case LFUN_BUFFER_BEGIN:
423 if (cur.depth() == 1) {
425 cur.clearSelection();
426 needsUpdate = cursorTop(cur);
427 finishChange(cur, false);
433 case LFUN_BUFFER_BEGIN_SELECT:
434 if (cur.depth() == 1) {
435 if (!cur.selection())
437 needsUpdate = cursorTop(cur);
438 finishChange(cur, true);
444 case LFUN_BUFFER_END:
445 if (cur.depth() == 1) {
447 cur.clearSelection();
448 needsUpdate = cursorBottom(cur);
449 finishChange(cur, false);
455 case LFUN_BUFFER_END_SELECT:
456 if (cur.depth() == 1) {
457 if (!cur.selection())
459 needsUpdate = cursorBottom(cur);
460 finishChange(cur, true);
466 case LFUN_CHAR_FORWARD:
467 case LFUN_CHAR_FORWARD_SELECT:
468 //lyxerr << BOOST_CURRENT_FUNCTION
469 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
470 cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
471 if (isRTL(cur.paragraph()))
472 needsUpdate = cursorLeft(cur);
474 needsUpdate = cursorRight(cur);
476 if (!needsUpdate && oldTopSlice == cur.top()
477 && cur.boundary() == oldBoundary) {
479 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
483 case LFUN_CHAR_BACKWARD:
484 case LFUN_CHAR_BACKWARD_SELECT:
485 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
486 cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
487 if (isRTL(cur.paragraph()))
488 needsUpdate = cursorRight(cur);
490 needsUpdate = cursorLeft(cur);
492 if (!needsUpdate && oldTopSlice == cur.top()
493 && cur.boundary() == oldBoundary) {
495 cmd = FuncRequest(LFUN_FINISHED_LEFT);
502 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
503 cur.selHandle(cmd.action == LFUN_UP_SELECT);
505 needsUpdate = cursorUp(cur);
506 if (!needsUpdate && oldTopSlice == cur.top()
507 && cur.boundary() == oldBoundary) {
509 cmd = FuncRequest(LFUN_FINISHED_UP);
514 case LFUN_DOWN_SELECT:
516 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
517 cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
518 needsUpdate = cursorDown(cur);
519 if (!needsUpdate && oldTopSlice == cur.top() &&
520 cur.boundary() == oldBoundary)
523 cmd = FuncRequest(LFUN_FINISHED_DOWN);
527 case LFUN_PARAGRAPH_UP:
529 cur.clearSelection();
530 needsUpdate = cursorUpParagraph(cur);
531 finishChange(cur, false);
534 case LFUN_PARAGRAPH_UP_SELECT:
535 if (!cur.selection())
537 cursorUpParagraph(cur);
538 finishChange(cur, true);
541 case LFUN_PARAGRAPH_DOWN:
543 cur.clearSelection();
544 needsUpdate = cursorDownParagraph(cur);
545 finishChange(cur, false);
548 case LFUN_PARAGRAPH_DOWN_SELECT:
549 if (!cur.selection())
551 cursorDownParagraph(cur);
552 finishChange(cur, true);
555 case LFUN_SCREEN_UP_SELECT:
557 if (!cur.selection())
559 needsUpdate = cursorPrevious(cur);
560 finishChange(cur, true);
563 case LFUN_SCREEN_DOWN_SELECT:
565 if (!cur.selection())
567 needsUpdate = cursorNext(cur);
568 finishChange(cur, true);
571 case LFUN_LINE_BEGIN_SELECT:
573 if (!cur.selection())
575 needsUpdate = cursorHome(cur);
576 finishChange(cur, true);
579 case LFUN_LINE_END_SELECT:
581 if (!cur.selection())
583 needsUpdate = cursorEnd(cur);
584 finishChange(cur, true);
587 case LFUN_WORD_FORWARD_SELECT:
588 if (!cur.selection())
590 if (isRTL(cur.paragraph()))
591 cursorLeftOneWord(cur);
593 cursorRightOneWord(cur);
594 finishChange(cur, true);
597 case LFUN_WORD_BACKWARD_SELECT:
598 if (!cur.selection())
600 if (isRTL(cur.paragraph()))
601 cursorRightOneWord(cur);
603 cursorLeftOneWord(cur);
604 finishChange(cur, true);
607 case LFUN_WORD_SELECT: {
608 selectWord(cur, lyx::WHOLE_WORD);
609 finishChange(cur, true);
616 cur.clearSelection();
617 finishChange(cur, false);
618 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
620 cmd = FuncRequest(LFUN_FINISHED_UP);
622 needsUpdate = cursorPrevious(cur);
626 case LFUN_SCREEN_DOWN:
629 cur.clearSelection();
630 finishChange(cur, false);
631 if (cur.pit() == cur.lastpit()
632 && cur.textRow().endpos() == cur.lastpos()) {
634 cmd = FuncRequest(LFUN_FINISHED_DOWN);
636 needsUpdate = cursorNext(cur);
640 case LFUN_LINE_BEGIN:
642 cur.clearSelection();
643 needsUpdate = cursorHome(cur);
644 finishChange(cur, false);
649 cur.clearSelection();
650 needsUpdate = cursorEnd(cur);
651 finishChange(cur, false);
654 case LFUN_BREAK_LINE: {
655 // Not allowed by LaTeX (labels or empty par)
656 if (cur.pos() > cur.paragraph().beginOfBody()) {
657 lyx::cap::replaceSelection(cur);
658 cur.insert(new InsetNewline);
660 moveCursor(cur, false);
665 case LFUN_CHAR_DELETE_FORWARD:
666 if (!cur.selection()) {
667 if (cur.pos() == cur.paragraph().size())
668 // Par boundary, force full-screen update
669 singleParUpdate = false;
670 needsUpdate = erase(cur);
672 // It is possible to make it a lot faster still
673 // just comment out the line below...
675 cutSelection(cur, true, false);
676 singleParUpdate = false;
678 moveCursor(cur, false);
681 case LFUN_DELETE_FORWARD_SKIP:
682 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
683 if (!cur.selection()) {
684 if (cur.pos() == cur.lastpos()) {
691 cutSelection(cur, true, false);
696 case LFUN_CHAR_DELETE_BACKWARD:
697 if (!cur.selection()) {
698 if (bv->owner()->getIntl().getTransManager().backspace()) {
699 // Par boundary, full-screen update
701 singleParUpdate = false;
702 needsUpdate = backspace(cur);
704 // It is possible to make it a lot faster still
705 // just comment out the line below...
708 cutSelection(cur, true, false);
709 singleParUpdate = false;
714 case LFUN_DELETE_BACKWARD_SKIP:
715 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
716 if (!cur.selection()) {
720 //CursorSlice cur = cursor();
724 cutSelection(cur, true, false);
728 case LFUN_BREAK_PARAGRAPH:
729 lyx::cap::replaceSelection(cur);
730 breakParagraph(cur, 0);
735 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
736 lyx::cap::replaceSelection(cur);
737 breakParagraph(cur, 1);
742 case LFUN_BREAK_PARAGRAPH_SKIP: {
743 // When at the beginning of a paragraph, remove
744 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
745 lyx::cap::replaceSelection(cur);
747 cur.paragraph().params().labelWidthString(string());
749 breakParagraph(cur, 0);
755 case LFUN_PARAGRAPH_SPACING: {
756 Paragraph & par = cur.paragraph();
757 Spacing::Space cur_spacing = par.params().spacing().getSpace();
758 string cur_value = "1.0";
759 if (cur_spacing == Spacing::Other)
760 cur_value = par.params().spacing().getValueAsString();
762 istringstream is(cmd.argument);
765 Spacing::Space new_spacing = cur_spacing;
766 string new_value = cur_value;
768 lyxerr << "Missing argument to `paragraph-spacing'"
770 } else if (tmp == "single") {
771 new_spacing = Spacing::Single;
772 } else if (tmp == "onehalf") {
773 new_spacing = Spacing::Onehalf;
774 } else if (tmp == "double") {
775 new_spacing = Spacing::Double;
776 } else if (tmp == "other") {
777 new_spacing = Spacing::Other;
778 string tmpval = "0.0";
780 lyxerr << "new_value = " << tmpval << endl;
783 } else if (tmp == "default") {
784 new_spacing = Spacing::Default;
786 lyxerr << _("Unknown spacing argument: ")
787 << cmd.argument << endl;
789 if (cur_spacing != new_spacing || cur_value != new_value)
790 par.params().spacing(Spacing(new_spacing, new_value));
794 case LFUN_INSET_INSERT: {
796 InsetBase * inset = createInset(bv, cmd);
798 insertInset(cur, inset);
804 case LFUN_INSET_SETTINGS:
805 cur.inset().showInsetDialog(bv);
808 case LFUN_NEXT_INSET_TOGGLE: {
809 InsetBase * inset = cur.nextInset();
810 // this is the real function we want to invoke
811 cmd = FuncRequest(LFUN_INSET_TOGGLE);
813 // if there is an inset at cursor, see whether it
816 LCursor tmpcur = cur;
817 tmpcur.pushLeft(*inset);
818 inset->dispatch(tmpcur, cmd);
819 if (tmpcur.result().dispatched()) {
820 cur.clearSelection();
824 // if it did not work, try the underlying inset.
825 if (!cur.result().dispatched())
826 cur.inset().dispatch(cur, cmd);
830 case LFUN_SPACE_INSERT:
831 if (cur.paragraph().layout()->free_spacing)
832 insertChar(cur, ' ');
834 doInsertInset(cur, this, cmd, false, false);
837 moveCursor(cur, false);
840 case LFUN_HYPHENATION_POINT_INSERT:
841 specialChar(cur, InsetSpecialChar::HYPHENATION);
844 case LFUN_LIGATURE_BREAK_INSERT:
845 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
848 case LFUN_DOTS_INSERT:
849 specialChar(cur, InsetSpecialChar::LDOTS);
852 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
853 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
856 case LFUN_MENU_SEPARATOR_INSERT:
857 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
860 case LFUN_WORD_UPCASE:
861 changeCase(cur, LyXText::text_uppercase);
864 case LFUN_WORD_LOWCASE:
865 changeCase(cur, LyXText::text_lowercase);
868 case LFUN_WORD_CAPITALIZE:
869 changeCase(cur, LyXText::text_capitalization);
872 case LFUN_CHARS_TRANSPOSE:
877 cur.message(_("Paste"));
878 lyx::cap::replaceSelection(cur);
879 if (isStrUnsignedInt(cmd.argument))
880 pasteSelection(cur, convert<unsigned int>(cmd.argument));
882 pasteSelection(cur, 0);
883 cur.clearSelection(); // bug 393
889 cutSelection(cur, true, true);
890 cur.message(_("Cut"));
895 cur.message(_("Copy"));
898 case LFUN_SERVER_GET_XY:
899 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
900 + convert<string>(cursorY(cur.top(), cur.boundary())));
903 case LFUN_SERVER_SET_XY: {
906 istringstream is(cmd.argument);
909 lyxerr << "SETXY: Could not parse coordinates in '"
910 << cmd.argument << std::endl;
912 setCursorFromCoordinates(cur, x, y);
916 case LFUN_SERVER_GET_FONT:
917 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
919 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
925 case LFUN_SERVER_GET_LAYOUT:
926 cur.message(cur.paragraph().layout()->name());
930 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
931 << cmd.argument << endl;
933 // This is not the good solution to the empty argument
934 // problem, but it will hopefully suffice for 1.2.0.
935 // The correct solution would be to augument the
936 // function list/array with information about what
937 // functions needs arguments and their type.
938 if (cmd.argument.empty()) {
939 cur.errorMessage(_("LyX function 'layout' needs an argument."));
943 // Derive layout number from given argument (string)
944 // and current buffer's textclass (number)
945 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
946 bool hasLayout = tclass.hasLayout(cmd.argument);
947 string layout = cmd.argument;
949 // If the entry is obsolete, use the new one instead.
951 string const & obs = tclass[layout]->obsoleted_by();
957 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
962 bool change_layout = (current_layout != layout);
964 if (!change_layout && cur.selection() &&
965 cur.selBegin().pit() != cur.selEnd().pit())
967 pit_type spit = cur.selBegin().pit();
968 pit_type epit = cur.selEnd().pit() + 1;
969 while (spit != epit) {
970 if (pars_[spit].layout()->name() != current_layout) {
971 change_layout = true;
979 current_layout = layout;
980 setLayout(cur, layout);
981 bv->owner()->setLayout(layout);
987 case LFUN_CLIPBOARD_PASTE: {
988 cur.clearSelection();
989 string const clip = bv->owner()->gui().clipboard().get();
992 if (cmd.argument == "paragraph")
993 insertStringAsParagraphs(cur, clip);
995 insertStringAsLines(cur, clip);
1000 case LFUN_PRIMARY_SELECTION_PASTE: {
1001 cur.clearSelection();
1002 string const clip = bv->owner()->gui().selection().get();
1003 if (!clip.empty()) {
1005 if (cmd.argument == "paragraph")
1006 insertStringAsParagraphs(cur, clip);
1008 insertStringAsLines(cur, clip);
1013 case LFUN_QUOTE_INSERT: {
1014 lyx::cap::replaceSelection(cur);
1015 Paragraph & par = cur.paragraph();
1016 lyx::pos_type pos = cur.pos();
1020 else if (cur.prevInset() && cur.prevInset()->isSpace())
1023 c = par.getChar(pos - 1);
1025 LyXLayout_ptr const & style = par.layout();
1027 BufferParams const & bufparams = bv->buffer()->params();
1028 if (!style->pass_thru
1029 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1030 string arg = cmd.argument;
1031 if (arg == "single")
1032 cur.insert(new InsetQuotes(c,
1033 bufparams.quotes_language,
1034 InsetQuotes::SingleQ));
1036 cur.insert(new InsetQuotes(c,
1037 bufparams.quotes_language,
1038 InsetQuotes::DoubleQ));
1042 bv->owner()->dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1046 case LFUN_DATE_INSERT:
1047 if (cmd.argument.empty())
1048 bv->owner()->dispatch(FuncRequest(LFUN_SELF_INSERT,
1049 lyx::formatted_time(lyx::current_time())));
1051 bv->owner()->dispatch(FuncRequest(LFUN_SELF_INSERT,
1052 lyx::formatted_time(lyx::current_time(), cmd.argument)));
1055 case LFUN_MOUSE_TRIPLE:
1056 if (cmd.button() == mouse_button::button1) {
1062 bv->owner()->gui().selection().haveSelection(cur.selection());
1066 case LFUN_MOUSE_DOUBLE:
1067 if (cmd.button() == mouse_button::button1) {
1068 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1070 bv->owner()->gui().selection().haveSelection(cur.selection());
1074 // Single-click on work area
1075 case LFUN_MOUSE_PRESS: {
1076 // Right click on a footnote flag opens float menu
1077 if (cmd.button() == mouse_button::button3)
1078 cur.clearSelection();
1080 // Middle button press pastes if we have a selection
1081 // We do this here as if the selection was inside an inset
1082 // it could get cleared on the unlocking of the inset so
1083 // we have to check this first
1084 bool paste_internally = false;
1085 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1086 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1087 paste_internally = true;
1090 bv->mouseSetCursor(cur);
1092 // Insert primary selection with middle mouse
1093 // if there is a local selection in the current buffer,
1095 if (cmd.button() == mouse_button::button2) {
1096 if (paste_internally)
1097 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1099 bv->owner()->dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1105 case LFUN_MOUSE_MOTION: {
1106 // Only use motion with button 1
1107 //if (cmd.button() != mouse_button::button1)
1110 // ignore motions deeper nested than the real anchor
1111 LCursor & bvcur = cur.bv().cursor();
1112 if (bvcur.anchor_.hasPart(cur)) {
1113 CursorSlice old = bvcur.top();
1115 int const wh = bv->workHeight();
1116 int const y = std::max(0, std::min(wh - 1, cmd.y));
1118 setCursorFromCoordinates(cur, cmd.x, y);
1119 cur.x_target() = cmd.x;
1124 // This is to allow jumping over large insets
1125 if (cur.top() == old) {
1132 if (cur.top() == old)
1135 // don't set anchor_
1136 bvcur.setCursor(cur);
1137 bvcur.selection() = true;
1138 //lyxerr << "MOTION: " << bv->cursor() << endl;
1146 case LFUN_MOUSE_RELEASE: {
1147 if (cmd.button() == mouse_button::button2)
1151 if (cmd.button() == mouse_button::button1)
1152 bv->owner()->gui().selection().haveSelection(cur.selection());
1155 bv->owner()->updateMenubar();
1156 bv->owner()->updateToolbars();
1160 case LFUN_SELF_INSERT: {
1161 if (cmd.argument.empty())
1164 // Automatically delete the currently selected
1165 // text and replace it with what is being
1166 // typed in now. Depends on lyxrc settings
1167 // "auto_region_delete", which defaults to
1170 if (lyxrc.auto_region_delete) {
1171 if (cur.selection())
1172 cutSelection(cur, false, false);
1173 bv->owner()->gui().selection().haveSelection(false);
1176 cur.clearSelection();
1177 LyXFont const old_font = real_current_font;
1179 string::const_iterator cit = cmd.argument.begin();
1180 string::const_iterator end = cmd.argument.end();
1181 for (; cit != end; ++cit)
1182 bv->owner()->getIntl().getTransManager().
1183 translateAndInsert(*cit, this);
1186 moveCursor(cur, false);
1190 case LFUN_URL_INSERT: {
1191 InsetCommandParams p("url");
1192 string const data = InsetCommandMailer::params2string("url", p);
1193 bv->owner()->getDialogs().show("url", data, 0);
1197 case LFUN_HTML_INSERT: {
1198 InsetCommandParams p("htmlurl");
1199 string const data = InsetCommandMailer::params2string("url", p);
1200 bv->owner()->getDialogs().show("url", data, 0);
1204 case LFUN_LABEL_INSERT: {
1205 // Try to generate a valid label
1206 string const contents = cmd.argument.empty() ?
1207 cur.getPossibleLabel() : cmd.argument;
1209 InsetCommandParams p("label", contents);
1210 string const data = InsetCommandMailer::params2string("label", p);
1212 if (cmd.argument.empty()) {
1213 bv->owner()->getDialogs().show("label", data, 0);
1215 FuncRequest fr(LFUN_INSET_INSERT, data);
1223 case LFUN_LIST_INSERT:
1224 case LFUN_THEOREM_INSERT:
1225 case LFUN_CAPTION_INSERT:
1227 case LFUN_NOTE_INSERT:
1228 case LFUN_CHARSTYLE_INSERT:
1229 case LFUN_BOX_INSERT:
1230 case LFUN_BRANCH_INSERT:
1231 case LFUN_BIBITEM_INSERT:
1232 case LFUN_ERT_INSERT:
1233 case LFUN_FOOTNOTE_INSERT:
1234 case LFUN_MARGINALNOTE_INSERT:
1235 case LFUN_OPTIONAL_INSERT:
1236 case LFUN_ENVIRONMENT_INSERT:
1237 // Open the inset, and move the current selection
1239 doInsertInset(cur, this, cmd, true, true);
1243 case LFUN_TABULAR_INSERT:
1244 // if there were no arguments, just open the dialog
1245 if (doInsertInset(cur, this, cmd, false, true))
1248 bv->owner()->getDialogs().show("tabularcreate");
1252 case LFUN_FLOAT_INSERT:
1253 case LFUN_FLOAT_WIDE_INSERT:
1254 case LFUN_WRAP_INSERT:
1255 doInsertInset(cur, this, cmd, true, true);
1257 // FIXME: the "Caption" name should not be hardcoded,
1258 // but given by the float definition.
1259 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1262 case LFUN_INDEX_INSERT: {
1263 InsetBase * inset = createInset(&cur.bv(), cmd);
1268 cur.clearSelection();
1269 insertInset(cur, inset);
1270 inset->edit(cur, true);
1275 case LFUN_INDEX_PRINT:
1276 case LFUN_TOC_INSERT:
1277 case LFUN_HFILL_INSERT:
1278 case LFUN_LINE_INSERT:
1279 case LFUN_PAGEBREAK_INSERT:
1281 doInsertInset(cur, this, cmd, false, false);
1285 case LFUN_DEPTH_DECREMENT:
1286 changeDepth(cur, DEC_DEPTH);
1289 case LFUN_DEPTH_INCREMENT:
1290 changeDepth(cur, INC_DEPTH);
1293 case LFUN_MATH_DISPLAY:
1294 mathDispatch(cur, cmd, true);
1297 case LFUN_MATH_IMPORT_SELECTION:
1298 case LFUN_MATH_MODE:
1299 if (cmd.argument == "on")
1300 // don't pass "on" as argument
1301 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1303 mathDispatch(cur, cmd, false);
1306 case LFUN_MATH_MACRO:
1307 if (cmd.argument.empty())
1308 cur.errorMessage(N_("Missing argument"));
1310 string s = cmd.argument;
1311 string const s1 = token(s, ' ', 1);
1312 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1313 string const s2 = token(s, ' ', 2);
1314 string const type = s2.empty() ? "newcommand" : s2;
1315 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1316 //cur.nextInset()->edit(cur, true);
1320 // passthrough hat and underscore outside mathed:
1321 case LFUN_MATH_SUBSCRIPT:
1322 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1324 case LFUN_MATH_SUPERSCRIPT:
1325 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1328 case LFUN_MATH_INSERT:
1329 case LFUN_MATH_MATRIX:
1330 case LFUN_MATH_DELIM:
1331 case LFUN_MATH_BIGDELIM: {
1332 cur.insert(new MathHullInset("simple"));
1333 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1338 case LFUN_FONT_EMPH: {
1339 LyXFont font(LyXFont::ALL_IGNORE);
1340 font.setEmph(LyXFont::TOGGLE);
1341 toggleAndShow(cur, this, font);
1345 case LFUN_FONT_BOLD: {
1346 LyXFont font(LyXFont::ALL_IGNORE);
1347 font.setSeries(LyXFont::BOLD_SERIES);
1348 toggleAndShow(cur, this, font);
1352 case LFUN_FONT_NOUN: {
1353 LyXFont font(LyXFont::ALL_IGNORE);
1354 font.setNoun(LyXFont::TOGGLE);
1355 toggleAndShow(cur, this, font);
1359 case LFUN_FONT_CODE: {
1360 LyXFont font(LyXFont::ALL_IGNORE);
1361 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1362 toggleAndShow(cur, this, font);
1366 case LFUN_FONT_SANS: {
1367 LyXFont font(LyXFont::ALL_IGNORE);
1368 font.setFamily(LyXFont::SANS_FAMILY);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_ROMAN: {
1374 LyXFont font(LyXFont::ALL_IGNORE);
1375 font.setFamily(LyXFont::ROMAN_FAMILY);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_FONT_DEFAULT: {
1381 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_UNDERLINE: {
1387 LyXFont font(LyXFont::ALL_IGNORE);
1388 font.setUnderbar(LyXFont::TOGGLE);
1389 toggleAndShow(cur, this, font);
1393 case LFUN_FONT_SIZE: {
1394 LyXFont font(LyXFont::ALL_IGNORE);
1395 font.setLyXSize(cmd.argument);
1396 toggleAndShow(cur, this, font);
1400 case LFUN_LANGUAGE: {
1401 Language const * lang = languages.getLanguage(cmd.argument);
1404 LyXFont font(LyXFont::ALL_IGNORE);
1405 font.setLanguage(lang);
1406 toggleAndShow(cur, this, font);
1411 case LFUN_FONT_FREE_APPLY:
1412 toggleAndShow(cur, this, freefont, toggleall);
1413 cur.message(_("Character set"));
1416 // Set the freefont using the contents of \param data dispatched from
1417 // the frontends and apply it at the current cursor location.
1418 case LFUN_FONT_FREE_UPDATE: {
1421 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1424 toggleAndShow(cur, this, freefont, toggleall);
1425 cur.message(_("Character set"));
1430 case LFUN_FINISHED_LEFT:
1431 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1434 case LFUN_FINISHED_RIGHT:
1435 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1439 case LFUN_FINISHED_UP:
1440 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1444 case LFUN_FINISHED_DOWN:
1445 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1449 case LFUN_LAYOUT_PARAGRAPH: {
1451 params2string(cur.paragraph(), data);
1452 data = "show\n" + data;
1453 bv->owner()->getDialogs().show("paragraph", data);
1457 case LFUN_PARAGRAPH_UPDATE: {
1458 if (!bv->owner()->getDialogs().visible("paragraph"))
1461 params2string(cur.paragraph(), data);
1463 // Will the paragraph accept changes from the dialog?
1464 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1466 data = "update " + convert<string>(accept) + '\n' + data;
1467 bv->owner()->getDialogs().update("paragraph", data);
1471 case LFUN_ACCENT_UMLAUT:
1472 case LFUN_ACCENT_CIRCUMFLEX:
1473 case LFUN_ACCENT_GRAVE:
1474 case LFUN_ACCENT_ACUTE:
1475 case LFUN_ACCENT_TILDE:
1476 case LFUN_ACCENT_CEDILLA:
1477 case LFUN_ACCENT_MACRON:
1478 case LFUN_ACCENT_DOT:
1479 case LFUN_ACCENT_UNDERDOT:
1480 case LFUN_ACCENT_UNDERBAR:
1481 case LFUN_ACCENT_CARON:
1482 case LFUN_ACCENT_SPECIAL_CARON:
1483 case LFUN_ACCENT_BREVE:
1484 case LFUN_ACCENT_TIE:
1485 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1486 case LFUN_ACCENT_CIRCLE:
1487 case LFUN_ACCENT_OGONEK:
1488 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1489 if (!cmd.argument.empty())
1490 bv->owner()->getIntl().getTransManager()
1491 .translateAndInsert(cmd.argument[0], this);
1494 case LFUN_FLOAT_LIST: {
1495 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1496 if (tclass.floats().typeExist(cmd.argument)) {
1497 // not quite sure if we want this...
1499 cur.clearSelection();
1500 breakParagraph(cur);
1502 if (cur.lastpos() != 0) {
1504 breakParagraph(cur);
1507 setLayout(cur, tclass.defaultLayoutName());
1508 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1509 insertInset(cur, new InsetFloatList(cmd.argument));
1512 lyxerr << "Non-existent float type: "
1513 << cmd.argument << endl;
1518 case LFUN_CHANGE_ACCEPT: {
1523 case LFUN_CHANGE_REJECT: {
1528 case LFUN_THESAURUS_ENTRY: {
1529 string arg = cmd.argument;
1531 arg = cur.selectionAsString(false);
1533 if (arg.size() > 100 || arg.empty()) {
1534 // Get word or selection
1535 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1536 arg = cur.selectionAsString(false);
1539 bv->owner()->getDialogs().show("thesaurus", arg);
1543 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1544 // Given data, an encoding of the ParagraphParameters
1545 // generated in the Paragraph dialog, this function sets
1546 // the current paragraph appropriately.
1547 istringstream is(cmd.argument);
1550 ParagraphParameters params;
1555 params.labelWidthString(),
1557 cur.message(_("Paragraph layout set"));
1561 case LFUN_INSET_DIALOG_SHOW: {
1562 InsetBase * inset = cur.nextInset();
1564 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1565 inset->dispatch(cur, fr);
1571 if (cur.selection()) {
1572 cur.selection() = false;
1575 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1580 lyxerr[Debug::ACTION]
1581 << BOOST_CURRENT_FUNCTION
1582 << ": Command " << cmd
1583 << " not DISPATCHED by LyXText" << endl;
1588 if (singleParUpdate)
1589 // Inserting characters does not change par height
1590 if (cur.bottom().paragraph().dim().height()
1591 == olddim.height()) {
1592 // if so, update _only_ this paragraph
1593 cur.bv().update(Update::SinglePar |
1595 Update::MultiParSel);
1601 && &oldTopSlice.inset() == &cur.inset()
1602 && oldTopSlice.idx() == cur.idx()
1604 && !cur.selection())
1611 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1612 FuncStatus & flag) const
1614 BOOST_ASSERT(cur.text() == this);
1616 LyXFont const & font = real_current_font;
1618 InsetBase::Code code = InsetBase::NO_CODE;
1620 switch (cmd.action) {
1622 case LFUN_DEPTH_DECREMENT:
1623 enable = changeDepthAllowed(cur, DEC_DEPTH);
1626 case LFUN_DEPTH_INCREMENT:
1627 enable = changeDepthAllowed(cur, INC_DEPTH);
1631 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1634 case LFUN_BIBITEM_INSERT:
1635 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1638 case LFUN_DIALOG_SHOW_NEW_INSET:
1639 if (cmd.argument == "bibitem")
1640 code = InsetBase::BIBITEM_CODE;
1641 else if (cmd.argument == "bibtex")
1642 code = InsetBase::BIBTEX_CODE;
1643 else if (cmd.argument == "box")
1644 code = InsetBase::BOX_CODE;
1645 else if (cmd.argument == "branch")
1646 code = InsetBase::BRANCH_CODE;
1647 else if (cmd.argument == "citation")
1648 code = InsetBase::CITE_CODE;
1649 else if (cmd.argument == "ert")
1650 code = InsetBase::ERT_CODE;
1651 else if (cmd.argument == "external")
1652 code = InsetBase::EXTERNAL_CODE;
1653 else if (cmd.argument == "float")
1654 code = InsetBase::FLOAT_CODE;
1655 else if (cmd.argument == "graphics")
1656 code = InsetBase::GRAPHICS_CODE;
1657 else if (cmd.argument == "include")
1658 code = InsetBase::INCLUDE_CODE;
1659 else if (cmd.argument == "index")
1660 code = InsetBase::INDEX_CODE;
1661 else if (cmd.argument == "label")
1662 code = InsetBase::LABEL_CODE;
1663 else if (cmd.argument == "note")
1664 code = InsetBase::NOTE_CODE;
1665 else if (cmd.argument == "ref")
1666 code = InsetBase::REF_CODE;
1667 else if (cmd.argument == "toc")
1668 code = InsetBase::TOC_CODE;
1669 else if (cmd.argument == "url")
1670 code = InsetBase::URL_CODE;
1671 else if (cmd.argument == "vspace")
1672 code = InsetBase::VSPACE_CODE;
1673 else if (cmd.argument == "wrap")
1674 code = InsetBase::WRAP_CODE;
1677 case LFUN_ERT_INSERT:
1678 code = InsetBase::ERT_CODE;
1680 case LFUN_FOOTNOTE_INSERT:
1681 code = InsetBase::FOOT_CODE;
1683 case LFUN_TABULAR_INSERT:
1684 code = InsetBase::TABULAR_CODE;
1686 case LFUN_MARGINALNOTE_INSERT:
1687 code = InsetBase::MARGIN_CODE;
1689 case LFUN_FLOAT_INSERT:
1690 case LFUN_FLOAT_WIDE_INSERT:
1691 code = InsetBase::FLOAT_CODE;
1693 case LFUN_WRAP_INSERT:
1694 code = InsetBase::WRAP_CODE;
1696 case LFUN_FLOAT_LIST:
1697 code = InsetBase::FLOAT_LIST_CODE;
1700 case LFUN_LIST_INSERT:
1701 code = InsetBase::LIST_CODE;
1703 case LFUN_THEOREM_INSERT:
1704 code = InsetBase::THEOREM_CODE;
1707 case LFUN_CAPTION_INSERT:
1708 code = InsetBase::CAPTION_CODE;
1710 case LFUN_NOTE_INSERT:
1711 code = InsetBase::NOTE_CODE;
1713 case LFUN_CHARSTYLE_INSERT:
1714 code = InsetBase::CHARSTYLE_CODE;
1715 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1718 case LFUN_BOX_INSERT:
1719 code = InsetBase::BOX_CODE;
1721 case LFUN_BRANCH_INSERT:
1722 code = InsetBase::BRANCH_CODE;
1723 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1726 case LFUN_LABEL_INSERT:
1727 code = InsetBase::LABEL_CODE;
1729 case LFUN_OPTIONAL_INSERT:
1730 code = InsetBase::OPTARG_CODE;
1731 enable = numberOfOptArgs(cur.paragraph())
1732 < cur.paragraph().layout()->optionalargs;
1734 case LFUN_ENVIRONMENT_INSERT:
1735 code = InsetBase::BOX_CODE;
1737 case LFUN_INDEX_INSERT:
1738 code = InsetBase::INDEX_CODE;
1740 case LFUN_INDEX_PRINT:
1741 code = InsetBase::INDEX_PRINT_CODE;
1743 case LFUN_TOC_INSERT:
1744 code = InsetBase::TOC_CODE;
1746 case LFUN_HTML_INSERT:
1747 case LFUN_URL_INSERT:
1748 code = InsetBase::URL_CODE;
1750 case LFUN_QUOTE_INSERT:
1751 // always allow this, since we will inset a raw quote
1752 // if an inset is not allowed.
1754 case LFUN_HYPHENATION_POINT_INSERT:
1755 case LFUN_LIGATURE_BREAK_INSERT:
1756 case LFUN_HFILL_INSERT:
1757 case LFUN_MENU_SEPARATOR_INSERT:
1758 case LFUN_DOTS_INSERT:
1759 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1760 code = InsetBase::SPECIALCHAR_CODE;
1762 case LFUN_SPACE_INSERT:
1763 // slight hack: we know this is allowed in math mode
1765 code = InsetBase::SPACE_CODE;
1768 #ifdef WITH_WARNINGS
1769 #warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
1772 case LFUN_INSET_DIALOG_SHOW: {
1773 InsetBase * inset = cur.nextInset();
1776 code = inset->lyxCode();
1777 if (!(code == InsetBase::INCLUDE_CODE
1778 || code == InsetBase::BIBTEX_CODE
1779 || code == InsetBase::FLOAT_LIST_CODE
1780 || code == InsetBase::TOC_CODE))
1787 case LFUN_INSET_MODIFY:
1788 // We need to disable this, because we may get called for a
1790 // InsetTabular::getStatus() -> InsetText::getStatus()
1791 // and we don't handle LFUN_INSET_MODIFY.
1795 case LFUN_FONT_EMPH:
1796 flag.setOnOff(font.emph() == LyXFont::ON);
1799 case LFUN_FONT_NOUN:
1800 flag.setOnOff(font.noun() == LyXFont::ON);
1803 case LFUN_FONT_BOLD:
1804 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1807 case LFUN_FONT_SANS:
1808 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1811 case LFUN_FONT_ROMAN:
1812 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1815 case LFUN_FONT_CODE:
1816 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1821 enable = cur.selection();
1825 enable = lyx::cap::numberOfSelections() > 0;
1828 case LFUN_PARAGRAPH_MOVE_UP: {
1829 enable = cur.pit() > 0 && !cur.selection();
1833 case LFUN_PARAGRAPH_MOVE_DOWN: {
1834 enable = cur.pit() < cur.lastpit() && !cur.selection();
1838 case LFUN_WORD_DELETE_FORWARD:
1839 case LFUN_WORD_DELETE_BACKWARD:
1840 case LFUN_LINE_DELETE:
1841 case LFUN_WORD_FORWARD:
1842 case LFUN_WORD_BACKWARD:
1843 case LFUN_CHAR_FORWARD:
1844 case LFUN_CHAR_FORWARD_SELECT:
1845 case LFUN_CHAR_BACKWARD:
1846 case LFUN_CHAR_BACKWARD_SELECT:
1848 case LFUN_UP_SELECT:
1850 case LFUN_DOWN_SELECT:
1851 case LFUN_PARAGRAPH_UP_SELECT:
1852 case LFUN_PARAGRAPH_DOWN_SELECT:
1853 case LFUN_SCREEN_UP_SELECT:
1854 case LFUN_SCREEN_DOWN_SELECT:
1855 case LFUN_LINE_BEGIN_SELECT:
1856 case LFUN_LINE_END_SELECT:
1857 case LFUN_WORD_FORWARD_SELECT:
1858 case LFUN_WORD_BACKWARD_SELECT:
1859 case LFUN_WORD_SELECT:
1860 case LFUN_PARAGRAPH_UP:
1861 case LFUN_PARAGRAPH_DOWN:
1862 case LFUN_SCREEN_UP:
1863 case LFUN_SCREEN_DOWN:
1864 case LFUN_LINE_BEGIN:
1866 case LFUN_BREAK_LINE:
1867 case LFUN_CHAR_DELETE_FORWARD:
1868 case LFUN_DELETE_FORWARD_SKIP:
1869 case LFUN_CHAR_DELETE_BACKWARD:
1870 case LFUN_DELETE_BACKWARD_SKIP:
1871 case LFUN_BREAK_PARAGRAPH:
1872 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1873 case LFUN_BREAK_PARAGRAPH_SKIP:
1874 case LFUN_PARAGRAPH_SPACING:
1875 case LFUN_INSET_INSERT:
1876 case LFUN_NEXT_INSET_TOGGLE:
1877 case LFUN_WORD_UPCASE:
1878 case LFUN_WORD_LOWCASE:
1879 case LFUN_WORD_CAPITALIZE:
1880 case LFUN_CHARS_TRANSPOSE:
1881 case LFUN_SERVER_GET_XY:
1882 case LFUN_SERVER_SET_XY:
1883 case LFUN_SERVER_GET_FONT:
1884 case LFUN_SERVER_GET_LAYOUT:
1886 case LFUN_CLIPBOARD_PASTE:
1887 case LFUN_PRIMARY_SELECTION_PASTE:
1888 case LFUN_DATE_INSERT:
1889 case LFUN_SELF_INSERT:
1890 case LFUN_LINE_INSERT:
1891 case LFUN_PAGEBREAK_INSERT:
1892 case LFUN_MATH_DISPLAY:
1893 case LFUN_MATH_IMPORT_SELECTION:
1894 case LFUN_MATH_MODE:
1895 case LFUN_MATH_MACRO:
1896 case LFUN_MATH_INSERT:
1897 case LFUN_MATH_MATRIX:
1898 case LFUN_MATH_DELIM:
1899 case LFUN_MATH_BIGDELIM:
1900 case LFUN_MATH_SUBSCRIPT:
1901 case LFUN_MATH_SUPERSCRIPT:
1902 case LFUN_FONT_DEFAULT:
1903 case LFUN_FONT_UNDERLINE:
1904 case LFUN_FONT_SIZE:
1906 case LFUN_FONT_FREE_APPLY:
1907 case LFUN_FONT_FREE_UPDATE:
1908 case LFUN_LAYOUT_PARAGRAPH:
1909 case LFUN_PARAGRAPH_UPDATE:
1910 case LFUN_ACCENT_UMLAUT:
1911 case LFUN_ACCENT_CIRCUMFLEX:
1912 case LFUN_ACCENT_GRAVE:
1913 case LFUN_ACCENT_ACUTE:
1914 case LFUN_ACCENT_TILDE:
1915 case LFUN_ACCENT_CEDILLA:
1916 case LFUN_ACCENT_MACRON:
1917 case LFUN_ACCENT_DOT:
1918 case LFUN_ACCENT_UNDERDOT:
1919 case LFUN_ACCENT_UNDERBAR:
1920 case LFUN_ACCENT_CARON:
1921 case LFUN_ACCENT_SPECIAL_CARON:
1922 case LFUN_ACCENT_BREVE:
1923 case LFUN_ACCENT_TIE:
1924 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1925 case LFUN_ACCENT_CIRCLE:
1926 case LFUN_ACCENT_OGONEK:
1927 case LFUN_CHANGE_ACCEPT:
1928 case LFUN_CHANGE_REJECT:
1929 case LFUN_THESAURUS_ENTRY:
1930 case LFUN_PARAGRAPH_PARAMS_APPLY:
1932 case LFUN_BUFFER_END:
1933 case LFUN_BUFFER_BEGIN:
1934 case LFUN_BUFFER_BEGIN_SELECT:
1935 case LFUN_BUFFER_END_SELECT:
1936 // these are handled in our dispatch()
1944 if (code != InsetBase::NO_CODE
1945 && (cur.empty() || !cur.inset().insetAllowed(code)))
1948 flag.enabled(enable);