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"
49 extern string current_layout;
50 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
52 // the selection possible is needed, that only motion events are
53 // used, where the bottom press event was on the drawing area too
54 bool selection_possible = false;
59 void moveCursorUpdate(BufferView * bv, bool selecting)
61 LyXText * lt = bv->getLyXText();
63 if (selecting || lt->selection.mark()) {
66 bv->updateInset(lt->inset_owner);
70 if (!lt->isInInset()) {
71 bv->update(lt, BufferView::SELECT);
72 } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
73 bv->update(BufferView::SELECT);
76 if (!lt->selection.set())
77 bv->haveSelection(false);
83 void finishChange(BufferView * bv, bool selecting = false)
86 moveCursorUpdate(bv, selecting);
87 bv->owner()->view_state_changed();
90 // check if the given co-ordinates are inside an inset at the
91 // given cursor, if one exists. If so, the inset is returned,
92 // and the co-ordinates are made relative. Otherwise, 0 is returned.
93 Inset * checkInset(BufferView * bv, LyXText & text,
94 LyXCursor const & cur, int & x, int & y)
96 lyx::pos_type const pos = cur.pos();
97 Paragraph /*const*/ & par = *cur.par();
99 if (pos >= par.size() || !par.isInset(pos))
102 Inset /*const*/ * inset = par.getInset(pos);
104 if (!isEditableInset(inset))
107 // get inset dimensions
108 lyx::Assert(par.getInset(pos));
110 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
112 int const width = inset->width(bv, font);
113 int const inset_x = font.isVisibleRightToLeft()
114 ? (cur.ix() - width) : cur.ix();
117 inset_x + inset->scroll(),
119 cur.iy() - inset->ascent(bv, font),
120 cur.iy() + inset->descent(bv, font)
123 if (!b.contained(x, y)) {
124 lyxerr[Debug::GUI] << "Missed inset at x,y "
126 << " box " << b << endl;
130 text.setCursor(&par, pos, true);
133 // The origin of an inset is on the baseline
134 y -= text.cursor.iy();
142 Inset * LyXText::checkInsetHit(int & x, int & y)
144 int y_tmp = y + top_y();
147 setCursorFromCoordinates(cur, x, y_tmp);
149 Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
155 // look at previous position
160 setCursor(cur, cur.par(), cur.pos() - 1, true);
162 inset = checkInset(bv(), *this, cur, x, y_tmp);
169 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
170 string const & contents)
172 ParagraphList::iterator end = ownerParagraphs().end();
173 ParagraphList::iterator pit = cursor.par();
174 pos_type pos = cursor.pos();
178 if (pos + 1 < pit->size()) {
185 } while (pit != end &&
186 !(pit->isInset(pos) &&
187 (inset = pit->getInset(pos)) != 0 &&
188 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
190 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
194 setCursor(pit, pos, false);
201 void LyXText::gotoInset(vector<Inset::Code> const & codes,
204 bv()->beforeChange(this);
208 if (same_content && cursor.pos() < cursor.par()->size()
209 && cursor.par()->isInset(cursor.pos())) {
210 Inset const * inset = cursor.par()->getInset(cursor.pos());
211 if (find(codes.begin(), codes.end(), inset->lyxCode())
213 contents = static_cast<InsetCommand const *>(inset)->getContents();
216 if (!gotoNextInset(codes, contents)) {
217 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
218 LyXCursor tmp = cursor;
219 cursor.par(ownerParagraphs().begin());
221 if (!gotoNextInset(codes, contents)) {
223 bv()->owner()->message(_("No more insets"));
226 bv()->owner()->message(_("No more insets"));
230 selection.cursor = cursor;
234 void LyXText::gotoInset(Inset::Code code, bool same_content)
236 gotoInset(vector<Inset::Code>(1, code), same_content);
240 void LyXText::cursorPrevious()
244 if (cursor.row() == rows().begin()) {
246 int new_y = bv()->text->top_y() - bv()->workHeight();
247 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
248 bv()->updateScrollbar();
253 RowList::iterator cursorrow = cursor.row();
255 setCursorFromCoordinates(cursor.x_fix(), y);
259 if (cursorrow == bv()->text->cursor.row()) {
260 // we have a row which is taller than the workarea. The
261 // simplest solution is to move to the previous row instead.
264 // This is what we used to do, so we wouldn't skip right past
265 // tall rows, but it's not working right now.
267 new_y = bv->text->top_y() - bv->workHeight();
271 new_y = bv()->text->cursor.iy()
272 + bv()->theLockingInset()->insetInInsetY() + y
273 + cursor.row()->height()
274 - bv()->workHeight() + 1;
277 - cursor.row()->baseline()
278 + cursor.row()->height()
279 - bv()->workHeight() + 1;
282 bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
283 if (cursor.row() != rows().begin()) {
285 setCursor(cur, boost::prior(cursor.row())->par(),
286 boost::prior(cursor.row())->pos(), false);
287 if (cur.y() > top_y()) {
291 bv()->updateScrollbar();
295 void LyXText::cursorNext()
299 if (boost::next(cursor.row()) == rows().end()) {
300 int y = cursor.y() - cursor.row()->baseline() +
301 cursor.row()->height();
302 if (y > topy + bv()->workHeight()) {
303 bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
304 bv()->updateScrollbar();
309 int y = topy + bv()->workHeight();
310 if (inset_owner && !topy) {
311 y -= (bv()->text->cursor.iy()
312 - bv()->text->top_y()
313 + bv()->theLockingInset()->insetInInsetY());
318 RowList::iterator cursorrow = cursor.row();
319 setCursorFromCoordinates(cursor.x_fix(), y);
320 // + bv->workHeight());
324 if (cursorrow == bv()->text->cursor.row()) {
325 // we have a row which is taller than the workarea. The
326 // simplest solution is to move to the next row instead.
329 // This is what we used to do, so we wouldn't skip right past
330 // tall rows, but it's not working right now.
332 new_y = bv->text->top_y() + bv->workHeight();
336 new_y = bv()->text->cursor.iy()
337 + bv()->theLockingInset()->insetInInsetY()
338 + y - cursor.row()->baseline();
340 new_y = cursor.y() - cursor.row()->baseline();
343 bv()->screen().draw(bv()->text, bv(), new_y);
344 if (boost::next(cursor.row()) != rows().end()) {
346 setCursor(cur, boost::next(cursor.row())->par(),
347 boost::next(cursor.row())->pos(), false);
348 if (cur.y() < top_y() + bv()->workHeight()) {
352 bv()->updateScrollbar();
356 void LyXText::update()
358 bv()->update(this, BufferView::SELECT);
363 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
366 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
367 if (!bv->insertInset(new_inset))
370 bv->updateInset(new_inset);
374 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
375 bool edit, bool pastesel)
377 Inset * inset = createInset(cmd);
378 BufferView * bv = cmd.view();
382 if (lt->selection.set()) {
383 lt->cutSelection(true, false);
386 if (bv->insertInset(inset)) {
389 if (gotsel && pastesel)
390 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
399 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
401 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
402 <<"] arg[" << cmd.argument << ']' << endl;
404 BufferView * bv = cmd.view();
406 switch (cmd.action) {
408 case LFUN_APPENDIX: {
409 ParagraphList::iterator pit = cursor.par();
410 bool start = !pit->params().startOfAppendix();
412 // ensure that we have only one start_of_appendix in this document
413 ParagraphList::iterator tmp = ownerParagraphs().begin();
414 ParagraphList::iterator end = ownerParagraphs().end();
416 for (; tmp != end; ++tmp) {
417 if (tmp->params().startOfAppendix()) {
418 setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
419 tmp->params().startOfAppendix(false);
421 setHeightOfRow(getRow(tmp, 0, tmpy));
426 setUndo(bv, Undo::EDIT, pit, boost::next(pit));
427 pit->params().startOfAppendix(start);
429 // we can set the refreshing parameters now
431 redoHeightOfParagraph();
433 setCursor(cursor.par(), cursor.pos());
438 case LFUN_DELETE_WORD_FORWARD:
439 bv->beforeChange(this);
446 case LFUN_DELETE_WORD_BACKWARD:
447 bv->beforeChange(this);
449 deleteWordBackward();
454 case LFUN_DELETE_LINE_FORWARD:
455 bv->beforeChange(this);
463 if (!selection.mark())
464 bv->beforeChange(this);
466 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
469 cursorRightOneWord();
474 if (!selection.mark())
475 bv->beforeChange(this);
477 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
478 cursorRightOneWord();
484 case LFUN_BEGINNINGBUF:
485 if (!selection.mark())
486 bv->beforeChange(this);
493 if (selection.mark())
494 bv->beforeChange(this);
502 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
506 finishChange(bv, true);
511 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
515 finishChange(bv, true);
521 finishChange(bv, true);
527 finishChange(bv, true);
530 case LFUN_UP_PARAGRAPHSEL:
533 finishChange(bv, true);
536 case LFUN_DOWN_PARAGRAPHSEL:
538 cursorDownParagraph();
539 finishChange(bv, true);
545 finishChange(bv, true);
551 finishChange(bv, true);
557 finishChange(bv, true);
563 finishChange(bv, true);
566 case LFUN_WORDRIGHTSEL:
568 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
571 cursorRightOneWord();
572 finishChange(bv, true);
575 case LFUN_WORDLEFTSEL:
577 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
578 cursorRightOneWord();
581 finishChange(bv, true);
588 getWord(cur1, cur2, WHOLE_WORD);
589 setCursor(cur1.par(), cur1.pos());
590 bv->beforeChange(this);
591 setCursor(cur2.par(), cur2.pos());
592 finishChange(bv, true);
597 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
598 if (!selection.mark())
599 bv->beforeChange(this);
603 if (cursor.pos() < cursor.par()->size()
604 && cursor.par()->isInset(cursor.pos())
605 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
606 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
607 cmd.message(tmpinset->editMessage());
608 tmpinset->edit(bv, !is_rtl);
618 // This is soooo ugly. Isn`t it possible to make
620 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
621 if (!selection.mark())
622 bv->beforeChange(this);
624 LyXCursor const cur = cursor;
627 if ((is_rtl || cur != cursor) && // only if really moved!
628 cursor.pos() < cursor.par()->size() &&
629 cursor.par()->isInset(cursor.pos()) &&
630 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
631 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
632 cmd.message(tmpinset->editMessage());
633 tmpinset->edit(bv, is_rtl);
643 if (!selection.mark())
644 bv->beforeChange(this);
645 bv->update(this, BufferView::UPDATE);
651 if (!selection.mark())
652 bv->beforeChange(this);
653 bv->update(this, BufferView::UPDATE);
658 case LFUN_UP_PARAGRAPH:
659 if (!selection.mark())
660 bv->beforeChange(this);
661 bv->update(this, BufferView::UPDATE);
666 case LFUN_DOWN_PARAGRAPH:
667 if (!selection.mark())
668 bv->beforeChange(this);
669 bv->update(this, BufferView::UPDATE);
670 cursorDownParagraph();
671 finishChange(bv, false);
675 if (!selection.mark())
676 bv->beforeChange(this);
677 bv->update(this, BufferView::UPDATE);
679 finishChange(bv, false);
682 // moveCursorUpdate(bv, false, false);
683 // owner_->view_state_changed();
687 if (!selection.mark())
688 bv->beforeChange(this);
689 bv->update(this, BufferView::UPDATE);
691 finishChange(bv, false);
695 if (!selection.mark())
696 bv->beforeChange(this);
699 finishChange(bv, false);
703 if (!selection.mark())
704 bv->beforeChange(this);
707 finishChange(bv, false);
710 case LFUN_BREAKLINE: {
711 lyx::pos_type body = cursor.par()->beginningOfBody();
713 // Not allowed by LaTeX (labels or empty par)
714 if (cursor.pos() <= body)
717 bv->beforeChange(this);
718 insertInset(new InsetNewline);
720 setCursor(cursor.par(), cursor.pos());
721 moveCursorUpdate(bv, false);
726 if (!selection.set()) {
728 selection.cursor = cursor;
730 // It is possible to make it a lot faster still
731 // just comment out the line below...
734 cutSelection(bv, true);
737 moveCursorUpdate(bv, false);
738 bv->owner()->view_state_changed();
742 case LFUN_DELETE_SKIP:
743 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
744 if (!selection.set()) {
745 LyXCursor cur = cursor;
746 if (cur.pos() == cur.par()->size()) {
750 && !(cur.par()->params().spaceTop()
751 == VSpace (VSpace::NONE))) {
753 cur.par()->params().lineTop(),
754 cur.par()->params().lineBottom(),
755 cur.par()->params().pagebreakTop(),
756 cur.par()->params().pagebreakBottom(),
757 VSpace(VSpace::NONE),
758 cur.par()->params().spaceBottom(),
759 cur.par()->params().spacing(),
760 cur.par()->params().align(),
761 cur.par()->params().labelWidthString(), 0);
767 selection.cursor = cursor;
771 selection.cursor = cursor;
775 cutSelection(bv, true);
782 if (!selection.set()) {
783 if (bv->owner()->getIntl().getTransManager().backspace()) {
785 selection.cursor = cursor;
787 // It is possible to make it a lot faster still
788 // just comment out the line below...
792 cutSelection(bv, true);
795 bv->owner()->view_state_changed();
799 case LFUN_BACKSPACE_SKIP:
800 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
801 if (!selection.set()) {
802 LyXCursor cur = cursor;
804 && !(cur.par()->params().spaceTop()
805 == VSpace (VSpace::NONE))) {
807 cur.par()->params().lineTop(),
808 cur.par()->params().lineBottom(),
809 cur.par()->params().pagebreakTop(),
810 cur.par()->params().pagebreakBottom(),
811 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
812 cur.par()->params().spacing(),
813 cur.par()->params().align(),
814 cur.par()->params().labelWidthString(), 0);
817 selection.cursor = cur;
821 cutSelection(bv, true);
826 case LFUN_BREAKPARAGRAPH:
827 bv->beforeChange(this);
828 breakParagraph(bv->buffer()->paragraphs, 0);
830 selection.cursor = cursor;
832 bv->owner()->view_state_changed();
835 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
836 bv->beforeChange(this);
837 breakParagraph(bv->buffer()->paragraphs, 1);
839 selection.cursor = cursor;
841 bv->owner()->view_state_changed();
844 case LFUN_BREAKPARAGRAPH_SKIP: {
845 // When at the beginning of a paragraph, remove
846 // indentation and add a "defskip" at the top.
847 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
848 LyXCursor cur = cursor;
849 bv->beforeChange(this);
850 if (cur.pos() == 0) {
851 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
853 cur.par()->params().lineTop(),
854 cur.par()->params().lineBottom(),
855 cur.par()->params().pagebreakTop(),
856 cur.par()->params().pagebreakBottom(),
857 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
858 cur.par()->params().spacing(),
859 cur.par()->params().align(),
860 cur.par()->params().labelWidthString(), 1);
864 breakParagraph(bv->buffer()->paragraphs, 0);
867 selection.cursor = cur;
869 bv->owner()->view_state_changed();
873 case LFUN_PARAGRAPH_SPACING: {
874 ParagraphList::iterator pit = cursor.par();
875 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
876 float cur_value = 1.0;
877 if (cur_spacing == Spacing::Other)
878 cur_value = pit->params().spacing().getValue();
880 istringstream is(cmd.argument.c_str());
883 Spacing::Space new_spacing = cur_spacing;
884 float new_value = cur_value;
886 lyxerr << "Missing argument to `paragraph-spacing'"
888 } else if (tmp == "single") {
889 new_spacing = Spacing::Single;
890 } else if (tmp == "onehalf") {
891 new_spacing = Spacing::Onehalf;
892 } else if (tmp == "double") {
893 new_spacing = Spacing::Double;
894 } else if (tmp == "other") {
895 new_spacing = Spacing::Other;
898 lyxerr << "new_value = " << tmpval << endl;
901 } else if (tmp == "default") {
902 new_spacing = Spacing::Default;
904 lyxerr << _("Unknown spacing argument: ")
905 << cmd.argument << endl;
907 if (cur_spacing != new_spacing || cur_value != new_value) {
908 pit->params().spacing(Spacing(new_spacing, new_value));
915 case LFUN_INSET_SETTINGS:
916 lyx::Assert(bv->theLockingInset());
917 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
920 case LFUN_INSET_TOGGLE:
921 bv->beforeChange(this);
928 case LFUN_PROTECTEDSPACE:
929 if (cursor.par()->layout()->free_spacing) {
933 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
935 moveCursorUpdate(bv, false);
938 case LFUN_HYPHENATION:
939 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
942 case LFUN_LIGATURE_BREAK:
943 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
947 specialChar(this, bv, InsetSpecialChar::LDOTS);
950 case LFUN_END_OF_SENTENCE:
951 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
954 case LFUN_MENU_SEPARATOR:
955 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
959 bv->beforeChange(this);
961 selection.cursor = cursor;
962 cmd.message(N_("Mark off"));
966 bv->beforeChange(this);
967 selection.mark(true);
969 selection.cursor = cursor;
970 cmd.message(N_("Mark on"));
974 bv->beforeChange(this);
975 if (selection.mark()) {
977 cmd.message(N_("Mark removed"));
979 selection.mark(true);
981 cmd.message(N_("Mark set"));
983 selection.cursor = cursor;
986 case LFUN_UPCASE_WORD:
988 changeCase(LyXText::text_uppercase);
990 bv->updateInset(inset_owner);
994 case LFUN_LOWCASE_WORD:
996 changeCase(LyXText::text_lowercase);
998 bv->updateInset(inset_owner);
1002 case LFUN_CAPITALIZE_WORD:
1004 changeCase(LyXText::text_capitalization);
1006 bv->updateInset(inset_owner);
1010 case LFUN_TRANSPOSE_CHARS:
1012 transposeChars(*this, cursor);
1014 bv->updateInset(inset_owner);
1019 cmd.message(_("Paste"));
1020 // clear the selection
1021 bv->toggleSelection();
1025 clearSelection(); // bug 393
1032 cutSelection(bv, true);
1034 cmd.message(_("Cut"));
1039 cmd.message(_("Copy"));
1042 case LFUN_BEGINNINGBUFSEL:
1044 return UNDISPATCHED;
1047 finishChange(bv, true);
1050 case LFUN_ENDBUFSEL:
1052 return UNDISPATCHED;
1055 finishChange(bv, true);
1059 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1065 istringstream is(cmd.argument.c_str());
1068 lyxerr << "SETXY: Could not parse coordinates in '"
1069 << cmd.argument << std::endl;
1071 setCursorFromCoordinates(x, y);
1076 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1078 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1084 case LFUN_GETLAYOUT:
1085 cmd.message(tostr(cursor.par()->layout()));
1089 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1090 << cmd.argument << endl;
1092 // This is not the good solution to the empty argument
1093 // problem, but it will hopefully suffice for 1.2.0.
1094 // The correct solution would be to augument the
1095 // function list/array with information about what
1096 // functions needs arguments and their type.
1097 if (cmd.argument.empty()) {
1098 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1102 // Derive layout number from given argument (string)
1103 // and current buffer's textclass (number)
1104 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1105 bool hasLayout = tclass.hasLayout(cmd.argument);
1106 string layout = cmd.argument;
1108 // If the entry is obsolete, use the new one instead.
1110 string const & obs = tclass[layout]->obsoleted_by();
1116 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1121 bool change_layout = (current_layout != layout);
1122 if (!change_layout && selection.set() &&
1123 selection.start.par() != selection.end.par())
1125 ParagraphList::iterator spit = selection.start.par();
1126 ParagraphList::iterator epit = boost::next(selection.end.par());
1127 while (spit != epit) {
1128 if (spit->layout()->name() != current_layout) {
1129 change_layout = true;
1135 if (change_layout) {
1136 current_layout = layout;
1139 bv->owner()->setLayout(layout);
1146 case LFUN_PASTESELECTION: {
1149 // this was originally a beforeChange(bv->text), i.e
1150 // the outermost LyXText!
1151 bv->beforeChange(this);
1152 string const clip = bv->getClipboard();
1153 if (!clip.empty()) {
1154 if (cmd.argument == "paragraph")
1155 insertStringAsParagraphs(clip);
1157 insertStringAsLines(clip);
1164 case LFUN_GOTOERROR:
1165 gotoInset(Inset::ERROR_CODE, false);
1169 gotoInset(Inset::NOTE_CODE, false);
1172 case LFUN_REFERENCE_GOTO:
1174 vector<Inset::Code> tmp;
1175 tmp.push_back(Inset::LABEL_CODE);
1176 tmp.push_back(Inset::REF_CODE);
1177 gotoInset(tmp, true);
1182 ParagraphList::iterator pit = cursor.par();
1183 lyx::pos_type pos = cursor.pos();
1187 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1190 c = pit->getChar(pos - 1);
1192 LyXLayout_ptr const & style = pit->layout();
1194 if (style->pass_thru ||
1195 pit->getFontSettings(bv->buffer()->params,
1196 pos).language()->lang() == "hebrew" ||
1197 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1198 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1202 case LFUN_DATE_INSERT: {
1203 time_t now_time_t = time(NULL);
1204 struct tm * now_tm = localtime(&now_time_t);
1205 setlocale(LC_TIME, "");
1207 if (!cmd.argument.empty())
1210 arg = lyxrc.date_insert_format;
1212 int const datetmp_len =
1213 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1215 for (int i = 0; i < datetmp_len; i++) {
1216 insertChar(datetmp[i]);
1219 selection.cursor = cursor;
1220 moveCursorUpdate(bv, false);
1224 case LFUN_MOUSE_TRIPLE:
1227 if (!isInInset() && bv->theLockingInset())
1229 if (cmd.button() == mouse_button::button1) {
1231 bv->screen().toggleSelection(this, bv);
1234 selection.cursor = cursor;
1238 bv->screen().toggleSelection(this, bv, false);
1240 bv->haveSelection(selection.set());
1244 case LFUN_MOUSE_DOUBLE:
1247 if (!isInInset() && bv->theLockingInset())
1249 if (cmd.button() == mouse_button::button1) {
1251 bv->screen().toggleSelection(this, bv);
1252 selectWord(LyXText::WHOLE_WORD_STRICT);
1253 bv->screen().toggleSelection(this, bv, false);
1255 selectWord(LyXText::WHOLE_WORD_STRICT);
1258 bv->haveSelection(selection.set());
1262 case LFUN_MOUSE_MOTION:
1264 // Only use motion with button 1
1265 //if (ev.button() != mouse_button::button1)
1271 // Check for inset locking
1272 if (bv->theLockingInset()) {
1273 Inset * tli = bv->theLockingInset();
1274 LyXCursor cursor = bv->text->cursor;
1275 LyXFont font = bv->text->getFont(bv->buffer(),
1276 cursor.par(), cursor.pos());
1277 int width = tli->width(bv, font);
1278 int inset_x = font.isVisibleRightToLeft()
1279 ? cursor.ix() - width : cursor.ix();
1280 int start_x = inset_x + tli->scroll();
1281 FuncRequest cmd1 = cmd;
1282 cmd1.x = cmd.x - start_x;
1283 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1284 tli->localDispatch(cmd1);
1288 // The test for not selection possible is needed, that only motion
1289 // events are used, where the bottom press event was on
1290 // the drawing area too
1291 if (!selection_possible) {
1292 lyxerr[Debug::ACTION]
1293 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1297 RowList::iterator cursorrow = bv->text->cursor.row();
1298 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1300 // sorry for this but I have a strange error that the y value jumps at
1301 // a certain point. This seems like an error in my xforms library or
1302 // in some other local environment, but I would like to leave this here
1303 // for the moment until I can remove this (Jug 20020418)
1304 if (y_before < bv->text->cursor.y())
1305 lyxerr << y_before << ':'
1306 << bv->text->cursor.y() << endl;
1308 // This is to allow jumping over large insets
1309 if (cursorrow == bv->text->cursor.row()) {
1310 if (cmd.y >= bv->workHeight())
1311 bv->text->cursorDown(false);
1313 bv->text->cursorUp(false);
1316 // Maybe an empty line was deleted
1317 if (!bv->text->selection.set())
1318 bv->update(BufferView::UPDATE);
1319 bv->text->setSelection();
1320 bv->screen().toggleToggle(bv->text, bv);
1325 // Single-click on work area
1326 case LFUN_MOUSE_PRESS:
1331 // ok ok, this is a hack (for xforms)
1332 // We shouldn't go further down as we really should only do the
1333 // scrolling and be done with this. Otherwise we may open some
1334 // dialogs (Jug 20020424).
1335 if (cmd.button() == mouse_button::button4) {
1336 bv->scroll(-lyxrc.wheel_jump);
1339 if (cmd.button() == mouse_button::button5) {
1340 bv->scroll(lyxrc.wheel_jump);
1346 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1348 // Middle button press pastes if we have a selection
1349 // We do this here as if the selection was inside an inset
1350 // it could get cleared on the unlocking of the inset so
1351 // we have to check this first
1352 bool paste_internally = false;
1353 if (cmd.button() == mouse_button::button2 && selection.set()) {
1354 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1355 paste_internally = true;
1358 int const screen_first = bv->text->top_y();
1360 if (bv->theLockingInset()) {
1361 // We are in inset locking mode
1363 // Check whether the inset was hit. If not reset mode,
1364 // otherwise give the event to the inset
1365 if (inset_hit == bv->theLockingInset()) {
1366 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1367 bv->theLockingInset()->localDispatch(cmd1);
1370 bv->unlockInset(bv->theLockingInset());
1374 selection_possible = true;
1376 // Clear the selection
1377 bv->screen().toggleSelection(bv->text, bv);
1378 bv->text->clearSelection();
1379 bv->text->fullRebreak();
1381 bv->updateScrollbar();
1383 // Single left click in math inset?
1384 if (isHighlyEditableInset(inset_hit)) {
1385 // Highly editable inset, like math
1386 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1387 selection_possible = false;
1388 bv->owner()->message(inset->editMessage());
1389 // We just have to lock the inset before calling a PressEvent on it!
1390 if (!bv->lockInset(inset))
1391 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1392 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1393 inset->localDispatch(cmd1);
1396 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1398 // Right click on a footnote flag opens float menu
1399 if (cmd.button() == mouse_button::button3) {
1400 selection_possible = false;
1404 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1405 bv->text->setCursorFromCoordinates(x, y + screen_first);
1407 bv->text->selection.cursor = bv->text->cursor;
1408 bv->text->cursor.x_fix(bv->text->cursor.x());
1410 if (bv->fitCursor())
1411 selection_possible = false;
1413 // Insert primary selection with middle mouse
1414 // if there is a local selection in the current buffer,
1416 if (cmd.button() == mouse_button::button2) {
1417 if (paste_internally)
1418 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1420 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1421 selection_possible = false;
1426 case LFUN_MOUSE_RELEASE:
1428 // do nothing if we used the mouse wheel
1432 if (cmd.button() == mouse_button::button4
1433 || cmd.button() == mouse_button::button5)
1436 // If we hit an inset, we have the inset coordinates in these
1437 // and inset_hit points to the inset. If we do not hit an
1438 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1441 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1443 if (bv->theLockingInset()) {
1444 // We are in inset locking mode.
1446 // LyX does a kind of work-area grabbing for insets.
1447 // Only a ButtonPress FuncRequest outside the inset will
1448 // force a insetUnlock.
1449 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1450 bv->theLockingInset()->localDispatch(cmd1);
1454 selection_possible = false;
1456 if (cmd.button() == mouse_button::button2)
1460 if (cmd.button() == mouse_button::button1)
1461 bv->haveSelection(selection.set());
1464 bv->owner()->view_state_changed();
1465 bv->owner()->updateMenubar();
1466 bv->owner()->updateToolbar();
1468 // Did we hit an editable inset?
1470 selection_possible = false;
1472 // if we reach this point with a selection, it
1473 // must mean we are currently selecting.
1474 // But we don't want to open the inset
1475 // because that is annoying for the user.
1476 // So just pretend we didn't hit it.
1477 // this is OK because a "kosher" ButtonRelease
1478 // will follow a ButtonPress that clears
1480 // Note this also fixes selection drawing
1481 // problems if we end up opening an inset
1482 if (selection.set())
1485 // CHECK fix this proper in 0.13
1486 // well, maybe 13.0 !!!!!!!!!
1488 // Following a ref shouldn't issue
1489 // a push on the undo-stack
1490 // anylonger, now that we have
1491 // keybindings for following
1492 // references and returning from
1493 // references. IMHO though, it
1494 // should be the inset's own business
1495 // to push or not push on the undo
1496 // stack. They don't *have* to
1497 // alter the document...
1499 // ...or maybe the SetCursorParUndo()
1500 // below isn't necessary at all anylonger?
1501 if (inset_hit->lyxCode() == Inset::REF_CODE)
1502 setCursorParUndo(bv);
1504 bv->owner()->message(inset_hit->editMessage());
1506 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1507 inset_hit->localDispatch(cmd1);
1513 case LFUN_SELFINSERT: {
1514 if (cmd.argument.empty())
1517 // Automatically delete the currently selected
1518 // text and replace it with what is being
1519 // typed in now. Depends on lyxrc settings
1520 // "auto_region_delete", which defaults to
1523 if (lyxrc.auto_region_delete) {
1524 if (selection.set()) {
1525 cutSelection(false, false);
1528 bv->haveSelection(false);
1531 bv->beforeChange(this);
1532 LyXFont const old_font(real_current_font);
1534 string::const_iterator cit = cmd.argument.begin();
1535 string::const_iterator end = cmd.argument.end();
1536 for (; cit != end; ++cit)
1537 bv->owner()->getIntl().getTransManager().
1538 TranslateAndInsert(*cit, this);
1541 selection.cursor = cursor;
1542 moveCursorUpdate(bv, false);
1544 // real_current_font.number can change so we need to
1545 // update the minibuffer
1546 if (old_font != real_current_font)
1547 bv->owner()->view_state_changed();
1551 case LFUN_HTMLURL: {
1552 InsetCommandParams p("htmlurl");
1553 string const data = InsetCommandMailer::params2string("url", p);
1554 bv->owner()->getDialogs().show("url", data, 0);
1559 InsetCommandParams p("url");
1560 string const data = InsetCommandMailer::params2string("url", p);
1561 bv->owner()->getDialogs().show("url", data, 0);
1567 case LFUN_INSET_LIST:
1568 case LFUN_INSET_THEOREM:
1569 case LFUN_INSET_CAPTION:
1571 case LFUN_INSERT_NOTE:
1572 case LFUN_INSERT_BIBITEM:
1573 case LFUN_INSET_ERT:
1574 case LFUN_INSET_FLOAT:
1575 case LFUN_INSET_FOOTNOTE:
1576 case LFUN_INSET_MARGINAL:
1577 case LFUN_INSET_MINIPAGE:
1578 case LFUN_INSET_OPTARG:
1579 case LFUN_INSET_WIDE_FLOAT:
1580 case LFUN_INSET_WRAP:
1581 case LFUN_TABULAR_INSERT:
1582 case LFUN_ENVIRONMENT_INSERT:
1583 // Open the inset, and move the current selection
1585 doInsertInset(this, cmd, true, true);
1588 case LFUN_INDEX_INSERT:
1589 // Just open the inset
1590 doInsertInset(this, cmd, true, false);
1593 case LFUN_INDEX_PRINT:
1594 case LFUN_PARENTINSERT:
1595 case LFUN_TOC_INSERT:
1598 doInsertInset(this, cmd, false, false);
1602 return UNDISPATCHED;