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 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);
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 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);
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 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);
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 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
767 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
771 case LFUN_INSET_INSERT: {
773 InsetBase * inset = createInset(bv, cmd);
775 insertInset(cur, inset);
779 case LFUN_INSET_SETTINGS:
780 if (cur.inset().asUpdatableInset())
781 cur.inset().asUpdatableInset()->showInsetDialog(bv);
784 case LFUN_INSET_TOGGLE:
785 cur.clearSelection();
786 if (!toggleInset(cur))
792 case LFUN_SPACE_INSERT:
793 if (cur.paragraph().layout()->free_spacing)
794 insertChar(cur, ' ');
796 doInsertInset(cur, this, cmd, false, false);
797 moveCursor(cur, false);
800 case LFUN_HYPHENATION:
801 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
804 case LFUN_LIGATURE_BREAK:
805 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
809 specialChar(cur, this, InsetSpecialChar::LDOTS);
812 case LFUN_END_OF_SENTENCE:
813 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
816 case LFUN_MENU_SEPARATOR:
817 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
820 case LFUN_UPCASE_WORD:
821 changeCase(cur, LyXText::text_uppercase);
825 case LFUN_LOWCASE_WORD:
826 changeCase(cur, LyXText::text_lowercase);
830 case LFUN_CAPITALIZE_WORD:
831 changeCase(cur, LyXText::text_capitalization);
835 case LFUN_TRANSPOSE_CHARS:
842 cur.message(_("Paste"));
843 replaceSelection(cur);
844 #warning FIXME Check if the arg is in the domain of available selections.
845 if (isStrUnsignedInt(cmd.argument))
846 pasteSelection(cur, strToUnsignedInt(cmd.argument));
848 pasteSelection(cur, 0);
849 cur.clearSelection(); // bug 393
856 cutSelection(cur, true, true);
857 cur.message(_("Cut"));
863 cur.message(_("Copy"));
867 cur.message(tostr(cursorX(cur.top())) + ' '
868 + tostr(cursorY(cur.top())));
874 istringstream is(cmd.argument);
877 lyxerr << "SETXY: Could not parse coordinates in '"
878 << cmd.argument << std::endl;
880 setCursorFromCoordinates(cur, x, y);
885 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
887 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
894 cur.message(cur.paragraph().layout()->name());
898 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
899 << cmd.argument << endl;
901 // This is not the good solution to the empty argument
902 // problem, but it will hopefully suffice for 1.2.0.
903 // The correct solution would be to augument the
904 // function list/array with information about what
905 // functions needs arguments and their type.
906 if (cmd.argument.empty()) {
907 cur.errorMessage(_("LyX function 'layout' needs an argument."));
911 // Derive layout number from given argument (string)
912 // and current buffer's textclass (number)
913 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
914 bool hasLayout = tclass.hasLayout(cmd.argument);
915 string layout = cmd.argument;
917 // If the entry is obsolete, use the new one instead.
919 string const & obs = tclass[layout]->obsoleted_by();
925 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
930 bool change_layout = (current_layout != layout);
932 if (!change_layout && cur.selection() &&
933 cur.selBegin().par() != cur.selEnd().par())
935 ParagraphList::iterator spit = getPar(cur.selBegin());
936 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
937 while (spit != epit) {
938 if (spit->layout()->name() != current_layout) {
939 change_layout = true;
947 current_layout = layout;
948 setLayout(cur, layout);
949 bv->owner()->setLayout(layout);
956 case LFUN_PASTESELECTION: {
957 cur.clearSelection();
958 string const clip = bv->getClipboard();
960 if (cmd.argument == "paragraph")
961 insertStringAsParagraphs(cur, clip);
963 insertStringAsLines(cur, clip);
970 gotoInset(cur, InsetBase::ERROR_CODE, false);
974 gotoInset(cur, InsetBase::NOTE_CODE, false);
977 case LFUN_REFERENCE_GOTO: {
978 vector<InsetOld_code> tmp;
979 tmp.push_back(InsetBase::LABEL_CODE);
980 tmp.push_back(InsetBase::REF_CODE);
981 gotoInset(cur, tmp, true);
986 replaceSelection(cur);
987 Paragraph & par = cur.paragraph();
988 lyx::pos_type pos = cur.pos();
992 else if (cur.prevInset() && cur.prevInset()->isSpace())
995 c = par.getChar(pos - 1);
997 LyXLayout_ptr const & style = par.layout();
999 BufferParams const & bufparams = bv->buffer()->params();
1000 if (!style->pass_thru
1001 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1002 string arg = cmd.argument;
1003 if (arg == "single")
1004 cur.insert(new InsetQuotes(c,
1005 bufparams.quotes_language,
1006 InsetQuotes::SingleQ));
1007 else if (arg == "double")
1008 cur.insert(new InsetQuotes(c,
1009 bufparams.quotes_language,
1010 InsetQuotes::DoubleQ));
1012 cur.insert(new InsetQuotes(c, bufparams));
1015 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1019 case LFUN_DATE_INSERT: {
1020 replaceSelection(cur);
1021 time_t now_time_t = time(NULL);
1022 struct tm * now_tm = localtime(&now_time_t);
1023 setlocale(LC_TIME, "");
1025 if (!cmd.argument.empty())
1028 arg = lyxrc.date_insert_format;
1030 int const datetmp_len =
1031 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1033 for (int i = 0; i < datetmp_len; i++)
1034 insertChar(cur, datetmp[i]);
1037 moveCursor(cur, false);
1041 case LFUN_MOUSE_TRIPLE:
1042 if (cmd.button() == mouse_button::button1) {
1043 selection_possible = true;
1048 bv->haveSelection(cur.selection());
1052 case LFUN_MOUSE_DOUBLE:
1053 if (cmd.button() == mouse_button::button1) {
1054 selection_possible = true;
1055 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1056 bv->haveSelection(cur.selection());
1060 case LFUN_MOUSE_MOTION: {
1061 // Only use motion with button 1
1062 //if (cmd.button() != mouse_button::button1)
1064 // The test for not selection possible is needed, that
1065 // only motion events are used, where the bottom press
1066 // event was on the drawing area too
1067 if (!selection_possible) {
1068 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1069 "Dispatch: no selection possible\n";
1072 CursorSlice old = cur.top();
1073 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1075 // This is to allow jumping over large insets
1076 // FIXME: shouldn't be top-text-specific
1077 if (isMainText() && cur.top() == old) {
1078 if (cmd.y - bv->top_y() >= bv->workHeight())
1080 else if (cmd.y - bv->top_y() < 0)
1084 // don't set anchor_
1085 bv->cursor().setCursor(cur, false);
1089 // Single-click on work area
1090 case LFUN_MOUSE_PRESS: {
1091 // ok ok, this is a hack (for xforms)
1092 // We shouldn't go further down as we really should only do the
1093 // scrolling and be done with this. Otherwise we may open some
1094 // dialogs (Jug 20020424).
1095 if (cmd.button() == mouse_button::button4) {
1096 bv->scroll(-lyxrc.wheel_jump);
1100 if (cmd.button() == mouse_button::button5) {
1101 bv->scroll(lyxrc.wheel_jump);
1105 // Right click on a footnote flag opens float menu
1106 if (cmd.button() == mouse_button::button3) {
1107 cur.clearSelection();
1108 selection_possible = false;
1112 // Middle button press pastes if we have a selection
1113 // We do this here as if the selection was inside an inset
1114 // it could get cleared on the unlocking of the inset so
1115 // we have to check this first
1116 bool paste_internally = false;
1117 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1118 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1119 paste_internally = true;
1122 selection_possible = true;
1124 // Clear the selection
1125 cur.clearSelection();
1127 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1130 cur.x_target() = cursorX(cur.top());
1132 // set cursor and anchor to this position
1135 if (bv->fitCursor())
1136 selection_possible = false;
1138 // Insert primary selection with middle mouse
1139 // if there is a local selection in the current buffer,
1141 if (cmd.button() == mouse_button::button2) {
1142 if (paste_internally)
1143 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1145 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1146 selection_possible = false;
1151 case LFUN_MOUSE_RELEASE: {
1152 // do nothing if we used the mouse wheel
1153 if (cmd.button() == mouse_button::button4
1154 || cmd.button() == mouse_button::button5) {
1159 selection_possible = false;
1161 if (cmd.button() == mouse_button::button2)
1165 if (cmd.button() == mouse_button::button1)
1166 bv->haveSelection(cur.selection());
1169 bv->owner()->updateMenubar();
1170 bv->owner()->updateToolbar();
1174 case LFUN_SELFINSERT: {
1175 if (cmd.argument.empty())
1178 // Automatically delete the currently selected
1179 // text and replace it with what is being
1180 // typed in now. Depends on lyxrc settings
1181 // "auto_region_delete", which defaults to
1184 if (lyxrc.auto_region_delete) {
1185 if (cur.selection())
1186 cutSelection(cur, false, false);
1187 bv->haveSelection(false);
1190 cur.clearSelection();
1191 LyXFont const old_font = real_current_font;
1193 string::const_iterator cit = cmd.argument.begin();
1194 string::const_iterator end = cmd.argument.end();
1195 for (; cit != end; ++cit)
1196 bv->owner()->getIntl().getTransManager().
1197 TranslateAndInsert(*cit, this);
1200 moveCursor(cur, false);
1202 // real_current_font.number can change so we need to
1203 // update the minibuffer
1204 if (old_font != real_current_font)
1205 bv->updateScrollbar();
1210 InsetCommandParams p("url");
1211 string const data = InsetCommandMailer::params2string("url", p);
1212 bv->owner()->getDialogs().show("url", data, 0);
1216 case LFUN_HTMLURL: {
1217 InsetCommandParams p("htmlurl");
1218 string const data = InsetCommandMailer::params2string("url", p);
1219 bv->owner()->getDialogs().show("url", data, 0);
1223 case LFUN_INSERT_LABEL: {
1224 InsetCommandParams p("label");
1225 string const data = InsetCommandMailer::params2string("label", p);
1226 bv->owner()->getDialogs().show("label", data, 0);
1232 case LFUN_INSET_LIST:
1233 case LFUN_INSET_THEOREM:
1234 case LFUN_INSET_CAPTION:
1236 case LFUN_INSERT_NOTE:
1237 case LFUN_INSERT_CHARSTYLE:
1238 case LFUN_INSERT_BOX:
1239 case LFUN_INSERT_BRANCH:
1240 case LFUN_INSERT_BIBITEM:
1241 case LFUN_INSET_ERT:
1242 case LFUN_INSET_FLOAT:
1243 case LFUN_INSET_FOOTNOTE:
1244 case LFUN_INSET_MARGINAL:
1245 case LFUN_INSET_OPTARG:
1246 case LFUN_INSET_WIDE_FLOAT:
1247 case LFUN_INSET_WRAP:
1248 case LFUN_TABULAR_INSERT:
1249 case LFUN_ENVIRONMENT_INSERT:
1250 // Open the inset, and move the current selection
1252 doInsertInset(cur, this, cmd, true, true);
1255 case LFUN_INDEX_INSERT:
1256 // Just open the inset
1257 doInsertInset(cur, this, cmd, true, false);
1260 case LFUN_INDEX_PRINT:
1261 case LFUN_TOC_INSERT:
1263 case LFUN_INSERT_LINE:
1264 case LFUN_INSERT_PAGEBREAK:
1266 doInsertInset(cur, this, cmd, false, false);
1269 case LFUN_DEPTH_MIN:
1270 changeDepth(cur, bv_funcs::DEC_DEPTH);
1274 case LFUN_DEPTH_PLUS:
1275 changeDepth(cur, bv_funcs::INC_DEPTH);
1279 case LFUN_MATH_DISPLAY:
1280 mathDispatch(cur, this, cmd, true);
1283 case LFUN_MATH_IMPORT_SELECTION:
1284 case LFUN_MATH_MODE:
1285 mathDispatch(cur, this, cmd, false);
1288 case LFUN_MATH_MACRO:
1289 if (cmd.argument.empty())
1290 cur.errorMessage(N_("Missing argument"));
1292 string s = cmd.argument;
1293 string const s1 = token(s, ' ', 1);
1294 int const nargs = s1.empty() ? 0 : atoi(s1);
1295 string const s2 = token(s, ' ', 2);
1296 string const type = s2.empty() ? "newcommand" : s2;
1297 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1298 cur.nextInset()->edit(cur, true);
1302 case LFUN_INSERT_MATH:
1303 case LFUN_INSERT_MATRIX:
1304 case LFUN_MATH_DELIM: {
1305 cur.insert(new MathHullInset);
1306 cur.dispatch(FuncRequest(LFUN_RIGHT));
1307 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1313 LyXFont font(LyXFont::ALL_IGNORE);
1314 font.setEmph(LyXFont::TOGGLE);
1315 toggleAndShow(cur, this, font);
1320 LyXFont font(LyXFont::ALL_IGNORE);
1321 font.setSeries(LyXFont::BOLD_SERIES);
1322 toggleAndShow(cur, this, font);
1327 LyXFont font(LyXFont::ALL_IGNORE);
1328 font.setNoun(LyXFont::TOGGLE);
1329 toggleAndShow(cur, this, font);
1334 LyXFont font(LyXFont::ALL_IGNORE);
1335 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1336 toggleAndShow(cur, this, font);
1341 LyXFont font(LyXFont::ALL_IGNORE);
1342 font.setFamily(LyXFont::SANS_FAMILY);
1343 toggleAndShow(cur, this, font);
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setFamily(LyXFont::ROMAN_FAMILY);
1350 toggleAndShow(cur, this, font);
1354 case LFUN_DEFAULT: {
1355 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1356 toggleAndShow(cur, this, font);
1360 case LFUN_UNDERLINE: {
1361 LyXFont font(LyXFont::ALL_IGNORE);
1362 font.setUnderbar(LyXFont::TOGGLE);
1363 toggleAndShow(cur, this, font);
1367 case LFUN_FONT_SIZE: {
1368 LyXFont font(LyXFont::ALL_IGNORE);
1369 font.setLyXSize(cmd.argument);
1370 toggleAndShow(cur, this, font);
1374 case LFUN_LANGUAGE: {
1375 Language const * lang = languages.getLanguage(cmd.argument);
1378 LyXFont font(LyXFont::ALL_IGNORE);
1379 font.setLanguage(lang);
1380 toggleAndShow(cur, this, font);
1385 case LFUN_FREEFONT_APPLY:
1386 toggleAndShow(cur, this, freefont, toggleall);
1387 cur.message(_("Character set"));
1390 // Set the freefont using the contents of \param data dispatched from
1391 // the frontends and apply it at the current cursor location.
1392 case LFUN_FREEFONT_UPDATE: {
1395 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1398 toggleAndShow(cur, this, freefont, toggleall);
1399 cur.message(_("Character set"));
1404 case LFUN_FINISHED_LEFT:
1405 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1406 if (isRTL(cur.paragraph()))
1408 cur.bv().cursor() = cur;
1411 case LFUN_FINISHED_RIGHT:
1412 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1413 if (!isRTL(cur.paragraph()))
1415 cur.bv().cursor() = cur;
1418 case LFUN_FINISHED_UP:
1419 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1421 cur.bv().cursor() = cur;
1424 case LFUN_FINISHED_DOWN:
1425 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1427 cur.bv().cursor() = cur;
1430 case LFUN_LAYOUT_PARAGRAPH: {
1432 params2string(cur.paragraph(), data);
1433 data = "show\n" + data;
1434 bv->owner()->getDialogs().show("paragraph", data);
1438 case LFUN_PARAGRAPH_UPDATE: {
1439 if (!bv->owner()->getDialogs().visible("paragraph"))
1442 params2string(cur.paragraph(), data);
1444 // Will the paragraph accept changes from the dialog?
1445 InsetBase & inset = cur.inset();
1446 bool const accept = !inset.forceDefaultParagraphs(&inset);
1448 data = "update " + tostr(accept) + '\n' + data;
1449 bv->owner()->getDialogs().update("paragraph", data);
1454 case LFUN_CIRCUMFLEX:
1464 case LFUN_SPECIAL_CARON:
1467 case LFUN_HUNG_UMLAUT:
1470 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1471 if (!cmd.argument.empty())
1472 bv->owner()->getIntl().getTransManager()
1473 .TranslateAndInsert(cmd.argument[0], this);
1476 case LFUN_FLOAT_LIST: {
1477 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1478 if (tclass.floats().typeExist(cmd.argument)) {
1479 // not quite sure if we want this...
1481 cur.clearSelection();
1482 breakParagraph(cur);
1484 if (cur.lastpos() != 0) {
1486 breakParagraph(cur);
1489 setLayout(cur, tclass.defaultLayoutName());
1490 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1491 insertInset(cur, new InsetFloatList(cmd.argument));
1493 lyxerr << "Non-existent float type: "
1494 << cmd.argument << endl;
1499 case LFUN_ACCEPT_CHANGE: {
1505 case LFUN_REJECT_CHANGE: {
1511 case LFUN_THESAURUS_ENTRY: {
1512 string arg = cmd.argument;
1514 arg = cur.selectionAsString(false);
1516 if (arg.size() > 100 || arg.empty()) {
1517 // Get word or selection
1518 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1519 arg = cur.selectionAsString(false);
1522 bv->owner()->getDialogs().show("thesaurus", arg);
1526 case LFUN_PARAGRAPH_APPLY: {
1527 // Given data, an encoding of the ParagraphParameters
1528 // generated in the Paragraph dialog, this function sets
1529 // the current paragraph appropriately.
1530 istringstream is(cmd.argument);
1533 ParagraphParameters params;
1538 params.labelWidthString(),
1541 cur.message(_("Paragraph layout set"));
1546 if (cur.selection())
1547 cur.selection() = false;
1549 cur.dispatched(FINISHED_LEFT);
1559 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)