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 cur.insert(new InsetMathHull(hullSimple));
148 BOOST_ASSERT(old_pos == cur.pos());
149 cur.nextInset()->edit(cur, true);
150 // don't do that also for LFUN_MATH_MODE
151 // unless you want end up with always changing
152 // to mathrm when opening an inlined inset --
153 // I really hate "LyXfunc overloading"...
155 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
156 // Avoid an unnecessary undo step if cmd.argument
158 if (!cmd.argument().empty())
159 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
162 // create a macro if we see "\\newcommand"
163 // somewhere, and an ordinary formula
165 if (sel.find(from_ascii("\\newcommand")) == string::npos
166 && sel.find(from_ascii("\\def")) == string::npos)
168 InsetMathHull * formula = new InsetMathHull;
169 istringstream is(to_utf8(sel));
172 formula->read(cur.buffer(), lex);
173 if (formula->getType() == hullNone)
174 // Don't create pseudo formulas if
175 // delimiters are left out
176 formula->mutate(hullSimple);
179 cur.insert(new MathMacroTemplate(sel));
182 cur.message(from_utf8(N_("Math editor mode")));
191 string const freefont2string()
194 if (font2string(freefont, toggleall, data))
201 void LyXText::cursorPrevious(LCursor & cur)
203 pos_type cpos = cur.pos();
204 pit_type cpar = cur.pit();
206 int x = cur.x_target();
207 setCursorFromCoordinates(cur, x, 0);
208 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
210 if (cpar == cur.pit() && cpos == cur.pos())
211 // we have a row which is taller than the workarea. The
212 // simplest solution is to move to the previous row instead.
213 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
216 cur.updateFlags(Update::Force | Update::FitCursor);
220 void LyXText::cursorNext(LCursor & cur)
222 pos_type cpos = cur.pos();
223 pit_type cpar = cur.pit();
225 int x = cur.x_target();
226 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
227 cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
229 if (cpar == cur.pit() && cpos == cur.pos())
230 // we have a row which is taller than the workarea. The
231 // simplest solution is to move to the next row instead.
233 FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
236 cur.updateFlags(Update::Force | Update::FitCursor);
242 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
244 cap::replaceSelection(cur);
245 cur.insert(new InsetSpecialChar(kind));
250 bool doInsertInset(LCursor & cur, LyXText * text,
251 FuncRequest const & cmd, bool edit, bool pastesel)
253 InsetBase * inset = createInset(&cur.bv(), cmd);
259 if (cur.selection()) {
260 lyx::dispatch(FuncRequest(LFUN_CUT));
263 text->insertInset(cur, inset);
266 inset->edit(cur, true);
268 if (gotsel && pastesel) {
269 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
270 // reset first par to default
271 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
272 LyXLayout_ptr const layout =
273 cur.buffer().params().getLyXTextClass().defaultLayout();
274 cur.text()->paragraphs().begin()->layout(layout);
284 void LyXText::number(LCursor & cur)
286 LyXFont font(LyXFont::ALL_IGNORE);
287 font.setNumber(LyXFont::TOGGLE);
288 toggleAndShow(cur, this, font);
292 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
294 return par.isRightToLeftPar(buffer.params());
298 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
300 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
302 // FIXME: We use the update flag to indicates wether a singlePar or a
303 // full screen update is needed. We reset it here but shall we restore it
307 BOOST_ASSERT(cur.text() == this);
308 BufferView * bv = &cur.bv();
309 CursorSlice oldTopSlice = cur.top();
310 bool oldBoundary = cur.boundary();
311 bool sel = cur.selection();
312 // Signals that, even if needsUpdate == false, an update of the
313 // cursor paragraph is required
314 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
315 LyXAction::SingleParUpdate);
316 // Signals that a full-screen update is required
317 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
318 LyXAction::NoUpdate) || singleParUpdate);
319 // Remember the old paragraph metric (_outer_ paragraph!)
320 ParagraphMetrics const & pm = cur.bv().parMetrics(
321 cur.bottom().text(), cur.bottom().pit());
322 Dimension olddim = pm.dim();
324 switch (cmd.action) {
326 case LFUN_PARAGRAPH_MOVE_DOWN: {
327 pit_type const pit = cur.pit();
328 recUndo(cur, pit, pit + 1);
330 std::swap(pars_[pit], pars_[pit + 1]);
332 ParIterator begin(cur);
334 ParIterator end = boost::next(ParIterator(cur));
335 updateLabels(cur.buffer(), begin, end);
341 case LFUN_PARAGRAPH_MOVE_UP: {
342 pit_type const pit = cur.pit();
343 recUndo(cur, pit - 1, pit);
345 std::swap(pars_[pit], pars_[pit - 1]);
347 ParIterator end = boost::next(ParIterator(cur));
349 ParIterator begin(cur);
350 updateLabels(cur.buffer(), begin, end);
356 case LFUN_APPENDIX: {
357 Paragraph & par = cur.paragraph();
358 bool start = !par.params().startOfAppendix();
361 #warning The code below only makes sense at top level.
362 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
364 // ensure that we have only one start_of_appendix in this document
365 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
366 if (pars_[tmp].params().startOfAppendix()) {
368 pars_[tmp].params().startOfAppendix(false);
374 par.params().startOfAppendix(start);
376 // we can set the refreshing parameters now
377 updateLabels(cur.buffer());
381 case LFUN_WORD_DELETE_FORWARD:
382 cur.clearSelection();
383 deleteWordForward(cur);
384 finishChange(cur, false);
387 case LFUN_WORD_DELETE_BACKWARD:
388 cur.clearSelection();
389 deleteWordBackward(cur);
390 finishChange(cur, false);
393 case LFUN_LINE_DELETE:
394 cur.clearSelection();
395 deleteLineForward(cur);
396 finishChange(cur, false);
399 case LFUN_BUFFER_BEGIN:
400 case LFUN_BUFFER_BEGIN_SELECT:
401 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
402 if (cur.depth() == 1) {
403 needsUpdate |= cursorTop(cur);
409 case LFUN_BUFFER_END:
410 case LFUN_BUFFER_END_SELECT:
411 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
412 if (cur.depth() == 1) {
413 needsUpdate |= cursorBottom(cur);
419 case LFUN_CHAR_FORWARD:
420 case LFUN_CHAR_FORWARD_SELECT:
421 //lyxerr << BOOST_CURRENT_FUNCTION
422 // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
423 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
424 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
425 needsUpdate |= cursorLeft(cur);
427 needsUpdate |= cursorRight(cur);
429 if (!needsUpdate && oldTopSlice == cur.top()
430 && cur.boundary() == oldBoundary) {
432 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
436 case LFUN_CHAR_BACKWARD:
437 case LFUN_CHAR_BACKWARD_SELECT:
438 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
439 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
440 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
441 needsUpdate |= cursorRight(cur);
443 needsUpdate |= cursorLeft(cur);
445 if (!needsUpdate && oldTopSlice == cur.top()
446 && cur.boundary() == oldBoundary) {
448 cmd = FuncRequest(LFUN_FINISHED_LEFT);
454 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
455 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
457 needsUpdate |= cursorUp(cur);
459 if (!needsUpdate && oldTopSlice == cur.top()
460 && cur.boundary() == oldBoundary) {
462 cmd = FuncRequest(LFUN_FINISHED_UP);
467 case LFUN_DOWN_SELECT:
468 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
469 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
470 needsUpdate |= cursorDown(cur);
472 if (!needsUpdate && oldTopSlice == cur.top() &&
473 cur.boundary() == oldBoundary)
476 cmd = FuncRequest(LFUN_FINISHED_DOWN);
480 case LFUN_PARAGRAPH_UP:
481 case LFUN_PARAGRAPH_UP_SELECT:
482 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
483 needsUpdate |= cursorUpParagraph(cur);
486 case LFUN_PARAGRAPH_DOWN:
487 case LFUN_PARAGRAPH_DOWN_SELECT:
488 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
489 needsUpdate |= cursorDownParagraph(cur);
493 case LFUN_SCREEN_UP_SELECT:
494 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
495 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
497 cmd = FuncRequest(LFUN_FINISHED_UP);
503 case LFUN_SCREEN_DOWN:
504 case LFUN_SCREEN_DOWN_SELECT:
505 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
506 if (cur.pit() == cur.lastpit()
507 && cur.textRow().endpos() == cur.lastpos()) {
509 cmd = FuncRequest(LFUN_FINISHED_DOWN);
515 case LFUN_LINE_BEGIN:
516 case LFUN_LINE_BEGIN_SELECT:
517 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
518 needsUpdate |= cursorHome(cur);
522 case LFUN_LINE_END_SELECT:
523 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
524 needsUpdate |= cursorEnd(cur);
527 case LFUN_WORD_FORWARD:
528 case LFUN_WORD_FORWARD_SELECT:
529 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
530 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
531 needsUpdate |= cursorLeftOneWord(cur);
533 needsUpdate |= cursorRightOneWord(cur);
536 case LFUN_WORD_BACKWARD:
537 case LFUN_WORD_BACKWARD_SELECT:
538 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
539 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
540 needsUpdate |= cursorRightOneWord(cur);
542 needsUpdate |= cursorLeftOneWord(cur);
545 case LFUN_WORD_SELECT: {
546 selectWord(cur, WHOLE_WORD);
547 finishChange(cur, true);
551 case LFUN_BREAK_LINE: {
552 // Not allowed by LaTeX (labels or empty par)
553 if (cur.pos() > cur.paragraph().beginOfBody()) {
554 cap::replaceSelection(cur);
555 cur.insert(new InsetNewline);
557 moveCursor(cur, false);
562 case LFUN_CHAR_DELETE_FORWARD:
563 if (!cur.selection()) {
564 if (cur.pos() == cur.paragraph().size())
565 // Par boundary, force full-screen update
566 singleParUpdate = false;
567 needsUpdate |= erase(cur);
569 // It is possible to make it a lot faster still
570 // just comment out the line below...
572 cutSelection(cur, true, false);
573 singleParUpdate = false;
575 moveCursor(cur, false);
578 case LFUN_DELETE_FORWARD_SKIP:
579 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
580 if (!cur.selection()) {
581 if (cur.pos() == cur.lastpos()) {
588 cutSelection(cur, true, false);
593 case LFUN_CHAR_DELETE_BACKWARD:
594 if (!cur.selection()) {
595 if (bv->getIntl().getTransManager().backspace()) {
596 // Par boundary, full-screen update
598 singleParUpdate = false;
599 needsUpdate |= backspace(cur);
601 // It is possible to make it a lot faster still
602 // just comment out the line below...
605 cutSelection(cur, true, false);
606 singleParUpdate = false;
611 case LFUN_DELETE_BACKWARD_SKIP:
612 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
613 if (!cur.selection()) {
617 //CursorSlice cur = cursor();
621 cutSelection(cur, true, false);
625 case LFUN_BREAK_PARAGRAPH:
626 cap::replaceSelection(cur);
627 breakParagraph(cur, 0);
632 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
633 cap::replaceSelection(cur);
634 breakParagraph(cur, 1);
639 case LFUN_BREAK_PARAGRAPH_SKIP: {
640 // When at the beginning of a paragraph, remove
641 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
642 cap::replaceSelection(cur);
644 cur.paragraph().params().labelWidthString(docstring());
646 breakParagraph(cur, 0);
652 case LFUN_PARAGRAPH_SPACING: {
653 Paragraph & par = cur.paragraph();
654 Spacing::Space cur_spacing = par.params().spacing().getSpace();
655 string cur_value = "1.0";
656 if (cur_spacing == Spacing::Other)
657 cur_value = par.params().spacing().getValueAsString();
659 istringstream is(to_utf8(cmd.argument()));
662 Spacing::Space new_spacing = cur_spacing;
663 string new_value = cur_value;
665 lyxerr << "Missing argument to `paragraph-spacing'"
667 } else if (tmp == "single") {
668 new_spacing = Spacing::Single;
669 } else if (tmp == "onehalf") {
670 new_spacing = Spacing::Onehalf;
671 } else if (tmp == "double") {
672 new_spacing = Spacing::Double;
673 } else if (tmp == "other") {
674 new_spacing = Spacing::Other;
675 string tmpval = "0.0";
677 lyxerr << "new_value = " << tmpval << endl;
680 } else if (tmp == "default") {
681 new_spacing = Spacing::Default;
683 lyxerr << to_utf8(_("Unknown spacing argument: "))
684 << to_utf8(cmd.argument()) << endl;
686 if (cur_spacing != new_spacing || cur_value != new_value)
687 par.params().spacing(Spacing(new_spacing, new_value));
691 case LFUN_INSET_INSERT: {
693 InsetBase * inset = createInset(bv, cmd);
695 insertInset(cur, inset);
701 case LFUN_INSET_DISSOLVE:
702 needsUpdate |= dissolveInset(cur);
705 case LFUN_INSET_SETTINGS:
706 cur.inset().showInsetDialog(bv);
709 case LFUN_SPACE_INSERT:
710 if (cur.paragraph().layout()->free_spacing)
711 insertChar(cur, ' ');
713 doInsertInset(cur, this, cmd, false, false);
716 moveCursor(cur, false);
719 case LFUN_HYPHENATION_POINT_INSERT:
720 specialChar(cur, InsetSpecialChar::HYPHENATION);
723 case LFUN_LIGATURE_BREAK_INSERT:
724 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
727 case LFUN_DOTS_INSERT:
728 specialChar(cur, InsetSpecialChar::LDOTS);
731 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
732 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
735 case LFUN_MENU_SEPARATOR_INSERT:
736 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
739 case LFUN_WORD_UPCASE:
740 changeCase(cur, LyXText::text_uppercase);
743 case LFUN_WORD_LOWCASE:
744 changeCase(cur, LyXText::text_lowercase);
747 case LFUN_WORD_CAPITALIZE:
748 changeCase(cur, LyXText::text_capitalization);
751 case LFUN_CHARS_TRANSPOSE:
756 cur.message(_("Paste"));
757 cap::replaceSelection(cur);
758 if (cmd.argument().empty() && !theClipboard().isInternal())
759 pasteString(cur, theClipboard().get(), docstring());
761 string const arg(to_utf8(cmd.argument()));
762 pasteSelection(cur, bv->buffer()->errorList("Paste"),
763 isStrUnsignedInt(arg) ?
764 convert<unsigned int>(arg) :
766 bv->buffer()->errors("Paste");
768 cur.clearSelection(); // bug 393
774 cutSelection(cur, true, true);
775 cur.message(_("Cut"));
780 cur.message(_("Copy"));
783 case LFUN_SERVER_GET_XY:
784 cur.message(from_utf8(
785 convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
786 + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
789 case LFUN_SERVER_SET_XY: {
792 istringstream is(to_utf8(cmd.argument()));
795 lyxerr << "SETXY: Could not parse coordinates in '"
796 << to_utf8(cmd.argument()) << std::endl;
798 setCursorFromCoordinates(cur, x, y);
802 case LFUN_SERVER_GET_FONT:
803 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
804 cur.message(from_ascii("E"));
805 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
806 cur.message(from_ascii("N"));
808 cur.message(from_ascii("0"));
811 case LFUN_SERVER_GET_LAYOUT:
812 cur.message(from_utf8(cur.paragraph().layout()->name()));
816 string layout = to_ascii(cmd.argument());
817 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) " << layout << endl;
819 // Derive layout number from given argument (string)
820 // and current buffer's textclass (number)
821 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
823 layout = tclass.defaultLayoutName();
824 bool hasLayout = tclass.hasLayout(layout);
826 // If the entry is obsolete, use the new one instead.
828 string const & obs = tclass[layout]->obsoleted_by();
834 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
835 from_utf8(N_(" not known")));
839 bool change_layout = (current_layout != layout);
841 if (!change_layout && cur.selection() &&
842 cur.selBegin().pit() != cur.selEnd().pit())
844 pit_type spit = cur.selBegin().pit();
845 pit_type epit = cur.selEnd().pit() + 1;
846 while (spit != epit) {
847 if (pars_[spit].layout()->name() != current_layout) {
848 change_layout = true;
856 current_layout = layout;
857 setLayout(cur, layout);
858 // inform the GUI that the layout has changed.
859 bv->layoutChanged(layout);
865 case LFUN_CLIPBOARD_PASTE:
866 pasteString(cur, theClipboard().get(), cmd.argument());
869 case LFUN_PRIMARY_SELECTION_PASTE:
870 pasteString(cur, theSelection().get(), cmd.argument());
873 case LFUN_UNICODE_INSERT: {
874 if (cmd.argument().empty())
876 docstring hexstring = cmd.argument();
877 if (lyx::support::isHex(hexstring)) {
878 char_type c = lyx::support::hexToInt(hexstring);
879 if (c > 32 && c < 0x10ffff) {
880 lyxerr << "Inserting c: " << c << endl;
881 docstring s = docstring(1, c);
882 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
888 case LFUN_QUOTE_INSERT: {
889 cap::replaceSelection(cur);
890 Paragraph & par = cur.paragraph();
891 pos_type pos = cur.pos();
895 else if (cur.prevInset() && cur.prevInset()->isSpace())
898 c = par.getChar(pos - 1);
900 LyXLayout_ptr const & style = par.layout();
902 BufferParams const & bufparams = bv->buffer()->params();
903 if (!style->pass_thru
904 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
905 string arg = to_utf8(cmd.argument());
907 cur.insert(new InsetQuotes(c,
908 bufparams.quotes_language,
909 InsetQuotes::SingleQ));
911 cur.insert(new InsetQuotes(c,
912 bufparams.quotes_language,
913 InsetQuotes::DoubleQ));
917 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
921 case LFUN_DATE_INSERT:
922 if (cmd.argument().empty())
923 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
924 formatted_time(current_time())));
926 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
927 formatted_time(current_time(), to_utf8(cmd.argument()))));
930 case LFUN_MOUSE_TRIPLE:
931 if (cmd.button() == mouse_button::button1) {
937 theSelection().haveSelection(cur.selection());
941 case LFUN_MOUSE_DOUBLE:
942 if (cmd.button() == mouse_button::button1) {
943 selectWord(cur, WHOLE_WORD_STRICT);
945 theSelection().haveSelection(cur.selection());
949 // Single-click on work area
950 case LFUN_MOUSE_PRESS: {
951 // Right click on a footnote flag opens float menu
952 if (cmd.button() == mouse_button::button3)
953 cur.clearSelection();
955 // Middle button press pastes if we have a selection
956 // We do this here as if the selection was inside an inset
957 // it could get cleared on the unlocking of the inset so
958 // we have to check this first
959 bool paste_internally = false;
960 if (cmd.button() == mouse_button::button2 && cur.selection()) {
961 lyx::dispatch(FuncRequest(LFUN_COPY));
962 paste_internally = true;
965 // we have to update after dePM triggered
966 bool update = bv->mouseSetCursor(cur);
968 // Insert primary selection with middle mouse
969 // if there is a local selection in the current buffer,
971 if (cmd.button() == mouse_button::button2) {
972 if (paste_internally)
973 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
975 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
978 if (!update && cmd.button() == mouse_button::button1) {
986 case LFUN_MOUSE_MOTION: {
987 // Only use motion with button 1
988 //if (cmd.button() != mouse_button::button1)
991 // ignore motions deeper nested than the real anchor
992 LCursor & bvcur = cur.bv().cursor();
993 if (bvcur.anchor_.hasPart(cur)) {
994 CursorSlice old = bvcur.top();
996 int const wh = bv->workHeight();
997 int const y = std::max(0, std::min(wh - 1, cmd.y));
999 setCursorFromCoordinates(cur, cmd.x, y);
1000 cur.x_target() = cmd.x;
1002 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1004 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1005 // This is to allow jumping over large insets
1006 if (cur.top() == old) {
1008 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1010 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1013 if (cur.top() == old)
1016 // don't set anchor_
1017 bvcur.setCursor(cur);
1018 bvcur.selection() = true;
1019 //lyxerr << "MOTION: " << bv->cursor() << endl;
1027 case LFUN_MOUSE_RELEASE: {
1028 if (cmd.button() == mouse_button::button2)
1032 if (cmd.button() == mouse_button::button1) {
1033 if (cur.selection())
1034 theSelection().haveSelection(cur.selection());
1035 needsUpdate = false;
1043 case LFUN_SELF_INSERT: {
1044 if (cmd.argument().empty())
1047 // Automatically delete the currently selected
1048 // text and replace it with what is being
1049 // typed in now. Depends on lyxrc settings
1050 // "auto_region_delete", which defaults to
1053 if (lyxrc.auto_region_delete) {
1054 if (cur.selection())
1055 cutSelection(cur, false, false);
1056 theSelection().haveSelection(false);
1059 cur.clearSelection();
1060 LyXFont const old_font = real_current_font;
1062 docstring::const_iterator cit = cmd.argument().begin();
1063 docstring::const_iterator end = cmd.argument().end();
1064 for (; cit != end; ++cit)
1066 bv->getIntl().getTransManager().
1067 translateAndInsert(*cit, this);
1069 insertChar(bv->cursor(), *cit);
1073 moveCursor(cur, false);
1077 case LFUN_URL_INSERT: {
1078 InsetCommandParams p("url");
1079 string const data = InsetCommandMailer::params2string("url", p);
1080 bv->showInsetDialog("url", data, 0);
1084 case LFUN_HTML_INSERT: {
1085 InsetCommandParams p("htmlurl");
1086 string const data = InsetCommandMailer::params2string("url", p);
1087 bv->showInsetDialog("url", data, 0);
1091 case LFUN_LABEL_INSERT: {
1092 InsetCommandParams p("label");
1093 // Try to generate a valid label
1094 p["name"] = (cmd.argument().empty()) ?
1095 cur.getPossibleLabel() :
1097 string const data = InsetCommandMailer::params2string("label", p);
1099 if (cmd.argument().empty()) {
1100 bv->showInsetDialog("label", data, 0);
1102 FuncRequest fr(LFUN_INSET_INSERT, data);
1110 case LFUN_LIST_INSERT:
1111 case LFUN_THEOREM_INSERT:
1112 case LFUN_CAPTION_INSERT:
1114 case LFUN_NOTE_INSERT:
1115 case LFUN_CHARSTYLE_INSERT:
1116 case LFUN_BOX_INSERT:
1117 case LFUN_BRANCH_INSERT:
1118 case LFUN_BIBITEM_INSERT:
1119 case LFUN_ERT_INSERT:
1120 case LFUN_FOOTNOTE_INSERT:
1121 case LFUN_MARGINALNOTE_INSERT:
1122 case LFUN_OPTIONAL_INSERT:
1123 case LFUN_ENVIRONMENT_INSERT:
1124 // Open the inset, and move the current selection
1126 doInsertInset(cur, this, cmd, true, true);
1130 case LFUN_TABULAR_INSERT:
1131 // if there were no arguments, just open the dialog
1132 if (doInsertInset(cur, this, cmd, false, true))
1135 bv->showDialog("tabularcreate");
1139 case LFUN_FLOAT_INSERT:
1140 case LFUN_FLOAT_WIDE_INSERT:
1141 case LFUN_WRAP_INSERT:
1142 doInsertInset(cur, this, cmd, true, true);
1144 // FIXME: the "Caption" name should not be hardcoded,
1145 // but given by the float definition.
1146 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1149 case LFUN_INDEX_INSERT:
1150 case LFUN_NOMENCL_INSERT: {
1151 InsetBase * inset = createInset(&cur.bv(), cmd);
1156 cur.clearSelection();
1157 insertInset(cur, inset);
1158 inset->edit(cur, true);
1159 // Show the dialog for the nomenclature entry, since the
1160 // description entry still needs to be filled in.
1161 if (cmd.action == LFUN_NOMENCL_INSERT)
1162 InsetCommandMailer("nomenclature",
1163 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1168 case LFUN_INDEX_PRINT:
1169 case LFUN_NOMENCL_PRINT:
1170 case LFUN_TOC_INSERT:
1171 case LFUN_HFILL_INSERT:
1172 case LFUN_LINE_INSERT:
1173 case LFUN_PAGEBREAK_INSERT:
1174 case LFUN_CLEARPAGE_INSERT:
1175 case LFUN_CLEARDOUBLEPAGE_INSERT:
1177 doInsertInset(cur, this, cmd, false, false);
1181 case LFUN_DEPTH_DECREMENT:
1182 changeDepth(cur, DEC_DEPTH);
1185 case LFUN_DEPTH_INCREMENT:
1186 changeDepth(cur, INC_DEPTH);
1189 case LFUN_MATH_DISPLAY:
1190 mathDispatch(cur, cmd, true);
1193 case LFUN_MATH_IMPORT_SELECTION:
1194 case LFUN_MATH_MODE:
1195 if (cmd.argument() == "on")
1196 // don't pass "on" as argument
1197 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1199 mathDispatch(cur, cmd, false);
1202 case LFUN_MATH_MACRO:
1203 if (cmd.argument().empty())
1204 cur.errorMessage(from_utf8(N_("Missing argument")));
1206 string s = to_utf8(cmd.argument());
1207 string const s1 = token(s, ' ', 1);
1208 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1209 string const s2 = token(s, ' ', 2);
1210 string const type = s2.empty() ? "newcommand" : s2;
1211 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1212 //cur.nextInset()->edit(cur, true);
1216 // passthrough hat and underscore outside mathed:
1217 case LFUN_MATH_SUBSCRIPT:
1218 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1220 case LFUN_MATH_SUPERSCRIPT:
1221 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1224 case LFUN_MATH_INSERT:
1225 case LFUN_MATH_MATRIX:
1226 case LFUN_MATH_DELIM:
1227 case LFUN_MATH_BIGDELIM: {
1228 cur.insert(new InsetMathHull(hullSimple));
1229 cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
1234 case LFUN_FONT_EMPH: {
1235 LyXFont font(LyXFont::ALL_IGNORE);
1236 font.setEmph(LyXFont::TOGGLE);
1237 toggleAndShow(cur, this, font);
1241 case LFUN_FONT_BOLD: {
1242 LyXFont font(LyXFont::ALL_IGNORE);
1243 font.setSeries(LyXFont::BOLD_SERIES);
1244 toggleAndShow(cur, this, font);
1248 case LFUN_FONT_NOUN: {
1249 LyXFont font(LyXFont::ALL_IGNORE);
1250 font.setNoun(LyXFont::TOGGLE);
1251 toggleAndShow(cur, this, font);
1255 case LFUN_FONT_CODE: {
1256 LyXFont font(LyXFont::ALL_IGNORE);
1257 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1258 toggleAndShow(cur, this, font);
1262 case LFUN_FONT_SANS: {
1263 LyXFont font(LyXFont::ALL_IGNORE);
1264 font.setFamily(LyXFont::SANS_FAMILY);
1265 toggleAndShow(cur, this, font);
1269 case LFUN_FONT_ROMAN: {
1270 LyXFont font(LyXFont::ALL_IGNORE);
1271 font.setFamily(LyXFont::ROMAN_FAMILY);
1272 toggleAndShow(cur, this, font);
1276 case LFUN_FONT_DEFAULT: {
1277 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1278 toggleAndShow(cur, this, font);
1282 case LFUN_FONT_UNDERLINE: {
1283 LyXFont font(LyXFont::ALL_IGNORE);
1284 font.setUnderbar(LyXFont::TOGGLE);
1285 toggleAndShow(cur, this, font);
1289 case LFUN_FONT_SIZE: {
1290 LyXFont font(LyXFont::ALL_IGNORE);
1291 font.setLyXSize(to_utf8(cmd.argument()));
1292 toggleAndShow(cur, this, font);
1296 case LFUN_LANGUAGE: {
1297 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1300 LyXFont font(LyXFont::ALL_IGNORE);
1301 font.setLanguage(lang);
1302 toggleAndShow(cur, this, font);
1307 case LFUN_FONT_FREE_APPLY:
1308 toggleAndShow(cur, this, freefont, toggleall);
1309 cur.message(_("Character set"));
1312 // Set the freefont using the contents of \param data dispatched from
1313 // the frontends and apply it at the current cursor location.
1314 case LFUN_FONT_FREE_UPDATE: {
1317 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1320 toggleAndShow(cur, this, freefont, toggleall);
1321 cur.message(_("Character set"));
1326 case LFUN_FINISHED_LEFT:
1327 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1330 case LFUN_FINISHED_RIGHT:
1331 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1335 case LFUN_FINISHED_UP:
1336 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1340 case LFUN_FINISHED_DOWN:
1341 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1345 case LFUN_LAYOUT_PARAGRAPH: {
1347 params2string(cur.paragraph(), data);
1348 data = "show\n" + data;
1349 bv->showDialogWithData("paragraph", data);
1353 case LFUN_PARAGRAPH_UPDATE: {
1355 params2string(cur.paragraph(), data);
1357 // Will the paragraph accept changes from the dialog?
1358 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1360 data = "update " + convert<string>(accept) + '\n' + data;
1361 bv->updateDialog("paragraph", data);
1365 case LFUN_ACCENT_UMLAUT:
1366 case LFUN_ACCENT_CIRCUMFLEX:
1367 case LFUN_ACCENT_GRAVE:
1368 case LFUN_ACCENT_ACUTE:
1369 case LFUN_ACCENT_TILDE:
1370 case LFUN_ACCENT_CEDILLA:
1371 case LFUN_ACCENT_MACRON:
1372 case LFUN_ACCENT_DOT:
1373 case LFUN_ACCENT_UNDERDOT:
1374 case LFUN_ACCENT_UNDERBAR:
1375 case LFUN_ACCENT_CARON:
1376 case LFUN_ACCENT_SPECIAL_CARON:
1377 case LFUN_ACCENT_BREVE:
1378 case LFUN_ACCENT_TIE:
1379 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1380 case LFUN_ACCENT_CIRCLE:
1381 case LFUN_ACCENT_OGONEK:
1382 theLyXFunc().handleKeyFunc(cmd.action);
1383 if (!cmd.argument().empty())
1384 // FIXME: Are all these characters encoded in one byte in utf8?
1385 bv->getIntl().getTransManager()
1386 .translateAndInsert(cmd.argument()[0], this, cur);
1389 case LFUN_FLOAT_LIST: {
1390 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1391 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1392 // not quite sure if we want this...
1394 cur.clearSelection();
1395 breakParagraph(cur);
1397 if (cur.lastpos() != 0) {
1399 breakParagraph(cur);
1402 setLayout(cur, tclass.defaultLayoutName());
1403 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1404 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1407 lyxerr << "Non-existent float type: "
1408 << to_utf8(cmd.argument()) << endl;
1413 case LFUN_CHANGE_ACCEPT: {
1418 case LFUN_CHANGE_REJECT: {
1423 case LFUN_THESAURUS_ENTRY: {
1424 docstring arg = cmd.argument();
1426 arg = cur.selectionAsString(false);
1428 if (arg.size() > 100 || arg.empty()) {
1429 // Get word or selection
1430 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1431 arg = cur.selectionAsString(false);
1434 bv->showDialogWithData("thesaurus", to_utf8(arg));
1438 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1439 // Given data, an encoding of the ParagraphParameters
1440 // generated in the Paragraph dialog, this function sets
1441 // the current paragraph appropriately.
1442 istringstream is(to_utf8(cmd.argument()));
1445 ParagraphParameters params;
1450 params.labelWidthString(),
1452 cur.message(_("Paragraph layout set"));
1457 if (cur.selection()) {
1458 cur.selection() = false;
1461 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1466 lyxerr[Debug::ACTION]
1467 << BOOST_CURRENT_FUNCTION
1468 << ": Command " << cmd
1469 << " not DISPATCHED by LyXText" << endl;
1474 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1476 // FIXME: The cursor flag is reset two lines below
1477 // so we need to check here if some of the LFUN did touch that.
1478 // for now only LyXText::erase() and LyXText::backspace() do that.
1479 // The plan is to verify all the LFUNs and then to remove this
1480 // singleParUpdate boolean altogether.
1481 if (cur.result().update() & Update::Force) {
1482 singleParUpdate = false;
1486 // FIXME: the following code should go in favor of fine grained
1487 // update flag treatment.
1488 if (singleParUpdate) {
1489 // Inserting characters does not change par height
1490 ParagraphMetrics const & pms
1491 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1492 if (pms.dim().height()
1493 == olddim.height()) {
1494 // if so, update _only_ this paragraph
1495 cur.updateFlags(Update::SinglePar |
1497 Update::MultiParSel);
1504 && &oldTopSlice.inset() == &cur.inset()
1505 && oldTopSlice.idx() == cur.idx()
1506 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1507 && !cur.selection())
1508 // FIXME: it would be better if we could just do this
1510 //if (cur.result().update() != Update::FitCursor)
1513 // But some LFUNs do not set Update::FitCursor when needed, so we
1514 // do it for all. This is not very harmfull as FitCursor will provoke
1515 // a full redraw only if needed but still, a proper review of all LFUN
1516 // should be done and this needsUpdate boolean can then be removed.
1517 cur.updateFlags(Update::FitCursor);
1519 cur.updateFlags(Update::Force | Update::FitCursor);
1523 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1524 FuncStatus & flag) const
1526 BOOST_ASSERT(cur.text() == this);
1528 LyXFont const & font = real_current_font;
1530 InsetBase::Code code = InsetBase::NO_CODE;
1532 switch (cmd.action) {
1534 case LFUN_DEPTH_DECREMENT:
1535 enable = changeDepthAllowed(cur, DEC_DEPTH);
1538 case LFUN_DEPTH_INCREMENT:
1539 enable = changeDepthAllowed(cur, INC_DEPTH);
1543 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1546 case LFUN_BIBITEM_INSERT:
1547 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1550 case LFUN_DIALOG_SHOW_NEW_INSET:
1551 if (cmd.argument() == "bibitem")
1552 code = InsetBase::BIBITEM_CODE;
1553 else if (cmd.argument() == "bibtex")
1554 code = InsetBase::BIBTEX_CODE;
1555 else if (cmd.argument() == "box")
1556 code = InsetBase::BOX_CODE;
1557 else if (cmd.argument() == "branch")
1558 code = InsetBase::BRANCH_CODE;
1559 else if (cmd.argument() == "citation")
1560 code = InsetBase::CITE_CODE;
1561 else if (cmd.argument() == "ert")
1562 code = InsetBase::ERT_CODE;
1563 else if (cmd.argument() == "external")
1564 code = InsetBase::EXTERNAL_CODE;
1565 else if (cmd.argument() == "float")
1566 code = InsetBase::FLOAT_CODE;
1567 else if (cmd.argument() == "graphics")
1568 code = InsetBase::GRAPHICS_CODE;
1569 else if (cmd.argument() == "include")
1570 code = InsetBase::INCLUDE_CODE;
1571 else if (cmd.argument() == "index")
1572 code = InsetBase::INDEX_CODE;
1573 else if (cmd.argument() == "nomenclature")
1574 code = InsetBase::NOMENCL_CODE;
1575 else if (cmd.argument() == "label")
1576 code = InsetBase::LABEL_CODE;
1577 else if (cmd.argument() == "note")
1578 code = InsetBase::NOTE_CODE;
1579 else if (cmd.argument() == "ref")
1580 code = InsetBase::REF_CODE;
1581 else if (cmd.argument() == "toc")
1582 code = InsetBase::TOC_CODE;
1583 else if (cmd.argument() == "url")
1584 code = InsetBase::URL_CODE;
1585 else if (cmd.argument() == "vspace")
1586 code = InsetBase::VSPACE_CODE;
1587 else if (cmd.argument() == "wrap")
1588 code = InsetBase::WRAP_CODE;
1591 case LFUN_ERT_INSERT:
1592 code = InsetBase::ERT_CODE;
1594 case LFUN_FOOTNOTE_INSERT:
1595 code = InsetBase::FOOT_CODE;
1597 case LFUN_TABULAR_INSERT:
1598 code = InsetBase::TABULAR_CODE;
1600 case LFUN_MARGINALNOTE_INSERT:
1601 code = InsetBase::MARGIN_CODE;
1603 case LFUN_FLOAT_INSERT:
1604 case LFUN_FLOAT_WIDE_INSERT:
1605 code = InsetBase::FLOAT_CODE;
1607 case LFUN_WRAP_INSERT:
1608 code = InsetBase::WRAP_CODE;
1610 case LFUN_FLOAT_LIST:
1611 code = InsetBase::FLOAT_LIST_CODE;
1614 case LFUN_LIST_INSERT:
1615 code = InsetBase::LIST_CODE;
1617 case LFUN_THEOREM_INSERT:
1618 code = InsetBase::THEOREM_CODE;
1621 case LFUN_CAPTION_INSERT:
1622 code = InsetBase::CAPTION_CODE;
1624 case LFUN_NOTE_INSERT:
1625 code = InsetBase::NOTE_CODE;
1627 case LFUN_CHARSTYLE_INSERT:
1628 code = InsetBase::CHARSTYLE_CODE;
1629 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1632 case LFUN_BOX_INSERT:
1633 code = InsetBase::BOX_CODE;
1635 case LFUN_BRANCH_INSERT:
1636 code = InsetBase::BRANCH_CODE;
1637 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1640 case LFUN_LABEL_INSERT:
1641 code = InsetBase::LABEL_CODE;
1643 case LFUN_OPTIONAL_INSERT:
1644 code = InsetBase::OPTARG_CODE;
1645 enable = numberOfOptArgs(cur.paragraph())
1646 < cur.paragraph().layout()->optionalargs;
1648 case LFUN_ENVIRONMENT_INSERT:
1649 code = InsetBase::BOX_CODE;
1651 case LFUN_INDEX_INSERT:
1652 code = InsetBase::INDEX_CODE;
1654 case LFUN_INDEX_PRINT:
1655 code = InsetBase::INDEX_PRINT_CODE;
1657 case LFUN_NOMENCL_INSERT:
1658 code = InsetBase::NOMENCL_CODE;
1660 case LFUN_NOMENCL_PRINT:
1661 code = InsetBase::NOMENCL_PRINT_CODE;
1663 case LFUN_TOC_INSERT:
1664 code = InsetBase::TOC_CODE;
1666 case LFUN_HTML_INSERT:
1667 case LFUN_URL_INSERT:
1668 code = InsetBase::URL_CODE;
1670 case LFUN_QUOTE_INSERT:
1671 // always allow this, since we will inset a raw quote
1672 // if an inset is not allowed.
1674 case LFUN_HYPHENATION_POINT_INSERT:
1675 case LFUN_LIGATURE_BREAK_INSERT:
1676 case LFUN_HFILL_INSERT:
1677 case LFUN_MENU_SEPARATOR_INSERT:
1678 case LFUN_DOTS_INSERT:
1679 case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1680 code = InsetBase::SPECIALCHAR_CODE;
1682 case LFUN_SPACE_INSERT:
1683 // slight hack: we know this is allowed in math mode
1685 code = InsetBase::SPACE_CODE;
1688 case LFUN_INSET_MODIFY:
1689 // We need to disable this, because we may get called for a
1691 // InsetTabular::getStatus() -> InsetText::getStatus()
1692 // and we don't handle LFUN_INSET_MODIFY.
1696 case LFUN_FONT_EMPH:
1697 flag.setOnOff(font.emph() == LyXFont::ON);
1700 case LFUN_FONT_NOUN:
1701 flag.setOnOff(font.noun() == LyXFont::ON);
1704 case LFUN_FONT_BOLD:
1705 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1708 case LFUN_FONT_SANS:
1709 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1712 case LFUN_FONT_ROMAN:
1713 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1716 case LFUN_FONT_CODE:
1717 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1722 enable = cur.selection();
1726 // FIXME: This is not correct, but the correct code below is
1728 enable = cap::numberOfSelections() > 0 ||
1729 !theClipboard().isInternal();
1731 if (cmd.argument().empty()) {
1732 if (theClipboard().isInternal())
1733 enable = cap::numberOfSelections() > 0;
1735 enable = !theClipboard().get().empty();
1736 } else if (isStrUnsignedInt(to_utf8(cmd.argument()))) {
1737 int n = convert<unsigned int>(to_utf8(cmd.argument()));
1738 enable = cap::numberOfSelections() > n;
1745 case LFUN_PARAGRAPH_MOVE_UP:
1746 enable = cur.pit() > 0 && !cur.selection();
1749 case LFUN_PARAGRAPH_MOVE_DOWN:
1750 enable = cur.pit() < cur.lastpit() && !cur.selection();
1753 case LFUN_INSET_DISSOLVE:
1754 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1757 case LFUN_CHANGE_ACCEPT:
1758 case LFUN_CHANGE_REJECT:
1759 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1760 // In principle, these LFUNs should only be enabled if there
1761 // is a change at the current position/in the current selection.
1762 // However, without proper optimizations, this will inevitably
1763 // result in unacceptable performance - just imagine a user who
1764 // wants to select the complete content of a long document.
1768 case LFUN_WORD_DELETE_FORWARD:
1769 case LFUN_WORD_DELETE_BACKWARD:
1770 case LFUN_LINE_DELETE:
1771 case LFUN_WORD_FORWARD:
1772 case LFUN_WORD_BACKWARD:
1773 case LFUN_CHAR_FORWARD:
1774 case LFUN_CHAR_FORWARD_SELECT:
1775 case LFUN_CHAR_BACKWARD:
1776 case LFUN_CHAR_BACKWARD_SELECT:
1778 case LFUN_UP_SELECT:
1780 case LFUN_DOWN_SELECT:
1781 case LFUN_PARAGRAPH_UP_SELECT:
1782 case LFUN_PARAGRAPH_DOWN_SELECT:
1783 case LFUN_SCREEN_UP_SELECT:
1784 case LFUN_SCREEN_DOWN_SELECT:
1785 case LFUN_LINE_BEGIN_SELECT:
1786 case LFUN_LINE_END_SELECT:
1787 case LFUN_WORD_FORWARD_SELECT:
1788 case LFUN_WORD_BACKWARD_SELECT:
1789 case LFUN_WORD_SELECT:
1790 case LFUN_PARAGRAPH_UP:
1791 case LFUN_PARAGRAPH_DOWN:
1792 case LFUN_SCREEN_UP:
1793 case LFUN_SCREEN_DOWN:
1794 case LFUN_LINE_BEGIN:
1796 case LFUN_BREAK_LINE:
1797 case LFUN_CHAR_DELETE_FORWARD:
1798 case LFUN_DELETE_FORWARD_SKIP:
1799 case LFUN_CHAR_DELETE_BACKWARD:
1800 case LFUN_DELETE_BACKWARD_SKIP:
1801 case LFUN_BREAK_PARAGRAPH:
1802 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1803 case LFUN_BREAK_PARAGRAPH_SKIP:
1804 case LFUN_PARAGRAPH_SPACING:
1805 case LFUN_INSET_INSERT:
1806 case LFUN_WORD_UPCASE:
1807 case LFUN_WORD_LOWCASE:
1808 case LFUN_WORD_CAPITALIZE:
1809 case LFUN_CHARS_TRANSPOSE:
1810 case LFUN_SERVER_GET_XY:
1811 case LFUN_SERVER_SET_XY:
1812 case LFUN_SERVER_GET_FONT:
1813 case LFUN_SERVER_GET_LAYOUT:
1815 case LFUN_CLIPBOARD_PASTE:
1816 case LFUN_PRIMARY_SELECTION_PASTE:
1817 case LFUN_DATE_INSERT:
1818 case LFUN_SELF_INSERT:
1819 case LFUN_LINE_INSERT:
1820 case LFUN_PAGEBREAK_INSERT:
1821 case LFUN_CLEARPAGE_INSERT:
1822 case LFUN_CLEARDOUBLEPAGE_INSERT:
1823 case LFUN_MATH_DISPLAY:
1824 case LFUN_MATH_IMPORT_SELECTION:
1825 case LFUN_MATH_MODE:
1826 case LFUN_MATH_MACRO:
1827 case LFUN_MATH_MATRIX:
1828 case LFUN_MATH_DELIM:
1829 case LFUN_MATH_BIGDELIM:
1830 case LFUN_MATH_SUBSCRIPT:
1831 case LFUN_MATH_SUPERSCRIPT:
1832 case LFUN_FONT_DEFAULT:
1833 case LFUN_FONT_UNDERLINE:
1834 case LFUN_FONT_SIZE:
1836 case LFUN_FONT_FREE_APPLY:
1837 case LFUN_FONT_FREE_UPDATE:
1838 case LFUN_LAYOUT_PARAGRAPH:
1839 case LFUN_PARAGRAPH_UPDATE:
1840 case LFUN_ACCENT_UMLAUT:
1841 case LFUN_ACCENT_CIRCUMFLEX:
1842 case LFUN_ACCENT_GRAVE:
1843 case LFUN_ACCENT_ACUTE:
1844 case LFUN_ACCENT_TILDE:
1845 case LFUN_ACCENT_CEDILLA:
1846 case LFUN_ACCENT_MACRON:
1847 case LFUN_ACCENT_DOT:
1848 case LFUN_ACCENT_UNDERDOT:
1849 case LFUN_ACCENT_UNDERBAR:
1850 case LFUN_ACCENT_CARON:
1851 case LFUN_ACCENT_SPECIAL_CARON:
1852 case LFUN_ACCENT_BREVE:
1853 case LFUN_ACCENT_TIE:
1854 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1855 case LFUN_ACCENT_CIRCLE:
1856 case LFUN_ACCENT_OGONEK:
1857 case LFUN_THESAURUS_ENTRY:
1858 case LFUN_PARAGRAPH_PARAMS_APPLY:
1860 case LFUN_BUFFER_END:
1861 case LFUN_BUFFER_BEGIN:
1862 case LFUN_BUFFER_BEGIN_SELECT:
1863 case LFUN_BUFFER_END_SELECT:
1864 case LFUN_UNICODE_INSERT:
1865 // these are handled in our dispatch()
1873 if (code != InsetBase::NO_CODE
1874 && (cur.empty() || !cur.inset().insetAllowed(code)))
1877 flag.enabled(enable);
1882 void LyXText::pasteString(LCursor & cur, docstring const & clip,
1883 docstring const & argument)
1885 cur.clearSelection();
1886 if (!clip.empty()) {
1888 if (argument == "paragraph")
1889 insertStringAsParagraphs(cur, clip);
1891 insertStringAsLines(cur, clip);