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);
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 text->cutSelection(cur, 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(LCursor & cur,
219 vector<InsetOld_code> const & codes, string const & contents)
221 BOOST_ASSERT(this == cur.text());
222 ParagraphList::iterator end = paragraphs().end();
223 ParagraphList::iterator pit = getPar(cur.par());
224 pos_type pos = cur.pos();
228 if (pos + 1 < pit->size()) {
235 } while (pit != end &&
236 !(pit->isInset(pos) &&
237 (inset = pit->getInset(pos)) != 0 &&
238 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
240 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
246 setCursor(cur, parOffset(pit), pos, false);
251 void LyXText::gotoInset(LCursor & cur,
252 vector<InsetOld_code> const & codes, bool same_content)
254 cur.clearSelection();
258 && cur.pos() < cur.lastpos()
259 && cur.paragraph().isInset(cur.pos())) {
260 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
261 if (find(codes.begin(), codes.end(), inset->lyxCode())
263 contents = static_cast<InsetCommand const *>(inset)->getContents();
266 if (!gotoNextInset(cur, codes, contents)) {
267 if (cur.pos() || cur.par() != 0) {
268 CursorSlice tmp = cur.current();
271 if (!gotoNextInset(cur, codes, contents)) {
273 cur.message(_("No more insets"));
276 cur.message(_("No more insets"));
284 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
286 gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
290 void LyXText::cursorPrevious(LCursor & cur)
292 pos_type cpos = cur.pos();
293 lyx::paroffset_type cpar = cur.par();
295 int x = cur.x_target();
296 int y = bv()->top_y();
297 setCursorFromCoordinates(cur, 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(LCursor & cur)
312 pos_type cpos = cur.pos();
313 lyx::paroffset_type cpar = cur.par();
315 int x = cur.x_target();
316 int y = bv()->top_y() + bv()->workHeight();
317 setCursorFromCoordinates(cur, x, y);
319 if (cpar == cur.par() && cpos == cur.pos()) {
320 // we have a row which is taller than the workarea. The
321 // simplest solution is to move to the next row instead.
325 bv()->updateScrollbar();
332 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
334 text->replaceSelection(cur);
335 cur.insert(new InsetSpecialChar(kind));
340 void doInsertInset(LCursor & cur, LyXText * text,
341 FuncRequest const & cmd, bool edit, bool pastesel)
343 InsetBase * inset = createInset(&cur.bv(), cmd);
348 if (cur.selection()) {
349 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
352 text->insertInset(cur, inset);
354 inset->edit(cur, true);
355 if (gotsel && pastesel)
356 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
362 void LyXText::number(LCursor & cur)
364 LyXFont font(LyXFont::ALL_IGNORE);
365 font.setNumber(LyXFont::TOGGLE);
366 toggleAndShow(cur, this, font);
370 bool LyXText::isRTL(Paragraph const & par) const
372 return par.isRightToLeftPar(bv()->buffer()->params());
376 void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
378 lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
379 //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
381 BufferView * bv = &cur.bv();
382 CursorSlice sl = cur.current();
384 switch (cmd.action) {
386 case LFUN_APPENDIX: {
387 Paragraph & par = cur.paragraph();
388 bool start = !par.params().startOfAppendix();
390 // ensure that we have only one start_of_appendix in this document
391 ParagraphList::iterator tmp = paragraphs().begin();
392 ParagraphList::iterator end = paragraphs().end();
394 for (; tmp != end; ++tmp) {
395 if (tmp->params().startOfAppendix()) {
396 recUndo(parOffset(tmp));
397 tmp->params().startOfAppendix(false);
404 par.params().startOfAppendix(start);
406 // we can set the refreshing parameters now
413 case LFUN_DELETE_WORD_FORWARD:
414 cur.clearSelection();
415 deleteWordForward(cur);
419 case LFUN_DELETE_WORD_BACKWARD:
420 cur.clearSelection();
421 deleteWordBackward(cur);
425 case LFUN_DELETE_LINE_FORWARD:
426 cur.clearSelection();
427 deleteLineForward(cur);
433 cur.clearSelection();
434 if (isRTL(cur.paragraph()))
435 cursorLeftOneWord(cur);
437 cursorRightOneWord(cur);
443 cur.clearSelection();
444 if (isRTL(cur.paragraph()))
445 cursorRightOneWord(cur);
447 cursorLeftOneWord(cur);
451 case LFUN_BEGINNINGBUF:
453 cur.clearSelection();
460 cur.clearSelection();
467 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
468 if (isRTL(cur.paragraph()))
472 if (sl == cur.current())
473 cur.dispatched(FINISHED_RIGHT);
478 cur.selHandle(cmd.action == LFUN_LEFTSEL);
479 if (isRTL(cur.paragraph()))
483 if (sl == cur.current())
484 cur.dispatched(FINISHED_LEFT);
489 cur.selHandle(cmd.action == LFUN_UPSEL);
491 if (sl == cur.current())
492 cur.dispatched(FINISHED_UP);
497 cur.selHandle(cmd.action == LFUN_DOWNSEL);
499 if (sl == cur.current())
500 cur.dispatched(FINISHED_DOWN);
503 case LFUN_UP_PARAGRAPHSEL:
504 if (!cur.selection())
506 cursorUpParagraph(cur);
507 finishChange(cur, true);
510 case LFUN_DOWN_PARAGRAPHSEL:
511 if (!cur.selection())
513 cursorDownParagraph(cur);
514 finishChange(cur, true);
518 if (!cur.selection())
521 finishChange(cur, true);
525 if (!cur.selection())
528 finishChange(cur, true);
532 if (!cur.selection())
535 finishChange(cur, true);
539 if (!cur.selection())
542 finishChange(cur, true);
545 case LFUN_WORDRIGHTSEL:
546 if (!cur.selection())
548 if (isRTL(cur.paragraph()))
549 cursorLeftOneWord(cur);
551 cursorRightOneWord(cur);
552 finishChange(cur, true);
555 case LFUN_WORDLEFTSEL:
556 if (!cur.selection())
558 if (isRTL(cur.paragraph()))
559 cursorRightOneWord(cur);
561 cursorLeftOneWord(cur);
562 finishChange(cur, true);
566 selectWord(cur, lyx::WHOLE_WORD);
567 finishChange(cur, true);
571 case LFUN_UP_PARAGRAPH:
573 cur.clearSelection();
574 cursorUpParagraph(cur);
578 case LFUN_DOWN_PARAGRAPH:
580 cur.clearSelection();
581 cursorDownParagraph(cur);
582 finishChange(cur, false);
587 cur.clearSelection();
588 finishChange(cur, false);
589 if (cur.par() == 0 && cur.textRow().pos() == 0)
590 cur.dispatched(FINISHED_UP);
597 cur.clearSelection();
598 finishChange(cur, false);
599 if (cur.par() == cur.lastpar()
600 && cur.textRow().endpos() == cur.lastpos())
601 cur.dispatched(FINISHED_DOWN);
608 cur.clearSelection();
610 finishChange(cur, false);
615 cur.clearSelection();
617 finishChange(cur, false);
620 case LFUN_BREAKLINE: {
621 // Not allowed by LaTeX (labels or empty par)
622 if (cur.pos() > cur.paragraph().beginOfBody()) {
623 replaceSelection(cur);
624 cur.insert(new InsetNewline);
625 moveCursor(cur, false);
631 if (!cur.selection()) {
634 // It is possible to make it a lot faster still
635 // just comment out the line below...
637 cutSelection(cur, true, false);
639 moveCursor(cur, false);
640 bv->owner()->view_state_changed();
643 case LFUN_DELETE_SKIP:
644 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
645 if (!cur.selection()) {
646 if (cur.pos() == cur.lastpos()) {
653 cutSelection(cur, true, false);
660 if (!cur.selection()) {
661 if (bv->owner()->getIntl().getTransManager().backspace()) {
664 // It is possible to make it a lot faster still
665 // just comment out the line below...
668 cutSelection(cur, true, false);
670 bv->owner()->view_state_changed();
675 case LFUN_BACKSPACE_SKIP:
676 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
677 if (!cur.selection()) {
679 //CursorSlice cur = cursor();
683 cutSelection(cur, true, false);
688 case LFUN_BREAKPARAGRAPH:
689 replaceSelection(cur);
690 breakParagraph(cur, 0);
694 bv->owner()->view_state_changed();
697 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
698 replaceSelection(cur);
699 breakParagraph(cur, 1);
703 bv->owner()->view_state_changed();
706 case LFUN_BREAKPARAGRAPH_SKIP: {
707 // When at the beginning of a paragraph, remove
708 // indentation and add a "defskip" at the top.
709 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
710 replaceSelection(cur);
711 if (cur.pos() == 0) {
712 ParagraphParameters & params = cur.paragraph().params();
716 params.labelWidthString(), 1);
718 breakParagraph(cur, 0);
723 bv->owner()->view_state_changed();
727 case LFUN_PARAGRAPH_SPACING: {
728 Paragraph & par = cur.paragraph();
729 Spacing::Space cur_spacing = par.params().spacing().getSpace();
730 float cur_value = 1.0;
731 if (cur_spacing == Spacing::Other)
732 cur_value = par.params().spacing().getValue();
734 istringstream is(cmd.argument);
737 Spacing::Space new_spacing = cur_spacing;
738 float new_value = cur_value;
740 lyxerr << "Missing argument to `paragraph-spacing'"
742 } else if (tmp == "single") {
743 new_spacing = Spacing::Single;
744 } else if (tmp == "onehalf") {
745 new_spacing = Spacing::Onehalf;
746 } else if (tmp == "double") {
747 new_spacing = Spacing::Double;
748 } else if (tmp == "other") {
749 new_spacing = Spacing::Other;
752 lyxerr << "new_value = " << tmpval << endl;
755 } else if (tmp == "default") {
756 new_spacing = Spacing::Default;
758 lyxerr << _("Unknown spacing argument: ")
759 << cmd.argument << endl;
761 if (cur_spacing != new_spacing || cur_value != new_value) {
762 par.params().spacing(Spacing(new_spacing, new_value));
769 case LFUN_INSET_APPLY: {
770 string const name = cmd.getArg(0);
771 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
773 inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
775 dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
779 case LFUN_INSET_INSERT: {
780 InsetBase * inset = createInset(bv, cmd);
782 insertInset(cur, inset);
786 case LFUN_INSET_SETTINGS:
787 if (cur.inset() && cur.inset()->asUpdatableInset())
788 cur.inset()->asUpdatableInset()->showInsetDialog(bv);
791 case LFUN_INSET_TOGGLE:
792 cur.clearSelection();
793 if (!toggleInset(cur))
799 case LFUN_SPACE_INSERT:
800 if (cur.paragraph().layout()->free_spacing)
801 insertChar(cur, ' ');
803 doInsertInset(cur, this, cmd, false, false);
804 moveCursor(cur, false);
807 case LFUN_HYPHENATION:
808 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
811 case LFUN_LIGATURE_BREAK:
812 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
816 specialChar(cur, this, InsetSpecialChar::LDOTS);
819 case LFUN_END_OF_SENTENCE:
820 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
823 case LFUN_MENU_SEPARATOR:
824 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
827 case LFUN_UPCASE_WORD:
828 changeCase(cur, LyXText::text_uppercase);
832 case LFUN_LOWCASE_WORD:
833 changeCase(cur, LyXText::text_lowercase);
837 case LFUN_CAPITALIZE_WORD:
838 changeCase(cur, LyXText::text_capitalization);
842 case LFUN_TRANSPOSE_CHARS:
849 cur.message(_("Paste"));
850 replaceSelection(cur);
851 #warning FIXME Check if the arg is in the domain of available selections.
852 if (isStrUnsignedInt(cmd.argument))
853 pasteSelection(cur, strToUnsignedInt(cmd.argument));
855 pasteSelection(cur, 0);
856 cur.clearSelection(); // bug 393
863 cutSelection(cur, true, true);
864 cur.message(_("Cut"));
870 cur.message(_("Copy"));
873 case LFUN_BEGINNINGBUFSEL:
877 if (!cur.selection())
880 finishChange(cur, true);
888 if (!cur.selection())
891 finishChange(cur, true);
896 cur.message(tostr(cursorX(cur.current())) + ' '
897 + tostr(cursorY(cur.current())));
903 istringstream is(cmd.argument);
906 lyxerr << "SETXY: Could not parse coordinates in '"
907 << cmd.argument << std::endl;
909 setCursorFromCoordinates(cur, x, y);
914 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
916 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
923 cur.message(cur.paragraph().layout()->name());
927 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
928 << cmd.argument << endl;
930 // This is not the good solution to the empty argument
931 // problem, but it will hopefully suffice for 1.2.0.
932 // The correct solution would be to augument the
933 // function list/array with information about what
934 // functions needs arguments and their type.
935 if (cmd.argument.empty()) {
936 cur.errorMessage(_("LyX function 'layout' needs an argument."));
940 // Derive layout number from given argument (string)
941 // and current buffer's textclass (number)
942 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
943 bool hasLayout = tclass.hasLayout(cmd.argument);
944 string layout = cmd.argument;
946 // If the entry is obsolete, use the new one instead.
948 string const & obs = tclass[layout]->obsoleted_by();
954 cur.errorMessage(string(N_("Layout ")) + cmd.argument +
959 bool change_layout = (current_layout != layout);
961 if (!change_layout && cur.selection() &&
962 cur.selBegin().par() != cur.selEnd().par())
964 ParagraphList::iterator spit = getPar(cur.selBegin());
965 ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
966 while (spit != epit) {
967 if (spit->layout()->name() != current_layout) {
968 change_layout = true;
976 current_layout = layout;
977 setLayout(cur, layout);
978 bv->owner()->setLayout(layout);
985 case LFUN_PASTESELECTION: {
986 cur.clearSelection();
987 string const clip = bv->getClipboard();
989 if (cmd.argument == "paragraph")
990 insertStringAsParagraphs(cur, clip);
992 insertStringAsLines(cur, clip);
999 gotoInset(cur, InsetBase::ERROR_CODE, false);
1003 gotoInset(cur, InsetBase::NOTE_CODE, false);
1006 case LFUN_REFERENCE_GOTO: {
1007 vector<InsetOld_code> tmp;
1008 tmp.push_back(InsetBase::LABEL_CODE);
1009 tmp.push_back(InsetBase::REF_CODE);
1010 gotoInset(cur, tmp, true);
1015 replaceSelection(cur);
1016 Paragraph & par = cur.paragraph();
1017 lyx::pos_type pos = cur.pos();
1021 else if (cur.prevInset() && cur.prevInset()->isSpace())
1024 c = par.getChar(pos - 1);
1026 LyXLayout_ptr const & style = par.layout();
1028 BufferParams const & bufparams = bv->buffer()->params();
1029 if (!style->pass_thru
1030 && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1031 string arg = cmd.argument;
1032 if (arg == "single")
1033 cur.insert(new InsetQuotes(c,
1034 bufparams.quotes_language,
1035 InsetQuotes::SingleQ));
1036 else if (arg == "double")
1037 cur.insert(new InsetQuotes(c,
1038 bufparams.quotes_language,
1039 InsetQuotes::DoubleQ));
1041 cur.insert(new InsetQuotes(c, bufparams));
1044 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1048 case LFUN_DATE_INSERT: {
1049 replaceSelection(cur);
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(cur, 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(cur, lyx::WHOLE_WORD_STRICT);
1085 bv->haveSelection(cur.selection());
1089 case LFUN_MOUSE_MOTION: {
1090 // Only use motion with button 1
1091 //if (cmd.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 CursorSlice old = cur.current();
1102 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1104 // This is to allow jumping over large insets
1105 // FIXME: shouldn't be top-text-specific
1106 if (!in_inset_ && cur.current() == old) {
1107 if (cmd.y - bv->top_y() >= bv->workHeight())
1109 else if (cmd.y - bv->top_y() < 0)
1113 // don't set anchor_
1114 bv->cursor().cursor_ = cur.cursor_;
1115 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, cmd.x, cmd.y);
1160 cur.x_target() = cursorX(cur.current());
1162 // set cursor and anchor to this position
1165 if (bv->fitCursor())
1166 selection_possible = false;
1168 // Insert primary selection with middle mouse
1169 // if there is a local selection in the current buffer,
1171 if (cmd.button() == mouse_button::button2) {
1172 if (paste_internally)
1173 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1175 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1176 selection_possible = false;
1181 case LFUN_MOUSE_RELEASE: {
1182 // do nothing if we used the mouse wheel
1183 if (cmd.button() == mouse_button::button4
1184 || cmd.button() == mouse_button::button5) {
1185 cur.notdispatched();
1189 selection_possible = false;
1191 if (cmd.button() == mouse_button::button2)
1195 if (cmd.button() == mouse_button::button1)
1196 bv->haveSelection(cur.selection());
1199 bv->owner()->view_state_changed();
1200 bv->owner()->updateMenubar();
1201 bv->owner()->updateToolbar();
1205 case LFUN_SELFINSERT: {
1206 if (cmd.argument.empty())
1209 // Automatically delete the currently selected
1210 // text and replace it with what is being
1211 // typed in now. Depends on lyxrc settings
1212 // "auto_region_delete", which defaults to
1215 if (lyxrc.auto_region_delete) {
1216 if (cur.selection())
1217 cutSelection(cur, false, false);
1218 bv->haveSelection(false);
1221 cur.clearSelection();
1222 LyXFont const old_font = real_current_font;
1224 string::const_iterator cit = cmd.argument.begin();
1225 string::const_iterator end = cmd.argument.end();
1226 for (; cit != end; ++cit)
1227 bv->owner()->getIntl().getTransManager().
1228 TranslateAndInsert(*cit, this);
1231 moveCursor(cur, false);
1233 // real_current_font.number can change so we need to
1234 // update the minibuffer
1235 if (old_font != real_current_font)
1236 bv->owner()->view_state_changed();
1237 bv->updateScrollbar();
1242 InsetCommandParams p("url");
1243 string const data = InsetCommandMailer::params2string("url", p);
1244 bv->owner()->getDialogs().show("url", data, 0);
1248 case LFUN_HTMLURL: {
1249 InsetCommandParams p("htmlurl");
1250 string const data = InsetCommandMailer::params2string("url", p);
1251 bv->owner()->getDialogs().show("url", data, 0);
1255 case LFUN_INSERT_LABEL: {
1256 InsetCommandParams p("label");
1257 string const data = InsetCommandMailer::params2string("label", p);
1258 bv->owner()->getDialogs().show("label", data, 0);
1264 case LFUN_INSET_LIST:
1265 case LFUN_INSET_THEOREM:
1266 case LFUN_INSET_CAPTION:
1268 case LFUN_INSERT_NOTE:
1269 case LFUN_INSERT_CHARSTYLE:
1270 case LFUN_INSERT_BOX:
1271 case LFUN_INSERT_BRANCH:
1272 case LFUN_INSERT_BIBITEM:
1273 case LFUN_INSET_ERT:
1274 case LFUN_INSET_FLOAT:
1275 case LFUN_INSET_FOOTNOTE:
1276 case LFUN_INSET_MARGINAL:
1277 case LFUN_INSET_OPTARG:
1278 case LFUN_INSET_WIDE_FLOAT:
1279 case LFUN_INSET_WRAP:
1280 case LFUN_TABULAR_INSERT:
1281 case LFUN_ENVIRONMENT_INSERT:
1282 // Open the inset, and move the current selection
1284 doInsertInset(cur, this, cmd, true, true);
1287 case LFUN_INDEX_INSERT:
1288 // Just open the inset
1289 doInsertInset(cur, this, cmd, true, false);
1292 case LFUN_INDEX_PRINT:
1293 case LFUN_TOC_INSERT:
1295 case LFUN_INSERT_LINE:
1296 case LFUN_INSERT_PAGEBREAK:
1298 doInsertInset(cur, this, cmd, false, false);
1301 case LFUN_DEPTH_MIN:
1302 changeDepth(cur, bv_funcs::DEC_DEPTH);
1306 case LFUN_DEPTH_PLUS:
1307 changeDepth(cur, bv_funcs::INC_DEPTH);
1311 case LFUN_MATH_DISPLAY:
1312 mathDispatch(cur, this, cmd, true);
1315 case LFUN_MATH_IMPORT_SELECTION:
1316 case LFUN_MATH_MODE:
1317 mathDispatch(cur, this, cmd, false);
1320 case LFUN_MATH_MACRO:
1321 if (cmd.argument.empty())
1322 cur.errorMessage(N_("Missing argument"));
1324 string s = cmd.argument;
1325 string const s1 = token(s, ' ', 1);
1326 int const nargs = s1.empty() ? 0 : atoi(s1);
1327 string const s2 = token(s, ' ', 2);
1328 string const type = s2.empty() ? "newcommand" : s2;
1329 cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1330 cur.nextInset()->edit(cur, true);
1334 case LFUN_INSERT_MATH:
1335 case LFUN_INSERT_MATRIX:
1336 case LFUN_MATH_DELIM: {
1337 cur.insert(new MathHullInset);
1338 cur.dispatch(FuncRequest(LFUN_RIGHT));
1339 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1345 LyXFont font(LyXFont::ALL_IGNORE);
1346 font.setEmph(LyXFont::TOGGLE);
1347 toggleAndShow(cur, this, font);
1348 bv->owner()->view_state_changed();
1353 LyXFont font(LyXFont::ALL_IGNORE);
1354 font.setSeries(LyXFont::BOLD_SERIES);
1355 toggleAndShow(cur, this, font);
1356 bv->owner()->view_state_changed();
1361 LyXFont font(LyXFont::ALL_IGNORE);
1362 font.setNoun(LyXFont::TOGGLE);
1363 toggleAndShow(cur, this, font);
1364 bv->owner()->view_state_changed();
1369 LyXFont font(LyXFont::ALL_IGNORE);
1370 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1371 toggleAndShow(cur, this, font);
1372 bv->owner()->view_state_changed();
1377 LyXFont font(LyXFont::ALL_IGNORE);
1378 font.setFamily(LyXFont::SANS_FAMILY);
1379 toggleAndShow(cur, this, font);
1380 bv->owner()->view_state_changed();
1385 LyXFont font(LyXFont::ALL_IGNORE);
1386 font.setFamily(LyXFont::ROMAN_FAMILY);
1387 toggleAndShow(cur, this, font);
1388 bv->owner()->view_state_changed();
1392 case LFUN_DEFAULT: {
1393 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1394 toggleAndShow(cur, this, font);
1395 bv->owner()->view_state_changed();
1399 case LFUN_UNDERLINE: {
1400 LyXFont font(LyXFont::ALL_IGNORE);
1401 font.setUnderbar(LyXFont::TOGGLE);
1402 toggleAndShow(cur, this, font);
1403 bv->owner()->view_state_changed();
1407 case LFUN_FONT_SIZE: {
1408 LyXFont font(LyXFont::ALL_IGNORE);
1409 font.setLyXSize(cmd.argument);
1410 toggleAndShow(cur, this, font);
1411 bv->owner()->view_state_changed();
1415 case LFUN_LANGUAGE: {
1416 Language const * lang = languages.getLanguage(cmd.argument);
1419 LyXFont font(LyXFont::ALL_IGNORE);
1420 font.setLanguage(lang);
1421 toggleAndShow(cur, this, font);
1423 bv->owner()->view_state_changed();
1427 case LFUN_FREEFONT_APPLY:
1428 toggleAndShow(cur, this, freefont, toggleall);
1429 bv->owner()->view_state_changed();
1430 cur.message(_("Character set"));
1433 // Set the freefont using the contents of \param data dispatched from
1434 // the frontends and apply it at the current cursor location.
1435 case LFUN_FREEFONT_UPDATE: {
1438 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1441 toggleAndShow(cur, this, freefont, toggleall);
1442 bv->owner()->view_state_changed();
1443 cur.message(_("Character set"));
1448 case LFUN_FINISHED_LEFT:
1449 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1450 cur.pop(cur.currentDepth());
1451 if (isRTL(cur.paragraph()))
1453 cur.bv().cursor() = cur;
1456 case LFUN_FINISHED_RIGHT:
1457 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1458 cur.pop(cur.currentDepth());
1459 if (!isRTL(cur.paragraph()))
1461 cur.bv().cursor() = cur;
1464 case LFUN_FINISHED_UP:
1465 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1466 cur.pop(cur.currentDepth());
1468 cur.bv().cursor() = cur;
1471 case LFUN_FINISHED_DOWN:
1472 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1473 cur.pop(cur.currentDepth());
1475 cur.bv().cursor() = cur;
1478 case LFUN_LAYOUT_PARAGRAPH: {
1480 params2string(cur.paragraph(), data);
1481 data = "show\n" + data;
1482 bv->owner()->getDialogs().show("paragraph", data);
1486 case LFUN_PARAGRAPH_UPDATE: {
1487 if (!bv->owner()->getDialogs().visible("paragraph"))
1490 params2string(cur.paragraph(), data);
1492 // Will the paragraph accept changes from the dialog?
1493 InsetBase * const inset = cur.inset();
1495 !(inset && inset->forceDefaultParagraphs(inset));
1497 data = "update " + tostr(accept) + '\n' + data;
1498 bv->owner()->getDialogs().update("paragraph", data);
1503 case LFUN_CIRCUMFLEX:
1513 case LFUN_SPECIAL_CARON:
1516 case LFUN_HUNG_UMLAUT:
1519 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1520 if (!cmd.argument.empty())
1521 bv->owner()->getIntl().getTransManager()
1522 .TranslateAndInsert(cmd.argument[0], this);
1525 case LFUN_FLOAT_LIST: {
1526 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1527 if (tclass.floats().typeExist(cmd.argument)) {
1528 // not quite sure if we want this...
1531 cur.clearSelection();
1532 breakParagraph(cur);
1534 if (cur.lastpos() != 0) {
1536 breakParagraph(cur);
1539 setLayout(cur, tclass.defaultLayoutName());
1540 setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1541 cur.insert(new InsetFloatList(cmd.argument));
1544 lyxerr << "Non-existent float type: "
1545 << cmd.argument << endl;
1550 case LFUN_ACCEPT_CHANGE: {
1556 case LFUN_REJECT_CHANGE: {
1562 case LFUN_THESAURUS_ENTRY: {
1563 string arg = cmd.argument;
1565 arg = cur.selectionAsString(false);
1567 if (arg.size() > 100 || arg.empty()) {
1568 // Get word or selection
1569 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1570 arg = cur.selectionAsString(false);
1573 bv->owner()->getDialogs().show("thesaurus", arg);
1577 case LFUN_PARAGRAPH_APPLY: {
1578 // Given data, an encoding of the ParagraphParameters
1579 // generated in the Paragraph dialog, this function sets
1580 // the current paragraph appropriately.
1581 istringstream is(cmd.argument);
1584 ParagraphParameters params;
1589 params.labelWidthString(),
1592 cur.message(_("Paragraph layout set"));
1597 if (cur.selection())
1598 cur.selection() = false;
1600 cur.dispatched(FINISHED_LEFT);
1604 cur.notdispatched();
1610 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)