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))
256 InsetOld * LyXText::checkInsetHit(int x, int y)
258 ParagraphList::iterator pit;
259 ParagraphList::iterator end;
261 getParsInRange(paragraphs(),
263 bv()->top_y() - yo_ + bv()->workHeight(),
266 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
267 for ( ; pit != end; ++pit) {
268 InsetList::iterator iit = pit->insetlist.begin();
269 InsetList::iterator iend = pit->insetlist.end();
270 for ( ; iit != iend; ++iit) {
271 InsetOld * inset = iit->inset;
272 //lyxerr << "examining inset " << inset
273 // << " xy: " << inset->x() << "/" << inset->y()
274 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
275 // << " y: " << inset->y() - inset->ascent() << "..."
276 // << inset->y() + inset->descent()
279 && x <= inset->x() + inset->width()
280 && y >= inset->y() - inset->ascent()
281 && y <= inset->y() + inset->descent())
283 lyxerr << "Hit inset: " << inset << endl;
288 lyxerr << "No inset hit. " << endl;
293 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
294 string const & contents)
296 ParagraphList::iterator end = paragraphs().end();
297 ParagraphList::iterator pit = cursorPar();
298 pos_type pos = cursor.pos();
302 if (pos + 1 < pit->size()) {
309 } while (pit != end &&
310 !(pit->isInset(pos) &&
311 (inset = pit->getInset(pos)) != 0 &&
312 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
314 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
320 setCursor(parOffset(pit), pos, false);
325 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
331 if (same_content && cursor.pos() < cursorPar()->size()
332 && cursorPar()->isInset(cursor.pos())) {
333 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
334 if (find(codes.begin(), codes.end(), inset->lyxCode())
336 contents = static_cast<InsetCommand const *>(inset)->getContents();
339 if (!gotoNextInset(codes, contents)) {
340 if (cursor.pos() || cursorPar() != paragraphs().begin()) {
341 LyXCursor tmp = cursor;
344 if (!gotoNextInset(codes, contents)) {
346 bv()->owner()->message(_("No more insets"));
349 bv()->owner()->message(_("No more insets"));
353 selection.cursor = cursor;
357 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
359 gotoInset(vector<InsetOld::Code>(1, code), same_content);
363 void LyXText::cursorPrevious()
366 RowList::iterator crit = cursorRow();
367 ParagraphList::iterator cpar = cursorPar();
369 int x = bv()->x_target() - xo_;
370 int y = bv()->top_y() - yo_;
371 setCursorFromCoordinates(x, y);
373 if (cpar == cursorPar() && crit == cursorRow()) {
374 // we have a row which is taller than the workarea. The
375 // simplest solution is to move to the previous row instead.
379 bv()->updateScrollbar();
384 void LyXText::cursorNext()
386 RowList::iterator crit = cursorRow();
387 ParagraphList::iterator cpar = cursorPar();
389 int x = bv()->x_target() - xo_;
390 int y = bv()->top_y() + bv()->workHeight() - yo_;
391 setCursorFromCoordinates(x, y);
393 if (cpar == cursorPar() && crit == cursorRow()) {
394 // we have a row which is taller than the workarea. The
395 // simplest solution is to move to the next row instead.
399 bv()->updateScrollbar();
406 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
409 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
410 replaceSelection(lt);
411 if (!bv->insertInset(new_inset))
418 void doInsertInset(LyXText const & lt, FuncRequest const & cmd,
419 bool edit, bool pastesel)
421 InsetOld * inset = createInset(cmd);
422 BufferView * bv = cmd.view();
426 if (lt.selection.set()) {
427 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
430 if (bv->insertInset(inset)) {
432 inset->edit(bv, true);
433 if (gotsel && pastesel)
434 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
443 void LyXText::number()
445 LyXFont font(LyXFont::ALL_IGNORE);
446 font.setNumber(LyXFont::TOGGLE);
447 toggleAndShow(bv(), this, font);
451 bool LyXText::rtl() const
453 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
457 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
459 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
461 BufferView * bv = cmd.view();
463 switch (cmd.action) {
465 case LFUN_APPENDIX: {
466 ParagraphList::iterator pit = cursorPar();
467 bool start = !pit->params().startOfAppendix();
469 // ensure that we have only one start_of_appendix in this document
470 ParagraphList::iterator tmp = paragraphs().begin();
471 ParagraphList::iterator end = paragraphs().end();
473 for (; tmp != end; ++tmp) {
474 if (tmp->params().startOfAppendix()) {
475 recUndo(parOffset(tmp));
476 tmp->params().startOfAppendix(false);
482 recUndo(parOffset(pit));
483 pit->params().startOfAppendix(start);
485 // we can set the refreshing parameters now
487 redoParagraph(cursorPar());
488 setCursor(cursorPar(), cursor.pos());
493 case LFUN_DELETE_WORD_FORWARD:
499 case LFUN_DELETE_WORD_BACKWARD:
501 deleteWordBackward();
505 case LFUN_DELETE_LINE_FORWARD:
512 if (!selection.mark())
517 cursorRightOneWord();
522 if (!selection.mark())
525 cursorRightOneWord();
531 case LFUN_BEGINNINGBUF:
532 if (!selection.mark())
539 if (selection.mark())
546 if (!selection.set())
547 selection.cursor = cursor;
552 finishChange(bv, true);
556 if (!selection.set())
557 selection.cursor = cursor;
562 finishChange(bv, true);
566 if (!selection.set())
567 selection.cursor = cursor;
569 finishChange(bv, true);
573 if (!selection.set())
574 selection.cursor = cursor;
576 finishChange(bv, true);
579 case LFUN_UP_PARAGRAPHSEL:
580 if (!selection.set())
581 selection.cursor = cursor;
583 finishChange(bv, true);
586 case LFUN_DOWN_PARAGRAPHSEL:
587 if (!selection.set())
588 selection.cursor = cursor;
589 cursorDownParagraph();
590 finishChange(bv, true);
594 if (!selection.set())
595 selection.cursor = cursor;
597 finishChange(bv, true);
601 if (!selection.set())
602 selection.cursor = cursor;
604 finishChange(bv, true);
608 if (!selection.set())
609 selection.cursor = cursor;
611 finishChange(bv, true);
615 if (!selection.set())
616 selection.cursor = cursor;
618 finishChange(bv, true);
621 case LFUN_WORDRIGHTSEL:
625 cursorRightOneWord();
626 finishChange(bv, true);
629 case LFUN_WORDLEFTSEL:
631 cursorRightOneWord();
634 finishChange(bv, true);
638 LyXCursor cur1 = cursor;
640 getWord(cur1, cur2, lyx::WHOLE_WORD);
641 setCursor(cur1.par(), cur1.pos());
643 setCursor(cur2.par(), cur2.pos());
644 finishChange(bv, true);
664 case LFUN_UP_PARAGRAPH:
665 if (!selection.mark())
671 case LFUN_DOWN_PARAGRAPH:
672 if (!selection.mark())
674 cursorDownParagraph();
675 finishChange(bv, false);
679 if (!selection.mark())
681 finishChange(bv, false);
682 if (cursorPar() == firstPar() && cursorRow() == firstRow())
683 return DispatchResult(false, FINISHED_UP);
688 if (!selection.mark())
690 finishChange(bv, false);
691 if (cursorPar() == lastPar() && cursorRow() == lastRow())
692 return DispatchResult(false, FINISHED_DOWN);
697 if (!selection.mark())
700 finishChange(bv, false);
704 if (!selection.mark())
707 finishChange(bv, false);
710 case LFUN_BREAKLINE: {
711 lyx::pos_type body = cursorPar()->beginOfBody();
713 // Not allowed by LaTeX (labels or empty par)
714 if (cursor.pos() <= body)
717 replaceSelection(bv->getLyXText());
718 insertInset(new InsetNewline);
719 setCursor(cursorPar(), cursor.pos());
720 moveCursor(bv, false);
725 if (!selection.set()) {
727 selection.cursor = cursor;
728 // It is possible to make it a lot faster still
729 // just comment out the line below...
731 cutSelection(true, false);
733 moveCursor(bv, false);
734 bv->owner()->view_state_changed();
737 case LFUN_DELETE_SKIP:
738 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
739 if (!selection.set()) {
740 if (cursor.pos() == cursorPar()->size()) {
744 selection.cursor = cursor;
747 selection.cursor = cursor;
750 cutSelection(true, false);
757 if (!selection.set()) {
758 if (bv->owner()->getIntl().getTransManager().backspace()) {
760 selection.cursor = cursor;
761 // It is possible to make it a lot faster still
762 // just comment out the line below...
765 cutSelection(true, false);
767 bv->owner()->view_state_changed();
772 case LFUN_BACKSPACE_SKIP:
773 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
774 if (!selection.set()) {
775 LyXCursor cur = cursor;
777 selection.cursor = cur;
779 cutSelection(true, false);
784 case LFUN_BREAKPARAGRAPH:
785 replaceSelection(bv->getLyXText());
786 breakParagraph(bv->buffer()->paragraphs(), 0);
788 selection.cursor = cursor;
790 bv->owner()->view_state_changed();
793 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
794 replaceSelection(bv->getLyXText());
795 breakParagraph(bv->buffer()->paragraphs(), 1);
797 selection.cursor = cursor;
799 bv->owner()->view_state_changed();
802 case LFUN_BREAKPARAGRAPH_SKIP: {
803 // When at the beginning of a paragraph, remove
804 // indentation and add a "defskip" at the top.
805 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
806 LyXCursor cur = cursor;
807 replaceSelection(bv->getLyXText());
808 if (cur.pos() == 0) {
809 ParagraphParameters & params = getPar(cur)->params();
813 params.labelWidthString(), 1);
815 breakParagraph(bv->buffer()->paragraphs(), 0);
818 selection.cursor = cur;
820 bv->owner()->view_state_changed();
824 case LFUN_PARAGRAPH_SPACING: {
825 ParagraphList::iterator pit = cursorPar();
826 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
827 float cur_value = 1.0;
828 if (cur_spacing == Spacing::Other)
829 cur_value = pit->params().spacing().getValue();
831 istringstream is(cmd.argument);
834 Spacing::Space new_spacing = cur_spacing;
835 float new_value = cur_value;
837 lyxerr << "Missing argument to `paragraph-spacing'"
839 } else if (tmp == "single") {
840 new_spacing = Spacing::Single;
841 } else if (tmp == "onehalf") {
842 new_spacing = Spacing::Onehalf;
843 } else if (tmp == "double") {
844 new_spacing = Spacing::Double;
845 } else if (tmp == "other") {
846 new_spacing = Spacing::Other;
849 lyxerr << "new_value = " << tmpval << endl;
852 } else if (tmp == "default") {
853 new_spacing = Spacing::Default;
855 lyxerr << _("Unknown spacing argument: ")
856 << cmd.argument << endl;
858 if (cur_spacing != new_spacing || cur_value != new_value) {
859 pit->params().spacing(Spacing(new_spacing, new_value));
866 case LFUN_INSET_APPLY: {
867 string const name = cmd.getArg(0);
868 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
870 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
873 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
879 case LFUN_INSET_INSERT: {
880 InsetOld * inset = createInset(cmd);
881 if (!inset || !bv->insertInset(inset))
886 case LFUN_INSET_SETTINGS:
887 bv->cursor().innerInset()->showInsetDialog(bv);
890 case LFUN_INSET_TOGGLE:
893 return DispatchResult(false);
898 case LFUN_SPACE_INSERT:
899 if (cursorPar()->layout()->free_spacing)
902 doInsertInset(*this, cmd, false, false);
903 moveCursor(bv, false);
906 case LFUN_HYPHENATION:
907 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
910 case LFUN_LIGATURE_BREAK:
911 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
915 specialChar(this, bv, InsetSpecialChar::LDOTS);
918 case LFUN_END_OF_SENTENCE:
919 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
922 case LFUN_MENU_SEPARATOR:
923 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
929 selection.cursor = cursor;
930 cmd.message(N_("Mark off"));
935 selection.mark(true);
937 selection.cursor = cursor;
938 cmd.message(N_("Mark on"));
943 if (selection.mark()) {
944 cmd.message(N_("Mark removed"));
946 selection.mark(true);
947 cmd.message(N_("Mark set"));
949 selection.cursor = cursor;
953 case LFUN_UPCASE_WORD:
954 changeCase(LyXText::text_uppercase);
958 case LFUN_LOWCASE_WORD:
959 changeCase(LyXText::text_lowercase);
963 case LFUN_CAPITALIZE_WORD:
964 changeCase(LyXText::text_capitalization);
968 case LFUN_TRANSPOSE_CHARS:
969 recUndo(cursor.par());
975 cmd.message(_("Paste"));
976 replaceSelection(bv->getLyXText());
977 #warning FIXME Check if the arg is in the domain of available selections.
978 if (isStrUnsignedInt(cmd.argument))
979 pasteSelection(strToUnsignedInt(cmd.argument));
982 clearSelection(); // bug 393
989 cutSelection(true, true);
990 cmd.message(_("Cut"));
996 cmd.message(_("Copy"));
999 case LFUN_BEGINNINGBUFSEL:
1001 return DispatchResult(false);
1003 finishChange(bv, true);
1006 case LFUN_ENDBUFSEL:
1008 return DispatchResult(false);
1010 finishChange(bv, true);
1014 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1020 istringstream is(cmd.argument);
1023 lyxerr << "SETXY: Could not parse coordinates in '"
1024 << cmd.argument << std::endl;
1026 setCursorFromCoordinates(x, y);
1031 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1033 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1039 case LFUN_GETLAYOUT:
1040 cmd.message(tostr(cursorPar()->layout()));
1044 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1045 << cmd.argument << endl;
1047 // This is not the good solution to the empty argument
1048 // problem, but it will hopefully suffice for 1.2.0.
1049 // The correct solution would be to augument the
1050 // function list/array with information about what
1051 // functions needs arguments and their type.
1052 if (cmd.argument.empty()) {
1053 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1057 // Derive layout number from given argument (string)
1058 // and current buffer's textclass (number)
1059 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1060 bool hasLayout = tclass.hasLayout(cmd.argument);
1061 string layout = cmd.argument;
1063 // If the entry is obsolete, use the new one instead.
1065 string const & obs = tclass[layout]->obsoleted_by();
1071 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1076 bool change_layout = (current_layout != layout);
1078 if (!change_layout && selection.set() &&
1079 selection.start.par() != selection.end.par())
1081 ParagraphList::iterator spit = getPar(selection.start);
1082 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1083 while (spit != epit) {
1084 if (spit->layout()->name() != current_layout) {
1085 change_layout = true;
1092 if (change_layout) {
1093 current_layout = layout;
1095 bv->owner()->setLayout(layout);
1102 case LFUN_PASTESELECTION: {
1103 // this was originally a bv->text->clearSelection(), i.e
1104 // the outermost LyXText!
1106 string const clip = bv->getClipboard();
1107 if (!clip.empty()) {
1108 if (cmd.argument == "paragraph")
1109 insertStringAsParagraphs(clip);
1111 insertStringAsLines(clip);
1117 case LFUN_GOTOERROR:
1118 gotoInset(InsetOld::ERROR_CODE, false);
1122 gotoInset(InsetOld::NOTE_CODE, false);
1125 case LFUN_REFERENCE_GOTO: {
1126 vector<InsetOld::Code> tmp;
1127 tmp.push_back(InsetOld::LABEL_CODE);
1128 tmp.push_back(InsetOld::REF_CODE);
1129 gotoInset(tmp, true);
1134 replaceSelection(bv->getLyXText());
1135 ParagraphList::iterator pit = cursorPar();
1136 lyx::pos_type pos = cursor.pos();
1140 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1143 c = pit->getChar(pos - 1);
1145 LyXLayout_ptr const & style = pit->layout();
1147 BufferParams const & bufparams = bv->buffer()->params();
1148 if (style->pass_thru ||
1149 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1150 !bv->insertInset(new InsetQuotes(c, bufparams)))
1151 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1155 case LFUN_DATE_INSERT: {
1156 replaceSelection(bv->getLyXText());
1157 time_t now_time_t = time(NULL);
1158 struct tm * now_tm = localtime(&now_time_t);
1159 setlocale(LC_TIME, "");
1161 if (!cmd.argument.empty())
1164 arg = lyxrc.date_insert_format;
1166 int const datetmp_len =
1167 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1169 for (int i = 0; i < datetmp_len; i++)
1170 insertChar(datetmp[i]);
1172 selection.cursor = cursor;
1173 moveCursor(bv, false);
1177 case LFUN_MOUSE_TRIPLE:
1180 if (cmd.button() == mouse_button::button1) {
1181 selection_possible = true;
1183 selection.cursor = cursor;
1186 bv->haveSelection(selection.set());
1190 case LFUN_MOUSE_DOUBLE:
1193 if (cmd.button() == mouse_button::button1) {
1194 selection_possible = true;
1195 selectWord(lyx::WHOLE_WORD_STRICT);
1196 bv->haveSelection(selection.set());
1200 case LFUN_MOUSE_MOTION: {
1201 // Only use motion with button 1
1202 //if (ev.button() != mouse_button::button1)
1207 // The test for not selection possible is needed, that
1208 // only motion events are used, where the bottom press
1209 // event was on the drawing area too
1210 if (!selection_possible) {
1211 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1212 "Dispatch: no selection possible\n";
1215 RowList::iterator cursorrow = cursorRow();
1217 setCursorFromCoordinates(cmd.x, cmd.y);
1219 // This is to allow jumping over large insets
1220 // FIXME: shouldn't be top-text-specific
1221 if (cursorrow == cursorRow() && !in_inset_) {
1222 if (cmd.y - bv->top_y() >= bv->workHeight())
1224 else if (cmd.y - bv->top_y() < 0)
1231 // Single-click on work area
1232 case LFUN_MOUSE_PRESS: {
1236 // ok ok, this is a hack (for xforms)
1237 // We shouldn't go further down as we really should only do the
1238 // scrolling and be done with this. Otherwise we may open some
1239 // dialogs (Jug 20020424).
1240 if (cmd.button() == mouse_button::button4) {
1241 bv->scroll(-lyxrc.wheel_jump);
1244 if (cmd.button() == mouse_button::button5) {
1245 bv->scroll(lyxrc.wheel_jump);
1249 // Middle button press pastes if we have a selection
1250 // We do this here as if the selection was inside an inset
1251 // it could get cleared on the unlocking of the inset so
1252 // we have to check this first
1253 bool paste_internally = false;
1254 if (cmd.button() == mouse_button::button2 && selection.set()) {
1255 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1256 paste_internally = true;
1259 selection_possible = true;
1261 // Clear the selection
1264 // Right click on a footnote flag opens float menu
1265 if (cmd.button() == mouse_button::button3) {
1266 selection_possible = false;
1270 setCursorFromCoordinates(cmd.x, cmd.y);
1271 selection.cursor = cursor;
1273 bv->x_target(cursor.x() + xo_);
1275 if (bv->fitCursor())
1276 selection_possible = false;
1278 // Insert primary selection with middle mouse
1279 // if there is a local selection in the current buffer,
1281 if (cmd.button() == mouse_button::button2) {
1282 if (paste_internally)
1283 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1285 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1286 selection_possible = false;
1291 case LFUN_MOUSE_RELEASE: {
1295 // do nothing if we used the mouse wheel
1296 if (cmd.button() == mouse_button::button4
1297 || cmd.button() == mouse_button::button5)
1298 return DispatchResult(true, false);
1300 selection_possible = false;
1302 if (cmd.button() == mouse_button::button2)
1306 if (cmd.button() == mouse_button::button1)
1307 bv->haveSelection(selection.set());
1310 bv->owner()->view_state_changed();
1311 bv->owner()->updateMenubar();
1312 bv->owner()->updateToolbar();
1316 case LFUN_SELFINSERT: {
1317 if (cmd.argument.empty())
1320 // Automatically delete the currently selected
1321 // text and replace it with what is being
1322 // typed in now. Depends on lyxrc settings
1323 // "auto_region_delete", which defaults to
1326 if (lyxrc.auto_region_delete) {
1327 if (selection.set())
1328 cutSelection(false, false);
1329 bv->haveSelection(false);
1333 LyXFont const old_font = real_current_font;
1335 string::const_iterator cit = cmd.argument.begin();
1336 string::const_iterator end = cmd.argument.end();
1337 for (; cit != end; ++cit)
1338 bv->owner()->getIntl().getTransManager().
1339 TranslateAndInsert(*cit, this);
1341 selection.cursor = cursor;
1342 moveCursor(bv, false);
1344 // real_current_font.number can change so we need to
1345 // update the minibuffer
1346 if (old_font != real_current_font)
1347 bv->owner()->view_state_changed();
1348 bv->updateScrollbar();
1353 InsetCommandParams p("url");
1354 string const data = InsetCommandMailer::params2string("url", p);
1355 bv->owner()->getDialogs().show("url", data, 0);
1359 case LFUN_HTMLURL: {
1360 InsetCommandParams p("htmlurl");
1361 string const data = InsetCommandMailer::params2string("url", p);
1362 bv->owner()->getDialogs().show("url", data, 0);
1366 case LFUN_INSERT_LABEL: {
1367 InsetCommandParams p("label");
1368 string const data = InsetCommandMailer::params2string("label", p);
1369 bv->owner()->getDialogs().show("label", data, 0);
1375 case LFUN_INSET_LIST:
1376 case LFUN_INSET_THEOREM:
1377 case LFUN_INSET_CAPTION:
1379 case LFUN_INSERT_NOTE:
1380 case LFUN_INSERT_CHARSTYLE:
1381 case LFUN_INSERT_BOX:
1382 case LFUN_INSERT_BRANCH:
1383 case LFUN_INSERT_BIBITEM:
1384 case LFUN_INSET_ERT:
1385 case LFUN_INSET_FLOAT:
1386 case LFUN_INSET_FOOTNOTE:
1387 case LFUN_INSET_MARGINAL:
1388 case LFUN_INSET_MINIPAGE:
1389 case LFUN_INSET_OPTARG:
1390 case LFUN_INSET_WIDE_FLOAT:
1391 case LFUN_INSET_WRAP:
1392 case LFUN_TABULAR_INSERT:
1393 case LFUN_ENVIRONMENT_INSERT:
1394 // Open the inset, and move the current selection
1396 doInsertInset(*this, cmd, true, true);
1399 case LFUN_INDEX_INSERT:
1400 // Just open the inset
1401 doInsertInset(*this, cmd, true, false);
1404 case LFUN_INDEX_PRINT:
1405 case LFUN_TOC_INSERT:
1407 case LFUN_INSERT_LINE:
1408 case LFUN_INSERT_PAGEBREAK:
1410 doInsertInset(*this, cmd, false, false);
1413 case LFUN_DEPTH_MIN:
1414 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1418 case LFUN_DEPTH_PLUS:
1419 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1423 case LFUN_MATH_DELIM:
1424 case LFUN_MATH_DISPLAY:
1425 case LFUN_INSERT_MATH:
1426 case LFUN_MATH_LIMITS:
1427 case LFUN_MATH_MACRO:
1428 case LFUN_MATH_MUTATE:
1429 case LFUN_MATH_SPACE:
1430 case LFUN_MATH_IMPORT_SELECTION:
1431 case LFUN_MATH_MODE:
1432 case LFUN_MATH_NONUMBER:
1433 case LFUN_MATH_NUMBER:
1434 case LFUN_MATH_EXTERN:
1435 case LFUN_MATH_SIZE:
1441 bv->owner()->view_state_changed();
1446 bv->owner()->view_state_changed();
1451 bv->owner()->view_state_changed();
1456 bv->owner()->view_state_changed();
1461 bv->owner()->view_state_changed();
1466 bv->owner()->view_state_changed();
1470 styleReset(bv, this);
1471 bv->owner()->view_state_changed();
1474 case LFUN_UNDERLINE:
1475 underline(bv, this);
1476 bv->owner()->view_state_changed();
1479 case LFUN_FONT_SIZE:
1480 fontSize(bv, cmd.argument, this);
1481 bv->owner()->view_state_changed();
1485 lang(bv, cmd.argument, this);
1487 bv->owner()->view_state_changed();
1490 case LFUN_FREEFONT_APPLY:
1491 apply_freefont(bv, this);
1494 case LFUN_FREEFONT_UPDATE:
1495 update_and_apply_freefont(bv, this, cmd.argument);
1498 case LFUN_FINISHED_LEFT:
1499 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1504 case LFUN_FINISHED_RIGHT:
1505 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1510 case LFUN_FINISHED_UP:
1511 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1515 case LFUN_FINISHED_DOWN:
1516 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1521 return DispatchResult(false);
1524 return DispatchResult(true, true);