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 text->toggleFree(cur, font, toggleall);
95 if (font.language() != ignore_language ||
96 font.number() != LyXFont::IGNORE) {
97 Paragraph & par = cur.paragraph();
98 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
100 text->bidi.isBoundary(*cur.bv().buffer(), par,
102 text->real_current_font))
103 text->setCursor(cur, cur.par(), cur.pos(),
104 false, !cur.boundary());
109 void moveCursor(LCursor & cur, bool selecting)
111 if (selecting || cur.mark())
113 if (!cur.selection())
114 cur.bv().haveSelection(false);
115 cur.bv().switchKeyMap();
119 void finishChange(LCursor & cur, bool selecting)
122 moveCursor(cur, selecting);
126 void mathDispatch(LCursor & cur, LyXText * text,
127 FuncRequest const & cmd, bool display)
130 string sel = cur.selectionAsString(false);
131 lyxerr << "selection is: '" << sel << "'" << endl;
134 cur.insert(new MathHullInset);
135 cur.dispatch(FuncRequest(LFUN_RIGHT));
136 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
137 // don't do that also for LFUN_MATH_MODE unless you want end up with
138 // always changing to mathrm when opening an inlined inset
139 // -- I really hate "LyXfunc overloading"...
141 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
142 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
144 // create a macro if we see "\\newcommand" somewhere, and an ordinary
146 text->cutSelection(cur, true, true);
147 if (sel.find("\\newcommand") == string::npos
148 && sel.find("\\def") == string::npos)
150 cur.insert(new MathHullInset);
151 cur.dispatch(FuncRequest(LFUN_RIGHT));
152 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
153 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
155 cur.insert(new InsetFormulaMacro(sel));
156 cur.dispatch(FuncRequest(LFUN_RIGHT));
159 cur.message(N_("Math editor mode"));
168 string const freefont2string()
171 if (font2string(freefont, toggleall, data))
179 //takes absolute x,y coordinates
180 InsetBase * LyXText::checkInsetHit(int x, int y)
182 ParagraphList::iterator pit;
183 ParagraphList::iterator end;
185 getParsInRange(paragraphs(),
187 bv()->top_y() - yo_ + bv()->workHeight(),
190 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
191 for ( ; pit != end; ++pit) {
192 InsetList::iterator iit = pit->insetlist.begin();
193 InsetList::iterator iend = pit->insetlist.end();
194 for ( ; iit != iend; ++iit) {
195 InsetBase * inset = iit->inset;
197 lyxerr << "examining inset " << inset
198 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
199 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
200 << " yo: " << inset->yo() - inset->ascent() << "..."
201 << inset->yo() + inset->descent() << endl;
203 if (inset->covers(x, y)) {
204 lyxerr << "Hit inset: " << inset << endl;
209 lyxerr << "No inset hit. " << endl;
214 bool LyXText::gotoNextInset(LCursor & cur,
215 vector<InsetOld_code> const & codes, string const & contents)
217 BOOST_ASSERT(this == cur.text());
218 ParagraphList::iterator end = paragraphs().end();
219 ParagraphList::iterator pit = getPar(cur.par());
220 pos_type pos = cur.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(cur, parOffset(pit), pos, false);
247 void LyXText::gotoInset(LCursor & cur,
248 vector<InsetOld_code> const & codes, bool same_content)
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(cur, codes, contents)) {
263 if (cur.pos() || cur.par() != 0) {
264 CursorSlice tmp = cur.top();
267 if (!gotoNextInset(cur, codes, contents)) {
269 cur.message(_("No more insets"));
272 cur.message(_("No more insets"));
280 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
282 gotoInset(cur, 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(cur, 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(cur, 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.
321 bv()->updateScrollbar();
328 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
330 text->replaceSelection(cur);
331 cur.insert(new InsetSpecialChar(kind));
336 void doInsertInset(LCursor & cur, LyXText * text,
337 FuncRequest const & cmd, bool edit, bool pastesel)
339 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 & 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);
413 finishChange(cur, false);
416 case LFUN_DELETE_WORD_BACKWARD:
417 cur.clearSelection();
418 deleteWordBackward(cur);
419 finishChange(cur, false);
422 case LFUN_DELETE_LINE_FORWARD:
423 cur.clearSelection();
424 deleteLineForward(cur);
425 finishChange(cur, false);
430 cur.clearSelection();
431 if (isRTL(cur.paragraph()))
432 cursorLeftOneWord(cur);
434 cursorRightOneWord(cur);
435 finishChange(cur, false);
440 cur.clearSelection();
441 if (isRTL(cur.paragraph()))
442 cursorRightOneWord(cur);
444 cursorLeftOneWord(cur);
445 finishChange(cur, false);
448 case LFUN_BEGINNINGBUF:
450 cur.clearSelection();
452 finishChange(cur, false);
457 cur.clearSelection();
459 finishChange(cur, false);
464 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
465 if (isRTL(cur.paragraph()))
470 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
475 cur.selHandle(cmd.action == LFUN_LEFTSEL);
476 if (isRTL(cur.paragraph()))
481 cmd = FuncRequest(LFUN_FINISHED_LEFT);
486 cur.selHandle(cmd.action == LFUN_UPSEL);
489 cmd = FuncRequest(LFUN_FINISHED_UP);
494 cur.selHandle(cmd.action == LFUN_DOWNSEL);
497 cmd = FuncRequest(LFUN_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);
572 finishChange(cur, false);
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 cmd = FuncRequest(LFUN_FINISHED_UP);
594 cur.clearSelection();
595 finishChange(cur, false);
596 if (cur.par() == cur.lastpar()
597 && cur.textRow().endpos() == cur.lastpos())
598 cmd = FuncRequest(LFUN_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);
639 case LFUN_DELETE_SKIP:
640 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
641 if (!cur.selection()) {
642 if (cur.pos() == cur.lastpos()) {
649 cutSelection(cur, true, false);
656 if (!cur.selection()) {
657 if (bv->owner()->getIntl().getTransManager().backspace()) {
660 // It is possible to make it a lot faster still
661 // just comment out the line below...
664 cutSelection(cur, true, false);
670 case LFUN_BACKSPACE_SKIP:
671 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
672 if (!cur.selection()) {
674 //CursorSlice cur = cursor();
678 cutSelection(cur, true, false);
683 case LFUN_BREAKPARAGRAPH:
684 replaceSelection(cur);
685 breakParagraph(cur, 0);
691 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
692 replaceSelection(cur);
693 breakParagraph(cur, 1);
699 case LFUN_BREAKPARAGRAPH_SKIP: {
700 // When at the beginning of a paragraph, remove
701 // indentation and add a "defskip" at the top.
702 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
703 replaceSelection(cur);
704 if (cur.pos() == 0) {
705 ParagraphParameters & params = cur.paragraph().params();
709 params.labelWidthString(), 1);
711 breakParagraph(cur, 0);
719 case LFUN_PARAGRAPH_SPACING: {
720 Paragraph & par = cur.paragraph();
721 Spacing::Space cur_spacing = par.params().spacing().getSpace();
722 float cur_value = 1.0;
723 if (cur_spacing == Spacing::Other)
724 cur_value = par.params().spacing().getValue();
726 istringstream is(cmd.argument);
729 Spacing::Space new_spacing = cur_spacing;
730 float new_value = cur_value;
732 lyxerr << "Missing argument to `paragraph-spacing'"
734 } else if (tmp == "single") {
735 new_spacing = Spacing::Single;
736 } else if (tmp == "onehalf") {
737 new_spacing = Spacing::Onehalf;
738 } else if (tmp == "double") {
739 new_spacing = Spacing::Double;
740 } else if (tmp == "other") {
741 new_spacing = Spacing::Other;
744 lyxerr << "new_value = " << tmpval << endl;
747 } else if (tmp == "default") {
748 new_spacing = Spacing::Default;
750 lyxerr << _("Unknown spacing argument: ")
751 << cmd.argument << endl;
753 if (cur_spacing != new_spacing || cur_value != new_value) {
754 par.params().spacing(Spacing(new_spacing, new_value));
761 case LFUN_INSET_APPLY: {
762 string const name = cmd.getArg(0);
763 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
765 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
766 inset->dispatch(cur, fr);
768 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
774 case LFUN_INSET_INSERT: {
776 InsetBase * inset = createInset(bv, cmd);
778 insertInset(cur, inset);
782 case LFUN_INSET_SETTINGS:
783 if (cur.inset().asUpdatableInset())
784 cur.inset().asUpdatableInset()->showInsetDialog(bv);
787 case LFUN_INSET_TOGGLE:
788 cur.clearSelection();
789 if (!toggleInset(cur))
795 case LFUN_SPACE_INSERT:
796 if (cur.paragraph().layout()->free_spacing)
797 insertChar(cur, ' ');
799 doInsertInset(cur, this, cmd, false, false);
800 moveCursor(cur, false);
803 case LFUN_HYPHENATION:
804 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
807 case LFUN_LIGATURE_BREAK:
808 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
812 specialChar(cur, this, InsetSpecialChar::LDOTS);
815 case LFUN_END_OF_SENTENCE:
816 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
819 case LFUN_MENU_SEPARATOR:
820 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
823 case LFUN_UPCASE_WORD:
824 changeCase(cur, LyXText::text_uppercase);
828 case LFUN_LOWCASE_WORD:
829 changeCase(cur, LyXText::text_lowercase);
833 case LFUN_CAPITALIZE_WORD:
834 changeCase(cur, LyXText::text_capitalization);
838 case LFUN_TRANSPOSE_CHARS:
845 cur.message(_("Paste"));
846 replaceSelection(cur);
847 #warning FIXME Check if the arg is in the domain of available selections.
848 if (isStrUnsignedInt(cmd.argument))
849 pasteSelection(cur, strToUnsignedInt(cmd.argument));
851 pasteSelection(cur, 0);
852 cur.clearSelection(); // bug 393
859 cutSelection(cur, true, true);
860 cur.message(_("Cut"));
866 cur.message(_("Copy"));
870 cur.message(tostr(cursorX(cur.top())) + ' '
871 + tostr(cursorY(cur.top())));
877 istringstream is(cmd.argument);
880 lyxerr << "SETXY: Could not parse coordinates in '"
881 << cmd.argument << std::endl;
883 setCursorFromCoordinates(cur, x, y);
888 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
890 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
897 cur.message(cur.paragraph().layout()->name());
901 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
902 << cmd.argument << endl;
904 // This is not the good solution to the empty argument
905 // problem, but it will hopefully suffice for 1.2.0.
906 // The correct solution would be to augument the
907 // function list/array with information about what
908 // functions needs arguments and their type.
909 if (cmd.argument.empty()) {
910 cur.errorMessage(_("LyX function 'layout' needs an argument."));
914 // Derive layout number from given argument (string)
915 // and current buffer's textclass (number)
916 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
917 bool hasLayout = tclass.hasLayout(cmd.argument);
918 string layout = cmd.argument;
920 // If the entry is obsolete, use the new one instead.
922 string const & obs = tclass[layout]->obsoleted_by();
928 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
933 bool change_layout = (current_layout != layout);
935 if (!change_layout && cur.selection() &&
936 cur.selBegin().par() != cur.selEnd().par())
938 ParagraphList::iterator spit = getPar(cur.selBegin());
939 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
940 while (spit != epit) {
941 if (spit->layout()->name() != current_layout) {
942 change_layout = true;
950 current_layout = layout;
951 setLayout(cur, layout);
952 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);
973 gotoInset(cur, InsetBase::ERROR_CODE, false);
977 gotoInset(cur, InsetBase::NOTE_CODE, false);
980 case LFUN_REFERENCE_GOTO: {
981 vector<InsetOld_code> tmp;
982 tmp.push_back(InsetBase::LABEL_CODE);
983 tmp.push_back(InsetBase::REF_CODE);
984 gotoInset(cur, tmp, true);
989 replaceSelection(cur);
990 Paragraph & par = cur.paragraph();
991 lyx::pos_type pos = cur.pos();
995 else if (cur.prevInset() && cur.prevInset()->isSpace())
998 c = par.getChar(pos - 1);
1000 LyXLayout_ptr const & style = par.layout();
1002 BufferParams const & bufparams = bv->buffer()->params();
1003 if (!style->pass_thru
1004 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1005 string arg = cmd.argument;
1006 if (arg == "single")
1007 cur.insert(new InsetQuotes(c,
1008 bufparams.quotes_language,
1009 InsetQuotes::SingleQ));
1010 else if (arg == "double")
1011 cur.insert(new InsetQuotes(c,
1012 bufparams.quotes_language,
1013 InsetQuotes::DoubleQ));
1015 cur.insert(new InsetQuotes(c, bufparams));
1018 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1022 case LFUN_DATE_INSERT: {
1023 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 case LFUN_MOUSE_MOTION: {
1064 // Only use motion with button 1
1065 //if (cmd.button() != mouse_button::button1)
1067 // The test for not selection possible is needed, that
1068 // only motion events are used, where the bottom press
1069 // event was on the drawing area too
1070 if (!selection_possible) {
1071 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1072 "Dispatch: no selection possible\n";
1075 CursorSlice old = cur.top();
1076 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1078 // This is to allow jumping over large insets
1079 // FIXME: shouldn't be top-text-specific
1080 if (isMainText() && cur.top() == old) {
1081 if (cmd.y - bv->top_y() >= bv->workHeight())
1083 else if (cmd.y - bv->top_y() < 0)
1087 // don't set anchor_
1088 bv->cursor().setCursor(cur, false);
1092 // Single-click on work area
1093 case LFUN_MOUSE_PRESS: {
1094 // ok ok, this is a hack (for xforms)
1095 // We shouldn't go further down as we really should only do the
1096 // scrolling and be done with this. Otherwise we may open some
1097 // dialogs (Jug 20020424).
1098 if (cmd.button() == mouse_button::button4) {
1099 bv->scroll(-lyxrc.wheel_jump);
1103 if (cmd.button() == mouse_button::button5) {
1104 bv->scroll(lyxrc.wheel_jump);
1108 // Right click on a footnote flag opens float menu
1109 if (cmd.button() == mouse_button::button3) {
1110 cur.clearSelection();
1111 selection_possible = false;
1115 // Middle button press pastes if we have a selection
1116 // We do this here as if the selection was inside an inset
1117 // it could get cleared on the unlocking of the inset so
1118 // we have to check this first
1119 bool paste_internally = false;
1120 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1121 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1122 paste_internally = true;
1125 selection_possible = true;
1127 // Clear the selection
1128 cur.clearSelection();
1130 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1133 cur.x_target() = cursorX(cur.top());
1135 // set cursor and anchor to this position
1138 if (bv->fitCursor())
1139 selection_possible = false;
1141 // Insert primary selection with middle mouse
1142 // if there is a local selection in the current buffer,
1144 if (cmd.button() == mouse_button::button2) {
1145 if (paste_internally)
1146 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1148 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1149 selection_possible = false;
1154 case LFUN_MOUSE_RELEASE: {
1155 // do nothing if we used the mouse wheel
1156 if (cmd.button() == mouse_button::button4
1157 || cmd.button() == mouse_button::button5) {
1162 selection_possible = false;
1164 if (cmd.button() == mouse_button::button2)
1168 if (cmd.button() == mouse_button::button1)
1169 bv->haveSelection(cur.selection());
1172 bv->owner()->updateMenubar();
1173 bv->owner()->updateToolbar();
1177 case LFUN_SELFINSERT: {
1178 if (cmd.argument.empty())
1181 // Automatically delete the currently selected
1182 // text and replace it with what is being
1183 // typed in now. Depends on lyxrc settings
1184 // "auto_region_delete", which defaults to
1187 if (lyxrc.auto_region_delete) {
1188 if (cur.selection())
1189 cutSelection(cur, false, false);
1190 bv->haveSelection(false);
1193 cur.clearSelection();
1194 LyXFont const old_font = real_current_font;
1196 string::const_iterator cit = cmd.argument.begin();
1197 string::const_iterator end = cmd.argument.end();
1198 for (; cit != end; ++cit)
1199 bv->owner()->getIntl().getTransManager().
1200 TranslateAndInsert(*cit, this);
1203 moveCursor(cur, false);
1205 // real_current_font.number can change so we need to
1206 // update the minibuffer
1207 if (old_font != real_current_font)
1208 bv->updateScrollbar();
1213 InsetCommandParams p("url");
1214 string const data = InsetCommandMailer::params2string("url", p);
1215 bv->owner()->getDialogs().show("url", data, 0);
1219 case LFUN_HTMLURL: {
1220 InsetCommandParams p("htmlurl");
1221 string const data = InsetCommandMailer::params2string("url", p);
1222 bv->owner()->getDialogs().show("url", data, 0);
1226 case LFUN_INSERT_LABEL: {
1227 InsetCommandParams p("label");
1228 string const data = InsetCommandMailer::params2string("label", p);
1229 bv->owner()->getDialogs().show("label", data, 0);
1235 case LFUN_INSET_LIST:
1236 case LFUN_INSET_THEOREM:
1237 case LFUN_INSET_CAPTION:
1239 case LFUN_INSERT_NOTE:
1240 case LFUN_INSERT_CHARSTYLE:
1241 case LFUN_INSERT_BOX:
1242 case LFUN_INSERT_BRANCH:
1243 case LFUN_INSERT_BIBITEM:
1244 case LFUN_INSET_ERT:
1245 case LFUN_INSET_FLOAT:
1246 case LFUN_INSET_FOOTNOTE:
1247 case LFUN_INSET_MARGINAL:
1248 case LFUN_INSET_OPTARG:
1249 case LFUN_INSET_WIDE_FLOAT:
1250 case LFUN_INSET_WRAP:
1251 case LFUN_TABULAR_INSERT:
1252 case LFUN_ENVIRONMENT_INSERT:
1253 // Open the inset, and move the current selection
1255 doInsertInset(cur, this, cmd, true, true);
1258 case LFUN_INDEX_INSERT:
1259 // Just open the inset
1260 doInsertInset(cur, this, cmd, true, false);
1263 case LFUN_INDEX_PRINT:
1264 case LFUN_TOC_INSERT:
1266 case LFUN_INSERT_LINE:
1267 case LFUN_INSERT_PAGEBREAK:
1269 doInsertInset(cur, this, cmd, false, false);
1272 case LFUN_DEPTH_MIN:
1273 changeDepth(cur, bv_funcs::DEC_DEPTH);
1277 case LFUN_DEPTH_PLUS:
1278 changeDepth(cur, bv_funcs::INC_DEPTH);
1282 case LFUN_MATH_DISPLAY:
1283 mathDispatch(cur, this, cmd, true);
1286 case LFUN_MATH_IMPORT_SELECTION:
1287 case LFUN_MATH_MODE:
1288 mathDispatch(cur, this, cmd, false);
1291 case LFUN_MATH_MACRO:
1292 if (cmd.argument.empty())
1293 cur.errorMessage(N_("Missing argument"));
1295 string s = cmd.argument;
1296 string const s1 = token(s, ' ', 1);
1297 int const nargs = s1.empty() ? 0 : atoi(s1);
1298 string const s2 = token(s, ' ', 2);
1299 string const type = s2.empty() ? "newcommand" : s2;
1300 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1301 cur.nextInset()->edit(cur, true);
1305 case LFUN_INSERT_MATH:
1306 case LFUN_INSERT_MATRIX:
1307 case LFUN_MATH_DELIM: {
1308 cur.insert(new MathHullInset);
1309 cur.dispatch(FuncRequest(LFUN_RIGHT));
1310 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1316 LyXFont font(LyXFont::ALL_IGNORE);
1317 font.setEmph(LyXFont::TOGGLE);
1318 toggleAndShow(cur, this, font);
1323 LyXFont font(LyXFont::ALL_IGNORE);
1324 font.setSeries(LyXFont::BOLD_SERIES);
1325 toggleAndShow(cur, this, font);
1330 LyXFont font(LyXFont::ALL_IGNORE);
1331 font.setNoun(LyXFont::TOGGLE);
1332 toggleAndShow(cur, this, font);
1337 LyXFont font(LyXFont::ALL_IGNORE);
1338 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1339 toggleAndShow(cur, this, font);
1344 LyXFont font(LyXFont::ALL_IGNORE);
1345 font.setFamily(LyXFont::SANS_FAMILY);
1346 toggleAndShow(cur, this, font);
1351 LyXFont font(LyXFont::ALL_IGNORE);
1352 font.setFamily(LyXFont::ROMAN_FAMILY);
1353 toggleAndShow(cur, this, font);
1357 case LFUN_DEFAULT: {
1358 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1359 toggleAndShow(cur, this, font);
1363 case LFUN_UNDERLINE: {
1364 LyXFont font(LyXFont::ALL_IGNORE);
1365 font.setUnderbar(LyXFont::TOGGLE);
1366 toggleAndShow(cur, this, font);
1370 case LFUN_FONT_SIZE: {
1371 LyXFont font(LyXFont::ALL_IGNORE);
1372 font.setLyXSize(cmd.argument);
1373 toggleAndShow(cur, this, font);
1377 case LFUN_LANGUAGE: {
1378 Language const * lang = languages.getLanguage(cmd.argument);
1381 LyXFont font(LyXFont::ALL_IGNORE);
1382 font.setLanguage(lang);
1383 toggleAndShow(cur, this, font);
1388 case LFUN_FREEFONT_APPLY:
1389 toggleAndShow(cur, this, freefont, toggleall);
1390 cur.message(_("Character set"));
1393 // Set the freefont using the contents of \param data dispatched from
1394 // the frontends and apply it at the current cursor location.
1395 case LFUN_FREEFONT_UPDATE: {
1398 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1401 toggleAndShow(cur, this, freefont, toggleall);
1402 cur.message(_("Character set"));
1407 case LFUN_FINISHED_LEFT:
1408 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1409 if (isRTL(cur.paragraph()))
1411 cur.bv().cursor() = cur;
1414 case LFUN_FINISHED_RIGHT:
1415 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1416 if (!isRTL(cur.paragraph()))
1418 cur.bv().cursor() = cur;
1421 case LFUN_FINISHED_UP:
1422 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1424 cur.bv().cursor() = cur;
1427 case LFUN_FINISHED_DOWN:
1428 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1430 cur.bv().cursor() = cur;
1433 case LFUN_LAYOUT_PARAGRAPH: {
1435 params2string(cur.paragraph(), data);
1436 data = "show\n" + data;
1437 bv->owner()->getDialogs().show("paragraph", data);
1441 case LFUN_PARAGRAPH_UPDATE: {
1442 if (!bv->owner()->getDialogs().visible("paragraph"))
1445 params2string(cur.paragraph(), data);
1447 // Will the paragraph accept changes from the dialog?
1448 InsetBase & inset = cur.inset();
1449 bool const accept = !inset.forceDefaultParagraphs(&inset);
1451 data = "update " + tostr(accept) + '\n' + data;
1452 bv->owner()->getDialogs().update("paragraph", data);
1457 case LFUN_CIRCUMFLEX:
1467 case LFUN_SPECIAL_CARON:
1470 case LFUN_HUNG_UMLAUT:
1473 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1474 if (!cmd.argument.empty())
1475 bv->owner()->getIntl().getTransManager()
1476 .TranslateAndInsert(cmd.argument[0], this);
1479 case LFUN_FLOAT_LIST: {
1480 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1481 if (tclass.floats().typeExist(cmd.argument)) {
1482 // not quite sure if we want this...
1484 cur.clearSelection();
1485 breakParagraph(cur);
1487 if (cur.lastpos() != 0) {
1489 breakParagraph(cur);
1492 setLayout(cur, tclass.defaultLayoutName());
1493 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1494 insertInset(cur, new InsetFloatList(cmd.argument));
1496 lyxerr << "Non-existent float type: "
1497 << cmd.argument << endl;
1502 case LFUN_ACCEPT_CHANGE: {
1508 case LFUN_REJECT_CHANGE: {
1514 case LFUN_THESAURUS_ENTRY: {
1515 string arg = cmd.argument;
1517 arg = cur.selectionAsString(false);
1519 if (arg.size() > 100 || arg.empty()) {
1520 // Get word or selection
1521 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1522 arg = cur.selectionAsString(false);
1525 bv->owner()->getDialogs().show("thesaurus", arg);
1529 case LFUN_PARAGRAPH_APPLY: {
1530 // Given data, an encoding of the ParagraphParameters
1531 // generated in the Paragraph dialog, this function sets
1532 // the current paragraph appropriately.
1533 istringstream is(cmd.argument);
1536 ParagraphParameters params;
1541 params.labelWidthString(),
1544 cur.message(_("Paragraph layout set"));
1548 case LFUN_INSET_DIALOG_SHOW: {
1549 InsetBase * inset = cur.nextInset();
1551 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1552 inset->dispatch(cur, fr);
1558 if (cur.selection())
1559 cur.selection() = false;
1561 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1571 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)