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::pasteClipboard;
80 using cap::pasteSelection;
81 using cap::replaceSelection;
83 using support::isStrUnsignedInt;
88 using std::istringstream;
89 using std::ostringstream;
92 extern string current_layout;
98 LyXFont freefont(LyXFont::ALL_IGNORE);
99 bool toggleall = false;
102 void toggleAndShow(LCursor & cur, LyXText * text,
103 LyXFont const & font, bool toggleall = true)
105 text->toggleFree(cur, font, toggleall);
107 if (font.language() != ignore_language ||
108 font.number() != LyXFont::IGNORE) {
109 Paragraph & par = cur.paragraph();
110 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
111 if (cur.boundary() !=
112 text->bidi.isBoundary(cur.buffer(), par,
114 text->real_current_font))
115 text->setCursor(cur, cur.pit(), cur.pos(),
116 false, !cur.boundary());
121 void moveCursor(LCursor & cur, bool selecting)
123 if (selecting || cur.mark())
125 theSelection().haveSelection(cur.selection());
126 cur.bv().switchKeyMap();
130 void finishChange(LCursor & cur, bool selecting)
133 moveCursor(cur, selecting);
137 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
140 docstring sel = cur.selectionAsString(false);
141 //lyxerr << "selection is: '" << sel << "'" << endl;
143 // It may happen that sel is empty but there is a selection
144 replaceSelection(cur);
147 #ifdef ENABLE_ASSERTIONS
148 const int old_pos = cur.pos();
150 cur.insert(new InsetMathHull(hullSimple));
151 BOOST_ASSERT(old_pos == cur.pos());
152 cur.nextInset()->edit(cur, true);
153 // don't do that also for LFUN_MATH_MODE
154 // unless you want end up with always changing
155 // to mathrm when opening an inlined inset --
156 // I really hate "LyXfunc overloading"...
158 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
159 // Avoid an unnecessary undo step if cmd.argument
161 if (!cmd.argument().empty())
162 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
165 // create a macro if we see "\\newcommand"
166 // somewhere, and an ordinary formula
168 if (sel.find(from_ascii("\\newcommand")) == string::npos
169 && sel.find(from_ascii("\\def")) == string::npos)
171 InsetMathHull * formula = new InsetMathHull;
172 istringstream is(to_utf8(sel));
175 formula->read(cur.buffer(), lex);
176 if (formula->getType() == hullNone)
177 // Don't create pseudo formulas if
178 // delimiters are left out
179 formula->mutate(hullSimple);
182 cur.insert(new MathMacroTemplate(sel));
185 cur.message(from_utf8(N_("Math editor mode")));
194 string const freefont2string()
197 if (font2string(freefont, toggleall, data))
204 void LyXText::cursorPrevious(LCursor & cur)
206 pos_type cpos = cur.pos();
207 pit_type cpar = cur.pit();
209 int x = cur.x_target();
210 setCursorFromCoordinates(cur, x, 0);
211 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
213 if (cpar == cur.pit() && cpos == cur.pos())
214 // we have a row which is taller than the workarea. The
215 // simplest solution is to move to the previous row instead.
216 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
219 cur.updateFlags(Update::Force | Update::FitCursor);
223 void LyXText::cursorNext(LCursor & cur)
225 pos_type cpos = cur.pos();
226 pit_type cpar = cur.pit();
228 int x = cur.x_target();
229 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
230 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232 if (cpar == cur.pit() && cpos == cur.pos())
233 // we have a row which is taller than the workarea. The
234 // simplest solution is to move to the next row instead.
236 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
239 cur.updateFlags(Update::Force | Update::FitCursor);
245 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
247 cap::replaceSelection(cur);
248 cur.insert(new InsetSpecialChar(kind));
253 bool doInsertInset(LCursor & cur, LyXText * text,
254 FuncRequest const & cmd, bool edit, bool pastesel)
256 InsetBase * inset = createInset(&cur.bv(), cmd);
262 if (cur.selection()) {
263 lyx::dispatch(FuncRequest(LFUN_CUT));
266 text->insertInset(cur, inset);
269 inset->edit(cur, true);
271 if (gotsel && pastesel) {
272 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
273 // reset first par to default
274 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
275 LyXLayout_ptr const layout =
276 cur.buffer().params().getLyXTextClass().defaultLayout();
277 cur.text()->paragraphs().begin()->layout(layout);
287 void LyXText::number(LCursor & cur)
289 LyXFont font(LyXFont::ALL_IGNORE);
290 font.setNumber(LyXFont::TOGGLE);
291 toggleAndShow(cur, this, font);
295 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
297 return par.isRightToLeftPar(buffer.params());
301 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
303 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
305 // FIXME: We use the update flag to indicates wether a singlePar or a
306 // full screen update is needed. We reset it here but shall we restore it
310 BOOST_ASSERT(cur.text() == this);
311 BufferView * bv = &cur.bv();
312 CursorSlice oldTopSlice = cur.top();
313 bool oldBoundary = cur.boundary();
314 bool sel = cur.selection();
315 // Signals that, even if needsUpdate == false, an update of the
316 // cursor paragraph is required
317 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
318 LyXAction::SingleParUpdate);
319 // Signals that a full-screen update is required
320 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
321 LyXAction::NoUpdate) || singleParUpdate);
322 // Remember the old paragraph metric (_outer_ paragraph!)
323 ParagraphMetrics const & pm = cur.bv().parMetrics(
324 cur.bottom().text(), cur.bottom().pit());
325 Dimension olddim = pm.dim();
327 switch (cmd.action) {
329 case LFUN_PARAGRAPH_MOVE_DOWN: {
330 pit_type const pit = cur.pit();
331 recUndo(cur, 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(cur, 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_BUFFER_BEGIN:
403 case LFUN_BUFFER_BEGIN_SELECT:
404 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
405 if (cur.depth() == 1) {
406 needsUpdate |= cursorTop(cur);
412 case LFUN_BUFFER_END:
413 case LFUN_BUFFER_END_SELECT:
414 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
415 if (cur.depth() == 1) {
416 needsUpdate |= cursorBottom(cur);
422 case LFUN_CHAR_FORWARD:
423 case LFUN_CHAR_FORWARD_SELECT:
424 //lyxerr << BOOST_CURRENT_FUNCTION
425 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
426 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
427 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
428 needsUpdate |= cursorLeft(cur);
430 needsUpdate |= cursorRight(cur);
432 if (!needsUpdate && oldTopSlice == cur.top()
433 && cur.boundary() == oldBoundary) {
435 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
439 case LFUN_CHAR_BACKWARD:
440 case LFUN_CHAR_BACKWARD_SELECT:
441 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
442 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
443 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
444 needsUpdate |= cursorRight(cur);
446 needsUpdate |= cursorLeft(cur);
448 if (!needsUpdate && oldTopSlice == cur.top()
449 && cur.boundary() == oldBoundary) {
451 cmd = FuncRequest(LFUN_FINISHED_LEFT);
457 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
458 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
460 needsUpdate |= cursorUp(cur);
462 if (!needsUpdate && oldTopSlice == cur.top()
463 && cur.boundary() == oldBoundary) {
465 cmd = FuncRequest(LFUN_FINISHED_UP);
470 case LFUN_DOWN_SELECT:
471 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
472 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
473 needsUpdate |= cursorDown(cur);
475 if (!needsUpdate && oldTopSlice == cur.top() &&
476 cur.boundary() == oldBoundary)
479 cmd = FuncRequest(LFUN_FINISHED_DOWN);
483 case LFUN_PARAGRAPH_UP:
484 case LFUN_PARAGRAPH_UP_SELECT:
485 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
486 needsUpdate |= cursorUpParagraph(cur);
489 case LFUN_PARAGRAPH_DOWN:
490 case LFUN_PARAGRAPH_DOWN_SELECT:
491 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
492 needsUpdate |= cursorDownParagraph(cur);
496 case LFUN_SCREEN_UP_SELECT:
497 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
498 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
500 cmd = FuncRequest(LFUN_FINISHED_UP);
506 case LFUN_SCREEN_DOWN:
507 case LFUN_SCREEN_DOWN_SELECT:
508 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
509 if (cur.pit() == cur.lastpit()
510 && cur.textRow().endpos() == cur.lastpos()) {
512 cmd = FuncRequest(LFUN_FINISHED_DOWN);
518 case LFUN_LINE_BEGIN:
519 case LFUN_LINE_BEGIN_SELECT:
520 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
521 needsUpdate |= cursorHome(cur);
525 case LFUN_LINE_END_SELECT:
526 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
527 needsUpdate |= cursorEnd(cur);
530 case LFUN_WORD_FORWARD:
531 case LFUN_WORD_FORWARD_SELECT:
532 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
533 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
534 needsUpdate |= cursorLeftOneWord(cur);
536 needsUpdate |= cursorRightOneWord(cur);
539 case LFUN_WORD_BACKWARD:
540 case LFUN_WORD_BACKWARD_SELECT:
541 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
542 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
543 needsUpdate |= cursorRightOneWord(cur);
545 needsUpdate |= cursorLeftOneWord(cur);
548 case LFUN_WORD_SELECT: {
549 selectWord(cur, WHOLE_WORD);
550 finishChange(cur, true);
554 case LFUN_BREAK_LINE: {
555 // Not allowed by LaTeX (labels or empty par)
556 if (cur.pos() > cur.paragraph().beginOfBody()) {
557 if (!cur.selection())
559 cap::replaceSelection(cur);
560 cur.insert(new InsetNewline);
562 moveCursor(cur, false);
567 case LFUN_CHAR_DELETE_FORWARD:
568 if (!cur.selection()) {
569 if (cur.pos() == cur.paragraph().size())
570 // Par boundary, force full-screen update
571 singleParUpdate = false;
572 needsUpdate |= erase(cur);
574 // It is possible to make it a lot faster still
575 // just comment out the line below...
577 cutSelection(cur, true, false);
578 singleParUpdate = false;
580 moveCursor(cur, false);
583 case LFUN_DELETE_FORWARD_SKIP:
584 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
585 if (!cur.selection()) {
586 if (cur.pos() == cur.lastpos()) {
593 cutSelection(cur, true, false);
598 case LFUN_CHAR_DELETE_BACKWARD:
599 if (!cur.selection()) {
600 if (bv->getIntl().getTransManager().backspace()) {
601 // Par boundary, full-screen update
603 singleParUpdate = false;
604 needsUpdate |= backspace(cur);
606 // It is possible to make it a lot faster still
607 // just comment out the line below...
610 cutSelection(cur, true, false);
611 singleParUpdate = false;
616 case LFUN_DELETE_BACKWARD_SKIP:
617 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
618 if (!cur.selection()) {
622 //CursorSlice cur = cursor();
626 cutSelection(cur, true, false);
630 case LFUN_BREAK_PARAGRAPH:
631 cap::replaceSelection(cur);
632 breakParagraph(cur, 0);
637 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
638 cap::replaceSelection(cur);
639 breakParagraph(cur, 1);
644 case LFUN_BREAK_PARAGRAPH_SKIP: {
645 // When at the beginning of a paragraph, remove
646 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
647 cap::replaceSelection(cur);
649 cur.paragraph().params().labelWidthString(docstring());
651 breakParagraph(cur, 0);
657 case LFUN_PARAGRAPH_SPACING: {
658 Paragraph & par = cur.paragraph();
659 Spacing::Space cur_spacing = par.params().spacing().getSpace();
660 string cur_value = "1.0";
661 if (cur_spacing == Spacing::Other)
662 cur_value = par.params().spacing().getValueAsString();
664 istringstream is(to_utf8(cmd.argument()));
667 Spacing::Space new_spacing = cur_spacing;
668 string new_value = cur_value;
670 lyxerr << "Missing argument to `paragraph-spacing'"
672 } else if (tmp == "single") {
673 new_spacing = Spacing::Single;
674 } else if (tmp == "onehalf") {
675 new_spacing = Spacing::Onehalf;
676 } else if (tmp == "double") {
677 new_spacing = Spacing::Double;
678 } else if (tmp == "other") {
679 new_spacing = Spacing::Other;
680 string tmpval = "0.0";
682 lyxerr << "new_value = " << tmpval << endl;
685 } else if (tmp == "default") {
686 new_spacing = Spacing::Default;
688 lyxerr << to_utf8(_("Unknown spacing argument: "))
689 << to_utf8(cmd.argument()) << endl;
691 if (cur_spacing != new_spacing || cur_value != new_value)
692 par.params().spacing(Spacing(new_spacing, new_value));
696 case LFUN_INSET_INSERT: {
698 InsetBase * inset = createInset(bv, cmd);
700 insertInset(cur, inset);
706 case LFUN_INSET_DISSOLVE:
707 needsUpdate |= dissolveInset(cur);
710 case LFUN_INSET_SETTINGS:
711 cur.inset().showInsetDialog(bv);
714 case LFUN_SPACE_INSERT:
715 if (cur.paragraph().layout()->free_spacing)
716 insertChar(cur, ' ');
718 doInsertInset(cur, this, cmd, false, false);
721 moveCursor(cur, false);
724 case LFUN_HYPHENATION_POINT_INSERT:
725 specialChar(cur, InsetSpecialChar::HYPHENATION);
728 case LFUN_LIGATURE_BREAK_INSERT:
729 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
732 case LFUN_DOTS_INSERT:
733 specialChar(cur, InsetSpecialChar::LDOTS);
736 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
737 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
740 case LFUN_MENU_SEPARATOR_INSERT:
741 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
744 case LFUN_WORD_UPCASE:
745 changeCase(cur, LyXText::text_uppercase);
748 case LFUN_WORD_LOWCASE:
749 changeCase(cur, LyXText::text_lowercase);
752 case LFUN_WORD_CAPITALIZE:
753 changeCase(cur, LyXText::text_capitalization);
756 case LFUN_CHARS_TRANSPOSE:
761 cur.message(_("Paste"));
762 cap::replaceSelection(cur);
763 if (cmd.argument().empty() && !theClipboard().isInternal())
764 pasteClipboard(cur, bv->buffer()->errorList("Paste"));
766 string const arg(to_utf8(cmd.argument()));
767 pasteSelection(cur, bv->buffer()->errorList("Paste"),
768 isStrUnsignedInt(arg) ?
769 convert<unsigned int>(arg) :
772 bv->buffer()->errors("Paste");
773 cur.clearSelection(); // bug 393
779 cutSelection(cur, true, true);
780 cur.message(_("Cut"));
785 cur.message(_("Copy"));
788 case LFUN_SERVER_GET_XY:
789 cur.message(from_utf8(
790 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
791 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
794 case LFUN_SERVER_SET_XY: {
797 istringstream is(to_utf8(cmd.argument()));
800 lyxerr << "SETXY: Could not parse coordinates in '"
801 << to_utf8(cmd.argument()) << std::endl;
803 setCursorFromCoordinates(cur, x, y);
807 case LFUN_SERVER_GET_FONT:
808 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
809 cur.message(from_ascii("E"));
810 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
811 cur.message(from_ascii("N"));
813 cur.message(from_ascii("0"));
816 case LFUN_SERVER_GET_LAYOUT:
817 cur.message(from_utf8(cur.paragraph().layout()->name()));
821 string layout = to_ascii(cmd.argument());
822 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
824 // Derive layout number from given argument (string)
825 // and current buffer's textclass (number)
826 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
828 layout = tclass.defaultLayoutName();
829 bool hasLayout = tclass.hasLayout(layout);
831 // If the entry is obsolete, use the new one instead.
833 string const & obs = tclass[layout]->obsoleted_by();
839 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
840 from_utf8(N_(" not known")));
844 bool change_layout = (current_layout != layout);
846 if (!change_layout && cur.selection() &&
847 cur.selBegin().pit() != cur.selEnd().pit())
849 pit_type spit = cur.selBegin().pit();
850 pit_type epit = cur.selEnd().pit() + 1;
851 while (spit != epit) {
852 if (pars_[spit].layout()->name() != current_layout) {
853 change_layout = true;
861 current_layout = layout;
862 setLayout(cur, layout);
863 // inform the GUI that the layout has changed.
864 bv->layoutChanged(layout);
870 case LFUN_CLIPBOARD_PASTE:
871 cur.clearSelection();
872 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
873 cmd.argument() == "paragraph");
874 bv->buffer()->errors("Paste");
877 case LFUN_PRIMARY_SELECTION_PASTE:
878 pasteString(cur, theSelection().get(),
879 cmd.argument() == "paragraph");
882 case LFUN_UNICODE_INSERT: {
883 if (cmd.argument().empty())
885 docstring hexstring = cmd.argument();
886 if (lyx::support::isHex(hexstring)) {
887 char_type c = lyx::support::hexToInt(hexstring);
888 if (c > 32 && c < 0x10ffff) {
889 lyxerr << "Inserting c: " << c << endl;
890 docstring s = docstring(1, c);
891 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
897 case LFUN_QUOTE_INSERT: {
898 cap::replaceSelection(cur);
899 Paragraph & par = cur.paragraph();
900 pos_type pos = cur.pos();
904 else if (cur.prevInset() && cur.prevInset()->isSpace())
907 c = par.getChar(pos - 1);
909 LyXLayout_ptr const & style = par.layout();
911 BufferParams const & bufparams = bv->buffer()->params();
912 if (!style->pass_thru
913 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
914 string arg = to_utf8(cmd.argument());
916 cur.insert(new InsetQuotes(c,
917 bufparams.quotes_language,
918 InsetQuotes::SingleQ));
920 cur.insert(new InsetQuotes(c,
921 bufparams.quotes_language,
922 InsetQuotes::DoubleQ));
926 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
930 case LFUN_DATE_INSERT:
931 if (cmd.argument().empty())
932 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
933 formatted_time(current_time())));
935 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
936 formatted_time(current_time(), to_utf8(cmd.argument()))));
939 case LFUN_MOUSE_TRIPLE:
940 if (cmd.button() == mouse_button::button1) {
946 theSelection().haveSelection(cur.selection());
950 case LFUN_MOUSE_DOUBLE:
951 if (cmd.button() == mouse_button::button1) {
952 selectWord(cur, WHOLE_WORD_STRICT);
954 theSelection().haveSelection(cur.selection());
958 // Single-click on work area
959 case LFUN_MOUSE_PRESS: {
960 // Right click on a footnote flag opens float menu
961 if (cmd.button() == mouse_button::button3)
962 cur.clearSelection();
964 // Middle button press pastes if we have a selection
965 // We do this here as if the selection was inside an inset
966 // it could get cleared on the unlocking of the inset so
967 // we have to check this first
968 bool paste_internally = false;
969 if (cmd.button() == mouse_button::button2 && cur.selection()) {
970 // Copy the selection to the clipboard stack. This
971 // is done for two reasons:
972 // - We want it to appear in the "Edit->Paste recent"
974 // - We can then use the normal copy/paste machinery
975 // instead of theSelection().get() to preserve
976 // formatting of the pasted stuff.
977 cap::copySelectionToStack(cur.bv().cursor());
978 paste_internally = true;
981 // we have to update after dePM triggered
982 bool update = bv->mouseSetCursor(cur);
984 // Insert primary selection with middle mouse
985 // if there is a local selection in the current buffer,
987 if (cmd.button() == mouse_button::button2) {
988 if (paste_internally)
989 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
991 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
994 if (!update && cmd.button() == mouse_button::button1) {
1002 case LFUN_MOUSE_MOTION: {
1003 // Only use motion with button 1
1004 //if (cmd.button() != mouse_button::button1)
1007 // ignore motions deeper nested than the real anchor
1008 LCursor & bvcur = cur.bv().cursor();
1009 if (bvcur.anchor_.hasPart(cur)) {
1010 CursorSlice old = bvcur.top();
1012 int const wh = bv->workHeight();
1013 int const y = std::max(0, std::min(wh - 1, cmd.y));
1015 setCursorFromCoordinates(cur, cmd.x, y);
1016 cur.x_target() = cmd.x;
1018 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1020 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1021 // This is to allow jumping over large insets
1022 if (cur.top() == old) {
1024 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1026 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1029 if (cur.top() == old)
1032 // don't set anchor_
1033 bvcur.setCursor(cur);
1034 bvcur.selection() = true;
1035 //lyxerr << "MOTION: " << bv->cursor() << endl;
1043 case LFUN_MOUSE_RELEASE: {
1044 if (cmd.button() == mouse_button::button2)
1048 if (cmd.button() == mouse_button::button1) {
1049 if (cur.selection())
1050 theSelection().haveSelection(true);
1051 needsUpdate = false;
1059 case LFUN_SELF_INSERT: {
1060 if (cmd.argument().empty())
1063 // Automatically delete the currently selected
1064 // text and replace it with what is being
1065 // typed in now. Depends on lyxrc settings
1066 // "auto_region_delete", which defaults to
1069 if (lyxrc.auto_region_delete) {
1070 if (cur.selection())
1071 cutSelection(cur, false, false);
1072 // cutSelection clears the X selection.
1074 theSelection().haveSelection(false);
1077 cur.clearSelection();
1078 LyXFont const old_font = real_current_font;
1080 docstring::const_iterator cit = cmd.argument().begin();
1081 docstring::const_iterator end = cmd.argument().end();
1082 for (; cit != end; ++cit)
1084 bv->getIntl().getTransManager().
1085 translateAndInsert(*cit, this);
1087 insertChar(bv->cursor(), *cit);
1091 moveCursor(cur, false);
1095 case LFUN_URL_INSERT: {
1096 InsetCommandParams p("url");
1097 string const data = InsetCommandMailer::params2string("url", p);
1098 bv->showInsetDialog("url", data, 0);
1102 case LFUN_HTML_INSERT: {
1103 InsetCommandParams p("htmlurl");
1104 string const data = InsetCommandMailer::params2string("url", p);
1105 bv->showInsetDialog("url", data, 0);
1109 case LFUN_LABEL_INSERT: {
1110 InsetCommandParams p("label");
1111 // Try to generate a valid label
1112 p["name"] = (cmd.argument().empty()) ?
1113 cur.getPossibleLabel() :
1115 string const data = InsetCommandMailer::params2string("label", p);
1117 if (cmd.argument().empty()) {
1118 bv->showInsetDialog("label", data, 0);
1120 FuncRequest fr(LFUN_INSET_INSERT, data);
1128 case LFUN_LIST_INSERT:
1129 case LFUN_THEOREM_INSERT:
1131 case LFUN_CAPTION_INSERT:
1132 // Open the inset, and move the current selection
1134 doInsertInset(cur, this, cmd, true, true);
1136 updateLabels(*bv->buffer());
1138 case LFUN_NOTE_INSERT:
1139 case LFUN_CHARSTYLE_INSERT:
1140 case LFUN_BOX_INSERT:
1141 case LFUN_BRANCH_INSERT:
1142 case LFUN_BIBITEM_INSERT:
1143 case LFUN_ERT_INSERT:
1144 case LFUN_FOOTNOTE_INSERT:
1145 case LFUN_MARGINALNOTE_INSERT:
1146 case LFUN_OPTIONAL_INSERT:
1147 case LFUN_ENVIRONMENT_INSERT:
1148 // Open the inset, and move the current selection
1150 doInsertInset(cur, this, cmd, true, true);
1154 case LFUN_TABULAR_INSERT:
1155 // if there were no arguments, just open the dialog
1156 if (doInsertInset(cur, this, cmd, false, true))
1159 bv->showDialog("tabularcreate");
1163 case LFUN_FLOAT_INSERT:
1164 case LFUN_FLOAT_WIDE_INSERT:
1165 case LFUN_WRAP_INSERT: {
1166 doInsertInset(cur, this, cmd, true, true);
1168 ParagraphList & pars = cur.text()->paragraphs();
1169 // We create two additional empty paragraphs so that the
1170 // user can choose where to put the graphics (or table).
1171 pars.push_back(pars[0]);
1172 pars.push_back(pars[0]);
1173 // Now that we have three paragraphs, we reposition the cursor
1174 // at the beginning of the second one.
1177 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1178 // FIXME: When leaving the Float (or Wrap) inset we should
1179 // delete any empty paragraph left above or below the
1184 case LFUN_INDEX_INSERT:
1185 case LFUN_NOMENCL_INSERT: {
1186 InsetBase * inset = createInset(&cur.bv(), cmd);
1191 cur.clearSelection();
1192 insertInset(cur, inset);
1193 inset->edit(cur, true);
1194 // Show the dialog for the nomenclature entry, since the
1195 // description entry still needs to be filled in.
1196 if (cmd.action == LFUN_NOMENCL_INSERT)
1197 InsetCommandMailer("nomenclature",
1198 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1203 case LFUN_INDEX_PRINT:
1204 case LFUN_NOMENCL_PRINT:
1205 case LFUN_TOC_INSERT:
1206 case LFUN_HFILL_INSERT:
1207 case LFUN_LINE_INSERT:
1208 case LFUN_PAGEBREAK_INSERT:
1209 case LFUN_CLEARPAGE_INSERT:
1210 case LFUN_CLEARDOUBLEPAGE_INSERT:
1212 doInsertInset(cur, this, cmd, false, false);
1216 case LFUN_DEPTH_DECREMENT:
1217 changeDepth(cur, DEC_DEPTH);
1220 case LFUN_DEPTH_INCREMENT:
1221 changeDepth(cur, INC_DEPTH);
1224 case LFUN_MATH_DISPLAY:
1225 mathDispatch(cur, cmd, true);
1228 case LFUN_MATH_IMPORT_SELECTION:
1229 case LFUN_MATH_MODE:
1230 if (cmd.argument() == "on")
1231 // don't pass "on" as argument
1232 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1234 mathDispatch(cur, cmd, false);
1237 case LFUN_MATH_MACRO:
1238 if (cmd.argument().empty())
1239 cur.errorMessage(from_utf8(N_("Missing argument")));
1241 string s = to_utf8(cmd.argument());
1242 string const s1 = token(s, ' ', 1);
1243 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1244 string const s2 = token(s, ' ', 2);
1245 string const type = s2.empty() ? "newcommand" : s2;
1246 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1247 //cur.nextInset()->edit(cur, true);
1251 // passthrough hat and underscore outside mathed:
1252 case LFUN_MATH_SUBSCRIPT:
1253 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1255 case LFUN_MATH_SUPERSCRIPT:
1256 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1259 case LFUN_MATH_INSERT:
1260 case LFUN_MATH_MATRIX:
1261 case LFUN_MATH_DELIM:
1262 case LFUN_MATH_BIGDELIM: {
1263 cur.insert(new InsetMathHull(hullSimple));
1264 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1269 case LFUN_FONT_EMPH: {
1270 LyXFont font(LyXFont::ALL_IGNORE);
1271 font.setEmph(LyXFont::TOGGLE);
1272 toggleAndShow(cur, this, font);
1276 case LFUN_FONT_BOLD: {
1277 LyXFont font(LyXFont::ALL_IGNORE);
1278 font.setSeries(LyXFont::BOLD_SERIES);
1279 toggleAndShow(cur, this, font);
1283 case LFUN_FONT_NOUN: {
1284 LyXFont font(LyXFont::ALL_IGNORE);
1285 font.setNoun(LyXFont::TOGGLE);
1286 toggleAndShow(cur, this, font);
1290 case LFUN_FONT_CODE: {
1291 LyXFont font(LyXFont::ALL_IGNORE);
1292 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1293 toggleAndShow(cur, this, font);
1297 case LFUN_FONT_SANS: {
1298 LyXFont font(LyXFont::ALL_IGNORE);
1299 font.setFamily(LyXFont::SANS_FAMILY);
1300 toggleAndShow(cur, this, font);
1304 case LFUN_FONT_ROMAN: {
1305 LyXFont font(LyXFont::ALL_IGNORE);
1306 font.setFamily(LyXFont::ROMAN_FAMILY);
1307 toggleAndShow(cur, this, font);
1311 case LFUN_FONT_DEFAULT: {
1312 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1313 toggleAndShow(cur, this, font);
1317 case LFUN_FONT_UNDERLINE: {
1318 LyXFont font(LyXFont::ALL_IGNORE);
1319 font.setUnderbar(LyXFont::TOGGLE);
1320 toggleAndShow(cur, this, font);
1324 case LFUN_FONT_SIZE: {
1325 LyXFont font(LyXFont::ALL_IGNORE);
1326 font.setLyXSize(to_utf8(cmd.argument()));
1327 toggleAndShow(cur, this, font);
1331 case LFUN_LANGUAGE: {
1332 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1335 LyXFont font(LyXFont::ALL_IGNORE);
1336 font.setLanguage(lang);
1337 toggleAndShow(cur, this, font);
1342 case LFUN_FONT_FREE_APPLY:
1343 toggleAndShow(cur, this, freefont, toggleall);
1344 cur.message(_("Character set"));
1347 // Set the freefont using the contents of \param data dispatched from
1348 // the frontends and apply it at the current cursor location.
1349 case LFUN_FONT_FREE_UPDATE: {
1352 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1355 toggleAndShow(cur, this, freefont, toggleall);
1356 cur.message(_("Character set"));
1361 case LFUN_FINISHED_LEFT:
1362 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1365 case LFUN_FINISHED_RIGHT:
1366 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1370 case LFUN_FINISHED_UP:
1371 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1375 case LFUN_FINISHED_DOWN:
1376 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1380 case LFUN_LAYOUT_PARAGRAPH: {
1382 params2string(cur.paragraph(), data);
1383 data = "show\n" + data;
1384 bv->showDialogWithData("paragraph", data);
1388 case LFUN_PARAGRAPH_UPDATE: {
1390 params2string(cur.paragraph(), data);
1392 // Will the paragraph accept changes from the dialog?
1393 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1395 data = "update " + convert<string>(accept) + '\n' + data;
1396 bv->updateDialog("paragraph", data);
1400 case LFUN_ACCENT_UMLAUT:
1401 case LFUN_ACCENT_CIRCUMFLEX:
1402 case LFUN_ACCENT_GRAVE:
1403 case LFUN_ACCENT_ACUTE:
1404 case LFUN_ACCENT_TILDE:
1405 case LFUN_ACCENT_CEDILLA:
1406 case LFUN_ACCENT_MACRON:
1407 case LFUN_ACCENT_DOT:
1408 case LFUN_ACCENT_UNDERDOT:
1409 case LFUN_ACCENT_UNDERBAR:
1410 case LFUN_ACCENT_CARON:
1411 case LFUN_ACCENT_SPECIAL_CARON:
1412 case LFUN_ACCENT_BREVE:
1413 case LFUN_ACCENT_TIE:
1414 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1415 case LFUN_ACCENT_CIRCLE:
1416 case LFUN_ACCENT_OGONEK:
1417 theLyXFunc().handleKeyFunc(cmd.action);
1418 if (!cmd.argument().empty())
1419 // FIXME: Are all these characters encoded in one byte in utf8?
1420 bv->getIntl().getTransManager()
1421 .translateAndInsert(cmd.argument()[0], this, cur);
1424 case LFUN_FLOAT_LIST: {
1425 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1426 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1427 // not quite sure if we want this...
1429 cur.clearSelection();
1430 breakParagraph(cur);
1432 if (cur.lastpos() != 0) {
1434 breakParagraph(cur);
1437 setLayout(cur, tclass.defaultLayoutName());
1438 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1439 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1442 lyxerr << "Non-existent float type: "
1443 << to_utf8(cmd.argument()) << endl;
1448 case LFUN_CHANGE_ACCEPT: {
1449 acceptOrRejectChanges(cur, ACCEPT);
1453 case LFUN_CHANGE_REJECT: {
1454 acceptOrRejectChanges(cur, REJECT);
1458 case LFUN_THESAURUS_ENTRY: {
1459 docstring arg = cmd.argument();
1461 arg = cur.selectionAsString(false);
1463 if (arg.size() > 100 || arg.empty()) {
1464 // Get word or selection
1465 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1466 arg = cur.selectionAsString(false);
1469 bv->showDialogWithData("thesaurus", to_utf8(arg));
1473 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1474 // Given data, an encoding of the ParagraphParameters
1475 // generated in the Paragraph dialog, this function sets
1476 // the current paragraph appropriately.
1477 istringstream is(to_utf8(cmd.argument()));
1480 ParagraphParameters params;
1485 params.labelWidthString(),
1487 cur.message(_("Paragraph layout set"));
1492 if (cur.selection()) {
1493 cur.selection() = false;
1496 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1501 lyxerr[Debug::ACTION]
1502 << BOOST_CURRENT_FUNCTION
1503 << ": Command " << cmd
1504 << " not DISPATCHED by LyXText" << endl;
1509 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1511 // FIXME: The cursor flag is reset two lines below
1512 // so we need to check here if some of the LFUN did touch that.
1513 // for now only LyXText::erase() and LyXText::backspace() do that.
1514 // The plan is to verify all the LFUNs and then to remove this
1515 // singleParUpdate boolean altogether.
1516 if (cur.result().update() & Update::Force) {
1517 singleParUpdate = false;
1521 // FIXME: the following code should go in favor of fine grained
1522 // update flag treatment.
1523 if (singleParUpdate) {
1524 // Inserting characters does not change par height
1525 ParagraphMetrics const & pms
1526 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1527 if (pms.dim().height()
1528 == olddim.height()) {
1529 // if so, update _only_ this paragraph
1530 cur.updateFlags(Update::SinglePar |
1532 Update::MultiParSel);
1539 && &oldTopSlice.inset() == &cur.inset()
1540 && oldTopSlice.idx() == cur.idx()
1541 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1542 && !cur.selection())
1543 // FIXME: it would be better if we could just do this
1545 //if (cur.result().update() != Update::FitCursor)
1548 // But some LFUNs do not set Update::FitCursor when needed, so we
1549 // do it for all. This is not very harmfull as FitCursor will provoke
1550 // a full redraw only if needed but still, a proper review of all LFUN
1551 // should be done and this needsUpdate boolean can then be removed.
1552 cur.updateFlags(Update::FitCursor);
1554 cur.updateFlags(Update::Force | Update::FitCursor);
1558 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1559 FuncStatus & flag) const
1561 BOOST_ASSERT(cur.text() == this);
1563 LyXFont const & font = real_current_font;
1565 InsetBase::Code code = InsetBase::NO_CODE;
1567 switch (cmd.action) {
1569 case LFUN_DEPTH_DECREMENT:
1570 enable = changeDepthAllowed(cur, DEC_DEPTH);
1573 case LFUN_DEPTH_INCREMENT:
1574 enable = changeDepthAllowed(cur, INC_DEPTH);
1578 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1581 case LFUN_BIBITEM_INSERT:
1582 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1585 case LFUN_DIALOG_SHOW_NEW_INSET:
1586 if (cmd.argument() == "bibitem")
1587 code = InsetBase::BIBITEM_CODE;
1588 else if (cmd.argument() == "bibtex")
1589 code = InsetBase::BIBTEX_CODE;
1590 else if (cmd.argument() == "box")
1591 code = InsetBase::BOX_CODE;
1592 else if (cmd.argument() == "branch")
1593 code = InsetBase::BRANCH_CODE;
1594 else if (cmd.argument() == "citation")
1595 code = InsetBase::CITE_CODE;
1596 else if (cmd.argument() == "ert")
1597 code = InsetBase::ERT_CODE;
1598 else if (cmd.argument() == "external")
1599 code = InsetBase::EXTERNAL_CODE;
1600 else if (cmd.argument() == "float")
1601 code = InsetBase::FLOAT_CODE;
1602 else if (cmd.argument() == "graphics")
1603 code = InsetBase::GRAPHICS_CODE;
1604 else if (cmd.argument() == "include")
1605 code = InsetBase::INCLUDE_CODE;
1606 else if (cmd.argument() == "index")
1607 code = InsetBase::INDEX_CODE;
1608 else if (cmd.argument() == "nomenclature")
1609 code = InsetBase::NOMENCL_CODE;
1610 else if (cmd.argument() == "label")
1611 code = InsetBase::LABEL_CODE;
1612 else if (cmd.argument() == "note")
1613 code = InsetBase::NOTE_CODE;
1614 else if (cmd.argument() == "ref")
1615 code = InsetBase::REF_CODE;
1616 else if (cmd.argument() == "toc")
1617 code = InsetBase::TOC_CODE;
1618 else if (cmd.argument() == "url")
1619 code = InsetBase::URL_CODE;
1620 else if (cmd.argument() == "vspace")
1621 code = InsetBase::VSPACE_CODE;
1622 else if (cmd.argument() == "wrap")
1623 code = InsetBase::WRAP_CODE;
1626 case LFUN_ERT_INSERT:
1627 code = InsetBase::ERT_CODE;
1629 case LFUN_FOOTNOTE_INSERT:
1630 code = InsetBase::FOOT_CODE;
1632 case LFUN_TABULAR_INSERT:
1633 code = InsetBase::TABULAR_CODE;
1635 case LFUN_MARGINALNOTE_INSERT:
1636 code = InsetBase::MARGIN_CODE;
1638 case LFUN_FLOAT_INSERT:
1639 case LFUN_FLOAT_WIDE_INSERT:
1640 code = InsetBase::FLOAT_CODE;
1642 case LFUN_WRAP_INSERT:
1643 code = InsetBase::WRAP_CODE;
1645 case LFUN_FLOAT_LIST:
1646 code = InsetBase::FLOAT_LIST_CODE;
1649 case LFUN_LIST_INSERT:
1650 code = InsetBase::LIST_CODE;
1652 case LFUN_THEOREM_INSERT:
1653 code = InsetBase::THEOREM_CODE;
1656 case LFUN_CAPTION_INSERT:
1657 code = InsetBase::CAPTION_CODE;
1659 case LFUN_NOTE_INSERT:
1660 code = InsetBase::NOTE_CODE;
1662 case LFUN_CHARSTYLE_INSERT:
1663 code = InsetBase::CHARSTYLE_CODE;
1664 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1667 case LFUN_BOX_INSERT:
1668 code = InsetBase::BOX_CODE;
1670 case LFUN_BRANCH_INSERT:
1671 code = InsetBase::BRANCH_CODE;
1672 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1675 case LFUN_LABEL_INSERT:
1676 code = InsetBase::LABEL_CODE;
1678 case LFUN_OPTIONAL_INSERT:
1679 code = InsetBase::OPTARG_CODE;
1680 enable = numberOfOptArgs(cur.paragraph())
1681 < cur.paragraph().layout()->optionalargs;
1683 case LFUN_ENVIRONMENT_INSERT:
1684 code = InsetBase::BOX_CODE;
1686 case LFUN_INDEX_INSERT:
1687 code = InsetBase::INDEX_CODE;
1689 case LFUN_INDEX_PRINT:
1690 code = InsetBase::INDEX_PRINT_CODE;
1692 case LFUN_NOMENCL_INSERT:
1693 code = InsetBase::NOMENCL_CODE;
1695 case LFUN_NOMENCL_PRINT:
1696 code = InsetBase::NOMENCL_PRINT_CODE;
1698 case LFUN_TOC_INSERT:
1699 code = InsetBase::TOC_CODE;
1701 case LFUN_HTML_INSERT:
1702 case LFUN_URL_INSERT:
1703 code = InsetBase::URL_CODE;
1705 case LFUN_QUOTE_INSERT:
1706 // always allow this, since we will inset a raw quote
1707 // if an inset is not allowed.
1709 case LFUN_HYPHENATION_POINT_INSERT:
1710 case LFUN_LIGATURE_BREAK_INSERT:
1711 case LFUN_HFILL_INSERT:
1712 case LFUN_MENU_SEPARATOR_INSERT:
1713 case LFUN_DOTS_INSERT:
1714 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1715 code = InsetBase::SPECIALCHAR_CODE;
1717 case LFUN_SPACE_INSERT:
1718 // slight hack: we know this is allowed in math mode
1720 code = InsetBase::SPACE_CODE;
1723 case LFUN_INSET_MODIFY:
1724 // We need to disable this, because we may get called for a
1726 // InsetTabular::getStatus() -> InsetText::getStatus()
1727 // and we don't handle LFUN_INSET_MODIFY.
1731 case LFUN_FONT_EMPH:
1732 flag.setOnOff(font.emph() == LyXFont::ON);
1735 case LFUN_FONT_NOUN:
1736 flag.setOnOff(font.noun() == LyXFont::ON);
1739 case LFUN_FONT_BOLD:
1740 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1743 case LFUN_FONT_SANS:
1744 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1747 case LFUN_FONT_ROMAN:
1748 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1751 case LFUN_FONT_CODE:
1752 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1757 enable = cur.selection();
1761 if (cmd.argument().empty()) {
1762 if (theClipboard().isInternal())
1763 enable = cap::numberOfSelections() > 0;
1765 enable = !theClipboard().empty();
1767 string const arg = to_utf8(cmd.argument());
1768 if (isStrUnsignedInt(arg)) {
1769 unsigned int n = convert<unsigned int>(arg);
1770 enable = cap::numberOfSelections() > n;
1777 case LFUN_CLIPBOARD_PASTE:
1778 enable = !theClipboard().empty();
1781 case LFUN_PRIMARY_SELECTION_PASTE:
1782 enable = cur.selection() || !theSelection().empty();
1785 case LFUN_PARAGRAPH_MOVE_UP:
1786 enable = cur.pit() > 0 && !cur.selection();
1789 case LFUN_PARAGRAPH_MOVE_DOWN:
1790 enable = cur.pit() < cur.lastpit() && !cur.selection();
1793 case LFUN_INSET_DISSOLVE:
1794 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1797 case LFUN_CHANGE_ACCEPT:
1798 case LFUN_CHANGE_REJECT:
1799 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1800 // In principle, these LFUNs should only be enabled if there
1801 // is a change at the current position/in the current selection.
1802 // However, without proper optimizations, this will inevitably
1803 // result in unacceptable performance - just imagine a user who
1804 // wants to select the complete content of a long document.
1808 case LFUN_WORD_DELETE_FORWARD:
1809 case LFUN_WORD_DELETE_BACKWARD:
1810 case LFUN_LINE_DELETE:
1811 case LFUN_WORD_FORWARD:
1812 case LFUN_WORD_BACKWARD:
1813 case LFUN_CHAR_FORWARD:
1814 case LFUN_CHAR_FORWARD_SELECT:
1815 case LFUN_CHAR_BACKWARD:
1816 case LFUN_CHAR_BACKWARD_SELECT:
1818 case LFUN_UP_SELECT:
1820 case LFUN_DOWN_SELECT:
1821 case LFUN_PARAGRAPH_UP_SELECT:
1822 case LFUN_PARAGRAPH_DOWN_SELECT:
1823 case LFUN_SCREEN_UP_SELECT:
1824 case LFUN_SCREEN_DOWN_SELECT:
1825 case LFUN_LINE_BEGIN_SELECT:
1826 case LFUN_LINE_END_SELECT:
1827 case LFUN_WORD_FORWARD_SELECT:
1828 case LFUN_WORD_BACKWARD_SELECT:
1829 case LFUN_WORD_SELECT:
1830 case LFUN_PARAGRAPH_UP:
1831 case LFUN_PARAGRAPH_DOWN:
1832 case LFUN_SCREEN_UP:
1833 case LFUN_SCREEN_DOWN:
1834 case LFUN_LINE_BEGIN:
1836 case LFUN_BREAK_LINE:
1837 case LFUN_CHAR_DELETE_FORWARD:
1838 case LFUN_DELETE_FORWARD_SKIP:
1839 case LFUN_CHAR_DELETE_BACKWARD:
1840 case LFUN_DELETE_BACKWARD_SKIP:
1841 case LFUN_BREAK_PARAGRAPH:
1842 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1843 case LFUN_BREAK_PARAGRAPH_SKIP:
1844 case LFUN_PARAGRAPH_SPACING:
1845 case LFUN_INSET_INSERT:
1846 case LFUN_WORD_UPCASE:
1847 case LFUN_WORD_LOWCASE:
1848 case LFUN_WORD_CAPITALIZE:
1849 case LFUN_CHARS_TRANSPOSE:
1850 case LFUN_SERVER_GET_XY:
1851 case LFUN_SERVER_SET_XY:
1852 case LFUN_SERVER_GET_FONT:
1853 case LFUN_SERVER_GET_LAYOUT:
1855 case LFUN_DATE_INSERT:
1856 case LFUN_SELF_INSERT:
1857 case LFUN_LINE_INSERT:
1858 case LFUN_PAGEBREAK_INSERT:
1859 case LFUN_CLEARPAGE_INSERT:
1860 case LFUN_CLEARDOUBLEPAGE_INSERT:
1861 case LFUN_MATH_DISPLAY:
1862 case LFUN_MATH_IMPORT_SELECTION:
1863 case LFUN_MATH_MODE:
1864 case LFUN_MATH_MACRO:
1865 case LFUN_MATH_MATRIX:
1866 case LFUN_MATH_DELIM:
1867 case LFUN_MATH_BIGDELIM:
1868 case LFUN_MATH_SUBSCRIPT:
1869 case LFUN_MATH_SUPERSCRIPT:
1870 case LFUN_FONT_DEFAULT:
1871 case LFUN_FONT_UNDERLINE:
1872 case LFUN_FONT_SIZE:
1874 case LFUN_FONT_FREE_APPLY:
1875 case LFUN_FONT_FREE_UPDATE:
1876 case LFUN_LAYOUT_PARAGRAPH:
1877 case LFUN_PARAGRAPH_UPDATE:
1878 case LFUN_ACCENT_UMLAUT:
1879 case LFUN_ACCENT_CIRCUMFLEX:
1880 case LFUN_ACCENT_GRAVE:
1881 case LFUN_ACCENT_ACUTE:
1882 case LFUN_ACCENT_TILDE:
1883 case LFUN_ACCENT_CEDILLA:
1884 case LFUN_ACCENT_MACRON:
1885 case LFUN_ACCENT_DOT:
1886 case LFUN_ACCENT_UNDERDOT:
1887 case LFUN_ACCENT_UNDERBAR:
1888 case LFUN_ACCENT_CARON:
1889 case LFUN_ACCENT_SPECIAL_CARON:
1890 case LFUN_ACCENT_BREVE:
1891 case LFUN_ACCENT_TIE:
1892 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1893 case LFUN_ACCENT_CIRCLE:
1894 case LFUN_ACCENT_OGONEK:
1895 case LFUN_THESAURUS_ENTRY:
1896 case LFUN_PARAGRAPH_PARAMS_APPLY:
1898 case LFUN_BUFFER_END:
1899 case LFUN_BUFFER_BEGIN:
1900 case LFUN_BUFFER_BEGIN_SELECT:
1901 case LFUN_BUFFER_END_SELECT:
1902 case LFUN_UNICODE_INSERT:
1903 // these are handled in our dispatch()
1911 if (code != InsetBase::NO_CODE
1912 && (cur.empty() || !cur.inset().insetAllowed(code)))
1915 flag.enabled(enable);
1920 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1923 cur.clearSelection();
1924 if (!clip.empty()) {
1927 insertStringAsParagraphs(cur, clip);
1929 insertStringAsLines(cur, clip);