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"
26 #include "CutAndPaste.h"
28 #include "dispatchresult.h"
30 #include "funcrequest.h"
38 #include "paragraph.h"
39 #include "paragraph_funcs.h"
40 #include "ParagraphParameters.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
47 #include "insets/insetcommand.h"
48 #include "insets/insetfloatlist.h"
49 #include "insets/insetnewline.h"
50 #include "insets/insetquotes.h"
51 #include "insets/insetspecialchar.h"
52 #include "insets/insettext.h"
54 #include "support/lstrings.h"
55 #include "support/lyxlib.h"
56 #include "support/tostr.h"
57 #include "support/std_sstream.h"
59 #include "mathed/math_hullinset.h"
60 #include "mathed/formulamacro.h"
66 using lyx::cap::copySelection;
67 using lyx::cap::cutSelection;
68 using lyx::cap::pasteSelection;
69 using lyx::cap::replaceSelection;
71 using lyx::support::isStrUnsignedInt;
72 using lyx::support::strToUnsignedInt;
73 using lyx::support::atoi;
74 using lyx::support::token;
79 using std::istringstream;
83 extern string current_layout;
85 // the selection possible is needed, that only motion events are
86 // used, where the button press event was on the drawing area too
87 bool selection_possible = false;
93 LyXFont freefont(LyXFont::ALL_IGNORE);
94 bool toggleall = false;
97 void toggleAndShow(LCursor & cur, LyXText * text,
98 LyXFont const & font, bool toggleall = true)
100 text->toggleFree(cur, font, toggleall);
102 if (font.language() != ignore_language ||
103 font.number() != LyXFont::IGNORE) {
104 Paragraph & par = cur.paragraph();
105 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
106 if (cur.boundary() !=
107 text->bidi.isBoundary(*cur.bv().buffer(), par,
109 text->real_current_font))
110 text->setCursor(cur, cur.par(), cur.pos(),
111 false, !cur.boundary());
116 void moveCursor(LCursor & cur, bool selecting)
118 if (selecting || cur.mark())
120 if (!cur.selection())
121 cur.bv().haveSelection(false);
122 cur.bv().switchKeyMap();
126 void finishChange(LCursor & cur, bool selecting)
129 moveCursor(cur, selecting);
133 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
136 string sel = cur.selectionAsString(false);
137 lyxerr << "selection is: '" << sel << "'" << endl;
140 cur.insert(new MathHullInset);
141 cur.nextInset()->edit(cur, true);
142 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
143 // don't do that also for LFUN_MATH_MODE unless you want end up with
144 // always changing to mathrm when opening an inlined inset
145 // -- I really hate "LyXfunc overloading"...
147 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
148 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
150 // create a macro if we see "\\newcommand" somewhere, and an ordinary
152 cutSelection(cur, true, true);
153 if (sel.find("\\newcommand") == string::npos
154 && sel.find("\\def") == string::npos)
156 cur.insert(new MathHullInset);
157 cur.dispatch(FuncRequest(LFUN_RIGHT));
158 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
159 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
161 cur.insert(new InsetFormulaMacro(sel));
162 cur.dispatch(FuncRequest(LFUN_RIGHT));
165 cur.message(N_("Math editor mode"));
174 string const freefont2string()
177 if (font2string(freefont, toggleall, data))
185 //takes absolute x,y coordinates
186 InsetBase * LyXText::checkInsetHit(int x, int y)
191 getParsInRange(paragraphs(),
193 bv()->top_y() - yo_ + bv()->workHeight(),
196 //lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
197 for ( ; pit != end; ++pit) {
198 InsetList::iterator iit = pars_[pit].insetlist.begin();
199 InsetList::iterator iend = pars_[pit].insetlist.end();
200 for ( ; iit != iend; ++iit) {
201 InsetBase * inset = iit->inset;
203 lyxerr << "examining inset " << inset
204 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
205 << " yo: " << inset->yo() - inset->ascent() << "..."
206 << inset->yo() + inset->descent() << endl;
208 if (inset->covers(x, y)) {
209 lyxerr << "Hit inset: " << inset << endl;
214 //lyxerr << "No inset hit. " << endl;
219 bool LyXText::gotoNextInset(LCursor & cur,
220 vector<InsetOld_code> const & codes, string const & contents)
222 BOOST_ASSERT(this == cur.text());
223 par_type end = paragraphs().size();
224 par_type pit = cur.par();
225 pos_type pos = cur.pos();
229 if (pos + 1 < pars_[pit].size()) {
236 } while (pit != end &&
237 !(pars_[pit].isInset(pos) &&
238 (inset = pars_[pit].getInset(pos)) != 0 &&
239 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
241 static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
247 setCursor(cur, pit, pos, false);
252 void LyXText::gotoInset(LCursor & cur,
253 vector<InsetOld_code> const & codes, bool same_content)
255 cur.clearSelection();
259 && cur.pos() < cur.lastpos()
260 && cur.paragraph().isInset(cur.pos())) {
261 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
262 if (find(codes.begin(), codes.end(), inset->lyxCode())
264 contents = static_cast<InsetCommand const *>(inset)->getContents();
267 if (!gotoNextInset(cur, codes, contents)) {
268 if (cur.pos() || cur.par() != 0) {
269 CursorSlice tmp = cur.top();
272 if (!gotoNextInset(cur, codes, contents)) {
274 cur.message(_("No more insets"));
277 cur.message(_("No more insets"));
284 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
286 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
290 void LyXText::cursorPrevious(LCursor & cur)
292 pos_type cpos = cur.pos();
293 lyx::par_type cpar = cur.par();
295 int x = cur.x_target();
296 int y = bv()->top_y();
297 setCursorFromCoordinates(cur, x, y);
299 if (cpar == cur.par() && cpos == cur.pos()) {
300 // we have a row which is taller than the workarea. The
301 // simplest solution is to move to the previous row instead.
305 bv()->updateScrollbar();
310 void LyXText::cursorNext(LCursor & cur)
312 pos_type cpos = cur.pos();
313 lyx::par_type cpar = cur.par();
315 int x = cur.x_target();
316 int y = bv()->top_y() + bv()->workHeight();
317 setCursorFromCoordinates(cur, x, y);
319 if (cpar == cur.par() && cpos == cur.pos()) {
320 // we have a row which is taller than the workarea. The
321 // simplest solution is to move to the next row instead.
325 bv()->updateScrollbar();
332 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
334 lyx::cap::replaceSelection(cur);
335 cur.insert(new InsetSpecialChar(kind));
339 void doInsertInset(LCursor & cur, LyXText * text,
340 FuncRequest const & cmd, bool edit, bool pastesel)
342 InsetBase * inset = createInset(&cur.bv(), cmd);
348 if (cur.selection()) {
349 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
352 text->insertInset(cur, inset);
354 inset->edit(cur, true);
355 if (gotsel && pastesel)
356 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
362 void LyXText::number(LCursor & cur)
364 LyXFont font(LyXFont::ALL_IGNORE);
365 font.setNumber(LyXFont::TOGGLE);
366 toggleAndShow(cur, this, font);
370 bool LyXText::isRTL(Paragraph const & par) const
372 return par.isRightToLeftPar(bv()->buffer()->params());
376 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
378 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
379 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
381 BOOST_ASSERT(cur.text() == this);
382 BufferView * bv = &cur.bv();
383 CursorSlice sl = cur.top();
385 switch (cmd.action) {
387 case LFUN_APPENDIX: {
388 Paragraph & par = cur.paragraph();
389 bool start = !par.params().startOfAppendix();
391 // ensure that we have only one start_of_appendix in this document
392 for (par_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
393 if (pars_[tmp].params().startOfAppendix()) {
395 pars_[tmp].params().startOfAppendix(false);
402 par.params().startOfAppendix(start);
404 // 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 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
465 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
466 if (isRTL(cur.paragraph()))
470 if (sl == cur.top()) {
472 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
478 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
479 cur.selHandle(cmd.action == LFUN_LEFTSEL);
480 if (isRTL(cur.paragraph()))
484 if (sl == cur.top()) {
486 cmd = FuncRequest(LFUN_FINISHED_LEFT);
492 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
493 cur.selHandle(cmd.action == LFUN_UPSEL);
495 if (sl == cur.top()) {
497 cmd = FuncRequest(LFUN_FINISHED_UP);
503 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
504 cur.selHandle(cmd.action == LFUN_DOWNSEL);
506 if (sl == cur.top()) {
508 cmd = FuncRequest(LFUN_FINISHED_DOWN);
512 case LFUN_UP_PARAGRAPHSEL:
513 if (!cur.selection())
515 cursorUpParagraph(cur);
516 finishChange(cur, true);
519 case LFUN_DOWN_PARAGRAPHSEL:
520 if (!cur.selection())
522 cursorDownParagraph(cur);
523 finishChange(cur, true);
527 if (!cur.selection())
530 finishChange(cur, true);
534 if (!cur.selection())
537 finishChange(cur, true);
541 if (!cur.selection())
544 finishChange(cur, true);
548 if (!cur.selection())
551 finishChange(cur, true);
554 case LFUN_WORDRIGHTSEL:
555 if (!cur.selection())
557 if (isRTL(cur.paragraph()))
558 cursorLeftOneWord(cur);
560 cursorRightOneWord(cur);
561 finishChange(cur, true);
564 case LFUN_WORDLEFTSEL:
565 if (!cur.selection())
567 if (isRTL(cur.paragraph()))
568 cursorRightOneWord(cur);
570 cursorLeftOneWord(cur);
571 finishChange(cur, true);
575 selectWord(cur, lyx::WHOLE_WORD);
576 finishChange(cur, true);
580 case LFUN_UP_PARAGRAPH:
582 cur.clearSelection();
583 cursorUpParagraph(cur);
584 finishChange(cur, false);
587 case LFUN_DOWN_PARAGRAPH:
589 cur.clearSelection();
590 cursorDownParagraph(cur);
591 finishChange(cur, false);
596 cur.clearSelection();
597 finishChange(cur, false);
598 if (cur.par() == 0 && cur.textRow().pos() == 0) {
600 cmd = FuncRequest(LFUN_FINISHED_UP);
608 cur.clearSelection();
609 finishChange(cur, false);
610 if (cur.par() == cur.lastpar()
611 && cur.textRow().endpos() == cur.lastpos()) {
613 cmd = FuncRequest(LFUN_FINISHED_DOWN);
621 cur.clearSelection();
623 finishChange(cur, false);
628 cur.clearSelection();
630 finishChange(cur, false);
633 case LFUN_BREAKLINE: {
634 // Not allowed by LaTeX (labels or empty par)
635 if (cur.pos() > cur.paragraph().beginOfBody()) {
636 lyx::cap::replaceSelection(cur);
637 cur.insert(new InsetNewline);
638 moveCursor(cur, false);
644 if (!cur.selection()) {
647 // It is possible to make it a lot faster still
648 // just comment out the line below...
650 cutSelection(cur, true, false);
652 moveCursor(cur, false);
655 case LFUN_DELETE_SKIP:
656 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
657 if (!cur.selection()) {
658 if (cur.pos() == cur.lastpos()) {
665 cutSelection(cur, true, false);
671 if (!cur.selection()) {
672 if (bv->owner()->getIntl().getTransManager().backspace()) {
675 // It is possible to make it a lot faster still
676 // just comment out the line below...
679 cutSelection(cur, true, false);
684 case LFUN_BACKSPACE_SKIP:
685 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
686 if (!cur.selection()) {
690 //CursorSlice cur = cursor();
694 cutSelection(cur, true, false);
698 case LFUN_BREAKPARAGRAPH:
699 lyx::cap::replaceSelection(cur);
700 breakParagraph(cur, 0);
705 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
706 lyx::cap::replaceSelection(cur);
707 breakParagraph(cur, 1);
712 case LFUN_BREAKPARAGRAPH_SKIP: {
713 // When at the beginning of a paragraph, remove
714 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
715 lyx::cap::replaceSelection(cur);
717 cur.paragraph().params().labelWidthString(string());
719 breakParagraph(cur, 0);
725 case LFUN_PARAGRAPH_SPACING: {
726 Paragraph & par = cur.paragraph();
727 Spacing::Space cur_spacing = par.params().spacing().getSpace();
728 float cur_value = 1.0;
729 if (cur_spacing == Spacing::Other)
730 cur_value = par.params().spacing().getValue();
732 istringstream is(cmd.argument);
735 Spacing::Space new_spacing = cur_spacing;
736 float new_value = cur_value;
738 lyxerr << "Missing argument to `paragraph-spacing'"
740 } else if (tmp == "single") {
741 new_spacing = Spacing::Single;
742 } else if (tmp == "onehalf") {
743 new_spacing = Spacing::Onehalf;
744 } else if (tmp == "double") {
745 new_spacing = Spacing::Double;
746 } else if (tmp == "other") {
747 new_spacing = Spacing::Other;
750 lyxerr << "new_value = " << tmpval << endl;
753 } else if (tmp == "default") {
754 new_spacing = Spacing::Default;
756 lyxerr << _("Unknown spacing argument: ")
757 << cmd.argument << endl;
759 if (cur_spacing != new_spacing || cur_value != new_value) {
760 par.params().spacing(Spacing(new_spacing, new_value));
766 case LFUN_INSET_APPLY: {
767 string const name = cmd.getArg(0);
768 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
770 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
771 inset->dispatch(cur, fr);
773 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
779 case LFUN_INSET_INSERT: {
781 InsetBase * inset = createInset(bv, cmd);
783 insertInset(cur, inset);
787 case LFUN_INSET_SETTINGS:
788 if (cur.inset().asUpdatableInset())
789 cur.inset().asUpdatableInset()->showInsetDialog(bv);
792 case LFUN_NEXT_INSET_TOGGLE: {
793 InsetBase * inset = cur.nextInset();
795 cur.clearSelection();
796 FuncRequest fr = cmd;
797 fr.action = LFUN_INSET_TOGGLE;
798 inset->dispatch(cur, fr);
803 case LFUN_KEYMAP_TOGGLE:
804 cur.clearSelection();
808 case LFUN_SPACE_INSERT:
809 if (cur.paragraph().layout()->free_spacing)
810 insertChar(cur, ' ');
812 doInsertInset(cur, this, cmd, false, false);
813 moveCursor(cur, false);
816 case LFUN_HYPHENATION:
817 specialChar(cur, InsetSpecialChar::HYPHENATION);
820 case LFUN_LIGATURE_BREAK:
821 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
825 specialChar(cur, InsetSpecialChar::LDOTS);
828 case LFUN_END_OF_SENTENCE:
829 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
832 case LFUN_MENU_SEPARATOR:
833 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
836 case LFUN_UPCASE_WORD:
837 changeCase(cur, LyXText::text_uppercase);
840 case LFUN_LOWCASE_WORD:
841 changeCase(cur, LyXText::text_lowercase);
844 case LFUN_CAPITALIZE_WORD:
845 changeCase(cur, LyXText::text_capitalization);
848 case LFUN_TRANSPOSE_CHARS:
854 cur.message(_("Paste"));
855 lyx::cap::replaceSelection(cur);
857 #warning FIXME Check if the arg is in the domain of available selections.
859 if (isStrUnsignedInt(cmd.argument))
860 pasteSelection(cur, strToUnsignedInt(cmd.argument));
862 pasteSelection(cur, 0);
863 cur.clearSelection(); // bug 393
869 cutSelection(cur, true, true);
870 cur.message(_("Cut"));
875 cur.message(_("Copy"));
879 cur.message(tostr(cursorX(cur.top())) + ' '
880 + tostr(cursorY(cur.top())));
886 istringstream is(cmd.argument);
889 lyxerr << "SETXY: Could not parse coordinates in '"
890 << cmd.argument << std::endl;
892 setCursorFromCoordinates(cur, x, y);
897 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
899 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
906 cur.message(cur.paragraph().layout()->name());
910 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
911 << cmd.argument << endl;
913 // This is not the good solution to the empty argument
914 // problem, but it will hopefully suffice for 1.2.0.
915 // The correct solution would be to augument the
916 // function list/array with information about what
917 // functions needs arguments and their type.
918 if (cmd.argument.empty()) {
919 cur.errorMessage(_("LyX function 'layout' needs an argument."));
923 // Derive layout number from given argument (string)
924 // and current buffer's textclass (number)
925 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
926 bool hasLayout = tclass.hasLayout(cmd.argument);
927 string layout = cmd.argument;
929 // If the entry is obsolete, use the new one instead.
931 string const & obs = tclass[layout]->obsoleted_by();
937 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
942 bool change_layout = (current_layout != layout);
944 if (!change_layout && cur.selection() &&
945 cur.selBegin().par() != cur.selEnd().par())
947 par_type spit = cur.selBegin().par();
948 par_type epit = cur.selEnd().par() + 1;
949 while (spit != epit) {
950 if (pars_[spit].layout()->name() != current_layout) {
951 change_layout = true;
959 current_layout = layout;
960 setLayout(cur, layout);
961 bv->owner()->setLayout(layout);
967 case LFUN_PASTESELECTION: {
968 cur.clearSelection();
969 string const clip = bv->getClipboard();
971 if (cmd.argument == "paragraph")
972 insertStringAsParagraphs(cur, clip);
974 insertStringAsLines(cur, clip);
980 gotoInset(cur, InsetBase::ERROR_CODE, false);
984 gotoInset(cur, InsetBase::NOTE_CODE, false);
987 case LFUN_REFERENCE_GOTO: {
988 vector<InsetOld_code> tmp;
989 tmp.push_back(InsetBase::LABEL_CODE);
990 tmp.push_back(InsetBase::REF_CODE);
991 gotoInset(cur, tmp, true);
996 lyx::cap::replaceSelection(cur);
997 Paragraph & par = cur.paragraph();
998 lyx::pos_type pos = cur.pos();
1002 else if (cur.prevInset() && cur.prevInset()->isSpace())
1005 c = par.getChar(pos - 1);
1007 LyXLayout_ptr const & style = par.layout();
1009 BufferParams const & bufparams = bv->buffer()->params();
1010 if (!style->pass_thru
1011 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1012 string arg = cmd.argument;
1013 if (arg == "single")
1014 cur.insert(new InsetQuotes(c,
1015 bufparams.quotes_language,
1016 InsetQuotes::SingleQ));
1017 else if (arg == "double")
1018 cur.insert(new InsetQuotes(c,
1019 bufparams.quotes_language,
1020 InsetQuotes::DoubleQ));
1022 cur.insert(new InsetQuotes(c, bufparams));
1025 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1029 case LFUN_DATE_INSERT: {
1030 lyx::cap::replaceSelection(cur);
1031 time_t now_time_t = time(NULL);
1032 struct tm * now_tm = localtime(&now_time_t);
1033 setlocale(LC_TIME, "");
1035 if (!cmd.argument.empty())
1038 arg = lyxrc.date_insert_format;
1040 int const datetmp_len =
1041 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1043 for (int i = 0; i < datetmp_len; i++)
1044 insertChar(cur, datetmp[i]);
1047 moveCursor(cur, false);
1051 case LFUN_MOUSE_TRIPLE:
1052 if (cmd.button() == mouse_button::button1) {
1053 selection_possible = true;
1058 bv->haveSelection(cur.selection());
1062 case LFUN_MOUSE_DOUBLE:
1063 if (cmd.button() == mouse_button::button1) {
1064 selection_possible = true;
1065 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1066 bv->haveSelection(cur.selection());
1070 case LFUN_MOUSE_MOTION: {
1071 // Only use motion with button 1
1072 //if (cmd.button() != mouse_button::button1)
1074 // We want to use only motion events for which
1075 // the button press event was on the drawing area too.
1076 if (!selection_possible) {
1077 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1078 "dispatch: no selection possible\n";
1079 lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
1083 // ignore motions deeper nested than the real anchor
1084 LCursor & bvcur = cur.bv().cursor();
1085 if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
1088 CursorSlice old = cur.top();
1089 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1091 // This is to allow jumping over large insets
1092 // FIXME: shouldn't be top-text-specific
1093 if (isMainText() && cur.top() == old) {
1094 if (cmd.y - bv->top_y() >= bv->workHeight())
1096 else if (cmd.y - bv->top_y() < 0)
1100 // don't set anchor_
1101 bv->cursor().setCursor(cur, true);
1102 lyxerr << "MOTION: " << bv->cursor() << endl;
1106 // Single-click on work area
1107 case LFUN_MOUSE_PRESS: {
1108 // ok ok, this is a hack (for xforms)
1109 // We shouldn't go further down as we really need to. Only do the
1110 // scrolling and be done with this. Otherwise we may open some
1111 // dialogs (Jug 20020424).
1112 if (cmd.button() == mouse_button::button4) {
1113 bv->scroll(-lyxrc.wheel_jump);
1117 if (cmd.button() == mouse_button::button5) {
1118 bv->scroll(lyxrc.wheel_jump);
1122 // Right click on a footnote flag opens float menu
1123 if (cmd.button() == mouse_button::button3) {
1124 cur.clearSelection();
1125 selection_possible = false;
1129 // Middle button press pastes if we have a selection
1130 // We do this here as if the selection was inside an inset
1131 // it could get cleared on the unlocking of the inset so
1132 // we have to check this first
1133 bool paste_internally = false;
1134 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1135 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1136 paste_internally = true;
1139 selection_possible = true;
1141 // Clear the selection
1142 cur.clearSelection();
1144 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1147 cur.x_target() = cursorX(cur.top());
1152 // Don't allow selection after a big jump.
1153 if (bv->fitCursor())
1154 selection_possible = false;
1156 // Insert primary selection with middle mouse
1157 // if there is a local selection in the current buffer,
1159 if (cmd.button() == mouse_button::button2) {
1160 if (paste_internally)
1161 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1163 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1164 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, DEC_DEPTH);
1292 case LFUN_DEPTH_PLUS:
1293 changeDepth(cur, INC_DEPTH);
1296 case LFUN_MATH_DISPLAY:
1297 mathDispatch(cur, cmd, true);
1300 case LFUN_MATH_IMPORT_SELECTION:
1301 case LFUN_MATH_MODE:
1302 mathDispatch(cur, cmd, false);
1305 case LFUN_MATH_MACRO:
1306 if (cmd.argument.empty())
1307 cur.errorMessage(N_("Missing argument"));
1309 string s = cmd.argument;
1310 string const s1 = token(s, ' ', 1);
1311 int const nargs = s1.empty() ? 0 : atoi(s1);
1312 string const s2 = token(s, ' ', 2);
1313 string const type = s2.empty() ? "newcommand" : s2;
1314 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1315 cur.nextInset()->edit(cur, true);
1319 case LFUN_INSERT_MATH:
1320 case LFUN_INSERT_MATRIX:
1321 case LFUN_MATH_DELIM: {
1322 cur.insert(new MathHullInset);
1323 cur.dispatch(FuncRequest(LFUN_RIGHT));
1324 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1330 LyXFont font(LyXFont::ALL_IGNORE);
1331 font.setEmph(LyXFont::TOGGLE);
1332 toggleAndShow(cur, this, font);
1337 LyXFont font(LyXFont::ALL_IGNORE);
1338 font.setSeries(LyXFont::BOLD_SERIES);
1339 toggleAndShow(cur, this, font);
1344 LyXFont font(LyXFont::ALL_IGNORE);
1345 font.setNoun(LyXFont::TOGGLE);
1346 toggleAndShow(cur, this, font);
1351 LyXFont font(LyXFont::ALL_IGNORE);
1352 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1353 toggleAndShow(cur, this, font);
1358 LyXFont font(LyXFont::ALL_IGNORE);
1359 font.setFamily(LyXFont::SANS_FAMILY);
1360 toggleAndShow(cur, this, font);
1365 LyXFont font(LyXFont::ALL_IGNORE);
1366 font.setFamily(LyXFont::ROMAN_FAMILY);
1367 toggleAndShow(cur, this, font);
1371 case LFUN_DEFAULT: {
1372 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1373 toggleAndShow(cur, this, font);
1377 case LFUN_UNDERLINE: {
1378 LyXFont font(LyXFont::ALL_IGNORE);
1379 font.setUnderbar(LyXFont::TOGGLE);
1380 toggleAndShow(cur, this, font);
1384 case LFUN_FONT_SIZE: {
1385 LyXFont font(LyXFont::ALL_IGNORE);
1386 font.setLyXSize(cmd.argument);
1387 toggleAndShow(cur, this, font);
1391 case LFUN_LANGUAGE: {
1392 Language const * lang = languages.getLanguage(cmd.argument);
1395 LyXFont font(LyXFont::ALL_IGNORE);
1396 font.setLanguage(lang);
1397 toggleAndShow(cur, this, font);
1402 case LFUN_FREEFONT_APPLY:
1403 toggleAndShow(cur, this, freefont, toggleall);
1404 cur.message(_("Character set"));
1407 // Set the freefont using the contents of \param data dispatched from
1408 // the frontends and apply it at the current cursor location.
1409 case LFUN_FREEFONT_UPDATE: {
1412 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1415 toggleAndShow(cur, this, freefont, toggleall);
1416 cur.message(_("Character set"));
1421 case LFUN_FINISHED_LEFT:
1422 lyxerr << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1425 case LFUN_FINISHED_RIGHT:
1426 lyxerr << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1430 case LFUN_FINISHED_UP:
1431 lyxerr << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1435 case LFUN_FINISHED_DOWN:
1436 lyxerr << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1440 case LFUN_LAYOUT_PARAGRAPH: {
1442 params2string(cur.paragraph(), data);
1443 data = "show\n" + data;
1444 bv->owner()->getDialogs().show("paragraph", data);
1448 case LFUN_PARAGRAPH_UPDATE: {
1449 if (!bv->owner()->getDialogs().visible("paragraph"))
1452 params2string(cur.paragraph(), data);
1454 // Will the paragraph accept changes from the dialog?
1455 InsetBase & inset = cur.inset();
1456 bool const accept = !inset.forceDefaultParagraphs(&inset);
1458 data = "update " + tostr(accept) + '\n' + data;
1459 bv->owner()->getDialogs().update("paragraph", data);
1464 case LFUN_CIRCUMFLEX:
1474 case LFUN_SPECIAL_CARON:
1477 case LFUN_HUNG_UMLAUT:
1480 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1481 if (!cmd.argument.empty())
1482 bv->owner()->getIntl().getTransManager()
1483 .TranslateAndInsert(cmd.argument[0], this);
1486 case LFUN_FLOAT_LIST: {
1487 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1488 if (tclass.floats().typeExist(cmd.argument)) {
1489 // not quite sure if we want this...
1491 cur.clearSelection();
1492 breakParagraph(cur);
1494 if (cur.lastpos() != 0) {
1496 breakParagraph(cur);
1499 setLayout(cur, tclass.defaultLayoutName());
1500 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1501 insertInset(cur, new InsetFloatList(cmd.argument));
1503 lyxerr << "Non-existent float type: "
1504 << cmd.argument << endl;
1509 case LFUN_ACCEPT_CHANGE: {
1514 case LFUN_REJECT_CHANGE: {
1519 case LFUN_THESAURUS_ENTRY: {
1520 string arg = cmd.argument;
1522 arg = cur.selectionAsString(false);
1524 if (arg.size() > 100 || arg.empty()) {
1525 // Get word or selection
1526 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1527 arg = cur.selectionAsString(false);
1530 bv->owner()->getDialogs().show("thesaurus", arg);
1534 case LFUN_PARAGRAPH_APPLY: {
1535 // Given data, an encoding of the ParagraphParameters
1536 // generated in the Paragraph dialog, this function sets
1537 // the current paragraph appropriately.
1538 istringstream is(cmd.argument);
1541 ParagraphParameters params;
1546 params.labelWidthString(),
1548 cur.message(_("Paragraph layout set"));
1552 case LFUN_INSET_DIALOG_SHOW: {
1553 InsetBase * inset = cur.nextInset();
1555 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1556 inset->dispatch(cur, fr);
1562 if (cur.selection()) {
1563 cur.selection() = false;
1566 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1577 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1578 FuncStatus & flag) const
1580 BOOST_ASSERT(cur.text() == this);
1581 LyXFont const & font = real_current_font;
1584 switch (cmd.action) {
1586 case LFUN_DEPTH_MIN:
1587 enable = changeDepthAllowed(cur, DEC_DEPTH);
1590 case LFUN_DEPTH_PLUS:
1591 enable = changeDepthAllowed(cur, INC_DEPTH);
1594 case LFUN_INSET_OPTARG:
1595 enable = cur.paragraph().layout()->optionalargs;
1599 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1603 // the functions which insert insets
1604 InsetOld::Code code = InsetOld::NO_CODE;
1605 switch (cmd.action) {
1606 case LFUN_DIALOG_SHOW_NEW_INSET:
1607 if (cmd.argument == "bibitem")
1608 code = InsetOld::BIBITEM_CODE;
1609 else if (cmd.argument == "bibtex")
1610 code = InsetOld::BIBTEX_CODE;
1611 else if (cmd.argument == "box")
1612 code = InsetOld::BOX_CODE;
1613 else if (cmd.argument == "branch")
1614 code = InsetOld::BRANCH_CODE;
1615 else if (cmd.argument == "citation")
1616 code = InsetOld::CITE_CODE;
1617 else if (cmd.argument == "ert")
1618 code = InsetOld::ERT_CODE;
1619 else if (cmd.argument == "external")
1620 code = InsetOld::EXTERNAL_CODE;
1621 else if (cmd.argument == "float")
1622 code = InsetOld::FLOAT_CODE;
1623 else if (cmd.argument == "graphics")
1624 code = InsetOld::GRAPHICS_CODE;
1625 else if (cmd.argument == "include")
1626 code = InsetOld::INCLUDE_CODE;
1627 else if (cmd.argument == "index")
1628 code = InsetOld::INDEX_CODE;
1629 else if (cmd.argument == "label")
1630 code = InsetOld::LABEL_CODE;
1631 else if (cmd.argument == "note")
1632 code = InsetOld::NOTE_CODE;
1633 else if (cmd.argument == "ref")
1634 code = InsetOld::REF_CODE;
1635 else if (cmd.argument == "toc")
1636 code = InsetOld::TOC_CODE;
1637 else if (cmd.argument == "url")
1638 code = InsetOld::URL_CODE;
1639 else if (cmd.argument == "vspace")
1640 code = InsetOld::VSPACE_CODE;
1641 else if (cmd.argument == "wrap")
1642 code = InsetOld::WRAP_CODE;
1645 case LFUN_INSET_ERT:
1646 code = InsetOld::ERT_CODE;
1648 case LFUN_INSET_FOOTNOTE:
1649 code = InsetOld::FOOT_CODE;
1651 case LFUN_TABULAR_INSERT:
1652 code = InsetOld::TABULAR_CODE;
1654 case LFUN_INSET_MARGINAL:
1655 code = InsetOld::MARGIN_CODE;
1657 case LFUN_INSET_FLOAT:
1658 case LFUN_INSET_WIDE_FLOAT:
1659 code = InsetOld::FLOAT_CODE;
1661 case LFUN_INSET_WRAP:
1662 code = InsetOld::WRAP_CODE;
1664 case LFUN_FLOAT_LIST:
1665 code = InsetOld::FLOAT_LIST_CODE;
1668 case LFUN_INSET_LIST:
1669 code = InsetOld::LIST_CODE;
1671 case LFUN_INSET_THEOREM:
1672 code = InsetOld::THEOREM_CODE;
1675 case LFUN_INSET_CAPTION:
1676 code = InsetOld::CAPTION_CODE;
1678 case LFUN_INSERT_NOTE:
1679 code = InsetOld::NOTE_CODE;
1681 case LFUN_INSERT_CHARSTYLE:
1682 code = InsetOld::CHARSTYLE_CODE;
1683 if (buf->params().getLyXTextClass().charstyles().empty())
1686 case LFUN_INSERT_BOX:
1687 code = InsetOld::BOX_CODE;
1689 case LFUN_INSERT_BRANCH:
1690 code = InsetOld::BRANCH_CODE;
1691 if (buf->params().branchlist().empty())
1694 case LFUN_INSERT_LABEL:
1695 code = InsetOld::LABEL_CODE;
1697 case LFUN_INSET_OPTARG:
1698 code = InsetOld::OPTARG_CODE;
1700 case LFUN_ENVIRONMENT_INSERT:
1701 code = InsetOld::BOX_CODE;
1703 case LFUN_INDEX_INSERT:
1704 code = InsetOld::INDEX_CODE;
1706 case LFUN_INDEX_PRINT:
1707 code = InsetOld::INDEX_PRINT_CODE;
1709 case LFUN_TOC_INSERT:
1710 code = InsetOld::TOC_CODE;
1714 code = InsetOld::URL_CODE;
1717 // always allow this, since we will inset a raw quote
1718 // if an inset is not allowed.
1720 case LFUN_HYPHENATION:
1721 case LFUN_LIGATURE_BREAK:
1723 case LFUN_MENU_SEPARATOR:
1725 case LFUN_END_OF_SENTENCE:
1726 code = InsetOld::SPECIALCHAR_CODE;
1728 case LFUN_SPACE_INSERT:
1729 // slight hack: we know this is allowed in math mode
1731 code = InsetOld::SPACE_CODE;
1733 case LFUN_INSET_DIALOG_SHOW: {
1734 InsetBase * inset = cur.nextInset();
1737 code = inset->lyxCode();
1738 if (!(code == InsetOld::INCLUDE_CODE
1739 || code == InsetOld::BIBTEX_CODE
1740 || code == InsetOld::FLOAT_LIST_CODE
1741 || code == InsetOld::TOC_CODE))
1750 if (code != InsetOld::NO_CODE
1751 && (cur.empty() || !cur.inset().insetAllowed(code)))
1756 case LFUN_DIALOG_SHOW_NEW_INSET:
1757 case LFUN_INSET_ERT:
1758 case LFUN_INSERT_BOX:
1759 case LFUN_INSERT_BRANCH:
1760 case LFUN_ENVIRONMENT_INSERT:
1761 case LFUN_INDEX_INSERT:
1762 case LFUN_INDEX_PRINT:
1763 case LFUN_TOC_INSERT:
1767 case LFUN_HYPHENATION:
1768 case LFUN_LIGATURE_BREAK:
1770 case LFUN_MENU_SEPARATOR:
1772 case LFUN_END_OF_SENTENCE:
1773 case LFUN_SPACE_INSERT:
1774 case LFUN_INSET_DIALOG_SHOW:
1778 flag.setOnOff(font.emph() == LyXFont::ON);
1782 flag.setOnOff(font.noun() == LyXFont::ON);
1786 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1790 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1794 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1798 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1801 case LFUN_DELETE_WORD_FORWARD:
1802 case LFUN_DELETE_WORD_BACKWARD:
1803 case LFUN_DELETE_LINE_FORWARD:
1804 case LFUN_WORDRIGHT:
1807 case LFUN_BEGINNINGBUF:
1816 case LFUN_UP_PARAGRAPHSEL:
1817 case LFUN_DOWN_PARAGRAPHSEL:
1822 case LFUN_WORDRIGHTSEL:
1823 case LFUN_WORDLEFTSEL:
1825 case LFUN_UP_PARAGRAPH:
1826 case LFUN_DOWN_PARAGRAPH:
1831 case LFUN_BREAKLINE:
1833 case LFUN_DELETE_SKIP:
1834 case LFUN_BACKSPACE:
1835 case LFUN_BACKSPACE_SKIP:
1836 case LFUN_BREAKPARAGRAPH:
1837 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1838 case LFUN_BREAKPARAGRAPH_SKIP:
1839 case LFUN_PARAGRAPH_SPACING:
1840 case LFUN_INSET_APPLY:
1841 case LFUN_INSET_INSERT:
1842 case LFUN_NEXT_INSET_TOGGLE:
1843 case LFUN_UPCASE_WORD:
1844 case LFUN_LOWCASE_WORD:
1845 case LFUN_CAPITALIZE_WORD:
1846 case LFUN_TRANSPOSE_CHARS:
1853 case LFUN_GETLAYOUT:
1855 case LFUN_PASTESELECTION:
1856 case LFUN_GOTOERROR:
1858 case LFUN_REFERENCE_GOTO:
1859 case LFUN_DATE_INSERT:
1860 case LFUN_SELFINSERT:
1861 case LFUN_INSERT_LABEL:
1862 case LFUN_INSERT_NOTE:
1863 case LFUN_INSERT_CHARSTYLE:
1864 case LFUN_INSERT_BIBITEM:
1865 case LFUN_INSET_FLOAT:
1866 case LFUN_INSET_FOOTNOTE:
1867 case LFUN_INSET_MARGINAL:
1868 case LFUN_INSET_WIDE_FLOAT:
1869 case LFUN_INSET_WRAP:
1870 case LFUN_TABULAR_INSERT:
1871 case LFUN_INSERT_LINE:
1872 case LFUN_INSERT_PAGEBREAK:
1873 case LFUN_MATH_DISPLAY:
1874 case LFUN_MATH_IMPORT_SELECTION:
1875 case LFUN_MATH_MODE:
1876 case LFUN_MATH_MACRO:
1877 case LFUN_INSERT_MATH:
1878 case LFUN_INSERT_MATRIX:
1879 case LFUN_MATH_DELIM:
1881 case LFUN_UNDERLINE:
1882 case LFUN_FONT_SIZE:
1884 case LFUN_FREEFONT_APPLY:
1885 case LFUN_FREEFONT_UPDATE:
1886 case LFUN_LAYOUT_PARAGRAPH:
1887 case LFUN_PARAGRAPH_UPDATE:
1889 case LFUN_CIRCUMFLEX:
1899 case LFUN_SPECIAL_CARON:
1902 case LFUN_HUNG_UMLAUT:
1905 case LFUN_FLOAT_LIST:
1906 case LFUN_ACCEPT_CHANGE:
1907 case LFUN_REJECT_CHANGE:
1908 case LFUN_THESAURUS_ENTRY:
1909 case LFUN_PARAGRAPH_APPLY:
1911 case LFUN_KEYMAP_TOGGLE:
1912 // these are handled in our dispatch()
1920 flag.enabled(enable);