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 "FloatList.h"
21 #include "FuncStatus.h"
23 #include "bufferparams.h"
24 #include "BufferView.h"
26 #include "coordcache.h"
27 #include "CutAndPaste.h"
29 #include "dispatchresult.h"
31 #include "funcrequest.h"
39 #include "paragraph.h"
40 #include "paragraph_funcs.h"
41 #include "ParagraphParameters.h"
45 #include "frontends/Dialogs.h"
46 #include "frontends/LyXView.h"
48 #include "insets/insetcommand.h"
49 #include "insets/insetfloatlist.h"
50 #include "insets/insetnewline.h"
51 #include "insets/insetquotes.h"
52 #include "insets/insetspecialchar.h"
53 #include "insets/insettext.h"
55 #include "support/lstrings.h"
56 #include "support/lyxlib.h"
57 #include "support/convert.h"
59 #include "mathed/math_hullinset.h"
60 #include "mathed/math_macrotemplate.h"
67 using lyx::cap::copySelection;
68 using lyx::cap::cutSelection;
69 using lyx::cap::pasteSelection;
70 using lyx::cap::replaceSelection;
72 using lyx::support::isStrUnsignedInt;
73 using lyx::support::strToUnsignedInt;
74 using lyx::support::atoi;
75 using lyx::support::token;
80 using std::istringstream;
84 extern string current_layout;
90 LyXFont freefont(LyXFont::ALL_IGNORE);
91 bool toggleall = false;
94 void toggleAndShow(LCursor & cur, LyXText * text,
95 LyXFont const & font, bool toggleall = true)
97 text->toggleFree(cur, font, toggleall);
99 if (font.language() != ignore_language ||
100 font.number() != LyXFont::IGNORE) {
101 Paragraph & par = cur.paragraph();
102 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
103 if (cur.boundary() !=
104 text->bidi.isBoundary(cur.buffer(), par,
106 text->real_current_font))
107 text->setCursor(cur, cur.pit(), cur.pos(),
108 false, !cur.boundary());
113 void moveCursor(LCursor & cur, bool selecting)
115 if (selecting || cur.mark())
117 if (!cur.selection())
118 cur.bv().haveSelection(false);
119 cur.bv().switchKeyMap();
123 void finishChange(LCursor & cur, bool selecting)
126 moveCursor(cur, selecting);
130 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
133 string sel = cur.selectionAsString(false);
134 lyxerr << "selection is: '" << sel << "'" << endl;
137 const int old_pos = cur.pos();
138 cur.insert(new MathHullInset);
139 BOOST_ASSERT(old_pos == cur.pos());
140 cur.nextInset()->edit(cur, true);
141 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
142 // don't do that also for LFUN_MATH_MODE
143 // unless you want end up with always changing
144 // to mathrm when opening an inlined inset --
145 // I really hate "LyXfunc overloading"...
147 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
148 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
150 // create a macro if we see "\\newcommand"
151 // somewhere, and an ordinary formula
153 cutSelection(cur, true, true);
154 if (sel.find("\\newcommand") == string::npos
155 && sel.find("\\def") == string::npos)
157 cur.insert(new MathHullInset);
158 cur.dispatch(FuncRequest(LFUN_RIGHT));
159 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
160 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
162 istringstream is(sel);
163 cur.insert(new MathMacroTemplate(is));
166 cur.message(N_("Math editor mode"));
175 string const freefont2string()
178 if (font2string(freefont, toggleall, data))
185 bool LyXText::gotoNextInset(LCursor & cur,
186 vector<InsetBase_code> const & codes, string const & contents)
188 BOOST_ASSERT(this == cur.text());
189 pit_type end = paragraphs().size();
190 pit_type pit = cur.pit();
191 pos_type pos = cur.pos();
195 if (pos + 1 < pars_[pit].size()) {
202 } while (pit != end &&
203 !(pars_[pit].isInset(pos) &&
204 (inset = pars_[pit].getInset(pos)) != 0 &&
205 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
207 static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
213 setCursor(cur, pit, pos, false);
218 void LyXText::gotoInset(LCursor & cur,
219 vector<InsetBase_code> const & codes, bool same_content)
221 cur.clearSelection();
225 && cur.pos() < cur.lastpos()
226 && cur.paragraph().isInset(cur.pos())) {
227 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
228 if (find(codes.begin(), codes.end(), inset->lyxCode())
230 contents = static_cast<InsetCommand const *>(inset)->getContents();
233 if (!gotoNextInset(cur, codes, contents)) {
234 if (cur.pos() || cur.pit() != 0) {
235 CursorSlice tmp = cur.top();
238 if (!gotoNextInset(cur, codes, contents)) {
240 cur.message(_("No more insets"));
243 cur.message(_("No more insets"));
250 void LyXText::gotoInset(LCursor & cur, InsetBase_code code, bool same_content)
252 gotoInset(cur, vector<InsetBase_code>(1, code), same_content);
256 void LyXText::cursorPrevious(LCursor & cur)
258 pos_type cpos = cur.pos();
259 lyx::pit_type cpar = cur.pit();
261 int x = cur.x_target();
263 setCursorFromCoordinates(cur, x, 0);
266 if (cpar == cur.pit() && cpos == cur.pos()) {
267 // we have a row which is taller than the workarea. The
268 // simplest solution is to move to the previous row instead.
272 cur.bv().updateScrollbar();
277 void LyXText::cursorNext(LCursor & cur)
279 pos_type cpos = cur.pos();
280 lyx::pit_type cpar = cur.pit();
282 int x = cur.x_target();
283 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
286 if (cpar == cur.pit() && cpos == cur.pos()) {
287 // we have a row which is taller than the workarea. The
288 // simplest solution is to move to the next row instead.
292 cur.bv().updateScrollbar();
299 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
301 lyx::cap::replaceSelection(cur);
302 cur.insert(new InsetSpecialChar(kind));
307 void doInsertInset(LCursor & cur, LyXText * text,
308 FuncRequest const & cmd, bool edit, bool pastesel)
310 InsetBase * inset = createInset(&cur.bv(), cmd);
316 if (cur.selection()) {
317 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
320 text->insertInset(cur, inset);
323 inset->edit(cur, true);
325 if (gotsel && pastesel)
326 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
330 void update(LCursor & cur)
332 //we don't call update(true, false) directly to save a metrics call
333 if (cur.bv().fitCursor())
334 cur.bv().update(false, true);
341 void LyXText::number(LCursor & cur)
343 LyXFont font(LyXFont::ALL_IGNORE);
344 font.setNumber(LyXFont::TOGGLE);
345 toggleAndShow(cur, this, font);
349 bool LyXText::isRTL(Paragraph const & par) const
351 return par.isRightToLeftPar(bv()->buffer()->params());
355 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
357 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
358 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
360 BOOST_ASSERT(cur.text() == this);
361 BufferView * bv = &cur.bv();
362 CursorSlice sl = cur.top();
363 bool sel = cur.selection();
366 switch (cmd.action) {
368 case LFUN_APPENDIX: {
369 Paragraph & par = cur.paragraph();
370 bool start = !par.params().startOfAppendix();
372 // ensure that we have only one start_of_appendix in this document
373 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
374 if (pars_[tmp].params().startOfAppendix()) {
376 pars_[tmp].params().startOfAppendix(false);
382 par.params().startOfAppendix(start);
384 // we can set the refreshing parameters now
389 case LFUN_DELETE_WORD_FORWARD:
390 cur.clearSelection();
391 deleteWordForward(cur);
392 finishChange(cur, false);
395 case LFUN_DELETE_WORD_BACKWARD:
396 cur.clearSelection();
397 deleteWordBackward(cur);
398 finishChange(cur, false);
401 case LFUN_DELETE_LINE_FORWARD:
402 cur.clearSelection();
403 deleteLineForward(cur);
404 finishChange(cur, false);
410 cur.clearSelection();
411 if (isRTL(cur.paragraph()))
412 cursorLeftOneWord(cur);
414 cursorRightOneWord(cur);
415 finishChange(cur, false);
421 cur.clearSelection();
422 if (isRTL(cur.paragraph()))
423 cursorRightOneWord(cur);
425 cursorLeftOneWord(cur);
426 finishChange(cur, false);
429 case LFUN_BEGINNINGBUF:
430 if (cur.size() == 1) {
432 cur.clearSelection();
434 finishChange(cur, false);
440 case LFUN_BEGINNINGBUFSEL:
441 if (cur.size() == 1) {
442 if (!cur.selection())
445 finishChange(cur, true);
452 if (cur.size() == 1) {
454 cur.clearSelection();
456 finishChange(cur, false);
463 if (cur.size() == 1) {
464 if (!cur.selection())
467 finishChange(cur, true);
476 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
477 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
478 if (isRTL(cur.paragraph()))
482 if (sl == cur.top()) {
484 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
491 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
492 cur.selHandle(cmd.action == LFUN_LEFTSEL);
493 if (isRTL(cur.paragraph()))
497 if (sl == cur.top()) {
499 cmd = FuncRequest(LFUN_FINISHED_LEFT);
507 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
508 cur.selHandle(cmd.action == LFUN_UPSEL);
510 if (sl == cur.top()) {
512 cmd = FuncRequest(LFUN_FINISHED_UP);
520 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
521 cur.selHandle(cmd.action == LFUN_DOWNSEL);
523 if (sl == cur.top()) {
525 cmd = FuncRequest(LFUN_FINISHED_DOWN);
529 case LFUN_UP_PARAGRAPHSEL:
530 if (!cur.selection())
532 cursorUpParagraph(cur);
533 finishChange(cur, true);
536 case LFUN_DOWN_PARAGRAPHSEL:
537 if (!cur.selection())
539 cursorDownParagraph(cur);
540 finishChange(cur, true);
545 if (!cur.selection())
548 finishChange(cur, true);
553 if (!cur.selection())
556 finishChange(cur, true);
561 if (!cur.selection())
564 finishChange(cur, true);
569 if (!cur.selection())
572 finishChange(cur, true);
575 case LFUN_WORDRIGHTSEL:
576 if (!cur.selection())
578 if (isRTL(cur.paragraph()))
579 cursorLeftOneWord(cur);
581 cursorRightOneWord(cur);
582 finishChange(cur, true);
585 case LFUN_WORDLEFTSEL:
586 if (!cur.selection())
588 if (isRTL(cur.paragraph()))
589 cursorRightOneWord(cur);
591 cursorLeftOneWord(cur);
592 finishChange(cur, true);
596 selectWord(cur, lyx::WHOLE_WORD);
597 finishChange(cur, true);
601 case LFUN_UP_PARAGRAPH:
604 cur.clearSelection();
605 cursorUpParagraph(cur);
606 finishChange(cur, false);
609 case LFUN_DOWN_PARAGRAPH:
612 cur.clearSelection();
613 cursorDownParagraph(cur);
614 finishChange(cur, false);
621 cur.clearSelection();
622 finishChange(cur, false);
623 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
625 cmd = FuncRequest(LFUN_FINISHED_UP);
635 cur.clearSelection();
636 finishChange(cur, false);
637 if (cur.pit() == cur.lastpit()
638 && cur.textRow().endpos() == cur.lastpos()) {
640 cmd = FuncRequest(LFUN_FINISHED_DOWN);
648 cur.clearSelection();
650 finishChange(cur, false);
655 cur.clearSelection();
657 finishChange(cur, false);
660 case LFUN_BREAKLINE: {
661 // Not allowed by LaTeX (labels or empty par)
662 if (cur.pos() > cur.paragraph().beginOfBody()) {
663 lyx::cap::replaceSelection(cur);
664 cur.insert(new InsetNewline);
666 moveCursor(cur, false);
672 if (!cur.selection()) {
675 // It is possible to make it a lot faster still
676 // just comment out the line below...
678 cutSelection(cur, true, false);
680 moveCursor(cur, false);
683 case LFUN_DELETE_SKIP:
684 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
685 if (!cur.selection()) {
686 if (cur.pos() == cur.lastpos()) {
693 cutSelection(cur, true, false);
699 if (!cur.selection()) {
700 if (bv->owner()->getIntl().getTransManager().backspace()) {
703 // It is possible to make it a lot faster still
704 // just comment out the line below...
707 cutSelection(cur, true, false);
712 case LFUN_BACKSPACE_SKIP:
713 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
714 if (!cur.selection()) {
718 //CursorSlice cur = cursor();
722 cutSelection(cur, true, false);
726 case LFUN_BREAKPARAGRAPH:
727 lyx::cap::replaceSelection(cur);
728 breakParagraph(cur, 0);
733 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
734 lyx::cap::replaceSelection(cur);
735 breakParagraph(cur, 1);
740 case LFUN_BREAKPARAGRAPH_SKIP: {
741 // When at the beginning of a paragraph, remove
742 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
743 lyx::cap::replaceSelection(cur);
745 cur.paragraph().params().labelWidthString(string());
747 breakParagraph(cur, 0);
753 case LFUN_PARAGRAPH_SPACING: {
754 Paragraph & par = cur.paragraph();
755 Spacing::Space cur_spacing = par.params().spacing().getSpace();
756 string cur_value = "1.0";
757 if (cur_spacing == Spacing::Other)
758 cur_value = par.params().spacing().getValueAsString();
760 istringstream is(cmd.argument);
763 Spacing::Space new_spacing = cur_spacing;
764 string new_value = cur_value;
766 lyxerr << "Missing argument to `paragraph-spacing'"
768 } else if (tmp == "single") {
769 new_spacing = Spacing::Single;
770 } else if (tmp == "onehalf") {
771 new_spacing = Spacing::Onehalf;
772 } else if (tmp == "double") {
773 new_spacing = Spacing::Double;
774 } else if (tmp == "other") {
775 new_spacing = Spacing::Other;
776 string tmpval = "0.0";
778 lyxerr << "new_value = " << tmpval << endl;
781 } else if (tmp == "default") {
782 new_spacing = Spacing::Default;
784 lyxerr << _("Unknown spacing argument: ")
785 << cmd.argument << endl;
787 if (cur_spacing != new_spacing || cur_value != new_value)
788 par.params().spacing(Spacing(new_spacing, new_value));
792 case LFUN_INSET_APPLY: {
793 string const name = cmd.getArg(0);
794 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
796 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
797 inset->dispatch(cur, fr);
799 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
805 case LFUN_INSET_INSERT: {
807 InsetBase * inset = createInset(bv, cmd);
809 insertInset(cur, inset);
815 case LFUN_INSET_SETTINGS:
816 if (cur.inset().asUpdatableInset())
817 cur.inset().asUpdatableInset()->showInsetDialog(bv);
820 case LFUN_NEXT_INSET_TOGGLE: {
821 InsetBase * inset = cur.nextInset();
823 cur.clearSelection();
824 FuncRequest fr = cmd;
825 fr.action = LFUN_INSET_TOGGLE;
826 inset->dispatch(cur, fr);
831 case LFUN_KEYMAP_TOGGLE:
832 cur.clearSelection();
836 case LFUN_SPACE_INSERT:
837 if (cur.paragraph().layout()->free_spacing)
838 insertChar(cur, ' ');
840 doInsertInset(cur, this, cmd, false, false);
843 moveCursor(cur, false);
846 case LFUN_HYPHENATION:
847 specialChar(cur, InsetSpecialChar::HYPHENATION);
850 case LFUN_LIGATURE_BREAK:
851 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
855 specialChar(cur, InsetSpecialChar::LDOTS);
858 case LFUN_END_OF_SENTENCE:
859 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
862 case LFUN_MENU_SEPARATOR:
863 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
866 case LFUN_UPCASE_WORD:
867 changeCase(cur, LyXText::text_uppercase);
870 case LFUN_LOWCASE_WORD:
871 changeCase(cur, LyXText::text_lowercase);
874 case LFUN_CAPITALIZE_WORD:
875 changeCase(cur, LyXText::text_capitalization);
878 case LFUN_TRANSPOSE_CHARS:
883 cur.message(_("Paste"));
884 lyx::cap::replaceSelection(cur);
886 #warning FIXME Check if the arg is in the domain of available selections.
888 if (isStrUnsignedInt(cmd.argument))
889 pasteSelection(cur, strToUnsignedInt(cmd.argument));
891 pasteSelection(cur, 0);
892 cur.clearSelection(); // bug 393
898 cutSelection(cur, true, true);
899 cur.message(_("Cut"));
904 cur.message(_("Copy"));
908 cur.message(convert<string>(cursorX(cur.top())) + ' '
909 + convert<string>(cursorY(cur.top())));
915 istringstream is(cmd.argument);
918 lyxerr << "SETXY: Could not parse coordinates in '"
919 << cmd.argument << std::endl;
921 setCursorFromCoordinates(cur, x, y);
926 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
928 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
935 cur.message(cur.paragraph().layout()->name());
939 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
940 << cmd.argument << endl;
942 // This is not the good solution to the empty argument
943 // problem, but it will hopefully suffice for 1.2.0.
944 // The correct solution would be to augument the
945 // function list/array with information about what
946 // functions needs arguments and their type.
947 if (cmd.argument.empty()) {
948 cur.errorMessage(_("LyX function 'layout' needs an argument."));
952 // Derive layout number from given argument (string)
953 // and current buffer's textclass (number)
954 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
955 bool hasLayout = tclass.hasLayout(cmd.argument);
956 string layout = cmd.argument;
958 // If the entry is obsolete, use the new one instead.
960 string const & obs = tclass[layout]->obsoleted_by();
966 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
971 bool change_layout = (current_layout != layout);
973 if (!change_layout && cur.selection() &&
974 cur.selBegin().pit() != cur.selEnd().pit())
976 pit_type spit = cur.selBegin().pit();
977 pit_type epit = cur.selEnd().pit() + 1;
978 while (spit != epit) {
979 if (pars_[spit].layout()->name() != current_layout) {
980 change_layout = true;
988 current_layout = layout;
989 setLayout(cur, layout);
990 bv->owner()->setLayout(layout);
996 case LFUN_PASTESELECTION: {
997 cur.clearSelection();
998 string const clip = bv->getClipboard();
1000 if (cmd.argument == "paragraph")
1001 insertStringAsParagraphs(cur, clip);
1003 insertStringAsLines(cur, clip);
1008 case LFUN_GOTOERROR:
1009 gotoInset(cur, InsetBase::ERROR_CODE, false);
1013 gotoInset(cur, InsetBase::NOTE_CODE, false);
1016 case LFUN_REFERENCE_GOTO: {
1017 vector<InsetBase_code> tmp;
1018 tmp.push_back(InsetBase::LABEL_CODE);
1019 tmp.push_back(InsetBase::REF_CODE);
1020 gotoInset(cur, tmp, true);
1025 lyx::cap::replaceSelection(cur);
1026 Paragraph & par = cur.paragraph();
1027 lyx::pos_type pos = cur.pos();
1031 else if (cur.prevInset() && cur.prevInset()->isSpace())
1034 c = par.getChar(pos - 1);
1036 LyXLayout_ptr const & style = par.layout();
1038 BufferParams const & bufparams = bv->buffer()->params();
1039 if (!style->pass_thru
1040 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1041 string arg = cmd.argument;
1042 if (arg == "single")
1043 cur.insert(new InsetQuotes(c,
1044 bufparams.quotes_language,
1045 InsetQuotes::SingleQ));
1046 else if (arg == "double")
1047 cur.insert(new InsetQuotes(c,
1048 bufparams.quotes_language,
1049 InsetQuotes::DoubleQ));
1051 cur.insert(new InsetQuotes(c, bufparams));
1055 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1059 case LFUN_DATE_INSERT: {
1060 lyx::cap::replaceSelection(cur);
1061 time_t now_time_t = time(NULL);
1062 struct tm * now_tm = localtime(&now_time_t);
1063 setlocale(LC_TIME, "");
1065 if (!cmd.argument.empty())
1068 arg = lyxrc.date_insert_format;
1070 int const datetmp_len =
1071 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1073 for (int i = 0; i < datetmp_len; i++)
1074 insertChar(cur, datetmp[i]);
1077 moveCursor(cur, false);
1081 case LFUN_MOUSE_TRIPLE:
1082 if (cmd.button() == mouse_button::button1) {
1087 bv->haveSelection(cur.selection());
1091 case LFUN_MOUSE_DOUBLE:
1092 if (cmd.button() == mouse_button::button1) {
1093 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1094 bv->haveSelection(cur.selection());
1098 // Single-click on work area
1099 case LFUN_MOUSE_PRESS: {
1100 // Right click on a footnote flag opens float menu
1101 if (cmd.button() == mouse_button::button3) {
1102 cur.clearSelection();
1106 // Middle button press pastes if we have a selection
1107 // We do this here as if the selection was inside an inset
1108 // it could get cleared on the unlocking of the inset so
1109 // we have to check this first
1110 bool paste_internally = false;
1111 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1112 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1113 paste_internally = true;
1116 // Clear the selection
1117 cur.clearSelection();
1119 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1124 // Has the cursor just left the inset?
1125 if (bv->cursor().inMathed() && !cur.inMathed())
1126 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1131 // Insert primary selection with middle mouse
1132 // if there is a local selection in the current buffer,
1134 if (cmd.button() == mouse_button::button2) {
1135 if (paste_internally)
1136 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1138 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1144 case LFUN_MOUSE_MOTION: {
1145 // Only use motion with button 1
1146 //if (cmd.button() != mouse_button::button1)
1149 // ignore motions deeper nested than the real anchor
1150 LCursor & bvcur = cur.bv().cursor();
1151 if (bvcur.anchor_.hasPart(cur)) {
1152 CursorSlice old = bvcur.top();
1154 int const wh = bv->workHeight();
1155 int const y = std::max(0, std::min(wh - 1, cmd.y));
1157 setCursorFromCoordinates(cur, cmd.x, y);
1158 cur.x_target() = cmd.x;
1163 // This is to allow jumping over large insets
1164 if (cur.top() == old) {
1171 if (cur.top() == old)
1174 // don't set anchor_
1175 bvcur.setCursor(cur);
1176 bvcur.selection() = true;
1177 lyxerr << "MOTION: " << bv->cursor() << endl;
1185 case LFUN_MOUSE_RELEASE: {
1186 if (cmd.button() == mouse_button::button2)
1190 if (cmd.button() == mouse_button::button1)
1191 bv->haveSelection(cur.selection());
1194 bv->owner()->updateMenubar();
1195 bv->owner()->updateToolbars();
1199 case LFUN_SELFINSERT: {
1200 if (cmd.argument.empty())
1203 // Automatically delete the currently selected
1204 // text and replace it with what is being
1205 // typed in now. Depends on lyxrc settings
1206 // "auto_region_delete", which defaults to
1209 if (lyxrc.auto_region_delete) {
1210 if (cur.selection())
1211 cutSelection(cur, false, false);
1212 bv->haveSelection(false);
1215 cur.clearSelection();
1216 LyXFont const old_font = real_current_font;
1218 string::const_iterator cit = cmd.argument.begin();
1219 string::const_iterator end = cmd.argument.end();
1220 for (; cit != end; ++cit)
1221 bv->owner()->getIntl().getTransManager().
1222 TranslateAndInsert(*cit, this);
1225 moveCursor(cur, false);
1227 // real_current_font.number can change so we need to
1228 // update the minibuffer
1229 if (old_font != real_current_font)
1230 bv->updateScrollbar();
1235 InsetCommandParams p("url");
1236 string const data = InsetCommandMailer::params2string("url", p);
1237 bv->owner()->getDialogs().show("url", data, 0);
1241 case LFUN_HTMLURL: {
1242 InsetCommandParams p("htmlurl");
1243 string const data = InsetCommandMailer::params2string("url", p);
1244 bv->owner()->getDialogs().show("url", data, 0);
1248 case LFUN_INSERT_LABEL: {
1249 // Try to generate a valid label
1250 string const contents = cmd.argument.empty() ?
1251 cur.getPossibleLabel() : cmd.argument;
1253 InsetCommandParams p("label", contents);
1254 string const data = InsetCommandMailer::params2string("label", p);
1256 if (cmd.argument.empty()) {
1257 bv->owner()->getDialogs().show("label", data, 0);
1259 FuncRequest fr(LFUN_INSET_INSERT, data);
1267 case LFUN_INSET_LIST:
1268 case LFUN_INSET_THEOREM:
1269 case LFUN_INSET_CAPTION:
1271 case LFUN_INSERT_NOTE:
1272 case LFUN_INSERT_CHARSTYLE:
1273 case LFUN_INSERT_BOX:
1274 case LFUN_INSERT_BRANCH:
1275 case LFUN_INSERT_BIBITEM:
1276 case LFUN_INSET_ERT:
1277 case LFUN_INSET_FLOAT:
1278 case LFUN_INSET_FOOTNOTE:
1279 case LFUN_INSET_MARGINAL:
1280 case LFUN_INSET_OPTARG:
1281 case LFUN_INSET_WIDE_FLOAT:
1282 case LFUN_INSET_WRAP:
1283 case LFUN_TABULAR_INSERT:
1284 case LFUN_ENVIRONMENT_INSERT:
1285 // Open the inset, and move the current selection
1287 doInsertInset(cur, this, cmd, true, true);
1291 case LFUN_INDEX_INSERT:
1292 // Just open the inset
1293 doInsertInset(cur, this, cmd, true, false);
1297 case LFUN_INDEX_PRINT:
1298 case LFUN_TOC_INSERT:
1300 case LFUN_INSERT_LINE:
1301 case LFUN_INSERT_PAGEBREAK:
1303 doInsertInset(cur, this, cmd, false, false);
1307 case LFUN_DEPTH_MIN:
1308 changeDepth(cur, DEC_DEPTH);
1311 case LFUN_DEPTH_PLUS:
1312 changeDepth(cur, INC_DEPTH);
1315 case LFUN_MATH_DISPLAY:
1316 mathDispatch(cur, cmd, true);
1319 case LFUN_MATH_IMPORT_SELECTION:
1320 case LFUN_MATH_MODE:
1321 if (cmd.argument == "on")
1322 // don't pass "on" as argument
1323 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1325 mathDispatch(cur, cmd, false);
1328 case LFUN_MATH_MACRO:
1329 if (cmd.argument.empty())
1330 cur.errorMessage(N_("Missing argument"));
1332 string s = cmd.argument;
1333 string const s1 = token(s, ' ', 1);
1334 int const nargs = s1.empty() ? 0 : atoi(s1);
1335 string const s2 = token(s, ' ', 2);
1336 string const type = s2.empty() ? "newcommand" : s2;
1337 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1338 //cur.nextInset()->edit(cur, true);
1342 // passthrough hat and underscore outside mathed:
1343 case LFUN_SUBSCRIPT:
1344 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1346 case LFUN_SUPERSCRIPT:
1347 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1350 case LFUN_INSERT_MATH:
1351 case LFUN_INSERT_MATRIX:
1352 case LFUN_MATH_DELIM: {
1353 cur.insert(new MathHullInset);
1354 cur.dispatch(FuncRequest(LFUN_RIGHT));
1355 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1361 LyXFont font(LyXFont::ALL_IGNORE);
1362 font.setEmph(LyXFont::TOGGLE);
1363 toggleAndShow(cur, this, font);
1368 LyXFont font(LyXFont::ALL_IGNORE);
1369 font.setSeries(LyXFont::BOLD_SERIES);
1370 toggleAndShow(cur, this, font);
1375 LyXFont font(LyXFont::ALL_IGNORE);
1376 font.setNoun(LyXFont::TOGGLE);
1377 toggleAndShow(cur, this, font);
1382 LyXFont font(LyXFont::ALL_IGNORE);
1383 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1384 toggleAndShow(cur, this, font);
1389 LyXFont font(LyXFont::ALL_IGNORE);
1390 font.setFamily(LyXFont::SANS_FAMILY);
1391 toggleAndShow(cur, this, font);
1396 LyXFont font(LyXFont::ALL_IGNORE);
1397 font.setFamily(LyXFont::ROMAN_FAMILY);
1398 toggleAndShow(cur, this, font);
1402 case LFUN_DEFAULT: {
1403 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1404 toggleAndShow(cur, this, font);
1408 case LFUN_UNDERLINE: {
1409 LyXFont font(LyXFont::ALL_IGNORE);
1410 font.setUnderbar(LyXFont::TOGGLE);
1411 toggleAndShow(cur, this, font);
1415 case LFUN_FONT_SIZE: {
1416 LyXFont font(LyXFont::ALL_IGNORE);
1417 font.setLyXSize(cmd.argument);
1418 toggleAndShow(cur, this, font);
1422 case LFUN_LANGUAGE: {
1423 Language const * lang = languages.getLanguage(cmd.argument);
1426 LyXFont font(LyXFont::ALL_IGNORE);
1427 font.setLanguage(lang);
1428 toggleAndShow(cur, this, font);
1433 case LFUN_FREEFONT_APPLY:
1434 toggleAndShow(cur, this, freefont, toggleall);
1435 cur.message(_("Character set"));
1438 // Set the freefont using the contents of \param data dispatched from
1439 // the frontends and apply it at the current cursor location.
1440 case LFUN_FREEFONT_UPDATE: {
1443 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1446 toggleAndShow(cur, this, freefont, toggleall);
1447 cur.message(_("Character set"));
1452 case LFUN_FINISHED_LEFT:
1453 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1456 case LFUN_FINISHED_RIGHT:
1457 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1461 case LFUN_FINISHED_UP:
1462 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1466 case LFUN_FINISHED_DOWN:
1467 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1471 case LFUN_LAYOUT_PARAGRAPH: {
1473 params2string(cur.paragraph(), data);
1474 data = "show\n" + data;
1475 bv->owner()->getDialogs().show("paragraph", data);
1479 case LFUN_PARAGRAPH_UPDATE: {
1480 if (!bv->owner()->getDialogs().visible("paragraph"))
1483 params2string(cur.paragraph(), data);
1485 // Will the paragraph accept changes from the dialog?
1486 InsetBase & inset = cur.inset();
1487 bool const accept = !inset.forceDefaultParagraphs(&inset);
1489 data = "update " + convert<string>(accept) + '\n' + data;
1490 bv->owner()->getDialogs().update("paragraph", data);
1495 case LFUN_CIRCUMFLEX:
1505 case LFUN_SPECIAL_CARON:
1508 case LFUN_HUNG_UMLAUT:
1511 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1512 if (!cmd.argument.empty())
1513 bv->owner()->getIntl().getTransManager()
1514 .TranslateAndInsert(cmd.argument[0], this);
1517 case LFUN_FLOAT_LIST: {
1518 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1519 if (tclass.floats().typeExist(cmd.argument)) {
1520 // not quite sure if we want this...
1522 cur.clearSelection();
1523 breakParagraph(cur);
1525 if (cur.lastpos() != 0) {
1527 breakParagraph(cur);
1530 setLayout(cur, tclass.defaultLayoutName());
1531 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1532 insertInset(cur, new InsetFloatList(cmd.argument));
1535 lyxerr << "Non-existent float type: "
1536 << cmd.argument << endl;
1541 case LFUN_ACCEPT_CHANGE: {
1546 case LFUN_REJECT_CHANGE: {
1551 case LFUN_THESAURUS_ENTRY: {
1552 string arg = cmd.argument;
1554 arg = cur.selectionAsString(false);
1556 if (arg.size() > 100 || arg.empty()) {
1557 // Get word or selection
1558 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1559 arg = cur.selectionAsString(false);
1562 bv->owner()->getDialogs().show("thesaurus", arg);
1566 case LFUN_PARAGRAPH_APPLY: {
1567 // Given data, an encoding of the ParagraphParameters
1568 // generated in the Paragraph dialog, this function sets
1569 // the current paragraph appropriately.
1570 istringstream is(cmd.argument);
1573 ParagraphParameters params;
1578 params.labelWidthString(),
1580 cur.message(_("Paragraph layout set"));
1584 case LFUN_INSET_DIALOG_SHOW: {
1585 InsetBase * inset = cur.nextInset();
1587 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1588 inset->dispatch(cur, fr);
1594 if (cur.selection()) {
1595 cur.selection() = false;
1598 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1607 // avoid to update when navigating
1609 && &sl.inset() == &cur.inset()
1610 && sl.idx() == cur.idx()
1612 && cur.selection() == false)
1617 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1618 FuncStatus & flag) const
1620 BOOST_ASSERT(cur.text() == this);
1621 LyXFont const & font = real_current_font;
1624 switch (cmd.action) {
1626 case LFUN_DEPTH_MIN:
1627 enable = changeDepthAllowed(cur, DEC_DEPTH);
1630 case LFUN_DEPTH_PLUS:
1631 enable = changeDepthAllowed(cur, INC_DEPTH);
1634 case LFUN_INSET_OPTARG:
1635 enable = numberOfOptArgs(cur.paragraph())
1636 < cur.paragraph().layout()->optionalargs;
1640 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1644 // the functions which insert insets
1645 InsetBase::Code code = InsetBase::NO_CODE;
1646 switch (cmd.action) {
1647 case LFUN_DIALOG_SHOW_NEW_INSET:
1648 if (cmd.argument == "bibitem")
1649 code = InsetBase::BIBITEM_CODE;
1650 else if (cmd.argument == "bibtex")
1651 code = InsetBase::BIBTEX_CODE;
1652 else if (cmd.argument == "box")
1653 code = InsetBase::BOX_CODE;
1654 else if (cmd.argument == "branch")
1655 code = InsetBase::BRANCH_CODE;
1656 else if (cmd.argument == "citation")
1657 code = InsetBase::CITE_CODE;
1658 else if (cmd.argument == "ert")
1659 code = InsetBase::ERT_CODE;
1660 else if (cmd.argument == "external")
1661 code = InsetBase::EXTERNAL_CODE;
1662 else if (cmd.argument == "float")
1663 code = InsetBase::FLOAT_CODE;
1664 else if (cmd.argument == "graphics")
1665 code = InsetBase::GRAPHICS_CODE;
1666 else if (cmd.argument == "include")
1667 code = InsetBase::INCLUDE_CODE;
1668 else if (cmd.argument == "index")
1669 code = InsetBase::INDEX_CODE;
1670 else if (cmd.argument == "label")
1671 code = InsetBase::LABEL_CODE;
1672 else if (cmd.argument == "note")
1673 code = InsetBase::NOTE_CODE;
1674 else if (cmd.argument == "ref")
1675 code = InsetBase::REF_CODE;
1676 else if (cmd.argument == "toc")
1677 code = InsetBase::TOC_CODE;
1678 else if (cmd.argument == "url")
1679 code = InsetBase::URL_CODE;
1680 else if (cmd.argument == "vspace")
1681 code = InsetBase::VSPACE_CODE;
1682 else if (cmd.argument == "wrap")
1683 code = InsetBase::WRAP_CODE;
1686 case LFUN_INSET_ERT:
1687 code = InsetBase::ERT_CODE;
1689 case LFUN_INSET_FOOTNOTE:
1690 code = InsetBase::FOOT_CODE;
1692 case LFUN_TABULAR_INSERT:
1693 code = InsetBase::TABULAR_CODE;
1695 case LFUN_INSET_MARGINAL:
1696 code = InsetBase::MARGIN_CODE;
1698 case LFUN_INSET_FLOAT:
1699 case LFUN_INSET_WIDE_FLOAT:
1700 code = InsetBase::FLOAT_CODE;
1702 case LFUN_INSET_WRAP:
1703 code = InsetBase::WRAP_CODE;
1705 case LFUN_FLOAT_LIST:
1706 code = InsetBase::FLOAT_LIST_CODE;
1709 case LFUN_INSET_LIST:
1710 code = InsetBase::LIST_CODE;
1712 case LFUN_INSET_THEOREM:
1713 code = InsetBase::THEOREM_CODE;
1716 case LFUN_INSET_CAPTION:
1717 code = InsetBase::CAPTION_CODE;
1719 case LFUN_INSERT_NOTE:
1720 code = InsetBase::NOTE_CODE;
1722 case LFUN_INSERT_CHARSTYLE:
1723 code = InsetBase::CHARSTYLE_CODE;
1724 if (buf->params().getLyXTextClass().charstyles().empty())
1727 case LFUN_INSERT_BOX:
1728 code = InsetBase::BOX_CODE;
1730 case LFUN_INSERT_BRANCH:
1731 code = InsetBase::BRANCH_CODE;
1732 if (buf->params().branchlist().empty())
1735 case LFUN_INSERT_LABEL:
1736 code = InsetBase::LABEL_CODE;
1738 case LFUN_INSET_OPTARG:
1739 code = InsetBase::OPTARG_CODE;
1741 case LFUN_ENVIRONMENT_INSERT:
1742 code = InsetBase::BOX_CODE;
1744 case LFUN_INDEX_INSERT:
1745 code = InsetBase::INDEX_CODE;
1747 case LFUN_INDEX_PRINT:
1748 code = InsetBase::INDEX_PRINT_CODE;
1750 case LFUN_TOC_INSERT:
1751 code = InsetBase::TOC_CODE;
1755 code = InsetBase::URL_CODE;
1758 // always allow this, since we will inset a raw quote
1759 // if an inset is not allowed.
1761 case LFUN_HYPHENATION:
1762 case LFUN_LIGATURE_BREAK:
1764 case LFUN_MENU_SEPARATOR:
1766 case LFUN_END_OF_SENTENCE:
1767 code = InsetBase::SPECIALCHAR_CODE;
1769 case LFUN_SPACE_INSERT:
1770 // slight hack: we know this is allowed in math mode
1772 code = InsetBase::SPACE_CODE;
1774 case LFUN_INSET_DIALOG_SHOW: {
1775 InsetBase * inset = cur.nextInset();
1778 code = inset->lyxCode();
1779 if (!(code == InsetBase::INCLUDE_CODE
1780 || code == InsetBase::BIBTEX_CODE
1781 || code == InsetBase::FLOAT_LIST_CODE
1782 || code == InsetBase::TOC_CODE))
1791 if (code != InsetBase::NO_CODE
1792 && (cur.empty() || !cur.inset().insetAllowed(code)))
1797 case LFUN_DIALOG_SHOW_NEW_INSET:
1798 case LFUN_INSET_ERT:
1799 case LFUN_INSERT_BOX:
1800 case LFUN_INSERT_BRANCH:
1801 case LFUN_ENVIRONMENT_INSERT:
1802 case LFUN_INDEX_INSERT:
1803 case LFUN_INDEX_PRINT:
1804 case LFUN_TOC_INSERT:
1808 case LFUN_HYPHENATION:
1809 case LFUN_LIGATURE_BREAK:
1811 case LFUN_MENU_SEPARATOR:
1813 case LFUN_END_OF_SENTENCE:
1814 case LFUN_SPACE_INSERT:
1815 case LFUN_INSET_DIALOG_SHOW:
1819 flag.setOnOff(font.emph() == LyXFont::ON);
1823 flag.setOnOff(font.noun() == LyXFont::ON);
1827 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1831 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1835 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1839 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1842 case LFUN_DELETE_WORD_FORWARD:
1843 case LFUN_DELETE_WORD_BACKWARD:
1844 case LFUN_DELETE_LINE_FORWARD:
1845 case LFUN_WORDRIGHT:
1855 case LFUN_UP_PARAGRAPHSEL:
1856 case LFUN_DOWN_PARAGRAPHSEL:
1861 case LFUN_WORDRIGHTSEL:
1862 case LFUN_WORDLEFTSEL:
1864 case LFUN_UP_PARAGRAPH:
1865 case LFUN_DOWN_PARAGRAPH:
1870 case LFUN_BREAKLINE:
1872 case LFUN_DELETE_SKIP:
1873 case LFUN_BACKSPACE:
1874 case LFUN_BACKSPACE_SKIP:
1875 case LFUN_BREAKPARAGRAPH:
1876 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1877 case LFUN_BREAKPARAGRAPH_SKIP:
1878 case LFUN_PARAGRAPH_SPACING:
1879 case LFUN_INSET_APPLY:
1880 case LFUN_INSET_INSERT:
1881 case LFUN_NEXT_INSET_TOGGLE:
1882 case LFUN_UPCASE_WORD:
1883 case LFUN_LOWCASE_WORD:
1884 case LFUN_CAPITALIZE_WORD:
1885 case LFUN_TRANSPOSE_CHARS:
1892 case LFUN_GETLAYOUT:
1894 case LFUN_PASTESELECTION:
1895 case LFUN_GOTOERROR:
1897 case LFUN_REFERENCE_GOTO:
1898 case LFUN_DATE_INSERT:
1899 case LFUN_SELFINSERT:
1900 case LFUN_INSERT_LABEL:
1901 case LFUN_INSERT_NOTE:
1902 case LFUN_INSERT_CHARSTYLE:
1903 case LFUN_INSERT_BIBITEM:
1904 case LFUN_INSET_FLOAT:
1905 case LFUN_INSET_FOOTNOTE:
1906 case LFUN_INSET_MARGINAL:
1907 case LFUN_INSET_WIDE_FLOAT:
1908 case LFUN_INSET_WRAP:
1909 case LFUN_TABULAR_INSERT:
1910 case LFUN_INSERT_LINE:
1911 case LFUN_INSERT_PAGEBREAK:
1912 case LFUN_MATH_DISPLAY:
1913 case LFUN_MATH_IMPORT_SELECTION:
1914 case LFUN_MATH_MODE:
1915 case LFUN_MATH_MACRO:
1916 case LFUN_INSERT_MATH:
1917 case LFUN_INSERT_MATRIX:
1918 case LFUN_MATH_DELIM:
1919 case LFUN_SUBSCRIPT:
1920 case LFUN_SUPERSCRIPT:
1922 case LFUN_UNDERLINE:
1923 case LFUN_FONT_SIZE:
1925 case LFUN_FREEFONT_APPLY:
1926 case LFUN_FREEFONT_UPDATE:
1927 case LFUN_LAYOUT_PARAGRAPH:
1928 case LFUN_PARAGRAPH_UPDATE:
1930 case LFUN_CIRCUMFLEX:
1940 case LFUN_SPECIAL_CARON:
1943 case LFUN_HUNG_UMLAUT:
1946 case LFUN_FLOAT_LIST:
1947 case LFUN_ACCEPT_CHANGE:
1948 case LFUN_REJECT_CHANGE:
1949 case LFUN_THESAURUS_ENTRY:
1950 case LFUN_PARAGRAPH_APPLY:
1952 case LFUN_KEYMAP_TOGGLE:
1954 case LFUN_BEGINNINGBUF:
1955 case LFUN_BEGINNINGBUFSEL:
1956 case LFUN_ENDBUFSEL:
1957 // these are handled in our dispatch()
1964 flag.enabled(enable);