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"
35 #include "paragraph.h"
36 #include "paragraph_funcs.h"
37 #include "ParagraphParameters.h"
41 #include "frontends/Dialogs.h"
42 #include "frontends/LyXView.h"
44 #include "insets/insetcommand.h"
45 #include "insets/insetfloatlist.h"
46 #include "insets/insetnewline.h"
47 #include "insets/insetspecialchar.h"
48 #include "insets/insettext.h"
50 #include "support/lstrings.h"
51 #include "support/lyxlib.h"
52 #include "support/tostr.h"
53 #include "support/std_sstream.h"
55 #include "mathed/math_hullinset.h"
56 #include "mathed/formulamacro.h"
62 using lyx::support::isStrUnsignedInt;
63 using lyx::support::strToUnsignedInt;
64 using lyx::support::atoi;
65 using lyx::support::token;
70 using std::istringstream;
74 extern string current_layout;
76 // the selection possible is needed, that only motion events are
77 // used, where the button press event was on the drawing area too
78 bool selection_possible = false;
84 LyXFont freefont(LyXFont::ALL_IGNORE);
85 bool toggleall = false;
88 void toggleAndShow(LCursor & cur, LyXText * text,
89 LyXFont const & font, bool toggleall = true)
91 if (!cur.bv().available())
94 text->toggleFree(cur, font, toggleall);
96 if (font.language() != ignore_language ||
97 font.number() != LyXFont::IGNORE) {
98 Paragraph & par = cur.paragraph();
99 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
100 if (cur.boundary() !=
101 text->bidi.isBoundary(*cur.bv().buffer(), par,
103 text->real_current_font))
104 text->setCursor(cur.par(), cur.pos(),
105 false, !cur.boundary());
111 void moveCursor(LCursor & cur, bool selecting)
113 if (selecting || cur.mark())
115 if (!cur.selection())
116 cur.bv().haveSelection(false);
117 cur.bv().switchKeyMap();
121 void finishChange(LCursor & cur, bool selecting = false)
124 moveCursor(cur, selecting);
125 cur.bv().owner()->view_state_changed();
129 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
131 string sel = cur.selectionAsString(false);
132 lyxerr << "selection is: '" << sel << "'" << endl;
135 cur.insert(new MathHullInset);
136 cur.dispatch(FuncRequest(LFUN_RIGHT));
137 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
138 // don't do that also for LFUN_MATH_MODE unless you want end up with
139 // always changing to mathrm when opening an inlined inset
140 // -- I really hate "LyXfunc overloading"...
142 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
143 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
145 // create a macro if we see "\\newcommand" somewhere, and an ordinary
147 cur.bv().getLyXText()->cutSelection(true, true);
148 if (sel.find("\\newcommand") == string::npos &&
149 sel.find("\\def") == string::npos)
151 cur.insert(new MathHullInset);
152 cur.dispatch(FuncRequest(LFUN_RIGHT));
153 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
154 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
156 cur.insert(new InsetFormulaMacro(sel));
157 cur.dispatch(FuncRequest(LFUN_RIGHT));
160 cur.message(N_("Math editor mode"));
169 string const freefont2string()
172 if (font2string(freefont, toggleall, data))
180 //takes absolute x,y coordinates
181 InsetBase * LyXText::checkInsetHit(int x, int y)
183 ParagraphList::iterator pit;
184 ParagraphList::iterator end;
186 getParsInRange(paragraphs(),
188 bv()->top_y() - yo_ + bv()->workHeight(),
191 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
192 for ( ; pit != end; ++pit) {
193 InsetList::iterator iit = pit->insetlist.begin();
194 InsetList::iterator iend = pit->insetlist.end();
195 for ( ; iit != iend; ++iit) {
196 InsetBase * inset = iit->inset;
198 lyxerr << "examining inset " << inset
199 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
200 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
201 << " yo: " << inset->yo() - inset->ascent() << "..."
202 << inset->yo() + inset->descent() << endl;
204 if (inset->covers(x, y)) {
205 lyxerr << "Hit inset: " << inset << endl;
210 lyxerr << "No inset hit. " << endl;
215 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
216 string const & contents)
218 ParagraphList::iterator end = paragraphs().end();
219 ParagraphList::iterator pit = cursorPar();
220 pos_type pos = cursor().pos();
224 if (pos + 1 < pit->size()) {
231 } while (pit != end &&
232 !(pit->isInset(pos) &&
233 (inset = pit->getInset(pos)) != 0 &&
234 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
236 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
242 setCursor(parOffset(pit), pos, false);
247 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
249 LCursor & cur = bv()->cursor();
250 cur.clearSelection();
254 && cur.pos() < cur.lastpos()
255 && cur.paragraph().isInset(cur.pos())) {
256 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
257 if (find(codes.begin(), codes.end(), inset->lyxCode())
259 contents = static_cast<InsetCommand const *>(inset)->getContents();
262 if (!gotoNextInset(codes, contents)) {
263 if (cur.pos() || cur.par() != 0) {
264 CursorSlice tmp = cursor();
267 if (!gotoNextInset(codes, contents)) {
269 cur.message(_("No more insets"));
272 cur.message(_("No more insets"));
280 void LyXText::gotoInset(InsetOld_code code, bool same_content)
282 gotoInset(vector<InsetOld_code>(1, code), same_content);
286 void LyXText::cursorPrevious(LCursor & cur)
288 pos_type cpos = cur.pos();
289 lyx::paroffset_type cpar = cur.par();
291 int x = cur.x_target();
292 int y = bv()->top_y();
293 setCursorFromCoordinates(x, y);
295 if (cpar == cur.par() && cpos == cur.pos()) {
296 // we have a row which is taller than the workarea. The
297 // simplest solution is to move to the previous row instead.
301 bv()->updateScrollbar();
306 void LyXText::cursorNext(LCursor & cur)
308 pos_type cpos = cur.pos();
309 lyx::paroffset_type cpar = cur.par();
311 int x = cur.x_target();
312 int y = bv()->top_y() + bv()->workHeight();
313 setCursorFromCoordinates(x, y);
315 if (cpar == cur.par() && cpos == cur.pos()) {
316 // we have a row which is taller than the workarea. The
317 // simplest solution is to move to the next row instead.
318 cursorDown(cur, true);
321 bv()->updateScrollbar();
328 void specialChar(LCursor & cur, LyXText * text, BufferView * bv,
329 InsetSpecialChar::Kind kind)
332 text->replaceSelection(cur);
333 cur.insert(new InsetSpecialChar(kind));
338 void doInsertInset(LCursor & cur, LyXText * text, BufferView * bv,
339 FuncRequest const & cmd, bool edit, bool pastesel)
341 InsetBase * inset = createInset(bv, cmd);
346 if (cur.selection()) {
347 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
350 text->insertInset(cur, inset);
352 inset->edit(cur, true);
353 if (gotsel && pastesel)
354 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
360 void LyXText::number()
362 LyXFont font(LyXFont::ALL_IGNORE);
363 font.setNumber(LyXFont::TOGGLE);
364 toggleAndShow(bv()->cursor(), this, font);
368 bool LyXText::rtl() const
370 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
374 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
376 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
377 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
379 BufferView * bv = &cur.bv();
381 switch (cmd.action) {
383 case LFUN_APPENDIX: {
384 Paragraph & par = cur.paragraph();
385 bool start = !par.params().startOfAppendix();
387 // ensure that we have only one start_of_appendix in this document
388 ParagraphList::iterator tmp = paragraphs().begin();
389 ParagraphList::iterator end = paragraphs().end();
391 for (; tmp != end; ++tmp) {
392 if (tmp->params().startOfAppendix()) {
393 recUndo(parOffset(tmp));
394 tmp->params().startOfAppendix(false);
401 par.params().startOfAppendix(start);
403 // we can set the refreshing parameters now
410 case LFUN_DELETE_WORD_FORWARD:
411 cur.clearSelection();
412 deleteWordForward(cur);
416 case LFUN_DELETE_WORD_BACKWARD:
417 cur.clearSelection();
418 deleteWordBackward(cur);
422 case LFUN_DELETE_LINE_FORWARD:
423 cur.clearSelection();
424 deleteLineForward(cur);
430 cur.clearSelection();
432 cursorLeftOneWord(cur);
434 cursorRightOneWord(cur);
440 cur.clearSelection();
442 cursorRightOneWord(cur);
444 cursorLeftOneWord(cur);
448 case LFUN_BEGINNINGBUF:
450 cur.clearSelection();
457 cur.clearSelection();
463 if (!cur.selection())
466 cursorLeft(cur, true);
468 cursorRight(cur, true);
469 finishChange(cur, true);
473 if (!cur.selection())
476 cursorRight(cur, true);
478 cursorLeft(cur, true);
479 finishChange(cur, true);
483 if (!cur.selection())
486 finishChange(cur, true);
490 if (!cur.selection())
492 cursorDown(cur, true);
493 finishChange(cur, true);
496 case LFUN_UP_PARAGRAPHSEL:
497 if (!cur.selection())
499 cursorUpParagraph(cur);
500 finishChange(cur, true);
503 case LFUN_DOWN_PARAGRAPHSEL:
504 if (!cur.selection())
506 cursorDownParagraph(cur);
507 finishChange(cur, true);
511 if (!cur.selection())
514 finishChange(cur, true);
518 if (!cur.selection())
521 finishChange(cur, true);
525 if (!cur.selection())
528 finishChange(cur, true);
532 if (!cur.selection())
535 finishChange(cur, true);
538 case LFUN_WORDRIGHTSEL:
539 if (!cur.selection())
542 cursorLeftOneWord(cur);
544 cursorRightOneWord(cur);
545 finishChange(cur, true);
548 case LFUN_WORDLEFTSEL:
549 if (!cur.selection())
552 cursorRightOneWord(cur);
554 cursorLeftOneWord(cur);
555 finishChange(cur, true);
559 selectWord(cur, lyx::WHOLE_WORD);
560 finishChange(cur, true);
566 return moveRight(cur);
570 return moveLeft(cur);
578 return moveDown(cur);
580 case LFUN_UP_PARAGRAPH:
582 cur.clearSelection();
583 cursorUpParagraph(cur);
587 case LFUN_DOWN_PARAGRAPH:
589 cur.clearSelection();
590 cursorDownParagraph(cur);
591 finishChange(cur, false);
596 cur.clearSelection();
597 finishChange(cur, false);
598 if (cur.par() == 0 && cur.textRow().pos() == 0)
599 return DispatchResult(false, FINISHED_UP);
605 cur.clearSelection();
606 finishChange(cur, false);
607 if (cur.par() == cur.lastpar()
608 && cur.textRow().endpos() == cur.lastpos())
609 return DispatchResult(false, FINISHED_DOWN);
615 cur.clearSelection();
617 finishChange(cur, false);
622 cur.clearSelection();
624 finishChange(cur, false);
627 case LFUN_BREAKLINE: {
628 // Not allowed by LaTeX (labels or empty par)
629 if (cur.pos() > cur.paragraph().beginOfBody()) {
630 replaceSelection(cur);
631 cur.insert(new InsetNewline);
632 moveCursor(cur, false);
638 if (!cur.selection()) {
641 // It is possible to make it a lot faster still
642 // just comment out the line below...
644 cutSelection(true, false);
646 moveCursor(cur, false);
647 bv->owner()->view_state_changed();
650 case LFUN_DELETE_SKIP:
651 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
652 if (!cur.selection()) {
653 if (cur.pos() == cur.lastpos()) {
654 cursorRight(cur, true);
655 cursorLeft(cur, true);
660 cutSelection(true, false);
667 if (!cur.selection()) {
668 if (bv->owner()->getIntl().getTransManager().backspace()) {
671 // It is possible to make it a lot faster still
672 // just comment out the line below...
675 cutSelection(true, false);
677 bv->owner()->view_state_changed();
682 case LFUN_BACKSPACE_SKIP:
683 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
684 if (!cur.selection()) {
686 //CursorSlice cur = cursor();
690 cutSelection(true, false);
695 case LFUN_BREAKPARAGRAPH:
696 replaceSelection(cur);
697 breakParagraph(cur, 0);
701 bv->owner()->view_state_changed();
704 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
705 replaceSelection(cur);
706 breakParagraph(cur, 1);
710 bv->owner()->view_state_changed();
713 case LFUN_BREAKPARAGRAPH_SKIP: {
714 // When at the beginning of a paragraph, remove
715 // indentation and add a "defskip" at the top.
716 // 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, bv, cmd, false, false);
812 moveCursor(cur, false);
815 case LFUN_HYPHENATION:
816 specialChar(cur, this, bv, InsetSpecialChar::HYPHENATION);
819 case LFUN_LIGATURE_BREAK:
820 specialChar(cur, this, bv, InsetSpecialChar::LIGATURE_BREAK);
824 specialChar(cur, this, bv, InsetSpecialChar::LDOTS);
827 case LFUN_END_OF_SENTENCE:
828 specialChar(cur, this, bv, InsetSpecialChar::END_OF_SENTENCE);
831 case LFUN_MENU_SEPARATOR:
832 specialChar(cur, this, bv, 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(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(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(InsetBase::ERROR_CODE, false);
1007 gotoInset(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(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 (ev.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();
1097 setCursorFromCoordinates(cmd.x, cmd.y);
1099 // This is to allow jumping over large insets
1100 // FIXME: shouldn't be top-text-specific
1101 if (!in_inset_ && cur.current() == old) {
1102 if (cmd.y - bv->top_y() >= bv->workHeight())
1103 cursorDown(cur, true);
1104 else if (cmd.y - bv->top_y() < 0)
1105 cursorUp(cur, true);
1108 // don't set anchor_
1109 bv->cursor().cursor_ = cur.cursor_;
1110 bv->cursor().setSelection();
1115 // Single-click on work area
1116 case LFUN_MOUSE_PRESS: {
1117 // ok ok, this is a hack (for xforms)
1118 // We shouldn't go further down as we really should only do the
1119 // scrolling and be done with this. Otherwise we may open some
1120 // dialogs (Jug 20020424).
1121 if (cmd.button() == mouse_button::button4) {
1122 bv->scroll(-lyxrc.wheel_jump);
1126 if (cmd.button() == mouse_button::button5) {
1127 bv->scroll(lyxrc.wheel_jump);
1131 // Right click on a footnote flag opens float menu
1132 if (cmd.button() == mouse_button::button3) {
1133 cur.clearSelection();
1134 selection_possible = false;
1138 // Middle button press pastes if we have a selection
1139 // We do this here as if the selection was inside an inset
1140 // it could get cleared on the unlocking of the inset so
1141 // we have to check this first
1142 bool paste_internally = false;
1143 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1144 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1145 paste_internally = true;
1148 selection_possible = true;
1150 // Clear the selection
1151 cur.clearSelection();
1153 setCursorFromCoordinates(cur.current(), cmd.x - xo_,
1157 cur.x_target() = cursorX(cur.current());
1159 // set cursor and anchor to this position
1162 if (bv->fitCursor())
1163 selection_possible = false;
1165 // Insert primary selection with middle mouse
1166 // if there is a local selection in the current buffer,
1168 if (cmd.button() == mouse_button::button2) {
1169 if (paste_internally)
1170 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1172 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1173 selection_possible = false;
1178 case LFUN_MOUSE_RELEASE: {
1179 // do nothing if we used the mouse wheel
1180 if (cmd.button() == mouse_button::button4
1181 || cmd.button() == mouse_button::button5)
1182 return DispatchResult(true, false);
1184 selection_possible = false;
1186 if (cmd.button() == mouse_button::button2)
1190 if (cmd.button() == mouse_button::button1)
1191 bv->haveSelection(cur.selection());
1194 bv->owner()->view_state_changed();
1195 bv->owner()->updateMenubar();
1196 bv->owner()->updateToolbar();
1200 case LFUN_SELFINSERT: {
1201 if (cmd.argument.empty())
1204 // Automatically delete the currently selected
1205 // text and replace it with what is being
1206 // typed in now. Depends on lyxrc settings
1207 // "auto_region_delete", which defaults to
1210 if (lyxrc.auto_region_delete) {
1211 if (cur.selection())
1212 cutSelection(false, false);
1213 bv->haveSelection(false);
1216 cur.clearSelection();
1217 LyXFont const old_font = real_current_font;
1219 string::const_iterator cit = cmd.argument.begin();
1220 string::const_iterator end = cmd.argument.end();
1221 for (; cit != end; ++cit)
1222 bv->owner()->getIntl().getTransManager().
1223 TranslateAndInsert(*cit, this);
1226 moveCursor(cur, false);
1228 // real_current_font.number can change so we need to
1229 // update the minibuffer
1230 if (old_font != real_current_font)
1231 bv->owner()->view_state_changed();
1232 bv->updateScrollbar();
1237 InsetCommandParams p("url");
1238 string const data = InsetCommandMailer::params2string("url", p);
1239 bv->owner()->getDialogs().show("url", data, 0);
1243 case LFUN_HTMLURL: {
1244 InsetCommandParams p("htmlurl");
1245 string const data = InsetCommandMailer::params2string("url", p);
1246 bv->owner()->getDialogs().show("url", data, 0);
1250 case LFUN_INSERT_LABEL: {
1251 InsetCommandParams p("label");
1252 string const data = InsetCommandMailer::params2string("label", p);
1253 bv->owner()->getDialogs().show("label", data, 0);
1259 case LFUN_INSET_LIST:
1260 case LFUN_INSET_THEOREM:
1261 case LFUN_INSET_CAPTION:
1263 case LFUN_INSERT_NOTE:
1264 case LFUN_INSERT_CHARSTYLE:
1265 case LFUN_INSERT_BOX:
1266 case LFUN_INSERT_BRANCH:
1267 case LFUN_INSERT_BIBITEM:
1268 case LFUN_INSET_ERT:
1269 case LFUN_INSET_FLOAT:
1270 case LFUN_INSET_FOOTNOTE:
1271 case LFUN_INSET_MARGINAL:
1272 case LFUN_INSET_OPTARG:
1273 case LFUN_INSET_WIDE_FLOAT:
1274 case LFUN_INSET_WRAP:
1275 case LFUN_TABULAR_INSERT:
1276 case LFUN_ENVIRONMENT_INSERT:
1277 // Open the inset, and move the current selection
1279 doInsertInset(cur, this, bv, cmd, true, true);
1282 case LFUN_INDEX_INSERT:
1283 // Just open the inset
1284 doInsertInset(cur, this, bv, cmd, true, false);
1287 case LFUN_INDEX_PRINT:
1288 case LFUN_TOC_INSERT:
1290 case LFUN_INSERT_LINE:
1291 case LFUN_INSERT_PAGEBREAK:
1293 doInsertInset(cur, this, bv, cmd, false, false);
1296 case LFUN_DEPTH_MIN:
1297 changeDepth(cur, bv_funcs::DEC_DEPTH);
1301 case LFUN_DEPTH_PLUS:
1302 changeDepth(cur, bv_funcs::INC_DEPTH);
1306 case LFUN_MATH_DISPLAY:
1307 mathDispatch(cur, cmd, true);
1310 case LFUN_MATH_IMPORT_SELECTION:
1311 case LFUN_MATH_MODE:
1312 mathDispatch(cur, cmd, false);
1315 case LFUN_MATH_MACRO:
1316 if (cmd.argument.empty())
1317 cur.errorMessage(N_("Missing argument"));
1319 string s = cmd.argument;
1320 string const s1 = token(s, ' ', 1);
1321 int const nargs = s1.empty() ? 0 : atoi(s1);
1322 string const s2 = token(s, ' ', 2);
1323 string const type = s2.empty() ? "newcommand" : s2;
1324 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1325 cur.nextInset()->edit(cur, true);
1329 case LFUN_INSERT_MATH:
1330 case LFUN_INSERT_MATRIX:
1331 case LFUN_MATH_DELIM: {
1332 cur.insert(new MathHullInset);
1333 cur.dispatch(FuncRequest(LFUN_RIGHT));
1334 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1340 LyXFont font(LyXFont::ALL_IGNORE);
1341 font.setEmph(LyXFont::TOGGLE);
1342 toggleAndShow(cur, this, font);
1343 bv->owner()->view_state_changed();
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setSeries(LyXFont::BOLD_SERIES);
1350 toggleAndShow(cur, this, font);
1351 bv->owner()->view_state_changed();
1356 LyXFont font(LyXFont::ALL_IGNORE);
1357 font.setNoun(LyXFont::TOGGLE);
1358 toggleAndShow(cur, this, font);
1359 bv->owner()->view_state_changed();
1364 LyXFont font(LyXFont::ALL_IGNORE);
1365 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1366 toggleAndShow(cur, this, font);
1367 bv->owner()->view_state_changed();
1372 LyXFont font(LyXFont::ALL_IGNORE);
1373 font.setFamily(LyXFont::SANS_FAMILY);
1374 toggleAndShow(cur, this, font);
1375 bv->owner()->view_state_changed();
1380 LyXFont font(LyXFont::ALL_IGNORE);
1381 font.setFamily(LyXFont::ROMAN_FAMILY);
1382 toggleAndShow(cur, this, font);
1383 bv->owner()->view_state_changed();
1387 case LFUN_DEFAULT: {
1388 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1389 toggleAndShow(cur, this, font);
1390 bv->owner()->view_state_changed();
1394 case LFUN_UNDERLINE: {
1395 LyXFont font(LyXFont::ALL_IGNORE);
1396 font.setUnderbar(LyXFont::TOGGLE);
1397 toggleAndShow(cur, this, font);
1398 bv->owner()->view_state_changed();
1402 case LFUN_FONT_SIZE: {
1403 LyXFont font(LyXFont::ALL_IGNORE);
1404 font.setLyXSize(cmd.argument);
1405 toggleAndShow(cur, this, font);
1406 bv->owner()->view_state_changed();
1410 case LFUN_LANGUAGE: {
1411 Language const * lang = languages.getLanguage(cmd.argument);
1414 LyXFont font(LyXFont::ALL_IGNORE);
1415 font.setLanguage(lang);
1416 toggleAndShow(cur, this, font);
1418 bv->owner()->view_state_changed();
1422 case LFUN_FREEFONT_APPLY:
1423 toggleAndShow(cur, this, freefont, toggleall);
1424 bv->owner()->view_state_changed();
1425 cur.message(_("Character set"));
1428 // Set the freefont using the contents of \param data dispatched from
1429 // the frontends and apply it at the current cursor location.
1430 case LFUN_FREEFONT_UPDATE: {
1433 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1436 toggleAndShow(cur, this, freefont, toggleall);
1437 bv->owner()->view_state_changed();
1438 cur.message(_("Character set"));
1443 case LFUN_FINISHED_LEFT:
1444 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1445 cur.pop(cur.currentDepth());
1447 cursorLeft(cur, true);
1448 cur.bv().cursor() = cur;
1451 case LFUN_FINISHED_RIGHT:
1452 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1453 cur.pop(cur.currentDepth());
1455 cursorRight(cur, true);
1456 cur.bv().cursor() = cur;
1459 case LFUN_FINISHED_UP:
1460 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1461 cur.pop(cur.currentDepth());
1462 cursorUp(cur, true);
1463 cur.bv().cursor() = cur;
1466 case LFUN_FINISHED_DOWN:
1467 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1468 cur.pop(cur.currentDepth());
1469 cursorDown(cur, true);
1470 cur.bv().cursor() = cur;
1473 case LFUN_LAYOUT_PARAGRAPH: {
1475 params2string(cur.paragraph(), data);
1476 data = "show\n" + data;
1477 bv->owner()->getDialogs().show("paragraph", data);
1481 case LFUN_PARAGRAPH_UPDATE: {
1482 if (!bv->owner()->getDialogs().visible("paragraph"))
1485 params2string(cur.paragraph(), data);
1487 // Will the paragraph accept changes from the dialog?
1488 InsetBase * const inset = cur.inset();
1490 !(inset && inset->forceDefaultParagraphs(inset));
1492 data = "update " + tostr(accept) + '\n' + data;
1493 bv->owner()->getDialogs().update("paragraph", data);
1498 case LFUN_CIRCUMFLEX:
1508 case LFUN_SPECIAL_CARON:
1511 case LFUN_HUNG_UMLAUT:
1514 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1515 if (!cmd.argument.empty())
1516 bv->owner()->getIntl().getTransManager()
1517 .TranslateAndInsert(cmd.argument[0], this);
1520 case LFUN_FLOAT_LIST: {
1521 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1522 if (tclass.floats().typeExist(cmd.argument)) {
1523 // not quite sure if we want this...
1526 cur.clearSelection();
1527 breakParagraph(cur);
1529 if (cur.lastpos() != 0) {
1530 cursorLeft(cur, true);
1531 breakParagraph(cur);
1534 setLayout(cur, tclass.defaultLayoutName());
1535 setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1536 cur.insert(new InsetFloatList(cmd.argument));
1539 lyxerr << "Non-existent float type: "
1540 << cmd.argument << endl;
1545 case LFUN_ACCEPT_CHANGE: {
1551 case LFUN_REJECT_CHANGE: {
1557 case LFUN_THESAURUS_ENTRY: {
1558 string arg = cmd.argument;
1560 arg = cur.selectionAsString(false);
1562 if (arg.size() > 100 || arg.empty()) {
1563 // Get word or selection
1564 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1565 arg = cur.selectionAsString(false);
1568 bv->owner()->getDialogs().show("thesaurus", arg);
1573 return DispatchResult(false);
1576 return DispatchResult(true, true);