1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2002 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
16 #include "BufferView.h"
17 #include "funcrequest.h"
21 #include "bufferparams.h"
23 #include "ParagraphParameters.h"
29 #include "support/tostr.h"
30 #include "frontends/LyXView.h"
31 #include "frontends/screen.h"
32 #include "frontends/Dialogs.h"
33 #include "insets/insetspecialchar.h"
34 #include "insets/insettext.h"
35 #include "insets/insetquotes.h"
36 #include "insets/insetcommand.h"
37 #include "insets/insetnewline.h"
38 #include "undo_funcs.h"
39 #include "text_funcs.h"
50 extern string current_layout;
51 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
53 // the selection possible is needed, that only motion events are
54 // used, where the bottom press event was on the drawing area too
55 bool selection_possible = false;
60 void moveCursorUpdate(BufferView * bv, bool selecting)
62 LyXText * lt = bv->getLyXText();
64 if (selecting || lt->selection.mark()) {
67 bv->updateInset(lt->inset_owner);
71 if (!lt->isInInset()) {
72 bv->update(lt, BufferView::SELECT);
73 } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
74 bv->update(BufferView::SELECT);
77 if (!lt->selection.set())
78 bv->haveSelection(false);
84 void finishChange(BufferView * bv, bool selecting = false)
87 moveCursorUpdate(bv, selecting);
88 bv->owner()->view_state_changed();
91 // check if the given co-ordinates are inside an inset at the
92 // given cursor, if one exists. If so, the inset is returned,
93 // and the co-ordinates are made relative. Otherwise, 0 is returned.
94 Inset * checkInset(BufferView * bv, LyXText & text,
95 LyXCursor const & cur, int & x, int & y)
97 lyx::pos_type const pos = cur.pos();
98 Paragraph /*const*/ & par = *cur.par();
100 if (pos >= par.size() || !par.isInset(pos))
103 Inset /*const*/ * inset = par.getInset(pos);
105 if (!isEditableInset(inset))
108 // get inset dimensions
109 lyx::Assert(par.getInset(pos));
111 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
113 int const width = inset->width(bv, font);
114 int const inset_x = font.isVisibleRightToLeft()
115 ? (cur.ix() - width) : cur.ix();
118 inset_x + inset->scroll(),
120 cur.iy() - inset->ascent(bv, font),
121 cur.iy() + inset->descent(bv, font)
124 if (!b.contained(x, y)) {
125 lyxerr[Debug::GUI] << "Missed inset at x,y "
127 << " box " << b << endl;
131 text.setCursor(&par, pos, true);
134 // The origin of an inset is on the baseline
135 y -= text.cursor.iy();
143 Inset * LyXText::checkInsetHit(int & x, int & y)
145 int y_tmp = y + top_y();
148 setCursorFromCoordinates(cur, x, y_tmp);
150 Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
156 // look at previous position
161 setCursor(cur, cur.par(), cur.pos() - 1, true);
163 inset = checkInset(bv(), *this, cur, x, y_tmp);
170 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
171 string const & contents)
173 ParagraphList::iterator end = ownerParagraphs().end();
174 ParagraphList::iterator pit = cursor.par();
175 pos_type pos = cursor.pos();
179 if (pos + 1 < pit->size()) {
186 } while (pit != end &&
187 !(pit->isInset(pos) &&
188 (inset = pit->getInset(pos)) != 0 &&
189 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
191 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
195 setCursor(pit, pos, false);
202 void LyXText::gotoInset(vector<Inset::Code> const & codes,
205 bv()->beforeChange(this);
209 if (same_content && cursor.pos() < cursor.par()->size()
210 && cursor.par()->isInset(cursor.pos())) {
211 Inset const * inset = cursor.par()->getInset(cursor.pos());
212 if (find(codes.begin(), codes.end(), inset->lyxCode())
214 contents = static_cast<InsetCommand const *>(inset)->getContents();
217 if (!gotoNextInset(codes, contents)) {
218 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
219 LyXCursor tmp = cursor;
220 cursor.par(ownerParagraphs().begin());
222 if (!gotoNextInset(codes, contents)) {
224 bv()->owner()->message(_("No more insets"));
227 bv()->owner()->message(_("No more insets"));
231 selection.cursor = cursor;
235 void LyXText::gotoInset(Inset::Code code, bool same_content)
237 gotoInset(vector<Inset::Code>(1, code), same_content);
241 void LyXText::cursorPrevious()
245 if (cursor.row() == rows().begin()) {
247 int new_y = bv()->text->top_y() - bv()->workHeight();
248 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
249 bv()->updateScrollbar();
254 RowList::iterator cursorrow = cursor.row();
256 setCursorFromCoordinates(cursor.x_fix(), y);
260 if (cursorrow == bv()->text->cursor.row()) {
261 // we have a row which is taller than the workarea. The
262 // simplest solution is to move to the previous row instead.
265 // This is what we used to do, so we wouldn't skip right past
266 // tall rows, but it's not working right now.
268 new_y = bv->text->top_y() - bv->workHeight();
272 new_y = bv()->text->cursor.iy()
273 + bv()->theLockingInset()->insetInInsetY() + y
274 + cursor.row()->height()
275 - bv()->workHeight() + 1;
278 - cursor.row()->baseline()
279 + cursor.row()->height()
280 - bv()->workHeight() + 1;
283 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
284 if (cursor.row() != rows().begin()) {
286 setCursor(cur, boost::prior(cursor.row())->par(),
287 boost::prior(cursor.row())->pos(), false);
288 if (cur.y() > top_y()) {
292 bv()->updateScrollbar();
296 void LyXText::cursorNext()
300 if (boost::next(cursor.row()) == rows().end()) {
301 int y = cursor.y() - cursor.row()->baseline() +
302 cursor.row()->height();
303 if (y > topy + bv()->workHeight()) {
304 bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
305 bv()->updateScrollbar();
310 int y = topy + bv()->workHeight();
311 if (inset_owner && !topy) {
312 y -= (bv()->text->cursor.iy()
313 - bv()->text->top_y()
314 + bv()->theLockingInset()->insetInInsetY());
319 RowList::iterator cursorrow = cursor.row();
320 setCursorFromCoordinates(cursor.x_fix(), y);
321 // + bv->workHeight());
325 if (cursorrow == bv()->text->cursor.row()) {
326 // we have a row which is taller than the workarea. The
327 // simplest solution is to move to the next row instead.
330 // This is what we used to do, so we wouldn't skip right past
331 // tall rows, but it's not working right now.
333 new_y = bv->text->top_y() + bv->workHeight();
337 new_y = bv()->text->cursor.iy()
338 + bv()->theLockingInset()->insetInInsetY()
339 + y - cursor.row()->baseline();
341 new_y = cursor.y() - cursor.row()->baseline();
344 bv()->screen().draw(bv()->text, bv(), new_y);
345 if (boost::next(cursor.row()) != rows().end()) {
347 setCursor(cur, boost::next(cursor.row())->par(),
348 boost::next(cursor.row())->pos(), false);
349 if (cur.y() < top_y() + bv()->workHeight()) {
353 bv()->updateScrollbar();
357 void LyXText::update()
359 bv()->update(this, BufferView::SELECT);
364 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
367 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
368 if (!bv->insertInset(new_inset))
371 bv->updateInset(new_inset);
375 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
376 bool edit, bool pastesel)
378 Inset * inset = createInset(cmd);
379 BufferView * bv = cmd.view();
383 if (lt->selection.set()) {
384 lt->cutSelection(true, false);
387 if (bv->insertInset(inset)) {
390 if (gotsel && pastesel)
391 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
400 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
402 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
403 <<"] arg[" << cmd.argument << ']' << endl;
405 BufferView * bv = cmd.view();
407 switch (cmd.action) {
409 case LFUN_APPENDIX: {
410 ParagraphList::iterator pit = cursor.par();
411 bool start = !pit->params().startOfAppendix();
413 // ensure that we have only one start_of_appendix in this document
414 ParagraphList::iterator tmp = ownerParagraphs().begin();
415 ParagraphList::iterator end = ownerParagraphs().end();
417 for (; tmp != end; ++tmp) {
418 if (tmp->params().startOfAppendix()) {
419 setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
420 tmp->params().startOfAppendix(false);
422 setHeightOfRow(getRow(tmp, 0, tmpy));
427 setUndo(bv, Undo::EDIT, pit, boost::next(pit));
428 pit->params().startOfAppendix(start);
430 // we can set the refreshing parameters now
432 redoHeightOfParagraph();
434 setCursor(cursor.par(), cursor.pos());
439 case LFUN_DELETE_WORD_FORWARD:
440 bv->beforeChange(this);
447 case LFUN_DELETE_WORD_BACKWARD:
448 bv->beforeChange(this);
450 deleteWordBackward();
455 case LFUN_DELETE_LINE_FORWARD:
456 bv->beforeChange(this);
464 if (!selection.mark())
465 bv->beforeChange(this);
467 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
470 cursorRightOneWord();
475 if (!selection.mark())
476 bv->beforeChange(this);
478 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
479 cursorRightOneWord();
485 case LFUN_BEGINNINGBUF:
486 if (!selection.mark())
487 bv->beforeChange(this);
494 if (selection.mark())
495 bv->beforeChange(this);
503 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
507 finishChange(bv, true);
512 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
516 finishChange(bv, true);
522 finishChange(bv, true);
528 finishChange(bv, true);
531 case LFUN_UP_PARAGRAPHSEL:
534 finishChange(bv, true);
537 case LFUN_DOWN_PARAGRAPHSEL:
539 cursorDownParagraph();
540 finishChange(bv, true);
546 finishChange(bv, true);
552 finishChange(bv, true);
558 finishChange(bv, true);
564 finishChange(bv, true);
567 case LFUN_WORDRIGHTSEL:
569 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
572 cursorRightOneWord();
573 finishChange(bv, true);
576 case LFUN_WORDLEFTSEL:
578 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
579 cursorRightOneWord();
582 finishChange(bv, true);
589 getWord(cur1, cur2, WHOLE_WORD);
590 setCursor(cur1.par(), cur1.pos());
591 bv->beforeChange(this);
592 setCursor(cur2.par(), cur2.pos());
593 finishChange(bv, true);
598 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
599 if (!selection.mark())
600 bv->beforeChange(this);
604 if (cursor.pos() < cursor.par()->size()
605 && cursor.par()->isInset(cursor.pos())
606 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
607 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
608 cmd.message(tmpinset->editMessage());
609 tmpinset->edit(bv, !is_rtl);
619 // This is soooo ugly. Isn`t it possible to make
621 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
622 if (!selection.mark())
623 bv->beforeChange(this);
625 LyXCursor const cur = cursor;
628 if ((is_rtl || cur != cursor) && // only if really moved!
629 cursor.pos() < cursor.par()->size() &&
630 cursor.par()->isInset(cursor.pos()) &&
631 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
632 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
633 cmd.message(tmpinset->editMessage());
634 tmpinset->edit(bv, is_rtl);
644 if (!selection.mark())
645 bv->beforeChange(this);
646 bv->update(this, BufferView::UPDATE);
652 if (!selection.mark())
653 bv->beforeChange(this);
654 bv->update(this, BufferView::UPDATE);
659 case LFUN_UP_PARAGRAPH:
660 if (!selection.mark())
661 bv->beforeChange(this);
662 bv->update(this, BufferView::UPDATE);
667 case LFUN_DOWN_PARAGRAPH:
668 if (!selection.mark())
669 bv->beforeChange(this);
670 bv->update(this, BufferView::UPDATE);
671 cursorDownParagraph();
672 finishChange(bv, false);
676 if (!selection.mark())
677 bv->beforeChange(this);
678 bv->update(this, BufferView::UPDATE);
680 finishChange(bv, false);
683 // moveCursorUpdate(bv, false, false);
684 // owner_->view_state_changed();
688 if (!selection.mark())
689 bv->beforeChange(this);
690 bv->update(this, BufferView::UPDATE);
692 finishChange(bv, false);
696 if (!selection.mark())
697 bv->beforeChange(this);
700 finishChange(bv, false);
704 if (!selection.mark())
705 bv->beforeChange(this);
708 finishChange(bv, false);
711 case LFUN_BREAKLINE: {
712 lyx::pos_type body = cursor.par()->beginningOfBody();
714 // Not allowed by LaTeX (labels or empty par)
715 if (cursor.pos() <= body)
718 bv->beforeChange(this);
719 insertInset(new InsetNewline);
721 setCursor(cursor.par(), cursor.pos());
722 moveCursorUpdate(bv, false);
727 if (!selection.set()) {
729 selection.cursor = cursor;
731 // It is possible to make it a lot faster still
732 // just comment out the line below...
735 cutSelection(bv, true);
738 moveCursorUpdate(bv, false);
739 bv->owner()->view_state_changed();
743 case LFUN_DELETE_SKIP:
744 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
745 if (!selection.set()) {
746 LyXCursor cur = cursor;
747 if (cur.pos() == cur.par()->size()) {
751 && !(cur.par()->params().spaceTop()
752 == VSpace (VSpace::NONE))) {
754 cur.par()->params().lineTop(),
755 cur.par()->params().lineBottom(),
756 cur.par()->params().pagebreakTop(),
757 cur.par()->params().pagebreakBottom(),
758 VSpace(VSpace::NONE),
759 cur.par()->params().spaceBottom(),
760 cur.par()->params().spacing(),
761 cur.par()->params().align(),
762 cur.par()->params().labelWidthString(), 0);
768 selection.cursor = cursor;
772 selection.cursor = cursor;
776 cutSelection(bv, true);
783 if (!selection.set()) {
784 if (bv->owner()->getIntl().getTransManager().backspace()) {
786 selection.cursor = cursor;
788 // It is possible to make it a lot faster still
789 // just comment out the line below...
793 cutSelection(bv, true);
796 bv->owner()->view_state_changed();
800 case LFUN_BACKSPACE_SKIP:
801 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
802 if (!selection.set()) {
803 LyXCursor cur = cursor;
805 && !(cur.par()->params().spaceTop()
806 == VSpace (VSpace::NONE))) {
808 cur.par()->params().lineTop(),
809 cur.par()->params().lineBottom(),
810 cur.par()->params().pagebreakTop(),
811 cur.par()->params().pagebreakBottom(),
812 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
813 cur.par()->params().spacing(),
814 cur.par()->params().align(),
815 cur.par()->params().labelWidthString(), 0);
818 selection.cursor = cur;
822 cutSelection(bv, true);
827 case LFUN_BREAKPARAGRAPH:
828 bv->beforeChange(this);
829 breakParagraph(bv->buffer()->paragraphs, 0);
831 selection.cursor = cursor;
833 bv->owner()->view_state_changed();
836 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
837 bv->beforeChange(this);
838 breakParagraph(bv->buffer()->paragraphs, 1);
840 selection.cursor = cursor;
842 bv->owner()->view_state_changed();
845 case LFUN_BREAKPARAGRAPH_SKIP: {
846 // When at the beginning of a paragraph, remove
847 // indentation and add a "defskip" at the top.
848 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
849 LyXCursor cur = cursor;
850 bv->beforeChange(this);
851 if (cur.pos() == 0) {
852 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
854 cur.par()->params().lineTop(),
855 cur.par()->params().lineBottom(),
856 cur.par()->params().pagebreakTop(),
857 cur.par()->params().pagebreakBottom(),
858 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
859 cur.par()->params().spacing(),
860 cur.par()->params().align(),
861 cur.par()->params().labelWidthString(), 1);
865 breakParagraph(bv->buffer()->paragraphs, 0);
868 selection.cursor = cur;
870 bv->owner()->view_state_changed();
874 case LFUN_PARAGRAPH_SPACING: {
875 ParagraphList::iterator pit = cursor.par();
876 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
877 float cur_value = 1.0;
878 if (cur_spacing == Spacing::Other)
879 cur_value = pit->params().spacing().getValue();
881 istringstream is(STRCONV(cmd.argument));
884 Spacing::Space new_spacing = cur_spacing;
885 float new_value = cur_value;
887 lyxerr << "Missing argument to `paragraph-spacing'"
889 } else if (tmp == "single") {
890 new_spacing = Spacing::Single;
891 } else if (tmp == "onehalf") {
892 new_spacing = Spacing::Onehalf;
893 } else if (tmp == "double") {
894 new_spacing = Spacing::Double;
895 } else if (tmp == "other") {
896 new_spacing = Spacing::Other;
899 lyxerr << "new_value = " << tmpval << endl;
902 } else if (tmp == "default") {
903 new_spacing = Spacing::Default;
905 lyxerr << _("Unknown spacing argument: ")
906 << cmd.argument << endl;
908 if (cur_spacing != new_spacing || cur_value != new_value) {
909 pit->params().spacing(Spacing(new_spacing, new_value));
916 case LFUN_INSET_SETTINGS:
917 lyx::Assert(bv->theLockingInset());
918 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
921 case LFUN_INSET_TOGGLE:
922 bv->beforeChange(this);
929 case LFUN_PROTECTEDSPACE:
930 if (cursor.par()->layout()->free_spacing) {
934 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
936 moveCursorUpdate(bv, false);
939 case LFUN_HYPHENATION:
940 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
943 case LFUN_LIGATURE_BREAK:
944 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
948 specialChar(this, bv, InsetSpecialChar::LDOTS);
951 case LFUN_END_OF_SENTENCE:
952 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
955 case LFUN_MENU_SEPARATOR:
956 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
960 bv->beforeChange(this);
962 selection.cursor = cursor;
963 cmd.message(N_("Mark off"));
967 bv->beforeChange(this);
968 selection.mark(true);
970 selection.cursor = cursor;
971 cmd.message(N_("Mark on"));
975 bv->beforeChange(this);
976 if (selection.mark()) {
978 cmd.message(N_("Mark removed"));
980 selection.mark(true);
982 cmd.message(N_("Mark set"));
984 selection.cursor = cursor;
987 case LFUN_UPCASE_WORD:
989 changeCase(LyXText::text_uppercase);
991 bv->updateInset(inset_owner);
995 case LFUN_LOWCASE_WORD:
997 changeCase(LyXText::text_lowercase);
999 bv->updateInset(inset_owner);
1003 case LFUN_CAPITALIZE_WORD:
1005 changeCase(LyXText::text_capitalization);
1007 bv->updateInset(inset_owner);
1011 case LFUN_TRANSPOSE_CHARS:
1013 transposeChars(*this, cursor);
1015 bv->updateInset(inset_owner);
1020 cmd.message(_("Paste"));
1021 // clear the selection
1022 bv->toggleSelection();
1026 clearSelection(); // bug 393
1033 cutSelection(bv, true);
1035 cmd.message(_("Cut"));
1040 cmd.message(_("Copy"));
1043 case LFUN_BEGINNINGBUFSEL:
1045 return UNDISPATCHED;
1048 finishChange(bv, true);
1051 case LFUN_ENDBUFSEL:
1053 return UNDISPATCHED;
1056 finishChange(bv, true);
1060 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1066 istringstream is(STRCONV(cmd.argument));
1069 lyxerr << "SETXY: Could not parse coordinates in '"
1070 << cmd.argument << std::endl;
1072 setCursorFromCoordinates(x, y);
1077 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1079 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1085 case LFUN_GETLAYOUT:
1086 cmd.message(tostr(cursor.par()->layout()));
1090 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1091 << cmd.argument << endl;
1093 // This is not the good solution to the empty argument
1094 // problem, but it will hopefully suffice for 1.2.0.
1095 // The correct solution would be to augument the
1096 // function list/array with information about what
1097 // functions needs arguments and their type.
1098 if (cmd.argument.empty()) {
1099 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1103 // Derive layout number from given argument (string)
1104 // and current buffer's textclass (number)
1105 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1106 bool hasLayout = tclass.hasLayout(cmd.argument);
1107 string layout = cmd.argument;
1109 // If the entry is obsolete, use the new one instead.
1111 string const & obs = tclass[layout]->obsoleted_by();
1117 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1122 bool change_layout = (current_layout != layout);
1123 if (!change_layout && selection.set() &&
1124 selection.start.par() != selection.end.par())
1126 ParagraphList::iterator spit = selection.start.par();
1127 ParagraphList::iterator epit = boost::next(selection.end.par());
1128 while (spit != epit) {
1129 if (spit->layout()->name() != current_layout) {
1130 change_layout = true;
1136 if (change_layout) {
1137 current_layout = layout;
1140 bv->owner()->setLayout(layout);
1147 case LFUN_PASTESELECTION: {
1150 // this was originally a beforeChange(bv->text), i.e
1151 // the outermost LyXText!
1152 bv->beforeChange(this);
1153 string const clip = bv->getClipboard();
1154 if (!clip.empty()) {
1155 if (cmd.argument == "paragraph")
1156 insertStringAsParagraphs(clip);
1158 insertStringAsLines(clip);
1165 case LFUN_GOTOERROR:
1166 gotoInset(Inset::ERROR_CODE, false);
1170 gotoInset(Inset::NOTE_CODE, false);
1173 case LFUN_REFERENCE_GOTO:
1175 vector<Inset::Code> tmp;
1176 tmp.push_back(Inset::LABEL_CODE);
1177 tmp.push_back(Inset::REF_CODE);
1178 gotoInset(tmp, true);
1183 ParagraphList::iterator pit = cursor.par();
1184 lyx::pos_type pos = cursor.pos();
1188 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1191 c = pit->getChar(pos - 1);
1193 LyXLayout_ptr const & style = pit->layout();
1195 if (style->pass_thru ||
1196 pit->getFontSettings(bv->buffer()->params,
1197 pos).language()->lang() == "hebrew" ||
1198 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1199 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1203 case LFUN_DATE_INSERT: {
1204 time_t now_time_t = time(NULL);
1205 struct tm * now_tm = localtime(&now_time_t);
1206 setlocale(LC_TIME, "");
1208 if (!cmd.argument.empty())
1211 arg = lyxrc.date_insert_format;
1213 int const datetmp_len =
1214 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1216 for (int i = 0; i < datetmp_len; i++) {
1217 insertChar(datetmp[i]);
1220 selection.cursor = cursor;
1221 moveCursorUpdate(bv, false);
1225 case LFUN_MOUSE_TRIPLE:
1228 if (!isInInset() && bv->theLockingInset())
1230 if (cmd.button() == mouse_button::button1) {
1232 bv->screen().toggleSelection(this, bv);
1235 selection.cursor = cursor;
1239 bv->screen().toggleSelection(this, bv, false);
1241 bv->haveSelection(selection.set());
1245 case LFUN_MOUSE_DOUBLE:
1248 if (!isInInset() && bv->theLockingInset())
1250 if (cmd.button() == mouse_button::button1) {
1252 bv->screen().toggleSelection(this, bv);
1253 selectWord(LyXText::WHOLE_WORD_STRICT);
1254 bv->screen().toggleSelection(this, bv, false);
1256 selectWord(LyXText::WHOLE_WORD_STRICT);
1259 bv->haveSelection(selection.set());
1263 case LFUN_MOUSE_MOTION:
1265 // Only use motion with button 1
1266 //if (ev.button() != mouse_button::button1)
1272 // Check for inset locking
1273 if (bv->theLockingInset()) {
1274 Inset * tli = bv->theLockingInset();
1275 LyXCursor cursor = bv->text->cursor;
1276 LyXFont font = bv->text->getFont(bv->buffer(),
1277 cursor.par(), cursor.pos());
1278 int width = tli->width(bv, font);
1279 int inset_x = font.isVisibleRightToLeft()
1280 ? cursor.ix() - width : cursor.ix();
1281 int start_x = inset_x + tli->scroll();
1282 FuncRequest cmd1 = cmd;
1283 cmd1.x = cmd.x - start_x;
1284 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1285 tli->localDispatch(cmd1);
1289 // The test for not selection possible is needed, that only motion
1290 // events are used, where the bottom press event was on
1291 // the drawing area too
1292 if (!selection_possible) {
1293 lyxerr[Debug::ACTION]
1294 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1298 RowList::iterator cursorrow = bv->text->cursor.row();
1299 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1301 // sorry for this but I have a strange error that the y value jumps at
1302 // a certain point. This seems like an error in my xforms library or
1303 // in some other local environment, but I would like to leave this here
1304 // for the moment until I can remove this (Jug 20020418)
1305 if (y_before < bv->text->cursor.y())
1306 lyxerr << y_before << ':'
1307 << bv->text->cursor.y() << endl;
1309 // This is to allow jumping over large insets
1310 if (cursorrow == bv->text->cursor.row()) {
1311 if (cmd.y >= bv->workHeight())
1312 bv->text->cursorDown(false);
1314 bv->text->cursorUp(false);
1317 // Maybe an empty line was deleted
1318 if (!bv->text->selection.set())
1319 bv->update(BufferView::UPDATE);
1320 bv->text->setSelection();
1321 bv->screen().toggleToggle(bv->text, bv);
1326 // Single-click on work area
1327 case LFUN_MOUSE_PRESS:
1332 // ok ok, this is a hack (for xforms)
1333 // We shouldn't go further down as we really should only do the
1334 // scrolling and be done with this. Otherwise we may open some
1335 // dialogs (Jug 20020424).
1336 if (cmd.button() == mouse_button::button4) {
1337 bv->scroll(-lyxrc.wheel_jump);
1340 if (cmd.button() == mouse_button::button5) {
1341 bv->scroll(lyxrc.wheel_jump);
1347 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1349 // Middle button press pastes if we have a selection
1350 // We do this here as if the selection was inside an inset
1351 // it could get cleared on the unlocking of the inset so
1352 // we have to check this first
1353 bool paste_internally = false;
1354 if (cmd.button() == mouse_button::button2 && selection.set()) {
1355 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1356 paste_internally = true;
1359 int const screen_first = bv->text->top_y();
1361 if (bv->theLockingInset()) {
1362 // We are in inset locking mode
1364 // Check whether the inset was hit. If not reset mode,
1365 // otherwise give the event to the inset
1366 if (inset_hit == bv->theLockingInset()) {
1367 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1368 bv->theLockingInset()->localDispatch(cmd1);
1371 bv->unlockInset(bv->theLockingInset());
1375 selection_possible = true;
1377 // Clear the selection
1378 bv->screen().toggleSelection(bv->text, bv);
1379 bv->text->clearSelection();
1380 bv->text->fullRebreak();
1382 bv->updateScrollbar();
1384 // Single left click in math inset?
1385 if (isHighlyEditableInset(inset_hit)) {
1386 // Highly editable inset, like math
1387 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1388 selection_possible = false;
1389 bv->owner()->message(inset->editMessage());
1390 // We just have to lock the inset before calling a PressEvent on it!
1391 if (!bv->lockInset(inset))
1392 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1393 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1394 inset->localDispatch(cmd1);
1397 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1399 // Right click on a footnote flag opens float menu
1400 if (cmd.button() == mouse_button::button3) {
1401 selection_possible = false;
1405 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1406 bv->text->setCursorFromCoordinates(x, y + screen_first);
1408 bv->text->selection.cursor = bv->text->cursor;
1409 bv->text->cursor.x_fix(bv->text->cursor.x());
1411 if (bv->fitCursor())
1412 selection_possible = false;
1414 // Insert primary selection with middle mouse
1415 // if there is a local selection in the current buffer,
1417 if (cmd.button() == mouse_button::button2) {
1418 if (paste_internally)
1419 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1421 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1422 selection_possible = false;
1427 case LFUN_MOUSE_RELEASE:
1429 // do nothing if we used the mouse wheel
1433 if (cmd.button() == mouse_button::button4
1434 || cmd.button() == mouse_button::button5)
1437 // If we hit an inset, we have the inset coordinates in these
1438 // and inset_hit points to the inset. If we do not hit an
1439 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1442 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1444 if (bv->theLockingInset()) {
1445 // We are in inset locking mode.
1447 // LyX does a kind of work-area grabbing for insets.
1448 // Only a ButtonPress FuncRequest outside the inset will
1449 // force a insetUnlock.
1450 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1451 bv->theLockingInset()->localDispatch(cmd1);
1455 selection_possible = false;
1457 if (cmd.button() == mouse_button::button2)
1461 if (cmd.button() == mouse_button::button1)
1462 bv->haveSelection(selection.set());
1465 bv->owner()->view_state_changed();
1466 bv->owner()->updateMenubar();
1467 bv->owner()->updateToolbar();
1469 // Did we hit an editable inset?
1471 selection_possible = false;
1473 // if we reach this point with a selection, it
1474 // must mean we are currently selecting.
1475 // But we don't want to open the inset
1476 // because that is annoying for the user.
1477 // So just pretend we didn't hit it.
1478 // this is OK because a "kosher" ButtonRelease
1479 // will follow a ButtonPress that clears
1481 // Note this also fixes selection drawing
1482 // problems if we end up opening an inset
1483 if (selection.set())
1486 // CHECK fix this proper in 0.13
1487 // well, maybe 13.0 !!!!!!!!!
1489 // Following a ref shouldn't issue
1490 // a push on the undo-stack
1491 // anylonger, now that we have
1492 // keybindings for following
1493 // references and returning from
1494 // references. IMHO though, it
1495 // should be the inset's own business
1496 // to push or not push on the undo
1497 // stack. They don't *have* to
1498 // alter the document...
1500 // ...or maybe the SetCursorParUndo()
1501 // below isn't necessary at all anylonger?
1502 if (inset_hit->lyxCode() == Inset::REF_CODE)
1503 setCursorParUndo(bv);
1505 bv->owner()->message(inset_hit->editMessage());
1507 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1508 inset_hit->localDispatch(cmd1);
1514 case LFUN_SELFINSERT: {
1515 if (cmd.argument.empty())
1518 // Automatically delete the currently selected
1519 // text and replace it with what is being
1520 // typed in now. Depends on lyxrc settings
1521 // "auto_region_delete", which defaults to
1524 if (lyxrc.auto_region_delete) {
1525 if (selection.set()) {
1526 cutSelection(false, false);
1529 bv->haveSelection(false);
1532 bv->beforeChange(this);
1533 LyXFont const old_font(real_current_font);
1535 string::const_iterator cit = cmd.argument.begin();
1536 string::const_iterator end = cmd.argument.end();
1537 for (; cit != end; ++cit)
1538 bv->owner()->getIntl().getTransManager().
1539 TranslateAndInsert(*cit, this);
1542 selection.cursor = cursor;
1543 moveCursorUpdate(bv, false);
1545 // real_current_font.number can change so we need to
1546 // update the minibuffer
1547 if (old_font != real_current_font)
1548 bv->owner()->view_state_changed();
1552 case LFUN_HTMLURL: {
1553 InsetCommandParams p("htmlurl");
1554 string const data = InsetCommandMailer::params2string("url", p);
1555 bv->owner()->getDialogs().show("url", data, 0);
1560 InsetCommandParams p("url");
1561 string const data = InsetCommandMailer::params2string("url", p);
1562 bv->owner()->getDialogs().show("url", data, 0);
1568 case LFUN_INSET_LIST:
1569 case LFUN_INSET_THEOREM:
1570 case LFUN_INSET_CAPTION:
1572 case LFUN_INSERT_NOTE:
1573 case LFUN_INSERT_BIBITEM:
1574 case LFUN_INSET_ERT:
1575 case LFUN_INSET_FLOAT:
1576 case LFUN_INSET_FOOTNOTE:
1577 case LFUN_INSET_MARGINAL:
1578 case LFUN_INSET_MINIPAGE:
1579 case LFUN_INSET_OPTARG:
1580 case LFUN_INSET_WIDE_FLOAT:
1581 case LFUN_INSET_WRAP:
1582 case LFUN_TABULAR_INSERT:
1583 case LFUN_ENVIRONMENT_INSERT:
1584 // Open the inset, and move the current selection
1586 doInsertInset(this, cmd, true, true);
1589 case LFUN_INDEX_INSERT:
1590 // Just open the inset
1591 doInsertInset(this, cmd, true, false);
1594 case LFUN_INDEX_PRINT:
1595 case LFUN_PARENTINSERT:
1596 case LFUN_TOC_INSERT:
1599 doInsertInset(this, cmd, false, false);
1603 return UNDISPATCHED;