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));
159 formula->read(cur.buffer(), lex);
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 Inset * inset = createInset(cur.bv().buffer(), cmd);
189 if (InsetCollapsable * ci = inset->asInsetCollapsable())
190 ci->setLayout(cur.bv().buffer().params());
193 if (cmd.action == LFUN_INDEX_INSERT) {
194 docstring ds = subst(text->getStringToIndex(cur), '\n', ' ');
195 text->insertInset(cur, inset);
197 inset->edit(cur, true);
198 // Now put this into inset
199 static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
204 if (cur.selection()) {
205 lyx::dispatch(FuncRequest(LFUN_CUT));
208 text->insertInset(cur, inset);
211 inset->edit(cur, true);
213 if (!gotsel || !pastesel)
216 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
217 InsetText * insetText = dynamic_cast<InsetText *>(inset);
218 if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
219 // reset first par to default
220 LayoutPtr const layout = insetText->useEmptyLayout() ?
221 cur.buffer().params().getTextClass().emptyLayout() :
222 cur.buffer().params().getTextClass().defaultLayout();
223 cur.text()->paragraphs().begin()->layout(layout);
226 // Merge multiple paragraphs -- hack
227 while (cur.lastpit() > 0) {
228 mergeParagraph(cur.buffer().params(),
229 cur.text()->paragraphs(), 0);
232 // reset surrounding par to default
233 docstring const layoutname = insetText->useEmptyLayout() ?
234 cur.buffer().params().getTextClass().emptyLayoutName() :
235 cur.buffer().params().getTextClass().defaultLayoutName();
236 cur.leaveInset(*inset);
237 text->setLayout(cur, layoutname);
244 string const freefont2string()
246 return freefont.toString(toggleall);
250 /// the type of outline operation
252 OutlineUp, // Move this header with text down
253 OutlineDown, // Move this header with text up
254 OutlineIn, // Make this header deeper
255 OutlineOut // Make this header shallower
259 static void outline(OutlineOp mode, Cursor & cur)
261 Buffer & buf = cur.buffer();
262 pit_type & pit = cur.pit();
263 ParagraphList & pars = buf.text().paragraphs();
264 ParagraphList::iterator bgn = pars.begin();
265 // The first paragraph of the area to be copied:
266 ParagraphList::iterator start = boost::next(bgn, pit);
267 // The final paragraph of area to be copied:
268 ParagraphList::iterator finish = start;
269 ParagraphList::iterator end = pars.end();
271 TextClass::const_iterator lit =
272 buf.params().getTextClass().begin();
273 TextClass::const_iterator const lend =
274 buf.params().getTextClass().end();
276 int const thistoclevel = start->layout()->toclevel;
280 // Move out (down) from this section header
283 // Seek the one (on same level) below
284 for (; finish != end; ++finish) {
285 toclevel = finish->layout()->toclevel;
286 if (toclevel != Layout::NOT_IN_TOC
287 && toclevel <= thistoclevel) {
291 ParagraphList::iterator dest = start;
292 // Move out (up) from this header
295 // Search previous same-level header above
298 toclevel = dest->layout()->toclevel;
300 && (toclevel == Layout::NOT_IN_TOC
301 || toclevel > thistoclevel));
302 // Not found; do nothing
303 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
305 pit_type const newpit = distance(bgn, dest);
306 pit_type const len = distance(start, finish);
307 pit_type const deletepit = pit + len;
308 buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
309 pars.insert(dest, start, finish);
310 start = boost::next(pars.begin(), deletepit);
312 pars.erase(start, finish);
316 // Go down out of current header:
319 // Find next same-level header:
320 for (; finish != end; ++finish) {
321 toclevel = finish->layout()->toclevel;
322 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
325 ParagraphList::iterator dest = finish;
326 // Go one down from *this* header:
331 // Go further down to find header to insert in front of:
332 for (; dest != end; ++dest) {
333 toclevel = dest->layout()->toclevel;
334 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
337 // One such was found:
338 pit_type newpit = distance(bgn, dest);
339 pit_type const len = distance(start, finish);
340 buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
341 pars.insert(dest, start, finish);
342 start = boost::next(bgn, pit);
344 pars.erase(start, finish);
348 buf.undo().recordUndo(cur);
349 for (; lit != lend; ++lit) {
350 if ((*lit)->toclevel == thistoclevel + 1 &&
351 start->layout()->labeltype == (*lit)->labeltype) {
352 start->layout((*lit));
358 buf.undo().recordUndo(cur);
359 for (; lit != lend; ++lit) {
360 if ((*lit)->toclevel == thistoclevel - 1 &&
361 start->layout()->labeltype == (*lit)->labeltype) {
362 start->layout((*lit));
373 void Text::number(Cursor & cur)
375 FontInfo font = ignore_font;
376 font.setNumber(FONT_TOGGLE);
377 toggleAndShow(cur, this, Font(font));
381 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
383 return par.isRTL(buffer.params());
387 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
389 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
391 // FIXME: We use the update flag to indicates wether a singlePar or a
392 // full screen update is needed. We reset it here but shall we restore it
396 BOOST_ASSERT(cur.text() == this);
397 BufferView * bv = &cur.bv();
398 TextMetrics & tm = cur.bv().textMetrics(this);
399 CursorSlice oldTopSlice = cur.top();
400 bool oldBoundary = cur.boundary();
401 bool sel = cur.selection();
402 // Signals that, even if needsUpdate == false, an update of the
403 // cursor paragraph is required
404 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
405 LyXAction::SingleParUpdate);
406 // Signals that a full-screen update is required
407 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
408 LyXAction::NoUpdate) || singleParUpdate);
409 // Remember the old paragraph metric (_outer_ paragraph!)
410 ParagraphMetrics const & pm = cur.bv().parMetrics(
411 cur.bottom().text(), cur.bottom().pit());
412 Dimension olddim = pm.dim();
414 switch (cmd.action) {
416 case LFUN_PARAGRAPH_MOVE_DOWN: {
417 pit_type const pit = cur.pit();
418 recUndo(cur, pit, pit + 1);
420 swap(pars_[pit], pars_[pit + 1]);
421 updateLabels(cur.buffer());
427 case LFUN_PARAGRAPH_MOVE_UP: {
428 pit_type const pit = cur.pit();
429 recUndo(cur, pit - 1, pit);
431 swap(pars_[pit], pars_[pit - 1]);
432 updateLabels(cur.buffer());
438 case LFUN_APPENDIX: {
439 Paragraph & par = cur.paragraph();
440 bool start = !par.params().startOfAppendix();
442 // FIXME: The code below only makes sense at top level.
443 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
444 // ensure that we have only one start_of_appendix in this document
445 // FIXME: this don't work for multipart document!
446 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
447 if (pars_[tmp].params().startOfAppendix()) {
449 pars_[tmp].params().startOfAppendix(false);
455 par.params().startOfAppendix(start);
457 // we can set the refreshing parameters now
458 updateLabels(cur.buffer());
462 case LFUN_WORD_DELETE_FORWARD:
463 if (cur.selection()) {
464 cutSelection(cur, true, false);
466 deleteWordForward(cur);
467 finishChange(cur, false);
470 case LFUN_WORD_DELETE_BACKWARD:
471 if (cur.selection()) {
472 cutSelection(cur, true, false);
474 deleteWordBackward(cur);
475 finishChange(cur, false);
478 case LFUN_LINE_DELETE:
479 if (cur.selection()) {
480 cutSelection(cur, true, false);
482 tm.deleteLineForward(cur);
483 finishChange(cur, false);
486 case LFUN_BUFFER_BEGIN:
487 case LFUN_BUFFER_BEGIN_SELECT:
488 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
489 if (cur.depth() == 1) {
490 needsUpdate |= cursorTop(cur);
494 cur.updateFlags(Update::FitCursor);
497 case LFUN_BUFFER_END:
498 case LFUN_BUFFER_END_SELECT:
499 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
500 if (cur.depth() == 1) {
501 needsUpdate |= cursorBottom(cur);
505 cur.updateFlags(Update::FitCursor);
508 case LFUN_CHAR_FORWARD:
509 case LFUN_CHAR_FORWARD_SELECT:
510 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
511 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
512 needsUpdate |= cursorForward(cur);
514 if (!needsUpdate && oldTopSlice == cur.top()
515 && cur.boundary() == oldBoundary) {
517 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
521 case LFUN_CHAR_BACKWARD:
522 case LFUN_CHAR_BACKWARD_SELECT:
523 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
524 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
525 needsUpdate |= cursorBackward(cur);
527 if (!needsUpdate && oldTopSlice == cur.top()
528 && cur.boundary() == oldBoundary) {
530 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
535 case LFUN_CHAR_LEFT_SELECT:
536 if (lyxrc.visual_cursor) {
537 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_LEFT_SELECT);
538 needsUpdate |= cursorVisLeft(cur);
539 if (!needsUpdate && oldTopSlice == cur.top()
540 && cur.boundary() == oldBoundary) {
542 cmd = FuncRequest(LFUN_FINISHED_LEFT);
545 if (reverseDirectionNeeded(cur)) {
546 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
547 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
549 cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
550 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
557 case LFUN_CHAR_RIGHT:
558 case LFUN_CHAR_RIGHT_SELECT:
559 if (lyxrc.visual_cursor) {
560 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_RIGHT_SELECT);
561 needsUpdate |= cursorVisRight(cur);
562 if (!needsUpdate && oldTopSlice == cur.top()
563 && cur.boundary() == oldBoundary) {
565 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
568 if (reverseDirectionNeeded(cur)) {
569 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
570 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
572 cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
573 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
582 case LFUN_DOWN_SELECT:
585 // stop/start the selection
586 bool select = cmd.action == LFUN_DOWN_SELECT ||
587 cmd.action == LFUN_UP_SELECT;
588 cur.selHandle(select);
590 // move cursor up/down
591 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
592 bool const successful = cur.upDownInText(up, needsUpdate);
594 // notify insets which were left and get their update flags
595 notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
598 // redraw if you leave mathed (for the decorations)
599 needsUpdate |= cur.beforeDispatchCursor().inMathed();
606 case LFUN_PARAGRAPH_UP:
607 case LFUN_PARAGRAPH_UP_SELECT:
608 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
609 needsUpdate |= cursorUpParagraph(cur);
612 case LFUN_PARAGRAPH_DOWN:
613 case LFUN_PARAGRAPH_DOWN_SELECT:
614 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
615 needsUpdate |= cursorDownParagraph(cur);
618 case LFUN_SCREEN_UP_SELECT:
619 needsUpdate |= cur.selHandle(true);
620 if (cur.pit() == 0 && cur.textRow().pos() == 0)
623 tm.cursorPrevious(cur);
627 case LFUN_SCREEN_DOWN_SELECT:
628 needsUpdate |= cur.selHandle(true);
629 if (cur.pit() == cur.lastpit()
630 && cur.textRow().endpos() == cur.lastpos())
637 case LFUN_LINE_BEGIN:
638 case LFUN_LINE_BEGIN_SELECT:
639 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
640 needsUpdate |= tm.cursorHome(cur);
644 case LFUN_LINE_END_SELECT:
645 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
646 needsUpdate |= tm.cursorEnd(cur);
649 case LFUN_WORD_RIGHT:
650 case LFUN_WORD_RIGHT_SELECT:
651 //FIXME: for visual cursor mode, really move right
652 if (reverseDirectionNeeded(cur)) {
653 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
654 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
656 cmd.action = cmd.action == LFUN_WORD_RIGHT_SELECT ?
657 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
662 case LFUN_WORD_FORWARD:
663 case LFUN_WORD_FORWARD_SELECT:
664 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
665 needsUpdate |= cursorForwardOneWord(cur);
669 case LFUN_WORD_LEFT_SELECT:
670 //FIXME: for visual cursor mode, really move left
671 if (reverseDirectionNeeded(cur)) {
672 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
673 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD;
675 cmd.action = cmd.action == LFUN_WORD_LEFT_SELECT ?
676 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD;
681 case LFUN_WORD_BACKWARD:
682 case LFUN_WORD_BACKWARD_SELECT:
683 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
684 needsUpdate |= cursorBackwardOneWord(cur);
687 case LFUN_WORD_SELECT: {
688 selectWord(cur, WHOLE_WORD);
689 finishChange(cur, true);
693 case LFUN_NEW_LINE: {
694 // Not allowed by LaTeX (labels or empty par)
695 if (cur.pos() > cur.paragraph().beginOfBody()) {
696 // this avoids a double undo
697 // FIXME: should not be needed, ideally
698 if (!cur.selection())
700 cap::replaceSelection(cur);
701 cur.insert(new InsetNewline);
703 moveCursor(cur, false);
708 case LFUN_LINE_BREAK: {
709 // Not allowed by LaTeX (labels or empty par)
710 if (cur.pos() > cur.paragraph().beginOfBody()) {
711 // this avoids a double undo
712 // FIXME: should not be needed, ideally
713 if (!cur.selection())
715 cap::replaceSelection(cur);
716 cur.insert(new InsetLinebreak);
718 moveCursor(cur, false);
723 case LFUN_CHAR_DELETE_FORWARD:
724 if (!cur.selection()) {
725 if (cur.pos() == cur.paragraph().size())
726 // Par boundary, force full-screen update
727 singleParUpdate = false;
728 needsUpdate |= erase(cur);
730 // It is possible to make it a lot faster still
731 // just comment out the line below...
733 cutSelection(cur, true, false);
734 singleParUpdate = false;
736 moveCursor(cur, false);
739 case LFUN_DELETE_FORWARD_SKIP:
740 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
741 if (!cur.selection()) {
742 if (cur.pos() == cur.lastpos()) {
749 cutSelection(cur, true, false);
754 case LFUN_CHAR_DELETE_BACKWARD:
755 if (!cur.selection()) {
756 if (bv->getIntl().getTransManager().backspace()) {
757 // Par boundary, full-screen update
759 singleParUpdate = false;
760 needsUpdate |= backspace(cur);
762 // It is possible to make it a lot faster still
763 // just comment out the line below...
766 cutSelection(cur, true, false);
767 singleParUpdate = false;
771 case LFUN_DELETE_BACKWARD_SKIP:
772 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
773 if (!cur.selection()) {
775 //CursorSlice cur = cursor();
779 cutSelection(cur, true, false);
783 case LFUN_BREAK_PARAGRAPH:
784 cap::replaceSelection(cur);
785 breakParagraph(cur, cmd.argument() == "inverse");
789 case LFUN_BREAK_PARAGRAPH_SKIP: {
790 // When at the beginning of a paragraph, remove
791 // indentation. Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
792 cap::replaceSelection(cur);
794 cur.paragraph().params().labelWidthString(docstring());
796 breakParagraph(cur, false);
802 // With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
803 // as its duties can be performed there. Should it be removed??
804 // FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
805 case LFUN_PARAGRAPH_SPACING: {
806 Paragraph & par = cur.paragraph();
807 Spacing::Space cur_spacing = par.params().spacing().getSpace();
808 string cur_value = "1.0";
809 if (cur_spacing == Spacing::Other)
810 cur_value = par.params().spacing().getValueAsString();
812 istringstream is(to_utf8(cmd.argument()));
815 Spacing::Space new_spacing = cur_spacing;
816 string new_value = cur_value;
818 lyxerr << "Missing argument to `paragraph-spacing'"
820 } else if (tmp == "single") {
821 new_spacing = Spacing::Single;
822 } else if (tmp == "onehalf") {
823 new_spacing = Spacing::Onehalf;
824 } else if (tmp == "double") {
825 new_spacing = Spacing::Double;
826 } else if (tmp == "other") {
827 new_spacing = Spacing::Other;
828 string tmpval = "0.0";
830 lyxerr << "new_value = " << tmpval << endl;
833 } else if (tmp == "default") {
834 new_spacing = Spacing::Default;
836 lyxerr << to_utf8(_("Unknown spacing argument: "))
837 << to_utf8(cmd.argument()) << endl;
839 if (cur_spacing != new_spacing || cur_value != new_value)
840 par.params().spacing(Spacing(new_spacing, new_value));
844 case LFUN_INSET_INSERT: {
846 Inset * inset = createInset(bv->buffer(), cmd);
848 // FIXME (Abdel 01/02/2006):
849 // What follows would be a partial fix for bug 2154:
850 // http://bugzilla.lyx.org/show_bug.cgi?id=2154
851 // This automatically put the label inset _after_ a
852 // numbered section. It should be possible to extend the mechanism
853 // to any kind of LateX environement.
854 // The correct way to fix that bug would be at LateX generation.
855 // I'll let the code here for reference as it could be used for some
856 // other feature like "automatic labelling".
858 Paragraph & par = pars_[cur.pit()];
859 if (inset->lyxCode() == LABEL_CODE
860 && par.layout()->labeltype == LABEL_COUNTER) {
861 // Go to the end of the paragraph
862 // Warning: Because of Change-Tracking, the last
863 // position is 'size()' and not 'size()-1':
864 cur.pos() = par.size();
865 // Insert a new paragraph
866 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
871 cutSelection(cur, true, false);
872 insertInset(cur, inset);
878 case LFUN_INSET_DISSOLVE:
879 needsUpdate |= dissolveInset(cur);
882 case LFUN_INSET_SETTINGS:
883 cur.inset().showInsetDialog(bv);
886 case LFUN_SPACE_INSERT:
887 if (cur.paragraph().layout()->free_spacing)
888 insertChar(cur, ' ');
890 doInsertInset(cur, this, cmd, false, false);
893 moveCursor(cur, false);
896 case LFUN_SPECIALCHAR_INSERT: {
897 string const name = to_utf8(cmd.argument());
898 if (name == "hyphenation")
899 specialChar(cur, InsetSpecialChar::HYPHENATION);
900 else if (name == "ligature-break")
901 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
902 else if (name == "slash")
903 specialChar(cur, InsetSpecialChar::SLASH);
904 else if (name == "nobreakdash")
905 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
906 else if (name == "dots")
907 specialChar(cur, InsetSpecialChar::LDOTS);
908 else if (name == "end-of-sentence")
909 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
910 else if (name == "menu-separator")
911 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
912 else if (name.empty())
913 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
915 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
919 case LFUN_WORD_UPCASE:
920 changeCase(cur, text_uppercase);
923 case LFUN_WORD_LOWCASE:
924 changeCase(cur, text_lowercase);
927 case LFUN_WORD_CAPITALIZE:
928 changeCase(cur, text_capitalization);
931 case LFUN_CHARS_TRANSPOSE:
936 cur.message(_("Paste"));
937 cap::replaceSelection(cur);
940 string const arg = to_utf8(cmd.argument());
942 if (theClipboard().isInternal())
943 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
944 else if (theClipboard().hasGraphicsContents())
945 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
947 pasteClipboardText(cur, bv->buffer().errorList("Paste"));
948 } else if (isStrUnsignedInt(arg)) {
949 // we have a numerical argument
950 pasteFromStack(cur, bv->buffer().errorList("Paste"),
951 convert<unsigned int>(arg));
953 Clipboard::GraphicsType type;
955 type = Clipboard::PdfGraphicsType;
956 else if (arg == "png")
957 type = Clipboard::PngGraphicsType;
958 else if (arg == "jpeg")
959 type = Clipboard::JpegGraphicsType;
960 else if (arg == "linkback")
961 type = Clipboard::LinkBackGraphicsType;
965 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
968 bv->buffer().errors("Paste");
969 cur.clearSelection(); // bug 393
975 cutSelection(cur, true, true);
976 cur.message(_("Cut"));
981 cur.message(_("Copy"));
984 case LFUN_SERVER_GET_XY:
985 cur.message(from_utf8(
986 convert<string>(tm.cursorX(cur.top(), cur.boundary()))
987 + ' ' + convert<string>(tm.cursorY(cur.top(), cur.boundary()))));
990 case LFUN_SERVER_SET_XY: {
993 istringstream is(to_utf8(cmd.argument()));
996 lyxerr << "SETXY: Could not parse coordinates in '"
997 << to_utf8(cmd.argument()) << endl;
999 tm.setCursorFromCoordinates(cur, x, y);
1003 case LFUN_SERVER_GET_FONT:
1004 if (cur.current_font.fontInfo().shape() == ITALIC_SHAPE)
1005 cur.message(from_ascii("E"));
1006 else if (cur.current_font.fontInfo().shape() == SMALLCAPS_SHAPE)
1007 cur.message(from_ascii("N"));
1009 cur.message(from_ascii("0"));
1012 case LFUN_SERVER_GET_LAYOUT:
1013 cur.message(cur.paragraph().layout()->name());
1017 docstring layout = cmd.argument();
1018 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
1020 Paragraph const & para = cur.paragraph();
1021 docstring const old_layout = para.layout()->name();
1022 TextClass const & tclass = bv->buffer().params().getTextClass();
1025 layout = tclass.defaultLayoutName();
1027 if (para.forceEmptyLayout())
1028 // in this case only the empty layout is allowed
1029 layout = tclass.emptyLayoutName();
1030 else if (para.useEmptyLayout()) {
1031 // in this case, default layout maps to empty layout
1032 if (layout == tclass.defaultLayoutName())
1033 layout = tclass.emptyLayoutName();
1035 // otherwise, the empty layout maps to the default
1036 if (layout == tclass.emptyLayoutName())
1037 layout = tclass.defaultLayoutName();
1040 bool hasLayout = tclass.hasLayout(layout);
1042 // If the entry is obsolete, use the new one instead.
1044 docstring const & obs = tclass[layout]->obsoleted_by();
1050 cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
1051 from_utf8(N_(" not known")));
1055 bool change_layout = (old_layout != layout);
1057 if (!change_layout && cur.selection() &&
1058 cur.selBegin().pit() != cur.selEnd().pit())
1060 pit_type spit = cur.selBegin().pit();
1061 pit_type epit = cur.selEnd().pit() + 1;
1062 while (spit != epit) {
1063 if (pars_[spit].layout()->name() != old_layout) {
1064 change_layout = true;
1072 setLayout(cur, layout);
1077 case LFUN_CLIPBOARD_PASTE:
1078 cur.clearSelection();
1079 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1080 cmd.argument() == "paragraph");
1081 bv->buffer().errors("Paste");
1084 case LFUN_PRIMARY_SELECTION_PASTE:
1085 pasteString(cur, theSelection().get(),
1086 cmd.argument() == "paragraph");
1089 case LFUN_UNICODE_INSERT: {
1090 if (cmd.argument().empty())
1092 docstring hexstring = cmd.argument();
1093 if (isHex(hexstring)) {
1094 char_type c = hexToInt(hexstring);
1095 if (c >= 32 && c < 0x10ffff) {
1096 lyxerr << "Inserting c: " << c << endl;
1097 docstring s = docstring(1, c);
1098 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
1104 case LFUN_QUOTE_INSERT: {
1105 Paragraph & par = cur.paragraph();
1106 pos_type pos = cur.pos();
1107 BufferParams const & bufparams = bv->buffer().params();
1108 LayoutPtr const & style = par.layout();
1109 if (!style->pass_thru
1110 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1111 // this avoids a double undo
1112 // FIXME: should not be needed, ideally
1113 if (!cur.selection())
1115 cap::replaceSelection(cur);
1120 else if (cur.prevInset() && cur.prevInset()->isSpace())
1123 c = par.getChar(pos - 1);
1124 string arg = to_utf8(cmd.argument());
1125 if (arg == "single")
1126 cur.insert(new InsetQuotes(c,
1127 bufparams.quotes_language,
1128 InsetQuotes::SingleQ));
1130 cur.insert(new InsetQuotes(c,
1131 bufparams.quotes_language,
1132 InsetQuotes::DoubleQ));
1136 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1140 case LFUN_DATE_INSERT: {
1141 string const format = cmd.argument().empty()
1142 ? lyxrc.date_insert_format : to_utf8(cmd.argument());
1143 string const time = formatted_time(current_time(), format);
1144 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
1148 case LFUN_MOUSE_TRIPLE:
1149 if (cmd.button() == mouse_button::button1) {
1158 case LFUN_MOUSE_DOUBLE:
1159 if (cmd.button() == mouse_button::button1) {
1160 selectWord(cur, WHOLE_WORD_STRICT);
1165 // Single-click on work area
1166 case LFUN_MOUSE_PRESS: {
1167 // Right click on a footnote flag opens float menu
1168 // FIXME: Why should we clear the selection in this case?
1169 if (cmd.button() == mouse_button::button3)
1170 cur.clearSelection();
1172 bool do_selection = cmd.button() == mouse_button::button1
1173 && cmd.argument() == "region-select";
1175 bool update = bv->mouseSetCursor(cur, do_selection);
1177 // Insert primary selection with middle mouse
1178 // if there is a local selection in the current buffer,
1180 if (cmd.button() == mouse_button::button2) {
1181 if (cap::selection()) {
1182 // Copy the selection buffer to the clipboard
1183 // stack, because we want it to appear in the
1184 // "Edit->Paste recent" menu.
1185 cap::copySelectionToStack();
1187 cap::pasteSelection(bv->cursor(),
1188 bv->buffer().errorList("Paste"));
1189 bv->buffer().errors("Paste");
1190 bv->buffer().markDirty();
1191 bv->cursor().finishUndo();
1193 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1197 // we have to update after dEPM triggered
1198 if (!update && cmd.button() == mouse_button::button1) {
1199 needsUpdate = false;
1206 case LFUN_MOUSE_MOTION: {
1207 // Only use motion with button 1
1208 //if (cmd.button() != mouse_button::button1)
1211 // ignore motions deeper nested than the real anchor
1212 Cursor & bvcur = cur.bv().cursor();
1213 if (!bvcur.anchor_.hasPart(cur)) {
1217 CursorSlice old = bvcur.top();
1219 int const wh = bv->workHeight();
1220 int const y = max(0, min(wh - 1, cmd.y));
1222 tm.setCursorFromCoordinates(cur, cmd.x, y);
1223 cur.setTargetX(cmd.x);
1225 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1227 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1228 // This is to allow jumping over large insets
1229 if (cur.top() == old) {
1231 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1233 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1236 if (cur.top() == old)
1239 // FIXME: This is brute force! But without it the selected
1240 // area is not corrected updated while moving the mouse.
1241 cur.updateFlags(Update::Force | Update::FitCursor);
1242 // don't set anchor_
1243 bvcur.setCursor(cur);
1244 bvcur.selection() = true;
1245 //lyxerr << "MOTION: " << bv->cursor() << endl;
1250 case LFUN_MOUSE_RELEASE: {
1251 if (cmd.button() == mouse_button::button2)
1254 if (cmd.button() == mouse_button::button1) {
1255 // if there is new selection, update persistent
1256 // selection, otherwise, single click does not
1257 // clear persistent selection buffer
1258 if (cur.selection()) {
1260 // if double click, cur is moved to the end of word by selectWord
1261 // but bvcur is current mouse position
1262 Cursor & bvcur = cur.bv().cursor();
1263 bvcur.selection() = true;
1265 needsUpdate = false;
1272 case LFUN_SELF_INSERT: {
1273 if (cmd.argument().empty())
1276 // Automatically delete the currently selected
1277 // text and replace it with what is being
1278 // typed in now. Depends on lyxrc settings
1279 // "auto_region_delete", which defaults to
1282 if (lyxrc.auto_region_delete && cur.selection())
1283 cutSelection(cur, false, false);
1285 cur.clearSelection();
1286 Font const old_font = cur.real_current_font;
1288 docstring::const_iterator cit = cmd.argument().begin();
1289 docstring::const_iterator end = cmd.argument().end();
1290 for (; cit != end; ++cit)
1291 bv->translateAndInsert(*cit, this, cur);
1294 moveCursor(cur, false);
1298 case LFUN_HYPERLINK_INSERT: {
1299 InsetCommandParams p(HYPERLINK_CODE);
1301 if (cur.selection()) {
1302 content = cur.selectionAsString(false);
1303 cutSelection(cur, true, false);
1305 p["target"] = (cmd.argument().empty()) ?
1306 content : cmd.argument();
1307 string const data = InsetCommandMailer::params2string("href", p);
1308 if (p["target"].empty()) {
1309 bv->showDialog("href", data);
1311 FuncRequest fr(LFUN_INSET_INSERT, data);
1317 case LFUN_LABEL_INSERT: {
1318 InsetCommandParams p(LABEL_CODE);
1319 // Try to generate a valid label
1320 p["name"] = (cmd.argument().empty()) ?
1321 cur.getPossibleLabel() :
1323 string const data = InsetCommandMailer::params2string("label", p);
1325 if (cmd.argument().empty()) {
1326 bv->showDialog("label", data);
1328 FuncRequest fr(LFUN_INSET_INSERT, data);
1334 case LFUN_INFO_INSERT: {
1335 Inset * inset = createInset(cur.bv().buffer(), cmd);
1338 // if an empty inset is created (cmd.argument() is empty)
1339 // use current selection as parameter.
1340 if (cmd.argument().empty() && cur.selection()) {
1341 // use selected text as info to avoid a separate UI
1342 docstring ds = cur.selectionAsString(false);
1343 cutSelection(cur, true, false);
1344 static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
1345 static_cast<InsetInfo *>(inset)->updateInfo(cur.bv().buffer());
1347 insertInset(cur, inset);
1352 case LFUN_LIST_INSERT:
1353 case LFUN_THEOREM_INSERT:
1355 case LFUN_CAPTION_INSERT:
1356 case LFUN_FOOTNOTE_INSERT:
1357 // Open the inset, and move the current selection
1359 doInsertInset(cur, this, cmd, true, true);
1361 // These insets are numbered.
1362 updateLabels(bv->buffer());
1364 case LFUN_NOTE_INSERT:
1365 case LFUN_FLEX_INSERT:
1366 case LFUN_BOX_INSERT:
1367 case LFUN_BRANCH_INSERT:
1368 case LFUN_BIBITEM_INSERT:
1369 case LFUN_ERT_INSERT:
1370 case LFUN_LISTING_INSERT:
1371 case LFUN_MARGINALNOTE_INSERT:
1372 case LFUN_OPTIONAL_INSERT:
1373 case LFUN_ENVIRONMENT_INSERT:
1374 // Open the inset, and move the current selection
1376 doInsertInset(cur, this, cmd, true, true);
1380 case LFUN_TABULAR_INSERT:
1381 // if there were no arguments, just open the dialog
1382 if (doInsertInset(cur, this, cmd, false, true))
1385 bv->showDialog("tabularcreate");
1389 case LFUN_FLOAT_INSERT:
1390 case LFUN_FLOAT_WIDE_INSERT:
1391 case LFUN_WRAP_INSERT: {
1392 bool content = cur.selection(); // will some text be moved into the inset?
1394 doInsertInset(cur, this, cmd, true, true);
1396 ParagraphList & pars = cur.text()->paragraphs();
1398 TextClass const & tclass = bv->buffer().params().getTextClass();
1400 // add a separate paragraph for the caption inset
1401 pars.push_back(Paragraph());
1402 pars.back().setInsetOwner(pars[0].inInset());
1403 if (pars.back().useEmptyLayout())
1404 pars.back().layout(tclass.emptyLayout());
1406 pars.back().layout(tclass.defaultLayout());
1408 int cap_pit = pars.size() - 1;
1410 // if an empty inset was created, we create an additional empty
1411 // paragraph at the bottom so that the user can choose where to put
1412 // the graphics (or table).
1414 pars.push_back(Paragraph());
1415 pars.back().setInsetOwner(pars[0].inInset());
1416 if (pars.back().useEmptyLayout())
1417 pars.back().layout(tclass.emptyLayout());
1419 pars.back().layout(tclass.defaultLayout());
1422 // reposition the cursor to the caption
1423 cur.pit() = cap_pit;
1425 // FIXME: This Text/Cursor dispatch handling is a mess!
1426 // We cannot use Cursor::dispatch here it needs access to up to
1428 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
1429 cur.text()->dispatch(cur, cmd_caption);
1430 cur.updateFlags(Update::Force);
1431 // FIXME: When leaving the Float (or Wrap) inset we should
1432 // delete any empty paragraph left above or below the
1437 case LFUN_INDEX_INSERT:
1438 doInsertInset(cur, this, cmd, true, true);
1442 case LFUN_NOMENCL_INSERT: {
1443 FuncRequest cmd1 = cmd;
1444 if (cmd.argument().empty())
1445 cmd1 = FuncRequest(cmd,
1446 bv->cursor().innerText()->getStringToIndex(bv->cursor()));
1447 Inset * inset = createInset(cur.bv().buffer(), cmd1);
1451 cur.clearSelection();
1452 insertInset(cur, inset);
1453 // Show the dialog for the nomenclature entry, since the
1454 // description entry still needs to be filled in.
1455 if (cmd.action == LFUN_NOMENCL_INSERT)
1456 inset->edit(cur, true);
1461 case LFUN_INDEX_PRINT:
1462 case LFUN_NOMENCL_PRINT:
1463 case LFUN_TOC_INSERT:
1464 case LFUN_HFILL_INSERT:
1465 case LFUN_LINE_INSERT:
1466 case LFUN_NEWPAGE_INSERT:
1467 case LFUN_PAGEBREAK_INSERT:
1468 case LFUN_CLEARPAGE_INSERT:
1469 case LFUN_CLEARDOUBLEPAGE_INSERT:
1471 doInsertInset(cur, this, cmd, false, false);
1475 case LFUN_DEPTH_DECREMENT:
1476 changeDepth(cur, DEC_DEPTH);
1479 case LFUN_DEPTH_INCREMENT:
1480 changeDepth(cur, INC_DEPTH);
1483 case LFUN_MATH_DISPLAY:
1484 mathDispatch(cur, cmd, true);
1487 case LFUN_MATH_IMPORT_SELECTION:
1488 case LFUN_MATH_MODE:
1489 if (cmd.argument() == "on")
1490 // don't pass "on" as argument
1491 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1493 mathDispatch(cur, cmd, false);
1496 case LFUN_MATH_MACRO:
1497 if (cmd.argument().empty())
1498 cur.errorMessage(from_utf8(N_("Missing argument")));
1500 string s = to_utf8(cmd.argument());
1501 string const s1 = token(s, ' ', 1);
1502 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1503 string const s2 = token(s, ' ', 2);
1504 MacroType type = MacroTypeNewcommand;
1506 type = MacroTypeDef;
1507 cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type));
1508 //cur.nextInset()->edit(cur, true);
1512 // passthrough hat and underscore outside mathed:
1513 case LFUN_MATH_SUBSCRIPT:
1514 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1516 case LFUN_MATH_SUPERSCRIPT:
1517 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1520 case LFUN_MATH_INSERT:
1521 case LFUN_MATH_MATRIX:
1522 case LFUN_MATH_DELIM:
1523 case LFUN_MATH_BIGDELIM: {
1524 cap::replaceSelection(cur);
1525 cur.insert(new InsetMathHull(hullSimple));
1526 checkAndActivateInset(cur, true);
1527 BOOST_ASSERT(cur.inMathed());
1532 case LFUN_FONT_EMPH: {
1533 Font font(ignore_font, ignore_language);
1534 font.fontInfo().setEmph(FONT_TOGGLE);
1535 toggleAndShow(cur, this, font);
1539 case LFUN_FONT_BOLD: {
1540 Font font(ignore_font, ignore_language);
1541 font.fontInfo().setSeries(BOLD_SERIES);
1542 toggleAndShow(cur, this, font);
1546 case LFUN_FONT_NOUN: {
1547 Font font(ignore_font, ignore_language);
1548 font.fontInfo().setNoun(FONT_TOGGLE);
1549 toggleAndShow(cur, this, font);
1553 case LFUN_FONT_TYPEWRITER: {
1554 Font font(ignore_font, ignore_language);
1555 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
1556 toggleAndShow(cur, this, font);
1560 case LFUN_FONT_SANS: {
1561 Font font(ignore_font, ignore_language);
1562 font.fontInfo().setFamily(SANS_FAMILY);
1563 toggleAndShow(cur, this, font);
1567 case LFUN_FONT_ROMAN: {
1568 Font font(ignore_font, ignore_language);
1569 font.fontInfo().setFamily(ROMAN_FAMILY);
1570 toggleAndShow(cur, this, font);
1574 case LFUN_FONT_DEFAULT: {
1575 Font font(inherit_font, ignore_language);
1576 toggleAndShow(cur, this, font);
1580 case LFUN_FONT_UNDERLINE: {
1581 Font font(ignore_font, ignore_language);
1582 font.fontInfo().setUnderbar(FONT_TOGGLE);
1583 toggleAndShow(cur, this, font);
1587 case LFUN_FONT_SIZE: {
1588 Font font(ignore_font, ignore_language);
1589 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
1590 toggleAndShow(cur, this, font);
1594 case LFUN_LANGUAGE: {
1595 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1598 Font font(ignore_font, lang);
1599 toggleAndShow(cur, this, font);
1603 case LFUN_FONT_FREE_APPLY:
1604 toggleAndShow(cur, this, freefont, toggleall);
1605 cur.message(_("Character set"));
1608 // Set the freefont using the contents of \param data dispatched from
1609 // the frontends and apply it at the current cursor location.
1610 case LFUN_FONT_FREE_UPDATE: {
1613 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
1616 toggleAndShow(cur, this, freefont, toggleall);
1617 cur.message(_("Character set"));
1619 lyxerr << "Argument not ok";
1624 case LFUN_FINISHED_LEFT:
1625 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
1626 // We're leaving an inset, going left. If the inset is LTR, we're
1627 // leaving from the front, so we should not move (remain at --- but
1628 // not in --- the inset). If the inset is RTL, move left, without
1629 // entering the inset itself; i.e., move to after the inset.
1630 if (cur.paragraph().getFontSettings(
1631 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1632 cursorVisLeft(cur, true);
1635 case LFUN_FINISHED_RIGHT:
1636 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
1637 // We're leaving an inset, going right. If the inset is RTL, we're
1638 // leaving from the front, so we should not move (remain at --- but
1639 // not in --- the inset). If the inset is LTR, move right, without
1640 // entering the inset itself; i.e., move to after the inset.
1641 if (!cur.paragraph().getFontSettings(
1642 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
1643 cursorVisRight(cur, true);
1646 case LFUN_FINISHED_BACKWARD:
1647 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
1650 case LFUN_FINISHED_FORWARD:
1651 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
1653 cur.setCurrentFont();
1656 case LFUN_LAYOUT_PARAGRAPH: {
1658 params2string(cur.paragraph(), data);
1659 data = "show\n" + data;
1660 bv->showDialog("paragraph", data);
1664 case LFUN_PARAGRAPH_UPDATE: {
1666 params2string(cur.paragraph(), data);
1668 // Will the paragraph accept changes from the dialog?
1670 cur.inset().allowParagraphCustomization(cur.idx());
1672 data = "update " + convert<string>(accept) + '\n' + data;
1673 bv->updateDialog("paragraph", data);
1677 case LFUN_ACCENT_UMLAUT:
1678 case LFUN_ACCENT_CIRCUMFLEX:
1679 case LFUN_ACCENT_GRAVE:
1680 case LFUN_ACCENT_ACUTE:
1681 case LFUN_ACCENT_TILDE:
1682 case LFUN_ACCENT_CEDILLA:
1683 case LFUN_ACCENT_MACRON:
1684 case LFUN_ACCENT_DOT:
1685 case LFUN_ACCENT_UNDERDOT:
1686 case LFUN_ACCENT_UNDERBAR:
1687 case LFUN_ACCENT_CARON:
1688 case LFUN_ACCENT_SPECIAL_CARON:
1689 case LFUN_ACCENT_BREVE:
1690 case LFUN_ACCENT_TIE:
1691 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1692 case LFUN_ACCENT_CIRCLE:
1693 case LFUN_ACCENT_OGONEK:
1694 theLyXFunc().handleKeyFunc(cmd.action);
1695 if (!cmd.argument().empty())
1696 // FIXME: Are all these characters encoded in one byte in utf8?
1697 bv->translateAndInsert(cmd.argument()[0], this, cur);
1700 case LFUN_FLOAT_LIST: {
1701 TextClass const & tclass = bv->buffer().params().getTextClass();
1702 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1704 if (cur.selection())
1705 cutSelection(cur, true, false);
1706 breakParagraph(cur);
1708 if (cur.lastpos() != 0) {
1709 cursorBackward(cur);
1710 breakParagraph(cur);
1713 //FIXME Check if this should be emptyLayout()
1714 setLayout(cur, tclass.defaultLayoutName());
1715 ParagraphParameters p;
1716 setParagraphs(cur, p);
1717 insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1720 lyxerr << "Non-existent float type: "
1721 << to_utf8(cmd.argument()) << endl;
1726 case LFUN_CHANGE_ACCEPT: {
1727 acceptOrRejectChanges(cur, ACCEPT);
1731 case LFUN_CHANGE_REJECT: {
1732 acceptOrRejectChanges(cur, REJECT);
1736 case LFUN_THESAURUS_ENTRY: {
1737 docstring arg = cmd.argument();
1739 arg = cur.selectionAsString(false);
1741 if (arg.size() > 100 || arg.empty()) {
1742 // Get word or selection
1743 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1744 arg = cur.selectionAsString(false);
1747 bv->showDialog("thesaurus", to_utf8(arg));
1751 case LFUN_PARAGRAPH_PARAMS_APPLY: {
1752 // Given data, an encoding of the ParagraphParameters
1753 // generated in the Paragraph dialog, this function sets
1754 // the current paragraph, or currently selected paragraphs,
1756 // NOTE: This function overrides all existing settings.
1757 setParagraphs(cur, cmd.argument());
1758 cur.message(_("Paragraph layout set"));
1762 case LFUN_PARAGRAPH_PARAMS: {
1763 // Given data, an encoding of the ParagraphParameters as we'd
1764 // find them in a LyX file, this function modifies the current paragraph,
1765 // or currently selected paragraphs.
1766 // NOTE: This function only modifies, and does not override, existing
1768 setParagraphs(cur, cmd.argument(), true);
1769 cur.message(_("Paragraph layout set"));
1774 if (cur.selection()) {
1775 cur.selection() = false;
1778 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
1779 // correct, but I'm not 100% sure -- dov, 071019
1780 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1784 case LFUN_OUTLINE_UP:
1785 outline(OutlineUp, cur);
1786 setCursor(cur, cur.pit(), 0);
1787 updateLabels(cur.buffer());
1791 case LFUN_OUTLINE_DOWN:
1792 outline(OutlineDown, cur);
1793 setCursor(cur, cur.pit(), 0);
1794 updateLabels(cur.buffer());
1798 case LFUN_OUTLINE_IN:
1799 outline(OutlineIn, cur);
1800 updateLabels(cur.buffer());
1804 case LFUN_OUTLINE_OUT:
1805 outline(OutlineOut, cur);
1806 updateLabels(cur.buffer());
1811 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
1816 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1818 // FIXME: The cursor flag is reset two lines below
1819 // so we need to check here if some of the LFUN did touch that.
1820 // for now only Text::erase() and Text::backspace() do that.
1821 // The plan is to verify all the LFUNs and then to remove this
1822 // singleParUpdate boolean altogether.
1823 if (cur.result().update() & Update::Force) {
1824 singleParUpdate = false;
1828 // FIXME: the following code should go in favor of fine grained
1829 // update flag treatment.
1830 if (singleParUpdate) {
1831 // Inserting characters does not change par height
1832 ParagraphMetrics const & pms
1833 = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1834 if (pms.dim().height() == olddim.height()) {
1835 // if so, update _only_ this paragraph
1836 cur.updateFlags(Update::SinglePar |
1844 && &oldTopSlice.inset() == &cur.inset()
1845 && oldTopSlice.idx() == cur.idx()
1846 && !sel // sel is a backup of cur.selection() at the biginning of the function.
1847 && !cur.selection())
1848 // FIXME: it would be better if we could just do this
1850 //if (cur.result().update() != Update::FitCursor)
1853 // But some LFUNs do not set Update::FitCursor when needed, so we
1854 // do it for all. This is not very harmfull as FitCursor will provoke
1855 // a full redraw only if needed but still, a proper review of all LFUN
1856 // should be done and this needsUpdate boolean can then be removed.
1857 cur.updateFlags(Update::FitCursor);
1859 cur.updateFlags(Update::Force | Update::FitCursor);
1863 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1864 FuncStatus & flag) const
1866 BOOST_ASSERT(cur.text() == this);
1868 Font const & font = cur.real_current_font;
1869 FontInfo const & fontinfo = font.fontInfo();
1871 InsetCode code = NO_CODE;
1873 switch (cmd.action) {
1875 case LFUN_DEPTH_DECREMENT:
1876 enable = changeDepthAllowed(cur, DEC_DEPTH);
1879 case LFUN_DEPTH_INCREMENT:
1880 enable = changeDepthAllowed(cur, INC_DEPTH);
1884 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1887 case LFUN_BIBITEM_INSERT:
1888 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1892 case LFUN_DIALOG_SHOW_NEW_INSET:
1893 if (cmd.argument() == "bibitem")
1894 code = BIBITEM_CODE;
1895 else if (cmd.argument() == "bibtex")
1897 else if (cmd.argument() == "box")
1899 else if (cmd.argument() == "branch")
1901 else if (cmd.argument() == "citation")
1903 else if (cmd.argument() == "ert")
1905 else if (cmd.argument() == "external")
1906 code = EXTERNAL_CODE;
1907 else if (cmd.argument() == "float")
1909 else if (cmd.argument() == "graphics")
1910 code = GRAPHICS_CODE;
1911 else if (cmd.argument() == "href")
1912 code = HYPERLINK_CODE;
1913 else if (cmd.argument() == "include")
1914 code = INCLUDE_CODE;
1915 else if (cmd.argument() == "index")
1917 else if (cmd.argument() == "nomenclature")
1918 code = NOMENCL_CODE;
1919 else if (cmd.argument() == "label")
1921 else if (cmd.argument() == "note")
1923 else if (cmd.argument() == "ref")
1925 else if (cmd.argument() == "toc")
1927 else if (cmd.argument() == "vspace")
1929 else if (cmd.argument() == "wrap")
1931 else if (cmd.argument() == "listings")
1932 code = LISTINGS_CODE;
1935 case LFUN_ERT_INSERT:
1938 case LFUN_LISTING_INSERT:
1939 code = LISTINGS_CODE;
1941 case LFUN_FOOTNOTE_INSERT:
1944 case LFUN_TABULAR_INSERT:
1945 code = TABULAR_CODE;
1947 case LFUN_MARGINALNOTE_INSERT:
1950 case LFUN_FLOAT_INSERT:
1951 case LFUN_FLOAT_WIDE_INSERT:
1954 case LFUN_WRAP_INSERT:
1957 case LFUN_FLOAT_LIST:
1958 code = FLOAT_LIST_CODE;
1961 case LFUN_LIST_INSERT:
1964 case LFUN_THEOREM_INSERT:
1965 code = THEOREM_CODE;
1968 case LFUN_CAPTION_INSERT:
1969 code = CAPTION_CODE;
1971 case LFUN_NOTE_INSERT:
1974 case LFUN_FLEX_INSERT: {
1976 string s = cmd.getArg(0);
1977 InsetLayout il = cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
1978 if (il.lyxtype != "charstyle" &&
1979 il.lyxtype != "custom" &&
1980 il.lyxtype != "element" &&
1981 il.lyxtype != "standard")
1985 case LFUN_BOX_INSERT:
1988 case LFUN_BRANCH_INSERT:
1990 if (cur.buffer().masterBuffer()->params().branchlist().empty())
1993 case LFUN_LABEL_INSERT:
1996 case LFUN_INFO_INSERT:
1999 case LFUN_OPTIONAL_INSERT:
2001 enable = cur.paragraph().insetList().count(OPTARG_CODE)
2002 < cur.paragraph().layout()->optionalargs;
2004 case LFUN_ENVIRONMENT_INSERT:
2007 case LFUN_INDEX_INSERT:
2010 case LFUN_INDEX_PRINT:
2011 code = INDEX_PRINT_CODE;
2013 case LFUN_NOMENCL_INSERT:
2014 code = NOMENCL_CODE;
2016 case LFUN_NOMENCL_PRINT:
2017 code = NOMENCL_PRINT_CODE;
2019 case LFUN_TOC_INSERT:
2022 case LFUN_HYPERLINK_INSERT:
2023 code = HYPERLINK_CODE;
2025 case LFUN_QUOTE_INSERT:
2026 // always allow this, since we will inset a raw quote
2027 // if an inset is not allowed.
2029 case LFUN_HFILL_INSERT:
2030 case LFUN_SPECIALCHAR_INSERT:
2031 code = SPECIALCHAR_CODE;
2033 case LFUN_SPACE_INSERT:
2034 // slight hack: we know this is allowed in math mode
2039 case LFUN_INSET_MODIFY:
2040 // We need to disable this, because we may get called for a
2042 // InsetTabular::getStatus() -> InsetText::getStatus()
2043 // and we don't handle LFUN_INSET_MODIFY.
2047 case LFUN_FONT_EMPH:
2048 flag.setOnOff(fontinfo.emph() == FONT_ON);
2051 case LFUN_FONT_NOUN:
2052 flag.setOnOff(fontinfo.noun() == FONT_ON);
2055 case LFUN_FONT_BOLD:
2056 flag.setOnOff(fontinfo.series() == BOLD_SERIES);
2059 case LFUN_FONT_SANS:
2060 flag.setOnOff(fontinfo.family() == SANS_FAMILY);
2063 case LFUN_FONT_ROMAN:
2064 flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
2067 case LFUN_FONT_TYPEWRITER:
2068 flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
2073 enable = cur.selection();
2077 if (cmd.argument().empty()) {
2078 if (theClipboard().isInternal())
2079 enable = cap::numberOfSelections() > 0;
2081 enable = !theClipboard().empty();
2085 // we have an argument
2086 string const arg = to_utf8(cmd.argument());
2087 if (isStrUnsignedInt(arg)) {
2088 // it's a number and therefore means the internal stack
2089 unsigned int n = convert<unsigned int>(arg);
2090 enable = cap::numberOfSelections() > n;
2094 // explicit graphics type?
2095 if ((arg == "pdf" && theClipboard().hasGraphicsContents(Clipboard::PdfGraphicsType))
2096 || (arg == "png" && theClipboard().hasGraphicsContents(Clipboard::PngGraphicsType))
2097 || (arg == "jpeg" && theClipboard().hasGraphicsContents(Clipboard::JpegGraphicsType))
2098 || (arg == "linkback" && theClipboard().hasGraphicsContents(Clipboard::LinkBackGraphicsType))) {
2108 case LFUN_CLIPBOARD_PASTE:
2109 enable = !theClipboard().empty();
2112 case LFUN_PRIMARY_SELECTION_PASTE:
2113 enable = cur.selection() || !theSelection().empty();
2116 case LFUN_PARAGRAPH_MOVE_UP:
2117 enable = cur.pit() > 0 && !cur.selection();
2120 case LFUN_PARAGRAPH_MOVE_DOWN:
2121 enable = cur.pit() < cur.lastpit() && !cur.selection();
2124 case LFUN_INSET_DISSOLVE:
2125 if (!cmd.argument().empty()) {
2126 InsetLayout il = cur.inset().getLayout(cur.buffer().params());
2127 enable = cur.inset().lyxCode() == FLEX_CODE
2128 && il.lyxtype == to_utf8(cmd.argument());
2130 enable = !isMainText(cur.bv().buffer())
2131 && cur.inset().nargs() == 1;
2135 case LFUN_CHANGE_ACCEPT:
2136 case LFUN_CHANGE_REJECT:
2137 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
2138 // In principle, these LFUNs should only be enabled if there
2139 // is a change at the current position/in the current selection.
2140 // However, without proper optimizations, this will inevitably
2141 // result in unacceptable performance - just imagine a user who
2142 // wants to select the complete content of a long document.
2146 case LFUN_OUTLINE_UP:
2147 case LFUN_OUTLINE_DOWN:
2148 case LFUN_OUTLINE_IN:
2149 case LFUN_OUTLINE_OUT:
2150 enable = (cur.paragraph().layout()->toclevel != Layout::NOT_IN_TOC);
2153 case LFUN_WORD_DELETE_FORWARD:
2154 case LFUN_WORD_DELETE_BACKWARD:
2155 case LFUN_LINE_DELETE:
2156 case LFUN_WORD_FORWARD:
2157 case LFUN_WORD_BACKWARD:
2158 case LFUN_WORD_RIGHT:
2159 case LFUN_WORD_LEFT:
2160 case LFUN_CHAR_FORWARD:
2161 case LFUN_CHAR_FORWARD_SELECT:
2162 case LFUN_CHAR_BACKWARD:
2163 case LFUN_CHAR_BACKWARD_SELECT:
2164 case LFUN_CHAR_LEFT:
2165 case LFUN_CHAR_LEFT_SELECT:
2166 case LFUN_CHAR_RIGHT:
2167 case LFUN_CHAR_RIGHT_SELECT:
2169 case LFUN_UP_SELECT:
2171 case LFUN_DOWN_SELECT:
2172 case LFUN_PARAGRAPH_UP_SELECT:
2173 case LFUN_PARAGRAPH_DOWN_SELECT:
2174 case LFUN_SCREEN_UP_SELECT:
2175 case LFUN_SCREEN_DOWN_SELECT:
2176 case LFUN_LINE_BEGIN_SELECT:
2177 case LFUN_LINE_END_SELECT:
2178 case LFUN_WORD_FORWARD_SELECT:
2179 case LFUN_WORD_BACKWARD_SELECT:
2180 case LFUN_WORD_RIGHT_SELECT:
2181 case LFUN_WORD_LEFT_SELECT:
2182 case LFUN_WORD_SELECT:
2183 case LFUN_PARAGRAPH_UP:
2184 case LFUN_PARAGRAPH_DOWN:
2185 case LFUN_LINE_BEGIN:
2186 case LFUN_LINE_BREAK:
2189 case LFUN_CHAR_DELETE_FORWARD:
2190 case LFUN_DELETE_FORWARD_SKIP:
2191 case LFUN_CHAR_DELETE_BACKWARD:
2192 case LFUN_DELETE_BACKWARD_SKIP:
2193 case LFUN_BREAK_PARAGRAPH:
2194 case LFUN_BREAK_PARAGRAPH_SKIP:
2195 case LFUN_PARAGRAPH_SPACING:
2196 case LFUN_INSET_INSERT:
2197 case LFUN_WORD_UPCASE:
2198 case LFUN_WORD_LOWCASE:
2199 case LFUN_WORD_CAPITALIZE:
2200 case LFUN_CHARS_TRANSPOSE:
2201 case LFUN_SERVER_GET_XY:
2202 case LFUN_SERVER_SET_XY:
2203 case LFUN_SERVER_GET_FONT:
2204 case LFUN_SERVER_GET_LAYOUT:
2206 case LFUN_DATE_INSERT:
2207 case LFUN_SELF_INSERT:
2208 case LFUN_LINE_INSERT:
2209 case LFUN_NEWPAGE_INSERT:
2210 case LFUN_PAGEBREAK_INSERT:
2211 case LFUN_CLEARPAGE_INSERT:
2212 case LFUN_CLEARDOUBLEPAGE_INSERT:
2213 case LFUN_MATH_DISPLAY:
2214 case LFUN_MATH_IMPORT_SELECTION:
2215 case LFUN_MATH_MODE:
2216 case LFUN_MATH_MACRO:
2217 case LFUN_MATH_MATRIX:
2218 case LFUN_MATH_DELIM:
2219 case LFUN_MATH_BIGDELIM:
2220 case LFUN_MATH_INSERT:
2221 case LFUN_MATH_SUBSCRIPT:
2222 case LFUN_MATH_SUPERSCRIPT:
2223 case LFUN_FONT_DEFAULT:
2224 case LFUN_FONT_UNDERLINE:
2225 case LFUN_FONT_SIZE:
2227 case LFUN_FONT_FREE_APPLY:
2228 case LFUN_FONT_FREE_UPDATE:
2229 case LFUN_LAYOUT_PARAGRAPH:
2230 case LFUN_PARAGRAPH_UPDATE:
2231 case LFUN_ACCENT_UMLAUT:
2232 case LFUN_ACCENT_CIRCUMFLEX:
2233 case LFUN_ACCENT_GRAVE:
2234 case LFUN_ACCENT_ACUTE:
2235 case LFUN_ACCENT_TILDE:
2236 case LFUN_ACCENT_CEDILLA:
2237 case LFUN_ACCENT_MACRON:
2238 case LFUN_ACCENT_DOT:
2239 case LFUN_ACCENT_UNDERDOT:
2240 case LFUN_ACCENT_UNDERBAR:
2241 case LFUN_ACCENT_CARON:
2242 case LFUN_ACCENT_SPECIAL_CARON:
2243 case LFUN_ACCENT_BREVE:
2244 case LFUN_ACCENT_TIE:
2245 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2246 case LFUN_ACCENT_CIRCLE:
2247 case LFUN_ACCENT_OGONEK:
2248 case LFUN_THESAURUS_ENTRY:
2249 case LFUN_PARAGRAPH_PARAMS_APPLY:
2250 case LFUN_PARAGRAPH_PARAMS:
2252 case LFUN_BUFFER_END:
2253 case LFUN_BUFFER_BEGIN:
2254 case LFUN_BUFFER_BEGIN_SELECT:
2255 case LFUN_BUFFER_END_SELECT:
2256 case LFUN_UNICODE_INSERT:
2257 // these are handled in our dispatch()
2266 && (cur.empty() || !cur.inset().insetAllowed(code)))
2269 flag.enabled(enable);
2274 void Text::pasteString(Cursor & cur, docstring const & clip,
2277 cur.clearSelection();
2278 if (!clip.empty()) {
2281 insertStringAsParagraphs(cur, clip);
2283 insertStringAsLines(cur, clip);