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 "funcrequest.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
51 #include "mathed/math_hullinset.h"
55 using bv_funcs::replaceSelection;
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
65 using std::istringstream;
69 extern string current_layout;
71 // the selection possible is needed, that only motion events are
72 // used, where the button press event was on the drawing area too
73 bool selection_possible = false;
79 LyXFont freefont(LyXFont::ALL_IGNORE);
80 bool toggleall = false;
83 void toggleAndShow(BufferView * bv, LyXText * text,
84 LyXFont const & font, bool toggleall = true)
89 text->toggleFree(font, toggleall);
92 if (font.language() != ignore_language ||
93 font.number() != LyXFont::IGNORE) {
94 CursorSlice & cur = text->cursor();
95 Paragraph & par = *text->cursorPar();
96 text->bidi.computeTables(par, *bv->buffer(),
97 *par.getRow(cur.pos()));
99 text->bidi.isBoundary(*bv->buffer(), par,
101 text->real_current_font))
102 text->setCursor(cur.par(), cur.pos(),
103 false, !cur.boundary());
108 /// Apply the contents of freefont at the current cursor location.
109 void apply_freefont(BufferView * bv, LyXText * text)
111 toggleAndShow(bv, text, freefont, toggleall);
112 bv->owner()->view_state_changed();
113 bv->owner()->message(_("Character set"));
117 /** Set the freefont using the contents of \param data dispatched from
118 * the frontends and apply it at the current cursor location.
120 void update_and_apply_freefont(BufferView * bv, LyXText * text,
125 if (bv_funcs::string2font(data, font, toggle)) {
128 apply_freefont(bv, text);
133 void emph(BufferView * bv, LyXText * text)
135 LyXFont font(LyXFont::ALL_IGNORE);
136 font.setEmph(LyXFont::TOGGLE);
137 toggleAndShow(bv, text, font);
141 void bold(BufferView * bv, LyXText * text)
143 LyXFont font(LyXFont::ALL_IGNORE);
144 font.setSeries(LyXFont::BOLD_SERIES);
145 toggleAndShow(bv, text, font);
149 void noun(BufferView * bv, LyXText * text)
151 LyXFont font(LyXFont::ALL_IGNORE);
152 font.setNoun(LyXFont::TOGGLE);
153 toggleAndShow(bv, text, font);
157 void lang(BufferView * bv, string const & l, LyXText * text)
159 Language const * lang = languages.getLanguage(l);
163 LyXFont font(LyXFont::ALL_IGNORE);
164 font.setLanguage(lang);
165 toggleAndShow(bv, text, font);
169 void code(BufferView * bv, LyXText * text)
171 LyXFont font(LyXFont::ALL_IGNORE);
172 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
173 toggleAndShow(bv, text, font);
177 void sans(BufferView * bv, LyXText * text)
179 LyXFont font(LyXFont::ALL_IGNORE);
180 font.setFamily(LyXFont::SANS_FAMILY);
181 toggleAndShow(bv, text, font);
185 void roman(BufferView * bv, LyXText * text)
187 LyXFont font(LyXFont::ALL_IGNORE);
188 font.setFamily(LyXFont::ROMAN_FAMILY);
189 toggleAndShow(bv, text, font);
193 void styleReset(BufferView * bv, LyXText * text)
195 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
196 toggleAndShow(bv, text, font);
200 void underline(BufferView * bv, LyXText * text)
202 LyXFont font(LyXFont::ALL_IGNORE);
203 font.setUnderbar(LyXFont::TOGGLE);
204 toggleAndShow(bv, text, font);
208 void fontSize(BufferView * bv, string const & size, LyXText * text)
210 LyXFont font(LyXFont::ALL_IGNORE);
211 font.setLyXSize(size);
212 toggleAndShow(bv, text, font);
216 void moveCursor(LCursor & cur, bool selecting)
218 if (selecting || cur.mark())
220 if (!cur.selection())
221 cur.bv().haveSelection(false);
222 cur.bv().switchKeyMap();
226 void finishChange(BufferView * bv, bool selecting = false)
229 moveCursor(bv->cursor(), selecting);
230 bv->owner()->view_state_changed();
238 string const freefont2string()
241 if (font2string(freefont, toggleall, data))
249 InsetBase * LyXText::checkInsetHit(int x, int y)
251 ParagraphList::iterator pit;
252 ParagraphList::iterator end;
254 getParsInRange(paragraphs(),
256 bv()->top_y() + bv()->workHeight(),
259 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
260 for ( ; pit != end; ++pit) {
261 InsetList::iterator iit = pit->insetlist.begin();
262 InsetList::iterator iend = pit->insetlist.end();
263 for ( ; iit != iend; ++iit) {
264 InsetBase * inset = iit->inset;
266 lyxerr << "examining inset " << inset
267 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
268 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
269 << " yo: " << inset->yo() - inset->ascent() << "..."
270 << inset->yo() + inset->descent() << endl;
272 if (inset->covers(x, y - bv()->top_y())) {
273 lyxerr << "Hit inset: " << inset << endl;
278 lyxerr << "No inset hit. " << endl;
283 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
284 string const & contents)
286 ParagraphList::iterator end = paragraphs().end();
287 ParagraphList::iterator pit = cursorPar();
288 pos_type pos = cursor().pos();
292 if (pos + 1 < pit->size()) {
299 } while (pit != end &&
300 !(pit->isInset(pos) &&
301 (inset = pit->getInset(pos)) != 0 &&
302 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
304 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
310 setCursor(parOffset(pit), pos, false);
315 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
317 LCursor & cur = bv()->cursor();
318 cur.clearSelection();
322 && cur.pos() < cur.lastpos()
323 && cur.paragraph().isInset(cur.pos())) {
324 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
325 if (find(codes.begin(), codes.end(), inset->lyxCode())
327 contents = static_cast<InsetCommand const *>(inset)->getContents();
330 if (!gotoNextInset(codes, contents)) {
331 if (cur.pos() || cur.par() != 0) {
332 CursorSlice tmp = cursor();
335 if (!gotoNextInset(codes, contents)) {
337 cur.bv().owner()->message(_("No more insets"));
340 cur.bv().owner()->message(_("No more insets"));
348 void LyXText::gotoInset(InsetOld_code code, bool same_content)
350 gotoInset(vector<InsetOld_code>(1, code), same_content);
354 void LyXText::cursorPrevious()
356 LCursor & cur = bv()->cursor();
357 pos_type cpos = cur.pos();
358 lyx::paroffset_type cpar = cur.par();
360 int x = bv()->cursor().x_target();
361 int y = bv()->top_y();
362 setCursorFromCoordinates(x, y);
364 if (cpar == cur.par() && cpos == cur.pos()) {
365 // we have a row which is taller than the workarea. The
366 // simplest solution is to move to the previous row instead.
370 bv()->updateScrollbar();
375 void LyXText::cursorNext()
377 LCursor & cur = bv()->cursor();
378 pos_type cpos = cur.pos();
379 lyx::paroffset_type cpar = cur.par();
381 int x = cur.x_target();
382 int y = bv()->top_y() + bv()->workHeight();
383 setCursorFromCoordinates(x, y);
385 if (cpar == cur.par() && cpos == cur.pos()) {
386 // we have a row which is taller than the workarea. The
387 // simplest solution is to move to the next row instead.
391 bv()->updateScrollbar();
398 void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind)
401 replaceSelection(text);
402 text->insertInset(new InsetSpecialChar(kind));
407 void doInsertInset(LyXText * text, BufferView * bv, FuncRequest const & cmd,
408 bool edit, bool pastesel)
410 InsetBase * inset = createInset(bv, cmd);
415 if (bv->cursor().selection()) {
416 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
419 text->insertInset(inset);
421 inset->edit(bv->cursor(), true);
422 if (gotsel && pastesel)
423 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
429 void LyXText::number()
431 LyXFont font(LyXFont::ALL_IGNORE);
432 font.setNumber(LyXFont::TOGGLE);
433 toggleAndShow(bv(), this, font);
437 bool LyXText::rtl() const
439 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
443 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
445 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
446 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
448 BufferView * bv = &cur.bv();
450 switch (cmd.action) {
452 case LFUN_APPENDIX: {
453 ParagraphList::iterator pit = cursorPar();
454 bool start = !pit->params().startOfAppendix();
456 // ensure that we have only one start_of_appendix in this document
457 ParagraphList::iterator tmp = paragraphs().begin();
458 ParagraphList::iterator end = paragraphs().end();
460 for (; tmp != end; ++tmp) {
461 if (tmp->params().startOfAppendix()) {
462 recUndo(parOffset(tmp));
463 tmp->params().startOfAppendix(false);
469 recUndo(parOffset(pit));
470 pit->params().startOfAppendix(start);
472 // we can set the refreshing parameters now
474 redoParagraph(cursorPar());
479 case LFUN_DELETE_WORD_FORWARD:
480 cur.clearSelection();
485 case LFUN_DELETE_WORD_BACKWARD:
486 cur.clearSelection();
487 deleteWordBackward();
491 case LFUN_DELETE_LINE_FORWARD:
492 cur.clearSelection();
499 cur.clearSelection();
503 cursorRightOneWord();
509 cur.clearSelection();
511 cursorRightOneWord();
517 case LFUN_BEGINNINGBUF:
519 cur.clearSelection();
526 cur.clearSelection();
532 if (!cur.selection())
538 finishChange(bv, true);
542 if (!cur.selection())
548 finishChange(bv, true);
552 if (!cur.selection())
555 finishChange(bv, true);
559 if (!cur.selection())
562 finishChange(bv, true);
565 case LFUN_UP_PARAGRAPHSEL:
566 if (!cur.selection())
569 finishChange(bv, true);
572 case LFUN_DOWN_PARAGRAPHSEL:
573 if (!cur.selection())
575 cursorDownParagraph();
576 finishChange(bv, true);
580 if (!cur.selection())
583 finishChange(bv, true);
587 if (!cur.selection())
590 finishChange(bv, true);
594 if (!cur.selection())
597 finishChange(bv, true);
601 if (!cur.selection())
604 finishChange(bv, true);
607 case LFUN_WORDRIGHTSEL:
608 if (!cur.selection())
613 cursorRightOneWord();
614 finishChange(bv, true);
617 case LFUN_WORDLEFTSEL:
618 if (!cur.selection())
621 cursorRightOneWord();
624 finishChange(bv, true);
628 selectWord(lyx::WHOLE_WORD);
629 finishChange(bv, true);
649 case LFUN_UP_PARAGRAPH:
651 cur.clearSelection();
656 case LFUN_DOWN_PARAGRAPH:
658 cur.clearSelection();
659 cursorDownParagraph();
660 finishChange(bv, false);
665 cur.clearSelection();
666 finishChange(bv, false);
667 if (cur.par() == 0 && cursorRow() == firstRow())
668 return DispatchResult(false, FINISHED_UP);
674 cur.clearSelection();
675 finishChange(bv, false);
676 if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
677 return DispatchResult(false, FINISHED_DOWN);
683 cur.clearSelection();
685 finishChange(bv, false);
690 cur.clearSelection();
692 finishChange(bv, false);
695 case LFUN_BREAKLINE: {
696 lyx::pos_type body = cursorPar()->beginOfBody();
698 // Not allowed by LaTeX (labels or empty par)
699 if (cursor().pos() <= body)
702 replaceSelection(bv->getLyXText());
703 insertInset(new InsetNewline);
704 moveCursor(cur, false);
709 if (!cur.selection()) {
712 // It is possible to make it a lot faster still
713 // just comment out the line below...
715 cutSelection(true, false);
717 moveCursor(cur, false);
718 bv->owner()->view_state_changed();
721 case LFUN_DELETE_SKIP:
722 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
723 if (!cur.selection()) {
724 if (cursor().pos() == cursorPar()->size()) {
734 cutSelection(true, false);
741 if (!cur.selection()) {
742 if (bv->owner()->getIntl().getTransManager().backspace()) {
745 // It is possible to make it a lot faster still
746 // just comment out the line below...
749 cutSelection(true, false);
751 bv->owner()->view_state_changed();
756 case LFUN_BACKSPACE_SKIP:
757 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
758 if (!cur.selection()) {
760 //CursorSlice cur = cursor();
764 cutSelection(true, false);
769 case LFUN_BREAKPARAGRAPH:
770 replaceSelection(bv->getLyXText());
771 breakParagraph(bv->buffer()->paragraphs(), 0);
775 bv->owner()->view_state_changed();
778 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
779 replaceSelection(bv->getLyXText());
780 breakParagraph(bv->buffer()->paragraphs(), 1);
784 bv->owner()->view_state_changed();
787 case LFUN_BREAKPARAGRAPH_SKIP: {
788 // When at the beginning of a paragraph, remove
789 // indentation and add a "defskip" at the top.
790 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
792 // CursorSlice cur = cursor();
793 replaceSelection(bv->getLyXText());
794 if (cur.pos() == 0) {
795 ParagraphParameters & params = getPar(cur.current())->params();
799 params.labelWidthString(), 1);
801 breakParagraph(bv->buffer()->paragraphs(), 0);
806 bv->owner()->view_state_changed();
810 case LFUN_PARAGRAPH_SPACING: {
811 ParagraphList::iterator pit = cursorPar();
812 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
813 float cur_value = 1.0;
814 if (cur_spacing == Spacing::Other)
815 cur_value = pit->params().spacing().getValue();
817 istringstream is(cmd.argument);
820 Spacing::Space new_spacing = cur_spacing;
821 float new_value = cur_value;
823 lyxerr << "Missing argument to `paragraph-spacing'"
825 } else if (tmp == "single") {
826 new_spacing = Spacing::Single;
827 } else if (tmp == "onehalf") {
828 new_spacing = Spacing::Onehalf;
829 } else if (tmp == "double") {
830 new_spacing = Spacing::Double;
831 } else if (tmp == "other") {
832 new_spacing = Spacing::Other;
835 lyxerr << "new_value = " << tmpval << endl;
838 } else if (tmp == "default") {
839 new_spacing = Spacing::Default;
841 lyxerr << _("Unknown spacing argument: ")
842 << cmd.argument << endl;
844 if (cur_spacing != new_spacing || cur_value != new_value) {
845 pit->params().spacing(Spacing(new_spacing, new_value));
852 case LFUN_INSET_APPLY: {
853 string const name = cmd.getArg(0);
854 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
856 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
858 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
862 case LFUN_INSET_INSERT: {
863 InsetBase * inset = createInset(bv, cmd);
869 case LFUN_INSET_SETTINGS:
870 if (cur.inset() && cur.inset()->asUpdatableInset())
871 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
874 case LFUN_INSET_TOGGLE:
875 cur.clearSelection();
877 return DispatchResult(false);
882 case LFUN_SPACE_INSERT:
883 if (cursorPar()->layout()->free_spacing)
886 doInsertInset(this, bv, cmd, false, false);
887 moveCursor(cur, false);
890 case LFUN_HYPHENATION:
891 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
894 case LFUN_LIGATURE_BREAK:
895 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
899 specialChar(this, bv, InsetSpecialChar::LDOTS);
902 case LFUN_END_OF_SENTENCE:
903 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
906 case LFUN_MENU_SEPARATOR:
907 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
910 case LFUN_UPCASE_WORD:
911 changeCase(LyXText::text_uppercase);
915 case LFUN_LOWCASE_WORD:
916 changeCase(LyXText::text_lowercase);
920 case LFUN_CAPITALIZE_WORD:
921 changeCase(LyXText::text_capitalization);
925 case LFUN_TRANSPOSE_CHARS:
926 recUndo(cursor().par());
932 cur.message(_("Paste"));
933 replaceSelection(bv->getLyXText());
934 #warning FIXME Check if the arg is in the domain of available selections.
935 if (isStrUnsignedInt(cmd.argument))
936 pasteSelection(strToUnsignedInt(cmd.argument));
939 cur.clearSelection(); // bug 393
946 cutSelection(true, true);
947 cur.message(_("Cut"));
953 cur.message(_("Copy"));
956 case LFUN_BEGINNINGBUFSEL:
958 return DispatchResult(false);
959 if (!cur.selection())
962 finishChange(bv, true);
967 return DispatchResult(false);
968 if (!cur.selection())
971 finishChange(bv, true);
975 cur.message(tostr(cursorX(cur.current())) + ' '
976 + tostr(cursorY(cur.current())));
982 istringstream is(cmd.argument);
985 lyxerr << "SETXY: Could not parse coordinates in '"
986 << cmd.argument << std::endl;
988 setCursorFromCoordinates(x, y);
993 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
995 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1001 case LFUN_GETLAYOUT:
1002 cur.message(cursorPar()->layout()->name());
1006 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1007 << cmd.argument << endl;
1009 // This is not the good solution to the empty argument
1010 // problem, but it will hopefully suffice for 1.2.0.
1011 // The correct solution would be to augument the
1012 // function list/array with information about what
1013 // functions needs arguments and their type.
1014 if (cmd.argument.empty()) {
1015 cur.errorMessage(_("LyX function 'layout' needs an argument."));
1019 // Derive layout number from given argument (string)
1020 // and current buffer's textclass (number)
1021 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1022 bool hasLayout = tclass.hasLayout(cmd.argument);
1023 string layout = cmd.argument;
1025 // If the entry is obsolete, use the new one instead.
1027 string const & obs = tclass[layout]->obsoleted_by();
1033 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
1038 bool change_layout = (current_layout != layout);
1040 if (!change_layout && cur.selection() &&
1041 cur.selBegin().par() != cur.selEnd().par())
1043 ParagraphList::iterator spit = getPar(cur.selBegin());
1044 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
1045 while (spit != epit) {
1046 if (spit->layout()->name() != current_layout) {
1047 change_layout = true;
1054 if (change_layout) {
1055 current_layout = layout;
1057 bv->owner()->setLayout(layout);
1064 case LFUN_PASTESELECTION: {
1065 cur.clearSelection();
1066 string const clip = bv->getClipboard();
1067 if (!clip.empty()) {
1068 if (cmd.argument == "paragraph")
1069 insertStringAsParagraphs(clip);
1071 insertStringAsLines(clip);
1077 case LFUN_GOTOERROR:
1078 gotoInset(InsetBase::ERROR_CODE, false);
1082 gotoInset(InsetBase::NOTE_CODE, false);
1085 case LFUN_REFERENCE_GOTO: {
1086 vector<InsetOld_code> tmp;
1087 tmp.push_back(InsetBase::LABEL_CODE);
1088 tmp.push_back(InsetBase::REF_CODE);
1089 gotoInset(tmp, true);
1094 replaceSelection(bv->getLyXText());
1095 ParagraphList::iterator pit = cursorPar();
1096 lyx::pos_type pos = cursor().pos();
1100 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1103 c = pit->getChar(pos - 1);
1105 LyXLayout_ptr const & style = pit->layout();
1107 BufferParams const & bufparams = bv->buffer()->params();
1108 if (style->pass_thru ||
1109 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew")
1110 insertInset(new InsetQuotes(c, bufparams));
1112 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1116 case LFUN_DATE_INSERT: {
1117 replaceSelection(bv->getLyXText());
1118 time_t now_time_t = time(NULL);
1119 struct tm * now_tm = localtime(&now_time_t);
1120 setlocale(LC_TIME, "");
1122 if (!cmd.argument.empty())
1125 arg = lyxrc.date_insert_format;
1127 int const datetmp_len =
1128 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1130 for (int i = 0; i < datetmp_len; i++)
1131 insertChar(datetmp[i]);
1134 moveCursor(cur, false);
1138 case LFUN_MOUSE_TRIPLE:
1139 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1140 selection_possible = true;
1145 bv->haveSelection(cur.selection());
1149 case LFUN_MOUSE_DOUBLE:
1150 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1151 selection_possible = true;
1152 selectWord(lyx::WHOLE_WORD_STRICT);
1153 bv->haveSelection(cur.selection());
1157 case LFUN_MOUSE_MOTION: {
1159 // Only use motion with button 1
1160 //if (ev.button() != mouse_button::button1)
1162 // don't set anchor_
1163 bv->cursor().cursor_ = cur.cursor_;
1167 // The test for not selection possible is needed, that
1168 // only motion events are used, where the bottom press
1169 // event was on the drawing area too
1170 if (!selection_possible) {
1171 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1172 "Dispatch: no selection possible\n";
1175 RowList::iterator cursorrow = cursorRow();
1177 setCursorFromCoordinates(cmd.x, cmd.y);
1179 // This is to allow jumping over large insets
1180 // FIXME: shouldn't be top-text-specific
1181 if (cursorrow == cursorRow() && !in_inset_) {
1182 if (cmd.y - bv->top_y() >= bv->workHeight())
1184 else if (cmd.y - bv->top_y() < 0)
1192 // Single-click on work area
1193 case LFUN_MOUSE_PRESS: {
1197 // ok ok, this is a hack (for xforms)
1198 // We shouldn't go further down as we really should only do the
1199 // scrolling and be done with this. Otherwise we may open some
1200 // dialogs (Jug 20020424).
1201 if (cmd.button() == mouse_button::button4) {
1202 bv->scroll(-lyxrc.wheel_jump);
1205 if (cmd.button() == mouse_button::button5) {
1206 bv->scroll(lyxrc.wheel_jump);
1210 // Middle button press pastes if we have a selection
1211 // We do this here as if the selection was inside an inset
1212 // it could get cleared on the unlocking of the inset so
1213 // we have to check this first
1214 bool paste_internally = false;
1215 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1216 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1217 paste_internally = true;
1220 selection_possible = true;
1222 // Clear the selection
1223 cur.clearSelection();
1225 // Right click on a footnote flag opens float menu
1226 if (cmd.button() == mouse_button::button3) {
1227 selection_possible = false;
1231 setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
1234 cur.x_target() = cursorX(cur.current());
1236 // set cursor and anchor to this position
1239 if (bv->fitCursor())
1240 selection_possible = false;
1242 // Insert primary selection with middle mouse
1243 // if there is a local selection in the current buffer,
1245 if (cmd.button() == mouse_button::button2) {
1246 if (paste_internally)
1247 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1249 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1250 selection_possible = false;
1255 case LFUN_MOUSE_RELEASE: {
1259 // do nothing if we used the mouse wheel
1260 if (cmd.button() == mouse_button::button4
1261 || cmd.button() == mouse_button::button5)
1262 return DispatchResult(true, false);
1264 selection_possible = false;
1266 if (cmd.button() == mouse_button::button2)
1270 if (cmd.button() == mouse_button::button1)
1271 bv->haveSelection(cur.selection());
1274 bv->owner()->view_state_changed();
1275 bv->owner()->updateMenubar();
1276 bv->owner()->updateToolbar();
1280 case LFUN_SELFINSERT: {
1281 if (cmd.argument.empty())
1284 // Automatically delete the currently selected
1285 // text and replace it with what is being
1286 // typed in now. Depends on lyxrc settings
1287 // "auto_region_delete", which defaults to
1290 if (lyxrc.auto_region_delete) {
1291 if (cur.selection())
1292 cutSelection(false, false);
1293 bv->haveSelection(false);
1296 cur.clearSelection();
1297 LyXFont const old_font = real_current_font;
1299 string::const_iterator cit = cmd.argument.begin();
1300 string::const_iterator end = cmd.argument.end();
1301 for (; cit != end; ++cit)
1302 bv->owner()->getIntl().getTransManager().
1303 TranslateAndInsert(*cit, this);
1306 moveCursor(cur, false);
1308 // real_current_font.number can change so we need to
1309 // update the minibuffer
1310 if (old_font != real_current_font)
1311 bv->owner()->view_state_changed();
1312 bv->updateScrollbar();
1317 InsetCommandParams p("url");
1318 string const data = InsetCommandMailer::params2string("url", p);
1319 bv->owner()->getDialogs().show("url", data, 0);
1323 case LFUN_HTMLURL: {
1324 InsetCommandParams p("htmlurl");
1325 string const data = InsetCommandMailer::params2string("url", p);
1326 bv->owner()->getDialogs().show("url", data, 0);
1330 case LFUN_INSERT_LABEL: {
1331 InsetCommandParams p("label");
1332 string const data = InsetCommandMailer::params2string("label", p);
1333 bv->owner()->getDialogs().show("label", data, 0);
1339 case LFUN_INSET_LIST:
1340 case LFUN_INSET_THEOREM:
1341 case LFUN_INSET_CAPTION:
1343 case LFUN_INSERT_NOTE:
1344 case LFUN_INSERT_CHARSTYLE:
1345 case LFUN_INSERT_BOX:
1346 case LFUN_INSERT_BRANCH:
1347 case LFUN_INSERT_BIBITEM:
1348 case LFUN_INSET_ERT:
1349 case LFUN_INSET_FLOAT:
1350 case LFUN_INSET_FOOTNOTE:
1351 case LFUN_INSET_MARGINAL:
1352 case LFUN_INSET_OPTARG:
1353 case LFUN_INSET_WIDE_FLOAT:
1354 case LFUN_INSET_WRAP:
1355 case LFUN_TABULAR_INSERT:
1356 case LFUN_ENVIRONMENT_INSERT:
1357 // Open the inset, and move the current selection
1359 doInsertInset(this, bv, cmd, true, true);
1362 case LFUN_INDEX_INSERT:
1363 // Just open the inset
1364 doInsertInset(this, bv, cmd, true, false);
1367 case LFUN_INDEX_PRINT:
1368 case LFUN_TOC_INSERT:
1370 case LFUN_INSERT_LINE:
1371 case LFUN_INSERT_PAGEBREAK:
1373 doInsertInset(this, bv, cmd, false, false);
1376 case LFUN_DEPTH_MIN:
1377 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1381 case LFUN_DEPTH_PLUS:
1382 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1386 case LFUN_MATH_DELIM:
1387 case LFUN_MATH_DISPLAY:
1388 case LFUN_INSERT_MATH:
1389 case LFUN_MATH_LIMITS:
1390 case LFUN_MATH_MACRO:
1391 case LFUN_MATH_MUTATE:
1392 case LFUN_MATH_SPACE:
1393 case LFUN_MATH_IMPORT_SELECTION:
1394 case LFUN_MATH_MODE:
1395 case LFUN_MATH_NONUMBER:
1396 case LFUN_MATH_NUMBER:
1397 case LFUN_MATH_EXTERN:
1398 case LFUN_MATH_SIZE:
1399 mathDispatch(cur, cmd);
1404 bv->owner()->view_state_changed();
1409 bv->owner()->view_state_changed();
1414 bv->owner()->view_state_changed();
1419 bv->owner()->view_state_changed();
1424 bv->owner()->view_state_changed();
1429 bv->owner()->view_state_changed();
1433 styleReset(bv, this);
1434 bv->owner()->view_state_changed();
1437 case LFUN_UNDERLINE:
1438 underline(bv, this);
1439 bv->owner()->view_state_changed();
1442 case LFUN_FONT_SIZE:
1443 fontSize(bv, cmd.argument, this);
1444 bv->owner()->view_state_changed();
1448 lang(bv, cmd.argument, this);
1450 bv->owner()->view_state_changed();
1453 case LFUN_FREEFONT_APPLY:
1454 apply_freefont(bv, this);
1457 case LFUN_FREEFONT_UPDATE:
1458 update_and_apply_freefont(bv, this, cmd.argument);
1461 case LFUN_FINISHED_LEFT:
1462 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1463 cur.pop(cur.currentDepth());
1464 cur.bv().cursor() = cur;
1469 case LFUN_FINISHED_RIGHT:
1470 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1471 cur.pop(cur.currentDepth());
1472 cur.bv().cursor() = cur;
1477 case LFUN_FINISHED_UP:
1478 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1479 cur.pop(cur.currentDepth());
1480 cur.bv().cursor() = cur;
1484 case LFUN_FINISHED_DOWN:
1485 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1486 cur.pop(cur.currentDepth());
1487 cur.bv().cursor() = cur;
1492 return DispatchResult(false);
1495 return DispatchResult(true, true);