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"
36 #include "paragraph.h"
37 #include "paragraph_funcs.h"
38 #include "ParagraphParameters.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
45 #include "insets/insetcommand.h"
46 #include "insets/insetfloatlist.h"
47 #include "insets/insetnewline.h"
48 #include "insets/insetquotes.h"
49 #include "insets/insetspecialchar.h"
50 #include "insets/insettext.h"
52 #include "support/lstrings.h"
53 #include "support/lyxlib.h"
54 #include "support/tostr.h"
55 #include "support/std_sstream.h"
57 #include "mathed/math_hullinset.h"
58 #include "mathed/formulamacro.h"
64 using lyx::support::isStrUnsignedInt;
65 using lyx::support::strToUnsignedInt;
66 using lyx::support::atoi;
67 using lyx::support::token;
72 using std::istringstream;
76 extern string current_layout;
78 // the selection possible is needed, that only motion events are
79 // used, where the button press event was on the drawing area too
80 bool selection_possible = false;
86 LyXFont freefont(LyXFont::ALL_IGNORE);
87 bool toggleall = false;
90 void toggleAndShow(LCursor & cur, LyXText * text,
91 LyXFont const & font, bool toggleall = true)
93 if (!cur.bv().available())
96 text->toggleFree(cur, font, toggleall);
98 if (font.language() != ignore_language ||
99 font.number() != LyXFont::IGNORE) {
100 Paragraph & par = cur.paragraph();
101 text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
102 if (cur.boundary() !=
103 text->bidi.isBoundary(*cur.bv().buffer(), par,
105 text->real_current_font))
106 text->setCursor(cur, cur.par(), cur.pos(),
107 false, !cur.boundary());
113 void moveCursor(LCursor & cur, bool selecting)
115 if (selecting || cur.mark())
117 if (!cur.selection())
118 cur.bv().haveSelection(false);
119 cur.bv().switchKeyMap();
123 void finishChange(LCursor & cur, bool selecting = false)
126 moveCursor(cur, selecting);
127 cur.bv().owner()->view_state_changed();
131 void mathDispatch(LCursor & cur, LyXText * text,
132 FuncRequest const & cmd, bool display)
134 string sel = cur.selectionAsString(false);
135 lyxerr << "selection is: '" << sel << "'" << endl;
138 cur.insert(new MathHullInset); // activates inset
139 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
140 // don't do that also for LFUN_MATH_MODE unless you want end up with
141 // always changing to mathrm when opening an inlined inset
142 // -- I really hate "LyXfunc overloading"...
144 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
145 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
147 // create a macro if we see "\\newcommand" somewhere, and an ordinary
149 text->cutSelection(cur, true, true);
150 if (sel.find("\\newcommand") == string::npos &&
151 sel.find("\\def") == string::npos)
153 cur.insert(new MathHullInset);
154 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
155 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
157 cur.insert(new InsetFormulaMacro(sel));
160 cur.message(N_("Math editor mode"));
169 string const freefont2string()
172 if (font2string(freefont, toggleall, data))
180 //takes absolute x,y coordinates
181 InsetBase * LyXText::checkInsetHit(int x, int y)
183 ParagraphList::iterator pit;
184 ParagraphList::iterator end;
186 getParsInRange(paragraphs(),
188 bv()->top_y() - yo_ + bv()->workHeight(),
191 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
192 for ( ; pit != end; ++pit) {
193 InsetList::iterator iit = pit->insetlist.begin();
194 InsetList::iterator iend = pit->insetlist.end();
195 for ( ; iit != iend; ++iit) {
196 InsetBase * inset = iit->inset;
198 lyxerr << "examining inset " << inset
199 //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
200 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
201 << " yo: " << inset->yo() - inset->ascent() << "..."
202 << inset->yo() + inset->descent() << endl;
204 if (inset->covers(x, y)) {
205 lyxerr << "Hit inset: " << inset << endl;
210 lyxerr << "No inset hit. " << endl;
215 bool LyXText::gotoNextInset(LCursor & cur,
216 vector<InsetOld_code> const & codes, string const & contents)
218 BOOST_ASSERT(this == cur.text());
219 ParagraphList::iterator end = paragraphs().end();
220 ParagraphList::iterator pit = getPar(cur.par());
221 pos_type pos = cur.pos();
225 if (pos + 1 < pit->size()) {
232 } while (pit != end &&
233 !(pit->isInset(pos) &&
234 (inset = pit->getInset(pos)) != 0 &&
235 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
237 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
243 setCursor(cur, parOffset(pit), pos, false);
248 void LyXText::gotoInset(LCursor & cur,
249 vector<InsetOld_code> const & codes, bool same_content)
251 cur.clearSelection();
255 && cur.pos() < cur.lastpos()
256 && cur.paragraph().isInset(cur.pos())) {
257 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
258 if (find(codes.begin(), codes.end(), inset->lyxCode())
260 contents = static_cast<InsetCommand const *>(inset)->getContents();
263 if (!gotoNextInset(cur, codes, contents)) {
264 if (cur.pos() || cur.par() != 0) {
265 CursorSlice tmp = cur.current();
268 if (!gotoNextInset(cur, codes, contents)) {
270 cur.message(_("No more insets"));
273 cur.message(_("No more insets"));
281 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
283 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
287 void LyXText::cursorPrevious(LCursor & cur)
289 pos_type cpos = cur.pos();
290 lyx::paroffset_type cpar = cur.par();
292 int x = cur.x_target();
293 int y = bv()->top_y();
294 setCursorFromCoordinates(cur, x, y);
296 if (cpar == cur.par() && cpos == cur.pos()) {
297 // we have a row which is taller than the workarea. The
298 // simplest solution is to move to the previous row instead.
302 bv()->updateScrollbar();
307 void LyXText::cursorNext(LCursor & cur)
309 pos_type cpos = cur.pos();
310 lyx::paroffset_type cpar = cur.par();
312 int x = cur.x_target();
313 int y = bv()->top_y() + bv()->workHeight();
314 setCursorFromCoordinates(cur, x, y);
316 if (cpar == cur.par() && cpos == cur.pos()) {
317 // we have a row which is taller than the workarea. The
318 // simplest solution is to move to the next row instead.
322 bv()->updateScrollbar();
329 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
331 text->replaceSelection(cur);
332 cur.insert(new InsetSpecialChar(kind));
337 void doInsertInset(LCursor & cur, LyXText * text,
338 FuncRequest const & cmd, bool edit, bool pastesel)
340 InsetBase * inset = createInset(&cur.bv(), cmd);
345 if (cur.selection()) {
346 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
349 text->insertInset(cur, inset);
351 inset->edit(cur, true);
352 if (gotsel && pastesel)
353 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
359 void LyXText::number(LCursor & cur)
361 LyXFont font(LyXFont::ALL_IGNORE);
362 font.setNumber(LyXFont::TOGGLE);
363 toggleAndShow(cur, this, font);
367 bool LyXText::isRTL(Paragraph const & par) const
369 return par.isRightToLeftPar(bv()->buffer()->params());
373 void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
375 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
376 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
378 BufferView * bv = &cur.bv();
379 CursorSlice sl = cur.current();
381 switch (cmd.action) {
383 case LFUN_APPENDIX: {
384 Paragraph & par = cur.paragraph();
385 bool start = !par.params().startOfAppendix();
387 // ensure that we have only one start_of_appendix in this document
388 ParagraphList::iterator tmp = paragraphs().begin();
389 ParagraphList::iterator end = paragraphs().end();
391 for (; tmp != end; ++tmp) {
392 if (tmp->params().startOfAppendix()) {
393 recUndo(parOffset(tmp));
394 tmp->params().startOfAppendix(false);
401 par.params().startOfAppendix(start);
403 // we can set the refreshing parameters now
410 case LFUN_DELETE_WORD_FORWARD:
411 cur.clearSelection();
412 deleteWordForward(cur);
416 case LFUN_DELETE_WORD_BACKWARD:
417 cur.clearSelection();
418 deleteWordBackward(cur);
422 case LFUN_DELETE_LINE_FORWARD:
423 cur.clearSelection();
424 deleteLineForward(cur);
430 cur.clearSelection();
431 if (isRTL(cur.paragraph()))
432 cursorLeftOneWord(cur);
434 cursorRightOneWord(cur);
440 cur.clearSelection();
441 if (isRTL(cur.paragraph()))
442 cursorRightOneWord(cur);
444 cursorLeftOneWord(cur);
448 case LFUN_BEGINNINGBUF:
450 cur.clearSelection();
457 cur.clearSelection();
464 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
465 if (isRTL(cur.paragraph()))
469 if (sl == cur.current())
470 cur.dispatched(FINISHED_RIGHT);
475 cur.selHandle(cmd.action == LFUN_LEFTSEL);
476 if (isRTL(cur.paragraph()))
480 if (sl == cur.current())
481 cur.dispatched(FINISHED_LEFT);
486 cur.selHandle(cmd.action == LFUN_UPSEL);
488 if (sl == cur.current())
489 cur.dispatched(FINISHED_UP);
494 cur.selHandle(cmd.action == LFUN_DOWNSEL);
496 if (sl == cur.current())
497 cur.dispatched(FINISHED_DOWN);
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())
545 if (isRTL(cur.paragraph()))
546 cursorLeftOneWord(cur);
548 cursorRightOneWord(cur);
549 finishChange(cur, true);
552 case LFUN_WORDLEFTSEL:
553 if (!cur.selection())
555 if (isRTL(cur.paragraph()))
556 cursorRightOneWord(cur);
558 cursorLeftOneWord(cur);
559 finishChange(cur, true);
563 selectWord(cur, lyx::WHOLE_WORD);
564 finishChange(cur, true);
568 case LFUN_UP_PARAGRAPH:
570 cur.clearSelection();
571 cursorUpParagraph(cur);
575 case LFUN_DOWN_PARAGRAPH:
577 cur.clearSelection();
578 cursorDownParagraph(cur);
579 finishChange(cur, false);
584 cur.clearSelection();
585 finishChange(cur, false);
586 if (cur.par() == 0 && cur.textRow().pos() == 0)
587 cur.dispatched(FINISHED_UP);
594 cur.clearSelection();
595 finishChange(cur, false);
596 if (cur.par() == cur.lastpar()
597 && cur.textRow().endpos() == cur.lastpos())
598 cur.dispatched(FINISHED_DOWN);
605 cur.clearSelection();
607 finishChange(cur, false);
612 cur.clearSelection();
614 finishChange(cur, false);
617 case LFUN_BREAKLINE: {
618 // Not allowed by LaTeX (labels or empty par)
619 if (cur.pos() > cur.paragraph().beginOfBody()) {
620 replaceSelection(cur);
621 cur.insert(new InsetNewline);
622 moveCursor(cur, false);
628 if (!cur.selection()) {
631 // It is possible to make it a lot faster still
632 // just comment out the line below...
634 cutSelection(cur, true, false);
636 moveCursor(cur, false);
637 bv->owner()->view_state_changed();
640 case LFUN_DELETE_SKIP:
641 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
642 if (!cur.selection()) {
643 if (cur.pos() == cur.lastpos()) {
650 cutSelection(cur, true, false);
657 if (!cur.selection()) {
658 if (bv->owner()->getIntl().getTransManager().backspace()) {
661 // It is possible to make it a lot faster still
662 // just comment out the line below...
665 cutSelection(cur, true, false);
667 bv->owner()->view_state_changed();
672 case LFUN_BACKSPACE_SKIP:
673 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
674 if (!cur.selection()) {
676 //CursorSlice cur = cursor();
680 cutSelection(cur, true, false);
685 case LFUN_BREAKPARAGRAPH:
686 replaceSelection(cur);
687 breakParagraph(cur, 0);
691 bv->owner()->view_state_changed();
694 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
695 replaceSelection(cur);
696 breakParagraph(cur, 1);
700 bv->owner()->view_state_changed();
703 case LFUN_BREAKPARAGRAPH_SKIP: {
704 // When at the beginning of a paragraph, remove
705 // indentation and add a "defskip" at the top.
706 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
707 replaceSelection(cur);
708 if (cur.pos() == 0) {
709 ParagraphParameters & params = cur.paragraph().params();
713 params.labelWidthString(), 1);
715 breakParagraph(cur, 0);
720 bv->owner()->view_state_changed();
724 case LFUN_PARAGRAPH_SPACING: {
725 Paragraph & par = cur.paragraph();
726 Spacing::Space cur_spacing = par.params().spacing().getSpace();
727 float cur_value = 1.0;
728 if (cur_spacing == Spacing::Other)
729 cur_value = par.params().spacing().getValue();
731 istringstream is(cmd.argument);
734 Spacing::Space new_spacing = cur_spacing;
735 float new_value = cur_value;
737 lyxerr << "Missing argument to `paragraph-spacing'"
739 } else if (tmp == "single") {
740 new_spacing = Spacing::Single;
741 } else if (tmp == "onehalf") {
742 new_spacing = Spacing::Onehalf;
743 } else if (tmp == "double") {
744 new_spacing = Spacing::Double;
745 } else if (tmp == "other") {
746 new_spacing = Spacing::Other;
749 lyxerr << "new_value = " << tmpval << endl;
752 } else if (tmp == "default") {
753 new_spacing = Spacing::Default;
755 lyxerr << _("Unknown spacing argument: ")
756 << cmd.argument << endl;
758 if (cur_spacing != new_spacing || cur_value != new_value) {
759 par.params().spacing(Spacing(new_spacing, new_value));
766 case LFUN_INSET_APPLY: {
767 string const name = cmd.getArg(0);
768 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
770 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
772 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
776 case LFUN_INSET_INSERT: {
777 InsetBase * inset = createInset(bv, cmd);
779 insertInset(cur, inset);
783 case LFUN_INSET_SETTINGS:
784 if (cur.inset() && cur.inset()->asUpdatableInset())
785 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
788 case LFUN_INSET_TOGGLE:
789 cur.clearSelection();
790 if (!toggleInset(cur))
796 case LFUN_SPACE_INSERT:
797 if (cur.paragraph().layout()->free_spacing)
798 insertChar(cur, ' ');
800 doInsertInset(cur, this, cmd, false, false);
801 moveCursor(cur, false);
804 case LFUN_HYPHENATION:
805 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
808 case LFUN_LIGATURE_BREAK:
809 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
813 specialChar(cur, this, InsetSpecialChar::LDOTS);
816 case LFUN_END_OF_SENTENCE:
817 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
820 case LFUN_MENU_SEPARATOR:
821 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
824 case LFUN_UPCASE_WORD:
825 changeCase(cur, LyXText::text_uppercase);
829 case LFUN_LOWCASE_WORD:
830 changeCase(cur, LyXText::text_lowercase);
834 case LFUN_CAPITALIZE_WORD:
835 changeCase(cur, LyXText::text_capitalization);
839 case LFUN_TRANSPOSE_CHARS:
846 cur.message(_("Paste"));
847 replaceSelection(cur);
848 #warning FIXME Check if the arg is in the domain of available selections.
849 if (isStrUnsignedInt(cmd.argument))
850 pasteSelection(cur, strToUnsignedInt(cmd.argument));
852 pasteSelection(cur, 0);
853 cur.clearSelection(); // bug 393
860 cutSelection(cur, true, true);
861 cur.message(_("Cut"));
867 cur.message(_("Copy"));
870 case LFUN_BEGINNINGBUFSEL:
874 if (!cur.selection())
877 finishChange(cur, true);
885 if (!cur.selection())
888 finishChange(cur, true);
893 cur.message(tostr(cursorX(cur.current())) + ' '
894 + tostr(cursorY(cur.current())));
900 istringstream is(cmd.argument);
903 lyxerr << "SETXY: Could not parse coordinates in '"
904 << cmd.argument << std::endl;
906 setCursorFromCoordinates(cur, x, y);
911 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
913 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
920 cur.message(cur.paragraph().layout()->name());
924 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
925 << cmd.argument << endl;
927 // This is not the good solution to the empty argument
928 // problem, but it will hopefully suffice for 1.2.0.
929 // The correct solution would be to augument the
930 // function list/array with information about what
931 // functions needs arguments and their type.
932 if (cmd.argument.empty()) {
933 cur.errorMessage(_("LyX function 'layout' needs an argument."));
937 // Derive layout number from given argument (string)
938 // and current buffer's textclass (number)
939 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
940 bool hasLayout = tclass.hasLayout(cmd.argument);
941 string layout = cmd.argument;
943 // If the entry is obsolete, use the new one instead.
945 string const & obs = tclass[layout]->obsoleted_by();
951 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
956 bool change_layout = (current_layout != layout);
958 if (!change_layout && cur.selection() &&
959 cur.selBegin().par() != cur.selEnd().par())
961 ParagraphList::iterator spit = getPar(cur.selBegin());
962 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
963 while (spit != epit) {
964 if (spit->layout()->name() != current_layout) {
965 change_layout = true;
973 current_layout = layout;
974 setLayout(cur, layout);
975 bv->owner()->setLayout(layout);
982 case LFUN_PASTESELECTION: {
983 cur.clearSelection();
984 string const clip = bv->getClipboard();
986 if (cmd.argument == "paragraph")
987 insertStringAsParagraphs(cur, clip);
989 insertStringAsLines(cur, clip);
996 gotoInset(cur, InsetBase::ERROR_CODE, false);
1000 gotoInset(cur, InsetBase::NOTE_CODE, false);
1003 case LFUN_REFERENCE_GOTO: {
1004 vector<InsetOld_code> tmp;
1005 tmp.push_back(InsetBase::LABEL_CODE);
1006 tmp.push_back(InsetBase::REF_CODE);
1007 gotoInset(cur, tmp, true);
1012 replaceSelection(cur);
1013 Paragraph & par = cur.paragraph();
1014 lyx::pos_type pos = cur.pos();
1018 else if (cur.prevInset() && cur.prevInset()->isSpace())
1021 c = par.getChar(pos - 1);
1023 LyXLayout_ptr const & style = par.layout();
1025 BufferParams const & bufparams = bv->buffer()->params();
1026 if (!style->pass_thru
1027 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1028 string arg = cmd.argument;
1029 if (arg == "single")
1030 cur.insert(new InsetQuotes(c,
1031 bufparams.quotes_language,
1032 InsetQuotes::SingleQ));
1033 else if (arg == "double")
1034 cur.insert(new InsetQuotes(c,
1035 bufparams.quotes_language,
1036 InsetQuotes::DoubleQ));
1038 cur.insert(new InsetQuotes(c, bufparams));
1041 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1045 case LFUN_DATE_INSERT: {
1046 replaceSelection(cur);
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(cur, 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(cur, lyx::WHOLE_WORD_STRICT);
1082 bv->haveSelection(cur.selection());
1086 case LFUN_MOUSE_MOTION: {
1087 // Only use motion with button 1
1088 //if (cmd.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 CursorSlice old = cur.current();
1099 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1101 // This is to allow jumping over large insets
1102 // FIXME: shouldn't be top-text-specific
1103 if (!in_inset_ && cur.current() == old) {
1104 if (cmd.y - bv->top_y() >= bv->workHeight())
1106 else if (cmd.y - bv->top_y() < 0)
1110 // don't set anchor_
1111 bv->cursor().cursor_ = cur.cursor_;
1112 bv->cursor().setSelection();
1116 // Single-click on work area
1117 case LFUN_MOUSE_PRESS: {
1118 // ok ok, this is a hack (for xforms)
1119 // We shouldn't go further down as we really should only do the
1120 // scrolling and be done with this. Otherwise we may open some
1121 // dialogs (Jug 20020424).
1122 if (cmd.button() == mouse_button::button4) {
1123 bv->scroll(-lyxrc.wheel_jump);
1127 if (cmd.button() == mouse_button::button5) {
1128 bv->scroll(lyxrc.wheel_jump);
1132 // Right click on a footnote flag opens float menu
1133 if (cmd.button() == mouse_button::button3) {
1134 cur.clearSelection();
1135 selection_possible = false;
1139 // Middle button press pastes if we have a selection
1140 // We do this here as if the selection was inside an inset
1141 // it could get cleared on the unlocking of the inset so
1142 // we have to check this first
1143 bool paste_internally = false;
1144 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1145 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1146 paste_internally = true;
1149 selection_possible = true;
1151 // Clear the selection
1152 cur.clearSelection();
1154 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1157 cur.x_target() = cursorX(cur.current());
1159 // set cursor and anchor to this position
1162 if (bv->fitCursor())
1163 selection_possible = false;
1165 // Insert primary selection with middle mouse
1166 // if there is a local selection in the current buffer,
1168 if (cmd.button() == mouse_button::button2) {
1169 if (paste_internally)
1170 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1172 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1173 selection_possible = false;
1178 case LFUN_MOUSE_RELEASE: {
1179 // do nothing if we used the mouse wheel
1180 if (cmd.button() == mouse_button::button4
1181 || cmd.button() == mouse_button::button5) {
1182 cur.notdispatched();
1186 selection_possible = false;
1188 if (cmd.button() == mouse_button::button2)
1192 if (cmd.button() == mouse_button::button1)
1193 bv->haveSelection(cur.selection());
1196 bv->owner()->view_state_changed();
1197 bv->owner()->updateMenubar();
1198 bv->owner()->updateToolbar();
1202 case LFUN_SELFINSERT: {
1203 if (cmd.argument.empty())
1206 // Automatically delete the currently selected
1207 // text and replace it with what is being
1208 // typed in now. Depends on lyxrc settings
1209 // "auto_region_delete", which defaults to
1212 if (lyxrc.auto_region_delete) {
1213 if (cur.selection())
1214 cutSelection(cur, false, false);
1215 bv->haveSelection(false);
1218 cur.clearSelection();
1219 LyXFont const old_font = real_current_font;
1221 string::const_iterator cit = cmd.argument.begin();
1222 string::const_iterator end = cmd.argument.end();
1223 for (; cit != end; ++cit)
1224 bv->owner()->getIntl().getTransManager().
1225 TranslateAndInsert(*cit, this);
1228 moveCursor(cur, false);
1230 // real_current_font.number can change so we need to
1231 // update the minibuffer
1232 if (old_font != real_current_font)
1233 bv->owner()->view_state_changed();
1234 bv->updateScrollbar();
1239 InsetCommandParams p("url");
1240 string const data = InsetCommandMailer::params2string("url", p);
1241 bv->owner()->getDialogs().show("url", data, 0);
1245 case LFUN_HTMLURL: {
1246 InsetCommandParams p("htmlurl");
1247 string const data = InsetCommandMailer::params2string("url", p);
1248 bv->owner()->getDialogs().show("url", data, 0);
1252 case LFUN_INSERT_LABEL: {
1253 InsetCommandParams p("label");
1254 string const data = InsetCommandMailer::params2string("label", p);
1255 bv->owner()->getDialogs().show("label", data, 0);
1261 case LFUN_INSET_LIST:
1262 case LFUN_INSET_THEOREM:
1263 case LFUN_INSET_CAPTION:
1265 case LFUN_INSERT_NOTE:
1266 case LFUN_INSERT_CHARSTYLE:
1267 case LFUN_INSERT_BOX:
1268 case LFUN_INSERT_BRANCH:
1269 case LFUN_INSERT_BIBITEM:
1270 case LFUN_INSET_ERT:
1271 case LFUN_INSET_FLOAT:
1272 case LFUN_INSET_FOOTNOTE:
1273 case LFUN_INSET_MARGINAL:
1274 case LFUN_INSET_OPTARG:
1275 case LFUN_INSET_WIDE_FLOAT:
1276 case LFUN_INSET_WRAP:
1277 case LFUN_TABULAR_INSERT:
1278 case LFUN_ENVIRONMENT_INSERT:
1279 // Open the inset, and move the current selection
1281 doInsertInset(cur, this, cmd, true, true);
1284 case LFUN_INDEX_INSERT:
1285 // Just open the inset
1286 doInsertInset(cur, this, cmd, true, false);
1289 case LFUN_INDEX_PRINT:
1290 case LFUN_TOC_INSERT:
1292 case LFUN_INSERT_LINE:
1293 case LFUN_INSERT_PAGEBREAK:
1295 doInsertInset(cur, this, cmd, false, false);
1298 case LFUN_DEPTH_MIN:
1299 changeDepth(cur, bv_funcs::DEC_DEPTH);
1303 case LFUN_DEPTH_PLUS:
1304 changeDepth(cur, bv_funcs::INC_DEPTH);
1308 case LFUN_MATH_DISPLAY:
1309 mathDispatch(cur, this, cmd, true);
1312 case LFUN_MATH_IMPORT_SELECTION:
1313 case LFUN_MATH_MODE:
1314 mathDispatch(cur, this, cmd, false);
1317 case LFUN_MATH_MACRO:
1318 if (cmd.argument.empty())
1319 cur.errorMessage(N_("Missing argument"));
1321 string s = cmd.argument;
1322 string const s1 = token(s, ' ', 1);
1323 int const nargs = s1.empty() ? 0 : atoi(s1);
1324 string const s2 = token(s, ' ', 2);
1325 string const type = s2.empty() ? "newcommand" : s2;
1326 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1327 cur.nextInset()->edit(cur, true);
1331 case LFUN_INSERT_MATH:
1332 case LFUN_INSERT_MATRIX:
1333 case LFUN_MATH_DELIM: {
1334 cur.insert(new MathHullInset);
1335 cur.dispatch(FuncRequest(LFUN_RIGHT));
1336 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1342 LyXFont font(LyXFont::ALL_IGNORE);
1343 font.setEmph(LyXFont::TOGGLE);
1344 toggleAndShow(cur, this, font);
1345 bv->owner()->view_state_changed();
1350 LyXFont font(LyXFont::ALL_IGNORE);
1351 font.setSeries(LyXFont::BOLD_SERIES);
1352 toggleAndShow(cur, this, font);
1353 bv->owner()->view_state_changed();
1358 LyXFont font(LyXFont::ALL_IGNORE);
1359 font.setNoun(LyXFont::TOGGLE);
1360 toggleAndShow(cur, this, font);
1361 bv->owner()->view_state_changed();
1366 LyXFont font(LyXFont::ALL_IGNORE);
1367 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1368 toggleAndShow(cur, this, font);
1369 bv->owner()->view_state_changed();
1374 LyXFont font(LyXFont::ALL_IGNORE);
1375 font.setFamily(LyXFont::SANS_FAMILY);
1376 toggleAndShow(cur, this, font);
1377 bv->owner()->view_state_changed();
1382 LyXFont font(LyXFont::ALL_IGNORE);
1383 font.setFamily(LyXFont::ROMAN_FAMILY);
1384 toggleAndShow(cur, this, font);
1385 bv->owner()->view_state_changed();
1389 case LFUN_DEFAULT: {
1390 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1391 toggleAndShow(cur, this, font);
1392 bv->owner()->view_state_changed();
1396 case LFUN_UNDERLINE: {
1397 LyXFont font(LyXFont::ALL_IGNORE);
1398 font.setUnderbar(LyXFont::TOGGLE);
1399 toggleAndShow(cur, this, font);
1400 bv->owner()->view_state_changed();
1404 case LFUN_FONT_SIZE: {
1405 LyXFont font(LyXFont::ALL_IGNORE);
1406 font.setLyXSize(cmd.argument);
1407 toggleAndShow(cur, this, font);
1408 bv->owner()->view_state_changed();
1412 case LFUN_LANGUAGE: {
1413 Language const * lang = languages.getLanguage(cmd.argument);
1416 LyXFont font(LyXFont::ALL_IGNORE);
1417 font.setLanguage(lang);
1418 toggleAndShow(cur, this, font);
1420 bv->owner()->view_state_changed();
1424 case LFUN_FREEFONT_APPLY:
1425 toggleAndShow(cur, this, freefont, toggleall);
1426 bv->owner()->view_state_changed();
1427 cur.message(_("Character set"));
1430 // Set the freefont using the contents of \param data dispatched from
1431 // the frontends and apply it at the current cursor location.
1432 case LFUN_FREEFONT_UPDATE: {
1435 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1438 toggleAndShow(cur, this, freefont, toggleall);
1439 bv->owner()->view_state_changed();
1440 cur.message(_("Character set"));
1445 case LFUN_FINISHED_LEFT:
1446 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1447 cur.pop(cur.currentDepth());
1448 if (isRTL(cur.paragraph()))
1450 cur.bv().cursor() = cur;
1453 case LFUN_FINISHED_RIGHT:
1454 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1455 cur.pop(cur.currentDepth());
1456 if (!isRTL(cur.paragraph()))
1458 cur.bv().cursor() = cur;
1461 case LFUN_FINISHED_UP:
1462 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1463 cur.pop(cur.currentDepth());
1465 cur.bv().cursor() = cur;
1468 case LFUN_FINISHED_DOWN:
1469 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1470 cur.pop(cur.currentDepth());
1472 cur.bv().cursor() = cur;
1475 case LFUN_LAYOUT_PARAGRAPH: {
1477 params2string(cur.paragraph(), data);
1478 data = "show\n" + data;
1479 bv->owner()->getDialogs().show("paragraph", data);
1483 case LFUN_PARAGRAPH_UPDATE: {
1484 if (!bv->owner()->getDialogs().visible("paragraph"))
1487 params2string(cur.paragraph(), data);
1489 // Will the paragraph accept changes from the dialog?
1490 InsetBase * const inset = cur.inset();
1492 !(inset && inset->forceDefaultParagraphs(inset));
1494 data = "update " + tostr(accept) + '\n' + data;
1495 bv->owner()->getDialogs().update("paragraph", data);
1500 case LFUN_CIRCUMFLEX:
1510 case LFUN_SPECIAL_CARON:
1513 case LFUN_HUNG_UMLAUT:
1516 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1517 if (!cmd.argument.empty())
1518 bv->owner()->getIntl().getTransManager()
1519 .TranslateAndInsert(cmd.argument[0], this);
1522 case LFUN_FLOAT_LIST: {
1523 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1524 if (tclass.floats().typeExist(cmd.argument)) {
1525 // not quite sure if we want this...
1528 cur.clearSelection();
1529 breakParagraph(cur);
1531 if (cur.lastpos() != 0) {
1533 breakParagraph(cur);
1536 setLayout(cur, tclass.defaultLayoutName());
1537 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1538 cur.insert(new InsetFloatList(cmd.argument));
1541 lyxerr << "Non-existent float type: "
1542 << cmd.argument << endl;
1547 case LFUN_ACCEPT_CHANGE: {
1553 case LFUN_REJECT_CHANGE: {
1559 case LFUN_THESAURUS_ENTRY: {
1560 string arg = cmd.argument;
1562 arg = cur.selectionAsString(false);
1564 if (arg.size() > 100 || arg.empty()) {
1565 // Get word or selection
1566 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1567 arg = cur.selectionAsString(false);
1570 bv->owner()->getDialogs().show("thesaurus", arg);
1574 case LFUN_PARAGRAPH_APPLY: {
1575 // Given data, an encoding of the ParagraphParameters
1576 // generated in the Paragraph dialog, this function sets
1577 // the current paragraph appropriately.
1578 istringstream is(cmd.argument);
1581 ParagraphParameters params;
1586 params.labelWidthString(),
1589 cur.message(_("Paragraph layout set"));
1594 if (cur.selection())
1595 cur.selection() = false;
1597 cur.dispatched(FINISHED_LEFT);
1601 cur.notdispatched();
1607 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)