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"
24 #include "dispatchresult.h"
26 #include "funcrequest.h"
32 #include "paragraph.h"
33 #include "ParagraphParameters.h"
34 #include "text_funcs.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/LyXView.h"
41 #include "insets/insetcommand.h"
42 #include "insets/insetnewline.h"
43 #include "insets/insetspecialchar.h"
44 #include "insets/insettext.h"
46 #include "support/lstrings.h"
47 #include "support/tostr.h"
49 #include "support/std_sstream.h"
52 using bv_funcs::replaceSelection;
56 using lyx::support::isStrUnsignedInt;
57 using lyx::support::strToUnsignedInt;
62 using std::istringstream;
66 extern string current_layout;
67 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
69 // the selection possible is needed, that only motion events are
70 // used, where the bottom press event was on the drawing area too
71 bool selection_possible = false;
76 void moveCursorUpdate(BufferView * bv, bool selecting)
78 LyXText * lt = bv->getLyXText();
80 // if (!lt->selection.set())
81 // lt->selection.cursor = lt->cursor;
83 if (selecting || lt->selection.mark())
86 if (!lt->selection.set())
87 bv->haveSelection(false);
94 void finishChange(BufferView * bv, bool selecting = false)
97 moveCursorUpdate(bv, selecting);
98 bv->owner()->view_state_changed();
101 // check if the given co-ordinates are inside an inset at the
102 // given cursor, if one exists. If so, the inset is returned,
103 // and the co-ordinates are made relative. Otherwise, 0 is returned.
104 InsetOld * checkInset(LyXText & text,
105 LyXCursor const & cur, int & x, int & y)
107 lyx::pos_type const pos = cur.pos();
108 ParagraphList::iterator par = text.getPar(cur);
110 if (pos >= par->size() || !par->isInset(pos))
113 InsetOld /*const*/ * inset = par->getInset(pos);
115 if (!isEditableInset(inset))
118 // get inset dimensions
119 BOOST_ASSERT(par->getInset(pos));
121 LyXFont const & font = text.getFont(par, pos);
123 int const width = inset->width();
124 int const inset_x = font.isVisibleRightToLeft()
125 ? (cur.x() - width) : cur.x();
128 inset_x + inset->scroll(),
130 cur.y() - inset->ascent(),
131 cur.y() + inset->descent()
134 if (!b.contains(x, y)) {
135 lyxerr[Debug::GUI] << "Missed inset at x,y "
137 << " box " << b << endl;
141 text.setCursor(cur.par(), pos, true);
144 // The origin of an inset is on the baseline
145 y -= text.cursor.y();
153 InsetOld * LyXText::checkInsetHit(int & x, int & y)
155 int y_tmp = y + bv_owner->top_y();
158 setCursorFromCoordinates(cur, x, y_tmp);
160 InsetOld * inset = checkInset(*this, cur, x, y_tmp);
166 // look at previous position
171 setCursor(cur, cur.par(), cur.pos() - 1, true);
173 inset = checkInset(*this, cur, x, y_tmp);
180 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
181 string const & contents)
183 ParagraphList::iterator end = ownerParagraphs().end();
184 ParagraphList::iterator pit = cursorPar();
185 pos_type pos = cursor.pos();
189 if (pos + 1 < pit->size()) {
196 } while (pit != end &&
197 !(pit->isInset(pos) &&
198 (inset = pit->getInset(pos)) != 0 &&
199 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
201 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
207 setCursor(parOffset(pit), pos, false);
212 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
215 bv()->beforeChange(this);
218 if (same_content && cursor.pos() < cursorPar()->size()
219 && cursorPar()->isInset(cursor.pos())) {
220 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
221 if (find(codes.begin(), codes.end(), inset->lyxCode())
223 contents = static_cast<InsetCommand const *>(inset)->getContents();
226 if (!gotoNextInset(codes, contents)) {
227 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
228 LyXCursor tmp = cursor;
231 if (!gotoNextInset(codes, contents)) {
233 bv()->owner()->message(_("No more insets"));
236 bv()->owner()->message(_("No more insets"));
240 selection.cursor = cursor;
244 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
246 gotoInset(vector<InsetOld::Code>(1, code), same_content);
250 void LyXText::cursorPrevious()
252 int y = bv()->top_y();
254 ParagraphList::iterator cpit = cursorPar();
255 RowList::iterator crit = cpit->getRow(cursor.pos());
257 if (isFirstRow(cpit, *crit)) {
259 bv()->updateScrollbar();
263 setCursorFromCoordinates(cursor.x_fix(), y);
266 if (crit == bv()->text->cursorRow()) {
267 // we have a row which is taller than the workarea. The
268 // simplest solution is to move to the previous row instead.
273 int new_y = + crit->height() - bv()->workHeight() + 1;
276 new_y += bv()->text->cursor.y()
277 + bv()->theLockingInset()->insetInInsetY() + y;
279 new_y += cursor.y() - crit->baseline();
282 previousRow(cpit, crit);
284 setCursor(cur, parOffset(cpit), crit->pos(), false);
285 if (cur.y() > bv()->top_y())
287 bv()->updateScrollbar();
291 void LyXText::cursorNext()
293 int topy = bv()->top_y();
295 ParagraphList::iterator cpit = cursorPar();
296 RowList::iterator crit = cpit->getRow(cursor.pos());
298 if (isLastRow(cpit, *crit)) {
299 int y = cursor.y() - crit->baseline() + crit->height();
300 if (y > topy + bv()->workHeight())
301 bv()->updateScrollbar();
305 int y = topy + bv()->workHeight();
306 if (inset_owner && !topy) {
307 y -= (bv()->text->cursor.y()
309 + bv()->theLockingInset()->insetInInsetY());
312 ParagraphList::iterator dummypit;
313 Row const & rr = *getRowNearY(y, dummypit);
314 y = dummypit->y + rr.y_offset();
316 setCursorFromCoordinates(cursor.x_fix(), y);
317 // + bv->workHeight());
321 if (crit == bv()->text->cursorRow()) {
322 // we have a row which is taller than the workarea. The
323 // simplest solution is to move to the next row instead.
326 // This is what we used to do, so we wouldn't skip right past
327 // tall rows, but it's not working right now.
329 new_y = bv->top_y() + bv->workHeight();
334 new_y = bv()->text->cursor.y()
335 + bv()->theLockingInset()->insetInInsetY()
336 + y - crit->baseline();
338 new_y = cursor.y() - crit->baseline();
344 setCursor(cur, parOffset(cpit), crit->pos(), false);
345 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
347 bv()->updateScrollbar();
353 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
356 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
357 replaceSelection(lt);
358 if (!bv->insertInset(new_inset))
361 bv->updateInset(new_inset);
365 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
366 bool edit, bool pastesel)
368 InsetOld * inset = createInset(cmd);
369 BufferView * bv = cmd.view();
373 if (lt->selection.set()) {
374 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
377 if (bv->insertInset(inset)) {
379 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
380 inset->dispatch(cmd);
382 if (gotsel && pastesel)
383 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
393 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
395 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
396 <<"] arg[" << cmd.argument << ']' << "xy[" <<
397 cmd.x << ',' << cmd.y << ']' << endl;
399 BufferView * bv = cmd.view();
401 switch (cmd.action) {
403 case LFUN_APPENDIX: {
404 ParagraphList::iterator pit = cursorPar();
405 bool start = !pit->params().startOfAppendix();
407 // ensure that we have only one start_of_appendix in this document
408 ParagraphList::iterator tmp = ownerParagraphs().begin();
409 ParagraphList::iterator end = ownerParagraphs().end();
411 for (; tmp != end; ++tmp) {
412 if (tmp->params().startOfAppendix()) {
413 recUndo(parOffset(tmp));
414 tmp->params().startOfAppendix(false);
420 recUndo(parOffset(pit));
421 pit->params().startOfAppendix(start);
423 // we can set the refreshing parameters now
425 redoParagraph(cursorPar());
426 setCursor(cursorPar(), cursor.pos());
431 case LFUN_DELETE_WORD_FORWARD:
432 bv->beforeChange(this);
437 case LFUN_DELETE_WORD_BACKWARD:
438 bv->beforeChange(this);
439 deleteWordBackward();
443 case LFUN_DELETE_LINE_FORWARD:
444 bv->beforeChange(this);
450 if (!selection.mark())
451 bv->beforeChange(this);
452 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
455 cursorRightOneWord();
460 if (!selection.mark())
461 bv->beforeChange(this);
462 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
463 cursorRightOneWord();
469 case LFUN_BEGINNINGBUF:
470 if (!selection.mark())
471 bv->beforeChange(this);
477 if (selection.mark())
478 bv->beforeChange(this);
484 if (!selection.set())
485 selection.cursor = cursor;
486 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
490 finishChange(bv, true);
494 if (!selection.set())
495 selection.cursor = cursor;
496 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
500 finishChange(bv, true);
504 if (!selection.set())
505 selection.cursor = cursor;
507 finishChange(bv, true);
511 if (!selection.set())
512 selection.cursor = cursor;
514 finishChange(bv, true);
517 case LFUN_UP_PARAGRAPHSEL:
518 if (!selection.set())
519 selection.cursor = cursor;
521 finishChange(bv, true);
524 case LFUN_DOWN_PARAGRAPHSEL:
525 if (!selection.set())
526 selection.cursor = cursor;
527 cursorDownParagraph();
528 finishChange(bv, true);
532 if (!selection.set())
533 selection.cursor = cursor;
535 finishChange(bv, true);
539 if (!selection.set())
540 selection.cursor = cursor;
542 finishChange(bv, true);
546 if (!selection.set())
547 selection.cursor = cursor;
549 finishChange(bv, true);
553 if (!selection.set())
554 selection.cursor = cursor;
556 finishChange(bv, true);
559 case LFUN_WORDRIGHTSEL:
560 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
563 cursorRightOneWord();
564 finishChange(bv, true);
567 case LFUN_WORDLEFTSEL:
568 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
569 cursorRightOneWord();
572 finishChange(bv, true);
576 LyXCursor cur1 = cursor;
578 ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
579 setCursor(cur1.par(), cur1.pos());
580 bv->beforeChange(this);
581 setCursor(cur2.par(), cur2.pos());
582 finishChange(bv, true);
587 bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
588 if (!selection.mark())
589 bv->beforeChange(this);
592 if (cursor.pos() < cursorPar()->size()
593 && cursorPar()->isInset(cursor.pos())
594 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
595 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
596 cmd.message(tmpinset->editMessage());
597 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
598 tmpinset->dispatch(cmd1);
608 // This is soooo ugly. Isn`t it possible to make
610 bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
611 if (!selection.mark())
612 bv->beforeChange(this);
613 LyXCursor const cur = cursor;
616 if ((is_rtl || cur != cursor) && // only if really moved!
617 cursor.pos() < cursorPar()->size() &&
618 cursorPar()->isInset(cursor.pos()) &&
619 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
620 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
621 cmd.message(tmpinset->editMessage());
622 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
623 tmpinset->dispatch(cmd1);
633 if (!selection.mark())
634 bv->beforeChange(this);
640 if (!selection.mark())
641 bv->beforeChange(this);
646 case LFUN_UP_PARAGRAPH:
647 if (!selection.mark())
648 bv->beforeChange(this);
653 case LFUN_DOWN_PARAGRAPH:
654 if (!selection.mark())
655 bv->beforeChange(this);
656 cursorDownParagraph();
657 finishChange(bv, false);
661 if (!selection.mark())
662 bv->beforeChange(this);
664 finishChange(bv, false);
668 if (!selection.mark())
669 bv->beforeChange(this);
671 finishChange(bv, false);
675 if (!selection.mark())
676 bv->beforeChange(this);
678 finishChange(bv, false);
682 if (!selection.mark())
683 bv->beforeChange(this);
685 finishChange(bv, false);
688 case LFUN_BREAKLINE: {
689 lyx::pos_type body = cursorPar()->beginningOfBody();
691 // Not allowed by LaTeX (labels or empty par)
692 if (cursor.pos() <= body)
695 replaceSelection(bv->getLyXText());
696 insertInset(new InsetNewline);
697 setCursor(cursorPar(), cursor.pos());
698 moveCursorUpdate(bv, false);
703 if (!selection.set()) {
705 selection.cursor = cursor;
706 // It is possible to make it a lot faster still
707 // just comment out the line below...
709 cutSelection(true, false);
711 moveCursorUpdate(bv, false);
712 bv->owner()->view_state_changed();
715 case LFUN_DELETE_SKIP:
716 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
717 if (!selection.set()) {
718 if (cursor.pos() == cursorPar()->size()) {
720 ParagraphParameters & params = cursorPar()->params();
721 if (cursor.pos() == 0
722 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
724 VSpace(VSpace::NONE),
725 params.spaceBottom(),
728 params.labelWidthString(), 0);
733 selection.cursor = cursor;
737 selection.cursor = cursor;
740 cutSelection(true, false);
747 if (!selection.set()) {
748 if (bv->owner()->getIntl().getTransManager().backspace()) {
750 selection.cursor = cursor;
751 // It is possible to make it a lot faster still
752 // just comment out the line below...
755 cutSelection(true, false);
757 bv->owner()->view_state_changed();
762 case LFUN_BACKSPACE_SKIP:
763 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
764 if (!selection.set()) {
765 ParagraphParameters & params = cursorPar()->params();
766 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
768 VSpace(VSpace::NONE),
769 params.spaceBottom(),
772 params.labelWidthString(), 0);
774 LyXCursor cur = cursor;
776 selection.cursor = cur;
779 cutSelection(true, false);
784 case LFUN_BREAKPARAGRAPH:
785 replaceSelection(bv->getLyXText());
786 breakParagraph(bv->buffer()->paragraphs(), 0);
788 selection.cursor = cursor;
790 bv->owner()->view_state_changed();
793 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
794 replaceSelection(bv->getLyXText());
795 breakParagraph(bv->buffer()->paragraphs(), 1);
797 selection.cursor = cursor;
799 bv->owner()->view_state_changed();
802 case LFUN_BREAKPARAGRAPH_SKIP: {
803 // When at the beginning of a paragraph, remove
804 // indentation and add a "defskip" at the top.
805 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
806 LyXCursor cur = cursor;
807 replaceSelection(bv->getLyXText());
808 if (cur.pos() == 0) {
809 ParagraphParameters & params = getPar(cur)->params();
810 if (params.spaceTop() == VSpace(VSpace::NONE)) {
812 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
815 params.labelWidthString(), 1);
819 breakParagraph(bv->buffer()->paragraphs(), 0);
822 selection.cursor = cur;
824 bv->owner()->view_state_changed();
828 case LFUN_PARAGRAPH_SPACING: {
829 ParagraphList::iterator pit = cursorPar();
830 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
831 float cur_value = 1.0;
832 if (cur_spacing == Spacing::Other)
833 cur_value = pit->params().spacing().getValue();
835 istringstream is(cmd.argument);
838 Spacing::Space new_spacing = cur_spacing;
839 float new_value = cur_value;
841 lyxerr << "Missing argument to `paragraph-spacing'"
843 } else if (tmp == "single") {
844 new_spacing = Spacing::Single;
845 } else if (tmp == "onehalf") {
846 new_spacing = Spacing::Onehalf;
847 } else if (tmp == "double") {
848 new_spacing = Spacing::Double;
849 } else if (tmp == "other") {
850 new_spacing = Spacing::Other;
853 lyxerr << "new_value = " << tmpval << endl;
856 } else if (tmp == "default") {
857 new_spacing = Spacing::Default;
859 lyxerr << _("Unknown spacing argument: ")
860 << cmd.argument << endl;
862 if (cur_spacing != new_spacing || cur_value != new_value) {
863 pit->params().spacing(Spacing(new_spacing, new_value));
870 case LFUN_INSET_SETTINGS:
871 BOOST_ASSERT(bv->theLockingInset());
872 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
875 case LFUN_INSET_TOGGLE:
876 bv->beforeChange(this);
882 case LFUN_SPACE_INSERT:
883 if (cursorPar()->layout()->free_spacing)
886 doInsertInset(this, cmd, false, false);
887 moveCursorUpdate(bv, false);
890 case LFUN_HYPHENATION:
891 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
894 case LFUN_LIGATURE_BREAK:
895 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
899 specialChar(this, bv, InsetSpecialChar::LDOTS);
902 case LFUN_END_OF_SENTENCE:
903 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
906 case LFUN_MENU_SEPARATOR:
907 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
911 bv->beforeChange(this);
913 selection.cursor = cursor;
914 cmd.message(N_("Mark off"));
918 bv->beforeChange(this);
919 selection.mark(true);
921 selection.cursor = cursor;
922 cmd.message(N_("Mark on"));
926 bv->beforeChange(this);
927 if (selection.mark()) {
928 cmd.message(N_("Mark removed"));
930 selection.mark(true);
931 cmd.message(N_("Mark set"));
933 selection.cursor = cursor;
937 case LFUN_UPCASE_WORD:
938 changeCase(LyXText::text_uppercase);
942 case LFUN_LOWCASE_WORD:
943 changeCase(LyXText::text_lowercase);
947 case LFUN_CAPITALIZE_WORD:
948 changeCase(LyXText::text_capitalization);
952 case LFUN_TRANSPOSE_CHARS:
953 recUndo(cursor.par());
959 cmd.message(_("Paste"));
960 replaceSelection(bv->getLyXText());
961 #warning FIXME Check if the arg is in the domain of available selections.
962 if (isStrUnsignedInt(cmd.argument))
963 pasteSelection(strToUnsignedInt(cmd.argument));
966 clearSelection(); // bug 393
973 cutSelection(true, true);
974 cmd.message(_("Cut"));
980 cmd.message(_("Copy"));
983 case LFUN_BEGINNINGBUFSEL:
987 finishChange(bv, true);
994 finishChange(bv, true);
998 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1004 istringstream is(cmd.argument);
1007 lyxerr << "SETXY: Could not parse coordinates in '"
1008 << cmd.argument << std::endl;
1010 setCursorFromCoordinates(x, y);
1015 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1017 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1023 case LFUN_GETLAYOUT:
1024 cmd.message(tostr(cursorPar()->layout()));
1028 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1029 << cmd.argument << endl;
1031 // This is not the good solution to the empty argument
1032 // problem, but it will hopefully suffice for 1.2.0.
1033 // The correct solution would be to augument the
1034 // function list/array with information about what
1035 // functions needs arguments and their type.
1036 if (cmd.argument.empty()) {
1037 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1041 // Derive layout number from given argument (string)
1042 // and current buffer's textclass (number)
1043 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1044 bool hasLayout = tclass.hasLayout(cmd.argument);
1045 string layout = cmd.argument;
1047 // If the entry is obsolete, use the new one instead.
1049 string const & obs = tclass[layout]->obsoleted_by();
1055 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1060 bool change_layout = (current_layout != layout);
1062 if (!change_layout && selection.set() &&
1063 selection.start.par() != selection.end.par())
1065 ParagraphList::iterator spit = getPar(selection.start);
1066 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1067 while (spit != epit) {
1068 if (spit->layout()->name() != current_layout) {
1069 change_layout = true;
1076 if (change_layout) {
1077 current_layout = layout;
1079 bv->owner()->setLayout(layout);
1086 case LFUN_PASTESELECTION: {
1087 // this was originally a beforeChange(bv->text), i.e
1088 // the outermost LyXText!
1089 bv->beforeChange(this);
1090 string const clip = bv->getClipboard();
1091 if (!clip.empty()) {
1092 if (cmd.argument == "paragraph")
1093 insertStringAsParagraphs(clip);
1095 insertStringAsLines(clip);
1102 case LFUN_GOTOERROR:
1103 gotoInset(InsetOld::ERROR_CODE, false);
1107 gotoInset(InsetOld::NOTE_CODE, false);
1110 case LFUN_REFERENCE_GOTO:
1112 vector<InsetOld::Code> tmp;
1113 tmp.push_back(InsetOld::LABEL_CODE);
1114 tmp.push_back(InsetOld::REF_CODE);
1115 gotoInset(tmp, true);
1120 replaceSelection(bv->getLyXText());
1121 ParagraphList::iterator pit = cursorPar();
1122 lyx::pos_type pos = cursor.pos();
1126 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1129 c = pit->getChar(pos - 1);
1131 LyXLayout_ptr const & style = pit->layout();
1133 BufferParams const & bufparams = bv->buffer()->params();
1134 if (style->pass_thru ||
1135 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1136 !bv->insertInset(new InsetQuotes(c, bufparams)))
1137 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1141 case LFUN_DATE_INSERT: {
1142 replaceSelection(bv->getLyXText());
1143 time_t now_time_t = time(NULL);
1144 struct tm * now_tm = localtime(&now_time_t);
1145 setlocale(LC_TIME, "");
1147 if (!cmd.argument.empty())
1150 arg = lyxrc.date_insert_format;
1152 int const datetmp_len =
1153 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1155 for (int i = 0; i < datetmp_len; i++)
1156 insertChar(datetmp[i]);
1158 selection.cursor = cursor;
1159 moveCursorUpdate(bv, false);
1163 case LFUN_MOUSE_TRIPLE:
1166 if (!isInInset() && bv->theLockingInset())
1168 if (cmd.button() == mouse_button::button1) {
1170 selection.cursor = cursor;
1174 bv->haveSelection(selection.set());
1178 case LFUN_MOUSE_DOUBLE:
1181 if (!isInInset() && bv->theLockingInset())
1183 if (cmd.button() == mouse_button::button1) {
1184 selectWord(lyx::WHOLE_WORD_STRICT);
1186 bv->haveSelection(selection.set());
1190 case LFUN_MOUSE_MOTION:
1192 // Only use motion with button 1
1193 //if (ev.button() != mouse_button::button1)
1199 // Check for inset locking
1200 if (bv->theLockingInset()) {
1201 InsetOld * tli = bv->theLockingInset();
1202 LyXCursor cursor = bv->text->cursor;
1203 LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1204 int width = tli->width();
1205 int inset_x = font.isVisibleRightToLeft()
1206 ? cursor.x() - width : cursor.x();
1207 int start_x = inset_x + tli->scroll();
1208 FuncRequest cmd1 = cmd;
1209 cmd1.x = cmd.x - start_x;
1210 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1211 tli->dispatch(cmd1);
1215 // The test for not selection possible is needed, that only motion
1216 // events are used, where the bottom press event was on
1217 // the drawing area too
1218 if (!selection_possible) {
1219 lyxerr[Debug::ACTION]
1220 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1224 RowList::iterator cursorrow = bv->text->cursorRow();
1225 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1227 // sorry for this but I have a strange error that the y value jumps at
1228 // a certain point. This seems like an error in my xforms library or
1229 // in some other local environment, but I would like to leave this here
1230 // for the moment until I can remove this (Jug 20020418)
1231 if (y_before < bv->text->cursor.y())
1232 lyxerr << y_before << ':'
1233 << bv->text->cursor.y() << endl;
1235 // This is to allow jumping over large insets
1236 if (cursorrow == bv->text->cursorRow()) {
1237 if (cmd.y >= bv->workHeight())
1238 bv->text->cursorDown(false);
1240 bv->text->cursorUp(false);
1243 bv->text->setSelection();
1248 // Single-click on work area
1249 case LFUN_MOUSE_PRESS:
1254 // ok ok, this is a hack (for xforms)
1255 // We shouldn't go further down as we really should only do the
1256 // scrolling and be done with this. Otherwise we may open some
1257 // dialogs (Jug 20020424).
1258 if (cmd.button() == mouse_button::button4) {
1259 bv->scroll(-lyxrc.wheel_jump);
1262 if (cmd.button() == mouse_button::button5) {
1263 bv->scroll(lyxrc.wheel_jump);
1269 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1271 // Middle button press pastes if we have a selection
1272 // We do this here as if the selection was inside an inset
1273 // it could get cleared on the unlocking of the inset so
1274 // we have to check this first
1275 bool paste_internally = false;
1276 if (cmd.button() == mouse_button::button2 && selection.set()) {
1277 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1278 paste_internally = true;
1281 int const screen_first = bv->top_y();
1283 if (bv->theLockingInset()) {
1284 // We are in inset locking mode
1286 // Check whether the inset was hit. If not reset mode,
1287 // otherwise give the event to the inset
1288 if (inset_hit == bv->theLockingInset()) {
1289 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1290 bv->theLockingInset()->dispatch(cmd1);
1293 bv->unlockInset(bv->theLockingInset());
1297 selection_possible = true;
1299 // Clear the selection
1300 bv->text->clearSelection();
1302 bv->updateScrollbar();
1304 // Single left click in math inset?
1305 if (isHighlyEditableInset(inset_hit)) {
1306 // Highly editable inset, like math
1307 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1308 selection_possible = false;
1309 bv->owner()->message(inset->editMessage());
1310 // We just have to lock the inset before calling a PressEvent on it!
1311 if (!bv->lockInset(inset))
1312 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1313 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1314 inset->dispatch(cmd1);
1317 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1319 // Right click on a footnote flag opens float menu
1320 if (cmd.button() == mouse_button::button3) {
1321 selection_possible = false;
1325 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1326 bv->text->setCursorFromCoordinates(x, y + screen_first);
1328 bv->text->selection.cursor = bv->text->cursor;
1329 bv->text->cursor.x_fix(bv->text->cursor.x());
1331 if (bv->fitCursor())
1332 selection_possible = false;
1334 // Insert primary selection with middle mouse
1335 // if there is a local selection in the current buffer,
1337 if (cmd.button() == mouse_button::button2) {
1338 if (paste_internally)
1339 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1341 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1342 selection_possible = false;
1347 case LFUN_MOUSE_RELEASE:
1349 // do nothing if we used the mouse wheel
1353 if (cmd.button() == mouse_button::button4
1354 || cmd.button() == mouse_button::button5)
1357 // If we hit an inset, we have the inset coordinates in these
1358 // and inset_hit points to the inset. If we do not hit an
1359 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1362 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1364 if (bv->theLockingInset()) {
1365 // We are in inset locking mode.
1367 // LyX does a kind of work-area grabbing for insets.
1368 // Only a ButtonPress FuncRequest outside the inset will
1369 // force a insetUnlock.
1370 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1371 bv->theLockingInset()->dispatch(cmd1);
1375 selection_possible = false;
1377 if (cmd.button() == mouse_button::button2)
1381 if (cmd.button() == mouse_button::button1)
1382 bv->haveSelection(selection.set());
1385 bv->owner()->view_state_changed();
1386 bv->owner()->updateMenubar();
1387 bv->owner()->updateToolbar();
1389 // Did we hit an editable inset?
1391 selection_possible = false;
1393 // if we reach this point with a selection, it
1394 // must mean we are currently selecting.
1395 // But we don't want to open the inset
1396 // because that is annoying for the user.
1397 // So just pretend we didn't hit it.
1398 // this is OK because a "kosher" ButtonRelease
1399 // will follow a ButtonPress that clears
1401 // Note this also fixes selection drawing
1402 // problems if we end up opening an inset
1403 if (selection.set())
1406 // CHECK fix this proper in 0.13
1407 // well, maybe 13.0 !!!!!!!!!
1409 // Following a ref shouldn't issue
1410 // a push on the undo-stack
1411 // anylonger, now that we have
1412 // keybindings for following
1413 // references and returning from
1414 // references. IMHO though, it
1415 // should be the inset's own business
1416 // to push or not push on the undo
1417 // stack. They don't *have* to
1418 // alter the document...
1420 // ...or maybe the recordUndo()
1421 // below isn't necessary at all anylonger?
1422 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1423 recUndo(cursor.par());
1425 bv->owner()->message(inset_hit->editMessage());
1427 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1428 inset_hit->dispatch(cmd1);
1434 case LFUN_SELFINSERT: {
1435 if (cmd.argument.empty())
1438 // Automatically delete the currently selected
1439 // text and replace it with what is being
1440 // typed in now. Depends on lyxrc settings
1441 // "auto_region_delete", which defaults to
1444 if (lyxrc.auto_region_delete) {
1445 if (selection.set())
1446 cutSelection(false, false);
1447 bv->haveSelection(false);
1450 bv->beforeChange(this);
1451 LyXFont const old_font = real_current_font;
1453 string::const_iterator cit = cmd.argument.begin();
1454 string::const_iterator end = cmd.argument.end();
1455 for (; cit != end; ++cit)
1456 bv->owner()->getIntl().getTransManager().
1457 TranslateAndInsert(*cit, this);
1459 selection.cursor = cursor;
1460 moveCursorUpdate(bv, false);
1462 // real_current_font.number can change so we need to
1463 // update the minibuffer
1464 if (old_font != real_current_font)
1465 bv->owner()->view_state_changed();
1466 bv->updateScrollbar();
1470 case LFUN_HTMLURL: {
1471 InsetCommandParams p("htmlurl");
1472 string const data = InsetCommandMailer::params2string("url", p);
1473 bv->owner()->getDialogs().show("url", data, 0);
1478 InsetCommandParams p("url");
1479 string const data = InsetCommandMailer::params2string("url", p);
1480 bv->owner()->getDialogs().show("url", data, 0);
1486 case LFUN_INSET_LIST:
1487 case LFUN_INSET_THEOREM:
1488 case LFUN_INSET_CAPTION:
1490 case LFUN_INSERT_NOTE:
1491 case LFUN_INSERT_BOX:
1492 case LFUN_INSERT_BRANCH:
1493 case LFUN_INSERT_BIBITEM:
1494 case LFUN_INSET_ERT:
1495 case LFUN_INSET_FLOAT:
1496 case LFUN_INSET_FOOTNOTE:
1497 case LFUN_INSET_MARGINAL:
1498 case LFUN_INSET_MINIPAGE:
1499 case LFUN_INSET_OPTARG:
1500 case LFUN_INSET_WIDE_FLOAT:
1501 case LFUN_INSET_WRAP:
1502 case LFUN_TABULAR_INSERT:
1503 case LFUN_ENVIRONMENT_INSERT:
1504 // Open the inset, and move the current selection
1506 doInsertInset(this, cmd, true, true);
1509 case LFUN_INDEX_INSERT:
1510 // Just open the inset
1511 doInsertInset(this, cmd, true, false);
1514 case LFUN_INDEX_PRINT:
1515 case LFUN_TOC_INSERT:
1517 case LFUN_INSERT_LINE:
1518 case LFUN_INSERT_PAGEBREAK:
1520 doInsertInset(this, cmd, false, false);
1523 case LFUN_DEPTH_MIN:
1524 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1529 case LFUN_DEPTH_PLUS:
1531 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1537 return UNDISPATCHED;