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 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 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)
338 if (start == pars.begin())
341 ParagraphList::iterator dest = start;
342 // Move out (up) from this header
345 // Search previous same-level header above
348 toclevel = dest->layout().toclevel;
350 && (toclevel == Layout::NOT_IN_TOC
351 || toclevel > thistoclevel));
352 // Not found; do nothing
353 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
355 pit_type const newpit = distance(bgn, dest);
356 pit_type const len = distance(start, finish);
357 pit_type const deletepit = pit + len;
358 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
359 pars.insert(dest, start, finish);
360 start = boost::next(pars.begin(), deletepit);
362 pars.erase(start, finish);
369 // Go one down from *this* header:
370 ParagraphList::iterator dest = boost::next(finish, 1);
371 // Go further down to find header to insert in front of:
372 for (; dest != end; ++dest) {
373 toclevel = dest->layout().toclevel;
374 if (toclevel != Layout::NOT_IN_TOC
375 && toclevel <= thistoclevel)
378 // One such was found:
379 pit_type newpit = distance(bgn, dest);
380 pit_type const len = distance(start, finish);
381 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
382 pars.insert(dest, start, finish);
383 start = boost::next(bgn, pit);
385 pars.erase(start, finish);
389 pit_type const len = distance(start, finish);
390 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
391 for (; start != finish; ++start) {
392 toclevel = start->layout().toclevel;
393 if (toclevel == Layout::NOT_IN_TOC)
395 DocumentClass::const_iterator lit = tc.begin();
396 DocumentClass::const_iterator len = tc.end();
397 for (; lit != len; ++lit) {
398 if (lit->toclevel == toclevel + 1 &&
399 start->layout().labeltype == lit->labeltype) {
400 start->setLayout(*lit);
408 pit_type const len = distance(start, finish);
409 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
410 for (; start != finish; ++start) {
411 toclevel = start->layout().toclevel;
412 if (toclevel == Layout::NOT_IN_TOC)
414 DocumentClass::const_iterator lit = tc.begin();
415 DocumentClass::const_iterator len = tc.end();
416 for (; lit != len; ++lit) {
417 if (lit->toclevel == toclevel - 1 &&
418 start->layout().labeltype == lit->labeltype) {
419 start->setLayout(*lit);
430 void Text::number(Cursor & cur)
432 FontInfo font = ignore_font;
433 font.setNumber(FONT_TOGGLE);
434 toggleAndShow(cur, this, Font(font, ignore_language));
438 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
440 return par.isRTL(buffer.params());
444 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
446 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
448 BufferView * bv = &cur.bv();
449 TextMetrics & tm = bv->textMetrics(this);
450 if (!tm.contains(cur.pit())) {
451 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
452 tm = bv->textMetrics(this);
455 // FIXME: We use the update flag to indicates wether a singlePar or a
456 // full screen update is needed. We reset it here but shall we restore it
460 LASSERT(cur.text() == this, /**/);
461 CursorSlice oldTopSlice = cur.top();
462 bool oldBoundary = cur.boundary();
463 bool sel = cur.selection();
464 // Signals that, even if needsUpdate == false, an update of the
465 // cursor paragraph is required
466 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
467 LyXAction::SingleParUpdate);
468 // Signals that a full-screen update is required
469 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
470 LyXAction::NoUpdate) || singleParUpdate);
472 switch (cmd.action) {
474 case LFUN_PARAGRAPH_MOVE_DOWN: {
475 pit_type const pit = cur.pit();
476 recUndo(cur, pit, pit + 1);
478 swap(pars_[pit], pars_[pit + 1]);
479 cur.buffer()->updateLabels();
485 case LFUN_PARAGRAPH_MOVE_UP: {
486 pit_type const pit = cur.pit();
487 recUndo(cur, pit - 1, pit);
489 swap(pars_[pit], pars_[pit - 1]);
490 cur.buffer()->updateLabels();
496 case LFUN_APPENDIX: {
497 Paragraph & par = cur.paragraph();
498 bool start = !par.params().startOfAppendix();
500 // FIXME: The code below only makes sense at top level.
501 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
502 // ensure that we have only one start_of_appendix in this document
503 // FIXME: this don't work for multipart document!
504 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
505 if (pars_[tmp].params().startOfAppendix()) {
507 pars_[tmp].params().startOfAppendix(false);
513 par.params().startOfAppendix(start);
515 // we can set the refreshing parameters now
516 cur.buffer()->updateLabels();
520 case LFUN_WORD_DELETE_FORWARD:
522 cutSelection(cur, true, false);
524 deleteWordForward(cur);
525 finishChange(cur, false);
528 case LFUN_WORD_DELETE_BACKWARD:
530 cutSelection(cur, true, false);
532 deleteWordBackward(cur);
533 finishChange(cur, false);
536 case LFUN_LINE_DELETE:
538 cutSelection(cur, true, false);
540 tm.deleteLineForward(cur);
541 finishChange(cur, false);
544 case LFUN_BUFFER_BEGIN:
545 case LFUN_BUFFER_BEGIN_SELECT:
546 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
547 if (cur.depth() == 1)
548 needsUpdate |= cursorTop(cur);
551 cur.updateFlags(Update::FitCursor);
554 case LFUN_BUFFER_END:
555 case LFUN_BUFFER_END_SELECT:
556 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
557 if (cur.depth() == 1)
558 needsUpdate |= cursorBottom(cur);
561 cur.updateFlags(Update::FitCursor);
564 case LFUN_INSET_BEGIN:
565 case LFUN_INSET_BEGIN_SELECT:
566 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_BEGIN_SELECT);
567 if (cur.depth() == 1 || cur.pos() > 0)
568 needsUpdate |= cursorTop(cur);
571 cur.updateFlags(Update::FitCursor);
575 case LFUN_INSET_END_SELECT:
576 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_END_SELECT);
577 if (cur.depth() == 1 || cur.pos() < cur.lastpos())
578 needsUpdate |= cursorBottom(cur);
581 cur.updateFlags(Update::FitCursor);
584 case LFUN_CHAR_FORWARD:
585 case LFUN_CHAR_FORWARD_SELECT:
586 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
587 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
588 needsUpdate |= cursorForward(cur);
590 if (!needsUpdate && oldTopSlice == cur.top()
591 && cur.boundary() == oldBoundary) {
593 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
597 case LFUN_CHAR_BACKWARD:
598 case LFUN_CHAR_BACKWARD_SELECT:
599 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
600 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
601 needsUpdate |= cursorBackward(cur);
603 if (!needsUpdate && oldTopSlice == cur.top()
604 && cur.boundary() == oldBoundary) {
606 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
611 case LFUN_CHAR_LEFT_SELECT:
612 if (lyxrc.visual_cursor) {
613 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
614 needsUpdate |= cursorVisLeft(cur);
615 if (!needsUpdate && oldTopSlice == cur.top()
616 && cur.boundary() == oldBoundary) {
618 cmd = FuncRequest(LFUN_FINISHED_LEFT);
621 if (reverseDirectionNeeded(cur)) {
622 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
623 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
625 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
626 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
633 case LFUN_CHAR_RIGHT:
634 case LFUN_CHAR_RIGHT_SELECT:
635 if (lyxrc.visual_cursor) {
636 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
637 needsUpdate |= cursorVisRight(cur);
638 if (!needsUpdate && oldTopSlice == cur.top()
639 && cur.boundary() == oldBoundary) {
641 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
644 if (reverseDirectionNeeded(cur)) {
645 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
646 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
648 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
649 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
658 case LFUN_DOWN_SELECT:
661 // stop/start the selection
662 bool select = cmd.action == LFUN_DOWN_SELECT ||
663 cmd.action == LFUN_UP_SELECT;
665 // move cursor up/down
666 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
667 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
669 if (!atFirstOrLastRow) {
670 needsUpdate |= cur.selHandle(select);
671 cur.selHandle(select);
672 cur.upDownInText(up, needsUpdate);
673 needsUpdate |= cur.beforeDispatchCursor().inMathed();
675 // if the cursor cannot be moved up or down do not remove
676 // the selection right now, but wait for the next dispatch.
678 needsUpdate |= cur.selHandle(select);
679 cur.upDownInText(up, needsUpdate);
686 case LFUN_PARAGRAPH_UP:
687 case LFUN_PARAGRAPH_UP_SELECT:
688 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
689 needsUpdate |= cursorUpParagraph(cur);
692 case LFUN_PARAGRAPH_DOWN:
693 case LFUN_PARAGRAPH_DOWN_SELECT:
694 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
695 needsUpdate |= cursorDownParagraph(cur);
698 case LFUN_LINE_BEGIN:
699 case LFUN_LINE_BEGIN_SELECT:
700 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
701 needsUpdate |= tm.cursorHome(cur);
705 case LFUN_LINE_END_SELECT:
706 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
707 needsUpdate |= tm.cursorEnd(cur);
710 case LFUN_SECTION_SELECT: {
711 Buffer const & buf = *cur.buffer();
712 pit_type const pit = cur.pit();
713 ParagraphList & pars = buf.text().paragraphs();
714 ParagraphList::iterator bgn = pars.begin();
715 // The first paragraph of the area to be selected:
716 ParagraphList::iterator start = boost::next(bgn, pit);
717 // The final paragraph of area to be selected:
718 ParagraphList::iterator finish = start;
719 ParagraphList::iterator end = pars.end();
721 int const thistoclevel = start->layout().toclevel;
722 if (thistoclevel == Layout::NOT_IN_TOC)
726 Cursor const old_cur = cur;
727 needsUpdate |= cur.selHandle(true);
729 // Move out (down) from this section header
733 // Seek the one (on same level) below
734 for (; finish != end; ++finish, ++cur.pit()) {
735 int const toclevel = finish->layout().toclevel;
736 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
739 cur.pos() = cur.lastpos();
741 needsUpdate |= cur != old_cur;
745 case LFUN_WORD_RIGHT:
746 case LFUN_WORD_RIGHT_SELECT:
747 if (lyxrc.visual_cursor) {
748 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
749 needsUpdate |= cursorVisRightOneWord(cur);
750 if (!needsUpdate && oldTopSlice == cur.top()
751 && cur.boundary() == oldBoundary) {
753 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
756 if (reverseDirectionNeeded(cur)) {
757 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
758 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
760 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
761 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
768 case LFUN_WORD_FORWARD:
769 case LFUN_WORD_FORWARD_SELECT:
770 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
771 needsUpdate |= cursorForwardOneWord(cur);
775 case LFUN_WORD_LEFT_SELECT:
776 if (lyxrc.visual_cursor) {
777 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
778 needsUpdate |= cursorVisLeftOneWord(cur);
779 if (!needsUpdate && oldTopSlice == cur.top()
780 && cur.boundary() == oldBoundary) {
782 cmd = FuncRequest(LFUN_FINISHED_LEFT);
785 if (reverseDirectionNeeded(cur)) {
786 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
787 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
789 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
790 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
797 case LFUN_WORD_BACKWARD:
798 case LFUN_WORD_BACKWARD_SELECT:
799 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
800 needsUpdate |= cursorBackwardOneWord(cur);
803 case LFUN_WORD_SELECT: {
804 selectWord(cur, WHOLE_WORD);
805 finishChange(cur, true);
809 case LFUN_NEWLINE_INSERT: {
810 InsetNewlineParams inp;
811 docstring arg = cmd.argument();
812 // this avoids a double undo
813 // FIXME: should not be needed, ideally
814 if (!cur.selection())
816 cap::replaceSelection(cur);
817 if (arg == "linebreak")
818 inp.kind = InsetNewlineParams::LINEBREAK;
820 inp.kind = InsetNewlineParams::NEWLINE;
821 cur.insert(new InsetNewline(inp));
823 moveCursor(cur, false);
827 case LFUN_CHAR_DELETE_FORWARD:
828 if (!cur.selection()) {
829 if (cur.pos() == cur.paragraph().size())
830 // Par boundary, force full-screen update
831 singleParUpdate = false;
832 needsUpdate |= erase(cur);
834 // It is possible to make it a lot faster still
835 // just comment out the line below...
837 cutSelection(cur, true, false);
838 singleParUpdate = false;
840 moveCursor(cur, false);
843 case LFUN_CHAR_DELETE_BACKWARD:
844 if (!cur.selection()) {
845 if (bv->getIntl().getTransManager().backspace()) {
846 // Par boundary, full-screen update
848 singleParUpdate = false;
849 needsUpdate |= backspace(cur);
851 // It is possible to make it a lot faster still
852 // just comment out the line below...
855 cutSelection(cur, true, false);
856 singleParUpdate = false;
860 case LFUN_BREAK_PARAGRAPH:
861 cap::replaceSelection(cur);
862 breakParagraph(cur, cmd.argument() == "inverse");
867 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
868 // as its duties can be performed there. Should it be removed??
869 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
870 case LFUN_PARAGRAPH_SPACING: {
871 Paragraph & par = cur.paragraph();
872 Spacing::Space cur_spacing = par.params().spacing().getSpace();
873 string cur_value = "1.0";
874 if (cur_spacing == Spacing::Other)
875 cur_value = par.params().spacing().getValueAsString();
877 istringstream is(to_utf8(cmd.argument()));
880 Spacing::Space new_spacing = cur_spacing;
881 string new_value = cur_value;
883 lyxerr << "Missing argument to `paragraph-spacing'"
885 } else if (tmp == "single") {
886 new_spacing = Spacing::Single;
887 } else if (tmp == "onehalf") {
888 new_spacing = Spacing::Onehalf;
889 } else if (tmp == "double") {
890 new_spacing = Spacing::Double;
891 } else if (tmp == "other") {
892 new_spacing = Spacing::Other;
893 string tmpval = "0.0";
895 lyxerr << "new_value = " << tmpval << endl;
898 } else if (tmp == "default") {
899 new_spacing = Spacing::Default;
901 lyxerr << to_utf8(_("Unknown spacing argument: "))
902 << to_utf8(cmd.argument()) << endl;
904 if (cur_spacing != new_spacing || cur_value != new_value)
905 par.params().spacing(Spacing(new_spacing, new_value));
909 case LFUN_INSET_INSERT: {
912 // We have to avoid triggering InstantPreview loading
913 // before inserting into the document. See bug #5626.
914 bool loaded = bv->buffer().isFullyLoaded();
915 bv->buffer().setFullyLoaded(false);
916 Inset * inset = createInset(bv->buffer(), cmd);
917 bv->buffer().setFullyLoaded(loaded);
920 // FIXME (Abdel 01/02/2006):
921 // What follows would be a partial fix for bug 2154:
922 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
923 // This automatically put the label inset _after_ a
924 // numbered section. It should be possible to extend the mechanism
925 // to any kind of LateX environement.
926 // The correct way to fix that bug would be at LateX generation.
927 // I'll let the code here for reference as it could be used for some
928 // other feature like "automatic labelling".
930 Paragraph & par = pars_[cur.pit()];
931 if (inset->lyxCode() == LABEL_CODE
932 && par.layout().labeltype == LABEL_COUNTER) {
933 // Go to the end of the paragraph
934 // Warning: Because of Change-Tracking, the last
935 // position is 'size()' and not 'size()-1':
936 cur.pos() = par.size();
937 // Insert a new paragraph
938 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
943 cutSelection(cur, true, false);
947 // trigger InstantPreview now
948 if (inset->lyxCode() == EXTERNAL_CODE) {
949 InsetExternal & ins =
950 static_cast<InsetExternal &>(*inset);
958 case LFUN_INSET_DISSOLVE: {
959 // first, try if there's an inset at cursor
960 // FIXME: this first part should be moved to
961 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
962 // some generic "next-inset inset-dissolve"
963 Inset * inset = cur.nextInset();
964 if (inset && inset->isActive()) {
966 tmpcur.pushBackward(*inset);
967 inset->dispatch(tmpcur, cmd);
968 if (tmpcur.result().dispatched()) {
973 // if it did not work, try the underlying inset
974 if (dissolveInset(cur)) {
978 // if it did not work, do nothing.
982 case LFUN_SET_GRAPHICS_GROUP: {
983 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
989 string id = to_utf8(cmd.argument());
990 string grp = graphics::getGroupParams(bv->buffer(), id);
991 InsetGraphicsParams tmp, inspar = ins->getParams();
994 inspar.groupId = to_utf8(cmd.argument());
996 InsetGraphics::string2params(grp, bv->buffer(), tmp);
997 tmp.filename = inspar.filename;
1001 ins->setParams(inspar);
1004 case LFUN_SPACE_INSERT:
1005 if (cur.paragraph().layout().free_spacing)
1006 insertChar(cur, ' ');
1008 doInsertInset(cur, this, cmd, false, false);
1011 moveCursor(cur, false);
1014 case LFUN_SPECIALCHAR_INSERT: {
1015 string const name = to_utf8(cmd.argument());
1016 if (name == "hyphenation")
1017 specialChar(cur, InsetSpecialChar::HYPHENATION);
1018 else if (name == "ligature-break")
1019 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1020 else if (name == "slash")
1021 specialChar(cur, InsetSpecialChar::SLASH);
1022 else if (name == "nobreakdash")
1023 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1024 else if (name == "dots")
1025 specialChar(cur, InsetSpecialChar::LDOTS);
1026 else if (name == "end-of-sentence")
1027 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1028 else if (name == "menu-separator")
1029 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1030 else if (name.empty())
1031 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1033 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1037 case LFUN_WORD_UPCASE:
1038 changeCase(cur, text_uppercase);
1041 case LFUN_WORD_LOWCASE:
1042 changeCase(cur, text_lowercase);
1045 case LFUN_WORD_CAPITALIZE:
1046 changeCase(cur, text_capitalization);
1049 case LFUN_CHARS_TRANSPOSE:
1050 charsTranspose(cur);
1054 cur.message(_("Paste"));
1055 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1056 cap::replaceSelection(cur);
1058 // without argument?
1059 string const arg = to_utf8(cmd.argument());
1061 if (theClipboard().isInternal())
1062 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1063 else if (theClipboard().hasGraphicsContents()
1064 && !theClipboard().hasTextContents())
1065 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1067 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1068 } else if (isStrUnsignedInt(arg)) {
1069 // we have a numerical argument
1070 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1071 convert<unsigned int>(arg));
1073 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1075 type = Clipboard::PdfGraphicsType;
1076 else if (arg == "png")
1077 type = Clipboard::PngGraphicsType;
1078 else if (arg == "jpeg")
1079 type = Clipboard::JpegGraphicsType;
1080 else if (arg == "linkback")
1081 type = Clipboard::LinkBackGraphicsType;
1082 else if (arg == "emf")
1083 type = Clipboard::EmfGraphicsType;
1084 else if (arg == "wmf")
1085 type = Clipboard::WmfGraphicsType;
1088 LASSERT(false, /**/);
1090 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1093 bv->buffer().errors("Paste");
1094 cur.clearSelection(); // bug 393
1100 cutSelection(cur, true, true);
1101 cur.message(_("Cut"));
1106 cur.message(_("Copy"));
1109 case LFUN_SERVER_GET_XY:
1110 cur.message(from_utf8(
1111 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1112 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1115 case LFUN_SERVER_SET_XY: {
1118 istringstream is(to_utf8(cmd.argument()));
1121 lyxerr << "SETXY: Could not parse coordinates in '"
1122 << to_utf8(cmd.argument()) << endl;
1124 tm.setCursorFromCoordinates(cur, x, y);
1128 case LFUN_SERVER_GET_LAYOUT:
1129 cur.message(cur.paragraph().layout().name());
1133 docstring layout = cmd.argument();
1134 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1136 Paragraph const & para = cur.paragraph();
1137 docstring const old_layout = para.layout().name();
1138 DocumentClass const & tclass = bv->buffer().params().documentClass();
1141 layout = tclass.defaultLayoutName();
1143 if (para.forcePlainLayout())
1144 // in this case only the empty layout is allowed
1145 layout = tclass.plainLayoutName();
1146 else if (para.usePlainLayout()) {
1147 // in this case, default layout maps to empty layout
1148 if (layout == tclass.defaultLayoutName())
1149 layout = tclass.plainLayoutName();
1151 // otherwise, the empty layout maps to the default
1152 if (layout == tclass.plainLayoutName())
1153 layout = tclass.defaultLayoutName();
1156 bool hasLayout = tclass.hasLayout(layout);
1158 // If the entry is obsolete, use the new one instead.
1160 docstring const & obs = tclass[layout].obsoleted_by();
1166 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1167 from_utf8(N_(" not known")));
1171 bool change_layout = (old_layout != layout);
1173 if (!change_layout && cur.selection() &&
1174 cur.selBegin().pit() != cur.selEnd().pit())
1176 pit_type spit = cur.selBegin().pit();
1177 pit_type epit = cur.selEnd().pit() + 1;
1178 while (spit != epit) {
1179 if (pars_[spit].layout().name() != old_layout) {
1180 change_layout = true;
1188 setLayout(cur, layout);
1193 case LFUN_CLIPBOARD_PASTE:
1194 cur.clearSelection();
1195 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1196 cmd.argument() == "paragraph");
1197 bv->buffer().errors("Paste");
1200 case LFUN_PRIMARY_SELECTION_PASTE:
1201 pasteString(cur, theSelection().get(),
1202 cmd.argument() == "paragraph");
1205 case LFUN_SELECTION_PASTE:
1206 // Copy the selection buffer to the clipboard stack,
1207 // because we want it to appear in the "Edit->Paste
1209 cap::copySelectionToStack();
1210 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1211 bv->buffer().errors("Paste");
1214 case LFUN_UNICODE_INSERT: {
1215 if (cmd.argument().empty())
1217 docstring hexstring = cmd.argument();
1218 if (isHex(hexstring)) {
1219 char_type c = hexToInt(hexstring);
1220 if (c >= 32 && c < 0x10ffff) {
1221 lyxerr << "Inserting c: " << c << endl;
1222 docstring s = docstring(1, c);
1223 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1229 case LFUN_QUOTE_INSERT: {
1230 Paragraph & par = cur.paragraph();
1231 pos_type pos = cur.pos();
1232 BufferParams const & bufparams = bv->buffer().params();
1233 Layout const & style = par.layout();
1234 InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
1235 if (!style.pass_thru && !ilayout.isPassThru()
1236 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1237 // this avoids a double undo
1238 // FIXME: should not be needed, ideally
1239 if (!cur.selection())
1241 cap::replaceSelection(cur);
1246 else if (cur.prevInset() && cur.prevInset()->isSpace())
1249 c = par.getChar(pos - 1);
1250 string arg = to_utf8(cmd.argument());
1251 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1252 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1256 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1260 case LFUN_DATE_INSERT: {
1261 string const format = cmd.argument().empty()
1262 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1263 string const time = formatted_time(current_time(), format);
1264 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1268 case LFUN_MOUSE_TRIPLE:
1269 if (cmd.button() == mouse_button::button1) {
1278 case LFUN_MOUSE_DOUBLE:
1279 if (cmd.button() == mouse_button::button1) {
1280 selectWord(cur, WHOLE_WORD_STRICT);
1285 // Single-click on work area
1286 case LFUN_MOUSE_PRESS:
1287 // We are not marking a selection with the keyboard in any case.
1288 cur.bv().cursor().setMark(false);
1289 switch (cmd.button()) {
1290 case mouse_button::button1:
1292 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1293 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1296 case mouse_button::button2:
1297 // Middle mouse pasting.
1298 bv->mouseSetCursor(cur);
1300 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1301 "selection-paste ; primary-selection-paste paragraph"));
1305 case mouse_button::button3: {
1306 Cursor const & bvcur = cur.bv().cursor();
1307 // Don't do anything if we right-click a
1308 // selection, a context menu will popup.
1309 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1310 && cur < bvcur.selectionEnd()) {
1314 if (!bv->mouseSetCursor(cur, false))
1315 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1321 } // switch (cmd.button())
1324 case LFUN_MOUSE_MOTION: {
1325 // Mouse motion with right or middle mouse do nothing for now.
1326 if (cmd.button() != mouse_button::button1) {
1330 // ignore motions deeper nested than the real anchor
1331 Cursor & bvcur = cur.bv().cursor();
1332 if (!bvcur.anchor_.hasPart(cur)) {
1336 CursorSlice old = bvcur.top();
1338 int const wh = bv->workHeight();
1339 int const y = max(0, min(wh - 1, cmd.y));
1341 tm.setCursorFromCoordinates(cur, cmd.x, y);
1342 cur.setTargetX(cmd.x);
1344 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1346 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1347 // This is to allow jumping over large insets
1348 if (cur.top() == old) {
1350 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1352 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1354 // We continue with our existing selection or start a new one, so don't
1355 // reset the anchor.
1356 bvcur.setCursor(cur);
1357 bvcur.setSelection(true);
1358 if (cur.top() == old) {
1359 // We didn't move one iota, so no need to update the screen.
1360 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1367 case LFUN_MOUSE_RELEASE:
1368 switch (cmd.button()) {
1369 case mouse_button::button1:
1370 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1371 // If there is a new selection, update persistent selection;
1372 // otherwise, single click does not clear persistent selection
1374 if (cur.selection()) {
1375 // Finish selection. If double click,
1376 // cur is moved to the end of word by
1377 // selectWord but bvcur is current
1379 cur.bv().cursor().setSelection();
1380 // We might have removed an empty but drawn selection
1381 // (probably a margin)
1382 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1385 // FIXME: We could try to handle drag and drop of selection here.
1388 case mouse_button::button2:
1389 // Middle mouse pasting is handled at mouse press time,
1390 // see LFUN_MOUSE_PRESS.
1394 case mouse_button::button3:
1395 // Cursor was set at LFUN_MOUSE_PRESS time.
1396 // FIXME: If there is a selection we could try to handle a special
1397 // drag & drop context menu.
1401 case mouse_button::none:
1402 case mouse_button::button4:
1403 case mouse_button::button5:
1405 } // switch (cmd.button())
1409 case LFUN_SELF_INSERT: {
1410 if (cmd.argument().empty())
1413 // Automatically delete the currently selected
1414 // text and replace it with what is being
1415 // typed in now. Depends on lyxrc settings
1416 // "auto_region_delete", which defaults to
1419 if (lyxrc.auto_region_delete && cur.selection())
1420 cutSelection(cur, false, false);
1422 cur.clearSelection();
1424 docstring::const_iterator cit = cmd.argument().begin();
1425 docstring::const_iterator const end = cmd.argument().end();
1426 for (; cit != end; ++cit)
1427 bv->translateAndInsert(*cit, this, cur);
1430 moveCursor(cur, false);
1431 bv->bookmarkEditPosition();
1435 case LFUN_HYPERLINK_INSERT: {
1436 InsetCommandParams p(HYPERLINK_CODE);
1438 if (cur.selection()) {
1439 content = cur.selectionAsString(false);
1440 cutSelection(cur, true, false);
1442 p["target"] = (cmd.argument().empty()) ?
1443 content : cmd.argument();
1444 string const data = InsetCommand::params2string("href", p);
1445 if (p["target"].empty()) {
1446 bv->showDialog("href", data);
1448 FuncRequest fr(LFUN_INSET_INSERT, data);
1454 case LFUN_LABEL_INSERT: {
1455 InsetCommandParams p(LABEL_CODE);
1456 // Try to generate a valid label
1457 p["name"] = (cmd.argument().empty()) ?
1458 cur.getPossibleLabel() :
1460 string const data = InsetCommand::params2string("label", p);
1462 if (cmd.argument().empty()) {
1463 bv->showDialog("label", data);
1465 FuncRequest fr(LFUN_INSET_INSERT, data);
1471 case LFUN_INFO_INSERT: {
1473 if (cmd.argument().empty() && cur.selection()) {
1474 // if command argument is empty use current selection as parameter.
1475 docstring ds = cur.selectionAsString(false);
1476 cutSelection(cur, true, false);
1477 FuncRequest cmd0(cmd, ds);
1478 inset = createInset(cur.bv().buffer(), cmd0);
1480 inset = createInset(cur.bv().buffer(), cmd);
1484 insertInset(cur, inset);
1488 case LFUN_CAPTION_INSERT:
1489 case LFUN_FOOTNOTE_INSERT:
1490 case LFUN_NOTE_INSERT:
1491 case LFUN_FLEX_INSERT:
1492 case LFUN_BOX_INSERT:
1493 case LFUN_BRANCH_INSERT:
1494 case LFUN_PHANTOM_INSERT:
1495 case LFUN_ERT_INSERT:
1496 case LFUN_LISTING_INSERT:
1497 case LFUN_MARGINALNOTE_INSERT:
1498 case LFUN_OPTIONAL_INSERT:
1499 case LFUN_INDEX_INSERT:
1500 // Open the inset, and move the current selection
1502 doInsertInset(cur, this, cmd, true, true);
1504 // Some insets are numbered, others are shown in the outline pane so
1505 // let's update the labels and the toc backend.
1506 bv->buffer().updateLabels();
1509 case LFUN_TABULAR_INSERT:
1510 // if there were no arguments, just open the dialog
1511 if (doInsertInset(cur, this, cmd, false, true))
1514 bv->showDialog("tabularcreate");
1518 case LFUN_FLOAT_INSERT:
1519 case LFUN_FLOAT_WIDE_INSERT:
1520 case LFUN_WRAP_INSERT: {
1521 // will some text be moved into the inset?
1522 bool content = cur.selection();
1524 doInsertInset(cur, this, cmd, true, true);
1527 // If some text is moved into the inset, doInsertInset
1528 // puts the cursor outside the inset. To insert the
1529 // caption we put it back into the inset.
1533 ParagraphList & pars = cur.text()->paragraphs();
1535 DocumentClass const & tclass = bv->buffer().params().documentClass();
1537 // add a separate paragraph for the caption inset
1538 pars.push_back(Paragraph());
1539 pars.back().setInsetOwner(&pars[0].inInset());
1540 pars.back().setPlainOrDefaultLayout(tclass);
1541 int cap_pit = pars.size() - 1;
1543 // if an empty inset was created, we create an additional empty
1544 // paragraph at the bottom so that the user can choose where to put
1545 // the graphics (or table).
1547 pars.push_back(Paragraph());
1548 pars.back().setInsetOwner(&pars[0].inInset());
1549 pars.back().setPlainOrDefaultLayout(tclass);
1552 // reposition the cursor to the caption
1553 cur.pit() = cap_pit;
1555 // FIXME: This Text/Cursor dispatch handling is a mess!
1556 // We cannot use Cursor::dispatch here it needs access to up to
1558 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1559 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1560 bv->buffer().updateLabels();
1561 cur.updateFlags(Update::Force);
1562 // FIXME: When leaving the Float (or Wrap) inset we should
1563 // delete any empty paragraph left above or below the
1568 case LFUN_NOMENCL_INSERT: {
1569 InsetCommandParams p(NOMENCL_CODE);
1570 if (cmd.argument().empty())
1571 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1573 p["symbol"] = cmd.argument();
1574 string const data = InsetCommand::params2string("nomenclature", p);
1575 bv->showDialog("nomenclature", data);
1579 case LFUN_INDEX_PRINT: {
1580 InsetCommandParams p(INDEX_PRINT_CODE);
1581 if (cmd.argument().empty())
1582 p["type"] = from_ascii("idx");
1584 p["type"] = cmd.argument();
1585 string const data = InsetCommand::params2string("index_print", p);
1586 FuncRequest fr(LFUN_INSET_INSERT, data);
1591 case LFUN_NOMENCL_PRINT:
1592 case LFUN_TOC_INSERT:
1593 case LFUN_LINE_INSERT:
1594 case LFUN_NEWPAGE_INSERT:
1596 doInsertInset(cur, this, cmd, false, false);
1600 case LFUN_DEPTH_DECREMENT:
1601 changeDepth(cur, DEC_DEPTH);
1604 case LFUN_DEPTH_INCREMENT:
1605 changeDepth(cur, INC_DEPTH);
1608 case LFUN_MATH_DISPLAY:
1609 mathDispatch(cur, cmd, true);
1612 case LFUN_REGEXP_MODE:
1613 regexpDispatch(cur, cmd);
1616 case LFUN_MATH_MODE:
1617 if (cmd.argument() == "on")
1618 // don't pass "on" as argument
1619 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1621 mathDispatch(cur, cmd, false);
1624 case LFUN_MATH_MACRO:
1625 if (cmd.argument().empty())
1626 cur.errorMessage(from_utf8(N_("Missing argument")));
1628 string s = to_utf8(cmd.argument());
1629 string const s1 = token(s, ' ', 1);
1630 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1631 string const s2 = token(s, ' ', 2);
1632 MacroType type = MacroTypeNewcommand;
1634 type = MacroTypeDef;
1635 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1636 inset->setBuffer(bv->buffer());
1637 insertInset(cur, inset);
1639 // enter macro inset and select the name
1641 cur.top().pos() = cur.top().lastpos();
1643 cur.setSelection(true);
1644 cur.top().pos() = 0;
1648 // passthrough hat and underscore outside mathed:
1649 case LFUN_MATH_SUBSCRIPT:
1650 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1652 case LFUN_MATH_SUPERSCRIPT:
1653 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1656 case LFUN_MATH_INSERT:
1657 case LFUN_MATH_MATRIX:
1658 case LFUN_MATH_DELIM:
1659 case LFUN_MATH_BIGDELIM: {
1661 cap::replaceSelection(cur);
1662 cur.insert(new InsetMathHull(hullSimple));
1663 checkAndActivateInset(cur, true);
1664 LASSERT(cur.inMathed(), /**/);
1669 case LFUN_FONT_EMPH: {
1670 Font font(ignore_font, ignore_language);
1671 font.fontInfo().setEmph(FONT_TOGGLE);
1672 toggleAndShow(cur, this, font);
1676 case LFUN_FONT_ITAL: {
1677 Font font(ignore_font, ignore_language);
1678 font.fontInfo().setShape(ITALIC_SHAPE);
1679 toggleAndShow(cur, this, font);
1683 case LFUN_FONT_BOLD:
1684 case LFUN_FONT_BOLDSYMBOL: {
1685 Font font(ignore_font, ignore_language);
1686 font.fontInfo().setSeries(BOLD_SERIES);
1687 toggleAndShow(cur, this, font);
1691 case LFUN_FONT_NOUN: {
1692 Font font(ignore_font, ignore_language);
1693 font.fontInfo().setNoun(FONT_TOGGLE);
1694 toggleAndShow(cur, this, font);
1698 case LFUN_FONT_TYPEWRITER: {
1699 Font font(ignore_font, ignore_language);
1700 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1701 toggleAndShow(cur, this, font);
1705 case LFUN_FONT_SANS: {
1706 Font font(ignore_font, ignore_language);
1707 font.fontInfo().setFamily(SANS_FAMILY);
1708 toggleAndShow(cur, this, font);
1712 case LFUN_FONT_ROMAN: {
1713 Font font(ignore_font, ignore_language);
1714 font.fontInfo().setFamily(ROMAN_FAMILY);
1715 toggleAndShow(cur, this, font);
1719 case LFUN_FONT_DEFAULT: {
1720 Font font(inherit_font, ignore_language);
1721 toggleAndShow(cur, this, font);
1725 case LFUN_FONT_STRIKEOUT: {
1726 Font font(ignore_font, ignore_language);
1727 font.fontInfo().setStrikeout(FONT_TOGGLE);
1728 toggleAndShow(cur, this, font);
1732 case LFUN_FONT_UULINE: {
1733 Font font(ignore_font, ignore_language);
1734 font.fontInfo().setUuline(FONT_TOGGLE);
1735 toggleAndShow(cur, this, font);
1739 case LFUN_FONT_UWAVE: {
1740 Font font(ignore_font, ignore_language);
1741 font.fontInfo().setUwave(FONT_TOGGLE);
1742 toggleAndShow(cur, this, font);
1746 case LFUN_FONT_UNDERLINE: {
1747 Font font(ignore_font, ignore_language);
1748 font.fontInfo().setUnderbar(FONT_TOGGLE);
1749 toggleAndShow(cur, this, font);
1753 case LFUN_FONT_SIZE: {
1754 Font font(ignore_font, ignore_language);
1755 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1756 toggleAndShow(cur, this, font);
1760 case LFUN_LANGUAGE: {
1761 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1764 Font font(ignore_font, lang);
1765 toggleAndShow(cur, this, font);
1769 case LFUN_TEXTSTYLE_APPLY:
1770 toggleAndShow(cur, this, freefont, toggleall);
1771 cur.message(_("Character set"));
1774 // Set the freefont using the contents of \param data dispatched from
1775 // the frontends and apply it at the current cursor location.
1776 case LFUN_TEXTSTYLE_UPDATE: {
1779 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1782 toggleAndShow(cur, this, freefont, toggleall);
1783 cur.message(_("Character set"));
1785 lyxerr << "Argument not ok";
1790 case LFUN_FINISHED_LEFT:
1791 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1792 // We're leaving an inset, going left. If the inset is LTR, we're
1793 // leaving from the front, so we should not move (remain at --- but
1794 // not in --- the inset). If the inset is RTL, move left, without
1795 // entering the inset itself; i.e., move to after the inset.
1796 if (cur.paragraph().getFontSettings(
1797 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1798 cursorVisLeft(cur, true);
1801 case LFUN_FINISHED_RIGHT:
1802 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1803 // We're leaving an inset, going right. If the inset is RTL, we're
1804 // leaving from the front, so we should not move (remain at --- but
1805 // not in --- the inset). If the inset is LTR, move right, without
1806 // entering the inset itself; i.e., move to after the inset.
1807 if (!cur.paragraph().getFontSettings(
1808 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1809 cursorVisRight(cur, true);
1812 case LFUN_FINISHED_BACKWARD:
1813 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1816 case LFUN_FINISHED_FORWARD:
1817 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1819 cur.setCurrentFont();
1822 case LFUN_LAYOUT_PARAGRAPH: {
1824 params2string(cur.paragraph(), data);
1825 data = "show\n" + data;
1826 bv->showDialog("paragraph", data);
1830 case LFUN_PARAGRAPH_UPDATE: {
1832 params2string(cur.paragraph(), data);
1834 // Will the paragraph accept changes from the dialog?
1836 cur.inset().allowParagraphCustomization(cur.idx());
1838 data = "update " + convert<string>(accept) + '\n' + data;
1839 bv->updateDialog("paragraph", data);
1843 case LFUN_ACCENT_UMLAUT:
1844 case LFUN_ACCENT_CIRCUMFLEX:
1845 case LFUN_ACCENT_GRAVE:
1846 case LFUN_ACCENT_ACUTE:
1847 case LFUN_ACCENT_TILDE:
1848 case LFUN_ACCENT_CEDILLA:
1849 case LFUN_ACCENT_MACRON:
1850 case LFUN_ACCENT_DOT:
1851 case LFUN_ACCENT_UNDERDOT:
1852 case LFUN_ACCENT_UNDERBAR:
1853 case LFUN_ACCENT_CARON:
1854 case LFUN_ACCENT_BREVE:
1855 case LFUN_ACCENT_TIE:
1856 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1857 case LFUN_ACCENT_CIRCLE:
1858 case LFUN_ACCENT_OGONEK:
1859 theLyXFunc().handleKeyFunc(cmd.action);
1860 if (!cmd.argument().empty())
1861 // FIXME: Are all these characters encoded in one byte in utf8?
1862 bv->translateAndInsert(cmd.argument()[0], this, cur);
1865 case LFUN_FLOAT_LIST_INSERT: {
1866 DocumentClass const & tclass = bv->buffer().params().documentClass();
1867 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1869 if (cur.selection())
1870 cutSelection(cur, true, false);
1871 breakParagraph(cur);
1873 if (cur.lastpos() != 0) {
1874 cursorBackward(cur);
1875 breakParagraph(cur);
1878 docstring const laystr = cur.inset().usePlainLayout() ?
1879 tclass.plainLayoutName() :
1880 tclass.defaultLayoutName();
1881 setLayout(cur, laystr);
1882 ParagraphParameters p;
1883 // FIXME If this call were replaced with one to clearParagraphParams(),
1884 // then we could get rid of this method altogether.
1885 setParagraphs(cur, p);
1886 // FIXME This should be simplified when InsetFloatList takes a
1887 // Buffer in its constructor.
1888 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1889 ifl->setBuffer(bv->buffer());
1890 insertInset(cur, ifl);
1893 lyxerr << "Non-existent float type: "
1894 << to_utf8(cmd.argument()) << endl;
1899 case LFUN_CHANGE_ACCEPT: {
1900 acceptOrRejectChanges(cur, ACCEPT);
1904 case LFUN_CHANGE_REJECT: {
1905 acceptOrRejectChanges(cur, REJECT);
1909 case LFUN_THESAURUS_ENTRY: {
1910 docstring arg = cmd.argument();
1912 arg = cur.selectionAsString(false);
1914 if (arg.size() > 100 || arg.empty()) {
1915 // Get word or selection
1916 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1917 arg = cur.selectionAsString(false);
1918 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1921 bv->showDialog("thesaurus", to_utf8(arg));
1925 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1926 // Given data, an encoding of the ParagraphParameters
1927 // generated in the Paragraph dialog, this function sets
1928 // the current paragraph, or currently selected paragraphs,
1930 // NOTE: This function overrides all existing settings.
1931 setParagraphs(cur, cmd.argument());
1932 cur.message(_("Paragraph layout set"));
1936 case LFUN_PARAGRAPH_PARAMS: {
1937 // Given data, an encoding of the ParagraphParameters as we'd
1938 // find them in a LyX file, this function modifies the current paragraph,
1939 // or currently selected paragraphs.
1940 // NOTE: This function only modifies, and does not override, existing
1942 setParagraphs(cur, cmd.argument(), true);
1943 cur.message(_("Paragraph layout set"));
1948 if (cur.selection()) {
1949 cur.setSelection(false);
1952 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1953 // correct, but I'm not 100% sure -- dov, 071019
1954 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1958 case LFUN_OUTLINE_UP:
1959 outline(OutlineUp, cur);
1960 setCursor(cur, cur.pit(), 0);
1961 cur.buffer()->updateLabels();
1965 case LFUN_OUTLINE_DOWN:
1966 outline(OutlineDown, cur);
1967 setCursor(cur, cur.pit(), 0);
1968 cur.buffer()->updateLabels();
1972 case LFUN_OUTLINE_IN:
1973 outline(OutlineIn, cur);
1974 cur.buffer()->updateLabels();
1978 case LFUN_OUTLINE_OUT:
1979 outline(OutlineOut, cur);
1980 cur.buffer()->updateLabels();
1985 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1990 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1992 // FIXME: The cursor flag is reset two lines below
1993 // so we need to check here if some of the LFUN did touch that.
1994 // for now only Text::erase() and Text::backspace() do that.
1995 // The plan is to verify all the LFUNs and then to remove this
1996 // singleParUpdate boolean altogether.
1997 if (cur.result().update() & Update::Force) {
1998 singleParUpdate = false;
2002 // FIXME: the following code should go in favor of fine grained
2003 // update flag treatment.
2004 if (singleParUpdate) {
2005 // Inserting characters does not change par height in general. So, try
2006 // to update _only_ this paragraph. BufferView will detect if a full
2007 // metrics update is needed anyway.
2008 cur.updateFlags(Update::SinglePar | Update::FitCursor);
2013 && &oldTopSlice.inset() == &cur.inset()
2014 && oldTopSlice.idx() == cur.idx()
2015 && !sel // sel is a backup of cur.selection() at the biginning of the function.
2016 && !cur.selection())
2017 // FIXME: it would be better if we could just do this
2019 //if (cur.result().update() != Update::FitCursor)
2022 // But some LFUNs do not set Update::FitCursor when needed, so we
2023 // do it for all. This is not very harmfull as FitCursor will provoke
2024 // a full redraw only if needed but still, a proper review of all LFUN
2025 // should be done and this needsUpdate boolean can then be removed.
2026 cur.updateFlags(Update::FitCursor);
2028 cur.updateFlags(Update::Force | Update::FitCursor);
2032 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
2033 FuncStatus & flag) const
2035 LASSERT(cur.text() == this, /**/);
2037 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
2039 InsetCode code = NO_CODE;
2041 switch (cmd.action) {
2043 case LFUN_DEPTH_DECREMENT:
2044 enable = changeDepthAllowed(cur, DEC_DEPTH);
2047 case LFUN_DEPTH_INCREMENT:
2048 enable = changeDepthAllowed(cur, INC_DEPTH);
2052 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2055 case LFUN_DIALOG_SHOW_NEW_INSET:
2056 if (cmd.argument() == "bibitem")
2057 code = BIBITEM_CODE;
2058 else if (cmd.argument() == "bibtex")
2060 else if (cmd.argument() == "box")
2062 else if (cmd.argument() == "branch")
2064 else if (cmd.argument() == "citation")
2066 else if (cmd.argument() == "ert")
2068 else if (cmd.argument() == "external")
2069 code = EXTERNAL_CODE;
2070 else if (cmd.argument() == "float")
2072 else if (cmd.argument() == "graphics")
2073 code = GRAPHICS_CODE;
2074 else if (cmd.argument() == "href")
2075 code = HYPERLINK_CODE;
2076 else if (cmd.argument() == "include")
2077 code = INCLUDE_CODE;
2078 else if (cmd.argument() == "index")
2080 else if (cmd.argument() == "index_print")
2081 code = INDEX_PRINT_CODE;
2082 else if (cmd.argument() == "nomenclature")
2083 code = NOMENCL_CODE;
2084 else if (cmd.argument() == "label")
2086 else if (cmd.argument() == "note")
2088 else if (cmd.argument() == "phantom")
2089 code = PHANTOM_CODE;
2090 else if (cmd.argument() == "ref")
2092 else if (cmd.argument() == "space")
2094 else if (cmd.argument() == "toc")
2096 else if (cmd.argument() == "vspace")
2098 else if (cmd.argument() == "wrap")
2100 else if (cmd.argument() == "listings")
2101 code = LISTINGS_CODE;
2104 case LFUN_ERT_INSERT:
2107 case LFUN_LISTING_INSERT:
2108 code = LISTINGS_CODE;
2109 // not allowed in description items
2110 enable = !inDescriptionItem(cur);
2112 case LFUN_FOOTNOTE_INSERT:
2115 case LFUN_TABULAR_INSERT:
2116 code = TABULAR_CODE;
2118 case LFUN_MARGINALNOTE_INSERT:
2121 case LFUN_FLOAT_INSERT:
2122 case LFUN_FLOAT_WIDE_INSERT:
2124 // not allowed in description items
2125 enable = !inDescriptionItem(cur);
2127 case LFUN_WRAP_INSERT:
2129 // not allowed in description items
2130 enable = !inDescriptionItem(cur);
2132 case LFUN_FLOAT_LIST_INSERT:
2133 code = FLOAT_LIST_CODE;
2135 case LFUN_CAPTION_INSERT:
2136 code = CAPTION_CODE;
2137 // not allowed in description items
2138 enable = !inDescriptionItem(cur);
2140 case LFUN_NOTE_INSERT:
2142 // in commands (sections etc.) and description items,
2143 // only Notes are allowed
2144 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2145 (!cur.paragraph().layout().isCommand()
2146 && !inDescriptionItem(cur)));
2148 case LFUN_FLEX_INSERT: {
2150 string s = cmd.getArg(0);
2152 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2153 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2154 il.lyxtype() != InsetLayout::CUSTOM &&
2155 il.lyxtype() != InsetLayout::ELEMENT &&
2156 il.lyxtype ()!= InsetLayout::STANDARD)
2160 case LFUN_BOX_INSERT:
2163 case LFUN_BRANCH_INSERT:
2165 if (cur.buffer()->masterBuffer()->params().branchlist().empty())
2168 case LFUN_PHANTOM_INSERT:
2169 code = PHANTOM_CODE;
2171 case LFUN_LABEL_INSERT:
2174 case LFUN_INFO_INSERT:
2177 case LFUN_OPTIONAL_INSERT:
2179 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2180 < cur.paragraph().layout().optionalargs;
2182 case LFUN_INDEX_INSERT:
2185 case LFUN_INDEX_PRINT:
2186 code = INDEX_PRINT_CODE;
2188 case LFUN_NOMENCL_INSERT:
2189 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2193 code = NOMENCL_CODE;
2195 case LFUN_NOMENCL_PRINT:
2196 code = NOMENCL_PRINT_CODE;
2198 case LFUN_TOC_INSERT:
2201 case LFUN_HYPERLINK_INSERT:
2202 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2206 code = HYPERLINK_CODE;
2208 case LFUN_QUOTE_INSERT:
2209 // always allow this, since we will inset a raw quote
2210 // if an inset is not allowed.
2212 case LFUN_SPECIALCHAR_INSERT:
2213 code = SPECIALCHAR_CODE;
2215 case LFUN_SPACE_INSERT:
2216 // slight hack: we know this is allowed in math mode
2221 case LFUN_INSET_MODIFY:
2222 // We need to disable this, because we may get called for a
2224 // InsetTabular::getStatus() -> InsetText::getStatus()
2225 // and we don't handle LFUN_INSET_MODIFY.
2229 case LFUN_FONT_EMPH:
2230 flag.setOnOff(fontinfo.emph() == FONT_ON);
2233 case LFUN_FONT_ITAL:
2234 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2237 case LFUN_FONT_NOUN:
2238 flag.setOnOff(fontinfo.noun() == FONT_ON);
2241 case LFUN_FONT_BOLD:
2242 case LFUN_FONT_BOLDSYMBOL:
2243 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2246 case LFUN_FONT_SANS:
2247 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2250 case LFUN_FONT_ROMAN:
2251 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2254 case LFUN_FONT_TYPEWRITER:
2255 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2260 enable = cur.selection();
2264 if (cmd.argument().empty()) {
2265 if (theClipboard().isInternal())
2266 enable = cap::numberOfSelections() > 0;
2268 enable = !theClipboard().empty();
2272 // we have an argument
2273 string const arg = to_utf8(cmd.argument());
2274 if (isStrUnsignedInt(arg)) {
2275 // it's a number and therefore means the internal stack
2276 unsigned int n = convert<unsigned int>(arg);
2277 enable = cap::numberOfSelections() > n;
2281 // explicit graphics type?
2282 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2283 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2284 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2285 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2286 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2287 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2288 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2289 enable = theClipboard().hasGraphicsContents(type);
2298 case LFUN_CLIPBOARD_PASTE:
2299 enable = !theClipboard().empty();
2302 case LFUN_PRIMARY_SELECTION_PASTE:
2303 enable = cur.selection() || !theSelection().empty();
2306 case LFUN_SELECTION_PASTE:
2307 enable = cap::selection();
2310 case LFUN_PARAGRAPH_MOVE_UP:
2311 enable = cur.pit() > 0 && !cur.selection();
2314 case LFUN_PARAGRAPH_MOVE_DOWN:
2315 enable = cur.pit() < cur.lastpit() && !cur.selection();
2318 case LFUN_INSET_DISSOLVE:
2319 if (!cmd.argument().empty()) {
2320 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2321 InsetLayout::InsetLyXType const type =
2322 translateLyXType(to_utf8(cmd.argument()));
2323 enable = cur.inset().lyxCode() == FLEX_CODE
2324 && il.lyxtype() == type;
2326 enable = ((!isMainText(cur.bv().buffer())
2327 && cur.inset().nargs() == 1)
2329 && cur.nextInset()->nargs() == 1));
2333 case LFUN_CHANGE_ACCEPT:
2334 case LFUN_CHANGE_REJECT:
2335 // In principle, these LFUNs should only be enabled if there
2336 // is a change at the current position/in the current selection.
2337 // However, without proper optimizations, this will inevitably
2338 // result in unacceptable performance - just imagine a user who
2339 // wants to select the complete content of a long document.
2340 if (!cur.selection()) {
2341 Change const & change = cur.paragraph().lookupChange(cur.pos());
2342 enable = change.changed();
2344 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2349 case LFUN_OUTLINE_UP:
2350 case LFUN_OUTLINE_DOWN:
2351 case LFUN_OUTLINE_IN:
2352 case LFUN_OUTLINE_OUT:
2353 // FIXME: LyX is not ready for outlining within inset.
2354 enable = isMainText(cur.bv().buffer())
2355 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2358 case LFUN_NEWLINE_INSERT:
2359 // LaTeX restrictions (labels or empty par)
2360 enable = (cur.pos() > cur.paragraph().beginOfBody());
2363 case LFUN_SET_GRAPHICS_GROUP: {
2364 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2368 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2372 case LFUN_NEWPAGE_INSERT:
2373 // not allowed in description items
2374 enable = !inDescriptionItem(cur);
2377 case LFUN_MATH_INSERT:
2378 case LFUN_MATH_MATRIX:
2379 case LFUN_MATH_DELIM:
2380 case LFUN_MATH_BIGDELIM:
2381 // not allowed in ERT, for example.
2382 enable = cur.inset().insetAllowed(MATH_CODE);
2385 case LFUN_DATE_INSERT: {
2386 string const format = cmd.argument().empty()
2387 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2388 enable = support::os::is_valid_strftime(format);
2392 case LFUN_WORD_DELETE_FORWARD:
2393 case LFUN_WORD_DELETE_BACKWARD:
2394 case LFUN_LINE_DELETE:
2395 case LFUN_WORD_FORWARD:
2396 case LFUN_WORD_BACKWARD:
2397 case LFUN_WORD_RIGHT:
2398 case LFUN_WORD_LEFT:
2399 case LFUN_CHAR_FORWARD:
2400 case LFUN_CHAR_FORWARD_SELECT:
2401 case LFUN_CHAR_BACKWARD:
2402 case LFUN_CHAR_BACKWARD_SELECT:
2403 case LFUN_CHAR_LEFT:
2404 case LFUN_CHAR_LEFT_SELECT:
2405 case LFUN_CHAR_RIGHT:
2406 case LFUN_CHAR_RIGHT_SELECT:
2408 case LFUN_UP_SELECT:
2410 case LFUN_DOWN_SELECT:
2411 case LFUN_PARAGRAPH_UP_SELECT:
2412 case LFUN_PARAGRAPH_DOWN_SELECT:
2413 case LFUN_LINE_BEGIN_SELECT:
2414 case LFUN_LINE_END_SELECT:
2415 case LFUN_WORD_FORWARD_SELECT:
2416 case LFUN_WORD_BACKWARD_SELECT:
2417 case LFUN_WORD_RIGHT_SELECT:
2418 case LFUN_WORD_LEFT_SELECT:
2419 case LFUN_WORD_SELECT:
2420 case LFUN_SECTION_SELECT:
2421 case LFUN_PARAGRAPH_UP:
2422 case LFUN_PARAGRAPH_DOWN:
2423 case LFUN_LINE_BEGIN:
2425 case LFUN_CHAR_DELETE_FORWARD:
2426 case LFUN_CHAR_DELETE_BACKWARD:
2427 case LFUN_BREAK_PARAGRAPH:
2428 case LFUN_PARAGRAPH_SPACING:
2429 case LFUN_INSET_INSERT:
2430 case LFUN_WORD_UPCASE:
2431 case LFUN_WORD_LOWCASE:
2432 case LFUN_WORD_CAPITALIZE:
2433 case LFUN_CHARS_TRANSPOSE:
2434 case LFUN_SERVER_GET_XY:
2435 case LFUN_SERVER_SET_XY:
2436 case LFUN_SERVER_GET_LAYOUT:
2438 case LFUN_SELF_INSERT:
2439 case LFUN_LINE_INSERT:
2440 case LFUN_MATH_DISPLAY:
2441 case LFUN_MATH_MODE:
2442 case LFUN_MATH_MACRO:
2443 case LFUN_MATH_SUBSCRIPT:
2444 case LFUN_MATH_SUPERSCRIPT:
2445 case LFUN_FONT_DEFAULT:
2446 case LFUN_FONT_UNDERLINE:
2447 case LFUN_FONT_STRIKEOUT:
2448 case LFUN_FONT_UULINE:
2449 case LFUN_FONT_UWAVE:
2450 case LFUN_FONT_SIZE:
2452 case LFUN_TEXTSTYLE_APPLY:
2453 case LFUN_TEXTSTYLE_UPDATE:
2454 case LFUN_LAYOUT_PARAGRAPH:
2455 case LFUN_PARAGRAPH_UPDATE:
2456 case LFUN_ACCENT_UMLAUT:
2457 case LFUN_ACCENT_CIRCUMFLEX:
2458 case LFUN_ACCENT_GRAVE:
2459 case LFUN_ACCENT_ACUTE:
2460 case LFUN_ACCENT_TILDE:
2461 case LFUN_ACCENT_CEDILLA:
2462 case LFUN_ACCENT_MACRON:
2463 case LFUN_ACCENT_DOT:
2464 case LFUN_ACCENT_UNDERDOT:
2465 case LFUN_ACCENT_UNDERBAR:
2466 case LFUN_ACCENT_CARON:
2467 case LFUN_ACCENT_BREVE:
2468 case LFUN_ACCENT_TIE:
2469 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2470 case LFUN_ACCENT_CIRCLE:
2471 case LFUN_ACCENT_OGONEK:
2472 case LFUN_THESAURUS_ENTRY:
2473 case LFUN_PARAGRAPH_PARAMS_APPLY:
2474 case LFUN_PARAGRAPH_PARAMS:
2476 case LFUN_BUFFER_BEGIN:
2477 case LFUN_BUFFER_END:
2478 case LFUN_BUFFER_BEGIN_SELECT:
2479 case LFUN_BUFFER_END_SELECT:
2480 case LFUN_INSET_BEGIN:
2481 case LFUN_INSET_END:
2482 case LFUN_INSET_BEGIN_SELECT:
2483 case LFUN_INSET_END_SELECT:
2484 case LFUN_UNICODE_INSERT:
2485 // these are handled in our dispatch()
2494 && (cur.empty() || !cur.inset().insetAllowed(code)))
2497 flag.setEnabled(enable);
2502 void Text::pasteString(Cursor & cur, docstring const & clip,
2505 cur.clearSelection();
2506 if (!clip.empty()) {
2509 insertStringAsParagraphs(cur, clip);
2511 insertStringAsLines(cur, clip);
2516 // FIXME: an item inset would make things much easier.
2517 bool Text::inDescriptionItem(Cursor & cur) const
2519 Paragraph & par = cur.paragraph();
2520 pos_type const pos = cur.pos();
2521 pos_type const body_pos = par.beginOfBody();
2523 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2524 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2525 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2528 return (pos < body_pos
2530 && (pos == 0 || par.getChar(pos - 1) != ' ')));