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/formulabase.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 bottom 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 InsetOld * LyXText::checkInsetHit(int x, int y)
251 ParagraphList::iterator pit;
252 ParagraphList::iterator end;
254 getParsInRange(paragraphs(),
256 bv()->top_y() - yo_ + 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 InsetOld * inset = iit->inset;
265 //lyxerr << "examining inset " << inset
266 // << " xy: " << inset->x() << "/" << inset->y()
267 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
268 // << " y: " << inset->y() - inset->ascent() << "..."
269 // << inset->y() + inset->descent()
272 && x <= inset->x() + inset->width()
273 && y >= inset->y() - inset->ascent()
274 && y <= inset->y() + inset->descent())
276 lyxerr << "Hit inset: " << inset << endl;
281 lyxerr << "No inset hit. " << endl;
286 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
287 string const & contents)
289 ParagraphList::iterator end = paragraphs().end();
290 ParagraphList::iterator pit = cursorPar();
291 pos_type pos = cursor().pos();
295 if (pos + 1 < pit->size()) {
302 } while (pit != end &&
303 !(pit->isInset(pos) &&
304 (inset = pit->getInset(pos)) != 0 &&
305 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
307 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
313 setCursor(parOffset(pit), pos, false);
318 void LyXText::gotoInset(vector<InsetOld::Code> const & codes, bool same_content)
320 LCursor & cur = bv()->cursor();
321 cur.clearSelection();
325 && cur.pos() < cur.lastpos()
326 && cur.paragraph().isInset(cur.pos())) {
327 InsetOld const * inset = cur.paragraph().getInset(cur.pos());
328 if (find(codes.begin(), codes.end(), inset->lyxCode())
330 contents = static_cast<InsetCommand const *>(inset)->getContents();
333 if (!gotoNextInset(codes, contents)) {
334 if (cur.pos() || cur.par() != 0) {
335 CursorSlice tmp = cursor();
338 if (!gotoNextInset(codes, contents)) {
340 cur.bv().owner()->message(_("No more insets"));
343 cur.bv().owner()->message(_("No more insets"));
351 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
353 gotoInset(vector<InsetOld::Code>(1, code), same_content);
357 void LyXText::cursorPrevious()
359 LCursor & cur = bv()->cursor();
360 RowList::iterator crit = cursorRow();
361 lyx::paroffset_type cpar = cur.par();
363 int x = bv()->cursor().x_target() - xo_;
364 int y = bv()->top_y() - yo_;
365 setCursorFromCoordinates(x, y);
367 if (cpar == cur.par() && crit == cursorRow()) {
368 // we have a row which is taller than the workarea. The
369 // simplest solution is to move to the previous row instead.
373 bv()->updateScrollbar();
378 void LyXText::cursorNext()
380 RowList::iterator crit = cursorRow();
381 ParagraphList::iterator cpar = cursorPar();
383 int x = bv()->cursor().x_target() - xo_;
384 int y = bv()->top_y() + bv()->workHeight() - yo_;
385 setCursorFromCoordinates(x, y);
387 if (cpar == cursorPar() && crit == cursorRow()) {
388 // we have a row which is taller than the workarea. The
389 // simplest solution is to move to the next row instead.
393 bv()->updateScrollbar();
400 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
403 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
404 replaceSelection(lt);
405 if (!bv->insertInset(new_inset))
412 void doInsertInset(BufferView * bv, FuncRequest const & cmd,
413 bool edit, bool pastesel)
415 InsetOld * inset = createInset(bv, cmd);
420 if (bv->cursor().selection()) {
421 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
424 if (bv->insertInset(inset)) {
426 inset->edit(bv->cursor(), true);
427 if (gotsel && pastesel)
428 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
437 void LyXText::number()
439 LyXFont font(LyXFont::ALL_IGNORE);
440 font.setNumber(LyXFont::TOGGLE);
441 toggleAndShow(bv(), this, font);
445 bool LyXText::rtl() const
447 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
451 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
453 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
455 BufferView * bv = &cur.bv();
457 switch (cmd.action) {
459 case LFUN_APPENDIX: {
460 ParagraphList::iterator pit = cursorPar();
461 bool start = !pit->params().startOfAppendix();
463 // ensure that we have only one start_of_appendix in this document
464 ParagraphList::iterator tmp = paragraphs().begin();
465 ParagraphList::iterator end = paragraphs().end();
467 for (; tmp != end; ++tmp) {
468 if (tmp->params().startOfAppendix()) {
469 recUndo(parOffset(tmp));
470 tmp->params().startOfAppendix(false);
476 recUndo(parOffset(pit));
477 pit->params().startOfAppendix(start);
479 // we can set the refreshing parameters now
481 redoParagraph(cursorPar());
486 case LFUN_DELETE_WORD_FORWARD:
487 cur.clearSelection();
492 case LFUN_DELETE_WORD_BACKWARD:
493 cur.clearSelection();
494 deleteWordBackward();
498 case LFUN_DELETE_LINE_FORWARD:
499 cur.clearSelection();
506 cur.clearSelection();
510 cursorRightOneWord();
516 cur.clearSelection();
518 cursorRightOneWord();
524 case LFUN_BEGINNINGBUF:
526 cur.clearSelection();
533 cur.clearSelection();
539 if (!cur.selection())
545 finishChange(bv, true);
549 if (!cur.selection())
555 finishChange(bv, true);
559 if (!cur.selection())
562 finishChange(bv, true);
566 if (!cur.selection())
569 finishChange(bv, true);
572 case LFUN_UP_PARAGRAPHSEL:
573 if (!cur.selection())
576 finishChange(bv, true);
579 case LFUN_DOWN_PARAGRAPHSEL:
580 if (!cur.selection())
582 cursorDownParagraph();
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);
608 if (!cur.selection())
611 finishChange(bv, true);
614 case LFUN_WORDRIGHTSEL:
615 if (!cur.selection())
620 cursorRightOneWord();
621 finishChange(bv, true);
624 case LFUN_WORDLEFTSEL:
625 if (!cur.selection())
628 cursorRightOneWord();
631 finishChange(bv, true);
635 selectWord(lyx::WHOLE_WORD);
636 finishChange(bv, true);
656 case LFUN_UP_PARAGRAPH:
658 cur.clearSelection();
663 case LFUN_DOWN_PARAGRAPH:
665 cur.clearSelection();
666 cursorDownParagraph();
667 finishChange(bv, false);
672 cur.clearSelection();
673 finishChange(bv, false);
674 if (cursorPar() == firstPar() && cursorRow() == firstRow())
675 return DispatchResult(false, FINISHED_UP);
681 cur.clearSelection();
682 finishChange(bv, false);
683 if (cursorPar() == lastPar() && cursorRow() == lastRow())
684 return DispatchResult(false, FINISHED_DOWN);
690 cur.clearSelection();
692 finishChange(bv, false);
697 cur.clearSelection();
699 finishChange(bv, false);
702 case LFUN_BREAKLINE: {
703 lyx::pos_type body = cursorPar()->beginOfBody();
705 // Not allowed by LaTeX (labels or empty par)
706 if (cursor().pos() <= body)
709 replaceSelection(bv->getLyXText());
710 insertInset(new InsetNewline);
711 moveCursor(cur, false);
716 if (!cur.selection()) {
719 // It is possible to make it a lot faster still
720 // just comment out the line below...
722 cutSelection(true, false);
724 moveCursor(cur, false);
725 bv->owner()->view_state_changed();
728 case LFUN_DELETE_SKIP:
729 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
730 if (!cur.selection()) {
731 if (cursor().pos() == cursorPar()->size()) {
741 cutSelection(true, false);
748 if (!cur.selection()) {
749 if (bv->owner()->getIntl().getTransManager().backspace()) {
752 // It is possible to make it a lot faster still
753 // just comment out the line below...
756 cutSelection(true, false);
758 bv->owner()->view_state_changed();
763 case LFUN_BACKSPACE_SKIP:
764 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
765 if (!cur.selection()) {
766 CursorSlice cur = cursor();
770 cutSelection(true, false);
775 case LFUN_BREAKPARAGRAPH:
776 replaceSelection(bv->getLyXText());
777 breakParagraph(bv->buffer()->paragraphs(), 0);
781 bv->owner()->view_state_changed();
784 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
785 replaceSelection(bv->getLyXText());
786 breakParagraph(bv->buffer()->paragraphs(), 1);
790 bv->owner()->view_state_changed();
793 case LFUN_BREAKPARAGRAPH_SKIP: {
794 // When at the beginning of a paragraph, remove
795 // indentation and add a "defskip" at the top.
796 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
797 CursorSlice cur = cursor();
798 replaceSelection(bv->getLyXText());
799 if (cur.pos() == 0) {
800 ParagraphParameters & params = getPar(cur)->params();
804 params.labelWidthString(), 1);
806 breakParagraph(bv->buffer()->paragraphs(), 0);
811 bv->owner()->view_state_changed();
815 case LFUN_PARAGRAPH_SPACING: {
816 ParagraphList::iterator pit = cursorPar();
817 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
818 float cur_value = 1.0;
819 if (cur_spacing == Spacing::Other)
820 cur_value = pit->params().spacing().getValue();
822 istringstream is(cmd.argument);
825 Spacing::Space new_spacing = cur_spacing;
826 float new_value = cur_value;
828 lyxerr << "Missing argument to `paragraph-spacing'"
830 } else if (tmp == "single") {
831 new_spacing = Spacing::Single;
832 } else if (tmp == "onehalf") {
833 new_spacing = Spacing::Onehalf;
834 } else if (tmp == "double") {
835 new_spacing = Spacing::Double;
836 } else if (tmp == "other") {
837 new_spacing = Spacing::Other;
840 lyxerr << "new_value = " << tmpval << endl;
843 } else if (tmp == "default") {
844 new_spacing = Spacing::Default;
846 lyxerr << _("Unknown spacing argument: ")
847 << cmd.argument << endl;
849 if (cur_spacing != new_spacing || cur_value != new_value) {
850 pit->params().spacing(Spacing(new_spacing, new_value));
857 case LFUN_INSET_APPLY: {
858 string const name = cmd.getArg(0);
859 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
861 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
863 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
867 case LFUN_INSET_INSERT: {
868 InsetOld * inset = createInset(bv, cmd);
869 if (inset && !bv->insertInset(inset))
874 case LFUN_INSET_SETTINGS:
875 if (cur.inset() && cur.inset()->asUpdatableInset())
876 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
879 case LFUN_INSET_TOGGLE:
880 cur.clearSelection();
882 return DispatchResult(false);
887 case LFUN_SPACE_INSERT:
888 if (cursorPar()->layout()->free_spacing)
891 doInsertInset(bv, cmd, false, false);
892 moveCursor(cur, false);
895 case LFUN_HYPHENATION:
896 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
899 case LFUN_LIGATURE_BREAK:
900 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
904 specialChar(this, bv, InsetSpecialChar::LDOTS);
907 case LFUN_END_OF_SENTENCE:
908 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
911 case LFUN_MENU_SEPARATOR:
912 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
915 case LFUN_UPCASE_WORD:
916 changeCase(LyXText::text_uppercase);
920 case LFUN_LOWCASE_WORD:
921 changeCase(LyXText::text_lowercase);
925 case LFUN_CAPITALIZE_WORD:
926 changeCase(LyXText::text_capitalization);
930 case LFUN_TRANSPOSE_CHARS:
931 recUndo(cursor().par());
937 cmd.message(_("Paste"));
938 replaceSelection(bv->getLyXText());
939 #warning FIXME Check if the arg is in the domain of available selections.
940 if (isStrUnsignedInt(cmd.argument))
941 pasteSelection(strToUnsignedInt(cmd.argument));
944 cur.clearSelection(); // bug 393
951 cutSelection(true, true);
952 cmd.message(_("Cut"));
958 cmd.message(_("Copy"));
961 case LFUN_BEGINNINGBUFSEL:
963 return DispatchResult(false);
964 if (!cur.selection())
967 finishChange(bv, true);
972 return DispatchResult(false);
973 if (!cur.selection())
976 finishChange(bv, true);
980 cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
986 istringstream is(cmd.argument);
989 lyxerr << "SETXY: Could not parse coordinates in '"
990 << cmd.argument << std::endl;
992 setCursorFromCoordinates(x, y);
997 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
999 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1005 case LFUN_GETLAYOUT:
1006 cmd.message(cursorPar()->layout()->name());
1010 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1011 << cmd.argument << endl;
1013 // This is not the good solution to the empty argument
1014 // problem, but it will hopefully suffice for 1.2.0.
1015 // The correct solution would be to augument the
1016 // function list/array with information about what
1017 // functions needs arguments and their type.
1018 if (cmd.argument.empty()) {
1019 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1023 // Derive layout number from given argument (string)
1024 // and current buffer's textclass (number)
1025 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1026 bool hasLayout = tclass.hasLayout(cmd.argument);
1027 string layout = cmd.argument;
1029 // If the entry is obsolete, use the new one instead.
1031 string const & obs = tclass[layout]->obsoleted_by();
1037 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1042 bool change_layout = (current_layout != layout);
1044 if (!change_layout && cur.selection() &&
1045 cur.selStart().par() != cur.selEnd().par())
1047 ParagraphList::iterator spit = getPar(cur.selStart());
1048 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
1049 while (spit != epit) {
1050 if (spit->layout()->name() != current_layout) {
1051 change_layout = true;
1058 if (change_layout) {
1059 current_layout = layout;
1061 bv->owner()->setLayout(layout);
1068 case LFUN_PASTESELECTION: {
1069 cur.clearSelection();
1070 string const clip = bv->getClipboard();
1071 if (!clip.empty()) {
1072 if (cmd.argument == "paragraph")
1073 insertStringAsParagraphs(clip);
1075 insertStringAsLines(clip);
1081 case LFUN_GOTOERROR:
1082 gotoInset(InsetOld::ERROR_CODE, false);
1086 gotoInset(InsetOld::NOTE_CODE, false);
1089 case LFUN_REFERENCE_GOTO: {
1090 vector<InsetOld::Code> tmp;
1091 tmp.push_back(InsetOld::LABEL_CODE);
1092 tmp.push_back(InsetOld::REF_CODE);
1093 gotoInset(tmp, true);
1098 replaceSelection(bv->getLyXText());
1099 ParagraphList::iterator pit = cursorPar();
1100 lyx::pos_type pos = cursor().pos();
1104 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1107 c = pit->getChar(pos - 1);
1109 LyXLayout_ptr const & style = pit->layout();
1111 BufferParams const & bufparams = bv->buffer()->params();
1112 if (style->pass_thru ||
1113 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1114 !bv->insertInset(new InsetQuotes(c, bufparams)))
1115 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1119 case LFUN_DATE_INSERT: {
1120 replaceSelection(bv->getLyXText());
1121 time_t now_time_t = time(NULL);
1122 struct tm * now_tm = localtime(&now_time_t);
1123 setlocale(LC_TIME, "");
1125 if (!cmd.argument.empty())
1128 arg = lyxrc.date_insert_format;
1130 int const datetmp_len =
1131 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1133 for (int i = 0; i < datetmp_len; i++)
1134 insertChar(datetmp[i]);
1137 moveCursor(cur, false);
1141 case LFUN_MOUSE_TRIPLE:
1142 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1143 selection_possible = true;
1148 bv->haveSelection(cur.selection());
1152 case LFUN_MOUSE_DOUBLE:
1153 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1154 selection_possible = true;
1155 selectWord(lyx::WHOLE_WORD_STRICT);
1156 bv->haveSelection(cur.selection());
1160 case LFUN_MOUSE_MOTION: {
1161 // Only use motion with button 1
1162 //if (ev.button() != mouse_button::button1)
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)
1191 // Single-click on work area
1192 case LFUN_MOUSE_PRESS: {
1196 // ok ok, this is a hack (for xforms)
1197 // We shouldn't go further down as we really should only do the
1198 // scrolling and be done with this. Otherwise we may open some
1199 // dialogs (Jug 20020424).
1200 if (cmd.button() == mouse_button::button4) {
1201 bv->scroll(-lyxrc.wheel_jump);
1204 if (cmd.button() == mouse_button::button5) {
1205 bv->scroll(lyxrc.wheel_jump);
1209 // Middle button press pastes if we have a selection
1210 // We do this here as if the selection was inside an inset
1211 // it could get cleared on the unlocking of the inset so
1212 // we have to check this first
1213 bool paste_internally = false;
1214 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1215 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1216 paste_internally = true;
1219 selection_possible = true;
1221 // Clear the selection
1222 cur.clearSelection();
1224 // Right click on a footnote flag opens float menu
1225 if (cmd.button() == mouse_button::button3) {
1226 selection_possible = false;
1230 setCursorFromCoordinates(cmd.x, cmd.y);
1233 cur.x_target(cursorX() + xo_);
1235 if (bv->fitCursor())
1236 selection_possible = false;
1238 // Insert primary selection with middle mouse
1239 // if there is a local selection in the current buffer,
1241 if (cmd.button() == mouse_button::button2) {
1242 if (paste_internally)
1243 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1245 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1246 selection_possible = false;
1251 case LFUN_MOUSE_RELEASE: {
1255 // do nothing if we used the mouse wheel
1256 if (cmd.button() == mouse_button::button4
1257 || cmd.button() == mouse_button::button5)
1258 return DispatchResult(true, false);
1260 selection_possible = false;
1262 if (cmd.button() == mouse_button::button2)
1266 if (cmd.button() == mouse_button::button1)
1267 bv->haveSelection(cur.selection());
1270 bv->owner()->view_state_changed();
1271 bv->owner()->updateMenubar();
1272 bv->owner()->updateToolbar();
1276 case LFUN_SELFINSERT: {
1277 if (cmd.argument.empty())
1280 // Automatically delete the currently selected
1281 // text and replace it with what is being
1282 // typed in now. Depends on lyxrc settings
1283 // "auto_region_delete", which defaults to
1286 if (lyxrc.auto_region_delete) {
1287 if (cur.selection())
1288 cutSelection(false, false);
1289 bv->haveSelection(false);
1292 cur.clearSelection();
1293 LyXFont const old_font = real_current_font;
1295 string::const_iterator cit = cmd.argument.begin();
1296 string::const_iterator end = cmd.argument.end();
1297 for (; cit != end; ++cit)
1298 bv->owner()->getIntl().getTransManager().
1299 TranslateAndInsert(*cit, this);
1302 moveCursor(cur, false);
1304 // real_current_font.number can change so we need to
1305 // update the minibuffer
1306 if (old_font != real_current_font)
1307 bv->owner()->view_state_changed();
1308 bv->updateScrollbar();
1313 InsetCommandParams p("url");
1314 string const data = InsetCommandMailer::params2string("url", p);
1315 bv->owner()->getDialogs().show("url", data, 0);
1319 case LFUN_HTMLURL: {
1320 InsetCommandParams p("htmlurl");
1321 string const data = InsetCommandMailer::params2string("url", p);
1322 bv->owner()->getDialogs().show("url", data, 0);
1326 case LFUN_INSERT_LABEL: {
1327 InsetCommandParams p("label");
1328 string const data = InsetCommandMailer::params2string("label", p);
1329 bv->owner()->getDialogs().show("label", data, 0);
1335 case LFUN_INSET_LIST:
1336 case LFUN_INSET_THEOREM:
1337 case LFUN_INSET_CAPTION:
1339 case LFUN_INSERT_NOTE:
1340 case LFUN_INSERT_CHARSTYLE:
1341 case LFUN_INSERT_BOX:
1342 case LFUN_INSERT_BRANCH:
1343 case LFUN_INSERT_BIBITEM:
1344 case LFUN_INSET_ERT:
1345 case LFUN_INSET_FLOAT:
1346 case LFUN_INSET_FOOTNOTE:
1347 case LFUN_INSET_MARGINAL:
1348 case LFUN_INSET_OPTARG:
1349 case LFUN_INSET_WIDE_FLOAT:
1350 case LFUN_INSET_WRAP:
1351 case LFUN_TABULAR_INSERT:
1352 case LFUN_ENVIRONMENT_INSERT:
1353 // Open the inset, and move the current selection
1355 doInsertInset(bv, cmd, true, true);
1358 case LFUN_INDEX_INSERT:
1359 // Just open the inset
1360 doInsertInset(bv, cmd, true, false);
1363 case LFUN_INDEX_PRINT:
1364 case LFUN_TOC_INSERT:
1366 case LFUN_INSERT_LINE:
1367 case LFUN_INSERT_PAGEBREAK:
1369 doInsertInset(bv, cmd, false, false);
1372 case LFUN_DEPTH_MIN:
1373 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1377 case LFUN_DEPTH_PLUS:
1378 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1382 case LFUN_MATH_DELIM:
1383 case LFUN_MATH_DISPLAY:
1384 case LFUN_INSERT_MATH:
1385 case LFUN_MATH_LIMITS:
1386 case LFUN_MATH_MACRO:
1387 case LFUN_MATH_MUTATE:
1388 case LFUN_MATH_SPACE:
1389 case LFUN_MATH_IMPORT_SELECTION:
1390 case LFUN_MATH_MODE:
1391 case LFUN_MATH_NONUMBER:
1392 case LFUN_MATH_NUMBER:
1393 case LFUN_MATH_EXTERN:
1394 case LFUN_MATH_SIZE:
1395 mathDispatch(cur, cmd);
1400 bv->owner()->view_state_changed();
1405 bv->owner()->view_state_changed();
1410 bv->owner()->view_state_changed();
1415 bv->owner()->view_state_changed();
1420 bv->owner()->view_state_changed();
1425 bv->owner()->view_state_changed();
1429 styleReset(bv, this);
1430 bv->owner()->view_state_changed();
1433 case LFUN_UNDERLINE:
1434 underline(bv, this);
1435 bv->owner()->view_state_changed();
1438 case LFUN_FONT_SIZE:
1439 fontSize(bv, cmd.argument, this);
1440 bv->owner()->view_state_changed();
1444 lang(bv, cmd.argument, this);
1446 bv->owner()->view_state_changed();
1449 case LFUN_FREEFONT_APPLY:
1450 apply_freefont(bv, this);
1453 case LFUN_FREEFONT_UPDATE:
1454 update_and_apply_freefont(bv, this, cmd.argument);
1457 case LFUN_FINISHED_LEFT:
1458 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1463 case LFUN_FINISHED_RIGHT:
1464 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1469 case LFUN_FINISHED_UP:
1470 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1474 case LFUN_FINISHED_DOWN:
1475 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1480 return DispatchResult(false);
1483 return DispatchResult(true, true);