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/insetquotes.h"
49 #include "insets/insetspecialchar.h"
50 #include "insets/insettext.h"
52 #include "support/lstrings.h"
53 #include "support/lyxlib.h"
54 #include "support/tostr.h"
55 #include "support/std_sstream.h"
57 #include "mathed/math_hullinset.h"
58 #include "mathed/formulamacro.h"
64 using lyx::support::isStrUnsignedInt;
65 using lyx::support::strToUnsignedInt;
66 using lyx::support::atoi;
67 using lyx::support::token;
72 using std::istringstream;
76 extern string current_layout;
78 // the selection possible is needed, that only motion events are
79 // used, where the button press event was on the drawing area too
80 bool selection_possible = false;
86 LyXFont freefont(LyXFont::ALL_IGNORE);
87 bool toggleall = false;
90 void toggleAndShow(LCursor & cur, LyXText * text,
91 LyXFont const & font, bool toggleall = true)
93 if (!cur.bv().available())
96 text->toggleFree(cur, font, toggleall);
98 if (font.language() != ignore_language ||
99 font.number() != LyXFont::IGNORE) {
100 Paragraph & par = cur.paragraph();
101 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
102 if (cur.boundary() !=
103 text->bidi.isBoundary(*cur.bv().buffer(), par,
105 text->real_current_font))
106 text->setCursor(cur, cur.par(), cur.pos(),
107 false, !cur.boundary());
113 void moveCursor(LCursor & cur, bool selecting)
115 if (selecting || cur.mark())
117 if (!cur.selection())
118 cur.bv().haveSelection(false);
119 cur.bv().switchKeyMap();
123 void finishChange(LCursor & cur, bool selecting = false)
126 moveCursor(cur, selecting);
127 cur.bv().owner()->view_state_changed();
131 void mathDispatch(LCursor & cur, LyXText * text,
132 FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 lyxerr << "selection is: '" << sel << "'" << endl;
138 cur.insert(new MathHullInset); // activates inset
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_MATH_MUTATE, "simple"));
155 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
157 cur.insert(new InsetFormulaMacro(sel));
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(LCursor & cur,
216 vector<InsetOld_code> const & codes, string const & contents)
218 BOOST_ASSERT(this == cur.text());
219 ParagraphList::iterator end = paragraphs().end();
220 ParagraphList::iterator pit = getPar(cur.par());
221 pos_type pos = cur.pos();
225 if (pos + 1 < pit->size()) {
232 } while (pit != end &&
233 !(pit->isInset(pos) &&
234 (inset = pit->getInset(pos)) != 0 &&
235 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
237 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
243 setCursor(cur, parOffset(pit), pos, false);
248 void LyXText::gotoInset(LCursor & cur,
249 vector<InsetOld_code> const & codes, bool same_content)
251 cur.clearSelection();
255 && cur.pos() < cur.lastpos()
256 && cur.paragraph().isInset(cur.pos())) {
257 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
258 if (find(codes.begin(), codes.end(), inset->lyxCode())
260 contents = static_cast<InsetCommand const *>(inset)->getContents();
263 if (!gotoNextInset(cur, codes, contents)) {
264 if (cur.pos() || cur.par() != 0) {
265 CursorSlice tmp = cur.top();
268 if (!gotoNextInset(cur, codes, contents)) {
270 cur.message(_("No more insets"));
273 cur.message(_("No more insets"));
281 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
283 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
287 void LyXText::cursorPrevious(LCursor & cur)
289 pos_type cpos = cur.pos();
290 lyx::paroffset_type cpar = cur.par();
292 int x = cur.x_target();
293 int y = bv()->top_y();
294 setCursorFromCoordinates(cur, x, y);
296 if (cpar == cur.par() && cpos == cur.pos()) {
297 // we have a row which is taller than the workarea. The
298 // simplest solution is to move to the previous row instead.
302 bv()->updateScrollbar();
307 void LyXText::cursorNext(LCursor & cur)
309 pos_type cpos = cur.pos();
310 lyx::paroffset_type cpar = cur.par();
312 int x = cur.x_target();
313 int y = bv()->top_y() + bv()->workHeight();
314 setCursorFromCoordinates(cur, x, y);
316 if (cpar == cur.par() && cpos == cur.pos()) {
317 // we have a row which is taller than the workarea. The
318 // simplest solution is to move to the next row instead.
322 bv()->updateScrollbar();
329 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
331 text->replaceSelection(cur);
332 cur.insert(new InsetSpecialChar(kind));
337 void doInsertInset(LCursor & cur, LyXText * text,
338 FuncRequest const & cmd, bool edit, bool pastesel)
340 InsetBase * inset = createInset(&cur.bv(), cmd);
345 if (cur.selection()) {
346 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
349 text->insertInset(cur, inset);
351 inset->edit(cur, true);
352 if (gotsel && pastesel)
353 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
359 void LyXText::number(LCursor & cur)
361 LyXFont font(LyXFont::ALL_IGNORE);
362 font.setNumber(LyXFont::TOGGLE);
363 toggleAndShow(cur, this, font);
367 bool LyXText::isRTL(Paragraph const & par) const
369 return par.isRightToLeftPar(bv()->buffer()->params());
373 void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
375 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
376 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
378 BufferView * bv = &cur.bv();
379 CursorSlice sl = cur.top();
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();
431 if (isRTL(cur.paragraph()))
432 cursorLeftOneWord(cur);
434 cursorRightOneWord(cur);
440 cur.clearSelection();
441 if (isRTL(cur.paragraph()))
442 cursorRightOneWord(cur);
444 cursorLeftOneWord(cur);
448 case LFUN_BEGINNINGBUF:
450 cur.clearSelection();
457 cur.clearSelection();
464 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
465 if (isRTL(cur.paragraph()))
470 cur.dispatched(FINISHED_RIGHT);
475 cur.selHandle(cmd.action == LFUN_LEFTSEL);
476 if (isRTL(cur.paragraph()))
481 cur.dispatched(FINISHED_LEFT);
486 cur.selHandle(cmd.action == LFUN_UPSEL);
489 cur.dispatched(FINISHED_UP);
494 cur.selHandle(cmd.action == LFUN_DOWNSEL);
497 cur.dispatched(FINISHED_DOWN);
500 case LFUN_UP_PARAGRAPHSEL:
501 if (!cur.selection())
503 cursorUpParagraph(cur);
504 finishChange(cur, true);
507 case LFUN_DOWN_PARAGRAPHSEL:
508 if (!cur.selection())
510 cursorDownParagraph(cur);
511 finishChange(cur, true);
515 if (!cur.selection())
518 finishChange(cur, true);
522 if (!cur.selection())
525 finishChange(cur, true);
529 if (!cur.selection())
532 finishChange(cur, true);
536 if (!cur.selection())
539 finishChange(cur, true);
542 case LFUN_WORDRIGHTSEL:
543 if (!cur.selection())
545 if (isRTL(cur.paragraph()))
546 cursorLeftOneWord(cur);
548 cursorRightOneWord(cur);
549 finishChange(cur, true);
552 case LFUN_WORDLEFTSEL:
553 if (!cur.selection())
555 if (isRTL(cur.paragraph()))
556 cursorRightOneWord(cur);
558 cursorLeftOneWord(cur);
559 finishChange(cur, true);
563 selectWord(cur, lyx::WHOLE_WORD);
564 finishChange(cur, true);
568 case LFUN_UP_PARAGRAPH:
570 cur.clearSelection();
571 cursorUpParagraph(cur);
575 case LFUN_DOWN_PARAGRAPH:
577 cur.clearSelection();
578 cursorDownParagraph(cur);
579 finishChange(cur, false);
584 cur.clearSelection();
585 finishChange(cur, false);
586 if (cur.par() == 0 && cur.textRow().pos() == 0)
587 cur.dispatched(FINISHED_UP);
594 cur.clearSelection();
595 finishChange(cur, false);
596 if (cur.par() == cur.lastpar()
597 && cur.textRow().endpos() == cur.lastpos())
598 cur.dispatched(FINISHED_DOWN);
605 cur.clearSelection();
607 finishChange(cur, false);
612 cur.clearSelection();
614 finishChange(cur, false);
617 case LFUN_BREAKLINE: {
618 // Not allowed by LaTeX (labels or empty par)
619 if (cur.pos() > cur.paragraph().beginOfBody()) {
620 replaceSelection(cur);
621 cur.insert(new InsetNewline);
622 moveCursor(cur, false);
628 if (!cur.selection()) {
631 // It is possible to make it a lot faster still
632 // just comment out the line below...
634 cutSelection(cur, true, false);
636 moveCursor(cur, false);
637 bv->owner()->view_state_changed();
640 case LFUN_DELETE_SKIP:
641 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
642 if (!cur.selection()) {
643 if (cur.pos() == cur.lastpos()) {
650 cutSelection(cur, true, false);
657 if (!cur.selection()) {
658 if (bv->owner()->getIntl().getTransManager().backspace()) {
661 // It is possible to make it a lot faster still
662 // just comment out the line below...
665 cutSelection(cur, true, false);
667 bv->owner()->view_state_changed();
672 case LFUN_BACKSPACE_SKIP:
673 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
674 if (!cur.selection()) {
676 //CursorSlice cur = cursor();
680 cutSelection(cur, true, false);
685 case LFUN_BREAKPARAGRAPH:
686 replaceSelection(cur);
687 breakParagraph(cur, 0);
691 bv->owner()->view_state_changed();
694 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
695 replaceSelection(cur);
696 breakParagraph(cur, 1);
700 bv->owner()->view_state_changed();
703 case LFUN_BREAKPARAGRAPH_SKIP: {
704 // When at the beginning of a paragraph, remove
705 // indentation and add a "defskip" at the top.
706 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
707 replaceSelection(cur);
708 if (cur.pos() == 0) {
709 ParagraphParameters & params = cur.paragraph().params();
713 params.labelWidthString(), 1);
715 breakParagraph(cur, 0);
720 bv->owner()->view_state_changed();
724 case LFUN_PARAGRAPH_SPACING: {
725 Paragraph & par = cur.paragraph();
726 Spacing::Space cur_spacing = par.params().spacing().getSpace();
727 float cur_value = 1.0;
728 if (cur_spacing == Spacing::Other)
729 cur_value = par.params().spacing().getValue();
731 istringstream is(cmd.argument);
734 Spacing::Space new_spacing = cur_spacing;
735 float new_value = cur_value;
737 lyxerr << "Missing argument to `paragraph-spacing'"
739 } else if (tmp == "single") {
740 new_spacing = Spacing::Single;
741 } else if (tmp == "onehalf") {
742 new_spacing = Spacing::Onehalf;
743 } else if (tmp == "double") {
744 new_spacing = Spacing::Double;
745 } else if (tmp == "other") {
746 new_spacing = Spacing::Other;
749 lyxerr << "new_value = " << tmpval << endl;
752 } else if (tmp == "default") {
753 new_spacing = Spacing::Default;
755 lyxerr << _("Unknown spacing argument: ")
756 << cmd.argument << endl;
758 if (cur_spacing != new_spacing || cur_value != new_value) {
759 par.params().spacing(Spacing(new_spacing, new_value));
766 case LFUN_INSET_APPLY: {
767 string const name = cmd.getArg(0);
768 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
770 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
772 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
776 case LFUN_INSET_INSERT: {
777 InsetBase * inset = createInset(bv, cmd);
779 insertInset(cur, inset);
783 case LFUN_INSET_SETTINGS:
784 if (cur.inset() && cur.inset()->asUpdatableInset())
785 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
788 case LFUN_INSET_TOGGLE:
789 cur.clearSelection();
790 if (!toggleInset(cur))
796 case LFUN_SPACE_INSERT:
797 if (cur.paragraph().layout()->free_spacing)
798 insertChar(cur, ' ');
800 doInsertInset(cur, this, cmd, false, false);
801 moveCursor(cur, false);
804 case LFUN_HYPHENATION:
805 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
808 case LFUN_LIGATURE_BREAK:
809 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
813 specialChar(cur, this, InsetSpecialChar::LDOTS);
816 case LFUN_END_OF_SENTENCE:
817 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
820 case LFUN_MENU_SEPARATOR:
821 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
824 case LFUN_UPCASE_WORD:
825 changeCase(cur, LyXText::text_uppercase);
829 case LFUN_LOWCASE_WORD:
830 changeCase(cur, LyXText::text_lowercase);
834 case LFUN_CAPITALIZE_WORD:
835 changeCase(cur, LyXText::text_capitalization);
839 case LFUN_TRANSPOSE_CHARS:
846 cur.message(_("Paste"));
847 replaceSelection(cur);
848 #warning FIXME Check if the arg is in the domain of available selections.
849 if (isStrUnsignedInt(cmd.argument))
850 pasteSelection(cur, strToUnsignedInt(cmd.argument));
852 pasteSelection(cur, 0);
853 cur.clearSelection(); // bug 393
860 cutSelection(cur, true, true);
861 cur.message(_("Cut"));
867 cur.message(_("Copy"));
870 case LFUN_BEGINNINGBUFSEL:
874 if (!cur.selection())
877 finishChange(cur, true);
885 if (!cur.selection())
888 finishChange(cur, true);
893 cur.message(tostr(cursorX(cur.top())) + ' '
894 + tostr(cursorY(cur.top())));
900 istringstream is(cmd.argument);
903 lyxerr << "SETXY: Could not parse coordinates in '"
904 << cmd.argument << std::endl;
906 setCursorFromCoordinates(cur, x, y);
911 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
913 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
920 cur.message(cur.paragraph().layout()->name());
924 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
925 << cmd.argument << endl;
927 // This is not the good solution to the empty argument
928 // problem, but it will hopefully suffice for 1.2.0.
929 // The correct solution would be to augument the
930 // function list/array with information about what
931 // functions needs arguments and their type.
932 if (cmd.argument.empty()) {
933 cur.errorMessage(_("LyX function 'layout' needs an argument."));
937 // Derive layout number from given argument (string)
938 // and current buffer's textclass (number)
939 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
940 bool hasLayout = tclass.hasLayout(cmd.argument);
941 string layout = cmd.argument;
943 // If the entry is obsolete, use the new one instead.
945 string const & obs = tclass[layout]->obsoleted_by();
951 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
956 bool change_layout = (current_layout != layout);
958 if (!change_layout && cur.selection() &&
959 cur.selBegin().par() != cur.selEnd().par())
961 ParagraphList::iterator spit = getPar(cur.selBegin());
962 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
963 while (spit != epit) {
964 if (spit->layout()->name() != current_layout) {
965 change_layout = true;
973 current_layout = layout;
974 setLayout(cur, layout);
975 bv->owner()->setLayout(layout);
982 case LFUN_PASTESELECTION: {
983 cur.clearSelection();
984 string const clip = bv->getClipboard();
986 if (cmd.argument == "paragraph")
987 insertStringAsParagraphs(cur, clip);
989 insertStringAsLines(cur, clip);
996 gotoInset(cur, InsetBase::ERROR_CODE, false);
1000 gotoInset(cur, InsetBase::NOTE_CODE, false);
1003 case LFUN_REFERENCE_GOTO: {
1004 vector<InsetOld_code> tmp;
1005 tmp.push_back(InsetBase::LABEL_CODE);
1006 tmp.push_back(InsetBase::REF_CODE);
1007 gotoInset(cur, tmp, true);
1012 replaceSelection(cur);
1013 Paragraph & par = cur.paragraph();
1014 lyx::pos_type pos = cur.pos();
1018 else if (cur.prevInset() && cur.prevInset()->isSpace())
1021 c = par.getChar(pos - 1);
1023 LyXLayout_ptr const & style = par.layout();
1025 BufferParams const & bufparams = bv->buffer()->params();
1026 if (!style->pass_thru
1027 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1028 string arg = cmd.argument;
1029 if (arg == "single")
1030 cur.insert(new InsetQuotes(c,
1031 bufparams.quotes_language,
1032 InsetQuotes::SingleQ));
1033 else if (arg == "double")
1034 cur.insert(new InsetQuotes(c,
1035 bufparams.quotes_language,
1036 InsetQuotes::DoubleQ));
1038 cur.insert(new InsetQuotes(c, bufparams));
1041 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1045 case LFUN_DATE_INSERT: {
1046 replaceSelection(cur);
1047 time_t now_time_t = time(NULL);
1048 struct tm * now_tm = localtime(&now_time_t);
1049 setlocale(LC_TIME, "");
1051 if (!cmd.argument.empty())
1054 arg = lyxrc.date_insert_format;
1056 int const datetmp_len =
1057 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1059 for (int i = 0; i < datetmp_len; i++)
1060 insertChar(cur, datetmp[i]);
1063 moveCursor(cur, false);
1067 case LFUN_MOUSE_TRIPLE:
1068 if (cmd.button() == mouse_button::button1) {
1069 selection_possible = true;
1074 bv->haveSelection(cur.selection());
1078 case LFUN_MOUSE_DOUBLE:
1079 if (cmd.button() == mouse_button::button1) {
1080 selection_possible = true;
1081 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1082 bv->haveSelection(cur.selection());
1086 case LFUN_MOUSE_MOTION: {
1087 // Only use motion with button 1
1088 //if (cmd.button() != mouse_button::button1)
1090 // The test for not selection possible is needed, that
1091 // only motion events are used, where the bottom press
1092 // event was on the drawing area too
1093 if (!selection_possible) {
1094 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1095 "Dispatch: no selection possible\n";
1098 CursorSlice old = cur.top();
1099 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1101 // This is to allow jumping over large insets
1102 // FIXME: shouldn't be top-text-specific
1103 if (!in_inset_ && cur.top() == old) {
1104 if (cmd.y - bv->top_y() >= bv->workHeight())
1106 else if (cmd.y - bv->top_y() < 0)
1110 // don't set anchor_
1111 bv->cursor().setCursor(cur, false);
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, cmd.x, cmd.y);
1156 cur.x_target() = cursorX(cur.top());
1158 // set cursor and anchor to this position
1161 if (bv->fitCursor())
1162 selection_possible = false;
1164 // Insert primary selection with middle mouse
1165 // if there is a local selection in the current buffer,
1167 if (cmd.button() == mouse_button::button2) {
1168 if (paste_internally)
1169 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1171 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1172 selection_possible = false;
1177 case LFUN_MOUSE_RELEASE: {
1178 // do nothing if we used the mouse wheel
1179 if (cmd.button() == mouse_button::button4
1180 || cmd.button() == mouse_button::button5) {
1185 selection_possible = false;
1187 if (cmd.button() == mouse_button::button2)
1191 if (cmd.button() == mouse_button::button1)
1192 bv->haveSelection(cur.selection());
1195 bv->owner()->view_state_changed();
1196 bv->owner()->updateMenubar();
1197 bv->owner()->updateToolbar();
1201 case LFUN_SELFINSERT: {
1202 if (cmd.argument.empty())
1205 // Automatically delete the currently selected
1206 // text and replace it with what is being
1207 // typed in now. Depends on lyxrc settings
1208 // "auto_region_delete", which defaults to
1211 if (lyxrc.auto_region_delete) {
1212 if (cur.selection())
1213 cutSelection(cur, false, false);
1214 bv->haveSelection(false);
1217 cur.clearSelection();
1218 LyXFont const old_font = real_current_font;
1220 string::const_iterator cit = cmd.argument.begin();
1221 string::const_iterator end = cmd.argument.end();
1222 for (; cit != end; ++cit)
1223 bv->owner()->getIntl().getTransManager().
1224 TranslateAndInsert(*cit, this);
1227 moveCursor(cur, false);
1229 // real_current_font.number can change so we need to
1230 // update the minibuffer
1231 if (old_font != real_current_font)
1232 bv->owner()->view_state_changed();
1233 bv->updateScrollbar();
1238 InsetCommandParams p("url");
1239 string const data = InsetCommandMailer::params2string("url", p);
1240 bv->owner()->getDialogs().show("url", data, 0);
1244 case LFUN_HTMLURL: {
1245 InsetCommandParams p("htmlurl");
1246 string const data = InsetCommandMailer::params2string("url", p);
1247 bv->owner()->getDialogs().show("url", data, 0);
1251 case LFUN_INSERT_LABEL: {
1252 InsetCommandParams p("label");
1253 string const data = InsetCommandMailer::params2string("label", p);
1254 bv->owner()->getDialogs().show("label", data, 0);
1260 case LFUN_INSET_LIST:
1261 case LFUN_INSET_THEOREM:
1262 case LFUN_INSET_CAPTION:
1264 case LFUN_INSERT_NOTE:
1265 case LFUN_INSERT_CHARSTYLE:
1266 case LFUN_INSERT_BOX:
1267 case LFUN_INSERT_BRANCH:
1268 case LFUN_INSERT_BIBITEM:
1269 case LFUN_INSET_ERT:
1270 case LFUN_INSET_FLOAT:
1271 case LFUN_INSET_FOOTNOTE:
1272 case LFUN_INSET_MARGINAL:
1273 case LFUN_INSET_OPTARG:
1274 case LFUN_INSET_WIDE_FLOAT:
1275 case LFUN_INSET_WRAP:
1276 case LFUN_TABULAR_INSERT:
1277 case LFUN_ENVIRONMENT_INSERT:
1278 // Open the inset, and move the current selection
1280 doInsertInset(cur, this, cmd, true, true);
1283 case LFUN_INDEX_INSERT:
1284 // Just open the inset
1285 doInsertInset(cur, this, cmd, true, false);
1288 case LFUN_INDEX_PRINT:
1289 case LFUN_TOC_INSERT:
1291 case LFUN_INSERT_LINE:
1292 case LFUN_INSERT_PAGEBREAK:
1294 doInsertInset(cur, this, cmd, false, false);
1297 case LFUN_DEPTH_MIN:
1298 changeDepth(cur, bv_funcs::DEC_DEPTH);
1302 case LFUN_DEPTH_PLUS:
1303 changeDepth(cur, bv_funcs::INC_DEPTH);
1307 case LFUN_MATH_DISPLAY:
1308 mathDispatch(cur, this, cmd, true);
1311 case LFUN_MATH_IMPORT_SELECTION:
1312 case LFUN_MATH_MODE:
1313 mathDispatch(cur, this, cmd, false);
1316 case LFUN_MATH_MACRO:
1317 if (cmd.argument.empty())
1318 cur.errorMessage(N_("Missing argument"));
1320 string s = cmd.argument;
1321 string const s1 = token(s, ' ', 1);
1322 int const nargs = s1.empty() ? 0 : atoi(s1);
1323 string const s2 = token(s, ' ', 2);
1324 string const type = s2.empty() ? "newcommand" : s2;
1325 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1326 cur.nextInset()->edit(cur, true);
1330 case LFUN_INSERT_MATH:
1331 case LFUN_INSERT_MATRIX:
1332 case LFUN_MATH_DELIM: {
1333 cur.insert(new MathHullInset);
1334 cur.dispatch(FuncRequest(LFUN_RIGHT));
1335 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1341 LyXFont font(LyXFont::ALL_IGNORE);
1342 font.setEmph(LyXFont::TOGGLE);
1343 toggleAndShow(cur, this, font);
1344 bv->owner()->view_state_changed();
1349 LyXFont font(LyXFont::ALL_IGNORE);
1350 font.setSeries(LyXFont::BOLD_SERIES);
1351 toggleAndShow(cur, this, font);
1352 bv->owner()->view_state_changed();
1357 LyXFont font(LyXFont::ALL_IGNORE);
1358 font.setNoun(LyXFont::TOGGLE);
1359 toggleAndShow(cur, this, font);
1360 bv->owner()->view_state_changed();
1365 LyXFont font(LyXFont::ALL_IGNORE);
1366 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1367 toggleAndShow(cur, this, font);
1368 bv->owner()->view_state_changed();
1373 LyXFont font(LyXFont::ALL_IGNORE);
1374 font.setFamily(LyXFont::SANS_FAMILY);
1375 toggleAndShow(cur, this, font);
1376 bv->owner()->view_state_changed();
1381 LyXFont font(LyXFont::ALL_IGNORE);
1382 font.setFamily(LyXFont::ROMAN_FAMILY);
1383 toggleAndShow(cur, this, font);
1384 bv->owner()->view_state_changed();
1388 case LFUN_DEFAULT: {
1389 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1390 toggleAndShow(cur, this, font);
1391 bv->owner()->view_state_changed();
1395 case LFUN_UNDERLINE: {
1396 LyXFont font(LyXFont::ALL_IGNORE);
1397 font.setUnderbar(LyXFont::TOGGLE);
1398 toggleAndShow(cur, this, font);
1399 bv->owner()->view_state_changed();
1403 case LFUN_FONT_SIZE: {
1404 LyXFont font(LyXFont::ALL_IGNORE);
1405 font.setLyXSize(cmd.argument);
1406 toggleAndShow(cur, this, font);
1407 bv->owner()->view_state_changed();
1411 case LFUN_LANGUAGE: {
1412 Language const * lang = languages.getLanguage(cmd.argument);
1415 LyXFont font(LyXFont::ALL_IGNORE);
1416 font.setLanguage(lang);
1417 toggleAndShow(cur, this, font);
1419 bv->owner()->view_state_changed();
1423 case LFUN_FREEFONT_APPLY:
1424 toggleAndShow(cur, this, freefont, toggleall);
1425 bv->owner()->view_state_changed();
1426 cur.message(_("Character set"));
1429 // Set the freefont using the contents of \param data dispatched from
1430 // the frontends and apply it at the current cursor location.
1431 case LFUN_FREEFONT_UPDATE: {
1434 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1437 toggleAndShow(cur, this, freefont, toggleall);
1438 bv->owner()->view_state_changed();
1439 cur.message(_("Character set"));
1444 case LFUN_FINISHED_LEFT:
1445 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1446 if (isRTL(cur.paragraph()))
1448 cur.bv().cursor() = cur;
1451 case LFUN_FINISHED_RIGHT:
1452 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1453 if (!isRTL(cur.paragraph()))
1455 cur.bv().cursor() = cur;
1458 case LFUN_FINISHED_UP:
1459 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1461 cur.bv().cursor() = cur;
1464 case LFUN_FINISHED_DOWN:
1465 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1467 cur.bv().cursor() = cur;
1470 case LFUN_LAYOUT_PARAGRAPH: {
1472 params2string(cur.paragraph(), data);
1473 data = "show\n" + data;
1474 bv->owner()->getDialogs().show("paragraph", data);
1478 case LFUN_PARAGRAPH_UPDATE: {
1479 if (!bv->owner()->getDialogs().visible("paragraph"))
1482 params2string(cur.paragraph(), data);
1484 // Will the paragraph accept changes from the dialog?
1485 InsetBase * const inset = cur.inset();
1487 !(inset && inset->forceDefaultParagraphs(inset));
1489 data = "update " + tostr(accept) + '\n' + data;
1490 bv->owner()->getDialogs().update("paragraph", data);
1495 case LFUN_CIRCUMFLEX:
1505 case LFUN_SPECIAL_CARON:
1508 case LFUN_HUNG_UMLAUT:
1511 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1512 if (!cmd.argument.empty())
1513 bv->owner()->getIntl().getTransManager()
1514 .TranslateAndInsert(cmd.argument[0], this);
1517 case LFUN_FLOAT_LIST: {
1518 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1519 if (tclass.floats().typeExist(cmd.argument)) {
1520 // not quite sure if we want this...
1523 cur.clearSelection();
1524 breakParagraph(cur);
1526 if (cur.lastpos() != 0) {
1528 breakParagraph(cur);
1531 setLayout(cur, tclass.defaultLayoutName());
1532 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1533 cur.insert(new InsetFloatList(cmd.argument));
1536 lyxerr << "Non-existent float type: "
1537 << cmd.argument << endl;
1542 case LFUN_ACCEPT_CHANGE: {
1548 case LFUN_REJECT_CHANGE: {
1554 case LFUN_THESAURUS_ENTRY: {
1555 string arg = cmd.argument;
1557 arg = cur.selectionAsString(false);
1559 if (arg.size() > 100 || arg.empty()) {
1560 // Get word or selection
1561 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1562 arg = cur.selectionAsString(false);
1565 bv->owner()->getDialogs().show("thesaurus", arg);
1569 case LFUN_PARAGRAPH_APPLY: {
1570 // Given data, an encoding of the ParagraphParameters
1571 // generated in the Paragraph dialog, this function sets
1572 // the current paragraph appropriately.
1573 istringstream is(cmd.argument);
1576 ParagraphParameters params;
1581 params.labelWidthString(),
1584 cur.message(_("Paragraph layout set"));
1589 if (cur.selection())
1590 cur.selection() = false;
1592 cur.dispatched(FINISHED_LEFT);
1602 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)