3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "bufferparams.h"
22 #include "BufferView.h"
25 #include "dispatchresult.h"
27 #include "funcrequest.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
51 #include "mathed/math_hullinset.h"
55 using bv_funcs::replaceSelection;
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
65 using std::istringstream;
69 extern string current_layout;
71 // the selection possible is needed, that only motion events are
72 // used, where the button press event was on the drawing area too
73 bool selection_possible = false;
79 LyXFont freefont(LyXFont::ALL_IGNORE);
80 bool toggleall = false;
83 void toggleAndShow(BufferView * bv, LyXText * text,
84 LyXFont const & font, bool toggleall = true)
89 text->toggleFree(font, toggleall);
92 if (font.language() != ignore_language ||
93 font.number() != LyXFont::IGNORE) {
94 CursorSlice & cur = text->cursor();
95 Paragraph & par = *text->cursorPar();
96 text->bidi.computeTables(par, *bv->buffer(),
97 *par.getRow(cur.pos()));
99 text->bidi.isBoundary(*bv->buffer(), par,
101 text->real_current_font))
102 text->setCursor(cur.par(), cur.pos(),
103 false, !cur.boundary());
108 /// Apply the contents of freefont at the current cursor location.
109 void apply_freefont(BufferView * bv, LyXText * text)
111 toggleAndShow(bv, text, freefont, toggleall);
112 bv->owner()->view_state_changed();
113 bv->owner()->message(_("Character set"));
117 /** Set the freefont using the contents of \param data dispatched from
118 * the frontends and apply it at the current cursor location.
120 void update_and_apply_freefont(BufferView * bv, LyXText * text,
125 if (bv_funcs::string2font(data, font, toggle)) {
128 apply_freefont(bv, text);
133 void emph(BufferView * bv, LyXText * text)
135 LyXFont font(LyXFont::ALL_IGNORE);
136 font.setEmph(LyXFont::TOGGLE);
137 toggleAndShow(bv, text, font);
141 void bold(BufferView * bv, LyXText * text)
143 LyXFont font(LyXFont::ALL_IGNORE);
144 font.setSeries(LyXFont::BOLD_SERIES);
145 toggleAndShow(bv, text, font);
149 void noun(BufferView * bv, LyXText * text)
151 LyXFont font(LyXFont::ALL_IGNORE);
152 font.setNoun(LyXFont::TOGGLE);
153 toggleAndShow(bv, text, font);
157 void lang(BufferView * bv, string const & l, LyXText * text)
159 Language const * lang = languages.getLanguage(l);
163 LyXFont font(LyXFont::ALL_IGNORE);
164 font.setLanguage(lang);
165 toggleAndShow(bv, text, font);
169 void code(BufferView * bv, LyXText * text)
171 LyXFont font(LyXFont::ALL_IGNORE);
172 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
173 toggleAndShow(bv, text, font);
177 void sans(BufferView * bv, LyXText * text)
179 LyXFont font(LyXFont::ALL_IGNORE);
180 font.setFamily(LyXFont::SANS_FAMILY);
181 toggleAndShow(bv, text, font);
185 void roman(BufferView * bv, LyXText * text)
187 LyXFont font(LyXFont::ALL_IGNORE);
188 font.setFamily(LyXFont::ROMAN_FAMILY);
189 toggleAndShow(bv, text, font);
193 void styleReset(BufferView * bv, LyXText * text)
195 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
196 toggleAndShow(bv, text, font);
200 void underline(BufferView * bv, LyXText * text)
202 LyXFont font(LyXFont::ALL_IGNORE);
203 font.setUnderbar(LyXFont::TOGGLE);
204 toggleAndShow(bv, text, font);
208 void fontSize(BufferView * bv, string const & size, LyXText * text)
210 LyXFont font(LyXFont::ALL_IGNORE);
211 font.setLyXSize(size);
212 toggleAndShow(bv, text, font);
216 void moveCursor(LCursor & cur, bool selecting)
218 if (selecting || cur.mark())
220 if (!cur.selection())
221 cur.bv().haveSelection(false);
222 cur.bv().switchKeyMap();
226 void finishChange(BufferView * bv, bool selecting = false)
229 moveCursor(bv->cursor(), selecting);
230 bv->owner()->view_state_changed();
238 string const freefont2string()
241 if (font2string(freefont, toggleall, data))
249 //takes absolute x,y coordinates
250 InsetBase * 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 InsetBase * inset = iit->inset;
267 lyxerr << "examining inset " << inset
268 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
269 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
270 << " yo: " << inset->yo() - inset->ascent() << "..."
271 << inset->yo() + inset->descent() << endl;
273 if (inset->covers(x, y)) {
274 lyxerr << "Hit inset: " << inset << endl;
279 lyxerr << "No inset hit. " << endl;
284 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
285 string const & contents)
287 ParagraphList::iterator end = paragraphs().end();
288 ParagraphList::iterator pit = cursorPar();
289 pos_type pos = cursor().pos();
293 if (pos + 1 < pit->size()) {
300 } while (pit != end &&
301 !(pit->isInset(pos) &&
302 (inset = pit->getInset(pos)) != 0 &&
303 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
305 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
311 setCursor(parOffset(pit), pos, false);
316 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
318 LCursor & cur = bv()->cursor();
319 cur.clearSelection();
323 && cur.pos() < cur.lastpos()
324 && cur.paragraph().isInset(cur.pos())) {
325 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
326 if (find(codes.begin(), codes.end(), inset->lyxCode())
328 contents = static_cast<InsetCommand const *>(inset)->getContents();
331 if (!gotoNextInset(codes, contents)) {
332 if (cur.pos() || cur.par() != 0) {
333 CursorSlice tmp = cursor();
336 if (!gotoNextInset(codes, contents)) {
338 cur.bv().owner()->message(_("No more insets"));
341 cur.bv().owner()->message(_("No more insets"));
349 void LyXText::gotoInset(InsetOld_code code, bool same_content)
351 gotoInset(vector<InsetOld_code>(1, code), same_content);
355 void LyXText::cursorPrevious()
357 LCursor & cur = bv()->cursor();
358 pos_type cpos = cur.pos();
359 lyx::paroffset_type cpar = cur.par();
361 int x = bv()->cursor().x_target();
362 int y = bv()->top_y();
363 setCursorFromCoordinates(x, y);
365 if (cpar == cur.par() && cpos == cur.pos()) {
366 // we have a row which is taller than the workarea. The
367 // simplest solution is to move to the previous row instead.
371 bv()->updateScrollbar();
376 void LyXText::cursorNext()
378 LCursor & cur = bv()->cursor();
379 pos_type cpos = cur.pos();
380 lyx::paroffset_type cpar = cur.par();
382 int x = cur.x_target();
383 int y = bv()->top_y() + bv()->workHeight();
384 setCursorFromCoordinates(x, y);
386 if (cpar == cur.par() && cpos == cur.pos()) {
387 // we have a row which is taller than the workarea. The
388 // simplest solution is to move to the next row instead.
392 bv()->updateScrollbar();
399 void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind)
402 replaceSelection(text);
403 text->insertInset(new InsetSpecialChar(kind));
408 void doInsertInset(LyXText * text, BufferView * bv, FuncRequest const & cmd,
409 bool edit, bool pastesel)
411 InsetBase * inset = createInset(bv, cmd);
416 if (bv->cursor().selection()) {
417 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
420 text->insertInset(inset);
422 inset->edit(bv->cursor(), true);
423 if (gotsel && pastesel)
424 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
430 void LyXText::number()
432 LyXFont font(LyXFont::ALL_IGNORE);
433 font.setNumber(LyXFont::TOGGLE);
434 toggleAndShow(bv(), this, font);
438 bool LyXText::rtl() const
440 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
444 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
446 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
447 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
449 BufferView * bv = &cur.bv();
451 switch (cmd.action) {
453 case LFUN_APPENDIX: {
454 ParagraphList::iterator pit = cursorPar();
455 bool start = !pit->params().startOfAppendix();
457 // ensure that we have only one start_of_appendix in this document
458 ParagraphList::iterator tmp = paragraphs().begin();
459 ParagraphList::iterator end = paragraphs().end();
461 for (; tmp != end; ++tmp) {
462 if (tmp->params().startOfAppendix()) {
463 recUndo(parOffset(tmp));
464 tmp->params().startOfAppendix(false);
470 recUndo(parOffset(pit));
471 pit->params().startOfAppendix(start);
473 // we can set the refreshing parameters now
475 redoParagraph(cursorPar());
480 case LFUN_DELETE_WORD_FORWARD:
481 cur.clearSelection();
486 case LFUN_DELETE_WORD_BACKWARD:
487 cur.clearSelection();
488 deleteWordBackward();
492 case LFUN_DELETE_LINE_FORWARD:
493 cur.clearSelection();
500 cur.clearSelection();
504 cursorRightOneWord();
510 cur.clearSelection();
512 cursorRightOneWord();
518 case LFUN_BEGINNINGBUF:
520 cur.clearSelection();
527 cur.clearSelection();
533 if (!cur.selection())
539 finishChange(bv, true);
543 if (!cur.selection())
549 finishChange(bv, true);
553 if (!cur.selection())
556 finishChange(bv, true);
560 if (!cur.selection())
563 finishChange(bv, true);
566 case LFUN_UP_PARAGRAPHSEL:
567 if (!cur.selection())
570 finishChange(bv, true);
573 case LFUN_DOWN_PARAGRAPHSEL:
574 if (!cur.selection())
576 cursorDownParagraph();
577 finishChange(bv, true);
581 if (!cur.selection())
584 finishChange(bv, true);
588 if (!cur.selection())
591 finishChange(bv, true);
595 if (!cur.selection())
598 finishChange(bv, true);
602 if (!cur.selection())
605 finishChange(bv, true);
608 case LFUN_WORDRIGHTSEL:
609 if (!cur.selection())
614 cursorRightOneWord();
615 finishChange(bv, true);
618 case LFUN_WORDLEFTSEL:
619 if (!cur.selection())
622 cursorRightOneWord();
625 finishChange(bv, true);
629 selectWord(lyx::WHOLE_WORD);
630 finishChange(bv, true);
650 case LFUN_UP_PARAGRAPH:
652 cur.clearSelection();
657 case LFUN_DOWN_PARAGRAPH:
659 cur.clearSelection();
660 cursorDownParagraph();
661 finishChange(bv, false);
666 cur.clearSelection();
667 finishChange(bv, false);
668 if (cur.par() == 0 && cursorRow() == firstRow())
669 return DispatchResult(false, FINISHED_UP);
675 cur.clearSelection();
676 finishChange(bv, false);
677 if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
678 return DispatchResult(false, FINISHED_DOWN);
684 cur.clearSelection();
686 finishChange(bv, false);
691 cur.clearSelection();
693 finishChange(bv, false);
696 case LFUN_BREAKLINE: {
697 lyx::pos_type body = cursorPar()->beginOfBody();
699 // Not allowed by LaTeX (labels or empty par)
700 if (cursor().pos() <= body)
703 replaceSelection(bv->getLyXText());
704 insertInset(new InsetNewline);
705 moveCursor(cur, false);
710 if (!cur.selection()) {
713 // It is possible to make it a lot faster still
714 // just comment out the line below...
716 cutSelection(true, false);
718 moveCursor(cur, false);
719 bv->owner()->view_state_changed();
722 case LFUN_DELETE_SKIP:
723 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
724 if (!cur.selection()) {
725 if (cursor().pos() == cursorPar()->size()) {
735 cutSelection(true, false);
742 if (!cur.selection()) {
743 if (bv->owner()->getIntl().getTransManager().backspace()) {
746 // It is possible to make it a lot faster still
747 // just comment out the line below...
750 cutSelection(true, false);
752 bv->owner()->view_state_changed();
757 case LFUN_BACKSPACE_SKIP:
758 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
759 if (!cur.selection()) {
761 //CursorSlice cur = cursor();
765 cutSelection(true, false);
770 case LFUN_BREAKPARAGRAPH:
771 replaceSelection(bv->getLyXText());
772 breakParagraph(bv->buffer()->paragraphs(), 0);
776 bv->owner()->view_state_changed();
779 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
780 replaceSelection(bv->getLyXText());
781 breakParagraph(bv->buffer()->paragraphs(), 1);
785 bv->owner()->view_state_changed();
788 case LFUN_BREAKPARAGRAPH_SKIP: {
789 // When at the beginning of a paragraph, remove
790 // indentation and add a "defskip" at the top.
791 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
793 // CursorSlice cur = cursor();
794 replaceSelection(bv->getLyXText());
795 if (cur.pos() == 0) {
796 ParagraphParameters & params = getPar(cur.current())->params();
800 params.labelWidthString(), 1);
802 breakParagraph(bv->buffer()->paragraphs(), 0);
807 bv->owner()->view_state_changed();
811 case LFUN_PARAGRAPH_SPACING: {
812 ParagraphList::iterator pit = cursorPar();
813 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
814 float cur_value = 1.0;
815 if (cur_spacing == Spacing::Other)
816 cur_value = pit->params().spacing().getValue();
818 istringstream is(cmd.argument);
821 Spacing::Space new_spacing = cur_spacing;
822 float new_value = cur_value;
824 lyxerr << "Missing argument to `paragraph-spacing'"
826 } else if (tmp == "single") {
827 new_spacing = Spacing::Single;
828 } else if (tmp == "onehalf") {
829 new_spacing = Spacing::Onehalf;
830 } else if (tmp == "double") {
831 new_spacing = Spacing::Double;
832 } else if (tmp == "other") {
833 new_spacing = Spacing::Other;
836 lyxerr << "new_value = " << tmpval << endl;
839 } else if (tmp == "default") {
840 new_spacing = Spacing::Default;
842 lyxerr << _("Unknown spacing argument: ")
843 << cmd.argument << endl;
845 if (cur_spacing != new_spacing || cur_value != new_value) {
846 pit->params().spacing(Spacing(new_spacing, new_value));
853 case LFUN_INSET_APPLY: {
854 string const name = cmd.getArg(0);
855 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
857 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
859 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
863 case LFUN_INSET_INSERT: {
864 InsetBase * inset = createInset(bv, cmd);
870 case LFUN_INSET_SETTINGS:
871 if (cur.inset() && cur.inset()->asUpdatableInset())
872 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
875 case LFUN_INSET_TOGGLE:
876 cur.clearSelection();
878 return DispatchResult(false);
883 case LFUN_SPACE_INSERT:
884 if (cursorPar()->layout()->free_spacing)
887 doInsertInset(this, bv, cmd, false, false);
888 moveCursor(cur, false);
891 case LFUN_HYPHENATION:
892 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
895 case LFUN_LIGATURE_BREAK:
896 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
900 specialChar(this, bv, InsetSpecialChar::LDOTS);
903 case LFUN_END_OF_SENTENCE:
904 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
907 case LFUN_MENU_SEPARATOR:
908 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
911 case LFUN_UPCASE_WORD:
912 changeCase(LyXText::text_uppercase);
916 case LFUN_LOWCASE_WORD:
917 changeCase(LyXText::text_lowercase);
921 case LFUN_CAPITALIZE_WORD:
922 changeCase(LyXText::text_capitalization);
926 case LFUN_TRANSPOSE_CHARS:
927 recUndo(cursor().par());
933 cur.message(_("Paste"));
934 replaceSelection(bv->getLyXText());
935 #warning FIXME Check if the arg is in the domain of available selections.
936 if (isStrUnsignedInt(cmd.argument))
937 pasteSelection(strToUnsignedInt(cmd.argument));
940 cur.clearSelection(); // bug 393
947 cutSelection(true, true);
948 cur.message(_("Cut"));
954 cur.message(_("Copy"));
957 case LFUN_BEGINNINGBUFSEL:
959 return DispatchResult(false);
960 if (!cur.selection())
963 finishChange(bv, true);
968 return DispatchResult(false);
969 if (!cur.selection())
972 finishChange(bv, true);
976 cur.message(tostr(cursorX(cur.current())) + ' '
977 + tostr(cursorY(cur.current())));
983 istringstream is(cmd.argument);
986 lyxerr << "SETXY: Could not parse coordinates in '"
987 << cmd.argument << std::endl;
989 setCursorFromCoordinates(x, y);
994 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
996 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1002 case LFUN_GETLAYOUT:
1003 cur.message(cursorPar()->layout()->name());
1007 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1008 << cmd.argument << endl;
1010 // This is not the good solution to the empty argument
1011 // problem, but it will hopefully suffice for 1.2.0.
1012 // The correct solution would be to augument the
1013 // function list/array with information about what
1014 // functions needs arguments and their type.
1015 if (cmd.argument.empty()) {
1016 cur.errorMessage(_("LyX function 'layout' needs an argument."));
1020 // Derive layout number from given argument (string)
1021 // and current buffer's textclass (number)
1022 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1023 bool hasLayout = tclass.hasLayout(cmd.argument);
1024 string layout = cmd.argument;
1026 // If the entry is obsolete, use the new one instead.
1028 string const & obs = tclass[layout]->obsoleted_by();
1034 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
1039 bool change_layout = (current_layout != layout);
1041 if (!change_layout && cur.selection() &&
1042 cur.selBegin().par() != cur.selEnd().par())
1044 ParagraphList::iterator spit = getPar(cur.selBegin());
1045 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
1046 while (spit != epit) {
1047 if (spit->layout()->name() != current_layout) {
1048 change_layout = true;
1055 if (change_layout) {
1056 current_layout = layout;
1058 bv->owner()->setLayout(layout);
1065 case LFUN_PASTESELECTION: {
1066 cur.clearSelection();
1067 string const clip = bv->getClipboard();
1068 if (!clip.empty()) {
1069 if (cmd.argument == "paragraph")
1070 insertStringAsParagraphs(clip);
1072 insertStringAsLines(clip);
1078 case LFUN_GOTOERROR:
1079 gotoInset(InsetBase::ERROR_CODE, false);
1083 gotoInset(InsetBase::NOTE_CODE, false);
1086 case LFUN_REFERENCE_GOTO: {
1087 vector<InsetOld_code> tmp;
1088 tmp.push_back(InsetBase::LABEL_CODE);
1089 tmp.push_back(InsetBase::REF_CODE);
1090 gotoInset(tmp, true);
1095 replaceSelection(bv->getLyXText());
1096 ParagraphList::iterator pit = cursorPar();
1097 lyx::pos_type pos = cursor().pos();
1101 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1104 c = pit->getChar(pos - 1);
1106 LyXLayout_ptr const & style = pit->layout();
1108 BufferParams const & bufparams = bv->buffer()->params();
1109 if (style->pass_thru ||
1110 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew")
1111 insertInset(new InsetQuotes(c, bufparams));
1113 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1117 case LFUN_DATE_INSERT: {
1118 replaceSelection(bv->getLyXText());
1119 time_t now_time_t = time(NULL);
1120 struct tm * now_tm = localtime(&now_time_t);
1121 setlocale(LC_TIME, "");
1123 if (!cmd.argument.empty())
1126 arg = lyxrc.date_insert_format;
1128 int const datetmp_len =
1129 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1131 for (int i = 0; i < datetmp_len; i++)
1132 insertChar(datetmp[i]);
1135 moveCursor(cur, false);
1139 case LFUN_MOUSE_TRIPLE:
1140 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1141 selection_possible = true;
1146 bv->haveSelection(cur.selection());
1150 case LFUN_MOUSE_DOUBLE:
1151 if (bv->buffer() && cmd.button() == mouse_button::button1) {
1152 selection_possible = true;
1153 selectWord(lyx::WHOLE_WORD_STRICT);
1154 bv->haveSelection(cur.selection());
1158 case LFUN_MOUSE_MOTION: {
1160 // Only use motion with button 1
1161 //if (ev.button() != mouse_button::button1)
1163 // don't set anchor_
1164 bv->cursor().cursor_ = cur.cursor_;
1168 // The test for not selection possible is needed, that
1169 // only motion events are used, where the bottom press
1170 // event was on the drawing area too
1171 if (!selection_possible) {
1172 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1173 "Dispatch: no selection possible\n";
1176 RowList::iterator cursorrow = cursorRow();
1178 setCursorFromCoordinates(cmd.x, cmd.y);
1180 // This is to allow jumping over large insets
1181 // FIXME: shouldn't be top-text-specific
1182 if (cursorrow == cursorRow() && !in_inset_) {
1183 if (cmd.y - bv->top_y() >= bv->workHeight())
1185 else if (cmd.y - bv->top_y() < 0)
1193 // Single-click on work area
1194 case LFUN_MOUSE_PRESS: {
1198 // ok ok, this is a hack (for xforms)
1199 // We shouldn't go further down as we really should only do the
1200 // scrolling and be done with this. Otherwise we may open some
1201 // dialogs (Jug 20020424).
1202 if (cmd.button() == mouse_button::button4) {
1203 bv->scroll(-lyxrc.wheel_jump);
1206 if (cmd.button() == mouse_button::button5) {
1207 bv->scroll(lyxrc.wheel_jump);
1211 // Middle button press pastes if we have a selection
1212 // We do this here as if the selection was inside an inset
1213 // it could get cleared on the unlocking of the inset so
1214 // we have to check this first
1215 bool paste_internally = false;
1216 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1217 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1218 paste_internally = true;
1221 selection_possible = true;
1223 // Clear the selection
1224 cur.clearSelection();
1226 // Right click on a footnote flag opens float menu
1227 if (cmd.button() == mouse_button::button3) {
1228 selection_possible = false;
1232 setCursorFromCoordinates(cur.current(), cmd.x - xo_,
1236 cur.x_target() = cursorX(cur.current());
1238 // set cursor and anchor to this position
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(cur.selection());
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 (cur.selection())
1294 cutSelection(false, false);
1295 bv->haveSelection(false);
1298 cur.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(cur, 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(this, bv, cmd, true, true);
1364 case LFUN_INDEX_INSERT:
1365 // Just open the inset
1366 doInsertInset(this, bv, 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(this, bv, 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:
1401 mathDispatch(cur, cmd);
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 << "handle LFUN_FINISHED_LEFT" << endl;
1465 cur.pop(cur.currentDepth());
1466 cur.bv().cursor() = cur;
1471 case LFUN_FINISHED_RIGHT:
1472 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1473 cur.pop(cur.currentDepth());
1474 cur.bv().cursor() = cur;
1479 case LFUN_FINISHED_UP:
1480 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1481 cur.pop(cur.currentDepth());
1482 cur.bv().cursor() = cur;
1486 case LFUN_FINISHED_DOWN:
1487 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1488 cur.pop(cur.currentDepth());
1489 cur.bv().cursor() = cur;
1494 return DispatchResult(false);
1497 return DispatchResult(true, true);