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;
86 // the selection possible is needed, that only motion events are
87 // used, where the button press event was on the drawing area too
88 bool selection_possible = false;
94 LyXFont freefont(LyXFont::ALL_IGNORE);
95 bool toggleall = false;
98 void toggleAndShow(LCursor & cur, LyXText * text,
99 LyXFont const & font, bool toggleall = true)
101 text->toggleFree(cur, font, toggleall);
103 if (font.language() != ignore_language ||
104 font.number() != LyXFont::IGNORE) {
105 Paragraph & par = cur.paragraph();
106 text->bidi.computeTables(par, cur.buffer(), cur.textRow());
107 if (cur.boundary() !=
108 text->bidi.isBoundary(cur.buffer(), par,
110 text->real_current_font))
111 text->setCursor(cur, cur.par(), cur.pos(),
112 false, !cur.boundary());
117 void moveCursor(LCursor & cur, bool selecting)
119 if (selecting || cur.mark())
121 if (!cur.selection())
122 cur.bv().haveSelection(false);
123 cur.bv().switchKeyMap();
127 void finishChange(LCursor & cur, bool selecting)
130 moveCursor(cur, selecting);
134 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
137 string sel = cur.selectionAsString(false);
138 lyxerr << "selection is: '" << sel << "'" << endl;
141 const int old_pos = cur.pos();
142 cur.insert(new MathHullInset);
143 BOOST_ASSERT(old_pos == cur.pos());
144 cur.nextInset()->edit(cur, true);
145 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
146 // don't do that also for LFUN_MATH_MODE unless you want end up with
147 // always changing to mathrm when opening an inlined inset
148 // -- I really hate "LyXfunc overloading"...
150 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
151 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
153 // create a macro if we see "\\newcommand" somewhere, and an ordinary
155 cutSelection(cur, true, true);
156 if (sel.find("\\newcommand") == string::npos
157 && sel.find("\\def") == string::npos)
159 cur.insert(new MathHullInset);
160 cur.dispatch(FuncRequest(LFUN_RIGHT));
161 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
162 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
164 istringstream is(sel);
165 cur.insert(new MathMacroTemplate(is));
168 cur.message(N_("Math editor mode"));
177 string const freefont2string()
180 if (font2string(freefont, toggleall, data))
187 bool LyXText::gotoNextInset(LCursor & cur,
188 vector<InsetOld_code> const & codes, string const & contents)
190 BOOST_ASSERT(this == cur.text());
191 par_type end = paragraphs().size();
192 par_type pit = cur.par();
193 pos_type pos = cur.pos();
197 if (pos + 1 < pars_[pit].size()) {
204 } while (pit != end &&
205 !(pars_[pit].isInset(pos) &&
206 (inset = pars_[pit].getInset(pos)) != 0 &&
207 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
209 static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
215 setCursor(cur, pit, pos, false);
220 void LyXText::gotoInset(LCursor & cur,
221 vector<InsetOld_code> const & codes, bool same_content)
223 cur.clearSelection();
227 && cur.pos() < cur.lastpos()
228 && cur.paragraph().isInset(cur.pos())) {
229 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
230 if (find(codes.begin(), codes.end(), inset->lyxCode())
232 contents = static_cast<InsetCommand const *>(inset)->getContents();
235 if (!gotoNextInset(cur, codes, contents)) {
236 if (cur.pos() || cur.par() != 0) {
237 CursorSlice tmp = cur.top();
240 if (!gotoNextInset(cur, codes, contents)) {
242 cur.message(_("No more insets"));
245 cur.message(_("No more insets"));
252 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
254 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
258 void LyXText::cursorPrevious(LCursor & cur)
260 pos_type cpos = cur.pos();
261 lyx::par_type cpar = cur.par();
263 int x = cur.x_target();
264 int y = cur.bv().top_y();
265 setCursorFromCoordinates(cur, x, y);
267 if (cpar == cur.par() && cpos == cur.pos()) {
268 // we have a row which is taller than the workarea. The
269 // simplest solution is to move to the previous row instead.
273 cur.bv().updateScrollbar();
278 void LyXText::cursorNext(LCursor & cur)
280 pos_type cpos = cur.pos();
281 lyx::par_type cpar = cur.par();
283 int x = cur.x_target();
284 int y = cur.bv().top_y() + cur.bv().workHeight();
285 setCursorFromCoordinates(cur, x, y);
287 if (cpar == cur.par() && cpos == cur.pos()) {
288 // we have a row which is taller than the workarea. The
289 // simplest solution is to move to the next row instead.
293 cur.bv().updateScrollbar();
300 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
302 lyx::cap::replaceSelection(cur);
303 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));
332 void LyXText::number(LCursor & cur)
334 LyXFont font(LyXFont::ALL_IGNORE);
335 font.setNumber(LyXFont::TOGGLE);
336 toggleAndShow(cur, this, font);
340 bool LyXText::isRTL(Paragraph const & par) const
342 return par.isRightToLeftPar(bv()->buffer()->params());
346 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
348 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
349 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
351 BOOST_ASSERT(cur.text() == this);
352 BufferView * bv = &cur.bv();
353 CursorSlice sl = cur.top();
354 bool sel = cur.selection();
357 switch (cmd.action) {
359 case LFUN_APPENDIX: {
360 Paragraph & par = cur.paragraph();
361 bool start = !par.params().startOfAppendix();
363 // ensure that we have only one start_of_appendix in this document
364 for (par_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
365 if (pars_[tmp].params().startOfAppendix()) {
367 pars_[tmp].params().startOfAppendix(false);
374 par.params().startOfAppendix(start);
376 // we can set the refreshing parameters now
382 case LFUN_DELETE_WORD_FORWARD:
383 cur.clearSelection();
384 deleteWordForward(cur);
385 finishChange(cur, false);
388 case LFUN_DELETE_WORD_BACKWARD:
389 cur.clearSelection();
390 deleteWordBackward(cur);
391 finishChange(cur, false);
394 case LFUN_DELETE_LINE_FORWARD:
395 cur.clearSelection();
396 deleteLineForward(cur);
397 finishChange(cur, false);
403 cur.clearSelection();
404 if (isRTL(cur.paragraph()))
405 cursorLeftOneWord(cur);
407 cursorRightOneWord(cur);
408 finishChange(cur, false);
414 cur.clearSelection();
415 if (isRTL(cur.paragraph()))
416 cursorRightOneWord(cur);
418 cursorLeftOneWord(cur);
419 finishChange(cur, false);
422 case LFUN_BEGINNINGBUF:
423 if (cur.size() == 1) {
425 cur.clearSelection();
427 finishChange(cur, false);
434 if (cur.size() == 1) {
436 cur.clearSelection();
438 finishChange(cur, false);
447 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
448 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
449 if (isRTL(cur.paragraph()))
453 if (sl == cur.top()) {
455 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
462 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
463 cur.selHandle(cmd.action == LFUN_LEFTSEL);
464 if (isRTL(cur.paragraph()))
468 if (sl == cur.top()) {
470 cmd = FuncRequest(LFUN_FINISHED_LEFT);
477 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
478 cur.selHandle(cmd.action == LFUN_UPSEL);
480 if (sl == cur.top()) {
482 cmd = FuncRequest(LFUN_FINISHED_UP);
489 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
490 cur.selHandle(cmd.action == LFUN_DOWNSEL);
492 if (sl == cur.top()) {
494 cmd = FuncRequest(LFUN_FINISHED_DOWN);
498 case LFUN_UP_PARAGRAPHSEL:
499 if (!cur.selection())
501 cursorUpParagraph(cur);
502 finishChange(cur, true);
505 case LFUN_DOWN_PARAGRAPHSEL:
506 if (!cur.selection())
508 cursorDownParagraph(cur);
509 finishChange(cur, true);
513 if (!cur.selection())
516 finishChange(cur, true);
520 if (!cur.selection())
523 finishChange(cur, true);
527 if (!cur.selection())
530 finishChange(cur, true);
534 if (!cur.selection())
537 finishChange(cur, true);
540 case LFUN_WORDRIGHTSEL:
541 if (!cur.selection())
543 if (isRTL(cur.paragraph()))
544 cursorLeftOneWord(cur);
546 cursorRightOneWord(cur);
547 finishChange(cur, true);
550 case LFUN_WORDLEFTSEL:
551 if (!cur.selection())
553 if (isRTL(cur.paragraph()))
554 cursorRightOneWord(cur);
556 cursorLeftOneWord(cur);
557 finishChange(cur, true);
561 selectWord(cur, lyx::WHOLE_WORD);
562 finishChange(cur, true);
566 case LFUN_UP_PARAGRAPH:
569 cur.clearSelection();
570 cursorUpParagraph(cur);
571 finishChange(cur, false);
574 case LFUN_DOWN_PARAGRAPH:
577 cur.clearSelection();
578 cursorDownParagraph(cur);
579 finishChange(cur, false);
585 cur.clearSelection();
586 finishChange(cur, false);
587 if (cur.par() == 0 && cur.textRow().pos() == 0) {
589 cmd = FuncRequest(LFUN_FINISHED_UP);
598 cur.clearSelection();
599 finishChange(cur, false);
600 if (cur.par() == cur.lastpar()
601 && cur.textRow().endpos() == cur.lastpos()) {
603 cmd = FuncRequest(LFUN_FINISHED_DOWN);
611 cur.clearSelection();
613 finishChange(cur, false);
618 cur.clearSelection();
620 finishChange(cur, false);
623 case LFUN_BREAKLINE: {
624 // Not allowed by LaTeX (labels or empty par)
625 if (cur.pos() > cur.paragraph().beginOfBody()) {
626 lyx::cap::replaceSelection(cur);
627 cur.insert(new InsetNewline);
628 moveCursor(cur, false);
634 if (!cur.selection()) {
637 // It is possible to make it a lot faster still
638 // just comment out the line below...
640 cutSelection(cur, true, false);
642 moveCursor(cur, false);
645 case LFUN_DELETE_SKIP:
646 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
647 if (!cur.selection()) {
648 if (cur.pos() == cur.lastpos()) {
655 cutSelection(cur, true, false);
661 if (!cur.selection()) {
662 if (bv->owner()->getIntl().getTransManager().backspace()) {
665 // It is possible to make it a lot faster still
666 // just comment out the line below...
669 cutSelection(cur, true, false);
674 case LFUN_BACKSPACE_SKIP:
675 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
676 if (!cur.selection()) {
680 //CursorSlice cur = cursor();
684 cutSelection(cur, true, false);
688 case LFUN_BREAKPARAGRAPH:
689 lyx::cap::replaceSelection(cur);
690 breakParagraph(cur, 0);
695 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
696 lyx::cap::replaceSelection(cur);
697 breakParagraph(cur, 1);
702 case LFUN_BREAKPARAGRAPH_SKIP: {
703 // When at the beginning of a paragraph, remove
704 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
705 lyx::cap::replaceSelection(cur);
707 cur.paragraph().params().labelWidthString(string());
709 breakParagraph(cur, 0);
715 case LFUN_PARAGRAPH_SPACING: {
716 Paragraph & par = cur.paragraph();
717 Spacing::Space cur_spacing = par.params().spacing().getSpace();
718 float cur_value = 1.0;
719 if (cur_spacing == Spacing::Other)
720 cur_value = par.params().spacing().getValue();
722 istringstream is(cmd.argument);
725 Spacing::Space new_spacing = cur_spacing;
726 float new_value = cur_value;
728 lyxerr << "Missing argument to `paragraph-spacing'"
730 } else if (tmp == "single") {
731 new_spacing = Spacing::Single;
732 } else if (tmp == "onehalf") {
733 new_spacing = Spacing::Onehalf;
734 } else if (tmp == "double") {
735 new_spacing = Spacing::Double;
736 } else if (tmp == "other") {
737 new_spacing = Spacing::Other;
740 lyxerr << "new_value = " << tmpval << endl;
743 } else if (tmp == "default") {
744 new_spacing = Spacing::Default;
746 lyxerr << _("Unknown spacing argument: ")
747 << cmd.argument << endl;
749 if (cur_spacing != new_spacing || cur_value != new_value) {
750 par.params().spacing(Spacing(new_spacing, new_value));
756 case LFUN_INSET_APPLY: {
757 string const name = cmd.getArg(0);
758 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
760 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
761 inset->dispatch(cur, fr);
763 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
769 case LFUN_INSET_INSERT: {
771 InsetBase * inset = createInset(bv, cmd);
773 insertInset(cur, inset);
779 case LFUN_INSET_SETTINGS:
780 if (cur.inset().asUpdatableInset())
781 cur.inset().asUpdatableInset()->showInsetDialog(bv);
784 case LFUN_NEXT_INSET_TOGGLE: {
785 InsetBase * inset = cur.nextInset();
787 cur.clearSelection();
788 FuncRequest fr = cmd;
789 fr.action = LFUN_INSET_TOGGLE;
790 inset->dispatch(cur, fr);
795 case LFUN_KEYMAP_TOGGLE:
796 cur.clearSelection();
800 case LFUN_SPACE_INSERT:
801 if (cur.paragraph().layout()->free_spacing)
802 insertChar(cur, ' ');
804 doInsertInset(cur, this, cmd, false, false);
805 moveCursor(cur, false);
808 case LFUN_HYPHENATION:
809 specialChar(cur, InsetSpecialChar::HYPHENATION);
812 case LFUN_LIGATURE_BREAK:
813 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
817 specialChar(cur, InsetSpecialChar::LDOTS);
820 case LFUN_END_OF_SENTENCE:
821 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
824 case LFUN_MENU_SEPARATOR:
825 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
828 case LFUN_UPCASE_WORD:
829 changeCase(cur, LyXText::text_uppercase);
832 case LFUN_LOWCASE_WORD:
833 changeCase(cur, LyXText::text_lowercase);
836 case LFUN_CAPITALIZE_WORD:
837 changeCase(cur, LyXText::text_capitalization);
840 case LFUN_TRANSPOSE_CHARS:
846 cur.message(_("Paste"));
847 lyx::cap::replaceSelection(cur);
849 #warning FIXME Check if the arg is in the domain of available selections.
851 if (isStrUnsignedInt(cmd.argument))
852 pasteSelection(cur, strToUnsignedInt(cmd.argument));
854 pasteSelection(cur, 0);
855 cur.clearSelection(); // bug 393
861 cutSelection(cur, true, true);
862 cur.message(_("Cut"));
867 cur.message(_("Copy"));
871 cur.message(tostr(cursorX(cur.top())) + ' '
872 + tostr(cursorY(cur.top())));
878 istringstream is(cmd.argument);
881 lyxerr << "SETXY: Could not parse coordinates in '"
882 << cmd.argument << std::endl;
884 setCursorFromCoordinates(cur, x, y);
889 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
891 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
898 cur.message(cur.paragraph().layout()->name());
902 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
903 << cmd.argument << endl;
905 // This is not the good solution to the empty argument
906 // problem, but it will hopefully suffice for 1.2.0.
907 // The correct solution would be to augument the
908 // function list/array with information about what
909 // functions needs arguments and their type.
910 if (cmd.argument.empty()) {
911 cur.errorMessage(_("LyX function 'layout' needs an argument."));
915 // Derive layout number from given argument (string)
916 // and current buffer's textclass (number)
917 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
918 bool hasLayout = tclass.hasLayout(cmd.argument);
919 string layout = cmd.argument;
921 // If the entry is obsolete, use the new one instead.
923 string const & obs = tclass[layout]->obsoleted_by();
929 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
934 bool change_layout = (current_layout != layout);
936 if (!change_layout && cur.selection() &&
937 cur.selBegin().par() != cur.selEnd().par())
939 par_type spit = cur.selBegin().par();
940 par_type epit = cur.selEnd().par() + 1;
941 while (spit != epit) {
942 if (pars_[spit].layout()->name() != current_layout) {
943 change_layout = true;
951 current_layout = layout;
952 setLayout(cur, layout);
953 bv->owner()->setLayout(layout);
959 case LFUN_PASTESELECTION: {
960 cur.clearSelection();
961 string const clip = bv->getClipboard();
963 if (cmd.argument == "paragraph")
964 insertStringAsParagraphs(cur, clip);
966 insertStringAsLines(cur, clip);
972 gotoInset(cur, InsetBase::ERROR_CODE, false);
976 gotoInset(cur, InsetBase::NOTE_CODE, false);
979 case LFUN_REFERENCE_GOTO: {
980 vector<InsetOld_code> tmp;
981 tmp.push_back(InsetBase::LABEL_CODE);
982 tmp.push_back(InsetBase::REF_CODE);
983 gotoInset(cur, tmp, true);
988 lyx::cap::replaceSelection(cur);
989 Paragraph & par = cur.paragraph();
990 lyx::pos_type pos = cur.pos();
994 else if (cur.prevInset() && cur.prevInset()->isSpace())
997 c = par.getChar(pos - 1);
999 LyXLayout_ptr const & style = par.layout();
1001 BufferParams const & bufparams = bv->buffer()->params();
1002 if (!style->pass_thru
1003 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1004 string arg = cmd.argument;
1005 if (arg == "single")
1006 cur.insert(new InsetQuotes(c,
1007 bufparams.quotes_language,
1008 InsetQuotes::SingleQ));
1009 else if (arg == "double")
1010 cur.insert(new InsetQuotes(c,
1011 bufparams.quotes_language,
1012 InsetQuotes::DoubleQ));
1014 cur.insert(new InsetQuotes(c, bufparams));
1018 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1022 case LFUN_DATE_INSERT: {
1023 lyx::cap::replaceSelection(cur);
1024 time_t now_time_t = time(NULL);
1025 struct tm * now_tm = localtime(&now_time_t);
1026 setlocale(LC_TIME, "");
1028 if (!cmd.argument.empty())
1031 arg = lyxrc.date_insert_format;
1033 int const datetmp_len =
1034 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1036 for (int i = 0; i < datetmp_len; i++)
1037 insertChar(cur, datetmp[i]);
1040 moveCursor(cur, false);
1044 case LFUN_MOUSE_TRIPLE:
1045 if (cmd.button() == mouse_button::button1) {
1046 selection_possible = true;
1051 bv->haveSelection(cur.selection());
1055 case LFUN_MOUSE_DOUBLE:
1056 if (cmd.button() == mouse_button::button1) {
1057 selection_possible = true;
1058 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1059 bv->haveSelection(cur.selection());
1063 // Single-click on work area
1064 case LFUN_MOUSE_PRESS: {
1065 // Right click on a footnote flag opens float menu
1066 if (cmd.button() == mouse_button::button3) {
1067 cur.clearSelection();
1068 selection_possible = false;
1072 // Middle button press pastes if we have a selection
1073 // We do this here as if the selection was inside an inset
1074 // it could get cleared on the unlocking of the inset so
1075 // we have to check this first
1076 bool paste_internally = false;
1077 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1078 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1079 paste_internally = true;
1082 selection_possible = true;
1084 // Clear the selection
1085 cur.clearSelection();
1087 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1090 cur.x_target() = cursorX(cur.top());
1092 // Has the cursor just left the inset?
1093 if (bv->cursor().inMathed() && !cur.inMathed())
1094 bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1099 // Don't allow selection after a big jump.
1100 if (bv->fitCursor())
1101 selection_possible = false;
1103 // Insert primary selection with middle mouse
1104 // if there is a local selection in the current buffer,
1106 if (cmd.button() == mouse_button::button2) {
1107 if (paste_internally)
1108 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1110 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1111 selection_possible = false;
1117 case LFUN_MOUSE_MOTION: {
1118 // Only use motion with button 1
1119 //if (cmd.button() != mouse_button::button1)
1121 // We want to use only motion events for which
1122 // the button press event was on the drawing area too.
1123 if (!selection_possible) {
1124 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1125 "dispatch: no selection possible\n";
1126 lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
1130 // ignore motions deeper nested than the real anchor
1131 LCursor & bvcur = cur.bv().cursor();
1132 if (bvcur.anchor_.hasPart(cur)) {
1133 CursorSlice old = cur.top();
1134 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1136 // This is to allow jumping over large insets
1137 // FIXME: shouldn't be top-text-specific
1138 if (isMainText() && cur.top() == old) {
1139 if (cmd.y - bv->top_y() >= bv->workHeight())
1141 else if (cmd.y - bv->top_y() < 0)
1145 // don't set anchor_
1146 bv->cursor().setCursor(cur);
1147 bv->cursor().selection() = true;
1148 lyxerr << "MOTION: " << bv->cursor() << endl;
1153 case LFUN_MOUSE_RELEASE: {
1154 selection_possible = false;
1156 if (cmd.button() == mouse_button::button2)
1160 if (cmd.button() == mouse_button::button1)
1161 bv->haveSelection(cur.selection());
1164 bv->owner()->updateMenubar();
1165 bv->owner()->updateToolbars();
1169 case LFUN_SELFINSERT: {
1170 if (cmd.argument.empty())
1173 // Automatically delete the currently selected
1174 // text and replace it with what is being
1175 // typed in now. Depends on lyxrc settings
1176 // "auto_region_delete", which defaults to
1179 if (lyxrc.auto_region_delete) {
1180 if (cur.selection())
1181 cutSelection(cur, false, false);
1182 bv->haveSelection(false);
1185 cur.clearSelection();
1186 LyXFont const old_font = real_current_font;
1188 string::const_iterator cit = cmd.argument.begin();
1189 string::const_iterator end = cmd.argument.end();
1190 for (; cit != end; ++cit)
1191 bv->owner()->getIntl().getTransManager().
1192 TranslateAndInsert(*cit, this);
1195 moveCursor(cur, false);
1197 // real_current_font.number can change so we need to
1198 // update the minibuffer
1199 if (old_font != real_current_font)
1200 bv->updateScrollbar();
1205 InsetCommandParams p("url");
1206 string const data = InsetCommandMailer::params2string("url", p);
1207 bv->owner()->getDialogs().show("url", data, 0);
1211 case LFUN_HTMLURL: {
1212 InsetCommandParams p("htmlurl");
1213 string const data = InsetCommandMailer::params2string("url", p);
1214 bv->owner()->getDialogs().show("url", data, 0);
1218 case LFUN_INSERT_LABEL: {
1219 // Try to generate a valid label
1220 string const contents = cmd.argument.empty() ?
1221 cur.getPossibleLabel() : cmd.argument;
1223 InsetCommandParams p("label", contents);
1224 string const data = InsetCommandMailer::params2string("label", p);
1226 if (cmd.argument.empty()) {
1227 bv->owner()->getDialogs().show("label", data, 0);
1229 FuncRequest fr(LFUN_INSET_INSERT, data);
1237 case LFUN_INSET_LIST:
1238 case LFUN_INSET_THEOREM:
1239 case LFUN_INSET_CAPTION:
1241 case LFUN_INSERT_NOTE:
1242 case LFUN_INSERT_CHARSTYLE:
1243 case LFUN_INSERT_BOX:
1244 case LFUN_INSERT_BRANCH:
1245 case LFUN_INSERT_BIBITEM:
1246 case LFUN_INSET_ERT:
1247 case LFUN_INSET_FLOAT:
1248 case LFUN_INSET_FOOTNOTE:
1249 case LFUN_INSET_MARGINAL:
1250 case LFUN_INSET_OPTARG:
1251 case LFUN_INSET_WIDE_FLOAT:
1252 case LFUN_INSET_WRAP:
1253 case LFUN_TABULAR_INSERT:
1254 case LFUN_ENVIRONMENT_INSERT:
1255 // Open the inset, and move the current selection
1257 doInsertInset(cur, this, cmd, true, true);
1261 case LFUN_INDEX_INSERT:
1262 // Just open the inset
1263 doInsertInset(cur, this, cmd, true, false);
1267 case LFUN_INDEX_PRINT:
1268 case LFUN_TOC_INSERT:
1270 case LFUN_INSERT_LINE:
1271 case LFUN_INSERT_PAGEBREAK:
1273 doInsertInset(cur, this, cmd, false, false);
1277 case LFUN_DEPTH_MIN:
1278 changeDepth(cur, DEC_DEPTH);
1281 case LFUN_DEPTH_PLUS:
1282 changeDepth(cur, INC_DEPTH);
1285 case LFUN_MATH_DISPLAY:
1286 mathDispatch(cur, cmd, true);
1289 case LFUN_MATH_IMPORT_SELECTION:
1290 case LFUN_MATH_MODE:
1291 mathDispatch(cur, cmd, false);
1294 case LFUN_MATH_MACRO:
1295 if (cmd.argument.empty())
1296 cur.errorMessage(N_("Missing argument"));
1298 string s = cmd.argument;
1299 string const s1 = token(s, ' ', 1);
1300 int const nargs = s1.empty() ? 0 : atoi(s1);
1301 string const s2 = token(s, ' ', 2);
1302 string const type = s2.empty() ? "newcommand" : s2;
1303 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1304 //cur.nextInset()->edit(cur, true);
1308 case LFUN_INSERT_MATH:
1309 case LFUN_INSERT_MATRIX:
1310 case LFUN_MATH_DELIM: {
1311 cur.insert(new MathHullInset);
1312 cur.dispatch(FuncRequest(LFUN_RIGHT));
1313 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1319 LyXFont font(LyXFont::ALL_IGNORE);
1320 font.setEmph(LyXFont::TOGGLE);
1321 toggleAndShow(cur, this, font);
1326 LyXFont font(LyXFont::ALL_IGNORE);
1327 font.setSeries(LyXFont::BOLD_SERIES);
1328 toggleAndShow(cur, this, font);
1333 LyXFont font(LyXFont::ALL_IGNORE);
1334 font.setNoun(LyXFont::TOGGLE);
1335 toggleAndShow(cur, this, font);
1340 LyXFont font(LyXFont::ALL_IGNORE);
1341 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1342 toggleAndShow(cur, this, font);
1347 LyXFont font(LyXFont::ALL_IGNORE);
1348 font.setFamily(LyXFont::SANS_FAMILY);
1349 toggleAndShow(cur, this, font);
1354 LyXFont font(LyXFont::ALL_IGNORE);
1355 font.setFamily(LyXFont::ROMAN_FAMILY);
1356 toggleAndShow(cur, this, font);
1360 case LFUN_DEFAULT: {
1361 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1362 toggleAndShow(cur, this, font);
1366 case LFUN_UNDERLINE: {
1367 LyXFont font(LyXFont::ALL_IGNORE);
1368 font.setUnderbar(LyXFont::TOGGLE);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_FONT_SIZE: {
1374 LyXFont font(LyXFont::ALL_IGNORE);
1375 font.setLyXSize(cmd.argument);
1376 toggleAndShow(cur, this, font);
1380 case LFUN_LANGUAGE: {
1381 Language const * lang = languages.getLanguage(cmd.argument);
1384 LyXFont font(LyXFont::ALL_IGNORE);
1385 font.setLanguage(lang);
1386 toggleAndShow(cur, this, font);
1391 case LFUN_FREEFONT_APPLY:
1392 toggleAndShow(cur, this, freefont, toggleall);
1393 cur.message(_("Character set"));
1396 // Set the freefont using the contents of \param data dispatched from
1397 // the frontends and apply it at the current cursor location.
1398 case LFUN_FREEFONT_UPDATE: {
1401 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1404 toggleAndShow(cur, this, freefont, toggleall);
1405 cur.message(_("Character set"));
1410 case LFUN_FINISHED_LEFT:
1411 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1414 case LFUN_FINISHED_RIGHT:
1415 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1419 case LFUN_FINISHED_UP:
1420 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1424 case LFUN_FINISHED_DOWN:
1425 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1429 case LFUN_LAYOUT_PARAGRAPH: {
1431 params2string(cur.paragraph(), data);
1432 data = "show\n" + data;
1433 bv->owner()->getDialogs().show("paragraph", data);
1437 case LFUN_PARAGRAPH_UPDATE: {
1438 if (!bv->owner()->getDialogs().visible("paragraph"))
1441 params2string(cur.paragraph(), data);
1443 // Will the paragraph accept changes from the dialog?
1444 InsetBase & inset = cur.inset();
1445 bool const accept = !inset.forceDefaultParagraphs(&inset);
1447 data = "update " + tostr(accept) + '\n' + data;
1448 bv->owner()->getDialogs().update("paragraph", data);
1453 case LFUN_CIRCUMFLEX:
1463 case LFUN_SPECIAL_CARON:
1466 case LFUN_HUNG_UMLAUT:
1469 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1470 if (!cmd.argument.empty())
1471 bv->owner()->getIntl().getTransManager()
1472 .TranslateAndInsert(cmd.argument[0], this);
1475 case LFUN_FLOAT_LIST: {
1476 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1477 if (tclass.floats().typeExist(cmd.argument)) {
1478 // not quite sure if we want this...
1480 cur.clearSelection();
1481 breakParagraph(cur);
1483 if (cur.lastpos() != 0) {
1485 breakParagraph(cur);
1488 setLayout(cur, tclass.defaultLayoutName());
1489 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1490 insertInset(cur, new InsetFloatList(cmd.argument));
1492 lyxerr << "Non-existent float type: "
1493 << cmd.argument << endl;
1498 case LFUN_ACCEPT_CHANGE: {
1503 case LFUN_REJECT_CHANGE: {
1508 case LFUN_THESAURUS_ENTRY: {
1509 string arg = cmd.argument;
1511 arg = cur.selectionAsString(false);
1513 if (arg.size() > 100 || arg.empty()) {
1514 // Get word or selection
1515 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1516 arg = cur.selectionAsString(false);
1519 bv->owner()->getDialogs().show("thesaurus", arg);
1523 case LFUN_PARAGRAPH_APPLY: {
1524 // Given data, an encoding of the ParagraphParameters
1525 // generated in the Paragraph dialog, this function sets
1526 // the current paragraph appropriately.
1527 istringstream is(cmd.argument);
1530 ParagraphParameters params;
1535 params.labelWidthString(),
1537 cur.message(_("Paragraph layout set"));
1541 case LFUN_INSET_DIALOG_SHOW: {
1542 InsetBase * inset = cur.nextInset();
1544 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1545 inset->dispatch(cur, fr);
1551 if (cur.selection()) {
1552 cur.selection() = false;
1555 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1564 // avoid to update when navigating
1566 && &sl.inset() == &cur.inset()
1567 && sl.idx() == cur.idx()
1569 && cur.selection() == false)
1574 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1575 FuncStatus & flag) const
1577 BOOST_ASSERT(cur.text() == this);
1578 LyXFont const & font = real_current_font;
1581 switch (cmd.action) {
1583 case LFUN_DEPTH_MIN:
1584 enable = changeDepthAllowed(cur, DEC_DEPTH);
1587 case LFUN_DEPTH_PLUS:
1588 enable = changeDepthAllowed(cur, INC_DEPTH);
1591 case LFUN_INSET_OPTARG:
1592 enable = cur.paragraph().layout()->optionalargs;
1596 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1600 // the functions which insert insets
1601 InsetOld::Code code = InsetOld::NO_CODE;
1602 switch (cmd.action) {
1603 case LFUN_DIALOG_SHOW_NEW_INSET:
1604 if (cmd.argument == "bibitem")
1605 code = InsetOld::BIBITEM_CODE;
1606 else if (cmd.argument == "bibtex")
1607 code = InsetOld::BIBTEX_CODE;
1608 else if (cmd.argument == "box")
1609 code = InsetOld::BOX_CODE;
1610 else if (cmd.argument == "branch")
1611 code = InsetOld::BRANCH_CODE;
1612 else if (cmd.argument == "citation")
1613 code = InsetOld::CITE_CODE;
1614 else if (cmd.argument == "ert")
1615 code = InsetOld::ERT_CODE;
1616 else if (cmd.argument == "external")
1617 code = InsetOld::EXTERNAL_CODE;
1618 else if (cmd.argument == "float")
1619 code = InsetOld::FLOAT_CODE;
1620 else if (cmd.argument == "graphics")
1621 code = InsetOld::GRAPHICS_CODE;
1622 else if (cmd.argument == "include")
1623 code = InsetOld::INCLUDE_CODE;
1624 else if (cmd.argument == "index")
1625 code = InsetOld::INDEX_CODE;
1626 else if (cmd.argument == "label")
1627 code = InsetOld::LABEL_CODE;
1628 else if (cmd.argument == "note")
1629 code = InsetOld::NOTE_CODE;
1630 else if (cmd.argument == "ref")
1631 code = InsetOld::REF_CODE;
1632 else if (cmd.argument == "toc")
1633 code = InsetOld::TOC_CODE;
1634 else if (cmd.argument == "url")
1635 code = InsetOld::URL_CODE;
1636 else if (cmd.argument == "vspace")
1637 code = InsetOld::VSPACE_CODE;
1638 else if (cmd.argument == "wrap")
1639 code = InsetOld::WRAP_CODE;
1642 case LFUN_INSET_ERT:
1643 code = InsetOld::ERT_CODE;
1645 case LFUN_INSET_FOOTNOTE:
1646 code = InsetOld::FOOT_CODE;
1648 case LFUN_TABULAR_INSERT:
1649 code = InsetOld::TABULAR_CODE;
1651 case LFUN_INSET_MARGINAL:
1652 code = InsetOld::MARGIN_CODE;
1654 case LFUN_INSET_FLOAT:
1655 case LFUN_INSET_WIDE_FLOAT:
1656 code = InsetOld::FLOAT_CODE;
1658 case LFUN_INSET_WRAP:
1659 code = InsetOld::WRAP_CODE;
1661 case LFUN_FLOAT_LIST:
1662 code = InsetOld::FLOAT_LIST_CODE;
1665 case LFUN_INSET_LIST:
1666 code = InsetOld::LIST_CODE;
1668 case LFUN_INSET_THEOREM:
1669 code = InsetOld::THEOREM_CODE;
1672 case LFUN_INSET_CAPTION:
1673 code = InsetOld::CAPTION_CODE;
1675 case LFUN_INSERT_NOTE:
1676 code = InsetOld::NOTE_CODE;
1678 case LFUN_INSERT_CHARSTYLE:
1679 code = InsetOld::CHARSTYLE_CODE;
1680 if (buf->params().getLyXTextClass().charstyles().empty())
1683 case LFUN_INSERT_BOX:
1684 code = InsetOld::BOX_CODE;
1686 case LFUN_INSERT_BRANCH:
1687 code = InsetOld::BRANCH_CODE;
1688 if (buf->params().branchlist().empty())
1691 case LFUN_INSERT_LABEL:
1692 code = InsetOld::LABEL_CODE;
1694 case LFUN_INSET_OPTARG:
1695 code = InsetOld::OPTARG_CODE;
1697 case LFUN_ENVIRONMENT_INSERT:
1698 code = InsetOld::BOX_CODE;
1700 case LFUN_INDEX_INSERT:
1701 code = InsetOld::INDEX_CODE;
1703 case LFUN_INDEX_PRINT:
1704 code = InsetOld::INDEX_PRINT_CODE;
1706 case LFUN_TOC_INSERT:
1707 code = InsetOld::TOC_CODE;
1711 code = InsetOld::URL_CODE;
1714 // always allow this, since we will inset a raw quote
1715 // if an inset is not allowed.
1717 case LFUN_HYPHENATION:
1718 case LFUN_LIGATURE_BREAK:
1720 case LFUN_MENU_SEPARATOR:
1722 case LFUN_END_OF_SENTENCE:
1723 code = InsetOld::SPECIALCHAR_CODE;
1725 case LFUN_SPACE_INSERT:
1726 // slight hack: we know this is allowed in math mode
1728 code = InsetOld::SPACE_CODE;
1730 case LFUN_INSET_DIALOG_SHOW: {
1731 InsetBase * inset = cur.nextInset();
1734 code = inset->lyxCode();
1735 if (!(code == InsetOld::INCLUDE_CODE
1736 || code == InsetOld::BIBTEX_CODE
1737 || code == InsetOld::FLOAT_LIST_CODE
1738 || code == InsetOld::TOC_CODE))
1747 if (code != InsetOld::NO_CODE
1748 && (cur.empty() || !cur.inset().insetAllowed(code)))
1753 case LFUN_DIALOG_SHOW_NEW_INSET:
1754 case LFUN_INSET_ERT:
1755 case LFUN_INSERT_BOX:
1756 case LFUN_INSERT_BRANCH:
1757 case LFUN_ENVIRONMENT_INSERT:
1758 case LFUN_INDEX_INSERT:
1759 case LFUN_INDEX_PRINT:
1760 case LFUN_TOC_INSERT:
1764 case LFUN_HYPHENATION:
1765 case LFUN_LIGATURE_BREAK:
1767 case LFUN_MENU_SEPARATOR:
1769 case LFUN_END_OF_SENTENCE:
1770 case LFUN_SPACE_INSERT:
1771 case LFUN_INSET_DIALOG_SHOW:
1775 flag.setOnOff(font.emph() == LyXFont::ON);
1779 flag.setOnOff(font.noun() == LyXFont::ON);
1783 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1787 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1791 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1795 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1798 case LFUN_DELETE_WORD_FORWARD:
1799 case LFUN_DELETE_WORD_BACKWARD:
1800 case LFUN_DELETE_LINE_FORWARD:
1801 case LFUN_WORDRIGHT:
1811 case LFUN_UP_PARAGRAPHSEL:
1812 case LFUN_DOWN_PARAGRAPHSEL:
1817 case LFUN_WORDRIGHTSEL:
1818 case LFUN_WORDLEFTSEL:
1820 case LFUN_UP_PARAGRAPH:
1821 case LFUN_DOWN_PARAGRAPH:
1826 case LFUN_BREAKLINE:
1828 case LFUN_DELETE_SKIP:
1829 case LFUN_BACKSPACE:
1830 case LFUN_BACKSPACE_SKIP:
1831 case LFUN_BREAKPARAGRAPH:
1832 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1833 case LFUN_BREAKPARAGRAPH_SKIP:
1834 case LFUN_PARAGRAPH_SPACING:
1835 case LFUN_INSET_APPLY:
1836 case LFUN_INSET_INSERT:
1837 case LFUN_NEXT_INSET_TOGGLE:
1838 case LFUN_UPCASE_WORD:
1839 case LFUN_LOWCASE_WORD:
1840 case LFUN_CAPITALIZE_WORD:
1841 case LFUN_TRANSPOSE_CHARS:
1848 case LFUN_GETLAYOUT:
1850 case LFUN_PASTESELECTION:
1851 case LFUN_GOTOERROR:
1853 case LFUN_REFERENCE_GOTO:
1854 case LFUN_DATE_INSERT:
1855 case LFUN_SELFINSERT:
1856 case LFUN_INSERT_LABEL:
1857 case LFUN_INSERT_NOTE:
1858 case LFUN_INSERT_CHARSTYLE:
1859 case LFUN_INSERT_BIBITEM:
1860 case LFUN_INSET_FLOAT:
1861 case LFUN_INSET_FOOTNOTE:
1862 case LFUN_INSET_MARGINAL:
1863 case LFUN_INSET_WIDE_FLOAT:
1864 case LFUN_INSET_WRAP:
1865 case LFUN_TABULAR_INSERT:
1866 case LFUN_INSERT_LINE:
1867 case LFUN_INSERT_PAGEBREAK:
1868 case LFUN_MATH_DISPLAY:
1869 case LFUN_MATH_IMPORT_SELECTION:
1870 case LFUN_MATH_MODE:
1871 case LFUN_MATH_MACRO:
1872 case LFUN_INSERT_MATH:
1873 case LFUN_INSERT_MATRIX:
1874 case LFUN_MATH_DELIM:
1876 case LFUN_UNDERLINE:
1877 case LFUN_FONT_SIZE:
1879 case LFUN_FREEFONT_APPLY:
1880 case LFUN_FREEFONT_UPDATE:
1881 case LFUN_LAYOUT_PARAGRAPH:
1882 case LFUN_PARAGRAPH_UPDATE:
1884 case LFUN_CIRCUMFLEX:
1894 case LFUN_SPECIAL_CARON:
1897 case LFUN_HUNG_UMLAUT:
1900 case LFUN_FLOAT_LIST:
1901 case LFUN_ACCEPT_CHANGE:
1902 case LFUN_REJECT_CHANGE:
1903 case LFUN_THESAURUS_ENTRY:
1904 case LFUN_PARAGRAPH_APPLY:
1906 case LFUN_KEYMAP_TOGGLE:
1907 // these are handled in our dispatch()
1912 case LFUN_BEGINNINGBUF:
1920 flag.enabled(enable);