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 LyXCursor & cursor = text->cursor;
95 Paragraph & par = *text->cursorPar();
96 text->bidi.computeTables(par, *bv->buffer(),
97 *par.getRow(cursor.pos()));
98 if (cursor.boundary() !=
99 text->bidi.isBoundary(*bv->buffer(), par,
101 text->real_current_font))
102 text->setCursor(cursor.par(), cursor.pos(),
103 false, !cursor.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 (!lt->selection.set())
221 // lt->selection.cursor = lt->cursor;
223 if (selecting || lt->selection.mark())
226 if (!lt->selection.set())
227 bv->haveSelection(false);
232 void finishChange(BufferView * bv, bool selecting = false)
235 moveCursor(bv, selecting);
236 bv->owner()->view_state_changed();
244 string const freefont2string()
247 if (font2string(freefont, toggleall, data))
255 InsetOld * LyXText::checkInsetHit(int x, int y)
257 ParagraphList::iterator pit;
258 ParagraphList::iterator end;
260 getParsInRange(paragraphs(),
262 bv()->top_y() - yo_ + bv()->workHeight(),
265 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
266 for ( ; pit != end; ++pit) {
267 InsetList::iterator iit = pit->insetlist.begin();
268 InsetList::iterator iend = pit->insetlist.end();
269 for ( ; iit != iend; ++iit) {
270 InsetOld * inset = iit->inset;
271 //lyxerr << "examining inset " << inset
272 // << " xy: " << inset->x() << "/" << inset->y()
273 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
274 // << " y: " << inset->y() - inset->ascent() << "..."
275 // << inset->y() + inset->descent()
278 && x <= inset->x() + inset->width()
279 && y >= inset->y() - inset->ascent()
280 && y <= inset->y() + inset->descent())
282 lyxerr << "Hit inset: " << inset << endl;
287 lyxerr << "No inset hit. " << endl;
292 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
293 string const & contents)
295 ParagraphList::iterator end = paragraphs().end();
296 ParagraphList::iterator pit = cursorPar();
297 pos_type pos = cursor.pos();
301 if (pos + 1 < pit->size()) {
308 } while (pit != end &&
309 !(pit->isInset(pos) &&
310 (inset = pit->getInset(pos)) != 0 &&
311 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
313 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
319 setCursor(parOffset(pit), pos, false);
324 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
330 if (same_content && cursor.pos() < cursorPar()->size()
331 && cursorPar()->isInset(cursor.pos())) {
332 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
333 if (find(codes.begin(), codes.end(), inset->lyxCode())
335 contents = static_cast<InsetCommand const *>(inset)->getContents();
338 if (!gotoNextInset(codes, contents)) {
339 if (cursor.pos() || cursorPar() != paragraphs().begin()) {
340 LyXCursor tmp = cursor;
343 if (!gotoNextInset(codes, contents)) {
345 bv()->owner()->message(_("No more insets"));
348 bv()->owner()->message(_("No more insets"));
352 selection.cursor = cursor;
356 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
358 gotoInset(vector<InsetOld::Code>(1, code), same_content);
362 void LyXText::cursorPrevious()
365 RowList::iterator crit = cursorRow();
366 ParagraphList::iterator cpar = cursorPar();
368 int x = bv()->x_target() - xo_;
369 int y = bv()->top_y() - yo_;
370 setCursorFromCoordinates(x, y);
372 if (cpar == cursorPar() && crit == cursorRow()) {
373 // we have a row which is taller than the workarea. The
374 // simplest solution is to move to the previous row instead.
378 bv()->updateScrollbar();
383 void LyXText::cursorNext()
385 RowList::iterator crit = cursorRow();
386 ParagraphList::iterator cpar = cursorPar();
388 int x = bv()->x_target() - xo_;
389 int y = bv()->top_y() + bv()->workHeight() - yo_;
390 setCursorFromCoordinates(x, y);
392 if (cpar == cursorPar() && crit == cursorRow()) {
393 // we have a row which is taller than the workarea. The
394 // simplest solution is to move to the next row instead.
398 bv()->updateScrollbar();
405 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
408 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
409 replaceSelection(lt);
410 if (!bv->insertInset(new_inset))
417 void doInsertInset(LyXText const & lt, FuncRequest const & cmd,
418 bool edit, bool pastesel)
420 InsetOld * inset = createInset(cmd);
421 BufferView * bv = cmd.view();
425 if (lt.selection.set()) {
426 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
429 if (bv->insertInset(inset)) {
431 inset->edit(bv, true);
432 if (gotsel && pastesel)
433 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
442 void LyXText::number()
444 LyXFont font(LyXFont::ALL_IGNORE);
445 font.setNumber(LyXFont::TOGGLE);
446 toggleAndShow(bv(), this, font);
450 bool LyXText::rtl() const
452 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
456 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
458 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
460 BufferView * bv = cmd.view();
462 switch (cmd.action) {
464 case LFUN_APPENDIX: {
465 ParagraphList::iterator pit = cursorPar();
466 bool start = !pit->params().startOfAppendix();
468 // ensure that we have only one start_of_appendix in this document
469 ParagraphList::iterator tmp = paragraphs().begin();
470 ParagraphList::iterator end = paragraphs().end();
472 for (; tmp != end; ++tmp) {
473 if (tmp->params().startOfAppendix()) {
474 recUndo(parOffset(tmp));
475 tmp->params().startOfAppendix(false);
481 recUndo(parOffset(pit));
482 pit->params().startOfAppendix(start);
484 // we can set the refreshing parameters now
486 redoParagraph(cursorPar());
487 setCursor(cursorPar(), cursor.pos());
492 case LFUN_DELETE_WORD_FORWARD:
498 case LFUN_DELETE_WORD_BACKWARD:
500 deleteWordBackward();
504 case LFUN_DELETE_LINE_FORWARD:
511 if (!selection.mark())
516 cursorRightOneWord();
521 if (!selection.mark())
524 cursorRightOneWord();
530 case LFUN_BEGINNINGBUF:
531 if (!selection.mark())
538 if (selection.mark())
545 if (!selection.set())
546 selection.cursor = cursor;
551 finishChange(bv, true);
555 if (!selection.set())
556 selection.cursor = cursor;
561 finishChange(bv, true);
565 if (!selection.set())
566 selection.cursor = cursor;
568 finishChange(bv, true);
572 if (!selection.set())
573 selection.cursor = cursor;
575 finishChange(bv, true);
578 case LFUN_UP_PARAGRAPHSEL:
579 if (!selection.set())
580 selection.cursor = cursor;
582 finishChange(bv, true);
585 case LFUN_DOWN_PARAGRAPHSEL:
586 if (!selection.set())
587 selection.cursor = cursor;
588 cursorDownParagraph();
589 finishChange(bv, true);
593 if (!selection.set())
594 selection.cursor = cursor;
596 finishChange(bv, true);
600 if (!selection.set())
601 selection.cursor = cursor;
603 finishChange(bv, true);
607 if (!selection.set())
608 selection.cursor = cursor;
610 finishChange(bv, true);
614 if (!selection.set())
615 selection.cursor = cursor;
617 finishChange(bv, true);
620 case LFUN_WORDRIGHTSEL:
624 cursorRightOneWord();
625 finishChange(bv, true);
628 case LFUN_WORDLEFTSEL:
630 cursorRightOneWord();
633 finishChange(bv, true);
637 LyXCursor cur1 = cursor;
639 getWord(cur1, cur2, lyx::WHOLE_WORD);
640 setCursor(cur1.par(), cur1.pos());
642 setCursor(cur2.par(), cur2.pos());
643 finishChange(bv, true);
663 case LFUN_UP_PARAGRAPH:
664 if (!selection.mark())
670 case LFUN_DOWN_PARAGRAPH:
671 if (!selection.mark())
673 cursorDownParagraph();
674 finishChange(bv, false);
678 if (!selection.mark())
680 finishChange(bv, false);
681 if (cursorPar() == firstPar() && cursorRow() == firstRow())
682 return DispatchResult(false, FINISHED_UP);
687 if (!selection.mark())
689 finishChange(bv, false);
690 if (cursorPar() == lastPar() && cursorRow() == lastRow())
691 return DispatchResult(false, FINISHED_DOWN);
696 if (!selection.mark())
699 finishChange(bv, false);
703 if (!selection.mark())
706 finishChange(bv, false);
709 case LFUN_BREAKLINE: {
710 lyx::pos_type body = cursorPar()->beginOfBody();
712 // Not allowed by LaTeX (labels or empty par)
713 if (cursor.pos() <= body)
716 replaceSelection(bv->getLyXText());
717 insertInset(new InsetNewline);
718 setCursor(cursorPar(), cursor.pos());
719 moveCursor(bv, false);
724 if (!selection.set()) {
726 selection.cursor = cursor;
727 // It is possible to make it a lot faster still
728 // just comment out the line below...
730 cutSelection(true, false);
732 moveCursor(bv, false);
733 bv->owner()->view_state_changed();
736 case LFUN_DELETE_SKIP:
737 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
738 if (!selection.set()) {
739 if (cursor.pos() == cursorPar()->size()) {
743 selection.cursor = cursor;
746 selection.cursor = cursor;
749 cutSelection(true, false);
756 if (!selection.set()) {
757 if (bv->owner()->getIntl().getTransManager().backspace()) {
759 selection.cursor = cursor;
760 // It is possible to make it a lot faster still
761 // just comment out the line below...
764 cutSelection(true, false);
766 bv->owner()->view_state_changed();
771 case LFUN_BACKSPACE_SKIP:
772 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
773 if (!selection.set()) {
774 LyXCursor cur = cursor;
776 selection.cursor = cur;
778 cutSelection(true, false);
783 case LFUN_BREAKPARAGRAPH:
784 replaceSelection(bv->getLyXText());
785 breakParagraph(bv->buffer()->paragraphs(), 0);
787 selection.cursor = cursor;
789 bv->owner()->view_state_changed();
792 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
793 replaceSelection(bv->getLyXText());
794 breakParagraph(bv->buffer()->paragraphs(), 1);
796 selection.cursor = cursor;
798 bv->owner()->view_state_changed();
801 case LFUN_BREAKPARAGRAPH_SKIP: {
802 // When at the beginning of a paragraph, remove
803 // indentation and add a "defskip" at the top.
804 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
805 LyXCursor cur = cursor;
806 replaceSelection(bv->getLyXText());
807 if (cur.pos() == 0) {
808 ParagraphParameters & params = getPar(cur)->params();
812 params.labelWidthString(), 1);
814 breakParagraph(bv->buffer()->paragraphs(), 0);
817 selection.cursor = cur;
819 bv->owner()->view_state_changed();
823 case LFUN_PARAGRAPH_SPACING: {
824 ParagraphList::iterator pit = cursorPar();
825 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
826 float cur_value = 1.0;
827 if (cur_spacing == Spacing::Other)
828 cur_value = pit->params().spacing().getValue();
830 istringstream is(cmd.argument);
833 Spacing::Space new_spacing = cur_spacing;
834 float new_value = cur_value;
836 lyxerr << "Missing argument to `paragraph-spacing'"
838 } else if (tmp == "single") {
839 new_spacing = Spacing::Single;
840 } else if (tmp == "onehalf") {
841 new_spacing = Spacing::Onehalf;
842 } else if (tmp == "double") {
843 new_spacing = Spacing::Double;
844 } else if (tmp == "other") {
845 new_spacing = Spacing::Other;
848 lyxerr << "new_value = " << tmpval << endl;
851 } else if (tmp == "default") {
852 new_spacing = Spacing::Default;
854 lyxerr << _("Unknown spacing argument: ")
855 << cmd.argument << endl;
857 if (cur_spacing != new_spacing || cur_value != new_value) {
858 pit->params().spacing(Spacing(new_spacing, new_value));
865 case LFUN_INSET_APPLY: {
866 string const name = cmd.getArg(0);
867 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
869 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
872 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
878 case LFUN_INSET_INSERT: {
879 InsetOld * inset = createInset(cmd);
880 if (!inset || !bv->insertInset(inset))
885 case LFUN_INSET_SETTINGS:
886 bv->cursor().innerInset()->showInsetDialog(bv);
889 case LFUN_INSET_TOGGLE:
892 return DispatchResult(false);
897 case LFUN_SPACE_INSERT:
898 if (cursorPar()->layout()->free_spacing)
901 doInsertInset(*this, cmd, false, false);
902 moveCursor(bv, false);
905 case LFUN_HYPHENATION:
906 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
909 case LFUN_LIGATURE_BREAK:
910 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
914 specialChar(this, bv, InsetSpecialChar::LDOTS);
917 case LFUN_END_OF_SENTENCE:
918 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
921 case LFUN_MENU_SEPARATOR:
922 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
928 selection.cursor = cursor;
929 cmd.message(N_("Mark off"));
934 selection.mark(true);
936 selection.cursor = cursor;
937 cmd.message(N_("Mark on"));
942 if (selection.mark()) {
943 cmd.message(N_("Mark removed"));
945 selection.mark(true);
946 cmd.message(N_("Mark set"));
948 selection.cursor = cursor;
952 case LFUN_UPCASE_WORD:
953 changeCase(LyXText::text_uppercase);
957 case LFUN_LOWCASE_WORD:
958 changeCase(LyXText::text_lowercase);
962 case LFUN_CAPITALIZE_WORD:
963 changeCase(LyXText::text_capitalization);
967 case LFUN_TRANSPOSE_CHARS:
968 recUndo(cursor.par());
974 cmd.message(_("Paste"));
975 replaceSelection(bv->getLyXText());
976 #warning FIXME Check if the arg is in the domain of available selections.
977 if (isStrUnsignedInt(cmd.argument))
978 pasteSelection(strToUnsignedInt(cmd.argument));
981 clearSelection(); // bug 393
988 cutSelection(true, true);
989 cmd.message(_("Cut"));
995 cmd.message(_("Copy"));
998 case LFUN_BEGINNINGBUFSEL:
1000 return DispatchResult(false);
1002 finishChange(bv, true);
1005 case LFUN_ENDBUFSEL:
1007 return DispatchResult(false);
1009 finishChange(bv, true);
1013 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1019 istringstream is(cmd.argument);
1022 lyxerr << "SETXY: Could not parse coordinates in '"
1023 << cmd.argument << std::endl;
1025 setCursorFromCoordinates(x, y);
1030 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1032 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1038 case LFUN_GETLAYOUT:
1039 cmd.message(tostr(cursorPar()->layout()));
1043 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1044 << cmd.argument << endl;
1046 // This is not the good solution to the empty argument
1047 // problem, but it will hopefully suffice for 1.2.0.
1048 // The correct solution would be to augument the
1049 // function list/array with information about what
1050 // functions needs arguments and their type.
1051 if (cmd.argument.empty()) {
1052 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1056 // Derive layout number from given argument (string)
1057 // and current buffer's textclass (number)
1058 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1059 bool hasLayout = tclass.hasLayout(cmd.argument);
1060 string layout = cmd.argument;
1062 // If the entry is obsolete, use the new one instead.
1064 string const & obs = tclass[layout]->obsoleted_by();
1070 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1075 bool change_layout = (current_layout != layout);
1077 if (!change_layout && selection.set() &&
1078 selection.start.par() != selection.end.par())
1080 ParagraphList::iterator spit = getPar(selection.start);
1081 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1082 while (spit != epit) {
1083 if (spit->layout()->name() != current_layout) {
1084 change_layout = true;
1091 if (change_layout) {
1092 current_layout = layout;
1094 bv->owner()->setLayout(layout);
1101 case LFUN_PASTESELECTION: {
1102 // this was originally a bv->text->clearSelection(), i.e
1103 // the outermost LyXText!
1105 string const clip = bv->getClipboard();
1106 if (!clip.empty()) {
1107 if (cmd.argument == "paragraph")
1108 insertStringAsParagraphs(clip);
1110 insertStringAsLines(clip);
1116 case LFUN_GOTOERROR:
1117 gotoInset(InsetOld::ERROR_CODE, false);
1121 gotoInset(InsetOld::NOTE_CODE, false);
1124 case LFUN_REFERENCE_GOTO: {
1125 vector<InsetOld::Code> tmp;
1126 tmp.push_back(InsetOld::LABEL_CODE);
1127 tmp.push_back(InsetOld::REF_CODE);
1128 gotoInset(tmp, true);
1133 replaceSelection(bv->getLyXText());
1134 ParagraphList::iterator pit = cursorPar();
1135 lyx::pos_type pos = cursor.pos();
1139 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1142 c = pit->getChar(pos - 1);
1144 LyXLayout_ptr const & style = pit->layout();
1146 BufferParams const & bufparams = bv->buffer()->params();
1147 if (style->pass_thru ||
1148 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1149 !bv->insertInset(new InsetQuotes(c, bufparams)))
1150 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1154 case LFUN_DATE_INSERT: {
1155 replaceSelection(bv->getLyXText());
1156 time_t now_time_t = time(NULL);
1157 struct tm * now_tm = localtime(&now_time_t);
1158 setlocale(LC_TIME, "");
1160 if (!cmd.argument.empty())
1163 arg = lyxrc.date_insert_format;
1165 int const datetmp_len =
1166 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1168 for (int i = 0; i < datetmp_len; i++)
1169 insertChar(datetmp[i]);
1171 selection.cursor = cursor;
1172 moveCursor(bv, false);
1176 case LFUN_MOUSE_TRIPLE:
1179 if (cmd.button() == mouse_button::button1) {
1180 selection_possible = true;
1182 selection.cursor = cursor;
1185 bv->haveSelection(selection.set());
1189 case LFUN_MOUSE_DOUBLE:
1192 if (cmd.button() == mouse_button::button1) {
1193 selection_possible = true;
1194 selectWord(lyx::WHOLE_WORD_STRICT);
1195 bv->haveSelection(selection.set());
1199 case LFUN_MOUSE_MOTION: {
1200 // Only use motion with button 1
1201 //if (ev.button() != mouse_button::button1)
1206 // The test for not selection possible is needed, that
1207 // only motion events are used, where the bottom press
1208 // event was on the drawing area too
1209 if (!selection_possible) {
1210 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1211 "Dispatch: no selection possible\n";
1214 RowList::iterator cursorrow = cursorRow();
1216 setCursorFromCoordinates(cmd.x, cmd.y);
1218 // This is to allow jumping over large insets
1219 // FIXME: shouldn't be top-text-specific
1220 if (cursorrow == cursorRow() && !in_inset_) {
1221 if (cmd.y - bv->top_y() >= bv->workHeight())
1223 else if (cmd.y - bv->top_y() < 0)
1230 // Single-click on work area
1231 case LFUN_MOUSE_PRESS: {
1235 // ok ok, this is a hack (for xforms)
1236 // We shouldn't go further down as we really should only do the
1237 // scrolling and be done with this. Otherwise we may open some
1238 // dialogs (Jug 20020424).
1239 if (cmd.button() == mouse_button::button4) {
1240 bv->scroll(-lyxrc.wheel_jump);
1243 if (cmd.button() == mouse_button::button5) {
1244 bv->scroll(lyxrc.wheel_jump);
1248 // Middle button press pastes if we have a selection
1249 // We do this here as if the selection was inside an inset
1250 // it could get cleared on the unlocking of the inset so
1251 // we have to check this first
1252 bool paste_internally = false;
1253 if (cmd.button() == mouse_button::button2 && selection.set()) {
1254 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1255 paste_internally = true;
1258 selection_possible = true;
1260 // Clear the selection
1263 // Right click on a footnote flag opens float menu
1264 if (cmd.button() == mouse_button::button3) {
1265 selection_possible = false;
1269 setCursorFromCoordinates(cmd.x, cmd.y);
1270 selection.cursor = cursor;
1272 bv->x_target(cursor.x() + xo_);
1274 if (bv->fitCursor())
1275 selection_possible = false;
1277 // Insert primary selection with middle mouse
1278 // if there is a local selection in the current buffer,
1280 if (cmd.button() == mouse_button::button2) {
1281 if (paste_internally)
1282 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1284 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1285 selection_possible = false;
1290 case LFUN_MOUSE_RELEASE: {
1294 // do nothing if we used the mouse wheel
1295 if (cmd.button() == mouse_button::button4
1296 || cmd.button() == mouse_button::button5)
1297 return DispatchResult(true, false);
1299 selection_possible = false;
1301 if (cmd.button() == mouse_button::button2)
1305 if (cmd.button() == mouse_button::button1)
1306 bv->haveSelection(selection.set());
1309 bv->owner()->view_state_changed();
1310 bv->owner()->updateMenubar();
1311 bv->owner()->updateToolbar();
1315 case LFUN_SELFINSERT: {
1316 if (cmd.argument.empty())
1319 // Automatically delete the currently selected
1320 // text and replace it with what is being
1321 // typed in now. Depends on lyxrc settings
1322 // "auto_region_delete", which defaults to
1325 if (lyxrc.auto_region_delete) {
1326 if (selection.set())
1327 cutSelection(false, false);
1328 bv->haveSelection(false);
1332 LyXFont const old_font = real_current_font;
1334 string::const_iterator cit = cmd.argument.begin();
1335 string::const_iterator end = cmd.argument.end();
1336 for (; cit != end; ++cit)
1337 bv->owner()->getIntl().getTransManager().
1338 TranslateAndInsert(*cit, this);
1340 selection.cursor = cursor;
1341 moveCursor(bv, false);
1343 // real_current_font.number can change so we need to
1344 // update the minibuffer
1345 if (old_font != real_current_font)
1346 bv->owner()->view_state_changed();
1347 bv->updateScrollbar();
1352 InsetCommandParams p("url");
1353 string const data = InsetCommandMailer::params2string("url", p);
1354 bv->owner()->getDialogs().show("url", data, 0);
1358 case LFUN_HTMLURL: {
1359 InsetCommandParams p("htmlurl");
1360 string const data = InsetCommandMailer::params2string("url", p);
1361 bv->owner()->getDialogs().show("url", data, 0);
1365 case LFUN_INSERT_LABEL: {
1366 InsetCommandParams p("label");
1367 string const data = InsetCommandMailer::params2string("label", p);
1368 bv->owner()->getDialogs().show("label", data, 0);
1374 case LFUN_INSET_LIST:
1375 case LFUN_INSET_THEOREM:
1376 case LFUN_INSET_CAPTION:
1378 case LFUN_INSERT_NOTE:
1379 case LFUN_INSERT_CHARSTYLE:
1380 case LFUN_INSERT_BOX:
1381 case LFUN_INSERT_BRANCH:
1382 case LFUN_INSERT_BIBITEM:
1383 case LFUN_INSET_ERT:
1384 case LFUN_INSET_FLOAT:
1385 case LFUN_INSET_FOOTNOTE:
1386 case LFUN_INSET_MARGINAL:
1387 case LFUN_INSET_MINIPAGE:
1388 case LFUN_INSET_OPTARG:
1389 case LFUN_INSET_WIDE_FLOAT:
1390 case LFUN_INSET_WRAP:
1391 case LFUN_TABULAR_INSERT:
1392 case LFUN_ENVIRONMENT_INSERT:
1393 // Open the inset, and move the current selection
1395 doInsertInset(*this, cmd, true, true);
1398 case LFUN_INDEX_INSERT:
1399 // Just open the inset
1400 doInsertInset(*this, cmd, true, false);
1403 case LFUN_INDEX_PRINT:
1404 case LFUN_TOC_INSERT:
1406 case LFUN_INSERT_LINE:
1407 case LFUN_INSERT_PAGEBREAK:
1409 doInsertInset(*this, cmd, false, false);
1412 case LFUN_DEPTH_MIN:
1413 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1417 case LFUN_DEPTH_PLUS:
1418 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1422 case LFUN_MATH_DELIM:
1423 case LFUN_MATH_DISPLAY:
1424 case LFUN_INSERT_MATH:
1425 case LFUN_MATH_LIMITS:
1426 case LFUN_MATH_MACRO:
1427 case LFUN_MATH_MUTATE:
1428 case LFUN_MATH_SPACE:
1429 case LFUN_MATH_IMPORT_SELECTION:
1430 case LFUN_MATH_MODE:
1431 case LFUN_MATH_NONUMBER:
1432 case LFUN_MATH_NUMBER:
1433 case LFUN_MATH_EXTERN:
1434 case LFUN_MATH_SIZE:
1440 bv->owner()->view_state_changed();
1445 bv->owner()->view_state_changed();
1450 bv->owner()->view_state_changed();
1455 bv->owner()->view_state_changed();
1460 bv->owner()->view_state_changed();
1465 bv->owner()->view_state_changed();
1469 styleReset(bv, this);
1470 bv->owner()->view_state_changed();
1473 case LFUN_UNDERLINE:
1474 underline(bv, this);
1475 bv->owner()->view_state_changed();
1478 case LFUN_FONT_SIZE:
1479 fontSize(bv, cmd.argument, this);
1480 bv->owner()->view_state_changed();
1484 lang(bv, cmd.argument, this);
1486 bv->owner()->view_state_changed();
1489 case LFUN_FREEFONT_APPLY:
1490 apply_freefont(bv, this);
1493 case LFUN_FREEFONT_UPDATE:
1494 update_and_apply_freefont(bv, this, cmd.argument);
1497 case LFUN_FINISHED_LEFT:
1498 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1503 case LFUN_FINISHED_RIGHT:
1504 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1509 case LFUN_FINISHED_UP:
1510 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1514 case LFUN_FINISHED_DOWN:
1515 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1520 return DispatchResult(false);
1523 return DispatchResult(true, true);