3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
21 #include "bufferparams.h"
22 #include "BufferView.h"
25 #include "dispatchresult.h"
27 #include "funcrequest.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
51 #include "mathed/formulabase.h"
55 using bv_funcs::replaceSelection;
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
65 using std::istringstream;
69 extern string current_layout;
70 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
72 // the selection possible is needed, that only motion events are
73 // used, where the bottom press event was on the drawing area too
74 bool selection_possible = false;
80 LyXFont freefont(LyXFont::ALL_IGNORE);
81 bool toggleall = false;
84 void toggleAndShow(BufferView * bv, LyXText * text,
85 LyXFont const & font, bool toggleall = true)
90 text->toggleFree(font, toggleall);
93 if (font.language() != ignore_language ||
94 font.number() != LyXFont::IGNORE) {
95 LyXCursor & cursor = text->cursor;
96 Paragraph & par = *text->cursorPar();
97 text->bidi.computeTables(par, *bv->buffer(),
98 *par.getRow(cursor.pos()));
99 if (cursor.boundary() !=
100 text->bidi.isBoundary(*bv->buffer(), par,
102 text->real_current_font))
103 text->setCursor(cursor.par(), cursor.pos(),
104 false, !cursor.boundary());
109 /// Apply the contents of freefont at the current cursor location.
110 void apply_freefont(BufferView * bv, LyXText * text)
112 toggleAndShow(bv, text, freefont, toggleall);
113 bv->owner()->view_state_changed();
114 bv->owner()->message(_("Character set"));
118 /** Set the freefont using the contents of \param data dispatched from
119 * the frontends and apply it at the current cursor location.
121 void update_and_apply_freefont(BufferView * bv, LyXText * text,
126 if (bv_funcs::string2font(data, font, toggle)) {
129 apply_freefont(bv, text);
134 void emph(BufferView * bv, LyXText * text)
136 LyXFont font(LyXFont::ALL_IGNORE);
137 font.setEmph(LyXFont::TOGGLE);
138 toggleAndShow(bv, text, font);
142 void bold(BufferView * bv, LyXText * text)
144 LyXFont font(LyXFont::ALL_IGNORE);
145 font.setSeries(LyXFont::BOLD_SERIES);
146 toggleAndShow(bv, text, font);
150 void noun(BufferView * bv, LyXText * text)
152 LyXFont font(LyXFont::ALL_IGNORE);
153 font.setNoun(LyXFont::TOGGLE);
154 toggleAndShow(bv, text, font);
158 void lang(BufferView * bv, string const & l, LyXText * text)
160 Language const * lang = languages.getLanguage(l);
164 LyXFont font(LyXFont::ALL_IGNORE);
165 font.setLanguage(lang);
166 toggleAndShow(bv, text, font);
170 void code(BufferView * bv, LyXText * text)
172 LyXFont font(LyXFont::ALL_IGNORE);
173 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
174 toggleAndShow(bv, text, font);
178 void sans(BufferView * bv, LyXText * text)
180 LyXFont font(LyXFont::ALL_IGNORE);
181 font.setFamily(LyXFont::SANS_FAMILY);
182 toggleAndShow(bv, text, font);
186 void roman(BufferView * bv, LyXText * text)
188 LyXFont font(LyXFont::ALL_IGNORE);
189 font.setFamily(LyXFont::ROMAN_FAMILY);
190 toggleAndShow(bv, text, font);
194 void styleReset(BufferView * bv, LyXText * text)
196 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
197 toggleAndShow(bv, text, font);
201 void underline(BufferView * bv, LyXText * text)
203 LyXFont font(LyXFont::ALL_IGNORE);
204 font.setUnderbar(LyXFont::TOGGLE);
205 toggleAndShow(bv, text, font);
209 void fontSize(BufferView * bv, string const & size, LyXText * text)
211 LyXFont font(LyXFont::ALL_IGNORE);
212 font.setLyXSize(size);
213 toggleAndShow(bv, text, font);
217 void moveCursor(BufferView * bv, bool selecting)
219 LyXText * lt = bv->getLyXText();
221 // if (!lt->selection.set())
222 // lt->selection.cursor = lt->cursor;
224 if (selecting || lt->selection.mark())
227 if (!lt->selection.set())
228 bv->haveSelection(false);
233 void finishChange(BufferView * bv, bool selecting = false)
236 moveCursor(bv, selecting);
237 bv->owner()->view_state_changed();
245 string const freefont2string()
248 if (font2string(freefont, toggleall, data))
257 InsetOld * LyXText::checkInsetHit(int x, int y)
259 ParagraphList::iterator pit;
260 ParagraphList::iterator end;
262 getParsInRange(ownerParagraphs(),
264 bv()->top_y() - yo_ + bv()->workHeight(),
267 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
268 for ( ; pit != end; ++pit) {
269 InsetList::iterator iit = pit->insetlist.begin();
270 InsetList::iterator iend = pit->insetlist.end();
271 for ( ; iit != iend; ++iit) {
272 InsetOld * inset = iit->inset;
273 //lyxerr << "examining inset " << inset
274 // << " xy: " << inset->x() << "/" << inset->y()
275 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
276 // << " y: " << inset->y() - inset->ascent() << "..."
277 // << inset->y() + inset->descent()
280 && x <= inset->x() + inset->width()
281 && y >= inset->y() - inset->ascent()
282 && y <= inset->y() + inset->descent())
284 lyxerr << "Hit inset: " << inset << endl;
289 lyxerr << "No inset hit. " << endl;
294 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
295 string const & contents)
297 ParagraphList::iterator end = ownerParagraphs().end();
298 ParagraphList::iterator pit = cursorPar();
299 pos_type pos = cursor.pos();
303 if (pos + 1 < pit->size()) {
310 } while (pit != end &&
311 !(pit->isInset(pos) &&
312 (inset = pit->getInset(pos)) != 0 &&
313 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
315 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
321 setCursor(parOffset(pit), pos, false);
326 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
332 if (same_content && cursor.pos() < cursorPar()->size()
333 && cursorPar()->isInset(cursor.pos())) {
334 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
335 if (find(codes.begin(), codes.end(), inset->lyxCode())
337 contents = static_cast<InsetCommand const *>(inset)->getContents();
340 if (!gotoNextInset(codes, contents)) {
341 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
342 LyXCursor tmp = cursor;
345 if (!gotoNextInset(codes, contents)) {
347 bv()->owner()->message(_("No more insets"));
350 bv()->owner()->message(_("No more insets"));
354 selection.cursor = cursor;
358 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
360 gotoInset(vector<InsetOld::Code>(1, code), same_content);
364 void LyXText::cursorPrevious()
367 RowList::iterator crit = cursorRow();
369 int x = bv()->x_target() - xo_;
370 int y = bv()->top_y() - yo_;
371 setCursorFromCoordinates(x, y);
373 if (crit == cursorRow()) {
374 // we have a row which is taller than the workarea. The
375 // simplest solution is to move to the previous row instead.
379 bv()->updateScrollbar();
384 void LyXText::cursorNext()
386 RowList::iterator crit = cursorRow();
388 int x = bv()->x_target() - xo_;
389 int y = bv()->top_y() + bv()->workHeight() - yo_;
390 setCursorFromCoordinates(x, y);
392 if (crit == cursorRow()) {
393 // we have a row which is taller than the workarea. The
394 // simplest solution is to move to the next row instead.
398 bv()->updateScrollbar();
405 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
408 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
409 replaceSelection(lt);
410 if (!bv->insertInset(new_inset))
417 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
418 bool edit, bool pastesel)
420 InsetOld * inset = createInset(cmd);
421 BufferView * bv = cmd.view();
425 if (lt->selection.set()) {
426 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
429 if (bv->insertInset(inset)) {
431 inset->edit(bv, true);
432 if (gotsel && pastesel)
433 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
442 void LyXText::number()
444 LyXFont font(LyXFont::ALL_IGNORE);
445 font.setNumber(LyXFont::TOGGLE);
446 toggleAndShow(bv(), this, font);
450 bool LyXText::rtl() const
452 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
456 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
458 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
459 lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
461 BufferView * bv = cmd.view();
463 switch (cmd.action) {
465 case LFUN_APPENDIX: {
466 ParagraphList::iterator pit = cursorPar();
467 bool start = !pit->params().startOfAppendix();
469 // ensure that we have only one start_of_appendix in this document
470 ParagraphList::iterator tmp = ownerParagraphs().begin();
471 ParagraphList::iterator end = ownerParagraphs().end();
473 for (; tmp != end; ++tmp) {
474 if (tmp->params().startOfAppendix()) {
475 recUndo(parOffset(tmp));
476 tmp->params().startOfAppendix(false);
482 recUndo(parOffset(pit));
483 pit->params().startOfAppendix(start);
485 // we can set the refreshing parameters now
487 redoParagraph(cursorPar());
488 setCursor(cursorPar(), cursor.pos());
493 case LFUN_DELETE_WORD_FORWARD:
499 case LFUN_DELETE_WORD_BACKWARD:
501 deleteWordBackward();
505 case LFUN_DELETE_LINE_FORWARD:
512 if (!selection.mark())
517 cursorRightOneWord();
522 if (!selection.mark())
525 cursorRightOneWord();
531 case LFUN_BEGINNINGBUF:
532 if (!selection.mark())
539 if (selection.mark())
546 if (!selection.set())
547 selection.cursor = cursor;
552 finishChange(bv, true);
556 if (!selection.set())
557 selection.cursor = cursor;
562 finishChange(bv, true);
566 if (!selection.set())
567 selection.cursor = cursor;
569 finishChange(bv, true);
573 if (!selection.set())
574 selection.cursor = cursor;
576 finishChange(bv, true);
579 case LFUN_UP_PARAGRAPHSEL:
580 if (!selection.set())
581 selection.cursor = cursor;
583 finishChange(bv, true);
586 case LFUN_DOWN_PARAGRAPHSEL:
587 if (!selection.set())
588 selection.cursor = cursor;
589 cursorDownParagraph();
590 finishChange(bv, true);
594 if (!selection.set())
595 selection.cursor = cursor;
597 finishChange(bv, true);
601 if (!selection.set())
602 selection.cursor = cursor;
604 finishChange(bv, true);
608 if (!selection.set())
609 selection.cursor = cursor;
611 finishChange(bv, true);
615 if (!selection.set())
616 selection.cursor = cursor;
618 finishChange(bv, true);
621 case LFUN_WORDRIGHTSEL:
625 cursorRightOneWord();
626 finishChange(bv, true);
629 case LFUN_WORDLEFTSEL:
631 cursorRightOneWord();
634 finishChange(bv, true);
638 LyXCursor cur1 = cursor;
640 getWord(cur1, cur2, lyx::WHOLE_WORD);
641 setCursor(cur1.par(), cur1.pos());
643 setCursor(cur2.par(), cur2.pos());
644 finishChange(bv, true);
664 case LFUN_UP_PARAGRAPH:
665 if (!selection.mark())
671 case LFUN_DOWN_PARAGRAPH:
672 if (!selection.mark())
674 cursorDownParagraph();
675 finishChange(bv, false);
679 if (!selection.mark())
681 finishChange(bv, false);
682 if (cursorRow() == firstRow())
683 return DispatchResult(false, FINISHED_UP);
688 if (!selection.mark())
690 finishChange(bv, false);
691 if (cursorRow() == lastRow())
692 return DispatchResult(false, FINISHED_DOWN);
697 if (!selection.mark())
700 finishChange(bv, false);
704 if (!selection.mark())
707 finishChange(bv, false);
710 case LFUN_BREAKLINE: {
711 lyx::pos_type body = cursorPar()->beginOfBody();
713 // Not allowed by LaTeX (labels or empty par)
714 if (cursor.pos() <= body)
717 replaceSelection(bv->getLyXText());
718 insertInset(new InsetNewline);
719 setCursor(cursorPar(), cursor.pos());
720 moveCursor(bv, false);
725 if (!selection.set()) {
727 selection.cursor = cursor;
728 // It is possible to make it a lot faster still
729 // just comment out the line below...
731 cutSelection(true, false);
733 moveCursor(bv, false);
734 bv->owner()->view_state_changed();
737 case LFUN_DELETE_SKIP:
738 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
739 if (!selection.set()) {
740 if (cursor.pos() == cursorPar()->size()) {
742 ParagraphParameters & params = cursorPar()->params();
743 if (cursor.pos() == 0
744 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
746 VSpace(VSpace::NONE),
747 params.spaceBottom(),
750 params.labelWidthString(), 0);
755 selection.cursor = cursor;
759 selection.cursor = cursor;
762 cutSelection(true, false);
769 if (!selection.set()) {
770 if (bv->owner()->getIntl().getTransManager().backspace()) {
772 selection.cursor = cursor;
773 // It is possible to make it a lot faster still
774 // just comment out the line below...
777 cutSelection(true, false);
779 bv->owner()->view_state_changed();
784 case LFUN_BACKSPACE_SKIP:
785 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
786 if (!selection.set()) {
787 ParagraphParameters & params = cursorPar()->params();
788 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
790 VSpace(VSpace::NONE),
791 params.spaceBottom(),
794 params.labelWidthString(), 0);
796 LyXCursor cur = cursor;
798 selection.cursor = cur;
801 cutSelection(true, false);
806 case LFUN_BREAKPARAGRAPH:
807 replaceSelection(bv->getLyXText());
808 breakParagraph(bv->buffer()->paragraphs(), 0);
810 selection.cursor = cursor;
812 bv->owner()->view_state_changed();
815 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
816 replaceSelection(bv->getLyXText());
817 breakParagraph(bv->buffer()->paragraphs(), 1);
819 selection.cursor = cursor;
821 bv->owner()->view_state_changed();
824 case LFUN_BREAKPARAGRAPH_SKIP: {
825 // When at the beginning of a paragraph, remove
826 // indentation and add a "defskip" at the top.
827 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
828 LyXCursor cur = cursor;
829 replaceSelection(bv->getLyXText());
830 if (cur.pos() == 0) {
831 ParagraphParameters & params = getPar(cur)->params();
832 if (params.spaceTop() == VSpace(VSpace::NONE)) {
834 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
837 params.labelWidthString(), 1);
841 breakParagraph(bv->buffer()->paragraphs(), 0);
844 selection.cursor = cur;
846 bv->owner()->view_state_changed();
850 case LFUN_PARAGRAPH_SPACING: {
851 ParagraphList::iterator pit = cursorPar();
852 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
853 float cur_value = 1.0;
854 if (cur_spacing == Spacing::Other)
855 cur_value = pit->params().spacing().getValue();
857 istringstream is(cmd.argument);
860 Spacing::Space new_spacing = cur_spacing;
861 float new_value = cur_value;
863 lyxerr << "Missing argument to `paragraph-spacing'"
865 } else if (tmp == "single") {
866 new_spacing = Spacing::Single;
867 } else if (tmp == "onehalf") {
868 new_spacing = Spacing::Onehalf;
869 } else if (tmp == "double") {
870 new_spacing = Spacing::Double;
871 } else if (tmp == "other") {
872 new_spacing = Spacing::Other;
875 lyxerr << "new_value = " << tmpval << endl;
878 } else if (tmp == "default") {
879 new_spacing = Spacing::Default;
881 lyxerr << _("Unknown spacing argument: ")
882 << cmd.argument << endl;
884 if (cur_spacing != new_spacing || cur_value != new_value) {
885 pit->params().spacing(Spacing(new_spacing, new_value));
892 case LFUN_INSET_APPLY: {
893 string const name = cmd.getArg(0);
894 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
896 FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
899 FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
905 case LFUN_INSET_INSERT: {
906 InsetOld * inset = createInset(cmd);
907 if (!inset || !bv->insertInset(inset))
912 case LFUN_INSET_SETTINGS:
913 bv->cursor().innerInset()->showInsetDialog(bv);
916 case LFUN_INSET_TOGGLE:
923 case LFUN_SPACE_INSERT:
924 if (cursorPar()->layout()->free_spacing)
927 doInsertInset(this, cmd, false, false);
928 moveCursor(bv, false);
931 case LFUN_HYPHENATION:
932 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
935 case LFUN_LIGATURE_BREAK:
936 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
940 specialChar(this, bv, InsetSpecialChar::LDOTS);
943 case LFUN_END_OF_SENTENCE:
944 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
947 case LFUN_MENU_SEPARATOR:
948 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
954 selection.cursor = cursor;
955 cmd.message(N_("Mark off"));
960 selection.mark(true);
962 selection.cursor = cursor;
963 cmd.message(N_("Mark on"));
968 if (selection.mark()) {
969 cmd.message(N_("Mark removed"));
971 selection.mark(true);
972 cmd.message(N_("Mark set"));
974 selection.cursor = cursor;
978 case LFUN_UPCASE_WORD:
979 changeCase(LyXText::text_uppercase);
983 case LFUN_LOWCASE_WORD:
984 changeCase(LyXText::text_lowercase);
988 case LFUN_CAPITALIZE_WORD:
989 changeCase(LyXText::text_capitalization);
993 case LFUN_TRANSPOSE_CHARS:
994 recUndo(cursor.par());
1000 cmd.message(_("Paste"));
1001 replaceSelection(bv->getLyXText());
1002 #warning FIXME Check if the arg is in the domain of available selections.
1003 if (isStrUnsignedInt(cmd.argument))
1004 pasteSelection(strToUnsignedInt(cmd.argument));
1007 clearSelection(); // bug 393
1014 cutSelection(true, true);
1015 cmd.message(_("Cut"));
1021 cmd.message(_("Copy"));
1024 case LFUN_BEGINNINGBUFSEL:
1026 return DispatchResult(false);
1028 finishChange(bv, true);
1031 case LFUN_ENDBUFSEL:
1033 return DispatchResult(false);
1035 finishChange(bv, true);
1039 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1045 istringstream is(cmd.argument);
1048 lyxerr << "SETXY: Could not parse coordinates in '"
1049 << cmd.argument << std::endl;
1051 setCursorFromCoordinates(x, y);
1056 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1058 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1064 case LFUN_GETLAYOUT:
1065 cmd.message(tostr(cursorPar()->layout()));
1069 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1070 << cmd.argument << endl;
1072 // This is not the good solution to the empty argument
1073 // problem, but it will hopefully suffice for 1.2.0.
1074 // The correct solution would be to augument the
1075 // function list/array with information about what
1076 // functions needs arguments and their type.
1077 if (cmd.argument.empty()) {
1078 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1082 // Derive layout number from given argument (string)
1083 // and current buffer's textclass (number)
1084 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1085 bool hasLayout = tclass.hasLayout(cmd.argument);
1086 string layout = cmd.argument;
1088 // If the entry is obsolete, use the new one instead.
1090 string const & obs = tclass[layout]->obsoleted_by();
1096 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1101 bool change_layout = (current_layout != layout);
1103 if (!change_layout && selection.set() &&
1104 selection.start.par() != selection.end.par())
1106 ParagraphList::iterator spit = getPar(selection.start);
1107 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1108 while (spit != epit) {
1109 if (spit->layout()->name() != current_layout) {
1110 change_layout = true;
1117 if (change_layout) {
1118 current_layout = layout;
1120 bv->owner()->setLayout(layout);
1127 case LFUN_PASTESELECTION: {
1128 // this was originally a bv->text->clearSelection(), i.e
1129 // the outermost LyXText!
1131 string const clip = bv->getClipboard();
1132 if (!clip.empty()) {
1133 if (cmd.argument == "paragraph")
1134 insertStringAsParagraphs(clip);
1136 insertStringAsLines(clip);
1142 case LFUN_GOTOERROR:
1143 gotoInset(InsetOld::ERROR_CODE, false);
1147 gotoInset(InsetOld::NOTE_CODE, false);
1150 case LFUN_REFERENCE_GOTO: {
1151 vector<InsetOld::Code> tmp;
1152 tmp.push_back(InsetOld::LABEL_CODE);
1153 tmp.push_back(InsetOld::REF_CODE);
1154 gotoInset(tmp, true);
1159 replaceSelection(bv->getLyXText());
1160 ParagraphList::iterator pit = cursorPar();
1161 lyx::pos_type pos = cursor.pos();
1165 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1168 c = pit->getChar(pos - 1);
1170 LyXLayout_ptr const & style = pit->layout();
1172 BufferParams const & bufparams = bv->buffer()->params();
1173 if (style->pass_thru ||
1174 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1175 !bv->insertInset(new InsetQuotes(c, bufparams)))
1176 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1180 case LFUN_DATE_INSERT: {
1181 replaceSelection(bv->getLyXText());
1182 time_t now_time_t = time(NULL);
1183 struct tm * now_tm = localtime(&now_time_t);
1184 setlocale(LC_TIME, "");
1186 if (!cmd.argument.empty())
1189 arg = lyxrc.date_insert_format;
1191 int const datetmp_len =
1192 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1194 for (int i = 0; i < datetmp_len; i++)
1195 insertChar(datetmp[i]);
1197 selection.cursor = cursor;
1198 moveCursor(bv, false);
1202 case LFUN_MOUSE_TRIPLE:
1205 if (cmd.button() == mouse_button::button1) {
1207 selection.cursor = cursor;
1210 bv->haveSelection(selection.set());
1214 case LFUN_MOUSE_DOUBLE:
1217 if (cmd.button() == mouse_button::button1) {
1218 selectWord(lyx::WHOLE_WORD_STRICT);
1219 bv->haveSelection(selection.set());
1223 case LFUN_MOUSE_MOTION: {
1224 // Only use motion with button 1
1225 //if (ev.button() != mouse_button::button1)
1230 // The test for not selection possible is needed, that
1231 // only motion events are used, where the bottom press
1232 // event was on the drawing area too
1233 if (!selection_possible) {
1234 lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1235 "Dispatch: no selection possible\n";
1238 RowList::iterator cursorrow = cursorRow();
1240 setCursorFromCoordinates(cmd.x, cmd.y);
1242 // This is to allow jumping over large insets
1243 // FIXME: shouldn't be top-text-specific
1244 if (cursorrow == cursorRow() && !in_inset_) {
1245 if (cmd.y - bv->top_y() >= bv->workHeight())
1247 else if (cmd.y - bv->top_y() < 0)
1254 // Single-click on work area
1255 case LFUN_MOUSE_PRESS: {
1259 // ok ok, this is a hack (for xforms)
1260 // We shouldn't go further down as we really should only do the
1261 // scrolling and be done with this. Otherwise we may open some
1262 // dialogs (Jug 20020424).
1263 if (cmd.button() == mouse_button::button4) {
1264 bv->scroll(-lyxrc.wheel_jump);
1267 if (cmd.button() == mouse_button::button5) {
1268 bv->scroll(lyxrc.wheel_jump);
1272 // Middle button press pastes if we have a selection
1273 // We do this here as if the selection was inside an inset
1274 // it could get cleared on the unlocking of the inset so
1275 // we have to check this first
1276 bool paste_internally = false;
1277 if (cmd.button() == mouse_button::button2 && selection.set()) {
1278 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1279 paste_internally = true;
1282 selection_possible = true;
1284 // Clear the selection
1287 // Right click on a footnote flag opens float menu
1288 if (cmd.button() == mouse_button::button3) {
1289 selection_possible = false;
1293 setCursorFromCoordinates(cmd.x, cmd.y);
1294 selection.cursor = cursor;
1296 bv->x_target(cursor.x() + xo_);
1298 if (bv->fitCursor())
1299 selection_possible = false;
1301 // Insert primary selection with middle mouse
1302 // if there is a local selection in the current buffer,
1304 if (cmd.button() == mouse_button::button2) {
1305 if (paste_internally)
1306 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1308 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1309 selection_possible = false;
1314 case LFUN_MOUSE_RELEASE: {
1318 // do nothing if we used the mouse wheel
1319 if (cmd.button() == mouse_button::button4
1320 || cmd.button() == mouse_button::button5)
1321 return DispatchResult(true, false);
1323 selection_possible = false;
1325 if (cmd.button() == mouse_button::button2)
1329 if (cmd.button() == mouse_button::button1)
1330 bv->haveSelection(selection.set());
1333 bv->owner()->view_state_changed();
1334 bv->owner()->updateMenubar();
1335 bv->owner()->updateToolbar();
1339 case LFUN_SELFINSERT: {
1340 if (cmd.argument.empty())
1343 // Automatically delete the currently selected
1344 // text and replace it with what is being
1345 // typed in now. Depends on lyxrc settings
1346 // "auto_region_delete", which defaults to
1349 if (lyxrc.auto_region_delete) {
1350 if (selection.set())
1351 cutSelection(false, false);
1352 bv->haveSelection(false);
1356 LyXFont const old_font = real_current_font;
1358 string::const_iterator cit = cmd.argument.begin();
1359 string::const_iterator end = cmd.argument.end();
1360 for (; cit != end; ++cit)
1361 bv->owner()->getIntl().getTransManager().
1362 TranslateAndInsert(*cit, this);
1364 selection.cursor = cursor;
1365 moveCursor(bv, false);
1367 // real_current_font.number can change so we need to
1368 // update the minibuffer
1369 if (old_font != real_current_font)
1370 bv->owner()->view_state_changed();
1371 bv->updateScrollbar();
1376 InsetCommandParams p("url");
1377 string const data = InsetCommandMailer::params2string("url", p);
1378 bv->owner()->getDialogs().show("url", data, 0);
1382 case LFUN_HTMLURL: {
1383 InsetCommandParams p("htmlurl");
1384 string const data = InsetCommandMailer::params2string("url", p);
1385 bv->owner()->getDialogs().show("url", data, 0);
1389 case LFUN_INSERT_LABEL: {
1390 InsetCommandParams p("label");
1391 string const data = InsetCommandMailer::params2string("label", p);
1392 bv->owner()->getDialogs().show("label", data, 0);
1398 case LFUN_INSET_LIST:
1399 case LFUN_INSET_THEOREM:
1400 case LFUN_INSET_CAPTION:
1402 case LFUN_INSERT_NOTE:
1403 case LFUN_INSERT_CHARSTYLE:
1404 case LFUN_INSERT_BOX:
1405 case LFUN_INSERT_BRANCH:
1406 case LFUN_INSERT_BIBITEM:
1407 case LFUN_INSET_ERT:
1408 case LFUN_INSET_FLOAT:
1409 case LFUN_INSET_FOOTNOTE:
1410 case LFUN_INSET_MARGINAL:
1411 case LFUN_INSET_MINIPAGE:
1412 case LFUN_INSET_OPTARG:
1413 case LFUN_INSET_WIDE_FLOAT:
1414 case LFUN_INSET_WRAP:
1415 case LFUN_TABULAR_INSERT:
1416 case LFUN_ENVIRONMENT_INSERT:
1417 // Open the inset, and move the current selection
1419 doInsertInset(this, cmd, true, true);
1422 case LFUN_INDEX_INSERT:
1423 // Just open the inset
1424 doInsertInset(this, cmd, true, false);
1427 case LFUN_INDEX_PRINT:
1428 case LFUN_TOC_INSERT:
1430 case LFUN_INSERT_LINE:
1431 case LFUN_INSERT_PAGEBREAK:
1433 doInsertInset(this, cmd, false, false);
1436 case LFUN_DEPTH_MIN:
1438 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1442 case LFUN_DEPTH_PLUS:
1444 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1448 case LFUN_MATH_DELIM:
1449 case LFUN_MATH_DISPLAY:
1450 case LFUN_INSERT_MATH:
1451 case LFUN_MATH_LIMITS:
1452 case LFUN_MATH_MACRO:
1453 case LFUN_MATH_MUTATE:
1454 case LFUN_MATH_SPACE:
1455 case LFUN_MATH_IMPORT_SELECTION:
1456 case LFUN_MATH_MODE:
1457 case LFUN_MATH_NONUMBER:
1458 case LFUN_MATH_NUMBER:
1459 case LFUN_MATH_EXTERN:
1460 case LFUN_MATH_SIZE:
1466 bv->owner()->view_state_changed();
1471 bv->owner()->view_state_changed();
1476 bv->owner()->view_state_changed();
1481 bv->owner()->view_state_changed();
1486 bv->owner()->view_state_changed();
1491 bv->owner()->view_state_changed();
1495 styleReset(bv, this);
1496 bv->owner()->view_state_changed();
1499 case LFUN_UNDERLINE:
1500 underline(bv, this);
1501 bv->owner()->view_state_changed();
1504 case LFUN_FONT_SIZE:
1505 fontSize(bv, cmd.argument, this);
1506 bv->owner()->view_state_changed();
1510 lang(bv, cmd.argument, this);
1512 bv->owner()->view_state_changed();
1515 case LFUN_FREEFONT_APPLY:
1516 apply_freefont(bv, this);
1519 case LFUN_FREEFONT_UPDATE:
1520 update_and_apply_freefont(bv, this, cmd.argument);
1523 case LFUN_FINISHED_LEFT:
1524 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1529 case LFUN_FINISHED_RIGHT:
1530 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1535 case LFUN_FINISHED_UP:
1536 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1540 case LFUN_FINISHED_DOWN:
1541 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1546 return DispatchResult(false);
1549 return DispatchResult(true, true);