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.
21 #include "BranchList.h"
22 #include "FloatList.h"
23 #include "FuncStatus.h"
25 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
30 #include "CutAndPaste.h"
31 #include "DispatchResult.h"
32 #include "ErrorList.h"
34 #include "FuncRequest.h"
35 #include "InsetList.h"
39 #include "LyXAction.h"
43 #include "Paragraph.h"
44 #include "paragraph_funcs.h"
45 #include "ParagraphParameters.h"
46 #include "TextClass.h"
47 #include "TextMetrics.h"
50 #include "frontends/Application.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/LyXView.h"
53 #include "frontends/Selection.h"
54 #include "frontends/WorkArea.h"
56 #include "insets/InsetCollapsable.h"
57 #include "insets/InsetCommand.h"
58 #include "insets/InsetExternal.h"
59 #include "insets/InsetFloatList.h"
60 #include "insets/InsetGraphics.h"
61 #include "insets/InsetGraphicsParams.h"
62 #include "insets/InsetNewline.h"
63 #include "insets/InsetQuotes.h"
64 #include "insets/InsetSpecialChar.h"
65 #include "insets/InsetText.h"
67 #include "support/convert.h"
68 #include "support/debug.h"
69 #include "support/gettext.h"
70 #include "support/lstrings.h"
71 #include "support/lyxtime.h"
72 #include "support/os.h"
74 #include "mathed/InsetMathHull.h"
75 #include "mathed/MathMacroTemplate.h"
77 #include <boost/next_prior.hpp>
83 using namespace lyx::support;
87 using cap::copySelection;
88 using cap::cutSelection;
89 using cap::pasteFromStack;
90 using cap::pasteClipboardText;
91 using cap::pasteClipboardGraphics;
92 using cap::replaceSelection;
93 using cap::grabAndEraseSelection;
94 using cap::selClearOrDel;
97 static Font freefont(ignore_font, ignore_language);
98 static bool toggleall = false;
100 static void toggleAndShow(Cursor & cur, Text * text,
101 Font const & font, bool toggleall = true)
103 text->toggleFree(cur, font, toggleall);
105 if (font.language() != ignore_language ||
106 font.fontInfo().number() != FONT_IGNORE) {
107 TextMetrics const & tm = cur.bv().textMetrics(text);
108 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
109 cur.real_current_font))
110 text->setCursor(cur, cur.pit(), cur.pos(),
111 false, !cur.boundary());
116 static void moveCursor(Cursor & cur, bool selecting)
118 if (selecting || cur.mark())
123 static void finishChange(Cursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
133 docstring sel = cur.selectionAsString(false);
135 // It may happen that sel is empty but there is a selection
136 replaceSelection(cur);
138 // Is this a valid formula?
142 #ifdef ENABLE_ASSERTIONS
143 const int old_pos = cur.pos();
145 cur.insert(new InsetMathHull(hullSimple));
146 #ifdef ENABLE_ASSERTIONS
147 LASSERT(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("\\newlyxcommand")) == string::npos
167 && sel.find(from_ascii("\\def")) == string::npos)
169 InsetMathHull * formula = new InsetMathHull;
170 string const selstr = to_utf8(sel);
171 istringstream is(selstr);
174 if (!formula->readQuiet(lex)) {
175 // No valid formula, let's try with delims
176 is.str("$" + selstr + "$");
178 if (!formula->readQuiet(lex)) {
179 // Still not valid, leave it as is
188 cur.insert(new MathMacroTemplate(sel));
192 cur.message(from_utf8(N_("Math editor mode")));
194 cur.message(from_utf8(N_("No valid math formula")));
198 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
200 BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
201 if (cur.inRegexped()) {
202 cur.message(_("Already in regexp mode"));
206 docstring const save_selection = grabAndEraseSelection(cur);
208 // replaceSelection(cur);
210 cur.insert(new InsetMathHull(hullRegexp));
211 cur.nextInset()->edit(cur, true);
212 cur.niceInsert(save_selection);
214 cur.message(_("Regexp editor mode"));
218 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
221 cap::replaceSelection(cur);
222 cur.insert(new InsetSpecialChar(kind));
227 static bool doInsertInset(Cursor & cur, Text * text,
228 FuncRequest const & cmd, bool edit, bool pastesel)
230 Buffer & buffer = cur.bv().buffer();
231 BufferParams const & bparams = buffer.params();
232 Inset * inset = createInset(buffer, cmd);
236 if (InsetCollapsable * ci = inset->asInsetCollapsable())
237 ci->setLayout(bparams);
240 if (cmd.action == LFUN_INDEX_INSERT) {
241 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
242 text->insertInset(cur, inset);
244 inset->edit(cur, true);
245 // Now put this into inset
246 static_cast<InsetCollapsable *>(inset)->
247 text().insertStringAsParagraphs(cur, ds);
252 if (cur.selection()) {
253 cutSelection(cur, false, pastesel);
254 cur.clearSelection();
257 text->insertInset(cur, inset);
260 inset->edit(cur, true);
262 if (!gotsel || !pastesel)
265 pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
266 cur.buffer()->errors("Paste");
267 cur.clearSelection(); // bug 393
269 InsetText * insetText = dynamic_cast<InsetText *>(inset);
270 if (insetText && (!insetText->allowMultiPar() || cur.lastpit() == 0)) {
271 // reset first par to default
272 cur.text()->paragraphs().begin()
273 ->setPlainOrDefaultLayout(bparams.documentClass());
276 // Merge multiple paragraphs -- hack
277 while (cur.lastpit() > 0)
278 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
279 cur.leaveInset(*inset);
281 cur.leaveInset(*inset);
282 // reset surrounding par to default
283 DocumentClass const & dc = bparams.documentClass();
284 docstring const layoutname = inset->usePlainLayout()
285 ? dc.plainLayoutName()
286 : dc.defaultLayoutName();
287 text->setLayout(cur, layoutname);
294 string const freefont2string()
296 return freefont.toString(toggleall);
300 /// the type of outline operation
302 OutlineUp, // Move this header with text down
303 OutlineDown, // Move this header with text up
304 OutlineIn, // Make this header deeper
305 OutlineOut // Make this header shallower
309 static void outline(OutlineOp mode, Cursor & cur)
311 Buffer & buf = *cur.buffer();
312 pit_type & pit = cur.pit();
313 ParagraphList & pars = buf.text().paragraphs();
314 ParagraphList::iterator const bgn = pars.begin();
315 // The first paragraph of the area to be copied:
316 ParagraphList::iterator start = boost::next(bgn, pit);
317 // The final paragraph of area to be copied:
318 ParagraphList::iterator finish = start;
319 ParagraphList::iterator const end = pars.end();
321 DocumentClass const & tc = buf.params().documentClass();
323 int const thistoclevel = start->layout().toclevel;
326 // Move out (down) from this section header
329 // Seek the one (on same level) below
330 for (; finish != end; ++finish) {
331 toclevel = finish->layout().toclevel;
332 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
336 // Do we need to set insets' buffer_ members, because we copied
337 // some stuff? We'll assume we do and reset it otherwise.
338 bool setBuffers = true;
342 if (start == pars.begin())
345 ParagraphList::iterator dest = start;
346 // Move out (up) from this header
349 // Search previous same-level header above
352 toclevel = dest->layout().toclevel;
354 && (toclevel == Layout::NOT_IN_TOC
355 || toclevel > thistoclevel));
356 // Not found; do nothing
357 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
359 pit_type const newpit = distance(bgn, dest);
360 pit_type const len = distance(start, finish);
361 pit_type const deletepit = pit + len;
362 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
363 pars.insert(dest, start, finish);
364 start = boost::next(pars.begin(), deletepit);
366 pars.erase(start, finish);
373 // Go one down from *this* header:
374 ParagraphList::iterator dest = boost::next(finish, 1);
375 // Go further down to find header to insert in front of:
376 for (; dest != end; ++dest) {
377 toclevel = dest->layout().toclevel;
378 if (toclevel != Layout::NOT_IN_TOC
379 && toclevel <= thistoclevel)
382 // One such was found:
383 pit_type newpit = distance(bgn, dest);
384 pit_type const len = distance(start, finish);
385 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
386 pars.insert(dest, start, finish);
387 start = boost::next(bgn, pit);
389 pars.erase(start, finish);
393 pit_type const len = distance(start, finish);
394 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
395 for (; start != finish; ++start) {
396 toclevel = start->layout().toclevel;
397 if (toclevel == Layout::NOT_IN_TOC)
399 DocumentClass::const_iterator lit = tc.begin();
400 DocumentClass::const_iterator len = tc.end();
401 for (; lit != len; ++lit) {
402 if (lit->toclevel == toclevel + 1 &&
403 start->layout().labeltype == lit->labeltype) {
404 start->setLayout(*lit);
413 pit_type const len = distance(start, finish);
414 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
415 for (; start != finish; ++start) {
416 toclevel = start->layout().toclevel;
417 if (toclevel == Layout::NOT_IN_TOC)
419 DocumentClass::const_iterator lit = tc.begin();
420 DocumentClass::const_iterator len = tc.end();
421 for (; lit != len; ++lit) {
422 if (lit->toclevel == toclevel - 1 &&
423 start->layout().labeltype == lit->labeltype) {
424 start->setLayout(*lit);
434 // FIXME This only really needs doing for the newly introduced
435 // paragraphs. Something like:
436 // pit_type const numpars = distance(start, finish);
437 // start = boost::next(bgn, pit);
438 // finish = boost::next(start, numpars);
439 // for (; start != finish; ++start)
440 // start->setBuffer(buf);
441 // But while this seems to work, it is kind of fragile.
442 buf.inset().setBuffer(buf);
446 void Text::number(Cursor & cur)
448 FontInfo font = ignore_font;
449 font.setNumber(FONT_TOGGLE);
450 toggleAndShow(cur, this, Font(font, ignore_language));
454 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
456 return par.isRTL(buffer.params());
460 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
462 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
464 BufferView * bv = &cur.bv();
465 TextMetrics & tm = bv->textMetrics(this);
466 if (!tm.contains(cur.pit())) {
467 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
468 tm = bv->textMetrics(this);
471 // FIXME: We use the update flag to indicates wether a singlePar or a
472 // full screen update is needed. We reset it here but shall we restore it
476 LASSERT(cur.text() == this, /**/);
477 CursorSlice oldTopSlice = cur.top();
478 bool oldBoundary = cur.boundary();
479 bool sel = cur.selection();
480 // Signals that, even if needsUpdate == false, an update of the
481 // cursor paragraph is required
482 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
483 LyXAction::SingleParUpdate);
484 // Signals that a full-screen update is required
485 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
486 LyXAction::NoUpdate) || singleParUpdate);
488 switch (cmd.action) {
490 case LFUN_PARAGRAPH_MOVE_DOWN: {
491 pit_type const pit = cur.pit();
492 recUndo(cur, pit, pit + 1);
494 swap(pars_[pit], pars_[pit + 1]);
495 cur.buffer()->updateLabels();
501 case LFUN_PARAGRAPH_MOVE_UP: {
502 pit_type const pit = cur.pit();
503 recUndo(cur, pit - 1, pit);
505 swap(pars_[pit], pars_[pit - 1]);
506 cur.buffer()->updateLabels();
512 case LFUN_APPENDIX: {
513 Paragraph & par = cur.paragraph();
514 bool start = !par.params().startOfAppendix();
516 // FIXME: The code below only makes sense at top level.
517 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
518 // ensure that we have only one start_of_appendix in this document
519 // FIXME: this don't work for multipart document!
520 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
521 if (pars_[tmp].params().startOfAppendix()) {
523 pars_[tmp].params().startOfAppendix(false);
529 par.params().startOfAppendix(start);
531 // we can set the refreshing parameters now
532 cur.buffer()->updateLabels();
536 case LFUN_WORD_DELETE_FORWARD:
538 cutSelection(cur, true, false);
540 deleteWordForward(cur);
541 finishChange(cur, false);
544 case LFUN_WORD_DELETE_BACKWARD:
546 cutSelection(cur, true, false);
548 deleteWordBackward(cur);
549 finishChange(cur, false);
552 case LFUN_LINE_DELETE:
554 cutSelection(cur, true, false);
556 tm.deleteLineForward(cur);
557 finishChange(cur, false);
560 case LFUN_BUFFER_BEGIN:
561 case LFUN_BUFFER_BEGIN_SELECT:
562 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
563 if (cur.depth() == 1)
564 needsUpdate |= cursorTop(cur);
567 cur.updateFlags(Update::FitCursor);
570 case LFUN_BUFFER_END:
571 case LFUN_BUFFER_END_SELECT:
572 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
573 if (cur.depth() == 1)
574 needsUpdate |= cursorBottom(cur);
577 cur.updateFlags(Update::FitCursor);
580 case LFUN_INSET_BEGIN:
581 case LFUN_INSET_BEGIN_SELECT:
582 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_BEGIN_SELECT);
583 if (cur.depth() == 1 || cur.pos() > 0)
584 needsUpdate |= cursorTop(cur);
587 cur.updateFlags(Update::FitCursor);
591 case LFUN_INSET_END_SELECT:
592 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_END_SELECT);
593 if (cur.depth() == 1 || cur.pos() < cur.lastpos())
594 needsUpdate |= cursorBottom(cur);
597 cur.updateFlags(Update::FitCursor);
600 case LFUN_CHAR_FORWARD:
601 case LFUN_CHAR_FORWARD_SELECT:
602 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
603 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
604 needsUpdate |= cursorForward(cur);
606 if (!needsUpdate && oldTopSlice == cur.top()
607 && cur.boundary() == oldBoundary) {
609 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
613 case LFUN_CHAR_BACKWARD:
614 case LFUN_CHAR_BACKWARD_SELECT:
615 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
616 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
617 needsUpdate |= cursorBackward(cur);
619 if (!needsUpdate && oldTopSlice == cur.top()
620 && cur.boundary() == oldBoundary) {
622 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
627 case LFUN_CHAR_LEFT_SELECT:
628 if (lyxrc.visual_cursor) {
629 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
630 needsUpdate |= cursorVisLeft(cur);
631 if (!needsUpdate && oldTopSlice == cur.top()
632 && cur.boundary() == oldBoundary) {
634 cmd = FuncRequest(LFUN_FINISHED_LEFT);
637 if (reverseDirectionNeeded(cur)) {
638 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
639 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
641 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
642 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
649 case LFUN_CHAR_RIGHT:
650 case LFUN_CHAR_RIGHT_SELECT:
651 if (lyxrc.visual_cursor) {
652 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
653 needsUpdate |= cursorVisRight(cur);
654 if (!needsUpdate && oldTopSlice == cur.top()
655 && cur.boundary() == oldBoundary) {
657 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
660 if (reverseDirectionNeeded(cur)) {
661 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
662 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
664 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
665 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
674 case LFUN_DOWN_SELECT:
677 // stop/start the selection
678 bool select = cmd.action == LFUN_DOWN_SELECT ||
679 cmd.action == LFUN_UP_SELECT;
681 // move cursor up/down
682 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
683 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
685 if (!atFirstOrLastRow) {
686 needsUpdate |= cur.selHandle(select);
687 cur.selHandle(select);
688 cur.upDownInText(up, needsUpdate);
689 needsUpdate |= cur.beforeDispatchCursor().inMathed();
691 // if the cursor cannot be moved up or down do not remove
692 // the selection right now, but wait for the next dispatch.
694 needsUpdate |= cur.selHandle(select);
695 cur.upDownInText(up, needsUpdate);
702 case LFUN_PARAGRAPH_UP:
703 case LFUN_PARAGRAPH_UP_SELECT:
704 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
705 needsUpdate |= cursorUpParagraph(cur);
708 case LFUN_PARAGRAPH_DOWN:
709 case LFUN_PARAGRAPH_DOWN_SELECT:
710 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
711 needsUpdate |= cursorDownParagraph(cur);
714 case LFUN_LINE_BEGIN:
715 case LFUN_LINE_BEGIN_SELECT:
716 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
717 needsUpdate |= tm.cursorHome(cur);
721 case LFUN_LINE_END_SELECT:
722 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
723 needsUpdate |= tm.cursorEnd(cur);
726 case LFUN_SECTION_SELECT: {
727 Buffer const & buf = *cur.buffer();
728 pit_type const pit = cur.pit();
729 ParagraphList & pars = buf.text().paragraphs();
730 ParagraphList::iterator bgn = pars.begin();
731 // The first paragraph of the area to be selected:
732 ParagraphList::iterator start = boost::next(bgn, pit);
733 // The final paragraph of area to be selected:
734 ParagraphList::iterator finish = start;
735 ParagraphList::iterator end = pars.end();
737 int const thistoclevel = start->layout().toclevel;
738 if (thistoclevel == Layout::NOT_IN_TOC)
742 Cursor const old_cur = cur;
743 needsUpdate |= cur.selHandle(true);
745 // Move out (down) from this section header
749 // Seek the one (on same level) below
750 for (; finish != end; ++finish, ++cur.pit()) {
751 int const toclevel = finish->layout().toclevel;
752 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
755 cur.pos() = cur.lastpos();
757 needsUpdate |= cur != old_cur;
761 case LFUN_WORD_RIGHT:
762 case LFUN_WORD_RIGHT_SELECT:
763 if (lyxrc.visual_cursor) {
764 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
765 needsUpdate |= cursorVisRightOneWord(cur);
766 if (!needsUpdate && oldTopSlice == cur.top()
767 && cur.boundary() == oldBoundary) {
769 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
772 if (reverseDirectionNeeded(cur)) {
773 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
774 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
776 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
777 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
784 case LFUN_WORD_FORWARD:
785 case LFUN_WORD_FORWARD_SELECT:
786 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
787 needsUpdate |= cursorForwardOneWord(cur);
791 case LFUN_WORD_LEFT_SELECT:
792 if (lyxrc.visual_cursor) {
793 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
794 needsUpdate |= cursorVisLeftOneWord(cur);
795 if (!needsUpdate && oldTopSlice == cur.top()
796 && cur.boundary() == oldBoundary) {
798 cmd = FuncRequest(LFUN_FINISHED_LEFT);
801 if (reverseDirectionNeeded(cur)) {
802 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
803 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
805 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
806 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
813 case LFUN_WORD_BACKWARD:
814 case LFUN_WORD_BACKWARD_SELECT:
815 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
816 needsUpdate |= cursorBackwardOneWord(cur);
819 case LFUN_WORD_SELECT: {
820 selectWord(cur, WHOLE_WORD);
821 finishChange(cur, true);
825 case LFUN_NEWLINE_INSERT: {
826 InsetNewlineParams inp;
827 docstring arg = cmd.argument();
828 // this avoids a double undo
829 // FIXME: should not be needed, ideally
830 if (!cur.selection())
832 cap::replaceSelection(cur);
833 if (arg == "linebreak")
834 inp.kind = InsetNewlineParams::LINEBREAK;
836 inp.kind = InsetNewlineParams::NEWLINE;
837 cur.insert(new InsetNewline(inp));
839 moveCursor(cur, false);
843 case LFUN_CHAR_DELETE_FORWARD:
844 if (!cur.selection()) {
845 if (cur.pos() == cur.paragraph().size())
846 // Par boundary, force full-screen update
847 singleParUpdate = false;
848 needsUpdate |= erase(cur);
850 // It is possible to make it a lot faster still
851 // just comment out the line below...
853 cutSelection(cur, true, false);
854 singleParUpdate = false;
856 moveCursor(cur, false);
859 case LFUN_CHAR_DELETE_BACKWARD:
860 if (!cur.selection()) {
861 if (bv->getIntl().getTransManager().backspace()) {
862 // Par boundary, full-screen update
864 singleParUpdate = false;
865 needsUpdate |= backspace(cur);
867 // It is possible to make it a lot faster still
868 // just comment out the line below...
871 cutSelection(cur, true, false);
872 singleParUpdate = false;
876 case LFUN_BREAK_PARAGRAPH:
877 cap::replaceSelection(cur);
878 breakParagraph(cur, cmd.argument() == "inverse");
883 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
884 // as its duties can be performed there. Should it be removed??
885 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
886 case LFUN_PARAGRAPH_SPACING: {
887 Paragraph & par = cur.paragraph();
888 Spacing::Space cur_spacing = par.params().spacing().getSpace();
889 string cur_value = "1.0";
890 if (cur_spacing == Spacing::Other)
891 cur_value = par.params().spacing().getValueAsString();
893 istringstream is(to_utf8(cmd.argument()));
896 Spacing::Space new_spacing = cur_spacing;
897 string new_value = cur_value;
899 lyxerr << "Missing argument to `paragraph-spacing'"
901 } else if (tmp == "single") {
902 new_spacing = Spacing::Single;
903 } else if (tmp == "onehalf") {
904 new_spacing = Spacing::Onehalf;
905 } else if (tmp == "double") {
906 new_spacing = Spacing::Double;
907 } else if (tmp == "other") {
908 new_spacing = Spacing::Other;
909 string tmpval = "0.0";
911 lyxerr << "new_value = " << tmpval << endl;
914 } else if (tmp == "default") {
915 new_spacing = Spacing::Default;
917 lyxerr << to_utf8(_("Unknown spacing argument: "))
918 << to_utf8(cmd.argument()) << endl;
920 if (cur_spacing != new_spacing || cur_value != new_value)
921 par.params().spacing(Spacing(new_spacing, new_value));
925 case LFUN_INSET_INSERT: {
928 // We have to avoid triggering InstantPreview loading
929 // before inserting into the document. See bug #5626.
930 bool loaded = bv->buffer().isFullyLoaded();
931 bv->buffer().setFullyLoaded(false);
932 Inset * inset = createInset(bv->buffer(), cmd);
933 bv->buffer().setFullyLoaded(loaded);
936 // FIXME (Abdel 01/02/2006):
937 // What follows would be a partial fix for bug 2154:
938 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
939 // This automatically put the label inset _after_ a
940 // numbered section. It should be possible to extend the mechanism
941 // to any kind of LateX environement.
942 // The correct way to fix that bug would be at LateX generation.
943 // I'll let the code here for reference as it could be used for some
944 // other feature like "automatic labelling".
946 Paragraph & par = pars_[cur.pit()];
947 if (inset->lyxCode() == LABEL_CODE
948 && par.layout().labeltype == LABEL_COUNTER) {
949 // Go to the end of the paragraph
950 // Warning: Because of Change-Tracking, the last
951 // position is 'size()' and not 'size()-1':
952 cur.pos() = par.size();
953 // Insert a new paragraph
954 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
959 cutSelection(cur, true, false);
963 // trigger InstantPreview now
964 if (inset->lyxCode() == EXTERNAL_CODE) {
965 InsetExternal & ins =
966 static_cast<InsetExternal &>(*inset);
974 case LFUN_INSET_DISSOLVE: {
975 // first, try if there's an inset at cursor
976 // FIXME: this first part should be moved to
977 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
978 // some generic "next-inset inset-dissolve"
979 Inset * inset = cur.nextInset();
980 if (inset && inset->isActive()) {
982 tmpcur.pushBackward(*inset);
983 inset->dispatch(tmpcur, cmd);
984 if (tmpcur.result().dispatched()) {
989 // if it did not work, try the underlying inset
990 if (dissolveInset(cur)) {
994 // if it did not work, do nothing.
998 case LFUN_SET_GRAPHICS_GROUP: {
999 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1005 string id = to_utf8(cmd.argument());
1006 string grp = graphics::getGroupParams(bv->buffer(), id);
1007 InsetGraphicsParams tmp, inspar = ins->getParams();
1010 inspar.groupId = to_utf8(cmd.argument());
1012 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1013 tmp.filename = inspar.filename;
1017 ins->setParams(inspar);
1020 case LFUN_SPACE_INSERT:
1021 if (cur.paragraph().layout().free_spacing)
1022 insertChar(cur, ' ');
1024 doInsertInset(cur, this, cmd, false, false);
1027 moveCursor(cur, false);
1030 case LFUN_SPECIALCHAR_INSERT: {
1031 string const name = to_utf8(cmd.argument());
1032 if (name == "hyphenation")
1033 specialChar(cur, InsetSpecialChar::HYPHENATION);
1034 else if (name == "ligature-break")
1035 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1036 else if (name == "slash")
1037 specialChar(cur, InsetSpecialChar::SLASH);
1038 else if (name == "nobreakdash")
1039 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1040 else if (name == "dots")
1041 specialChar(cur, InsetSpecialChar::LDOTS);
1042 else if (name == "end-of-sentence")
1043 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1044 else if (name == "menu-separator")
1045 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1046 else if (name.empty())
1047 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1049 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1053 case LFUN_WORD_UPCASE:
1054 changeCase(cur, text_uppercase);
1057 case LFUN_WORD_LOWCASE:
1058 changeCase(cur, text_lowercase);
1061 case LFUN_WORD_CAPITALIZE:
1062 changeCase(cur, text_capitalization);
1065 case LFUN_CHARS_TRANSPOSE:
1066 charsTranspose(cur);
1070 cur.message(_("Paste"));
1071 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1072 cap::replaceSelection(cur);
1074 // without argument?
1075 string const arg = to_utf8(cmd.argument());
1077 if (theClipboard().isInternal())
1078 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1079 else if (theClipboard().hasGraphicsContents()
1080 && !theClipboard().hasTextContents())
1081 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1083 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1084 } else if (isStrUnsignedInt(arg)) {
1085 // we have a numerical argument
1086 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1087 convert<unsigned int>(arg));
1089 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1091 type = Clipboard::PdfGraphicsType;
1092 else if (arg == "png")
1093 type = Clipboard::PngGraphicsType;
1094 else if (arg == "jpeg")
1095 type = Clipboard::JpegGraphicsType;
1096 else if (arg == "linkback")
1097 type = Clipboard::LinkBackGraphicsType;
1098 else if (arg == "emf")
1099 type = Clipboard::EmfGraphicsType;
1100 else if (arg == "wmf")
1101 type = Clipboard::WmfGraphicsType;
1104 LASSERT(false, /**/);
1106 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1109 bv->buffer().errors("Paste");
1110 cur.clearSelection(); // bug 393
1116 cutSelection(cur, true, true);
1117 cur.message(_("Cut"));
1122 cur.message(_("Copy"));
1125 case LFUN_SERVER_GET_XY:
1126 cur.message(from_utf8(
1127 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1128 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1131 case LFUN_SERVER_SET_XY: {
1134 istringstream is(to_utf8(cmd.argument()));
1137 lyxerr << "SETXY: Could not parse coordinates in '"
1138 << to_utf8(cmd.argument()) << endl;
1140 tm.setCursorFromCoordinates(cur, x, y);
1144 case LFUN_SERVER_GET_LAYOUT:
1145 cur.message(cur.paragraph().layout().name());
1149 docstring layout = cmd.argument();
1150 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1152 Paragraph const & para = cur.paragraph();
1153 docstring const old_layout = para.layout().name();
1154 DocumentClass const & tclass = bv->buffer().params().documentClass();
1157 layout = tclass.defaultLayoutName();
1159 if (para.forcePlainLayout())
1160 // in this case only the empty layout is allowed
1161 layout = tclass.plainLayoutName();
1162 else if (para.usePlainLayout()) {
1163 // in this case, default layout maps to empty layout
1164 if (layout == tclass.defaultLayoutName())
1165 layout = tclass.plainLayoutName();
1167 // otherwise, the empty layout maps to the default
1168 if (layout == tclass.plainLayoutName())
1169 layout = tclass.defaultLayoutName();
1172 bool hasLayout = tclass.hasLayout(layout);
1174 // If the entry is obsolete, use the new one instead.
1176 docstring const & obs = tclass[layout].obsoleted_by();
1182 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1183 from_utf8(N_(" not known")));
1187 bool change_layout = (old_layout != layout);
1189 if (!change_layout && cur.selection() &&
1190 cur.selBegin().pit() != cur.selEnd().pit())
1192 pit_type spit = cur.selBegin().pit();
1193 pit_type epit = cur.selEnd().pit() + 1;
1194 while (spit != epit) {
1195 if (pars_[spit].layout().name() != old_layout) {
1196 change_layout = true;
1204 setLayout(cur, layout);
1209 case LFUN_CLIPBOARD_PASTE:
1210 cur.clearSelection();
1211 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1212 cmd.argument() == "paragraph");
1213 bv->buffer().errors("Paste");
1216 case LFUN_PRIMARY_SELECTION_PASTE:
1217 pasteString(cur, theSelection().get(),
1218 cmd.argument() == "paragraph");
1221 case LFUN_SELECTION_PASTE:
1222 // Copy the selection buffer to the clipboard stack,
1223 // because we want it to appear in the "Edit->Paste
1225 cap::copySelectionToStack();
1226 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1227 bv->buffer().errors("Paste");
1230 case LFUN_UNICODE_INSERT: {
1231 if (cmd.argument().empty())
1233 docstring hexstring = cmd.argument();
1234 if (isHex(hexstring)) {
1235 char_type c = hexToInt(hexstring);
1236 if (c >= 32 && c < 0x10ffff) {
1237 lyxerr << "Inserting c: " << c << endl;
1238 docstring s = docstring(1, c);
1239 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1245 case LFUN_QUOTE_INSERT: {
1246 Paragraph & par = cur.paragraph();
1247 pos_type pos = cur.pos();
1248 BufferParams const & bufparams = bv->buffer().params();
1249 Layout const & style = par.layout();
1250 InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
1251 if (!style.pass_thru && !ilayout.isPassThru()
1252 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1253 // this avoids a double undo
1254 // FIXME: should not be needed, ideally
1255 if (!cur.selection())
1257 cap::replaceSelection(cur);
1262 else if (cur.prevInset() && cur.prevInset()->isSpace())
1265 c = par.getChar(pos - 1);
1266 string arg = to_utf8(cmd.argument());
1267 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1268 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1272 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1276 case LFUN_DATE_INSERT: {
1277 string const format = cmd.argument().empty()
1278 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1279 string const time = formatted_time(current_time(), format);
1280 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1284 case LFUN_MOUSE_TRIPLE:
1285 if (cmd.button() == mouse_button::button1) {
1294 case LFUN_MOUSE_DOUBLE:
1295 if (cmd.button() == mouse_button::button1) {
1296 selectWord(cur, WHOLE_WORD_STRICT);
1301 // Single-click on work area
1302 case LFUN_MOUSE_PRESS:
1303 // We are not marking a selection with the keyboard in any case.
1304 cur.bv().cursor().setMark(false);
1305 switch (cmd.button()) {
1306 case mouse_button::button1:
1308 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1309 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1312 case mouse_button::button2:
1313 // Middle mouse pasting.
1314 bv->mouseSetCursor(cur);
1316 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1317 "selection-paste ; primary-selection-paste paragraph"));
1321 case mouse_button::button3: {
1322 Cursor const & bvcur = cur.bv().cursor();
1323 // Don't do anything if we right-click a
1324 // selection, a context menu will popup.
1325 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1326 && cur < bvcur.selectionEnd()) {
1330 if (!bv->mouseSetCursor(cur, false))
1331 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1337 } // switch (cmd.button())
1340 case LFUN_MOUSE_MOTION: {
1341 // Mouse motion with right or middle mouse do nothing for now.
1342 if (cmd.button() != mouse_button::button1) {
1346 // ignore motions deeper nested than the real anchor
1347 Cursor & bvcur = cur.bv().cursor();
1348 if (!bvcur.anchor_.hasPart(cur)) {
1352 CursorSlice old = bvcur.top();
1354 int const wh = bv->workHeight();
1355 int const y = max(0, min(wh - 1, cmd.y));
1357 tm.setCursorFromCoordinates(cur, cmd.x, y);
1358 cur.setTargetX(cmd.x);
1360 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1362 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1363 // This is to allow jumping over large insets
1364 if (cur.top() == old) {
1366 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1368 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1370 // We continue with our existing selection or start a new one, so don't
1371 // reset the anchor.
1372 bvcur.setCursor(cur);
1373 bvcur.setSelection(true);
1374 if (cur.top() == old) {
1375 // We didn't move one iota, so no need to update the screen.
1376 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1383 case LFUN_MOUSE_RELEASE:
1384 switch (cmd.button()) {
1385 case mouse_button::button1:
1386 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1387 // If there is a new selection, update persistent selection;
1388 // otherwise, single click does not clear persistent selection
1390 if (cur.selection()) {
1391 // Finish selection. If double click,
1392 // cur is moved to the end of word by
1393 // selectWord but bvcur is current
1395 cur.bv().cursor().setSelection();
1396 // We might have removed an empty but drawn selection
1397 // (probably a margin)
1398 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1401 // FIXME: We could try to handle drag and drop of selection here.
1404 case mouse_button::button2:
1405 // Middle mouse pasting is handled at mouse press time,
1406 // see LFUN_MOUSE_PRESS.
1410 case mouse_button::button3:
1411 // Cursor was set at LFUN_MOUSE_PRESS time.
1412 // FIXME: If there is a selection we could try to handle a special
1413 // drag & drop context menu.
1417 case mouse_button::none:
1418 case mouse_button::button4:
1419 case mouse_button::button5:
1421 } // switch (cmd.button())
1425 case LFUN_SELF_INSERT: {
1426 if (cmd.argument().empty())
1429 // Automatically delete the currently selected
1430 // text and replace it with what is being
1431 // typed in now. Depends on lyxrc settings
1432 // "auto_region_delete", which defaults to
1435 if (lyxrc.auto_region_delete && cur.selection())
1436 cutSelection(cur, false, false);
1438 cur.clearSelection();
1440 docstring::const_iterator cit = cmd.argument().begin();
1441 docstring::const_iterator const end = cmd.argument().end();
1442 for (; cit != end; ++cit)
1443 bv->translateAndInsert(*cit, this, cur);
1446 moveCursor(cur, false);
1447 bv->bookmarkEditPosition();
1451 case LFUN_HYPERLINK_INSERT: {
1452 InsetCommandParams p(HYPERLINK_CODE);
1454 if (cur.selection()) {
1455 content = cur.selectionAsString(false);
1456 cutSelection(cur, true, false);
1458 p["target"] = (cmd.argument().empty()) ?
1459 content : cmd.argument();
1460 string const data = InsetCommand::params2string("href", p);
1461 if (p["target"].empty()) {
1462 bv->showDialog("href", data);
1464 FuncRequest fr(LFUN_INSET_INSERT, data);
1470 case LFUN_LABEL_INSERT: {
1471 InsetCommandParams p(LABEL_CODE);
1472 // Try to generate a valid label
1473 p["name"] = (cmd.argument().empty()) ?
1474 cur.getPossibleLabel() :
1476 string const data = InsetCommand::params2string("label", p);
1478 if (cmd.argument().empty()) {
1479 bv->showDialog("label", data);
1481 FuncRequest fr(LFUN_INSET_INSERT, data);
1487 case LFUN_INFO_INSERT: {
1489 if (cmd.argument().empty() && cur.selection()) {
1490 // if command argument is empty use current selection as parameter.
1491 docstring ds = cur.selectionAsString(false);
1492 cutSelection(cur, true, false);
1493 FuncRequest cmd0(cmd, ds);
1494 inset = createInset(cur.bv().buffer(), cmd0);
1496 inset = createInset(cur.bv().buffer(), cmd);
1500 insertInset(cur, inset);
1504 case LFUN_CAPTION_INSERT:
1505 case LFUN_FOOTNOTE_INSERT:
1506 case LFUN_NOTE_INSERT:
1507 case LFUN_FLEX_INSERT:
1508 case LFUN_BOX_INSERT:
1509 case LFUN_BRANCH_INSERT:
1510 case LFUN_PHANTOM_INSERT:
1511 case LFUN_ERT_INSERT:
1512 case LFUN_LISTING_INSERT:
1513 case LFUN_MARGINALNOTE_INSERT:
1514 case LFUN_OPTIONAL_INSERT:
1515 case LFUN_INDEX_INSERT:
1516 // Open the inset, and move the current selection
1518 doInsertInset(cur, this, cmd, true, true);
1520 // Some insets are numbered, others are shown in the outline pane so
1521 // let's update the labels and the toc backend.
1522 bv->buffer().updateLabels();
1525 case LFUN_TABULAR_INSERT:
1526 // if there were no arguments, just open the dialog
1527 if (doInsertInset(cur, this, cmd, false, true))
1530 bv->showDialog("tabularcreate");
1534 case LFUN_FLOAT_INSERT:
1535 case LFUN_FLOAT_WIDE_INSERT:
1536 case LFUN_WRAP_INSERT: {
1537 // will some text be moved into the inset?
1538 bool content = cur.selection();
1540 doInsertInset(cur, this, cmd, true, true);
1543 // If some text is moved into the inset, doInsertInset
1544 // puts the cursor outside the inset. To insert the
1545 // caption we put it back into the inset.
1549 ParagraphList & pars = cur.text()->paragraphs();
1551 DocumentClass const & tclass = bv->buffer().params().documentClass();
1553 // add a separate paragraph for the caption inset
1554 pars.push_back(Paragraph());
1555 pars.back().setInsetOwner(&pars[0].inInset());
1556 pars.back().setPlainOrDefaultLayout(tclass);
1557 int cap_pit = pars.size() - 1;
1559 // if an empty inset was created, we create an additional empty
1560 // paragraph at the bottom so that the user can choose where to put
1561 // the graphics (or table).
1563 pars.push_back(Paragraph());
1564 pars.back().setInsetOwner(&pars[0].inInset());
1565 pars.back().setPlainOrDefaultLayout(tclass);
1568 // reposition the cursor to the caption
1569 cur.pit() = cap_pit;
1571 // FIXME: This Text/Cursor dispatch handling is a mess!
1572 // We cannot use Cursor::dispatch here it needs access to up to
1574 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1575 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1576 bv->buffer().updateLabels();
1577 cur.updateFlags(Update::Force);
1578 // FIXME: When leaving the Float (or Wrap) inset we should
1579 // delete any empty paragraph left above or below the
1584 case LFUN_NOMENCL_INSERT: {
1585 InsetCommandParams p(NOMENCL_CODE);
1586 if (cmd.argument().empty())
1587 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1589 p["symbol"] = cmd.argument();
1590 string const data = InsetCommand::params2string("nomenclature", p);
1591 bv->showDialog("nomenclature", data);
1595 case LFUN_INDEX_PRINT: {
1596 InsetCommandParams p(INDEX_PRINT_CODE);
1597 if (cmd.argument().empty())
1598 p["type"] = from_ascii("idx");
1600 p["type"] = cmd.argument();
1601 string const data = InsetCommand::params2string("index_print", p);
1602 FuncRequest fr(LFUN_INSET_INSERT, data);
1607 case LFUN_NOMENCL_PRINT:
1608 case LFUN_TOC_INSERT:
1609 case LFUN_LINE_INSERT:
1610 case LFUN_NEWPAGE_INSERT:
1612 doInsertInset(cur, this, cmd, false, false);
1616 case LFUN_DEPTH_DECREMENT:
1617 changeDepth(cur, DEC_DEPTH);
1620 case LFUN_DEPTH_INCREMENT:
1621 changeDepth(cur, INC_DEPTH);
1624 case LFUN_MATH_DISPLAY:
1625 mathDispatch(cur, cmd, true);
1628 case LFUN_REGEXP_MODE:
1629 regexpDispatch(cur, cmd);
1632 case LFUN_MATH_MODE:
1633 if (cmd.argument() == "on")
1634 // don't pass "on" as argument
1635 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1637 mathDispatch(cur, cmd, false);
1640 case LFUN_MATH_MACRO:
1641 if (cmd.argument().empty())
1642 cur.errorMessage(from_utf8(N_("Missing argument")));
1644 string s = to_utf8(cmd.argument());
1645 string const s1 = token(s, ' ', 1);
1646 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1647 string const s2 = token(s, ' ', 2);
1648 MacroType type = MacroTypeNewcommand;
1650 type = MacroTypeDef;
1651 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1652 inset->setBuffer(bv->buffer());
1653 insertInset(cur, inset);
1655 // enter macro inset and select the name
1657 cur.top().pos() = cur.top().lastpos();
1659 cur.setSelection(true);
1660 cur.top().pos() = 0;
1664 // passthrough hat and underscore outside mathed:
1665 case LFUN_MATH_SUBSCRIPT:
1666 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1668 case LFUN_MATH_SUPERSCRIPT:
1669 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1672 case LFUN_MATH_INSERT:
1673 case LFUN_MATH_MATRIX:
1674 case LFUN_MATH_DELIM:
1675 case LFUN_MATH_BIGDELIM: {
1677 cap::replaceSelection(cur);
1678 cur.insert(new InsetMathHull(hullSimple));
1679 checkAndActivateInset(cur, true);
1680 LASSERT(cur.inMathed(), /**/);
1685 case LFUN_FONT_EMPH: {
1686 Font font(ignore_font, ignore_language);
1687 font.fontInfo().setEmph(FONT_TOGGLE);
1688 toggleAndShow(cur, this, font);
1692 case LFUN_FONT_ITAL: {
1693 Font font(ignore_font, ignore_language);
1694 font.fontInfo().setShape(ITALIC_SHAPE);
1695 toggleAndShow(cur, this, font);
1699 case LFUN_FONT_BOLD:
1700 case LFUN_FONT_BOLDSYMBOL: {
1701 Font font(ignore_font, ignore_language);
1702 font.fontInfo().setSeries(BOLD_SERIES);
1703 toggleAndShow(cur, this, font);
1707 case LFUN_FONT_NOUN: {
1708 Font font(ignore_font, ignore_language);
1709 font.fontInfo().setNoun(FONT_TOGGLE);
1710 toggleAndShow(cur, this, font);
1714 case LFUN_FONT_TYPEWRITER: {
1715 Font font(ignore_font, ignore_language);
1716 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1717 toggleAndShow(cur, this, font);
1721 case LFUN_FONT_SANS: {
1722 Font font(ignore_font, ignore_language);
1723 font.fontInfo().setFamily(SANS_FAMILY);
1724 toggleAndShow(cur, this, font);
1728 case LFUN_FONT_ROMAN: {
1729 Font font(ignore_font, ignore_language);
1730 font.fontInfo().setFamily(ROMAN_FAMILY);
1731 toggleAndShow(cur, this, font);
1735 case LFUN_FONT_DEFAULT: {
1736 Font font(inherit_font, ignore_language);
1737 toggleAndShow(cur, this, font);
1741 case LFUN_FONT_STRIKEOUT: {
1742 Font font(ignore_font, ignore_language);
1743 font.fontInfo().setStrikeout(FONT_TOGGLE);
1744 toggleAndShow(cur, this, font);
1748 case LFUN_FONT_UULINE: {
1749 Font font(ignore_font, ignore_language);
1750 font.fontInfo().setUuline(FONT_TOGGLE);
1751 toggleAndShow(cur, this, font);
1755 case LFUN_FONT_UWAVE: {
1756 Font font(ignore_font, ignore_language);
1757 font.fontInfo().setUwave(FONT_TOGGLE);
1758 toggleAndShow(cur, this, font);
1762 case LFUN_FONT_UNDERLINE: {
1763 Font font(ignore_font, ignore_language);
1764 font.fontInfo().setUnderbar(FONT_TOGGLE);
1765 toggleAndShow(cur, this, font);
1769 case LFUN_FONT_SIZE: {
1770 Font font(ignore_font, ignore_language);
1771 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1772 toggleAndShow(cur, this, font);
1776 case LFUN_LANGUAGE: {
1777 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1780 Font font(ignore_font, lang);
1781 toggleAndShow(cur, this, font);
1785 case LFUN_TEXTSTYLE_APPLY:
1786 toggleAndShow(cur, this, freefont, toggleall);
1787 cur.message(_("Character set"));
1790 // Set the freefont using the contents of \param data dispatched from
1791 // the frontends and apply it at the current cursor location.
1792 case LFUN_TEXTSTYLE_UPDATE: {
1795 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1798 toggleAndShow(cur, this, freefont, toggleall);
1799 cur.message(_("Character set"));
1801 lyxerr << "Argument not ok";
1806 case LFUN_FINISHED_LEFT:
1807 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1808 // We're leaving an inset, going left. If the inset is LTR, we're
1809 // leaving from the front, so we should not move (remain at --- but
1810 // not in --- the inset). If the inset is RTL, move left, without
1811 // entering the inset itself; i.e., move to after the inset.
1812 if (cur.paragraph().getFontSettings(
1813 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1814 cursorVisLeft(cur, true);
1817 case LFUN_FINISHED_RIGHT:
1818 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1819 // We're leaving an inset, going right. If the inset is RTL, we're
1820 // leaving from the front, so we should not move (remain at --- but
1821 // not in --- the inset). If the inset is LTR, move right, without
1822 // entering the inset itself; i.e., move to after the inset.
1823 if (!cur.paragraph().getFontSettings(
1824 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1825 cursorVisRight(cur, true);
1828 case LFUN_FINISHED_BACKWARD:
1829 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1832 case LFUN_FINISHED_FORWARD:
1833 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1835 cur.setCurrentFont();
1838 case LFUN_LAYOUT_PARAGRAPH: {
1840 params2string(cur.paragraph(), data);
1841 data = "show\n" + data;
1842 bv->showDialog("paragraph", data);
1846 case LFUN_PARAGRAPH_UPDATE: {
1848 params2string(cur.paragraph(), data);
1850 // Will the paragraph accept changes from the dialog?
1852 cur.inset().allowParagraphCustomization(cur.idx());
1854 data = "update " + convert<string>(accept) + '\n' + data;
1855 bv->updateDialog("paragraph", data);
1859 case LFUN_ACCENT_UMLAUT:
1860 case LFUN_ACCENT_CIRCUMFLEX:
1861 case LFUN_ACCENT_GRAVE:
1862 case LFUN_ACCENT_ACUTE:
1863 case LFUN_ACCENT_TILDE:
1864 case LFUN_ACCENT_CEDILLA:
1865 case LFUN_ACCENT_MACRON:
1866 case LFUN_ACCENT_DOT:
1867 case LFUN_ACCENT_UNDERDOT:
1868 case LFUN_ACCENT_UNDERBAR:
1869 case LFUN_ACCENT_CARON:
1870 case LFUN_ACCENT_BREVE:
1871 case LFUN_ACCENT_TIE:
1872 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1873 case LFUN_ACCENT_CIRCLE:
1874 case LFUN_ACCENT_OGONEK:
1875 theLyXFunc().handleKeyFunc(cmd.action);
1876 if (!cmd.argument().empty())
1877 // FIXME: Are all these characters encoded in one byte in utf8?
1878 bv->translateAndInsert(cmd.argument()[0], this, cur);
1881 case LFUN_FLOAT_LIST_INSERT: {
1882 DocumentClass const & tclass = bv->buffer().params().documentClass();
1883 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1885 if (cur.selection())
1886 cutSelection(cur, true, false);
1887 breakParagraph(cur);
1889 if (cur.lastpos() != 0) {
1890 cursorBackward(cur);
1891 breakParagraph(cur);
1894 docstring const laystr = cur.inset().usePlainLayout() ?
1895 tclass.plainLayoutName() :
1896 tclass.defaultLayoutName();
1897 setLayout(cur, laystr);
1898 ParagraphParameters p;
1899 // FIXME If this call were replaced with one to clearParagraphParams(),
1900 // then we could get rid of this method altogether.
1901 setParagraphs(cur, p);
1902 // FIXME This should be simplified when InsetFloatList takes a
1903 // Buffer in its constructor.
1904 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1905 ifl->setBuffer(bv->buffer());
1906 insertInset(cur, ifl);
1909 lyxerr << "Non-existent float type: "
1910 << to_utf8(cmd.argument()) << endl;
1915 case LFUN_CHANGE_ACCEPT: {
1916 acceptOrRejectChanges(cur, ACCEPT);
1920 case LFUN_CHANGE_REJECT: {
1921 acceptOrRejectChanges(cur, REJECT);
1925 case LFUN_THESAURUS_ENTRY: {
1926 docstring arg = cmd.argument();
1928 arg = cur.selectionAsString(false);
1930 if (arg.size() > 100 || arg.empty()) {
1931 // Get word or selection
1932 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1933 arg = cur.selectionAsString(false);
1934 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1937 bv->showDialog("thesaurus", to_utf8(arg));
1941 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1942 // Given data, an encoding of the ParagraphParameters
1943 // generated in the Paragraph dialog, this function sets
1944 // the current paragraph, or currently selected paragraphs,
1946 // NOTE: This function overrides all existing settings.
1947 setParagraphs(cur, cmd.argument());
1948 cur.message(_("Paragraph layout set"));
1952 case LFUN_PARAGRAPH_PARAMS: {
1953 // Given data, an encoding of the ParagraphParameters as we'd
1954 // find them in a LyX file, this function modifies the current paragraph,
1955 // or currently selected paragraphs.
1956 // NOTE: This function only modifies, and does not override, existing
1958 setParagraphs(cur, cmd.argument(), true);
1959 cur.message(_("Paragraph layout set"));
1964 if (cur.selection()) {
1965 cur.setSelection(false);
1968 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1969 // correct, but I'm not 100% sure -- dov, 071019
1970 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1974 case LFUN_OUTLINE_UP:
1975 outline(OutlineUp, cur);
1976 setCursor(cur, cur.pit(), 0);
1977 cur.buffer()->updateLabels();
1981 case LFUN_OUTLINE_DOWN:
1982 outline(OutlineDown, cur);
1983 setCursor(cur, cur.pit(), 0);
1984 cur.buffer()->updateLabels();
1988 case LFUN_OUTLINE_IN:
1989 outline(OutlineIn, cur);
1990 cur.buffer()->updateLabels();
1994 case LFUN_OUTLINE_OUT:
1995 outline(OutlineOut, cur);
1996 cur.buffer()->updateLabels();
2001 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2006 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2008 // FIXME: The cursor flag is reset two lines below
2009 // so we need to check here if some of the LFUN did touch that.
2010 // for now only Text::erase() and Text::backspace() do that.
2011 // The plan is to verify all the LFUNs and then to remove this
2012 // singleParUpdate boolean altogether.
2013 if (cur.result().update() & Update::Force) {
2014 singleParUpdate = false;
2018 // FIXME: the following code should go in favor of fine grained
2019 // update flag treatment.
2020 if (singleParUpdate) {
2021 // Inserting characters does not change par height in general. So, try
2022 // to update _only_ this paragraph. BufferView will detect if a full
2023 // metrics update is needed anyway.
2024 cur.updateFlags(Update::SinglePar | Update::FitCursor);
2029 && &oldTopSlice.inset() == &cur.inset()
2030 && oldTopSlice.idx() == cur.idx()
2031 && !sel // sel is a backup of cur.selection() at the biginning of the function.
2032 && !cur.selection())
2033 // FIXME: it would be better if we could just do this
2035 //if (cur.result().update() != Update::FitCursor)
2038 // But some LFUNs do not set Update::FitCursor when needed, so we
2039 // do it for all. This is not very harmfull as FitCursor will provoke
2040 // a full redraw only if needed but still, a proper review of all LFUN
2041 // should be done and this needsUpdate boolean can then be removed.
2042 cur.updateFlags(Update::FitCursor);
2044 cur.updateFlags(Update::Force | Update::FitCursor);
2048 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2049 FuncStatus & flag) const
2051 LASSERT(cur.text() == this, /**/);
2053 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2055 InsetCode code = NO_CODE;
2057 switch (cmd.action) {
2059 case LFUN_DEPTH_DECREMENT:
2060 enable = changeDepthAllowed(cur, DEC_DEPTH);
2063 case LFUN_DEPTH_INCREMENT:
2064 enable = changeDepthAllowed(cur, INC_DEPTH);
2068 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2071 case LFUN_DIALOG_SHOW_NEW_INSET:
2072 if (cmd.argument() == "bibitem")
2073 code = BIBITEM_CODE;
2074 else if (cmd.argument() == "bibtex")
2076 else if (cmd.argument() == "box")
2078 else if (cmd.argument() == "branch")
2080 else if (cmd.argument() == "citation")
2082 else if (cmd.argument() == "ert")
2084 else if (cmd.argument() == "external")
2085 code = EXTERNAL_CODE;
2086 else if (cmd.argument() == "float")
2088 else if (cmd.argument() == "graphics")
2089 code = GRAPHICS_CODE;
2090 else if (cmd.argument() == "href")
2091 code = HYPERLINK_CODE;
2092 else if (cmd.argument() == "include")
2093 code = INCLUDE_CODE;
2094 else if (cmd.argument() == "index")
2096 else if (cmd.argument() == "index_print")
2097 code = INDEX_PRINT_CODE;
2098 else if (cmd.argument() == "nomenclature")
2099 code = NOMENCL_CODE;
2100 else if (cmd.argument() == "label")
2102 else if (cmd.argument() == "note")
2104 else if (cmd.argument() == "phantom")
2105 code = PHANTOM_CODE;
2106 else if (cmd.argument() == "ref")
2108 else if (cmd.argument() == "space")
2110 else if (cmd.argument() == "toc")
2112 else if (cmd.argument() == "vspace")
2114 else if (cmd.argument() == "wrap")
2116 else if (cmd.argument() == "listings")
2117 code = LISTINGS_CODE;
2120 case LFUN_ERT_INSERT:
2123 case LFUN_LISTING_INSERT:
2124 code = LISTINGS_CODE;
2125 // not allowed in description items
2126 enable = !inDescriptionItem(cur);
2128 case LFUN_FOOTNOTE_INSERT:
2131 case LFUN_TABULAR_INSERT:
2132 code = TABULAR_CODE;
2134 case LFUN_MARGINALNOTE_INSERT:
2137 case LFUN_FLOAT_INSERT:
2138 case LFUN_FLOAT_WIDE_INSERT:
2140 // not allowed in description items
2141 enable = !inDescriptionItem(cur);
2143 case LFUN_WRAP_INSERT:
2145 // not allowed in description items
2146 enable = !inDescriptionItem(cur);
2148 case LFUN_FLOAT_LIST_INSERT:
2149 code = FLOAT_LIST_CODE;
2151 case LFUN_CAPTION_INSERT:
2152 code = CAPTION_CODE;
2153 // not allowed in description items
2154 enable = !inDescriptionItem(cur);
2156 case LFUN_NOTE_INSERT:
2158 // in commands (sections etc.) and description items,
2159 // only Notes are allowed
2160 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2161 (!cur.paragraph().layout().isCommand()
2162 && !inDescriptionItem(cur)));
2164 case LFUN_FLEX_INSERT: {
2166 string s = cmd.getArg(0);
2168 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2169 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2170 il.lyxtype() != InsetLayout::CUSTOM &&
2171 il.lyxtype() != InsetLayout::ELEMENT &&
2172 il.lyxtype ()!= InsetLayout::STANDARD)
2176 case LFUN_BOX_INSERT:
2179 case LFUN_BRANCH_INSERT:
2181 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
2182 && cur.buffer()->params().branchlist().empty())
2185 case LFUN_PHANTOM_INSERT:
2186 code = PHANTOM_CODE;
2188 case LFUN_LABEL_INSERT:
2191 case LFUN_INFO_INSERT:
2194 case LFUN_OPTIONAL_INSERT:
2196 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2197 < cur.paragraph().layout().optionalargs;
2199 case LFUN_INDEX_INSERT:
2202 case LFUN_INDEX_PRINT:
2203 code = INDEX_PRINT_CODE;
2205 case LFUN_NOMENCL_INSERT:
2206 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2210 code = NOMENCL_CODE;
2212 case LFUN_NOMENCL_PRINT:
2213 code = NOMENCL_PRINT_CODE;
2215 case LFUN_TOC_INSERT:
2218 case LFUN_HYPERLINK_INSERT:
2219 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2223 code = HYPERLINK_CODE;
2225 case LFUN_QUOTE_INSERT:
2226 // always allow this, since we will inset a raw quote
2227 // if an inset is not allowed.
2229 case LFUN_SPECIALCHAR_INSERT:
2230 code = SPECIALCHAR_CODE;
2232 case LFUN_SPACE_INSERT:
2233 // slight hack: we know this is allowed in math mode
2238 case LFUN_INSET_MODIFY:
2239 // We need to disable this, because we may get called for a
2241 // InsetTabular::getStatus() -> InsetText::getStatus()
2242 // and we don't handle LFUN_INSET_MODIFY.
2246 case LFUN_FONT_EMPH:
2247 flag.setOnOff(fontinfo.emph() == FONT_ON);
2250 case LFUN_FONT_ITAL:
2251 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2254 case LFUN_FONT_NOUN:
2255 flag.setOnOff(fontinfo.noun() == FONT_ON);
2258 case LFUN_FONT_BOLD:
2259 case LFUN_FONT_BOLDSYMBOL:
2260 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2263 case LFUN_FONT_SANS:
2264 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2267 case LFUN_FONT_ROMAN:
2268 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2271 case LFUN_FONT_TYPEWRITER:
2272 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2277 enable = cur.selection();
2281 if (cmd.argument().empty()) {
2282 if (theClipboard().isInternal())
2283 enable = cap::numberOfSelections() > 0;
2285 enable = !theClipboard().empty();
2289 // we have an argument
2290 string const arg = to_utf8(cmd.argument());
2291 if (isStrUnsignedInt(arg)) {
2292 // it's a number and therefore means the internal stack
2293 unsigned int n = convert<unsigned int>(arg);
2294 enable = cap::numberOfSelections() > n;
2298 // explicit graphics type?
2299 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2300 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2301 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2302 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2303 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2304 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2305 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2306 enable = theClipboard().hasGraphicsContents(type);
2315 case LFUN_CLIPBOARD_PASTE:
2316 enable = !theClipboard().empty();
2319 case LFUN_PRIMARY_SELECTION_PASTE:
2320 enable = cur.selection() || !theSelection().empty();
2323 case LFUN_SELECTION_PASTE:
2324 enable = cap::selection();
2327 case LFUN_PARAGRAPH_MOVE_UP:
2328 enable = cur.pit() > 0 && !cur.selection();
2331 case LFUN_PARAGRAPH_MOVE_DOWN:
2332 enable = cur.pit() < cur.lastpit() && !cur.selection();
2335 case LFUN_INSET_DISSOLVE:
2336 if (!cmd.argument().empty()) {
2337 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2338 InsetLayout::InsetLyXType const type =
2339 translateLyXType(to_utf8(cmd.argument()));
2340 enable = cur.inset().lyxCode() == FLEX_CODE
2341 && il.lyxtype() == type;
2343 enable = ((!isMainText(cur.bv().buffer())
2344 && cur.inset().nargs() == 1)
2346 && cur.nextInset()->nargs() == 1));
2350 case LFUN_CHANGE_ACCEPT:
2351 case LFUN_CHANGE_REJECT:
2352 // In principle, these LFUNs should only be enabled if there
2353 // is a change at the current position/in the current selection.
2354 // However, without proper optimizations, this will inevitably
2355 // result in unacceptable performance - just imagine a user who
2356 // wants to select the complete content of a long document.
2357 if (!cur.selection()) {
2358 Change const & change = cur.paragraph().lookupChange(cur.pos());
2359 enable = change.changed();
2361 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2366 case LFUN_OUTLINE_UP:
2367 case LFUN_OUTLINE_DOWN:
2368 case LFUN_OUTLINE_IN:
2369 case LFUN_OUTLINE_OUT:
2370 // FIXME: LyX is not ready for outlining within inset.
2371 enable = isMainText(cur.bv().buffer())
2372 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2375 case LFUN_NEWLINE_INSERT:
2376 // LaTeX restrictions (labels or empty par)
2377 enable = (cur.pos() > cur.paragraph().beginOfBody());
2380 case LFUN_SET_GRAPHICS_GROUP: {
2381 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2385 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2389 case LFUN_NEWPAGE_INSERT:
2390 // not allowed in description items
2391 enable = !inDescriptionItem(cur);
2394 case LFUN_MATH_INSERT:
2395 case LFUN_MATH_MATRIX:
2396 case LFUN_MATH_DELIM:
2397 case LFUN_MATH_BIGDELIM:
2398 // not allowed in ERT, for example.
2399 enable = cur.inset().insetAllowed(MATH_CODE);
2402 case LFUN_DATE_INSERT: {
2403 string const format = cmd.argument().empty()
2404 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2405 enable = support::os::is_valid_strftime(format);
2409 case LFUN_WORD_DELETE_FORWARD:
2410 case LFUN_WORD_DELETE_BACKWARD:
2411 case LFUN_LINE_DELETE:
2412 case LFUN_WORD_FORWARD:
2413 case LFUN_WORD_BACKWARD:
2414 case LFUN_WORD_RIGHT:
2415 case LFUN_WORD_LEFT:
2416 case LFUN_CHAR_FORWARD:
2417 case LFUN_CHAR_FORWARD_SELECT:
2418 case LFUN_CHAR_BACKWARD:
2419 case LFUN_CHAR_BACKWARD_SELECT:
2420 case LFUN_CHAR_LEFT:
2421 case LFUN_CHAR_LEFT_SELECT:
2422 case LFUN_CHAR_RIGHT:
2423 case LFUN_CHAR_RIGHT_SELECT:
2425 case LFUN_UP_SELECT:
2427 case LFUN_DOWN_SELECT:
2428 case LFUN_PARAGRAPH_UP_SELECT:
2429 case LFUN_PARAGRAPH_DOWN_SELECT:
2430 case LFUN_LINE_BEGIN_SELECT:
2431 case LFUN_LINE_END_SELECT:
2432 case LFUN_WORD_FORWARD_SELECT:
2433 case LFUN_WORD_BACKWARD_SELECT:
2434 case LFUN_WORD_RIGHT_SELECT:
2435 case LFUN_WORD_LEFT_SELECT:
2436 case LFUN_WORD_SELECT:
2437 case LFUN_SECTION_SELECT:
2438 case LFUN_PARAGRAPH_UP:
2439 case LFUN_PARAGRAPH_DOWN:
2440 case LFUN_LINE_BEGIN:
2442 case LFUN_CHAR_DELETE_FORWARD:
2443 case LFUN_CHAR_DELETE_BACKWARD:
2444 case LFUN_BREAK_PARAGRAPH:
2445 case LFUN_PARAGRAPH_SPACING:
2446 case LFUN_INSET_INSERT:
2447 case LFUN_WORD_UPCASE:
2448 case LFUN_WORD_LOWCASE:
2449 case LFUN_WORD_CAPITALIZE:
2450 case LFUN_CHARS_TRANSPOSE:
2451 case LFUN_SERVER_GET_XY:
2452 case LFUN_SERVER_SET_XY:
2453 case LFUN_SERVER_GET_LAYOUT:
2455 case LFUN_SELF_INSERT:
2456 case LFUN_LINE_INSERT:
2457 case LFUN_MATH_DISPLAY:
2458 case LFUN_MATH_MODE:
2459 case LFUN_MATH_MACRO:
2460 case LFUN_MATH_SUBSCRIPT:
2461 case LFUN_MATH_SUPERSCRIPT:
2462 case LFUN_FONT_DEFAULT:
2463 case LFUN_FONT_UNDERLINE:
2464 case LFUN_FONT_STRIKEOUT:
2465 case LFUN_FONT_UULINE:
2466 case LFUN_FONT_UWAVE:
2467 case LFUN_FONT_SIZE:
2469 case LFUN_TEXTSTYLE_APPLY:
2470 case LFUN_TEXTSTYLE_UPDATE:
2471 case LFUN_LAYOUT_PARAGRAPH:
2472 case LFUN_PARAGRAPH_UPDATE:
2473 case LFUN_ACCENT_UMLAUT:
2474 case LFUN_ACCENT_CIRCUMFLEX:
2475 case LFUN_ACCENT_GRAVE:
2476 case LFUN_ACCENT_ACUTE:
2477 case LFUN_ACCENT_TILDE:
2478 case LFUN_ACCENT_CEDILLA:
2479 case LFUN_ACCENT_MACRON:
2480 case LFUN_ACCENT_DOT:
2481 case LFUN_ACCENT_UNDERDOT:
2482 case LFUN_ACCENT_UNDERBAR:
2483 case LFUN_ACCENT_CARON:
2484 case LFUN_ACCENT_BREVE:
2485 case LFUN_ACCENT_TIE:
2486 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2487 case LFUN_ACCENT_CIRCLE:
2488 case LFUN_ACCENT_OGONEK:
2489 case LFUN_THESAURUS_ENTRY:
2490 case LFUN_PARAGRAPH_PARAMS_APPLY:
2491 case LFUN_PARAGRAPH_PARAMS:
2493 case LFUN_BUFFER_BEGIN:
2494 case LFUN_BUFFER_END:
2495 case LFUN_BUFFER_BEGIN_SELECT:
2496 case LFUN_BUFFER_END_SELECT:
2497 case LFUN_INSET_BEGIN:
2498 case LFUN_INSET_END:
2499 case LFUN_INSET_BEGIN_SELECT:
2500 case LFUN_INSET_END_SELECT:
2501 case LFUN_UNICODE_INSERT:
2502 // these are handled in our dispatch()
2511 && (cur.empty() || !cur.inset().insetAllowed(code)))
2514 flag.setEnabled(enable);
2519 void Text::pasteString(Cursor & cur, docstring const & clip,
2522 cur.clearSelection();
2523 if (!clip.empty()) {
2526 insertStringAsParagraphs(cur, clip);
2528 insertStringAsLines(cur, clip);
2533 // FIXME: an item inset would make things much easier.
2534 bool Text::inDescriptionItem(Cursor & cur) const
2536 Paragraph & par = cur.paragraph();
2537 pos_type const pos = cur.pos();
2538 pos_type const body_pos = par.beginOfBody();
2540 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2541 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2542 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2545 return (pos < body_pos
2547 && (pos == 0 || par.getChar(pos - 1) != ' ')));