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 "FloatList.h"
28 #include "funcrequest.h"
35 #include "paragraph.h"
36 #include "paragraph_funcs.h"
37 #include "ParagraphParameters.h"
41 #include "frontends/Dialogs.h"
42 #include "frontends/LyXView.h"
44 #include "insets/insetcommand.h"
45 #include "insets/insetfloatlist.h"
46 #include "insets/insetnewline.h"
47 #include "insets/insetspecialchar.h"
48 #include "insets/insettext.h"
50 #include "support/lstrings.h"
51 #include "support/lyxlib.h"
52 #include "support/tostr.h"
53 #include "support/std_sstream.h"
55 #include "mathed/math_hullinset.h"
56 #include "mathed/formulamacro.h"
61 using bv_funcs::replaceSelection;
65 using lyx::support::isStrUnsignedInt;
66 using lyx::support::strToUnsignedInt;
67 using lyx::support::atoi;
68 using lyx::support::token;
73 using std::istringstream;
77 extern string current_layout;
79 // the selection possible is needed, that only motion events are
80 // used, where the button press event was on the drawing area too
81 bool selection_possible = false;
87 LyXFont freefont(LyXFont::ALL_IGNORE);
88 bool toggleall = false;
91 void toggleAndShow(BufferView * bv, LyXText * text,
92 LyXFont const & font, bool toggleall = true)
97 text->toggleFree(font, toggleall);
100 if (font.language() != ignore_language ||
101 font.number() != LyXFont::IGNORE) {
102 CursorSlice & cur = text->cursor();
103 Paragraph & par = *text->cursorPar();
104 text->bidi.computeTables(par, *bv->buffer(),
105 *par.getRow(cur.pos()));
106 if (cur.boundary() !=
107 text->bidi.isBoundary(*bv->buffer(), par,
109 text->real_current_font))
110 text->setCursor(cur.par(), cur.pos(),
111 false, !cur.boundary());
116 void moveCursor(LCursor & cur, bool selecting)
118 if (selecting || cur.mark())
120 if (!cur.selection())
121 cur.bv().haveSelection(false);
122 cur.bv().switchKeyMap();
126 void finishChange(LCursor & cur, bool selecting = false)
129 moveCursor(cur, selecting);
130 cur.bv().owner()->view_state_changed();
134 void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
136 string sel = cur.selectionAsString(false);
137 lyxerr << "selection is: '" << sel << "'" << endl;
140 cur.insert(new MathHullInset);
141 cur.dispatch(FuncRequest(LFUN_RIGHT));
142 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
143 // don't do that also for LFUN_MATH_MODE unless you want end up with
144 // always changing to mathrm when opening an inlined inset
145 // -- I really hate "LyXfunc overloading"...
147 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
148 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
150 // create a macro if we see "\\newcommand" somewhere, and an ordinary
152 cur.bv().getLyXText()->cutSelection(true, true);
153 if (sel.find("\\newcommand") == string::npos &&
154 sel.find("\\def") == string::npos)
156 cur.insert(new MathHullInset);
157 cur.dispatch(FuncRequest(LFUN_RIGHT));
158 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
159 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
161 cur.insert(new InsetFormulaMacro(sel));
162 cur.dispatch(FuncRequest(LFUN_RIGHT));
165 cur.message(N_("Math editor mode"));
174 string const freefont2string()
177 if (font2string(freefont, toggleall, data))
185 //takes absolute x,y coordinates
186 InsetBase * LyXText::checkInsetHit(int x, int y)
188 ParagraphList::iterator pit;
189 ParagraphList::iterator end;
191 getParsInRange(paragraphs(),
193 bv()->top_y() - yo_ + bv()->workHeight(),
196 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
197 for ( ; pit != end; ++pit) {
198 InsetList::iterator iit = pit->insetlist.begin();
199 InsetList::iterator iend = pit->insetlist.end();
200 for ( ; iit != iend; ++iit) {
201 InsetBase * inset = iit->inset;
203 lyxerr << "examining inset " << inset
204 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
205 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
206 << " yo: " << inset->yo() - inset->ascent() << "..."
207 << inset->yo() + inset->descent() << endl;
209 if (inset->covers(x, y)) {
210 lyxerr << "Hit inset: " << inset << endl;
215 lyxerr << "No inset hit. " << endl;
220 bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
221 string const & contents)
223 ParagraphList::iterator end = paragraphs().end();
224 ParagraphList::iterator pit = cursorPar();
225 pos_type pos = cursor().pos();
229 if (pos + 1 < pit->size()) {
236 } while (pit != end &&
237 !(pit->isInset(pos) &&
238 (inset = pit->getInset(pos)) != 0 &&
239 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
241 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
247 setCursor(parOffset(pit), pos, false);
252 void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
254 LCursor & cur = bv()->cursor();
255 cur.clearSelection();
259 && cur.pos() < cur.lastpos()
260 && cur.paragraph().isInset(cur.pos())) {
261 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
262 if (find(codes.begin(), codes.end(), inset->lyxCode())
264 contents = static_cast<InsetCommand const *>(inset)->getContents();
267 if (!gotoNextInset(codes, contents)) {
268 if (cur.pos() || cur.par() != 0) {
269 CursorSlice tmp = cursor();
272 if (!gotoNextInset(codes, contents)) {
274 cur.bv().owner()->message(_("No more insets"));
277 cur.bv().owner()->message(_("No more insets"));
285 void LyXText::gotoInset(InsetOld_code code, bool same_content)
287 gotoInset(vector<InsetOld_code>(1, code), same_content);
291 void LyXText::cursorPrevious(LCursor & cur)
293 pos_type cpos = cur.pos();
294 lyx::paroffset_type cpar = cur.par();
296 int x = cur.x_target();
297 int y = bv()->top_y();
298 setCursorFromCoordinates(x, y);
300 if (cpar == cur.par() && cpos == cur.pos()) {
301 // we have a row which is taller than the workarea. The
302 // simplest solution is to move to the previous row instead.
306 bv()->updateScrollbar();
311 void LyXText::cursorNext(LCursor & cur)
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.
323 cursorDown(cur, true);
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();
416 deleteWordForward(cur);
420 case LFUN_DELETE_WORD_BACKWARD:
421 cur.clearSelection();
422 deleteWordBackward(cur);
426 case LFUN_DELETE_LINE_FORWARD:
427 cur.clearSelection();
428 deleteLineForward(cur);
434 cur.clearSelection();
436 cursorLeftOneWord(cur);
438 cursorRightOneWord(cur);
444 cur.clearSelection();
446 cursorRightOneWord(cur);
448 cursorLeftOneWord(cur);
452 case LFUN_BEGINNINGBUF:
454 cur.clearSelection();
461 cur.clearSelection();
467 if (!cur.selection())
470 cursorLeft(cur, true);
472 cursorRight(cur, true);
473 finishChange(cur, true);
477 if (!cur.selection())
480 cursorRight(cur, true);
482 cursorLeft(cur, true);
483 finishChange(cur, true);
487 if (!cur.selection())
490 finishChange(cur, true);
494 if (!cur.selection())
496 cursorDown(cur, true);
497 finishChange(cur, true);
500 case LFUN_UP_PARAGRAPHSEL:
501 if (!cur.selection())
503 cursorUpParagraph(cur);
504 finishChange(cur, true);
507 case LFUN_DOWN_PARAGRAPHSEL:
508 if (!cur.selection())
510 cursorDownParagraph(cur);
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())
546 cursorLeftOneWord(cur);
548 cursorRightOneWord(cur);
549 finishChange(cur, true);
552 case LFUN_WORDLEFTSEL:
553 if (!cur.selection())
556 cursorRightOneWord(cur);
558 cursorLeftOneWord(cur);
559 finishChange(cur, true);
563 selectWord(lyx::WHOLE_WORD);
564 finishChange(cur, true);
570 return moveRight(cur);
574 return moveLeft(cur);
582 return moveDown(cur);
584 case LFUN_UP_PARAGRAPH:
586 cur.clearSelection();
587 cursorUpParagraph(cur);
591 case LFUN_DOWN_PARAGRAPH:
593 cur.clearSelection();
594 cursorDownParagraph(cur);
595 finishChange(cur, false);
600 cur.clearSelection();
601 finishChange(cur, false);
602 if (cur.par() == 0 && cur.textRow().pos() == 0)
603 return DispatchResult(false, FINISHED_UP);
609 cur.clearSelection();
610 finishChange(cur, false);
611 if (cur.par() == cur.lastpar()
612 && cur.textRow().endpos() == cur.lastpos())
613 return DispatchResult(false, FINISHED_DOWN);
619 cur.clearSelection();
621 finishChange(cur, false);
626 cur.clearSelection();
628 finishChange(cur, false);
631 case LFUN_BREAKLINE: {
632 // Not allowed by LaTeX (labels or empty par)
633 if (cursor().pos() > cursorPar()->beginOfBody()) {
634 replaceSelection(this);
635 insertInset(new InsetNewline);
636 moveCursor(cur, false);
642 if (!cur.selection()) {
645 // It is possible to make it a lot faster still
646 // just comment out the line below...
648 cutSelection(true, false);
650 moveCursor(cur, false);
651 bv->owner()->view_state_changed();
654 case LFUN_DELETE_SKIP:
655 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
656 if (!cur.selection()) {
657 if (cur.pos() == cur.lastpos()) {
658 cursorRight(cur, true);
659 cursorLeft(cur, true);
664 cutSelection(true, false);
671 if (!cur.selection()) {
672 if (bv->owner()->getIntl().getTransManager().backspace()) {
675 // It is possible to make it a lot faster still
676 // just comment out the line below...
679 cutSelection(true, false);
681 bv->owner()->view_state_changed();
686 case LFUN_BACKSPACE_SKIP:
687 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
688 if (!cur.selection()) {
690 //CursorSlice cur = cursor();
694 cutSelection(true, false);
699 case LFUN_BREAKPARAGRAPH:
700 replaceSelection(this);
701 breakParagraph(cur, 0);
705 bv->owner()->view_state_changed();
708 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
709 replaceSelection(this);
710 breakParagraph(cur, 1);
714 bv->owner()->view_state_changed();
717 case LFUN_BREAKPARAGRAPH_SKIP: {
718 // When at the beginning of a paragraph, remove
719 // indentation and add a "defskip" at the top.
720 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
722 replaceSelection(this);
723 if (cur.pos() == 0) {
724 ParagraphParameters & params = cur.paragraph().params();
728 params.labelWidthString(), 1);
730 breakParagraph(cur, 0);
735 bv->owner()->view_state_changed();
739 case LFUN_PARAGRAPH_SPACING: {
740 Paragraph & par = cur.paragraph();
741 Spacing::Space cur_spacing = par.params().spacing().getSpace();
742 float cur_value = 1.0;
743 if (cur_spacing == Spacing::Other)
744 cur_value = par.params().spacing().getValue();
746 istringstream is(cmd.argument);
749 Spacing::Space new_spacing = cur_spacing;
750 float new_value = cur_value;
752 lyxerr << "Missing argument to `paragraph-spacing'"
754 } else if (tmp == "single") {
755 new_spacing = Spacing::Single;
756 } else if (tmp == "onehalf") {
757 new_spacing = Spacing::Onehalf;
758 } else if (tmp == "double") {
759 new_spacing = Spacing::Double;
760 } else if (tmp == "other") {
761 new_spacing = Spacing::Other;
764 lyxerr << "new_value = " << tmpval << endl;
767 } else if (tmp == "default") {
768 new_spacing = Spacing::Default;
770 lyxerr << _("Unknown spacing argument: ")
771 << cmd.argument << endl;
773 if (cur_spacing != new_spacing || cur_value != new_value) {
774 par.params().spacing(Spacing(new_spacing, new_value));
781 case LFUN_INSET_APPLY: {
782 string const name = cmd.getArg(0);
783 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
785 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
787 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
791 case LFUN_INSET_INSERT: {
792 InsetBase * inset = createInset(bv, cmd);
798 case LFUN_INSET_SETTINGS:
799 if (cur.inset() && cur.inset()->asUpdatableInset())
800 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
803 case LFUN_INSET_TOGGLE:
804 cur.clearSelection();
806 return DispatchResult(false);
811 case LFUN_SPACE_INSERT:
812 if (cursorPar()->layout()->free_spacing)
815 doInsertInset(this, bv, cmd, false, false);
816 moveCursor(cur, false);
819 case LFUN_HYPHENATION:
820 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
823 case LFUN_LIGATURE_BREAK:
824 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
828 specialChar(this, bv, InsetSpecialChar::LDOTS);
831 case LFUN_END_OF_SENTENCE:
832 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
835 case LFUN_MENU_SEPARATOR:
836 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
839 case LFUN_UPCASE_WORD:
840 changeCase(LyXText::text_uppercase);
844 case LFUN_LOWCASE_WORD:
845 changeCase(LyXText::text_lowercase);
849 case LFUN_CAPITALIZE_WORD:
850 changeCase(LyXText::text_capitalization);
854 case LFUN_TRANSPOSE_CHARS:
855 recUndo(cursor().par());
861 cur.message(_("Paste"));
862 replaceSelection(this);
863 #warning FIXME Check if the arg is in the domain of available selections.
864 if (isStrUnsignedInt(cmd.argument))
865 pasteSelection(strToUnsignedInt(cmd.argument));
868 cur.clearSelection(); // bug 393
875 cutSelection(true, true);
876 cur.message(_("Cut"));
882 cur.message(_("Copy"));
885 case LFUN_BEGINNINGBUFSEL:
887 return DispatchResult(false);
888 if (!cur.selection())
891 finishChange(cur, true);
896 return DispatchResult(false);
897 if (!cur.selection())
900 finishChange(cur, true);
904 cur.message(tostr(cursorX(cur.current())) + ' '
905 + tostr(cursorY(cur.current())));
911 istringstream is(cmd.argument);
914 lyxerr << "SETXY: Could not parse coordinates in '"
915 << cmd.argument << std::endl;
917 setCursorFromCoordinates(x, y);
922 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
924 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
931 cur.message(cursorPar()->layout()->name());
935 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
936 << cmd.argument << endl;
938 // This is not the good solution to the empty argument
939 // problem, but it will hopefully suffice for 1.2.0.
940 // The correct solution would be to augument the
941 // function list/array with information about what
942 // functions needs arguments and their type.
943 if (cmd.argument.empty()) {
944 cur.errorMessage(_("LyX function 'layout' needs an argument."));
948 // Derive layout number from given argument (string)
949 // and current buffer's textclass (number)
950 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
951 bool hasLayout = tclass.hasLayout(cmd.argument);
952 string layout = cmd.argument;
954 // If the entry is obsolete, use the new one instead.
956 string const & obs = tclass[layout]->obsoleted_by();
962 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
967 bool change_layout = (current_layout != layout);
969 if (!change_layout && cur.selection() &&
970 cur.selBegin().par() != cur.selEnd().par())
972 ParagraphList::iterator spit = getPar(cur.selBegin());
973 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
974 while (spit != epit) {
975 if (spit->layout()->name() != current_layout) {
976 change_layout = true;
984 current_layout = layout;
986 bv->owner()->setLayout(layout);
993 case LFUN_PASTESELECTION: {
994 cur.clearSelection();
995 string const clip = bv->getClipboard();
997 if (cmd.argument == "paragraph")
998 insertStringAsParagraphs(clip);
1000 insertStringAsLines(clip);
1006 case LFUN_GOTOERROR:
1007 gotoInset(InsetBase::ERROR_CODE, false);
1011 gotoInset(InsetBase::NOTE_CODE, false);
1014 case LFUN_REFERENCE_GOTO: {
1015 vector<InsetOld_code> tmp;
1016 tmp.push_back(InsetBase::LABEL_CODE);
1017 tmp.push_back(InsetBase::REF_CODE);
1018 gotoInset(tmp, true);
1023 replaceSelection(this);
1024 ParagraphList::iterator pit = cursorPar();
1025 lyx::pos_type pos = cursor().pos();
1029 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1032 c = pit->getChar(pos - 1);
1034 LyXLayout_ptr const & style = pit->layout();
1036 BufferParams const & bufparams = bv->buffer()->params();
1037 if (style->pass_thru ||
1038 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew")
1039 insertInset(new InsetQuotes(c, bufparams));
1041 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1045 case LFUN_DATE_INSERT: {
1046 replaceSelection(this);
1047 time_t now_time_t = time(NULL);
1048 struct tm * now_tm = localtime(&now_time_t);
1049 setlocale(LC_TIME, "");
1051 if (!cmd.argument.empty())
1054 arg = lyxrc.date_insert_format;
1056 int const datetmp_len =
1057 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1059 for (int i = 0; i < datetmp_len; i++)
1060 insertChar(datetmp[i]);
1063 moveCursor(cur, false);
1067 case LFUN_MOUSE_TRIPLE:
1068 if (cmd.button() == mouse_button::button1) {
1069 selection_possible = true;
1074 bv->haveSelection(cur.selection());
1078 case LFUN_MOUSE_DOUBLE:
1079 if (cmd.button() == mouse_button::button1) {
1080 selection_possible = true;
1081 selectWord(lyx::WHOLE_WORD_STRICT);
1082 bv->haveSelection(cur.selection());
1086 case LFUN_MOUSE_MOTION: {
1087 // Only use motion with button 1
1088 //if (ev.button() != mouse_button::button1)
1090 // The test for not selection possible is needed, that
1091 // only motion events are used, where the bottom press
1092 // event was on the drawing area too
1093 if (!selection_possible) {
1094 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1095 "Dispatch: no selection possible\n";
1098 RowList::iterator cursorrow = cursorRow();
1101 setCursorFromCoordinates(cmd.x, cmd.y);
1103 // This is to allow jumping over large insets
1104 // FIXME: shouldn't be top-text-specific
1105 if (cursorrow == cursorRow() && !in_inset_) {
1106 if (cmd.y - bv->top_y() >= bv->workHeight())
1107 cursorDown(cur, true);
1108 else if (cmd.y - bv->top_y() < 0)
1109 cursorUp(cur, true);
1112 // don't set anchor_
1113 bv->cursor().cursor_ = cur.cursor_;
1114 bv->cursor().setSelection();
1119 // Single-click on work area
1120 case LFUN_MOUSE_PRESS: {
1121 // ok ok, this is a hack (for xforms)
1122 // We shouldn't go further down as we really should only do the
1123 // scrolling and be done with this. Otherwise we may open some
1124 // dialogs (Jug 20020424).
1125 if (cmd.button() == mouse_button::button4) {
1126 bv->scroll(-lyxrc.wheel_jump);
1130 if (cmd.button() == mouse_button::button5) {
1131 bv->scroll(lyxrc.wheel_jump);
1135 // Right click on a footnote flag opens float menu
1136 if (cmd.button() == mouse_button::button3) {
1137 cur.clearSelection();
1138 selection_possible = false;
1142 // Middle button press pastes if we have a selection
1143 // We do this here as if the selection was inside an inset
1144 // it could get cleared on the unlocking of the inset so
1145 // we have to check this first
1146 bool paste_internally = false;
1147 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1148 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1149 paste_internally = true;
1152 selection_possible = true;
1154 // Clear the selection
1155 cur.clearSelection();
1157 setCursorFromCoordinates(cur.current(), cmd.x - xo_,
1161 cur.x_target() = cursorX(cur.current());
1163 // set cursor and anchor to this position
1166 if (bv->fitCursor())
1167 selection_possible = false;
1169 // Insert primary selection with middle mouse
1170 // if there is a local selection in the current buffer,
1172 if (cmd.button() == mouse_button::button2) {
1173 if (paste_internally)
1174 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1176 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1177 selection_possible = false;
1182 case LFUN_MOUSE_RELEASE: {
1183 // do nothing if we used the mouse wheel
1184 if (cmd.button() == mouse_button::button4
1185 || cmd.button() == mouse_button::button5)
1186 return DispatchResult(true, false);
1188 selection_possible = false;
1190 if (cmd.button() == mouse_button::button2)
1194 if (cmd.button() == mouse_button::button1)
1195 bv->haveSelection(cur.selection());
1198 bv->owner()->view_state_changed();
1199 bv->owner()->updateMenubar();
1200 bv->owner()->updateToolbar();
1204 case LFUN_SELFINSERT: {
1205 if (cmd.argument.empty())
1208 // Automatically delete the currently selected
1209 // text and replace it with what is being
1210 // typed in now. Depends on lyxrc settings
1211 // "auto_region_delete", which defaults to
1214 if (lyxrc.auto_region_delete) {
1215 if (cur.selection())
1216 cutSelection(false, false);
1217 bv->haveSelection(false);
1220 cur.clearSelection();
1221 LyXFont const old_font = real_current_font;
1223 string::const_iterator cit = cmd.argument.begin();
1224 string::const_iterator end = cmd.argument.end();
1225 for (; cit != end; ++cit)
1226 bv->owner()->getIntl().getTransManager().
1227 TranslateAndInsert(*cit, this);
1230 moveCursor(cur, false);
1232 // real_current_font.number can change so we need to
1233 // update the minibuffer
1234 if (old_font != real_current_font)
1235 bv->owner()->view_state_changed();
1236 bv->updateScrollbar();
1241 InsetCommandParams p("url");
1242 string const data = InsetCommandMailer::params2string("url", p);
1243 bv->owner()->getDialogs().show("url", data, 0);
1247 case LFUN_HTMLURL: {
1248 InsetCommandParams p("htmlurl");
1249 string const data = InsetCommandMailer::params2string("url", p);
1250 bv->owner()->getDialogs().show("url", data, 0);
1254 case LFUN_INSERT_LABEL: {
1255 InsetCommandParams p("label");
1256 string const data = InsetCommandMailer::params2string("label", p);
1257 bv->owner()->getDialogs().show("label", data, 0);
1263 case LFUN_INSET_LIST:
1264 case LFUN_INSET_THEOREM:
1265 case LFUN_INSET_CAPTION:
1267 case LFUN_INSERT_NOTE:
1268 case LFUN_INSERT_CHARSTYLE:
1269 case LFUN_INSERT_BOX:
1270 case LFUN_INSERT_BRANCH:
1271 case LFUN_INSERT_BIBITEM:
1272 case LFUN_INSET_ERT:
1273 case LFUN_INSET_FLOAT:
1274 case LFUN_INSET_FOOTNOTE:
1275 case LFUN_INSET_MARGINAL:
1276 case LFUN_INSET_OPTARG:
1277 case LFUN_INSET_WIDE_FLOAT:
1278 case LFUN_INSET_WRAP:
1279 case LFUN_TABULAR_INSERT:
1280 case LFUN_ENVIRONMENT_INSERT:
1281 // Open the inset, and move the current selection
1283 doInsertInset(this, bv, cmd, true, true);
1286 case LFUN_INDEX_INSERT:
1287 // Just open the inset
1288 doInsertInset(this, bv, cmd, true, false);
1291 case LFUN_INDEX_PRINT:
1292 case LFUN_TOC_INSERT:
1294 case LFUN_INSERT_LINE:
1295 case LFUN_INSERT_PAGEBREAK:
1297 doInsertInset(this, bv, cmd, false, false);
1300 case LFUN_DEPTH_MIN:
1301 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1305 case LFUN_DEPTH_PLUS:
1306 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1310 case LFUN_MATH_DISPLAY:
1311 mathDispatch(cur, cmd, true);
1314 case LFUN_MATH_IMPORT_SELECTION:
1315 case LFUN_MATH_MODE:
1316 mathDispatch(cur, cmd, false);
1319 case LFUN_MATH_MACRO:
1320 if (cmd.argument.empty())
1321 cur.errorMessage(N_("Missing argument"));
1323 string s = cmd.argument;
1324 string const s1 = token(s, ' ', 1);
1325 int const nargs = s1.empty() ? 0 : atoi(s1);
1326 string const s2 = token(s, ' ', 2);
1327 string const type = s2.empty() ? "newcommand" : s2;
1328 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1329 cur.nextInset()->edit(cur, true);
1333 case LFUN_INSERT_MATH:
1334 case LFUN_INSERT_MATRIX:
1335 case LFUN_MATH_DELIM: {
1336 cur.insert(new MathHullInset);
1337 cur.dispatch(FuncRequest(LFUN_RIGHT));
1338 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1344 LyXFont font(LyXFont::ALL_IGNORE);
1345 font.setEmph(LyXFont::TOGGLE);
1346 toggleAndShow(bv, this, font);
1347 bv->owner()->view_state_changed();
1352 LyXFont font(LyXFont::ALL_IGNORE);
1353 font.setSeries(LyXFont::BOLD_SERIES);
1354 toggleAndShow(bv, this, font);
1355 bv->owner()->view_state_changed();
1360 LyXFont font(LyXFont::ALL_IGNORE);
1361 font.setNoun(LyXFont::TOGGLE);
1362 toggleAndShow(bv, this, font);
1363 bv->owner()->view_state_changed();
1368 LyXFont font(LyXFont::ALL_IGNORE);
1369 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1370 toggleAndShow(bv, this, font);
1371 bv->owner()->view_state_changed();
1376 LyXFont font(LyXFont::ALL_IGNORE);
1377 font.setFamily(LyXFont::SANS_FAMILY);
1378 toggleAndShow(bv, this, font);
1379 bv->owner()->view_state_changed();
1384 LyXFont font(LyXFont::ALL_IGNORE);
1385 font.setFamily(LyXFont::ROMAN_FAMILY);
1386 toggleAndShow(bv, this, font);
1387 bv->owner()->view_state_changed();
1391 case LFUN_DEFAULT: {
1392 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1393 toggleAndShow(bv, this, font);
1394 bv->owner()->view_state_changed();
1398 case LFUN_UNDERLINE: {
1399 LyXFont font(LyXFont::ALL_IGNORE);
1400 font.setUnderbar(LyXFont::TOGGLE);
1401 toggleAndShow(bv, this, font);
1402 bv->owner()->view_state_changed();
1406 case LFUN_FONT_SIZE: {
1407 LyXFont font(LyXFont::ALL_IGNORE);
1408 font.setLyXSize(cmd.argument);
1409 toggleAndShow(bv, this, font);
1410 bv->owner()->view_state_changed();
1414 case LFUN_LANGUAGE: {
1415 Language const * lang = languages.getLanguage(cmd.argument);
1418 LyXFont font(LyXFont::ALL_IGNORE);
1419 font.setLanguage(lang);
1420 toggleAndShow(bv, this, font);
1422 bv->owner()->view_state_changed();
1426 case LFUN_FREEFONT_APPLY:
1427 toggleAndShow(bv, this, freefont, toggleall);
1428 bv->owner()->view_state_changed();
1429 bv->owner()->message(_("Character set"));
1432 // Set the freefont using the contents of \param data dispatched from
1433 // the frontends and apply it at the current cursor location.
1434 case LFUN_FREEFONT_UPDATE: {
1437 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1440 toggleAndShow(bv, this, freefont, toggleall);
1441 bv->owner()->view_state_changed();
1442 bv->owner()->message(_("Character set"));
1447 case LFUN_FINISHED_LEFT:
1448 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1449 cur.pop(cur.currentDepth());
1451 cursorLeft(cur, true);
1452 cur.bv().cursor() = cur;
1455 case LFUN_FINISHED_RIGHT:
1456 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1457 cur.pop(cur.currentDepth());
1459 cursorRight(cur, true);
1460 cur.bv().cursor() = cur;
1463 case LFUN_FINISHED_UP:
1464 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1465 cur.pop(cur.currentDepth());
1466 cursorUp(cur, true);
1467 cur.bv().cursor() = cur;
1470 case LFUN_FINISHED_DOWN:
1471 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1472 cur.pop(cur.currentDepth());
1473 cursorDown(cur, true);
1474 cur.bv().cursor() = cur;
1477 case LFUN_LAYOUT_PARAGRAPH: {
1479 params2string(cur.paragraph(), data);
1480 data = "show\n" + data;
1481 bv->owner()->getDialogs().show("paragraph", data);
1485 case LFUN_PARAGRAPH_UPDATE: {
1486 if (!bv->owner()->getDialogs().visible("paragraph"))
1489 params2string(cur.paragraph(), data);
1491 // Will the paragraph accept changes from the dialog?
1492 InsetBase * const inset = cur.inset();
1494 !(inset && inset->forceDefaultParagraphs(inset));
1496 data = "update " + tostr(accept) + '\n' + data;
1497 bv->owner()->getDialogs().update("paragraph", data);
1502 case LFUN_CIRCUMFLEX:
1512 case LFUN_SPECIAL_CARON:
1515 case LFUN_HUNG_UMLAUT:
1518 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1519 if (!cmd.argument.empty())
1520 bv->owner()->getIntl().getTransManager()
1521 .TranslateAndInsert(cmd.argument[0], this);
1524 case LFUN_FLOAT_LIST: {
1525 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1526 if (tclass.floats().typeExist(cmd.argument)) {
1527 // not quite sure if we want this...
1530 cur.clearSelection();
1531 breakParagraph(cur);
1533 if (cur.lastpos() != 0) {
1534 cursorLeft(cur, true);
1535 breakParagraph(cur);
1538 setLayout(tclass.defaultLayoutName());
1539 setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1540 insertInset(new InsetFloatList(cmd.argument));
1543 lyxerr << "Non-existent float type: "
1544 << cmd.argument << endl;
1550 return DispatchResult(false);
1553 return DispatchResult(true, true);