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 if (selecting || bv->selection().mark())
221 if (!bv->selection().set())
222 bv->haveSelection(false);
227 void finishChange(BufferView * bv, bool selecting = false)
230 moveCursor(bv, selecting);
231 bv->owner()->view_state_changed();
239 string const freefont2string()
242 if (font2string(freefont, toggleall, data))
250 InsetOld * LyXText::checkInsetHit(int x, int y)
252 ParagraphList::iterator pit;
253 ParagraphList::iterator end;
255 getParsInRange(paragraphs(),
257 bv()->top_y() - yo_ + bv()->workHeight(),
260 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
261 for ( ; pit != end; ++pit) {
262 InsetList::iterator iit = pit->insetlist.begin();
263 InsetList::iterator iend = pit->insetlist.end();
264 for ( ; iit != iend; ++iit) {
265 InsetOld * inset = iit->inset;
266 //lyxerr << "examining inset " << inset
267 // << " xy: " << inset->x() << "/" << inset->y()
268 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
269 // << " y: " << inset->y() - inset->ascent() << "..."
270 // << inset->y() + inset->descent()
273 && x <= inset->x() + inset->width()
274 && y >= inset->y() - inset->ascent()
275 && y <= inset->y() + inset->descent())
277 lyxerr << "Hit inset: " << inset << endl;
282 lyxerr << "No inset hit. " << endl;
287 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
288 string const & contents)
290 ParagraphList::iterator end = paragraphs().end();
291 ParagraphList::iterator pit = cursorPar();
292 pos_type pos = cursor().pos();
296 if (pos + 1 < pit->size()) {
303 } while (pit != end &&
304 !(pit->isInset(pos) &&
305 (inset = pit->getInset(pos)) != 0 &&
306 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
308 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
314 setCursor(parOffset(pit), pos, false);
319 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
322 bv()->clearSelection();
325 if (same_content && cursor().pos() < cursorPar()->size()
326 && cursorPar()->isInset(cursor().pos())) {
327 InsetOld const * inset = cursorPar()->getInset(cursor().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 (cursor().pos() || cursorPar() != paragraphs().begin()) {
335 CursorSlice tmp = cursor();
338 if (!gotoNextInset(codes, contents)) {
340 bv()->owner()->message(_("No more insets"));
343 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()
360 RowList::iterator crit = cursorRow();
361 ParagraphList::iterator cpar = cursorPar();
363 int x = bv()->x_target() - xo_;
364 int y = bv()->top_y() - yo_;
365 setCursorFromCoordinates(x, y);
367 if (cpar == cursorPar() && 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()->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->selection().set()) {
421 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
424 if (bv->insertInset(inset)) {
426 inset->edit(bv, true);
427 if (gotsel && pastesel)
428 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
436 void LyXText::number()
438 LyXFont font(LyXFont::ALL_IGNORE);
439 font.setNumber(LyXFont::TOGGLE);
440 toggleAndShow(bv(), this, font);
444 bool LyXText::rtl() const
446 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
450 DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
452 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
454 BufferView * bv = &view;
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 bv->clearSelection();
491 case LFUN_DELETE_WORD_BACKWARD:
492 bv->clearSelection();
493 deleteWordBackward();
497 case LFUN_DELETE_LINE_FORWARD:
498 bv->clearSelection();
504 if (!bv->selection().mark())
505 bv->clearSelection();
509 cursorRightOneWord();
514 if (!bv->selection().mark())
515 bv->clearSelection();
517 cursorRightOneWord();
523 case LFUN_BEGINNINGBUF:
524 if (!bv->selection().mark())
525 bv->clearSelection();
531 if (bv->selection().mark())
532 bv->clearSelection();
538 if (!bv->selection().set())
544 finishChange(bv, true);
548 if (!bv->selection().set())
554 finishChange(bv, true);
558 if (!bv->selection().set())
561 finishChange(bv, true);
565 if (!bv->selection().set())
568 finishChange(bv, true);
571 case LFUN_UP_PARAGRAPHSEL:
572 if (!bv->selection().set())
575 finishChange(bv, true);
578 case LFUN_DOWN_PARAGRAPHSEL:
579 if (!bv->selection().set())
581 cursorDownParagraph();
582 finishChange(bv, true);
586 if (!bv->selection().set())
589 finishChange(bv, true);
593 if (!bv->selection().set())
596 finishChange(bv, true);
600 if (!bv->selection().set())
603 finishChange(bv, true);
607 if (!bv->selection().set())
610 finishChange(bv, true);
613 case LFUN_WORDRIGHTSEL:
614 if (!bv->selection().set())
619 cursorRightOneWord();
620 finishChange(bv, true);
623 case LFUN_WORDLEFTSEL:
624 if (!bv->selection().set())
627 cursorRightOneWord();
630 finishChange(bv, true);
634 selectWord(lyx::WHOLE_WORD);
635 finishChange(bv, true);
655 case LFUN_UP_PARAGRAPH:
656 if (!bv->selection().mark())
657 bv->clearSelection();
662 case LFUN_DOWN_PARAGRAPH:
663 if (!bv->selection().mark())
664 bv->clearSelection();
665 cursorDownParagraph();
666 finishChange(bv, false);
670 if (!bv->selection().mark())
671 bv->clearSelection();
672 finishChange(bv, false);
673 if (cursorPar() == firstPar() && cursorRow() == firstRow())
674 return DispatchResult(false, FINISHED_UP);
679 if (!bv->selection().mark())
680 bv->clearSelection();
681 finishChange(bv, false);
682 if (cursorPar() == lastPar() && cursorRow() == lastRow())
683 return DispatchResult(false, FINISHED_DOWN);
688 if (!bv->selection().mark())
689 bv->clearSelection();
691 finishChange(bv, false);
695 if (!bv->selection().mark())
696 bv->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(bv, false);
715 if (!bv->selection().set()) {
718 // It is possible to make it a lot faster still
719 // just comment out the line below...
721 cutSelection(true, false);
723 moveCursor(bv, false);
724 bv->owner()->view_state_changed();
727 case LFUN_DELETE_SKIP:
728 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
729 if (!bv->selection().set()) {
730 if (cursor().pos() == cursorPar()->size()) {
740 cutSelection(true, false);
747 if (!bv->selection().set()) {
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 (!bv->selection().set()) {
765 CursorSlice cur = cursor();
769 cutSelection(true, false);
774 case LFUN_BREAKPARAGRAPH:
775 replaceSelection(bv->getLyXText());
776 breakParagraph(bv->buffer()->paragraphs(), 0);
780 bv->owner()->view_state_changed();
783 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
784 replaceSelection(bv->getLyXText());
785 breakParagraph(bv->buffer()->paragraphs(), 1);
789 bv->owner()->view_state_changed();
792 case LFUN_BREAKPARAGRAPH_SKIP: {
793 // When at the beginning of a paragraph, remove
794 // indentation and add a "defskip" at the top.
795 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
796 CursorSlice cur = cursor();
797 replaceSelection(bv->getLyXText());
798 if (cur.pos() == 0) {
799 ParagraphParameters & params = getPar(cur)->params();
803 params.labelWidthString(), 1);
805 breakParagraph(bv->buffer()->paragraphs(), 0);
810 bv->owner()->view_state_changed();
814 case LFUN_PARAGRAPH_SPACING: {
815 ParagraphList::iterator pit = cursorPar();
816 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
817 float cur_value = 1.0;
818 if (cur_spacing == Spacing::Other)
819 cur_value = pit->params().spacing().getValue();
821 istringstream is(cmd.argument);
824 Spacing::Space new_spacing = cur_spacing;
825 float new_value = cur_value;
827 lyxerr << "Missing argument to `paragraph-spacing'"
829 } else if (tmp == "single") {
830 new_spacing = Spacing::Single;
831 } else if (tmp == "onehalf") {
832 new_spacing = Spacing::Onehalf;
833 } else if (tmp == "double") {
834 new_spacing = Spacing::Double;
835 } else if (tmp == "other") {
836 new_spacing = Spacing::Other;
839 lyxerr << "new_value = " << tmpval << endl;
842 } else if (tmp == "default") {
843 new_spacing = Spacing::Default;
845 lyxerr << _("Unknown spacing argument: ")
846 << cmd.argument << endl;
848 if (cur_spacing != new_spacing || cur_value != new_value) {
849 pit->params().spacing(Spacing(new_spacing, new_value));
856 case LFUN_INSET_APPLY: {
857 string const name = cmd.getArg(0);
858 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
860 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
861 inset->dispatch(*bv, fr);
863 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
869 case LFUN_INSET_INSERT: {
870 InsetOld * inset = createInset(bv, cmd);
871 if (inset && !bv->insertInset(inset))
876 case LFUN_INSET_SETTINGS:
877 bv->fullCursor().innerInset()->showInsetDialog(bv);
880 case LFUN_INSET_TOGGLE:
881 bv->clearSelection();
883 return DispatchResult(false);
888 case LFUN_SPACE_INSERT:
889 if (cursorPar()->layout()->free_spacing)
892 doInsertInset(bv, cmd, false, false);
893 moveCursor(bv, 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 bv->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 (!bv->selection().set())
968 finishChange(bv, true);
973 return DispatchResult(false);
974 if (!bv->selection().set())
977 finishChange(bv, true);
981 cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
987 istringstream is(cmd.argument);
990 lyxerr << "SETXY: Could not parse coordinates in '"
991 << cmd.argument << std::endl;
993 setCursorFromCoordinates(x, y);
998 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1000 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1006 case LFUN_GETLAYOUT:
1007 cmd.message(cursorPar()->layout()->name());
1011 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1012 << cmd.argument << endl;
1014 // This is not the good solution to the empty argument
1015 // problem, but it will hopefully suffice for 1.2.0.
1016 // The correct solution would be to augument the
1017 // function list/array with information about what
1018 // functions needs arguments and their type.
1019 if (cmd.argument.empty()) {
1020 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1024 // Derive layout number from given argument (string)
1025 // and current buffer's textclass (number)
1026 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1027 bool hasLayout = tclass.hasLayout(cmd.argument);
1028 string layout = cmd.argument;
1030 // If the entry is obsolete, use the new one instead.
1032 string const & obs = tclass[layout]->obsoleted_by();
1038 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1043 bool change_layout = (current_layout != layout);
1045 if (!change_layout && bv->selection().set() &&
1046 bv->selStart().par() != bv->selEnd().par())
1048 ParagraphList::iterator spit = getPar(bv->selStart());
1049 ParagraphList::iterator epit = boost::next(getPar(bv->selEnd()));
1050 while (spit != epit) {
1051 if (spit->layout()->name() != current_layout) {
1052 change_layout = true;
1059 if (change_layout) {
1060 current_layout = layout;
1062 bv->owner()->setLayout(layout);
1069 case LFUN_PASTESELECTION: {
1070 bv->clearSelection();
1071 string const clip = bv->getClipboard();
1072 if (!clip.empty()) {
1073 if (cmd.argument == "paragraph")
1074 insertStringAsParagraphs(clip);
1076 insertStringAsLines(clip);
1082 case LFUN_GOTOERROR:
1083 gotoInset(InsetOld::ERROR_CODE, false);
1087 gotoInset(InsetOld::NOTE_CODE, false);
1090 case LFUN_REFERENCE_GOTO: {
1091 vector<InsetOld::Code> tmp;
1092 tmp.push_back(InsetOld::LABEL_CODE);
1093 tmp.push_back(InsetOld::REF_CODE);
1094 gotoInset(tmp, true);
1099 replaceSelection(bv->getLyXText());
1100 ParagraphList::iterator pit = cursorPar();
1101 lyx::pos_type pos = cursor().pos();
1105 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1108 c = pit->getChar(pos - 1);
1110 LyXLayout_ptr const & style = pit->layout();
1112 BufferParams const & bufparams = bv->buffer()->params();
1113 if (style->pass_thru ||
1114 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1115 !bv->insertInset(new InsetQuotes(c, bufparams)))
1116 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1120 case LFUN_DATE_INSERT: {
1121 replaceSelection(bv->getLyXText());
1122 time_t now_time_t = time(NULL);
1123 struct tm * now_tm = localtime(&now_time_t);
1124 setlocale(LC_TIME, "");
1126 if (!cmd.argument.empty())
1129 arg = lyxrc.date_insert_format;
1131 int const datetmp_len =
1132 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1134 for (int i = 0; i < datetmp_len; i++)
1135 insertChar(datetmp[i]);
1138 moveCursor(bv, false);
1142 case LFUN_MOUSE_TRIPLE:
1145 if (cmd.button() == mouse_button::button1) {
1146 selection_possible = true;
1151 bv->haveSelection(bv->selection().set());
1155 case LFUN_MOUSE_DOUBLE:
1158 if (cmd.button() == mouse_button::button1) {
1159 selection_possible = true;
1160 selectWord(lyx::WHOLE_WORD_STRICT);
1161 bv->haveSelection(bv->selection().set());
1165 case LFUN_MOUSE_MOTION: {
1166 // Only use motion with button 1
1167 //if (ev.button() != mouse_button::button1)
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)
1196 // Single-click on work area
1197 case LFUN_MOUSE_PRESS: {
1201 // ok ok, this is a hack (for xforms)
1202 // We shouldn't go further down as we really should only do the
1203 // scrolling and be done with this. Otherwise we may open some
1204 // dialogs (Jug 20020424).
1205 if (cmd.button() == mouse_button::button4) {
1206 bv->scroll(-lyxrc.wheel_jump);
1209 if (cmd.button() == mouse_button::button5) {
1210 bv->scroll(lyxrc.wheel_jump);
1214 // Middle button press pastes if we have a selection
1215 // We do this here as if the selection was inside an inset
1216 // it could get cleared on the unlocking of the inset so
1217 // we have to check this first
1218 bool paste_internally = false;
1219 if (cmd.button() == mouse_button::button2 && bv->selection().set()) {
1220 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1221 paste_internally = true;
1224 selection_possible = true;
1226 // Clear the selection
1227 bv->clearSelection();
1229 // Right click on a footnote flag opens float menu
1230 if (cmd.button() == mouse_button::button3) {
1231 selection_possible = false;
1235 setCursorFromCoordinates(cmd.x, cmd.y);
1238 bv->x_target(cursorX() + xo_);
1240 if (bv->fitCursor())
1241 selection_possible = false;
1243 // Insert primary selection with middle mouse
1244 // if there is a local selection in the current buffer,
1246 if (cmd.button() == mouse_button::button2) {
1247 if (paste_internally)
1248 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1250 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1251 selection_possible = false;
1256 case LFUN_MOUSE_RELEASE: {
1260 // do nothing if we used the mouse wheel
1261 if (cmd.button() == mouse_button::button4
1262 || cmd.button() == mouse_button::button5)
1263 return DispatchResult(true, false);
1265 selection_possible = false;
1267 if (cmd.button() == mouse_button::button2)
1271 if (cmd.button() == mouse_button::button1)
1272 bv->haveSelection(bv->selection().set());
1275 bv->owner()->view_state_changed();
1276 bv->owner()->updateMenubar();
1277 bv->owner()->updateToolbar();
1281 case LFUN_SELFINSERT: {
1282 if (cmd.argument.empty())
1285 // Automatically delete the currently selected
1286 // text and replace it with what is being
1287 // typed in now. Depends on lyxrc settings
1288 // "auto_region_delete", which defaults to
1291 if (lyxrc.auto_region_delete) {
1292 if (bv->selection().set())
1293 cutSelection(false, false);
1294 bv->haveSelection(false);
1297 bv->clearSelection();
1298 LyXFont const old_font = real_current_font;
1300 string::const_iterator cit = cmd.argument.begin();
1301 string::const_iterator end = cmd.argument.end();
1302 for (; cit != end; ++cit)
1303 bv->owner()->getIntl().getTransManager().
1304 TranslateAndInsert(*cit, this);
1307 moveCursor(bv, false);
1309 // real_current_font.number can change so we need to
1310 // update the minibuffer
1311 if (old_font != real_current_font)
1312 bv->owner()->view_state_changed();
1313 bv->updateScrollbar();
1318 InsetCommandParams p("url");
1319 string const data = InsetCommandMailer::params2string("url", p);
1320 bv->owner()->getDialogs().show("url", data, 0);
1324 case LFUN_HTMLURL: {
1325 InsetCommandParams p("htmlurl");
1326 string const data = InsetCommandMailer::params2string("url", p);
1327 bv->owner()->getDialogs().show("url", data, 0);
1331 case LFUN_INSERT_LABEL: {
1332 InsetCommandParams p("label");
1333 string const data = InsetCommandMailer::params2string("label", p);
1334 bv->owner()->getDialogs().show("label", data, 0);
1340 case LFUN_INSET_LIST:
1341 case LFUN_INSET_THEOREM:
1342 case LFUN_INSET_CAPTION:
1344 case LFUN_INSERT_NOTE:
1345 case LFUN_INSERT_CHARSTYLE:
1346 case LFUN_INSERT_BOX:
1347 case LFUN_INSERT_BRANCH:
1348 case LFUN_INSERT_BIBITEM:
1349 case LFUN_INSET_ERT:
1350 case LFUN_INSET_FLOAT:
1351 case LFUN_INSET_FOOTNOTE:
1352 case LFUN_INSET_MARGINAL:
1353 case LFUN_INSET_OPTARG:
1354 case LFUN_INSET_WIDE_FLOAT:
1355 case LFUN_INSET_WRAP:
1356 case LFUN_TABULAR_INSERT:
1357 case LFUN_ENVIRONMENT_INSERT:
1358 // Open the inset, and move the current selection
1360 doInsertInset(bv, cmd, true, true);
1363 case LFUN_INDEX_INSERT:
1364 // Just open the inset
1365 doInsertInset(bv, cmd, true, false);
1368 case LFUN_INDEX_PRINT:
1369 case LFUN_TOC_INSERT:
1371 case LFUN_INSERT_LINE:
1372 case LFUN_INSERT_PAGEBREAK:
1374 doInsertInset(bv, cmd, false, false);
1377 case LFUN_DEPTH_MIN:
1378 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1382 case LFUN_DEPTH_PLUS:
1383 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1387 case LFUN_MATH_DELIM:
1388 case LFUN_MATH_DISPLAY:
1389 case LFUN_INSERT_MATH:
1390 case LFUN_MATH_LIMITS:
1391 case LFUN_MATH_MACRO:
1392 case LFUN_MATH_MUTATE:
1393 case LFUN_MATH_SPACE:
1394 case LFUN_MATH_IMPORT_SELECTION:
1395 case LFUN_MATH_MODE:
1396 case LFUN_MATH_NONUMBER:
1397 case LFUN_MATH_NUMBER:
1398 case LFUN_MATH_EXTERN:
1399 case LFUN_MATH_SIZE:
1400 mathDispatch(*bv, cmd);
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();
1430 bv->owner()->view_state_changed();
1434 styleReset(bv, this);
1435 bv->owner()->view_state_changed();
1438 case LFUN_UNDERLINE:
1439 underline(bv, this);
1440 bv->owner()->view_state_changed();
1443 case LFUN_FONT_SIZE:
1444 fontSize(bv, cmd.argument, this);
1445 bv->owner()->view_state_changed();
1449 lang(bv, cmd.argument, this);
1451 bv->owner()->view_state_changed();
1454 case LFUN_FREEFONT_APPLY:
1455 apply_freefont(bv, this);
1458 case LFUN_FREEFONT_UPDATE:
1459 update_and_apply_freefont(bv, this, cmd.argument);
1462 case LFUN_FINISHED_LEFT:
1463 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1468 case LFUN_FINISHED_RIGHT:
1469 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1474 case LFUN_FINISHED_UP:
1475 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1479 case LFUN_FINISHED_DOWN:
1480 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1485 return DispatchResult(false);
1488 return DispatchResult(true, true);