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(FuncRequest const & cmd, bool edit, bool pastesel)
414 InsetOld * inset = createInset(cmd);
418 BufferView * bv = cmd.view();
421 if (bv->selection().set()) {
422 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
425 if (bv->insertInset(inset)) {
427 inset->edit(bv, true);
428 if (gotsel && pastesel)
429 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(FuncRequest const & cmd)
453 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
455 BufferView * bv = cmd.view();
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 bv->clearSelection();
492 case LFUN_DELETE_WORD_BACKWARD:
493 bv->clearSelection();
494 deleteWordBackward();
498 case LFUN_DELETE_LINE_FORWARD:
499 bv->clearSelection();
505 if (!bv->selection().mark())
506 bv->clearSelection();
510 cursorRightOneWord();
515 if (!bv->selection().mark())
516 bv->clearSelection();
518 cursorRightOneWord();
524 case LFUN_BEGINNINGBUF:
525 if (!bv->selection().mark())
526 bv->clearSelection();
532 if (bv->selection().mark())
533 bv->clearSelection();
539 if (!bv->selection().set())
545 finishChange(bv, true);
549 if (!bv->selection().set())
555 finishChange(bv, true);
559 if (!bv->selection().set())
562 finishChange(bv, true);
566 if (!bv->selection().set())
569 finishChange(bv, true);
572 case LFUN_UP_PARAGRAPHSEL:
573 if (!bv->selection().set())
576 finishChange(bv, true);
579 case LFUN_DOWN_PARAGRAPHSEL:
580 if (!bv->selection().set())
582 cursorDownParagraph();
583 finishChange(bv, true);
587 if (!bv->selection().set())
590 finishChange(bv, true);
594 if (!bv->selection().set())
597 finishChange(bv, true);
601 if (!bv->selection().set())
604 finishChange(bv, true);
608 if (!bv->selection().set())
611 finishChange(bv, true);
614 case LFUN_WORDRIGHTSEL:
615 if (!bv->selection().set())
620 cursorRightOneWord();
621 finishChange(bv, true);
624 case LFUN_WORDLEFTSEL:
625 if (!bv->selection().set())
628 cursorRightOneWord();
631 finishChange(bv, true);
635 selectWord(lyx::WHOLE_WORD);
636 finishChange(bv, true);
656 case LFUN_UP_PARAGRAPH:
657 if (!bv->selection().mark())
658 bv->clearSelection();
663 case LFUN_DOWN_PARAGRAPH:
664 if (!bv->selection().mark())
665 bv->clearSelection();
666 cursorDownParagraph();
667 finishChange(bv, false);
671 if (!bv->selection().mark())
672 bv->clearSelection();
673 finishChange(bv, false);
674 if (cursorPar() == firstPar() && cursorRow() == firstRow())
675 return DispatchResult(false, FINISHED_UP);
680 if (!bv->selection().mark())
681 bv->clearSelection();
682 finishChange(bv, false);
683 if (cursorPar() == lastPar() && cursorRow() == lastRow())
684 return DispatchResult(false, FINISHED_DOWN);
689 if (!bv->selection().mark())
690 bv->clearSelection();
692 finishChange(bv, false);
696 if (!bv->selection().mark())
697 bv->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(bv, false);
716 if (!bv->selection().set()) {
719 // It is possible to make it a lot faster still
720 // just comment out the line below...
722 cutSelection(true, false);
724 moveCursor(bv, false);
725 bv->owner()->view_state_changed();
728 case LFUN_DELETE_SKIP:
729 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
730 if (!bv->selection().set()) {
731 if (cursor().pos() == cursorPar()->size()) {
741 cutSelection(true, false);
748 if (!bv->selection().set()) {
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 (!bv->selection().set()) {
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 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
864 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
870 case LFUN_INSET_INSERT: {
871 InsetOld * inset = createInset(cmd);
872 if (inset && !bv->insertInset(inset))
877 case LFUN_INSET_SETTINGS:
878 bv->fullCursor().innerInset()->showInsetDialog(bv);
881 case LFUN_INSET_TOGGLE:
882 bv->clearSelection();
884 return DispatchResult(false);
889 case LFUN_SPACE_INSERT:
890 if (cursorPar()->layout()->free_spacing)
893 doInsertInset(cmd, false, false);
894 moveCursor(bv, false);
897 case LFUN_HYPHENATION:
898 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
901 case LFUN_LIGATURE_BREAK:
902 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
906 specialChar(this, bv, InsetSpecialChar::LDOTS);
909 case LFUN_END_OF_SENTENCE:
910 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
913 case LFUN_MENU_SEPARATOR:
914 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
917 case LFUN_UPCASE_WORD:
918 changeCase(LyXText::text_uppercase);
922 case LFUN_LOWCASE_WORD:
923 changeCase(LyXText::text_lowercase);
927 case LFUN_CAPITALIZE_WORD:
928 changeCase(LyXText::text_capitalization);
932 case LFUN_TRANSPOSE_CHARS:
933 recUndo(cursor().par());
939 cmd.message(_("Paste"));
940 replaceSelection(bv->getLyXText());
941 #warning FIXME Check if the arg is in the domain of available selections.
942 if (isStrUnsignedInt(cmd.argument))
943 pasteSelection(strToUnsignedInt(cmd.argument));
946 bv->clearSelection(); // bug 393
953 cutSelection(true, true);
954 cmd.message(_("Cut"));
960 cmd.message(_("Copy"));
963 case LFUN_BEGINNINGBUFSEL:
965 return DispatchResult(false);
966 if (!bv->selection().set())
969 finishChange(bv, true);
974 return DispatchResult(false);
975 if (!bv->selection().set())
978 finishChange(bv, true);
982 cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
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 && bv->selection().set() &&
1047 bv->selStart().par() != bv->selEnd().par())
1049 ParagraphList::iterator spit = getPar(bv->selStart());
1050 ParagraphList::iterator epit = boost::next(getPar(bv->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 bv->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(InsetOld::ERROR_CODE, false);
1088 gotoInset(InsetOld::NOTE_CODE, false);
1091 case LFUN_REFERENCE_GOTO: {
1092 vector<InsetOld::Code> tmp;
1093 tmp.push_back(InsetOld::LABEL_CODE);
1094 tmp.push_back(InsetOld::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(bv, false);
1143 case LFUN_MOUSE_TRIPLE:
1146 if (cmd.button() == mouse_button::button1) {
1147 selection_possible = true;
1152 bv->haveSelection(bv->selection().set());
1156 case LFUN_MOUSE_DOUBLE:
1159 if (cmd.button() == mouse_button::button1) {
1160 selection_possible = true;
1161 selectWord(lyx::WHOLE_WORD_STRICT);
1162 bv->haveSelection(bv->selection().set());
1166 case LFUN_MOUSE_MOTION: {
1167 // Only use motion with button 1
1168 //if (ev.button() != mouse_button::button1)
1173 // The test for not selection possible is needed, that
1174 // only motion events are used, where the bottom press
1175 // event was on the drawing area too
1176 if (!selection_possible) {
1177 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1178 "Dispatch: no selection possible\n";
1181 RowList::iterator cursorrow = cursorRow();
1183 setCursorFromCoordinates(cmd.x, cmd.y);
1185 // This is to allow jumping over large insets
1186 // FIXME: shouldn't be top-text-specific
1187 if (cursorrow == cursorRow() && !in_inset_) {
1188 if (cmd.y - bv->top_y() >= bv->workHeight())
1190 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 && bv->selection().set()) {
1221 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1222 paste_internally = true;
1225 selection_possible = true;
1227 // Clear the selection
1228 bv->clearSelection();
1230 // Right click on a footnote flag opens float menu
1231 if (cmd.button() == mouse_button::button3) {
1232 selection_possible = false;
1236 setCursorFromCoordinates(cmd.x, cmd.y);
1239 bv->x_target(cursorX() + xo_);
1241 if (bv->fitCursor())
1242 selection_possible = false;
1244 // Insert primary selection with middle mouse
1245 // if there is a local selection in the current buffer,
1247 if (cmd.button() == mouse_button::button2) {
1248 if (paste_internally)
1249 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1251 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1252 selection_possible = false;
1257 case LFUN_MOUSE_RELEASE: {
1261 // do nothing if we used the mouse wheel
1262 if (cmd.button() == mouse_button::button4
1263 || cmd.button() == mouse_button::button5)
1264 return DispatchResult(true, false);
1266 selection_possible = false;
1268 if (cmd.button() == mouse_button::button2)
1272 if (cmd.button() == mouse_button::button1)
1273 bv->haveSelection(bv->selection().set());
1276 bv->owner()->view_state_changed();
1277 bv->owner()->updateMenubar();
1278 bv->owner()->updateToolbar();
1282 case LFUN_SELFINSERT: {
1283 if (cmd.argument.empty())
1286 // Automatically delete the currently selected
1287 // text and replace it with what is being
1288 // typed in now. Depends on lyxrc settings
1289 // "auto_region_delete", which defaults to
1292 if (lyxrc.auto_region_delete) {
1293 if (bv->selection().set())
1294 cutSelection(false, false);
1295 bv->haveSelection(false);
1298 bv->clearSelection();
1299 LyXFont const old_font = real_current_font;
1301 string::const_iterator cit = cmd.argument.begin();
1302 string::const_iterator end = cmd.argument.end();
1303 for (; cit != end; ++cit)
1304 bv->owner()->getIntl().getTransManager().
1305 TranslateAndInsert(*cit, this);
1308 moveCursor(bv, false);
1310 // real_current_font.number can change so we need to
1311 // update the minibuffer
1312 if (old_font != real_current_font)
1313 bv->owner()->view_state_changed();
1314 bv->updateScrollbar();
1319 InsetCommandParams p("url");
1320 string const data = InsetCommandMailer::params2string("url", p);
1321 bv->owner()->getDialogs().show("url", data, 0);
1325 case LFUN_HTMLURL: {
1326 InsetCommandParams p("htmlurl");
1327 string const data = InsetCommandMailer::params2string("url", p);
1328 bv->owner()->getDialogs().show("url", data, 0);
1332 case LFUN_INSERT_LABEL: {
1333 InsetCommandParams p("label");
1334 string const data = InsetCommandMailer::params2string("label", p);
1335 bv->owner()->getDialogs().show("label", data, 0);
1341 case LFUN_INSET_LIST:
1342 case LFUN_INSET_THEOREM:
1343 case LFUN_INSET_CAPTION:
1345 case LFUN_INSERT_NOTE:
1346 case LFUN_INSERT_CHARSTYLE:
1347 case LFUN_INSERT_BOX:
1348 case LFUN_INSERT_BRANCH:
1349 case LFUN_INSERT_BIBITEM:
1350 case LFUN_INSET_ERT:
1351 case LFUN_INSET_FLOAT:
1352 case LFUN_INSET_FOOTNOTE:
1353 case LFUN_INSET_MARGINAL:
1354 case LFUN_INSET_OPTARG:
1355 case LFUN_INSET_WIDE_FLOAT:
1356 case LFUN_INSET_WRAP:
1357 case LFUN_TABULAR_INSERT:
1358 case LFUN_ENVIRONMENT_INSERT:
1359 // Open the inset, and move the current selection
1361 doInsertInset(cmd, true, true);
1364 case LFUN_INDEX_INSERT:
1365 // Just open the inset
1366 doInsertInset(cmd, true, false);
1369 case LFUN_INDEX_PRINT:
1370 case LFUN_TOC_INSERT:
1372 case LFUN_INSERT_LINE:
1373 case LFUN_INSERT_PAGEBREAK:
1375 doInsertInset(cmd, false, false);
1378 case LFUN_DEPTH_MIN:
1379 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1383 case LFUN_DEPTH_PLUS:
1384 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1388 case LFUN_MATH_DELIM:
1389 case LFUN_MATH_DISPLAY:
1390 case LFUN_INSERT_MATH:
1391 case LFUN_MATH_LIMITS:
1392 case LFUN_MATH_MACRO:
1393 case LFUN_MATH_MUTATE:
1394 case LFUN_MATH_SPACE:
1395 case LFUN_MATH_IMPORT_SELECTION:
1396 case LFUN_MATH_MODE:
1397 case LFUN_MATH_NONUMBER:
1398 case LFUN_MATH_NUMBER:
1399 case LFUN_MATH_EXTERN:
1400 case LFUN_MATH_SIZE:
1406 bv->owner()->view_state_changed();
1411 bv->owner()->view_state_changed();
1416 bv->owner()->view_state_changed();
1421 bv->owner()->view_state_changed();
1426 bv->owner()->view_state_changed();
1431 bv->owner()->view_state_changed();
1435 styleReset(bv, this);
1436 bv->owner()->view_state_changed();
1439 case LFUN_UNDERLINE:
1440 underline(bv, this);
1441 bv->owner()->view_state_changed();
1444 case LFUN_FONT_SIZE:
1445 fontSize(bv, cmd.argument, this);
1446 bv->owner()->view_state_changed();
1450 lang(bv, cmd.argument, this);
1452 bv->owner()->view_state_changed();
1455 case LFUN_FREEFONT_APPLY:
1456 apply_freefont(bv, this);
1459 case LFUN_FREEFONT_UPDATE:
1460 update_and_apply_freefont(bv, this, cmd.argument);
1463 case LFUN_FINISHED_LEFT:
1464 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1469 case LFUN_FINISHED_RIGHT:
1470 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1475 case LFUN_FINISHED_UP:
1476 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1480 case LFUN_FINISHED_DOWN:
1481 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1486 return DispatchResult(false);
1489 return DispatchResult(true, true);