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(BufferView * bv, bool selecting)
218 LyXText * lt = bv->getLyXText();
220 if (selecting || bv->selection().mark())
223 if (!bv->selection().set())
224 bv->haveSelection(false);
229 void finishChange(BufferView * bv, bool selecting = false)
232 moveCursor(bv, selecting);
233 bv->owner()->view_state_changed();
241 string const freefont2string()
244 if (font2string(freefont, toggleall, data))
252 InsetOld * LyXText::checkInsetHit(int x, int y)
254 ParagraphList::iterator pit;
255 ParagraphList::iterator end;
257 getParsInRange(paragraphs(),
259 bv()->top_y() - yo_ + bv()->workHeight(),
262 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
263 for ( ; pit != end; ++pit) {
264 InsetList::iterator iit = pit->insetlist.begin();
265 InsetList::iterator iend = pit->insetlist.end();
266 for ( ; iit != iend; ++iit) {
267 InsetOld * inset = iit->inset;
268 //lyxerr << "examining inset " << inset
269 // << " xy: " << inset->x() << "/" << inset->y()
270 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
271 // << " y: " << inset->y() - inset->ascent() << "..."
272 // << inset->y() + inset->descent()
275 && x <= inset->x() + inset->width()
276 && y >= inset->y() - inset->ascent()
277 && y <= inset->y() + inset->descent())
279 lyxerr << "Hit inset: " << inset << endl;
284 lyxerr << "No inset hit. " << endl;
289 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
290 string const & contents)
292 ParagraphList::iterator end = paragraphs().end();
293 ParagraphList::iterator pit = cursorPar();
294 pos_type pos = cursor().pos();
298 if (pos + 1 < pit->size()) {
305 } while (pit != end &&
306 !(pit->isInset(pos) &&
307 (inset = pit->getInset(pos)) != 0 &&
308 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
310 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
316 setCursor(parOffset(pit), pos, false);
321 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
327 if (same_content && cursor().pos() < cursorPar()->size()
328 && cursorPar()->isInset(cursor().pos())) {
329 InsetOld const * inset = cursorPar()->getInset(cursor().pos());
330 if (find(codes.begin(), codes.end(), inset->lyxCode())
332 contents = static_cast<InsetCommand const *>(inset)->getContents();
335 if (!gotoNextInset(codes, contents)) {
336 if (cursor().pos() || cursorPar() != paragraphs().begin()) {
337 CursorSlice tmp = cursor();
340 if (!gotoNextInset(codes, contents)) {
342 bv()->owner()->message(_("No more insets"));
345 bv()->owner()->message(_("No more insets"));
353 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
355 gotoInset(vector<InsetOld::Code>(1, code), same_content);
359 void LyXText::cursorPrevious()
362 RowList::iterator crit = cursorRow();
363 ParagraphList::iterator cpar = cursorPar();
365 int x = bv()->x_target() - xo_;
366 int y = bv()->top_y() - yo_;
367 setCursorFromCoordinates(x, y);
369 if (cpar == cursorPar() && crit == cursorRow()) {
370 // we have a row which is taller than the workarea. The
371 // simplest solution is to move to the previous row instead.
375 bv()->updateScrollbar();
380 void LyXText::cursorNext()
382 RowList::iterator crit = cursorRow();
383 ParagraphList::iterator cpar = cursorPar();
385 int x = bv()->x_target() - xo_;
386 int y = bv()->top_y() + bv()->workHeight() - yo_;
387 setCursorFromCoordinates(x, y);
389 if (cpar == cursorPar() && crit == cursorRow()) {
390 // we have a row which is taller than the workarea. The
391 // simplest solution is to move to the next row instead.
395 bv()->updateScrollbar();
402 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
405 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
406 replaceSelection(lt);
407 if (!bv->insertInset(new_inset))
414 void doInsertInset(FuncRequest const & cmd, bool edit, bool pastesel)
416 InsetOld * inset = createInset(cmd);
420 BufferView * bv = cmd.view();
423 if (bv->selection().set()) {
424 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
427 if (bv->insertInset(inset)) {
429 inset->edit(bv, true);
430 if (gotsel && pastesel)
431 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
439 void LyXText::number()
441 LyXFont font(LyXFont::ALL_IGNORE);
442 font.setNumber(LyXFont::TOGGLE);
443 toggleAndShow(bv(), this, font);
447 bool LyXText::rtl() const
449 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
453 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
455 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
457 BufferView * bv = cmd.view();
459 switch (cmd.action) {
461 case LFUN_APPENDIX: {
462 ParagraphList::iterator pit = cursorPar();
463 bool start = !pit->params().startOfAppendix();
465 // ensure that we have only one start_of_appendix in this document
466 ParagraphList::iterator tmp = paragraphs().begin();
467 ParagraphList::iterator end = paragraphs().end();
469 for (; tmp != end; ++tmp) {
470 if (tmp->params().startOfAppendix()) {
471 recUndo(parOffset(tmp));
472 tmp->params().startOfAppendix(false);
478 recUndo(parOffset(pit));
479 pit->params().startOfAppendix(start);
481 // we can set the refreshing parameters now
483 redoParagraph(cursorPar());
488 case LFUN_DELETE_WORD_FORWARD:
494 case LFUN_DELETE_WORD_BACKWARD:
496 deleteWordBackward();
500 case LFUN_DELETE_LINE_FORWARD:
507 if (!bv->selection().mark())
512 cursorRightOneWord();
517 if (!bv->selection().mark())
520 cursorRightOneWord();
526 case LFUN_BEGINNINGBUF:
527 if (!bv->selection().mark())
534 if (bv->selection().mark())
541 if (!bv->selection().set())
547 finishChange(bv, true);
551 if (!bv->selection().set())
557 finishChange(bv, true);
561 if (!bv->selection().set())
564 finishChange(bv, true);
568 if (!bv->selection().set())
571 finishChange(bv, true);
574 case LFUN_UP_PARAGRAPHSEL:
575 if (!bv->selection().set())
578 finishChange(bv, true);
581 case LFUN_DOWN_PARAGRAPHSEL:
582 if (!bv->selection().set())
584 cursorDownParagraph();
585 finishChange(bv, true);
589 if (!bv->selection().set())
592 finishChange(bv, true);
596 if (!bv->selection().set())
599 finishChange(bv, true);
603 if (!bv->selection().set())
606 finishChange(bv, true);
610 if (!bv->selection().set())
613 finishChange(bv, true);
616 case LFUN_WORDRIGHTSEL:
617 if (!bv->selection().set())
622 cursorRightOneWord();
623 finishChange(bv, true);
626 case LFUN_WORDLEFTSEL:
627 if (!bv->selection().set())
630 cursorRightOneWord();
633 finishChange(bv, true);
637 selectWord(lyx::WHOLE_WORD);
638 finishChange(bv, true);
658 case LFUN_UP_PARAGRAPH:
659 if (!bv->selection().mark())
665 case LFUN_DOWN_PARAGRAPH:
666 if (!bv->selection().mark())
668 cursorDownParagraph();
669 finishChange(bv, false);
673 if (!bv->selection().mark())
675 finishChange(bv, false);
676 if (cursorPar() == firstPar() && cursorRow() == firstRow())
677 return DispatchResult(false, FINISHED_UP);
682 if (!bv->selection().mark())
684 finishChange(bv, false);
685 if (cursorPar() == lastPar() && cursorRow() == lastRow())
686 return DispatchResult(false, FINISHED_DOWN);
691 if (!bv->selection().mark())
694 finishChange(bv, false);
698 if (!bv->selection().mark())
701 finishChange(bv, false);
704 case LFUN_BREAKLINE: {
705 lyx::pos_type body = cursorPar()->beginOfBody();
707 // Not allowed by LaTeX (labels or empty par)
708 if (cursor().pos() <= body)
711 replaceSelection(bv->getLyXText());
712 insertInset(new InsetNewline);
713 moveCursor(bv, false);
718 if (!bv->selection().set()) {
721 // It is possible to make it a lot faster still
722 // just comment out the line below...
724 cutSelection(true, false);
726 moveCursor(bv, false);
727 bv->owner()->view_state_changed();
730 case LFUN_DELETE_SKIP:
731 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
732 if (!bv->selection().set()) {
733 if (cursor().pos() == cursorPar()->size()) {
743 cutSelection(true, false);
750 if (!bv->selection().set()) {
751 if (bv->owner()->getIntl().getTransManager().backspace()) {
754 // It is possible to make it a lot faster still
755 // just comment out the line below...
758 cutSelection(true, false);
760 bv->owner()->view_state_changed();
765 case LFUN_BACKSPACE_SKIP:
766 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
767 if (!bv->selection().set()) {
768 CursorSlice cur = cursor();
772 cutSelection(true, false);
777 case LFUN_BREAKPARAGRAPH:
778 replaceSelection(bv->getLyXText());
779 breakParagraph(bv->buffer()->paragraphs(), 0);
783 bv->owner()->view_state_changed();
786 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
787 replaceSelection(bv->getLyXText());
788 breakParagraph(bv->buffer()->paragraphs(), 1);
792 bv->owner()->view_state_changed();
795 case LFUN_BREAKPARAGRAPH_SKIP: {
796 // When at the beginning of a paragraph, remove
797 // indentation and add a "defskip" at the top.
798 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
799 CursorSlice cur = cursor();
800 replaceSelection(bv->getLyXText());
801 if (cur.pos() == 0) {
802 ParagraphParameters & params = getPar(cur)->params();
806 params.labelWidthString(), 1);
808 breakParagraph(bv->buffer()->paragraphs(), 0);
813 bv->owner()->view_state_changed();
817 case LFUN_PARAGRAPH_SPACING: {
818 ParagraphList::iterator pit = cursorPar();
819 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
820 float cur_value = 1.0;
821 if (cur_spacing == Spacing::Other)
822 cur_value = pit->params().spacing().getValue();
824 istringstream is(cmd.argument);
827 Spacing::Space new_spacing = cur_spacing;
828 float new_value = cur_value;
830 lyxerr << "Missing argument to `paragraph-spacing'"
832 } else if (tmp == "single") {
833 new_spacing = Spacing::Single;
834 } else if (tmp == "onehalf") {
835 new_spacing = Spacing::Onehalf;
836 } else if (tmp == "double") {
837 new_spacing = Spacing::Double;
838 } else if (tmp == "other") {
839 new_spacing = Spacing::Other;
842 lyxerr << "new_value = " << tmpval << endl;
845 } else if (tmp == "default") {
846 new_spacing = Spacing::Default;
848 lyxerr << _("Unknown spacing argument: ")
849 << cmd.argument << endl;
851 if (cur_spacing != new_spacing || cur_value != new_value) {
852 pit->params().spacing(Spacing(new_spacing, new_value));
859 case LFUN_INSET_APPLY: {
860 string const name = cmd.getArg(0);
861 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
863 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
866 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
872 case LFUN_INSET_INSERT: {
873 InsetOld * inset = createInset(cmd);
874 if (inset && !bv->insertInset(inset))
879 case LFUN_INSET_SETTINGS:
880 bv->fullCursor().innerInset()->showInsetDialog(bv);
883 case LFUN_INSET_TOGGLE:
886 return DispatchResult(false);
891 case LFUN_SPACE_INSERT:
892 if (cursorPar()->layout()->free_spacing)
895 doInsertInset(cmd, false, false);
896 moveCursor(bv, false);
899 case LFUN_HYPHENATION:
900 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
903 case LFUN_LIGATURE_BREAK:
904 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
908 specialChar(this, bv, InsetSpecialChar::LDOTS);
911 case LFUN_END_OF_SENTENCE:
912 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
915 case LFUN_MENU_SEPARATOR:
916 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
923 cmd.message(N_("Mark off"));
928 bv->selection().mark(true);
931 cmd.message(N_("Mark on"));
936 if (bv->selection().mark()) {
937 cmd.message(N_("Mark removed"));
939 bv->selection().mark(true);
940 cmd.message(N_("Mark set"));
946 case LFUN_UPCASE_WORD:
947 changeCase(LyXText::text_uppercase);
951 case LFUN_LOWCASE_WORD:
952 changeCase(LyXText::text_lowercase);
956 case LFUN_CAPITALIZE_WORD:
957 changeCase(LyXText::text_capitalization);
961 case LFUN_TRANSPOSE_CHARS:
962 recUndo(cursor().par());
968 cmd.message(_("Paste"));
969 replaceSelection(bv->getLyXText());
970 #warning FIXME Check if the arg is in the domain of available selections.
971 if (isStrUnsignedInt(cmd.argument))
972 pasteSelection(strToUnsignedInt(cmd.argument));
975 clearSelection(); // bug 393
982 cutSelection(true, true);
983 cmd.message(_("Cut"));
989 cmd.message(_("Copy"));
992 case LFUN_BEGINNINGBUFSEL:
994 return DispatchResult(false);
995 if (!bv->selection().set())
998 finishChange(bv, true);
1001 case LFUN_ENDBUFSEL:
1003 return DispatchResult(false);
1004 if (!bv->selection().set())
1007 finishChange(bv, true);
1011 cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
1017 istringstream is(cmd.argument);
1020 lyxerr << "SETXY: Could not parse coordinates in '"
1021 << cmd.argument << std::endl;
1023 setCursorFromCoordinates(x, y);
1028 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1030 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1036 case LFUN_GETLAYOUT:
1037 cmd.message(cursorPar()->layout()->name());
1041 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1042 << cmd.argument << endl;
1044 // This is not the good solution to the empty argument
1045 // problem, but it will hopefully suffice for 1.2.0.
1046 // The correct solution would be to augument the
1047 // function list/array with information about what
1048 // functions needs arguments and their type.
1049 if (cmd.argument.empty()) {
1050 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1054 // Derive layout number from given argument (string)
1055 // and current buffer's textclass (number)
1056 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1057 bool hasLayout = tclass.hasLayout(cmd.argument);
1058 string layout = cmd.argument;
1060 // If the entry is obsolete, use the new one instead.
1062 string const & obs = tclass[layout]->obsoleted_by();
1068 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1073 bool change_layout = (current_layout != layout);
1075 if (!change_layout && bv->selection().set() &&
1076 bv->selStart().par() != bv->selEnd().par())
1078 ParagraphList::iterator spit = getPar(bv->selStart());
1079 ParagraphList::iterator epit = boost::next(getPar(bv->selEnd()));
1080 while (spit != epit) {
1081 if (spit->layout()->name() != current_layout) {
1082 change_layout = true;
1089 if (change_layout) {
1090 current_layout = layout;
1092 bv->owner()->setLayout(layout);
1099 case LFUN_PASTESELECTION: {
1100 // this was originally a bv->text->clearSelection(), i.e
1101 // the outermost LyXText!
1103 string const clip = bv->getClipboard();
1104 if (!clip.empty()) {
1105 if (cmd.argument == "paragraph")
1106 insertStringAsParagraphs(clip);
1108 insertStringAsLines(clip);
1114 case LFUN_GOTOERROR:
1115 gotoInset(InsetOld::ERROR_CODE, false);
1119 gotoInset(InsetOld::NOTE_CODE, false);
1122 case LFUN_REFERENCE_GOTO: {
1123 vector<InsetOld::Code> tmp;
1124 tmp.push_back(InsetOld::LABEL_CODE);
1125 tmp.push_back(InsetOld::REF_CODE);
1126 gotoInset(tmp, true);
1131 replaceSelection(bv->getLyXText());
1132 ParagraphList::iterator pit = cursorPar();
1133 lyx::pos_type pos = cursor().pos();
1137 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1140 c = pit->getChar(pos - 1);
1142 LyXLayout_ptr const & style = pit->layout();
1144 BufferParams const & bufparams = bv->buffer()->params();
1145 if (style->pass_thru ||
1146 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1147 !bv->insertInset(new InsetQuotes(c, bufparams)))
1148 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1152 case LFUN_DATE_INSERT: {
1153 replaceSelection(bv->getLyXText());
1154 time_t now_time_t = time(NULL);
1155 struct tm * now_tm = localtime(&now_time_t);
1156 setlocale(LC_TIME, "");
1158 if (!cmd.argument.empty())
1161 arg = lyxrc.date_insert_format;
1163 int const datetmp_len =
1164 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1166 for (int i = 0; i < datetmp_len; i++)
1167 insertChar(datetmp[i]);
1170 moveCursor(bv, false);
1174 case LFUN_MOUSE_TRIPLE:
1177 if (cmd.button() == mouse_button::button1) {
1178 selection_possible = true;
1183 bv->haveSelection(bv->selection().set());
1187 case LFUN_MOUSE_DOUBLE:
1190 if (cmd.button() == mouse_button::button1) {
1191 selection_possible = true;
1192 selectWord(lyx::WHOLE_WORD_STRICT);
1193 bv->haveSelection(bv->selection().set());
1197 case LFUN_MOUSE_MOTION: {
1198 // Only use motion with button 1
1199 //if (ev.button() != mouse_button::button1)
1204 // The test for not selection possible is needed, that
1205 // only motion events are used, where the bottom press
1206 // event was on the drawing area too
1207 if (!selection_possible) {
1208 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1209 "Dispatch: no selection possible\n";
1212 RowList::iterator cursorrow = cursorRow();
1214 setCursorFromCoordinates(cmd.x, cmd.y);
1216 // This is to allow jumping over large insets
1217 // FIXME: shouldn't be top-text-specific
1218 if (cursorrow == cursorRow() && !in_inset_) {
1219 if (cmd.y - bv->top_y() >= bv->workHeight())
1221 else if (cmd.y - bv->top_y() < 0)
1228 // Single-click on work area
1229 case LFUN_MOUSE_PRESS: {
1233 // ok ok, this is a hack (for xforms)
1234 // We shouldn't go further down as we really should only do the
1235 // scrolling and be done with this. Otherwise we may open some
1236 // dialogs (Jug 20020424).
1237 if (cmd.button() == mouse_button::button4) {
1238 bv->scroll(-lyxrc.wheel_jump);
1241 if (cmd.button() == mouse_button::button5) {
1242 bv->scroll(lyxrc.wheel_jump);
1246 // Middle button press pastes if we have a selection
1247 // We do this here as if the selection was inside an inset
1248 // it could get cleared on the unlocking of the inset so
1249 // we have to check this first
1250 bool paste_internally = false;
1251 if (cmd.button() == mouse_button::button2 && bv->selection().set()) {
1252 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1253 paste_internally = true;
1256 selection_possible = true;
1258 // Clear the selection
1261 // Right click on a footnote flag opens float menu
1262 if (cmd.button() == mouse_button::button3) {
1263 selection_possible = false;
1267 setCursorFromCoordinates(cmd.x, cmd.y);
1270 bv->x_target(cursorX() + xo_);
1272 if (bv->fitCursor())
1273 selection_possible = false;
1275 // Insert primary selection with middle mouse
1276 // if there is a local selection in the current buffer,
1278 if (cmd.button() == mouse_button::button2) {
1279 if (paste_internally)
1280 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1282 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1283 selection_possible = false;
1288 case LFUN_MOUSE_RELEASE: {
1292 // do nothing if we used the mouse wheel
1293 if (cmd.button() == mouse_button::button4
1294 || cmd.button() == mouse_button::button5)
1295 return DispatchResult(true, false);
1297 selection_possible = false;
1299 if (cmd.button() == mouse_button::button2)
1303 if (cmd.button() == mouse_button::button1)
1304 bv->haveSelection(bv->selection().set());
1307 bv->owner()->view_state_changed();
1308 bv->owner()->updateMenubar();
1309 bv->owner()->updateToolbar();
1313 case LFUN_SELFINSERT: {
1314 if (cmd.argument.empty())
1317 // Automatically delete the currently selected
1318 // text and replace it with what is being
1319 // typed in now. Depends on lyxrc settings
1320 // "auto_region_delete", which defaults to
1323 if (lyxrc.auto_region_delete) {
1324 if (bv->selection().set())
1325 cutSelection(false, false);
1326 bv->haveSelection(false);
1330 LyXFont const old_font = real_current_font;
1332 string::const_iterator cit = cmd.argument.begin();
1333 string::const_iterator end = cmd.argument.end();
1334 for (; cit != end; ++cit)
1335 bv->owner()->getIntl().getTransManager().
1336 TranslateAndInsert(*cit, this);
1339 moveCursor(bv, false);
1341 // real_current_font.number can change so we need to
1342 // update the minibuffer
1343 if (old_font != real_current_font)
1344 bv->owner()->view_state_changed();
1345 bv->updateScrollbar();
1350 InsetCommandParams p("url");
1351 string const data = InsetCommandMailer::params2string("url", p);
1352 bv->owner()->getDialogs().show("url", data, 0);
1356 case LFUN_HTMLURL: {
1357 InsetCommandParams p("htmlurl");
1358 string const data = InsetCommandMailer::params2string("url", p);
1359 bv->owner()->getDialogs().show("url", data, 0);
1363 case LFUN_INSERT_LABEL: {
1364 InsetCommandParams p("label");
1365 string const data = InsetCommandMailer::params2string("label", p);
1366 bv->owner()->getDialogs().show("label", data, 0);
1372 case LFUN_INSET_LIST:
1373 case LFUN_INSET_THEOREM:
1374 case LFUN_INSET_CAPTION:
1376 case LFUN_INSERT_NOTE:
1377 case LFUN_INSERT_CHARSTYLE:
1378 case LFUN_INSERT_BOX:
1379 case LFUN_INSERT_BRANCH:
1380 case LFUN_INSERT_BIBITEM:
1381 case LFUN_INSET_ERT:
1382 case LFUN_INSET_FLOAT:
1383 case LFUN_INSET_FOOTNOTE:
1384 case LFUN_INSET_MARGINAL:
1385 case LFUN_INSET_OPTARG:
1386 case LFUN_INSET_WIDE_FLOAT:
1387 case LFUN_INSET_WRAP:
1388 case LFUN_TABULAR_INSERT:
1389 case LFUN_ENVIRONMENT_INSERT:
1390 // Open the inset, and move the current selection
1392 doInsertInset(cmd, true, true);
1395 case LFUN_INDEX_INSERT:
1396 // Just open the inset
1397 doInsertInset(cmd, true, false);
1400 case LFUN_INDEX_PRINT:
1401 case LFUN_TOC_INSERT:
1403 case LFUN_INSERT_LINE:
1404 case LFUN_INSERT_PAGEBREAK:
1406 doInsertInset(cmd, false, false);
1409 case LFUN_DEPTH_MIN:
1410 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1414 case LFUN_DEPTH_PLUS:
1415 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1419 case LFUN_MATH_DELIM:
1420 case LFUN_MATH_DISPLAY:
1421 case LFUN_INSERT_MATH:
1422 case LFUN_MATH_LIMITS:
1423 case LFUN_MATH_MACRO:
1424 case LFUN_MATH_MUTATE:
1425 case LFUN_MATH_SPACE:
1426 case LFUN_MATH_IMPORT_SELECTION:
1427 case LFUN_MATH_MODE:
1428 case LFUN_MATH_NONUMBER:
1429 case LFUN_MATH_NUMBER:
1430 case LFUN_MATH_EXTERN:
1431 case LFUN_MATH_SIZE:
1437 bv->owner()->view_state_changed();
1442 bv->owner()->view_state_changed();
1447 bv->owner()->view_state_changed();
1452 bv->owner()->view_state_changed();
1457 bv->owner()->view_state_changed();
1462 bv->owner()->view_state_changed();
1466 styleReset(bv, this);
1467 bv->owner()->view_state_changed();
1470 case LFUN_UNDERLINE:
1471 underline(bv, this);
1472 bv->owner()->view_state_changed();
1475 case LFUN_FONT_SIZE:
1476 fontSize(bv, cmd.argument, this);
1477 bv->owner()->view_state_changed();
1481 lang(bv, cmd.argument, this);
1483 bv->owner()->view_state_changed();
1486 case LFUN_FREEFONT_APPLY:
1487 apply_freefont(bv, this);
1490 case LFUN_FREEFONT_UPDATE:
1491 update_and_apply_freefont(bv, this, cmd.argument);
1494 case LFUN_FINISHED_LEFT:
1495 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1500 case LFUN_FINISHED_RIGHT:
1501 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1506 case LFUN_FINISHED_UP:
1507 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1511 case LFUN_FINISHED_DOWN:
1512 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1517 return DispatchResult(false);
1520 return DispatchResult(true, true);