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::pasteSelection;
80 using cap::replaceSelection;
82 using support::isStrUnsignedInt;
87 using std::istringstream;
88 using std::ostringstream;
91 extern string current_layout;
97 LyXFont freefont(LyXFont::ALL_IGNORE);
98 bool toggleall = false;
101 void toggleAndShow(LCursor & cur, LyXText * text,
102 LyXFont const & font, bool toggleall = true)
104 text->toggleFree(cur, font, toggleall);
106 if (font.language() != ignore_language ||
107 font.number() != LyXFont::IGNORE) {
108 Paragraph & par = cur.paragraph();
109 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
110 if (cur.boundary() !=
111 text->bidi.isBoundary(cur.buffer(), par,
113 text->real_current_font))
114 text->setCursor(cur, cur.pit(), cur.pos(),
115 false, !cur.boundary());
120 void moveCursor(LCursor & cur, bool selecting)
122 if (selecting || cur.mark())
124 if (!cur.selection())
125 theSelection().haveSelection(false);
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 cap::replaceSelection(cur);
558 cur.insert(new InsetNewline);
560 moveCursor(cur, false);
565 case LFUN_CHAR_DELETE_FORWARD:
566 if (!cur.selection()) {
567 if (cur.pos() == cur.paragraph().size())
568 // Par boundary, force full-screen update
569 singleParUpdate = false;
570 needsUpdate |= erase(cur);
572 // It is possible to make it a lot faster still
573 // just comment out the line below...
575 cutSelection(cur, true, false);
576 singleParUpdate = false;
578 moveCursor(cur, false);
581 case LFUN_DELETE_FORWARD_SKIP:
582 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
583 if (!cur.selection()) {
584 if (cur.pos() == cur.lastpos()) {
591 cutSelection(cur, true, false);
596 case LFUN_CHAR_DELETE_BACKWARD:
597 if (!cur.selection()) {
598 if (bv->getIntl().getTransManager().backspace()) {
599 // Par boundary, full-screen update
601 singleParUpdate = false;
602 needsUpdate |= backspace(cur);
604 // It is possible to make it a lot faster still
605 // just comment out the line below...
608 cutSelection(cur, true, false);
609 singleParUpdate = false;
614 case LFUN_DELETE_BACKWARD_SKIP:
615 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
616 if (!cur.selection()) {
620 //CursorSlice cur = cursor();
624 cutSelection(cur, true, false);
628 case LFUN_BREAK_PARAGRAPH:
629 cap::replaceSelection(cur);
630 breakParagraph(cur, 0);
635 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
636 cap::replaceSelection(cur);
637 breakParagraph(cur, 1);
642 case LFUN_BREAK_PARAGRAPH_SKIP: {
643 // When at the beginning of a paragraph, remove
644 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
645 cap::replaceSelection(cur);
647 cur.paragraph().params().labelWidthString(docstring());
649 breakParagraph(cur, 0);
655 case LFUN_PARAGRAPH_SPACING: {
656 Paragraph & par = cur.paragraph();
657 Spacing::Space cur_spacing = par.params().spacing().getSpace();
658 string cur_value = "1.0";
659 if (cur_spacing == Spacing::Other)
660 cur_value = par.params().spacing().getValueAsString();
662 istringstream is(to_utf8(cmd.argument()));
665 Spacing::Space new_spacing = cur_spacing;
666 string new_value = cur_value;
668 lyxerr << "Missing argument to `paragraph-spacing'"
670 } else if (tmp == "single") {
671 new_spacing = Spacing::Single;
672 } else if (tmp == "onehalf") {
673 new_spacing = Spacing::Onehalf;
674 } else if (tmp == "double") {
675 new_spacing = Spacing::Double;
676 } else if (tmp == "other") {
677 new_spacing = Spacing::Other;
678 string tmpval = "0.0";
680 lyxerr << "new_value = " << tmpval << endl;
683 } else if (tmp == "default") {
684 new_spacing = Spacing::Default;
686 lyxerr << to_utf8(_("Unknown spacing argument: "))
687 << to_utf8(cmd.argument()) << endl;
689 if (cur_spacing != new_spacing || cur_value != new_value)
690 par.params().spacing(Spacing(new_spacing, new_value));
694 case LFUN_INSET_INSERT: {
696 InsetBase * inset = createInset(bv, cmd);
698 insertInset(cur, inset);
704 case LFUN_INSET_DISSOLVE:
705 needsUpdate |= dissolveInset(cur);
708 case LFUN_INSET_SETTINGS:
709 cur.inset().showInsetDialog(bv);
712 case LFUN_SPACE_INSERT:
713 if (cur.paragraph().layout()->free_spacing)
714 insertChar(cur, ' ');
716 doInsertInset(cur, this, cmd, false, false);
719 moveCursor(cur, false);
722 case LFUN_HYPHENATION_POINT_INSERT:
723 specialChar(cur, InsetSpecialChar::HYPHENATION);
726 case LFUN_LIGATURE_BREAK_INSERT:
727 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
730 case LFUN_DOTS_INSERT:
731 specialChar(cur, InsetSpecialChar::LDOTS);
734 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
735 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
738 case LFUN_MENU_SEPARATOR_INSERT:
739 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
742 case LFUN_WORD_UPCASE:
743 changeCase(cur, LyXText::text_uppercase);
746 case LFUN_WORD_LOWCASE:
747 changeCase(cur, LyXText::text_lowercase);
750 case LFUN_WORD_CAPITALIZE:
751 changeCase(cur, LyXText::text_capitalization);
754 case LFUN_CHARS_TRANSPOSE:
759 cur.message(_("Paste"));
760 cap::replaceSelection(cur);
761 if (cmd.argument().empty() && !theClipboard().isInternal())
762 pasteString(cur, theClipboard().get(), docstring());
764 string const arg(to_utf8(cmd.argument()));
765 pasteSelection(cur, bv->buffer()->errorList("Paste"),
766 isStrUnsignedInt(arg) ?
767 convert<unsigned int>(arg) :
769 bv->buffer()->errors("Paste");
771 cur.clearSelection(); // bug 393
777 cutSelection(cur, true, true);
778 cur.message(_("Cut"));
783 cur.message(_("Copy"));
786 case LFUN_SERVER_GET_XY:
787 cur.message(from_utf8(
788 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
789 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
792 case LFUN_SERVER_SET_XY: {
795 istringstream is(to_utf8(cmd.argument()));
798 lyxerr << "SETXY: Could not parse coordinates in '"
799 << to_utf8(cmd.argument()) << std::endl;
801 setCursorFromCoordinates(cur, x, y);
805 case LFUN_SERVER_GET_FONT:
806 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
807 cur.message(from_ascii("E"));
808 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
809 cur.message(from_ascii("N"));
811 cur.message(from_ascii("0"));
814 case LFUN_SERVER_GET_LAYOUT:
815 cur.message(from_utf8(cur.paragraph().layout()->name()));
819 string layout = to_ascii(cmd.argument());
820 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
822 // Derive layout number from given argument (string)
823 // and current buffer's textclass (number)
824 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
826 layout = tclass.defaultLayoutName();
827 bool hasLayout = tclass.hasLayout(layout);
829 // If the entry is obsolete, use the new one instead.
831 string const & obs = tclass[layout]->obsoleted_by();
837 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
838 from_utf8(N_(" not known")));
842 bool change_layout = (current_layout != layout);
844 if (!change_layout && cur.selection() &&
845 cur.selBegin().pit() != cur.selEnd().pit())
847 pit_type spit = cur.selBegin().pit();
848 pit_type epit = cur.selEnd().pit() + 1;
849 while (spit != epit) {
850 if (pars_[spit].layout()->name() != current_layout) {
851 change_layout = true;
859 current_layout = layout;
860 setLayout(cur, layout);
861 // inform the GUI that the layout has changed.
862 bv->layoutChanged(layout);
868 case LFUN_CLIPBOARD_PASTE:
869 pasteString(cur, theClipboard().get(), cmd.argument());
872 case LFUN_PRIMARY_SELECTION_PASTE:
873 pasteString(cur, theSelection().get(), cmd.argument());
876 case LFUN_UNICODE_INSERT: {
877 if (cmd.argument().empty())
879 docstring hexstring = cmd.argument();
880 if (lyx::support::isHex(hexstring)) {
881 char_type c = lyx::support::hexToInt(hexstring);
882 if (c > 32 && c < 0x10ffff) {
883 lyxerr << "Inserting c: " << c << endl;
884 docstring s = docstring(1, c);
885 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
891 case LFUN_QUOTE_INSERT: {
892 cap::replaceSelection(cur);
893 Paragraph & par = cur.paragraph();
894 pos_type pos = cur.pos();
898 else if (cur.prevInset() && cur.prevInset()->isSpace())
901 c = par.getChar(pos - 1);
903 LyXLayout_ptr const & style = par.layout();
905 BufferParams const & bufparams = bv->buffer()->params();
906 if (!style->pass_thru
907 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
908 string arg = to_utf8(cmd.argument());
910 cur.insert(new InsetQuotes(c,
911 bufparams.quotes_language,
912 InsetQuotes::SingleQ));
914 cur.insert(new InsetQuotes(c,
915 bufparams.quotes_language,
916 InsetQuotes::DoubleQ));
920 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
924 case LFUN_DATE_INSERT:
925 if (cmd.argument().empty())
926 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
927 formatted_time(current_time())));
929 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
930 formatted_time(current_time(), to_utf8(cmd.argument()))));
933 case LFUN_MOUSE_TRIPLE:
934 if (cmd.button() == mouse_button::button1) {
940 theSelection().haveSelection(cur.selection());
944 case LFUN_MOUSE_DOUBLE:
945 if (cmd.button() == mouse_button::button1) {
946 selectWord(cur, WHOLE_WORD_STRICT);
948 theSelection().haveSelection(cur.selection());
952 // Single-click on work area
953 case LFUN_MOUSE_PRESS: {
954 // Right click on a footnote flag opens float menu
955 if (cmd.button() == mouse_button::button3)
956 cur.clearSelection();
958 // Middle button press pastes if we have a selection
959 // We do this here as if the selection was inside an inset
960 // it could get cleared on the unlocking of the inset so
961 // we have to check this first
962 bool paste_internally = false;
963 if (cmd.button() == mouse_button::button2 && cur.selection()) {
964 lyx::dispatch(FuncRequest(LFUN_COPY));
965 paste_internally = true;
968 // we have to update after dePM triggered
969 bool update = bv->mouseSetCursor(cur);
971 // Insert primary selection with middle mouse
972 // if there is a local selection in the current buffer,
974 if (cmd.button() == mouse_button::button2) {
975 if (paste_internally)
976 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
978 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
981 if (!update && cmd.button() == mouse_button::button1) {
989 case LFUN_MOUSE_MOTION: {
990 // Only use motion with button 1
991 //if (cmd.button() != mouse_button::button1)
994 // ignore motions deeper nested than the real anchor
995 LCursor & bvcur = cur.bv().cursor();
996 if (bvcur.anchor_.hasPart(cur)) {
997 CursorSlice old = bvcur.top();
999 int const wh = bv->workHeight();
1000 int const y = std::max(0, std::min(wh - 1, cmd.y));
1002 setCursorFromCoordinates(cur, cmd.x, y);
1003 cur.x_target() = cmd.x;
1005 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1007 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1008 // This is to allow jumping over large insets
1009 if (cur.top() == old) {
1011 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1013 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1016 if (cur.top() == old)
1019 // don't set anchor_
1020 bvcur.setCursor(cur);
1021 bvcur.selection() = true;
1022 //lyxerr << "MOTION: " << bv->cursor() << endl;
1030 case LFUN_MOUSE_RELEASE: {
1031 if (cmd.button() == mouse_button::button2)
1035 if (cmd.button() == mouse_button::button1) {
1036 if (cur.selection())
1037 theSelection().haveSelection(cur.selection());
1038 needsUpdate = false;
1046 case LFUN_SELF_INSERT: {
1047 if (cmd.argument().empty())
1050 // Automatically delete the currently selected
1051 // text and replace it with what is being
1052 // typed in now. Depends on lyxrc settings
1053 // "auto_region_delete", which defaults to
1056 if (lyxrc.auto_region_delete) {
1057 if (cur.selection())
1058 cutSelection(cur, false, false);
1059 theSelection().haveSelection(false);
1062 cur.clearSelection();
1063 LyXFont const old_font = real_current_font;
1065 docstring::const_iterator cit = cmd.argument().begin();
1066 docstring::const_iterator end = cmd.argument().end();
1067 for (; cit != end; ++cit)
1069 bv->getIntl().getTransManager().
1070 translateAndInsert(*cit, this);
1072 insertChar(bv->cursor(), *cit);
1076 moveCursor(cur, false);
1080 case LFUN_URL_INSERT: {
1081 InsetCommandParams p("url");
1082 string const data = InsetCommandMailer::params2string("url", p);
1083 bv->showInsetDialog("url", data, 0);
1087 case LFUN_HTML_INSERT: {
1088 InsetCommandParams p("htmlurl");
1089 string const data = InsetCommandMailer::params2string("url", p);
1090 bv->showInsetDialog("url", data, 0);
1094 case LFUN_LABEL_INSERT: {
1095 InsetCommandParams p("label");
1096 // Try to generate a valid label
1097 p["name"] = (cmd.argument().empty()) ?
1098 cur.getPossibleLabel() :
1100 string const data = InsetCommandMailer::params2string("label", p);
1102 if (cmd.argument().empty()) {
1103 bv->showInsetDialog("label", data, 0);
1105 FuncRequest fr(LFUN_INSET_INSERT, data);
1113 case LFUN_LIST_INSERT:
1114 case LFUN_THEOREM_INSERT:
1115 case LFUN_CAPTION_INSERT:
1117 case LFUN_NOTE_INSERT:
1118 case LFUN_CHARSTYLE_INSERT:
1119 case LFUN_BOX_INSERT:
1120 case LFUN_BRANCH_INSERT:
1121 case LFUN_BIBITEM_INSERT:
1122 case LFUN_ERT_INSERT:
1123 case LFUN_FOOTNOTE_INSERT:
1124 case LFUN_MARGINALNOTE_INSERT:
1125 case LFUN_OPTIONAL_INSERT:
1126 case LFUN_ENVIRONMENT_INSERT:
1127 // Open the inset, and move the current selection
1129 doInsertInset(cur, this, cmd, true, true);
1133 case LFUN_TABULAR_INSERT:
1134 // if there were no arguments, just open the dialog
1135 if (doInsertInset(cur, this, cmd, false, true))
1138 bv->showDialog("tabularcreate");
1142 case LFUN_FLOAT_INSERT:
1143 case LFUN_FLOAT_WIDE_INSERT:
1144 case LFUN_WRAP_INSERT:
1145 doInsertInset(cur, this, cmd, true, true);
1147 // FIXME: the "Caption" name should not be hardcoded,
1148 // but given by the float definition.
1149 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1152 case LFUN_INDEX_INSERT:
1153 case LFUN_NOMENCL_INSERT: {
1154 InsetBase * inset = createInset(&cur.bv(), cmd);
1159 cur.clearSelection();
1160 insertInset(cur, inset);
1161 inset->edit(cur, true);
1162 // Show the dialog for the nomenclature entry, since the
1163 // description entry still needs to be filled in.
1164 if (cmd.action == LFUN_NOMENCL_INSERT)
1165 InsetCommandMailer("nomenclature",
1166 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1171 case LFUN_INDEX_PRINT:
1172 case LFUN_NOMENCL_PRINT:
1173 case LFUN_TOC_INSERT:
1174 case LFUN_HFILL_INSERT:
1175 case LFUN_LINE_INSERT:
1176 case LFUN_PAGEBREAK_INSERT:
1177 case LFUN_CLEARPAGE_INSERT:
1178 case LFUN_CLEARDOUBLEPAGE_INSERT:
1180 doInsertInset(cur, this, cmd, false, false);
1184 case LFUN_DEPTH_DECREMENT:
1185 changeDepth(cur, DEC_DEPTH);
1188 case LFUN_DEPTH_INCREMENT:
1189 changeDepth(cur, INC_DEPTH);
1192 case LFUN_MATH_DISPLAY:
1193 mathDispatch(cur, cmd, true);
1196 case LFUN_MATH_IMPORT_SELECTION:
1197 case LFUN_MATH_MODE:
1198 if (cmd.argument() == "on")
1199 // don't pass "on" as argument
1200 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1202 mathDispatch(cur, cmd, false);
1205 case LFUN_MATH_MACRO:
1206 if (cmd.argument().empty())
1207 cur.errorMessage(from_utf8(N_("Missing argument")));
1209 string s = to_utf8(cmd.argument());
1210 string const s1 = token(s, ' ', 1);
1211 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1212 string const s2 = token(s, ' ', 2);
1213 string const type = s2.empty() ? "newcommand" : s2;
1214 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1215 //cur.nextInset()->edit(cur, true);
1219 // passthrough hat and underscore outside mathed:
1220 case LFUN_MATH_SUBSCRIPT:
1221 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1223 case LFUN_MATH_SUPERSCRIPT:
1224 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1227 case LFUN_MATH_INSERT:
1228 case LFUN_MATH_MATRIX:
1229 case LFUN_MATH_DELIM:
1230 case LFUN_MATH_BIGDELIM: {
1231 cur.insert(new InsetMathHull(hullSimple));
1232 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1237 case LFUN_FONT_EMPH: {
1238 LyXFont font(LyXFont::ALL_IGNORE);
1239 font.setEmph(LyXFont::TOGGLE);
1240 toggleAndShow(cur, this, font);
1244 case LFUN_FONT_BOLD: {
1245 LyXFont font(LyXFont::ALL_IGNORE);
1246 font.setSeries(LyXFont::BOLD_SERIES);
1247 toggleAndShow(cur, this, font);
1251 case LFUN_FONT_NOUN: {
1252 LyXFont font(LyXFont::ALL_IGNORE);
1253 font.setNoun(LyXFont::TOGGLE);
1254 toggleAndShow(cur, this, font);
1258 case LFUN_FONT_CODE: {
1259 LyXFont font(LyXFont::ALL_IGNORE);
1260 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1261 toggleAndShow(cur, this, font);
1265 case LFUN_FONT_SANS: {
1266 LyXFont font(LyXFont::ALL_IGNORE);
1267 font.setFamily(LyXFont::SANS_FAMILY);
1268 toggleAndShow(cur, this, font);
1272 case LFUN_FONT_ROMAN: {
1273 LyXFont font(LyXFont::ALL_IGNORE);
1274 font.setFamily(LyXFont::ROMAN_FAMILY);
1275 toggleAndShow(cur, this, font);
1279 case LFUN_FONT_DEFAULT: {
1280 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1281 toggleAndShow(cur, this, font);
1285 case LFUN_FONT_UNDERLINE: {
1286 LyXFont font(LyXFont::ALL_IGNORE);
1287 font.setUnderbar(LyXFont::TOGGLE);
1288 toggleAndShow(cur, this, font);
1292 case LFUN_FONT_SIZE: {
1293 LyXFont font(LyXFont::ALL_IGNORE);
1294 font.setLyXSize(to_utf8(cmd.argument()));
1295 toggleAndShow(cur, this, font);
1299 case LFUN_LANGUAGE: {
1300 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1303 LyXFont font(LyXFont::ALL_IGNORE);
1304 font.setLanguage(lang);
1305 toggleAndShow(cur, this, font);
1310 case LFUN_FONT_FREE_APPLY:
1311 toggleAndShow(cur, this, freefont, toggleall);
1312 cur.message(_("Character set"));
1315 // Set the freefont using the contents of \param data dispatched from
1316 // the frontends and apply it at the current cursor location.
1317 case LFUN_FONT_FREE_UPDATE: {
1320 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1323 toggleAndShow(cur, this, freefont, toggleall);
1324 cur.message(_("Character set"));
1329 case LFUN_FINISHED_LEFT:
1330 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1333 case LFUN_FINISHED_RIGHT:
1334 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1338 case LFUN_FINISHED_UP:
1339 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1343 case LFUN_FINISHED_DOWN:
1344 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1348 case LFUN_LAYOUT_PARAGRAPH: {
1350 params2string(cur.paragraph(), data);
1351 data = "show\n" + data;
1352 bv->showDialogWithData("paragraph", data);
1356 case LFUN_PARAGRAPH_UPDATE: {
1358 params2string(cur.paragraph(), data);
1360 // Will the paragraph accept changes from the dialog?
1361 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1363 data = "update " + convert<string>(accept) + '\n' + data;
1364 bv->updateDialog("paragraph", data);
1368 case LFUN_ACCENT_UMLAUT:
1369 case LFUN_ACCENT_CIRCUMFLEX:
1370 case LFUN_ACCENT_GRAVE:
1371 case LFUN_ACCENT_ACUTE:
1372 case LFUN_ACCENT_TILDE:
1373 case LFUN_ACCENT_CEDILLA:
1374 case LFUN_ACCENT_MACRON:
1375 case LFUN_ACCENT_DOT:
1376 case LFUN_ACCENT_UNDERDOT:
1377 case LFUN_ACCENT_UNDERBAR:
1378 case LFUN_ACCENT_CARON:
1379 case LFUN_ACCENT_SPECIAL_CARON:
1380 case LFUN_ACCENT_BREVE:
1381 case LFUN_ACCENT_TIE:
1382 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1383 case LFUN_ACCENT_CIRCLE:
1384 case LFUN_ACCENT_OGONEK:
1385 theLyXFunc().handleKeyFunc(cmd.action);
1386 if (!cmd.argument().empty())
1387 // FIXME: Are all these characters encoded in one byte in utf8?
1388 bv->getIntl().getTransManager()
1389 .translateAndInsert(cmd.argument()[0], this, cur);
1392 case LFUN_FLOAT_LIST: {
1393 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1394 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1395 // not quite sure if we want this...
1397 cur.clearSelection();
1398 breakParagraph(cur);
1400 if (cur.lastpos() != 0) {
1402 breakParagraph(cur);
1405 setLayout(cur, tclass.defaultLayoutName());
1406 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1407 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1410 lyxerr << "Non-existent float type: "
1411 << to_utf8(cmd.argument()) << endl;
1416 case LFUN_CHANGE_ACCEPT: {
1421 case LFUN_CHANGE_REJECT: {
1426 case LFUN_THESAURUS_ENTRY: {
1427 docstring arg = cmd.argument();
1429 arg = cur.selectionAsString(false);
1431 if (arg.size() > 100 || arg.empty()) {
1432 // Get word or selection
1433 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1434 arg = cur.selectionAsString(false);
1437 bv->showDialogWithData("thesaurus", to_utf8(arg));
1441 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1442 // Given data, an encoding of the ParagraphParameters
1443 // generated in the Paragraph dialog, this function sets
1444 // the current paragraph appropriately.
1445 istringstream is(to_utf8(cmd.argument()));
1448 ParagraphParameters params;
1453 params.labelWidthString(),
1455 cur.message(_("Paragraph layout set"));
1460 if (cur.selection()) {
1461 cur.selection() = false;
1464 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1469 lyxerr[Debug::ACTION]
1470 << BOOST_CURRENT_FUNCTION
1471 << ": Command " << cmd
1472 << " not DISPATCHED by LyXText" << endl;
1477 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1479 // FIXME: The cursor flag is reset two lines below
1480 // so we need to check here if some of the LFUN did touch that.
1481 // for now only LyXText::erase() and LyXText::backspace() do that.
1482 // The plan is to verify all the LFUNs and then to remove this
1483 // singleParUpdate boolean altogether.
1484 if (cur.result().update() & Update::Force) {
1485 singleParUpdate = false;
1489 // FIXME: the following code should go in favor of fine grained
1490 // update flag treatment.
1491 if (singleParUpdate) {
1492 // Inserting characters does not change par height
1493 ParagraphMetrics const & pms
1494 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1495 if (pms.dim().height()
1496 == olddim.height()) {
1497 // if so, update _only_ this paragraph
1498 cur.updateFlags(Update::SinglePar |
1500 Update::MultiParSel);
1507 && &oldTopSlice.inset() == &cur.inset()
1508 && oldTopSlice.idx() == cur.idx()
1509 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1510 && !cur.selection())
1511 // FIXME: it would be better if we could just do this
1513 //if (cur.result().update() != Update::FitCursor)
1516 // But some LFUNs do not set Update::FitCursor when needed, so we
1517 // do it for all. This is not very harmfull as FitCursor will provoke
1518 // a full redraw only if needed but still, a proper review of all LFUN
1519 // should be done and this needsUpdate boolean can then be removed.
1520 cur.updateFlags(Update::FitCursor);
1522 cur.updateFlags(Update::Force | Update::FitCursor);
1526 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1527 FuncStatus & flag) const
1529 BOOST_ASSERT(cur.text() == this);
1531 LyXFont const & font = real_current_font;
1533 InsetBase::Code code = InsetBase::NO_CODE;
1535 switch (cmd.action) {
1537 case LFUN_DEPTH_DECREMENT:
1538 enable = changeDepthAllowed(cur, DEC_DEPTH);
1541 case LFUN_DEPTH_INCREMENT:
1542 enable = changeDepthAllowed(cur, INC_DEPTH);
1546 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1549 case LFUN_BIBITEM_INSERT:
1550 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1553 case LFUN_DIALOG_SHOW_NEW_INSET:
1554 if (cmd.argument() == "bibitem")
1555 code = InsetBase::BIBITEM_CODE;
1556 else if (cmd.argument() == "bibtex")
1557 code = InsetBase::BIBTEX_CODE;
1558 else if (cmd.argument() == "box")
1559 code = InsetBase::BOX_CODE;
1560 else if (cmd.argument() == "branch")
1561 code = InsetBase::BRANCH_CODE;
1562 else if (cmd.argument() == "citation")
1563 code = InsetBase::CITE_CODE;
1564 else if (cmd.argument() == "ert")
1565 code = InsetBase::ERT_CODE;
1566 else if (cmd.argument() == "external")
1567 code = InsetBase::EXTERNAL_CODE;
1568 else if (cmd.argument() == "float")
1569 code = InsetBase::FLOAT_CODE;
1570 else if (cmd.argument() == "graphics")
1571 code = InsetBase::GRAPHICS_CODE;
1572 else if (cmd.argument() == "include")
1573 code = InsetBase::INCLUDE_CODE;
1574 else if (cmd.argument() == "index")
1575 code = InsetBase::INDEX_CODE;
1576 else if (cmd.argument() == "nomenclature")
1577 code = InsetBase::NOMENCL_CODE;
1578 else if (cmd.argument() == "label")
1579 code = InsetBase::LABEL_CODE;
1580 else if (cmd.argument() == "note")
1581 code = InsetBase::NOTE_CODE;
1582 else if (cmd.argument() == "ref")
1583 code = InsetBase::REF_CODE;
1584 else if (cmd.argument() == "toc")
1585 code = InsetBase::TOC_CODE;
1586 else if (cmd.argument() == "url")
1587 code = InsetBase::URL_CODE;
1588 else if (cmd.argument() == "vspace")
1589 code = InsetBase::VSPACE_CODE;
1590 else if (cmd.argument() == "wrap")
1591 code = InsetBase::WRAP_CODE;
1594 case LFUN_ERT_INSERT:
1595 code = InsetBase::ERT_CODE;
1597 case LFUN_FOOTNOTE_INSERT:
1598 code = InsetBase::FOOT_CODE;
1600 case LFUN_TABULAR_INSERT:
1601 code = InsetBase::TABULAR_CODE;
1603 case LFUN_MARGINALNOTE_INSERT:
1604 code = InsetBase::MARGIN_CODE;
1606 case LFUN_FLOAT_INSERT:
1607 case LFUN_FLOAT_WIDE_INSERT:
1608 code = InsetBase::FLOAT_CODE;
1610 case LFUN_WRAP_INSERT:
1611 code = InsetBase::WRAP_CODE;
1613 case LFUN_FLOAT_LIST:
1614 code = InsetBase::FLOAT_LIST_CODE;
1617 case LFUN_LIST_INSERT:
1618 code = InsetBase::LIST_CODE;
1620 case LFUN_THEOREM_INSERT:
1621 code = InsetBase::THEOREM_CODE;
1624 case LFUN_CAPTION_INSERT:
1625 code = InsetBase::CAPTION_CODE;
1627 case LFUN_NOTE_INSERT:
1628 code = InsetBase::NOTE_CODE;
1630 case LFUN_CHARSTYLE_INSERT:
1631 code = InsetBase::CHARSTYLE_CODE;
1632 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1635 case LFUN_BOX_INSERT:
1636 code = InsetBase::BOX_CODE;
1638 case LFUN_BRANCH_INSERT:
1639 code = InsetBase::BRANCH_CODE;
1640 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1643 case LFUN_LABEL_INSERT:
1644 code = InsetBase::LABEL_CODE;
1646 case LFUN_OPTIONAL_INSERT:
1647 code = InsetBase::OPTARG_CODE;
1648 enable = numberOfOptArgs(cur.paragraph())
1649 < cur.paragraph().layout()->optionalargs;
1651 case LFUN_ENVIRONMENT_INSERT:
1652 code = InsetBase::BOX_CODE;
1654 case LFUN_INDEX_INSERT:
1655 code = InsetBase::INDEX_CODE;
1657 case LFUN_INDEX_PRINT:
1658 code = InsetBase::INDEX_PRINT_CODE;
1660 case LFUN_NOMENCL_INSERT:
1661 code = InsetBase::NOMENCL_CODE;
1663 case LFUN_NOMENCL_PRINT:
1664 code = InsetBase::NOMENCL_PRINT_CODE;
1666 case LFUN_TOC_INSERT:
1667 code = InsetBase::TOC_CODE;
1669 case LFUN_HTML_INSERT:
1670 case LFUN_URL_INSERT:
1671 code = InsetBase::URL_CODE;
1673 case LFUN_QUOTE_INSERT:
1674 // always allow this, since we will inset a raw quote
1675 // if an inset is not allowed.
1677 case LFUN_HYPHENATION_POINT_INSERT:
1678 case LFUN_LIGATURE_BREAK_INSERT:
1679 case LFUN_HFILL_INSERT:
1680 case LFUN_MENU_SEPARATOR_INSERT:
1681 case LFUN_DOTS_INSERT:
1682 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1683 code = InsetBase::SPECIALCHAR_CODE;
1685 case LFUN_SPACE_INSERT:
1686 // slight hack: we know this is allowed in math mode
1688 code = InsetBase::SPACE_CODE;
1691 case LFUN_INSET_MODIFY:
1692 // We need to disable this, because we may get called for a
1694 // InsetTabular::getStatus() -> InsetText::getStatus()
1695 // and we don't handle LFUN_INSET_MODIFY.
1699 case LFUN_FONT_EMPH:
1700 flag.setOnOff(font.emph() == LyXFont::ON);
1703 case LFUN_FONT_NOUN:
1704 flag.setOnOff(font.noun() == LyXFont::ON);
1707 case LFUN_FONT_BOLD:
1708 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1711 case LFUN_FONT_SANS:
1712 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1715 case LFUN_FONT_ROMAN:
1716 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1719 case LFUN_FONT_CODE:
1720 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1725 enable = cur.selection();
1729 // FIXME: This is not correct, but the correct code below is
1731 enable = cap::numberOfSelections() > 0 ||
1732 !theClipboard().isInternal();
1734 if (cmd.argument().empty()) {
1735 if (theClipboard().isInternal())
1736 enable = cap::numberOfSelections() > 0;
1738 enable = !theClipboard().get().empty();
1739 } else if (isStrUnsignedInt(to_utf8(cmd.argument()))) {
1740 int n = convert<unsigned int>(to_utf8(cmd.argument()));
1741 enable = cap::numberOfSelections() > n;
1748 case LFUN_PARAGRAPH_MOVE_UP:
1749 enable = cur.pit() > 0 && !cur.selection();
1752 case LFUN_PARAGRAPH_MOVE_DOWN:
1753 enable = cur.pit() < cur.lastpit() && !cur.selection();
1756 case LFUN_INSET_DISSOLVE:
1757 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1760 case LFUN_CHANGE_ACCEPT:
1761 case LFUN_CHANGE_REJECT:
1762 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1763 // In principle, these LFUNs should only be enabled if there
1764 // is a change at the current position/in the current selection.
1765 // However, without proper optimizations, this will inevitably
1766 // result in unacceptable performance - just imagine a user who
1767 // wants to select the complete content of a long document.
1771 case LFUN_WORD_DELETE_FORWARD:
1772 case LFUN_WORD_DELETE_BACKWARD:
1773 case LFUN_LINE_DELETE:
1774 case LFUN_WORD_FORWARD:
1775 case LFUN_WORD_BACKWARD:
1776 case LFUN_CHAR_FORWARD:
1777 case LFUN_CHAR_FORWARD_SELECT:
1778 case LFUN_CHAR_BACKWARD:
1779 case LFUN_CHAR_BACKWARD_SELECT:
1781 case LFUN_UP_SELECT:
1783 case LFUN_DOWN_SELECT:
1784 case LFUN_PARAGRAPH_UP_SELECT:
1785 case LFUN_PARAGRAPH_DOWN_SELECT:
1786 case LFUN_SCREEN_UP_SELECT:
1787 case LFUN_SCREEN_DOWN_SELECT:
1788 case LFUN_LINE_BEGIN_SELECT:
1789 case LFUN_LINE_END_SELECT:
1790 case LFUN_WORD_FORWARD_SELECT:
1791 case LFUN_WORD_BACKWARD_SELECT:
1792 case LFUN_WORD_SELECT:
1793 case LFUN_PARAGRAPH_UP:
1794 case LFUN_PARAGRAPH_DOWN:
1795 case LFUN_SCREEN_UP:
1796 case LFUN_SCREEN_DOWN:
1797 case LFUN_LINE_BEGIN:
1799 case LFUN_BREAK_LINE:
1800 case LFUN_CHAR_DELETE_FORWARD:
1801 case LFUN_DELETE_FORWARD_SKIP:
1802 case LFUN_CHAR_DELETE_BACKWARD:
1803 case LFUN_DELETE_BACKWARD_SKIP:
1804 case LFUN_BREAK_PARAGRAPH:
1805 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1806 case LFUN_BREAK_PARAGRAPH_SKIP:
1807 case LFUN_PARAGRAPH_SPACING:
1808 case LFUN_INSET_INSERT:
1809 case LFUN_WORD_UPCASE:
1810 case LFUN_WORD_LOWCASE:
1811 case LFUN_WORD_CAPITALIZE:
1812 case LFUN_CHARS_TRANSPOSE:
1813 case LFUN_SERVER_GET_XY:
1814 case LFUN_SERVER_SET_XY:
1815 case LFUN_SERVER_GET_FONT:
1816 case LFUN_SERVER_GET_LAYOUT:
1818 case LFUN_CLIPBOARD_PASTE:
1819 case LFUN_PRIMARY_SELECTION_PASTE:
1820 case LFUN_DATE_INSERT:
1821 case LFUN_SELF_INSERT:
1822 case LFUN_LINE_INSERT:
1823 case LFUN_PAGEBREAK_INSERT:
1824 case LFUN_CLEARPAGE_INSERT:
1825 case LFUN_CLEARDOUBLEPAGE_INSERT:
1826 case LFUN_MATH_DISPLAY:
1827 case LFUN_MATH_IMPORT_SELECTION:
1828 case LFUN_MATH_MODE:
1829 case LFUN_MATH_MACRO:
1830 case LFUN_MATH_MATRIX:
1831 case LFUN_MATH_DELIM:
1832 case LFUN_MATH_BIGDELIM:
1833 case LFUN_MATH_SUBSCRIPT:
1834 case LFUN_MATH_SUPERSCRIPT:
1835 case LFUN_FONT_DEFAULT:
1836 case LFUN_FONT_UNDERLINE:
1837 case LFUN_FONT_SIZE:
1839 case LFUN_FONT_FREE_APPLY:
1840 case LFUN_FONT_FREE_UPDATE:
1841 case LFUN_LAYOUT_PARAGRAPH:
1842 case LFUN_PARAGRAPH_UPDATE:
1843 case LFUN_ACCENT_UMLAUT:
1844 case LFUN_ACCENT_CIRCUMFLEX:
1845 case LFUN_ACCENT_GRAVE:
1846 case LFUN_ACCENT_ACUTE:
1847 case LFUN_ACCENT_TILDE:
1848 case LFUN_ACCENT_CEDILLA:
1849 case LFUN_ACCENT_MACRON:
1850 case LFUN_ACCENT_DOT:
1851 case LFUN_ACCENT_UNDERDOT:
1852 case LFUN_ACCENT_UNDERBAR:
1853 case LFUN_ACCENT_CARON:
1854 case LFUN_ACCENT_SPECIAL_CARON:
1855 case LFUN_ACCENT_BREVE:
1856 case LFUN_ACCENT_TIE:
1857 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1858 case LFUN_ACCENT_CIRCLE:
1859 case LFUN_ACCENT_OGONEK:
1860 case LFUN_THESAURUS_ENTRY:
1861 case LFUN_PARAGRAPH_PARAMS_APPLY:
1863 case LFUN_BUFFER_END:
1864 case LFUN_BUFFER_BEGIN:
1865 case LFUN_BUFFER_BEGIN_SELECT:
1866 case LFUN_BUFFER_END_SELECT:
1867 case LFUN_UNICODE_INSERT:
1868 // these are handled in our dispatch()
1876 if (code != InsetBase::NO_CODE
1877 && (cur.empty() || !cur.inset().insetAllowed(code)))
1880 flag.enabled(enable);
1885 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1886 docstring const & argument)
1888 cur.clearSelection();
1889 if (!clip.empty()) {
1891 if (argument == "paragraph")
1892 insertStringAsParagraphs(cur, clip);
1894 insertStringAsLines(cur, clip);