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"
29 #include "CutAndPaste.h"
30 #include "DispatchResult.h"
31 #include "ErrorList.h"
33 #include "FuncRequest.h"
34 #include "InsetList.h"
38 #include "LyXAction.h"
42 #include "Paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
45 #include "TextClass.h"
46 #include "TextMetrics.h"
49 #include "frontends/Clipboard.h"
50 #include "frontends/Selection.h"
52 #include "insets/InsetCollapsable.h"
53 #include "insets/InsetCommand.h"
54 #include "insets/InsetFloatList.h"
55 #include "insets/InsetNewline.h"
56 #include "insets/InsetQuotes.h"
57 #include "insets/InsetSpecialChar.h"
58 #include "insets/InsetText.h"
59 #include "insets/InsetInfo.h"
61 #include "support/convert.h"
62 #include "support/debug.h"
63 #include "support/gettext.h"
64 #include "support/lstrings.h"
65 #include "support/lyxtime.h"
67 #include "mathed/InsetMathHull.h"
68 #include "mathed/MathMacroTemplate.h"
70 #include <boost/next_prior.hpp>
76 using namespace lyx::support;
80 using cap::copySelection;
81 using cap::cutSelection;
82 using cap::pasteFromStack;
83 using cap::pasteClipboardText;
84 using cap::pasteClipboardGraphics;
85 using cap::replaceSelection;
88 static Font freefont(ignore_font, ignore_language);
89 static bool toggleall = false;
91 static void toggleAndShow(Cursor & cur, Text * text,
92 Font const & font, bool toggleall = true)
94 text->toggleFree(cur, font, toggleall);
96 if (font.language() != ignore_language ||
97 font.fontInfo().number() != FONT_IGNORE) {
98 TextMetrics const & tm = cur.bv().textMetrics(text);
99 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
100 cur.real_current_font))
101 text->setCursor(cur, cur.pit(), cur.pos(),
102 false, !cur.boundary());
107 static void moveCursor(Cursor & cur, bool selecting)
109 if (selecting || cur.mark())
114 static void finishChange(Cursor & cur, bool selecting)
117 moveCursor(cur, selecting);
121 static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
124 docstring sel = cur.selectionAsString(false);
126 // It may happen that sel is empty but there is a selection
127 replaceSelection(cur);
130 #ifdef ENABLE_ASSERTIONS
131 const int old_pos = cur.pos();
133 cur.insert(new InsetMathHull(hullSimple));
134 BOOST_ASSERT(old_pos == cur.pos());
135 cur.nextInset()->edit(cur, true);
136 // don't do that also for LFUN_MATH_MODE
137 // unless you want end up with always changing
138 // to mathrm when opening an inlined inset --
139 // I really hate "LyXfunc overloading"...
141 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
142 // Avoid an unnecessary undo step if cmd.argument
144 if (!cmd.argument().empty())
145 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
148 // create a macro if we see "\\newcommand"
149 // somewhere, and an ordinary formula
151 if (sel.find(from_ascii("\\newcommand")) == string::npos
152 && sel.find(from_ascii("\\newlyxcommand")) == string::npos
153 && sel.find(from_ascii("\\def")) == string::npos)
155 InsetMathHull * formula = new InsetMathHull;
156 istringstream is(to_utf8(sel));
160 if (formula->getType() == hullNone)
161 // Don't create pseudo formulas if
162 // delimiters are left out
163 formula->mutate(hullSimple);
166 cur.insert(new MathMacroTemplate(sel));
169 cur.message(from_utf8(N_("Math editor mode")));
173 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
176 cap::replaceSelection(cur);
177 cur.insert(new InsetSpecialChar(kind));
182 static bool doInsertInset(Cursor & cur, Text * text,
183 FuncRequest const & cmd, bool edit, bool pastesel)
185 Buffer & buffer = cur.bv().buffer();
186 BufferParams const & bparams = buffer.params();
187 Inset * inset = createInset(buffer, cmd);
191 if (InsetCollapsable * ci = inset->asInsetCollapsable())
192 ci->setLayout(bparams);
195 if (cmd.action == LFUN_INDEX_INSERT) {
196 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
197 text->insertInset(cur, inset);
199 inset->edit(cur, true);
200 // Now put this into inset
201 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
206 if (cur.selection()) {
207 lyx::dispatch(FuncRequest(LFUN_CUT));
210 text->insertInset(cur, inset);
213 inset->edit(cur, true);
215 if (!gotsel || !pastesel)
218 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
219 InsetText * insetText = dynamic_cast<InsetText *>(inset);
220 if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
221 // reset first par to default
222 cur.text()->paragraphs().begin()
223 ->setEmptyOrDefaultLayout(bparams.documentClass());
226 // Merge multiple paragraphs -- hack
227 while (cur.lastpit() > 0)
228 mergeParagraph(bparams, cur.text()->paragraphs(), 0);
230 // reset surrounding par to default
231 docstring const layoutname = insetText->useEmptyLayout()
232 ? bparams.documentClass().emptyLayoutName()
233 : bparams.documentClass().defaultLayoutName();
234 cur.leaveInset(*inset);
235 text->setLayout(cur, layoutname);
242 string const freefont2string()
244 return freefont.toString(toggleall);
248 /// the type of outline operation
250 OutlineUp, // Move this header with text down
251 OutlineDown, // Move this header with text up
252 OutlineIn, // Make this header deeper
253 OutlineOut // Make this header shallower
257 static void outline(OutlineOp mode, Cursor & cur)
259 Buffer & buf = cur.buffer();
260 pit_type & pit = cur.pit();
261 ParagraphList & pars = buf.text().paragraphs();
262 ParagraphList::iterator bgn = pars.begin();
263 // The first paragraph of the area to be copied:
264 ParagraphList::iterator start = boost::next(bgn, pit);
265 // The final paragraph of area to be copied:
266 ParagraphList::iterator finish = start;
267 ParagraphList::iterator end = pars.end();
269 DocumentClass const & tc = buf.params().documentClass();
271 int const thistoclevel = start->layout().toclevel;
274 // Move out (down) from this section header
277 // Seek the one (on same level) below
278 for (; finish != end; ++finish) {
279 toclevel = finish->layout().toclevel;
280 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) {
287 ParagraphList::iterator dest = start;
288 // Move out (up) from this header
291 // Search previous same-level header above
294 toclevel = dest->layout().toclevel;
296 && (toclevel == Layout::NOT_IN_TOC
297 || toclevel > thistoclevel));
298 // Not found; do nothing
299 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
301 pit_type const newpit = distance(bgn, dest);
302 pit_type const len = distance(start, finish);
303 pit_type const deletepit = pit + len;
304 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
305 pars.insert(dest, start, finish);
306 start = boost::next(pars.begin(), deletepit);
308 pars.erase(start, finish);
312 ParagraphList::iterator dest = finish;
313 // One such was found:
314 pit_type newpit = distance(bgn, dest);
315 pit_type const len = distance(start, finish);
316 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
317 pars.insert(dest, start, finish);
318 start = boost::next(bgn, pit);
320 pars.erase(start, finish);
324 pit_type const len = distance(start, finish);
325 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
326 for (; start != finish; ++start) {
327 toclevel = start->layout().toclevel;
328 if (toclevel == Layout::NOT_IN_TOC)
330 DocumentClass::const_iterator lit = tc.begin();
331 DocumentClass::const_iterator len = tc.end();
332 for (; lit != len; ++lit) {
333 if (lit->toclevel == toclevel + 1 &&
334 start->layout().labeltype == lit->labeltype) {
335 start->setLayout(*lit);
343 pit_type const len = distance(start, finish);
344 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
345 for (; start != finish; ++start) {
346 toclevel = start->layout().toclevel;
347 if (toclevel == Layout::NOT_IN_TOC)
349 DocumentClass::const_iterator lit = tc.begin();
350 DocumentClass::const_iterator len = tc.end();
351 for (; lit != len; ++lit) {
352 if (lit->toclevel == toclevel - 1 &&
353 start->layout().labeltype == lit->labeltype) {
354 start->setLayout(*lit);
365 void Text::number(Cursor & cur)
367 FontInfo font = ignore_font;
368 font.setNumber(FONT_TOGGLE);
369 toggleAndShow(cur, this, Font(font, ignore_language));
373 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
375 return par.isRTL(buffer.params());
379 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
381 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
383 BufferView * bv = &cur.bv();
384 TextMetrics & tm = bv->textMetrics(this);
385 if (!tm.contains(cur.pit()))
386 lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
388 // FIXME: We use the update flag to indicates wether a singlePar or a
389 // full screen update is needed. We reset it here but shall we restore it
393 BOOST_ASSERT(cur.text() == this);
394 CursorSlice oldTopSlice = cur.top();
395 bool oldBoundary = cur.boundary();
396 bool sel = cur.selection();
397 // Signals that, even if needsUpdate == false, an update of the
398 // cursor paragraph is required
399 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
400 LyXAction::SingleParUpdate);
401 // Signals that a full-screen update is required
402 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
403 LyXAction::NoUpdate) || singleParUpdate);
405 switch (cmd.action) {
407 case LFUN_PARAGRAPH_MOVE_DOWN: {
408 pit_type const pit = cur.pit();
409 recUndo(cur, pit, pit + 1);
411 swap(pars_[pit], pars_[pit + 1]);
412 updateLabels(cur.buffer());
418 case LFUN_PARAGRAPH_MOVE_UP: {
419 pit_type const pit = cur.pit();
420 recUndo(cur, pit - 1, pit);
422 swap(pars_[pit], pars_[pit - 1]);
423 updateLabels(cur.buffer());
429 case LFUN_APPENDIX: {
430 Paragraph & par = cur.paragraph();
431 bool start = !par.params().startOfAppendix();
433 // FIXME: The code below only makes sense at top level.
434 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
435 // ensure that we have only one start_of_appendix in this document
436 // FIXME: this don't work for multipart document!
437 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
438 if (pars_[tmp].params().startOfAppendix()) {
440 pars_[tmp].params().startOfAppendix(false);
446 par.params().startOfAppendix(start);
448 // we can set the refreshing parameters now
449 updateLabels(cur.buffer());
453 case LFUN_WORD_DELETE_FORWARD:
454 if (cur.selection()) {
455 cutSelection(cur, true, false);
457 deleteWordForward(cur);
458 finishChange(cur, false);
461 case LFUN_WORD_DELETE_BACKWARD:
462 if (cur.selection()) {
463 cutSelection(cur, true, false);
465 deleteWordBackward(cur);
466 finishChange(cur, false);
469 case LFUN_LINE_DELETE:
470 if (cur.selection()) {
471 cutSelection(cur, true, false);
473 tm.deleteLineForward(cur);
474 finishChange(cur, false);
477 case LFUN_BUFFER_BEGIN:
478 case LFUN_BUFFER_BEGIN_SELECT:
479 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
480 if (cur.depth() == 1) {
481 needsUpdate |= cursorTop(cur);
485 cur.updateFlags(Update::FitCursor);
488 case LFUN_BUFFER_END:
489 case LFUN_BUFFER_END_SELECT:
490 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
491 if (cur.depth() == 1) {
492 needsUpdate |= cursorBottom(cur);
496 cur.updateFlags(Update::FitCursor);
499 case LFUN_CHAR_FORWARD:
500 case LFUN_CHAR_FORWARD_SELECT:
501 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
502 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
503 needsUpdate |= cursorForward(cur);
505 if (!needsUpdate && oldTopSlice == cur.top()
506 && cur.boundary() == oldBoundary) {
508 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
512 case LFUN_CHAR_BACKWARD:
513 case LFUN_CHAR_BACKWARD_SELECT:
514 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
515 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
516 needsUpdate |= cursorBackward(cur);
518 if (!needsUpdate && oldTopSlice == cur.top()
519 && cur.boundary() == oldBoundary) {
521 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
526 case LFUN_CHAR_LEFT_SELECT:
527 if (lyxrc.visual_cursor) {
528 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
529 needsUpdate |= cursorVisLeft(cur);
530 if (!needsUpdate && oldTopSlice == cur.top()
531 && cur.boundary() == oldBoundary) {
533 cmd = FuncRequest(LFUN_FINISHED_LEFT);
536 if (reverseDirectionNeeded(cur)) {
537 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
538 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
540 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
541 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
548 case LFUN_CHAR_RIGHT:
549 case LFUN_CHAR_RIGHT_SELECT:
550 if (lyxrc.visual_cursor) {
551 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
552 needsUpdate |= cursorVisRight(cur);
553 if (!needsUpdate && oldTopSlice == cur.top()
554 && cur.boundary() == oldBoundary) {
556 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
559 if (reverseDirectionNeeded(cur)) {
560 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
561 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
563 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
564 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
573 case LFUN_DOWN_SELECT:
576 // stop/start the selection
577 bool select = cmd.action == LFUN_DOWN_SELECT ||
578 cmd.action == LFUN_UP_SELECT;
579 cur.selHandle(select);
581 // move cursor up/down
582 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
583 bool const successful = cur.upDownInText(up, needsUpdate);
585 // redraw if you leave mathed (for the decorations)
586 needsUpdate |= cur.beforeDispatchCursor().inMathed();
593 case LFUN_PARAGRAPH_UP:
594 case LFUN_PARAGRAPH_UP_SELECT:
595 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
596 needsUpdate |= cursorUpParagraph(cur);
599 case LFUN_PARAGRAPH_DOWN:
600 case LFUN_PARAGRAPH_DOWN_SELECT:
601 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
602 needsUpdate |= cursorDownParagraph(cur);
605 case LFUN_LINE_BEGIN:
606 case LFUN_LINE_BEGIN_SELECT:
607 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
608 needsUpdate |= tm.cursorHome(cur);
612 case LFUN_LINE_END_SELECT:
613 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
614 needsUpdate |= tm.cursorEnd(cur);
617 case LFUN_WORD_RIGHT:
618 case LFUN_WORD_RIGHT_SELECT:
619 //FIXME: for visual cursor mode, really move right
620 if (reverseDirectionNeeded(cur)) {
621 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
622 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
624 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
625 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
630 case LFUN_WORD_FORWARD:
631 case LFUN_WORD_FORWARD_SELECT:
632 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
633 needsUpdate |= cursorForwardOneWord(cur);
637 case LFUN_WORD_LEFT_SELECT:
638 //FIXME: for visual cursor mode, really move left
639 if (reverseDirectionNeeded(cur)) {
640 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
641 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
643 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
644 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
649 case LFUN_WORD_BACKWARD:
650 case LFUN_WORD_BACKWARD_SELECT:
651 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
652 needsUpdate |= cursorBackwardOneWord(cur);
655 case LFUN_WORD_SELECT: {
656 selectWord(cur, WHOLE_WORD);
657 finishChange(cur, true);
661 case LFUN_NEW_LINE: {
662 // Not allowed by LaTeX (labels or empty par)
663 if (cur.pos() > cur.paragraph().beginOfBody()) {
664 // this avoids a double undo
665 // FIXME: should not be needed, ideally
666 if (!cur.selection())
668 cap::replaceSelection(cur);
669 cur.insert(new InsetNewline);
671 moveCursor(cur, false);
676 case LFUN_LINE_BREAK: {
677 // Not allowed by LaTeX (labels or empty par)
678 if (cur.pos() > cur.paragraph().beginOfBody()) {
679 // this avoids a double undo
680 // FIXME: should not be needed, ideally
681 if (!cur.selection())
683 cap::replaceSelection(cur);
684 cur.insert(new InsetLinebreak);
686 moveCursor(cur, false);
691 case LFUN_CHAR_DELETE_FORWARD:
692 if (!cur.selection()) {
693 if (cur.pos() == cur.paragraph().size())
694 // Par boundary, force full-screen update
695 singleParUpdate = false;
696 needsUpdate |= erase(cur);
698 // It is possible to make it a lot faster still
699 // just comment out the line below...
701 cutSelection(cur, true, false);
702 singleParUpdate = false;
704 moveCursor(cur, false);
707 case LFUN_DELETE_FORWARD_SKIP:
708 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
709 if (!cur.selection()) {
710 if (cur.pos() == cur.lastpos()) {
717 cutSelection(cur, true, false);
722 case LFUN_CHAR_DELETE_BACKWARD:
723 if (!cur.selection()) {
724 if (bv->getIntl().getTransManager().backspace()) {
725 // Par boundary, full-screen update
727 singleParUpdate = false;
728 needsUpdate |= backspace(cur);
730 // It is possible to make it a lot faster still
731 // just comment out the line below...
734 cutSelection(cur, true, false);
735 singleParUpdate = false;
739 case LFUN_DELETE_BACKWARD_SKIP:
740 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
741 if (!cur.selection()) {
743 //CursorSlice cur = cursor();
747 cutSelection(cur, true, false);
751 case LFUN_BREAK_PARAGRAPH:
752 cap::replaceSelection(cur);
753 breakParagraph(cur, cmd.argument() == "inverse");
757 case LFUN_BREAK_PARAGRAPH_SKIP: {
758 // When at the beginning of a paragraph, remove
759 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
760 cap::replaceSelection(cur);
762 cur.paragraph().params().labelWidthString(docstring());
764 breakParagraph(cur, false);
770 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
771 // as its duties can be performed there. Should it be removed??
772 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
773 case LFUN_PARAGRAPH_SPACING: {
774 Paragraph & par = cur.paragraph();
775 Spacing::Space cur_spacing = par.params().spacing().getSpace();
776 string cur_value = "1.0";
777 if (cur_spacing == Spacing::Other)
778 cur_value = par.params().spacing().getValueAsString();
780 istringstream is(to_utf8(cmd.argument()));
783 Spacing::Space new_spacing = cur_spacing;
784 string new_value = cur_value;
786 lyxerr << "Missing argument to `paragraph-spacing'"
788 } else if (tmp == "single") {
789 new_spacing = Spacing::Single;
790 } else if (tmp == "onehalf") {
791 new_spacing = Spacing::Onehalf;
792 } else if (tmp == "double") {
793 new_spacing = Spacing::Double;
794 } else if (tmp == "other") {
795 new_spacing = Spacing::Other;
796 string tmpval = "0.0";
798 lyxerr << "new_value = " << tmpval << endl;
801 } else if (tmp == "default") {
802 new_spacing = Spacing::Default;
804 lyxerr << to_utf8(_("Unknown spacing argument: "))
805 << to_utf8(cmd.argument()) << endl;
807 if (cur_spacing != new_spacing || cur_value != new_value)
808 par.params().spacing(Spacing(new_spacing, new_value));
812 case LFUN_INSET_INSERT: {
814 Inset * inset = createInset(bv->buffer(), cmd);
816 // FIXME (Abdel 01/02/2006):
817 // What follows would be a partial fix for bug 2154:
818 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
819 // This automatically put the label inset _after_ a
820 // numbered section. It should be possible to extend the mechanism
821 // to any kind of LateX environement.
822 // The correct way to fix that bug would be at LateX generation.
823 // I'll let the code here for reference as it could be used for some
824 // other feature like "automatic labelling".
826 Paragraph & par = pars_[cur.pit()];
827 if (inset->lyxCode() == LABEL_CODE
828 && par.layout().labeltype == LABEL_COUNTER) {
829 // Go to the end of the paragraph
830 // Warning: Because of Change-Tracking, the last
831 // position is 'size()' and not 'size()-1':
832 cur.pos() = par.size();
833 // Insert a new paragraph
834 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
839 cutSelection(cur, true, false);
846 case LFUN_INSET_DISSOLVE:
847 needsUpdate |= dissolveInset(cur);
850 case LFUN_INSET_SETTINGS:
851 cur.inset().showInsetDialog(bv);
854 case LFUN_SPACE_INSERT:
855 if (cur.paragraph().layout().free_spacing)
856 insertChar(cur, ' ');
858 doInsertInset(cur, this, cmd, false, false);
861 moveCursor(cur, false);
864 case LFUN_SPECIALCHAR_INSERT: {
865 string const name = to_utf8(cmd.argument());
866 if (name == "hyphenation")
867 specialChar(cur, InsetSpecialChar::HYPHENATION);
868 else if (name == "ligature-break")
869 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
870 else if (name == "slash")
871 specialChar(cur, InsetSpecialChar::SLASH);
872 else if (name == "nobreakdash")
873 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
874 else if (name == "dots")
875 specialChar(cur, InsetSpecialChar::LDOTS);
876 else if (name == "end-of-sentence")
877 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
878 else if (name == "menu-separator")
879 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
880 else if (name.empty())
881 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
883 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
887 case LFUN_WORD_UPCASE:
888 changeCase(cur, text_uppercase);
891 case LFUN_WORD_LOWCASE:
892 changeCase(cur, text_lowercase);
895 case LFUN_WORD_CAPITALIZE:
896 changeCase(cur, text_capitalization);
899 case LFUN_CHARS_TRANSPOSE:
904 cur.message(_("Paste"));
905 cap::replaceSelection(cur);
908 string const arg = to_utf8(cmd.argument());
910 if (theClipboard().isInternal())
911 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
912 else if (theClipboard().hasGraphicsContents())
913 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
915 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
916 } else if (isStrUnsignedInt(arg)) {
917 // we have a numerical argument
918 pasteFromStack(cur, bv->buffer().errorList("Paste"),
919 convert<unsigned int>(arg));
921 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
923 type = Clipboard::PdfGraphicsType;
924 else if (arg == "png")
925 type = Clipboard::PngGraphicsType;
926 else if (arg == "jpeg")
927 type = Clipboard::JpegGraphicsType;
928 else if (arg == "linkback")
929 type = Clipboard::LinkBackGraphicsType;
933 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
936 bv->buffer().errors("Paste");
937 cur.clearSelection(); // bug 393
943 cutSelection(cur, true, true);
944 cur.message(_("Cut"));
949 cur.message(_("Copy"));
952 case LFUN_SERVER_GET_XY:
953 cur.message(from_utf8(
954 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
955 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
958 case LFUN_SERVER_SET_XY: {
961 istringstream is(to_utf8(cmd.argument()));
964 lyxerr << "SETXY: Could not parse coordinates in '"
965 << to_utf8(cmd.argument()) << endl;
967 tm.setCursorFromCoordinates(cur, x, y);
971 case LFUN_SERVER_GET_FONT:
972 if (cur.current_font.fontInfo().shape() == ITALIC_SHAPE)
973 cur.message(from_ascii("E"));
974 else if (cur.current_font.fontInfo().shape() == SMALLCAPS_SHAPE)
975 cur.message(from_ascii("N"));
977 cur.message(from_ascii("0"));
980 case LFUN_SERVER_GET_LAYOUT:
981 cur.message(cur.paragraph().layout().name());
985 docstring layout = cmd.argument();
986 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
988 Paragraph const & para = cur.paragraph();
989 docstring const old_layout = para.layout().name();
990 DocumentClass const & tclass = bv->buffer().params().documentClass();
993 layout = tclass.defaultLayoutName();
995 if (para.forceEmptyLayout())
996 // in this case only the empty layout is allowed
997 layout = tclass.emptyLayoutName();
998 else if (para.useEmptyLayout()) {
999 // in this case, default layout maps to empty layout
1000 if (layout == tclass.defaultLayoutName())
1001 layout = tclass.emptyLayoutName();
1003 // otherwise, the empty layout maps to the default
1004 if (layout == tclass.emptyLayoutName())
1005 layout = tclass.defaultLayoutName();
1008 bool hasLayout = tclass.hasLayout(layout);
1010 // If the entry is obsolete, use the new one instead.
1012 docstring const & obs = tclass[layout].obsoleted_by();
1018 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1019 from_utf8(N_(" not known")));
1023 bool change_layout = (old_layout != layout);
1025 if (!change_layout && cur.selection() &&
1026 cur.selBegin().pit() != cur.selEnd().pit())
1028 pit_type spit = cur.selBegin().pit();
1029 pit_type epit = cur.selEnd().pit() + 1;
1030 while (spit != epit) {
1031 if (pars_[spit].layout().name() != old_layout) {
1032 change_layout = true;
1040 setLayout(cur, layout);
1045 case LFUN_CLIPBOARD_PASTE:
1046 cur.clearSelection();
1047 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1048 cmd.argument() == "paragraph");
1049 bv->buffer().errors("Paste");
1052 case LFUN_PRIMARY_SELECTION_PASTE:
1053 pasteString(cur, theSelection().get(),
1054 cmd.argument() == "paragraph");
1057 case LFUN_UNICODE_INSERT: {
1058 if (cmd.argument().empty())
1060 docstring hexstring = cmd.argument();
1061 if (isHex(hexstring)) {
1062 char_type c = hexToInt(hexstring);
1063 if (c >= 32 && c < 0x10ffff) {
1064 lyxerr << "Inserting c: " << c << endl;
1065 docstring s = docstring(1, c);
1066 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1072 case LFUN_QUOTE_INSERT: {
1073 Paragraph & par = cur.paragraph();
1074 pos_type pos = cur.pos();
1075 BufferParams const & bufparams = bv->buffer().params();
1076 Layout const & style = par.layout();
1077 if (!style.pass_thru
1078 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1079 // this avoids a double undo
1080 // FIXME: should not be needed, ideally
1081 if (!cur.selection())
1083 cap::replaceSelection(cur);
1088 else if (cur.prevInset() && cur.prevInset()->isSpace())
1091 c = par.getChar(pos - 1);
1092 string arg = to_utf8(cmd.argument());
1093 cur.insert(new InsetQuotes(c, bufparams.quotes_language,
1094 (arg == "single") ? InsetQuotes::SingleQuotes
1095 : InsetQuotes::DoubleQuotes));
1099 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1103 case LFUN_DATE_INSERT: {
1104 string const format = cmd.argument().empty()
1105 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1106 string const time = formatted_time(current_time(), format);
1107 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1111 case LFUN_MOUSE_TRIPLE:
1112 if (cmd.button() == mouse_button::button1) {
1121 case LFUN_MOUSE_DOUBLE:
1122 if (cmd.button() == mouse_button::button1) {
1123 selectWord(cur, WHOLE_WORD_STRICT);
1128 // Single-click on work area
1129 case LFUN_MOUSE_PRESS: {
1130 // Right click on a footnote flag opens float menu
1131 // FIXME: Why should we clear the selection in this case?
1132 if (cmd.button() == mouse_button::button3)
1133 cur.clearSelection();
1135 bool do_selection = cmd.button() == mouse_button::button1
1136 && cmd.argument() == "region-select";
1138 bool update = bv->mouseSetCursor(cur, do_selection);
1140 // Insert primary selection with middle mouse
1141 // if there is a local selection in the current buffer,
1143 if (cmd.button() == mouse_button::button2) {
1144 if (cap::selection()) {
1145 // Copy the selection buffer to the clipboard
1146 // stack, because we want it to appear in the
1147 // "Edit->Paste recent" menu.
1148 cap::copySelectionToStack();
1150 cap::pasteSelection(bv->cursor(),
1151 bv->buffer().errorList("Paste"));
1152 bv->buffer().errors("Paste");
1153 bv->buffer().markDirty();
1154 bv->cursor().finishUndo();
1156 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1160 // we have to update after dEPM triggered
1161 if (!update && cmd.button() == mouse_button::button1) {
1162 needsUpdate = false;
1169 case LFUN_MOUSE_MOTION: {
1170 // Only use motion with button 1
1171 //if (cmd.button() != mouse_button::button1)
1174 // ignore motions deeper nested than the real anchor
1175 Cursor & bvcur = cur.bv().cursor();
1176 if (!bvcur.anchor_.hasPart(cur)) {
1180 CursorSlice old = bvcur.top();
1182 int const wh = bv->workHeight();
1183 int const y = max(0, min(wh - 1, cmd.y));
1185 tm.setCursorFromCoordinates(cur, cmd.x, y);
1186 cur.setTargetX(cmd.x);
1188 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1190 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1191 // This is to allow jumping over large insets
1192 if (cur.top() == old) {
1194 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1196 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1199 if (cur.top() == old)
1202 // FIXME: This is brute force! But without it the selected
1203 // area is not corrected updated while moving the mouse.
1204 cur.updateFlags(Update::Force | Update::FitCursor);
1205 // don't set anchor_
1206 bvcur.setCursor(cur);
1207 bvcur.selection() = true;
1208 //lyxerr << "MOTION: " << bv->cursor() << endl;
1213 case LFUN_MOUSE_RELEASE: {
1214 if (cmd.button() == mouse_button::button2)
1217 if (cmd.button() == mouse_button::button1) {
1218 // if there is new selection, update persistent
1219 // selection, otherwise, single click does not
1220 // clear persistent selection buffer
1221 if (cur.selection()) {
1223 // if double click, cur is moved to the end of word by selectWord
1224 // but bvcur is current mouse position
1225 Cursor & bvcur = cur.bv().cursor();
1226 bvcur.selection() = true;
1228 needsUpdate = false;
1235 case LFUN_SELF_INSERT: {
1236 if (cmd.argument().empty())
1239 // Automatically delete the currently selected
1240 // text and replace it with what is being
1241 // typed in now. Depends on lyxrc settings
1242 // "auto_region_delete", which defaults to
1245 if (lyxrc.auto_region_delete && cur.selection())
1246 cutSelection(cur, false, false);
1248 cur.clearSelection();
1249 Font const old_font = cur.real_current_font;
1251 docstring::const_iterator cit = cmd.argument().begin();
1252 docstring::const_iterator end = cmd.argument().end();
1253 for (; cit != end; ++cit)
1254 bv->translateAndInsert(*cit, this, cur);
1257 moveCursor(cur, false);
1261 case LFUN_HYPERLINK_INSERT: {
1262 InsetCommandParams p(HYPERLINK_CODE);
1264 if (cur.selection()) {
1265 content = cur.selectionAsString(false);
1266 cutSelection(cur, true, false);
1268 p["target"] = (cmd.argument().empty()) ?
1269 content : cmd.argument();
1270 string const data = InsetCommandMailer::params2string("href", p);
1271 if (p["target"].empty()) {
1272 bv->showDialog("href", data);
1274 FuncRequest fr(LFUN_INSET_INSERT, data);
1280 case LFUN_LABEL_INSERT: {
1281 InsetCommandParams p(LABEL_CODE);
1282 // Try to generate a valid label
1283 p["name"] = (cmd.argument().empty()) ?
1284 cur.getPossibleLabel() :
1286 string const data = InsetCommandMailer::params2string("label", p);
1288 if (cmd.argument().empty()) {
1289 bv->showDialog("label", data);
1291 FuncRequest fr(LFUN_INSET_INSERT, data);
1297 case LFUN_INFO_INSERT: {
1298 Inset * inset = createInset(cur.bv().buffer(), cmd);
1301 // if an empty inset is created (cmd.argument() is empty)
1302 // use current selection as parameter.
1303 if (cmd.argument().empty() && cur.selection()) {
1304 // use selected text as info to avoid a separate UI
1305 docstring ds = cur.selectionAsString(false);
1306 cutSelection(cur, true, false);
1307 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1308 static_cast<InsetInfo *>(inset)->updateInfo();
1310 insertInset(cur, inset);
1315 case LFUN_LIST_INSERT:
1317 case LFUN_CAPTION_INSERT:
1318 case LFUN_FOOTNOTE_INSERT:
1319 case LFUN_NOTE_INSERT:
1320 case LFUN_FLEX_INSERT:
1321 case LFUN_BOX_INSERT:
1322 case LFUN_BRANCH_INSERT:
1323 case LFUN_BIBITEM_INSERT:
1324 case LFUN_ERT_INSERT:
1325 case LFUN_LISTING_INSERT:
1326 case LFUN_MARGINALNOTE_INSERT:
1327 case LFUN_OPTIONAL_INSERT:
1328 case LFUN_ENVIRONMENT_INSERT:
1329 case LFUN_INDEX_INSERT:
1330 // Open the inset, and move the current selection
1332 doInsertInset(cur, this, cmd, true, true);
1334 // Some insets are numbered, others are shown in the outline pane so
1335 // let's update the labels and the toc backend.
1336 updateLabels(bv->buffer());
1339 case LFUN_TABULAR_INSERT:
1340 // if there were no arguments, just open the dialog
1341 if (doInsertInset(cur, this, cmd, false, true))
1344 bv->showDialog("tabularcreate");
1348 case LFUN_FLOAT_INSERT:
1349 case LFUN_FLOAT_WIDE_INSERT:
1350 case LFUN_WRAP_INSERT: {
1351 bool content = cur.selection(); // will some text be moved into the inset?
1353 doInsertInset(cur, this, cmd, true, true);
1355 ParagraphList & pars = cur.text()->paragraphs();
1357 DocumentClass const & tclass = bv->buffer().params().documentClass();
1359 // add a separate paragraph for the caption inset
1360 pars.push_back(Paragraph());
1361 pars.back().setInsetOwner(pars[0].inInset());
1362 pars.back().setEmptyOrDefaultLayout(tclass);
1363 int cap_pit = pars.size() - 1;
1365 // if an empty inset was created, we create an additional empty
1366 // paragraph at the bottom so that the user can choose where to put
1367 // the graphics (or table).
1369 pars.push_back(Paragraph());
1370 pars.back().setInsetOwner(pars[0].inInset());
1371 pars.back().setEmptyOrDefaultLayout(tclass);
1374 // reposition the cursor to the caption
1375 cur.pit() = cap_pit;
1377 // FIXME: This Text/Cursor dispatch handling is a mess!
1378 // We cannot use Cursor::dispatch here it needs access to up to
1380 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1381 cur.text()->dispatch(cur, cmd_caption);
1382 cur.updateFlags(Update::Force);
1383 // FIXME: When leaving the Float (or Wrap) inset we should
1384 // delete any empty paragraph left above or below the
1389 case LFUN_NOMENCL_INSERT: {
1390 FuncRequest cmd1 = cmd;
1391 if (cmd.argument().empty())
1392 cmd1 = FuncRequest(cmd,
1393 bv->cursor().innerText()->getStringToIndex(bv->cursor()));
1394 Inset * inset = createInset(cur.bv().buffer(), cmd1);
1398 cur.clearSelection();
1399 insertInset(cur, inset);
1400 // Show the dialog for the nomenclature entry, since the
1401 // description entry still needs to be filled in.
1402 if (cmd.action == LFUN_NOMENCL_INSERT)
1403 inset->edit(cur, true);
1408 case LFUN_INDEX_PRINT:
1409 case LFUN_NOMENCL_PRINT:
1410 case LFUN_TOC_INSERT:
1411 case LFUN_LINE_INSERT:
1412 case LFUN_NEWPAGE_INSERT:
1413 case LFUN_PAGEBREAK_INSERT:
1414 case LFUN_CLEARPAGE_INSERT:
1415 case LFUN_CLEARDOUBLEPAGE_INSERT:
1417 doInsertInset(cur, this, cmd, false, false);
1421 case LFUN_DEPTH_DECREMENT:
1422 changeDepth(cur, DEC_DEPTH);
1425 case LFUN_DEPTH_INCREMENT:
1426 changeDepth(cur, INC_DEPTH);
1429 case LFUN_MATH_DISPLAY:
1430 mathDispatch(cur, cmd, true);
1433 case LFUN_MATH_IMPORT_SELECTION:
1434 case LFUN_MATH_MODE:
1435 if (cmd.argument() == "on")
1436 // don't pass "on" as argument
1437 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1439 mathDispatch(cur, cmd, false);
1442 case LFUN_MATH_MACRO:
1443 if (cmd.argument().empty())
1444 cur.errorMessage(from_utf8(N_("Missing argument")));
1446 string s = to_utf8(cmd.argument());
1447 string const s1 = token(s, ' ', 1);
1448 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1449 string const s2 = token(s, ' ', 2);
1450 MacroType type = MacroTypeNewcommand;
1452 type = MacroTypeDef;
1453 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type));
1454 //cur.nextInset()->edit(cur, true);
1458 // passthrough hat and underscore outside mathed:
1459 case LFUN_MATH_SUBSCRIPT:
1460 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1462 case LFUN_MATH_SUPERSCRIPT:
1463 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1466 case LFUN_MATH_INSERT:
1467 case LFUN_MATH_MATRIX:
1468 case LFUN_MATH_DELIM:
1469 case LFUN_MATH_BIGDELIM: {
1470 cap::replaceSelection(cur);
1471 cur.insert(new InsetMathHull(hullSimple));
1472 checkAndActivateInset(cur, true);
1473 BOOST_ASSERT(cur.inMathed());
1478 case LFUN_FONT_EMPH: {
1479 Font font(ignore_font, ignore_language);
1480 font.fontInfo().setEmph(FONT_TOGGLE);
1481 toggleAndShow(cur, this, font);
1485 case LFUN_FONT_BOLD: {
1486 Font font(ignore_font, ignore_language);
1487 font.fontInfo().setSeries(BOLD_SERIES);
1488 toggleAndShow(cur, this, font);
1492 case LFUN_FONT_NOUN: {
1493 Font font(ignore_font, ignore_language);
1494 font.fontInfo().setNoun(FONT_TOGGLE);
1495 toggleAndShow(cur, this, font);
1499 case LFUN_FONT_TYPEWRITER: {
1500 Font font(ignore_font, ignore_language);
1501 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1502 toggleAndShow(cur, this, font);
1506 case LFUN_FONT_SANS: {
1507 Font font(ignore_font, ignore_language);
1508 font.fontInfo().setFamily(SANS_FAMILY);
1509 toggleAndShow(cur, this, font);
1513 case LFUN_FONT_ROMAN: {
1514 Font font(ignore_font, ignore_language);
1515 font.fontInfo().setFamily(ROMAN_FAMILY);
1516 toggleAndShow(cur, this, font);
1520 case LFUN_FONT_DEFAULT: {
1521 Font font(inherit_font, ignore_language);
1522 toggleAndShow(cur, this, font);
1526 case LFUN_FONT_UNDERLINE: {
1527 Font font(ignore_font, ignore_language);
1528 font.fontInfo().setUnderbar(FONT_TOGGLE);
1529 toggleAndShow(cur, this, font);
1533 case LFUN_FONT_SIZE: {
1534 Font font(ignore_font, ignore_language);
1535 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1536 toggleAndShow(cur, this, font);
1540 case LFUN_LANGUAGE: {
1541 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1544 Font font(ignore_font, lang);
1545 toggleAndShow(cur, this, font);
1549 case LFUN_FONT_FREE_APPLY:
1550 toggleAndShow(cur, this, freefont, toggleall);
1551 cur.message(_("Character set"));
1554 // Set the freefont using the contents of \param data dispatched from
1555 // the frontends and apply it at the current cursor location.
1556 case LFUN_FONT_FREE_UPDATE: {
1559 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1562 toggleAndShow(cur, this, freefont, toggleall);
1563 cur.message(_("Character set"));
1565 lyxerr << "Argument not ok";
1570 case LFUN_FINISHED_LEFT:
1571 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1572 // We're leaving an inset, going left. If the inset is LTR, we're
1573 // leaving from the front, so we should not move (remain at --- but
1574 // not in --- the inset). If the inset is RTL, move left, without
1575 // entering the inset itself; i.e., move to after the inset.
1576 if (cur.paragraph().getFontSettings(
1577 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1578 cursorVisLeft(cur, true);
1581 case LFUN_FINISHED_RIGHT:
1582 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1583 // We're leaving an inset, going right. If the inset is RTL, we're
1584 // leaving from the front, so we should not move (remain at --- but
1585 // not in --- the inset). If the inset is LTR, move right, without
1586 // entering the inset itself; i.e., move to after the inset.
1587 if (!cur.paragraph().getFontSettings(
1588 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1589 cursorVisRight(cur, true);
1592 case LFUN_FINISHED_BACKWARD:
1593 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1596 case LFUN_FINISHED_FORWARD:
1597 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1599 cur.setCurrentFont();
1602 case LFUN_LAYOUT_PARAGRAPH: {
1604 params2string(cur.paragraph(), data);
1605 data = "show\n" + data;
1606 bv->showDialog("paragraph", data);
1610 case LFUN_PARAGRAPH_UPDATE: {
1612 params2string(cur.paragraph(), data);
1614 // Will the paragraph accept changes from the dialog?
1616 cur.inset().allowParagraphCustomization(cur.idx());
1618 data = "update " + convert<string>(accept) + '\n' + data;
1619 bv->updateDialog("paragraph", data);
1623 case LFUN_ACCENT_UMLAUT:
1624 case LFUN_ACCENT_CIRCUMFLEX:
1625 case LFUN_ACCENT_GRAVE:
1626 case LFUN_ACCENT_ACUTE:
1627 case LFUN_ACCENT_TILDE:
1628 case LFUN_ACCENT_CEDILLA:
1629 case LFUN_ACCENT_MACRON:
1630 case LFUN_ACCENT_DOT:
1631 case LFUN_ACCENT_UNDERDOT:
1632 case LFUN_ACCENT_UNDERBAR:
1633 case LFUN_ACCENT_CARON:
1634 case LFUN_ACCENT_SPECIAL_CARON:
1635 case LFUN_ACCENT_BREVE:
1636 case LFUN_ACCENT_TIE:
1637 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1638 case LFUN_ACCENT_CIRCLE:
1639 case LFUN_ACCENT_OGONEK:
1640 theLyXFunc().handleKeyFunc(cmd.action);
1641 if (!cmd.argument().empty())
1642 // FIXME: Are all these characters encoded in one byte in utf8?
1643 bv->translateAndInsert(cmd.argument()[0], this, cur);
1646 case LFUN_FLOAT_LIST: {
1647 DocumentClass const & tclass = bv->buffer().params().documentClass();
1648 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1650 if (cur.selection())
1651 cutSelection(cur, true, false);
1652 breakParagraph(cur);
1654 if (cur.lastpos() != 0) {
1655 cursorBackward(cur);
1656 breakParagraph(cur);
1659 //FIXME Check if this should be emptyLayout()
1660 setLayout(cur, tclass.defaultLayoutName());
1661 ParagraphParameters p;
1662 setParagraphs(cur, p);
1663 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1666 lyxerr << "Non-existent float type: "
1667 << to_utf8(cmd.argument()) << endl;
1672 case LFUN_CHANGE_ACCEPT: {
1673 acceptOrRejectChanges(cur, ACCEPT);
1677 case LFUN_CHANGE_REJECT: {
1678 acceptOrRejectChanges(cur, REJECT);
1682 case LFUN_THESAURUS_ENTRY: {
1683 docstring arg = cmd.argument();
1685 arg = cur.selectionAsString(false);
1687 if (arg.size() > 100 || arg.empty()) {
1688 // Get word or selection
1689 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1690 arg = cur.selectionAsString(false);
1693 bv->showDialog("thesaurus", to_utf8(arg));
1697 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1698 // Given data, an encoding of the ParagraphParameters
1699 // generated in the Paragraph dialog, this function sets
1700 // the current paragraph, or currently selected paragraphs,
1702 // NOTE: This function overrides all existing settings.
1703 setParagraphs(cur, cmd.argument());
1704 cur.message(_("Paragraph layout set"));
1708 case LFUN_PARAGRAPH_PARAMS: {
1709 // Given data, an encoding of the ParagraphParameters as we'd
1710 // find them in a LyX file, this function modifies the current paragraph,
1711 // or currently selected paragraphs.
1712 // NOTE: This function only modifies, and does not override, existing
1714 setParagraphs(cur, cmd.argument(), true);
1715 cur.message(_("Paragraph layout set"));
1720 if (cur.selection()) {
1721 cur.selection() = false;
1724 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1725 // correct, but I'm not 100% sure -- dov, 071019
1726 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1730 case LFUN_OUTLINE_UP:
1731 outline(OutlineUp, cur);
1732 setCursor(cur, cur.pit(), 0);
1733 updateLabels(cur.buffer());
1737 case LFUN_OUTLINE_DOWN:
1738 outline(OutlineDown, cur);
1739 setCursor(cur, cur.pit(), 0);
1740 updateLabels(cur.buffer());
1744 case LFUN_OUTLINE_IN:
1745 outline(OutlineIn, cur);
1746 updateLabels(cur.buffer());
1750 case LFUN_OUTLINE_OUT:
1751 outline(OutlineOut, cur);
1752 updateLabels(cur.buffer());
1757 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1762 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1764 // FIXME: The cursor flag is reset two lines below
1765 // so we need to check here if some of the LFUN did touch that.
1766 // for now only Text::erase() and Text::backspace() do that.
1767 // The plan is to verify all the LFUNs and then to remove this
1768 // singleParUpdate boolean altogether.
1769 if (cur.result().update() & Update::Force) {
1770 singleParUpdate = false;
1774 // FIXME: the following code should go in favor of fine grained
1775 // update flag treatment.
1776 if (singleParUpdate) {
1777 // Inserting characters does not change par height in general. So, try
1778 // to update _only_ this paragraph. BufferView will detect if a full
1779 // metrics update is needed anyway.
1780 cur.updateFlags(Update::SinglePar | Update::FitCursor);
1785 && &oldTopSlice.inset() == &cur.inset()
1786 && oldTopSlice.idx() == cur.idx()
1787 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1788 && !cur.selection())
1789 // FIXME: it would be better if we could just do this
1791 //if (cur.result().update() != Update::FitCursor)
1794 // But some LFUNs do not set Update::FitCursor when needed, so we
1795 // do it for all. This is not very harmfull as FitCursor will provoke
1796 // a full redraw only if needed but still, a proper review of all LFUN
1797 // should be done and this needsUpdate boolean can then be removed.
1798 cur.updateFlags(Update::FitCursor);
1800 cur.updateFlags(Update::Force | Update::FitCursor);
1804 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1805 FuncStatus & flag) const
1807 BOOST_ASSERT(cur.text() == this);
1809 Font const & font = cur.real_current_font;
1810 FontInfo const & fontinfo = font.fontInfo();
1812 InsetCode code = NO_CODE;
1814 switch (cmd.action) {
1816 case LFUN_DEPTH_DECREMENT:
1817 enable = changeDepthAllowed(cur, DEC_DEPTH);
1820 case LFUN_DEPTH_INCREMENT:
1821 enable = changeDepthAllowed(cur, INC_DEPTH);
1825 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1828 case LFUN_BIBITEM_INSERT:
1829 enable = (cur.paragraph().layout().labeltype == LABEL_BIBLIO
1833 case LFUN_DIALOG_SHOW_NEW_INSET:
1834 if (cmd.argument() == "bibitem")
1835 code = BIBITEM_CODE;
1836 else if (cmd.argument() == "bibtex")
1838 else if (cmd.argument() == "box")
1840 else if (cmd.argument() == "branch")
1842 else if (cmd.argument() == "citation")
1844 else if (cmd.argument() == "ert")
1846 else if (cmd.argument() == "external")
1847 code = EXTERNAL_CODE;
1848 else if (cmd.argument() == "float")
1850 else if (cmd.argument() == "graphics")
1851 code = GRAPHICS_CODE;
1852 else if (cmd.argument() == "href")
1853 code = HYPERLINK_CODE;
1854 else if (cmd.argument() == "include")
1855 code = INCLUDE_CODE;
1856 else if (cmd.argument() == "index")
1858 else if (cmd.argument() == "nomenclature")
1859 code = NOMENCL_CODE;
1860 else if (cmd.argument() == "label")
1862 else if (cmd.argument() == "note")
1864 else if (cmd.argument() == "ref")
1866 else if (cmd.argument() == "space")
1868 else if (cmd.argument() == "toc")
1870 else if (cmd.argument() == "vspace")
1872 else if (cmd.argument() == "wrap")
1874 else if (cmd.argument() == "listings")
1875 code = LISTINGS_CODE;
1878 case LFUN_ERT_INSERT:
1881 case LFUN_LISTING_INSERT:
1882 code = LISTINGS_CODE;
1884 case LFUN_FOOTNOTE_INSERT:
1887 case LFUN_TABULAR_INSERT:
1888 code = TABULAR_CODE;
1890 case LFUN_MARGINALNOTE_INSERT:
1893 case LFUN_FLOAT_INSERT:
1894 case LFUN_FLOAT_WIDE_INSERT:
1897 case LFUN_WRAP_INSERT:
1900 case LFUN_FLOAT_LIST:
1901 code = FLOAT_LIST_CODE;
1904 case LFUN_LIST_INSERT:
1908 case LFUN_CAPTION_INSERT:
1909 code = CAPTION_CODE;
1911 case LFUN_NOTE_INSERT:
1914 case LFUN_FLEX_INSERT: {
1916 string s = cmd.getArg(0);
1918 cur.buffer().params().documentClass().insetLayout(from_utf8(s));
1919 if (il.lyxtype() != "charstyle" &&
1920 il.lyxtype() != "custom" &&
1921 il.lyxtype() != "element" &&
1922 il.lyxtype ()!= "standard")
1926 case LFUN_BOX_INSERT:
1929 case LFUN_BRANCH_INSERT:
1931 if (cur.buffer().masterBuffer()->params().branchlist().empty())
1934 case LFUN_LABEL_INSERT:
1937 case LFUN_INFO_INSERT:
1940 case LFUN_OPTIONAL_INSERT:
1942 enable = cur.paragraph().insetList().count(OPTARG_CODE)
1943 < cur.paragraph().layout().optionalargs;
1945 case LFUN_ENVIRONMENT_INSERT:
1948 case LFUN_INDEX_INSERT:
1951 case LFUN_INDEX_PRINT:
1952 code = INDEX_PRINT_CODE;
1954 case LFUN_NOMENCL_INSERT:
1955 code = NOMENCL_CODE;
1957 case LFUN_NOMENCL_PRINT:
1958 code = NOMENCL_PRINT_CODE;
1960 case LFUN_TOC_INSERT:
1963 case LFUN_HYPERLINK_INSERT:
1964 code = HYPERLINK_CODE;
1966 case LFUN_QUOTE_INSERT:
1967 // always allow this, since we will inset a raw quote
1968 // if an inset is not allowed.
1970 case LFUN_SPECIALCHAR_INSERT:
1971 code = SPECIALCHAR_CODE;
1973 case LFUN_SPACE_INSERT:
1974 // slight hack: we know this is allowed in math mode
1979 case LFUN_INSET_MODIFY:
1980 // We need to disable this, because we may get called for a
1982 // InsetTabular::getStatus() -> InsetText::getStatus()
1983 // and we don't handle LFUN_INSET_MODIFY.
1987 case LFUN_FONT_EMPH:
1988 flag.setOnOff(fontinfo.emph() == FONT_ON);
1991 case LFUN_FONT_NOUN:
1992 flag.setOnOff(fontinfo.noun() == FONT_ON);
1995 case LFUN_FONT_BOLD:
1996 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
1999 case LFUN_FONT_SANS:
2000 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2003 case LFUN_FONT_ROMAN:
2004 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2007 case LFUN_FONT_TYPEWRITER:
2008 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2013 enable = cur.selection();
2017 if (cmd.argument().empty()) {
2018 if (theClipboard().isInternal())
2019 enable = cap::numberOfSelections() > 0;
2021 enable = !theClipboard().empty();
2025 // we have an argument
2026 string const arg = to_utf8(cmd.argument());
2027 if (isStrUnsignedInt(arg)) {
2028 // it's a number and therefore means the internal stack
2029 unsigned int n = convert<unsigned int>(arg);
2030 enable = cap::numberOfSelections() > n;
2034 // explicit graphics type?
2035 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2036 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2037 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2038 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2048 case LFUN_CLIPBOARD_PASTE:
2049 enable = !theClipboard().empty();
2052 case LFUN_PRIMARY_SELECTION_PASTE:
2053 enable = cur.selection() || !theSelection().empty();
2056 case LFUN_PARAGRAPH_MOVE_UP:
2057 enable = cur.pit() > 0 && !cur.selection();
2060 case LFUN_PARAGRAPH_MOVE_DOWN:
2061 enable = cur.pit() < cur.lastpit() && !cur.selection();
2064 case LFUN_INSET_DISSOLVE:
2065 if (!cmd.argument().empty()) {
2066 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
2067 enable = cur.inset().lyxCode() == FLEX_CODE
2068 && il.lyxtype() == to_utf8(cmd.argument());
2070 enable = !isMainText(cur.bv().buffer())
2071 && cur.inset().nargs() == 1;
2075 case LFUN_CHANGE_ACCEPT:
2076 case LFUN_CHANGE_REJECT:
2077 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2078 // In principle, these LFUNs should only be enabled if there
2079 // is a change at the current position/in the current selection.
2080 // However, without proper optimizations, this will inevitably
2081 // result in unacceptable performance - just imagine a user who
2082 // wants to select the complete content of a long document.
2086 case LFUN_OUTLINE_UP:
2087 case LFUN_OUTLINE_DOWN:
2088 case LFUN_OUTLINE_IN:
2089 case LFUN_OUTLINE_OUT:
2090 enable = (cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC);
2093 case LFUN_WORD_DELETE_FORWARD:
2094 case LFUN_WORD_DELETE_BACKWARD:
2095 case LFUN_LINE_DELETE:
2096 case LFUN_WORD_FORWARD:
2097 case LFUN_WORD_BACKWARD:
2098 case LFUN_WORD_RIGHT:
2099 case LFUN_WORD_LEFT:
2100 case LFUN_CHAR_FORWARD:
2101 case LFUN_CHAR_FORWARD_SELECT:
2102 case LFUN_CHAR_BACKWARD:
2103 case LFUN_CHAR_BACKWARD_SELECT:
2104 case LFUN_CHAR_LEFT:
2105 case LFUN_CHAR_LEFT_SELECT:
2106 case LFUN_CHAR_RIGHT:
2107 case LFUN_CHAR_RIGHT_SELECT:
2109 case LFUN_UP_SELECT:
2111 case LFUN_DOWN_SELECT:
2112 case LFUN_PARAGRAPH_UP_SELECT:
2113 case LFUN_PARAGRAPH_DOWN_SELECT:
2114 case LFUN_LINE_BEGIN_SELECT:
2115 case LFUN_LINE_END_SELECT:
2116 case LFUN_WORD_FORWARD_SELECT:
2117 case LFUN_WORD_BACKWARD_SELECT:
2118 case LFUN_WORD_RIGHT_SELECT:
2119 case LFUN_WORD_LEFT_SELECT:
2120 case LFUN_WORD_SELECT:
2121 case LFUN_PARAGRAPH_UP:
2122 case LFUN_PARAGRAPH_DOWN:
2123 case LFUN_LINE_BEGIN:
2124 case LFUN_LINE_BREAK:
2127 case LFUN_CHAR_DELETE_FORWARD:
2128 case LFUN_DELETE_FORWARD_SKIP:
2129 case LFUN_CHAR_DELETE_BACKWARD:
2130 case LFUN_DELETE_BACKWARD_SKIP:
2131 case LFUN_BREAK_PARAGRAPH:
2132 case LFUN_BREAK_PARAGRAPH_SKIP:
2133 case LFUN_PARAGRAPH_SPACING:
2134 case LFUN_INSET_INSERT:
2135 case LFUN_WORD_UPCASE:
2136 case LFUN_WORD_LOWCASE:
2137 case LFUN_WORD_CAPITALIZE:
2138 case LFUN_CHARS_TRANSPOSE:
2139 case LFUN_SERVER_GET_XY:
2140 case LFUN_SERVER_SET_XY:
2141 case LFUN_SERVER_GET_FONT:
2142 case LFUN_SERVER_GET_LAYOUT:
2144 case LFUN_DATE_INSERT:
2145 case LFUN_SELF_INSERT:
2146 case LFUN_LINE_INSERT:
2147 case LFUN_NEWPAGE_INSERT:
2148 case LFUN_PAGEBREAK_INSERT:
2149 case LFUN_CLEARPAGE_INSERT:
2150 case LFUN_CLEARDOUBLEPAGE_INSERT:
2151 case LFUN_MATH_DISPLAY:
2152 case LFUN_MATH_IMPORT_SELECTION:
2153 case LFUN_MATH_MODE:
2154 case LFUN_MATH_MACRO:
2155 case LFUN_MATH_MATRIX:
2156 case LFUN_MATH_DELIM:
2157 case LFUN_MATH_BIGDELIM:
2158 case LFUN_MATH_INSERT:
2159 case LFUN_MATH_SUBSCRIPT:
2160 case LFUN_MATH_SUPERSCRIPT:
2161 case LFUN_FONT_DEFAULT:
2162 case LFUN_FONT_UNDERLINE:
2163 case LFUN_FONT_SIZE:
2165 case LFUN_FONT_FREE_APPLY:
2166 case LFUN_FONT_FREE_UPDATE:
2167 case LFUN_LAYOUT_PARAGRAPH:
2168 case LFUN_PARAGRAPH_UPDATE:
2169 case LFUN_ACCENT_UMLAUT:
2170 case LFUN_ACCENT_CIRCUMFLEX:
2171 case LFUN_ACCENT_GRAVE:
2172 case LFUN_ACCENT_ACUTE:
2173 case LFUN_ACCENT_TILDE:
2174 case LFUN_ACCENT_CEDILLA:
2175 case LFUN_ACCENT_MACRON:
2176 case LFUN_ACCENT_DOT:
2177 case LFUN_ACCENT_UNDERDOT:
2178 case LFUN_ACCENT_UNDERBAR:
2179 case LFUN_ACCENT_CARON:
2180 case LFUN_ACCENT_SPECIAL_CARON:
2181 case LFUN_ACCENT_BREVE:
2182 case LFUN_ACCENT_TIE:
2183 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2184 case LFUN_ACCENT_CIRCLE:
2185 case LFUN_ACCENT_OGONEK:
2186 case LFUN_THESAURUS_ENTRY:
2187 case LFUN_PARAGRAPH_PARAMS_APPLY:
2188 case LFUN_PARAGRAPH_PARAMS:
2190 case LFUN_BUFFER_END:
2191 case LFUN_BUFFER_BEGIN:
2192 case LFUN_BUFFER_BEGIN_SELECT:
2193 case LFUN_BUFFER_END_SELECT:
2194 case LFUN_UNICODE_INSERT:
2195 // these are handled in our dispatch()
2204 && (cur.empty() || !cur.inset().insetAllowed(code)))
2207 flag.enabled(enable);
2212 void Text::pasteString(Cursor & cur, docstring const & clip,
2215 cur.clearSelection();
2216 if (!clip.empty()) {
2219 insertStringAsParagraphs(cur, clip);
2221 insertStringAsLines(cur, clip);