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_.size() < cur.size())
1135 CursorSlice old = cur.top();
1136 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1138 // This is to allow jumping over large insets
1139 // FIXME: shouldn't be top-text-specific
1140 if (isMainText() && cur.top() == old) {
1141 if (cmd.y - bv->top_y() >= bv->workHeight())
1143 else if (cmd.y - bv->top_y() < 0)
1147 // don't set anchor_
1148 bv->cursor().setCursor(cur);
1149 bv->cursor().selection() = true;
1150 lyxerr << "MOTION: " << bv->cursor() << endl;
1154 case LFUN_MOUSE_RELEASE: {
1155 selection_possible = false;
1157 if (cmd.button() == mouse_button::button2)
1161 if (cmd.button() == mouse_button::button1)
1162 bv->haveSelection(cur.selection());
1165 bv->owner()->updateMenubar();
1166 bv->owner()->updateToolbars();
1170 case LFUN_SELFINSERT: {
1171 if (cmd.argument.empty())
1174 // Automatically delete the currently selected
1175 // text and replace it with what is being
1176 // typed in now. Depends on lyxrc settings
1177 // "auto_region_delete", which defaults to
1180 if (lyxrc.auto_region_delete) {
1181 if (cur.selection())
1182 cutSelection(cur, false, false);
1183 bv->haveSelection(false);
1186 cur.clearSelection();
1187 LyXFont const old_font = real_current_font;
1189 string::const_iterator cit = cmd.argument.begin();
1190 string::const_iterator end = cmd.argument.end();
1191 for (; cit != end; ++cit)
1192 bv->owner()->getIntl().getTransManager().
1193 TranslateAndInsert(*cit, this);
1196 moveCursor(cur, false);
1198 // real_current_font.number can change so we need to
1199 // update the minibuffer
1200 if (old_font != real_current_font)
1201 bv->updateScrollbar();
1206 InsetCommandParams p("url");
1207 string const data = InsetCommandMailer::params2string("url", p);
1208 bv->owner()->getDialogs().show("url", data, 0);
1212 case LFUN_HTMLURL: {
1213 InsetCommandParams p("htmlurl");
1214 string const data = InsetCommandMailer::params2string("url", p);
1215 bv->owner()->getDialogs().show("url", data, 0);
1219 case LFUN_INSERT_LABEL: {
1220 // Try to generate a valid label
1221 string const contents = cmd.argument.empty() ?
1222 cur.getPossibleLabel() : cmd.argument;
1224 InsetCommandParams p("label", contents);
1225 string const data = InsetCommandMailer::params2string("label", p);
1227 if (cmd.argument.empty()) {
1228 bv->owner()->getDialogs().show("label", data, 0);
1230 FuncRequest fr(LFUN_INSET_INSERT, data);
1238 case LFUN_INSET_LIST:
1239 case LFUN_INSET_THEOREM:
1240 case LFUN_INSET_CAPTION:
1242 case LFUN_INSERT_NOTE:
1243 case LFUN_INSERT_CHARSTYLE:
1244 case LFUN_INSERT_BOX:
1245 case LFUN_INSERT_BRANCH:
1246 case LFUN_INSERT_BIBITEM:
1247 case LFUN_INSET_ERT:
1248 case LFUN_INSET_FLOAT:
1249 case LFUN_INSET_FOOTNOTE:
1250 case LFUN_INSET_MARGINAL:
1251 case LFUN_INSET_OPTARG:
1252 case LFUN_INSET_WIDE_FLOAT:
1253 case LFUN_INSET_WRAP:
1254 case LFUN_TABULAR_INSERT:
1255 case LFUN_ENVIRONMENT_INSERT:
1256 // Open the inset, and move the current selection
1258 doInsertInset(cur, this, cmd, true, true);
1262 case LFUN_INDEX_INSERT:
1263 // Just open the inset
1264 doInsertInset(cur, this, cmd, true, false);
1268 case LFUN_INDEX_PRINT:
1269 case LFUN_TOC_INSERT:
1271 case LFUN_INSERT_LINE:
1272 case LFUN_INSERT_PAGEBREAK:
1274 doInsertInset(cur, this, cmd, false, false);
1278 case LFUN_DEPTH_MIN:
1279 changeDepth(cur, DEC_DEPTH);
1282 case LFUN_DEPTH_PLUS:
1283 changeDepth(cur, INC_DEPTH);
1286 case LFUN_MATH_DISPLAY:
1287 mathDispatch(cur, cmd, true);
1290 case LFUN_MATH_IMPORT_SELECTION:
1291 case LFUN_MATH_MODE:
1292 mathDispatch(cur, cmd, false);
1295 case LFUN_MATH_MACRO:
1296 if (cmd.argument.empty())
1297 cur.errorMessage(N_("Missing argument"));
1299 string s = cmd.argument;
1300 string const s1 = token(s, ' ', 1);
1301 int const nargs = s1.empty() ? 0 : atoi(s1);
1302 string const s2 = token(s, ' ', 2);
1303 string const type = s2.empty() ? "newcommand" : s2;
1304 cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1305 //cur.nextInset()->edit(cur, true);
1309 case LFUN_INSERT_MATH:
1310 case LFUN_INSERT_MATRIX:
1311 case LFUN_MATH_DELIM: {
1312 cur.insert(new MathHullInset);
1313 cur.dispatch(FuncRequest(LFUN_RIGHT));
1314 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1320 LyXFont font(LyXFont::ALL_IGNORE);
1321 font.setEmph(LyXFont::TOGGLE);
1322 toggleAndShow(cur, this, font);
1327 LyXFont font(LyXFont::ALL_IGNORE);
1328 font.setSeries(LyXFont::BOLD_SERIES);
1329 toggleAndShow(cur, this, font);
1334 LyXFont font(LyXFont::ALL_IGNORE);
1335 font.setNoun(LyXFont::TOGGLE);
1336 toggleAndShow(cur, this, font);
1341 LyXFont font(LyXFont::ALL_IGNORE);
1342 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1343 toggleAndShow(cur, this, font);
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setFamily(LyXFont::SANS_FAMILY);
1350 toggleAndShow(cur, this, font);
1355 LyXFont font(LyXFont::ALL_IGNORE);
1356 font.setFamily(LyXFont::ROMAN_FAMILY);
1357 toggleAndShow(cur, this, font);
1361 case LFUN_DEFAULT: {
1362 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1363 toggleAndShow(cur, this, font);
1367 case LFUN_UNDERLINE: {
1368 LyXFont font(LyXFont::ALL_IGNORE);
1369 font.setUnderbar(LyXFont::TOGGLE);
1370 toggleAndShow(cur, this, font);
1374 case LFUN_FONT_SIZE: {
1375 LyXFont font(LyXFont::ALL_IGNORE);
1376 font.setLyXSize(cmd.argument);
1377 toggleAndShow(cur, this, font);
1381 case LFUN_LANGUAGE: {
1382 Language const * lang = languages.getLanguage(cmd.argument);
1385 LyXFont font(LyXFont::ALL_IGNORE);
1386 font.setLanguage(lang);
1387 toggleAndShow(cur, this, font);
1392 case LFUN_FREEFONT_APPLY:
1393 toggleAndShow(cur, this, freefont, toggleall);
1394 cur.message(_("Character set"));
1397 // Set the freefont using the contents of \param data dispatched from
1398 // the frontends and apply it at the current cursor location.
1399 case LFUN_FREEFONT_UPDATE: {
1402 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1405 toggleAndShow(cur, this, freefont, toggleall);
1406 cur.message(_("Character set"));
1411 case LFUN_FINISHED_LEFT:
1412 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1415 case LFUN_FINISHED_RIGHT:
1416 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1420 case LFUN_FINISHED_UP:
1421 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1425 case LFUN_FINISHED_DOWN:
1426 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1430 case LFUN_LAYOUT_PARAGRAPH: {
1432 params2string(cur.paragraph(), data);
1433 data = "show\n" + data;
1434 bv->owner()->getDialogs().show("paragraph", data);
1438 case LFUN_PARAGRAPH_UPDATE: {
1439 if (!bv->owner()->getDialogs().visible("paragraph"))
1442 params2string(cur.paragraph(), data);
1444 // Will the paragraph accept changes from the dialog?
1445 InsetBase & inset = cur.inset();
1446 bool const accept = !inset.forceDefaultParagraphs(&inset);
1448 data = "update " + tostr(accept) + '\n' + data;
1449 bv->owner()->getDialogs().update("paragraph", data);
1454 case LFUN_CIRCUMFLEX:
1464 case LFUN_SPECIAL_CARON:
1467 case LFUN_HUNG_UMLAUT:
1470 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1471 if (!cmd.argument.empty())
1472 bv->owner()->getIntl().getTransManager()
1473 .TranslateAndInsert(cmd.argument[0], this);
1476 case LFUN_FLOAT_LIST: {
1477 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1478 if (tclass.floats().typeExist(cmd.argument)) {
1479 // not quite sure if we want this...
1481 cur.clearSelection();
1482 breakParagraph(cur);
1484 if (cur.lastpos() != 0) {
1486 breakParagraph(cur);
1489 setLayout(cur, tclass.defaultLayoutName());
1490 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1491 insertInset(cur, new InsetFloatList(cmd.argument));
1493 lyxerr << "Non-existent float type: "
1494 << cmd.argument << endl;
1499 case LFUN_ACCEPT_CHANGE: {
1504 case LFUN_REJECT_CHANGE: {
1509 case LFUN_THESAURUS_ENTRY: {
1510 string arg = cmd.argument;
1512 arg = cur.selectionAsString(false);
1514 if (arg.size() > 100 || arg.empty()) {
1515 // Get word or selection
1516 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1517 arg = cur.selectionAsString(false);
1520 bv->owner()->getDialogs().show("thesaurus", arg);
1524 case LFUN_PARAGRAPH_APPLY: {
1525 // Given data, an encoding of the ParagraphParameters
1526 // generated in the Paragraph dialog, this function sets
1527 // the current paragraph appropriately.
1528 istringstream is(cmd.argument);
1531 ParagraphParameters params;
1536 params.labelWidthString(),
1538 cur.message(_("Paragraph layout set"));
1542 case LFUN_INSET_DIALOG_SHOW: {
1543 InsetBase * inset = cur.nextInset();
1545 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1546 inset->dispatch(cur, fr);
1552 if (cur.selection()) {
1553 cur.selection() = false;
1556 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1565 // avoid to update when navigating
1567 && &sl.inset() == &cur.inset()
1568 && sl.idx() == cur.idx()
1570 && cur.selection() == false)
1575 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1576 FuncStatus & flag) const
1578 BOOST_ASSERT(cur.text() == this);
1579 LyXFont const & font = real_current_font;
1582 switch (cmd.action) {
1584 case LFUN_DEPTH_MIN:
1585 enable = changeDepthAllowed(cur, DEC_DEPTH);
1588 case LFUN_DEPTH_PLUS:
1589 enable = changeDepthAllowed(cur, INC_DEPTH);
1592 case LFUN_INSET_OPTARG:
1593 enable = cur.paragraph().layout()->optionalargs;
1597 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1601 // the functions which insert insets
1602 InsetOld::Code code = InsetOld::NO_CODE;
1603 switch (cmd.action) {
1604 case LFUN_DIALOG_SHOW_NEW_INSET:
1605 if (cmd.argument == "bibitem")
1606 code = InsetOld::BIBITEM_CODE;
1607 else if (cmd.argument == "bibtex")
1608 code = InsetOld::BIBTEX_CODE;
1609 else if (cmd.argument == "box")
1610 code = InsetOld::BOX_CODE;
1611 else if (cmd.argument == "branch")
1612 code = InsetOld::BRANCH_CODE;
1613 else if (cmd.argument == "citation")
1614 code = InsetOld::CITE_CODE;
1615 else if (cmd.argument == "ert")
1616 code = InsetOld::ERT_CODE;
1617 else if (cmd.argument == "external")
1618 code = InsetOld::EXTERNAL_CODE;
1619 else if (cmd.argument == "float")
1620 code = InsetOld::FLOAT_CODE;
1621 else if (cmd.argument == "graphics")
1622 code = InsetOld::GRAPHICS_CODE;
1623 else if (cmd.argument == "include")
1624 code = InsetOld::INCLUDE_CODE;
1625 else if (cmd.argument == "index")
1626 code = InsetOld::INDEX_CODE;
1627 else if (cmd.argument == "label")
1628 code = InsetOld::LABEL_CODE;
1629 else if (cmd.argument == "note")
1630 code = InsetOld::NOTE_CODE;
1631 else if (cmd.argument == "ref")
1632 code = InsetOld::REF_CODE;
1633 else if (cmd.argument == "toc")
1634 code = InsetOld::TOC_CODE;
1635 else if (cmd.argument == "url")
1636 code = InsetOld::URL_CODE;
1637 else if (cmd.argument == "vspace")
1638 code = InsetOld::VSPACE_CODE;
1639 else if (cmd.argument == "wrap")
1640 code = InsetOld::WRAP_CODE;
1643 case LFUN_INSET_ERT:
1644 code = InsetOld::ERT_CODE;
1646 case LFUN_INSET_FOOTNOTE:
1647 code = InsetOld::FOOT_CODE;
1649 case LFUN_TABULAR_INSERT:
1650 code = InsetOld::TABULAR_CODE;
1652 case LFUN_INSET_MARGINAL:
1653 code = InsetOld::MARGIN_CODE;
1655 case LFUN_INSET_FLOAT:
1656 case LFUN_INSET_WIDE_FLOAT:
1657 code = InsetOld::FLOAT_CODE;
1659 case LFUN_INSET_WRAP:
1660 code = InsetOld::WRAP_CODE;
1662 case LFUN_FLOAT_LIST:
1663 code = InsetOld::FLOAT_LIST_CODE;
1666 case LFUN_INSET_LIST:
1667 code = InsetOld::LIST_CODE;
1669 case LFUN_INSET_THEOREM:
1670 code = InsetOld::THEOREM_CODE;
1673 case LFUN_INSET_CAPTION:
1674 code = InsetOld::CAPTION_CODE;
1676 case LFUN_INSERT_NOTE:
1677 code = InsetOld::NOTE_CODE;
1679 case LFUN_INSERT_CHARSTYLE:
1680 code = InsetOld::CHARSTYLE_CODE;
1681 if (buf->params().getLyXTextClass().charstyles().empty())
1684 case LFUN_INSERT_BOX:
1685 code = InsetOld::BOX_CODE;
1687 case LFUN_INSERT_BRANCH:
1688 code = InsetOld::BRANCH_CODE;
1689 if (buf->params().branchlist().empty())
1692 case LFUN_INSERT_LABEL:
1693 code = InsetOld::LABEL_CODE;
1695 case LFUN_INSET_OPTARG:
1696 code = InsetOld::OPTARG_CODE;
1698 case LFUN_ENVIRONMENT_INSERT:
1699 code = InsetOld::BOX_CODE;
1701 case LFUN_INDEX_INSERT:
1702 code = InsetOld::INDEX_CODE;
1704 case LFUN_INDEX_PRINT:
1705 code = InsetOld::INDEX_PRINT_CODE;
1707 case LFUN_TOC_INSERT:
1708 code = InsetOld::TOC_CODE;
1712 code = InsetOld::URL_CODE;
1715 // always allow this, since we will inset a raw quote
1716 // if an inset is not allowed.
1718 case LFUN_HYPHENATION:
1719 case LFUN_LIGATURE_BREAK:
1721 case LFUN_MENU_SEPARATOR:
1723 case LFUN_END_OF_SENTENCE:
1724 code = InsetOld::SPECIALCHAR_CODE;
1726 case LFUN_SPACE_INSERT:
1727 // slight hack: we know this is allowed in math mode
1729 code = InsetOld::SPACE_CODE;
1731 case LFUN_INSET_DIALOG_SHOW: {
1732 InsetBase * inset = cur.nextInset();
1735 code = inset->lyxCode();
1736 if (!(code == InsetOld::INCLUDE_CODE
1737 || code == InsetOld::BIBTEX_CODE
1738 || code == InsetOld::FLOAT_LIST_CODE
1739 || code == InsetOld::TOC_CODE))
1748 if (code != InsetOld::NO_CODE
1749 && (cur.empty() || !cur.inset().insetAllowed(code)))
1754 case LFUN_DIALOG_SHOW_NEW_INSET:
1755 case LFUN_INSET_ERT:
1756 case LFUN_INSERT_BOX:
1757 case LFUN_INSERT_BRANCH:
1758 case LFUN_ENVIRONMENT_INSERT:
1759 case LFUN_INDEX_INSERT:
1760 case LFUN_INDEX_PRINT:
1761 case LFUN_TOC_INSERT:
1765 case LFUN_HYPHENATION:
1766 case LFUN_LIGATURE_BREAK:
1768 case LFUN_MENU_SEPARATOR:
1770 case LFUN_END_OF_SENTENCE:
1771 case LFUN_SPACE_INSERT:
1772 case LFUN_INSET_DIALOG_SHOW:
1776 flag.setOnOff(font.emph() == LyXFont::ON);
1780 flag.setOnOff(font.noun() == LyXFont::ON);
1784 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1788 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1792 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1796 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1799 case LFUN_DELETE_WORD_FORWARD:
1800 case LFUN_DELETE_WORD_BACKWARD:
1801 case LFUN_DELETE_LINE_FORWARD:
1802 case LFUN_WORDRIGHT:
1812 case LFUN_UP_PARAGRAPHSEL:
1813 case LFUN_DOWN_PARAGRAPHSEL:
1818 case LFUN_WORDRIGHTSEL:
1819 case LFUN_WORDLEFTSEL:
1821 case LFUN_UP_PARAGRAPH:
1822 case LFUN_DOWN_PARAGRAPH:
1827 case LFUN_BREAKLINE:
1829 case LFUN_DELETE_SKIP:
1830 case LFUN_BACKSPACE:
1831 case LFUN_BACKSPACE_SKIP:
1832 case LFUN_BREAKPARAGRAPH:
1833 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1834 case LFUN_BREAKPARAGRAPH_SKIP:
1835 case LFUN_PARAGRAPH_SPACING:
1836 case LFUN_INSET_APPLY:
1837 case LFUN_INSET_INSERT:
1838 case LFUN_NEXT_INSET_TOGGLE:
1839 case LFUN_UPCASE_WORD:
1840 case LFUN_LOWCASE_WORD:
1841 case LFUN_CAPITALIZE_WORD:
1842 case LFUN_TRANSPOSE_CHARS:
1849 case LFUN_GETLAYOUT:
1851 case LFUN_PASTESELECTION:
1852 case LFUN_GOTOERROR:
1854 case LFUN_REFERENCE_GOTO:
1855 case LFUN_DATE_INSERT:
1856 case LFUN_SELFINSERT:
1857 case LFUN_INSERT_LABEL:
1858 case LFUN_INSERT_NOTE:
1859 case LFUN_INSERT_CHARSTYLE:
1860 case LFUN_INSERT_BIBITEM:
1861 case LFUN_INSET_FLOAT:
1862 case LFUN_INSET_FOOTNOTE:
1863 case LFUN_INSET_MARGINAL:
1864 case LFUN_INSET_WIDE_FLOAT:
1865 case LFUN_INSET_WRAP:
1866 case LFUN_TABULAR_INSERT:
1867 case LFUN_INSERT_LINE:
1868 case LFUN_INSERT_PAGEBREAK:
1869 case LFUN_MATH_DISPLAY:
1870 case LFUN_MATH_IMPORT_SELECTION:
1871 case LFUN_MATH_MODE:
1872 case LFUN_MATH_MACRO:
1873 case LFUN_INSERT_MATH:
1874 case LFUN_INSERT_MATRIX:
1875 case LFUN_MATH_DELIM:
1877 case LFUN_UNDERLINE:
1878 case LFUN_FONT_SIZE:
1880 case LFUN_FREEFONT_APPLY:
1881 case LFUN_FREEFONT_UPDATE:
1882 case LFUN_LAYOUT_PARAGRAPH:
1883 case LFUN_PARAGRAPH_UPDATE:
1885 case LFUN_CIRCUMFLEX:
1895 case LFUN_SPECIAL_CARON:
1898 case LFUN_HUNG_UMLAUT:
1901 case LFUN_FLOAT_LIST:
1902 case LFUN_ACCEPT_CHANGE:
1903 case LFUN_REJECT_CHANGE:
1904 case LFUN_THESAURUS_ENTRY:
1905 case LFUN_PARAGRAPH_APPLY:
1907 case LFUN_KEYMAP_TOGGLE:
1908 // these are handled in our dispatch()
1913 case LFUN_BEGINNINGBUF:
1921 flag.enabled(enable);