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);
72 } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
73 bv->theLockingInset()->hideInsetCursor(bv);
74 bv->update(BufferView::SELECT);
78 if (!lt->selection.set())
79 bv->haveSelection(false);
85 void finishChange(BufferView * bv, bool selecting = false)
88 moveCursorUpdate(bv, selecting);
89 bv->owner()->view_state_changed();
92 // check if the given co-ordinates are inside an inset at the
93 // given cursor, if one exists. If so, the inset is returned,
94 // and the co-ordinates are made relative. Otherwise, 0 is returned.
95 Inset * checkInset(BufferView * bv, LyXText & text,
96 LyXCursor const & cur, int & x, int & y)
98 lyx::pos_type const pos = cur.pos();
99 Paragraph /*const*/ & par = *cur.par();
101 if (pos >= par.size() || !par.isInset(pos))
104 Inset /*const*/ * inset = par.getInset(pos);
106 if (!isEditableInset(inset))
109 // get inset dimensions
110 lyx::Assert(par.getInset(pos));
112 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
114 int const width = inset->width(bv, font);
115 int const inset_x = font.isVisibleRightToLeft()
116 ? (cur.ix() - width) : cur.ix();
119 inset_x + inset->scroll(),
121 cur.iy() - inset->ascent(bv, font),
122 cur.iy() + inset->descent(bv, font)
125 if (!b.contained(x, y)) {
126 lyxerr[Debug::GUI] << "Missed inset at x,y "
128 << " box " << b << endl;
132 text.setCursor(&par, pos, true);
135 // The origin of an inset is on the baseline
136 y -= text.cursor.iy();
144 Inset * LyXText::checkInsetHit(int & x, int & y)
146 int y_tmp = y + top_y();
149 setCursorFromCoordinates(cur, x, y_tmp);
151 Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
157 // look at previous position
162 setCursor(cur, cur.par(), cur.pos() - 1, true);
164 inset = checkInset(bv(), *this, cur, x, y_tmp);
171 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
172 string const & contents)
174 ParagraphList::iterator end = ownerParagraphs().end();
175 ParagraphList::iterator pit = cursor.par();
176 pos_type pos = cursor.pos();
180 if (pos + 1 < pit->size()) {
187 } while (pit != end &&
188 !(pit->isInset(pos) &&
189 (inset = pit->getInset(pos)) != 0 &&
190 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
192 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
196 setCursor(pit, pos, false);
203 void LyXText::gotoInset(vector<Inset::Code> const & codes,
207 bv()->beforeChange(this);
211 if (same_content && cursor.pos() < cursor.par()->size()
212 && cursor.par()->isInset(cursor.pos())) {
213 Inset const * inset = cursor.par()->getInset(cursor.pos());
214 if (find(codes.begin(), codes.end(), inset->lyxCode())
216 contents = static_cast<InsetCommand const *>(inset)->getContents();
219 if (!gotoNextInset(codes, contents)) {
220 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
221 LyXCursor tmp = cursor;
222 cursor.par(ownerParagraphs().begin());
224 if (!gotoNextInset(codes, contents)) {
226 bv()->owner()->message(_("No more insets"));
229 bv()->owner()->message(_("No more insets"));
233 selection.cursor = cursor;
237 void LyXText::gotoInset(Inset::Code code, bool same_content)
239 gotoInset(vector<Inset::Code>(1, code), same_content);
243 void LyXText::cursorPrevious()
247 if (cursor.row() == rows().begin()) {
249 int new_y = bv()->text->top_y() - bv()->workHeight();
250 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
251 bv()->updateScrollbar();
256 RowList::iterator cursorrow = cursor.row();
258 setCursorFromCoordinates(cursor.x_fix(), y);
262 if (cursorrow == bv()->text->cursor.row()) {
263 // we have a row which is taller than the workarea. The
264 // simplest solution is to move to the previous row instead.
267 // This is what we used to do, so we wouldn't skip right past
268 // tall rows, but it's not working right now.
270 new_y = bv->text->top_y() - bv->workHeight();
274 new_y = bv()->text->cursor.iy()
275 + bv()->theLockingInset()->insetInInsetY() + y
276 + cursor.row()->height()
277 - bv()->workHeight() + 1;
280 - cursor.row()->baseline()
281 + cursor.row()->height()
282 - bv()->workHeight() + 1;
285 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
286 if (cursor.row() != rows().begin()) {
288 setCursor(cur, boost::prior(cursor.row())->par(),
289 boost::prior(cursor.row())->pos(), false);
290 if (cur.y() > top_y()) {
294 bv()->updateScrollbar();
298 void LyXText::cursorNext()
302 if (boost::next(cursor.row()) == rows().end()) {
303 int y = cursor.y() - cursor.row()->baseline() +
304 cursor.row()->height();
305 if (y > topy + bv()->workHeight()) {
306 bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
307 bv()->updateScrollbar();
312 int y = topy + bv()->workHeight();
313 if (inset_owner && !topy) {
314 y -= (bv()->text->cursor.iy()
315 - bv()->text->top_y()
316 + bv()->theLockingInset()->insetInInsetY());
321 RowList::iterator cursorrow = cursor.row();
322 setCursorFromCoordinates(cursor.x_fix(), y);
323 // + bv->workHeight());
327 if (cursorrow == bv()->text->cursor.row()) {
328 // we have a row which is taller than the workarea. The
329 // simplest solution is to move to the next row instead.
332 // This is what we used to do, so we wouldn't skip right past
333 // tall rows, but it's not working right now.
335 new_y = bv->text->top_y() + bv->workHeight();
339 new_y = bv()->text->cursor.iy()
340 + bv()->theLockingInset()->insetInInsetY()
341 + y - cursor.row()->baseline();
343 new_y = cursor.y() - cursor.row()->baseline();
346 bv()->screen().draw(bv()->text, bv(), new_y);
347 if (boost::next(cursor.row()) != rows().end()) {
349 setCursor(cur, boost::next(cursor.row())->par(),
350 boost::next(cursor.row())->pos(), false);
351 if (cur.y() < top_y() + bv()->workHeight()) {
355 bv()->updateScrollbar();
359 void LyXText::update()
361 bv()->update(this, BufferView::SELECT);
366 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
370 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
371 if (!bv->insertInset(new_inset))
374 bv->updateInset(new_inset);
378 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
379 bool edit, bool pastesel)
381 Inset * inset = createInset(cmd);
382 BufferView * bv = cmd.view();
386 if (lt->selection.set()) {
387 lt->cutSelection(true, false);
390 if (bv->insertInset(inset)) {
393 if (gotsel && pastesel)
394 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
403 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
405 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
406 <<"] arg[" << cmd.argument << ']' << endl;
408 BufferView * bv = cmd.view();
410 switch (cmd.action) {
412 case LFUN_APPENDIX: {
413 ParagraphList::iterator pit = cursor.par();
414 bool start = !pit->params().startOfAppendix();
416 // ensure that we have only one start_of_appendix in this document
417 ParagraphList::iterator tmp = ownerParagraphs().begin();
418 ParagraphList::iterator end = ownerParagraphs().end();
420 for (; tmp != end; ++tmp) {
421 if (tmp->params().startOfAppendix()) {
422 setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
423 tmp->params().startOfAppendix(false);
425 setHeightOfRow(getRow(tmp, 0, tmpy));
430 setUndo(bv, Undo::EDIT, pit, boost::next(pit));
431 pit->params().startOfAppendix(start);
433 // we can set the refreshing parameters now
435 redoHeightOfParagraph();
437 setCursor(cursor.par(), cursor.pos());
442 case LFUN_DELETE_WORD_FORWARD:
443 bv->beforeChange(this);
450 case LFUN_DELETE_WORD_BACKWARD:
451 bv->beforeChange(this);
453 deleteWordBackward();
458 case LFUN_DELETE_LINE_FORWARD:
459 bv->beforeChange(this);
467 if (!selection.mark())
468 bv->beforeChange(this);
470 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
473 cursorRightOneWord();
478 if (!selection.mark())
479 bv->beforeChange(this);
481 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
482 cursorRightOneWord();
488 case LFUN_BEGINNINGBUF:
489 if (!selection.mark())
490 bv->beforeChange(this);
497 if (selection.mark())
498 bv->beforeChange(this);
506 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
510 finishChange(bv, true);
515 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
519 finishChange(bv, true);
525 finishChange(bv, true);
531 finishChange(bv, true);
534 case LFUN_UP_PARAGRAPHSEL:
537 finishChange(bv, true);
540 case LFUN_DOWN_PARAGRAPHSEL:
542 cursorDownParagraph();
543 finishChange(bv, true);
549 finishChange(bv, true);
555 finishChange(bv, true);
561 finishChange(bv, true);
567 finishChange(bv, true);
570 case LFUN_WORDRIGHTSEL:
572 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
575 cursorRightOneWord();
576 finishChange(bv, true);
579 case LFUN_WORDLEFTSEL:
581 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
582 cursorRightOneWord();
585 finishChange(bv, true);
592 getWord(cur1, cur2, WHOLE_WORD);
593 setCursor(cur1.par(), cur1.pos());
594 bv->beforeChange(this);
595 setCursor(cur2.par(), cur2.pos());
596 finishChange(bv, true);
601 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
602 if (!selection.mark())
603 bv->beforeChange(this);
607 if (cursor.pos() < cursor.par()->size()
608 && cursor.par()->isInset(cursor.pos())
609 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
610 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
611 cmd.message(tmpinset->editMessage());
612 tmpinset->edit(bv, !is_rtl);
622 // This is soooo ugly. Isn`t it possible to make
624 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
625 if (!selection.mark())
626 bv->beforeChange(this);
628 LyXCursor const cur = cursor;
631 if ((is_rtl || cur != cursor) && // only if really moved!
632 cursor.pos() < cursor.par()->size() &&
633 cursor.par()->isInset(cursor.pos()) &&
634 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
635 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
636 cmd.message(tmpinset->editMessage());
637 tmpinset->edit(bv, is_rtl);
647 if (!selection.mark())
648 bv->beforeChange(this);
649 bv->update(this, BufferView::UPDATE);
655 if (!selection.mark())
656 bv->beforeChange(this);
657 bv->update(this, BufferView::UPDATE);
662 case LFUN_UP_PARAGRAPH:
663 if (!selection.mark())
664 bv->beforeChange(this);
665 bv->update(this, BufferView::UPDATE);
670 case LFUN_DOWN_PARAGRAPH:
671 if (!selection.mark())
672 bv->beforeChange(this);
673 bv->update(this, BufferView::UPDATE);
674 cursorDownParagraph();
675 finishChange(bv, false);
679 if (!selection.mark())
680 bv->beforeChange(this);
681 bv->update(this, BufferView::UPDATE);
683 finishChange(bv, false);
686 // moveCursorUpdate(bv, false, false);
687 // owner_->view_state_changed();
691 if (!selection.mark())
692 bv->beforeChange(this);
693 bv->update(this, BufferView::UPDATE);
695 finishChange(bv, false);
699 if (!selection.mark())
700 bv->beforeChange(this);
703 finishChange(bv, false);
707 if (!selection.mark())
708 bv->beforeChange(this);
711 finishChange(bv, false);
714 case LFUN_BREAKLINE: {
715 lyx::pos_type body = cursor.par()->beginningOfBody();
717 // Not allowed by LaTeX (labels or empty par)
718 if (cursor.pos() <= body)
721 bv->beforeChange(this);
722 insertInset(new InsetNewline);
724 setCursor(cursor.par(), cursor.pos());
725 moveCursorUpdate(bv, false);
730 if (!selection.set()) {
732 selection.cursor = cursor;
734 // It is possible to make it a lot faster still
735 // just comment out the line below...
739 cutSelection(bv, true);
742 moveCursorUpdate(bv, false);
743 bv->owner()->view_state_changed();
747 case LFUN_DELETE_SKIP:
748 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
749 if (!selection.set()) {
750 LyXCursor cur = cursor;
751 if (cur.pos() == cur.par()->size()) {
755 && !(cur.par()->params().spaceTop()
756 == VSpace (VSpace::NONE))) {
758 cur.par()->params().lineTop(),
759 cur.par()->params().lineBottom(),
760 cur.par()->params().pagebreakTop(),
761 cur.par()->params().pagebreakBottom(),
762 VSpace(VSpace::NONE),
763 cur.par()->params().spaceBottom(),
764 cur.par()->params().spacing(),
765 cur.par()->params().align(),
766 cur.par()->params().labelWidthString(), 0);
772 selection.cursor = cursor;
776 selection.cursor = cursor;
780 cutSelection(bv, true);
787 if (!selection.set()) {
788 if (bv->owner()->getIntl().getTransManager().backspace()) {
790 selection.cursor = cursor;
792 // It is possible to make it a lot faster still
793 // just comment out the line below...
798 cutSelection(bv, true);
801 bv->owner()->view_state_changed();
805 case LFUN_BACKSPACE_SKIP:
806 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
807 if (!selection.set()) {
808 LyXCursor cur = cursor;
810 && !(cur.par()->params().spaceTop()
811 == VSpace (VSpace::NONE))) {
813 cur.par()->params().lineTop(),
814 cur.par()->params().lineBottom(),
815 cur.par()->params().pagebreakTop(),
816 cur.par()->params().pagebreakBottom(),
817 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
818 cur.par()->params().spacing(),
819 cur.par()->params().align(),
820 cur.par()->params().labelWidthString(), 0);
823 selection.cursor = cur;
827 cutSelection(bv, true);
832 case LFUN_BREAKPARAGRAPH:
833 bv->beforeChange(this);
834 breakParagraph(bv->buffer()->paragraphs, 0);
836 selection.cursor = cursor;
838 bv->owner()->view_state_changed();
841 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
842 bv->beforeChange(this);
843 breakParagraph(bv->buffer()->paragraphs, 1);
845 selection.cursor = cursor;
847 bv->owner()->view_state_changed();
850 case LFUN_BREAKPARAGRAPH_SKIP: {
851 // When at the beginning of a paragraph, remove
852 // indentation and add a "defskip" at the top.
853 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
854 LyXCursor cur = cursor;
855 bv->beforeChange(this);
856 if (cur.pos() == 0) {
857 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
859 cur.par()->params().lineTop(),
860 cur.par()->params().lineBottom(),
861 cur.par()->params().pagebreakTop(),
862 cur.par()->params().pagebreakBottom(),
863 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
864 cur.par()->params().spacing(),
865 cur.par()->params().align(),
866 cur.par()->params().labelWidthString(), 1);
870 breakParagraph(bv->buffer()->paragraphs, 0);
873 selection.cursor = cur;
875 bv->owner()->view_state_changed();
879 case LFUN_PARAGRAPH_SPACING: {
880 ParagraphList::iterator pit = cursor.par();
881 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
882 float cur_value = 1.0;
883 if (cur_spacing == Spacing::Other)
884 cur_value = pit->params().spacing().getValue();
886 istringstream is(cmd.argument.c_str());
889 Spacing::Space new_spacing = cur_spacing;
890 float new_value = cur_value;
892 lyxerr << "Missing argument to `paragraph-spacing'"
894 } else if (tmp == "single") {
895 new_spacing = Spacing::Single;
896 } else if (tmp == "onehalf") {
897 new_spacing = Spacing::Onehalf;
898 } else if (tmp == "double") {
899 new_spacing = Spacing::Double;
900 } else if (tmp == "other") {
901 new_spacing = Spacing::Other;
904 lyxerr << "new_value = " << tmpval << endl;
907 } else if (tmp == "default") {
908 new_spacing = Spacing::Default;
910 lyxerr << _("Unknown spacing argument: ")
911 << cmd.argument << endl;
913 if (cur_spacing != new_spacing || cur_value != new_value) {
914 pit->params().spacing(Spacing(new_spacing, new_value));
921 case LFUN_INSET_SETTINGS:
922 lyx::Assert(bv->theLockingInset());
923 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
926 case LFUN_INSET_TOGGLE:
928 bv->beforeChange(this);
935 case LFUN_PROTECTEDSPACE:
936 if (cursor.par()->layout()->free_spacing) {
940 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
942 moveCursorUpdate(bv, false);
945 case LFUN_HYPHENATION:
946 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
949 case LFUN_LIGATURE_BREAK:
950 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
954 specialChar(this, bv, InsetSpecialChar::LDOTS);
957 case LFUN_END_OF_SENTENCE:
958 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
961 case LFUN_MENU_SEPARATOR:
962 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
966 bv->beforeChange(this);
968 selection.cursor = cursor;
969 cmd.message(N_("Mark off"));
973 bv->beforeChange(this);
974 selection.mark(true);
976 selection.cursor = cursor;
977 cmd.message(N_("Mark on"));
981 bv->beforeChange(this);
982 if (selection.mark()) {
984 cmd.message(N_("Mark removed"));
986 selection.mark(true);
988 cmd.message(N_("Mark set"));
990 selection.cursor = cursor;
993 case LFUN_UPCASE_WORD:
995 changeCase(LyXText::text_uppercase);
997 bv->updateInset(inset_owner);
1001 case LFUN_LOWCASE_WORD:
1003 changeCase(LyXText::text_lowercase);
1005 bv->updateInset(inset_owner);
1009 case LFUN_CAPITALIZE_WORD:
1011 changeCase(LyXText::text_capitalization);
1013 bv->updateInset(inset_owner);
1017 case LFUN_TRANSPOSE_CHARS:
1019 transposeChars(*this, cursor);
1021 bv->updateInset(inset_owner);
1026 cmd.message(_("Paste"));
1028 // clear the selection
1029 bv->toggleSelection();
1033 clearSelection(); // bug 393
1041 cutSelection(bv, true);
1043 cmd.message(_("Cut"));
1048 cmd.message(_("Copy"));
1051 case LFUN_BEGINNINGBUFSEL:
1053 return UNDISPATCHED;
1056 finishChange(bv, true);
1059 case LFUN_ENDBUFSEL:
1061 return UNDISPATCHED;
1064 finishChange(bv, true);
1068 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1074 istringstream is(cmd.argument.c_str());
1077 lyxerr << "SETXY: Could not parse coordinates in '"
1078 << cmd.argument << std::endl;
1080 setCursorFromCoordinates(x, y);
1085 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1087 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1093 case LFUN_GETLAYOUT:
1094 cmd.message(tostr(cursor.par()->layout()));
1098 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1099 << cmd.argument << endl;
1101 // This is not the good solution to the empty argument
1102 // problem, but it will hopefully suffice for 1.2.0.
1103 // The correct solution would be to augument the
1104 // function list/array with information about what
1105 // functions needs arguments and their type.
1106 if (cmd.argument.empty()) {
1107 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1111 // Derive layout number from given argument (string)
1112 // and current buffer's textclass (number)
1113 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1114 bool hasLayout = tclass.hasLayout(cmd.argument);
1115 string layout = cmd.argument;
1117 // If the entry is obsolete, use the new one instead.
1119 string const & obs = tclass[layout]->obsoleted_by();
1125 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1130 bool change_layout = (current_layout != layout);
1131 if (!change_layout && selection.set() &&
1132 selection.start.par() != selection.end.par())
1134 ParagraphList::iterator spit = selection.start.par();
1135 ParagraphList::iterator epit = boost::next(selection.end.par());
1136 while (spit != epit) {
1137 if (spit->layout()->name() != current_layout) {
1138 change_layout = true;
1144 if (change_layout) {
1146 current_layout = layout;
1149 bv->owner()->setLayout(layout);
1156 case LFUN_PASTESELECTION: {
1160 // this was originally a beforeChange(bv->text), i.e
1161 // the outermost LyXText!
1162 bv->beforeChange(this);
1163 string const clip = bv->getClipboard();
1164 if (!clip.empty()) {
1165 if (cmd.argument == "paragraph")
1166 insertStringAsParagraphs(clip);
1168 insertStringAsLines(clip);
1175 case LFUN_GOTOERROR:
1176 gotoInset(Inset::ERROR_CODE, false);
1180 gotoInset(Inset::NOTE_CODE, false);
1183 case LFUN_REFERENCE_GOTO:
1185 vector<Inset::Code> tmp;
1186 tmp.push_back(Inset::LABEL_CODE);
1187 tmp.push_back(Inset::REF_CODE);
1188 gotoInset(tmp, true);
1193 ParagraphList::iterator pit = cursor.par();
1194 lyx::pos_type pos = cursor.pos();
1198 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1201 c = pit->getChar(pos - 1);
1204 LyXLayout_ptr const & style = pit->layout();
1206 if (style->pass_thru ||
1207 pit->getFontSettings(bv->buffer()->params,
1208 pos).language()->lang() == "hebrew" ||
1209 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1210 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1214 case LFUN_DATE_INSERT: {
1215 time_t now_time_t = time(NULL);
1216 struct tm * now_tm = localtime(&now_time_t);
1217 setlocale(LC_TIME, "");
1219 if (!cmd.argument.empty())
1222 arg = lyxrc.date_insert_format;
1224 int const datetmp_len =
1225 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1227 for (int i = 0; i < datetmp_len; i++) {
1228 insertChar(datetmp[i]);
1231 selection.cursor = cursor;
1232 moveCursorUpdate(bv, false);
1236 case LFUN_MOUSE_TRIPLE:
1239 if (!isInInset() && bv->theLockingInset())
1241 if (cmd.button() == mouse_button::button1) {
1243 bv->screen().hideCursor();
1244 bv->screen().toggleSelection(this, bv);
1247 selection.cursor = cursor;
1251 bv->screen().toggleSelection(this, bv, false);
1253 bv->haveSelection(selection.set());
1257 case LFUN_MOUSE_DOUBLE:
1260 if (!isInInset() && bv->theLockingInset())
1262 if (cmd.button() == mouse_button::button1) {
1264 bv->screen().hideCursor();
1265 bv->screen().toggleSelection(this, bv);
1266 selectWord(LyXText::WHOLE_WORD_STRICT);
1267 bv->screen().toggleSelection(this, bv, false);
1269 selectWord(LyXText::WHOLE_WORD_STRICT);
1272 bv->haveSelection(selection.set());
1276 case LFUN_MOUSE_MOTION:
1278 // Only use motion with button 1
1279 //if (ev.button() != mouse_button::button1)
1285 // Check for inset locking
1286 if (bv->theLockingInset()) {
1287 Inset * tli = bv->theLockingInset();
1288 LyXCursor cursor = bv->text->cursor;
1289 LyXFont font = bv->text->getFont(bv->buffer(),
1290 cursor.par(), cursor.pos());
1291 int width = tli->width(bv, font);
1292 int inset_x = font.isVisibleRightToLeft()
1293 ? cursor.ix() - width : cursor.ix();
1294 int start_x = inset_x + tli->scroll();
1295 FuncRequest cmd1 = cmd;
1296 cmd1.x = cmd.x - start_x;
1297 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1298 tli->localDispatch(cmd1);
1302 // The test for not selection possible is needed, that only motion
1303 // events are used, where the bottom press event was on
1304 // the drawing area too
1305 if (!selection_possible) {
1306 lyxerr[Debug::ACTION]
1307 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1311 bv->screen().hideCursor();
1313 RowList::iterator cursorrow = bv->text->cursor.row();
1314 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1316 // sorry for this but I have a strange error that the y value jumps at
1317 // a certain point. This seems like an error in my xforms library or
1318 // in some other local environment, but I would like to leave this here
1319 // for the moment until I can remove this (Jug 20020418)
1320 if (y_before < bv->text->cursor.y())
1321 lyxerr << y_before << ':'
1322 << bv->text->cursor.y() << endl;
1324 // This is to allow jumping over large insets
1325 if (cursorrow == bv->text->cursor.row()) {
1326 if (cmd.y >= bv->workHeight())
1327 bv->text->cursorDown(false);
1329 bv->text->cursorUp(false);
1332 // Maybe an empty line was deleted
1333 if (!bv->text->selection.set())
1334 bv->update(BufferView::UPDATE);
1335 bv->text->setSelection();
1336 bv->screen().toggleToggle(bv->text, bv);
1342 // Single-click on work area
1343 case LFUN_MOUSE_PRESS:
1348 // ok ok, this is a hack (for xforms)
1349 // We shouldn't go further down as we really should only do the
1350 // scrolling and be done with this. Otherwise we may open some
1351 // dialogs (Jug 20020424).
1352 if (cmd.button() == mouse_button::button4) {
1353 bv->scroll(-lyxrc.wheel_jump);
1356 if (cmd.button() == mouse_button::button5) {
1357 bv->scroll(lyxrc.wheel_jump);
1363 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1365 // Middle button press pastes if we have a selection
1366 // We do this here as if the selection was inside an inset
1367 // it could get cleared on the unlocking of the inset so
1368 // we have to check this first
1369 bool paste_internally = false;
1370 if (cmd.button() == mouse_button::button2 && selection.set()) {
1371 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1372 paste_internally = true;
1375 int const screen_first = bv->text->top_y();
1377 if (bv->theLockingInset()) {
1378 // We are in inset locking mode
1380 // Check whether the inset was hit. If not reset mode,
1381 // otherwise give the event to the inset
1382 if (inset_hit == bv->theLockingInset()) {
1383 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1384 bv->theLockingInset()->localDispatch(cmd1);
1387 bv->unlockInset(bv->theLockingInset());
1391 selection_possible = true;
1392 bv->screen().hideCursor();
1394 // Clear the selection
1395 bv->screen().toggleSelection(bv->text, bv);
1396 bv->text->clearSelection();
1397 bv->text->fullRebreak();
1399 bv->updateScrollbar();
1401 // Single left click in math inset?
1402 if (isHighlyEditableInset(inset_hit)) {
1403 // Highly editable inset, like math
1404 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1405 selection_possible = false;
1406 bv->owner()->message(inset->editMessage());
1407 // We just have to lock the inset before calling a PressEvent on it!
1408 if (!bv->lockInset(inset))
1409 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1410 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1411 inset->localDispatch(cmd1);
1414 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1416 // Right click on a footnote flag opens float menu
1417 if (cmd.button() == mouse_button::button3) {
1418 selection_possible = false;
1422 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1423 bv->text->setCursorFromCoordinates(x, y + screen_first);
1425 bv->text->selection.cursor = bv->text->cursor;
1426 bv->text->cursor.x_fix(bv->text->cursor.x());
1428 if (bv->fitCursor())
1429 selection_possible = false;
1431 // Insert primary selection with middle mouse
1432 // if there is a local selection in the current buffer,
1434 if (cmd.button() == mouse_button::button2) {
1435 if (paste_internally)
1436 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1438 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1439 selection_possible = false;
1444 case LFUN_MOUSE_RELEASE:
1446 // do nothing if we used the mouse wheel
1450 if (cmd.button() == mouse_button::button4
1451 || cmd.button() == mouse_button::button5)
1454 // If we hit an inset, we have the inset coordinates in these
1455 // and inset_hit points to the inset. If we do not hit an
1456 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1459 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1461 if (bv->theLockingInset()) {
1462 // We are in inset locking mode.
1464 // LyX does a kind of work-area grabbing for insets.
1465 // Only a ButtonPress FuncRequest outside the inset will
1466 // force a insetUnlock.
1467 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1468 bv->theLockingInset()->localDispatch(cmd1);
1472 selection_possible = false;
1474 if (cmd.button() == mouse_button::button2)
1478 if (cmd.button() == mouse_button::button1)
1479 bv->haveSelection(selection.set());
1482 bv->owner()->view_state_changed();
1483 bv->owner()->updateMenubar();
1484 bv->owner()->updateToolbar();
1486 // Did we hit an editable inset?
1488 selection_possible = false;
1490 // if we reach this point with a selection, it
1491 // must mean we are currently selecting.
1492 // But we don't want to open the inset
1493 // because that is annoying for the user.
1494 // So just pretend we didn't hit it.
1495 // this is OK because a "kosher" ButtonRelease
1496 // will follow a ButtonPress that clears
1498 // Note this also fixes selection drawing
1499 // problems if we end up opening an inset
1500 if (selection.set())
1503 // CHECK fix this proper in 0.13
1504 // well, maybe 13.0 !!!!!!!!!
1506 // Following a ref shouldn't issue
1507 // a push on the undo-stack
1508 // anylonger, now that we have
1509 // keybindings for following
1510 // references and returning from
1511 // references. IMHO though, it
1512 // should be the inset's own business
1513 // to push or not push on the undo
1514 // stack. They don't *have* to
1515 // alter the document...
1517 // ...or maybe the SetCursorParUndo()
1518 // below isn't necessary at all anylonger?
1519 if (inset_hit->lyxCode() == Inset::REF_CODE)
1520 setCursorParUndo(bv);
1522 bv->owner()->message(inset_hit->editMessage());
1524 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1525 inset_hit->localDispatch(cmd1);
1531 case LFUN_SELFINSERT: {
1532 if (cmd.argument.empty())
1535 // Automatically delete the currently selected
1536 // text and replace it with what is being
1537 // typed in now. Depends on lyxrc settings
1538 // "auto_region_delete", which defaults to
1541 if (lyxrc.auto_region_delete) {
1542 if (selection.set()) {
1543 cutSelection(false, false);
1546 bv->haveSelection(false);
1549 bv->beforeChange(this);
1550 LyXFont const old_font(real_current_font);
1552 string::const_iterator cit = cmd.argument.begin();
1553 string::const_iterator end = cmd.argument.end();
1554 for (; cit != end; ++cit)
1555 bv->owner()->getIntl().getTransManager().
1556 TranslateAndInsert(*cit, this);
1559 selection.cursor = cursor;
1560 moveCursorUpdate(bv, false);
1562 // real_current_font.number can change so we need to
1563 // update the minibuffer
1564 if (old_font != real_current_font)
1565 bv->owner()->view_state_changed();
1569 case LFUN_HTMLURL: {
1570 InsetCommandParams p("htmlurl");
1571 string const data = InsetCommandMailer::params2string("url", p);
1572 bv->owner()->getDialogs().show("url", data, 0);
1577 InsetCommandParams p("url");
1578 string const data = InsetCommandMailer::params2string("url", p);
1579 bv->owner()->getDialogs().show("url", data, 0);
1585 case LFUN_INSET_LIST:
1586 case LFUN_INSET_THEOREM:
1587 case LFUN_INSET_CAPTION:
1589 case LFUN_INSERT_NOTE:
1590 case LFUN_INSERT_BIBITEM:
1591 case LFUN_INSET_ERT:
1592 case LFUN_INSET_FLOAT:
1593 case LFUN_INSET_FOOTNOTE:
1594 case LFUN_INSET_MARGINAL:
1595 case LFUN_INSET_MINIPAGE:
1596 case LFUN_INSET_OPTARG:
1597 case LFUN_INSET_WIDE_FLOAT:
1598 case LFUN_INSET_WRAP:
1599 case LFUN_TABULAR_INSERT:
1600 case LFUN_ENVIRONMENT_INSERT:
1601 // Open the inset, and move the current selection
1603 doInsertInset(this, cmd, true, true);
1606 case LFUN_INDEX_INSERT:
1607 // Just open the inset
1608 doInsertInset(this, cmd, true, false);
1611 case LFUN_INDEX_PRINT:
1612 case LFUN_PARENTINSERT:
1613 case LFUN_TOC_INSERT:
1616 doInsertInset(this, cmd, false, false);
1620 return UNDISPATCHED;