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 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 CursorSlice tmp = cursor();
343 if (!gotoNextInset(codes, contents)) {
345 bv()->owner()->message(_("No more insets"));
348 bv()->owner()->message(_("No more insets"));
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);
424 BufferView * bv = cmd.view();
427 if (lt.selection.set()) {
428 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
431 if (bv->insertInset(inset)) {
433 inset->edit(bv, true);
434 if (gotsel && pastesel)
435 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());
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())
551 finishChange(bv, true);
555 if (!selection.set())
561 finishChange(bv, true);
565 if (!selection.set())
568 finishChange(bv, true);
572 if (!selection.set())
575 finishChange(bv, true);
578 case LFUN_UP_PARAGRAPHSEL:
579 if (!selection.set())
582 finishChange(bv, true);
585 case LFUN_DOWN_PARAGRAPHSEL:
586 if (!selection.set())
588 cursorDownParagraph();
589 finishChange(bv, true);
593 if (!selection.set())
596 finishChange(bv, true);
600 if (!selection.set())
603 finishChange(bv, true);
607 if (!selection.set())
610 finishChange(bv, true);
614 if (!selection.set())
617 finishChange(bv, true);
620 case LFUN_WORDRIGHTSEL:
621 if (!selection.set())
626 cursorRightOneWord();
627 finishChange(bv, true);
630 case LFUN_WORDLEFTSEL:
631 if (!selection.set())
634 cursorRightOneWord();
637 finishChange(bv, true);
641 selectWord(lyx::WHOLE_WORD);
642 finishChange(bv, true);
662 case LFUN_UP_PARAGRAPH:
663 if (!selection.mark())
669 case LFUN_DOWN_PARAGRAPH:
670 if (!selection.mark())
672 cursorDownParagraph();
673 finishChange(bv, false);
677 if (!selection.mark())
679 finishChange(bv, false);
680 if (cursorPar() == firstPar() && cursorRow() == firstRow())
681 return DispatchResult(false, FINISHED_UP);
686 if (!selection.mark())
688 finishChange(bv, false);
689 if (cursorPar() == lastPar() && cursorRow() == lastRow())
690 return DispatchResult(false, FINISHED_DOWN);
695 if (!selection.mark())
698 finishChange(bv, false);
702 if (!selection.mark())
705 finishChange(bv, false);
708 case LFUN_BREAKLINE: {
709 lyx::pos_type body = cursorPar()->beginOfBody();
711 // Not allowed by LaTeX (labels or empty par)
712 if (cursor().pos() <= body)
715 replaceSelection(bv->getLyXText());
716 insertInset(new InsetNewline);
717 moveCursor(bv, false);
722 if (!selection.set()) {
725 // It is possible to make it a lot faster still
726 // just comment out the line below...
728 cutSelection(true, false);
730 moveCursor(bv, false);
731 bv->owner()->view_state_changed();
734 case LFUN_DELETE_SKIP:
735 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
736 if (!selection.set()) {
737 if (cursor().pos() == cursorPar()->size()) {
747 cutSelection(true, false);
754 if (!selection.set()) {
755 if (bv->owner()->getIntl().getTransManager().backspace()) {
758 // It is possible to make it a lot faster still
759 // just comment out the line below...
762 cutSelection(true, false);
764 bv->owner()->view_state_changed();
769 case LFUN_BACKSPACE_SKIP:
770 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
771 if (!selection.set()) {
772 CursorSlice cur = cursor();
776 cutSelection(true, false);
781 case LFUN_BREAKPARAGRAPH:
782 replaceSelection(bv->getLyXText());
783 breakParagraph(bv->buffer()->paragraphs(), 0);
787 bv->owner()->view_state_changed();
790 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
791 replaceSelection(bv->getLyXText());
792 breakParagraph(bv->buffer()->paragraphs(), 1);
796 bv->owner()->view_state_changed();
799 case LFUN_BREAKPARAGRAPH_SKIP: {
800 // When at the beginning of a paragraph, remove
801 // indentation and add a "defskip" at the top.
802 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
803 CursorSlice cur = cursor();
804 replaceSelection(bv->getLyXText());
805 if (cur.pos() == 0) {
806 ParagraphParameters & params = getPar(cur)->params();
810 params.labelWidthString(), 1);
812 breakParagraph(bv->buffer()->paragraphs(), 0);
817 bv->owner()->view_state_changed();
821 case LFUN_PARAGRAPH_SPACING: {
822 ParagraphList::iterator pit = cursorPar();
823 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
824 float cur_value = 1.0;
825 if (cur_spacing == Spacing::Other)
826 cur_value = pit->params().spacing().getValue();
828 istringstream is(cmd.argument);
831 Spacing::Space new_spacing = cur_spacing;
832 float new_value = cur_value;
834 lyxerr << "Missing argument to `paragraph-spacing'"
836 } else if (tmp == "single") {
837 new_spacing = Spacing::Single;
838 } else if (tmp == "onehalf") {
839 new_spacing = Spacing::Onehalf;
840 } else if (tmp == "double") {
841 new_spacing = Spacing::Double;
842 } else if (tmp == "other") {
843 new_spacing = Spacing::Other;
846 lyxerr << "new_value = " << tmpval << endl;
849 } else if (tmp == "default") {
850 new_spacing = Spacing::Default;
852 lyxerr << _("Unknown spacing argument: ")
853 << cmd.argument << endl;
855 if (cur_spacing != new_spacing || cur_value != new_value) {
856 pit->params().spacing(Spacing(new_spacing, new_value));
863 case LFUN_INSET_APPLY: {
864 string const name = cmd.getArg(0);
865 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
867 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
870 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
876 case LFUN_INSET_INSERT: {
877 InsetOld * inset = createInset(cmd);
878 if (inset && !bv->insertInset(inset))
883 case LFUN_INSET_SETTINGS:
884 bv->fullCursor().innerInset()->showInsetDialog(bv);
887 case LFUN_INSET_TOGGLE:
890 return DispatchResult(false);
895 case LFUN_SPACE_INSERT:
896 if (cursorPar()->layout()->free_spacing)
899 doInsertInset(*this, cmd, false, false);
900 moveCursor(bv, false);
903 case LFUN_HYPHENATION:
904 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
907 case LFUN_LIGATURE_BREAK:
908 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
912 specialChar(this, bv, InsetSpecialChar::LDOTS);
915 case LFUN_END_OF_SENTENCE:
916 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
919 case LFUN_MENU_SEPARATOR:
920 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
927 cmd.message(N_("Mark off"));
932 selection.mark(true);
935 cmd.message(N_("Mark on"));
940 if (selection.mark()) {
941 cmd.message(N_("Mark removed"));
943 selection.mark(true);
944 cmd.message(N_("Mark set"));
950 case LFUN_UPCASE_WORD:
951 changeCase(LyXText::text_uppercase);
955 case LFUN_LOWCASE_WORD:
956 changeCase(LyXText::text_lowercase);
960 case LFUN_CAPITALIZE_WORD:
961 changeCase(LyXText::text_capitalization);
965 case LFUN_TRANSPOSE_CHARS:
966 recUndo(cursor().par());
972 cmd.message(_("Paste"));
973 replaceSelection(bv->getLyXText());
974 #warning FIXME Check if the arg is in the domain of available selections.
975 if (isStrUnsignedInt(cmd.argument))
976 pasteSelection(strToUnsignedInt(cmd.argument));
979 clearSelection(); // bug 393
986 cutSelection(true, true);
987 cmd.message(_("Cut"));
993 cmd.message(_("Copy"));
996 case LFUN_BEGINNINGBUFSEL:
998 return DispatchResult(false);
999 if (!selection.set())
1002 finishChange(bv, true);
1005 case LFUN_ENDBUFSEL:
1007 return DispatchResult(false);
1008 if (!selection.set())
1011 finishChange(bv, true);
1015 cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
1021 istringstream is(cmd.argument);
1024 lyxerr << "SETXY: Could not parse coordinates in '"
1025 << cmd.argument << std::endl;
1027 setCursorFromCoordinates(x, y);
1032 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1034 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1040 case LFUN_GETLAYOUT:
1041 cmd.message(cursorPar()->layout()->name());
1045 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1046 << cmd.argument << endl;
1048 // This is not the good solution to the empty argument
1049 // problem, but it will hopefully suffice for 1.2.0.
1050 // The correct solution would be to augument the
1051 // function list/array with information about what
1052 // functions needs arguments and their type.
1053 if (cmd.argument.empty()) {
1054 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1058 // Derive layout number from given argument (string)
1059 // and current buffer's textclass (number)
1060 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1061 bool hasLayout = tclass.hasLayout(cmd.argument);
1062 string layout = cmd.argument;
1064 // If the entry is obsolete, use the new one instead.
1066 string const & obs = tclass[layout]->obsoleted_by();
1072 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1077 bool change_layout = (current_layout != layout);
1079 if (!change_layout && selection.set() &&
1080 selStart().par() != selEnd().par())
1082 ParagraphList::iterator spit = getPar(selStart());
1083 ParagraphList::iterator epit = boost::next(getPar(selEnd()));
1084 while (spit != epit) {
1085 if (spit->layout()->name() != current_layout) {
1086 change_layout = true;
1093 if (change_layout) {
1094 current_layout = layout;
1096 bv->owner()->setLayout(layout);
1103 case LFUN_PASTESELECTION: {
1104 // this was originally a bv->text->clearSelection(), i.e
1105 // the outermost LyXText!
1107 string const clip = bv->getClipboard();
1108 if (!clip.empty()) {
1109 if (cmd.argument == "paragraph")
1110 insertStringAsParagraphs(clip);
1112 insertStringAsLines(clip);
1118 case LFUN_GOTOERROR:
1119 gotoInset(InsetOld::ERROR_CODE, false);
1123 gotoInset(InsetOld::NOTE_CODE, false);
1126 case LFUN_REFERENCE_GOTO: {
1127 vector<InsetOld::Code> tmp;
1128 tmp.push_back(InsetOld::LABEL_CODE);
1129 tmp.push_back(InsetOld::REF_CODE);
1130 gotoInset(tmp, true);
1135 replaceSelection(bv->getLyXText());
1136 ParagraphList::iterator pit = cursorPar();
1137 lyx::pos_type pos = cursor().pos();
1141 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1144 c = pit->getChar(pos - 1);
1146 LyXLayout_ptr const & style = pit->layout();
1148 BufferParams const & bufparams = bv->buffer()->params();
1149 if (style->pass_thru ||
1150 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1151 !bv->insertInset(new InsetQuotes(c, bufparams)))
1152 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1156 case LFUN_DATE_INSERT: {
1157 replaceSelection(bv->getLyXText());
1158 time_t now_time_t = time(NULL);
1159 struct tm * now_tm = localtime(&now_time_t);
1160 setlocale(LC_TIME, "");
1162 if (!cmd.argument.empty())
1165 arg = lyxrc.date_insert_format;
1167 int const datetmp_len =
1168 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1170 for (int i = 0; i < datetmp_len; i++)
1171 insertChar(datetmp[i]);
1174 moveCursor(bv, false);
1178 case LFUN_MOUSE_TRIPLE:
1181 if (cmd.button() == mouse_button::button1) {
1182 selection_possible = true;
1187 bv->haveSelection(selection.set());
1191 case LFUN_MOUSE_DOUBLE:
1194 if (cmd.button() == mouse_button::button1) {
1195 selection_possible = true;
1196 selectWord(lyx::WHOLE_WORD_STRICT);
1197 bv->haveSelection(selection.set());
1201 case LFUN_MOUSE_MOTION: {
1202 // Only use motion with button 1
1203 //if (ev.button() != mouse_button::button1)
1208 // The test for not selection possible is needed, that
1209 // only motion events are used, where the bottom press
1210 // event was on the drawing area too
1211 if (!selection_possible) {
1212 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1213 "Dispatch: no selection possible\n";
1216 RowList::iterator cursorrow = cursorRow();
1218 setCursorFromCoordinates(cmd.x, cmd.y);
1220 // This is to allow jumping over large insets
1221 // FIXME: shouldn't be top-text-specific
1222 if (cursorrow == cursorRow() && !in_inset_) {
1223 if (cmd.y - bv->top_y() >= bv->workHeight())
1225 else if (cmd.y - bv->top_y() < 0)
1232 // Single-click on work area
1233 case LFUN_MOUSE_PRESS: {
1237 // ok ok, this is a hack (for xforms)
1238 // We shouldn't go further down as we really should only do the
1239 // scrolling and be done with this. Otherwise we may open some
1240 // dialogs (Jug 20020424).
1241 if (cmd.button() == mouse_button::button4) {
1242 bv->scroll(-lyxrc.wheel_jump);
1245 if (cmd.button() == mouse_button::button5) {
1246 bv->scroll(lyxrc.wheel_jump);
1250 // Middle button press pastes if we have a selection
1251 // We do this here as if the selection was inside an inset
1252 // it could get cleared on the unlocking of the inset so
1253 // we have to check this first
1254 bool paste_internally = false;
1255 if (cmd.button() == mouse_button::button2 && selection.set()) {
1256 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1257 paste_internally = true;
1260 selection_possible = true;
1262 // Clear the selection
1265 // Right click on a footnote flag opens float menu
1266 if (cmd.button() == mouse_button::button3) {
1267 selection_possible = false;
1271 setCursorFromCoordinates(cmd.x, cmd.y);
1274 bv->x_target(cursorX() + xo_);
1276 if (bv->fitCursor())
1277 selection_possible = false;
1279 // Insert primary selection with middle mouse
1280 // if there is a local selection in the current buffer,
1282 if (cmd.button() == mouse_button::button2) {
1283 if (paste_internally)
1284 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1286 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1287 selection_possible = false;
1292 case LFUN_MOUSE_RELEASE: {
1296 // do nothing if we used the mouse wheel
1297 if (cmd.button() == mouse_button::button4
1298 || cmd.button() == mouse_button::button5)
1299 return DispatchResult(true, false);
1301 selection_possible = false;
1303 if (cmd.button() == mouse_button::button2)
1307 if (cmd.button() == mouse_button::button1)
1308 bv->haveSelection(selection.set());
1311 bv->owner()->view_state_changed();
1312 bv->owner()->updateMenubar();
1313 bv->owner()->updateToolbar();
1317 case LFUN_SELFINSERT: {
1318 if (cmd.argument.empty())
1321 // Automatically delete the currently selected
1322 // text and replace it with what is being
1323 // typed in now. Depends on lyxrc settings
1324 // "auto_region_delete", which defaults to
1327 if (lyxrc.auto_region_delete) {
1328 if (selection.set())
1329 cutSelection(false, false);
1330 bv->haveSelection(false);
1334 LyXFont const old_font = real_current_font;
1336 string::const_iterator cit = cmd.argument.begin();
1337 string::const_iterator end = cmd.argument.end();
1338 for (; cit != end; ++cit)
1339 bv->owner()->getIntl().getTransManager().
1340 TranslateAndInsert(*cit, this);
1343 moveCursor(bv, false);
1345 // real_current_font.number can change so we need to
1346 // update the minibuffer
1347 if (old_font != real_current_font)
1348 bv->owner()->view_state_changed();
1349 bv->updateScrollbar();
1354 InsetCommandParams p("url");
1355 string const data = InsetCommandMailer::params2string("url", p);
1356 bv->owner()->getDialogs().show("url", data, 0);
1360 case LFUN_HTMLURL: {
1361 InsetCommandParams p("htmlurl");
1362 string const data = InsetCommandMailer::params2string("url", p);
1363 bv->owner()->getDialogs().show("url", data, 0);
1367 case LFUN_INSERT_LABEL: {
1368 InsetCommandParams p("label");
1369 string const data = InsetCommandMailer::params2string("label", p);
1370 bv->owner()->getDialogs().show("label", data, 0);
1376 case LFUN_INSET_LIST:
1377 case LFUN_INSET_THEOREM:
1378 case LFUN_INSET_CAPTION:
1380 case LFUN_INSERT_NOTE:
1381 case LFUN_INSERT_CHARSTYLE:
1382 case LFUN_INSERT_BOX:
1383 case LFUN_INSERT_BRANCH:
1384 case LFUN_INSERT_BIBITEM:
1385 case LFUN_INSET_ERT:
1386 case LFUN_INSET_FLOAT:
1387 case LFUN_INSET_FOOTNOTE:
1388 case LFUN_INSET_MARGINAL:
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);