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.
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
24 #include "buffer_funcs.h"
25 #include "bufferparams.h"
26 #include "BufferView.h"
28 #include "coordcache.h"
29 #include "CutAndPaste.h"
31 #include "dispatchresult.h"
33 #include "funcrequest.h"
37 #include "LyXAction.h"
42 #include "paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
48 #include "frontends/Dialogs.h"
49 #include "frontends/LyXView.h"
51 #include "insets/insetcommand.h"
52 #include "insets/insetfloatlist.h"
53 #include "insets/insetnewline.h"
54 #include "insets/insetquotes.h"
55 #include "insets/insetspecialchar.h"
56 #include "insets/insettext.h"
58 #include "support/lstrings.h"
59 #include "support/lyxlib.h"
60 #include "support/convert.h"
61 #include "support/lyxtime.h"
63 #include "mathed/math_hullinset.h"
64 #include "mathed/math_macrotemplate.h"
66 #include <boost/current_function.hpp>
73 using lyx::cap::copySelection;
74 using lyx::cap::cutSelection;
75 using lyx::cap::pasteSelection;
76 using lyx::cap::replaceSelection;
78 using lyx::support::isStrUnsignedInt;
79 using lyx::support::token;
83 using std::istringstream;
86 extern string current_layout;
92 LyXFont freefont(LyXFont::ALL_IGNORE);
93 bool toggleall = false;
96 void toggleAndShow(LCursor & cur, LyXText * text,
97 LyXFont const & font, bool toggleall = true)
99 text->toggleFree(cur, font, toggleall);
101 if (font.language() != ignore_language ||
102 font.number() != LyXFont::IGNORE) {
103 Paragraph & par = cur.paragraph();
104 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
105 if (cur.boundary() !=
106 text->bidi.isBoundary(cur.buffer(), par,
108 text->real_current_font))
109 text->setCursor(cur, cur.pit(), cur.pos(),
110 false, !cur.boundary());
115 void moveCursor(LCursor & cur, bool selecting)
117 if (selecting || cur.mark())
119 if (!cur.selection())
120 cur.bv().haveSelection(false);
121 cur.bv().switchKeyMap();
125 void finishChange(LCursor & cur, bool selecting)
128 moveCursor(cur, selecting);
132 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
135 string sel = cur.selectionAsString(false);
136 //lyxerr << "selection is: '" << sel << "'" << endl;
138 // It may happen that sel is empty but there is a selection
139 replaceSelection(cur);
142 const int old_pos = cur.pos();
143 cur.insert(new MathHullInset("simple"));
144 BOOST_ASSERT(old_pos == cur.pos());
145 cur.nextInset()->edit(cur, true);
146 // don't do that also for LFUN_MATH_MODE
147 // unless you want end up with always changing
148 // to mathrm when opening an inlined inset --
149 // I really hate "LyXfunc overloading"...
151 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
152 // Avoid an unnecessary undo step if cmd.argument
154 if (!cmd.argument.empty())
155 cur.dispatch(FuncRequest(LFUN_INSERT_MATH,
158 // create a macro if we see "\\newcommand"
159 // somewhere, and an ordinary formula
161 istringstream is(sel);
162 if (sel.find("\\newcommand") == string::npos
163 && sel.find("\\def") == string::npos)
165 MathHullInset * formula = new MathHullInset;
168 formula->read(cur.buffer(), lex);
169 if (formula->getType() == "none")
170 // Don't create pseudo formulas if
171 // delimiters are left out
172 formula->mutate("simple");
175 cur.insert(new MathMacroTemplate(is));
177 cur.message(N_("Math editor mode"));
186 string const freefont2string()
189 if (font2string(freefont, toggleall, data))
196 bool LyXText::cursorPrevious(LCursor & cur)
198 pos_type cpos = cur.pos();
199 lyx::pit_type cpar = cur.pit();
201 int x = cur.x_target();
203 bool updated = setCursorFromCoordinates(cur, x, 0);
206 updated |= cursorUp(cur);
208 if (cpar == cur.pit() && cpos == cur.pos()) {
209 // we have a row which is taller than the workarea. The
210 // simplest solution is to move to the previous row instead.
211 updated |= cursorUp(cur);
214 cur.bv().updateScrollbar();
220 bool LyXText::cursorNext(LCursor & cur)
222 pos_type cpos = cur.pos();
223 lyx::pit_type cpar = cur.pit();
225 int x = cur.x_target();
226 bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
229 updated |= cursorDown(cur);
231 if (cpar == cur.pit() && cpos == cur.pos()) {
232 // we have a row which is taller than the workarea. The
233 // simplest solution is to move to the next row instead.
234 updated |= cursorDown(cur);
237 cur.bv().updateScrollbar();
245 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
247 lyx::cap::replaceSelection(cur);
248 cur.insert(new InsetSpecialChar(kind));
253 bool doInsertInset(LCursor & cur, LyXText * text,
254 FuncRequest const & cmd, bool edit, bool pastesel)
256 InsetBase * inset = createInset(&cur.bv(), cmd);
262 if (cur.selection()) {
263 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
266 text->insertInset(cur, inset);
269 inset->edit(cur, true);
271 if (gotsel && pastesel)
272 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
277 void update(LCursor & cur)
279 //we don't call update(true, false) directly to save a metrics call
280 if (cur.bv().fitCursor())
281 cur.bv().update(Update::Force);
288 void LyXText::number(LCursor & cur)
290 LyXFont font(LyXFont::ALL_IGNORE);
291 font.setNumber(LyXFont::TOGGLE);
292 toggleAndShow(cur, this, font);
296 bool LyXText::isRTL(Paragraph const & par) const
298 return par.isRightToLeftPar(bv()->buffer()->params());
302 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
304 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
306 BOOST_ASSERT(cur.text() == this);
307 BufferView * bv = &cur.bv();
308 CursorSlice oldTopSlice = cur.top();
309 bool oldBoundary = cur.boundary();
310 bool sel = cur.selection();
311 // Signals that, even if needsUpdate == false, an update of the
312 // cursor paragraph is required
313 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
314 LyXAction::SingleParUpdate);
315 // Signals that a full-screen update is required
316 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
317 LyXAction::NoUpdate) || singleParUpdate);
318 // Remember the old paragraph metric (_outer_ paragraph!)
319 Dimension olddim = cur.bottom().paragraph().dim();
321 switch (cmd.action) {
323 case LFUN_APPENDIX: {
324 Paragraph & par = cur.paragraph();
325 bool start = !par.params().startOfAppendix();
328 #warning The code below only makes sense at top level.
329 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
331 // ensure that we have only one start_of_appendix in this document
332 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
333 if (pars_[tmp].params().startOfAppendix()) {
335 pars_[tmp].params().startOfAppendix(false);
341 par.params().startOfAppendix(start);
343 // we can set the refreshing parameters now
344 updateCounters(cur.buffer());
348 case LFUN_DELETE_WORD_FORWARD:
349 cur.clearSelection();
350 deleteWordForward(cur);
351 finishChange(cur, false);
354 case LFUN_DELETE_WORD_BACKWARD:
355 cur.clearSelection();
356 deleteWordBackward(cur);
357 finishChange(cur, false);
360 case LFUN_DELETE_LINE_FORWARD:
361 cur.clearSelection();
362 deleteLineForward(cur);
363 finishChange(cur, false);
368 cur.clearSelection();
369 if (isRTL(cur.paragraph()))
370 needsUpdate = cursorLeftOneWord(cur);
372 needsUpdate = cursorRightOneWord(cur);
373 finishChange(cur, false);
378 cur.clearSelection();
379 if (isRTL(cur.paragraph()))
380 needsUpdate = cursorRightOneWord(cur);
382 needsUpdate = cursorLeftOneWord(cur);
383 finishChange(cur, false);
386 case LFUN_BEGINNINGBUF:
387 if (cur.depth() == 1) {
389 cur.clearSelection();
391 finishChange(cur, false);
397 case LFUN_BEGINNINGBUFSEL:
398 if (cur.depth() == 1) {
399 if (!cur.selection())
402 finishChange(cur, true);
409 if (cur.depth() == 1) {
411 cur.clearSelection();
413 finishChange(cur, false);
420 if (cur.depth() == 1) {
421 if (!cur.selection())
424 finishChange(cur, true);
432 //lyxerr << BOOST_CURRENT_FUNCTION
433 // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
434 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
435 if (isRTL(cur.paragraph()))
436 needsUpdate = cursorLeft(cur);
438 needsUpdate = cursorRight(cur);
440 if (!needsUpdate && oldTopSlice == cur.top()
441 && cur.boundary() == oldBoundary) {
443 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
449 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
450 cur.selHandle(cmd.action == LFUN_LEFTSEL);
451 if (isRTL(cur.paragraph()))
452 needsUpdate = cursorRight(cur);
454 needsUpdate = cursorLeft(cur);
456 if (!needsUpdate && oldTopSlice == cur.top()
457 && cur.boundary() == oldBoundary) {
459 cmd = FuncRequest(LFUN_FINISHED_LEFT);
466 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
467 cur.selHandle(cmd.action == LFUN_UPSEL);
469 needsUpdate = cursorUp(cur);
470 if (!needsUpdate && oldTopSlice == cur.top()
471 && cur.boundary() == oldBoundary) {
473 cmd = FuncRequest(LFUN_FINISHED_UP);
480 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
481 cur.selHandle(cmd.action == LFUN_DOWNSEL);
482 needsUpdate = cursorDown(cur);
483 if (!needsUpdate && oldTopSlice == cur.top() &&
484 cur.boundary() == oldBoundary)
487 cmd = FuncRequest(LFUN_FINISHED_DOWN);
491 case LFUN_UP_PARAGRAPH:
493 cur.clearSelection();
494 needsUpdate = cursorUpParagraph(cur);
495 finishChange(cur, false);
498 case LFUN_UP_PARAGRAPHSEL:
499 if (!cur.selection())
501 cursorUpParagraph(cur);
502 finishChange(cur, true);
505 case LFUN_DOWN_PARAGRAPH:
507 cur.clearSelection();
508 needsUpdate = cursorDownParagraph(cur);
509 finishChange(cur, false);
512 case LFUN_DOWN_PARAGRAPHSEL:
513 if (!cur.selection())
515 cursorDownParagraph(cur);
516 finishChange(cur, true);
521 if (!cur.selection())
524 finishChange(cur, true);
529 if (!cur.selection())
532 finishChange(cur, true);
537 if (!cur.selection())
540 finishChange(cur, true);
545 if (!cur.selection())
548 finishChange(cur, true);
551 case LFUN_WORDRIGHTSEL:
552 if (!cur.selection())
554 if (isRTL(cur.paragraph()))
555 cursorLeftOneWord(cur);
557 cursorRightOneWord(cur);
558 finishChange(cur, true);
561 case LFUN_WORDLEFTSEL:
562 if (!cur.selection())
564 if (isRTL(cur.paragraph()))
565 cursorRightOneWord(cur);
567 cursorLeftOneWord(cur);
568 finishChange(cur, true);
572 selectWord(cur, lyx::WHOLE_WORD);
573 finishChange(cur, true);
580 cur.clearSelection();
581 finishChange(cur, false);
582 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
584 cmd = FuncRequest(LFUN_FINISHED_UP);
586 needsUpdate = cursorPrevious(cur);
593 cur.clearSelection();
594 finishChange(cur, false);
595 if (cur.pit() == cur.lastpit()
596 && cur.textRow().endpos() == cur.lastpos()) {
598 cmd = FuncRequest(LFUN_FINISHED_DOWN);
600 needsUpdate = cursorNext(cur);
606 cur.clearSelection();
608 finishChange(cur, false);
613 cur.clearSelection();
615 finishChange(cur, false);
618 case LFUN_BREAKLINE: {
619 // Not allowed by LaTeX (labels or empty par)
620 if (cur.pos() > cur.paragraph().beginOfBody()) {
621 lyx::cap::replaceSelection(cur);
622 cur.insert(new InsetNewline);
624 moveCursor(cur, false);
630 if (!cur.selection()) {
631 needsUpdate = Delete(cur);
633 // It is possible to make it a lot faster still
634 // just comment out the line below...
636 cutSelection(cur, true, false);
638 moveCursor(cur, false);
641 case LFUN_DELETE_SKIP:
642 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
643 if (!cur.selection()) {
644 if (cur.pos() == cur.lastpos()) {
651 cutSelection(cur, true, false);
657 if (!cur.selection()) {
658 if (bv->owner()->getIntl().getTransManager().backspace()) {
659 needsUpdate = backspace(cur);
661 // It is possible to make it a lot faster still
662 // just comment out the line below...
665 cutSelection(cur, true, false);
670 case LFUN_BACKSPACE_SKIP:
671 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
672 if (!cur.selection()) {
676 //CursorSlice cur = cursor();
680 cutSelection(cur, true, false);
684 case LFUN_BREAKPARAGRAPH:
685 lyx::cap::replaceSelection(cur);
686 breakParagraph(cur, 0);
691 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
692 lyx::cap::replaceSelection(cur);
693 breakParagraph(cur, 1);
698 case LFUN_BREAKPARAGRAPH_SKIP: {
699 // When at the beginning of a paragraph, remove
700 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
701 lyx::cap::replaceSelection(cur);
703 cur.paragraph().params().labelWidthString(string());
705 breakParagraph(cur, 0);
711 case LFUN_PARAGRAPH_SPACING: {
712 Paragraph & par = cur.paragraph();
713 Spacing::Space cur_spacing = par.params().spacing().getSpace();
714 string cur_value = "1.0";
715 if (cur_spacing == Spacing::Other)
716 cur_value = par.params().spacing().getValueAsString();
718 istringstream is(cmd.argument);
721 Spacing::Space new_spacing = cur_spacing;
722 string new_value = cur_value;
724 lyxerr << "Missing argument to `paragraph-spacing'"
726 } else if (tmp == "single") {
727 new_spacing = Spacing::Single;
728 } else if (tmp == "onehalf") {
729 new_spacing = Spacing::Onehalf;
730 } else if (tmp == "double") {
731 new_spacing = Spacing::Double;
732 } else if (tmp == "other") {
733 new_spacing = Spacing::Other;
734 string tmpval = "0.0";
736 lyxerr << "new_value = " << tmpval << endl;
739 } else if (tmp == "default") {
740 new_spacing = Spacing::Default;
742 lyxerr << _("Unknown spacing argument: ")
743 << cmd.argument << endl;
745 if (cur_spacing != new_spacing || cur_value != new_value)
746 par.params().spacing(Spacing(new_spacing, new_value));
750 case LFUN_INSET_INSERT: {
752 InsetBase * inset = createInset(bv, cmd);
754 insertInset(cur, inset);
760 case LFUN_INSET_SETTINGS:
761 cur.inset().showInsetDialog(bv);
764 case LFUN_NEXT_INSET_TOGGLE: {
765 InsetBase * inset = cur.nextInset();
766 // this is the real function we want to invoke
767 cmd = FuncRequest(LFUN_INSET_TOGGLE);
769 // if there is an inset at cursor, see whether it
772 LCursor tmpcur = cur;
773 tmpcur.pushLeft(*inset);
774 inset->dispatch(tmpcur, cmd);
775 if (tmpcur.result().dispatched()) {
776 cur.clearSelection();
780 // if it did not work, try the underlying inset.
781 if (!cur.result().dispatched())
782 cur.inset().dispatch(cur, cmd);
786 case LFUN_SPACE_INSERT:
787 if (cur.paragraph().layout()->free_spacing)
788 insertChar(cur, ' ');
790 doInsertInset(cur, this, cmd, false, false);
793 moveCursor(cur, false);
796 case LFUN_HYPHENATION:
797 specialChar(cur, InsetSpecialChar::HYPHENATION);
800 case LFUN_LIGATURE_BREAK:
801 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
805 specialChar(cur, InsetSpecialChar::LDOTS);
808 case LFUN_END_OF_SENTENCE:
809 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
812 case LFUN_MENU_SEPARATOR:
813 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
816 case LFUN_UPCASE_WORD:
817 changeCase(cur, LyXText::text_uppercase);
820 case LFUN_LOWCASE_WORD:
821 changeCase(cur, LyXText::text_lowercase);
824 case LFUN_CAPITALIZE_WORD:
825 changeCase(cur, LyXText::text_capitalization);
828 case LFUN_TRANSPOSE_CHARS:
833 cur.message(_("Paste"));
834 lyx::cap::replaceSelection(cur);
835 if (isStrUnsignedInt(cmd.argument))
836 pasteSelection(cur, convert<unsigned int>(cmd.argument));
838 pasteSelection(cur, 0);
839 cur.clearSelection(); // bug 393
845 cutSelection(cur, true, true);
846 cur.message(_("Cut"));
851 cur.message(_("Copy"));
855 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
856 + convert<string>(cursorY(cur.top(), cur.boundary())));
862 istringstream is(cmd.argument);
865 lyxerr << "SETXY: Could not parse coordinates in '"
866 << cmd.argument << std::endl;
868 setCursorFromCoordinates(cur, x, y);
873 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
875 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
882 cur.message(cur.paragraph().layout()->name());
886 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
887 << cmd.argument << endl;
889 // This is not the good solution to the empty argument
890 // problem, but it will hopefully suffice for 1.2.0.
891 // The correct solution would be to augument the
892 // function list/array with information about what
893 // functions needs arguments and their type.
894 if (cmd.argument.empty()) {
895 cur.errorMessage(_("LyX function 'layout' needs an argument."));
899 // Derive layout number from given argument (string)
900 // and current buffer's textclass (number)
901 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
902 bool hasLayout = tclass.hasLayout(cmd.argument);
903 string layout = cmd.argument;
905 // If the entry is obsolete, use the new one instead.
907 string const & obs = tclass[layout]->obsoleted_by();
913 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
918 bool change_layout = (current_layout != layout);
920 if (!change_layout && cur.selection() &&
921 cur.selBegin().pit() != cur.selEnd().pit())
923 pit_type spit = cur.selBegin().pit();
924 pit_type epit = cur.selEnd().pit() + 1;
925 while (spit != epit) {
926 if (pars_[spit].layout()->name() != current_layout) {
927 change_layout = true;
935 current_layout = layout;
936 setLayout(cur, layout);
937 bv->owner()->setLayout(layout);
943 case LFUN_PASTESELECTION: {
944 cur.clearSelection();
945 string const clip = bv->getClipboard();
948 if (cmd.argument == "paragraph")
949 insertStringAsParagraphs(cur, clip);
951 insertStringAsLines(cur, clip);
957 lyx::cap::replaceSelection(cur);
958 Paragraph & par = cur.paragraph();
959 lyx::pos_type pos = cur.pos();
963 else if (cur.prevInset() && cur.prevInset()->isSpace())
966 c = par.getChar(pos - 1);
968 LyXLayout_ptr const & style = par.layout();
970 BufferParams const & bufparams = bv->buffer()->params();
971 if (!style->pass_thru
972 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
973 string arg = cmd.argument;
975 cur.insert(new InsetQuotes(c,
976 bufparams.quotes_language,
977 InsetQuotes::SingleQ));
979 cur.insert(new InsetQuotes(c,
980 bufparams.quotes_language,
981 InsetQuotes::DoubleQ));
985 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
989 case LFUN_DATE_INSERT:
990 if (cmd.argument.empty())
991 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
992 lyx::formatted_time(lyx::current_time())));
994 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
995 lyx::formatted_time(lyx::current_time(), cmd.argument)));
998 case LFUN_MOUSE_TRIPLE:
999 if (cmd.button() == mouse_button::button1) {
1005 bv->haveSelection(cur.selection());
1009 case LFUN_MOUSE_DOUBLE:
1010 if (cmd.button() == mouse_button::button1) {
1011 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1013 bv->haveSelection(cur.selection());
1017 // Single-click on work area
1018 case LFUN_MOUSE_PRESS: {
1019 // Right click on a footnote flag opens float menu
1020 if (cmd.button() == mouse_button::button3) {
1021 cur.clearSelection();
1025 // Middle button press pastes if we have a selection
1026 // We do this here as if the selection was inside an inset
1027 // it could get cleared on the unlocking of the inset so
1028 // we have to check this first
1029 bool paste_internally = false;
1030 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1031 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1032 paste_internally = true;
1035 bv->mouseSetCursor(cur);
1037 // Insert primary selection with middle mouse
1038 // if there is a local selection in the current buffer,
1040 if (cmd.button() == mouse_button::button2) {
1041 if (paste_internally)
1042 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1044 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1050 case LFUN_MOUSE_MOTION: {
1051 // Only use motion with button 1
1052 //if (cmd.button() != mouse_button::button1)
1055 // ignore motions deeper nested than the real anchor
1056 LCursor & bvcur = cur.bv().cursor();
1057 if (bvcur.anchor_.hasPart(cur)) {
1058 CursorSlice old = bvcur.top();
1060 int const wh = bv->workHeight();
1061 int const y = std::max(0, std::min(wh - 1, cmd.y));
1063 setCursorFromCoordinates(cur, cmd.x, y);
1064 cur.x_target() = cmd.x;
1069 // This is to allow jumping over large insets
1070 if (cur.top() == old) {
1077 if (cur.top() == old)
1080 // don't set anchor_
1081 bvcur.setCursor(cur);
1082 bvcur.selection() = true;
1083 //lyxerr << "MOTION: " << bv->cursor() << endl;
1091 case LFUN_MOUSE_RELEASE: {
1092 if (cmd.button() == mouse_button::button2)
1096 if (cmd.button() == mouse_button::button1)
1097 bv->haveSelection(cur.selection());
1100 bv->owner()->updateMenubar();
1101 bv->owner()->updateToolbars();
1105 case LFUN_SELFINSERT: {
1106 if (cmd.argument.empty())
1109 // Automatically delete the currently selected
1110 // text and replace it with what is being
1111 // typed in now. Depends on lyxrc settings
1112 // "auto_region_delete", which defaults to
1115 if (lyxrc.auto_region_delete) {
1116 if (cur.selection())
1117 cutSelection(cur, false, false);
1118 bv->haveSelection(false);
1121 cur.clearSelection();
1122 LyXFont const old_font = real_current_font;
1124 string::const_iterator cit = cmd.argument.begin();
1125 string::const_iterator end = cmd.argument.end();
1126 for (; cit != end; ++cit)
1127 bv->owner()->getIntl().getTransManager().
1128 TranslateAndInsert(*cit, this);
1131 moveCursor(cur, false);
1132 bv->updateScrollbar();
1137 InsetCommandParams p("url");
1138 string const data = InsetCommandMailer::params2string("url", p);
1139 bv->owner()->getDialogs().show("url", data, 0);
1143 case LFUN_HTMLURL: {
1144 InsetCommandParams p("htmlurl");
1145 string const data = InsetCommandMailer::params2string("url", p);
1146 bv->owner()->getDialogs().show("url", data, 0);
1150 case LFUN_INSERT_LABEL: {
1151 // Try to generate a valid label
1152 string const contents = cmd.argument.empty() ?
1153 cur.getPossibleLabel() : cmd.argument;
1155 InsetCommandParams p("label", contents);
1156 string const data = InsetCommandMailer::params2string("label", p);
1158 if (cmd.argument.empty()) {
1159 bv->owner()->getDialogs().show("label", data, 0);
1161 FuncRequest fr(LFUN_INSET_INSERT, data);
1169 case LFUN_INSET_LIST:
1170 case LFUN_INSET_THEOREM:
1171 case LFUN_INSET_CAPTION:
1173 case LFUN_INSERT_NOTE:
1174 case LFUN_INSERT_CHARSTYLE:
1175 case LFUN_INSERT_BOX:
1176 case LFUN_INSERT_BRANCH:
1177 case LFUN_INSERT_BIBITEM:
1178 case LFUN_INSET_ERT:
1179 case LFUN_INSET_FOOTNOTE:
1180 case LFUN_INSET_MARGINAL:
1181 case LFUN_INSET_OPTARG:
1182 case LFUN_ENVIRONMENT_INSERT:
1183 // Open the inset, and move the current selection
1185 doInsertInset(cur, this, cmd, true, true);
1189 case LFUN_TABULAR_INSERT:
1190 // if there were no arguments, just open the dialog
1191 if (doInsertInset(cur, this, cmd, false, true))
1194 bv->owner()->getDialogs().show("tabularcreate");
1198 case LFUN_INSET_FLOAT:
1199 case LFUN_INSET_WIDE_FLOAT:
1200 case LFUN_INSET_WRAP:
1201 doInsertInset(cur, this, cmd, true, true);
1203 // FIXME: the "Caption" name should not be hardcoded,
1204 // but given by the float definition.
1205 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1208 case LFUN_INDEX_INSERT: {
1209 InsetBase * inset = createInset(&cur.bv(), cmd);
1214 cur.clearSelection();
1215 insertInset(cur, inset);
1216 inset->edit(cur, true);
1221 case LFUN_INDEX_PRINT:
1222 case LFUN_TOC_INSERT:
1224 case LFUN_INSERT_LINE:
1225 case LFUN_INSERT_PAGEBREAK:
1227 doInsertInset(cur, this, cmd, false, false);
1231 case LFUN_DEPTH_MIN:
1232 changeDepth(cur, DEC_DEPTH);
1235 case LFUN_DEPTH_PLUS:
1236 changeDepth(cur, INC_DEPTH);
1239 case LFUN_MATH_DISPLAY:
1240 mathDispatch(cur, cmd, true);
1243 case LFUN_MATH_IMPORT_SELECTION:
1244 case LFUN_MATH_MODE:
1245 if (cmd.argument == "on")
1246 // don't pass "on" as argument
1247 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1249 mathDispatch(cur, cmd, false);
1252 case LFUN_MATH_MACRO:
1253 if (cmd.argument.empty())
1254 cur.errorMessage(N_("Missing argument"));
1256 string s = cmd.argument;
1257 string const s1 = token(s, ' ', 1);
1258 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1259 string const s2 = token(s, ' ', 2);
1260 string const type = s2.empty() ? "newcommand" : s2;
1261 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type));
1262 //cur.nextInset()->edit(cur, true);
1266 // passthrough hat and underscore outside mathed:
1267 case LFUN_SUBSCRIPT:
1268 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1270 case LFUN_SUPERSCRIPT:
1271 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1274 case LFUN_INSERT_MATH:
1275 case LFUN_INSERT_MATRIX:
1276 case LFUN_MATH_DELIM: {
1277 cur.insert(new MathHullInset("simple"));
1278 cur.dispatch(FuncRequest(LFUN_RIGHT));
1284 LyXFont font(LyXFont::ALL_IGNORE);
1285 font.setEmph(LyXFont::TOGGLE);
1286 toggleAndShow(cur, this, font);
1291 LyXFont font(LyXFont::ALL_IGNORE);
1292 font.setSeries(LyXFont::BOLD_SERIES);
1293 toggleAndShow(cur, this, font);
1298 LyXFont font(LyXFont::ALL_IGNORE);
1299 font.setNoun(LyXFont::TOGGLE);
1300 toggleAndShow(cur, this, font);
1305 LyXFont font(LyXFont::ALL_IGNORE);
1306 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1307 toggleAndShow(cur, this, font);
1312 LyXFont font(LyXFont::ALL_IGNORE);
1313 font.setFamily(LyXFont::SANS_FAMILY);
1314 toggleAndShow(cur, this, font);
1319 LyXFont font(LyXFont::ALL_IGNORE);
1320 font.setFamily(LyXFont::ROMAN_FAMILY);
1321 toggleAndShow(cur, this, font);
1325 case LFUN_DEFAULT: {
1326 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1327 toggleAndShow(cur, this, font);
1331 case LFUN_UNDERLINE: {
1332 LyXFont font(LyXFont::ALL_IGNORE);
1333 font.setUnderbar(LyXFont::TOGGLE);
1334 toggleAndShow(cur, this, font);
1338 case LFUN_FONT_SIZE: {
1339 LyXFont font(LyXFont::ALL_IGNORE);
1340 font.setLyXSize(cmd.argument);
1341 toggleAndShow(cur, this, font);
1345 case LFUN_LANGUAGE: {
1346 Language const * lang = languages.getLanguage(cmd.argument);
1349 LyXFont font(LyXFont::ALL_IGNORE);
1350 font.setLanguage(lang);
1351 toggleAndShow(cur, this, font);
1356 case LFUN_FREEFONT_APPLY:
1357 toggleAndShow(cur, this, freefont, toggleall);
1358 cur.message(_("Character set"));
1361 // Set the freefont using the contents of \param data dispatched from
1362 // the frontends and apply it at the current cursor location.
1363 case LFUN_FREEFONT_UPDATE: {
1366 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1369 toggleAndShow(cur, this, freefont, toggleall);
1370 cur.message(_("Character set"));
1375 case LFUN_FINISHED_LEFT:
1376 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1379 case LFUN_FINISHED_RIGHT:
1380 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1384 case LFUN_FINISHED_UP:
1385 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1389 case LFUN_FINISHED_DOWN:
1390 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1394 case LFUN_LAYOUT_PARAGRAPH: {
1396 params2string(cur.paragraph(), data);
1397 data = "show\n" + data;
1398 bv->owner()->getDialogs().show("paragraph", data);
1402 case LFUN_PARAGRAPH_UPDATE: {
1403 if (!bv->owner()->getDialogs().visible("paragraph"))
1406 params2string(cur.paragraph(), data);
1408 // Will the paragraph accept changes from the dialog?
1409 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1411 data = "update " + convert<string>(accept) + '\n' + data;
1412 bv->owner()->getDialogs().update("paragraph", data);
1417 case LFUN_CIRCUMFLEX:
1427 case LFUN_SPECIAL_CARON:
1430 case LFUN_HUNG_UMLAUT:
1433 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1434 if (!cmd.argument.empty())
1435 bv->owner()->getIntl().getTransManager()
1436 .TranslateAndInsert(cmd.argument[0], this);
1439 case LFUN_FLOAT_LIST: {
1440 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1441 if (tclass.floats().typeExist(cmd.argument)) {
1442 // not quite sure if we want this...
1444 cur.clearSelection();
1445 breakParagraph(cur);
1447 if (cur.lastpos() != 0) {
1449 breakParagraph(cur);
1452 setLayout(cur, tclass.defaultLayoutName());
1453 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1454 insertInset(cur, new InsetFloatList(cmd.argument));
1457 lyxerr << "Non-existent float type: "
1458 << cmd.argument << endl;
1463 case LFUN_ACCEPT_CHANGE: {
1468 case LFUN_REJECT_CHANGE: {
1473 case LFUN_THESAURUS_ENTRY: {
1474 string arg = cmd.argument;
1476 arg = cur.selectionAsString(false);
1478 if (arg.size() > 100 || arg.empty()) {
1479 // Get word or selection
1480 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1481 arg = cur.selectionAsString(false);
1484 bv->owner()->getDialogs().show("thesaurus", arg);
1488 case LFUN_PARAGRAPH_APPLY: {
1489 // Given data, an encoding of the ParagraphParameters
1490 // generated in the Paragraph dialog, this function sets
1491 // the current paragraph appropriately.
1492 istringstream is(cmd.argument);
1495 ParagraphParameters params;
1500 params.labelWidthString(),
1502 cur.message(_("Paragraph layout set"));
1506 case LFUN_INSET_DIALOG_SHOW: {
1507 InsetBase * inset = cur.nextInset();
1509 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1510 inset->dispatch(cur, fr);
1516 if (cur.selection()) {
1517 cur.selection() = false;
1520 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1525 lyxerr[Debug::ACTION]
1526 << BOOST_CURRENT_FUNCTION
1527 << ": Command " << cmd
1528 << " not DISPATCHED by LyXText" << endl;
1533 if (singleParUpdate)
1534 // Inserting characters does not change par height
1535 if (cur.bottom().paragraph().dim().height()
1536 == olddim.height()) {
1537 // if so, update _only_ this paragraph
1538 cur.bv().update(Update::SinglePar | Update::Force);
1542 && &oldTopSlice.inset() == &cur.inset()
1543 && oldTopSlice.idx() == cur.idx()
1545 && !cur.selection())
1552 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1553 FuncStatus & flag) const
1555 BOOST_ASSERT(cur.text() == this);
1557 LyXFont const & font = real_current_font;
1559 InsetBase::Code code = InsetBase::NO_CODE;
1561 switch (cmd.action) {
1563 case LFUN_DEPTH_MIN:
1564 enable = changeDepthAllowed(cur, DEC_DEPTH);
1567 case LFUN_DEPTH_PLUS:
1568 enable = changeDepthAllowed(cur, INC_DEPTH);
1572 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1575 case LFUN_INSERT_BIBITEM:
1576 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1579 case LFUN_DIALOG_SHOW_NEW_INSET:
1580 if (cmd.argument == "bibitem")
1581 code = InsetBase::BIBITEM_CODE;
1582 else if (cmd.argument == "bibtex")
1583 code = InsetBase::BIBTEX_CODE;
1584 else if (cmd.argument == "box")
1585 code = InsetBase::BOX_CODE;
1586 else if (cmd.argument == "branch")
1587 code = InsetBase::BRANCH_CODE;
1588 else if (cmd.argument == "citation")
1589 code = InsetBase::CITE_CODE;
1590 else if (cmd.argument == "ert")
1591 code = InsetBase::ERT_CODE;
1592 else if (cmd.argument == "external")
1593 code = InsetBase::EXTERNAL_CODE;
1594 else if (cmd.argument == "float")
1595 code = InsetBase::FLOAT_CODE;
1596 else if (cmd.argument == "graphics")
1597 code = InsetBase::GRAPHICS_CODE;
1598 else if (cmd.argument == "include")
1599 code = InsetBase::INCLUDE_CODE;
1600 else if (cmd.argument == "index")
1601 code = InsetBase::INDEX_CODE;
1602 else if (cmd.argument == "label")
1603 code = InsetBase::LABEL_CODE;
1604 else if (cmd.argument == "note")
1605 code = InsetBase::NOTE_CODE;
1606 else if (cmd.argument == "ref")
1607 code = InsetBase::REF_CODE;
1608 else if (cmd.argument == "toc")
1609 code = InsetBase::TOC_CODE;
1610 else if (cmd.argument == "url")
1611 code = InsetBase::URL_CODE;
1612 else if (cmd.argument == "vspace")
1613 code = InsetBase::VSPACE_CODE;
1614 else if (cmd.argument == "wrap")
1615 code = InsetBase::WRAP_CODE;
1618 case LFUN_INSET_ERT:
1619 code = InsetBase::ERT_CODE;
1621 case LFUN_INSET_FOOTNOTE:
1622 code = InsetBase::FOOT_CODE;
1624 case LFUN_TABULAR_INSERT:
1625 code = InsetBase::TABULAR_CODE;
1627 case LFUN_INSET_MARGINAL:
1628 code = InsetBase::MARGIN_CODE;
1630 case LFUN_INSET_FLOAT:
1631 case LFUN_INSET_WIDE_FLOAT:
1632 code = InsetBase::FLOAT_CODE;
1634 case LFUN_INSET_WRAP:
1635 code = InsetBase::WRAP_CODE;
1637 case LFUN_FLOAT_LIST:
1638 code = InsetBase::FLOAT_LIST_CODE;
1641 case LFUN_INSET_LIST:
1642 code = InsetBase::LIST_CODE;
1644 case LFUN_INSET_THEOREM:
1645 code = InsetBase::THEOREM_CODE;
1648 case LFUN_INSET_CAPTION:
1649 code = InsetBase::CAPTION_CODE;
1651 case LFUN_INSERT_NOTE:
1652 code = InsetBase::NOTE_CODE;
1654 case LFUN_INSERT_CHARSTYLE:
1655 code = InsetBase::CHARSTYLE_CODE;
1656 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1659 case LFUN_INSERT_BOX:
1660 code = InsetBase::BOX_CODE;
1662 case LFUN_INSERT_BRANCH:
1663 code = InsetBase::BRANCH_CODE;
1664 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1667 case LFUN_INSERT_LABEL:
1668 code = InsetBase::LABEL_CODE;
1670 case LFUN_INSET_OPTARG:
1671 code = InsetBase::OPTARG_CODE;
1672 enable = numberOfOptArgs(cur.paragraph())
1673 < cur.paragraph().layout()->optionalargs;
1675 case LFUN_ENVIRONMENT_INSERT:
1676 code = InsetBase::BOX_CODE;
1678 case LFUN_INDEX_INSERT:
1679 code = InsetBase::INDEX_CODE;
1681 case LFUN_INDEX_PRINT:
1682 code = InsetBase::INDEX_PRINT_CODE;
1684 case LFUN_TOC_INSERT:
1685 code = InsetBase::TOC_CODE;
1689 code = InsetBase::URL_CODE;
1692 // always allow this, since we will inset a raw quote
1693 // if an inset is not allowed.
1695 case LFUN_HYPHENATION:
1696 case LFUN_LIGATURE_BREAK:
1698 case LFUN_MENU_SEPARATOR:
1700 case LFUN_END_OF_SENTENCE:
1701 code = InsetBase::SPECIALCHAR_CODE;
1703 case LFUN_SPACE_INSERT:
1704 // slight hack: we know this is allowed in math mode
1706 code = InsetBase::SPACE_CODE;
1709 #ifdef WITH_WARNINGS
1710 #warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
1713 case LFUN_INSET_DIALOG_SHOW: {
1714 InsetBase * inset = cur.nextInset();
1717 code = inset->lyxCode();
1718 if (!(code == InsetBase::INCLUDE_CODE
1719 || code == InsetBase::BIBTEX_CODE
1720 || code == InsetBase::FLOAT_LIST_CODE
1721 || code == InsetBase::TOC_CODE))
1728 case LFUN_INSET_MODIFY:
1729 // We need to disable this, because we may get called for a
1731 // InsetTabular::getStatus() -> InsetText::getStatus()
1732 // and we don't handle LFUN_INSET_MODIFY.
1737 flag.setOnOff(font.emph() == LyXFont::ON);
1741 flag.setOnOff(font.noun() == LyXFont::ON);
1745 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1749 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1753 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1757 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1762 enable = cur.selection();
1766 enable = lyx::cap::numberOfSelections() > 0;
1769 case LFUN_DELETE_WORD_FORWARD:
1770 case LFUN_DELETE_WORD_BACKWARD:
1771 case LFUN_DELETE_LINE_FORWARD:
1772 case LFUN_WORDRIGHT:
1782 case LFUN_UP_PARAGRAPHSEL:
1783 case LFUN_DOWN_PARAGRAPHSEL:
1788 case LFUN_WORDRIGHTSEL:
1789 case LFUN_WORDLEFTSEL:
1791 case LFUN_UP_PARAGRAPH:
1792 case LFUN_DOWN_PARAGRAPH:
1797 case LFUN_BREAKLINE:
1799 case LFUN_DELETE_SKIP:
1800 case LFUN_BACKSPACE:
1801 case LFUN_BACKSPACE_SKIP:
1802 case LFUN_BREAKPARAGRAPH:
1803 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1804 case LFUN_BREAKPARAGRAPH_SKIP:
1805 case LFUN_PARAGRAPH_SPACING:
1806 case LFUN_INSET_INSERT:
1807 case LFUN_NEXT_INSET_TOGGLE:
1808 case LFUN_UPCASE_WORD:
1809 case LFUN_LOWCASE_WORD:
1810 case LFUN_CAPITALIZE_WORD:
1811 case LFUN_TRANSPOSE_CHARS:
1815 case LFUN_GETLAYOUT:
1817 case LFUN_PASTESELECTION:
1818 case LFUN_DATE_INSERT:
1819 case LFUN_SELFINSERT:
1820 case LFUN_INSERT_LINE:
1821 case LFUN_INSERT_PAGEBREAK:
1822 case LFUN_MATH_DISPLAY:
1823 case LFUN_MATH_IMPORT_SELECTION:
1824 case LFUN_MATH_MODE:
1825 case LFUN_MATH_MACRO:
1826 case LFUN_INSERT_MATH:
1827 case LFUN_INSERT_MATRIX:
1828 case LFUN_MATH_DELIM:
1829 case LFUN_SUBSCRIPT:
1830 case LFUN_SUPERSCRIPT:
1832 case LFUN_UNDERLINE:
1833 case LFUN_FONT_SIZE:
1835 case LFUN_FREEFONT_APPLY:
1836 case LFUN_FREEFONT_UPDATE:
1837 case LFUN_LAYOUT_PARAGRAPH:
1838 case LFUN_PARAGRAPH_UPDATE:
1840 case LFUN_CIRCUMFLEX:
1850 case LFUN_SPECIAL_CARON:
1853 case LFUN_HUNG_UMLAUT:
1856 case LFUN_ACCEPT_CHANGE:
1857 case LFUN_REJECT_CHANGE:
1858 case LFUN_THESAURUS_ENTRY:
1859 case LFUN_PARAGRAPH_APPLY:
1862 case LFUN_BEGINNINGBUF:
1863 case LFUN_BEGINNINGBUFSEL:
1864 case LFUN_ENDBUFSEL:
1865 // these are handled in our dispatch()
1873 if (code != InsetBase::NO_CODE
1874 && (cur.empty() || !cur.inset().insetAllowed(code)))
1877 flag.enabled(enable);