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"
34 #include "paragraph.h"
35 #include "paragraph_funcs.h"
36 #include "ParagraphParameters.h"
40 #include "frontends/Dialogs.h"
41 #include "frontends/LyXView.h"
43 #include "insets/insetcommand.h"
44 #include "insets/insetnewline.h"
45 #include "insets/insetspecialchar.h"
46 #include "insets/insettext.h"
48 #include "support/lstrings.h"
49 #include "support/lyxlib.h"
50 #include "support/tostr.h"
51 #include "support/std_sstream.h"
53 #include "mathed/math_hullinset.h"
54 #include "mathed/formulamacro.h"
59 using bv_funcs::replaceSelection;
63 using lyx::support::isStrUnsignedInt;
64 using lyx::support::strToUnsignedInt;
65 using lyx::support::atoi;
66 using lyx::support::token;
71 using std::istringstream;
75 extern string current_layout;
77 // the selection possible is needed, that only motion events are
78 // used, where the button press event was on the drawing area too
79 bool selection_possible = false;
85 LyXFont freefont(LyXFont::ALL_IGNORE);
86 bool toggleall = false;
89 void toggleAndShow(BufferView * bv, LyXText * text,
90 LyXFont const & font, bool toggleall = true)
95 text->toggleFree(font, toggleall);
98 if (font.language() != ignore_language ||
99 font.number() != LyXFont::IGNORE) {
100 CursorSlice & cur = text->cursor();
101 Paragraph & par = *text->cursorPar();
102 text->bidi.computeTables(par, *bv->buffer(),
103 *par.getRow(cur.pos()));
104 if (cur.boundary() !=
105 text->bidi.isBoundary(*bv->buffer(), par,
107 text->real_current_font))
108 text->setCursor(cur.par(), cur.pos(),
109 false, !cur.boundary());
114 void moveCursor(LCursor & cur, bool selecting)
116 if (selecting || cur.mark())
118 if (!cur.selection())
119 cur.bv().haveSelection(false);
120 cur.bv().switchKeyMap();
124 void finishChange(LCursor & cur, bool selecting = false)
127 moveCursor(cur, selecting);
128 cur.bv().owner()->view_state_changed();
132 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 lyxerr << "selection is: '" << sel << "'" << endl;
138 cur.insert(new MathHullInset);
139 cur.dispatch(FuncRequest(LFUN_RIGHT));
140 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
141 // don't do that also for LFUN_MATH_MODE unless you want end up with
142 // always changing to mathrm when opening an inlined inset
143 // -- I really hate "LyXfunc overloading"...
145 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
146 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
148 // create a macro if we see "\\newcommand" somewhere, and an ordinary
150 cur.bv().getLyXText()->cutSelection(true, true);
151 if (sel.find("\\newcommand") == string::npos &&
152 sel.find("\\def") == string::npos)
154 cur.insert(new MathHullInset);
155 cur.dispatch(FuncRequest(LFUN_RIGHT));
156 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
157 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
159 cur.insert(new InsetFormulaMacro(sel));
160 cur.dispatch(FuncRequest(LFUN_RIGHT));
163 cur.message(N_("Math editor mode"));
172 string const freefont2string()
175 if (font2string(freefont, toggleall, data))
183 //takes absolute x,y coordinates
184 InsetBase * LyXText::checkInsetHit(int x, int y)
186 ParagraphList::iterator pit;
187 ParagraphList::iterator end;
189 getParsInRange(paragraphs(),
191 bv()->top_y() - yo_ + bv()->workHeight(),
194 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
195 for ( ; pit != end; ++pit) {
196 InsetList::iterator iit = pit->insetlist.begin();
197 InsetList::iterator iend = pit->insetlist.end();
198 for ( ; iit != iend; ++iit) {
199 InsetBase * inset = iit->inset;
201 lyxerr << "examining inset " << inset
202 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
203 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
204 << " yo: " << inset->yo() - inset->ascent() << "..."
205 << inset->yo() + inset->descent() << endl;
207 if (inset->covers(x, y)) {
208 lyxerr << "Hit inset: " << inset << endl;
213 lyxerr << "No inset hit. " << endl;
218 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
219 string const & contents)
221 ParagraphList::iterator end = paragraphs().end();
222 ParagraphList::iterator pit = cursorPar();
223 pos_type pos = cursor().pos();
227 if (pos + 1 < pit->size()) {
234 } while (pit != end &&
235 !(pit->isInset(pos) &&
236 (inset = pit->getInset(pos)) != 0 &&
237 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
239 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
245 setCursor(parOffset(pit), pos, false);
250 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
252 LCursor & cur = bv()->cursor();
253 cur.clearSelection();
257 && cur.pos() < cur.lastpos()
258 && cur.paragraph().isInset(cur.pos())) {
259 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
260 if (find(codes.begin(), codes.end(), inset->lyxCode())
262 contents = static_cast<InsetCommand const *>(inset)->getContents();
265 if (!gotoNextInset(codes, contents)) {
266 if (cur.pos() || cur.par() != 0) {
267 CursorSlice tmp = cursor();
270 if (!gotoNextInset(codes, contents)) {
272 cur.bv().owner()->message(_("No more insets"));
275 cur.bv().owner()->message(_("No more insets"));
283 void LyXText::gotoInset(InsetOld_code code, bool same_content)
285 gotoInset(vector<InsetOld_code>(1, code), same_content);
289 void LyXText::cursorPrevious()
291 LCursor & cur = bv()->cursor();
292 pos_type cpos = cur.pos();
293 lyx::paroffset_type cpar = cur.par();
295 int x = bv()->cursor().x_target();
296 int y = bv()->top_y();
297 setCursorFromCoordinates(x, y);
299 if (cpar == cur.par() && cpos == cur.pos()) {
300 // we have a row which is taller than the workarea. The
301 // simplest solution is to move to the previous row instead.
305 bv()->updateScrollbar();
310 void LyXText::cursorNext()
312 LCursor & cur = bv()->cursor();
313 pos_type cpos = cur.pos();
314 lyx::paroffset_type cpar = cur.par();
316 int x = cur.x_target();
317 int y = bv()->top_y() + bv()->workHeight();
318 setCursorFromCoordinates(x, y);
320 if (cpar == cur.par() && cpos == cur.pos()) {
321 // we have a row which is taller than the workarea. The
322 // simplest solution is to move to the next row instead.
326 bv()->updateScrollbar();
333 void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind)
336 replaceSelection(text);
337 text->insertInset(new InsetSpecialChar(kind));
342 void doInsertInset(LyXText * text, BufferView * bv, FuncRequest const & cmd,
343 bool edit, bool pastesel)
345 InsetBase * inset = createInset(bv, cmd);
350 if (bv->cursor().selection()) {
351 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
354 text->insertInset(inset);
356 inset->edit(bv->cursor(), true);
357 if (gotsel && pastesel)
358 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
364 void LyXText::number()
366 LyXFont font(LyXFont::ALL_IGNORE);
367 font.setNumber(LyXFont::TOGGLE);
368 toggleAndShow(bv(), this, font);
372 bool LyXText::rtl() const
374 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
378 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
380 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
381 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
383 BufferView * bv = &cur.bv();
385 switch (cmd.action) {
387 case LFUN_APPENDIX: {
388 ParagraphList::iterator pit = cursorPar();
389 bool start = !pit->params().startOfAppendix();
391 // ensure that we have only one start_of_appendix in this document
392 ParagraphList::iterator tmp = paragraphs().begin();
393 ParagraphList::iterator end = paragraphs().end();
395 for (; tmp != end; ++tmp) {
396 if (tmp->params().startOfAppendix()) {
397 recUndo(parOffset(tmp));
398 tmp->params().startOfAppendix(false);
404 recUndo(parOffset(pit));
405 pit->params().startOfAppendix(start);
407 // we can set the refreshing parameters now
409 redoParagraph(cursorPar());
414 case LFUN_DELETE_WORD_FORWARD:
415 cur.clearSelection();
420 case LFUN_DELETE_WORD_BACKWARD:
421 cur.clearSelection();
422 deleteWordBackward();
426 case LFUN_DELETE_LINE_FORWARD:
427 cur.clearSelection();
434 cur.clearSelection();
438 cursorRightOneWord();
444 cur.clearSelection();
446 cursorRightOneWord();
452 case LFUN_BEGINNINGBUF:
454 cur.clearSelection();
461 cur.clearSelection();
467 if (!cur.selection())
473 finishChange(cur, true);
477 if (!cur.selection())
483 finishChange(cur, true);
487 if (!cur.selection())
490 finishChange(cur, true);
494 if (!cur.selection())
497 finishChange(cur, true);
500 case LFUN_UP_PARAGRAPHSEL:
501 if (!cur.selection())
504 finishChange(cur, true);
507 case LFUN_DOWN_PARAGRAPHSEL:
508 if (!cur.selection())
510 cursorDownParagraph();
511 finishChange(cur, true);
515 if (!cur.selection())
518 finishChange(cur, true);
522 if (!cur.selection())
525 finishChange(cur, true);
529 if (!cur.selection())
532 finishChange(cur, true);
536 if (!cur.selection())
539 finishChange(cur, true);
542 case LFUN_WORDRIGHTSEL:
543 if (!cur.selection())
548 cursorRightOneWord();
549 finishChange(cur, true);
552 case LFUN_WORDLEFTSEL:
553 if (!cur.selection())
556 cursorRightOneWord();
559 finishChange(cur, true);
563 selectWord(lyx::WHOLE_WORD);
564 finishChange(cur, true);
584 case LFUN_UP_PARAGRAPH:
586 cur.clearSelection();
591 case LFUN_DOWN_PARAGRAPH:
593 cur.clearSelection();
594 cursorDownParagraph();
595 finishChange(cur, false);
600 cur.clearSelection();
601 finishChange(cur, false);
602 if (cur.par() == 0 && cursorRow() == firstRow())
603 return DispatchResult(false, FINISHED_UP);
609 cur.clearSelection();
610 finishChange(cur, false);
611 if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
612 return DispatchResult(false, FINISHED_DOWN);
618 cur.clearSelection();
620 finishChange(cur, false);
625 cur.clearSelection();
627 finishChange(cur, false);
630 case LFUN_BREAKLINE: {
631 // Not allowed by LaTeX (labels or empty par)
632 if (cursor().pos() > cursorPar()->beginOfBody()) {
633 replaceSelection(this);
634 insertInset(new InsetNewline);
635 moveCursor(cur, false);
641 if (!cur.selection()) {
644 // It is possible to make it a lot faster still
645 // just comment out the line below...
647 cutSelection(true, false);
649 moveCursor(cur, false);
650 bv->owner()->view_state_changed();
653 case LFUN_DELETE_SKIP:
654 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
655 if (!cur.selection()) {
656 if (cursor().pos() == cursorPar()->size()) {
666 cutSelection(true, false);
673 if (!cur.selection()) {
674 if (bv->owner()->getIntl().getTransManager().backspace()) {
677 // It is possible to make it a lot faster still
678 // just comment out the line below...
681 cutSelection(true, false);
683 bv->owner()->view_state_changed();
688 case LFUN_BACKSPACE_SKIP:
689 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
690 if (!cur.selection()) {
692 //CursorSlice cur = cursor();
696 cutSelection(true, false);
701 case LFUN_BREAKPARAGRAPH:
702 replaceSelection(this);
703 breakParagraph(bv->buffer()->paragraphs(), 0);
707 bv->owner()->view_state_changed();
710 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
711 replaceSelection(this);
712 breakParagraph(bv->buffer()->paragraphs(), 1);
716 bv->owner()->view_state_changed();
719 case LFUN_BREAKPARAGRAPH_SKIP: {
720 // When at the beginning of a paragraph, remove
721 // indentation and add a "defskip" at the top.
722 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
724 // CursorSlice cur = cursor();
725 replaceSelection(this);
726 if (cur.pos() == 0) {
727 ParagraphParameters & params = getPar(cur.current())->params();
731 params.labelWidthString(), 1);
733 breakParagraph(bv->buffer()->paragraphs(), 0);
738 bv->owner()->view_state_changed();
742 case LFUN_PARAGRAPH_SPACING: {
743 ParagraphList::iterator pit = cursorPar();
744 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
745 float cur_value = 1.0;
746 if (cur_spacing == Spacing::Other)
747 cur_value = pit->params().spacing().getValue();
749 istringstream is(cmd.argument);
752 Spacing::Space new_spacing = cur_spacing;
753 float new_value = cur_value;
755 lyxerr << "Missing argument to `paragraph-spacing'"
757 } else if (tmp == "single") {
758 new_spacing = Spacing::Single;
759 } else if (tmp == "onehalf") {
760 new_spacing = Spacing::Onehalf;
761 } else if (tmp == "double") {
762 new_spacing = Spacing::Double;
763 } else if (tmp == "other") {
764 new_spacing = Spacing::Other;
767 lyxerr << "new_value = " << tmpval << endl;
770 } else if (tmp == "default") {
771 new_spacing = Spacing::Default;
773 lyxerr << _("Unknown spacing argument: ")
774 << cmd.argument << endl;
776 if (cur_spacing != new_spacing || cur_value != new_value) {
777 pit->params().spacing(Spacing(new_spacing, new_value));
784 case LFUN_INSET_APPLY: {
785 string const name = cmd.getArg(0);
786 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
788 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
790 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
794 case LFUN_INSET_INSERT: {
795 InsetBase * inset = createInset(bv, cmd);
801 case LFUN_INSET_SETTINGS:
802 if (cur.inset() && cur.inset()->asUpdatableInset())
803 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
806 case LFUN_INSET_TOGGLE:
807 cur.clearSelection();
809 return DispatchResult(false);
814 case LFUN_SPACE_INSERT:
815 if (cursorPar()->layout()->free_spacing)
818 doInsertInset(this, bv, cmd, false, false);
819 moveCursor(cur, false);
822 case LFUN_HYPHENATION:
823 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
826 case LFUN_LIGATURE_BREAK:
827 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
831 specialChar(this, bv, InsetSpecialChar::LDOTS);
834 case LFUN_END_OF_SENTENCE:
835 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
838 case LFUN_MENU_SEPARATOR:
839 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
842 case LFUN_UPCASE_WORD:
843 changeCase(LyXText::text_uppercase);
847 case LFUN_LOWCASE_WORD:
848 changeCase(LyXText::text_lowercase);
852 case LFUN_CAPITALIZE_WORD:
853 changeCase(LyXText::text_capitalization);
857 case LFUN_TRANSPOSE_CHARS:
858 recUndo(cursor().par());
864 cur.message(_("Paste"));
865 replaceSelection(this);
866 #warning FIXME Check if the arg is in the domain of available selections.
867 if (isStrUnsignedInt(cmd.argument))
868 pasteSelection(strToUnsignedInt(cmd.argument));
871 cur.clearSelection(); // bug 393
878 cutSelection(true, true);
879 cur.message(_("Cut"));
885 cur.message(_("Copy"));
888 case LFUN_BEGINNINGBUFSEL:
890 return DispatchResult(false);
891 if (!cur.selection())
894 finishChange(cur, true);
899 return DispatchResult(false);
900 if (!cur.selection())
903 finishChange(cur, true);
907 cur.message(tostr(cursorX(cur.current())) + ' '
908 + tostr(cursorY(cur.current())));
914 istringstream is(cmd.argument);
917 lyxerr << "SETXY: Could not parse coordinates in '"
918 << cmd.argument << std::endl;
920 setCursorFromCoordinates(x, y);
925 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
927 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
934 cur.message(cursorPar()->layout()->name());
938 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
939 << cmd.argument << endl;
941 // This is not the good solution to the empty argument
942 // problem, but it will hopefully suffice for 1.2.0.
943 // The correct solution would be to augument the
944 // function list/array with information about what
945 // functions needs arguments and their type.
946 if (cmd.argument.empty()) {
947 cur.errorMessage(_("LyX function 'layout' needs an argument."));
951 // Derive layout number from given argument (string)
952 // and current buffer's textclass (number)
953 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
954 bool hasLayout = tclass.hasLayout(cmd.argument);
955 string layout = cmd.argument;
957 // If the entry is obsolete, use the new one instead.
959 string const & obs = tclass[layout]->obsoleted_by();
965 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
970 bool change_layout = (current_layout != layout);
972 if (!change_layout && cur.selection() &&
973 cur.selBegin().par() != cur.selEnd().par())
975 ParagraphList::iterator spit = getPar(cur.selBegin());
976 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
977 while (spit != epit) {
978 if (spit->layout()->name() != current_layout) {
979 change_layout = true;
987 current_layout = layout;
989 bv->owner()->setLayout(layout);
996 case LFUN_PASTESELECTION: {
997 cur.clearSelection();
998 string const clip = bv->getClipboard();
1000 if (cmd.argument == "paragraph")
1001 insertStringAsParagraphs(clip);
1003 insertStringAsLines(clip);
1009 case LFUN_GOTOERROR:
1010 gotoInset(InsetBase::ERROR_CODE, false);
1014 gotoInset(InsetBase::NOTE_CODE, false);
1017 case LFUN_REFERENCE_GOTO: {
1018 vector<InsetOld_code> tmp;
1019 tmp.push_back(InsetBase::LABEL_CODE);
1020 tmp.push_back(InsetBase::REF_CODE);
1021 gotoInset(tmp, true);
1026 replaceSelection(this);
1027 ParagraphList::iterator pit = cursorPar();
1028 lyx::pos_type pos = cursor().pos();
1032 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1035 c = pit->getChar(pos - 1);
1037 LyXLayout_ptr const & style = pit->layout();
1039 BufferParams const & bufparams = bv->buffer()->params();
1040 if (style->pass_thru ||
1041 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew")
1042 insertInset(new InsetQuotes(c, bufparams));
1044 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1048 case LFUN_DATE_INSERT: {
1049 replaceSelection(this);
1050 time_t now_time_t = time(NULL);
1051 struct tm * now_tm = localtime(&now_time_t);
1052 setlocale(LC_TIME, "");
1054 if (!cmd.argument.empty())
1057 arg = lyxrc.date_insert_format;
1059 int const datetmp_len =
1060 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1062 for (int i = 0; i < datetmp_len; i++)
1063 insertChar(datetmp[i]);
1066 moveCursor(cur, false);
1070 case LFUN_MOUSE_TRIPLE:
1071 if (cmd.button() == mouse_button::button1) {
1072 selection_possible = true;
1077 bv->haveSelection(cur.selection());
1081 case LFUN_MOUSE_DOUBLE:
1082 if (cmd.button() == mouse_button::button1) {
1083 selection_possible = true;
1084 selectWord(lyx::WHOLE_WORD_STRICT);
1085 bv->haveSelection(cur.selection());
1089 case LFUN_MOUSE_MOTION: {
1090 // Only use motion with button 1
1091 //if (ev.button() != mouse_button::button1)
1093 // The test for not selection possible is needed, that
1094 // only motion events are used, where the bottom press
1095 // event was on the drawing area too
1096 if (!selection_possible) {
1097 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1098 "Dispatch: no selection possible\n";
1101 RowList::iterator cursorrow = cursorRow();
1104 setCursorFromCoordinates(cmd.x, cmd.y);
1106 // This is to allow jumping over large insets
1107 // FIXME: shouldn't be top-text-specific
1108 if (cursorrow == cursorRow() && !in_inset_) {
1109 if (cmd.y - bv->top_y() >= bv->workHeight())
1111 else if (cmd.y - bv->top_y() < 0)
1115 // don't set anchor_
1116 bv->cursor().cursor_ = cur.cursor_;
1117 bv->cursor().setSelection();
1122 // Single-click on work area
1123 case LFUN_MOUSE_PRESS: {
1124 // ok ok, this is a hack (for xforms)
1125 // We shouldn't go further down as we really should only do the
1126 // scrolling and be done with this. Otherwise we may open some
1127 // dialogs (Jug 20020424).
1128 if (cmd.button() == mouse_button::button4) {
1129 bv->scroll(-lyxrc.wheel_jump);
1133 if (cmd.button() == mouse_button::button5) {
1134 bv->scroll(lyxrc.wheel_jump);
1138 // Right click on a footnote flag opens float menu
1139 if (cmd.button() == mouse_button::button3) {
1140 cur.clearSelection();
1141 selection_possible = false;
1145 // Middle button press pastes if we have a selection
1146 // We do this here as if the selection was inside an inset
1147 // it could get cleared on the unlocking of the inset so
1148 // we have to check this first
1149 bool paste_internally = false;
1150 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1151 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1152 paste_internally = true;
1155 selection_possible = true;
1157 // Clear the selection
1158 cur.clearSelection();
1160 setCursorFromCoordinates(cur.current(), cmd.x - xo_,
1164 cur.x_target() = cursorX(cur.current());
1166 // set cursor and anchor to this position
1169 if (bv->fitCursor())
1170 selection_possible = false;
1172 // Insert primary selection with middle mouse
1173 // if there is a local selection in the current buffer,
1175 if (cmd.button() == mouse_button::button2) {
1176 if (paste_internally)
1177 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1179 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1180 selection_possible = false;
1185 case LFUN_MOUSE_RELEASE: {
1186 // do nothing if we used the mouse wheel
1187 if (cmd.button() == mouse_button::button4
1188 || cmd.button() == mouse_button::button5)
1189 return DispatchResult(true, false);
1191 selection_possible = false;
1193 if (cmd.button() == mouse_button::button2)
1197 if (cmd.button() == mouse_button::button1)
1198 bv->haveSelection(cur.selection());
1201 bv->owner()->view_state_changed();
1202 bv->owner()->updateMenubar();
1203 bv->owner()->updateToolbar();
1207 case LFUN_SELFINSERT: {
1208 if (cmd.argument.empty())
1211 // Automatically delete the currently selected
1212 // text and replace it with what is being
1213 // typed in now. Depends on lyxrc settings
1214 // "auto_region_delete", which defaults to
1217 if (lyxrc.auto_region_delete) {
1218 if (cur.selection())
1219 cutSelection(false, false);
1220 bv->haveSelection(false);
1223 cur.clearSelection();
1224 LyXFont const old_font = real_current_font;
1226 string::const_iterator cit = cmd.argument.begin();
1227 string::const_iterator end = cmd.argument.end();
1228 for (; cit != end; ++cit)
1229 bv->owner()->getIntl().getTransManager().
1230 TranslateAndInsert(*cit, this);
1233 moveCursor(cur, false);
1235 // real_current_font.number can change so we need to
1236 // update the minibuffer
1237 if (old_font != real_current_font)
1238 bv->owner()->view_state_changed();
1239 bv->updateScrollbar();
1244 InsetCommandParams p("url");
1245 string const data = InsetCommandMailer::params2string("url", p);
1246 bv->owner()->getDialogs().show("url", data, 0);
1250 case LFUN_HTMLURL: {
1251 InsetCommandParams p("htmlurl");
1252 string const data = InsetCommandMailer::params2string("url", p);
1253 bv->owner()->getDialogs().show("url", data, 0);
1257 case LFUN_INSERT_LABEL: {
1258 InsetCommandParams p("label");
1259 string const data = InsetCommandMailer::params2string("label", p);
1260 bv->owner()->getDialogs().show("label", data, 0);
1266 case LFUN_INSET_LIST:
1267 case LFUN_INSET_THEOREM:
1268 case LFUN_INSET_CAPTION:
1270 case LFUN_INSERT_NOTE:
1271 case LFUN_INSERT_CHARSTYLE:
1272 case LFUN_INSERT_BOX:
1273 case LFUN_INSERT_BRANCH:
1274 case LFUN_INSERT_BIBITEM:
1275 case LFUN_INSET_ERT:
1276 case LFUN_INSET_FLOAT:
1277 case LFUN_INSET_FOOTNOTE:
1278 case LFUN_INSET_MARGINAL:
1279 case LFUN_INSET_OPTARG:
1280 case LFUN_INSET_WIDE_FLOAT:
1281 case LFUN_INSET_WRAP:
1282 case LFUN_TABULAR_INSERT:
1283 case LFUN_ENVIRONMENT_INSERT:
1284 // Open the inset, and move the current selection
1286 doInsertInset(this, bv, cmd, true, true);
1289 case LFUN_INDEX_INSERT:
1290 // Just open the inset
1291 doInsertInset(this, bv, cmd, true, false);
1294 case LFUN_INDEX_PRINT:
1295 case LFUN_TOC_INSERT:
1297 case LFUN_INSERT_LINE:
1298 case LFUN_INSERT_PAGEBREAK:
1300 doInsertInset(this, bv, cmd, false, false);
1303 case LFUN_DEPTH_MIN:
1304 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1308 case LFUN_DEPTH_PLUS:
1309 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1313 case LFUN_MATH_DISPLAY:
1314 mathDispatch(cur, cmd, true);
1317 case LFUN_MATH_IMPORT_SELECTION:
1318 case LFUN_MATH_MODE:
1319 mathDispatch(cur, cmd, false);
1322 case LFUN_MATH_MACRO:
1323 if (cmd.argument.empty())
1324 cur.errorMessage(N_("Missing argument"));
1326 string s = cmd.argument;
1327 string const s1 = token(s, ' ', 1);
1328 int const nargs = s1.empty() ? 0 : atoi(s1);
1329 string const s2 = token(s, ' ', 2);
1330 string const type = s2.empty() ? "newcommand" : s2;
1331 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1332 cur.nextInset()->edit(cur, true);
1336 case LFUN_INSERT_MATH:
1337 case LFUN_INSERT_MATRIX:
1338 case LFUN_MATH_DELIM: {
1339 cur.insert(new MathHullInset);
1340 cur.dispatch(FuncRequest(LFUN_RIGHT));
1341 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1347 LyXFont font(LyXFont::ALL_IGNORE);
1348 font.setEmph(LyXFont::TOGGLE);
1349 toggleAndShow(bv, this, font);
1350 bv->owner()->view_state_changed();
1355 LyXFont font(LyXFont::ALL_IGNORE);
1356 font.setSeries(LyXFont::BOLD_SERIES);
1357 toggleAndShow(bv, this, font);
1358 bv->owner()->view_state_changed();
1363 LyXFont font(LyXFont::ALL_IGNORE);
1364 font.setNoun(LyXFont::TOGGLE);
1365 toggleAndShow(bv, this, font);
1366 bv->owner()->view_state_changed();
1371 LyXFont font(LyXFont::ALL_IGNORE);
1372 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1373 toggleAndShow(bv, this, font);
1374 bv->owner()->view_state_changed();
1379 LyXFont font(LyXFont::ALL_IGNORE);
1380 font.setFamily(LyXFont::SANS_FAMILY);
1381 toggleAndShow(bv, this, font);
1382 bv->owner()->view_state_changed();
1387 LyXFont font(LyXFont::ALL_IGNORE);
1388 font.setFamily(LyXFont::ROMAN_FAMILY);
1389 toggleAndShow(bv, this, font);
1390 bv->owner()->view_state_changed();
1394 case LFUN_DEFAULT: {
1395 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1396 toggleAndShow(bv, this, font);
1397 bv->owner()->view_state_changed();
1401 case LFUN_UNDERLINE: {
1402 LyXFont font(LyXFont::ALL_IGNORE);
1403 font.setUnderbar(LyXFont::TOGGLE);
1404 toggleAndShow(bv, this, font);
1405 bv->owner()->view_state_changed();
1409 case LFUN_FONT_SIZE: {
1410 LyXFont font(LyXFont::ALL_IGNORE);
1411 font.setLyXSize(cmd.argument);
1412 toggleAndShow(bv, this, font);
1413 bv->owner()->view_state_changed();
1417 case LFUN_LANGUAGE: {
1418 Language const * lang = languages.getLanguage(cmd.argument);
1421 LyXFont font(LyXFont::ALL_IGNORE);
1422 font.setLanguage(lang);
1423 toggleAndShow(bv, this, font);
1425 bv->owner()->view_state_changed();
1429 case LFUN_FREEFONT_APPLY:
1430 toggleAndShow(bv, this, freefont, toggleall);
1431 bv->owner()->view_state_changed();
1432 bv->owner()->message(_("Character set"));
1435 // Set the freefont using the contents of \param data dispatched from
1436 // the frontends and apply it at the current cursor location.
1437 case LFUN_FREEFONT_UPDATE: {
1440 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1443 toggleAndShow(bv, this, freefont, toggleall);
1444 bv->owner()->view_state_changed();
1445 bv->owner()->message(_("Character set"));
1450 case LFUN_FINISHED_LEFT:
1451 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1452 cur.pop(cur.currentDepth());
1453 cur.bv().cursor() = cur;
1458 case LFUN_FINISHED_RIGHT:
1459 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1460 cur.pop(cur.currentDepth());
1461 cur.bv().cursor() = cur;
1466 case LFUN_FINISHED_UP:
1467 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1468 cur.pop(cur.currentDepth());
1469 cur.bv().cursor() = cur;
1473 case LFUN_FINISHED_DOWN:
1474 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1475 cur.pop(cur.currentDepth());
1476 cur.bv().cursor() = cur;
1480 case LFUN_LAYOUT_PARAGRAPH: {
1482 params2string(cur.paragraph(), data);
1483 data = "show\n" + data;
1484 bv->owner()->getDialogs().show("paragraph", data);
1488 case LFUN_PARAGRAPH_UPDATE: {
1489 if (!bv->owner()->getDialogs().visible("paragraph"))
1492 params2string(cur.paragraph(), data);
1494 // Will the paragraph accept changes from the dialog?
1495 InsetBase * const inset = cur.inset();
1497 !(inset && inset->forceDefaultParagraphs(inset));
1499 data = "update " + tostr(accept) + '\n' + data;
1500 bv->owner()->getDialogs().update("paragraph", data);
1505 case LFUN_CIRCUMFLEX:
1515 case LFUN_SPECIAL_CARON:
1518 case LFUN_HUNG_UMLAUT:
1521 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1522 if (!cmd.argument.empty())
1523 bv->owner()->getIntl().getTransManager()
1524 .TranslateAndInsert(cmd.argument[0], this);
1528 return DispatchResult(false);
1531 return DispatchResult(true, true);