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/tostr.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 float cur_value = 1.0;
757 if (cur_spacing == Spacing::Other)
758 cur_value = par.params().spacing().getValue();
760 istringstream is(cmd.argument);
763 Spacing::Space new_spacing = cur_spacing;
764 float 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;
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(tostr(cursorX(cur.top())) + ' '
909 + tostr(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 mathDispatch(cur, cmd, false);
1324 case LFUN_MATH_MACRO:
1325 if (cmd.argument.empty())
1326 cur.errorMessage(N_("Missing argument"));
1328 string s = cmd.argument;
1329 string const s1 = token(s, ' ', 1);
1330 int const nargs = s1.empty() ? 0 : atoi(s1);
1331 string const s2 = token(s, ' ', 2);
1332 string const type = s2.empty() ? "newcommand" : s2;
1333 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1334 //cur.nextInset()->edit(cur, true);
1338 case LFUN_INSERT_MATH:
1339 case LFUN_INSERT_MATRIX:
1340 case LFUN_MATH_DELIM: {
1341 cur.insert(new MathHullInset);
1342 cur.dispatch(FuncRequest(LFUN_RIGHT));
1343 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1349 LyXFont font(LyXFont::ALL_IGNORE);
1350 font.setEmph(LyXFont::TOGGLE);
1351 toggleAndShow(cur, this, font);
1356 LyXFont font(LyXFont::ALL_IGNORE);
1357 font.setSeries(LyXFont::BOLD_SERIES);
1358 toggleAndShow(cur, this, font);
1363 LyXFont font(LyXFont::ALL_IGNORE);
1364 font.setNoun(LyXFont::TOGGLE);
1365 toggleAndShow(cur, this, font);
1370 LyXFont font(LyXFont::ALL_IGNORE);
1371 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1372 toggleAndShow(cur, this, font);
1377 LyXFont font(LyXFont::ALL_IGNORE);
1378 font.setFamily(LyXFont::SANS_FAMILY);
1379 toggleAndShow(cur, this, font);
1384 LyXFont font(LyXFont::ALL_IGNORE);
1385 font.setFamily(LyXFont::ROMAN_FAMILY);
1386 toggleAndShow(cur, this, font);
1390 case LFUN_DEFAULT: {
1391 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1392 toggleAndShow(cur, this, font);
1396 case LFUN_UNDERLINE: {
1397 LyXFont font(LyXFont::ALL_IGNORE);
1398 font.setUnderbar(LyXFont::TOGGLE);
1399 toggleAndShow(cur, this, font);
1403 case LFUN_FONT_SIZE: {
1404 LyXFont font(LyXFont::ALL_IGNORE);
1405 font.setLyXSize(cmd.argument);
1406 toggleAndShow(cur, this, font);
1410 case LFUN_LANGUAGE: {
1411 Language const * lang = languages.getLanguage(cmd.argument);
1414 LyXFont font(LyXFont::ALL_IGNORE);
1415 font.setLanguage(lang);
1416 toggleAndShow(cur, this, font);
1421 case LFUN_FREEFONT_APPLY:
1422 toggleAndShow(cur, this, freefont, toggleall);
1423 cur.message(_("Character set"));
1426 // Set the freefont using the contents of \param data dispatched from
1427 // the frontends and apply it at the current cursor location.
1428 case LFUN_FREEFONT_UPDATE: {
1431 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1434 toggleAndShow(cur, this, freefont, toggleall);
1435 cur.message(_("Character set"));
1440 case LFUN_FINISHED_LEFT:
1441 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1444 case LFUN_FINISHED_RIGHT:
1445 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1449 case LFUN_FINISHED_UP:
1450 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1454 case LFUN_FINISHED_DOWN:
1455 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1459 case LFUN_LAYOUT_PARAGRAPH: {
1461 params2string(cur.paragraph(), data);
1462 data = "show\n" + data;
1463 bv->owner()->getDialogs().show("paragraph", data);
1467 case LFUN_PARAGRAPH_UPDATE: {
1468 if (!bv->owner()->getDialogs().visible("paragraph"))
1471 params2string(cur.paragraph(), data);
1473 // Will the paragraph accept changes from the dialog?
1474 InsetBase & inset = cur.inset();
1475 bool const accept = !inset.forceDefaultParagraphs(&inset);
1477 data = "update " + tostr(accept) + '\n' + data;
1478 bv->owner()->getDialogs().update("paragraph", data);
1483 case LFUN_CIRCUMFLEX:
1493 case LFUN_SPECIAL_CARON:
1496 case LFUN_HUNG_UMLAUT:
1499 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1500 if (!cmd.argument.empty())
1501 bv->owner()->getIntl().getTransManager()
1502 .TranslateAndInsert(cmd.argument[0], this);
1505 case LFUN_FLOAT_LIST: {
1506 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1507 if (tclass.floats().typeExist(cmd.argument)) {
1508 // not quite sure if we want this...
1510 cur.clearSelection();
1511 breakParagraph(cur);
1513 if (cur.lastpos() != 0) {
1515 breakParagraph(cur);
1518 setLayout(cur, tclass.defaultLayoutName());
1519 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1520 insertInset(cur, new InsetFloatList(cmd.argument));
1523 lyxerr << "Non-existent float type: "
1524 << cmd.argument << endl;
1529 case LFUN_ACCEPT_CHANGE: {
1534 case LFUN_REJECT_CHANGE: {
1539 case LFUN_THESAURUS_ENTRY: {
1540 string arg = cmd.argument;
1542 arg = cur.selectionAsString(false);
1544 if (arg.size() > 100 || arg.empty()) {
1545 // Get word or selection
1546 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1547 arg = cur.selectionAsString(false);
1550 bv->owner()->getDialogs().show("thesaurus", arg);
1554 case LFUN_PARAGRAPH_APPLY: {
1555 // Given data, an encoding of the ParagraphParameters
1556 // generated in the Paragraph dialog, this function sets
1557 // the current paragraph appropriately.
1558 istringstream is(cmd.argument);
1561 ParagraphParameters params;
1566 params.labelWidthString(),
1568 cur.message(_("Paragraph layout set"));
1572 case LFUN_INSET_DIALOG_SHOW: {
1573 InsetBase * inset = cur.nextInset();
1575 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1576 inset->dispatch(cur, fr);
1582 if (cur.selection()) {
1583 cur.selection() = false;
1586 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1595 // avoid to update when navigating
1597 && &sl.inset() == &cur.inset()
1598 && sl.idx() == cur.idx()
1600 && cur.selection() == false)
1605 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1606 FuncStatus & flag) const
1608 BOOST_ASSERT(cur.text() == this);
1609 LyXFont const & font = real_current_font;
1612 switch (cmd.action) {
1614 case LFUN_DEPTH_MIN:
1615 enable = changeDepthAllowed(cur, DEC_DEPTH);
1618 case LFUN_DEPTH_PLUS:
1619 enable = changeDepthAllowed(cur, INC_DEPTH);
1622 case LFUN_INSET_OPTARG:
1623 enable = numberOfOptArgs(cur.paragraph())
1624 < cur.paragraph().layout()->optionalargs;
1628 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1632 // the functions which insert insets
1633 InsetBase::Code code = InsetBase::NO_CODE;
1634 switch (cmd.action) {
1635 case LFUN_DIALOG_SHOW_NEW_INSET:
1636 if (cmd.argument == "bibitem")
1637 code = InsetBase::BIBITEM_CODE;
1638 else if (cmd.argument == "bibtex")
1639 code = InsetBase::BIBTEX_CODE;
1640 else if (cmd.argument == "box")
1641 code = InsetBase::BOX_CODE;
1642 else if (cmd.argument == "branch")
1643 code = InsetBase::BRANCH_CODE;
1644 else if (cmd.argument == "citation")
1645 code = InsetBase::CITE_CODE;
1646 else if (cmd.argument == "ert")
1647 code = InsetBase::ERT_CODE;
1648 else if (cmd.argument == "external")
1649 code = InsetBase::EXTERNAL_CODE;
1650 else if (cmd.argument == "float")
1651 code = InsetBase::FLOAT_CODE;
1652 else if (cmd.argument == "graphics")
1653 code = InsetBase::GRAPHICS_CODE;
1654 else if (cmd.argument == "include")
1655 code = InsetBase::INCLUDE_CODE;
1656 else if (cmd.argument == "index")
1657 code = InsetBase::INDEX_CODE;
1658 else if (cmd.argument == "label")
1659 code = InsetBase::LABEL_CODE;
1660 else if (cmd.argument == "note")
1661 code = InsetBase::NOTE_CODE;
1662 else if (cmd.argument == "ref")
1663 code = InsetBase::REF_CODE;
1664 else if (cmd.argument == "toc")
1665 code = InsetBase::TOC_CODE;
1666 else if (cmd.argument == "url")
1667 code = InsetBase::URL_CODE;
1668 else if (cmd.argument == "vspace")
1669 code = InsetBase::VSPACE_CODE;
1670 else if (cmd.argument == "wrap")
1671 code = InsetBase::WRAP_CODE;
1674 case LFUN_INSET_ERT:
1675 code = InsetBase::ERT_CODE;
1677 case LFUN_INSET_FOOTNOTE:
1678 code = InsetBase::FOOT_CODE;
1680 case LFUN_TABULAR_INSERT:
1681 code = InsetBase::TABULAR_CODE;
1683 case LFUN_INSET_MARGINAL:
1684 code = InsetBase::MARGIN_CODE;
1686 case LFUN_INSET_FLOAT:
1687 case LFUN_INSET_WIDE_FLOAT:
1688 code = InsetBase::FLOAT_CODE;
1690 case LFUN_INSET_WRAP:
1691 code = InsetBase::WRAP_CODE;
1693 case LFUN_FLOAT_LIST:
1694 code = InsetBase::FLOAT_LIST_CODE;
1697 case LFUN_INSET_LIST:
1698 code = InsetBase::LIST_CODE;
1700 case LFUN_INSET_THEOREM:
1701 code = InsetBase::THEOREM_CODE;
1704 case LFUN_INSET_CAPTION:
1705 code = InsetBase::CAPTION_CODE;
1707 case LFUN_INSERT_NOTE:
1708 code = InsetBase::NOTE_CODE;
1710 case LFUN_INSERT_CHARSTYLE:
1711 code = InsetBase::CHARSTYLE_CODE;
1712 if (buf->params().getLyXTextClass().charstyles().empty())
1715 case LFUN_INSERT_BOX:
1716 code = InsetBase::BOX_CODE;
1718 case LFUN_INSERT_BRANCH:
1719 code = InsetBase::BRANCH_CODE;
1720 if (buf->params().branchlist().empty())
1723 case LFUN_INSERT_LABEL:
1724 code = InsetBase::LABEL_CODE;
1726 case LFUN_INSET_OPTARG:
1727 code = InsetBase::OPTARG_CODE;
1729 case LFUN_ENVIRONMENT_INSERT:
1730 code = InsetBase::BOX_CODE;
1732 case LFUN_INDEX_INSERT:
1733 code = InsetBase::INDEX_CODE;
1735 case LFUN_INDEX_PRINT:
1736 code = InsetBase::INDEX_PRINT_CODE;
1738 case LFUN_TOC_INSERT:
1739 code = InsetBase::TOC_CODE;
1743 code = InsetBase::URL_CODE;
1746 // always allow this, since we will inset a raw quote
1747 // if an inset is not allowed.
1749 case LFUN_HYPHENATION:
1750 case LFUN_LIGATURE_BREAK:
1752 case LFUN_MENU_SEPARATOR:
1754 case LFUN_END_OF_SENTENCE:
1755 code = InsetBase::SPECIALCHAR_CODE;
1757 case LFUN_SPACE_INSERT:
1758 // slight hack: we know this is allowed in math mode
1760 code = InsetBase::SPACE_CODE;
1762 case LFUN_INSET_DIALOG_SHOW: {
1763 InsetBase * inset = cur.nextInset();
1766 code = inset->lyxCode();
1767 if (!(code == InsetBase::INCLUDE_CODE
1768 || code == InsetBase::BIBTEX_CODE
1769 || code == InsetBase::FLOAT_LIST_CODE
1770 || code == InsetBase::TOC_CODE))
1779 if (code != InsetBase::NO_CODE
1780 && (cur.empty() || !cur.inset().insetAllowed(code)))
1785 case LFUN_DIALOG_SHOW_NEW_INSET:
1786 case LFUN_INSET_ERT:
1787 case LFUN_INSERT_BOX:
1788 case LFUN_INSERT_BRANCH:
1789 case LFUN_ENVIRONMENT_INSERT:
1790 case LFUN_INDEX_INSERT:
1791 case LFUN_INDEX_PRINT:
1792 case LFUN_TOC_INSERT:
1796 case LFUN_HYPHENATION:
1797 case LFUN_LIGATURE_BREAK:
1799 case LFUN_MENU_SEPARATOR:
1801 case LFUN_END_OF_SENTENCE:
1802 case LFUN_SPACE_INSERT:
1803 case LFUN_INSET_DIALOG_SHOW:
1807 flag.setOnOff(font.emph() == LyXFont::ON);
1811 flag.setOnOff(font.noun() == LyXFont::ON);
1815 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1819 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1823 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1827 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1830 case LFUN_DELETE_WORD_FORWARD:
1831 case LFUN_DELETE_WORD_BACKWARD:
1832 case LFUN_DELETE_LINE_FORWARD:
1833 case LFUN_WORDRIGHT:
1843 case LFUN_UP_PARAGRAPHSEL:
1844 case LFUN_DOWN_PARAGRAPHSEL:
1849 case LFUN_WORDRIGHTSEL:
1850 case LFUN_WORDLEFTSEL:
1852 case LFUN_UP_PARAGRAPH:
1853 case LFUN_DOWN_PARAGRAPH:
1858 case LFUN_BREAKLINE:
1860 case LFUN_DELETE_SKIP:
1861 case LFUN_BACKSPACE:
1862 case LFUN_BACKSPACE_SKIP:
1863 case LFUN_BREAKPARAGRAPH:
1864 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1865 case LFUN_BREAKPARAGRAPH_SKIP:
1866 case LFUN_PARAGRAPH_SPACING:
1867 case LFUN_INSET_APPLY:
1868 case LFUN_INSET_INSERT:
1869 case LFUN_NEXT_INSET_TOGGLE:
1870 case LFUN_UPCASE_WORD:
1871 case LFUN_LOWCASE_WORD:
1872 case LFUN_CAPITALIZE_WORD:
1873 case LFUN_TRANSPOSE_CHARS:
1880 case LFUN_GETLAYOUT:
1882 case LFUN_PASTESELECTION:
1883 case LFUN_GOTOERROR:
1885 case LFUN_REFERENCE_GOTO:
1886 case LFUN_DATE_INSERT:
1887 case LFUN_SELFINSERT:
1888 case LFUN_INSERT_LABEL:
1889 case LFUN_INSERT_NOTE:
1890 case LFUN_INSERT_CHARSTYLE:
1891 case LFUN_INSERT_BIBITEM:
1892 case LFUN_INSET_FLOAT:
1893 case LFUN_INSET_FOOTNOTE:
1894 case LFUN_INSET_MARGINAL:
1895 case LFUN_INSET_WIDE_FLOAT:
1896 case LFUN_INSET_WRAP:
1897 case LFUN_TABULAR_INSERT:
1898 case LFUN_INSERT_LINE:
1899 case LFUN_INSERT_PAGEBREAK:
1900 case LFUN_MATH_DISPLAY:
1901 case LFUN_MATH_IMPORT_SELECTION:
1902 case LFUN_MATH_MODE:
1903 case LFUN_MATH_MACRO:
1904 case LFUN_INSERT_MATH:
1905 case LFUN_INSERT_MATRIX:
1906 case LFUN_MATH_DELIM:
1908 case LFUN_UNDERLINE:
1909 case LFUN_FONT_SIZE:
1911 case LFUN_FREEFONT_APPLY:
1912 case LFUN_FREEFONT_UPDATE:
1913 case LFUN_LAYOUT_PARAGRAPH:
1914 case LFUN_PARAGRAPH_UPDATE:
1916 case LFUN_CIRCUMFLEX:
1926 case LFUN_SPECIAL_CARON:
1929 case LFUN_HUNG_UMLAUT:
1932 case LFUN_FLOAT_LIST:
1933 case LFUN_ACCEPT_CHANGE:
1934 case LFUN_REJECT_CHANGE:
1935 case LFUN_THESAURUS_ENTRY:
1936 case LFUN_PARAGRAPH_APPLY:
1938 case LFUN_KEYMAP_TOGGLE:
1940 case LFUN_BEGINNINGBUF:
1941 case LFUN_BEGINNINGBUFSEL:
1942 case LFUN_ENDBUFSEL:
1943 // these are handled in our dispatch()
1950 flag.enabled(enable);