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.
19 #include "BufferView.h"
20 #include "funcrequest.h"
22 #include "support/std_sstream.h"
26 #include "paragraph.h"
27 #include "ParagraphParameters.h"
32 #include "support/tostr.h"
33 #include "support/lstrings.h"
34 #include "support/LAssert.h"
35 #include "frontends/LyXView.h"
36 #include "frontends/Dialogs.h"
37 #include "insets/insetspecialchar.h"
38 #include "insets/insettext.h"
39 #include "insets/insetcommand.h"
40 #include "insets/insetnewline.h"
41 #include "undo_funcs.h"
42 #include "text_funcs.h"
46 using namespace lyx::support;
47 using namespace bv_funcs;
51 using std::istringstream;
55 extern string current_layout;
56 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
58 // the selection possible is needed, that only motion events are
59 // used, where the bottom press event was on the drawing area too
60 bool selection_possible = false;
65 void moveCursorUpdate(BufferView * bv, bool selecting)
67 LyXText * lt = bv->getLyXText();
69 //if (!lt->selection.set())
70 // lt->selection.cursor = lt->cursor;
72 if (selecting || lt->selection.mark())
75 if (!lt->selection.set())
76 bv->haveSelection(false);
83 void finishChange(BufferView * bv, bool selecting = false)
86 moveCursorUpdate(bv, selecting);
87 bv->owner()->view_state_changed();
90 // check if the given co-ordinates are inside an inset at the
91 // given cursor, if one exists. If so, the inset is returned,
92 // and the co-ordinates are made relative. Otherwise, 0 is returned.
93 InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
94 LyXCursor const & cur, int & x, int & y)
96 lyx::pos_type const pos = cur.pos();
97 ParagraphList::iterator par = cur.par();
99 if (pos >= par->size() || !par->isInset(pos))
102 InsetOld /*const*/ * inset = par->getInset(pos);
104 if (!isEditableInset(inset))
107 // get inset dimensions
108 Assert(par->getInset(pos));
110 LyXFont const & font = text.getFont(par, pos);
112 int const width = inset->width();
113 int const inset_x = font.isVisibleRightToLeft()
114 ? (cur.x() - width) : cur.x();
117 inset_x + inset->scroll(),
119 cur.y() - inset->ascent(),
120 cur.y() + inset->descent()
123 if (!b.contains(x, y)) {
124 lyxerr[Debug::GUI] << "Missed inset at x,y "
126 << " box " << b << endl;
130 text.setCursor(par, pos, true);
133 // The origin of an inset is on the baseline
134 y -= text.cursor.y();
142 InsetOld * LyXText::checkInsetHit(int & x, int & y)
144 int y_tmp = y + bv_owner->top_y();
147 setCursorFromCoordinates(cur, x, y_tmp);
149 InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
155 // look at previous position
160 setCursor(cur, cur.par(), cur.pos() - 1, true);
162 inset = checkInset(bv(), *this, cur, x, y_tmp);
169 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
170 string const & contents)
172 ParagraphList::iterator end = ownerParagraphs().end();
173 ParagraphList::iterator pit = cursor.par();
174 pos_type pos = cursor.pos();
178 if (pos + 1 < pit->size()) {
185 } while (pit != end &&
186 !(pit->isInset(pos) &&
187 (inset = pit->getInset(pos)) != 0 &&
188 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
190 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
194 setCursor(pit, pos, false);
201 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
204 bv()->beforeChange(this);
207 if (same_content && cursor.pos() < cursor.par()->size()
208 && cursor.par()->isInset(cursor.pos())) {
209 InsetOld const * inset = cursor.par()->getInset(cursor.pos());
210 if (find(codes.begin(), codes.end(), inset->lyxCode())
212 contents = static_cast<InsetCommand const *>(inset)->getContents();
215 if (!gotoNextInset(codes, contents)) {
216 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
217 LyXCursor tmp = cursor;
218 cursor.par(ownerParagraphs().begin());
220 if (!gotoNextInset(codes, contents)) {
222 bv()->owner()->message(_("No more insets"));
225 bv()->owner()->message(_("No more insets"));
229 selection.cursor = cursor;
233 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
235 gotoInset(vector<InsetOld::Code>(1, code), same_content);
239 void LyXText::cursorPrevious()
241 int y = bv_owner->top_y();
243 RowList::iterator rit = cursorRow();
245 if (rit == firstRow()) {
247 bv()->updateScrollbar();
251 setCursorFromCoordinates(cursor.x_fix(), y);
255 if (rit == bv()->text->cursorRow()) {
256 // we have a row which is taller than the workarea. The
257 // simplest solution is to move to the previous row instead.
260 // This is what we used to do, so we wouldn't skip right past
261 // tall rows, but it's not working right now.
264 new_y = bv()->text->cursor.y()
265 + bv()->theLockingInset()->insetInInsetY() + y
267 - bv()->workHeight() + 1;
272 - bv()->workHeight() + 1;
277 ParagraphList::iterator pit = cursor.par();
278 previousRow(pit, rit);
279 setCursor(cur, pit, rit->pos(), false);
280 if (cur.y() > bv_owner->top_y())
282 bv()->updateScrollbar();
286 void LyXText::cursorNext()
288 int topy = bv_owner->top_y();
290 RowList::iterator rit = cursorRow();
291 if (rit == lastRow()) {
292 int y = cursor.y() - rit->baseline() + cursorRow()->height();
293 if (y > topy + bv()->workHeight())
294 bv_owner->updateScrollbar();
298 int y = topy + bv_owner->workHeight();
299 if (inset_owner && !topy) {
300 y -= (bv_owner->text->cursor.y()
302 + bv_owner->theLockingInset()->insetInInsetY());
305 ParagraphList::iterator dummypit;
306 y = getRowNearY(y, dummypit)->y();
308 setCursorFromCoordinates(cursor.x_fix(), y);
309 // + bv->workHeight());
313 if (rit == bv_owner->text->cursorRow()) {
314 // we have a row which is taller than the workarea. The
315 // simplest solution is to move to the next row instead.
318 // This is what we used to do, so we wouldn't skip right past
319 // tall rows, but it's not working right now.
321 new_y = bv->top_y() + bv->workHeight();
325 new_y = bv()->text->cursor.y()
326 + bv()->theLockingInset()->insetInInsetY()
327 + y - rit->baseline();
329 new_y = cursor.y() - cursorRow()->baseline();
333 ParagraphList::iterator pit = cursor.par();
336 setCursor(cur, pit, rit->pos(), false);
337 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
339 bv()->updateScrollbar();
345 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
348 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
349 replaceSelection(lt);
350 if (!bv->insertInset(new_inset))
353 bv->updateInset(new_inset);
357 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
358 bool edit, bool pastesel)
360 InsetOld * inset = createInset(cmd);
361 BufferView * bv = cmd.view();
365 if (lt->selection.set()) {
366 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
369 if (bv->insertInset(inset)) {
371 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
372 inset->localDispatch(cmd);
374 if (gotsel && pastesel)
375 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
384 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
386 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
387 <<"] arg[" << cmd.argument << ']' << "xy[" <<
388 cmd.x << ',' << cmd.y << ']' << endl;
390 BufferView * bv = cmd.view();
392 switch (cmd.action) {
394 case LFUN_APPENDIX: {
395 ParagraphList::iterator pit = cursor.par();
396 bool start = !pit->params().startOfAppendix();
398 // ensure that we have only one start_of_appendix in this document
399 ParagraphList::iterator tmp = ownerParagraphs().begin();
400 ParagraphList::iterator end = ownerParagraphs().end();
402 for (; tmp != end; ++tmp) {
403 if (tmp->params().startOfAppendix()) {
404 recordUndo(bv, Undo::ATOMIC, tmp);
405 tmp->params().startOfAppendix(false);
411 recordUndo(bv, Undo::ATOMIC, pit);
412 pit->params().startOfAppendix(start);
414 // we can set the refreshing parameters now
416 redoParagraph(cursor.par());
417 setCursor(cursor.par(), cursor.pos());
422 case LFUN_DELETE_WORD_FORWARD:
423 bv->beforeChange(this);
428 case LFUN_DELETE_WORD_BACKWARD:
429 bv->beforeChange(this);
430 deleteWordBackward();
434 case LFUN_DELETE_LINE_FORWARD:
435 bv->beforeChange(this);
441 if (!selection.mark())
442 bv->beforeChange(this);
443 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
446 cursorRightOneWord();
451 if (!selection.mark())
452 bv->beforeChange(this);
453 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
454 cursorRightOneWord();
460 case LFUN_BEGINNINGBUF:
461 if (!selection.mark())
462 bv->beforeChange(this);
468 if (selection.mark())
469 bv->beforeChange(this);
475 if (!selection.set())
476 selection.cursor = cursor;
477 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
481 finishChange(bv, true);
485 if (!selection.set())
486 selection.cursor = cursor;
487 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
491 finishChange(bv, true);
495 if (!selection.set())
496 selection.cursor = cursor;
498 finishChange(bv, true);
502 if (!selection.set())
503 selection.cursor = cursor;
505 finishChange(bv, true);
508 case LFUN_UP_PARAGRAPHSEL:
509 if (!selection.set())
510 selection.cursor = cursor;
512 finishChange(bv, true);
515 case LFUN_DOWN_PARAGRAPHSEL:
516 if (!selection.set())
517 selection.cursor = cursor;
518 cursorDownParagraph();
519 finishChange(bv, true);
523 if (!selection.set())
524 selection.cursor = cursor;
526 finishChange(bv, true);
530 if (!selection.set())
531 selection.cursor = cursor;
533 finishChange(bv, true);
537 if (!selection.set())
538 selection.cursor = cursor;
540 finishChange(bv, true);
544 if (!selection.set())
545 selection.cursor = cursor;
547 finishChange(bv, true);
550 case LFUN_WORDRIGHTSEL:
551 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
554 cursorRightOneWord();
555 finishChange(bv, true);
558 case LFUN_WORDLEFTSEL:
559 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
560 cursorRightOneWord();
563 finishChange(bv, true);
567 LyXCursor cur1 = cursor;
569 ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
570 setCursor(cur1.par(), cur1.pos());
571 bv->beforeChange(this);
572 setCursor(cur2.par(), cur2.pos());
573 finishChange(bv, true);
578 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
579 if (!selection.mark())
580 bv->beforeChange(this);
583 if (cursor.pos() < cursor.par()->size()
584 && cursor.par()->isInset(cursor.pos())
585 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
586 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
587 cmd.message(tmpinset->editMessage());
588 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
589 tmpinset->localDispatch(cmd1);
599 // This is soooo ugly. Isn`t it possible to make
601 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
602 if (!selection.mark())
603 bv->beforeChange(this);
604 LyXCursor const cur = cursor;
607 if ((is_rtl || cur != cursor) && // only if really moved!
608 cursor.pos() < cursor.par()->size() &&
609 cursor.par()->isInset(cursor.pos()) &&
610 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
611 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
612 cmd.message(tmpinset->editMessage());
613 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
614 tmpinset->localDispatch(cmd1);
624 if (!selection.mark())
625 bv->beforeChange(this);
631 if (!selection.mark())
632 bv->beforeChange(this);
637 case LFUN_UP_PARAGRAPH:
638 if (!selection.mark())
639 bv->beforeChange(this);
644 case LFUN_DOWN_PARAGRAPH:
645 if (!selection.mark())
646 bv->beforeChange(this);
647 cursorDownParagraph();
648 finishChange(bv, false);
652 if (!selection.mark())
653 bv->beforeChange(this);
655 finishChange(bv, false);
659 if (!selection.mark())
660 bv->beforeChange(this);
662 finishChange(bv, false);
666 if (!selection.mark())
667 bv->beforeChange(this);
669 finishChange(bv, false);
673 if (!selection.mark())
674 bv->beforeChange(this);
676 finishChange(bv, false);
679 case LFUN_BREAKLINE: {
680 lyx::pos_type body = cursor.par()->beginningOfBody();
682 // Not allowed by LaTeX (labels or empty par)
683 if (cursor.pos() <= body)
686 replaceSelection(bv->getLyXText());
687 insertInset(new InsetNewline);
688 setCursor(cursor.par(), cursor.pos());
689 moveCursorUpdate(bv, false);
694 if (!selection.set()) {
696 selection.cursor = cursor;
697 // It is possible to make it a lot faster still
698 // just comment out the line below...
700 cutSelection(true, false);
702 moveCursorUpdate(bv, false);
703 bv->owner()->view_state_changed();
706 case LFUN_DELETE_SKIP:
707 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
708 if (!selection.set()) {
709 LyXCursor cur = cursor;
710 if (cur.pos() == cur.par()->size()) {
714 && !(cur.par()->params().spaceTop()
715 == VSpace (VSpace::NONE))) {
717 cur.par()->params().lineTop(),
718 cur.par()->params().lineBottom(),
719 cur.par()->params().pagebreakTop(),
720 cur.par()->params().pagebreakBottom(),
721 VSpace(VSpace::NONE),
722 cur.par()->params().spaceBottom(),
723 cur.par()->params().spacing(),
724 cur.par()->params().align(),
725 cur.par()->params().labelWidthString(), 0);
730 selection.cursor = cursor;
734 selection.cursor = cursor;
737 cutSelection(true, false);
744 if (!selection.set()) {
745 if (bv->owner()->getIntl().getTransManager().backspace()) {
747 selection.cursor = cursor;
748 // It is possible to make it a lot faster still
749 // just comment out the line below...
752 cutSelection(true, false);
754 bv->owner()->view_state_changed();
759 case LFUN_BACKSPACE_SKIP:
760 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
761 if (!selection.set()) {
762 LyXCursor cur = cursor;
764 && !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
766 cur.par()->params().lineTop(),
767 cur.par()->params().lineBottom(),
768 cur.par()->params().pagebreakTop(),
769 cur.par()->params().pagebreakBottom(),
770 VSpace(VSpace::NONE),
771 cur.par()->params().spaceBottom(),
772 cur.par()->params().spacing(),
773 cur.par()->params().align(),
774 cur.par()->params().labelWidthString(), 0);
777 selection.cursor = cur;
780 cutSelection(true, false);
785 case LFUN_BREAKPARAGRAPH:
786 replaceSelection(bv->getLyXText());
787 breakParagraph(bv->buffer()->paragraphs, 0);
789 selection.cursor = cursor;
791 bv->owner()->view_state_changed();
794 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
795 replaceSelection(bv->getLyXText());
796 breakParagraph(bv->buffer()->paragraphs, 1);
798 selection.cursor = cursor;
800 bv->owner()->view_state_changed();
803 case LFUN_BREAKPARAGRAPH_SKIP: {
804 // When at the beginning of a paragraph, remove
805 // indentation and add a "defskip" at the top.
806 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
807 LyXCursor cur = cursor;
808 replaceSelection(bv->getLyXText());
809 if (cur.pos() == 0) {
810 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
812 cur.par()->params().lineTop(),
813 cur.par()->params().lineBottom(),
814 cur.par()->params().pagebreakTop(),
815 cur.par()->params().pagebreakBottom(),
816 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
817 cur.par()->params().spacing(),
818 cur.par()->params().align(),
819 cur.par()->params().labelWidthString(), 1);
823 breakParagraph(bv->buffer()->paragraphs, 0);
826 selection.cursor = cur;
828 bv->owner()->view_state_changed();
832 case LFUN_PARAGRAPH_SPACING: {
833 ParagraphList::iterator pit = cursor.par();
834 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
835 float cur_value = 1.0;
836 if (cur_spacing == Spacing::Other)
837 cur_value = pit->params().spacing().getValue();
839 istringstream is(STRCONV(cmd.argument));
842 Spacing::Space new_spacing = cur_spacing;
843 float new_value = cur_value;
845 lyxerr << "Missing argument to `paragraph-spacing'"
847 } else if (tmp == "single") {
848 new_spacing = Spacing::Single;
849 } else if (tmp == "onehalf") {
850 new_spacing = Spacing::Onehalf;
851 } else if (tmp == "double") {
852 new_spacing = Spacing::Double;
853 } else if (tmp == "other") {
854 new_spacing = Spacing::Other;
857 lyxerr << "new_value = " << tmpval << endl;
860 } else if (tmp == "default") {
861 new_spacing = Spacing::Default;
863 lyxerr << _("Unknown spacing argument: ")
864 << cmd.argument << endl;
866 if (cur_spacing != new_spacing || cur_value != new_value) {
867 pit->params().spacing(Spacing(new_spacing, new_value));
874 case LFUN_INSET_SETTINGS:
875 Assert(bv->theLockingInset());
876 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
879 case LFUN_INSET_TOGGLE:
880 bv->beforeChange(this);
886 case LFUN_SPACE_INSERT:
887 if (cursor.par()->layout()->free_spacing)
890 doInsertInset(this, cmd, false, false);
891 moveCursorUpdate(bv, false);
894 case LFUN_HYPHENATION:
895 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
898 case LFUN_LIGATURE_BREAK:
899 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
903 specialChar(this, bv, InsetSpecialChar::LDOTS);
906 case LFUN_END_OF_SENTENCE:
907 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
910 case LFUN_MENU_SEPARATOR:
911 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
915 bv->beforeChange(this);
917 selection.cursor = cursor;
918 cmd.message(N_("Mark off"));
922 bv->beforeChange(this);
923 selection.mark(true);
925 selection.cursor = cursor;
926 cmd.message(N_("Mark on"));
930 bv->beforeChange(this);
931 if (selection.mark()) {
932 cmd.message(N_("Mark removed"));
934 selection.mark(true);
935 cmd.message(N_("Mark set"));
937 selection.cursor = cursor;
941 case LFUN_UPCASE_WORD:
942 changeCase(LyXText::text_uppercase);
946 case LFUN_LOWCASE_WORD:
947 changeCase(LyXText::text_lowercase);
951 case LFUN_CAPITALIZE_WORD:
952 changeCase(LyXText::text_capitalization);
956 case LFUN_TRANSPOSE_CHARS:
957 recordUndo(bv, Undo::ATOMIC, cursor.par());
963 cmd.message(_("Paste"));
964 replaceSelection(bv->getLyXText());
965 size_t sel_index = 0;
966 string const & arg = cmd.argument;
967 if (isStrUnsignedInt(arg)) {
968 size_t const paste_arg = strToUnsignedInt(arg);
969 #warning FIXME Check if the arg is in the domain of available selections.
970 sel_index = paste_arg;
972 pasteSelection(sel_index);
973 clearSelection(); // bug 393
980 cutSelection(true, true);
981 cmd.message(_("Cut"));
987 cmd.message(_("Copy"));
990 case LFUN_BEGINNINGBUFSEL:
994 finishChange(bv, true);
1001 finishChange(bv, true);
1005 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1011 istringstream is(STRCONV(cmd.argument));
1014 lyxerr << "SETXY: Could not parse coordinates in '"
1015 << cmd.argument << std::endl;
1017 setCursorFromCoordinates(x, y);
1022 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1024 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1030 case LFUN_GETLAYOUT:
1031 cmd.message(tostr(cursor.par()->layout()));
1035 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1036 << cmd.argument << endl;
1038 // This is not the good solution to the empty argument
1039 // problem, but it will hopefully suffice for 1.2.0.
1040 // The correct solution would be to augument the
1041 // function list/array with information about what
1042 // functions needs arguments and their type.
1043 if (cmd.argument.empty()) {
1044 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1048 // Derive layout number from given argument (string)
1049 // and current buffer's textclass (number)
1050 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1051 bool hasLayout = tclass.hasLayout(cmd.argument);
1052 string layout = cmd.argument;
1054 // If the entry is obsolete, use the new one instead.
1056 string const & obs = tclass[layout]->obsoleted_by();
1062 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1067 bool change_layout = (current_layout != layout);
1069 if (!change_layout && selection.set() &&
1070 selection.start.par() != selection.end.par())
1072 ParagraphList::iterator spit = selection.start.par();
1073 ParagraphList::iterator epit = boost::next(selection.end.par());
1074 while (spit != epit) {
1075 if (spit->layout()->name() != current_layout) {
1076 change_layout = true;
1083 if (change_layout) {
1084 current_layout = layout;
1086 bv->owner()->setLayout(layout);
1093 case LFUN_PASTESELECTION: {
1094 // this was originally a beforeChange(bv->text), i.e
1095 // the outermost LyXText!
1096 bv->beforeChange(this);
1097 string const clip = bv->getClipboard();
1098 if (!clip.empty()) {
1099 if (cmd.argument == "paragraph")
1100 insertStringAsParagraphs(clip);
1102 insertStringAsLines(clip);
1109 case LFUN_GOTOERROR:
1110 gotoInset(InsetOld::ERROR_CODE, false);
1114 gotoInset(InsetOld::NOTE_CODE, false);
1117 case LFUN_REFERENCE_GOTO:
1119 vector<InsetOld::Code> tmp;
1120 tmp.push_back(InsetOld::LABEL_CODE);
1121 tmp.push_back(InsetOld::REF_CODE);
1122 gotoInset(tmp, true);
1127 replaceSelection(bv->getLyXText());
1128 ParagraphList::iterator pit = cursor.par();
1129 lyx::pos_type pos = cursor.pos();
1133 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1136 c = pit->getChar(pos - 1);
1138 LyXLayout_ptr const & style = pit->layout();
1140 if (style->pass_thru ||
1141 pit->getFontSettings(bv->buffer()->params,
1142 pos).language()->lang() == "hebrew" ||
1143 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1144 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1148 case LFUN_DATE_INSERT: {
1149 replaceSelection(bv->getLyXText());
1150 time_t now_time_t = time(NULL);
1151 struct tm * now_tm = localtime(&now_time_t);
1152 setlocale(LC_TIME, "");
1154 if (!cmd.argument.empty())
1157 arg = lyxrc.date_insert_format;
1159 int const datetmp_len =
1160 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1162 for (int i = 0; i < datetmp_len; i++)
1163 insertChar(datetmp[i]);
1165 selection.cursor = cursor;
1166 moveCursorUpdate(bv, false);
1170 case LFUN_MOUSE_TRIPLE:
1173 if (!isInInset() && bv->theLockingInset())
1175 if (cmd.button() == mouse_button::button1) {
1177 selection.cursor = cursor;
1181 bv->haveSelection(selection.set());
1185 case LFUN_MOUSE_DOUBLE:
1188 if (!isInInset() && bv->theLockingInset())
1190 if (cmd.button() == mouse_button::button1) {
1191 selectWord(lyx::WHOLE_WORD_STRICT);
1193 bv->haveSelection(selection.set());
1197 case LFUN_MOUSE_MOTION:
1199 // Only use motion with button 1
1200 //if (ev.button() != mouse_button::button1)
1206 // Check for inset locking
1207 if (bv->theLockingInset()) {
1208 InsetOld * tli = bv->theLockingInset();
1209 LyXCursor cursor = bv->text->cursor;
1210 LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
1211 int width = tli->width();
1212 int inset_x = font.isVisibleRightToLeft()
1213 ? cursor.x() - width : cursor.x();
1214 int start_x = inset_x + tli->scroll();
1215 FuncRequest cmd1 = cmd;
1216 cmd1.x = cmd.x - start_x;
1217 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1218 tli->localDispatch(cmd1);
1222 // The test for not selection possible is needed, that only motion
1223 // events are used, where the bottom press event was on
1224 // the drawing area too
1225 if (!selection_possible) {
1226 lyxerr[Debug::ACTION]
1227 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1231 RowList::iterator cursorrow = bv->text->cursorRow();
1232 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1234 // sorry for this but I have a strange error that the y value jumps at
1235 // a certain point. This seems like an error in my xforms library or
1236 // in some other local environment, but I would like to leave this here
1237 // for the moment until I can remove this (Jug 20020418)
1238 if (y_before < bv->text->cursor.y())
1239 lyxerr << y_before << ':'
1240 << bv->text->cursor.y() << endl;
1242 // This is to allow jumping over large insets
1243 if (cursorrow == bv->text->cursorRow()) {
1244 if (cmd.y >= bv->workHeight())
1245 bv->text->cursorDown(false);
1247 bv->text->cursorUp(false);
1250 bv->text->setSelection();
1255 // Single-click on work area
1256 case LFUN_MOUSE_PRESS:
1261 // ok ok, this is a hack (for xforms)
1262 // We shouldn't go further down as we really should only do the
1263 // scrolling and be done with this. Otherwise we may open some
1264 // dialogs (Jug 20020424).
1265 if (cmd.button() == mouse_button::button4) {
1266 bv->scroll(-lyxrc.wheel_jump);
1269 if (cmd.button() == mouse_button::button5) {
1270 bv->scroll(lyxrc.wheel_jump);
1276 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1278 // Middle button press pastes if we have a selection
1279 // We do this here as if the selection was inside an inset
1280 // it could get cleared on the unlocking of the inset so
1281 // we have to check this first
1282 bool paste_internally = false;
1283 if (cmd.button() == mouse_button::button2 && selection.set()) {
1284 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1285 paste_internally = true;
1288 int const screen_first = bv->top_y();
1290 if (bv->theLockingInset()) {
1291 // We are in inset locking mode
1293 // Check whether the inset was hit. If not reset mode,
1294 // otherwise give the event to the inset
1295 if (inset_hit == bv->theLockingInset()) {
1296 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1297 bv->theLockingInset()->localDispatch(cmd1);
1300 bv->unlockInset(bv->theLockingInset());
1304 selection_possible = true;
1306 // Clear the selection
1307 bv->text->clearSelection();
1309 bv->updateScrollbar();
1311 // Single left click in math inset?
1312 if (isHighlyEditableInset(inset_hit)) {
1313 // Highly editable inset, like math
1314 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1315 selection_possible = false;
1316 bv->owner()->message(inset->editMessage());
1317 // We just have to lock the inset before calling a PressEvent on it!
1318 if (!bv->lockInset(inset))
1319 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1320 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1321 inset->localDispatch(cmd1);
1324 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1326 // Right click on a footnote flag opens float menu
1327 if (cmd.button() == mouse_button::button3) {
1328 selection_possible = false;
1332 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1333 bv->text->setCursorFromCoordinates(x, y + screen_first);
1335 bv->text->selection.cursor = bv->text->cursor;
1336 bv->text->cursor.x_fix(bv->text->cursor.x());
1338 if (bv->fitCursor())
1339 selection_possible = false;
1341 // Insert primary selection with middle mouse
1342 // if there is a local selection in the current buffer,
1344 if (cmd.button() == mouse_button::button2) {
1345 if (paste_internally)
1346 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1348 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1349 selection_possible = false;
1354 case LFUN_MOUSE_RELEASE:
1356 // do nothing if we used the mouse wheel
1360 if (cmd.button() == mouse_button::button4
1361 || cmd.button() == mouse_button::button5)
1364 // If we hit an inset, we have the inset coordinates in these
1365 // and inset_hit points to the inset. If we do not hit an
1366 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1369 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1371 if (bv->theLockingInset()) {
1372 // We are in inset locking mode.
1374 // LyX does a kind of work-area grabbing for insets.
1375 // Only a ButtonPress FuncRequest outside the inset will
1376 // force a insetUnlock.
1377 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1378 bv->theLockingInset()->localDispatch(cmd1);
1382 selection_possible = false;
1384 if (cmd.button() == mouse_button::button2)
1388 if (cmd.button() == mouse_button::button1)
1389 bv->haveSelection(selection.set());
1392 bv->owner()->view_state_changed();
1393 bv->owner()->updateMenubar();
1394 bv->owner()->updateToolbar();
1396 // Did we hit an editable inset?
1398 selection_possible = false;
1400 // if we reach this point with a selection, it
1401 // must mean we are currently selecting.
1402 // But we don't want to open the inset
1403 // because that is annoying for the user.
1404 // So just pretend we didn't hit it.
1405 // this is OK because a "kosher" ButtonRelease
1406 // will follow a ButtonPress that clears
1408 // Note this also fixes selection drawing
1409 // problems if we end up opening an inset
1410 if (selection.set())
1413 // CHECK fix this proper in 0.13
1414 // well, maybe 13.0 !!!!!!!!!
1416 // Following a ref shouldn't issue
1417 // a push on the undo-stack
1418 // anylonger, now that we have
1419 // keybindings for following
1420 // references and returning from
1421 // references. IMHO though, it
1422 // should be the inset's own business
1423 // to push or not push on the undo
1424 // stack. They don't *have* to
1425 // alter the document...
1427 // ...or maybe the recordUndo()
1428 // below isn't necessary at all anylonger?
1429 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1430 recordUndo(bv, Undo::ATOMIC);
1432 bv->owner()->message(inset_hit->editMessage());
1434 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1435 inset_hit->localDispatch(cmd1);
1441 case LFUN_SELFINSERT: {
1442 if (cmd.argument.empty())
1445 // Automatically delete the currently selected
1446 // text and replace it with what is being
1447 // typed in now. Depends on lyxrc settings
1448 // "auto_region_delete", which defaults to
1451 if (lyxrc.auto_region_delete) {
1452 if (selection.set())
1453 cutSelection(false, false);
1454 bv->haveSelection(false);
1457 bv->beforeChange(this);
1458 LyXFont const old_font = real_current_font;
1460 string::const_iterator cit = cmd.argument.begin();
1461 string::const_iterator end = cmd.argument.end();
1462 for (; cit != end; ++cit)
1463 bv->owner()->getIntl().getTransManager().
1464 TranslateAndInsert(*cit, this);
1466 selection.cursor = cursor;
1467 moveCursorUpdate(bv, false);
1469 // real_current_font.number can change so we need to
1470 // update the minibuffer
1471 if (old_font != real_current_font)
1472 bv->owner()->view_state_changed();
1473 bv->updateScrollbar();
1477 case LFUN_HTMLURL: {
1478 InsetCommandParams p("htmlurl");
1479 string const data = InsetCommandMailer::params2string("url", p);
1480 bv->owner()->getDialogs().show("url", data, 0);
1485 InsetCommandParams p("url");
1486 string const data = InsetCommandMailer::params2string("url", p);
1487 bv->owner()->getDialogs().show("url", data, 0);
1493 case LFUN_INSET_LIST:
1494 case LFUN_INSET_THEOREM:
1495 case LFUN_INSET_CAPTION:
1497 case LFUN_INSERT_NOTE:
1498 case LFUN_INSERT_BRANCH:
1499 case LFUN_INSERT_BIBITEM:
1500 case LFUN_INSET_ERT:
1501 case LFUN_INSET_FLOAT:
1502 case LFUN_INSET_FOOTNOTE:
1503 case LFUN_INSET_MARGINAL:
1504 case LFUN_INSET_MINIPAGE:
1505 case LFUN_INSET_OPTARG:
1506 case LFUN_INSET_WIDE_FLOAT:
1507 case LFUN_INSET_WRAP:
1508 case LFUN_TABULAR_INSERT:
1509 case LFUN_ENVIRONMENT_INSERT:
1510 // Open the inset, and move the current selection
1512 doInsertInset(this, cmd, true, true);
1515 case LFUN_INDEX_INSERT:
1516 // Just open the inset
1517 doInsertInset(this, cmd, true, false);
1520 case LFUN_INDEX_PRINT:
1521 case LFUN_TOC_INSERT:
1524 doInsertInset(this, cmd, false, false);
1528 return UNDISPATCHED;