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 lyxerr << " pit: " << pit << " end: " << end << endl;
198 for ( ; pit != end; ++pit) {
199 InsetList::iterator iit = pars_[pit].insetlist.begin();
200 InsetList::iterator iend = pars_[pit].insetlist.end();
201 for ( ; iit != iend; ++iit) {
202 InsetBase * inset = iit->inset;
204 lyxerr << "examining inset " << inset
205 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
206 << " yo: " << inset->yo() - inset->ascent() << "..."
207 << inset->yo() + inset->descent() << endl;
209 if (inset->covers(x, y)) {
210 lyxerr << "Hit inset: " << inset << endl;
215 //lyxerr << "No inset hit. " << endl;
220 bool LyXText::gotoNextInset(LCursor & cur,
221 vector<InsetOld_code> const & codes, string const & contents)
223 BOOST_ASSERT(this == cur.text());
224 par_type end = paragraphs().size();
225 par_type pit = cur.par();
226 pos_type pos = cur.pos();
230 if (pos + 1 < pars_[pit].size()) {
237 } while (pit != end &&
238 !(pars_[pit].isInset(pos) &&
239 (inset = pars_[pit].getInset(pos)) != 0 &&
240 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
242 static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
248 setCursor(cur, pit, pos, false);
253 void LyXText::gotoInset(LCursor & cur,
254 vector<InsetOld_code> const & codes, bool same_content)
256 cur.clearSelection();
260 && cur.pos() < cur.lastpos()
261 && cur.paragraph().isInset(cur.pos())) {
262 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
263 if (find(codes.begin(), codes.end(), inset->lyxCode())
265 contents = static_cast<InsetCommand const *>(inset)->getContents();
268 if (!gotoNextInset(cur, codes, contents)) {
269 if (cur.pos() || cur.par() != 0) {
270 CursorSlice tmp = cur.top();
273 if (!gotoNextInset(cur, codes, contents)) {
275 cur.message(_("No more insets"));
278 cur.message(_("No more insets"));
285 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
287 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
291 void LyXText::cursorPrevious(LCursor & cur)
293 pos_type cpos = cur.pos();
294 lyx::par_type cpar = cur.par();
296 int x = cur.x_target();
297 int y = bv()->top_y();
298 setCursorFromCoordinates(cur, x, y);
300 if (cpar == cur.par() && cpos == cur.pos()) {
301 // we have a row which is taller than the workarea. The
302 // simplest solution is to move to the previous row instead.
306 bv()->updateScrollbar();
311 void LyXText::cursorNext(LCursor & cur)
313 pos_type cpos = cur.pos();
314 lyx::par_type cpar = cur.par();
316 int x = cur.x_target();
317 int y = bv()->top_y() + bv()->workHeight();
318 setCursorFromCoordinates(cur, x, y);
320 if (cpar == cur.par() && cpos == cur.pos()) {
321 // we have a row which is taller than the workarea. The
322 // simplest solution is to move to the next row instead.
326 bv()->updateScrollbar();
333 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
335 lyx::cap::replaceSelection(cur);
336 cur.insert(new InsetSpecialChar(kind));
340 void doInsertInset(LCursor & cur, LyXText * text,
341 FuncRequest const & cmd, bool edit, bool pastesel)
343 InsetBase * inset = createInset(&cur.bv(), cmd);
349 if (cur.selection()) {
350 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
353 text->insertInset(cur, inset);
355 inset->edit(cur, true);
356 if (gotsel && pastesel)
357 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
363 void LyXText::number(LCursor & cur)
365 LyXFont font(LyXFont::ALL_IGNORE);
366 font.setNumber(LyXFont::TOGGLE);
367 toggleAndShow(cur, this, font);
371 bool LyXText::isRTL(Paragraph const & par) const
373 return par.isRightToLeftPar(bv()->buffer()->params());
377 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
379 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
380 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
382 BOOST_ASSERT(cur.text() == this);
383 BufferView * bv = &cur.bv();
384 CursorSlice sl = cur.top();
386 switch (cmd.action) {
388 case LFUN_APPENDIX: {
389 Paragraph & par = cur.paragraph();
390 bool start = !par.params().startOfAppendix();
392 // ensure that we have only one start_of_appendix in this document
393 for (par_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
394 if (pars_[tmp].params().startOfAppendix()) {
396 pars_[tmp].params().startOfAppendix(false);
403 par.params().startOfAppendix(start);
405 // we can set the refreshing parameters now
411 case LFUN_DELETE_WORD_FORWARD:
412 cur.clearSelection();
413 deleteWordForward(cur);
414 finishChange(cur, false);
417 case LFUN_DELETE_WORD_BACKWARD:
418 cur.clearSelection();
419 deleteWordBackward(cur);
420 finishChange(cur, false);
423 case LFUN_DELETE_LINE_FORWARD:
424 cur.clearSelection();
425 deleteLineForward(cur);
426 finishChange(cur, false);
431 cur.clearSelection();
432 if (isRTL(cur.paragraph()))
433 cursorLeftOneWord(cur);
435 cursorRightOneWord(cur);
436 finishChange(cur, false);
441 cur.clearSelection();
442 if (isRTL(cur.paragraph()))
443 cursorRightOneWord(cur);
445 cursorLeftOneWord(cur);
446 finishChange(cur, false);
449 case LFUN_BEGINNINGBUF:
451 cur.clearSelection();
453 finishChange(cur, false);
458 cur.clearSelection();
460 finishChange(cur, false);
465 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
466 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
467 if (isRTL(cur.paragraph()))
471 if (sl == cur.top()) {
473 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
479 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
480 cur.selHandle(cmd.action == LFUN_LEFTSEL);
481 if (isRTL(cur.paragraph()))
485 if (sl == cur.top()) {
487 cmd = FuncRequest(LFUN_FINISHED_LEFT);
493 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
494 cur.selHandle(cmd.action == LFUN_UPSEL);
496 if (sl == cur.top()) {
498 cmd = FuncRequest(LFUN_FINISHED_UP);
504 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
505 cur.selHandle(cmd.action == LFUN_DOWNSEL);
507 if (sl == cur.top()) {
509 cmd = FuncRequest(LFUN_FINISHED_DOWN);
513 case LFUN_UP_PARAGRAPHSEL:
514 if (!cur.selection())
516 cursorUpParagraph(cur);
517 finishChange(cur, true);
520 case LFUN_DOWN_PARAGRAPHSEL:
521 if (!cur.selection())
523 cursorDownParagraph(cur);
524 finishChange(cur, true);
528 if (!cur.selection())
531 finishChange(cur, true);
535 if (!cur.selection())
538 finishChange(cur, true);
542 if (!cur.selection())
545 finishChange(cur, true);
549 if (!cur.selection())
552 finishChange(cur, true);
555 case LFUN_WORDRIGHTSEL:
556 if (!cur.selection())
558 if (isRTL(cur.paragraph()))
559 cursorLeftOneWord(cur);
561 cursorRightOneWord(cur);
562 finishChange(cur, true);
565 case LFUN_WORDLEFTSEL:
566 if (!cur.selection())
568 if (isRTL(cur.paragraph()))
569 cursorRightOneWord(cur);
571 cursorLeftOneWord(cur);
572 finishChange(cur, true);
576 selectWord(cur, lyx::WHOLE_WORD);
577 finishChange(cur, true);
581 case LFUN_UP_PARAGRAPH:
583 cur.clearSelection();
584 cursorUpParagraph(cur);
585 finishChange(cur, false);
588 case LFUN_DOWN_PARAGRAPH:
590 cur.clearSelection();
591 cursorDownParagraph(cur);
592 finishChange(cur, false);
597 cur.clearSelection();
598 finishChange(cur, false);
599 if (cur.par() == 0 && cur.textRow().pos() == 0) {
601 cmd = FuncRequest(LFUN_FINISHED_UP);
609 cur.clearSelection();
610 finishChange(cur, false);
611 if (cur.par() == cur.lastpar()
612 && cur.textRow().endpos() == cur.lastpos()) {
614 cmd = FuncRequest(LFUN_FINISHED_DOWN);
622 cur.clearSelection();
624 finishChange(cur, false);
629 cur.clearSelection();
631 finishChange(cur, false);
634 case LFUN_BREAKLINE: {
635 // Not allowed by LaTeX (labels or empty par)
636 if (cur.pos() > cur.paragraph().beginOfBody()) {
637 lyx::cap::replaceSelection(cur);
638 cur.insert(new InsetNewline);
639 moveCursor(cur, false);
645 if (!cur.selection()) {
648 // It is possible to make it a lot faster still
649 // just comment out the line below...
651 cutSelection(cur, true, false);
653 moveCursor(cur, false);
656 case LFUN_DELETE_SKIP:
657 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
658 if (!cur.selection()) {
659 if (cur.pos() == cur.lastpos()) {
666 cutSelection(cur, true, false);
672 if (!cur.selection()) {
673 if (bv->owner()->getIntl().getTransManager().backspace()) {
676 // It is possible to make it a lot faster still
677 // just comment out the line below...
680 cutSelection(cur, true, false);
685 case LFUN_BACKSPACE_SKIP:
686 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
687 if (!cur.selection()) {
691 //CursorSlice cur = cursor();
695 cutSelection(cur, true, false);
699 case LFUN_BREAKPARAGRAPH:
700 lyx::cap::replaceSelection(cur);
701 breakParagraph(cur, 0);
706 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
707 lyx::cap::replaceSelection(cur);
708 breakParagraph(cur, 1);
713 case LFUN_BREAKPARAGRAPH_SKIP: {
714 // When at the beginning of a paragraph, remove
715 // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
716 lyx::cap::replaceSelection(cur);
718 cur.paragraph().params().labelWidthString(string());
720 breakParagraph(cur, 0);
726 case LFUN_PARAGRAPH_SPACING: {
727 Paragraph & par = cur.paragraph();
728 Spacing::Space cur_spacing = par.params().spacing().getSpace();
729 float cur_value = 1.0;
730 if (cur_spacing == Spacing::Other)
731 cur_value = par.params().spacing().getValue();
733 istringstream is(cmd.argument);
736 Spacing::Space new_spacing = cur_spacing;
737 float new_value = cur_value;
739 lyxerr << "Missing argument to `paragraph-spacing'"
741 } else if (tmp == "single") {
742 new_spacing = Spacing::Single;
743 } else if (tmp == "onehalf") {
744 new_spacing = Spacing::Onehalf;
745 } else if (tmp == "double") {
746 new_spacing = Spacing::Double;
747 } else if (tmp == "other") {
748 new_spacing = Spacing::Other;
751 lyxerr << "new_value = " << tmpval << endl;
754 } else if (tmp == "default") {
755 new_spacing = Spacing::Default;
757 lyxerr << _("Unknown spacing argument: ")
758 << cmd.argument << endl;
760 if (cur_spacing != new_spacing || cur_value != new_value) {
761 par.params().spacing(Spacing(new_spacing, new_value));
767 case LFUN_INSET_APPLY: {
768 string const name = cmd.getArg(0);
769 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
771 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
772 inset->dispatch(cur, fr);
774 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
780 case LFUN_INSET_INSERT: {
782 InsetBase * inset = createInset(bv, cmd);
784 insertInset(cur, inset);
788 case LFUN_INSET_SETTINGS:
789 if (cur.inset().asUpdatableInset())
790 cur.inset().asUpdatableInset()->showInsetDialog(bv);
793 case LFUN_NEXT_INSET_TOGGLE: {
794 InsetBase * inset = cur.nextInset();
796 cur.clearSelection();
797 FuncRequest fr = cmd;
798 fr.action = LFUN_INSET_TOGGLE;
799 inset->dispatch(cur, fr);
804 case LFUN_KEYMAP_TOGGLE:
805 cur.clearSelection();
809 case LFUN_SPACE_INSERT:
810 if (cur.paragraph().layout()->free_spacing)
811 insertChar(cur, ' ');
813 doInsertInset(cur, this, cmd, false, false);
814 moveCursor(cur, false);
817 case LFUN_HYPHENATION:
818 specialChar(cur, InsetSpecialChar::HYPHENATION);
821 case LFUN_LIGATURE_BREAK:
822 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
826 specialChar(cur, InsetSpecialChar::LDOTS);
829 case LFUN_END_OF_SENTENCE:
830 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
833 case LFUN_MENU_SEPARATOR:
834 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
837 case LFUN_UPCASE_WORD:
838 changeCase(cur, LyXText::text_uppercase);
841 case LFUN_LOWCASE_WORD:
842 changeCase(cur, LyXText::text_lowercase);
845 case LFUN_CAPITALIZE_WORD:
846 changeCase(cur, LyXText::text_capitalization);
849 case LFUN_TRANSPOSE_CHARS:
855 cur.message(_("Paste"));
856 lyx::cap::replaceSelection(cur);
858 #warning FIXME Check if the arg is in the domain of available selections.
860 if (isStrUnsignedInt(cmd.argument))
861 pasteSelection(cur, strToUnsignedInt(cmd.argument));
863 pasteSelection(cur, 0);
864 cur.clearSelection(); // bug 393
870 cutSelection(cur, true, true);
871 cur.message(_("Cut"));
876 cur.message(_("Copy"));
880 cur.message(tostr(cursorX(cur.top())) + ' '
881 + tostr(cursorY(cur.top())));
887 istringstream is(cmd.argument);
890 lyxerr << "SETXY: Could not parse coordinates in '"
891 << cmd.argument << std::endl;
893 setCursorFromCoordinates(cur, x, y);
898 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
900 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
907 cur.message(cur.paragraph().layout()->name());
911 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
912 << cmd.argument << endl;
914 // This is not the good solution to the empty argument
915 // problem, but it will hopefully suffice for 1.2.0.
916 // The correct solution would be to augument the
917 // function list/array with information about what
918 // functions needs arguments and their type.
919 if (cmd.argument.empty()) {
920 cur.errorMessage(_("LyX function 'layout' needs an argument."));
924 // Derive layout number from given argument (string)
925 // and current buffer's textclass (number)
926 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
927 bool hasLayout = tclass.hasLayout(cmd.argument);
928 string layout = cmd.argument;
930 // If the entry is obsolete, use the new one instead.
932 string const & obs = tclass[layout]->obsoleted_by();
938 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
943 bool change_layout = (current_layout != layout);
945 if (!change_layout && cur.selection() &&
946 cur.selBegin().par() != cur.selEnd().par())
948 par_type spit = cur.selBegin().par();
949 par_type epit = cur.selEnd().par() + 1;
950 while (spit != epit) {
951 if (pars_[spit].layout()->name() != current_layout) {
952 change_layout = true;
960 current_layout = layout;
961 setLayout(cur, layout);
962 bv->owner()->setLayout(layout);
968 case LFUN_PASTESELECTION: {
969 cur.clearSelection();
970 string const clip = bv->getClipboard();
972 if (cmd.argument == "paragraph")
973 insertStringAsParagraphs(cur, clip);
975 insertStringAsLines(cur, clip);
981 gotoInset(cur, InsetBase::ERROR_CODE, false);
985 gotoInset(cur, InsetBase::NOTE_CODE, false);
988 case LFUN_REFERENCE_GOTO: {
989 vector<InsetOld_code> tmp;
990 tmp.push_back(InsetBase::LABEL_CODE);
991 tmp.push_back(InsetBase::REF_CODE);
992 gotoInset(cur, tmp, true);
997 lyx::cap::replaceSelection(cur);
998 Paragraph & par = cur.paragraph();
999 lyx::pos_type pos = cur.pos();
1003 else if (cur.prevInset() && cur.prevInset()->isSpace())
1006 c = par.getChar(pos - 1);
1008 LyXLayout_ptr const & style = par.layout();
1010 BufferParams const & bufparams = bv->buffer()->params();
1011 if (!style->pass_thru
1012 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1013 string arg = cmd.argument;
1014 if (arg == "single")
1015 cur.insert(new InsetQuotes(c,
1016 bufparams.quotes_language,
1017 InsetQuotes::SingleQ));
1018 else if (arg == "double")
1019 cur.insert(new InsetQuotes(c,
1020 bufparams.quotes_language,
1021 InsetQuotes::DoubleQ));
1023 cur.insert(new InsetQuotes(c, bufparams));
1026 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1030 case LFUN_DATE_INSERT: {
1031 lyx::cap::replaceSelection(cur);
1032 time_t now_time_t = time(NULL);
1033 struct tm * now_tm = localtime(&now_time_t);
1034 setlocale(LC_TIME, "");
1036 if (!cmd.argument.empty())
1039 arg = lyxrc.date_insert_format;
1041 int const datetmp_len =
1042 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1044 for (int i = 0; i < datetmp_len; i++)
1045 insertChar(cur, datetmp[i]);
1048 moveCursor(cur, false);
1052 case LFUN_MOUSE_TRIPLE:
1053 if (cmd.button() == mouse_button::button1) {
1054 selection_possible = true;
1059 bv->haveSelection(cur.selection());
1063 case LFUN_MOUSE_DOUBLE:
1064 if (cmd.button() == mouse_button::button1) {
1065 selection_possible = true;
1066 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1067 bv->haveSelection(cur.selection());
1071 case LFUN_MOUSE_MOTION: {
1072 // Only use motion with button 1
1073 //if (cmd.button() != mouse_button::button1)
1075 // We want to use only motion events for which
1076 // the button press event was on the drawing area too.
1077 if (!selection_possible) {
1078 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1079 "dispatch: no selection possible\n";
1080 lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
1084 // ignore motions deeper nested than the real anchor
1085 LCursor & bvcur = cur.bv().cursor();
1086 if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
1089 CursorSlice old = cur.top();
1090 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1092 // This is to allow jumping over large insets
1093 // FIXME: shouldn't be top-text-specific
1094 if (isMainText() && cur.top() == old) {
1095 if (cmd.y - bv->top_y() >= bv->workHeight())
1097 else if (cmd.y - bv->top_y() < 0)
1101 // don't set anchor_
1102 bv->cursor().setCursor(cur, true);
1103 lyxerr << "MOTION: " << bv->cursor() << endl;
1107 // Single-click on work area
1108 case LFUN_MOUSE_PRESS: {
1109 // ok ok, this is a hack (for xforms)
1110 // We shouldn't go further down as we really need to. Only do the
1111 // scrolling and be done with this. Otherwise we may open some
1112 // dialogs (Jug 20020424).
1113 if (cmd.button() == mouse_button::button4) {
1114 bv->scroll(-lyxrc.wheel_jump);
1118 if (cmd.button() == mouse_button::button5) {
1119 bv->scroll(lyxrc.wheel_jump);
1123 // Right click on a footnote flag opens float menu
1124 if (cmd.button() == mouse_button::button3) {
1125 cur.clearSelection();
1126 selection_possible = false;
1130 // Middle button press pastes if we have a selection
1131 // We do this here as if the selection was inside an inset
1132 // it could get cleared on the unlocking of the inset so
1133 // we have to check this first
1134 bool paste_internally = false;
1135 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1136 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1137 paste_internally = true;
1140 selection_possible = true;
1142 // Clear the selection
1143 cur.clearSelection();
1145 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1148 cur.x_target() = cursorX(cur.top());
1153 // Don't allow selection after a big jump.
1154 if (bv->fitCursor())
1155 selection_possible = false;
1157 // Insert primary selection with middle mouse
1158 // if there is a local selection in the current buffer,
1160 if (cmd.button() == mouse_button::button2) {
1161 if (paste_internally)
1162 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1164 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1165 selection_possible = false;
1171 case LFUN_MOUSE_RELEASE: {
1172 // do nothing if we used the mouse wheel
1173 if (cmd.button() == mouse_button::button4
1174 || cmd.button() == mouse_button::button5) {
1179 selection_possible = false;
1181 if (cmd.button() == mouse_button::button2)
1185 if (cmd.button() == mouse_button::button1)
1186 bv->haveSelection(cur.selection());
1189 bv->owner()->updateMenubar();
1190 bv->owner()->updateToolbar();
1194 case LFUN_SELFINSERT: {
1195 if (cmd.argument.empty())
1198 // Automatically delete the currently selected
1199 // text and replace it with what is being
1200 // typed in now. Depends on lyxrc settings
1201 // "auto_region_delete", which defaults to
1204 if (lyxrc.auto_region_delete) {
1205 if (cur.selection())
1206 cutSelection(cur, false, false);
1207 bv->haveSelection(false);
1210 cur.clearSelection();
1211 LyXFont const old_font = real_current_font;
1213 string::const_iterator cit = cmd.argument.begin();
1214 string::const_iterator end = cmd.argument.end();
1215 for (; cit != end; ++cit)
1216 bv->owner()->getIntl().getTransManager().
1217 TranslateAndInsert(*cit, this);
1220 moveCursor(cur, false);
1222 // real_current_font.number can change so we need to
1223 // update the minibuffer
1224 if (old_font != real_current_font)
1225 bv->updateScrollbar();
1230 InsetCommandParams p("url");
1231 string const data = InsetCommandMailer::params2string("url", p);
1232 bv->owner()->getDialogs().show("url", data, 0);
1236 case LFUN_HTMLURL: {
1237 InsetCommandParams p("htmlurl");
1238 string const data = InsetCommandMailer::params2string("url", p);
1239 bv->owner()->getDialogs().show("url", data, 0);
1243 case LFUN_INSERT_LABEL: {
1244 InsetCommandParams p("label");
1245 string const data = InsetCommandMailer::params2string("label", p);
1246 bv->owner()->getDialogs().show("label", data, 0);
1252 case LFUN_INSET_LIST:
1253 case LFUN_INSET_THEOREM:
1254 case LFUN_INSET_CAPTION:
1256 case LFUN_INSERT_NOTE:
1257 case LFUN_INSERT_CHARSTYLE:
1258 case LFUN_INSERT_BOX:
1259 case LFUN_INSERT_BRANCH:
1260 case LFUN_INSERT_BIBITEM:
1261 case LFUN_INSET_ERT:
1262 case LFUN_INSET_FLOAT:
1263 case LFUN_INSET_FOOTNOTE:
1264 case LFUN_INSET_MARGINAL:
1265 case LFUN_INSET_OPTARG:
1266 case LFUN_INSET_WIDE_FLOAT:
1267 case LFUN_INSET_WRAP:
1268 case LFUN_TABULAR_INSERT:
1269 case LFUN_ENVIRONMENT_INSERT:
1270 // Open the inset, and move the current selection
1272 doInsertInset(cur, this, cmd, true, true);
1275 case LFUN_INDEX_INSERT:
1276 // Just open the inset
1277 doInsertInset(cur, this, cmd, true, false);
1280 case LFUN_INDEX_PRINT:
1281 case LFUN_TOC_INSERT:
1283 case LFUN_INSERT_LINE:
1284 case LFUN_INSERT_PAGEBREAK:
1286 doInsertInset(cur, this, cmd, false, false);
1289 case LFUN_DEPTH_MIN:
1290 changeDepth(cur, DEC_DEPTH);
1293 case LFUN_DEPTH_PLUS:
1294 changeDepth(cur, INC_DEPTH);
1297 case LFUN_MATH_DISPLAY:
1298 mathDispatch(cur, cmd, true);
1301 case LFUN_MATH_IMPORT_SELECTION:
1302 case LFUN_MATH_MODE:
1303 mathDispatch(cur, cmd, false);
1306 case LFUN_MATH_MACRO:
1307 if (cmd.argument.empty())
1308 cur.errorMessage(N_("Missing argument"));
1310 string s = cmd.argument;
1311 string const s1 = token(s, ' ', 1);
1312 int const nargs = s1.empty() ? 0 : atoi(s1);
1313 string const s2 = token(s, ' ', 2);
1314 string const type = s2.empty() ? "newcommand" : s2;
1315 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1316 cur.nextInset()->edit(cur, true);
1320 case LFUN_INSERT_MATH:
1321 case LFUN_INSERT_MATRIX:
1322 case LFUN_MATH_DELIM: {
1323 cur.insert(new MathHullInset);
1324 cur.dispatch(FuncRequest(LFUN_RIGHT));
1325 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1331 LyXFont font(LyXFont::ALL_IGNORE);
1332 font.setEmph(LyXFont::TOGGLE);
1333 toggleAndShow(cur, this, font);
1338 LyXFont font(LyXFont::ALL_IGNORE);
1339 font.setSeries(LyXFont::BOLD_SERIES);
1340 toggleAndShow(cur, this, font);
1345 LyXFont font(LyXFont::ALL_IGNORE);
1346 font.setNoun(LyXFont::TOGGLE);
1347 toggleAndShow(cur, this, font);
1352 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1354 toggleAndShow(cur, this, font);
1359 LyXFont font(LyXFont::ALL_IGNORE);
1360 font.setFamily(LyXFont::SANS_FAMILY);
1361 toggleAndShow(cur, this, font);
1366 LyXFont font(LyXFont::ALL_IGNORE);
1367 font.setFamily(LyXFont::ROMAN_FAMILY);
1368 toggleAndShow(cur, this, font);
1372 case LFUN_DEFAULT: {
1373 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1374 toggleAndShow(cur, this, font);
1378 case LFUN_UNDERLINE: {
1379 LyXFont font(LyXFont::ALL_IGNORE);
1380 font.setUnderbar(LyXFont::TOGGLE);
1381 toggleAndShow(cur, this, font);
1385 case LFUN_FONT_SIZE: {
1386 LyXFont font(LyXFont::ALL_IGNORE);
1387 font.setLyXSize(cmd.argument);
1388 toggleAndShow(cur, this, font);
1392 case LFUN_LANGUAGE: {
1393 Language const * lang = languages.getLanguage(cmd.argument);
1396 LyXFont font(LyXFont::ALL_IGNORE);
1397 font.setLanguage(lang);
1398 toggleAndShow(cur, this, font);
1403 case LFUN_FREEFONT_APPLY:
1404 toggleAndShow(cur, this, freefont, toggleall);
1405 cur.message(_("Character set"));
1408 // Set the freefont using the contents of \param data dispatched from
1409 // the frontends and apply it at the current cursor location.
1410 case LFUN_FREEFONT_UPDATE: {
1413 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1416 toggleAndShow(cur, this, freefont, toggleall);
1417 cur.message(_("Character set"));
1422 case LFUN_FINISHED_LEFT:
1423 lyxerr << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1426 case LFUN_FINISHED_RIGHT:
1427 lyxerr << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1431 case LFUN_FINISHED_UP:
1432 lyxerr << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1436 case LFUN_FINISHED_DOWN:
1437 lyxerr << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1441 case LFUN_LAYOUT_PARAGRAPH: {
1443 params2string(cur.paragraph(), data);
1444 data = "show\n" + data;
1445 bv->owner()->getDialogs().show("paragraph", data);
1449 case LFUN_PARAGRAPH_UPDATE: {
1450 if (!bv->owner()->getDialogs().visible("paragraph"))
1453 params2string(cur.paragraph(), data);
1455 // Will the paragraph accept changes from the dialog?
1456 InsetBase & inset = cur.inset();
1457 bool const accept = !inset.forceDefaultParagraphs(&inset);
1459 data = "update " + tostr(accept) + '\n' + data;
1460 bv->owner()->getDialogs().update("paragraph", data);
1465 case LFUN_CIRCUMFLEX:
1475 case LFUN_SPECIAL_CARON:
1478 case LFUN_HUNG_UMLAUT:
1481 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1482 if (!cmd.argument.empty())
1483 bv->owner()->getIntl().getTransManager()
1484 .TranslateAndInsert(cmd.argument[0], this);
1487 case LFUN_FLOAT_LIST: {
1488 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1489 if (tclass.floats().typeExist(cmd.argument)) {
1490 // not quite sure if we want this...
1492 cur.clearSelection();
1493 breakParagraph(cur);
1495 if (cur.lastpos() != 0) {
1497 breakParagraph(cur);
1500 setLayout(cur, tclass.defaultLayoutName());
1501 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1502 insertInset(cur, new InsetFloatList(cmd.argument));
1504 lyxerr << "Non-existent float type: "
1505 << cmd.argument << endl;
1510 case LFUN_ACCEPT_CHANGE: {
1515 case LFUN_REJECT_CHANGE: {
1520 case LFUN_THESAURUS_ENTRY: {
1521 string arg = cmd.argument;
1523 arg = cur.selectionAsString(false);
1525 if (arg.size() > 100 || arg.empty()) {
1526 // Get word or selection
1527 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1528 arg = cur.selectionAsString(false);
1531 bv->owner()->getDialogs().show("thesaurus", arg);
1535 case LFUN_PARAGRAPH_APPLY: {
1536 // Given data, an encoding of the ParagraphParameters
1537 // generated in the Paragraph dialog, this function sets
1538 // the current paragraph appropriately.
1539 istringstream is(cmd.argument);
1542 ParagraphParameters params;
1547 params.labelWidthString(),
1549 cur.message(_("Paragraph layout set"));
1553 case LFUN_INSET_DIALOG_SHOW: {
1554 InsetBase * inset = cur.nextInset();
1556 FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1557 inset->dispatch(cur, fr);
1563 if (cur.selection()) {
1564 cur.selection() = false;
1567 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1578 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1579 FuncStatus & flag) const
1581 BOOST_ASSERT(cur.text() == this);
1582 LyXFont const & font = real_current_font;
1585 switch (cmd.action) {
1587 case LFUN_DEPTH_MIN:
1588 enable = changeDepthAllowed(cur, DEC_DEPTH);
1591 case LFUN_DEPTH_PLUS:
1592 enable = changeDepthAllowed(cur, INC_DEPTH);
1595 case LFUN_INSET_OPTARG:
1596 enable = cur.paragraph().layout()->optionalargs;
1600 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1604 // the functions which insert insets
1605 InsetOld::Code code = InsetOld::NO_CODE;
1606 switch (cmd.action) {
1607 case LFUN_DIALOG_SHOW_NEW_INSET:
1608 if (cmd.argument == "bibitem")
1609 code = InsetOld::BIBITEM_CODE;
1610 else if (cmd.argument == "bibtex")
1611 code = InsetOld::BIBTEX_CODE;
1612 else if (cmd.argument == "box")
1613 code = InsetOld::BOX_CODE;
1614 else if (cmd.argument == "branch")
1615 code = InsetOld::BRANCH_CODE;
1616 else if (cmd.argument == "citation")
1617 code = InsetOld::CITE_CODE;
1618 else if (cmd.argument == "ert")
1619 code = InsetOld::ERT_CODE;
1620 else if (cmd.argument == "external")
1621 code = InsetOld::EXTERNAL_CODE;
1622 else if (cmd.argument == "float")
1623 code = InsetOld::FLOAT_CODE;
1624 else if (cmd.argument == "graphics")
1625 code = InsetOld::GRAPHICS_CODE;
1626 else if (cmd.argument == "include")
1627 code = InsetOld::INCLUDE_CODE;
1628 else if (cmd.argument == "index")
1629 code = InsetOld::INDEX_CODE;
1630 else if (cmd.argument == "label")
1631 code = InsetOld::LABEL_CODE;
1632 else if (cmd.argument == "note")
1633 code = InsetOld::NOTE_CODE;
1634 else if (cmd.argument == "ref")
1635 code = InsetOld::REF_CODE;
1636 else if (cmd.argument == "toc")
1637 code = InsetOld::TOC_CODE;
1638 else if (cmd.argument == "url")
1639 code = InsetOld::URL_CODE;
1640 else if (cmd.argument == "vspace")
1641 code = InsetOld::VSPACE_CODE;
1642 else if (cmd.argument == "wrap")
1643 code = InsetOld::WRAP_CODE;
1646 case LFUN_INSET_ERT:
1647 code = InsetOld::ERT_CODE;
1649 case LFUN_INSET_FOOTNOTE:
1650 code = InsetOld::FOOT_CODE;
1652 case LFUN_TABULAR_INSERT:
1653 code = InsetOld::TABULAR_CODE;
1655 case LFUN_INSET_MARGINAL:
1656 code = InsetOld::MARGIN_CODE;
1658 case LFUN_INSET_FLOAT:
1659 case LFUN_INSET_WIDE_FLOAT:
1660 code = InsetOld::FLOAT_CODE;
1662 case LFUN_INSET_WRAP:
1663 code = InsetOld::WRAP_CODE;
1665 case LFUN_FLOAT_LIST:
1666 code = InsetOld::FLOAT_LIST_CODE;
1669 case LFUN_INSET_LIST:
1670 code = InsetOld::LIST_CODE;
1672 case LFUN_INSET_THEOREM:
1673 code = InsetOld::THEOREM_CODE;
1676 case LFUN_INSET_CAPTION:
1677 code = InsetOld::CAPTION_CODE;
1679 case LFUN_INSERT_NOTE:
1680 code = InsetOld::NOTE_CODE;
1682 case LFUN_INSERT_CHARSTYLE:
1683 code = InsetOld::CHARSTYLE_CODE;
1684 if (buf->params().getLyXTextClass().charstyles().empty())
1687 case LFUN_INSERT_BOX:
1688 code = InsetOld::BOX_CODE;
1690 case LFUN_INSERT_BRANCH:
1691 code = InsetOld::BRANCH_CODE;
1692 if (buf->params().branchlist().empty())
1695 case LFUN_INSERT_LABEL:
1696 code = InsetOld::LABEL_CODE;
1698 case LFUN_INSET_OPTARG:
1699 code = InsetOld::OPTARG_CODE;
1701 case LFUN_ENVIRONMENT_INSERT:
1702 code = InsetOld::BOX_CODE;
1704 case LFUN_INDEX_INSERT:
1705 code = InsetOld::INDEX_CODE;
1707 case LFUN_INDEX_PRINT:
1708 code = InsetOld::INDEX_PRINT_CODE;
1710 case LFUN_TOC_INSERT:
1711 code = InsetOld::TOC_CODE;
1715 code = InsetOld::URL_CODE;
1718 // always allow this, since we will inset a raw quote
1719 // if an inset is not allowed.
1721 case LFUN_HYPHENATION:
1722 case LFUN_LIGATURE_BREAK:
1724 case LFUN_MENU_SEPARATOR:
1726 case LFUN_END_OF_SENTENCE:
1727 code = InsetOld::SPECIALCHAR_CODE;
1729 case LFUN_SPACE_INSERT:
1730 // slight hack: we know this is allowed in math mode
1732 code = InsetOld::SPACE_CODE;
1734 case LFUN_INSET_DIALOG_SHOW: {
1735 InsetBase * inset = cur.nextInset();
1738 code = inset->lyxCode();
1739 if (!(code == InsetOld::INCLUDE_CODE
1740 || code == InsetOld::BIBTEX_CODE
1741 || code == InsetOld::FLOAT_LIST_CODE
1742 || code == InsetOld::TOC_CODE))
1751 if (code != InsetOld::NO_CODE
1752 && (cur.empty() || !cur.inset().insetAllowed(code)))
1757 case LFUN_DIALOG_SHOW_NEW_INSET:
1758 case LFUN_INSET_ERT:
1759 case LFUN_INSERT_BOX:
1760 case LFUN_INSERT_BRANCH:
1761 case LFUN_ENVIRONMENT_INSERT:
1762 case LFUN_INDEX_INSERT:
1763 case LFUN_INDEX_PRINT:
1764 case LFUN_TOC_INSERT:
1768 case LFUN_HYPHENATION:
1769 case LFUN_LIGATURE_BREAK:
1771 case LFUN_MENU_SEPARATOR:
1773 case LFUN_END_OF_SENTENCE:
1774 case LFUN_SPACE_INSERT:
1775 case LFUN_INSET_DIALOG_SHOW:
1779 flag.setOnOff(font.emph() == LyXFont::ON);
1783 flag.setOnOff(font.noun() == LyXFont::ON);
1787 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1791 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1795 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1799 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1802 case LFUN_DELETE_WORD_FORWARD:
1803 case LFUN_DELETE_WORD_BACKWARD:
1804 case LFUN_DELETE_LINE_FORWARD:
1805 case LFUN_WORDRIGHT:
1808 case LFUN_BEGINNINGBUF:
1817 case LFUN_UP_PARAGRAPHSEL:
1818 case LFUN_DOWN_PARAGRAPHSEL:
1823 case LFUN_WORDRIGHTSEL:
1824 case LFUN_WORDLEFTSEL:
1826 case LFUN_UP_PARAGRAPH:
1827 case LFUN_DOWN_PARAGRAPH:
1832 case LFUN_BREAKLINE:
1834 case LFUN_DELETE_SKIP:
1835 case LFUN_BACKSPACE:
1836 case LFUN_BACKSPACE_SKIP:
1837 case LFUN_BREAKPARAGRAPH:
1838 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1839 case LFUN_BREAKPARAGRAPH_SKIP:
1840 case LFUN_PARAGRAPH_SPACING:
1841 case LFUN_INSET_APPLY:
1842 case LFUN_INSET_INSERT:
1843 case LFUN_NEXT_INSET_TOGGLE:
1844 case LFUN_UPCASE_WORD:
1845 case LFUN_LOWCASE_WORD:
1846 case LFUN_CAPITALIZE_WORD:
1847 case LFUN_TRANSPOSE_CHARS:
1854 case LFUN_GETLAYOUT:
1856 case LFUN_PASTESELECTION:
1857 case LFUN_GOTOERROR:
1859 case LFUN_REFERENCE_GOTO:
1860 case LFUN_DATE_INSERT:
1861 case LFUN_SELFINSERT:
1862 case LFUN_INSERT_LABEL:
1863 case LFUN_INSERT_NOTE:
1864 case LFUN_INSERT_CHARSTYLE:
1865 case LFUN_INSERT_BIBITEM:
1866 case LFUN_INSET_FLOAT:
1867 case LFUN_INSET_FOOTNOTE:
1868 case LFUN_INSET_MARGINAL:
1869 case LFUN_INSET_WIDE_FLOAT:
1870 case LFUN_INSET_WRAP:
1871 case LFUN_TABULAR_INSERT:
1872 case LFUN_INSERT_LINE:
1873 case LFUN_INSERT_PAGEBREAK:
1874 case LFUN_MATH_DISPLAY:
1875 case LFUN_MATH_IMPORT_SELECTION:
1876 case LFUN_MATH_MODE:
1877 case LFUN_MATH_MACRO:
1878 case LFUN_INSERT_MATH:
1879 case LFUN_INSERT_MATRIX:
1880 case LFUN_MATH_DELIM:
1882 case LFUN_UNDERLINE:
1883 case LFUN_FONT_SIZE:
1885 case LFUN_FREEFONT_APPLY:
1886 case LFUN_FREEFONT_UPDATE:
1887 case LFUN_LAYOUT_PARAGRAPH:
1888 case LFUN_PARAGRAPH_UPDATE:
1890 case LFUN_CIRCUMFLEX:
1900 case LFUN_SPECIAL_CARON:
1903 case LFUN_HUNG_UMLAUT:
1906 case LFUN_FLOAT_LIST:
1907 case LFUN_ACCEPT_CHANGE:
1908 case LFUN_REJECT_CHANGE:
1909 case LFUN_THESAURUS_ENTRY:
1910 case LFUN_PARAGRAPH_APPLY:
1912 case LFUN_KEYMAP_TOGGLE:
1913 // these are handled in our dispatch()
1921 flag.enabled(enable);