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"
20 #include "bufferparams.h"
22 #include "ParagraphParameters.h"
28 #include "support/lstrings.h"
29 #include "frontends/LyXView.h"
30 #include "frontends/screen.h"
31 #include "frontends/Dialogs.h"
32 #include "insets/insetspecialchar.h"
33 #include "insets/insettext.h"
34 #include "insets/insetquotes.h"
35 #include "insets/insetcommand.h"
36 #include "insets/insetnewline.h"
37 #include "undo_funcs.h"
38 #include "text_funcs.h"
48 extern string current_layout;
49 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
51 // the selection possible is needed, that only motion events are
52 // used, where the bottom press event was on the drawing area too
53 bool selection_possible = false;
58 void moveCursorUpdate(BufferView * bv, bool selecting)
60 LyXText * lt = bv->getLyXText();
62 if (selecting || lt->selection.mark()) {
65 bv->updateInset(lt->inset_owner);
69 if (!lt->isInInset()) {
70 bv->update(lt, BufferView::SELECT);
71 } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
72 bv->update(BufferView::SELECT);
75 if (!lt->selection.set())
76 bv->haveSelection(false);
82 void finishChange(BufferView * bv, bool selecting = false)
85 moveCursorUpdate(bv, selecting);
86 bv->owner()->view_state_changed();
89 // check if the given co-ordinates are inside an inset at the
90 // given cursor, if one exists. If so, the inset is returned,
91 // and the co-ordinates are made relative. Otherwise, 0 is returned.
92 Inset * checkInset(BufferView * bv, LyXText & text,
93 LyXCursor const & cur, int & x, int & y)
95 lyx::pos_type const pos = cur.pos();
96 Paragraph /*const*/ & par = *cur.par();
98 if (pos >= par.size() || !par.isInset(pos))
101 Inset /*const*/ * inset = par.getInset(pos);
103 if (!isEditableInset(inset))
106 // get inset dimensions
107 lyx::Assert(par.getInset(pos));
109 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
111 int const width = inset->width(bv, font);
112 int const inset_x = font.isVisibleRightToLeft()
113 ? (cur.ix() - width) : cur.ix();
116 inset_x + inset->scroll(),
118 cur.iy() - inset->ascent(bv, font),
119 cur.iy() + inset->descent(bv, font)
122 if (!b.contained(x, y)) {
123 lyxerr[Debug::GUI] << "Missed inset at x,y "
125 << " box " << b << endl;
129 text.setCursor(&par, pos, true);
132 // The origin of an inset is on the baseline
133 y -= text.cursor.iy();
141 Inset * LyXText::checkInsetHit(int & x, int & y)
143 int y_tmp = y + top_y();
146 setCursorFromCoordinates(cur, x, y_tmp);
148 Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
154 // look at previous position
159 setCursor(cur, cur.par(), cur.pos() - 1, true);
161 inset = checkInset(bv(), *this, cur, x, y_tmp);
168 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
169 string const & contents)
171 ParagraphList::iterator end = ownerParagraphs().end();
172 ParagraphList::iterator pit = cursor.par();
173 pos_type pos = cursor.pos();
177 if (pos + 1 < pit->size()) {
184 } while (pit != end &&
185 !(pit->isInset(pos) &&
186 (inset = pit->getInset(pos)) != 0 &&
187 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
189 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
193 setCursor(pit, pos, false);
200 void LyXText::gotoInset(vector<Inset::Code> const & codes,
203 bv()->beforeChange(this);
207 if (same_content && cursor.pos() < cursor.par()->size()
208 && cursor.par()->isInset(cursor.pos())) {
209 Inset 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(Inset::Code code, bool same_content)
235 gotoInset(vector<Inset::Code>(1, code), same_content);
239 void LyXText::cursorPrevious()
243 if (cursor.row() == rows().begin()) {
245 int new_y = bv()->text->top_y() - bv()->workHeight();
246 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
247 bv()->updateScrollbar();
252 RowList::iterator cursorrow = cursor.row();
254 setCursorFromCoordinates(cursor.x_fix(), y);
258 if (cursorrow == bv()->text->cursor.row()) {
259 // we have a row which is taller than the workarea. The
260 // simplest solution is to move to the previous row instead.
263 // This is what we used to do, so we wouldn't skip right past
264 // tall rows, but it's not working right now.
266 new_y = bv->text->top_y() - bv->workHeight();
270 new_y = bv()->text->cursor.iy()
271 + bv()->theLockingInset()->insetInInsetY() + y
272 + cursor.row()->height()
273 - bv()->workHeight() + 1;
276 - cursor.row()->baseline()
277 + cursor.row()->height()
278 - bv()->workHeight() + 1;
281 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
282 if (cursor.row() != rows().begin()) {
284 setCursor(cur, boost::prior(cursor.row())->par(),
285 boost::prior(cursor.row())->pos(), false);
286 if (cur.y() > top_y()) {
290 bv()->updateScrollbar();
294 void LyXText::cursorNext()
298 if (boost::next(cursor.row()) == rows().end()) {
299 int y = cursor.y() - cursor.row()->baseline() +
300 cursor.row()->height();
301 if (y > topy + bv()->workHeight()) {
302 bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
303 bv()->updateScrollbar();
308 int y = topy + bv()->workHeight();
309 if (inset_owner && !topy) {
310 y -= (bv()->text->cursor.iy()
311 - bv()->text->top_y()
312 + bv()->theLockingInset()->insetInInsetY());
317 RowList::iterator cursorrow = cursor.row();
318 setCursorFromCoordinates(cursor.x_fix(), y);
319 // + bv->workHeight());
323 if (cursorrow == bv()->text->cursor.row()) {
324 // we have a row which is taller than the workarea. The
325 // simplest solution is to move to the next row instead.
328 // This is what we used to do, so we wouldn't skip right past
329 // tall rows, but it's not working right now.
331 new_y = bv->text->top_y() + bv->workHeight();
335 new_y = bv()->text->cursor.iy()
336 + bv()->theLockingInset()->insetInInsetY()
337 + y - cursor.row()->baseline();
339 new_y = cursor.y() - cursor.row()->baseline();
342 bv()->screen().draw(bv()->text, bv(), new_y);
343 if (boost::next(cursor.row()) != rows().end()) {
345 setCursor(cur, boost::next(cursor.row())->par(),
346 boost::next(cursor.row())->pos(), false);
347 if (cur.y() < top_y() + bv()->workHeight()) {
351 bv()->updateScrollbar();
355 void LyXText::update()
357 bv()->update(this, BufferView::SELECT);
362 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
365 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
366 if (!bv->insertInset(new_inset))
369 bv->updateInset(new_inset);
373 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
374 bool edit, bool pastesel)
376 Inset * inset = createInset(cmd);
377 BufferView * bv = cmd.view();
381 if (lt->selection.set()) {
382 lt->cutSelection(true, false);
385 if (bv->insertInset(inset)) {
388 if (gotsel && pastesel)
389 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
398 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
400 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
401 <<"] arg[" << cmd.argument << ']' << endl;
403 BufferView * bv = cmd.view();
405 switch (cmd.action) {
407 case LFUN_APPENDIX: {
408 ParagraphList::iterator pit = cursor.par();
409 bool start = !pit->params().startOfAppendix();
411 // ensure that we have only one start_of_appendix in this document
412 ParagraphList::iterator tmp = ownerParagraphs().begin();
413 ParagraphList::iterator end = ownerParagraphs().end();
415 for (; tmp != end; ++tmp) {
416 if (tmp->params().startOfAppendix()) {
417 setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
418 tmp->params().startOfAppendix(false);
420 setHeightOfRow(getRow(tmp, 0, tmpy));
425 setUndo(bv, Undo::EDIT, pit, boost::next(pit));
426 pit->params().startOfAppendix(start);
428 // we can set the refreshing parameters now
430 redoHeightOfParagraph();
432 setCursor(cursor.par(), cursor.pos());
437 case LFUN_DELETE_WORD_FORWARD:
438 bv->beforeChange(this);
445 case LFUN_DELETE_WORD_BACKWARD:
446 bv->beforeChange(this);
448 deleteWordBackward();
453 case LFUN_DELETE_LINE_FORWARD:
454 bv->beforeChange(this);
462 if (!selection.mark())
463 bv->beforeChange(this);
465 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
468 cursorRightOneWord();
473 if (!selection.mark())
474 bv->beforeChange(this);
476 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
477 cursorRightOneWord();
483 case LFUN_BEGINNINGBUF:
484 if (!selection.mark())
485 bv->beforeChange(this);
492 if (selection.mark())
493 bv->beforeChange(this);
501 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
505 finishChange(bv, true);
510 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
514 finishChange(bv, true);
520 finishChange(bv, true);
526 finishChange(bv, true);
529 case LFUN_UP_PARAGRAPHSEL:
532 finishChange(bv, true);
535 case LFUN_DOWN_PARAGRAPHSEL:
537 cursorDownParagraph();
538 finishChange(bv, true);
544 finishChange(bv, true);
550 finishChange(bv, true);
556 finishChange(bv, true);
562 finishChange(bv, true);
565 case LFUN_WORDRIGHTSEL:
567 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
570 cursorRightOneWord();
571 finishChange(bv, true);
574 case LFUN_WORDLEFTSEL:
576 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
577 cursorRightOneWord();
580 finishChange(bv, true);
587 getWord(cur1, cur2, WHOLE_WORD);
588 setCursor(cur1.par(), cur1.pos());
589 bv->beforeChange(this);
590 setCursor(cur2.par(), cur2.pos());
591 finishChange(bv, true);
596 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
597 if (!selection.mark())
598 bv->beforeChange(this);
602 if (cursor.pos() < cursor.par()->size()
603 && cursor.par()->isInset(cursor.pos())
604 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
605 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
606 cmd.message(tmpinset->editMessage());
607 tmpinset->edit(bv, !is_rtl);
617 // This is soooo ugly. Isn`t it possible to make
619 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
620 if (!selection.mark())
621 bv->beforeChange(this);
623 LyXCursor const cur = cursor;
626 if ((is_rtl || cur != cursor) && // only if really moved!
627 cursor.pos() < cursor.par()->size() &&
628 cursor.par()->isInset(cursor.pos()) &&
629 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
630 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
631 cmd.message(tmpinset->editMessage());
632 tmpinset->edit(bv, is_rtl);
642 if (!selection.mark())
643 bv->beforeChange(this);
644 bv->update(this, BufferView::UPDATE);
650 if (!selection.mark())
651 bv->beforeChange(this);
652 bv->update(this, BufferView::UPDATE);
657 case LFUN_UP_PARAGRAPH:
658 if (!selection.mark())
659 bv->beforeChange(this);
660 bv->update(this, BufferView::UPDATE);
665 case LFUN_DOWN_PARAGRAPH:
666 if (!selection.mark())
667 bv->beforeChange(this);
668 bv->update(this, BufferView::UPDATE);
669 cursorDownParagraph();
670 finishChange(bv, false);
674 if (!selection.mark())
675 bv->beforeChange(this);
676 bv->update(this, BufferView::UPDATE);
678 finishChange(bv, false);
681 // moveCursorUpdate(bv, false, false);
682 // owner_->view_state_changed();
686 if (!selection.mark())
687 bv->beforeChange(this);
688 bv->update(this, BufferView::UPDATE);
690 finishChange(bv, false);
694 if (!selection.mark())
695 bv->beforeChange(this);
698 finishChange(bv, false);
702 if (!selection.mark())
703 bv->beforeChange(this);
706 finishChange(bv, false);
709 case LFUN_BREAKLINE: {
710 lyx::pos_type body = cursor.par()->beginningOfBody();
712 // Not allowed by LaTeX (labels or empty par)
713 if (cursor.pos() <= body)
716 bv->beforeChange(this);
717 insertInset(new InsetNewline);
719 setCursor(cursor.par(), cursor.pos());
720 moveCursorUpdate(bv, false);
725 if (!selection.set()) {
727 selection.cursor = cursor;
729 // It is possible to make it a lot faster still
730 // just comment out the line below...
733 cutSelection(bv, true);
736 moveCursorUpdate(bv, false);
737 bv->owner()->view_state_changed();
741 case LFUN_DELETE_SKIP:
742 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
743 if (!selection.set()) {
744 LyXCursor cur = cursor;
745 if (cur.pos() == cur.par()->size()) {
749 && !(cur.par()->params().spaceTop()
750 == VSpace (VSpace::NONE))) {
752 cur.par()->params().lineTop(),
753 cur.par()->params().lineBottom(),
754 cur.par()->params().pagebreakTop(),
755 cur.par()->params().pagebreakBottom(),
756 VSpace(VSpace::NONE),
757 cur.par()->params().spaceBottom(),
758 cur.par()->params().spacing(),
759 cur.par()->params().align(),
760 cur.par()->params().labelWidthString(), 0);
766 selection.cursor = cursor;
770 selection.cursor = cursor;
774 cutSelection(bv, true);
781 if (!selection.set()) {
782 if (bv->owner()->getIntl().getTransManager().backspace()) {
784 selection.cursor = cursor;
786 // It is possible to make it a lot faster still
787 // just comment out the line below...
791 cutSelection(bv, true);
794 bv->owner()->view_state_changed();
798 case LFUN_BACKSPACE_SKIP:
799 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
800 if (!selection.set()) {
801 LyXCursor cur = cursor;
803 && !(cur.par()->params().spaceTop()
804 == VSpace (VSpace::NONE))) {
806 cur.par()->params().lineTop(),
807 cur.par()->params().lineBottom(),
808 cur.par()->params().pagebreakTop(),
809 cur.par()->params().pagebreakBottom(),
810 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
811 cur.par()->params().spacing(),
812 cur.par()->params().align(),
813 cur.par()->params().labelWidthString(), 0);
816 selection.cursor = cur;
820 cutSelection(bv, true);
825 case LFUN_BREAKPARAGRAPH:
826 bv->beforeChange(this);
827 breakParagraph(bv->buffer()->paragraphs, 0);
829 selection.cursor = cursor;
831 bv->owner()->view_state_changed();
834 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
835 bv->beforeChange(this);
836 breakParagraph(bv->buffer()->paragraphs, 1);
838 selection.cursor = cursor;
840 bv->owner()->view_state_changed();
843 case LFUN_BREAKPARAGRAPH_SKIP: {
844 // When at the beginning of a paragraph, remove
845 // indentation and add a "defskip" at the top.
846 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
847 LyXCursor cur = cursor;
848 bv->beforeChange(this);
849 if (cur.pos() == 0) {
850 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
852 cur.par()->params().lineTop(),
853 cur.par()->params().lineBottom(),
854 cur.par()->params().pagebreakTop(),
855 cur.par()->params().pagebreakBottom(),
856 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
857 cur.par()->params().spacing(),
858 cur.par()->params().align(),
859 cur.par()->params().labelWidthString(), 1);
863 breakParagraph(bv->buffer()->paragraphs, 0);
866 selection.cursor = cur;
868 bv->owner()->view_state_changed();
872 case LFUN_PARAGRAPH_SPACING: {
873 ParagraphList::iterator pit = cursor.par();
874 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
875 float cur_value = 1.0;
876 if (cur_spacing == Spacing::Other)
877 cur_value = pit->params().spacing().getValue();
879 istringstream is(cmd.argument.c_str());
882 Spacing::Space new_spacing = cur_spacing;
883 float new_value = cur_value;
885 lyxerr << "Missing argument to `paragraph-spacing'"
887 } else if (tmp == "single") {
888 new_spacing = Spacing::Single;
889 } else if (tmp == "onehalf") {
890 new_spacing = Spacing::Onehalf;
891 } else if (tmp == "double") {
892 new_spacing = Spacing::Double;
893 } else if (tmp == "other") {
894 new_spacing = Spacing::Other;
897 lyxerr << "new_value = " << tmpval << endl;
900 } else if (tmp == "default") {
901 new_spacing = Spacing::Default;
903 lyxerr << _("Unknown spacing argument: ")
904 << cmd.argument << endl;
906 if (cur_spacing != new_spacing || cur_value != new_value) {
907 pit->params().spacing(Spacing(new_spacing, new_value));
914 case LFUN_INSET_SETTINGS:
915 lyx::Assert(bv->theLockingInset());
916 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
919 case LFUN_INSET_TOGGLE:
920 bv->beforeChange(this);
927 case LFUN_PROTECTEDSPACE:
928 if (cursor.par()->layout()->free_spacing) {
932 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
934 moveCursorUpdate(bv, false);
937 case LFUN_HYPHENATION:
938 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
941 case LFUN_LIGATURE_BREAK:
942 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
946 specialChar(this, bv, InsetSpecialChar::LDOTS);
949 case LFUN_END_OF_SENTENCE:
950 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
953 case LFUN_MENU_SEPARATOR:
954 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
958 bv->beforeChange(this);
960 selection.cursor = cursor;
961 cmd.message(N_("Mark off"));
965 bv->beforeChange(this);
966 selection.mark(true);
968 selection.cursor = cursor;
969 cmd.message(N_("Mark on"));
973 bv->beforeChange(this);
974 if (selection.mark()) {
976 cmd.message(N_("Mark removed"));
978 selection.mark(true);
980 cmd.message(N_("Mark set"));
982 selection.cursor = cursor;
985 case LFUN_UPCASE_WORD:
987 changeCase(LyXText::text_uppercase);
989 bv->updateInset(inset_owner);
993 case LFUN_LOWCASE_WORD:
995 changeCase(LyXText::text_lowercase);
997 bv->updateInset(inset_owner);
1001 case LFUN_CAPITALIZE_WORD:
1003 changeCase(LyXText::text_capitalization);
1005 bv->updateInset(inset_owner);
1009 case LFUN_TRANSPOSE_CHARS:
1011 transposeChars(*this, cursor);
1013 bv->updateInset(inset_owner);
1018 cmd.message(_("Paste"));
1019 // clear the selection
1020 bv->toggleSelection();
1024 clearSelection(); // bug 393
1031 cutSelection(bv, true);
1033 cmd.message(_("Cut"));
1038 cmd.message(_("Copy"));
1041 case LFUN_BEGINNINGBUFSEL:
1043 return UNDISPATCHED;
1046 finishChange(bv, true);
1049 case LFUN_ENDBUFSEL:
1051 return UNDISPATCHED;
1054 finishChange(bv, true);
1058 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1064 istringstream is(cmd.argument.c_str());
1067 lyxerr << "SETXY: Could not parse coordinates in '"
1068 << cmd.argument << std::endl;
1070 setCursorFromCoordinates(x, y);
1075 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1077 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1083 case LFUN_GETLAYOUT:
1084 cmd.message(tostr(cursor.par()->layout()));
1088 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1089 << cmd.argument << endl;
1091 // This is not the good solution to the empty argument
1092 // problem, but it will hopefully suffice for 1.2.0.
1093 // The correct solution would be to augument the
1094 // function list/array with information about what
1095 // functions needs arguments and their type.
1096 if (cmd.argument.empty()) {
1097 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1101 // Derive layout number from given argument (string)
1102 // and current buffer's textclass (number)
1103 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1104 bool hasLayout = tclass.hasLayout(cmd.argument);
1105 string layout = cmd.argument;
1107 // If the entry is obsolete, use the new one instead.
1109 string const & obs = tclass[layout]->obsoleted_by();
1115 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1120 bool change_layout = (current_layout != layout);
1121 if (!change_layout && selection.set() &&
1122 selection.start.par() != selection.end.par())
1124 ParagraphList::iterator spit = selection.start.par();
1125 ParagraphList::iterator epit = boost::next(selection.end.par());
1126 while (spit != epit) {
1127 if (spit->layout()->name() != current_layout) {
1128 change_layout = true;
1134 if (change_layout) {
1135 current_layout = layout;
1138 bv->owner()->setLayout(layout);
1145 case LFUN_PASTESELECTION: {
1148 // this was originally a beforeChange(bv->text), i.e
1149 // the outermost LyXText!
1150 bv->beforeChange(this);
1151 string const clip = bv->getClipboard();
1152 if (!clip.empty()) {
1153 if (cmd.argument == "paragraph")
1154 insertStringAsParagraphs(clip);
1156 insertStringAsLines(clip);
1163 case LFUN_GOTOERROR:
1164 gotoInset(Inset::ERROR_CODE, false);
1168 gotoInset(Inset::NOTE_CODE, false);
1171 case LFUN_REFERENCE_GOTO:
1173 vector<Inset::Code> tmp;
1174 tmp.push_back(Inset::LABEL_CODE);
1175 tmp.push_back(Inset::REF_CODE);
1176 gotoInset(tmp, true);
1181 ParagraphList::iterator pit = cursor.par();
1182 lyx::pos_type pos = cursor.pos();
1186 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1189 c = pit->getChar(pos - 1);
1191 LyXLayout_ptr const & style = pit->layout();
1193 if (style->pass_thru ||
1194 pit->getFontSettings(bv->buffer()->params,
1195 pos).language()->lang() == "hebrew" ||
1196 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1197 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1201 case LFUN_DATE_INSERT: {
1202 time_t now_time_t = time(NULL);
1203 struct tm * now_tm = localtime(&now_time_t);
1204 setlocale(LC_TIME, "");
1206 if (!cmd.argument.empty())
1209 arg = lyxrc.date_insert_format;
1211 int const datetmp_len =
1212 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1214 for (int i = 0; i < datetmp_len; i++) {
1215 insertChar(datetmp[i]);
1218 selection.cursor = cursor;
1219 moveCursorUpdate(bv, false);
1223 case LFUN_MOUSE_TRIPLE:
1226 if (!isInInset() && bv->theLockingInset())
1228 if (cmd.button() == mouse_button::button1) {
1230 bv->screen().toggleSelection(this, bv);
1233 selection.cursor = cursor;
1237 bv->screen().toggleSelection(this, bv, false);
1239 bv->haveSelection(selection.set());
1243 case LFUN_MOUSE_DOUBLE:
1246 if (!isInInset() && bv->theLockingInset())
1248 if (cmd.button() == mouse_button::button1) {
1250 bv->screen().toggleSelection(this, bv);
1251 selectWord(LyXText::WHOLE_WORD_STRICT);
1252 bv->screen().toggleSelection(this, bv, false);
1254 selectWord(LyXText::WHOLE_WORD_STRICT);
1257 bv->haveSelection(selection.set());
1261 case LFUN_MOUSE_MOTION:
1263 // Only use motion with button 1
1264 //if (ev.button() != mouse_button::button1)
1270 // Check for inset locking
1271 if (bv->theLockingInset()) {
1272 Inset * tli = bv->theLockingInset();
1273 LyXCursor cursor = bv->text->cursor;
1274 LyXFont font = bv->text->getFont(bv->buffer(),
1275 cursor.par(), cursor.pos());
1276 int width = tli->width(bv, font);
1277 int inset_x = font.isVisibleRightToLeft()
1278 ? cursor.ix() - width : cursor.ix();
1279 int start_x = inset_x + tli->scroll();
1280 FuncRequest cmd1 = cmd;
1281 cmd1.x = cmd.x - start_x;
1282 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1283 tli->localDispatch(cmd1);
1287 // The test for not selection possible is needed, that only motion
1288 // events are used, where the bottom press event was on
1289 // the drawing area too
1290 if (!selection_possible) {
1291 lyxerr[Debug::ACTION]
1292 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1296 RowList::iterator cursorrow = bv->text->cursor.row();
1297 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1299 // sorry for this but I have a strange error that the y value jumps at
1300 // a certain point. This seems like an error in my xforms library or
1301 // in some other local environment, but I would like to leave this here
1302 // for the moment until I can remove this (Jug 20020418)
1303 if (y_before < bv->text->cursor.y())
1304 lyxerr << y_before << ':'
1305 << bv->text->cursor.y() << endl;
1307 // This is to allow jumping over large insets
1308 if (cursorrow == bv->text->cursor.row()) {
1309 if (cmd.y >= bv->workHeight())
1310 bv->text->cursorDown(false);
1312 bv->text->cursorUp(false);
1315 // Maybe an empty line was deleted
1316 if (!bv->text->selection.set())
1317 bv->update(BufferView::UPDATE);
1318 bv->text->setSelection();
1319 bv->screen().toggleToggle(bv->text, bv);
1324 // Single-click on work area
1325 case LFUN_MOUSE_PRESS:
1330 // ok ok, this is a hack (for xforms)
1331 // We shouldn't go further down as we really should only do the
1332 // scrolling and be done with this. Otherwise we may open some
1333 // dialogs (Jug 20020424).
1334 if (cmd.button() == mouse_button::button4) {
1335 bv->scroll(-lyxrc.wheel_jump);
1338 if (cmd.button() == mouse_button::button5) {
1339 bv->scroll(lyxrc.wheel_jump);
1345 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1347 // Middle button press pastes if we have a selection
1348 // We do this here as if the selection was inside an inset
1349 // it could get cleared on the unlocking of the inset so
1350 // we have to check this first
1351 bool paste_internally = false;
1352 if (cmd.button() == mouse_button::button2 && selection.set()) {
1353 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1354 paste_internally = true;
1357 int const screen_first = bv->text->top_y();
1359 if (bv->theLockingInset()) {
1360 // We are in inset locking mode
1362 // Check whether the inset was hit. If not reset mode,
1363 // otherwise give the event to the inset
1364 if (inset_hit == bv->theLockingInset()) {
1365 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1366 bv->theLockingInset()->localDispatch(cmd1);
1369 bv->unlockInset(bv->theLockingInset());
1373 selection_possible = true;
1375 // Clear the selection
1376 bv->screen().toggleSelection(bv->text, bv);
1377 bv->text->clearSelection();
1378 bv->text->fullRebreak();
1380 bv->updateScrollbar();
1382 // Single left click in math inset?
1383 if (isHighlyEditableInset(inset_hit)) {
1384 // Highly editable inset, like math
1385 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1386 selection_possible = false;
1387 bv->owner()->message(inset->editMessage());
1388 // We just have to lock the inset before calling a PressEvent on it!
1389 if (!bv->lockInset(inset))
1390 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1391 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1392 inset->localDispatch(cmd1);
1395 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1397 // Right click on a footnote flag opens float menu
1398 if (cmd.button() == mouse_button::button3) {
1399 selection_possible = false;
1403 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1404 bv->text->setCursorFromCoordinates(x, y + screen_first);
1406 bv->text->selection.cursor = bv->text->cursor;
1407 bv->text->cursor.x_fix(bv->text->cursor.x());
1409 if (bv->fitCursor())
1410 selection_possible = false;
1412 // Insert primary selection with middle mouse
1413 // if there is a local selection in the current buffer,
1415 if (cmd.button() == mouse_button::button2) {
1416 if (paste_internally)
1417 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1419 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1420 selection_possible = false;
1425 case LFUN_MOUSE_RELEASE:
1427 // do nothing if we used the mouse wheel
1431 if (cmd.button() == mouse_button::button4
1432 || cmd.button() == mouse_button::button5)
1435 // If we hit an inset, we have the inset coordinates in these
1436 // and inset_hit points to the inset. If we do not hit an
1437 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1440 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1442 if (bv->theLockingInset()) {
1443 // We are in inset locking mode.
1445 // LyX does a kind of work-area grabbing for insets.
1446 // Only a ButtonPress FuncRequest outside the inset will
1447 // force a insetUnlock.
1448 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1449 bv->theLockingInset()->localDispatch(cmd1);
1453 selection_possible = false;
1455 if (cmd.button() == mouse_button::button2)
1459 if (cmd.button() == mouse_button::button1)
1460 bv->haveSelection(selection.set());
1463 bv->owner()->view_state_changed();
1464 bv->owner()->updateMenubar();
1465 bv->owner()->updateToolbar();
1467 // Did we hit an editable inset?
1469 selection_possible = false;
1471 // if we reach this point with a selection, it
1472 // must mean we are currently selecting.
1473 // But we don't want to open the inset
1474 // because that is annoying for the user.
1475 // So just pretend we didn't hit it.
1476 // this is OK because a "kosher" ButtonRelease
1477 // will follow a ButtonPress that clears
1479 // Note this also fixes selection drawing
1480 // problems if we end up opening an inset
1481 if (selection.set())
1484 // CHECK fix this proper in 0.13
1485 // well, maybe 13.0 !!!!!!!!!
1487 // Following a ref shouldn't issue
1488 // a push on the undo-stack
1489 // anylonger, now that we have
1490 // keybindings for following
1491 // references and returning from
1492 // references. IMHO though, it
1493 // should be the inset's own business
1494 // to push or not push on the undo
1495 // stack. They don't *have* to
1496 // alter the document...
1498 // ...or maybe the SetCursorParUndo()
1499 // below isn't necessary at all anylonger?
1500 if (inset_hit->lyxCode() == Inset::REF_CODE)
1501 setCursorParUndo(bv);
1503 bv->owner()->message(inset_hit->editMessage());
1505 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1506 inset_hit->localDispatch(cmd1);
1512 case LFUN_SELFINSERT: {
1513 if (cmd.argument.empty())
1516 // Automatically delete the currently selected
1517 // text and replace it with what is being
1518 // typed in now. Depends on lyxrc settings
1519 // "auto_region_delete", which defaults to
1522 if (lyxrc.auto_region_delete) {
1523 if (selection.set()) {
1524 cutSelection(false, false);
1527 bv->haveSelection(false);
1530 bv->beforeChange(this);
1531 LyXFont const old_font(real_current_font);
1533 string::const_iterator cit = cmd.argument.begin();
1534 string::const_iterator end = cmd.argument.end();
1535 for (; cit != end; ++cit)
1536 bv->owner()->getIntl().getTransManager().
1537 TranslateAndInsert(*cit, this);
1540 selection.cursor = cursor;
1541 moveCursorUpdate(bv, false);
1543 // real_current_font.number can change so we need to
1544 // update the minibuffer
1545 if (old_font != real_current_font)
1546 bv->owner()->view_state_changed();
1550 case LFUN_HTMLURL: {
1551 InsetCommandParams p("htmlurl");
1552 string const data = InsetCommandMailer::params2string("url", p);
1553 bv->owner()->getDialogs().show("url", data, 0);
1558 InsetCommandParams p("url");
1559 string const data = InsetCommandMailer::params2string("url", p);
1560 bv->owner()->getDialogs().show("url", data, 0);
1566 case LFUN_INSET_LIST:
1567 case LFUN_INSET_THEOREM:
1568 case LFUN_INSET_CAPTION:
1570 case LFUN_INSERT_NOTE:
1571 case LFUN_INSERT_BIBITEM:
1572 case LFUN_INSET_ERT:
1573 case LFUN_INSET_FLOAT:
1574 case LFUN_INSET_FOOTNOTE:
1575 case LFUN_INSET_MARGINAL:
1576 case LFUN_INSET_MINIPAGE:
1577 case LFUN_INSET_OPTARG:
1578 case LFUN_INSET_WIDE_FLOAT:
1579 case LFUN_INSET_WRAP:
1580 case LFUN_TABULAR_INSERT:
1581 case LFUN_ENVIRONMENT_INSERT:
1582 // Open the inset, and move the current selection
1584 doInsertInset(this, cmd, true, true);
1587 case LFUN_INDEX_INSERT:
1588 // Just open the inset
1589 doInsertInset(this, cmd, true, false);
1592 case LFUN_INDEX_PRINT:
1593 case LFUN_PARENTINSERT:
1594 case LFUN_TOC_INSERT:
1597 doInsertInset(this, cmd, false, false);
1601 return UNDISPATCHED;