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.par()->isInset(cursor.pos())) {
212 Inset const * inset = cursor.par()->getInset(cursor.pos());
213 if (find(codes.begin(), codes.end(), inset->lyxCode())
215 contents = static_cast<InsetCommand const *>(inset)->getContents();
218 if (!gotoNextInset(codes, contents)) {
219 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
220 LyXCursor tmp = cursor;
221 cursor.par(ownerParagraphs().begin());
223 if (!gotoNextInset(codes, contents)) {
225 bv()->owner()->message(_("No more insets"));
228 bv()->owner()->message(_("No more insets"));
232 selection.cursor = cursor;
236 void LyXText::gotoInset(Inset::Code code, bool same_content)
238 gotoInset(vector<Inset::Code>(1, code), same_content);
242 void LyXText::cursorPrevious()
246 if (cursor.row() == rows().begin()) {
248 int new_y = bv()->text->top_y() - bv()->workHeight();
249 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
250 bv()->updateScrollbar();
255 RowList::iterator cursorrow = cursor.row();
257 setCursorFromCoordinates(cursor.x_fix(), y);
261 if (cursorrow == bv()->text->cursor.row()) {
262 // we have a row which is taller than the workarea. The
263 // simplest solution is to move to the previous row instead.
266 // This is what we used to do, so we wouldn't skip right past
267 // tall rows, but it's not working right now.
269 new_y = bv->text->top_y() - bv->workHeight();
273 new_y = bv()->text->cursor.iy()
274 + bv()->theLockingInset()->insetInInsetY() + y
275 + cursor.row()->height()
276 - bv()->workHeight() + 1;
279 - cursor.row()->baseline()
280 + cursor.row()->height()
281 - bv()->workHeight() + 1;
284 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
285 if (cursor.row() != rows().begin()) {
287 setCursor(cur, boost::prior(cursor.row())->par(),
288 boost::prior(cursor.row())->pos(), false);
289 if (cur.y() > top_y()) {
293 bv()->updateScrollbar();
297 void LyXText::cursorNext()
301 if (boost::next(cursor.row()) == rows().end()) {
302 int y = cursor.y() - cursor.row()->baseline() +
303 cursor.row()->height();
304 if (y > topy + bv()->workHeight()) {
305 bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
306 bv()->updateScrollbar();
311 int y = topy + bv()->workHeight();
312 if (inset_owner && !topy) {
313 y -= (bv()->text->cursor.iy()
314 - bv()->text->top_y()
315 + bv()->theLockingInset()->insetInInsetY());
320 RowList::iterator cursorrow = cursor.row();
321 setCursorFromCoordinates(cursor.x_fix(), y);
322 // + bv->workHeight());
326 if (cursorrow == bv()->text->cursor.row()) {
327 // we have a row which is taller than the workarea. The
328 // simplest solution is to move to the next row instead.
331 // This is what we used to do, so we wouldn't skip right past
332 // tall rows, but it's not working right now.
334 new_y = bv->text->top_y() + bv->workHeight();
338 new_y = bv()->text->cursor.iy()
339 + bv()->theLockingInset()->insetInInsetY()
340 + y - cursor.row()->baseline();
342 new_y = cursor.y() - cursor.row()->baseline();
345 bv()->screen().draw(bv()->text, bv(), new_y);
346 if (boost::next(cursor.row()) != rows().end()) {
348 setCursor(cur, boost::next(cursor.row())->par(),
349 boost::next(cursor.row())->pos(), false);
350 if (cur.y() < top_y() + bv()->workHeight()) {
354 bv()->updateScrollbar();
358 void LyXText::update()
360 bv()->update(this, BufferView::SELECT);
365 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
369 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
370 if (!bv->insertInset(new_inset))
373 bv->updateInset(new_inset);
377 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
378 bool edit, bool pastesel)
380 Inset * inset = createInset(cmd);
381 BufferView * bv = cmd.view();
385 if (lt->selection.set()) {
386 lt->cutSelection(true, false);
389 if (bv->insertInset(inset)) {
392 if (gotsel && pastesel)
393 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
402 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
404 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
405 <<"] arg[" << cmd.argument << ']' << endl;
407 BufferView * bv = cmd.view();
409 switch (cmd.action) {
411 case LFUN_APPENDIX: {
412 ParagraphList::iterator pit = cursor.par();
413 bool start = !pit->params().startOfAppendix();
415 // ensure that we have only one start_of_appendix in this document
416 ParagraphList::iterator tmp = ownerParagraphs().begin();
417 ParagraphList::iterator end = ownerParagraphs().end();
419 for (; tmp != end; ++tmp) {
420 if (tmp->params().startOfAppendix()) {
421 setUndo(bv, Undo::EDIT, &*tmp, &*boost::next(tmp));
422 tmp->params().startOfAppendix(false);
424 setHeightOfRow(getRow(tmp, 0, tmpy));
429 setUndo(bv, Undo::EDIT, &*pit, &*boost::next(pit));
430 pit->params().startOfAppendix(start);
432 // we can set the refreshing parameters now
434 redoHeightOfParagraph();
436 setCursor(cursor.par(), cursor.pos());
441 case LFUN_DELETE_WORD_FORWARD:
442 bv->beforeChange(this);
449 case LFUN_DELETE_WORD_BACKWARD:
450 bv->beforeChange(this);
452 deleteWordBackward();
457 case LFUN_DELETE_LINE_FORWARD:
458 bv->beforeChange(this);
466 if (!selection.mark())
467 bv->beforeChange(this);
469 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
472 cursorRightOneWord();
477 if (!selection.mark())
478 bv->beforeChange(this);
480 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
481 cursorRightOneWord();
487 case LFUN_BEGINNINGBUF:
488 if (!selection.mark())
489 bv->beforeChange(this);
496 if (selection.mark())
497 bv->beforeChange(this);
505 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
509 finishChange(bv, true);
514 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
518 finishChange(bv, true);
524 finishChange(bv, true);
530 finishChange(bv, true);
533 case LFUN_UP_PARAGRAPHSEL:
536 finishChange(bv, true);
539 case LFUN_DOWN_PARAGRAPHSEL:
541 cursorDownParagraph();
542 finishChange(bv, true);
548 finishChange(bv, true);
554 finishChange(bv, true);
560 finishChange(bv, true);
566 finishChange(bv, true);
569 case LFUN_WORDRIGHTSEL:
571 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
574 cursorRightOneWord();
575 finishChange(bv, true);
578 case LFUN_WORDLEFTSEL:
580 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
581 cursorRightOneWord();
584 finishChange(bv, true);
591 getWord(cur1, cur2, WHOLE_WORD);
592 setCursor(cur1.par(), cur1.pos());
593 bv->beforeChange(this);
594 setCursor(cur2.par(), cur2.pos());
595 finishChange(bv, true);
600 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
601 if (!selection.mark())
602 bv->beforeChange(this);
606 if (cursor.pos() < cursor.par()->size()
607 && cursor.par()->isInset(cursor.pos())
608 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
609 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
610 cmd.message(tmpinset->editMessage());
611 tmpinset->edit(bv, !is_rtl);
621 // This is soooo ugly. Isn`t it possible to make
623 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
624 if (!selection.mark())
625 bv->beforeChange(this);
627 LyXCursor const cur = cursor;
630 if ((is_rtl || cur != cursor) && // only if really moved!
631 cursor.pos() < cursor.par()->size() &&
632 cursor.par()->isInset(cursor.pos()) &&
633 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
634 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
635 cmd.message(tmpinset->editMessage());
636 tmpinset->edit(bv, is_rtl);
646 if (!selection.mark())
647 bv->beforeChange(this);
648 bv->update(this, BufferView::UPDATE);
654 if (!selection.mark())
655 bv->beforeChange(this);
656 bv->update(this, BufferView::UPDATE);
661 case LFUN_UP_PARAGRAPH:
662 if (!selection.mark())
663 bv->beforeChange(this);
664 bv->update(this, BufferView::UPDATE);
669 case LFUN_DOWN_PARAGRAPH:
670 if (!selection.mark())
671 bv->beforeChange(this);
672 bv->update(this, BufferView::UPDATE);
673 cursorDownParagraph();
674 finishChange(bv, false);
678 if (!selection.mark())
679 bv->beforeChange(this);
680 bv->update(this, BufferView::UPDATE);
682 finishChange(bv, false);
685 // moveCursorUpdate(bv, false, false);
686 // owner_->view_state_changed();
690 if (!selection.mark())
691 bv->beforeChange(this);
692 bv->update(this, BufferView::UPDATE);
694 finishChange(bv, false);
698 if (!selection.mark())
699 bv->beforeChange(this);
702 finishChange(bv, false);
706 if (!selection.mark())
707 bv->beforeChange(this);
710 finishChange(bv, false);
713 case LFUN_BREAKLINE: {
714 lyx::pos_type body = cursor.par()->beginningOfBody();
716 // Not allowed by LaTeX (labels or empty par)
717 if (cursor.pos() <= body)
720 bv->beforeChange(this);
721 insertInset(new InsetNewline);
723 setCursor(cursor.par(), cursor.pos());
724 moveCursorUpdate(bv, false);
729 if (!selection.set()) {
731 selection.cursor = cursor;
733 // It is possible to make it a lot faster still
734 // just comment out the line below...
738 cutSelection(bv, true);
741 moveCursorUpdate(bv, false);
742 bv->owner()->view_state_changed();
746 case LFUN_DELETE_SKIP:
747 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
748 if (!selection.set()) {
749 LyXCursor cur = cursor;
750 if (cur.pos() == cur.par()->size()) {
754 && !(cur.par()->params().spaceTop()
755 == VSpace (VSpace::NONE))) {
757 cur.par()->params().lineTop(),
758 cur.par()->params().lineBottom(),
759 cur.par()->params().pagebreakTop(),
760 cur.par()->params().pagebreakBottom(),
761 VSpace(VSpace::NONE),
762 cur.par()->params().spaceBottom(),
763 cur.par()->params().spacing(),
764 cur.par()->params().align(),
765 cur.par()->params().labelWidthString(), 0);
771 selection.cursor = cursor;
775 selection.cursor = cursor;
779 cutSelection(bv, true);
786 if (!selection.set()) {
787 if (bv->owner()->getIntl().getTransManager().backspace()) {
789 selection.cursor = cursor;
791 // It is possible to make it a lot faster still
792 // just comment out the line below...
797 cutSelection(bv, true);
800 bv->owner()->view_state_changed();
804 case LFUN_BACKSPACE_SKIP:
805 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
806 if (!selection.set()) {
807 LyXCursor cur = cursor;
809 && !(cur.par()->params().spaceTop()
810 == VSpace (VSpace::NONE))) {
812 cur.par()->params().lineTop(),
813 cur.par()->params().lineBottom(),
814 cur.par()->params().pagebreakTop(),
815 cur.par()->params().pagebreakBottom(),
816 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
817 cur.par()->params().spacing(),
818 cur.par()->params().align(),
819 cur.par()->params().labelWidthString(), 0);
822 selection.cursor = cur;
826 cutSelection(bv, true);
831 case LFUN_BREAKPARAGRAPH:
832 bv->beforeChange(this);
833 breakParagraph(bv->buffer()->paragraphs, 0);
835 selection.cursor = cursor;
837 bv->owner()->view_state_changed();
840 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
841 bv->beforeChange(this);
842 breakParagraph(bv->buffer()->paragraphs, 1);
844 selection.cursor = cursor;
846 bv->owner()->view_state_changed();
849 case LFUN_BREAKPARAGRAPH_SKIP: {
850 // When at the beginning of a paragraph, remove
851 // indentation and add a "defskip" at the top.
852 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
853 LyXCursor cur = cursor;
854 bv->beforeChange(this);
855 if (cur.pos() == 0) {
856 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
858 cur.par()->params().lineTop(),
859 cur.par()->params().lineBottom(),
860 cur.par()->params().pagebreakTop(),
861 cur.par()->params().pagebreakBottom(),
862 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
863 cur.par()->params().spacing(),
864 cur.par()->params().align(),
865 cur.par()->params().labelWidthString(), 1);
869 breakParagraph(bv->buffer()->paragraphs, 0);
872 selection.cursor = cur;
874 bv->owner()->view_state_changed();
878 case LFUN_PARAGRAPH_SPACING: {
879 ParagraphList::iterator pit = cursor.par();
880 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
881 float cur_value = 1.0;
882 if (cur_spacing == Spacing::Other)
883 cur_value = pit->params().spacing().getValue();
885 istringstream is(cmd.argument.c_str());
888 Spacing::Space new_spacing = cur_spacing;
889 float new_value = cur_value;
891 lyxerr << "Missing argument to `paragraph-spacing'"
893 } else if (tmp == "single") {
894 new_spacing = Spacing::Single;
895 } else if (tmp == "onehalf") {
896 new_spacing = Spacing::Onehalf;
897 } else if (tmp == "double") {
898 new_spacing = Spacing::Double;
899 } else if (tmp == "other") {
900 new_spacing = Spacing::Other;
903 lyxerr << "new_value = " << tmpval << endl;
906 } else if (tmp == "default") {
907 new_spacing = Spacing::Default;
909 lyxerr << _("Unknown spacing argument: ")
910 << cmd.argument << endl;
912 if (cur_spacing != new_spacing || cur_value != new_value) {
913 pit->params().spacing(Spacing(new_spacing, new_value));
920 case LFUN_INSET_SETTINGS:
921 lyx::Assert(bv->theLockingInset());
922 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
925 case LFUN_INSET_TOGGLE:
927 bv->beforeChange(this);
934 case LFUN_PROTECTEDSPACE:
935 if (cursor.par()->layout()->free_spacing) {
939 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
941 moveCursorUpdate(bv, false);
944 case LFUN_HYPHENATION:
945 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
948 case LFUN_LIGATURE_BREAK:
949 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
953 specialChar(this, bv, InsetSpecialChar::LDOTS);
956 case LFUN_END_OF_SENTENCE:
957 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
960 case LFUN_MENU_SEPARATOR:
961 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
965 bv->beforeChange(this);
967 selection.cursor = cursor;
968 cmd.message(N_("Mark off"));
972 bv->beforeChange(this);
973 selection.mark(true);
975 selection.cursor = cursor;
976 cmd.message(N_("Mark on"));
980 bv->beforeChange(this);
981 if (selection.mark()) {
983 cmd.message(N_("Mark removed"));
985 selection.mark(true);
987 cmd.message(N_("Mark set"));
989 selection.cursor = cursor;
992 case LFUN_UPCASE_WORD:
994 changeCase(LyXText::text_uppercase);
996 bv->updateInset(inset_owner);
1000 case LFUN_LOWCASE_WORD:
1002 changeCase(LyXText::text_lowercase);
1004 bv->updateInset(inset_owner);
1008 case LFUN_CAPITALIZE_WORD:
1010 changeCase(LyXText::text_capitalization);
1012 bv->updateInset(inset_owner);
1016 case LFUN_TRANSPOSE_CHARS:
1018 transposeChars(*this, cursor);
1020 bv->updateInset(inset_owner);
1025 cmd.message(_("Paste"));
1027 // clear the selection
1028 bv->toggleSelection();
1032 clearSelection(); // bug 393
1040 cutSelection(bv, true);
1042 cmd.message(_("Cut"));
1047 cmd.message(_("Copy"));
1050 case LFUN_BEGINNINGBUFSEL:
1052 return UNDISPATCHED;
1055 finishChange(bv, true);
1058 case LFUN_ENDBUFSEL:
1060 return UNDISPATCHED;
1063 finishChange(bv, true);
1067 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1073 istringstream is(cmd.argument.c_str());
1076 lyxerr << "SETXY: Could not parse coordinates in '"
1077 << cmd.argument << std::endl;
1079 setCursorFromCoordinates(x, y);
1084 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1086 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1092 case LFUN_GETLAYOUT:
1093 cmd.message(tostr(cursor.par()->layout()));
1097 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1098 << cmd.argument << endl;
1100 // This is not the good solution to the empty argument
1101 // problem, but it will hopefully suffice for 1.2.0.
1102 // The correct solution would be to augument the
1103 // function list/array with information about what
1104 // functions needs arguments and their type.
1105 if (cmd.argument.empty()) {
1106 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1110 // Derive layout number from given argument (string)
1111 // and current buffer's textclass (number)
1112 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1113 bool hasLayout = tclass.hasLayout(cmd.argument);
1114 string layout = cmd.argument;
1116 // If the entry is obsolete, use the new one instead.
1118 string const & obs = tclass[layout]->obsoleted_by();
1124 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1129 bool change_layout = (current_layout != layout);
1130 if (!change_layout && selection.set() &&
1131 selection.start.par() != selection.end.par())
1133 ParagraphList::iterator spit = selection.start.par();
1134 ParagraphList::iterator epit = boost::next(selection.end.par());
1135 while (spit != epit) {
1136 if (spit->layout()->name() != current_layout) {
1137 change_layout = true;
1143 if (change_layout) {
1145 current_layout = layout;
1148 bv->owner()->setLayout(layout);
1155 case LFUN_PASTESELECTION: {
1159 // this was originally a beforeChange(bv->text), i.e
1160 // the outermost LyXText!
1161 bv->beforeChange(this);
1162 string const clip = bv->getClipboard();
1163 if (!clip.empty()) {
1164 if (cmd.argument == "paragraph")
1165 insertStringAsParagraphs(clip);
1167 insertStringAsLines(clip);
1174 case LFUN_GOTOERROR:
1175 gotoInset(Inset::ERROR_CODE, false);
1179 gotoInset(Inset::NOTE_CODE, false);
1182 case LFUN_REFERENCE_GOTO:
1184 vector<Inset::Code> tmp;
1185 tmp.push_back(Inset::LABEL_CODE);
1186 tmp.push_back(Inset::REF_CODE);
1187 gotoInset(tmp, true);
1192 ParagraphList::iterator pit = cursor.par();
1193 lyx::pos_type pos = cursor.pos();
1197 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1200 c = pit->getChar(pos - 1);
1203 LyXLayout_ptr const & style = pit->layout();
1205 if (style->pass_thru ||
1206 pit->getFontSettings(bv->buffer()->params,
1207 pos).language()->lang() == "hebrew" ||
1208 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1209 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1213 case LFUN_DATE_INSERT: {
1214 time_t now_time_t = time(NULL);
1215 struct tm * now_tm = localtime(&now_time_t);
1216 setlocale(LC_TIME, "");
1218 if (!cmd.argument.empty())
1221 arg = lyxrc.date_insert_format;
1223 int const datetmp_len =
1224 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1226 for (int i = 0; i < datetmp_len; i++) {
1227 insertChar(datetmp[i]);
1230 selection.cursor = cursor;
1231 moveCursorUpdate(bv, false);
1235 case LFUN_MOUSE_TRIPLE:
1238 if (!isInInset() && bv->theLockingInset())
1240 if (cmd.button() == mouse_button::button1) {
1242 bv->screen().hideCursor();
1243 bv->screen().toggleSelection(this, bv);
1246 selection.cursor = cursor;
1250 bv->screen().toggleSelection(this, bv, false);
1252 bv->haveSelection(selection.set());
1256 case LFUN_MOUSE_DOUBLE:
1259 if (!isInInset() && bv->theLockingInset())
1261 if (cmd.button() == mouse_button::button1) {
1263 bv->screen().hideCursor();
1264 bv->screen().toggleSelection(this, bv);
1265 selectWord(LyXText::WHOLE_WORD_STRICT);
1266 bv->screen().toggleSelection(this, bv, false);
1268 selectWord(LyXText::WHOLE_WORD_STRICT);
1271 bv->haveSelection(selection.set());
1275 case LFUN_MOUSE_MOTION:
1277 // Only use motion with button 1
1278 //if (ev.button() != mouse_button::button1)
1284 // Check for inset locking
1285 if (bv->theLockingInset()) {
1286 Inset * tli = bv->theLockingInset();
1287 LyXCursor cursor = bv->text->cursor;
1288 LyXFont font = bv->text->getFont(bv->buffer(),
1289 cursor.par(), cursor.pos());
1290 int width = tli->width(bv, font);
1291 int inset_x = font.isVisibleRightToLeft()
1292 ? cursor.ix() - width : cursor.ix();
1293 int start_x = inset_x + tli->scroll();
1294 FuncRequest cmd1 = cmd;
1295 cmd1.x = cmd.x - start_x;
1296 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1297 tli->localDispatch(cmd1);
1301 // The test for not selection possible is needed, that only motion
1302 // events are used, where the bottom press event was on
1303 // the drawing area too
1304 if (!selection_possible) {
1305 lyxerr[Debug::ACTION]
1306 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1310 bv->screen().hideCursor();
1312 RowList::iterator cursorrow = bv->text->cursor.row();
1313 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1315 // sorry for this but I have a strange error that the y value jumps at
1316 // a certain point. This seems like an error in my xforms library or
1317 // in some other local environment, but I would like to leave this here
1318 // for the moment until I can remove this (Jug 20020418)
1319 if (y_before < bv->text->cursor.y())
1320 lyxerr << y_before << ':'
1321 << bv->text->cursor.y() << endl;
1323 // This is to allow jumping over large insets
1324 if (cursorrow == bv->text->cursor.row()) {
1325 if (cmd.y >= bv->workHeight())
1326 bv->text->cursorDown(false);
1328 bv->text->cursorUp(false);
1331 // Maybe an empty line was deleted
1332 if (!bv->text->selection.set())
1333 bv->update(BufferView::UPDATE);
1334 bv->text->setSelection();
1335 bv->screen().toggleToggle(bv->text, bv);
1341 // Single-click on work area
1342 case LFUN_MOUSE_PRESS:
1347 // ok ok, this is a hack (for xforms)
1348 // We shouldn't go further down as we really should only do the
1349 // scrolling and be done with this. Otherwise we may open some
1350 // dialogs (Jug 20020424).
1351 if (cmd.button() == mouse_button::button4) {
1352 bv->scroll(-lyxrc.wheel_jump);
1355 if (cmd.button() == mouse_button::button5) {
1356 bv->scroll(lyxrc.wheel_jump);
1362 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1364 // Middle button press pastes if we have a selection
1365 // We do this here as if the selection was inside an inset
1366 // it could get cleared on the unlocking of the inset so
1367 // we have to check this first
1368 bool paste_internally = false;
1369 if (cmd.button() == mouse_button::button2 && selection.set()) {
1370 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1371 paste_internally = true;
1374 int const screen_first = bv->text->top_y();
1376 if (bv->theLockingInset()) {
1377 // We are in inset locking mode
1379 // Check whether the inset was hit. If not reset mode,
1380 // otherwise give the event to the inset
1381 if (inset_hit == bv->theLockingInset()) {
1382 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1383 bv->theLockingInset()->localDispatch(cmd1);
1386 bv->unlockInset(bv->theLockingInset());
1390 selection_possible = true;
1391 bv->screen().hideCursor();
1393 // Clear the selection
1394 bv->screen().toggleSelection(bv->text, bv);
1395 bv->text->clearSelection();
1396 bv->text->fullRebreak();
1398 bv->updateScrollbar();
1400 // Single left click in math inset?
1401 if (isHighlyEditableInset(inset_hit)) {
1402 // Highly editable inset, like math
1403 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1404 selection_possible = false;
1405 bv->owner()->message(inset->editMessage());
1406 //inset->edit(bv, x, y, cmd.button());
1407 // We just have to lock the inset before calling a PressEvent on it!
1408 // we don't need the edit() call here! (Jug20020329)
1409 if (!bv->lockInset(inset))
1410 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1411 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1412 inset->localDispatch(cmd1);
1415 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1417 // Right click on a footnote flag opens float menu
1418 if (cmd.button() == mouse_button::button3) {
1419 selection_possible = false;
1423 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1424 bv->text->setCursorFromCoordinates(x, y + screen_first);
1426 bv->text->selection.cursor = bv->text->cursor;
1427 bv->text->cursor.x_fix(bv->text->cursor.x());
1429 if (bv->fitCursor())
1430 selection_possible = false;
1432 // Insert primary selection with middle mouse
1433 // if there is a local selection in the current buffer,
1435 if (cmd.button() == mouse_button::button2) {
1436 if (paste_internally)
1437 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1439 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1440 selection_possible = false;
1445 case LFUN_MOUSE_RELEASE:
1447 // do nothing if we used the mouse wheel
1451 if (cmd.button() == mouse_button::button4
1452 || cmd.button() == mouse_button::button5)
1455 // If we hit an inset, we have the inset coordinates in these
1456 // and inset_hit points to the inset. If we do not hit an
1457 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1460 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1462 if (bv->theLockingInset()) {
1463 // We are in inset locking mode.
1465 // LyX does a kind of work-area grabbing for insets.
1466 // Only a ButtonPress FuncRequest outside the inset will
1467 // force a insetUnlock.
1468 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1469 bv->theLockingInset()->localDispatch(cmd1);
1473 selection_possible = false;
1475 if (cmd.button() == mouse_button::button2)
1479 if (cmd.button() == mouse_button::button1)
1480 bv->haveSelection(selection.set());
1483 bv->owner()->view_state_changed();
1484 bv->owner()->updateMenubar();
1485 bv->owner()->updateToolbar();
1487 // Did we hit an editable inset?
1489 selection_possible = false;
1491 // if we reach this point with a selection, it
1492 // must mean we are currently selecting.
1493 // But we don't want to open the inset
1494 // because that is annoying for the user.
1495 // So just pretend we didn't hit it.
1496 // this is OK because a "kosher" ButtonRelease
1497 // will follow a ButtonPress that clears
1499 // Note this also fixes selection drawing
1500 // problems if we end up opening an inset
1501 if (selection.set())
1504 // CHECK fix this proper in 0.13
1505 // well, maybe 13.0 !!!!!!!!!
1507 // Following a ref shouldn't issue
1508 // a push on the undo-stack
1509 // anylonger, now that we have
1510 // keybindings for following
1511 // references and returning from
1512 // references. IMHO though, it
1513 // should be the inset's own business
1514 // to push or not push on the undo
1515 // stack. They don't *have* to
1516 // alter the document...
1518 // ...or maybe the SetCursorParUndo()
1519 // below isn't necessary at all anylonger?
1520 if (inset_hit->lyxCode() == Inset::REF_CODE)
1521 setCursorParUndo(bv);
1523 bv->owner()->message(inset_hit->editMessage());
1525 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1526 inset_hit->localDispatch(cmd1);
1532 case LFUN_SELFINSERT: {
1533 if (cmd.argument.empty())
1536 // Automatically delete the currently selected
1537 // text and replace it with what is being
1538 // typed in now. Depends on lyxrc settings
1539 // "auto_region_delete", which defaults to
1542 if (lyxrc.auto_region_delete) {
1543 if (selection.set()) {
1544 cutSelection(false, false);
1547 bv->haveSelection(false);
1550 bv->beforeChange(this);
1551 LyXFont const old_font(real_current_font);
1553 string::const_iterator cit = cmd.argument.begin();
1554 string::const_iterator end = cmd.argument.end();
1555 for (; cit != end; ++cit)
1556 bv->owner()->getIntl().getTransManager().
1557 TranslateAndInsert(*cit, this);
1560 selection.cursor = cursor;
1561 moveCursorUpdate(bv, false);
1563 // real_current_font.number can change so we need to
1564 // update the minibuffer
1565 if (old_font != real_current_font)
1566 bv->owner()->view_state_changed();
1570 case LFUN_HTMLURL: {
1571 InsetCommandParams p("htmlurl");
1572 string const data = InsetCommandMailer::params2string("url", p);
1573 bv->owner()->getDialogs().show("url", data, 0);
1578 InsetCommandParams p("url");
1579 string const data = InsetCommandMailer::params2string("url", p);
1580 bv->owner()->getDialogs().show("url", data, 0);
1586 case LFUN_INSET_LIST:
1587 case LFUN_INSET_THEOREM:
1588 case LFUN_INSET_CAPTION:
1590 case LFUN_INSERT_NOTE:
1591 case LFUN_INSERT_BIBITEM:
1592 case LFUN_INSET_ERT:
1593 case LFUN_INSET_FLOAT:
1594 case LFUN_INSET_FOOTNOTE:
1595 case LFUN_INSET_MARGINAL:
1596 case LFUN_INSET_MINIPAGE:
1597 case LFUN_INSET_OPTARG:
1598 case LFUN_INSET_WIDE_FLOAT:
1599 case LFUN_INSET_WRAP:
1600 case LFUN_TABULAR_INSERT:
1601 case LFUN_ENVIRONMENT_INSERT:
1602 // Open the inset, and move the current selection
1604 doInsertInset(this, cmd, true, true);
1607 case LFUN_INDEX_INSERT:
1608 // Just open the inset
1609 doInsertInset(this, cmd, true, false);
1612 case LFUN_INDEX_PRINT:
1613 case LFUN_PARENTINSERT:
1614 case LFUN_TOC_INSERT:
1617 doInsertInset(this, cmd, false, false);
1621 return UNDISPATCHED;