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"
27 #include "bufferview_funcs.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
35 #include "FuncRequest.h"
39 #include "LyXAction.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
49 #include "ParIterator.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
69 #include <boost/current_function.hpp>
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern docstring current_layout;
98 Font freefont(Font::ALL_IGNORE);
99 bool toggleall = false;
101 void toggleAndShow(Cursor & cur, Text * text,
102 Font const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != Font::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
110 cur.pos(), text->real_current_font))
111 text->setCursor(cur, cur.pit(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(Cursor & cur, bool selecting)
119 if (selecting || cur.mark())
124 void finishChange(Cursor & cur, bool selecting)
127 moveCursor(cur, selecting);
131 void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134 docstring sel = cur.selectionAsString(false);
136 // It may happen that sel is empty but there is a selection
137 replaceSelection(cur);
140 #ifdef ENABLE_ASSERTIONS
141 const int old_pos = cur.pos();
143 cur.insert(new InsetMathHull(hullSimple));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument().empty())
155 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 if (sel.find(from_ascii("\\newcommand")) == string::npos
162 && sel.find(from_ascii("\\def")) == string::npos)
164 InsetMathHull * formula = new InsetMathHull;
165 istringstream is(to_utf8(sel));
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == hullNone)
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate(hullSimple);
175 cur.insert(new MathMacroTemplate(sel));
178 cur.message(from_utf8(N_("Math editor mode")));
187 string const freefont2string()
190 if (font2string(freefont, toggleall, data))
197 void Text::cursorPrevious(Cursor & cur)
199 pos_type cpos = cur.pos();
200 pit_type cpar = cur.pit();
202 int x = cur.x_target();
203 setCursorFromCoordinates(cur, x, 0);
204 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
206 if (cpar == cur.pit() && cpos == cur.pos())
207 // we have a row which is taller than the workarea. The
208 // simplest solution is to move to the previous row instead.
209 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212 cur.updateFlags(Update::Force | Update::FitCursor);
216 void Text::cursorNext(Cursor & cur)
218 pos_type cpos = cur.pos();
219 pit_type cpar = cur.pit();
221 int x = cur.x_target();
222 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
223 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
225 if (cpar == cur.pit() && cpos == cur.pos())
226 // we have a row which is taller than the workarea. The
227 // simplest solution is to move to the next row instead.
229 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 cur.updateFlags(Update::Force | Update::FitCursor);
238 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 cap::replaceSelection(cur);
242 cur.insert(new InsetSpecialChar(kind));
247 bool doInsertInset(Cursor & cur, Text * text,
248 FuncRequest const & cmd, bool edit, bool pastesel)
250 Inset * inset = createInset(&cur.bv(), cmd);
256 if (cur.selection()) {
257 lyx::dispatch(FuncRequest(LFUN_CUT));
260 text->insertInset(cur, inset);
263 inset->edit(cur, true);
265 if (gotsel && pastesel) {
266 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
267 // reset first par to default
268 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
269 Layout_ptr const layout =
270 cur.buffer().params().getTextClass().defaultLayout();
271 cur.text()->paragraphs().begin()->layout(layout);
281 void Text::number(Cursor & cur)
283 Font font(Font::ALL_IGNORE);
284 font.setNumber(Font::TOGGLE);
285 toggleAndShow(cur, this, font);
289 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
291 return par.isRightToLeftPar(buffer.params());
295 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
297 if (!lyxrc.rtl_support && !sl.text())
301 if (boundary && sl.pos() > 0)
304 Paragraph const & par = getPar(sl.pit());
305 return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
309 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312 if (!lyxrc.rtl_support)
315 // no RTL boundary at line start
319 bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
321 if (pos == par.size())
322 right = par.isRightToLeftPar(buffer.params());
324 right = getFont(buffer, par, pos).isVisibleRightToLeft();
325 return left != right;
329 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
330 pos_type pos, Font const & font) const
332 if (!lyxrc.rtl_support)
335 bool left = font.isVisibleRightToLeft();
337 if (pos == par.size())
338 right = par.isRightToLeftPar(buffer.params());
340 right = getFont(buffer, par, pos).isVisibleRightToLeft();
341 return left != right;
345 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
347 LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
349 // FIXME: We use the update flag to indicates wether a singlePar or a
350 // full screen update is needed. We reset it here but shall we restore it
354 BOOST_ASSERT(cur.text() == this);
355 BufferView * bv = &cur.bv();
356 CursorSlice oldTopSlice = cur.top();
357 bool oldBoundary = cur.boundary();
358 bool sel = cur.selection();
359 // Signals that, even if needsUpdate == false, an update of the
360 // cursor paragraph is required
361 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
362 LyXAction::SingleParUpdate);
363 // Signals that a full-screen update is required
364 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
365 LyXAction::NoUpdate) || singleParUpdate);
366 // Remember the old paragraph metric (_outer_ paragraph!)
367 ParagraphMetrics const & pm = cur.bv().parMetrics(
368 cur.bottom().text(), cur.bottom().pit());
369 Dimension olddim = pm.dim();
371 switch (cmd.action) {
373 case LFUN_PARAGRAPH_MOVE_DOWN: {
374 pit_type const pit = cur.pit();
375 recUndo(cur, pit, pit + 1);
377 std::swap(pars_[pit], pars_[pit + 1]);
378 updateLabels(cur.buffer());
384 case LFUN_PARAGRAPH_MOVE_UP: {
385 pit_type const pit = cur.pit();
386 recUndo(cur, pit - 1, pit);
388 std::swap(pars_[pit], pars_[pit - 1]);
389 updateLabels(cur.buffer());
395 case LFUN_APPENDIX: {
396 Paragraph & par = cur.paragraph();
397 bool start = !par.params().startOfAppendix();
399 // FIXME: The code below only makes sense at top level.
400 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
401 // ensure that we have only one start_of_appendix in this document
402 // FIXME: this don't work for multipart document!
403 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
404 if (pars_[tmp].params().startOfAppendix()) {
406 pars_[tmp].params().startOfAppendix(false);
412 par.params().startOfAppendix(start);
414 // we can set the refreshing parameters now
415 updateLabels(cur.buffer());
419 case LFUN_WORD_DELETE_FORWARD:
420 if (cur.selection()) {
421 cutSelection(cur, true, false);
423 deleteWordForward(cur);
424 finishChange(cur, false);
427 case LFUN_WORD_DELETE_BACKWARD:
428 if (cur.selection()) {
429 cutSelection(cur, true, false);
431 deleteWordBackward(cur);
432 finishChange(cur, false);
435 case LFUN_LINE_DELETE:
436 if (cur.selection()) {
437 cutSelection(cur, true, false);
439 deleteLineForward(cur);
440 finishChange(cur, false);
443 case LFUN_BUFFER_BEGIN:
444 case LFUN_BUFFER_BEGIN_SELECT:
445 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
446 if (cur.depth() == 1) {
447 needsUpdate |= cursorTop(cur);
453 case LFUN_BUFFER_END:
454 case LFUN_BUFFER_END_SELECT:
455 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
456 if (cur.depth() == 1) {
457 needsUpdate |= cursorBottom(cur);
463 case LFUN_CHAR_FORWARD:
464 case LFUN_CHAR_FORWARD_SELECT:
465 //lyxerr << BOOST_CURRENT_FUNCTION
466 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
467 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
468 if (reverseDirectionNeeded(cur))
469 needsUpdate |= cursorLeft(cur);
471 needsUpdate |= cursorRight(cur);
473 if (!needsUpdate && oldTopSlice == cur.top()
474 && cur.boundary() == oldBoundary) {
476 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
480 case LFUN_CHAR_BACKWARD:
481 case LFUN_CHAR_BACKWARD_SELECT:
482 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
483 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
484 if (reverseDirectionNeeded(cur))
485 needsUpdate |= cursorRight(cur);
487 needsUpdate |= cursorLeft(cur);
489 if (!needsUpdate && oldTopSlice == cur.top()
490 && cur.boundary() == oldBoundary) {
492 cmd = FuncRequest(LFUN_FINISHED_LEFT);
497 case LFUN_DOWN_SELECT:
500 // stop/start the selection
501 bool select = cmd.action == LFUN_DOWN_SELECT ||
502 cmd.action == LFUN_UP_SELECT;
503 cur.selHandle(select);
505 // move cursor up/down
506 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
507 bool const successful = cur.upDownInText(up, needsUpdate);
509 // notify insets which were left and get their update flags
510 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
513 // redraw if you leave mathed (for the decorations)
514 needsUpdate |= cur.beforeDispatchCursor().inMathed();
521 case LFUN_PARAGRAPH_UP:
522 case LFUN_PARAGRAPH_UP_SELECT:
523 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
524 needsUpdate |= cursorUpParagraph(cur);
527 case LFUN_PARAGRAPH_DOWN:
528 case LFUN_PARAGRAPH_DOWN_SELECT:
529 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
530 needsUpdate |= cursorDownParagraph(cur);
534 case LFUN_SCREEN_UP_SELECT:
535 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
536 if (cur.pit() == 0 && cur.textRow().pos() == 0)
543 case LFUN_SCREEN_DOWN:
544 case LFUN_SCREEN_DOWN_SELECT:
545 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
546 if (cur.pit() == cur.lastpit()
547 && cur.textRow().endpos() == cur.lastpos())
554 case LFUN_LINE_BEGIN:
555 case LFUN_LINE_BEGIN_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
557 needsUpdate |= cursorHome(cur);
561 case LFUN_LINE_END_SELECT:
562 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
563 needsUpdate |= cursorEnd(cur);
566 case LFUN_WORD_FORWARD:
567 case LFUN_WORD_FORWARD_SELECT:
568 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
569 if (reverseDirectionNeeded(cur))
570 needsUpdate |= cursorLeftOneWord(cur);
572 needsUpdate |= cursorRightOneWord(cur);
575 case LFUN_WORD_BACKWARD:
576 case LFUN_WORD_BACKWARD_SELECT:
577 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
578 if (reverseDirectionNeeded(cur))
579 needsUpdate |= cursorRightOneWord(cur);
581 needsUpdate |= cursorLeftOneWord(cur);
584 case LFUN_WORD_SELECT: {
585 selectWord(cur, WHOLE_WORD);
586 finishChange(cur, true);
590 case LFUN_BREAK_LINE: {
591 // Not allowed by LaTeX (labels or empty par)
592 if (cur.pos() > cur.paragraph().beginOfBody()) {
593 // this avoids a double undo
594 // FIXME: should not be needed, ideally
595 if (!cur.selection())
597 cap::replaceSelection(cur);
598 cur.insert(new InsetNewline);
600 moveCursor(cur, false);
605 case LFUN_CHAR_DELETE_FORWARD:
606 if (!cur.selection()) {
607 if (cur.pos() == cur.paragraph().size())
608 // Par boundary, force full-screen update
609 singleParUpdate = false;
610 needsUpdate |= erase(cur);
612 // It is possible to make it a lot faster still
613 // just comment out the line below...
615 cutSelection(cur, true, false);
616 singleParUpdate = false;
618 moveCursor(cur, false);
621 case LFUN_DELETE_FORWARD_SKIP:
622 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
623 if (!cur.selection()) {
624 if (cur.pos() == cur.lastpos()) {
631 cutSelection(cur, true, false);
636 case LFUN_CHAR_DELETE_BACKWARD:
637 if (!cur.selection()) {
638 if (bv->getIntl().getTransManager().backspace()) {
639 // Par boundary, full-screen update
641 singleParUpdate = false;
642 needsUpdate |= backspace(cur);
644 // It is possible to make it a lot faster still
645 // just comment out the line below...
648 cutSelection(cur, true, false);
649 singleParUpdate = false;
653 case LFUN_DELETE_BACKWARD_SKIP:
654 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
655 if (!cur.selection()) {
657 //CursorSlice cur = cursor();
661 cutSelection(cur, true, false);
665 case LFUN_BREAK_PARAGRAPH:
666 cap::replaceSelection(cur);
667 breakParagraph(cur, 0);
671 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
672 cap::replaceSelection(cur);
673 breakParagraph(cur, 1);
677 case LFUN_BREAK_PARAGRAPH_SKIP: {
678 // When at the beginning of a paragraph, remove
679 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
680 cap::replaceSelection(cur);
682 cur.paragraph().params().labelWidthString(docstring());
684 breakParagraph(cur, 0);
689 case LFUN_PARAGRAPH_SPACING: {
690 Paragraph & par = cur.paragraph();
691 Spacing::Space cur_spacing = par.params().spacing().getSpace();
692 string cur_value = "1.0";
693 if (cur_spacing == Spacing::Other)
694 cur_value = par.params().spacing().getValueAsString();
696 istringstream is(to_utf8(cmd.argument()));
699 Spacing::Space new_spacing = cur_spacing;
700 string new_value = cur_value;
702 lyxerr << "Missing argument to `paragraph-spacing'"
704 } else if (tmp == "single") {
705 new_spacing = Spacing::Single;
706 } else if (tmp == "onehalf") {
707 new_spacing = Spacing::Onehalf;
708 } else if (tmp == "double") {
709 new_spacing = Spacing::Double;
710 } else if (tmp == "other") {
711 new_spacing = Spacing::Other;
712 string tmpval = "0.0";
714 lyxerr << "new_value = " << tmpval << endl;
717 } else if (tmp == "default") {
718 new_spacing = Spacing::Default;
720 lyxerr << to_utf8(_("Unknown spacing argument: "))
721 << to_utf8(cmd.argument()) << endl;
723 if (cur_spacing != new_spacing || cur_value != new_value)
724 par.params().spacing(Spacing(new_spacing, new_value));
728 case LFUN_INSET_INSERT: {
730 Inset * inset = createInset(bv, cmd);
732 // FIXME (Abdel 01/02/2006):
733 // What follows would be a partial fix for bug 2154:
734 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
735 // This automatically put the label inset _after_ a
736 // numbered section. It should be possible to extend the mechanism
737 // to any kind of LateX environement.
738 // The correct way to fix that bug would be at LateX generation.
739 // I'll let the code here for reference as it could be used for some
740 // other feature like "automatic labelling".
742 Paragraph & par = pars_[cur.pit()];
743 if (inset->lyxCode() == Inset::LABEL_CODE
744 && par.layout()->labeltype == LABEL_COUNTER) {
745 // Go to the end of the paragraph
746 // Warning: Because of Change-Tracking, the last
747 // position is 'size()' and not 'size()-1':
748 cur.pos() = par.size();
749 // Insert a new paragraph
750 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
755 cutSelection(cur, true, false);
756 insertInset(cur, inset);
762 case LFUN_INSET_DISSOLVE:
763 needsUpdate |= dissolveInset(cur);
766 case LFUN_INSET_SETTINGS:
767 cur.inset().showInsetDialog(bv);
770 case LFUN_SPACE_INSERT:
771 if (cur.paragraph().layout()->free_spacing)
772 insertChar(cur, ' ');
774 doInsertInset(cur, this, cmd, false, false);
777 moveCursor(cur, false);
780 case LFUN_HYPHENATION_POINT_INSERT:
781 specialChar(cur, InsetSpecialChar::HYPHENATION);
784 case LFUN_LIGATURE_BREAK_INSERT:
785 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
788 case LFUN_DOTS_INSERT:
789 specialChar(cur, InsetSpecialChar::LDOTS);
792 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
793 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
796 case LFUN_MENU_SEPARATOR_INSERT:
797 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
800 case LFUN_WORD_UPCASE:
801 changeCase(cur, Text::text_uppercase);
804 case LFUN_WORD_LOWCASE:
805 changeCase(cur, Text::text_lowercase);
808 case LFUN_WORD_CAPITALIZE:
809 changeCase(cur, Text::text_capitalization);
812 case LFUN_CHARS_TRANSPOSE:
817 cur.message(_("Paste"));
818 cap::replaceSelection(cur);
819 if (cmd.argument().empty() && !theClipboard().isInternal())
820 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
822 string const arg(to_utf8(cmd.argument()));
823 pasteFromStack(cur, bv->buffer()->errorList("Paste"),
824 isStrUnsignedInt(arg) ?
825 convert<unsigned int>(arg) :
828 bv->buffer()->errors("Paste");
829 cur.clearSelection(); // bug 393
834 cutSelection(cur, true, true);
835 cur.message(_("Cut"));
840 cur.message(_("Copy"));
843 case LFUN_SERVER_GET_XY:
844 cur.message(from_utf8(
845 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
846 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
849 case LFUN_SERVER_SET_XY: {
852 istringstream is(to_utf8(cmd.argument()));
855 lyxerr << "SETXY: Could not parse coordinates in '"
856 << to_utf8(cmd.argument()) << std::endl;
858 setCursorFromCoordinates(cur, x, y);
862 case LFUN_SERVER_GET_FONT:
863 if (current_font.shape() == Font::ITALIC_SHAPE)
864 cur.message(from_ascii("E"));
865 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
866 cur.message(from_ascii("N"));
868 cur.message(from_ascii("0"));
871 case LFUN_SERVER_GET_LAYOUT:
872 cur.message(cur.paragraph().layout()->name());
876 docstring layout = cmd.argument();
877 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
879 // Derive layout number from given argument (string)
880 // and current buffer's textclass (number)
881 TextClass const & tclass = bv->buffer()->params().getTextClass();
883 layout = tclass.defaultLayoutName();
884 bool hasLayout = tclass.hasLayout(layout);
886 // If the entry is obsolete, use the new one instead.
888 docstring const & obs = tclass[layout]->obsoleted_by();
894 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
895 from_utf8(N_(" not known")));
899 bool change_layout = (current_layout != layout);
901 if (!change_layout && cur.selection() &&
902 cur.selBegin().pit() != cur.selEnd().pit())
904 pit_type spit = cur.selBegin().pit();
905 pit_type epit = cur.selEnd().pit() + 1;
906 while (spit != epit) {
907 if (pars_[spit].layout()->name() != current_layout) {
908 change_layout = true;
916 setLayout(cur, layout);
917 // inform the GUI that the layout has changed.
918 bv->layoutChanged(layout);
923 case LFUN_CLIPBOARD_PASTE:
924 cur.clearSelection();
925 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
926 cmd.argument() == "paragraph");
927 bv->buffer()->errors("Paste");
930 case LFUN_PRIMARY_SELECTION_PASTE:
931 pasteString(cur, theSelection().get(),
932 cmd.argument() == "paragraph");
935 case LFUN_UNICODE_INSERT: {
936 if (cmd.argument().empty())
938 docstring hexstring = cmd.argument();
939 if (lyx::support::isHex(hexstring)) {
940 char_type c = lyx::support::hexToInt(hexstring);
941 if (c >= 32 && c < 0x10ffff) {
942 lyxerr << "Inserting c: " << c << endl;
943 docstring s = docstring(1, c);
944 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
950 case LFUN_QUOTE_INSERT: {
951 Paragraph & par = cur.paragraph();
952 pos_type pos = cur.pos();
953 BufferParams const & bufparams = bv->buffer()->params();
954 Layout_ptr const & style = par.layout();
955 if (!style->pass_thru
956 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
957 // this avoids a double undo
958 // FIXME: should not be needed, ideally
959 if (!cur.selection())
961 cap::replaceSelection(cur);
966 else if (cur.prevInset() && cur.prevInset()->isSpace())
969 c = par.getChar(pos - 1);
970 string arg = to_utf8(cmd.argument());
972 cur.insert(new InsetQuotes(c,
973 bufparams.quotes_language,
974 InsetQuotes::SingleQ));
976 cur.insert(new InsetQuotes(c,
977 bufparams.quotes_language,
978 InsetQuotes::DoubleQ));
982 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
986 case LFUN_DATE_INSERT:
987 if (cmd.argument().empty())
988 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
989 formatted_time(current_time())));
991 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
992 formatted_time(current_time(), to_utf8(cmd.argument()))));
995 case LFUN_MOUSE_TRIPLE:
996 if (cmd.button() == mouse_button::button1) {
1005 case LFUN_MOUSE_DOUBLE:
1006 if (cmd.button() == mouse_button::button1) {
1007 selectWord(cur, WHOLE_WORD_STRICT);
1012 // Single-click on work area
1013 case LFUN_MOUSE_PRESS: {
1014 // Right click on a footnote flag opens float menu
1015 if (cmd.button() == mouse_button::button3)
1016 cur.clearSelection();
1019 bool update = bv->mouseSetCursor(cur);
1021 // Insert primary selection with middle mouse
1022 // if there is a local selection in the current buffer,
1024 if (cmd.button() == mouse_button::button2) {
1025 if (cap::selection()) {
1026 // Copy the selection buffer to the clipboard
1027 // stack, because we want it to appear in the
1028 // "Edit->Paste recent" menu.
1029 cap::copySelectionToStack();
1031 cap::pasteSelection(bv->cursor(),
1032 bv->buffer()->errorList("Paste"));
1033 bv->buffer()->errors("Paste");
1034 bv->buffer()->markDirty();
1037 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1041 // we have to update after dEPM triggered
1042 if (!update && cmd.button() == mouse_button::button1) {
1043 needsUpdate = false;
1050 case LFUN_MOUSE_MOTION: {
1051 // Only use motion with button 1
1052 //if (cmd.button() != mouse_button::button1)
1055 // ignore motions deeper nested than the real anchor
1056 Cursor & bvcur = cur.bv().cursor();
1057 if (bvcur.anchor_.hasPart(cur)) {
1058 CursorSlice old = bvcur.top();
1060 int const wh = bv->workHeight();
1061 int const y = std::max(0, std::min(wh - 1, cmd.y));
1063 setCursorFromCoordinates(cur, cmd.x, y);
1064 cur.setTargetX(cmd.x);
1066 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1068 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1069 // This is to allow jumping over large insets
1070 if (cur.top() == old) {
1072 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1074 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1077 if (cur.top() == old)
1080 // don't set anchor_
1081 bvcur.setCursor(cur);
1082 bvcur.selection() = true;
1083 //lyxerr << "MOTION: " << bv->cursor() << endl;
1091 case LFUN_MOUSE_RELEASE: {
1092 if (cmd.button() == mouse_button::button2)
1095 if (cmd.button() == mouse_button::button1) {
1096 // if there is new selection, update persistent
1097 // selection, otherwise, single click does not
1098 // clear persistent selection buffer
1099 if (cur.selection()) {
1101 // if double click, cur is moved to the end of word by selectWord
1102 // but bvcur is current mouse position
1103 Cursor & bvcur = cur.bv().cursor();
1104 bvcur.selection() = true;
1106 needsUpdate = false;
1113 case LFUN_SELF_INSERT: {
1114 if (cmd.argument().empty())
1117 // Automatically delete the currently selected
1118 // text and replace it with what is being
1119 // typed in now. Depends on lyxrc settings
1120 // "auto_region_delete", which defaults to
1123 if (lyxrc.auto_region_delete && cur.selection()) {
1124 cutSelection(cur, false, false);
1125 // When change tracking is set to off, the metrics update
1126 // mechanism correctly detects if a full update is needed or not.
1127 // This detection fails when a selection spans multiple rows and
1128 // change tracking is enabled because the paragraph metrics stays
1129 // the same. In this case, we force the full update:
1130 // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
1131 if (cur.buffer().params().trackChanges)
1132 cur.updateFlags(Update::Force);
1135 cur.clearSelection();
1136 Font const old_font = real_current_font;
1138 docstring::const_iterator cit = cmd.argument().begin();
1139 docstring::const_iterator end = cmd.argument().end();
1140 for (; cit != end; ++cit)
1141 bv->translateAndInsert(*cit, this, cur);
1144 moveCursor(cur, false);
1148 case LFUN_URL_INSERT: {
1149 InsetCommandParams p("url");
1151 if (cur.selection()) {
1152 content = cur.selectionAsString(false);
1153 cutSelection(cur, true, false);
1155 p["target"] = (cmd.argument().empty()) ?
1156 content : cmd.argument();
1157 string const data = InsetCommandMailer::params2string("url", p);
1158 if (p["target"].empty()) {
1159 bv->showInsetDialog("url", data, 0);
1161 FuncRequest fr(LFUN_INSET_INSERT, data);
1167 case LFUN_HTML_INSERT: {
1168 InsetCommandParams p("htmlurl");
1170 if (cur.selection()) {
1171 content = cur.selectionAsString(false);
1172 cutSelection(cur, true, false);
1174 p["target"] = (cmd.argument().empty()) ?
1175 content : cmd.argument();
1176 string const data = InsetCommandMailer::params2string("url", p);
1177 if (p["target"].empty()) {
1178 bv->showInsetDialog("url", data, 0);
1180 FuncRequest fr(LFUN_INSET_INSERT, data);
1186 case LFUN_LABEL_INSERT: {
1187 InsetCommandParams p("label");
1188 // Try to generate a valid label
1189 p["name"] = (cmd.argument().empty()) ?
1190 cur.getPossibleLabel() :
1192 string const data = InsetCommandMailer::params2string("label", p);
1194 if (cmd.argument().empty()) {
1195 bv->showInsetDialog("label", data, 0);
1197 FuncRequest fr(LFUN_INSET_INSERT, data);
1205 case LFUN_LIST_INSERT:
1206 case LFUN_THEOREM_INSERT:
1208 case LFUN_CAPTION_INSERT:
1209 // Open the inset, and move the current selection
1211 doInsertInset(cur, this, cmd, true, true);
1213 updateLabels(*bv->buffer());
1215 case LFUN_NOTE_INSERT:
1216 case LFUN_CHARSTYLE_INSERT:
1217 case LFUN_BOX_INSERT:
1218 case LFUN_BRANCH_INSERT:
1219 case LFUN_BIBITEM_INSERT:
1220 case LFUN_ERT_INSERT:
1221 case LFUN_LISTING_INSERT:
1222 case LFUN_FOOTNOTE_INSERT:
1223 case LFUN_MARGINALNOTE_INSERT:
1224 case LFUN_OPTIONAL_INSERT:
1225 case LFUN_ENVIRONMENT_INSERT:
1226 // Open the inset, and move the current selection
1228 doInsertInset(cur, this, cmd, true, true);
1232 case LFUN_TABULAR_INSERT:
1233 // if there were no arguments, just open the dialog
1234 if (doInsertInset(cur, this, cmd, false, true))
1237 bv->showDialog("tabularcreate");
1241 case LFUN_FLOAT_INSERT:
1242 case LFUN_FLOAT_WIDE_INSERT:
1243 case LFUN_WRAP_INSERT: {
1244 bool content = cur.selection(); // will some text be moved into the inset?
1246 doInsertInset(cur, this, cmd, true, true);
1248 ParagraphList & pars = cur.text()->paragraphs();
1250 TextClass const & tclass = bv->buffer()->params().getTextClass();
1252 // add a separate paragraph for the caption inset
1253 pars.push_back(Paragraph());
1254 pars.back().setInsetOwner(pars[0].inInset());
1255 pars.back().layout(tclass.defaultLayout());
1257 int cap_pit = pars.size() - 1;
1259 // if an empty inset was created, we create an additional empty
1260 // paragraph at the bottom so that the user can choose where to put
1261 // the graphics (or table).
1263 pars.push_back(Paragraph());
1264 pars.back().setInsetOwner(pars[0].inInset());
1265 pars.back().layout(tclass.defaultLayout());
1269 // reposition the cursor to the caption
1270 cur.pit() = cap_pit;
1272 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1273 // FIXME: When leaving the Float (or Wrap) inset we should
1274 // delete any empty paragraph left above or below the
1279 case LFUN_INDEX_INSERT:
1280 case LFUN_NOMENCL_INSERT: {
1281 Inset * inset = createInset(&cur.bv(), cmd);
1285 cur.clearSelection();
1286 insertInset(cur, inset);
1287 inset->edit(cur, true);
1288 // Show the dialog for the nomenclature entry, since the
1289 // description entry still needs to be filled in.
1290 if (cmd.action == LFUN_NOMENCL_INSERT)
1291 InsetCommandMailer("nomenclature",
1292 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1297 case LFUN_INDEX_PRINT:
1298 case LFUN_NOMENCL_PRINT:
1299 case LFUN_TOC_INSERT:
1300 case LFUN_HFILL_INSERT:
1301 case LFUN_LINE_INSERT:
1302 case LFUN_PAGEBREAK_INSERT:
1303 case LFUN_CLEARPAGE_INSERT:
1304 case LFUN_CLEARDOUBLEPAGE_INSERT:
1306 doInsertInset(cur, this, cmd, false, false);
1310 case LFUN_DEPTH_DECREMENT:
1311 changeDepth(cur, DEC_DEPTH);
1314 case LFUN_DEPTH_INCREMENT:
1315 changeDepth(cur, INC_DEPTH);
1318 case LFUN_MATH_DISPLAY:
1319 mathDispatch(cur, cmd, true);
1322 case LFUN_MATH_IMPORT_SELECTION:
1323 case LFUN_MATH_MODE:
1324 if (cmd.argument() == "on")
1325 // don't pass "on" as argument
1326 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1328 mathDispatch(cur, cmd, false);
1331 case LFUN_MATH_MACRO:
1332 if (cmd.argument().empty())
1333 cur.errorMessage(from_utf8(N_("Missing argument")));
1335 string s = to_utf8(cmd.argument());
1336 string const s1 = token(s, ' ', 1);
1337 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1338 string const s2 = token(s, ' ', 2);
1339 string const type = s2.empty() ? "newcommand" : s2;
1340 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1341 //cur.nextInset()->edit(cur, true);
1345 // passthrough hat and underscore outside mathed:
1346 case LFUN_MATH_SUBSCRIPT:
1347 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1349 case LFUN_MATH_SUPERSCRIPT:
1350 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1353 case LFUN_MATH_INSERT:
1354 case LFUN_MATH_MATRIX:
1355 case LFUN_MATH_DELIM:
1356 case LFUN_MATH_BIGDELIM: {
1357 if (cur.selection())
1358 cur.clearSelection();
1359 // FIXME: instead of the above, this one
1360 // should be used (but it asserts with Bidi enabled)
1361 // cf. http://bugzilla.lyx.org/show_bug.cgi?id=4055
1362 // cap::replaceSelection(cur);
1363 cur.insert(new InsetMathHull(hullSimple));
1364 checkAndActivateInset(cur, true);
1365 BOOST_ASSERT(cur.inMathed());
1370 case LFUN_FONT_EMPH: {
1371 Font font(Font::ALL_IGNORE);
1372 font.setEmph(Font::TOGGLE);
1373 toggleAndShow(cur, this, font);
1377 case LFUN_FONT_BOLD: {
1378 Font font(Font::ALL_IGNORE);
1379 font.setSeries(Font::BOLD_SERIES);
1380 toggleAndShow(cur, this, font);
1384 case LFUN_FONT_NOUN: {
1385 Font font(Font::ALL_IGNORE);
1386 font.setNoun(Font::TOGGLE);
1387 toggleAndShow(cur, this, font);
1391 case LFUN_FONT_CODE: {
1392 Font font(Font::ALL_IGNORE);
1393 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1394 toggleAndShow(cur, this, font);
1398 case LFUN_FONT_SANS: {
1399 Font font(Font::ALL_IGNORE);
1400 font.setFamily(Font::SANS_FAMILY);
1401 toggleAndShow(cur, this, font);
1405 case LFUN_FONT_ROMAN: {
1406 Font font(Font::ALL_IGNORE);
1407 font.setFamily(Font::ROMAN_FAMILY);
1408 toggleAndShow(cur, this, font);
1412 case LFUN_FONT_DEFAULT: {
1413 Font font(Font::ALL_INHERIT, ignore_language);
1414 toggleAndShow(cur, this, font);
1418 case LFUN_FONT_UNDERLINE: {
1419 Font font(Font::ALL_IGNORE);
1420 font.setUnderbar(Font::TOGGLE);
1421 toggleAndShow(cur, this, font);
1425 case LFUN_FONT_SIZE: {
1426 Font font(Font::ALL_IGNORE);
1427 font.setLyXSize(to_utf8(cmd.argument()));
1428 toggleAndShow(cur, this, font);
1432 case LFUN_LANGUAGE: {
1433 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1436 Font font(Font::ALL_IGNORE);
1437 font.setLanguage(lang);
1438 toggleAndShow(cur, this, font);
1442 case LFUN_FONT_FREE_APPLY:
1443 toggleAndShow(cur, this, freefont, toggleall);
1444 cur.message(_("Character set"));
1447 // Set the freefont using the contents of \param data dispatched from
1448 // the frontends and apply it at the current cursor location.
1449 case LFUN_FONT_FREE_UPDATE: {
1452 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1455 toggleAndShow(cur, this, freefont, toggleall);
1456 cur.message(_("Character set"));
1461 case LFUN_FINISHED_LEFT:
1462 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1463 if (reverseDirectionNeeded(cur))
1467 case LFUN_FINISHED_RIGHT:
1468 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1469 if (!reverseDirectionNeeded(cur))
1473 case LFUN_LAYOUT_PARAGRAPH: {
1475 params2string(cur.paragraph(), data);
1476 data = "show\n" + data;
1477 bv->showDialogWithData("paragraph", data);
1481 case LFUN_PARAGRAPH_UPDATE: {
1483 params2string(cur.paragraph(), data);
1485 // Will the paragraph accept changes from the dialog?
1486 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1488 data = "update " + convert<string>(accept) + '\n' + data;
1489 bv->updateDialog("paragraph", data);
1493 case LFUN_ACCENT_UMLAUT:
1494 case LFUN_ACCENT_CIRCUMFLEX:
1495 case LFUN_ACCENT_GRAVE:
1496 case LFUN_ACCENT_ACUTE:
1497 case LFUN_ACCENT_TILDE:
1498 case LFUN_ACCENT_CEDILLA:
1499 case LFUN_ACCENT_MACRON:
1500 case LFUN_ACCENT_DOT:
1501 case LFUN_ACCENT_UNDERDOT:
1502 case LFUN_ACCENT_UNDERBAR:
1503 case LFUN_ACCENT_CARON:
1504 case LFUN_ACCENT_SPECIAL_CARON:
1505 case LFUN_ACCENT_BREVE:
1506 case LFUN_ACCENT_TIE:
1507 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1508 case LFUN_ACCENT_CIRCLE:
1509 case LFUN_ACCENT_OGONEK:
1510 theLyXFunc().handleKeyFunc(cmd.action);
1511 if (!cmd.argument().empty())
1512 // FIXME: Are all these characters encoded in one byte in utf8?
1513 bv->translateAndInsert(cmd.argument()[0], this, cur);
1516 case LFUN_FLOAT_LIST: {
1517 TextClass const & tclass = bv->buffer()->params().getTextClass();
1518 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1520 if (cur.selection())
1521 cutSelection(cur, true, false);
1522 breakParagraph(cur);
1524 if (cur.lastpos() != 0) {
1526 breakParagraph(cur);
1529 setLayout(cur, tclass.defaultLayoutName());
1530 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1531 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1534 lyxerr << "Non-existent float type: "
1535 << to_utf8(cmd.argument()) << endl;
1540 case LFUN_CHANGE_ACCEPT: {
1541 acceptOrRejectChanges(cur, ACCEPT);
1545 case LFUN_CHANGE_REJECT: {
1546 acceptOrRejectChanges(cur, REJECT);
1550 case LFUN_THESAURUS_ENTRY: {
1551 docstring arg = cmd.argument();
1553 arg = cur.selectionAsString(false);
1555 if (arg.size() > 100 || arg.empty()) {
1556 // Get word or selection
1557 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1558 arg = cur.selectionAsString(false);
1561 bv->showDialogWithData("thesaurus", to_utf8(arg));
1565 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1566 // Given data, an encoding of the ParagraphParameters
1567 // generated in the Paragraph dialog, this function sets
1568 // the current paragraph appropriately.
1569 istringstream is(to_utf8(cmd.argument()));
1572 ParagraphParameters params;
1577 params.labelWidthString(),
1579 cur.message(_("Paragraph layout set"));
1584 if (cur.selection()) {
1585 cur.selection() = false;
1588 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1593 LYXERR(Debug::ACTION)
1594 << BOOST_CURRENT_FUNCTION
1595 << ": Command " << cmd
1596 << " not DISPATCHED by Text" << endl;
1601 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1603 // FIXME: The cursor flag is reset two lines below
1604 // so we need to check here if some of the LFUN did touch that.
1605 // for now only Text::erase() and Text::backspace() do that.
1606 // The plan is to verify all the LFUNs and then to remove this
1607 // singleParUpdate boolean altogether.
1608 if (cur.result().update() & Update::Force) {
1609 singleParUpdate = false;
1613 // FIXME: the following code should go in favor of fine grained
1614 // update flag treatment.
1615 if (singleParUpdate) {
1616 // Inserting characters does not change par height
1617 ParagraphMetrics const & pms
1618 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1619 if (pms.dim().height()
1620 == olddim.height()) {
1621 // if so, update _only_ this paragraph
1622 cur.updateFlags(Update::SinglePar |
1624 Update::MultiParSel);
1631 && &oldTopSlice.inset() == &cur.inset()
1632 && oldTopSlice.idx() == cur.idx()
1633 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1634 && !cur.selection())
1635 // FIXME: it would be better if we could just do this
1637 //if (cur.result().update() != Update::FitCursor)
1640 // But some LFUNs do not set Update::FitCursor when needed, so we
1641 // do it for all. This is not very harmfull as FitCursor will provoke
1642 // a full redraw only if needed but still, a proper review of all LFUN
1643 // should be done and this needsUpdate boolean can then be removed.
1644 cur.updateFlags(Update::FitCursor);
1646 cur.updateFlags(Update::Force | Update::FitCursor);
1650 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1651 FuncStatus & flag) const
1653 BOOST_ASSERT(cur.text() == this);
1655 Font const & font = real_current_font;
1657 Inset::Code code = Inset::NO_CODE;
1659 switch (cmd.action) {
1661 case LFUN_DEPTH_DECREMENT:
1662 enable = changeDepthAllowed(cur, DEC_DEPTH);
1665 case LFUN_DEPTH_INCREMENT:
1666 enable = changeDepthAllowed(cur, INC_DEPTH);
1670 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1673 case LFUN_BIBITEM_INSERT:
1674 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1678 case LFUN_DIALOG_SHOW_NEW_INSET:
1679 if (cmd.argument() == "bibitem")
1680 code = Inset::BIBITEM_CODE;
1681 else if (cmd.argument() == "bibtex")
1682 code = Inset::BIBTEX_CODE;
1683 else if (cmd.argument() == "box")
1684 code = Inset::BOX_CODE;
1685 else if (cmd.argument() == "branch")
1686 code = Inset::BRANCH_CODE;
1687 else if (cmd.argument() == "citation")
1688 code = Inset::CITE_CODE;
1689 else if (cmd.argument() == "ert")
1690 code = Inset::ERT_CODE;
1691 else if (cmd.argument() == "external")
1692 code = Inset::EXTERNAL_CODE;
1693 else if (cmd.argument() == "float")
1694 code = Inset::FLOAT_CODE;
1695 else if (cmd.argument() == "graphics")
1696 code = Inset::GRAPHICS_CODE;
1697 else if (cmd.argument() == "include")
1698 code = Inset::INCLUDE_CODE;
1699 else if (cmd.argument() == "index")
1700 code = Inset::INDEX_CODE;
1701 else if (cmd.argument() == "nomenclature")
1702 code = Inset::NOMENCL_CODE;
1703 else if (cmd.argument() == "label")
1704 code = Inset::LABEL_CODE;
1705 else if (cmd.argument() == "note")
1706 code = Inset::NOTE_CODE;
1707 else if (cmd.argument() == "ref")
1708 code = Inset::REF_CODE;
1709 else if (cmd.argument() == "toc")
1710 code = Inset::TOC_CODE;
1711 else if (cmd.argument() == "url")
1712 code = Inset::URL_CODE;
1713 else if (cmd.argument() == "vspace")
1714 code = Inset::VSPACE_CODE;
1715 else if (cmd.argument() == "wrap")
1716 code = Inset::WRAP_CODE;
1717 else if (cmd.argument() == "listings")
1718 code = Inset::LISTINGS_CODE;
1721 case LFUN_ERT_INSERT:
1722 code = Inset::ERT_CODE;
1724 case LFUN_LISTING_INSERT:
1725 code = Inset::LISTINGS_CODE;
1727 case LFUN_FOOTNOTE_INSERT:
1728 code = Inset::FOOT_CODE;
1730 case LFUN_TABULAR_INSERT:
1731 code = Inset::TABULAR_CODE;
1733 case LFUN_MARGINALNOTE_INSERT:
1734 code = Inset::MARGIN_CODE;
1736 case LFUN_FLOAT_INSERT:
1737 case LFUN_FLOAT_WIDE_INSERT:
1738 code = Inset::FLOAT_CODE;
1740 case LFUN_WRAP_INSERT:
1741 code = Inset::WRAP_CODE;
1743 case LFUN_FLOAT_LIST:
1744 code = Inset::FLOAT_LIST_CODE;
1747 case LFUN_LIST_INSERT:
1748 code = Inset::LIST_CODE;
1750 case LFUN_THEOREM_INSERT:
1751 code = Inset::THEOREM_CODE;
1754 case LFUN_CAPTION_INSERT:
1755 code = Inset::CAPTION_CODE;
1757 case LFUN_NOTE_INSERT:
1758 code = Inset::NOTE_CODE;
1760 case LFUN_CHARSTYLE_INSERT:
1761 code = Inset::CHARSTYLE_CODE;
1762 if (cur.buffer().params().getTextClass().charstyles().empty())
1765 case LFUN_BOX_INSERT:
1766 code = Inset::BOX_CODE;
1768 case LFUN_BRANCH_INSERT:
1769 code = Inset::BRANCH_CODE;
1770 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1773 case LFUN_LABEL_INSERT:
1774 code = Inset::LABEL_CODE;
1776 case LFUN_OPTIONAL_INSERT:
1777 code = Inset::OPTARG_CODE;
1778 enable = numberOfOptArgs(cur.paragraph())
1779 < cur.paragraph().layout()->optionalargs;
1781 case LFUN_ENVIRONMENT_INSERT:
1782 code = Inset::BOX_CODE;
1784 case LFUN_INDEX_INSERT:
1785 code = Inset::INDEX_CODE;
1787 case LFUN_INDEX_PRINT:
1788 code = Inset::INDEX_PRINT_CODE;
1790 case LFUN_NOMENCL_INSERT:
1791 code = Inset::NOMENCL_CODE;
1793 case LFUN_NOMENCL_PRINT:
1794 code = Inset::NOMENCL_PRINT_CODE;
1796 case LFUN_TOC_INSERT:
1797 code = Inset::TOC_CODE;
1799 case LFUN_HTML_INSERT:
1800 case LFUN_URL_INSERT:
1801 code = Inset::URL_CODE;
1803 case LFUN_QUOTE_INSERT:
1804 // always allow this, since we will inset a raw quote
1805 // if an inset is not allowed.
1807 case LFUN_HYPHENATION_POINT_INSERT:
1808 case LFUN_LIGATURE_BREAK_INSERT:
1809 case LFUN_HFILL_INSERT:
1810 case LFUN_MENU_SEPARATOR_INSERT:
1811 case LFUN_DOTS_INSERT:
1812 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1813 code = Inset::SPECIALCHAR_CODE;
1815 case LFUN_SPACE_INSERT:
1816 // slight hack: we know this is allowed in math mode
1818 code = Inset::SPACE_CODE;
1821 case LFUN_INSET_MODIFY:
1822 // We need to disable this, because we may get called for a
1824 // InsetTabular::getStatus() -> InsetText::getStatus()
1825 // and we don't handle LFUN_INSET_MODIFY.
1829 case LFUN_FONT_EMPH:
1830 flag.setOnOff(font.emph() == Font::ON);
1833 case LFUN_FONT_NOUN:
1834 flag.setOnOff(font.noun() == Font::ON);
1837 case LFUN_FONT_BOLD:
1838 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1841 case LFUN_FONT_SANS:
1842 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1845 case LFUN_FONT_ROMAN:
1846 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1849 case LFUN_FONT_CODE:
1850 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1855 enable = cur.selection();
1859 if (cmd.argument().empty()) {
1860 if (theClipboard().isInternal())
1861 enable = cap::numberOfSelections() > 0;
1863 enable = !theClipboard().empty();
1865 string const arg = to_utf8(cmd.argument());
1866 if (isStrUnsignedInt(arg)) {
1867 unsigned int n = convert<unsigned int>(arg);
1868 enable = cap::numberOfSelections() > n;
1875 case LFUN_CLIPBOARD_PASTE:
1876 enable = !theClipboard().empty();
1879 case LFUN_PRIMARY_SELECTION_PASTE:
1880 enable = cur.selection() || !theSelection().empty();
1883 case LFUN_PARAGRAPH_MOVE_UP:
1884 enable = cur.pit() > 0 && !cur.selection();
1887 case LFUN_PARAGRAPH_MOVE_DOWN:
1888 enable = cur.pit() < cur.lastpit() && !cur.selection();
1891 case LFUN_INSET_DISSOLVE:
1892 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1895 case LFUN_CHANGE_ACCEPT:
1896 case LFUN_CHANGE_REJECT:
1897 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1898 // In principle, these LFUNs should only be enabled if there
1899 // is a change at the current position/in the current selection.
1900 // However, without proper optimizations, this will inevitably
1901 // result in unacceptable performance - just imagine a user who
1902 // wants to select the complete content of a long document.
1906 case LFUN_WORD_DELETE_FORWARD:
1907 case LFUN_WORD_DELETE_BACKWARD:
1908 case LFUN_LINE_DELETE:
1909 case LFUN_WORD_FORWARD:
1910 case LFUN_WORD_BACKWARD:
1911 case LFUN_CHAR_FORWARD:
1912 case LFUN_CHAR_FORWARD_SELECT:
1913 case LFUN_CHAR_BACKWARD:
1914 case LFUN_CHAR_BACKWARD_SELECT:
1916 case LFUN_UP_SELECT:
1918 case LFUN_DOWN_SELECT:
1919 case LFUN_PARAGRAPH_UP_SELECT:
1920 case LFUN_PARAGRAPH_DOWN_SELECT:
1921 case LFUN_SCREEN_UP_SELECT:
1922 case LFUN_SCREEN_DOWN_SELECT:
1923 case LFUN_LINE_BEGIN_SELECT:
1924 case LFUN_LINE_END_SELECT:
1925 case LFUN_WORD_FORWARD_SELECT:
1926 case LFUN_WORD_BACKWARD_SELECT:
1927 case LFUN_WORD_SELECT:
1928 case LFUN_PARAGRAPH_UP:
1929 case LFUN_PARAGRAPH_DOWN:
1930 case LFUN_SCREEN_UP:
1931 case LFUN_SCREEN_DOWN:
1932 case LFUN_LINE_BEGIN:
1934 case LFUN_BREAK_LINE:
1935 case LFUN_CHAR_DELETE_FORWARD:
1936 case LFUN_DELETE_FORWARD_SKIP:
1937 case LFUN_CHAR_DELETE_BACKWARD:
1938 case LFUN_DELETE_BACKWARD_SKIP:
1939 case LFUN_BREAK_PARAGRAPH:
1940 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1941 case LFUN_BREAK_PARAGRAPH_SKIP:
1942 case LFUN_PARAGRAPH_SPACING:
1943 case LFUN_INSET_INSERT:
1944 case LFUN_WORD_UPCASE:
1945 case LFUN_WORD_LOWCASE:
1946 case LFUN_WORD_CAPITALIZE:
1947 case LFUN_CHARS_TRANSPOSE:
1948 case LFUN_SERVER_GET_XY:
1949 case LFUN_SERVER_SET_XY:
1950 case LFUN_SERVER_GET_FONT:
1951 case LFUN_SERVER_GET_LAYOUT:
1953 case LFUN_DATE_INSERT:
1954 case LFUN_SELF_INSERT:
1955 case LFUN_LINE_INSERT:
1956 case LFUN_PAGEBREAK_INSERT:
1957 case LFUN_CLEARPAGE_INSERT:
1958 case LFUN_CLEARDOUBLEPAGE_INSERT:
1959 case LFUN_MATH_DISPLAY:
1960 case LFUN_MATH_IMPORT_SELECTION:
1961 case LFUN_MATH_MODE:
1962 case LFUN_MATH_MACRO:
1963 case LFUN_MATH_MATRIX:
1964 case LFUN_MATH_DELIM:
1965 case LFUN_MATH_BIGDELIM:
1966 case LFUN_MATH_INSERT:
1967 case LFUN_MATH_SUBSCRIPT:
1968 case LFUN_MATH_SUPERSCRIPT:
1969 case LFUN_FONT_DEFAULT:
1970 case LFUN_FONT_UNDERLINE:
1971 case LFUN_FONT_SIZE:
1973 case LFUN_FONT_FREE_APPLY:
1974 case LFUN_FONT_FREE_UPDATE:
1975 case LFUN_LAYOUT_PARAGRAPH:
1976 case LFUN_PARAGRAPH_UPDATE:
1977 case LFUN_ACCENT_UMLAUT:
1978 case LFUN_ACCENT_CIRCUMFLEX:
1979 case LFUN_ACCENT_GRAVE:
1980 case LFUN_ACCENT_ACUTE:
1981 case LFUN_ACCENT_TILDE:
1982 case LFUN_ACCENT_CEDILLA:
1983 case LFUN_ACCENT_MACRON:
1984 case LFUN_ACCENT_DOT:
1985 case LFUN_ACCENT_UNDERDOT:
1986 case LFUN_ACCENT_UNDERBAR:
1987 case LFUN_ACCENT_CARON:
1988 case LFUN_ACCENT_SPECIAL_CARON:
1989 case LFUN_ACCENT_BREVE:
1990 case LFUN_ACCENT_TIE:
1991 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1992 case LFUN_ACCENT_CIRCLE:
1993 case LFUN_ACCENT_OGONEK:
1994 case LFUN_THESAURUS_ENTRY:
1995 case LFUN_PARAGRAPH_PARAMS_APPLY:
1997 case LFUN_BUFFER_END:
1998 case LFUN_BUFFER_BEGIN:
1999 case LFUN_BUFFER_BEGIN_SELECT:
2000 case LFUN_BUFFER_END_SELECT:
2001 case LFUN_UNICODE_INSERT:
2002 // these are handled in our dispatch()
2010 if (code != Inset::NO_CODE
2011 && (cur.empty() || !cur.inset().insetAllowed(code)))
2014 flag.enabled(enable);
2019 void Text::pasteString(Cursor & cur, docstring const & clip,
2022 cur.clearSelection();
2023 if (!clip.empty()) {
2026 insertStringAsParagraphs(cur, clip);
2028 insertStringAsLines(cur, clip);