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) {
339 if (start == pars.begin())
342 ParagraphList::iterator dest = start;
343 // Move out (up) from this header
346 // Search previous same-level header above
349 toclevel = dest->layout().toclevel;
351 && (toclevel == Layout::NOT_IN_TOC
352 || toclevel > thistoclevel));
353 // Not found; do nothing
354 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
356 pit_type const newpit = distance(bgn, dest);
357 pit_type const len = distance(start, finish);
358 pit_type const deletepit = pit + len;
359 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
360 pars.insert(dest, start, finish);
361 start = boost::next(pars.begin(), deletepit);
363 pars.erase(start, finish);
370 // Go one down from *this* header:
371 ParagraphList::iterator dest = boost::next(finish, 1);
372 // Go further down to find header to insert in front of:
373 for (; dest != end; ++dest) {
374 toclevel = dest->layout().toclevel;
375 if (toclevel != Layout::NOT_IN_TOC
376 && toclevel <= thistoclevel) {
380 // One such was found:
381 pit_type newpit = distance(bgn, dest);
382 pit_type const len = distance(start, finish);
383 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
384 pars.insert(dest, start, finish);
385 start = boost::next(bgn, pit);
387 pars.erase(start, finish);
391 pit_type const len = distance(start, finish);
392 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
393 for (; start != finish; ++start) {
394 toclevel = start->layout().toclevel;
395 if (toclevel == Layout::NOT_IN_TOC)
397 DocumentClass::const_iterator lit = tc.begin();
398 DocumentClass::const_iterator len = tc.end();
399 for (; lit != len; ++lit) {
400 if (lit->toclevel == toclevel + 1 &&
401 start->layout().labeltype == lit->labeltype) {
402 start->setLayout(*lit);
410 pit_type const len = distance(start, finish);
411 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
412 for (; start != finish; ++start) {
413 toclevel = start->layout().toclevel;
414 if (toclevel == Layout::NOT_IN_TOC)
416 DocumentClass::const_iterator lit = tc.begin();
417 DocumentClass::const_iterator len = tc.end();
418 for (; lit != len; ++lit) {
419 if (lit->toclevel == toclevel - 1 &&
420 start->layout().labeltype == lit->labeltype) {
421 start->setLayout(*lit);
432 void Text::number(Cursor & cur)
434 FontInfo font = ignore_font;
435 font.setNumber(FONT_TOGGLE);
436 toggleAndShow(cur, this, Font(font, ignore_language));
440 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
442 return par.isRTL(buffer.params());
446 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
448 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
450 BufferView * bv = &cur.bv();
451 TextMetrics & tm = bv->textMetrics(this);
452 if (!tm.contains(cur.pit())) {
453 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
454 tm = bv->textMetrics(this);
457 // FIXME: We use the update flag to indicates wether a singlePar or a
458 // full screen update is needed. We reset it here but shall we restore it
462 LASSERT(cur.text() == this, /**/);
463 CursorSlice oldTopSlice = cur.top();
464 bool oldBoundary = cur.boundary();
465 bool sel = cur.selection();
466 // Signals that, even if needsUpdate == false, an update of the
467 // cursor paragraph is required
468 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
469 LyXAction::SingleParUpdate);
470 // Signals that a full-screen update is required
471 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
472 LyXAction::NoUpdate) || singleParUpdate);
474 switch (cmd.action) {
476 case LFUN_PARAGRAPH_MOVE_DOWN: {
477 pit_type const pit = cur.pit();
478 recUndo(cur, pit, pit + 1);
480 swap(pars_[pit], pars_[pit + 1]);
481 cur.buffer()->updateLabels();
487 case LFUN_PARAGRAPH_MOVE_UP: {
488 pit_type const pit = cur.pit();
489 recUndo(cur, pit - 1, pit);
491 swap(pars_[pit], pars_[pit - 1]);
492 cur.buffer()->updateLabels();
498 case LFUN_APPENDIX: {
499 Paragraph & par = cur.paragraph();
500 bool start = !par.params().startOfAppendix();
502 // FIXME: The code below only makes sense at top level.
503 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
504 // ensure that we have only one start_of_appendix in this document
505 // FIXME: this don't work for multipart document!
506 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
507 if (pars_[tmp].params().startOfAppendix()) {
509 pars_[tmp].params().startOfAppendix(false);
515 par.params().startOfAppendix(start);
517 // we can set the refreshing parameters now
518 cur.buffer()->updateLabels();
522 case LFUN_WORD_DELETE_FORWARD:
524 cutSelection(cur, true, false);
526 deleteWordForward(cur);
527 finishChange(cur, false);
530 case LFUN_WORD_DELETE_BACKWARD:
532 cutSelection(cur, true, false);
534 deleteWordBackward(cur);
535 finishChange(cur, false);
538 case LFUN_LINE_DELETE:
540 cutSelection(cur, true, false);
542 tm.deleteLineForward(cur);
543 finishChange(cur, false);
546 case LFUN_BUFFER_BEGIN:
547 case LFUN_BUFFER_BEGIN_SELECT:
548 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
549 if (cur.depth() == 1)
550 needsUpdate |= cursorTop(cur);
553 cur.updateFlags(Update::FitCursor);
556 case LFUN_BUFFER_END:
557 case LFUN_BUFFER_END_SELECT:
558 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
559 if (cur.depth() == 1)
560 needsUpdate |= cursorBottom(cur);
563 cur.updateFlags(Update::FitCursor);
566 case LFUN_INSET_BEGIN:
567 case LFUN_INSET_BEGIN_SELECT:
568 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_BEGIN_SELECT);
569 if (cur.depth() == 1 || cur.pos() > 0)
570 needsUpdate |= cursorTop(cur);
573 cur.updateFlags(Update::FitCursor);
577 case LFUN_INSET_END_SELECT:
578 needsUpdate |= cur.selHandle(cmd.action == LFUN_INSET_END_SELECT);
579 if (cur.depth() == 1 || cur.pos() < cur.lastpos())
580 needsUpdate |= cursorBottom(cur);
583 cur.updateFlags(Update::FitCursor);
586 case LFUN_CHAR_FORWARD:
587 case LFUN_CHAR_FORWARD_SELECT:
588 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
589 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
590 needsUpdate |= cursorForward(cur);
592 if (!needsUpdate && oldTopSlice == cur.top()
593 && cur.boundary() == oldBoundary) {
595 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
599 case LFUN_CHAR_BACKWARD:
600 case LFUN_CHAR_BACKWARD_SELECT:
601 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
602 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
603 needsUpdate |= cursorBackward(cur);
605 if (!needsUpdate && oldTopSlice == cur.top()
606 && cur.boundary() == oldBoundary) {
608 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
613 case LFUN_CHAR_LEFT_SELECT:
614 if (lyxrc.visual_cursor) {
615 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
616 needsUpdate |= cursorVisLeft(cur);
617 if (!needsUpdate && oldTopSlice == cur.top()
618 && cur.boundary() == oldBoundary) {
620 cmd = FuncRequest(LFUN_FINISHED_LEFT);
623 if (reverseDirectionNeeded(cur)) {
624 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
625 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
627 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
628 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
635 case LFUN_CHAR_RIGHT:
636 case LFUN_CHAR_RIGHT_SELECT:
637 if (lyxrc.visual_cursor) {
638 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
639 needsUpdate |= cursorVisRight(cur);
640 if (!needsUpdate && oldTopSlice == cur.top()
641 && cur.boundary() == oldBoundary) {
643 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
646 if (reverseDirectionNeeded(cur)) {
647 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
648 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
650 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
651 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
660 case LFUN_DOWN_SELECT:
663 // stop/start the selection
664 bool select = cmd.action == LFUN_DOWN_SELECT ||
665 cmd.action == LFUN_UP_SELECT;
667 // move cursor up/down
668 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
669 bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
671 if (!atFirstOrLastRow) {
672 needsUpdate |= cur.selHandle(select);
673 cur.selHandle(select);
674 cur.upDownInText(up, needsUpdate);
675 needsUpdate |= cur.beforeDispatchCursor().inMathed();
677 // if the cursor cannot be moved up or down do not remove
678 // the selection right now, but wait for the next dispatch.
680 needsUpdate |= cur.selHandle(select);
681 cur.upDownInText(up, needsUpdate);
688 case LFUN_PARAGRAPH_UP:
689 case LFUN_PARAGRAPH_UP_SELECT:
690 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
691 needsUpdate |= cursorUpParagraph(cur);
694 case LFUN_PARAGRAPH_DOWN:
695 case LFUN_PARAGRAPH_DOWN_SELECT:
696 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
697 needsUpdate |= cursorDownParagraph(cur);
700 case LFUN_LINE_BEGIN:
701 case LFUN_LINE_BEGIN_SELECT:
702 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
703 needsUpdate |= tm.cursorHome(cur);
707 case LFUN_LINE_END_SELECT:
708 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
709 needsUpdate |= tm.cursorEnd(cur);
712 case LFUN_WORD_RIGHT:
713 case LFUN_WORD_RIGHT_SELECT:
714 if (lyxrc.visual_cursor) {
715 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_RIGHT_SELECT);
716 needsUpdate |= cursorVisRightOneWord(cur);
717 if (!needsUpdate && oldTopSlice == cur.top()
718 && cur.boundary() == oldBoundary) {
720 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
723 if (reverseDirectionNeeded(cur)) {
724 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
725 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
727 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
728 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
735 case LFUN_WORD_FORWARD:
736 case LFUN_WORD_FORWARD_SELECT:
737 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
738 needsUpdate |= cursorForwardOneWord(cur);
742 case LFUN_WORD_LEFT_SELECT:
743 if (lyxrc.visual_cursor) {
744 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_LEFT_SELECT);
745 needsUpdate |= cursorVisLeftOneWord(cur);
746 if (!needsUpdate && oldTopSlice == cur.top()
747 && cur.boundary() == oldBoundary) {
749 cmd = FuncRequest(LFUN_FINISHED_LEFT);
752 if (reverseDirectionNeeded(cur)) {
753 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
754 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
756 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
757 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
764 case LFUN_WORD_BACKWARD:
765 case LFUN_WORD_BACKWARD_SELECT:
766 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
767 needsUpdate |= cursorBackwardOneWord(cur);
770 case LFUN_WORD_SELECT: {
771 selectWord(cur, WHOLE_WORD);
772 finishChange(cur, true);
776 case LFUN_NEWLINE_INSERT: {
777 InsetNewlineParams inp;
778 docstring arg = cmd.argument();
779 // this avoids a double undo
780 // FIXME: should not be needed, ideally
781 if (!cur.selection())
783 cap::replaceSelection(cur);
784 if (arg == "linebreak")
785 inp.kind = InsetNewlineParams::LINEBREAK;
787 inp.kind = InsetNewlineParams::NEWLINE;
788 cur.insert(new InsetNewline(inp));
790 moveCursor(cur, false);
794 case LFUN_CHAR_DELETE_FORWARD:
795 if (!cur.selection()) {
796 if (cur.pos() == cur.paragraph().size())
797 // Par boundary, force full-screen update
798 singleParUpdate = false;
799 needsUpdate |= erase(cur);
801 // It is possible to make it a lot faster still
802 // just comment out the line below...
804 cutSelection(cur, true, false);
805 singleParUpdate = false;
807 moveCursor(cur, false);
810 case LFUN_CHAR_DELETE_BACKWARD:
811 if (!cur.selection()) {
812 if (bv->getIntl().getTransManager().backspace()) {
813 // Par boundary, full-screen update
815 singleParUpdate = false;
816 needsUpdate |= backspace(cur);
818 // It is possible to make it a lot faster still
819 // just comment out the line below...
822 cutSelection(cur, true, false);
823 singleParUpdate = false;
827 case LFUN_BREAK_PARAGRAPH:
828 cap::replaceSelection(cur);
829 breakParagraph(cur, cmd.argument() == "inverse");
834 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
835 // as its duties can be performed there. Should it be removed??
836 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
837 case LFUN_PARAGRAPH_SPACING: {
838 Paragraph & par = cur.paragraph();
839 Spacing::Space cur_spacing = par.params().spacing().getSpace();
840 string cur_value = "1.0";
841 if (cur_spacing == Spacing::Other)
842 cur_value = par.params().spacing().getValueAsString();
844 istringstream is(to_utf8(cmd.argument()));
847 Spacing::Space new_spacing = cur_spacing;
848 string new_value = cur_value;
850 lyxerr << "Missing argument to `paragraph-spacing'"
852 } else if (tmp == "single") {
853 new_spacing = Spacing::Single;
854 } else if (tmp == "onehalf") {
855 new_spacing = Spacing::Onehalf;
856 } else if (tmp == "double") {
857 new_spacing = Spacing::Double;
858 } else if (tmp == "other") {
859 new_spacing = Spacing::Other;
860 string tmpval = "0.0";
862 lyxerr << "new_value = " << tmpval << endl;
865 } else if (tmp == "default") {
866 new_spacing = Spacing::Default;
868 lyxerr << to_utf8(_("Unknown spacing argument: "))
869 << to_utf8(cmd.argument()) << endl;
871 if (cur_spacing != new_spacing || cur_value != new_value)
872 par.params().spacing(Spacing(new_spacing, new_value));
876 case LFUN_INSET_INSERT: {
879 // We have to avoid triggering InstantPreview loading
880 // before inserting into the document. See bug #5626.
881 bool loaded = bv->buffer().isFullyLoaded();
882 bv->buffer().setFullyLoaded(false);
883 Inset * inset = createInset(bv->buffer(), cmd);
884 bv->buffer().setFullyLoaded(loaded);
887 // FIXME (Abdel 01/02/2006):
888 // What follows would be a partial fix for bug 2154:
889 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
890 // This automatically put the label inset _after_ a
891 // numbered section. It should be possible to extend the mechanism
892 // to any kind of LateX environement.
893 // The correct way to fix that bug would be at LateX generation.
894 // I'll let the code here for reference as it could be used for some
895 // other feature like "automatic labelling".
897 Paragraph & par = pars_[cur.pit()];
898 if (inset->lyxCode() == LABEL_CODE
899 && par.layout().labeltype == LABEL_COUNTER) {
900 // Go to the end of the paragraph
901 // Warning: Because of Change-Tracking, the last
902 // position is 'size()' and not 'size()-1':
903 cur.pos() = par.size();
904 // Insert a new paragraph
905 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
910 cutSelection(cur, true, false);
914 // trigger InstantPreview now
915 if (inset->lyxCode() == EXTERNAL_CODE) {
916 InsetExternal & ins =
917 static_cast<InsetExternal &>(*inset);
925 case LFUN_INSET_DISSOLVE: {
926 // first, try if there's an inset at cursor
927 // FIXME: this first part should be moved to
928 // a LFUN_NEXT_INSET_DISSOLVE, or be called via
929 // some generic "next-inset inset-dissolve"
930 Inset * inset = cur.nextInset();
931 if (inset && inset->isActive()) {
933 tmpcur.pushBackward(*inset);
934 inset->dispatch(tmpcur, cmd);
935 if (tmpcur.result().dispatched()) {
940 // if it did not work, try the underlying inset
941 if (dissolveInset(cur)) {
945 // if it did not work, do nothing.
949 case LFUN_SET_GRAPHICS_GROUP: {
950 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
956 string id = to_utf8(cmd.argument());
957 string grp = graphics::getGroupParams(bv->buffer(), id);
958 InsetGraphicsParams tmp, inspar = ins->getParams();
961 inspar.groupId = to_utf8(cmd.argument());
963 InsetGraphics::string2params(grp, bv->buffer(), tmp);
964 tmp.filename = inspar.filename;
968 ins->setParams(inspar);
971 case LFUN_SPACE_INSERT:
972 if (cur.paragraph().layout().free_spacing)
973 insertChar(cur, ' ');
975 doInsertInset(cur, this, cmd, false, false);
978 moveCursor(cur, false);
981 case LFUN_SPECIALCHAR_INSERT: {
982 string const name = to_utf8(cmd.argument());
983 if (name == "hyphenation")
984 specialChar(cur, InsetSpecialChar::HYPHENATION);
985 else if (name == "ligature-break")
986 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
987 else if (name == "slash")
988 specialChar(cur, InsetSpecialChar::SLASH);
989 else if (name == "nobreakdash")
990 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
991 else if (name == "dots")
992 specialChar(cur, InsetSpecialChar::LDOTS);
993 else if (name == "end-of-sentence")
994 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
995 else if (name == "menu-separator")
996 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
997 else if (name.empty())
998 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1000 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1004 case LFUN_WORD_UPCASE:
1005 changeCase(cur, text_uppercase);
1008 case LFUN_WORD_LOWCASE:
1009 changeCase(cur, text_lowercase);
1012 case LFUN_WORD_CAPITALIZE:
1013 changeCase(cur, text_capitalization);
1016 case LFUN_CHARS_TRANSPOSE:
1017 charsTranspose(cur);
1021 cur.message(_("Paste"));
1022 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
1023 cap::replaceSelection(cur);
1025 // without argument?
1026 string const arg = to_utf8(cmd.argument());
1028 if (theClipboard().isInternal())
1029 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1030 else if (theClipboard().hasGraphicsContents()
1031 && !theClipboard().hasTextContents())
1032 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1034 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
1035 } else if (isStrUnsignedInt(arg)) {
1036 // we have a numerical argument
1037 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1038 convert<unsigned int>(arg));
1040 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1042 type = Clipboard::PdfGraphicsType;
1043 else if (arg == "png")
1044 type = Clipboard::PngGraphicsType;
1045 else if (arg == "jpeg")
1046 type = Clipboard::JpegGraphicsType;
1047 else if (arg == "linkback")
1048 type = Clipboard::LinkBackGraphicsType;
1049 else if (arg == "emf")
1050 type = Clipboard::EmfGraphicsType;
1051 else if (arg == "wmf")
1052 type = Clipboard::WmfGraphicsType;
1055 LASSERT(false, /**/);
1057 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1060 bv->buffer().errors("Paste");
1061 cur.clearSelection(); // bug 393
1067 cutSelection(cur, true, true);
1068 cur.message(_("Cut"));
1073 cur.message(_("Copy"));
1076 case LFUN_SERVER_GET_XY:
1077 cur.message(from_utf8(
1078 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
1079 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
1082 case LFUN_SERVER_SET_XY: {
1085 istringstream is(to_utf8(cmd.argument()));
1088 lyxerr << "SETXY: Could not parse coordinates in '"
1089 << to_utf8(cmd.argument()) << endl;
1091 tm.setCursorFromCoordinates(cur, x, y);
1095 case LFUN_SERVER_GET_LAYOUT:
1096 cur.message(cur.paragraph().layout().name());
1100 docstring layout = cmd.argument();
1101 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1103 Paragraph const & para = cur.paragraph();
1104 docstring const old_layout = para.layout().name();
1105 DocumentClass const & tclass = bv->buffer().params().documentClass();
1108 layout = tclass.defaultLayoutName();
1110 if (para.forcePlainLayout())
1111 // in this case only the empty layout is allowed
1112 layout = tclass.plainLayoutName();
1113 else if (para.usePlainLayout()) {
1114 // in this case, default layout maps to empty layout
1115 if (layout == tclass.defaultLayoutName())
1116 layout = tclass.plainLayoutName();
1118 // otherwise, the empty layout maps to the default
1119 if (layout == tclass.plainLayoutName())
1120 layout = tclass.defaultLayoutName();
1123 bool hasLayout = tclass.hasLayout(layout);
1125 // If the entry is obsolete, use the new one instead.
1127 docstring const & obs = tclass[layout].obsoleted_by();
1133 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1134 from_utf8(N_(" not known")));
1138 bool change_layout = (old_layout != layout);
1140 if (!change_layout && cur.selection() &&
1141 cur.selBegin().pit() != cur.selEnd().pit())
1143 pit_type spit = cur.selBegin().pit();
1144 pit_type epit = cur.selEnd().pit() + 1;
1145 while (spit != epit) {
1146 if (pars_[spit].layout().name() != old_layout) {
1147 change_layout = true;
1155 setLayout(cur, layout);
1160 case LFUN_CLIPBOARD_PASTE:
1161 cur.clearSelection();
1162 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1163 cmd.argument() == "paragraph");
1164 bv->buffer().errors("Paste");
1167 case LFUN_PRIMARY_SELECTION_PASTE:
1168 pasteString(cur, theSelection().get(),
1169 cmd.argument() == "paragraph");
1172 case LFUN_SELECTION_PASTE:
1173 // Copy the selection buffer to the clipboard stack,
1174 // because we want it to appear in the "Edit->Paste
1176 cap::copySelectionToStack();
1177 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1178 bv->buffer().errors("Paste");
1181 case LFUN_UNICODE_INSERT: {
1182 if (cmd.argument().empty())
1184 docstring hexstring = cmd.argument();
1185 if (isHex(hexstring)) {
1186 char_type c = hexToInt(hexstring);
1187 if (c >= 32 && c < 0x10ffff) {
1188 lyxerr << "Inserting c: " << c << endl;
1189 docstring s = docstring(1, c);
1190 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1196 case LFUN_QUOTE_INSERT: {
1197 Paragraph & par = cur.paragraph();
1198 pos_type pos = cur.pos();
1199 BufferParams const & bufparams = bv->buffer().params();
1200 Layout const & style = par.layout();
1201 InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
1202 if (!style.pass_thru && !ilayout.isPassThru()
1203 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1204 // this avoids a double undo
1205 // FIXME: should not be needed, ideally
1206 if (!cur.selection())
1208 cap::replaceSelection(cur);
1213 else if (cur.prevInset() && cur.prevInset()->isSpace())
1216 c = par.getChar(pos - 1);
1217 string arg = to_utf8(cmd.argument());
1218 cur.insert(new InsetQuotes(bv->buffer(), c, (arg == "single")
1219 ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes));
1223 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1227 case LFUN_DATE_INSERT: {
1228 string const format = cmd.argument().empty()
1229 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1230 string const time = formatted_time(current_time(), format);
1231 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1235 case LFUN_MOUSE_TRIPLE:
1236 if (cmd.button() == mouse_button::button1) {
1245 case LFUN_MOUSE_DOUBLE:
1246 if (cmd.button() == mouse_button::button1) {
1247 selectWord(cur, WHOLE_WORD_STRICT);
1252 // Single-click on work area
1253 case LFUN_MOUSE_PRESS:
1254 // We are not marking a selection with the keyboard in any case.
1255 cur.bv().cursor().setMark(false);
1256 switch (cmd.button()) {
1257 case mouse_button::button1:
1259 if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
1260 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1263 case mouse_button::button2:
1264 // Middle mouse pasting.
1265 bv->mouseSetCursor(cur);
1267 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1268 "selection-paste ; primary-selection-paste paragraph"));
1272 case mouse_button::button3: {
1273 Cursor const & bvcur = cur.bv().cursor();
1274 // Don't do anything if we right-click a
1275 // selection, a context menu will popup.
1276 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1277 && cur < bvcur.selectionEnd()) {
1281 if (!bv->mouseSetCursor(cur, false))
1282 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1288 } // switch (cmd.button())
1291 case LFUN_MOUSE_MOTION: {
1292 // Mouse motion with right or middle mouse do nothing for now.
1293 if (cmd.button() != mouse_button::button1) {
1297 // ignore motions deeper nested than the real anchor
1298 Cursor & bvcur = cur.bv().cursor();
1299 if (!bvcur.anchor_.hasPart(cur)) {
1303 CursorSlice old = bvcur.top();
1305 int const wh = bv->workHeight();
1306 int const y = max(0, min(wh - 1, cmd.y));
1308 tm.setCursorFromCoordinates(cur, cmd.x, y);
1309 cur.setTargetX(cmd.x);
1311 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1313 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1314 // This is to allow jumping over large insets
1315 if (cur.top() == old) {
1317 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1319 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1321 // We continue with our existing selection or start a new one, so don't
1322 // reset the anchor.
1323 bvcur.setCursor(cur);
1324 bvcur.setSelection(true);
1325 if (cur.top() == old) {
1326 // We didn't move one iota, so no need to update the screen.
1327 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1334 case LFUN_MOUSE_RELEASE:
1335 switch (cmd.button()) {
1336 case mouse_button::button1:
1337 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1338 // If there is a new selection, update persistent selection;
1339 // otherwise, single click does not clear persistent selection
1341 if (cur.selection()) {
1342 // Finish selection. If double click,
1343 // cur is moved to the end of word by
1344 // selectWord but bvcur is current
1346 cur.bv().cursor().setSelection();
1347 // We might have removed an empty but drawn selection
1348 // (probably a margin)
1349 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1352 // FIXME: We could try to handle drag and drop of selection here.
1355 case mouse_button::button2:
1356 // Middle mouse pasting is handled at mouse press time,
1357 // see LFUN_MOUSE_PRESS.
1361 case mouse_button::button3:
1362 // Cursor was set at LFUN_MOUSE_PRESS time.
1363 // FIXME: If there is a selection we could try to handle a special
1364 // drag & drop context menu.
1368 case mouse_button::none:
1369 case mouse_button::button4:
1370 case mouse_button::button5:
1372 } // switch (cmd.button())
1376 case LFUN_SELF_INSERT: {
1377 if (cmd.argument().empty())
1380 // Automatically delete the currently selected
1381 // text and replace it with what is being
1382 // typed in now. Depends on lyxrc settings
1383 // "auto_region_delete", which defaults to
1386 if (lyxrc.auto_region_delete && cur.selection())
1387 cutSelection(cur, false, false);
1389 cur.clearSelection();
1391 docstring::const_iterator cit = cmd.argument().begin();
1392 docstring::const_iterator const end = cmd.argument().end();
1393 for (; cit != end; ++cit)
1394 bv->translateAndInsert(*cit, this, cur);
1397 moveCursor(cur, false);
1398 bv->bookmarkEditPosition();
1402 case LFUN_HYPERLINK_INSERT: {
1403 InsetCommandParams p(HYPERLINK_CODE);
1405 if (cur.selection()) {
1406 content = cur.selectionAsString(false);
1407 cutSelection(cur, true, false);
1409 p["target"] = (cmd.argument().empty()) ?
1410 content : cmd.argument();
1411 string const data = InsetCommand::params2string("href", p);
1412 if (p["target"].empty()) {
1413 bv->showDialog("href", data);
1415 FuncRequest fr(LFUN_INSET_INSERT, data);
1421 case LFUN_LABEL_INSERT: {
1422 InsetCommandParams p(LABEL_CODE);
1423 // Try to generate a valid label
1424 p["name"] = (cmd.argument().empty()) ?
1425 cur.getPossibleLabel() :
1427 string const data = InsetCommand::params2string("label", p);
1429 if (cmd.argument().empty()) {
1430 bv->showDialog("label", data);
1432 FuncRequest fr(LFUN_INSET_INSERT, data);
1438 case LFUN_INFO_INSERT: {
1440 if (cmd.argument().empty() && cur.selection()) {
1441 // if command argument is empty use current selection as parameter.
1442 docstring ds = cur.selectionAsString(false);
1443 cutSelection(cur, true, false);
1444 FuncRequest cmd0(cmd, ds);
1445 inset = createInset(cur.bv().buffer(), cmd0);
1447 inset = createInset(cur.bv().buffer(), cmd);
1451 insertInset(cur, inset);
1455 case LFUN_CAPTION_INSERT:
1456 case LFUN_FOOTNOTE_INSERT:
1457 case LFUN_NOTE_INSERT:
1458 case LFUN_FLEX_INSERT:
1459 case LFUN_BOX_INSERT:
1460 case LFUN_BRANCH_INSERT:
1461 case LFUN_PHANTOM_INSERT:
1462 case LFUN_ERT_INSERT:
1463 case LFUN_LISTING_INSERT:
1464 case LFUN_MARGINALNOTE_INSERT:
1465 case LFUN_OPTIONAL_INSERT:
1466 case LFUN_INDEX_INSERT:
1467 // Open the inset, and move the current selection
1469 doInsertInset(cur, this, cmd, true, true);
1471 // Some insets are numbered, others are shown in the outline pane so
1472 // let's update the labels and the toc backend.
1473 bv->buffer().updateLabels();
1476 case LFUN_TABULAR_INSERT:
1477 // if there were no arguments, just open the dialog
1478 if (doInsertInset(cur, this, cmd, false, true))
1481 bv->showDialog("tabularcreate");
1485 case LFUN_FLOAT_INSERT:
1486 case LFUN_FLOAT_WIDE_INSERT:
1487 case LFUN_WRAP_INSERT: {
1488 // will some text be moved into the inset?
1489 bool content = cur.selection();
1491 doInsertInset(cur, this, cmd, true, true);
1494 // If some text is moved into the inset, doInsertInset
1495 // puts the cursor outside the inset. To insert the
1496 // caption we put it back into the inset.
1500 ParagraphList & pars = cur.text()->paragraphs();
1502 DocumentClass const & tclass = bv->buffer().params().documentClass();
1504 // add a separate paragraph for the caption inset
1505 pars.push_back(Paragraph());
1506 pars.back().setInsetOwner(&pars[0].inInset());
1507 pars.back().setPlainOrDefaultLayout(tclass);
1508 int cap_pit = pars.size() - 1;
1510 // if an empty inset was created, we create an additional empty
1511 // paragraph at the bottom so that the user can choose where to put
1512 // the graphics (or table).
1514 pars.push_back(Paragraph());
1515 pars.back().setInsetOwner(&pars[0].inInset());
1516 pars.back().setPlainOrDefaultLayout(tclass);
1519 // reposition the cursor to the caption
1520 cur.pit() = cap_pit;
1522 // FIXME: This Text/Cursor dispatch handling is a mess!
1523 // We cannot use Cursor::dispatch here it needs access to up to
1525 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1526 doInsertInset(cur, cur.text(), cmd_caption, true, false);
1527 bv->buffer().updateLabels();
1528 cur.updateFlags(Update::Force);
1529 // FIXME: When leaving the Float (or Wrap) inset we should
1530 // delete any empty paragraph left above or below the
1535 case LFUN_NOMENCL_INSERT: {
1536 InsetCommandParams p(NOMENCL_CODE);
1537 if (cmd.argument().empty())
1538 p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
1540 p["symbol"] = cmd.argument();
1541 string const data = InsetCommand::params2string("nomenclature", p);
1542 bv->showDialog("nomenclature", data);
1546 case LFUN_INDEX_PRINT: {
1547 InsetCommandParams p(INDEX_PRINT_CODE);
1548 if (cmd.argument().empty())
1549 p["type"] = from_ascii("idx");
1551 p["type"] = cmd.argument();
1552 string const data = InsetCommand::params2string("index_print", p);
1553 FuncRequest fr(LFUN_INSET_INSERT, data);
1558 case LFUN_NOMENCL_PRINT:
1559 case LFUN_TOC_INSERT:
1560 case LFUN_LINE_INSERT:
1561 case LFUN_NEWPAGE_INSERT:
1563 doInsertInset(cur, this, cmd, false, false);
1567 case LFUN_DEPTH_DECREMENT:
1568 changeDepth(cur, DEC_DEPTH);
1571 case LFUN_DEPTH_INCREMENT:
1572 changeDepth(cur, INC_DEPTH);
1575 case LFUN_MATH_DISPLAY:
1576 mathDispatch(cur, cmd, true);
1579 case LFUN_REGEXP_MODE:
1580 regexpDispatch(cur, cmd);
1583 case LFUN_MATH_MODE:
1584 if (cmd.argument() == "on")
1585 // don't pass "on" as argument
1586 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1588 mathDispatch(cur, cmd, false);
1591 case LFUN_MATH_MACRO:
1592 if (cmd.argument().empty())
1593 cur.errorMessage(from_utf8(N_("Missing argument")));
1595 string s = to_utf8(cmd.argument());
1596 string const s1 = token(s, ' ', 1);
1597 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1598 string const s2 = token(s, ' ', 2);
1599 MacroType type = MacroTypeNewcommand;
1601 type = MacroTypeDef;
1602 MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
1603 inset->setBuffer(bv->buffer());
1604 insertInset(cur, inset);
1606 // enter macro inset and select the name
1608 cur.top().pos() = cur.top().lastpos();
1610 cur.setSelection(true);
1611 cur.top().pos() = 0;
1615 // passthrough hat and underscore outside mathed:
1616 case LFUN_MATH_SUBSCRIPT:
1617 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1619 case LFUN_MATH_SUPERSCRIPT:
1620 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1623 case LFUN_MATH_INSERT:
1624 case LFUN_MATH_MATRIX:
1625 case LFUN_MATH_DELIM:
1626 case LFUN_MATH_BIGDELIM: {
1628 cap::replaceSelection(cur);
1629 cur.insert(new InsetMathHull(hullSimple));
1630 checkAndActivateInset(cur, true);
1631 LASSERT(cur.inMathed(), /**/);
1636 case LFUN_FONT_EMPH: {
1637 Font font(ignore_font, ignore_language);
1638 font.fontInfo().setEmph(FONT_TOGGLE);
1639 toggleAndShow(cur, this, font);
1643 case LFUN_FONT_ITAL: {
1644 Font font(ignore_font, ignore_language);
1645 font.fontInfo().setShape(ITALIC_SHAPE);
1646 toggleAndShow(cur, this, font);
1650 case LFUN_FONT_BOLD:
1651 case LFUN_FONT_BOLDSYMBOL: {
1652 Font font(ignore_font, ignore_language);
1653 font.fontInfo().setSeries(BOLD_SERIES);
1654 toggleAndShow(cur, this, font);
1658 case LFUN_FONT_NOUN: {
1659 Font font(ignore_font, ignore_language);
1660 font.fontInfo().setNoun(FONT_TOGGLE);
1661 toggleAndShow(cur, this, font);
1665 case LFUN_FONT_TYPEWRITER: {
1666 Font font(ignore_font, ignore_language);
1667 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1668 toggleAndShow(cur, this, font);
1672 case LFUN_FONT_SANS: {
1673 Font font(ignore_font, ignore_language);
1674 font.fontInfo().setFamily(SANS_FAMILY);
1675 toggleAndShow(cur, this, font);
1679 case LFUN_FONT_ROMAN: {
1680 Font font(ignore_font, ignore_language);
1681 font.fontInfo().setFamily(ROMAN_FAMILY);
1682 toggleAndShow(cur, this, font);
1686 case LFUN_FONT_DEFAULT: {
1687 Font font(inherit_font, ignore_language);
1688 toggleAndShow(cur, this, font);
1692 case LFUN_FONT_UNDERLINE: {
1693 Font font(ignore_font, ignore_language);
1694 font.fontInfo().setUnderbar(FONT_TOGGLE);
1695 toggleAndShow(cur, this, font);
1699 case LFUN_FONT_SIZE: {
1700 Font font(ignore_font, ignore_language);
1701 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1702 toggleAndShow(cur, this, font);
1706 case LFUN_LANGUAGE: {
1707 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1710 Font font(ignore_font, lang);
1711 toggleAndShow(cur, this, font);
1715 case LFUN_TEXTSTYLE_APPLY:
1716 toggleAndShow(cur, this, freefont, toggleall);
1717 cur.message(_("Character set"));
1720 // Set the freefont using the contents of \param data dispatched from
1721 // the frontends and apply it at the current cursor location.
1722 case LFUN_TEXTSTYLE_UPDATE: {
1725 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1728 toggleAndShow(cur, this, freefont, toggleall);
1729 cur.message(_("Character set"));
1731 lyxerr << "Argument not ok";
1736 case LFUN_FINISHED_LEFT:
1737 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1738 // We're leaving an inset, going left. If the inset is LTR, we're
1739 // leaving from the front, so we should not move (remain at --- but
1740 // not in --- the inset). If the inset is RTL, move left, without
1741 // entering the inset itself; i.e., move to after the inset.
1742 if (cur.paragraph().getFontSettings(
1743 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1744 cursorVisLeft(cur, true);
1747 case LFUN_FINISHED_RIGHT:
1748 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1749 // We're leaving an inset, going right. If the inset is RTL, we're
1750 // leaving from the front, so we should not move (remain at --- but
1751 // not in --- the inset). If the inset is LTR, move right, without
1752 // entering the inset itself; i.e., move to after the inset.
1753 if (!cur.paragraph().getFontSettings(
1754 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1755 cursorVisRight(cur, true);
1758 case LFUN_FINISHED_BACKWARD:
1759 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1762 case LFUN_FINISHED_FORWARD:
1763 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1765 cur.setCurrentFont();
1768 case LFUN_LAYOUT_PARAGRAPH: {
1770 params2string(cur.paragraph(), data);
1771 data = "show\n" + data;
1772 bv->showDialog("paragraph", data);
1776 case LFUN_PARAGRAPH_UPDATE: {
1778 params2string(cur.paragraph(), data);
1780 // Will the paragraph accept changes from the dialog?
1782 cur.inset().allowParagraphCustomization(cur.idx());
1784 data = "update " + convert<string>(accept) + '\n' + data;
1785 bv->updateDialog("paragraph", data);
1789 case LFUN_ACCENT_UMLAUT:
1790 case LFUN_ACCENT_CIRCUMFLEX:
1791 case LFUN_ACCENT_GRAVE:
1792 case LFUN_ACCENT_ACUTE:
1793 case LFUN_ACCENT_TILDE:
1794 case LFUN_ACCENT_CEDILLA:
1795 case LFUN_ACCENT_MACRON:
1796 case LFUN_ACCENT_DOT:
1797 case LFUN_ACCENT_UNDERDOT:
1798 case LFUN_ACCENT_UNDERBAR:
1799 case LFUN_ACCENT_CARON:
1800 case LFUN_ACCENT_BREVE:
1801 case LFUN_ACCENT_TIE:
1802 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1803 case LFUN_ACCENT_CIRCLE:
1804 case LFUN_ACCENT_OGONEK:
1805 theLyXFunc().handleKeyFunc(cmd.action);
1806 if (!cmd.argument().empty())
1807 // FIXME: Are all these characters encoded in one byte in utf8?
1808 bv->translateAndInsert(cmd.argument()[0], this, cur);
1811 case LFUN_FLOAT_LIST_INSERT: {
1812 DocumentClass const & tclass = bv->buffer().params().documentClass();
1813 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1815 if (cur.selection())
1816 cutSelection(cur, true, false);
1817 breakParagraph(cur);
1819 if (cur.lastpos() != 0) {
1820 cursorBackward(cur);
1821 breakParagraph(cur);
1824 docstring const laystr = cur.inset().usePlainLayout() ?
1825 tclass.plainLayoutName() :
1826 tclass.defaultLayoutName();
1827 setLayout(cur, laystr);
1828 ParagraphParameters p;
1829 // FIXME If this call were replaced with one to clearParagraphParams(),
1830 // then we could get rid of this method altogether.
1831 setParagraphs(cur, p);
1832 // FIXME This should be simplified when InsetFloatList takes a
1833 // Buffer in its constructor.
1834 InsetFloatList * ifl = new InsetFloatList(to_utf8(cmd.argument()));
1835 ifl->setBuffer(bv->buffer());
1836 insertInset(cur, ifl);
1839 lyxerr << "Non-existent float type: "
1840 << to_utf8(cmd.argument()) << endl;
1845 case LFUN_CHANGE_ACCEPT: {
1846 acceptOrRejectChanges(cur, ACCEPT);
1850 case LFUN_CHANGE_REJECT: {
1851 acceptOrRejectChanges(cur, REJECT);
1855 case LFUN_THESAURUS_ENTRY: {
1856 docstring arg = cmd.argument();
1858 arg = cur.selectionAsString(false);
1860 if (arg.size() > 100 || arg.empty()) {
1861 // Get word or selection
1862 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1863 arg = cur.selectionAsString(false);
1864 arg += " lang=" + from_ascii(cur.getFont().language()->lang());
1867 bv->showDialog("thesaurus", to_utf8(arg));
1871 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1872 // Given data, an encoding of the ParagraphParameters
1873 // generated in the Paragraph dialog, this function sets
1874 // the current paragraph, or currently selected paragraphs,
1876 // NOTE: This function overrides all existing settings.
1877 setParagraphs(cur, cmd.argument());
1878 cur.message(_("Paragraph layout set"));
1882 case LFUN_PARAGRAPH_PARAMS: {
1883 // Given data, an encoding of the ParagraphParameters as we'd
1884 // find them in a LyX file, this function modifies the current paragraph,
1885 // or currently selected paragraphs.
1886 // NOTE: This function only modifies, and does not override, existing
1888 setParagraphs(cur, cmd.argument(), true);
1889 cur.message(_("Paragraph layout set"));
1894 if (cur.selection()) {
1895 cur.setSelection(false);
1898 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1899 // correct, but I'm not 100% sure -- dov, 071019
1900 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1904 case LFUN_OUTLINE_UP:
1905 outline(OutlineUp, cur);
1906 setCursor(cur, cur.pit(), 0);
1907 cur.buffer()->updateLabels();
1911 case LFUN_OUTLINE_DOWN:
1912 outline(OutlineDown, cur);
1913 setCursor(cur, cur.pit(), 0);
1914 cur.buffer()->updateLabels();
1918 case LFUN_OUTLINE_IN:
1919 outline(OutlineIn, cur);
1920 cur.buffer()->updateLabels();
1924 case LFUN_OUTLINE_OUT:
1925 outline(OutlineOut, cur);
1926 cur.buffer()->updateLabels();
1931 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1936 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1938 // FIXME: The cursor flag is reset two lines below
1939 // so we need to check here if some of the LFUN did touch that.
1940 // for now only Text::erase() and Text::backspace() do that.
1941 // The plan is to verify all the LFUNs and then to remove this
1942 // singleParUpdate boolean altogether.
1943 if (cur.result().update() & Update::Force) {
1944 singleParUpdate = false;
1948 // FIXME: the following code should go in favor of fine grained
1949 // update flag treatment.
1950 if (singleParUpdate) {
1951 // Inserting characters does not change par height in general. So, try
1952 // to update _only_ this paragraph. BufferView will detect if a full
1953 // metrics update is needed anyway.
1954 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1959 && &oldTopSlice.inset() == &cur.inset()
1960 && oldTopSlice.idx() == cur.idx()
1961 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1962 && !cur.selection())
1963 // FIXME: it would be better if we could just do this
1965 //if (cur.result().update() != Update::FitCursor)
1968 // But some LFUNs do not set Update::FitCursor when needed, so we
1969 // do it for all. This is not very harmfull as FitCursor will provoke
1970 // a full redraw only if needed but still, a proper review of all LFUN
1971 // should be done and this needsUpdate boolean can then be removed.
1972 cur.updateFlags(Update::FitCursor);
1974 cur.updateFlags(Update::Force | Update::FitCursor);
1978 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1979 FuncStatus & flag) const
1981 LASSERT(cur.text() == this, /**/);
1983 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
1985 InsetCode code = NO_CODE;
1987 switch (cmd.action) {
1989 case LFUN_DEPTH_DECREMENT:
1990 enable = changeDepthAllowed(cur, DEC_DEPTH);
1993 case LFUN_DEPTH_INCREMENT:
1994 enable = changeDepthAllowed(cur, INC_DEPTH);
1998 flag.setOnOff(cur.paragraph().params().startOfAppendix());
2001 case LFUN_DIALOG_SHOW_NEW_INSET:
2002 if (cmd.argument() == "bibitem")
2003 code = BIBITEM_CODE;
2004 else if (cmd.argument() == "bibtex")
2006 else if (cmd.argument() == "box")
2008 else if (cmd.argument() == "branch")
2010 else if (cmd.argument() == "citation")
2012 else if (cmd.argument() == "ert")
2014 else if (cmd.argument() == "external")
2015 code = EXTERNAL_CODE;
2016 else if (cmd.argument() == "float")
2018 else if (cmd.argument() == "graphics")
2019 code = GRAPHICS_CODE;
2020 else if (cmd.argument() == "href")
2021 code = HYPERLINK_CODE;
2022 else if (cmd.argument() == "include")
2023 code = INCLUDE_CODE;
2024 else if (cmd.argument() == "index")
2026 else if (cmd.argument() == "index_print")
2027 code = INDEX_PRINT_CODE;
2028 else if (cmd.argument() == "nomenclature")
2029 code = NOMENCL_CODE;
2030 else if (cmd.argument() == "label")
2032 else if (cmd.argument() == "note")
2034 else if (cmd.argument() == "phantom")
2035 code = PHANTOM_CODE;
2036 else if (cmd.argument() == "ref")
2038 else if (cmd.argument() == "space")
2040 else if (cmd.argument() == "toc")
2042 else if (cmd.argument() == "vspace")
2044 else if (cmd.argument() == "wrap")
2046 else if (cmd.argument() == "listings")
2047 code = LISTINGS_CODE;
2050 case LFUN_ERT_INSERT:
2053 case LFUN_LISTING_INSERT:
2054 code = LISTINGS_CODE;
2055 // not allowed in description items
2056 enable = !inDescriptionItem(cur);
2058 case LFUN_FOOTNOTE_INSERT:
2061 case LFUN_TABULAR_INSERT:
2062 code = TABULAR_CODE;
2064 case LFUN_MARGINALNOTE_INSERT:
2067 case LFUN_FLOAT_INSERT:
2068 case LFUN_FLOAT_WIDE_INSERT:
2070 // not allowed in description items
2071 enable = !inDescriptionItem(cur);
2073 case LFUN_WRAP_INSERT:
2075 // not allowed in description items
2076 enable = !inDescriptionItem(cur);
2078 case LFUN_FLOAT_LIST_INSERT:
2079 code = FLOAT_LIST_CODE;
2081 case LFUN_CAPTION_INSERT:
2082 code = CAPTION_CODE;
2083 // not allowed in description items
2084 enable = !inDescriptionItem(cur);
2086 case LFUN_NOTE_INSERT:
2088 // in commands (sections etc.) and description items,
2089 // only Notes are allowed
2090 enable = (cmd.argument().empty() || cmd.getArg(0) == "Note" ||
2091 (!cur.paragraph().layout().isCommand()
2092 && !inDescriptionItem(cur)));
2094 case LFUN_FLEX_INSERT: {
2096 string s = cmd.getArg(0);
2098 cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
2099 if (il.lyxtype() != InsetLayout::CHARSTYLE &&
2100 il.lyxtype() != InsetLayout::CUSTOM &&
2101 il.lyxtype() != InsetLayout::ELEMENT &&
2102 il.lyxtype ()!= InsetLayout::STANDARD)
2106 case LFUN_BOX_INSERT:
2109 case LFUN_BRANCH_INSERT:
2111 if (cur.buffer()->masterBuffer()->params().branchlist().empty())
2114 case LFUN_PHANTOM_INSERT:
2115 code = PHANTOM_CODE;
2117 case LFUN_LABEL_INSERT:
2120 case LFUN_INFO_INSERT:
2123 case LFUN_OPTIONAL_INSERT:
2125 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2126 < cur.paragraph().layout().optionalargs;
2128 case LFUN_INDEX_INSERT:
2131 case LFUN_INDEX_PRINT:
2132 code = INDEX_PRINT_CODE;
2134 case LFUN_NOMENCL_INSERT:
2135 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2139 code = NOMENCL_CODE;
2141 case LFUN_NOMENCL_PRINT:
2142 code = NOMENCL_PRINT_CODE;
2144 case LFUN_TOC_INSERT:
2147 case LFUN_HYPERLINK_INSERT:
2148 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
2152 code = HYPERLINK_CODE;
2154 case LFUN_QUOTE_INSERT:
2155 // always allow this, since we will inset a raw quote
2156 // if an inset is not allowed.
2158 case LFUN_SPECIALCHAR_INSERT:
2159 code = SPECIALCHAR_CODE;
2161 case LFUN_SPACE_INSERT:
2162 // slight hack: we know this is allowed in math mode
2167 case LFUN_INSET_MODIFY:
2168 // We need to disable this, because we may get called for a
2170 // InsetTabular::getStatus() -> InsetText::getStatus()
2171 // and we don't handle LFUN_INSET_MODIFY.
2175 case LFUN_FONT_EMPH:
2176 flag.setOnOff(fontinfo.emph() == FONT_ON);
2179 case LFUN_FONT_ITAL:
2180 flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
2183 case LFUN_FONT_NOUN:
2184 flag.setOnOff(fontinfo.noun() == FONT_ON);
2187 case LFUN_FONT_BOLD:
2188 case LFUN_FONT_BOLDSYMBOL:
2189 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2192 case LFUN_FONT_SANS:
2193 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2196 case LFUN_FONT_ROMAN:
2197 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2200 case LFUN_FONT_TYPEWRITER:
2201 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2206 enable = cur.selection();
2210 if (cmd.argument().empty()) {
2211 if (theClipboard().isInternal())
2212 enable = cap::numberOfSelections() > 0;
2214 enable = !theClipboard().empty();
2218 // we have an argument
2219 string const arg = to_utf8(cmd.argument());
2220 if (isStrUnsignedInt(arg)) {
2221 // it's a number and therefore means the internal stack
2222 unsigned int n = convert<unsigned int>(arg);
2223 enable = cap::numberOfSelections() > n;
2227 // explicit graphics type?
2228 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
2229 if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
2230 || (arg == "png" && (type = Clipboard::PngGraphicsType))
2231 || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
2232 || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
2233 || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
2234 || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
2235 enable = theClipboard().hasGraphicsContents(type);
2244 case LFUN_CLIPBOARD_PASTE:
2245 enable = !theClipboard().empty();
2248 case LFUN_PRIMARY_SELECTION_PASTE:
2249 enable = cur.selection() || !theSelection().empty();
2252 case LFUN_SELECTION_PASTE:
2253 enable = cap::selection();
2256 case LFUN_PARAGRAPH_MOVE_UP:
2257 enable = cur.pit() > 0 && !cur.selection();
2260 case LFUN_PARAGRAPH_MOVE_DOWN:
2261 enable = cur.pit() < cur.lastpit() && !cur.selection();
2264 case LFUN_INSET_DISSOLVE:
2265 if (!cmd.argument().empty()) {
2266 InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
2267 InsetLayout::InsetLyXType const type =
2268 translateLyXType(to_utf8(cmd.argument()));
2269 enable = cur.inset().lyxCode() == FLEX_CODE
2270 && il.lyxtype() == type;
2272 enable = ((!isMainText(cur.bv().buffer())
2273 && cur.inset().nargs() == 1)
2275 && cur.nextInset()->nargs() == 1));
2279 case LFUN_CHANGE_ACCEPT:
2280 case LFUN_CHANGE_REJECT:
2281 // In principle, these LFUNs should only be enabled if there
2282 // is a change at the current position/in the current selection.
2283 // However, without proper optimizations, this will inevitably
2284 // result in unacceptable performance - just imagine a user who
2285 // wants to select the complete content of a long document.
2286 if (!cur.selection()) {
2287 Change const & change = cur.paragraph().lookupChange(cur.pos());
2288 enable = change.changed();
2290 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2295 case LFUN_OUTLINE_UP:
2296 case LFUN_OUTLINE_DOWN:
2297 case LFUN_OUTLINE_IN:
2298 case LFUN_OUTLINE_OUT:
2299 // FIXME: LyX is not ready for outlining within inset.
2300 enable = isMainText(cur.bv().buffer())
2301 && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
2304 case LFUN_NEWLINE_INSERT:
2305 // LaTeX restrictions (labels or empty par)
2306 enable = (cur.pos() > cur.paragraph().beginOfBody());
2309 case LFUN_SET_GRAPHICS_GROUP: {
2310 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
2314 flag.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
2318 case LFUN_NEWPAGE_INSERT:
2319 // not allowed in description items
2320 enable = !inDescriptionItem(cur);
2323 case LFUN_MATH_INSERT:
2324 case LFUN_MATH_MATRIX:
2325 case LFUN_MATH_DELIM:
2326 case LFUN_MATH_BIGDELIM:
2327 // not allowed in ERT, for example.
2328 enable = cur.inset().insetAllowed(MATH_CODE);
2331 case LFUN_DATE_INSERT: {
2332 string const format = cmd.argument().empty()
2333 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
2334 enable = support::os::is_valid_strftime(format);
2338 case LFUN_WORD_DELETE_FORWARD:
2339 case LFUN_WORD_DELETE_BACKWARD:
2340 case LFUN_LINE_DELETE:
2341 case LFUN_WORD_FORWARD:
2342 case LFUN_WORD_BACKWARD:
2343 case LFUN_WORD_RIGHT:
2344 case LFUN_WORD_LEFT:
2345 case LFUN_CHAR_FORWARD:
2346 case LFUN_CHAR_FORWARD_SELECT:
2347 case LFUN_CHAR_BACKWARD:
2348 case LFUN_CHAR_BACKWARD_SELECT:
2349 case LFUN_CHAR_LEFT:
2350 case LFUN_CHAR_LEFT_SELECT:
2351 case LFUN_CHAR_RIGHT:
2352 case LFUN_CHAR_RIGHT_SELECT:
2354 case LFUN_UP_SELECT:
2356 case LFUN_DOWN_SELECT:
2357 case LFUN_PARAGRAPH_UP_SELECT:
2358 case LFUN_PARAGRAPH_DOWN_SELECT:
2359 case LFUN_LINE_BEGIN_SELECT:
2360 case LFUN_LINE_END_SELECT:
2361 case LFUN_WORD_FORWARD_SELECT:
2362 case LFUN_WORD_BACKWARD_SELECT:
2363 case LFUN_WORD_RIGHT_SELECT:
2364 case LFUN_WORD_LEFT_SELECT:
2365 case LFUN_WORD_SELECT:
2366 case LFUN_PARAGRAPH_UP:
2367 case LFUN_PARAGRAPH_DOWN:
2368 case LFUN_LINE_BEGIN:
2370 case LFUN_CHAR_DELETE_FORWARD:
2371 case LFUN_CHAR_DELETE_BACKWARD:
2372 case LFUN_BREAK_PARAGRAPH:
2373 case LFUN_PARAGRAPH_SPACING:
2374 case LFUN_INSET_INSERT:
2375 case LFUN_WORD_UPCASE:
2376 case LFUN_WORD_LOWCASE:
2377 case LFUN_WORD_CAPITALIZE:
2378 case LFUN_CHARS_TRANSPOSE:
2379 case LFUN_SERVER_GET_XY:
2380 case LFUN_SERVER_SET_XY:
2381 case LFUN_SERVER_GET_LAYOUT:
2383 case LFUN_SELF_INSERT:
2384 case LFUN_LINE_INSERT:
2385 case LFUN_MATH_DISPLAY:
2386 case LFUN_MATH_MODE:
2387 case LFUN_MATH_MACRO:
2388 case LFUN_MATH_SUBSCRIPT:
2389 case LFUN_MATH_SUPERSCRIPT:
2390 case LFUN_FONT_DEFAULT:
2391 case LFUN_FONT_UNDERLINE:
2392 case LFUN_FONT_SIZE:
2394 case LFUN_TEXTSTYLE_APPLY:
2395 case LFUN_TEXTSTYLE_UPDATE:
2396 case LFUN_LAYOUT_PARAGRAPH:
2397 case LFUN_PARAGRAPH_UPDATE:
2398 case LFUN_ACCENT_UMLAUT:
2399 case LFUN_ACCENT_CIRCUMFLEX:
2400 case LFUN_ACCENT_GRAVE:
2401 case LFUN_ACCENT_ACUTE:
2402 case LFUN_ACCENT_TILDE:
2403 case LFUN_ACCENT_CEDILLA:
2404 case LFUN_ACCENT_MACRON:
2405 case LFUN_ACCENT_DOT:
2406 case LFUN_ACCENT_UNDERDOT:
2407 case LFUN_ACCENT_UNDERBAR:
2408 case LFUN_ACCENT_CARON:
2409 case LFUN_ACCENT_BREVE:
2410 case LFUN_ACCENT_TIE:
2411 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2412 case LFUN_ACCENT_CIRCLE:
2413 case LFUN_ACCENT_OGONEK:
2414 case LFUN_THESAURUS_ENTRY:
2415 case LFUN_PARAGRAPH_PARAMS_APPLY:
2416 case LFUN_PARAGRAPH_PARAMS:
2418 case LFUN_BUFFER_BEGIN:
2419 case LFUN_BUFFER_END:
2420 case LFUN_BUFFER_BEGIN_SELECT:
2421 case LFUN_BUFFER_END_SELECT:
2422 case LFUN_INSET_BEGIN:
2423 case LFUN_INSET_END:
2424 case LFUN_INSET_BEGIN_SELECT:
2425 case LFUN_INSET_END_SELECT:
2426 case LFUN_UNICODE_INSERT:
2427 // these are handled in our dispatch()
2436 && (cur.empty() || !cur.inset().insetAllowed(code)))
2439 flag.setEnabled(enable);
2444 void Text::pasteString(Cursor & cur, docstring const & clip,
2447 cur.clearSelection();
2448 if (!clip.empty()) {
2451 insertStringAsParagraphs(cur, clip);
2453 insertStringAsLines(cur, clip);
2458 // FIXME: an item inset would make things much easier.
2459 bool Text::inDescriptionItem(Cursor & cur) const
2461 Paragraph & par = cur.paragraph();
2462 pos_type const pos = cur.pos();
2463 pos_type const body_pos = par.beginOfBody();
2465 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
2466 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
2467 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
2470 return (pos < body_pos
2472 && (pos == 0 || par.getChar(pos - 1) != ' ')));