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"
32 #include "errorlist.h"
34 #include "funcrequest.h"
38 #include "LyXAction.h"
43 #include "paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
48 #include "pariterator.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/Selection.h"
53 #include "insets/insetcommand.h"
54 #include "insets/insetfloatlist.h"
55 #include "insets/insetnewline.h"
56 #include "insets/insetquotes.h"
57 #include "insets/insetspecialchar.h"
58 #include "insets/insettext.h"
60 #include "support/lstrings.h"
61 #include "support/lyxlib.h"
62 #include "support/convert.h"
63 #include "support/lyxtime.h"
65 #include "mathed/InsetMathHull.h"
66 #include "mathed/MathMacroTemplate.h"
68 #include <boost/current_function.hpp>
76 using cap::copySelection;
77 using cap::cutSelection;
78 using cap::pasteSelection;
79 using cap::replaceSelection;
81 using support::isStrUnsignedInt;
86 using std::istringstream;
87 using std::ostringstream;
90 extern string current_layout;
96 LyXFont freefont(LyXFont::ALL_IGNORE);
97 bool toggleall = false;
100 void toggleAndShow(LCursor & cur, LyXText * text,
101 LyXFont const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.number() != LyXFont::IGNORE) {
107 Paragraph & par = cur.paragraph();
108 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
109 if (cur.boundary() !=
110 text->bidi.isBoundary(cur.buffer(), par,
112 text->real_current_font))
113 text->setCursor(cur, cur.pit(), cur.pos(),
114 false, !cur.boundary());
119 void moveCursor(LCursor & cur, bool selecting)
121 if (selecting || cur.mark())
123 if (!cur.selection())
124 theSelection().haveSelection(false);
125 cur.bv().switchKeyMap();
129 void finishChange(LCursor & cur, bool selecting)
132 moveCursor(cur, selecting);
136 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
139 docstring sel = cur.selectionAsString(false);
140 //lyxerr << "selection is: '" << sel << "'" << endl;
142 // It may happen that sel is empty but there is a selection
143 replaceSelection(cur);
146 const int old_pos = cur.pos();
147 cur.insert(new InsetMathHull(hullSimple));
148 BOOST_ASSERT(old_pos == cur.pos());
149 cur.nextInset()->edit(cur, true);
150 // don't do that also for LFUN_MATH_MODE
151 // unless you want end up with always changing
152 // to mathrm when opening an inlined inset --
153 // I really hate "LyXfunc overloading"...
155 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
156 // Avoid an unnecessary undo step if cmd.argument
158 if (!cmd.argument().empty())
159 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
162 // create a macro if we see "\\newcommand"
163 // somewhere, and an ordinary formula
165 if (sel.find(from_ascii("\\newcommand")) == string::npos
166 && sel.find(from_ascii("\\def")) == string::npos)
168 InsetMathHull * formula = new InsetMathHull;
169 istringstream is(to_utf8(sel));
172 formula->read(cur.buffer(), lex);
173 if (formula->getType() == hullNone)
174 // Don't create pseudo formulas if
175 // delimiters are left out
176 formula->mutate(hullSimple);
179 cur.insert(new MathMacroTemplate(sel));
182 cur.message(from_utf8(N_("Math editor mode")));
191 string const freefont2string()
194 if (font2string(freefont, toggleall, data))
201 void LyXText::cursorPrevious(LCursor & cur)
203 pos_type cpos = cur.pos();
204 pit_type cpar = cur.pit();
206 int x = cur.x_target();
208 // FIXME: there would maybe a need for this 'updated' boolean in the future...
209 bool updated = setCursorFromCoordinates(cur, x, 0);
213 updated |= cursorUp(cur);
215 if (cpar == cur.pit() && cpos == cur.pos()) {
216 // we have a row which is taller than the workarea. The
217 // simplest solution is to move to the previous row instead.
221 updated |= cursorUp(cur);
225 cur.updateFlags(Update::Force | Update::FitCursor);
229 void LyXText::cursorNext(LCursor & cur)
231 pos_type cpos = cur.pos();
232 pit_type cpar = cur.pit();
234 int x = cur.x_target();
235 // FIXME: there would maybe a need for this 'updated' boolean in the future...
236 bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
238 updated |= cur.down();
240 updated |= cursorDown(cur);
242 if (cpar == cur.pit() && cpos == cur.pos()) {
243 // we have a row which is taller than the workarea. The
244 // simplest solution is to move to the next row instead.
246 updated |= cur.down();
248 updated |= cursorDown(cur);
252 cur.updateFlags(Update::Force | Update::FitCursor);
258 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
260 cap::replaceSelection(cur);
261 cur.insert(new InsetSpecialChar(kind));
266 bool doInsertInset(LCursor & cur, LyXText * text,
267 FuncRequest const & cmd, bool edit, bool pastesel)
269 InsetBase * inset = createInset(&cur.bv(), cmd);
275 if (cur.selection()) {
276 lyx::dispatch(FuncRequest(LFUN_CUT));
279 text->insertInset(cur, inset);
282 inset->edit(cur, true);
284 if (gotsel && pastesel) {
285 lyx::dispatch(FuncRequest(LFUN_PASTE));
286 // reset first par to default
287 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
288 LyXLayout_ptr const layout =
289 cur.buffer().params().getLyXTextClass().defaultLayout();
290 cur.text()->paragraphs().begin()->layout(layout);
300 void LyXText::number(LCursor & cur)
302 LyXFont font(LyXFont::ALL_IGNORE);
303 font.setNumber(LyXFont::TOGGLE);
304 toggleAndShow(cur, this, font);
308 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
310 return par.isRightToLeftPar(buffer.params());
314 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
316 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
318 // FIXME: We use the update flag to indicates wether a singlePar or a
319 // full screen update is needed. We reset it here but shall we restore it
323 BOOST_ASSERT(cur.text() == this);
324 BufferView * bv = &cur.bv();
325 CursorSlice oldTopSlice = cur.top();
326 bool oldBoundary = cur.boundary();
327 bool sel = cur.selection();
328 // Signals that, even if needsUpdate == false, an update of the
329 // cursor paragraph is required
330 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
331 LyXAction::SingleParUpdate);
332 // Signals that a full-screen update is required
333 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
334 LyXAction::NoUpdate) || singleParUpdate);
335 // Remember the old paragraph metric (_outer_ paragraph!)
336 Dimension olddim = cur.bottom().paragraph().dim();
338 switch (cmd.action) {
340 case LFUN_PARAGRAPH_MOVE_DOWN: {
341 pit_type const pit = cur.pit();
342 recUndo(cur, pit, pit + 1);
344 std::swap(pars_[pit], pars_[pit + 1]);
346 ParIterator begin(cur);
348 ParIterator end = boost::next(ParIterator(cur));
349 updateLabels(cur.buffer(), begin, end);
355 case LFUN_PARAGRAPH_MOVE_UP: {
356 pit_type const pit = cur.pit();
357 recUndo(cur, pit - 1, pit);
359 std::swap(pars_[pit], pars_[pit - 1]);
361 ParIterator end = boost::next(ParIterator(cur));
363 ParIterator begin(cur);
364 updateLabels(cur.buffer(), begin, end);
370 case LFUN_APPENDIX: {
371 Paragraph & par = cur.paragraph();
372 bool start = !par.params().startOfAppendix();
375 #warning The code below only makes sense at top level.
376 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
378 // ensure that we have only one start_of_appendix in this document
379 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
380 if (pars_[tmp].params().startOfAppendix()) {
382 pars_[tmp].params().startOfAppendix(false);
388 par.params().startOfAppendix(start);
390 // we can set the refreshing parameters now
391 updateLabels(cur.buffer());
395 case LFUN_WORD_DELETE_FORWARD:
396 cur.clearSelection();
397 deleteWordForward(cur);
398 finishChange(cur, false);
401 case LFUN_WORD_DELETE_BACKWARD:
402 cur.clearSelection();
403 deleteWordBackward(cur);
404 finishChange(cur, false);
407 case LFUN_LINE_DELETE:
408 cur.clearSelection();
409 deleteLineForward(cur);
410 finishChange(cur, false);
413 case LFUN_BUFFER_BEGIN:
414 case LFUN_BUFFER_BEGIN_SELECT:
415 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
416 if (cur.depth() == 1) {
417 needsUpdate |= cursorTop(cur);
423 case LFUN_BUFFER_END:
424 case LFUN_BUFFER_END_SELECT:
425 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
426 if (cur.depth() == 1) {
427 needsUpdate |= cursorBottom(cur);
433 case LFUN_CHAR_FORWARD:
434 case LFUN_CHAR_FORWARD_SELECT:
435 //lyxerr << BOOST_CURRENT_FUNCTION
436 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
437 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
438 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
439 needsUpdate |= cursorLeft(cur);
441 needsUpdate |= cursorRight(cur);
443 if (!needsUpdate && oldTopSlice == cur.top()
444 && cur.boundary() == oldBoundary) {
446 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
450 case LFUN_CHAR_BACKWARD:
451 case LFUN_CHAR_BACKWARD_SELECT:
452 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
453 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
454 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
455 needsUpdate |= cursorRight(cur);
457 needsUpdate |= cursorLeft(cur);
459 if (!needsUpdate && oldTopSlice == cur.top()
460 && cur.boundary() == oldBoundary) {
462 cmd = FuncRequest(LFUN_FINISHED_LEFT);
468 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
471 needsUpdate |= cursorUp(cur);
473 if (!needsUpdate && oldTopSlice == cur.top()
474 && cur.boundary() == oldBoundary) {
476 cmd = FuncRequest(LFUN_FINISHED_UP);
481 case LFUN_DOWN_SELECT:
482 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
484 needsUpdate |= cursorDown(cur);
486 if (!needsUpdate && oldTopSlice == cur.top() &&
487 cur.boundary() == oldBoundary)
490 cmd = FuncRequest(LFUN_FINISHED_DOWN);
494 case LFUN_PARAGRAPH_UP:
495 case LFUN_PARAGRAPH_UP_SELECT:
496 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
497 needsUpdate |= cursorUpParagraph(cur);
500 case LFUN_PARAGRAPH_DOWN:
501 case LFUN_PARAGRAPH_DOWN_SELECT:
502 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
503 needsUpdate |= cursorDownParagraph(cur);
507 case LFUN_SCREEN_UP_SELECT:
508 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
509 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
511 cmd = FuncRequest(LFUN_FINISHED_UP);
517 case LFUN_SCREEN_DOWN:
518 case LFUN_SCREEN_DOWN_SELECT:
519 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
520 if (cur.pit() == cur.lastpit()
521 && cur.textRow().endpos() == cur.lastpos()) {
523 cmd = FuncRequest(LFUN_FINISHED_DOWN);
529 case LFUN_LINE_BEGIN:
530 case LFUN_LINE_BEGIN_SELECT:
531 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
532 needsUpdate |= cursorHome(cur);
536 case LFUN_LINE_END_SELECT:
537 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
538 needsUpdate |= cursorEnd(cur);
541 case LFUN_WORD_FORWARD:
542 case LFUN_WORD_FORWARD_SELECT:
543 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
544 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
545 needsUpdate |= cursorLeftOneWord(cur);
547 needsUpdate |= cursorRightOneWord(cur);
550 case LFUN_WORD_BACKWARD:
551 case LFUN_WORD_BACKWARD_SELECT:
552 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
553 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
554 needsUpdate |= cursorRightOneWord(cur);
556 needsUpdate |= cursorLeftOneWord(cur);
559 case LFUN_WORD_SELECT: {
560 selectWord(cur, WHOLE_WORD);
561 finishChange(cur, true);
565 case LFUN_BREAK_LINE: {
566 // Not allowed by LaTeX (labels or empty par)
567 if (cur.pos() > cur.paragraph().beginOfBody()) {
568 cap::replaceSelection(cur);
569 cur.insert(new InsetNewline);
571 moveCursor(cur, false);
576 case LFUN_CHAR_DELETE_FORWARD:
577 if (!cur.selection()) {
578 if (cur.pos() == cur.paragraph().size())
579 // Par boundary, force full-screen update
580 singleParUpdate = false;
581 needsUpdate |= erase(cur);
583 // It is possible to make it a lot faster still
584 // just comment out the line below...
586 cutSelection(cur, true, false);
587 singleParUpdate = false;
589 moveCursor(cur, false);
592 case LFUN_DELETE_FORWARD_SKIP:
593 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
594 if (!cur.selection()) {
595 if (cur.pos() == cur.lastpos()) {
602 cutSelection(cur, true, false);
607 case LFUN_CHAR_DELETE_BACKWARD:
608 if (!cur.selection()) {
609 if (bv->getIntl().getTransManager().backspace()) {
610 // Par boundary, full-screen update
612 singleParUpdate = false;
613 needsUpdate |= backspace(cur);
615 // It is possible to make it a lot faster still
616 // just comment out the line below...
619 cutSelection(cur, true, false);
620 singleParUpdate = false;
625 case LFUN_DELETE_BACKWARD_SKIP:
626 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
627 if (!cur.selection()) {
631 //CursorSlice cur = cursor();
635 cutSelection(cur, true, false);
639 case LFUN_BREAK_PARAGRAPH:
640 cap::replaceSelection(cur);
641 breakParagraph(cur, 0);
646 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
647 cap::replaceSelection(cur);
648 breakParagraph(cur, 1);
653 case LFUN_BREAK_PARAGRAPH_SKIP: {
654 // When at the beginning of a paragraph, remove
655 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
656 cap::replaceSelection(cur);
658 cur.paragraph().params().labelWidthString(docstring());
660 breakParagraph(cur, 0);
666 case LFUN_PARAGRAPH_SPACING: {
667 Paragraph & par = cur.paragraph();
668 Spacing::Space cur_spacing = par.params().spacing().getSpace();
669 string cur_value = "1.0";
670 if (cur_spacing == Spacing::Other)
671 cur_value = par.params().spacing().getValueAsString();
673 istringstream is(to_utf8(cmd.argument()));
676 Spacing::Space new_spacing = cur_spacing;
677 string new_value = cur_value;
679 lyxerr << "Missing argument to `paragraph-spacing'"
681 } else if (tmp == "single") {
682 new_spacing = Spacing::Single;
683 } else if (tmp == "onehalf") {
684 new_spacing = Spacing::Onehalf;
685 } else if (tmp == "double") {
686 new_spacing = Spacing::Double;
687 } else if (tmp == "other") {
688 new_spacing = Spacing::Other;
689 string tmpval = "0.0";
691 lyxerr << "new_value = " << tmpval << endl;
694 } else if (tmp == "default") {
695 new_spacing = Spacing::Default;
697 lyxerr << to_utf8(_("Unknown spacing argument: "))
698 << to_utf8(cmd.argument()) << endl;
700 if (cur_spacing != new_spacing || cur_value != new_value)
701 par.params().spacing(Spacing(new_spacing, new_value));
705 case LFUN_INSET_INSERT: {
707 InsetBase * inset = createInset(bv, cmd);
709 insertInset(cur, inset);
715 case LFUN_INSET_DISSOLVE:
716 needsUpdate |= dissolveInset(cur);
719 case LFUN_INSET_SETTINGS:
720 cur.inset().showInsetDialog(bv);
723 case LFUN_SPACE_INSERT:
724 if (cur.paragraph().layout()->free_spacing)
725 insertChar(cur, ' ');
727 doInsertInset(cur, this, cmd, false, false);
730 moveCursor(cur, false);
733 case LFUN_HYPHENATION_POINT_INSERT:
734 specialChar(cur, InsetSpecialChar::HYPHENATION);
737 case LFUN_LIGATURE_BREAK_INSERT:
738 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
741 case LFUN_DOTS_INSERT:
742 specialChar(cur, InsetSpecialChar::LDOTS);
745 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
746 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
749 case LFUN_MENU_SEPARATOR_INSERT:
750 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
753 case LFUN_WORD_UPCASE:
754 changeCase(cur, LyXText::text_uppercase);
757 case LFUN_WORD_LOWCASE:
758 changeCase(cur, LyXText::text_lowercase);
761 case LFUN_WORD_CAPITALIZE:
762 changeCase(cur, LyXText::text_capitalization);
765 case LFUN_CHARS_TRANSPOSE:
770 cur.message(_("Paste"));
771 cap::replaceSelection(cur);
772 if (isStrUnsignedInt(to_utf8(cmd.argument())))
773 pasteSelection(cur, bv->buffer()->errorList("Paste"),
774 convert<unsigned int>(to_utf8(cmd.argument())));
776 pasteSelection(cur, bv->buffer()->errorList("Paste"),
778 bv->buffer()->errors("Paste");
779 cur.clearSelection(); // bug 393
785 cutSelection(cur, true, true);
786 cur.message(_("Cut"));
791 cur.message(_("Copy"));
794 case LFUN_SERVER_GET_XY:
795 cur.message(from_utf8(
796 convert<string>(cursorX(cur.buffer(), cur.top(), cur.boundary()))
797 + ' ' + convert<string>(cursorY(cur.top(), cur.boundary()))));
800 case LFUN_SERVER_SET_XY: {
803 istringstream is(to_utf8(cmd.argument()));
806 lyxerr << "SETXY: Could not parse coordinates in '"
807 << to_utf8(cmd.argument()) << std::endl;
809 setCursorFromCoordinates(cur, x, y);
813 case LFUN_SERVER_GET_FONT:
814 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
815 cur.message(from_ascii("E"));
816 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
817 cur.message(from_ascii("N"));
819 cur.message(from_ascii("0"));
822 case LFUN_SERVER_GET_LAYOUT:
823 cur.message(from_utf8(cur.paragraph().layout()->name()));
827 string layout = to_ascii(cmd.argument());
828 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
830 // Derive layout number from given argument (string)
831 // and current buffer's textclass (number)
832 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
834 layout = tclass.defaultLayoutName();
835 bool hasLayout = tclass.hasLayout(layout);
837 // If the entry is obsolete, use the new one instead.
839 string const & obs = tclass[layout]->obsoleted_by();
845 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
846 from_utf8(N_(" not known")));
850 bool change_layout = (current_layout != layout);
852 if (!change_layout && cur.selection() &&
853 cur.selBegin().pit() != cur.selEnd().pit())
855 pit_type spit = cur.selBegin().pit();
856 pit_type epit = cur.selEnd().pit() + 1;
857 while (spit != epit) {
858 if (pars_[spit].layout()->name() != current_layout) {
859 change_layout = true;
867 current_layout = layout;
868 setLayout(cur, layout);
869 // inform the GUI that the layout has changed.
870 bv->layoutChanged(layout);
876 case LFUN_CLIPBOARD_PASTE: {
877 cur.clearSelection();
878 docstring const clip = theClipboard().get();
881 if (cmd.argument() == "paragraph")
882 insertStringAsParagraphs(cur, clip);
884 insertStringAsLines(cur, clip);
889 case LFUN_PRIMARY_SELECTION_PASTE: {
890 cur.clearSelection();
891 docstring const clip = theSelection().get();
894 if (cmd.argument() == "paragraph")
895 insertStringAsParagraphs(cur, clip);
897 insertStringAsLines(cur, clip);
902 case LFUN_UNICODE_INSERT: {
903 if (cmd.argument().empty())
905 docstring hexstring = cmd.argument();
906 if (lyx::support::isHex(hexstring)) {
907 char_type c = lyx::support::hexToInt(hexstring);
908 if (c > 32 && c < 0x10ffff) {
909 lyxerr << "Inserting c: " << c << endl;
910 docstring s = docstring(1, c);
911 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
917 case LFUN_QUOTE_INSERT: {
918 cap::replaceSelection(cur);
919 Paragraph & par = cur.paragraph();
920 pos_type pos = cur.pos();
924 else if (cur.prevInset() && cur.prevInset()->isSpace())
927 c = par.getChar(pos - 1);
929 LyXLayout_ptr const & style = par.layout();
931 BufferParams const & bufparams = bv->buffer()->params();
932 if (!style->pass_thru
933 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
934 string arg = to_utf8(cmd.argument());
936 cur.insert(new InsetQuotes(c,
937 bufparams.quotes_language,
938 InsetQuotes::SingleQ));
940 cur.insert(new InsetQuotes(c,
941 bufparams.quotes_language,
942 InsetQuotes::DoubleQ));
946 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
950 case LFUN_DATE_INSERT:
951 if (cmd.argument().empty())
952 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
953 formatted_time(current_time())));
955 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
956 formatted_time(current_time(), to_utf8(cmd.argument()))));
959 case LFUN_MOUSE_TRIPLE:
960 if (cmd.button() == mouse_button::button1) {
966 theSelection().haveSelection(cur.selection());
970 case LFUN_MOUSE_DOUBLE:
971 if (cmd.button() == mouse_button::button1) {
972 selectWord(cur, WHOLE_WORD_STRICT);
974 theSelection().haveSelection(cur.selection());
978 // Single-click on work area
979 case LFUN_MOUSE_PRESS: {
980 // Right click on a footnote flag opens float menu
981 if (cmd.button() == mouse_button::button3)
982 cur.clearSelection();
984 // Middle button press pastes if we have a selection
985 // We do this here as if the selection was inside an inset
986 // it could get cleared on the unlocking of the inset so
987 // we have to check this first
988 bool paste_internally = false;
989 if (cmd.button() == mouse_button::button2 && cur.selection()) {
990 lyx::dispatch(FuncRequest(LFUN_COPY));
991 paste_internally = true;
994 // we have to update after dePM triggered
995 bool update = bv->mouseSetCursor(cur);
997 // Insert primary selection with middle mouse
998 // if there is a local selection in the current buffer,
1000 if (cmd.button() == mouse_button::button2) {
1001 if (paste_internally)
1002 lyx::dispatch(FuncRequest(LFUN_PASTE));
1004 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1007 if (!update && cmd.button() == mouse_button::button1) {
1008 needsUpdate = false;
1015 case LFUN_MOUSE_MOTION: {
1016 // Only use motion with button 1
1017 //if (cmd.button() != mouse_button::button1)
1020 // ignore motions deeper nested than the real anchor
1021 LCursor & bvcur = cur.bv().cursor();
1022 if (bvcur.anchor_.hasPart(cur)) {
1023 CursorSlice old = bvcur.top();
1025 int const wh = bv->workHeight();
1026 int const y = std::max(0, std::min(wh - 1, cmd.y));
1028 setCursorFromCoordinates(cur, cmd.x, y);
1029 cur.x_target() = cmd.x;
1034 // This is to allow jumping over large insets
1035 if (cur.top() == old) {
1042 if (cur.top() == old)
1045 // don't set anchor_
1046 bvcur.setCursor(cur);
1047 bvcur.selection() = true;
1048 //lyxerr << "MOTION: " << bv->cursor() << endl;
1056 case LFUN_MOUSE_RELEASE: {
1057 if (cmd.button() == mouse_button::button2)
1061 if (cmd.button() == mouse_button::button1) {
1062 if (cur.selection())
1063 theSelection().haveSelection(cur.selection());
1064 needsUpdate = false;
1072 case LFUN_SELF_INSERT: {
1073 if (cmd.argument().empty())
1076 // Automatically delete the currently selected
1077 // text and replace it with what is being
1078 // typed in now. Depends on lyxrc settings
1079 // "auto_region_delete", which defaults to
1082 if (lyxrc.auto_region_delete) {
1083 if (cur.selection())
1084 cutSelection(cur, false, false);
1085 theSelection().haveSelection(false);
1088 cur.clearSelection();
1089 LyXFont const old_font = real_current_font;
1091 docstring::const_iterator cit = cmd.argument().begin();
1092 docstring::const_iterator end = cmd.argument().end();
1093 for (; cit != end; ++cit)
1095 bv->getIntl().getTransManager().
1096 translateAndInsert(*cit, this);
1098 insertChar(bv->cursor(), *cit);
1102 moveCursor(cur, false);
1106 case LFUN_URL_INSERT: {
1107 InsetCommandParams p("url");
1108 string const data = InsetCommandMailer::params2string("url", p);
1109 bv->showInsetDialog("url", data, 0);
1113 case LFUN_HTML_INSERT: {
1114 InsetCommandParams p("htmlurl");
1115 string const data = InsetCommandMailer::params2string("url", p);
1116 bv->showInsetDialog("url", data, 0);
1120 case LFUN_LABEL_INSERT: {
1121 InsetCommandParams p("label");
1122 // Try to generate a valid label
1123 p["name"] = (cmd.argument().empty()) ?
1124 cur.getPossibleLabel() :
1126 string const data = InsetCommandMailer::params2string("label", p);
1128 if (cmd.argument().empty()) {
1129 bv->showInsetDialog("label", data, 0);
1131 FuncRequest fr(LFUN_INSET_INSERT, data);
1139 case LFUN_LIST_INSERT:
1140 case LFUN_THEOREM_INSERT:
1141 case LFUN_CAPTION_INSERT:
1143 case LFUN_NOTE_INSERT:
1144 case LFUN_CHARSTYLE_INSERT:
1145 case LFUN_BOX_INSERT:
1146 case LFUN_BRANCH_INSERT:
1147 case LFUN_BIBITEM_INSERT:
1148 case LFUN_ERT_INSERT:
1149 case LFUN_FOOTNOTE_INSERT:
1150 case LFUN_MARGINALNOTE_INSERT:
1151 case LFUN_OPTIONAL_INSERT:
1152 case LFUN_ENVIRONMENT_INSERT:
1153 // Open the inset, and move the current selection
1155 doInsertInset(cur, this, cmd, true, true);
1159 case LFUN_TABULAR_INSERT:
1160 // if there were no arguments, just open the dialog
1161 if (doInsertInset(cur, this, cmd, false, true))
1164 bv->showDialog("tabularcreate");
1168 case LFUN_FLOAT_INSERT:
1169 case LFUN_FLOAT_WIDE_INSERT:
1170 case LFUN_WRAP_INSERT:
1171 doInsertInset(cur, this, cmd, true, true);
1173 // FIXME: the "Caption" name should not be hardcoded,
1174 // but given by the float definition.
1175 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1178 case LFUN_INDEX_INSERT:
1179 case LFUN_NOMENCL_INSERT: {
1180 InsetBase * inset = createInset(&cur.bv(), cmd);
1185 cur.clearSelection();
1186 insertInset(cur, inset);
1187 inset->edit(cur, true);
1188 // Show the dialog for the nomenclature entry, since the
1189 // description entry still needs to be filled in.
1190 if (cmd.action == LFUN_NOMENCL_INSERT)
1191 InsetCommandMailer("nomenclature",
1192 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1197 case LFUN_INDEX_PRINT:
1198 case LFUN_NOMENCL_PRINT:
1199 case LFUN_TOC_INSERT:
1200 case LFUN_HFILL_INSERT:
1201 case LFUN_LINE_INSERT:
1202 case LFUN_PAGEBREAK_INSERT:
1203 case LFUN_CLEARPAGE_INSERT:
1204 case LFUN_CLEARDOUBLEPAGE_INSERT:
1206 doInsertInset(cur, this, cmd, false, false);
1210 case LFUN_DEPTH_DECREMENT:
1211 changeDepth(cur, DEC_DEPTH);
1214 case LFUN_DEPTH_INCREMENT:
1215 changeDepth(cur, INC_DEPTH);
1218 case LFUN_MATH_DISPLAY:
1219 mathDispatch(cur, cmd, true);
1222 case LFUN_MATH_IMPORT_SELECTION:
1223 case LFUN_MATH_MODE:
1224 if (cmd.argument() == "on")
1225 // don't pass "on" as argument
1226 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1228 mathDispatch(cur, cmd, false);
1231 case LFUN_MATH_MACRO:
1232 if (cmd.argument().empty())
1233 cur.errorMessage(from_utf8(N_("Missing argument")));
1235 string s = to_utf8(cmd.argument());
1236 string const s1 = token(s, ' ', 1);
1237 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1238 string const s2 = token(s, ' ', 2);
1239 string const type = s2.empty() ? "newcommand" : s2;
1240 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1241 //cur.nextInset()->edit(cur, true);
1245 // passthrough hat and underscore outside mathed:
1246 case LFUN_MATH_SUBSCRIPT:
1247 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1249 case LFUN_MATH_SUPERSCRIPT:
1250 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1253 case LFUN_MATH_INSERT:
1254 case LFUN_MATH_MATRIX:
1255 case LFUN_MATH_DELIM:
1256 case LFUN_MATH_BIGDELIM: {
1257 cur.insert(new InsetMathHull(hullSimple));
1258 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1263 case LFUN_FONT_EMPH: {
1264 LyXFont font(LyXFont::ALL_IGNORE);
1265 font.setEmph(LyXFont::TOGGLE);
1266 toggleAndShow(cur, this, font);
1270 case LFUN_FONT_BOLD: {
1271 LyXFont font(LyXFont::ALL_IGNORE);
1272 font.setSeries(LyXFont::BOLD_SERIES);
1273 toggleAndShow(cur, this, font);
1277 case LFUN_FONT_NOUN: {
1278 LyXFont font(LyXFont::ALL_IGNORE);
1279 font.setNoun(LyXFont::TOGGLE);
1280 toggleAndShow(cur, this, font);
1284 case LFUN_FONT_CODE: {
1285 LyXFont font(LyXFont::ALL_IGNORE);
1286 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1287 toggleAndShow(cur, this, font);
1291 case LFUN_FONT_SANS: {
1292 LyXFont font(LyXFont::ALL_IGNORE);
1293 font.setFamily(LyXFont::SANS_FAMILY);
1294 toggleAndShow(cur, this, font);
1298 case LFUN_FONT_ROMAN: {
1299 LyXFont font(LyXFont::ALL_IGNORE);
1300 font.setFamily(LyXFont::ROMAN_FAMILY);
1301 toggleAndShow(cur, this, font);
1305 case LFUN_FONT_DEFAULT: {
1306 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1307 toggleAndShow(cur, this, font);
1311 case LFUN_FONT_UNDERLINE: {
1312 LyXFont font(LyXFont::ALL_IGNORE);
1313 font.setUnderbar(LyXFont::TOGGLE);
1314 toggleAndShow(cur, this, font);
1318 case LFUN_FONT_SIZE: {
1319 LyXFont font(LyXFont::ALL_IGNORE);
1320 font.setLyXSize(to_utf8(cmd.argument()));
1321 toggleAndShow(cur, this, font);
1325 case LFUN_LANGUAGE: {
1326 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1329 LyXFont font(LyXFont::ALL_IGNORE);
1330 font.setLanguage(lang);
1331 toggleAndShow(cur, this, font);
1336 case LFUN_FONT_FREE_APPLY:
1337 toggleAndShow(cur, this, freefont, toggleall);
1338 cur.message(_("Character set"));
1341 // Set the freefont using the contents of \param data dispatched from
1342 // the frontends and apply it at the current cursor location.
1343 case LFUN_FONT_FREE_UPDATE: {
1346 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1349 toggleAndShow(cur, this, freefont, toggleall);
1350 cur.message(_("Character set"));
1355 case LFUN_FINISHED_LEFT:
1356 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1359 case LFUN_FINISHED_RIGHT:
1360 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1364 case LFUN_FINISHED_UP:
1365 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1369 case LFUN_FINISHED_DOWN:
1370 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1374 case LFUN_LAYOUT_PARAGRAPH: {
1376 params2string(cur.paragraph(), data);
1377 data = "show\n" + data;
1378 bv->showDialogWithData("paragraph", data);
1382 case LFUN_PARAGRAPH_UPDATE: {
1384 params2string(cur.paragraph(), data);
1386 // Will the paragraph accept changes from the dialog?
1387 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1389 data = "update " + convert<string>(accept) + '\n' + data;
1390 bv->updateDialog("paragraph", data);
1394 case LFUN_ACCENT_UMLAUT:
1395 case LFUN_ACCENT_CIRCUMFLEX:
1396 case LFUN_ACCENT_GRAVE:
1397 case LFUN_ACCENT_ACUTE:
1398 case LFUN_ACCENT_TILDE:
1399 case LFUN_ACCENT_CEDILLA:
1400 case LFUN_ACCENT_MACRON:
1401 case LFUN_ACCENT_DOT:
1402 case LFUN_ACCENT_UNDERDOT:
1403 case LFUN_ACCENT_UNDERBAR:
1404 case LFUN_ACCENT_CARON:
1405 case LFUN_ACCENT_SPECIAL_CARON:
1406 case LFUN_ACCENT_BREVE:
1407 case LFUN_ACCENT_TIE:
1408 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1409 case LFUN_ACCENT_CIRCLE:
1410 case LFUN_ACCENT_OGONEK:
1411 theLyXFunc().handleKeyFunc(cmd.action);
1412 if (!cmd.argument().empty())
1413 // FIXME: Are all these characters encoded in one byte in utf8?
1414 bv->getIntl().getTransManager()
1415 .translateAndInsert(cmd.argument()[0], this, cur);
1418 case LFUN_FLOAT_LIST: {
1419 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1420 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1421 // not quite sure if we want this...
1423 cur.clearSelection();
1424 breakParagraph(cur);
1426 if (cur.lastpos() != 0) {
1428 breakParagraph(cur);
1431 setLayout(cur, tclass.defaultLayoutName());
1432 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1433 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1436 lyxerr << "Non-existent float type: "
1437 << to_utf8(cmd.argument()) << endl;
1442 case LFUN_CHANGE_ACCEPT: {
1447 case LFUN_CHANGE_REJECT: {
1452 case LFUN_THESAURUS_ENTRY: {
1453 docstring arg = cmd.argument();
1455 arg = cur.selectionAsString(false);
1457 if (arg.size() > 100 || arg.empty()) {
1458 // Get word or selection
1459 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1460 arg = cur.selectionAsString(false);
1463 bv->showDialogWithData("thesaurus", to_utf8(arg));
1467 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1468 // Given data, an encoding of the ParagraphParameters
1469 // generated in the Paragraph dialog, this function sets
1470 // the current paragraph appropriately.
1471 istringstream is(to_utf8(cmd.argument()));
1474 ParagraphParameters params;
1479 params.labelWidthString(),
1481 cur.message(_("Paragraph layout set"));
1486 if (cur.selection()) {
1487 cur.selection() = false;
1490 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1495 lyxerr[Debug::ACTION]
1496 << BOOST_CURRENT_FUNCTION
1497 << ": Command " << cmd
1498 << " not DISPATCHED by LyXText" << endl;
1503 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1505 // FIXME: The cursor flag is reset two lines below
1506 // so we need to check here if some of the LFUN did touch that.
1507 // for now only LyXText::erase() and LyXText::backspace() do that.
1508 // The plan is to verify all the LFUNs and then to remove this
1509 // singleParUpdate boolean altogether.
1510 if (cur.result().update() & Update::Force) {
1511 singleParUpdate = false;
1515 // FIXME: the following code should go in favor of fine grained
1516 // update flag treatment.
1517 if (singleParUpdate)
1518 // Inserting characters does not change par height
1519 if (cur.bottom().paragraph().dim().height()
1520 == olddim.height()) {
1521 // if so, update _only_ this paragraph
1522 cur.updateFlags(Update::SinglePar |
1524 Update::MultiParSel);
1530 && &oldTopSlice.inset() == &cur.inset()
1531 && oldTopSlice.idx() == cur.idx()
1532 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1533 && !cur.selection())
1534 // FIXME: it would be better if we could just do this
1536 //if (cur.result().update() != Update::FitCursor)
1539 // But some LFUNs do not set Update::FitCursor when needed, so we
1540 // do it for all. This is not very harmfull as FitCursor will provoke
1541 // a full redraw only if needed but still, a proper review of all LFUN
1542 // should be done and this needsUpdate boolean can then be removed.
1543 cur.updateFlags(Update::FitCursor);
1545 cur.updateFlags(Update::Force | Update::FitCursor);
1549 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1550 FuncStatus & flag) const
1552 BOOST_ASSERT(cur.text() == this);
1554 LyXFont const & font = real_current_font;
1556 InsetBase::Code code = InsetBase::NO_CODE;
1558 switch (cmd.action) {
1560 case LFUN_DEPTH_DECREMENT:
1561 enable = changeDepthAllowed(cur, DEC_DEPTH);
1564 case LFUN_DEPTH_INCREMENT:
1565 enable = changeDepthAllowed(cur, INC_DEPTH);
1569 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1572 case LFUN_BIBITEM_INSERT:
1573 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1576 case LFUN_DIALOG_SHOW_NEW_INSET:
1577 if (cmd.argument() == "bibitem")
1578 code = InsetBase::BIBITEM_CODE;
1579 else if (cmd.argument() == "bibtex")
1580 code = InsetBase::BIBTEX_CODE;
1581 else if (cmd.argument() == "box")
1582 code = InsetBase::BOX_CODE;
1583 else if (cmd.argument() == "branch")
1584 code = InsetBase::BRANCH_CODE;
1585 else if (cmd.argument() == "citation")
1586 code = InsetBase::CITE_CODE;
1587 else if (cmd.argument() == "ert")
1588 code = InsetBase::ERT_CODE;
1589 else if (cmd.argument() == "external")
1590 code = InsetBase::EXTERNAL_CODE;
1591 else if (cmd.argument() == "float")
1592 code = InsetBase::FLOAT_CODE;
1593 else if (cmd.argument() == "graphics")
1594 code = InsetBase::GRAPHICS_CODE;
1595 else if (cmd.argument() == "include")
1596 code = InsetBase::INCLUDE_CODE;
1597 else if (cmd.argument() == "index")
1598 code = InsetBase::INDEX_CODE;
1599 else if (cmd.argument() == "nomenclature")
1600 code = InsetBase::NOMENCL_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_ERT_INSERT:
1618 code = InsetBase::ERT_CODE;
1620 case LFUN_FOOTNOTE_INSERT:
1621 code = InsetBase::FOOT_CODE;
1623 case LFUN_TABULAR_INSERT:
1624 code = InsetBase::TABULAR_CODE;
1626 case LFUN_MARGINALNOTE_INSERT:
1627 code = InsetBase::MARGIN_CODE;
1629 case LFUN_FLOAT_INSERT:
1630 case LFUN_FLOAT_WIDE_INSERT:
1631 code = InsetBase::FLOAT_CODE;
1633 case LFUN_WRAP_INSERT:
1634 code = InsetBase::WRAP_CODE;
1636 case LFUN_FLOAT_LIST:
1637 code = InsetBase::FLOAT_LIST_CODE;
1640 case LFUN_LIST_INSERT:
1641 code = InsetBase::LIST_CODE;
1643 case LFUN_THEOREM_INSERT:
1644 code = InsetBase::THEOREM_CODE;
1647 case LFUN_CAPTION_INSERT:
1648 code = InsetBase::CAPTION_CODE;
1650 case LFUN_NOTE_INSERT:
1651 code = InsetBase::NOTE_CODE;
1653 case LFUN_CHARSTYLE_INSERT:
1654 code = InsetBase::CHARSTYLE_CODE;
1655 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1658 case LFUN_BOX_INSERT:
1659 code = InsetBase::BOX_CODE;
1661 case LFUN_BRANCH_INSERT:
1662 code = InsetBase::BRANCH_CODE;
1663 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1666 case LFUN_LABEL_INSERT:
1667 code = InsetBase::LABEL_CODE;
1669 case LFUN_OPTIONAL_INSERT:
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_NOMENCL_INSERT:
1684 code = InsetBase::NOMENCL_CODE;
1686 case LFUN_NOMENCL_PRINT:
1687 code = InsetBase::NOMENCL_PRINT_CODE;
1689 case LFUN_TOC_INSERT:
1690 code = InsetBase::TOC_CODE;
1692 case LFUN_HTML_INSERT:
1693 case LFUN_URL_INSERT:
1694 code = InsetBase::URL_CODE;
1696 case LFUN_QUOTE_INSERT:
1697 // always allow this, since we will inset a raw quote
1698 // if an inset is not allowed.
1700 case LFUN_HYPHENATION_POINT_INSERT:
1701 case LFUN_LIGATURE_BREAK_INSERT:
1702 case LFUN_HFILL_INSERT:
1703 case LFUN_MENU_SEPARATOR_INSERT:
1704 case LFUN_DOTS_INSERT:
1705 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1706 code = InsetBase::SPECIALCHAR_CODE;
1708 case LFUN_SPACE_INSERT:
1709 // slight hack: we know this is allowed in math mode
1711 code = InsetBase::SPACE_CODE;
1714 case LFUN_INSET_MODIFY:
1715 // We need to disable this, because we may get called for a
1717 // InsetTabular::getStatus() -> InsetText::getStatus()
1718 // and we don't handle LFUN_INSET_MODIFY.
1722 case LFUN_FONT_EMPH:
1723 flag.setOnOff(font.emph() == LyXFont::ON);
1726 case LFUN_FONT_NOUN:
1727 flag.setOnOff(font.noun() == LyXFont::ON);
1730 case LFUN_FONT_BOLD:
1731 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1734 case LFUN_FONT_SANS:
1735 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1738 case LFUN_FONT_ROMAN:
1739 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1742 case LFUN_FONT_CODE:
1743 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1748 enable = cur.selection();
1752 enable = cap::numberOfSelections() > 0;
1755 case LFUN_PARAGRAPH_MOVE_UP:
1756 enable = cur.pit() > 0 && !cur.selection();
1759 case LFUN_PARAGRAPH_MOVE_DOWN:
1760 enable = cur.pit() < cur.lastpit() && !cur.selection();
1763 case LFUN_INSET_DISSOLVE:
1764 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1767 case LFUN_CHANGE_ACCEPT:
1768 case LFUN_CHANGE_REJECT:
1769 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1770 // In principle, these LFUNs should only be enabled if there
1771 // is a change at the current position/in the current selection.
1772 // However, without proper optimizations, this will inevitably
1773 // result in unacceptable performance - just imagine a user who
1774 // wants to select the complete content of a long document.
1778 case LFUN_WORD_DELETE_FORWARD:
1779 case LFUN_WORD_DELETE_BACKWARD:
1780 case LFUN_LINE_DELETE:
1781 case LFUN_WORD_FORWARD:
1782 case LFUN_WORD_BACKWARD:
1783 case LFUN_CHAR_FORWARD:
1784 case LFUN_CHAR_FORWARD_SELECT:
1785 case LFUN_CHAR_BACKWARD:
1786 case LFUN_CHAR_BACKWARD_SELECT:
1788 case LFUN_UP_SELECT:
1790 case LFUN_DOWN_SELECT:
1791 case LFUN_PARAGRAPH_UP_SELECT:
1792 case LFUN_PARAGRAPH_DOWN_SELECT:
1793 case LFUN_SCREEN_UP_SELECT:
1794 case LFUN_SCREEN_DOWN_SELECT:
1795 case LFUN_LINE_BEGIN_SELECT:
1796 case LFUN_LINE_END_SELECT:
1797 case LFUN_WORD_FORWARD_SELECT:
1798 case LFUN_WORD_BACKWARD_SELECT:
1799 case LFUN_WORD_SELECT:
1800 case LFUN_PARAGRAPH_UP:
1801 case LFUN_PARAGRAPH_DOWN:
1802 case LFUN_SCREEN_UP:
1803 case LFUN_SCREEN_DOWN:
1804 case LFUN_LINE_BEGIN:
1806 case LFUN_BREAK_LINE:
1807 case LFUN_CHAR_DELETE_FORWARD:
1808 case LFUN_DELETE_FORWARD_SKIP:
1809 case LFUN_CHAR_DELETE_BACKWARD:
1810 case LFUN_DELETE_BACKWARD_SKIP:
1811 case LFUN_BREAK_PARAGRAPH:
1812 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1813 case LFUN_BREAK_PARAGRAPH_SKIP:
1814 case LFUN_PARAGRAPH_SPACING:
1815 case LFUN_INSET_INSERT:
1816 case LFUN_WORD_UPCASE:
1817 case LFUN_WORD_LOWCASE:
1818 case LFUN_WORD_CAPITALIZE:
1819 case LFUN_CHARS_TRANSPOSE:
1820 case LFUN_SERVER_GET_XY:
1821 case LFUN_SERVER_SET_XY:
1822 case LFUN_SERVER_GET_FONT:
1823 case LFUN_SERVER_GET_LAYOUT:
1825 case LFUN_CLIPBOARD_PASTE:
1826 case LFUN_PRIMARY_SELECTION_PASTE:
1827 case LFUN_DATE_INSERT:
1828 case LFUN_SELF_INSERT:
1829 case LFUN_LINE_INSERT:
1830 case LFUN_PAGEBREAK_INSERT:
1831 case LFUN_CLEARPAGE_INSERT:
1832 case LFUN_CLEARDOUBLEPAGE_INSERT:
1833 case LFUN_MATH_DISPLAY:
1834 case LFUN_MATH_IMPORT_SELECTION:
1835 case LFUN_MATH_MODE:
1836 case LFUN_MATH_MACRO:
1837 case LFUN_MATH_MATRIX:
1838 case LFUN_MATH_DELIM:
1839 case LFUN_MATH_BIGDELIM:
1840 case LFUN_MATH_SUBSCRIPT:
1841 case LFUN_MATH_SUPERSCRIPT:
1842 case LFUN_FONT_DEFAULT:
1843 case LFUN_FONT_UNDERLINE:
1844 case LFUN_FONT_SIZE:
1846 case LFUN_FONT_FREE_APPLY:
1847 case LFUN_FONT_FREE_UPDATE:
1848 case LFUN_LAYOUT_PARAGRAPH:
1849 case LFUN_PARAGRAPH_UPDATE:
1850 case LFUN_ACCENT_UMLAUT:
1851 case LFUN_ACCENT_CIRCUMFLEX:
1852 case LFUN_ACCENT_GRAVE:
1853 case LFUN_ACCENT_ACUTE:
1854 case LFUN_ACCENT_TILDE:
1855 case LFUN_ACCENT_CEDILLA:
1856 case LFUN_ACCENT_MACRON:
1857 case LFUN_ACCENT_DOT:
1858 case LFUN_ACCENT_UNDERDOT:
1859 case LFUN_ACCENT_UNDERBAR:
1860 case LFUN_ACCENT_CARON:
1861 case LFUN_ACCENT_SPECIAL_CARON:
1862 case LFUN_ACCENT_BREVE:
1863 case LFUN_ACCENT_TIE:
1864 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1865 case LFUN_ACCENT_CIRCLE:
1866 case LFUN_ACCENT_OGONEK:
1867 case LFUN_THESAURUS_ENTRY:
1868 case LFUN_PARAGRAPH_PARAMS_APPLY:
1870 case LFUN_BUFFER_END:
1871 case LFUN_BUFFER_BEGIN:
1872 case LFUN_BUFFER_BEGIN_SELECT:
1873 case LFUN_BUFFER_END_SELECT:
1874 case LFUN_UNICODE_INSERT:
1875 // these are handled in our dispatch()
1883 if (code != InsetBase::NO_CODE
1884 && (cur.empty() || !cur.inset().insetAllowed(code)))
1887 flag.enabled(enable);