3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "bufferparams.h"
22 #include "BufferView.h"
25 #include "dispatchresult.h"
27 #include "FloatList.h"
28 #include "funcrequest.h"
36 #include "paragraph.h"
37 #include "paragraph_funcs.h"
38 #include "ParagraphParameters.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
45 #include "insets/insetcommand.h"
46 #include "insets/insetfloatlist.h"
47 #include "insets/insetnewline.h"
48 #include "insets/insetquotes.h"
49 #include "insets/insetspecialchar.h"
50 #include "insets/insettext.h"
52 #include "support/lstrings.h"
53 #include "support/lyxlib.h"
54 #include "support/tostr.h"
55 #include "support/std_sstream.h"
57 #include "mathed/math_hullinset.h"
58 #include "mathed/formulamacro.h"
64 using lyx::support::isStrUnsignedInt;
65 using lyx::support::strToUnsignedInt;
66 using lyx::support::atoi;
67 using lyx::support::token;
72 using std::istringstream;
76 extern string current_layout;
78 // the selection possible is needed, that only motion events are
79 // used, where the button press event was on the drawing area too
80 bool selection_possible = false;
86 LyXFont freefont(LyXFont::ALL_IGNORE);
87 bool toggleall = false;
90 void toggleAndShow(LCursor & cur, LyXText * text,
91 LyXFont const & font, bool toggleall = true)
93 if (!cur.bv().available())
96 text->toggleFree(cur, font, toggleall);
98 if (font.language() != ignore_language ||
99 font.number() != LyXFont::IGNORE) {
100 Paragraph & par = cur.paragraph();
101 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
102 if (cur.boundary() !=
103 text->bidi.isBoundary(*cur.bv().buffer(), par,
105 text->real_current_font))
106 text->setCursor(cur, cur.par(), cur.pos(),
107 false, !cur.boundary());
113 void moveCursor(LCursor & cur, bool selecting)
115 if (selecting || cur.mark())
117 if (!cur.selection())
118 cur.bv().haveSelection(false);
119 cur.bv().switchKeyMap();
123 void finishChange(LCursor & cur, bool selecting = false)
126 moveCursor(cur, selecting);
127 cur.bv().owner()->view_state_changed();
131 void mathDispatch(LCursor & cur, LyXText * text,
132 FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 lyxerr << "selection is: '" << sel << "'" << endl;
138 cur.insert(new MathHullInset);
139 cur.dispatch(FuncRequest(LFUN_RIGHT));
140 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
141 // don't do that also for LFUN_MATH_MODE unless you want end up with
142 // always changing to mathrm when opening an inlined inset
143 // -- I really hate "LyXfunc overloading"...
145 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
146 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
148 // create a macro if we see "\\newcommand" somewhere, and an ordinary
150 text->cutSelection(cur, true, true);
151 if (sel.find("\\newcommand") == string::npos &&
152 sel.find("\\def") == string::npos)
154 cur.insert(new MathHullInset);
155 cur.dispatch(FuncRequest(LFUN_RIGHT));
156 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
157 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
159 cur.insert(new InsetFormulaMacro(sel));
160 cur.dispatch(FuncRequest(LFUN_RIGHT));
163 cur.message(N_("Math editor mode"));
172 string const freefont2string()
175 if (font2string(freefont, toggleall, data))
183 //takes absolute x,y coordinates
184 InsetBase * LyXText::checkInsetHit(int x, int y)
186 ParagraphList::iterator pit;
187 ParagraphList::iterator end;
189 getParsInRange(paragraphs(),
191 bv()->top_y() - yo_ + bv()->workHeight(),
194 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
195 for ( ; pit != end; ++pit) {
196 InsetList::iterator iit = pit->insetlist.begin();
197 InsetList::iterator iend = pit->insetlist.end();
198 for ( ; iit != iend; ++iit) {
199 InsetBase * inset = iit->inset;
201 lyxerr << "examining inset " << inset
202 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
203 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
204 << " yo: " << inset->yo() - inset->ascent() << "..."
205 << inset->yo() + inset->descent() << endl;
207 if (inset->covers(x, y)) {
208 lyxerr << "Hit inset: " << inset << endl;
213 lyxerr << "No inset hit. " << endl;
218 bool LyXText::gotoNextInset(LCursor & cur,
219 vector<InsetOld_code> const & codes, string const & contents)
221 BOOST_ASSERT(this == cur.text());
222 ParagraphList::iterator end = paragraphs().end();
223 ParagraphList::iterator pit = getPar(cur.par());
224 pos_type pos = cur.pos();
228 if (pos + 1 < pit->size()) {
235 } while (pit != end &&
236 !(pit->isInset(pos) &&
237 (inset = pit->getInset(pos)) != 0 &&
238 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
240 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
246 setCursor(cur, parOffset(pit), pos, false);
251 void LyXText::gotoInset(LCursor & cur,
252 vector<InsetOld_code> const & codes, bool same_content)
254 cur.clearSelection();
258 && cur.pos() < cur.lastpos()
259 && cur.paragraph().isInset(cur.pos())) {
260 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
261 if (find(codes.begin(), codes.end(), inset->lyxCode())
263 contents = static_cast<InsetCommand const *>(inset)->getContents();
266 if (!gotoNextInset(cur, codes, contents)) {
267 if (cur.pos() || cur.par() != 0) {
268 CursorSlice tmp = cur.current();
271 if (!gotoNextInset(cur, codes, contents)) {
273 cur.message(_("No more insets"));
276 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::paroffset_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::paroffset_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.
322 cursorDown(cur, true);
325 bv()->updateScrollbar();
332 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
334 text->replaceSelection(cur);
335 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);
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 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
378 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
379 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
381 BufferView * bv = &cur.bv();
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);
418 case LFUN_DELETE_WORD_BACKWARD:
419 cur.clearSelection();
420 deleteWordBackward(cur);
424 case LFUN_DELETE_LINE_FORWARD:
425 cur.clearSelection();
426 deleteLineForward(cur);
432 cur.clearSelection();
433 if (isRTL(cur.paragraph()))
434 cursorLeftOneWord(cur);
436 cursorRightOneWord(cur);
442 cur.clearSelection();
443 if (isRTL(cur.paragraph()))
444 cursorRightOneWord(cur);
446 cursorLeftOneWord(cur);
450 case LFUN_BEGINNINGBUF:
452 cur.clearSelection();
459 cur.clearSelection();
465 if (!cur.selection())
467 if (isRTL(cur.paragraph()))
468 cursorLeft(cur, true);
470 cursorRight(cur, true);
471 finishChange(cur, true);
475 if (!cur.selection())
477 if (isRTL(cur.paragraph()))
478 cursorRight(cur, true);
480 cursorLeft(cur, true);
481 finishChange(cur, true);
485 if (!cur.selection())
488 finishChange(cur, true);
492 if (!cur.selection())
494 cursorDown(cur, true);
495 finishChange(cur, true);
498 case LFUN_UP_PARAGRAPHSEL:
499 if (!cur.selection())
501 cursorUpParagraph(cur);
502 finishChange(cur, true);
505 case LFUN_DOWN_PARAGRAPHSEL:
506 if (!cur.selection())
508 cursorDownParagraph(cur);
509 finishChange(cur, true);
513 if (!cur.selection())
516 finishChange(cur, true);
520 if (!cur.selection())
523 finishChange(cur, true);
527 if (!cur.selection())
530 finishChange(cur, true);
534 if (!cur.selection())
537 finishChange(cur, true);
540 case LFUN_WORDRIGHTSEL:
541 if (!cur.selection())
543 if (isRTL(cur.paragraph()))
544 cursorLeftOneWord(cur);
546 cursorRightOneWord(cur);
547 finishChange(cur, true);
550 case LFUN_WORDLEFTSEL:
551 if (!cur.selection())
553 if (isRTL(cur.paragraph()))
554 cursorRightOneWord(cur);
556 cursorLeftOneWord(cur);
557 finishChange(cur, true);
561 selectWord(cur, lyx::WHOLE_WORD);
562 finishChange(cur, true);
568 return moveRight(cur);
572 return moveLeft(cur);
580 return moveDown(cur);
582 case LFUN_UP_PARAGRAPH:
584 cur.clearSelection();
585 cursorUpParagraph(cur);
589 case LFUN_DOWN_PARAGRAPH:
591 cur.clearSelection();
592 cursorDownParagraph(cur);
593 finishChange(cur, false);
598 cur.clearSelection();
599 finishChange(cur, false);
600 if (cur.par() == 0 && cur.textRow().pos() == 0)
601 return DispatchResult(false, FINISHED_UP);
607 cur.clearSelection();
608 finishChange(cur, false);
609 if (cur.par() == cur.lastpar()
610 && cur.textRow().endpos() == cur.lastpos())
611 return DispatchResult(false, FINISHED_DOWN);
617 cur.clearSelection();
619 finishChange(cur, false);
624 cur.clearSelection();
626 finishChange(cur, false);
629 case LFUN_BREAKLINE: {
630 // Not allowed by LaTeX (labels or empty par)
631 if (cur.pos() > cur.paragraph().beginOfBody()) {
632 replaceSelection(cur);
633 cur.insert(new InsetNewline);
634 moveCursor(cur, false);
640 if (!cur.selection()) {
643 // It is possible to make it a lot faster still
644 // just comment out the line below...
646 cutSelection(cur, true, false);
648 moveCursor(cur, false);
649 bv->owner()->view_state_changed();
652 case LFUN_DELETE_SKIP:
653 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
654 if (!cur.selection()) {
655 if (cur.pos() == cur.lastpos()) {
656 cursorRight(cur, true);
657 cursorLeft(cur, true);
662 cutSelection(cur, true, false);
669 if (!cur.selection()) {
670 if (bv->owner()->getIntl().getTransManager().backspace()) {
673 // It is possible to make it a lot faster still
674 // just comment out the line below...
677 cutSelection(cur, true, false);
679 bv->owner()->view_state_changed();
684 case LFUN_BACKSPACE_SKIP:
685 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
686 if (!cur.selection()) {
688 //CursorSlice cur = cursor();
692 cutSelection(cur, true, false);
697 case LFUN_BREAKPARAGRAPH:
698 replaceSelection(cur);
699 breakParagraph(cur, 0);
703 bv->owner()->view_state_changed();
706 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
707 replaceSelection(cur);
708 breakParagraph(cur, 1);
712 bv->owner()->view_state_changed();
715 case LFUN_BREAKPARAGRAPH_SKIP: {
716 // When at the beginning of a paragraph, remove
717 // indentation and add a "defskip" at the top.
718 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
719 replaceSelection(cur);
720 if (cur.pos() == 0) {
721 ParagraphParameters & params = cur.paragraph().params();
725 params.labelWidthString(), 1);
727 breakParagraph(cur, 0);
732 bv->owner()->view_state_changed();
736 case LFUN_PARAGRAPH_SPACING: {
737 Paragraph & par = cur.paragraph();
738 Spacing::Space cur_spacing = par.params().spacing().getSpace();
739 float cur_value = 1.0;
740 if (cur_spacing == Spacing::Other)
741 cur_value = par.params().spacing().getValue();
743 istringstream is(cmd.argument);
746 Spacing::Space new_spacing = cur_spacing;
747 float new_value = cur_value;
749 lyxerr << "Missing argument to `paragraph-spacing'"
751 } else if (tmp == "single") {
752 new_spacing = Spacing::Single;
753 } else if (tmp == "onehalf") {
754 new_spacing = Spacing::Onehalf;
755 } else if (tmp == "double") {
756 new_spacing = Spacing::Double;
757 } else if (tmp == "other") {
758 new_spacing = Spacing::Other;
761 lyxerr << "new_value = " << tmpval << endl;
764 } else if (tmp == "default") {
765 new_spacing = Spacing::Default;
767 lyxerr << _("Unknown spacing argument: ")
768 << cmd.argument << endl;
770 if (cur_spacing != new_spacing || cur_value != new_value) {
771 par.params().spacing(Spacing(new_spacing, new_value));
778 case LFUN_INSET_APPLY: {
779 string const name = cmd.getArg(0);
780 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
782 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
784 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
788 case LFUN_INSET_INSERT: {
789 InsetBase * inset = createInset(bv, cmd);
791 insertInset(cur, inset);
795 case LFUN_INSET_SETTINGS:
796 if (cur.inset() && cur.inset()->asUpdatableInset())
797 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
800 case LFUN_INSET_TOGGLE:
801 cur.clearSelection();
802 if (!toggleInset(cur))
803 return DispatchResult(false);
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, this, InsetSpecialChar::HYPHENATION);
820 case LFUN_LIGATURE_BREAK:
821 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
825 specialChar(cur, this, InsetSpecialChar::LDOTS);
828 case LFUN_END_OF_SENTENCE:
829 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
832 case LFUN_MENU_SEPARATOR:
833 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
836 case LFUN_UPCASE_WORD:
837 changeCase(cur, LyXText::text_uppercase);
841 case LFUN_LOWCASE_WORD:
842 changeCase(cur, LyXText::text_lowercase);
846 case LFUN_CAPITALIZE_WORD:
847 changeCase(cur, LyXText::text_capitalization);
851 case LFUN_TRANSPOSE_CHARS:
858 cur.message(_("Paste"));
859 replaceSelection(cur);
860 #warning FIXME Check if the arg is in the domain of available selections.
861 if (isStrUnsignedInt(cmd.argument))
862 pasteSelection(cur, strToUnsignedInt(cmd.argument));
864 pasteSelection(cur, 0);
865 cur.clearSelection(); // bug 393
872 cutSelection(cur, true, true);
873 cur.message(_("Cut"));
879 cur.message(_("Copy"));
882 case LFUN_BEGINNINGBUFSEL:
884 return DispatchResult(false);
885 if (!cur.selection())
888 finishChange(cur, true);
893 return DispatchResult(false);
894 if (!cur.selection())
897 finishChange(cur, true);
901 cur.message(tostr(cursorX(cur.current())) + ' '
902 + tostr(cursorY(cur.current())));
908 istringstream is(cmd.argument);
911 lyxerr << "SETXY: Could not parse coordinates in '"
912 << cmd.argument << std::endl;
914 setCursorFromCoordinates(cur, x, y);
919 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
921 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
928 cur.message(cur.paragraph().layout()->name());
932 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
933 << cmd.argument << endl;
935 // This is not the good solution to the empty argument
936 // problem, but it will hopefully suffice for 1.2.0.
937 // The correct solution would be to augument the
938 // function list/array with information about what
939 // functions needs arguments and their type.
940 if (cmd.argument.empty()) {
941 cur.errorMessage(_("LyX function 'layout' needs an argument."));
945 // Derive layout number from given argument (string)
946 // and current buffer's textclass (number)
947 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
948 bool hasLayout = tclass.hasLayout(cmd.argument);
949 string layout = cmd.argument;
951 // If the entry is obsolete, use the new one instead.
953 string const & obs = tclass[layout]->obsoleted_by();
959 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
964 bool change_layout = (current_layout != layout);
966 if (!change_layout && cur.selection() &&
967 cur.selBegin().par() != cur.selEnd().par())
969 ParagraphList::iterator spit = getPar(cur.selBegin());
970 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
971 while (spit != epit) {
972 if (spit->layout()->name() != current_layout) {
973 change_layout = true;
981 current_layout = layout;
982 setLayout(cur, layout);
983 bv->owner()->setLayout(layout);
990 case LFUN_PASTESELECTION: {
991 cur.clearSelection();
992 string const clip = bv->getClipboard();
994 if (cmd.argument == "paragraph")
995 insertStringAsParagraphs(cur, clip);
997 insertStringAsLines(cur, clip);
1003 case LFUN_GOTOERROR:
1004 gotoInset(cur, InsetBase::ERROR_CODE, false);
1008 gotoInset(cur, InsetBase::NOTE_CODE, false);
1011 case LFUN_REFERENCE_GOTO: {
1012 vector<InsetOld_code> tmp;
1013 tmp.push_back(InsetBase::LABEL_CODE);
1014 tmp.push_back(InsetBase::REF_CODE);
1015 gotoInset(cur, tmp, true);
1020 replaceSelection(cur);
1021 Paragraph & par = cur.paragraph();
1022 lyx::pos_type pos = cur.pos();
1026 else if (cur.prevInset() && cur.prevInset()->isSpace())
1029 c = par.getChar(pos - 1);
1031 LyXLayout_ptr const & style = par.layout();
1033 BufferParams const & bufparams = bv->buffer()->params();
1034 if (!style->pass_thru
1035 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1036 string arg = cmd.argument;
1037 if (arg == "single")
1038 cur.insert(new InsetQuotes(c,
1039 bufparams.quotes_language,
1040 InsetQuotes::SingleQ));
1041 else if (arg == "double")
1042 cur.insert(new InsetQuotes(c,
1043 bufparams.quotes_language,
1044 InsetQuotes::DoubleQ));
1046 cur.insert(new InsetQuotes(c, bufparams));
1049 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1053 case LFUN_DATE_INSERT: {
1054 replaceSelection(cur);
1055 time_t now_time_t = time(NULL);
1056 struct tm * now_tm = localtime(&now_time_t);
1057 setlocale(LC_TIME, "");
1059 if (!cmd.argument.empty())
1062 arg = lyxrc.date_insert_format;
1064 int const datetmp_len =
1065 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1067 for (int i = 0; i < datetmp_len; i++)
1068 insertChar(cur, datetmp[i]);
1071 moveCursor(cur, false);
1075 case LFUN_MOUSE_TRIPLE:
1076 if (cmd.button() == mouse_button::button1) {
1077 selection_possible = true;
1082 bv->haveSelection(cur.selection());
1086 case LFUN_MOUSE_DOUBLE:
1087 if (cmd.button() == mouse_button::button1) {
1088 selection_possible = true;
1089 selectWord(cur, lyx::WHOLE_WORD_STRICT);
1090 bv->haveSelection(cur.selection());
1094 case LFUN_MOUSE_MOTION: {
1095 // Only use motion with button 1
1096 //if (cmd.button() != mouse_button::button1)
1098 // The test for not selection possible is needed, that
1099 // only motion events are used, where the bottom press
1100 // event was on the drawing area too
1101 if (!selection_possible) {
1102 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1103 "Dispatch: no selection possible\n";
1106 CursorSlice old = cur.current();
1107 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1109 // This is to allow jumping over large insets
1110 // FIXME: shouldn't be top-text-specific
1111 if (!in_inset_ && cur.current() == old) {
1112 if (cmd.y - bv->top_y() >= bv->workHeight())
1113 cursorDown(cur, true);
1114 else if (cmd.y - bv->top_y() < 0)
1115 cursorUp(cur, true);
1118 // don't set anchor_
1119 bv->cursor().cursor_ = cur.cursor_;
1120 bv->cursor().setSelection();
1124 // Single-click on work area
1125 case LFUN_MOUSE_PRESS: {
1126 // ok ok, this is a hack (for xforms)
1127 // We shouldn't go further down as we really should only do the
1128 // scrolling and be done with this. Otherwise we may open some
1129 // dialogs (Jug 20020424).
1130 if (cmd.button() == mouse_button::button4) {
1131 bv->scroll(-lyxrc.wheel_jump);
1135 if (cmd.button() == mouse_button::button5) {
1136 bv->scroll(lyxrc.wheel_jump);
1140 // Right click on a footnote flag opens float menu
1141 if (cmd.button() == mouse_button::button3) {
1142 cur.clearSelection();
1143 selection_possible = false;
1147 // Middle button press pastes if we have a selection
1148 // We do this here as if the selection was inside an inset
1149 // it could get cleared on the unlocking of the inset so
1150 // we have to check this first
1151 bool paste_internally = false;
1152 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1153 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1154 paste_internally = true;
1157 selection_possible = true;
1159 // Clear the selection
1160 cur.clearSelection();
1162 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1165 cur.x_target() = cursorX(cur.current());
1167 // set cursor and anchor to this position
1170 if (bv->fitCursor())
1171 selection_possible = false;
1173 // Insert primary selection with middle mouse
1174 // if there is a local selection in the current buffer,
1176 if (cmd.button() == mouse_button::button2) {
1177 if (paste_internally)
1178 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1180 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1181 selection_possible = false;
1186 case LFUN_MOUSE_RELEASE: {
1187 // do nothing if we used the mouse wheel
1188 if (cmd.button() == mouse_button::button4
1189 || cmd.button() == mouse_button::button5)
1190 return DispatchResult(true, false);
1192 selection_possible = false;
1194 if (cmd.button() == mouse_button::button2)
1198 if (cmd.button() == mouse_button::button1)
1199 bv->haveSelection(cur.selection());
1202 bv->owner()->view_state_changed();
1203 bv->owner()->updateMenubar();
1204 bv->owner()->updateToolbar();
1208 case LFUN_SELFINSERT: {
1209 if (cmd.argument.empty())
1212 // Automatically delete the currently selected
1213 // text and replace it with what is being
1214 // typed in now. Depends on lyxrc settings
1215 // "auto_region_delete", which defaults to
1218 if (lyxrc.auto_region_delete) {
1219 if (cur.selection())
1220 cutSelection(cur, false, false);
1221 bv->haveSelection(false);
1224 cur.clearSelection();
1225 LyXFont const old_font = real_current_font;
1227 string::const_iterator cit = cmd.argument.begin();
1228 string::const_iterator end = cmd.argument.end();
1229 for (; cit != end; ++cit)
1230 bv->owner()->getIntl().getTransManager().
1231 TranslateAndInsert(*cit, this);
1234 moveCursor(cur, false);
1236 // real_current_font.number can change so we need to
1237 // update the minibuffer
1238 if (old_font != real_current_font)
1239 bv->owner()->view_state_changed();
1240 bv->updateScrollbar();
1245 InsetCommandParams p("url");
1246 string const data = InsetCommandMailer::params2string("url", p);
1247 bv->owner()->getDialogs().show("url", data, 0);
1251 case LFUN_HTMLURL: {
1252 InsetCommandParams p("htmlurl");
1253 string const data = InsetCommandMailer::params2string("url", p);
1254 bv->owner()->getDialogs().show("url", data, 0);
1258 case LFUN_INSERT_LABEL: {
1259 InsetCommandParams p("label");
1260 string const data = InsetCommandMailer::params2string("label", p);
1261 bv->owner()->getDialogs().show("label", data, 0);
1267 case LFUN_INSET_LIST:
1268 case LFUN_INSET_THEOREM:
1269 case LFUN_INSET_CAPTION:
1271 case LFUN_INSERT_NOTE:
1272 case LFUN_INSERT_CHARSTYLE:
1273 case LFUN_INSERT_BOX:
1274 case LFUN_INSERT_BRANCH:
1275 case LFUN_INSERT_BIBITEM:
1276 case LFUN_INSET_ERT:
1277 case LFUN_INSET_FLOAT:
1278 case LFUN_INSET_FOOTNOTE:
1279 case LFUN_INSET_MARGINAL:
1280 case LFUN_INSET_OPTARG:
1281 case LFUN_INSET_WIDE_FLOAT:
1282 case LFUN_INSET_WRAP:
1283 case LFUN_TABULAR_INSERT:
1284 case LFUN_ENVIRONMENT_INSERT:
1285 // Open the inset, and move the current selection
1287 doInsertInset(cur, this, cmd, true, true);
1290 case LFUN_INDEX_INSERT:
1291 // Just open the inset
1292 doInsertInset(cur, this, cmd, true, false);
1295 case LFUN_INDEX_PRINT:
1296 case LFUN_TOC_INSERT:
1298 case LFUN_INSERT_LINE:
1299 case LFUN_INSERT_PAGEBREAK:
1301 doInsertInset(cur, this, cmd, false, false);
1304 case LFUN_DEPTH_MIN:
1305 changeDepth(cur, bv_funcs::DEC_DEPTH);
1309 case LFUN_DEPTH_PLUS:
1310 changeDepth(cur, bv_funcs::INC_DEPTH);
1314 case LFUN_MATH_DISPLAY:
1315 mathDispatch(cur, this, cmd, true);
1318 case LFUN_MATH_IMPORT_SELECTION:
1319 case LFUN_MATH_MODE:
1320 mathDispatch(cur, this, cmd, false);
1323 case LFUN_MATH_MACRO:
1324 if (cmd.argument.empty())
1325 cur.errorMessage(N_("Missing argument"));
1327 string s = cmd.argument;
1328 string const s1 = token(s, ' ', 1);
1329 int const nargs = s1.empty() ? 0 : atoi(s1);
1330 string const s2 = token(s, ' ', 2);
1331 string const type = s2.empty() ? "newcommand" : s2;
1332 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1333 cur.nextInset()->edit(cur, true);
1337 case LFUN_INSERT_MATH:
1338 case LFUN_INSERT_MATRIX:
1339 case LFUN_MATH_DELIM: {
1340 cur.insert(new MathHullInset);
1341 cur.dispatch(FuncRequest(LFUN_RIGHT));
1342 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1348 LyXFont font(LyXFont::ALL_IGNORE);
1349 font.setEmph(LyXFont::TOGGLE);
1350 toggleAndShow(cur, this, font);
1351 bv->owner()->view_state_changed();
1356 LyXFont font(LyXFont::ALL_IGNORE);
1357 font.setSeries(LyXFont::BOLD_SERIES);
1358 toggleAndShow(cur, this, font);
1359 bv->owner()->view_state_changed();
1364 LyXFont font(LyXFont::ALL_IGNORE);
1365 font.setNoun(LyXFont::TOGGLE);
1366 toggleAndShow(cur, this, font);
1367 bv->owner()->view_state_changed();
1372 LyXFont font(LyXFont::ALL_IGNORE);
1373 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1374 toggleAndShow(cur, this, font);
1375 bv->owner()->view_state_changed();
1380 LyXFont font(LyXFont::ALL_IGNORE);
1381 font.setFamily(LyXFont::SANS_FAMILY);
1382 toggleAndShow(cur, this, font);
1383 bv->owner()->view_state_changed();
1388 LyXFont font(LyXFont::ALL_IGNORE);
1389 font.setFamily(LyXFont::ROMAN_FAMILY);
1390 toggleAndShow(cur, this, font);
1391 bv->owner()->view_state_changed();
1395 case LFUN_DEFAULT: {
1396 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1397 toggleAndShow(cur, this, font);
1398 bv->owner()->view_state_changed();
1402 case LFUN_UNDERLINE: {
1403 LyXFont font(LyXFont::ALL_IGNORE);
1404 font.setUnderbar(LyXFont::TOGGLE);
1405 toggleAndShow(cur, this, font);
1406 bv->owner()->view_state_changed();
1410 case LFUN_FONT_SIZE: {
1411 LyXFont font(LyXFont::ALL_IGNORE);
1412 font.setLyXSize(cmd.argument);
1413 toggleAndShow(cur, this, font);
1414 bv->owner()->view_state_changed();
1418 case LFUN_LANGUAGE: {
1419 Language const * lang = languages.getLanguage(cmd.argument);
1422 LyXFont font(LyXFont::ALL_IGNORE);
1423 font.setLanguage(lang);
1424 toggleAndShow(cur, this, font);
1426 bv->owner()->view_state_changed();
1430 case LFUN_FREEFONT_APPLY:
1431 toggleAndShow(cur, this, freefont, toggleall);
1432 bv->owner()->view_state_changed();
1433 cur.message(_("Character set"));
1436 // Set the freefont using the contents of \param data dispatched from
1437 // the frontends and apply it at the current cursor location.
1438 case LFUN_FREEFONT_UPDATE: {
1441 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1444 toggleAndShow(cur, this, freefont, toggleall);
1445 bv->owner()->view_state_changed();
1446 cur.message(_("Character set"));
1451 case LFUN_FINISHED_LEFT:
1452 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1453 cur.pop(cur.currentDepth());
1454 if (isRTL(cur.paragraph()))
1455 cursorLeft(cur, true);
1456 cur.bv().cursor() = cur;
1459 case LFUN_FINISHED_RIGHT:
1460 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1461 cur.pop(cur.currentDepth());
1462 if (!isRTL(cur.paragraph()))
1463 cursorRight(cur, true);
1464 cur.bv().cursor() = cur;
1467 case LFUN_FINISHED_UP:
1468 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1469 cur.pop(cur.currentDepth());
1470 cursorUp(cur, true);
1471 cur.bv().cursor() = cur;
1474 case LFUN_FINISHED_DOWN:
1475 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1476 cur.pop(cur.currentDepth());
1477 cursorDown(cur, true);
1478 cur.bv().cursor() = cur;
1481 case LFUN_LAYOUT_PARAGRAPH: {
1483 params2string(cur.paragraph(), data);
1484 data = "show\n" + data;
1485 bv->owner()->getDialogs().show("paragraph", data);
1489 case LFUN_PARAGRAPH_UPDATE: {
1490 if (!bv->owner()->getDialogs().visible("paragraph"))
1493 params2string(cur.paragraph(), data);
1495 // Will the paragraph accept changes from the dialog?
1496 InsetBase * const inset = cur.inset();
1498 !(inset && inset->forceDefaultParagraphs(inset));
1500 data = "update " + tostr(accept) + '\n' + data;
1501 bv->owner()->getDialogs().update("paragraph", data);
1506 case LFUN_CIRCUMFLEX:
1516 case LFUN_SPECIAL_CARON:
1519 case LFUN_HUNG_UMLAUT:
1522 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1523 if (!cmd.argument.empty())
1524 bv->owner()->getIntl().getTransManager()
1525 .TranslateAndInsert(cmd.argument[0], this);
1528 case LFUN_FLOAT_LIST: {
1529 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1530 if (tclass.floats().typeExist(cmd.argument)) {
1531 // not quite sure if we want this...
1534 cur.clearSelection();
1535 breakParagraph(cur);
1537 if (cur.lastpos() != 0) {
1538 cursorLeft(cur, true);
1539 breakParagraph(cur);
1542 setLayout(cur, tclass.defaultLayoutName());
1543 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1544 cur.insert(new InsetFloatList(cmd.argument));
1547 lyxerr << "Non-existent float type: "
1548 << cmd.argument << endl;
1553 case LFUN_ACCEPT_CHANGE: {
1559 case LFUN_REJECT_CHANGE: {
1565 case LFUN_THESAURUS_ENTRY: {
1566 string arg = cmd.argument;
1568 arg = cur.selectionAsString(false);
1570 if (arg.size() > 100 || arg.empty()) {
1571 // Get word or selection
1572 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1573 arg = cur.selectionAsString(false);
1576 bv->owner()->getDialogs().show("thesaurus", arg);
1580 case LFUN_PARAGRAPH_APPLY: {
1581 // Given data, an encoding of the ParagraphParameters
1582 // generated in the Paragraph dialog, this function sets
1583 // the current paragraph appropriately.
1584 istringstream is(cmd.argument);
1587 ParagraphParameters params;
1592 params.labelWidthString(),
1595 cur.message(_("Paragraph layout set"));
1600 return DispatchResult(false);
1603 return DispatchResult(true, true);