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::token;
78 using std::istringstream;
82 extern string current_layout;
88 LyXFont freefont(LyXFont::ALL_IGNORE);
89 bool toggleall = false;
92 void toggleAndShow(LCursor & cur, LyXText * text,
93 LyXFont const & font, bool toggleall = true)
95 text->toggleFree(cur, font, toggleall);
97 if (font.language() != ignore_language ||
98 font.number() != LyXFont::IGNORE) {
99 Paragraph & par = cur.paragraph();
100 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
101 if (cur.boundary() !=
102 text->bidi.isBoundary(cur.buffer(), par,
104 text->real_current_font))
105 text->setCursor(cur, cur.pit(), cur.pos(),
106 false, !cur.boundary());
111 void moveCursor(LCursor & cur, bool selecting)
113 if (selecting || cur.mark())
115 if (!cur.selection())
116 cur.bv().haveSelection(false);
117 cur.bv().switchKeyMap();
121 void finishChange(LCursor & cur, bool selecting)
124 moveCursor(cur, selecting);
128 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
131 string sel = cur.selectionAsString(false);
132 lyxerr << "selection is: '" << sel << "'" << endl;
135 const int old_pos = cur.pos();
136 cur.insert(new MathHullInset);
137 BOOST_ASSERT(old_pos == cur.pos());
138 cur.nextInset()->edit(cur, true);
139 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
140 // don't do that also for LFUN_MATH_MODE
141 // unless you want end up with always changing
142 // to mathrm when opening an inlined inset --
143 // I really hate "LyXfunc overloading"...
145 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
146 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
148 // create a macro if we see "\\newcommand"
149 // somewhere, and an ordinary formula
151 cutSelection(cur, true, true);
152 if (sel.find("\\newcommand") == string::npos
153 && sel.find("\\def") == string::npos)
155 cur.insert(new MathHullInset);
156 cur.dispatch(FuncRequest(LFUN_RIGHT));
157 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
158 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
160 istringstream is(sel);
161 cur.insert(new MathMacroTemplate(is));
164 cur.message(N_("Math editor mode"));
173 string const freefont2string()
176 if (font2string(freefont, toggleall, data))
183 bool LyXText::gotoNextInset(LCursor & cur,
184 vector<InsetBase_code> const & codes, string const & contents)
186 BOOST_ASSERT(this == cur.text());
187 pit_type end = paragraphs().size();
188 pit_type pit = cur.pit();
189 pos_type pos = cur.pos();
193 if (pos + 1 < pars_[pit].size()) {
200 } while (pit != end &&
201 !(pars_[pit].isInset(pos) &&
202 (inset = pars_[pit].getInset(pos)) != 0 &&
203 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
205 static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
211 setCursor(cur, pit, pos, false);
216 void LyXText::gotoInset(LCursor & cur,
217 vector<InsetBase_code> const & codes, bool same_content)
219 cur.clearSelection();
223 && cur.pos() < cur.lastpos()
224 && cur.paragraph().isInset(cur.pos())) {
225 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
226 if (find(codes.begin(), codes.end(), inset->lyxCode())
228 contents = static_cast<InsetCommand const *>(inset)->getContents();
231 if (!gotoNextInset(cur, codes, contents)) {
232 if (cur.pos() || cur.pit() != 0) {
233 CursorSlice tmp = cur.top();
236 if (!gotoNextInset(cur, codes, contents)) {
238 cur.message(_("No more insets"));
241 cur.message(_("No more insets"));
248 void LyXText::gotoInset(LCursor & cur, InsetBase_code code, bool same_content)
250 gotoInset(cur, vector<InsetBase_code>(1, code), same_content);
254 void LyXText::cursorPrevious(LCursor & cur)
256 pos_type cpos = cur.pos();
257 lyx::pit_type cpar = cur.pit();
259 int x = cur.x_target();
261 setCursorFromCoordinates(cur, x, 0);
264 if (cpar == cur.pit() && cpos == cur.pos()) {
265 // we have a row which is taller than the workarea. The
266 // simplest solution is to move to the previous row instead.
270 cur.bv().updateScrollbar();
275 void LyXText::cursorNext(LCursor & cur)
277 pos_type cpos = cur.pos();
278 lyx::pit_type cpar = cur.pit();
280 int x = cur.x_target();
281 setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
284 if (cpar == cur.pit() && cpos == cur.pos()) {
285 // we have a row which is taller than the workarea. The
286 // simplest solution is to move to the next row instead.
290 cur.bv().updateScrollbar();
297 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
299 lyx::cap::replaceSelection(cur);
300 cur.insert(new InsetSpecialChar(kind));
305 void doInsertInset(LCursor & cur, LyXText * text,
306 FuncRequest const & cmd, bool edit, bool pastesel)
308 InsetBase * inset = createInset(&cur.bv(), cmd);
314 if (cur.selection()) {
315 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
318 text->insertInset(cur, inset);
321 inset->edit(cur, true);
323 if (gotsel && pastesel)
324 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
328 void update(LCursor & cur)
330 //we don't call update(true, false) directly to save a metrics call
331 if (cur.bv().fitCursor())
332 cur.bv().update(false, true);
339 void LyXText::number(LCursor & cur)
341 LyXFont font(LyXFont::ALL_IGNORE);
342 font.setNumber(LyXFont::TOGGLE);
343 toggleAndShow(cur, this, font);
347 bool LyXText::isRTL(Paragraph const & par) const
349 return par.isRightToLeftPar(bv()->buffer()->params());
353 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
355 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
356 lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
358 BOOST_ASSERT(cur.text() == this);
359 BufferView * bv = &cur.bv();
360 CursorSlice sl = cur.top();
361 bool sel = cur.selection();
364 switch (cmd.action) {
366 case LFUN_APPENDIX: {
367 Paragraph & par = cur.paragraph();
368 bool start = !par.params().startOfAppendix();
370 // ensure that we have only one start_of_appendix in this document
371 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
372 if (pars_[tmp].params().startOfAppendix()) {
374 pars_[tmp].params().startOfAppendix(false);
380 par.params().startOfAppendix(start);
382 // we can set the refreshing parameters now
387 case LFUN_DELETE_WORD_FORWARD:
388 cur.clearSelection();
389 deleteWordForward(cur);
390 finishChange(cur, false);
393 case LFUN_DELETE_WORD_BACKWARD:
394 cur.clearSelection();
395 deleteWordBackward(cur);
396 finishChange(cur, false);
399 case LFUN_DELETE_LINE_FORWARD:
400 cur.clearSelection();
401 deleteLineForward(cur);
402 finishChange(cur, false);
408 cur.clearSelection();
409 if (isRTL(cur.paragraph()))
410 cursorLeftOneWord(cur);
412 cursorRightOneWord(cur);
413 finishChange(cur, false);
419 cur.clearSelection();
420 if (isRTL(cur.paragraph()))
421 cursorRightOneWord(cur);
423 cursorLeftOneWord(cur);
424 finishChange(cur, false);
427 case LFUN_BEGINNINGBUF:
428 if (cur.size() == 1) {
430 cur.clearSelection();
432 finishChange(cur, false);
438 case LFUN_BEGINNINGBUFSEL:
439 if (cur.size() == 1) {
440 if (!cur.selection())
443 finishChange(cur, true);
450 if (cur.size() == 1) {
452 cur.clearSelection();
454 finishChange(cur, false);
461 if (cur.size() == 1) {
462 if (!cur.selection())
465 finishChange(cur, true);
474 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
475 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
476 if (isRTL(cur.paragraph()))
480 if (sl == cur.top()) {
482 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
489 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
490 cur.selHandle(cmd.action == LFUN_LEFTSEL);
491 if (isRTL(cur.paragraph()))
495 if (sl == cur.top()) {
497 cmd = FuncRequest(LFUN_FINISHED_LEFT);
505 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
506 cur.selHandle(cmd.action == LFUN_UPSEL);
508 if (sl == cur.top()) {
510 cmd = FuncRequest(LFUN_FINISHED_UP);
518 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
519 cur.selHandle(cmd.action == LFUN_DOWNSEL);
521 if (sl == cur.top()) {
523 cmd = FuncRequest(LFUN_FINISHED_DOWN);
527 case LFUN_UP_PARAGRAPHSEL:
528 if (!cur.selection())
530 cursorUpParagraph(cur);
531 finishChange(cur, true);
534 case LFUN_DOWN_PARAGRAPHSEL:
535 if (!cur.selection())
537 cursorDownParagraph(cur);
538 finishChange(cur, true);
543 if (!cur.selection())
546 finishChange(cur, true);
551 if (!cur.selection())
554 finishChange(cur, true);
559 if (!cur.selection())
562 finishChange(cur, true);
567 if (!cur.selection())
570 finishChange(cur, true);
573 case LFUN_WORDRIGHTSEL:
574 if (!cur.selection())
576 if (isRTL(cur.paragraph()))
577 cursorLeftOneWord(cur);
579 cursorRightOneWord(cur);
580 finishChange(cur, true);
583 case LFUN_WORDLEFTSEL:
584 if (!cur.selection())
586 if (isRTL(cur.paragraph()))
587 cursorRightOneWord(cur);
589 cursorLeftOneWord(cur);
590 finishChange(cur, true);
594 selectWord(cur, lyx::WHOLE_WORD);
595 finishChange(cur, true);
599 case LFUN_UP_PARAGRAPH:
602 cur.clearSelection();
603 cursorUpParagraph(cur);
604 finishChange(cur, false);
607 case LFUN_DOWN_PARAGRAPH:
610 cur.clearSelection();
611 cursorDownParagraph(cur);
612 finishChange(cur, false);
619 cur.clearSelection();
620 finishChange(cur, false);
621 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
623 cmd = FuncRequest(LFUN_FINISHED_UP);
633 cur.clearSelection();
634 finishChange(cur, false);
635 if (cur.pit() == cur.lastpit()
636 && cur.textRow().endpos() == cur.lastpos()) {
638 cmd = FuncRequest(LFUN_FINISHED_DOWN);
646 cur.clearSelection();
648 finishChange(cur, false);
653 cur.clearSelection();
655 finishChange(cur, false);
658 case LFUN_BREAKLINE: {
659 // Not allowed by LaTeX (labels or empty par)
660 if (cur.pos() > cur.paragraph().beginOfBody()) {
661 lyx::cap::replaceSelection(cur);
662 cur.insert(new InsetNewline);
664 moveCursor(cur, false);
670 if (!cur.selection()) {
673 // It is possible to make it a lot faster still
674 // just comment out the line below...
676 cutSelection(cur, true, false);
678 moveCursor(cur, false);
681 case LFUN_DELETE_SKIP:
682 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
683 if (!cur.selection()) {
684 if (cur.pos() == cur.lastpos()) {
691 cutSelection(cur, true, false);
697 if (!cur.selection()) {
698 if (bv->owner()->getIntl().getTransManager().backspace()) {
701 // It is possible to make it a lot faster still
702 // just comment out the line below...
705 cutSelection(cur, true, false);
710 case LFUN_BACKSPACE_SKIP:
711 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
712 if (!cur.selection()) {
716 //CursorSlice cur = cursor();
720 cutSelection(cur, true, false);
724 case LFUN_BREAKPARAGRAPH:
725 lyx::cap::replaceSelection(cur);
726 breakParagraph(cur, 0);
731 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
732 lyx::cap::replaceSelection(cur);
733 breakParagraph(cur, 1);
738 case LFUN_BREAKPARAGRAPH_SKIP: {
739 // When at the beginning of a paragraph, remove
740 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
741 lyx::cap::replaceSelection(cur);
743 cur.paragraph().params().labelWidthString(string());
745 breakParagraph(cur, 0);
751 case LFUN_PARAGRAPH_SPACING: {
752 Paragraph & par = cur.paragraph();
753 Spacing::Space cur_spacing = par.params().spacing().getSpace();
754 string cur_value = "1.0";
755 if (cur_spacing == Spacing::Other)
756 cur_value = par.params().spacing().getValueAsString();
758 istringstream is(cmd.argument);
761 Spacing::Space new_spacing = cur_spacing;
762 string new_value = cur_value;
764 lyxerr << "Missing argument to `paragraph-spacing'"
766 } else if (tmp == "single") {
767 new_spacing = Spacing::Single;
768 } else if (tmp == "onehalf") {
769 new_spacing = Spacing::Onehalf;
770 } else if (tmp == "double") {
771 new_spacing = Spacing::Double;
772 } else if (tmp == "other") {
773 new_spacing = Spacing::Other;
774 string tmpval = "0.0";
776 lyxerr << "new_value = " << tmpval << endl;
779 } else if (tmp == "default") {
780 new_spacing = Spacing::Default;
782 lyxerr << _("Unknown spacing argument: ")
783 << cmd.argument << endl;
785 if (cur_spacing != new_spacing || cur_value != new_value)
786 par.params().spacing(Spacing(new_spacing, new_value));
790 case LFUN_INSET_APPLY: {
791 string const name = cmd.getArg(0);
792 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
794 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
795 inset->dispatch(cur, fr);
797 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
803 case LFUN_INSET_INSERT: {
805 InsetBase * inset = createInset(bv, cmd);
807 insertInset(cur, inset);
813 case LFUN_INSET_SETTINGS:
814 if (cur.inset().asUpdatableInset())
815 cur.inset().asUpdatableInset()->showInsetDialog(bv);
818 case LFUN_NEXT_INSET_TOGGLE: {
819 InsetBase * inset = cur.nextInset();
821 cur.clearSelection();
822 FuncRequest fr = cmd;
823 fr.action = LFUN_INSET_TOGGLE;
824 inset->dispatch(cur, fr);
829 case LFUN_KEYMAP_TOGGLE:
830 cur.clearSelection();
834 case LFUN_SPACE_INSERT:
835 if (cur.paragraph().layout()->free_spacing)
836 insertChar(cur, ' ');
838 doInsertInset(cur, this, cmd, false, false);
841 moveCursor(cur, false);
844 case LFUN_HYPHENATION:
845 specialChar(cur, InsetSpecialChar::HYPHENATION);
848 case LFUN_LIGATURE_BREAK:
849 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
853 specialChar(cur, InsetSpecialChar::LDOTS);
856 case LFUN_END_OF_SENTENCE:
857 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
860 case LFUN_MENU_SEPARATOR:
861 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
864 case LFUN_UPCASE_WORD:
865 changeCase(cur, LyXText::text_uppercase);
868 case LFUN_LOWCASE_WORD:
869 changeCase(cur, LyXText::text_lowercase);
872 case LFUN_CAPITALIZE_WORD:
873 changeCase(cur, LyXText::text_capitalization);
876 case LFUN_TRANSPOSE_CHARS:
881 cur.message(_("Paste"));
882 lyx::cap::replaceSelection(cur);
884 #warning FIXME Check if the arg is in the domain of available selections.
886 if (isStrUnsignedInt(cmd.argument))
887 pasteSelection(cur, convert<unsigned int>(cmd.argument));
889 pasteSelection(cur, 0);
890 cur.clearSelection(); // bug 393
896 cutSelection(cur, true, true);
897 cur.message(_("Cut"));
902 cur.message(_("Copy"));
906 cur.message(convert<string>(cursorX(cur.top())) + ' '
907 + convert<string>(cursorY(cur.top())));
913 istringstream is(cmd.argument);
916 lyxerr << "SETXY: Could not parse coordinates in '"
917 << cmd.argument << std::endl;
919 setCursorFromCoordinates(cur, x, y);
924 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
926 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
933 cur.message(cur.paragraph().layout()->name());
937 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
938 << cmd.argument << endl;
940 // This is not the good solution to the empty argument
941 // problem, but it will hopefully suffice for 1.2.0.
942 // The correct solution would be to augument the
943 // function list/array with information about what
944 // functions needs arguments and their type.
945 if (cmd.argument.empty()) {
946 cur.errorMessage(_("LyX function 'layout' needs an argument."));
950 // Derive layout number from given argument (string)
951 // and current buffer's textclass (number)
952 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
953 bool hasLayout = tclass.hasLayout(cmd.argument);
954 string layout = cmd.argument;
956 // If the entry is obsolete, use the new one instead.
958 string const & obs = tclass[layout]->obsoleted_by();
964 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
969 bool change_layout = (current_layout != layout);
971 if (!change_layout && cur.selection() &&
972 cur.selBegin().pit() != cur.selEnd().pit())
974 pit_type spit = cur.selBegin().pit();
975 pit_type epit = cur.selEnd().pit() + 1;
976 while (spit != epit) {
977 if (pars_[spit].layout()->name() != current_layout) {
978 change_layout = true;
986 current_layout = layout;
987 setLayout(cur, layout);
988 bv->owner()->setLayout(layout);
994 case LFUN_PASTESELECTION: {
995 cur.clearSelection();
996 string const clip = bv->getClipboard();
998 if (cmd.argument == "paragraph")
999 insertStringAsParagraphs(cur, clip);
1001 insertStringAsLines(cur, clip);
1006 case LFUN_GOTOERROR:
1007 gotoInset(cur, InsetBase::ERROR_CODE, false);
1011 gotoInset(cur, InsetBase::NOTE_CODE, false);
1014 case LFUN_REFERENCE_GOTO: {
1015 vector<InsetBase_code> tmp;
1016 tmp.push_back(InsetBase::LABEL_CODE);
1017 tmp.push_back(InsetBase::REF_CODE);
1018 gotoInset(cur, tmp, true);
1023 lyx::cap::replaceSelection(cur);
1024 Paragraph & par = cur.paragraph();
1025 lyx::pos_type pos = cur.pos();
1029 else if (cur.prevInset() && cur.prevInset()->isSpace())
1032 c = par.getChar(pos - 1);
1034 LyXLayout_ptr const & style = par.layout();
1036 BufferParams const & bufparams = bv->buffer()->params();
1037 if (!style->pass_thru
1038 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1039 string arg = cmd.argument;
1040 if (arg == "single")
1041 cur.insert(new InsetQuotes(c,
1042 bufparams.quotes_language,
1043 InsetQuotes::SingleQ));
1044 else if (arg == "double")
1045 cur.insert(new InsetQuotes(c,
1046 bufparams.quotes_language,
1047 InsetQuotes::DoubleQ));
1049 cur.insert(new InsetQuotes(c, bufparams));
1053 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1057 case LFUN_DATE_INSERT: {
1058 lyx::cap::replaceSelection(cur);
1059 time_t now_time_t = time(NULL);
1060 struct tm * now_tm = localtime(&now_time_t);
1061 setlocale(LC_TIME, "");
1063 if (!cmd.argument.empty())
1066 arg = lyxrc.date_insert_format;
1068 int const datetmp_len =
1069 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1071 for (int i = 0; i < datetmp_len; i++)
1072 insertChar(cur, datetmp[i]);
1075 moveCursor(cur, false);
1079 case LFUN_MOUSE_TRIPLE:
1080 if (cmd.button() == mouse_button::button1) {
1085 bv->haveSelection(cur.selection());
1089 case LFUN_MOUSE_DOUBLE:
1090 if (cmd.button() == mouse_button::button1) {
1091 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1092 bv->haveSelection(cur.selection());
1096 // Single-click on work area
1097 case LFUN_MOUSE_PRESS: {
1098 // Right click on a footnote flag opens float menu
1099 if (cmd.button() == mouse_button::button3) {
1100 cur.clearSelection();
1104 // Middle button press pastes if we have a selection
1105 // We do this here as if the selection was inside an inset
1106 // it could get cleared on the unlocking of the inset so
1107 // we have to check this first
1108 bool paste_internally = false;
1109 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1110 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1111 paste_internally = true;
1114 // Clear the selection
1115 cur.clearSelection();
1117 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1122 // Has the cursor just left the inset?
1123 if (bv->cursor().inMathed() && !cur.inMathed())
1124 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1129 // Insert primary selection with middle mouse
1130 // if there is a local selection in the current buffer,
1132 if (cmd.button() == mouse_button::button2) {
1133 if (paste_internally)
1134 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1136 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1142 case LFUN_MOUSE_MOTION: {
1143 // Only use motion with button 1
1144 //if (cmd.button() != mouse_button::button1)
1147 // ignore motions deeper nested than the real anchor
1148 LCursor & bvcur = cur.bv().cursor();
1149 if (bvcur.anchor_.hasPart(cur)) {
1150 CursorSlice old = bvcur.top();
1152 int const wh = bv->workHeight();
1153 int const y = std::max(0, std::min(wh - 1, cmd.y));
1155 setCursorFromCoordinates(cur, cmd.x, y);
1156 cur.x_target() = cmd.x;
1161 // This is to allow jumping over large insets
1162 if (cur.top() == old) {
1169 if (cur.top() == old)
1172 // don't set anchor_
1173 bvcur.setCursor(cur);
1174 bvcur.selection() = true;
1175 lyxerr << "MOTION: " << bv->cursor() << endl;
1183 case LFUN_MOUSE_RELEASE: {
1184 if (cmd.button() == mouse_button::button2)
1188 if (cmd.button() == mouse_button::button1)
1189 bv->haveSelection(cur.selection());
1192 bv->owner()->updateMenubar();
1193 bv->owner()->updateToolbars();
1197 case LFUN_SELFINSERT: {
1198 if (cmd.argument.empty())
1201 // Automatically delete the currently selected
1202 // text and replace it with what is being
1203 // typed in now. Depends on lyxrc settings
1204 // "auto_region_delete", which defaults to
1207 if (lyxrc.auto_region_delete) {
1208 if (cur.selection())
1209 cutSelection(cur, false, false);
1210 bv->haveSelection(false);
1213 cur.clearSelection();
1214 LyXFont const old_font = real_current_font;
1216 string::const_iterator cit = cmd.argument.begin();
1217 string::const_iterator end = cmd.argument.end();
1218 for (; cit != end; ++cit)
1219 bv->owner()->getIntl().getTransManager().
1220 TranslateAndInsert(*cit, this);
1223 moveCursor(cur, false);
1225 // real_current_font.number can change so we need to
1226 // update the minibuffer
1227 if (old_font != real_current_font)
1228 bv->updateScrollbar();
1233 InsetCommandParams p("url");
1234 string const data = InsetCommandMailer::params2string("url", p);
1235 bv->owner()->getDialogs().show("url", data, 0);
1239 case LFUN_HTMLURL: {
1240 InsetCommandParams p("htmlurl");
1241 string const data = InsetCommandMailer::params2string("url", p);
1242 bv->owner()->getDialogs().show("url", data, 0);
1246 case LFUN_INSERT_LABEL: {
1247 // Try to generate a valid label
1248 string const contents = cmd.argument.empty() ?
1249 cur.getPossibleLabel() : cmd.argument;
1251 InsetCommandParams p("label", contents);
1252 string const data = InsetCommandMailer::params2string("label", p);
1254 if (cmd.argument.empty()) {
1255 bv->owner()->getDialogs().show("label", data, 0);
1257 FuncRequest fr(LFUN_INSET_INSERT, data);
1265 case LFUN_INSET_LIST:
1266 case LFUN_INSET_THEOREM:
1267 case LFUN_INSET_CAPTION:
1269 case LFUN_INSERT_NOTE:
1270 case LFUN_INSERT_CHARSTYLE:
1271 case LFUN_INSERT_BOX:
1272 case LFUN_INSERT_BRANCH:
1273 case LFUN_INSERT_BIBITEM:
1274 case LFUN_INSET_ERT:
1275 case LFUN_INSET_FLOAT:
1276 case LFUN_INSET_FOOTNOTE:
1277 case LFUN_INSET_MARGINAL:
1278 case LFUN_INSET_OPTARG:
1279 case LFUN_INSET_WIDE_FLOAT:
1280 case LFUN_INSET_WRAP:
1281 case LFUN_TABULAR_INSERT:
1282 case LFUN_ENVIRONMENT_INSERT:
1283 // Open the inset, and move the current selection
1285 doInsertInset(cur, this, cmd, true, true);
1289 case LFUN_INDEX_INSERT:
1290 // Just open the inset
1291 doInsertInset(cur, this, cmd, true, false);
1295 case LFUN_INDEX_PRINT:
1296 case LFUN_TOC_INSERT:
1298 case LFUN_INSERT_LINE:
1299 case LFUN_INSERT_PAGEBREAK:
1301 doInsertInset(cur, this, cmd, false, false);
1305 case LFUN_DEPTH_MIN:
1306 changeDepth(cur, DEC_DEPTH);
1309 case LFUN_DEPTH_PLUS:
1310 changeDepth(cur, INC_DEPTH);
1313 case LFUN_MATH_DISPLAY:
1314 mathDispatch(cur, cmd, true);
1317 case LFUN_MATH_IMPORT_SELECTION:
1318 case LFUN_MATH_MODE:
1319 if (cmd.argument == "on")
1320 // don't pass "on" as argument
1321 mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1323 mathDispatch(cur, cmd, false);
1326 case LFUN_MATH_MACRO:
1327 if (cmd.argument.empty())
1328 cur.errorMessage(N_("Missing argument"));
1330 string s = cmd.argument;
1331 string const s1 = token(s, ' ', 1);
1332 int const nargs = s1.empty() ? 0 : convert<int>(s1);
1333 string const s2 = token(s, ' ', 2);
1334 string const type = s2.empty() ? "newcommand" : s2;
1335 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1336 //cur.nextInset()->edit(cur, true);
1340 // passthrough hat and underscore outside mathed:
1341 case LFUN_SUBSCRIPT:
1342 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1344 case LFUN_SUPERSCRIPT:
1345 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1348 case LFUN_INSERT_MATH:
1349 case LFUN_INSERT_MATRIX:
1350 case LFUN_MATH_DELIM: {
1351 cur.insert(new MathHullInset);
1352 cur.dispatch(FuncRequest(LFUN_RIGHT));
1353 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1359 LyXFont font(LyXFont::ALL_IGNORE);
1360 font.setEmph(LyXFont::TOGGLE);
1361 toggleAndShow(cur, this, font);
1366 LyXFont font(LyXFont::ALL_IGNORE);
1367 font.setSeries(LyXFont::BOLD_SERIES);
1368 toggleAndShow(cur, this, font);
1373 LyXFont font(LyXFont::ALL_IGNORE);
1374 font.setNoun(LyXFont::TOGGLE);
1375 toggleAndShow(cur, this, font);
1380 LyXFont font(LyXFont::ALL_IGNORE);
1381 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1382 toggleAndShow(cur, this, font);
1387 LyXFont font(LyXFont::ALL_IGNORE);
1388 font.setFamily(LyXFont::SANS_FAMILY);
1389 toggleAndShow(cur, this, font);
1394 LyXFont font(LyXFont::ALL_IGNORE);
1395 font.setFamily(LyXFont::ROMAN_FAMILY);
1396 toggleAndShow(cur, this, font);
1400 case LFUN_DEFAULT: {
1401 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1402 toggleAndShow(cur, this, font);
1406 case LFUN_UNDERLINE: {
1407 LyXFont font(LyXFont::ALL_IGNORE);
1408 font.setUnderbar(LyXFont::TOGGLE);
1409 toggleAndShow(cur, this, font);
1413 case LFUN_FONT_SIZE: {
1414 LyXFont font(LyXFont::ALL_IGNORE);
1415 font.setLyXSize(cmd.argument);
1416 toggleAndShow(cur, this, font);
1420 case LFUN_LANGUAGE: {
1421 Language const * lang = languages.getLanguage(cmd.argument);
1424 LyXFont font(LyXFont::ALL_IGNORE);
1425 font.setLanguage(lang);
1426 toggleAndShow(cur, this, font);
1431 case LFUN_FREEFONT_APPLY:
1432 toggleAndShow(cur, this, freefont, toggleall);
1433 cur.message(_("Character set"));
1436 // Set the freefont using the contents of \param data dispatched from
1437 // the frontends and apply it at the current cursor location.
1438 case LFUN_FREEFONT_UPDATE: {
1441 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1444 toggleAndShow(cur, this, freefont, toggleall);
1445 cur.message(_("Character set"));
1450 case LFUN_FINISHED_LEFT:
1451 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1454 case LFUN_FINISHED_RIGHT:
1455 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1459 case LFUN_FINISHED_UP:
1460 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1464 case LFUN_FINISHED_DOWN:
1465 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1469 case LFUN_LAYOUT_PARAGRAPH: {
1471 params2string(cur.paragraph(), data);
1472 data = "show\n" + data;
1473 bv->owner()->getDialogs().show("paragraph", data);
1477 case LFUN_PARAGRAPH_UPDATE: {
1478 if (!bv->owner()->getDialogs().visible("paragraph"))
1481 params2string(cur.paragraph(), data);
1483 // Will the paragraph accept changes from the dialog?
1484 InsetBase & inset = cur.inset();
1485 bool const accept = !inset.forceDefaultParagraphs(&inset);
1487 data = "update " + convert<string>(accept) + '\n' + data;
1488 bv->owner()->getDialogs().update("paragraph", data);
1493 case LFUN_CIRCUMFLEX:
1503 case LFUN_SPECIAL_CARON:
1506 case LFUN_HUNG_UMLAUT:
1509 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1510 if (!cmd.argument.empty())
1511 bv->owner()->getIntl().getTransManager()
1512 .TranslateAndInsert(cmd.argument[0], this);
1515 case LFUN_FLOAT_LIST: {
1516 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1517 if (tclass.floats().typeExist(cmd.argument)) {
1518 // not quite sure if we want this...
1520 cur.clearSelection();
1521 breakParagraph(cur);
1523 if (cur.lastpos() != 0) {
1525 breakParagraph(cur);
1528 setLayout(cur, tclass.defaultLayoutName());
1529 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1530 insertInset(cur, new InsetFloatList(cmd.argument));
1533 lyxerr << "Non-existent float type: "
1534 << cmd.argument << endl;
1539 case LFUN_ACCEPT_CHANGE: {
1544 case LFUN_REJECT_CHANGE: {
1549 case LFUN_THESAURUS_ENTRY: {
1550 string arg = cmd.argument;
1552 arg = cur.selectionAsString(false);
1554 if (arg.size() > 100 || arg.empty()) {
1555 // Get word or selection
1556 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1557 arg = cur.selectionAsString(false);
1560 bv->owner()->getDialogs().show("thesaurus", arg);
1564 case LFUN_PARAGRAPH_APPLY: {
1565 // Given data, an encoding of the ParagraphParameters
1566 // generated in the Paragraph dialog, this function sets
1567 // the current paragraph appropriately.
1568 istringstream is(cmd.argument);
1571 ParagraphParameters params;
1576 params.labelWidthString(),
1578 cur.message(_("Paragraph layout set"));
1582 case LFUN_INSET_DIALOG_SHOW: {
1583 InsetBase * inset = cur.nextInset();
1585 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1586 inset->dispatch(cur, fr);
1592 if (cur.selection()) {
1593 cur.selection() = false;
1596 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1605 // avoid to update when navigating
1607 && &sl.inset() == &cur.inset()
1608 && sl.idx() == cur.idx()
1610 && cur.selection() == false)
1615 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1616 FuncStatus & flag) const
1618 BOOST_ASSERT(cur.text() == this);
1619 LyXFont const & font = real_current_font;
1622 switch (cmd.action) {
1624 case LFUN_DEPTH_MIN:
1625 enable = changeDepthAllowed(cur, DEC_DEPTH);
1628 case LFUN_DEPTH_PLUS:
1629 enable = changeDepthAllowed(cur, INC_DEPTH);
1632 case LFUN_INSET_OPTARG:
1633 enable = numberOfOptArgs(cur.paragraph())
1634 < cur.paragraph().layout()->optionalargs;
1638 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1642 // the functions which insert insets
1643 InsetBase::Code code = InsetBase::NO_CODE;
1644 switch (cmd.action) {
1645 case LFUN_DIALOG_SHOW_NEW_INSET:
1646 if (cmd.argument == "bibitem")
1647 code = InsetBase::BIBITEM_CODE;
1648 else if (cmd.argument == "bibtex")
1649 code = InsetBase::BIBTEX_CODE;
1650 else if (cmd.argument == "box")
1651 code = InsetBase::BOX_CODE;
1652 else if (cmd.argument == "branch")
1653 code = InsetBase::BRANCH_CODE;
1654 else if (cmd.argument == "citation")
1655 code = InsetBase::CITE_CODE;
1656 else if (cmd.argument == "ert")
1657 code = InsetBase::ERT_CODE;
1658 else if (cmd.argument == "external")
1659 code = InsetBase::EXTERNAL_CODE;
1660 else if (cmd.argument == "float")
1661 code = InsetBase::FLOAT_CODE;
1662 else if (cmd.argument == "graphics")
1663 code = InsetBase::GRAPHICS_CODE;
1664 else if (cmd.argument == "include")
1665 code = InsetBase::INCLUDE_CODE;
1666 else if (cmd.argument == "index")
1667 code = InsetBase::INDEX_CODE;
1668 else if (cmd.argument == "label")
1669 code = InsetBase::LABEL_CODE;
1670 else if (cmd.argument == "note")
1671 code = InsetBase::NOTE_CODE;
1672 else if (cmd.argument == "ref")
1673 code = InsetBase::REF_CODE;
1674 else if (cmd.argument == "toc")
1675 code = InsetBase::TOC_CODE;
1676 else if (cmd.argument == "url")
1677 code = InsetBase::URL_CODE;
1678 else if (cmd.argument == "vspace")
1679 code = InsetBase::VSPACE_CODE;
1680 else if (cmd.argument == "wrap")
1681 code = InsetBase::WRAP_CODE;
1684 case LFUN_INSET_ERT:
1685 code = InsetBase::ERT_CODE;
1687 case LFUN_INSET_FOOTNOTE:
1688 code = InsetBase::FOOT_CODE;
1690 case LFUN_TABULAR_INSERT:
1691 code = InsetBase::TABULAR_CODE;
1693 case LFUN_INSET_MARGINAL:
1694 code = InsetBase::MARGIN_CODE;
1696 case LFUN_INSET_FLOAT:
1697 case LFUN_INSET_WIDE_FLOAT:
1698 code = InsetBase::FLOAT_CODE;
1700 case LFUN_INSET_WRAP:
1701 code = InsetBase::WRAP_CODE;
1703 case LFUN_FLOAT_LIST:
1704 code = InsetBase::FLOAT_LIST_CODE;
1707 case LFUN_INSET_LIST:
1708 code = InsetBase::LIST_CODE;
1710 case LFUN_INSET_THEOREM:
1711 code = InsetBase::THEOREM_CODE;
1714 case LFUN_INSET_CAPTION:
1715 code = InsetBase::CAPTION_CODE;
1717 case LFUN_INSERT_NOTE:
1718 code = InsetBase::NOTE_CODE;
1720 case LFUN_INSERT_CHARSTYLE:
1721 code = InsetBase::CHARSTYLE_CODE;
1722 if (buf->params().getLyXTextClass().charstyles().empty())
1725 case LFUN_INSERT_BOX:
1726 code = InsetBase::BOX_CODE;
1728 case LFUN_INSERT_BRANCH:
1729 code = InsetBase::BRANCH_CODE;
1730 if (buf->params().branchlist().empty())
1733 case LFUN_INSERT_LABEL:
1734 code = InsetBase::LABEL_CODE;
1736 case LFUN_INSET_OPTARG:
1737 code = InsetBase::OPTARG_CODE;
1739 case LFUN_ENVIRONMENT_INSERT:
1740 code = InsetBase::BOX_CODE;
1742 case LFUN_INDEX_INSERT:
1743 code = InsetBase::INDEX_CODE;
1745 case LFUN_INDEX_PRINT:
1746 code = InsetBase::INDEX_PRINT_CODE;
1748 case LFUN_TOC_INSERT:
1749 code = InsetBase::TOC_CODE;
1753 code = InsetBase::URL_CODE;
1756 // always allow this, since we will inset a raw quote
1757 // if an inset is not allowed.
1759 case LFUN_HYPHENATION:
1760 case LFUN_LIGATURE_BREAK:
1762 case LFUN_MENU_SEPARATOR:
1764 case LFUN_END_OF_SENTENCE:
1765 code = InsetBase::SPECIALCHAR_CODE;
1767 case LFUN_SPACE_INSERT:
1768 // slight hack: we know this is allowed in math mode
1770 code = InsetBase::SPACE_CODE;
1772 case LFUN_INSET_DIALOG_SHOW: {
1773 InsetBase * inset = cur.nextInset();
1776 code = inset->lyxCode();
1777 if (!(code == InsetBase::INCLUDE_CODE
1778 || code == InsetBase::BIBTEX_CODE
1779 || code == InsetBase::FLOAT_LIST_CODE
1780 || code == InsetBase::TOC_CODE))
1789 if (code != InsetBase::NO_CODE
1790 && (cur.empty() || !cur.inset().insetAllowed(code)))
1795 case LFUN_DIALOG_SHOW_NEW_INSET:
1796 case LFUN_INSET_ERT:
1797 case LFUN_INSERT_BOX:
1798 case LFUN_INSERT_BRANCH:
1799 case LFUN_ENVIRONMENT_INSERT:
1800 case LFUN_INDEX_INSERT:
1801 case LFUN_INDEX_PRINT:
1802 case LFUN_TOC_INSERT:
1806 case LFUN_HYPHENATION:
1807 case LFUN_LIGATURE_BREAK:
1809 case LFUN_MENU_SEPARATOR:
1811 case LFUN_END_OF_SENTENCE:
1812 case LFUN_SPACE_INSERT:
1813 case LFUN_INSET_DIALOG_SHOW:
1817 flag.setOnOff(font.emph() == LyXFont::ON);
1821 flag.setOnOff(font.noun() == LyXFont::ON);
1825 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1829 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1833 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1837 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1840 case LFUN_DELETE_WORD_FORWARD:
1841 case LFUN_DELETE_WORD_BACKWARD:
1842 case LFUN_DELETE_LINE_FORWARD:
1843 case LFUN_WORDRIGHT:
1853 case LFUN_UP_PARAGRAPHSEL:
1854 case LFUN_DOWN_PARAGRAPHSEL:
1859 case LFUN_WORDRIGHTSEL:
1860 case LFUN_WORDLEFTSEL:
1862 case LFUN_UP_PARAGRAPH:
1863 case LFUN_DOWN_PARAGRAPH:
1868 case LFUN_BREAKLINE:
1870 case LFUN_DELETE_SKIP:
1871 case LFUN_BACKSPACE:
1872 case LFUN_BACKSPACE_SKIP:
1873 case LFUN_BREAKPARAGRAPH:
1874 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1875 case LFUN_BREAKPARAGRAPH_SKIP:
1876 case LFUN_PARAGRAPH_SPACING:
1877 case LFUN_INSET_APPLY:
1878 case LFUN_INSET_INSERT:
1879 case LFUN_NEXT_INSET_TOGGLE:
1880 case LFUN_UPCASE_WORD:
1881 case LFUN_LOWCASE_WORD:
1882 case LFUN_CAPITALIZE_WORD:
1883 case LFUN_TRANSPOSE_CHARS:
1890 case LFUN_GETLAYOUT:
1892 case LFUN_PASTESELECTION:
1893 case LFUN_GOTOERROR:
1895 case LFUN_REFERENCE_GOTO:
1896 case LFUN_DATE_INSERT:
1897 case LFUN_SELFINSERT:
1898 case LFUN_INSERT_LABEL:
1899 case LFUN_INSERT_NOTE:
1900 case LFUN_INSERT_CHARSTYLE:
1901 case LFUN_INSERT_BIBITEM:
1902 case LFUN_INSET_FLOAT:
1903 case LFUN_INSET_FOOTNOTE:
1904 case LFUN_INSET_MARGINAL:
1905 case LFUN_INSET_WIDE_FLOAT:
1906 case LFUN_INSET_WRAP:
1907 case LFUN_TABULAR_INSERT:
1908 case LFUN_INSERT_LINE:
1909 case LFUN_INSERT_PAGEBREAK:
1910 case LFUN_MATH_DISPLAY:
1911 case LFUN_MATH_IMPORT_SELECTION:
1912 case LFUN_MATH_MODE:
1913 case LFUN_MATH_MACRO:
1914 case LFUN_INSERT_MATH:
1915 case LFUN_INSERT_MATRIX:
1916 case LFUN_MATH_DELIM:
1917 case LFUN_SUBSCRIPT:
1918 case LFUN_SUPERSCRIPT:
1920 case LFUN_UNDERLINE:
1921 case LFUN_FONT_SIZE:
1923 case LFUN_FREEFONT_APPLY:
1924 case LFUN_FREEFONT_UPDATE:
1925 case LFUN_LAYOUT_PARAGRAPH:
1926 case LFUN_PARAGRAPH_UPDATE:
1928 case LFUN_CIRCUMFLEX:
1938 case LFUN_SPECIAL_CARON:
1941 case LFUN_HUNG_UMLAUT:
1944 case LFUN_FLOAT_LIST:
1945 case LFUN_ACCEPT_CHANGE:
1946 case LFUN_REJECT_CHANGE:
1947 case LFUN_THESAURUS_ENTRY:
1948 case LFUN_PARAGRAPH_APPLY:
1950 case LFUN_KEYMAP_TOGGLE:
1952 case LFUN_BEGINNINGBUF:
1953 case LFUN_BEGINNINGBUFSEL:
1954 case LFUN_ENDBUFSEL:
1955 // these are handled in our dispatch()
1962 flag.enabled(enable);