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.
20 #include "FloatList.h"
21 #include "FuncStatus.h"
23 #include "bufferparams.h"
24 #include "BufferView.h"
27 #include "dispatchresult.h"
29 #include "funcrequest.h"
37 #include "paragraph.h"
38 #include "paragraph_funcs.h"
39 #include "ParagraphParameters.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/LyXView.h"
46 #include "insets/insetcommand.h"
47 #include "insets/insetfloatlist.h"
48 #include "insets/insetnewline.h"
49 #include "insets/insetquotes.h"
50 #include "insets/insetspecialchar.h"
51 #include "insets/insettext.h"
53 #include "support/lstrings.h"
54 #include "support/lyxlib.h"
55 #include "support/tostr.h"
56 #include "support/std_sstream.h"
58 #include "mathed/math_hullinset.h"
59 #include "mathed/formulamacro.h"
65 using lyx::support::isStrUnsignedInt;
66 using lyx::support::strToUnsignedInt;
67 using lyx::support::atoi;
68 using lyx::support::token;
73 using std::istringstream;
77 extern string current_layout;
79 // the selection possible is needed, that only motion events are
80 // used, where the button press event was on the drawing area too
81 bool selection_possible = false;
87 LyXFont freefont(LyXFont::ALL_IGNORE);
88 bool toggleall = false;
91 void toggleAndShow(LCursor & cur, LyXText * text,
92 LyXFont const & font, bool toggleall = true)
94 text->toggleFree(cur, font, toggleall);
96 if (font.language() != ignore_language ||
97 font.number() != LyXFont::IGNORE) {
98 Paragraph & par = cur.paragraph();
99 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
100 if (cur.boundary() !=
101 text->bidi.isBoundary(*cur.bv().buffer(), par,
103 text->real_current_font))
104 text->setCursor(cur, cur.par(), cur.pos(),
105 false, !cur.boundary());
110 void moveCursor(LCursor & cur, bool selecting)
112 if (selecting || cur.mark())
114 if (!cur.selection())
115 cur.bv().haveSelection(false);
116 cur.bv().switchKeyMap();
120 void finishChange(LCursor & cur, bool selecting)
123 moveCursor(cur, selecting);
127 void mathDispatch(LCursor & cur, LyXText * text,
128 FuncRequest const & cmd, bool display)
131 string sel = cur.selectionAsString(false);
132 lyxerr << "selection is: '" << sel << "'" << endl;
135 cur.insert(new MathHullInset);
136 cur.dispatch(FuncRequest(LFUN_RIGHT));
137 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
138 // don't do that also for LFUN_MATH_MODE unless you want end up with
139 // always changing to mathrm when opening an inlined inset
140 // -- I really hate "LyXfunc overloading"...
142 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
143 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
145 // create a macro if we see "\\newcommand" somewhere, and an ordinary
147 text->cutSelection(cur, true, true);
148 if (sel.find("\\newcommand") == string::npos
149 && sel.find("\\def") == string::npos)
151 cur.insert(new MathHullInset);
152 cur.dispatch(FuncRequest(LFUN_RIGHT));
153 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
154 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
156 cur.insert(new InsetFormulaMacro(sel));
157 cur.dispatch(FuncRequest(LFUN_RIGHT));
160 cur.message(N_("Math editor mode"));
169 string const freefont2string()
172 if (font2string(freefont, toggleall, data))
180 //takes absolute x,y coordinates
181 InsetBase * LyXText::checkInsetHit(int x, int y)
183 ParagraphList::iterator pit;
184 ParagraphList::iterator end;
186 getParsInRange(paragraphs(),
188 bv()->top_y() - yo_ + bv()->workHeight(),
191 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
192 for ( ; pit != end; ++pit) {
193 InsetList::iterator iit = pit->insetlist.begin();
194 InsetList::iterator iend = pit->insetlist.end();
195 for ( ; iit != iend; ++iit) {
196 InsetBase * inset = iit->inset;
198 lyxerr << "examining inset " << inset
199 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
200 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
201 << " yo: " << inset->yo() - inset->ascent() << "..."
202 << inset->yo() + inset->descent() << endl;
204 if (inset->covers(x, y)) {
205 lyxerr << "Hit inset: " << inset << endl;
210 lyxerr << "No inset hit. " << endl;
215 bool LyXText::gotoNextInset(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);
346 if (cur.selection()) {
347 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
350 text->insertInset(cur, inset);
352 inset->edit(cur, true);
353 if (gotsel && pastesel)
354 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
360 void LyXText::number(LCursor & cur)
362 LyXFont font(LyXFont::ALL_IGNORE);
363 font.setNumber(LyXFont::TOGGLE);
364 toggleAndShow(cur, this, font);
368 bool LyXText::isRTL(Paragraph const & par) const
370 return par.isRightToLeftPar(bv()->buffer()->params());
374 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
376 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
377 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
379 BOOST_ASSERT(cur.text() == this);
380 BufferView * bv = &cur.bv();
381 CursorSlice sl = cur.top();
383 switch (cmd.action) {
385 case LFUN_APPENDIX: {
386 Paragraph & par = cur.paragraph();
387 bool start = !par.params().startOfAppendix();
389 // ensure that we have only one start_of_appendix in this document
390 ParagraphList::iterator tmp = paragraphs().begin();
391 ParagraphList::iterator end = paragraphs().end();
393 for (; tmp != end; ++tmp) {
394 if (tmp->params().startOfAppendix()) {
395 recUndo(parOffset(tmp));
396 tmp->params().startOfAppendix(false);
403 par.params().startOfAppendix(start);
405 // we can set the refreshing parameters now
412 case LFUN_DELETE_WORD_FORWARD:
413 cur.clearSelection();
414 deleteWordForward(cur);
415 finishChange(cur, false);
418 case LFUN_DELETE_WORD_BACKWARD:
419 cur.clearSelection();
420 deleteWordBackward(cur);
421 finishChange(cur, false);
424 case LFUN_DELETE_LINE_FORWARD:
425 cur.clearSelection();
426 deleteLineForward(cur);
427 finishChange(cur, false);
432 cur.clearSelection();
433 if (isRTL(cur.paragraph()))
434 cursorLeftOneWord(cur);
436 cursorRightOneWord(cur);
437 finishChange(cur, false);
442 cur.clearSelection();
443 if (isRTL(cur.paragraph()))
444 cursorRightOneWord(cur);
446 cursorLeftOneWord(cur);
447 finishChange(cur, false);
450 case LFUN_BEGINNINGBUF:
452 cur.clearSelection();
454 finishChange(cur, false);
459 cur.clearSelection();
461 finishChange(cur, false);
466 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
467 if (isRTL(cur.paragraph()))
472 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
477 cur.selHandle(cmd.action == LFUN_LEFTSEL);
478 if (isRTL(cur.paragraph()))
483 cmd = FuncRequest(LFUN_FINISHED_LEFT);
488 cur.selHandle(cmd.action == LFUN_UPSEL);
491 cmd = FuncRequest(LFUN_FINISHED_UP);
496 cur.selHandle(cmd.action == LFUN_DOWNSEL);
499 cmd = FuncRequest(LFUN_FINISHED_DOWN);
502 case LFUN_UP_PARAGRAPHSEL:
503 if (!cur.selection())
505 cursorUpParagraph(cur);
506 finishChange(cur, true);
509 case LFUN_DOWN_PARAGRAPHSEL:
510 if (!cur.selection())
512 cursorDownParagraph(cur);
513 finishChange(cur, true);
517 if (!cur.selection())
520 finishChange(cur, true);
524 if (!cur.selection())
527 finishChange(cur, true);
531 if (!cur.selection())
534 finishChange(cur, true);
538 if (!cur.selection())
541 finishChange(cur, true);
544 case LFUN_WORDRIGHTSEL:
545 if (!cur.selection())
547 if (isRTL(cur.paragraph()))
548 cursorLeftOneWord(cur);
550 cursorRightOneWord(cur);
551 finishChange(cur, true);
554 case LFUN_WORDLEFTSEL:
555 if (!cur.selection())
557 if (isRTL(cur.paragraph()))
558 cursorRightOneWord(cur);
560 cursorLeftOneWord(cur);
561 finishChange(cur, true);
565 selectWord(cur, lyx::WHOLE_WORD);
566 finishChange(cur, true);
570 case LFUN_UP_PARAGRAPH:
572 cur.clearSelection();
573 cursorUpParagraph(cur);
574 finishChange(cur, false);
577 case LFUN_DOWN_PARAGRAPH:
579 cur.clearSelection();
580 cursorDownParagraph(cur);
581 finishChange(cur, false);
586 cur.clearSelection();
587 finishChange(cur, false);
588 if (cur.par() == 0 && cur.textRow().pos() == 0)
589 cmd = FuncRequest(LFUN_FINISHED_UP);
596 cur.clearSelection();
597 finishChange(cur, false);
598 if (cur.par() == cur.lastpar()
599 && cur.textRow().endpos() == cur.lastpos())
600 cmd = FuncRequest(LFUN_FINISHED_DOWN);
607 cur.clearSelection();
609 finishChange(cur, false);
614 cur.clearSelection();
616 finishChange(cur, false);
619 case LFUN_BREAKLINE: {
620 // Not allowed by LaTeX (labels or empty par)
621 if (cur.pos() > cur.paragraph().beginOfBody()) {
622 replaceSelection(cur);
623 cur.insert(new InsetNewline);
624 moveCursor(cur, false);
630 if (!cur.selection()) {
633 // It is possible to make it a lot faster still
634 // just comment out the line below...
636 cutSelection(cur, true, false);
638 moveCursor(cur, false);
641 case LFUN_DELETE_SKIP:
642 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
643 if (!cur.selection()) {
644 if (cur.pos() == cur.lastpos()) {
651 cutSelection(cur, true, false);
658 if (!cur.selection()) {
659 if (bv->owner()->getIntl().getTransManager().backspace()) {
662 // It is possible to make it a lot faster still
663 // just comment out the line below...
666 cutSelection(cur, true, false);
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);
693 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
694 replaceSelection(cur);
695 breakParagraph(cur, 1);
701 case LFUN_BREAKPARAGRAPH_SKIP: {
702 // When at the beginning of a paragraph, remove
703 // indentation and add a "defskip" at the top.
704 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
705 replaceSelection(cur);
706 if (cur.pos() == 0) {
707 ParagraphParameters & params = cur.paragraph().params();
711 params.labelWidthString(), 1);
713 breakParagraph(cur, 0);
721 case LFUN_PARAGRAPH_SPACING: {
722 Paragraph & par = cur.paragraph();
723 Spacing::Space cur_spacing = par.params().spacing().getSpace();
724 float cur_value = 1.0;
725 if (cur_spacing == Spacing::Other)
726 cur_value = par.params().spacing().getValue();
728 istringstream is(cmd.argument);
731 Spacing::Space new_spacing = cur_spacing;
732 float new_value = cur_value;
734 lyxerr << "Missing argument to `paragraph-spacing'"
736 } else if (tmp == "single") {
737 new_spacing = Spacing::Single;
738 } else if (tmp == "onehalf") {
739 new_spacing = Spacing::Onehalf;
740 } else if (tmp == "double") {
741 new_spacing = Spacing::Double;
742 } else if (tmp == "other") {
743 new_spacing = Spacing::Other;
746 lyxerr << "new_value = " << tmpval << endl;
749 } else if (tmp == "default") {
750 new_spacing = Spacing::Default;
752 lyxerr << _("Unknown spacing argument: ")
753 << cmd.argument << endl;
755 if (cur_spacing != new_spacing || cur_value != new_value) {
756 par.params().spacing(Spacing(new_spacing, new_value));
763 case LFUN_INSET_APPLY: {
764 string const name = cmd.getArg(0);
765 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
767 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
768 inset->dispatch(cur, fr);
770 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
776 case LFUN_INSET_INSERT: {
778 InsetBase * inset = createInset(bv, cmd);
780 insertInset(cur, inset);
784 case LFUN_INSET_SETTINGS:
785 if (cur.inset().asUpdatableInset())
786 cur.inset().asUpdatableInset()->showInsetDialog(bv);
789 case LFUN_INSET_TOGGLE:
790 cur.clearSelection();
791 if (!toggleInset(cur))
797 case LFUN_SPACE_INSERT:
798 if (cur.paragraph().layout()->free_spacing)
799 insertChar(cur, ' ');
801 doInsertInset(cur, this, cmd, false, false);
802 moveCursor(cur, false);
805 case LFUN_HYPHENATION:
806 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
809 case LFUN_LIGATURE_BREAK:
810 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
814 specialChar(cur, this, InsetSpecialChar::LDOTS);
817 case LFUN_END_OF_SENTENCE:
818 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
821 case LFUN_MENU_SEPARATOR:
822 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
825 case LFUN_UPCASE_WORD:
826 changeCase(cur, LyXText::text_uppercase);
830 case LFUN_LOWCASE_WORD:
831 changeCase(cur, LyXText::text_lowercase);
835 case LFUN_CAPITALIZE_WORD:
836 changeCase(cur, LyXText::text_capitalization);
840 case LFUN_TRANSPOSE_CHARS:
847 cur.message(_("Paste"));
848 replaceSelection(cur);
849 #warning FIXME Check if the arg is in the domain of available selections.
850 if (isStrUnsignedInt(cmd.argument))
851 pasteSelection(cur, strToUnsignedInt(cmd.argument));
853 pasteSelection(cur, 0);
854 cur.clearSelection(); // bug 393
861 cutSelection(cur, true, true);
862 cur.message(_("Cut"));
868 cur.message(_("Copy"));
872 cur.message(tostr(cursorX(cur.top())) + ' '
873 + tostr(cursorY(cur.top())));
879 istringstream is(cmd.argument);
882 lyxerr << "SETXY: Could not parse coordinates in '"
883 << cmd.argument << std::endl;
885 setCursorFromCoordinates(cur, x, y);
890 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
892 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
899 cur.message(cur.paragraph().layout()->name());
903 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
904 << cmd.argument << endl;
906 // This is not the good solution to the empty argument
907 // problem, but it will hopefully suffice for 1.2.0.
908 // The correct solution would be to augument the
909 // function list/array with information about what
910 // functions needs arguments and their type.
911 if (cmd.argument.empty()) {
912 cur.errorMessage(_("LyX function 'layout' needs an argument."));
916 // Derive layout number from given argument (string)
917 // and current buffer's textclass (number)
918 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
919 bool hasLayout = tclass.hasLayout(cmd.argument);
920 string layout = cmd.argument;
922 // If the entry is obsolete, use the new one instead.
924 string const & obs = tclass[layout]->obsoleted_by();
930 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
935 bool change_layout = (current_layout != layout);
937 if (!change_layout && cur.selection() &&
938 cur.selBegin().par() != cur.selEnd().par())
940 ParagraphList::iterator spit = getPar(cur.selBegin());
941 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
942 while (spit != epit) {
943 if (spit->layout()->name() != current_layout) {
944 change_layout = true;
952 current_layout = layout;
953 setLayout(cur, layout);
954 bv->owner()->setLayout(layout);
961 case LFUN_PASTESELECTION: {
962 cur.clearSelection();
963 string const clip = bv->getClipboard();
965 if (cmd.argument == "paragraph")
966 insertStringAsParagraphs(cur, clip);
968 insertStringAsLines(cur, clip);
975 gotoInset(cur, InsetBase::ERROR_CODE, false);
979 gotoInset(cur, InsetBase::NOTE_CODE, false);
982 case LFUN_REFERENCE_GOTO: {
983 vector<InsetOld_code> tmp;
984 tmp.push_back(InsetBase::LABEL_CODE);
985 tmp.push_back(InsetBase::REF_CODE);
986 gotoInset(cur, tmp, true);
991 replaceSelection(cur);
992 Paragraph & par = cur.paragraph();
993 lyx::pos_type pos = cur.pos();
997 else if (cur.prevInset() && cur.prevInset()->isSpace())
1000 c = par.getChar(pos - 1);
1002 LyXLayout_ptr const & style = par.layout();
1004 BufferParams const & bufparams = bv->buffer()->params();
1005 if (!style->pass_thru
1006 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1007 string arg = cmd.argument;
1008 if (arg == "single")
1009 cur.insert(new InsetQuotes(c,
1010 bufparams.quotes_language,
1011 InsetQuotes::SingleQ));
1012 else if (arg == "double")
1013 cur.insert(new InsetQuotes(c,
1014 bufparams.quotes_language,
1015 InsetQuotes::DoubleQ));
1017 cur.insert(new InsetQuotes(c, bufparams));
1020 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1024 case LFUN_DATE_INSERT: {
1025 replaceSelection(cur);
1026 time_t now_time_t = time(NULL);
1027 struct tm * now_tm = localtime(&now_time_t);
1028 setlocale(LC_TIME, "");
1030 if (!cmd.argument.empty())
1033 arg = lyxrc.date_insert_format;
1035 int const datetmp_len =
1036 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1038 for (int i = 0; i < datetmp_len; i++)
1039 insertChar(cur, datetmp[i]);
1042 moveCursor(cur, false);
1046 case LFUN_MOUSE_TRIPLE:
1047 if (cmd.button() == mouse_button::button1) {
1048 selection_possible = true;
1053 bv->haveSelection(cur.selection());
1057 case LFUN_MOUSE_DOUBLE:
1058 if (cmd.button() == mouse_button::button1) {
1059 selection_possible = true;
1060 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1061 bv->haveSelection(cur.selection());
1065 case LFUN_MOUSE_MOTION: {
1066 // Only use motion with button 1
1067 //if (cmd.button() != mouse_button::button1)
1069 // The test for not selection possible is needed, that
1070 // only motion events are used, where the bottom press
1071 // event was on the drawing area too
1072 if (!selection_possible) {
1073 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1074 "Dispatch: no selection possible\n";
1077 CursorSlice old = cur.top();
1078 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1080 // This is to allow jumping over large insets
1081 // FIXME: shouldn't be top-text-specific
1082 if (isMainText() && cur.top() == old) {
1083 if (cmd.y - bv->top_y() >= bv->workHeight())
1085 else if (cmd.y - bv->top_y() < 0)
1089 // don't set anchor_
1090 bv->cursor().setCursor(cur, false);
1094 // Single-click on work area
1095 case LFUN_MOUSE_PRESS: {
1096 // ok ok, this is a hack (for xforms)
1097 // We shouldn't go further down as we really should only do the
1098 // scrolling and be done with this. Otherwise we may open some
1099 // dialogs (Jug 20020424).
1100 if (cmd.button() == mouse_button::button4) {
1101 bv->scroll(-lyxrc.wheel_jump);
1105 if (cmd.button() == mouse_button::button5) {
1106 bv->scroll(lyxrc.wheel_jump);
1110 // Right click on a footnote flag opens float menu
1111 if (cmd.button() == mouse_button::button3) {
1112 cur.clearSelection();
1113 selection_possible = false;
1117 // Middle button press pastes if we have a selection
1118 // We do this here as if the selection was inside an inset
1119 // it could get cleared on the unlocking of the inset so
1120 // we have to check this first
1121 bool paste_internally = false;
1122 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1123 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1124 paste_internally = true;
1127 selection_possible = true;
1129 // Clear the selection
1130 cur.clearSelection();
1132 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1135 cur.x_target() = cursorX(cur.top());
1137 // set cursor and anchor to this position
1140 if (bv->fitCursor())
1141 selection_possible = false;
1143 // Insert primary selection with middle mouse
1144 // if there is a local selection in the current buffer,
1146 if (cmd.button() == mouse_button::button2) {
1147 if (paste_internally)
1148 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1150 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1151 selection_possible = false;
1156 case LFUN_MOUSE_RELEASE: {
1157 // do nothing if we used the mouse wheel
1158 if (cmd.button() == mouse_button::button4
1159 || cmd.button() == mouse_button::button5) {
1164 selection_possible = false;
1166 if (cmd.button() == mouse_button::button2)
1170 if (cmd.button() == mouse_button::button1)
1171 bv->haveSelection(cur.selection());
1174 bv->owner()->updateMenubar();
1175 bv->owner()->updateToolbar();
1179 case LFUN_SELFINSERT: {
1180 if (cmd.argument.empty())
1183 // Automatically delete the currently selected
1184 // text and replace it with what is being
1185 // typed in now. Depends on lyxrc settings
1186 // "auto_region_delete", which defaults to
1189 if (lyxrc.auto_region_delete) {
1190 if (cur.selection())
1191 cutSelection(cur, false, false);
1192 bv->haveSelection(false);
1195 cur.clearSelection();
1196 LyXFont const old_font = real_current_font;
1198 string::const_iterator cit = cmd.argument.begin();
1199 string::const_iterator end = cmd.argument.end();
1200 for (; cit != end; ++cit)
1201 bv->owner()->getIntl().getTransManager().
1202 TranslateAndInsert(*cit, this);
1205 moveCursor(cur, false);
1207 // real_current_font.number can change so we need to
1208 // update the minibuffer
1209 if (old_font != real_current_font)
1210 bv->updateScrollbar();
1215 InsetCommandParams p("url");
1216 string const data = InsetCommandMailer::params2string("url", p);
1217 bv->owner()->getDialogs().show("url", data, 0);
1221 case LFUN_HTMLURL: {
1222 InsetCommandParams p("htmlurl");
1223 string const data = InsetCommandMailer::params2string("url", p);
1224 bv->owner()->getDialogs().show("url", data, 0);
1228 case LFUN_INSERT_LABEL: {
1229 InsetCommandParams p("label");
1230 string const data = InsetCommandMailer::params2string("label", p);
1231 bv->owner()->getDialogs().show("label", data, 0);
1237 case LFUN_INSET_LIST:
1238 case LFUN_INSET_THEOREM:
1239 case LFUN_INSET_CAPTION:
1241 case LFUN_INSERT_NOTE:
1242 case LFUN_INSERT_CHARSTYLE:
1243 case LFUN_INSERT_BOX:
1244 case LFUN_INSERT_BRANCH:
1245 case LFUN_INSERT_BIBITEM:
1246 case LFUN_INSET_ERT:
1247 case LFUN_INSET_FLOAT:
1248 case LFUN_INSET_FOOTNOTE:
1249 case LFUN_INSET_MARGINAL:
1250 case LFUN_INSET_OPTARG:
1251 case LFUN_INSET_WIDE_FLOAT:
1252 case LFUN_INSET_WRAP:
1253 case LFUN_TABULAR_INSERT:
1254 case LFUN_ENVIRONMENT_INSERT:
1255 // Open the inset, and move the current selection
1257 doInsertInset(cur, this, cmd, true, true);
1260 case LFUN_INDEX_INSERT:
1261 // Just open the inset
1262 doInsertInset(cur, this, cmd, true, false);
1265 case LFUN_INDEX_PRINT:
1266 case LFUN_TOC_INSERT:
1268 case LFUN_INSERT_LINE:
1269 case LFUN_INSERT_PAGEBREAK:
1271 doInsertInset(cur, this, cmd, false, false);
1274 case LFUN_DEPTH_MIN:
1275 changeDepth(cur, DEC_DEPTH);
1279 case LFUN_DEPTH_PLUS:
1280 changeDepth(cur, INC_DEPTH);
1284 case LFUN_MATH_DISPLAY:
1285 mathDispatch(cur, this, cmd, true);
1288 case LFUN_MATH_IMPORT_SELECTION:
1289 case LFUN_MATH_MODE:
1290 mathDispatch(cur, this, cmd, false);
1293 case LFUN_MATH_MACRO:
1294 if (cmd.argument.empty())
1295 cur.errorMessage(N_("Missing argument"));
1297 string s = cmd.argument;
1298 string const s1 = token(s, ' ', 1);
1299 int const nargs = s1.empty() ? 0 : atoi(s1);
1300 string const s2 = token(s, ' ', 2);
1301 string const type = s2.empty() ? "newcommand" : s2;
1302 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1303 cur.nextInset()->edit(cur, true);
1307 case LFUN_INSERT_MATH:
1308 case LFUN_INSERT_MATRIX:
1309 case LFUN_MATH_DELIM: {
1310 cur.insert(new MathHullInset);
1311 cur.dispatch(FuncRequest(LFUN_RIGHT));
1312 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1318 LyXFont font(LyXFont::ALL_IGNORE);
1319 font.setEmph(LyXFont::TOGGLE);
1320 toggleAndShow(cur, this, font);
1325 LyXFont font(LyXFont::ALL_IGNORE);
1326 font.setSeries(LyXFont::BOLD_SERIES);
1327 toggleAndShow(cur, this, font);
1332 LyXFont font(LyXFont::ALL_IGNORE);
1333 font.setNoun(LyXFont::TOGGLE);
1334 toggleAndShow(cur, this, font);
1339 LyXFont font(LyXFont::ALL_IGNORE);
1340 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1341 toggleAndShow(cur, this, font);
1346 LyXFont font(LyXFont::ALL_IGNORE);
1347 font.setFamily(LyXFont::SANS_FAMILY);
1348 toggleAndShow(cur, this, font);
1353 LyXFont font(LyXFont::ALL_IGNORE);
1354 font.setFamily(LyXFont::ROMAN_FAMILY);
1355 toggleAndShow(cur, this, font);
1359 case LFUN_DEFAULT: {
1360 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1361 toggleAndShow(cur, this, font);
1365 case LFUN_UNDERLINE: {
1366 LyXFont font(LyXFont::ALL_IGNORE);
1367 font.setUnderbar(LyXFont::TOGGLE);
1368 toggleAndShow(cur, this, font);
1372 case LFUN_FONT_SIZE: {
1373 LyXFont font(LyXFont::ALL_IGNORE);
1374 font.setLyXSize(cmd.argument);
1375 toggleAndShow(cur, this, font);
1379 case LFUN_LANGUAGE: {
1380 Language const * lang = languages.getLanguage(cmd.argument);
1383 LyXFont font(LyXFont::ALL_IGNORE);
1384 font.setLanguage(lang);
1385 toggleAndShow(cur, this, font);
1390 case LFUN_FREEFONT_APPLY:
1391 toggleAndShow(cur, this, freefont, toggleall);
1392 cur.message(_("Character set"));
1395 // Set the freefont using the contents of \param data dispatched from
1396 // the frontends and apply it at the current cursor location.
1397 case LFUN_FREEFONT_UPDATE: {
1400 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1403 toggleAndShow(cur, this, freefont, toggleall);
1404 cur.message(_("Character set"));
1409 case LFUN_FINISHED_LEFT:
1410 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1411 if (isRTL(cur.paragraph()))
1413 cur.bv().cursor() = cur;
1416 case LFUN_FINISHED_RIGHT:
1417 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1418 if (!isRTL(cur.paragraph()))
1420 cur.bv().cursor() = cur;
1423 case LFUN_FINISHED_UP:
1424 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1426 cur.bv().cursor() = cur;
1429 case LFUN_FINISHED_DOWN:
1430 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1432 cur.bv().cursor() = cur;
1435 case LFUN_LAYOUT_PARAGRAPH: {
1437 params2string(cur.paragraph(), data);
1438 data = "show\n" + data;
1439 bv->owner()->getDialogs().show("paragraph", data);
1443 case LFUN_PARAGRAPH_UPDATE: {
1444 if (!bv->owner()->getDialogs().visible("paragraph"))
1447 params2string(cur.paragraph(), data);
1449 // Will the paragraph accept changes from the dialog?
1450 InsetBase & inset = cur.inset();
1451 bool const accept = !inset.forceDefaultParagraphs(&inset);
1453 data = "update " + tostr(accept) + '\n' + data;
1454 bv->owner()->getDialogs().update("paragraph", data);
1459 case LFUN_CIRCUMFLEX:
1469 case LFUN_SPECIAL_CARON:
1472 case LFUN_HUNG_UMLAUT:
1475 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1476 if (!cmd.argument.empty())
1477 bv->owner()->getIntl().getTransManager()
1478 .TranslateAndInsert(cmd.argument[0], this);
1481 case LFUN_FLOAT_LIST: {
1482 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1483 if (tclass.floats().typeExist(cmd.argument)) {
1484 // not quite sure if we want this...
1486 cur.clearSelection();
1487 breakParagraph(cur);
1489 if (cur.lastpos() != 0) {
1491 breakParagraph(cur);
1494 setLayout(cur, tclass.defaultLayoutName());
1495 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1496 insertInset(cur, new InsetFloatList(cmd.argument));
1498 lyxerr << "Non-existent float type: "
1499 << cmd.argument << endl;
1504 case LFUN_ACCEPT_CHANGE: {
1510 case LFUN_REJECT_CHANGE: {
1516 case LFUN_THESAURUS_ENTRY: {
1517 string arg = cmd.argument;
1519 arg = cur.selectionAsString(false);
1521 if (arg.size() > 100 || arg.empty()) {
1522 // Get word or selection
1523 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1524 arg = cur.selectionAsString(false);
1527 bv->owner()->getDialogs().show("thesaurus", arg);
1531 case LFUN_PARAGRAPH_APPLY: {
1532 // Given data, an encoding of the ParagraphParameters
1533 // generated in the Paragraph dialog, this function sets
1534 // the current paragraph appropriately.
1535 istringstream is(cmd.argument);
1538 ParagraphParameters params;
1543 params.labelWidthString(),
1546 cur.message(_("Paragraph layout set"));
1550 case LFUN_INSET_DIALOG_SHOW: {
1551 InsetBase * inset = cur.nextInset();
1553 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1554 inset->dispatch(cur, fr);
1560 if (cur.selection())
1561 cur.selection() = false;
1563 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1573 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1574 FuncStatus & flag) const
1576 BOOST_ASSERT(cur.text() == this);
1577 LyXFont const & font = real_current_font;
1580 switch (cmd.action) {
1582 case LFUN_DEPTH_MIN:
1583 enable = changeDepthAllowed(cur, DEC_DEPTH);
1586 case LFUN_DEPTH_PLUS:
1587 enable = changeDepthAllowed(cur, INC_DEPTH);
1590 case LFUN_INSET_OPTARG:
1591 enable = cur.paragraph().layout()->optionalargs;
1595 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1599 // the functions which insert insets
1600 InsetOld::Code code = InsetOld::NO_CODE;
1601 switch (cmd.action) {
1602 case LFUN_DIALOG_SHOW_NEW_INSET:
1603 if (cmd.argument == "bibitem")
1604 code = InsetOld::BIBITEM_CODE;
1605 else if (cmd.argument == "bibtex")
1606 code = InsetOld::BIBTEX_CODE;
1607 else if (cmd.argument == "box")
1608 code = InsetOld::BOX_CODE;
1609 else if (cmd.argument == "branch")
1610 code = InsetOld::BRANCH_CODE;
1611 else if (cmd.argument == "citation")
1612 code = InsetOld::CITE_CODE;
1613 else if (cmd.argument == "ert")
1614 code = InsetOld::ERT_CODE;
1615 else if (cmd.argument == "external")
1616 code = InsetOld::EXTERNAL_CODE;
1617 else if (cmd.argument == "float")
1618 code = InsetOld::FLOAT_CODE;
1619 else if (cmd.argument == "graphics")
1620 code = InsetOld::GRAPHICS_CODE;
1621 else if (cmd.argument == "include")
1622 code = InsetOld::INCLUDE_CODE;
1623 else if (cmd.argument == "index")
1624 code = InsetOld::INDEX_CODE;
1625 else if (cmd.argument == "label")
1626 code = InsetOld::LABEL_CODE;
1627 else if (cmd.argument == "note")
1628 code = InsetOld::NOTE_CODE;
1629 else if (cmd.argument == "ref")
1630 code = InsetOld::REF_CODE;
1631 else if (cmd.argument == "toc")
1632 code = InsetOld::TOC_CODE;
1633 else if (cmd.argument == "url")
1634 code = InsetOld::URL_CODE;
1635 else if (cmd.argument == "vspace")
1636 code = InsetOld::VSPACE_CODE;
1637 else if (cmd.argument == "wrap")
1638 code = InsetOld::WRAP_CODE;
1641 case LFUN_INSET_ERT:
1642 code = InsetOld::ERT_CODE;
1644 case LFUN_INSET_FOOTNOTE:
1645 code = InsetOld::FOOT_CODE;
1647 case LFUN_TABULAR_INSERT:
1648 code = InsetOld::TABULAR_CODE;
1650 case LFUN_INSET_MARGINAL:
1651 code = InsetOld::MARGIN_CODE;
1653 case LFUN_INSET_FLOAT:
1654 case LFUN_INSET_WIDE_FLOAT:
1655 code = InsetOld::FLOAT_CODE;
1657 case LFUN_INSET_WRAP:
1658 code = InsetOld::WRAP_CODE;
1660 case LFUN_FLOAT_LIST:
1661 code = InsetOld::FLOAT_LIST_CODE;
1664 case LFUN_INSET_LIST:
1665 code = InsetOld::LIST_CODE;
1667 case LFUN_INSET_THEOREM:
1668 code = InsetOld::THEOREM_CODE;
1671 case LFUN_INSET_CAPTION:
1672 code = InsetOld::CAPTION_CODE;
1674 case LFUN_INSERT_NOTE:
1675 code = InsetOld::NOTE_CODE;
1677 case LFUN_INSERT_CHARSTYLE:
1678 code = InsetOld::CHARSTYLE_CODE;
1679 if (buf->params().getLyXTextClass().charstyles().empty())
1682 case LFUN_INSERT_BOX:
1683 code = InsetOld::BOX_CODE;
1685 case LFUN_INSERT_BRANCH:
1686 code = InsetOld::BRANCH_CODE;
1687 if (buf->params().branchlist().empty())
1690 case LFUN_INSERT_LABEL:
1691 code = InsetOld::LABEL_CODE;
1693 case LFUN_INSET_OPTARG:
1694 code = InsetOld::OPTARG_CODE;
1696 case LFUN_ENVIRONMENT_INSERT:
1697 code = InsetOld::BOX_CODE;
1699 case LFUN_INDEX_INSERT:
1700 code = InsetOld::INDEX_CODE;
1702 case LFUN_INDEX_PRINT:
1703 code = InsetOld::INDEX_PRINT_CODE;
1705 case LFUN_TOC_INSERT:
1706 code = InsetOld::TOC_CODE;
1710 code = InsetOld::URL_CODE;
1713 // always allow this, since we will inset a raw quote
1714 // if an inset is not allowed.
1716 case LFUN_HYPHENATION:
1717 case LFUN_LIGATURE_BREAK:
1719 case LFUN_MENU_SEPARATOR:
1721 case LFUN_END_OF_SENTENCE:
1722 code = InsetOld::SPECIALCHAR_CODE;
1724 case LFUN_SPACE_INSERT:
1725 // slight hack: we know this is allowed in math mode
1727 code = InsetOld::SPACE_CODE;
1729 case LFUN_INSET_DIALOG_SHOW: {
1730 InsetBase * inset = cur.nextInset();
1733 code = inset->lyxCode();
1734 if (!(code == InsetOld::INCLUDE_CODE
1735 || code == InsetOld::BIBTEX_CODE
1736 || code == InsetOld::FLOAT_LIST_CODE
1737 || code == InsetOld::TOC_CODE))
1746 if (code != InsetOld::NO_CODE
1747 && (cur.empty() || !cur.inset().insetAllowed(code)))
1752 case LFUN_DIALOG_SHOW_NEW_INSET:
1753 case LFUN_INSET_ERT:
1754 case LFUN_INSERT_BOX:
1755 case LFUN_INSERT_BRANCH:
1756 case LFUN_ENVIRONMENT_INSERT:
1757 case LFUN_INDEX_INSERT:
1758 case LFUN_INDEX_PRINT:
1759 case LFUN_TOC_INSERT:
1763 case LFUN_HYPHENATION:
1764 case LFUN_LIGATURE_BREAK:
1766 case LFUN_MENU_SEPARATOR:
1768 case LFUN_END_OF_SENTENCE:
1769 case LFUN_SPACE_INSERT:
1770 case LFUN_INSET_DIALOG_SHOW:
1774 flag.setOnOff(font.emph() == LyXFont::ON);
1778 flag.setOnOff(font.noun() == LyXFont::ON);
1782 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1786 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1790 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1794 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1797 case LFUN_DELETE_WORD_FORWARD:
1798 case LFUN_DELETE_WORD_BACKWARD:
1799 case LFUN_DELETE_LINE_FORWARD:
1800 case LFUN_WORDRIGHT:
1811 case LFUN_UP_PARAGRAPHSEL:
1812 case LFUN_DOWN_PARAGRAPHSEL:
1817 case LFUN_WORDRIGHTSEL:
1818 case LFUN_WORDLEFTSEL:
1820 case LFUN_UP_PARAGRAPH:
1821 case LFUN_DOWN_PARAGRAPH:
1826 case LFUN_BREAKLINE:
1828 case LFUN_DELETE_SKIP:
1829 case LFUN_BACKSPACE:
1830 case LFUN_BACKSPACE_SKIP:
1831 case LFUN_BREAKPARAGRAPH:
1832 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1833 case LFUN_BREAKPARAGRAPH_SKIP:
1834 case LFUN_PARAGRAPH_SPACING:
1835 case LFUN_INSET_APPLY:
1836 case LFUN_INSET_INSERT:
1837 case LFUN_INSET_TOGGLE:
1838 case LFUN_UPCASE_WORD:
1839 case LFUN_LOWCASE_WORD:
1840 case LFUN_CAPITALIZE_WORD:
1841 case LFUN_TRANSPOSE_CHARS:
1848 case LFUN_GETLAYOUT:
1850 case LFUN_PASTESELECTION:
1851 case LFUN_GOTOERROR:
1853 case LFUN_REFERENCE_GOTO:
1854 case LFUN_DATE_INSERT:
1855 case LFUN_SELFINSERT:
1856 case LFUN_INSERT_LABEL:
1857 case LFUN_INSERT_NOTE:
1858 case LFUN_INSERT_CHARSTYLE:
1859 case LFUN_INSERT_BIBITEM:
1860 case LFUN_INSET_FLOAT:
1861 case LFUN_INSET_FOOTNOTE:
1862 case LFUN_INSET_MARGINAL:
1863 case LFUN_INSET_WIDE_FLOAT:
1864 case LFUN_INSET_WRAP:
1865 case LFUN_TABULAR_INSERT:
1866 case LFUN_INSERT_LINE:
1867 case LFUN_INSERT_PAGEBREAK:
1868 case LFUN_MATH_DISPLAY:
1869 case LFUN_MATH_IMPORT_SELECTION:
1870 case LFUN_MATH_MODE:
1871 case LFUN_MATH_MACRO:
1872 case LFUN_INSERT_MATH:
1873 case LFUN_INSERT_MATRIX:
1874 case LFUN_MATH_DELIM:
1876 case LFUN_UNDERLINE:
1877 case LFUN_FONT_SIZE:
1879 case LFUN_FREEFONT_APPLY:
1880 case LFUN_FREEFONT_UPDATE:
1881 case LFUN_LAYOUT_PARAGRAPH:
1882 case LFUN_PARAGRAPH_UPDATE:
1884 case LFUN_CIRCUMFLEX:
1894 case LFUN_SPECIAL_CARON:
1897 case LFUN_HUNG_UMLAUT:
1900 case LFUN_FLOAT_LIST:
1901 case LFUN_ACCEPT_CHANGE:
1902 case LFUN_REJECT_CHANGE:
1903 case LFUN_THESAURUS_ENTRY:
1904 case LFUN_PARAGRAPH_APPLY:
1906 // these are handled in our dispatch()
1914 flag.enabled(enable);