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.
21 #include "bufferparams.h"
22 #include "BufferView.h"
25 #include "dispatchresult.h"
27 #include "FloatList.h"
28 #include "funcrequest.h"
36 #include "paragraph.h"
37 #include "paragraph_funcs.h"
38 #include "ParagraphParameters.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
45 #include "insets/insetcommand.h"
46 #include "insets/insetfloatlist.h"
47 #include "insets/insetnewline.h"
48 #include "insets/insetspecialchar.h"
49 #include "insets/insettext.h"
51 #include "support/lstrings.h"
52 #include "support/lyxlib.h"
53 #include "support/tostr.h"
54 #include "support/std_sstream.h"
56 #include "mathed/math_hullinset.h"
57 #include "mathed/formulamacro.h"
63 using lyx::support::isStrUnsignedInt;
64 using lyx::support::strToUnsignedInt;
65 using lyx::support::atoi;
66 using lyx::support::token;
71 using std::istringstream;
75 extern string current_layout;
77 // the selection possible is needed, that only motion events are
78 // used, where the button press event was on the drawing area too
79 bool selection_possible = false;
85 LyXFont freefont(LyXFont::ALL_IGNORE);
86 bool toggleall = false;
89 void toggleAndShow(LCursor & cur, LyXText * text,
90 LyXFont const & font, bool toggleall = true)
92 if (!cur.bv().available())
95 text->toggleFree(cur, font, toggleall);
97 if (font.language() != ignore_language ||
98 font.number() != LyXFont::IGNORE) {
99 Paragraph & par = cur.paragraph();
100 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
101 if (cur.boundary() !=
102 text->bidi.isBoundary(*cur.bv().buffer(), par,
104 text->real_current_font))
105 text->setCursor(cur, cur.par(), cur.pos(),
106 false, !cur.boundary());
112 void moveCursor(LCursor & cur, bool selecting)
114 if (selecting || cur.mark())
116 if (!cur.selection())
117 cur.bv().haveSelection(false);
118 cur.bv().switchKeyMap();
122 void finishChange(LCursor & cur, bool selecting = false)
125 moveCursor(cur, selecting);
126 cur.bv().owner()->view_state_changed();
130 void mathDispatch(LCursor & cur, LyXText * text,
131 FuncRequest const & cmd, bool display)
133 string sel = cur.selectionAsString(false);
134 lyxerr << "selection is: '" << sel << "'" << endl;
137 cur.insert(new MathHullInset);
138 cur.dispatch(FuncRequest(LFUN_RIGHT));
139 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
140 // don't do that also for LFUN_MATH_MODE unless you want end up with
141 // always changing to mathrm when opening an inlined inset
142 // -- I really hate "LyXfunc overloading"...
144 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
145 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
147 // create a macro if we see "\\newcommand" somewhere, and an ordinary
149 text->cutSelection(cur, true, true);
150 if (sel.find("\\newcommand") == string::npos &&
151 sel.find("\\def") == string::npos)
153 cur.insert(new MathHullInset);
154 cur.dispatch(FuncRequest(LFUN_RIGHT));
155 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
156 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
158 cur.insert(new InsetFormulaMacro(sel));
159 cur.dispatch(FuncRequest(LFUN_RIGHT));
162 cur.message(N_("Math editor mode"));
171 string const freefont2string()
174 if (font2string(freefont, toggleall, data))
182 //takes absolute x,y coordinates
183 InsetBase * LyXText::checkInsetHit(int x, int y)
185 ParagraphList::iterator pit;
186 ParagraphList::iterator end;
188 getParsInRange(paragraphs(),
190 bv()->top_y() - yo_ + bv()->workHeight(),
193 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
194 for ( ; pit != end; ++pit) {
195 InsetList::iterator iit = pit->insetlist.begin();
196 InsetList::iterator iend = pit->insetlist.end();
197 for ( ; iit != iend; ++iit) {
198 InsetBase * inset = iit->inset;
200 lyxerr << "examining inset " << inset
201 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
202 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
203 << " yo: " << inset->yo() - inset->ascent() << "..."
204 << inset->yo() + inset->descent() << endl;
206 if (inset->covers(x, y)) {
207 lyxerr << "Hit inset: " << inset << endl;
212 lyxerr << "No inset hit. " << endl;
217 bool LyXText::gotoNextInset(LCursor & cur,
218 vector<InsetOld_code> const & codes, string const & contents)
220 BOOST_ASSERT(this == cur.text());
221 ParagraphList::iterator end = paragraphs().end();
222 ParagraphList::iterator pit = getPar(cur.par());
223 pos_type pos = cur.pos();
227 if (pos + 1 < pit->size()) {
234 } while (pit != end &&
235 !(pit->isInset(pos) &&
236 (inset = pit->getInset(pos)) != 0 &&
237 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
239 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
245 setCursor(cur, parOffset(pit), pos, false);
250 void LyXText::gotoInset(LCursor & cur,
251 vector<InsetOld_code> const & codes, bool same_content)
253 cur.clearSelection();
257 && cur.pos() < cur.lastpos()
258 && cur.paragraph().isInset(cur.pos())) {
259 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
260 if (find(codes.begin(), codes.end(), inset->lyxCode())
262 contents = static_cast<InsetCommand const *>(inset)->getContents();
265 if (!gotoNextInset(cur, codes, contents)) {
266 if (cur.pos() || cur.par() != 0) {
267 CursorSlice tmp = cur.current();
270 if (!gotoNextInset(cur, codes, contents)) {
272 cur.message(_("No more insets"));
275 cur.message(_("No more insets"));
283 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
285 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
289 void LyXText::cursorPrevious(LCursor & cur)
291 pos_type cpos = cur.pos();
292 lyx::paroffset_type cpar = cur.par();
294 int x = cur.x_target();
295 int y = bv()->top_y();
296 setCursorFromCoordinates(cur, x, y);
298 if (cpar == cur.par() && cpos == cur.pos()) {
299 // we have a row which is taller than the workarea. The
300 // simplest solution is to move to the previous row instead.
304 bv()->updateScrollbar();
309 void LyXText::cursorNext(LCursor & cur)
311 pos_type cpos = cur.pos();
312 lyx::paroffset_type cpar = cur.par();
314 int x = cur.x_target();
315 int y = bv()->top_y() + bv()->workHeight();
316 setCursorFromCoordinates(cur, x, y);
318 if (cpar == cur.par() && cpos == cur.pos()) {
319 // we have a row which is taller than the workarea. The
320 // simplest solution is to move to the next row instead.
321 cursorDown(cur, true);
324 bv()->updateScrollbar();
331 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
333 text->replaceSelection(cur);
334 cur.insert(new InsetSpecialChar(kind));
339 void doInsertInset(LCursor & cur, LyXText * text,
340 FuncRequest const & cmd, bool edit, bool pastesel)
342 InsetBase * inset = createInset(&cur.bv(), cmd);
347 if (cur.selection()) {
348 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
351 text->insertInset(cur, inset);
353 inset->edit(cur, true);
354 if (gotsel && pastesel)
355 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
361 void LyXText::number(LCursor & cur)
363 LyXFont font(LyXFont::ALL_IGNORE);
364 font.setNumber(LyXFont::TOGGLE);
365 toggleAndShow(cur, this, font);
369 bool LyXText::isRTL(Paragraph const & par) const
371 return par.isRightToLeftPar(bv()->buffer()->params());
375 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
377 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
378 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
380 BufferView * bv = &cur.bv();
382 switch (cmd.action) {
384 case LFUN_APPENDIX: {
385 Paragraph & par = cur.paragraph();
386 bool start = !par.params().startOfAppendix();
388 // ensure that we have only one start_of_appendix in this document
389 ParagraphList::iterator tmp = paragraphs().begin();
390 ParagraphList::iterator end = paragraphs().end();
392 for (; tmp != end; ++tmp) {
393 if (tmp->params().startOfAppendix()) {
394 recUndo(parOffset(tmp));
395 tmp->params().startOfAppendix(false);
402 par.params().startOfAppendix(start);
404 // we can set the refreshing parameters now
411 case LFUN_DELETE_WORD_FORWARD:
412 cur.clearSelection();
413 deleteWordForward(cur);
417 case LFUN_DELETE_WORD_BACKWARD:
418 cur.clearSelection();
419 deleteWordBackward(cur);
423 case LFUN_DELETE_LINE_FORWARD:
424 cur.clearSelection();
425 deleteLineForward(cur);
431 cur.clearSelection();
432 if (isRTL(cur.paragraph()))
433 cursorLeftOneWord(cur);
435 cursorRightOneWord(cur);
441 cur.clearSelection();
442 if (isRTL(cur.paragraph()))
443 cursorRightOneWord(cur);
445 cursorLeftOneWord(cur);
449 case LFUN_BEGINNINGBUF:
451 cur.clearSelection();
458 cur.clearSelection();
464 if (!cur.selection())
466 if (isRTL(cur.paragraph()))
467 cursorLeft(cur, true);
469 cursorRight(cur, true);
470 finishChange(cur, true);
474 if (!cur.selection())
476 if (isRTL(cur.paragraph()))
477 cursorRight(cur, true);
479 cursorLeft(cur, true);
480 finishChange(cur, true);
484 if (!cur.selection())
487 finishChange(cur, true);
491 if (!cur.selection())
493 cursorDown(cur, true);
494 finishChange(cur, true);
497 case LFUN_UP_PARAGRAPHSEL:
498 if (!cur.selection())
500 cursorUpParagraph(cur);
501 finishChange(cur, true);
504 case LFUN_DOWN_PARAGRAPHSEL:
505 if (!cur.selection())
507 cursorDownParagraph(cur);
508 finishChange(cur, true);
512 if (!cur.selection())
515 finishChange(cur, true);
519 if (!cur.selection())
522 finishChange(cur, true);
526 if (!cur.selection())
529 finishChange(cur, true);
533 if (!cur.selection())
536 finishChange(cur, true);
539 case LFUN_WORDRIGHTSEL:
540 if (!cur.selection())
542 if (isRTL(cur.paragraph()))
543 cursorLeftOneWord(cur);
545 cursorRightOneWord(cur);
546 finishChange(cur, true);
549 case LFUN_WORDLEFTSEL:
550 if (!cur.selection())
552 if (isRTL(cur.paragraph()))
553 cursorRightOneWord(cur);
555 cursorLeftOneWord(cur);
556 finishChange(cur, true);
560 selectWord(cur, lyx::WHOLE_WORD);
561 finishChange(cur, true);
567 return moveRight(cur);
571 return moveLeft(cur);
579 return moveDown(cur);
581 case LFUN_UP_PARAGRAPH:
583 cur.clearSelection();
584 cursorUpParagraph(cur);
588 case LFUN_DOWN_PARAGRAPH:
590 cur.clearSelection();
591 cursorDownParagraph(cur);
592 finishChange(cur, false);
597 cur.clearSelection();
598 finishChange(cur, false);
599 if (cur.par() == 0 && cur.textRow().pos() == 0)
600 return DispatchResult(false, FINISHED_UP);
606 cur.clearSelection();
607 finishChange(cur, false);
608 if (cur.par() == cur.lastpar()
609 && cur.textRow().endpos() == cur.lastpos())
610 return DispatchResult(false, FINISHED_DOWN);
616 cur.clearSelection();
618 finishChange(cur, false);
623 cur.clearSelection();
625 finishChange(cur, false);
628 case LFUN_BREAKLINE: {
629 // Not allowed by LaTeX (labels or empty par)
630 if (cur.pos() > cur.paragraph().beginOfBody()) {
631 replaceSelection(cur);
632 cur.insert(new InsetNewline);
633 moveCursor(cur, false);
639 if (!cur.selection()) {
642 // It is possible to make it a lot faster still
643 // just comment out the line below...
645 cutSelection(cur, true, false);
647 moveCursor(cur, false);
648 bv->owner()->view_state_changed();
651 case LFUN_DELETE_SKIP:
652 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
653 if (!cur.selection()) {
654 if (cur.pos() == cur.lastpos()) {
655 cursorRight(cur, true);
656 cursorLeft(cur, true);
661 cutSelection(cur, true, false);
668 if (!cur.selection()) {
669 if (bv->owner()->getIntl().getTransManager().backspace()) {
672 // It is possible to make it a lot faster still
673 // just comment out the line below...
676 cutSelection(cur, true, false);
678 bv->owner()->view_state_changed();
683 case LFUN_BACKSPACE_SKIP:
684 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
685 if (!cur.selection()) {
687 //CursorSlice cur = cursor();
691 cutSelection(cur, true, false);
696 case LFUN_BREAKPARAGRAPH:
697 replaceSelection(cur);
698 breakParagraph(cur, 0);
702 bv->owner()->view_state_changed();
705 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
706 replaceSelection(cur);
707 breakParagraph(cur, 1);
711 bv->owner()->view_state_changed();
714 case LFUN_BREAKPARAGRAPH_SKIP: {
715 // When at the beginning of a paragraph, remove
716 // indentation and add a "defskip" at the top.
717 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
718 replaceSelection(cur);
719 if (cur.pos() == 0) {
720 ParagraphParameters & params = cur.paragraph().params();
724 params.labelWidthString(), 1);
726 breakParagraph(cur, 0);
731 bv->owner()->view_state_changed();
735 case LFUN_PARAGRAPH_SPACING: {
736 Paragraph & par = cur.paragraph();
737 Spacing::Space cur_spacing = par.params().spacing().getSpace();
738 float cur_value = 1.0;
739 if (cur_spacing == Spacing::Other)
740 cur_value = par.params().spacing().getValue();
742 istringstream is(cmd.argument);
745 Spacing::Space new_spacing = cur_spacing;
746 float new_value = cur_value;
748 lyxerr << "Missing argument to `paragraph-spacing'"
750 } else if (tmp == "single") {
751 new_spacing = Spacing::Single;
752 } else if (tmp == "onehalf") {
753 new_spacing = Spacing::Onehalf;
754 } else if (tmp == "double") {
755 new_spacing = Spacing::Double;
756 } else if (tmp == "other") {
757 new_spacing = Spacing::Other;
760 lyxerr << "new_value = " << tmpval << endl;
763 } else if (tmp == "default") {
764 new_spacing = Spacing::Default;
766 lyxerr << _("Unknown spacing argument: ")
767 << cmd.argument << endl;
769 if (cur_spacing != new_spacing || cur_value != new_value) {
770 par.params().spacing(Spacing(new_spacing, new_value));
777 case LFUN_INSET_APPLY: {
778 string const name = cmd.getArg(0);
779 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
781 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
783 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
787 case LFUN_INSET_INSERT: {
788 InsetBase * inset = createInset(bv, cmd);
790 insertInset(cur, inset);
794 case LFUN_INSET_SETTINGS:
795 if (cur.inset() && cur.inset()->asUpdatableInset())
796 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
799 case LFUN_INSET_TOGGLE:
800 cur.clearSelection();
801 if (!toggleInset(cur))
802 return DispatchResult(false);
807 case LFUN_SPACE_INSERT:
808 if (cur.paragraph().layout()->free_spacing)
809 insertChar(cur, ' ');
811 doInsertInset(cur, this, cmd, false, false);
812 moveCursor(cur, false);
815 case LFUN_HYPHENATION:
816 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
819 case LFUN_LIGATURE_BREAK:
820 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
824 specialChar(cur, this, InsetSpecialChar::LDOTS);
827 case LFUN_END_OF_SENTENCE:
828 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
831 case LFUN_MENU_SEPARATOR:
832 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
835 case LFUN_UPCASE_WORD:
836 changeCase(cur, LyXText::text_uppercase);
840 case LFUN_LOWCASE_WORD:
841 changeCase(cur, LyXText::text_lowercase);
845 case LFUN_CAPITALIZE_WORD:
846 changeCase(cur, LyXText::text_capitalization);
850 case LFUN_TRANSPOSE_CHARS:
857 cur.message(_("Paste"));
858 replaceSelection(cur);
859 #warning FIXME Check if the arg is in the domain of available selections.
860 if (isStrUnsignedInt(cmd.argument))
861 pasteSelection(cur, strToUnsignedInt(cmd.argument));
863 pasteSelection(cur, 0);
864 cur.clearSelection(); // bug 393
871 cutSelection(cur, true, true);
872 cur.message(_("Cut"));
878 cur.message(_("Copy"));
881 case LFUN_BEGINNINGBUFSEL:
883 return DispatchResult(false);
884 if (!cur.selection())
887 finishChange(cur, true);
892 return DispatchResult(false);
893 if (!cur.selection())
896 finishChange(cur, true);
900 cur.message(tostr(cursorX(cur.current())) + ' '
901 + tostr(cursorY(cur.current())));
907 istringstream is(cmd.argument);
910 lyxerr << "SETXY: Could not parse coordinates in '"
911 << cmd.argument << std::endl;
913 setCursorFromCoordinates(cur, x, y);
918 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
920 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
927 cur.message(cur.paragraph().layout()->name());
931 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
932 << cmd.argument << endl;
934 // This is not the good solution to the empty argument
935 // problem, but it will hopefully suffice for 1.2.0.
936 // The correct solution would be to augument the
937 // function list/array with information about what
938 // functions needs arguments and their type.
939 if (cmd.argument.empty()) {
940 cur.errorMessage(_("LyX function 'layout' needs an argument."));
944 // Derive layout number from given argument (string)
945 // and current buffer's textclass (number)
946 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
947 bool hasLayout = tclass.hasLayout(cmd.argument);
948 string layout = cmd.argument;
950 // If the entry is obsolete, use the new one instead.
952 string const & obs = tclass[layout]->obsoleted_by();
958 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
963 bool change_layout = (current_layout != layout);
965 if (!change_layout && cur.selection() &&
966 cur.selBegin().par() != cur.selEnd().par())
968 ParagraphList::iterator spit = getPar(cur.selBegin());
969 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
970 while (spit != epit) {
971 if (spit->layout()->name() != current_layout) {
972 change_layout = true;
980 current_layout = layout;
981 setLayout(cur, layout);
982 bv->owner()->setLayout(layout);
989 case LFUN_PASTESELECTION: {
990 cur.clearSelection();
991 string const clip = bv->getClipboard();
993 if (cmd.argument == "paragraph")
994 insertStringAsParagraphs(cur, clip);
996 insertStringAsLines(cur, clip);
1002 case LFUN_GOTOERROR:
1003 gotoInset(cur, InsetBase::ERROR_CODE, false);
1007 gotoInset(cur, InsetBase::NOTE_CODE, false);
1010 case LFUN_REFERENCE_GOTO: {
1011 vector<InsetOld_code> tmp;
1012 tmp.push_back(InsetBase::LABEL_CODE);
1013 tmp.push_back(InsetBase::REF_CODE);
1014 gotoInset(cur, tmp, true);
1019 replaceSelection(cur);
1020 Paragraph & par = cur.paragraph();
1021 lyx::pos_type pos = cur.pos();
1025 else if (cur.prevInset() && cur.prevInset()->isSpace())
1028 c = par.getChar(pos - 1);
1030 LyXLayout_ptr const & style = par.layout();
1032 BufferParams const & bufparams = bv->buffer()->params();
1033 if (style->pass_thru ||
1034 par.getFontSettings(bufparams, pos).language()->lang() == "hebrew")
1035 cur.insert(new InsetQuotes(c, bufparams));
1037 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1041 case LFUN_DATE_INSERT: {
1042 replaceSelection(cur);
1043 time_t now_time_t = time(NULL);
1044 struct tm * now_tm = localtime(&now_time_t);
1045 setlocale(LC_TIME, "");
1047 if (!cmd.argument.empty())
1050 arg = lyxrc.date_insert_format;
1052 int const datetmp_len =
1053 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1055 for (int i = 0; i < datetmp_len; i++)
1056 insertChar(cur, datetmp[i]);
1059 moveCursor(cur, false);
1063 case LFUN_MOUSE_TRIPLE:
1064 if (cmd.button() == mouse_button::button1) {
1065 selection_possible = true;
1070 bv->haveSelection(cur.selection());
1074 case LFUN_MOUSE_DOUBLE:
1075 if (cmd.button() == mouse_button::button1) {
1076 selection_possible = true;
1077 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1078 bv->haveSelection(cur.selection());
1082 case LFUN_MOUSE_MOTION: {
1083 // Only use motion with button 1
1084 //if (cmd.button() != mouse_button::button1)
1086 // The test for not selection possible is needed, that
1087 // only motion events are used, where the bottom press
1088 // event was on the drawing area too
1089 if (!selection_possible) {
1090 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1091 "Dispatch: no selection possible\n";
1094 CursorSlice old = cur.current();
1095 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1097 // This is to allow jumping over large insets
1098 // FIXME: shouldn't be top-text-specific
1099 if (!in_inset_ && cur.current() == old) {
1100 if (cmd.y - bv->top_y() >= bv->workHeight())
1101 cursorDown(cur, true);
1102 else if (cmd.y - bv->top_y() < 0)
1103 cursorUp(cur, true);
1106 // don't set anchor_
1107 bv->cursor().cursor_ = cur.cursor_;
1108 bv->cursor().setSelection();
1112 // Single-click on work area
1113 case LFUN_MOUSE_PRESS: {
1114 // ok ok, this is a hack (for xforms)
1115 // We shouldn't go further down as we really should only do the
1116 // scrolling and be done with this. Otherwise we may open some
1117 // dialogs (Jug 20020424).
1118 if (cmd.button() == mouse_button::button4) {
1119 bv->scroll(-lyxrc.wheel_jump);
1123 if (cmd.button() == mouse_button::button5) {
1124 bv->scroll(lyxrc.wheel_jump);
1128 // Right click on a footnote flag opens float menu
1129 if (cmd.button() == mouse_button::button3) {
1130 cur.clearSelection();
1131 selection_possible = false;
1135 // Middle button press pastes if we have a selection
1136 // We do this here as if the selection was inside an inset
1137 // it could get cleared on the unlocking of the inset so
1138 // we have to check this first
1139 bool paste_internally = false;
1140 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1141 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1142 paste_internally = true;
1145 selection_possible = true;
1147 // Clear the selection
1148 cur.clearSelection();
1150 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1153 cur.x_target() = cursorX(cur.current());
1155 // set cursor and anchor to this position
1158 if (bv->fitCursor())
1159 selection_possible = false;
1161 // Insert primary selection with middle mouse
1162 // if there is a local selection in the current buffer,
1164 if (cmd.button() == mouse_button::button2) {
1165 if (paste_internally)
1166 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1168 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1169 selection_possible = false;
1174 case LFUN_MOUSE_RELEASE: {
1175 // do nothing if we used the mouse wheel
1176 if (cmd.button() == mouse_button::button4
1177 || cmd.button() == mouse_button::button5)
1178 return DispatchResult(true, false);
1180 selection_possible = false;
1182 if (cmd.button() == mouse_button::button2)
1186 if (cmd.button() == mouse_button::button1)
1187 bv->haveSelection(cur.selection());
1190 bv->owner()->view_state_changed();
1191 bv->owner()->updateMenubar();
1192 bv->owner()->updateToolbar();
1196 case LFUN_SELFINSERT: {
1197 if (cmd.argument.empty())
1200 // Automatically delete the currently selected
1201 // text and replace it with what is being
1202 // typed in now. Depends on lyxrc settings
1203 // "auto_region_delete", which defaults to
1206 if (lyxrc.auto_region_delete) {
1207 if (cur.selection())
1208 cutSelection(cur, false, false);
1209 bv->haveSelection(false);
1212 cur.clearSelection();
1213 LyXFont const old_font = real_current_font;
1215 string::const_iterator cit = cmd.argument.begin();
1216 string::const_iterator end = cmd.argument.end();
1217 for (; cit != end; ++cit)
1218 bv->owner()->getIntl().getTransManager().
1219 TranslateAndInsert(*cit, this);
1222 moveCursor(cur, false);
1224 // real_current_font.number can change so we need to
1225 // update the minibuffer
1226 if (old_font != real_current_font)
1227 bv->owner()->view_state_changed();
1228 bv->updateScrollbar();
1233 InsetCommandParams p("url");
1234 string const data = InsetCommandMailer::params2string("url", p);
1235 bv->owner()->getDialogs().show("url", data, 0);
1239 case LFUN_HTMLURL: {
1240 InsetCommandParams p("htmlurl");
1241 string const data = InsetCommandMailer::params2string("url", p);
1242 bv->owner()->getDialogs().show("url", data, 0);
1246 case LFUN_INSERT_LABEL: {
1247 InsetCommandParams p("label");
1248 string const data = InsetCommandMailer::params2string("label", p);
1249 bv->owner()->getDialogs().show("label", data, 0);
1255 case LFUN_INSET_LIST:
1256 case LFUN_INSET_THEOREM:
1257 case LFUN_INSET_CAPTION:
1259 case LFUN_INSERT_NOTE:
1260 case LFUN_INSERT_CHARSTYLE:
1261 case LFUN_INSERT_BOX:
1262 case LFUN_INSERT_BRANCH:
1263 case LFUN_INSERT_BIBITEM:
1264 case LFUN_INSET_ERT:
1265 case LFUN_INSET_FLOAT:
1266 case LFUN_INSET_FOOTNOTE:
1267 case LFUN_INSET_MARGINAL:
1268 case LFUN_INSET_OPTARG:
1269 case LFUN_INSET_WIDE_FLOAT:
1270 case LFUN_INSET_WRAP:
1271 case LFUN_TABULAR_INSERT:
1272 case LFUN_ENVIRONMENT_INSERT:
1273 // Open the inset, and move the current selection
1275 doInsertInset(cur, this, cmd, true, true);
1278 case LFUN_INDEX_INSERT:
1279 // Just open the inset
1280 doInsertInset(cur, this, cmd, true, false);
1283 case LFUN_INDEX_PRINT:
1284 case LFUN_TOC_INSERT:
1286 case LFUN_INSERT_LINE:
1287 case LFUN_INSERT_PAGEBREAK:
1289 doInsertInset(cur, this, cmd, false, false);
1292 case LFUN_DEPTH_MIN:
1293 changeDepth(cur, bv_funcs::DEC_DEPTH);
1297 case LFUN_DEPTH_PLUS:
1298 changeDepth(cur, bv_funcs::INC_DEPTH);
1302 case LFUN_MATH_DISPLAY:
1303 mathDispatch(cur, this, cmd, true);
1306 case LFUN_MATH_IMPORT_SELECTION:
1307 case LFUN_MATH_MODE:
1308 mathDispatch(cur, this, cmd, false);
1311 case LFUN_MATH_MACRO:
1312 if (cmd.argument.empty())
1313 cur.errorMessage(N_("Missing argument"));
1315 string s = cmd.argument;
1316 string const s1 = token(s, ' ', 1);
1317 int const nargs = s1.empty() ? 0 : atoi(s1);
1318 string const s2 = token(s, ' ', 2);
1319 string const type = s2.empty() ? "newcommand" : s2;
1320 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1321 cur.nextInset()->edit(cur, true);
1325 case LFUN_INSERT_MATH:
1326 case LFUN_INSERT_MATRIX:
1327 case LFUN_MATH_DELIM: {
1328 cur.insert(new MathHullInset);
1329 cur.dispatch(FuncRequest(LFUN_RIGHT));
1330 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1336 LyXFont font(LyXFont::ALL_IGNORE);
1337 font.setEmph(LyXFont::TOGGLE);
1338 toggleAndShow(cur, this, font);
1339 bv->owner()->view_state_changed();
1344 LyXFont font(LyXFont::ALL_IGNORE);
1345 font.setSeries(LyXFont::BOLD_SERIES);
1346 toggleAndShow(cur, this, font);
1347 bv->owner()->view_state_changed();
1352 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setNoun(LyXFont::TOGGLE);
1354 toggleAndShow(cur, this, font);
1355 bv->owner()->view_state_changed();
1360 LyXFont font(LyXFont::ALL_IGNORE);
1361 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1362 toggleAndShow(cur, this, font);
1363 bv->owner()->view_state_changed();
1368 LyXFont font(LyXFont::ALL_IGNORE);
1369 font.setFamily(LyXFont::SANS_FAMILY);
1370 toggleAndShow(cur, this, font);
1371 bv->owner()->view_state_changed();
1376 LyXFont font(LyXFont::ALL_IGNORE);
1377 font.setFamily(LyXFont::ROMAN_FAMILY);
1378 toggleAndShow(cur, this, font);
1379 bv->owner()->view_state_changed();
1383 case LFUN_DEFAULT: {
1384 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1385 toggleAndShow(cur, this, font);
1386 bv->owner()->view_state_changed();
1390 case LFUN_UNDERLINE: {
1391 LyXFont font(LyXFont::ALL_IGNORE);
1392 font.setUnderbar(LyXFont::TOGGLE);
1393 toggleAndShow(cur, this, font);
1394 bv->owner()->view_state_changed();
1398 case LFUN_FONT_SIZE: {
1399 LyXFont font(LyXFont::ALL_IGNORE);
1400 font.setLyXSize(cmd.argument);
1401 toggleAndShow(cur, this, font);
1402 bv->owner()->view_state_changed();
1406 case LFUN_LANGUAGE: {
1407 Language const * lang = languages.getLanguage(cmd.argument);
1410 LyXFont font(LyXFont::ALL_IGNORE);
1411 font.setLanguage(lang);
1412 toggleAndShow(cur, this, font);
1414 bv->owner()->view_state_changed();
1418 case LFUN_FREEFONT_APPLY:
1419 toggleAndShow(cur, this, freefont, toggleall);
1420 bv->owner()->view_state_changed();
1421 cur.message(_("Character set"));
1424 // Set the freefont using the contents of \param data dispatched from
1425 // the frontends and apply it at the current cursor location.
1426 case LFUN_FREEFONT_UPDATE: {
1429 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1432 toggleAndShow(cur, this, freefont, toggleall);
1433 bv->owner()->view_state_changed();
1434 cur.message(_("Character set"));
1439 case LFUN_FINISHED_LEFT:
1440 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1441 cur.pop(cur.currentDepth());
1442 if (isRTL(cur.paragraph()))
1443 cursorLeft(cur, true);
1444 cur.bv().cursor() = cur;
1447 case LFUN_FINISHED_RIGHT:
1448 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1449 cur.pop(cur.currentDepth());
1450 if (!isRTL(cur.paragraph()))
1451 cursorRight(cur, true);
1452 cur.bv().cursor() = cur;
1455 case LFUN_FINISHED_UP:
1456 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1457 cur.pop(cur.currentDepth());
1458 cursorUp(cur, true);
1459 cur.bv().cursor() = cur;
1462 case LFUN_FINISHED_DOWN:
1463 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1464 cur.pop(cur.currentDepth());
1465 cursorDown(cur, true);
1466 cur.bv().cursor() = cur;
1469 case LFUN_LAYOUT_PARAGRAPH: {
1471 params2string(cur.paragraph(), data);
1472 data = "show\n" + data;
1473 bv->owner()->getDialogs().show("paragraph", data);
1477 case LFUN_PARAGRAPH_UPDATE: {
1478 if (!bv->owner()->getDialogs().visible("paragraph"))
1481 params2string(cur.paragraph(), data);
1483 // Will the paragraph accept changes from the dialog?
1484 InsetBase * const inset = cur.inset();
1486 !(inset && inset->forceDefaultParagraphs(inset));
1488 data = "update " + tostr(accept) + '\n' + data;
1489 bv->owner()->getDialogs().update("paragraph", data);
1494 case LFUN_CIRCUMFLEX:
1504 case LFUN_SPECIAL_CARON:
1507 case LFUN_HUNG_UMLAUT:
1510 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1511 if (!cmd.argument.empty())
1512 bv->owner()->getIntl().getTransManager()
1513 .TranslateAndInsert(cmd.argument[0], this);
1516 case LFUN_FLOAT_LIST: {
1517 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1518 if (tclass.floats().typeExist(cmd.argument)) {
1519 // not quite sure if we want this...
1522 cur.clearSelection();
1523 breakParagraph(cur);
1525 if (cur.lastpos() != 0) {
1526 cursorLeft(cur, true);
1527 breakParagraph(cur);
1530 setLayout(cur, tclass.defaultLayoutName());
1531 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1532 cur.insert(new InsetFloatList(cmd.argument));
1535 lyxerr << "Non-existent float type: "
1536 << cmd.argument << endl;
1541 case LFUN_ACCEPT_CHANGE: {
1547 case LFUN_REJECT_CHANGE: {
1553 case LFUN_THESAURUS_ENTRY: {
1554 string arg = cmd.argument;
1556 arg = cur.selectionAsString(false);
1558 if (arg.size() > 100 || arg.empty()) {
1559 // Get word or selection
1560 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1561 arg = cur.selectionAsString(false);
1564 bv->owner()->getDialogs().show("thesaurus", arg);
1568 case LFUN_PARAGRAPH_APPLY: {
1569 // Given data, an encoding of the ParagraphParameters
1570 // generated in the Paragraph dialog, this function sets
1571 // the current paragraph appropriately.
1572 istringstream is(cmd.argument);
1575 ParagraphParameters params;
1580 params.labelWidthString(),
1583 cur.message(_("Paragraph layout set"));
1588 return DispatchResult(false);
1591 return DispatchResult(true, true);