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); // activates inset
135 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
136 // don't do that also for LFUN_MATH_MODE unless you want end up with
137 // always changing to mathrm when opening an inlined inset
138 // -- I really hate "LyXfunc overloading"...
140 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
141 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
143 // create a macro if we see "\\newcommand" somewhere, and an ordinary
145 text->cutSelection(cur, true, true);
146 if (sel.find("\\newcommand") == string::npos &&
147 sel.find("\\def") == string::npos)
149 cur.insert(new MathHullInset);
150 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
151 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
153 cur.insert(new InsetFormulaMacro(sel));
156 cur.message(N_("Math editor mode"));
165 string const freefont2string()
168 if (font2string(freefont, toggleall, data))
176 //takes absolute x,y coordinates
177 InsetBase * LyXText::checkInsetHit(int x, int y)
179 ParagraphList::iterator pit;
180 ParagraphList::iterator end;
182 getParsInRange(paragraphs(),
184 bv()->top_y() - yo_ + bv()->workHeight(),
187 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
188 for ( ; pit != end; ++pit) {
189 InsetList::iterator iit = pit->insetlist.begin();
190 InsetList::iterator iend = pit->insetlist.end();
191 for ( ; iit != iend; ++iit) {
192 InsetBase * inset = iit->inset;
194 lyxerr << "examining inset " << inset
195 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
196 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
197 << " yo: " << inset->yo() - inset->ascent() << "..."
198 << inset->yo() + inset->descent() << endl;
200 if (inset->covers(x, y)) {
201 lyxerr << "Hit inset: " << inset << endl;
206 lyxerr << "No inset hit. " << endl;
211 bool LyXText::gotoNextInset(LCursor & cur,
212 vector<InsetOld_code> const & codes, string const & contents)
214 BOOST_ASSERT(this == cur.text());
215 ParagraphList::iterator end = paragraphs().end();
216 ParagraphList::iterator pit = getPar(cur.par());
217 pos_type pos = cur.pos();
221 if (pos + 1 < pit->size()) {
228 } while (pit != end &&
229 !(pit->isInset(pos) &&
230 (inset = pit->getInset(pos)) != 0 &&
231 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
233 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
239 setCursor(cur, parOffset(pit), pos, false);
244 void LyXText::gotoInset(LCursor & cur,
245 vector<InsetOld_code> const & codes, bool same_content)
247 cur.clearSelection();
251 && cur.pos() < cur.lastpos()
252 && cur.paragraph().isInset(cur.pos())) {
253 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
254 if (find(codes.begin(), codes.end(), inset->lyxCode())
256 contents = static_cast<InsetCommand const *>(inset)->getContents();
259 if (!gotoNextInset(cur, codes, contents)) {
260 if (cur.pos() || cur.par() != 0) {
261 CursorSlice tmp = cur.top();
264 if (!gotoNextInset(cur, codes, contents)) {
266 cur.message(_("No more insets"));
269 cur.message(_("No more insets"));
277 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
279 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
283 void LyXText::cursorPrevious(LCursor & cur)
285 pos_type cpos = cur.pos();
286 lyx::paroffset_type cpar = cur.par();
288 int x = cur.x_target();
289 int y = bv()->top_y();
290 setCursorFromCoordinates(cur, x, y);
292 if (cpar == cur.par() && cpos == cur.pos()) {
293 // we have a row which is taller than the workarea. The
294 // simplest solution is to move to the previous row instead.
298 bv()->updateScrollbar();
303 void LyXText::cursorNext(LCursor & cur)
305 pos_type cpos = cur.pos();
306 lyx::paroffset_type cpar = cur.par();
308 int x = cur.x_target();
309 int y = bv()->top_y() + bv()->workHeight();
310 setCursorFromCoordinates(cur, x, y);
312 if (cpar == cur.par() && cpos == cur.pos()) {
313 // we have a row which is taller than the workarea. The
314 // simplest solution is to move to the next row instead.
318 bv()->updateScrollbar();
325 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
327 text->replaceSelection(cur);
328 cur.insert(new InsetSpecialChar(kind));
333 void doInsertInset(LCursor & cur, LyXText * text,
334 FuncRequest const & cmd, bool edit, bool pastesel)
336 InsetBase * inset = createInset(&cur.bv(), cmd);
342 if (cur.selection()) {
343 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
346 text->insertInset(cur, inset);
348 inset->edit(cur, true);
349 if (gotsel && pastesel)
350 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
356 void LyXText::number(LCursor & cur)
358 LyXFont font(LyXFont::ALL_IGNORE);
359 font.setNumber(LyXFont::TOGGLE);
360 toggleAndShow(cur, this, font);
364 bool LyXText::isRTL(Paragraph const & par) const
366 return par.isRightToLeftPar(bv()->buffer()->params());
370 void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
372 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
373 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
375 BufferView * bv = &cur.bv();
376 CursorSlice sl = cur.top();
378 switch (cmd.action) {
380 case LFUN_APPENDIX: {
381 Paragraph & par = cur.paragraph();
382 bool start = !par.params().startOfAppendix();
384 // ensure that we have only one start_of_appendix in this document
385 ParagraphList::iterator tmp = paragraphs().begin();
386 ParagraphList::iterator end = paragraphs().end();
388 for (; tmp != end; ++tmp) {
389 if (tmp->params().startOfAppendix()) {
390 recUndo(parOffset(tmp));
391 tmp->params().startOfAppendix(false);
398 par.params().startOfAppendix(start);
400 // we can set the refreshing parameters now
407 case LFUN_DELETE_WORD_FORWARD:
408 cur.clearSelection();
409 deleteWordForward(cur);
410 finishChange(cur, false);
413 case LFUN_DELETE_WORD_BACKWARD:
414 cur.clearSelection();
415 deleteWordBackward(cur);
416 finishChange(cur, false);
419 case LFUN_DELETE_LINE_FORWARD:
420 cur.clearSelection();
421 deleteLineForward(cur);
422 finishChange(cur, false);
427 cur.clearSelection();
428 if (isRTL(cur.paragraph()))
429 cursorLeftOneWord(cur);
431 cursorRightOneWord(cur);
432 finishChange(cur, false);
437 cur.clearSelection();
438 if (isRTL(cur.paragraph()))
439 cursorRightOneWord(cur);
441 cursorLeftOneWord(cur);
442 finishChange(cur, false);
445 case LFUN_BEGINNINGBUF:
447 cur.clearSelection();
449 finishChange(cur, false);
454 cur.clearSelection();
456 finishChange(cur, false);
461 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
462 if (isRTL(cur.paragraph()))
467 cur.dispatched(FINISHED_RIGHT);
472 cur.selHandle(cmd.action == LFUN_LEFTSEL);
473 if (isRTL(cur.paragraph()))
478 cur.dispatched(FINISHED_LEFT);
483 cur.selHandle(cmd.action == LFUN_UPSEL);
486 cur.dispatched(FINISHED_UP);
491 cur.selHandle(cmd.action == LFUN_DOWNSEL);
494 cur.dispatched(FINISHED_DOWN);
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);
565 case LFUN_UP_PARAGRAPH:
567 cur.clearSelection();
568 cursorUpParagraph(cur);
569 finishChange(cur, false);
572 case LFUN_DOWN_PARAGRAPH:
574 cur.clearSelection();
575 cursorDownParagraph(cur);
576 finishChange(cur, false);
581 cur.clearSelection();
582 finishChange(cur, false);
583 if (cur.par() == 0 && cur.textRow().pos() == 0)
584 cur.dispatched(FINISHED_UP);
591 cur.clearSelection();
592 finishChange(cur, false);
593 if (cur.par() == cur.lastpar()
594 && cur.textRow().endpos() == cur.lastpos())
595 cur.dispatched(FINISHED_DOWN);
602 cur.clearSelection();
604 finishChange(cur, false);
609 cur.clearSelection();
611 finishChange(cur, false);
614 case LFUN_BREAKLINE: {
615 // Not allowed by LaTeX (labels or empty par)
616 if (cur.pos() > cur.paragraph().beginOfBody()) {
617 replaceSelection(cur);
618 cur.insert(new InsetNewline);
619 moveCursor(cur, false);
625 if (!cur.selection()) {
628 // It is possible to make it a lot faster still
629 // just comment out the line below...
631 cutSelection(cur, true, false);
633 moveCursor(cur, false);
636 case LFUN_DELETE_SKIP:
637 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
638 if (!cur.selection()) {
639 if (cur.pos() == cur.lastpos()) {
646 cutSelection(cur, true, false);
653 if (!cur.selection()) {
654 if (bv->owner()->getIntl().getTransManager().backspace()) {
657 // It is possible to make it a lot faster still
658 // just comment out the line below...
661 cutSelection(cur, true, false);
667 case LFUN_BACKSPACE_SKIP:
668 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
669 if (!cur.selection()) {
671 //CursorSlice cur = cursor();
675 cutSelection(cur, true, false);
680 case LFUN_BREAKPARAGRAPH:
681 replaceSelection(cur);
682 breakParagraph(cur, 0);
688 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
689 replaceSelection(cur);
690 breakParagraph(cur, 1);
696 case LFUN_BREAKPARAGRAPH_SKIP: {
697 // When at the beginning of a paragraph, remove
698 // indentation and add a "defskip" at the top.
699 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
700 replaceSelection(cur);
701 if (cur.pos() == 0) {
702 ParagraphParameters & params = cur.paragraph().params();
706 params.labelWidthString(), 1);
708 breakParagraph(cur, 0);
716 case LFUN_PARAGRAPH_SPACING: {
717 Paragraph & par = cur.paragraph();
718 Spacing::Space cur_spacing = par.params().spacing().getSpace();
719 float cur_value = 1.0;
720 if (cur_spacing == Spacing::Other)
721 cur_value = par.params().spacing().getValue();
723 istringstream is(cmd.argument);
726 Spacing::Space new_spacing = cur_spacing;
727 float new_value = cur_value;
729 lyxerr << "Missing argument to `paragraph-spacing'"
731 } else if (tmp == "single") {
732 new_spacing = Spacing::Single;
733 } else if (tmp == "onehalf") {
734 new_spacing = Spacing::Onehalf;
735 } else if (tmp == "double") {
736 new_spacing = Spacing::Double;
737 } else if (tmp == "other") {
738 new_spacing = Spacing::Other;
741 lyxerr << "new_value = " << tmpval << endl;
744 } else if (tmp == "default") {
745 new_spacing = Spacing::Default;
747 lyxerr << _("Unknown spacing argument: ")
748 << cmd.argument << endl;
750 if (cur_spacing != new_spacing || cur_value != new_value) {
751 par.params().spacing(Spacing(new_spacing, new_value));
758 case LFUN_INSET_APPLY: {
759 string const name = cmd.getArg(0);
760 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
762 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
764 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
768 case LFUN_INSET_INSERT: {
770 InsetBase * inset = createInset(bv, cmd);
772 insertInset(cur, inset);
776 case LFUN_INSET_SETTINGS:
777 if (cur.inset() && cur.inset()->asUpdatableInset())
778 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
781 case LFUN_INSET_TOGGLE:
782 cur.clearSelection();
783 if (!toggleInset(cur))
789 case LFUN_SPACE_INSERT:
790 if (cur.paragraph().layout()->free_spacing)
791 insertChar(cur, ' ');
793 doInsertInset(cur, this, cmd, false, false);
794 moveCursor(cur, false);
797 case LFUN_HYPHENATION:
798 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
801 case LFUN_LIGATURE_BREAK:
802 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
806 specialChar(cur, this, InsetSpecialChar::LDOTS);
809 case LFUN_END_OF_SENTENCE:
810 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
813 case LFUN_MENU_SEPARATOR:
814 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
817 case LFUN_UPCASE_WORD:
818 changeCase(cur, LyXText::text_uppercase);
822 case LFUN_LOWCASE_WORD:
823 changeCase(cur, LyXText::text_lowercase);
827 case LFUN_CAPITALIZE_WORD:
828 changeCase(cur, LyXText::text_capitalization);
832 case LFUN_TRANSPOSE_CHARS:
839 cur.message(_("Paste"));
840 replaceSelection(cur);
841 #warning FIXME Check if the arg is in the domain of available selections.
842 if (isStrUnsignedInt(cmd.argument))
843 pasteSelection(cur, strToUnsignedInt(cmd.argument));
845 pasteSelection(cur, 0);
846 cur.clearSelection(); // bug 393
853 cutSelection(cur, true, true);
854 cur.message(_("Cut"));
860 cur.message(_("Copy"));
863 case LFUN_BEGINNINGBUFSEL:
867 if (!cur.selection())
870 finishChange(cur, true);
878 if (!cur.selection())
881 finishChange(cur, true);
886 cur.message(tostr(cursorX(cur.top())) + ' '
887 + tostr(cursorY(cur.top())));
893 istringstream is(cmd.argument);
896 lyxerr << "SETXY: Could not parse coordinates in '"
897 << cmd.argument << std::endl;
899 setCursorFromCoordinates(cur, x, y);
904 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
906 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
913 cur.message(cur.paragraph().layout()->name());
917 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
918 << cmd.argument << endl;
920 // This is not the good solution to the empty argument
921 // problem, but it will hopefully suffice for 1.2.0.
922 // The correct solution would be to augument the
923 // function list/array with information about what
924 // functions needs arguments and their type.
925 if (cmd.argument.empty()) {
926 cur.errorMessage(_("LyX function 'layout' needs an argument."));
930 // Derive layout number from given argument (string)
931 // and current buffer's textclass (number)
932 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
933 bool hasLayout = tclass.hasLayout(cmd.argument);
934 string layout = cmd.argument;
936 // If the entry is obsolete, use the new one instead.
938 string const & obs = tclass[layout]->obsoleted_by();
944 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
949 bool change_layout = (current_layout != layout);
951 if (!change_layout && cur.selection() &&
952 cur.selBegin().par() != cur.selEnd().par())
954 ParagraphList::iterator spit = getPar(cur.selBegin());
955 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
956 while (spit != epit) {
957 if (spit->layout()->name() != current_layout) {
958 change_layout = true;
966 current_layout = layout;
967 setLayout(cur, layout);
968 bv->owner()->setLayout(layout);
975 case LFUN_PASTESELECTION: {
976 cur.clearSelection();
977 string const clip = bv->getClipboard();
979 if (cmd.argument == "paragraph")
980 insertStringAsParagraphs(cur, clip);
982 insertStringAsLines(cur, clip);
989 gotoInset(cur, InsetBase::ERROR_CODE, false);
993 gotoInset(cur, InsetBase::NOTE_CODE, false);
996 case LFUN_REFERENCE_GOTO: {
997 vector<InsetOld_code> tmp;
998 tmp.push_back(InsetBase::LABEL_CODE);
999 tmp.push_back(InsetBase::REF_CODE);
1000 gotoInset(cur, tmp, true);
1005 replaceSelection(cur);
1006 Paragraph & par = cur.paragraph();
1007 lyx::pos_type pos = cur.pos();
1011 else if (cur.prevInset() && cur.prevInset()->isSpace())
1014 c = par.getChar(pos - 1);
1016 LyXLayout_ptr const & style = par.layout();
1018 BufferParams const & bufparams = bv->buffer()->params();
1019 if (!style->pass_thru
1020 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1021 string arg = cmd.argument;
1022 if (arg == "single")
1023 cur.insert(new InsetQuotes(c,
1024 bufparams.quotes_language,
1025 InsetQuotes::SingleQ));
1026 else if (arg == "double")
1027 cur.insert(new InsetQuotes(c,
1028 bufparams.quotes_language,
1029 InsetQuotes::DoubleQ));
1031 cur.insert(new InsetQuotes(c, bufparams));
1034 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1038 case LFUN_DATE_INSERT: {
1039 replaceSelection(cur);
1040 time_t now_time_t = time(NULL);
1041 struct tm * now_tm = localtime(&now_time_t);
1042 setlocale(LC_TIME, "");
1044 if (!cmd.argument.empty())
1047 arg = lyxrc.date_insert_format;
1049 int const datetmp_len =
1050 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1052 for (int i = 0; i < datetmp_len; i++)
1053 insertChar(cur, datetmp[i]);
1056 moveCursor(cur, false);
1060 case LFUN_MOUSE_TRIPLE:
1061 if (cmd.button() == mouse_button::button1) {
1062 selection_possible = true;
1067 bv->haveSelection(cur.selection());
1071 case LFUN_MOUSE_DOUBLE:
1072 if (cmd.button() == mouse_button::button1) {
1073 selection_possible = true;
1074 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1075 bv->haveSelection(cur.selection());
1079 case LFUN_MOUSE_MOTION: {
1080 // Only use motion with button 1
1081 //if (cmd.button() != mouse_button::button1)
1083 // The test for not selection possible is needed, that
1084 // only motion events are used, where the bottom press
1085 // event was on the drawing area too
1086 if (!selection_possible) {
1087 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1088 "Dispatch: no selection possible\n";
1091 CursorSlice old = cur.top();
1092 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1094 // This is to allow jumping over large insets
1095 // FIXME: shouldn't be top-text-specific
1096 if (!in_inset_ && cur.top() == old) {
1097 if (cmd.y - bv->top_y() >= bv->workHeight())
1099 else if (cmd.y - bv->top_y() < 0)
1103 // don't set anchor_
1104 bv->cursor().setCursor(cur, false);
1108 // Single-click on work area
1109 case LFUN_MOUSE_PRESS: {
1110 // ok ok, this is a hack (for xforms)
1111 // We shouldn't go further down as we really should only do the
1112 // scrolling and be done with this. Otherwise we may open some
1113 // dialogs (Jug 20020424).
1114 if (cmd.button() == mouse_button::button4) {
1115 bv->scroll(-lyxrc.wheel_jump);
1119 if (cmd.button() == mouse_button::button5) {
1120 bv->scroll(lyxrc.wheel_jump);
1124 // Right click on a footnote flag opens float menu
1125 if (cmd.button() == mouse_button::button3) {
1126 cur.clearSelection();
1127 selection_possible = false;
1131 // Middle button press pastes if we have a selection
1132 // We do this here as if the selection was inside an inset
1133 // it could get cleared on the unlocking of the inset so
1134 // we have to check this first
1135 bool paste_internally = false;
1136 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1137 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1138 paste_internally = true;
1141 selection_possible = true;
1143 // Clear the selection
1144 cur.clearSelection();
1146 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1149 cur.x_target() = cursorX(cur.top());
1151 // set cursor and anchor to this position
1154 if (bv->fitCursor())
1155 selection_possible = false;
1157 // Insert primary selection with middle mouse
1158 // if there is a local selection in the current buffer,
1160 if (cmd.button() == mouse_button::button2) {
1161 if (paste_internally)
1162 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1164 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1165 selection_possible = false;
1170 case LFUN_MOUSE_RELEASE: {
1171 // do nothing if we used the mouse wheel
1172 if (cmd.button() == mouse_button::button4
1173 || cmd.button() == mouse_button::button5) {
1178 selection_possible = false;
1180 if (cmd.button() == mouse_button::button2)
1184 if (cmd.button() == mouse_button::button1)
1185 bv->haveSelection(cur.selection());
1188 bv->owner()->updateMenubar();
1189 bv->owner()->updateToolbar();
1193 case LFUN_SELFINSERT: {
1194 if (cmd.argument.empty())
1197 // Automatically delete the currently selected
1198 // text and replace it with what is being
1199 // typed in now. Depends on lyxrc settings
1200 // "auto_region_delete", which defaults to
1203 if (lyxrc.auto_region_delete) {
1204 if (cur.selection())
1205 cutSelection(cur, false, false);
1206 bv->haveSelection(false);
1209 cur.clearSelection();
1210 LyXFont const old_font = real_current_font;
1212 string::const_iterator cit = cmd.argument.begin();
1213 string::const_iterator end = cmd.argument.end();
1214 for (; cit != end; ++cit)
1215 bv->owner()->getIntl().getTransManager().
1216 TranslateAndInsert(*cit, this);
1219 moveCursor(cur, false);
1221 // real_current_font.number can change so we need to
1222 // update the minibuffer
1223 if (old_font != real_current_font)
1224 bv->updateScrollbar();
1229 InsetCommandParams p("url");
1230 string const data = InsetCommandMailer::params2string("url", p);
1231 bv->owner()->getDialogs().show("url", data, 0);
1235 case LFUN_HTMLURL: {
1236 InsetCommandParams p("htmlurl");
1237 string const data = InsetCommandMailer::params2string("url", p);
1238 bv->owner()->getDialogs().show("url", data, 0);
1242 case LFUN_INSERT_LABEL: {
1243 InsetCommandParams p("label");
1244 string const data = InsetCommandMailer::params2string("label", p);
1245 bv->owner()->getDialogs().show("label", data, 0);
1251 case LFUN_INSET_LIST:
1252 case LFUN_INSET_THEOREM:
1253 case LFUN_INSET_CAPTION:
1255 case LFUN_INSERT_NOTE:
1256 case LFUN_INSERT_CHARSTYLE:
1257 case LFUN_INSERT_BOX:
1258 case LFUN_INSERT_BRANCH:
1259 case LFUN_INSERT_BIBITEM:
1260 case LFUN_INSET_ERT:
1261 case LFUN_INSET_FLOAT:
1262 case LFUN_INSET_FOOTNOTE:
1263 case LFUN_INSET_MARGINAL:
1264 case LFUN_INSET_OPTARG:
1265 case LFUN_INSET_WIDE_FLOAT:
1266 case LFUN_INSET_WRAP:
1267 case LFUN_TABULAR_INSERT:
1268 case LFUN_ENVIRONMENT_INSERT:
1269 // Open the inset, and move the current selection
1271 doInsertInset(cur, this, cmd, true, true);
1274 case LFUN_INDEX_INSERT:
1275 // Just open the inset
1276 doInsertInset(cur, this, cmd, true, false);
1279 case LFUN_INDEX_PRINT:
1280 case LFUN_TOC_INSERT:
1282 case LFUN_INSERT_LINE:
1283 case LFUN_INSERT_PAGEBREAK:
1285 doInsertInset(cur, this, cmd, false, false);
1288 case LFUN_DEPTH_MIN:
1289 changeDepth(cur, bv_funcs::DEC_DEPTH);
1293 case LFUN_DEPTH_PLUS:
1294 changeDepth(cur, bv_funcs::INC_DEPTH);
1298 case LFUN_MATH_DISPLAY:
1299 mathDispatch(cur, this, cmd, true);
1302 case LFUN_MATH_IMPORT_SELECTION:
1303 case LFUN_MATH_MODE:
1304 mathDispatch(cur, this, cmd, false);
1307 case LFUN_MATH_MACRO:
1308 if (cmd.argument.empty())
1309 cur.errorMessage(N_("Missing argument"));
1311 string s = cmd.argument;
1312 string const s1 = token(s, ' ', 1);
1313 int const nargs = s1.empty() ? 0 : atoi(s1);
1314 string const s2 = token(s, ' ', 2);
1315 string const type = s2.empty() ? "newcommand" : s2;
1316 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1317 cur.nextInset()->edit(cur, true);
1321 case LFUN_INSERT_MATH:
1322 case LFUN_INSERT_MATRIX:
1323 case LFUN_MATH_DELIM: {
1324 cur.insert(new MathHullInset);
1325 cur.dispatch(FuncRequest(LFUN_RIGHT));
1326 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1332 LyXFont font(LyXFont::ALL_IGNORE);
1333 font.setEmph(LyXFont::TOGGLE);
1334 toggleAndShow(cur, this, font);
1339 LyXFont font(LyXFont::ALL_IGNORE);
1340 font.setSeries(LyXFont::BOLD_SERIES);
1341 toggleAndShow(cur, this, font);
1346 LyXFont font(LyXFont::ALL_IGNORE);
1347 font.setNoun(LyXFont::TOGGLE);
1348 toggleAndShow(cur, this, font);
1353 LyXFont font(LyXFont::ALL_IGNORE);
1354 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1355 toggleAndShow(cur, this, font);
1360 LyXFont font(LyXFont::ALL_IGNORE);
1361 font.setFamily(LyXFont::SANS_FAMILY);
1362 toggleAndShow(cur, this, font);
1367 LyXFont font(LyXFont::ALL_IGNORE);
1368 font.setFamily(LyXFont::ROMAN_FAMILY);
1369 toggleAndShow(cur, this, font);
1373 case LFUN_DEFAULT: {
1374 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_UNDERLINE: {
1380 LyXFont font(LyXFont::ALL_IGNORE);
1381 font.setUnderbar(LyXFont::TOGGLE);
1382 toggleAndShow(cur, this, font);
1386 case LFUN_FONT_SIZE: {
1387 LyXFont font(LyXFont::ALL_IGNORE);
1388 font.setLyXSize(cmd.argument);
1389 toggleAndShow(cur, this, font);
1393 case LFUN_LANGUAGE: {
1394 Language const * lang = languages.getLanguage(cmd.argument);
1397 LyXFont font(LyXFont::ALL_IGNORE);
1398 font.setLanguage(lang);
1399 toggleAndShow(cur, this, font);
1404 case LFUN_FREEFONT_APPLY:
1405 toggleAndShow(cur, this, freefont, toggleall);
1406 cur.message(_("Character set"));
1409 // Set the freefont using the contents of \param data dispatched from
1410 // the frontends and apply it at the current cursor location.
1411 case LFUN_FREEFONT_UPDATE: {
1414 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1417 toggleAndShow(cur, this, freefont, toggleall);
1418 cur.message(_("Character set"));
1423 case LFUN_FINISHED_LEFT:
1424 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1425 if (isRTL(cur.paragraph()))
1427 cur.bv().cursor() = cur;
1430 case LFUN_FINISHED_RIGHT:
1431 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1432 if (!isRTL(cur.paragraph()))
1434 cur.bv().cursor() = cur;
1437 case LFUN_FINISHED_UP:
1438 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1440 cur.bv().cursor() = cur;
1443 case LFUN_FINISHED_DOWN:
1444 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1446 cur.bv().cursor() = cur;
1449 case LFUN_LAYOUT_PARAGRAPH: {
1451 params2string(cur.paragraph(), data);
1452 data = "show\n" + data;
1453 bv->owner()->getDialogs().show("paragraph", data);
1457 case LFUN_PARAGRAPH_UPDATE: {
1458 if (!bv->owner()->getDialogs().visible("paragraph"))
1461 params2string(cur.paragraph(), data);
1463 // Will the paragraph accept changes from the dialog?
1464 InsetBase * const inset = cur.inset();
1466 !(inset && inset->forceDefaultParagraphs(inset));
1468 data = "update " + tostr(accept) + '\n' + data;
1469 bv->owner()->getDialogs().update("paragraph", data);
1474 case LFUN_CIRCUMFLEX:
1484 case LFUN_SPECIAL_CARON:
1487 case LFUN_HUNG_UMLAUT:
1490 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1491 if (!cmd.argument.empty())
1492 bv->owner()->getIntl().getTransManager()
1493 .TranslateAndInsert(cmd.argument[0], this);
1496 case LFUN_FLOAT_LIST: {
1497 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1498 if (tclass.floats().typeExist(cmd.argument)) {
1499 // not quite sure if we want this...
1501 cur.clearSelection();
1502 breakParagraph(cur);
1504 if (cur.lastpos() != 0) {
1506 breakParagraph(cur);
1509 setLayout(cur, tclass.defaultLayoutName());
1510 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1511 insertInset(cur, new InsetFloatList(cmd.argument));
1513 lyxerr << "Non-existent float type: "
1514 << cmd.argument << endl;
1519 case LFUN_ACCEPT_CHANGE: {
1525 case LFUN_REJECT_CHANGE: {
1531 case LFUN_THESAURUS_ENTRY: {
1532 string arg = cmd.argument;
1534 arg = cur.selectionAsString(false);
1536 if (arg.size() > 100 || arg.empty()) {
1537 // Get word or selection
1538 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1539 arg = cur.selectionAsString(false);
1542 bv->owner()->getDialogs().show("thesaurus", arg);
1546 case LFUN_PARAGRAPH_APPLY: {
1547 // Given data, an encoding of the ParagraphParameters
1548 // generated in the Paragraph dialog, this function sets
1549 // the current paragraph appropriately.
1550 istringstream is(cmd.argument);
1553 ParagraphParameters params;
1558 params.labelWidthString(),
1561 cur.message(_("Paragraph layout set"));
1566 if (cur.selection())
1567 cur.selection() = false;
1569 cur.dispatched(FINISHED_LEFT);
1579 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)