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 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
402 replaceSelection(text);
403 if (!bv->insertInset(new_inset))
410 void doInsertInset(BufferView * bv, FuncRequest const & cmd,
411 bool edit, bool pastesel)
413 InsetBase * inset = createInset(bv, cmd);
418 if (bv->cursor().selection()) {
419 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
422 if (bv->insertInset(inset)) {
424 inset->edit(bv->cursor(), true);
425 if (gotsel && pastesel)
426 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
435 void LyXText::number()
437 LyXFont font(LyXFont::ALL_IGNORE);
438 font.setNumber(LyXFont::TOGGLE);
439 toggleAndShow(bv(), this, font);
443 bool LyXText::rtl() const
445 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
449 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
451 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
452 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
454 BufferView * bv = &cur.bv();
456 switch (cmd.action) {
458 case LFUN_APPENDIX: {
459 ParagraphList::iterator pit = cursorPar();
460 bool start = !pit->params().startOfAppendix();
462 // ensure that we have only one start_of_appendix in this document
463 ParagraphList::iterator tmp = paragraphs().begin();
464 ParagraphList::iterator end = paragraphs().end();
466 for (; tmp != end; ++tmp) {
467 if (tmp->params().startOfAppendix()) {
468 recUndo(parOffset(tmp));
469 tmp->params().startOfAppendix(false);
475 recUndo(parOffset(pit));
476 pit->params().startOfAppendix(start);
478 // we can set the refreshing parameters now
480 redoParagraph(cursorPar());
485 case LFUN_DELETE_WORD_FORWARD:
486 cur.clearSelection();
491 case LFUN_DELETE_WORD_BACKWARD:
492 cur.clearSelection();
493 deleteWordBackward();
497 case LFUN_DELETE_LINE_FORWARD:
498 cur.clearSelection();
505 cur.clearSelection();
509 cursorRightOneWord();
515 cur.clearSelection();
517 cursorRightOneWord();
523 case LFUN_BEGINNINGBUF:
525 cur.clearSelection();
532 cur.clearSelection();
538 if (!cur.selection())
544 finishChange(bv, true);
548 if (!cur.selection())
554 finishChange(bv, true);
558 if (!cur.selection())
561 finishChange(bv, true);
565 if (!cur.selection())
568 finishChange(bv, true);
571 case LFUN_UP_PARAGRAPHSEL:
572 if (!cur.selection())
575 finishChange(bv, true);
578 case LFUN_DOWN_PARAGRAPHSEL:
579 if (!cur.selection())
581 cursorDownParagraph();
582 finishChange(bv, true);
586 if (!cur.selection())
589 finishChange(bv, true);
593 if (!cur.selection())
596 finishChange(bv, true);
600 if (!cur.selection())
603 finishChange(bv, true);
607 if (!cur.selection())
610 finishChange(bv, true);
613 case LFUN_WORDRIGHTSEL:
614 if (!cur.selection())
619 cursorRightOneWord();
620 finishChange(bv, true);
623 case LFUN_WORDLEFTSEL:
624 if (!cur.selection())
627 cursorRightOneWord();
630 finishChange(bv, true);
634 selectWord(lyx::WHOLE_WORD);
635 finishChange(bv, true);
655 case LFUN_UP_PARAGRAPH:
657 cur.clearSelection();
662 case LFUN_DOWN_PARAGRAPH:
664 cur.clearSelection();
665 cursorDownParagraph();
666 finishChange(bv, false);
671 cur.clearSelection();
672 finishChange(bv, false);
673 if (cur.par() == 0 && cursorRow() == firstRow())
674 return DispatchResult(false, FINISHED_UP);
680 cur.clearSelection();
681 finishChange(bv, false);
682 if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
683 return DispatchResult(false, FINISHED_DOWN);
689 cur.clearSelection();
691 finishChange(bv, false);
696 cur.clearSelection();
698 finishChange(bv, false);
701 case LFUN_BREAKLINE: {
702 lyx::pos_type body = cursorPar()->beginOfBody();
704 // Not allowed by LaTeX (labels or empty par)
705 if (cursor().pos() <= body)
708 replaceSelection(bv->getLyXText());
709 insertInset(new InsetNewline);
710 moveCursor(cur, false);
715 if (!cur.selection()) {
718 // It is possible to make it a lot faster still
719 // just comment out the line below...
721 cutSelection(true, false);
723 moveCursor(cur, false);
724 bv->owner()->view_state_changed();
727 case LFUN_DELETE_SKIP:
728 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
729 if (!cur.selection()) {
730 if (cursor().pos() == cursorPar()->size()) {
740 cutSelection(true, false);
747 if (!cur.selection()) {
748 if (bv->owner()->getIntl().getTransManager().backspace()) {
751 // It is possible to make it a lot faster still
752 // just comment out the line below...
755 cutSelection(true, false);
757 bv->owner()->view_state_changed();
762 case LFUN_BACKSPACE_SKIP:
763 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
764 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.
798 // CursorSlice cur = cursor();
799 replaceSelection(bv->getLyXText());
800 if (cur.pos() == 0) {
801 ParagraphParameters & params = getPar(cur.current())->params();
805 params.labelWidthString(), 1);
807 breakParagraph(bv->buffer()->paragraphs(), 0);
812 bv->owner()->view_state_changed();
816 case LFUN_PARAGRAPH_SPACING: {
817 ParagraphList::iterator pit = cursorPar();
818 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
819 float cur_value = 1.0;
820 if (cur_spacing == Spacing::Other)
821 cur_value = pit->params().spacing().getValue();
823 istringstream is(cmd.argument);
826 Spacing::Space new_spacing = cur_spacing;
827 float new_value = cur_value;
829 lyxerr << "Missing argument to `paragraph-spacing'"
831 } else if (tmp == "single") {
832 new_spacing = Spacing::Single;
833 } else if (tmp == "onehalf") {
834 new_spacing = Spacing::Onehalf;
835 } else if (tmp == "double") {
836 new_spacing = Spacing::Double;
837 } else if (tmp == "other") {
838 new_spacing = Spacing::Other;
841 lyxerr << "new_value = " << tmpval << endl;
844 } else if (tmp == "default") {
845 new_spacing = Spacing::Default;
847 lyxerr << _("Unknown spacing argument: ")
848 << cmd.argument << endl;
850 if (cur_spacing != new_spacing || cur_value != new_value) {
851 pit->params().spacing(Spacing(new_spacing, new_value));
858 case LFUN_INSET_APPLY: {
859 string const name = cmd.getArg(0);
860 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
862 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
864 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
868 case LFUN_INSET_INSERT: {
869 InsetBase * inset = createInset(bv, cmd);
870 if (inset && !bv->insertInset(inset))
875 case LFUN_INSET_SETTINGS:
876 if (cur.inset() && cur.inset()->asUpdatableInset())
877 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
880 case LFUN_INSET_TOGGLE:
881 cur.clearSelection();
883 return DispatchResult(false);
888 case LFUN_SPACE_INSERT:
889 if (cursorPar()->layout()->free_spacing)
892 doInsertInset(bv, cmd, false, false);
893 moveCursor(cur, false);
896 case LFUN_HYPHENATION:
897 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
900 case LFUN_LIGATURE_BREAK:
901 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
905 specialChar(this, bv, InsetSpecialChar::LDOTS);
908 case LFUN_END_OF_SENTENCE:
909 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
912 case LFUN_MENU_SEPARATOR:
913 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
916 case LFUN_UPCASE_WORD:
917 changeCase(LyXText::text_uppercase);
921 case LFUN_LOWCASE_WORD:
922 changeCase(LyXText::text_lowercase);
926 case LFUN_CAPITALIZE_WORD:
927 changeCase(LyXText::text_capitalization);
931 case LFUN_TRANSPOSE_CHARS:
932 recUndo(cursor().par());
938 cmd.message(_("Paste"));
939 replaceSelection(bv->getLyXText());
940 #warning FIXME Check if the arg is in the domain of available selections.
941 if (isStrUnsignedInt(cmd.argument))
942 pasteSelection(strToUnsignedInt(cmd.argument));
945 cur.clearSelection(); // bug 393
952 cutSelection(true, true);
953 cmd.message(_("Cut"));
959 cmd.message(_("Copy"));
962 case LFUN_BEGINNINGBUFSEL:
964 return DispatchResult(false);
965 if (!cur.selection())
968 finishChange(bv, true);
973 return DispatchResult(false);
974 if (!cur.selection())
977 finishChange(bv, true);
981 cmd.message(tostr(cursorX(cur.current())) + ' '
982 + tostr(cursorY(cur.current())));
988 istringstream is(cmd.argument);
991 lyxerr << "SETXY: Could not parse coordinates in '"
992 << cmd.argument << std::endl;
994 setCursorFromCoordinates(x, y);
999 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1001 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1007 case LFUN_GETLAYOUT:
1008 cmd.message(cursorPar()->layout()->name());
1012 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1013 << cmd.argument << endl;
1015 // This is not the good solution to the empty argument
1016 // problem, but it will hopefully suffice for 1.2.0.
1017 // The correct solution would be to augument the
1018 // function list/array with information about what
1019 // functions needs arguments and their type.
1020 if (cmd.argument.empty()) {
1021 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1025 // Derive layout number from given argument (string)
1026 // and current buffer's textclass (number)
1027 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1028 bool hasLayout = tclass.hasLayout(cmd.argument);
1029 string layout = cmd.argument;
1031 // If the entry is obsolete, use the new one instead.
1033 string const & obs = tclass[layout]->obsoleted_by();
1039 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1044 bool change_layout = (current_layout != layout);
1046 if (!change_layout && cur.selection() &&
1047 cur.selBegin().par() != cur.selEnd().par())
1049 ParagraphList::iterator spit = getPar(cur.selBegin());
1050 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
1051 while (spit != epit) {
1052 if (spit->layout()->name() != current_layout) {
1053 change_layout = true;
1060 if (change_layout) {
1061 current_layout = layout;
1063 bv->owner()->setLayout(layout);
1070 case LFUN_PASTESELECTION: {
1071 cur.clearSelection();
1072 string const clip = bv->getClipboard();
1073 if (!clip.empty()) {
1074 if (cmd.argument == "paragraph")
1075 insertStringAsParagraphs(clip);
1077 insertStringAsLines(clip);
1083 case LFUN_GOTOERROR:
1084 gotoInset(InsetBase::ERROR_CODE, false);
1088 gotoInset(InsetBase::NOTE_CODE, false);
1091 case LFUN_REFERENCE_GOTO: {
1092 vector<InsetOld_code> tmp;
1093 tmp.push_back(InsetBase::LABEL_CODE);
1094 tmp.push_back(InsetBase::REF_CODE);
1095 gotoInset(tmp, true);
1100 replaceSelection(bv->getLyXText());
1101 ParagraphList::iterator pit = cursorPar();
1102 lyx::pos_type pos = cursor().pos();
1106 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1109 c = pit->getChar(pos - 1);
1111 LyXLayout_ptr const & style = pit->layout();
1113 BufferParams const & bufparams = bv->buffer()->params();
1114 if (style->pass_thru ||
1115 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1116 !bv->insertInset(new InsetQuotes(c, bufparams)))
1117 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1121 case LFUN_DATE_INSERT: {
1122 replaceSelection(bv->getLyXText());
1123 time_t now_time_t = time(NULL);
1124 struct tm * now_tm = localtime(&now_time_t);
1125 setlocale(LC_TIME, "");
1127 if (!cmd.argument.empty())
1130 arg = lyxrc.date_insert_format;
1132 int const datetmp_len =
1133 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1135 for (int i = 0; i < datetmp_len; i++)
1136 insertChar(datetmp[i]);
1139 moveCursor(cur, false);
1143 case LFUN_MOUSE_TRIPLE:
1144 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1145 selection_possible = true;
1150 bv->haveSelection(cur.selection());
1154 case LFUN_MOUSE_DOUBLE:
1155 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1156 selection_possible = true;
1157 selectWord(lyx::WHOLE_WORD_STRICT);
1158 bv->haveSelection(cur.selection());
1162 case LFUN_MOUSE_MOTION: {
1164 // Only use motion with button 1
1165 //if (ev.button() != mouse_button::button1)
1167 // don't set anchor_
1168 bv->cursor().cursor_ = cur.cursor_;
1172 // The test for not selection possible is needed, that
1173 // only motion events are used, where the bottom press
1174 // event was on the drawing area too
1175 if (!selection_possible) {
1176 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1177 "Dispatch: no selection possible\n";
1180 RowList::iterator cursorrow = cursorRow();
1182 setCursorFromCoordinates(cmd.x, cmd.y);
1184 // This is to allow jumping over large insets
1185 // FIXME: shouldn't be top-text-specific
1186 if (cursorrow == cursorRow() && !in_inset_) {
1187 if (cmd.y - bv->top_y() >= bv->workHeight())
1189 else if (cmd.y - bv->top_y() < 0)
1197 // Single-click on work area
1198 case LFUN_MOUSE_PRESS: {
1202 // ok ok, this is a hack (for xforms)
1203 // We shouldn't go further down as we really should only do the
1204 // scrolling and be done with this. Otherwise we may open some
1205 // dialogs (Jug 20020424).
1206 if (cmd.button() == mouse_button::button4) {
1207 bv->scroll(-lyxrc.wheel_jump);
1210 if (cmd.button() == mouse_button::button5) {
1211 bv->scroll(lyxrc.wheel_jump);
1215 // Middle button press pastes if we have a selection
1216 // We do this here as if the selection was inside an inset
1217 // it could get cleared on the unlocking of the inset so
1218 // we have to check this first
1219 bool paste_internally = false;
1220 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1221 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1222 paste_internally = true;
1225 selection_possible = true;
1227 // Clear the selection
1228 cur.clearSelection();
1230 // Right click on a footnote flag opens float menu
1231 if (cmd.button() == mouse_button::button3) {
1232 selection_possible = false;
1236 setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
1239 cur.x_target() = cursorX(cur.current());
1241 // set cursor and anchor to this position
1244 if (bv->fitCursor())
1245 selection_possible = false;
1247 // Insert primary selection with middle mouse
1248 // if there is a local selection in the current buffer,
1250 if (cmd.button() == mouse_button::button2) {
1251 if (paste_internally)
1252 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1254 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1255 selection_possible = false;
1260 case LFUN_MOUSE_RELEASE: {
1264 // do nothing if we used the mouse wheel
1265 if (cmd.button() == mouse_button::button4
1266 || cmd.button() == mouse_button::button5)
1267 return DispatchResult(true, false);
1269 selection_possible = false;
1271 if (cmd.button() == mouse_button::button2)
1275 if (cmd.button() == mouse_button::button1)
1276 bv->haveSelection(cur.selection());
1279 bv->owner()->view_state_changed();
1280 bv->owner()->updateMenubar();
1281 bv->owner()->updateToolbar();
1285 case LFUN_SELFINSERT: {
1286 if (cmd.argument.empty())
1289 // Automatically delete the currently selected
1290 // text and replace it with what is being
1291 // typed in now. Depends on lyxrc settings
1292 // "auto_region_delete", which defaults to
1295 if (lyxrc.auto_region_delete) {
1296 if (cur.selection())
1297 cutSelection(false, false);
1298 bv->haveSelection(false);
1301 cur.clearSelection();
1302 LyXFont const old_font = real_current_font;
1304 string::const_iterator cit = cmd.argument.begin();
1305 string::const_iterator end = cmd.argument.end();
1306 for (; cit != end; ++cit)
1307 bv->owner()->getIntl().getTransManager().
1308 TranslateAndInsert(*cit, this);
1311 moveCursor(cur, false);
1313 // real_current_font.number can change so we need to
1314 // update the minibuffer
1315 if (old_font != real_current_font)
1316 bv->owner()->view_state_changed();
1317 bv->updateScrollbar();
1322 InsetCommandParams p("url");
1323 string const data = InsetCommandMailer::params2string("url", p);
1324 bv->owner()->getDialogs().show("url", data, 0);
1328 case LFUN_HTMLURL: {
1329 InsetCommandParams p("htmlurl");
1330 string const data = InsetCommandMailer::params2string("url", p);
1331 bv->owner()->getDialogs().show("url", data, 0);
1335 case LFUN_INSERT_LABEL: {
1336 InsetCommandParams p("label");
1337 string const data = InsetCommandMailer::params2string("label", p);
1338 bv->owner()->getDialogs().show("label", data, 0);
1344 case LFUN_INSET_LIST:
1345 case LFUN_INSET_THEOREM:
1346 case LFUN_INSET_CAPTION:
1348 case LFUN_INSERT_NOTE:
1349 case LFUN_INSERT_CHARSTYLE:
1350 case LFUN_INSERT_BOX:
1351 case LFUN_INSERT_BRANCH:
1352 case LFUN_INSERT_BIBITEM:
1353 case LFUN_INSET_ERT:
1354 case LFUN_INSET_FLOAT:
1355 case LFUN_INSET_FOOTNOTE:
1356 case LFUN_INSET_MARGINAL:
1357 case LFUN_INSET_OPTARG:
1358 case LFUN_INSET_WIDE_FLOAT:
1359 case LFUN_INSET_WRAP:
1360 case LFUN_TABULAR_INSERT:
1361 case LFUN_ENVIRONMENT_INSERT:
1362 // Open the inset, and move the current selection
1364 doInsertInset(bv, cmd, true, true);
1367 case LFUN_INDEX_INSERT:
1368 // Just open the inset
1369 doInsertInset(bv, cmd, true, false);
1372 case LFUN_INDEX_PRINT:
1373 case LFUN_TOC_INSERT:
1375 case LFUN_INSERT_LINE:
1376 case LFUN_INSERT_PAGEBREAK:
1378 doInsertInset(bv, cmd, false, false);
1381 case LFUN_DEPTH_MIN:
1382 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1386 case LFUN_DEPTH_PLUS:
1387 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1391 case LFUN_MATH_DELIM:
1392 case LFUN_MATH_DISPLAY:
1393 case LFUN_INSERT_MATH:
1394 case LFUN_MATH_LIMITS:
1395 case LFUN_MATH_MACRO:
1396 case LFUN_MATH_MUTATE:
1397 case LFUN_MATH_SPACE:
1398 case LFUN_MATH_IMPORT_SELECTION:
1399 case LFUN_MATH_MODE:
1400 case LFUN_MATH_NONUMBER:
1401 case LFUN_MATH_NUMBER:
1402 case LFUN_MATH_EXTERN:
1403 case LFUN_MATH_SIZE:
1404 mathDispatch(cur, cmd);
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();
1434 bv->owner()->view_state_changed();
1438 styleReset(bv, this);
1439 bv->owner()->view_state_changed();
1442 case LFUN_UNDERLINE:
1443 underline(bv, this);
1444 bv->owner()->view_state_changed();
1447 case LFUN_FONT_SIZE:
1448 fontSize(bv, cmd.argument, this);
1449 bv->owner()->view_state_changed();
1453 lang(bv, cmd.argument, this);
1455 bv->owner()->view_state_changed();
1458 case LFUN_FREEFONT_APPLY:
1459 apply_freefont(bv, this);
1462 case LFUN_FREEFONT_UPDATE:
1463 update_and_apply_freefont(bv, this, cmd.argument);
1466 case LFUN_FINISHED_LEFT:
1467 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1472 case LFUN_FINISHED_RIGHT:
1473 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1478 case LFUN_FINISHED_UP:
1479 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1483 case LFUN_FINISHED_DOWN:
1484 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1489 return DispatchResult(false);
1492 return DispatchResult(true, true);