1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2002 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
16 #include "BufferView.h"
17 #include "funcrequest.h"
21 #include "bufferparams.h"
23 #include "bufferview_funcs.h"
24 #include "ParagraphParameters.h"
30 #include "support/tostr.h"
31 #include "support/lstrings.h"
32 #include "support/LAssert.h"
33 #include "frontends/LyXView.h"
34 #include "frontends/screen.h"
35 #include "frontends/Dialogs.h"
36 #include "insets/insetspecialchar.h"
37 #include "insets/insettext.h"
38 #include "insets/insetquotes.h"
39 #include "insets/insetcommand.h"
40 #include "insets/insetnewline.h"
41 #include "undo_funcs.h"
42 #include "text_funcs.h"
48 using namespace lyx::support;
49 using namespace bv_funcs;
56 extern string current_layout;
57 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
59 // the selection possible is needed, that only motion events are
60 // used, where the bottom press event was on the drawing area too
61 bool selection_possible = false;
66 void moveCursorUpdate(BufferView * bv, bool selecting)
68 LyXText * lt = bv->getLyXText();
70 if (selecting || lt->selection.mark()) {
73 bv->updateInset(lt->inset_owner);
77 if (!lt->selection.set())
78 bv->haveSelection(false);
84 void finishChange(BufferView * bv, bool selecting = false)
87 moveCursorUpdate(bv, selecting);
88 bv->owner()->view_state_changed();
91 // check if the given co-ordinates are inside an inset at the
92 // given cursor, if one exists. If so, the inset is returned,
93 // and the co-ordinates are made relative. Otherwise, 0 is returned.
94 InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
95 LyXCursor const & cur, int & x, int & y)
97 lyx::pos_type const pos = cur.pos();
98 ParagraphList::iterator par = cur.par();
100 if (pos >= par->size() || !par->isInset(pos))
103 InsetOld /*const*/ * inset = par->getInset(pos);
105 if (!isEditableInset(inset))
108 // get inset dimensions
109 Assert(par->getInset(pos));
111 LyXFont const & font = text.getFont(par, pos);
113 int const width = inset->width();
114 int const inset_x = font.isVisibleRightToLeft()
115 ? (cur.ix() - width) : cur.ix();
118 inset_x + inset->scroll(),
120 cur.iy() - inset->ascent(),
121 cur.iy() + inset->descent()
124 if (!b.contained(x, y)) {
125 lyxerr[Debug::GUI] << "Missed inset at x,y "
127 << " box " << b << endl;
131 text.setCursor(par, pos, true);
134 // The origin of an inset is on the baseline
135 y -= text.cursor.iy();
143 InsetOld * LyXText::checkInsetHit(int & x, int & y)
145 int y_tmp = y + top_y();
148 setCursorFromCoordinates(cur, x, y_tmp);
150 InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
156 // look at previous position
161 setCursor(cur, cur.par(), cur.pos() - 1, true);
163 inset = checkInset(bv(), *this, cur, x, y_tmp);
170 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
171 string const & contents)
173 ParagraphList::iterator end = ownerParagraphs().end();
174 ParagraphList::iterator pit = cursor.par();
175 pos_type pos = cursor.pos();
179 if (pos + 1 < pit->size()) {
186 } while (pit != end &&
187 !(pit->isInset(pos) &&
188 (inset = pit->getInset(pos)) != 0 &&
189 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
191 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
195 setCursor(pit, pos, false);
202 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
205 bv()->beforeChange(this);
208 if (same_content && cursor.pos() < cursor.par()->size()
209 && cursor.par()->isInset(cursor.pos())) {
210 InsetOld 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(InsetOld::Code code, bool same_content)
236 gotoInset(vector<InsetOld::Code>(1, code), same_content);
240 void LyXText::cursorPrevious()
244 if (cursorRow() == rows().begin()) {
246 bv()->updateScrollbar();
250 RowList::iterator cursorrow = cursorRow();
252 setCursorFromCoordinates(cursor.x_fix(), y);
256 if (cursorrow == bv()->text->cursorRow()) {
257 // we have a row which is taller than the workarea. The
258 // simplest solution is to move to the previous row instead.
261 // This is what we used to do, so we wouldn't skip right past
262 // tall rows, but it's not working right now.
265 new_y = bv()->text->cursor.iy()
266 + bv()->theLockingInset()->insetInInsetY() + y
267 + cursorRow()->height()
268 - bv()->workHeight() + 1;
271 - cursorRow()->baseline()
272 + cursorRow()->height()
273 - bv()->workHeight() + 1;
276 //bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
277 if (cursorRow() != rows().begin()) {
279 setCursor(cur, boost::prior(cursorRow())->par(),
280 boost::prior(cursorRow())->pos(), false);
281 if (cur.y() > top_y()) {
285 bv()->updateScrollbar();
289 void LyXText::cursorNext()
293 if (boost::next(cursorRow()) == rows().end()) {
294 int y = cursor.y() - cursorRow()->baseline() +
295 cursorRow()->height();
296 if (y > topy + bv()->workHeight()) {
297 //bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
298 bv()->updateScrollbar();
303 int y = topy + bv()->workHeight();
304 if (inset_owner && !topy) {
305 y -= (bv()->text->cursor.iy()
306 - bv()->text->top_y()
307 + bv()->theLockingInset()->insetInInsetY());
312 RowList::iterator cursorrow = cursorRow();
313 setCursorFromCoordinates(cursor.x_fix(), y);
314 // + bv->workHeight());
318 if (cursorrow == bv()->text->cursorRow()) {
319 // we have a row which is taller than the workarea. The
320 // simplest solution is to move to the next row instead.
323 // This is what we used to do, so we wouldn't skip right past
324 // tall rows, but it's not working right now.
326 new_y = bv->text->top_y() + bv->workHeight();
330 new_y = bv()->text->cursor.iy()
331 + bv()->theLockingInset()->insetInInsetY()
332 + y - cursorRow()->baseline();
334 new_y = cursor.y() - cursorRow()->baseline();
337 //bv()->screen().draw(bv()->text, bv(), new_y);
339 RowList::iterator next_row = boost::next(cursorRow());
340 if (next_row != rows().end()) {
342 setCursor(cur, next_row->par(), next_row->pos(), false);
343 if (cur.y() < top_y() + bv()->workHeight()) {
347 bv()->updateScrollbar();
351 void LyXText::update()
358 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
361 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
362 replaceSelection(lt);
363 if (!bv->insertInset(new_inset))
366 bv->updateInset(new_inset);
370 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
371 bool edit, bool pastesel)
373 InsetOld * inset = createInset(cmd);
374 BufferView * bv = cmd.view();
378 if (lt->selection.set()) {
379 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
382 if (bv->insertInset(inset)) {
384 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
385 inset->localDispatch(cmd);
387 if (gotsel && pastesel)
388 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
397 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
399 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
400 <<"] arg[" << cmd.argument << ']' << endl;
402 BufferView * bv = cmd.view();
404 switch (cmd.action) {
406 case LFUN_APPENDIX: {
407 ParagraphList::iterator pit = cursor.par();
408 bool start = !pit->params().startOfAppendix();
410 // ensure that we have only one start_of_appendix in this document
411 ParagraphList::iterator tmp = ownerParagraphs().begin();
412 ParagraphList::iterator end = ownerParagraphs().end();
414 for (; tmp != end; ++tmp) {
415 if (tmp->params().startOfAppendix()) {
416 recordUndo(bv, Undo::ATOMIC, tmp);
417 tmp->params().startOfAppendix(false);
419 setHeightOfRow(getRow(tmp, 0, tmpy));
424 recordUndo(bv, Undo::ATOMIC, pit);
425 pit->params().startOfAppendix(start);
427 // we can set the refreshing parameters now
429 redoHeightOfParagraph();
430 setCursor(cursor.par(), cursor.pos());
435 case LFUN_DELETE_WORD_FORWARD:
436 bv->beforeChange(this);
442 case LFUN_DELETE_WORD_BACKWARD:
443 bv->beforeChange(this);
444 deleteWordBackward();
449 case LFUN_DELETE_LINE_FORWARD:
450 bv->beforeChange(this);
457 if (!selection.mark())
458 bv->beforeChange(this);
459 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
462 cursorRightOneWord();
468 if (!selection.mark())
469 bv->beforeChange(this);
470 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
471 cursorRightOneWord();
478 case LFUN_BEGINNINGBUF:
479 if (!selection.mark())
480 bv->beforeChange(this);
487 if (selection.mark())
488 bv->beforeChange(this);
496 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
500 finishChange(bv, true);
505 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
509 finishChange(bv, true);
515 finishChange(bv, true);
521 finishChange(bv, true);
524 case LFUN_UP_PARAGRAPHSEL:
527 finishChange(bv, true);
530 case LFUN_DOWN_PARAGRAPHSEL:
532 cursorDownParagraph();
533 finishChange(bv, true);
539 finishChange(bv, true);
545 finishChange(bv, true);
551 finishChange(bv, true);
557 finishChange(bv, true);
560 case LFUN_WORDRIGHTSEL:
562 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
565 cursorRightOneWord();
566 finishChange(bv, true);
569 case LFUN_WORDLEFTSEL:
571 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
572 cursorRightOneWord();
575 finishChange(bv, true);
580 LyXCursor cur1 = cursor;
582 ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
583 setCursor(cur1.par(), cur1.pos());
584 bv->beforeChange(this);
585 setCursor(cur2.par(), cur2.pos());
586 finishChange(bv, true);
591 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
592 if (!selection.mark())
593 bv->beforeChange(this);
597 if (cursor.pos() < cursor.par()->size()
598 && cursor.par()->isInset(cursor.pos())
599 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
600 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
601 cmd.message(tmpinset->editMessage());
602 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
603 tmpinset->localDispatch(cmd1);
613 // This is soooo ugly. Isn`t it possible to make
615 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
616 if (!selection.mark())
617 bv->beforeChange(this);
619 LyXCursor const cur = cursor;
622 if ((is_rtl || cur != cursor) && // only if really moved!
623 cursor.pos() < cursor.par()->size() &&
624 cursor.par()->isInset(cursor.pos()) &&
625 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
626 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
627 cmd.message(tmpinset->editMessage());
628 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
629 tmpinset->localDispatch(cmd1);
639 if (!selection.mark())
640 bv->beforeChange(this);
647 if (!selection.mark())
648 bv->beforeChange(this);
654 case LFUN_UP_PARAGRAPH:
655 if (!selection.mark())
656 bv->beforeChange(this);
662 case LFUN_DOWN_PARAGRAPH:
663 if (!selection.mark())
664 bv->beforeChange(this);
666 cursorDownParagraph();
667 finishChange(bv, false);
671 if (!selection.mark())
672 bv->beforeChange(this);
675 finishChange(bv, false);
679 if (!selection.mark())
680 bv->beforeChange(this);
683 finishChange(bv, false);
687 if (!selection.mark())
688 bv->beforeChange(this);
691 finishChange(bv, false);
695 if (!selection.mark())
696 bv->beforeChange(this);
699 finishChange(bv, false);
702 case LFUN_BREAKLINE: {
703 lyx::pos_type body = cursor.par()->beginningOfBody();
705 // Not allowed by LaTeX (labels or empty par)
706 if (cursor.pos() <= body)
709 replaceSelection(bv->getLyXText());
710 insertInset(new InsetNewline);
712 setCursor(cursor.par(), cursor.pos());
713 moveCursorUpdate(bv, false);
718 if (!selection.set()) {
720 selection.cursor = cursor;
722 // It is possible to make it a lot faster still
723 // just comment out the line below...
725 cutSelection(true, false);
728 moveCursorUpdate(bv, false);
729 bv->owner()->view_state_changed();
733 case LFUN_DELETE_SKIP:
734 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
735 if (!selection.set()) {
736 LyXCursor cur = cursor;
737 if (cur.pos() == cur.par()->size()) {
741 && !(cur.par()->params().spaceTop()
742 == VSpace (VSpace::NONE))) {
744 cur.par()->params().lineTop(),
745 cur.par()->params().lineBottom(),
746 cur.par()->params().pagebreakTop(),
747 cur.par()->params().pagebreakBottom(),
748 VSpace(VSpace::NONE),
749 cur.par()->params().spaceBottom(),
750 cur.par()->params().spacing(),
751 cur.par()->params().align(),
752 cur.par()->params().labelWidthString(), 0);
757 selection.cursor = cursor;
761 selection.cursor = cursor;
764 cutSelection(true, false);
771 if (!selection.set()) {
772 if (bv->owner()->getIntl().getTransManager().backspace()) {
774 selection.cursor = cursor;
776 // It is possible to make it a lot faster still
777 // just comment out the line below...
780 cutSelection(true, false);
783 bv->owner()->view_state_changed();
787 case LFUN_BACKSPACE_SKIP:
788 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
789 if (!selection.set()) {
790 LyXCursor cur = cursor;
792 && !(cur.par()->params().spaceTop()
793 == VSpace (VSpace::NONE))) {
795 cur.par()->params().lineTop(),
796 cur.par()->params().lineBottom(),
797 cur.par()->params().pagebreakTop(),
798 cur.par()->params().pagebreakBottom(),
799 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
800 cur.par()->params().spacing(),
801 cur.par()->params().align(),
802 cur.par()->params().labelWidthString(), 0);
805 selection.cursor = cur;
809 cutSelection(true, false);
814 case LFUN_BREAKPARAGRAPH:
815 replaceSelection(bv->getLyXText());
816 breakParagraph(bv->buffer()->paragraphs, 0);
818 selection.cursor = cursor;
820 bv->owner()->view_state_changed();
823 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
824 replaceSelection(bv->getLyXText());
825 breakParagraph(bv->buffer()->paragraphs, 1);
827 selection.cursor = cursor;
829 bv->owner()->view_state_changed();
832 case LFUN_BREAKPARAGRAPH_SKIP: {
833 // When at the beginning of a paragraph, remove
834 // indentation and add a "defskip" at the top.
835 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
836 LyXCursor cur = cursor;
837 replaceSelection(bv->getLyXText());
838 if (cur.pos() == 0) {
839 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
841 cur.par()->params().lineTop(),
842 cur.par()->params().lineBottom(),
843 cur.par()->params().pagebreakTop(),
844 cur.par()->params().pagebreakBottom(),
845 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
846 cur.par()->params().spacing(),
847 cur.par()->params().align(),
848 cur.par()->params().labelWidthString(), 1);
852 breakParagraph(bv->buffer()->paragraphs, 0);
855 selection.cursor = cur;
857 bv->owner()->view_state_changed();
861 case LFUN_PARAGRAPH_SPACING: {
862 ParagraphList::iterator pit = cursor.par();
863 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
864 float cur_value = 1.0;
865 if (cur_spacing == Spacing::Other)
866 cur_value = pit->params().spacing().getValue();
868 istringstream is(STRCONV(cmd.argument));
871 Spacing::Space new_spacing = cur_spacing;
872 float new_value = cur_value;
874 lyxerr << "Missing argument to `paragraph-spacing'"
876 } else if (tmp == "single") {
877 new_spacing = Spacing::Single;
878 } else if (tmp == "onehalf") {
879 new_spacing = Spacing::Onehalf;
880 } else if (tmp == "double") {
881 new_spacing = Spacing::Double;
882 } else if (tmp == "other") {
883 new_spacing = Spacing::Other;
886 lyxerr << "new_value = " << tmpval << endl;
889 } else if (tmp == "default") {
890 new_spacing = Spacing::Default;
892 lyxerr << _("Unknown spacing argument: ")
893 << cmd.argument << endl;
895 if (cur_spacing != new_spacing || cur_value != new_value) {
896 pit->params().spacing(Spacing(new_spacing, new_value));
903 case LFUN_INSET_SETTINGS:
904 Assert(bv->theLockingInset());
905 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
908 case LFUN_INSET_TOGGLE:
909 bv->beforeChange(this);
916 case LFUN_SPACE_INSERT:
917 if (cursor.par()->layout()->free_spacing) {
921 doInsertInset(this, cmd, false, false);
923 moveCursorUpdate(bv, false);
926 case LFUN_HYPHENATION:
927 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
930 case LFUN_LIGATURE_BREAK:
931 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
935 specialChar(this, bv, InsetSpecialChar::LDOTS);
938 case LFUN_END_OF_SENTENCE:
939 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
942 case LFUN_MENU_SEPARATOR:
943 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
947 bv->beforeChange(this);
949 selection.cursor = cursor;
950 cmd.message(N_("Mark off"));
954 bv->beforeChange(this);
955 selection.mark(true);
957 selection.cursor = cursor;
958 cmd.message(N_("Mark on"));
962 bv->beforeChange(this);
963 if (selection.mark()) {
965 cmd.message(N_("Mark removed"));
967 selection.mark(true);
969 cmd.message(N_("Mark set"));
971 selection.cursor = cursor;
974 case LFUN_UPCASE_WORD:
976 changeCase(LyXText::text_uppercase);
978 bv->updateInset(inset_owner);
982 case LFUN_LOWCASE_WORD:
984 changeCase(LyXText::text_lowercase);
986 bv->updateInset(inset_owner);
990 case LFUN_CAPITALIZE_WORD:
992 changeCase(LyXText::text_capitalization);
994 bv->updateInset(inset_owner);
998 case LFUN_TRANSPOSE_CHARS:
1000 recordUndo(bv, Undo::ATOMIC, cursor.par());
1001 if (transposeChars(cursor))
1002 checkParagraph(cursor.par(), cursor.pos());
1004 bv->updateInset(inset_owner);
1009 cmd.message(_("Paste"));
1010 replaceSelection(bv->getLyXText());
1011 size_t sel_index = 0;
1012 string const & arg = cmd.argument;
1013 if (isStrUnsignedInt(arg)) {
1014 size_t const paste_arg = strToUnsignedInt(arg);
1015 #warning FIXME Check if the arg is in the domain of available selections.
1016 sel_index = paste_arg;
1018 pasteSelection(sel_index);
1019 clearSelection(); // bug 393
1027 cutSelection(true, true);
1029 cmd.message(_("Cut"));
1034 cmd.message(_("Copy"));
1037 case LFUN_BEGINNINGBUFSEL:
1039 return UNDISPATCHED;
1042 finishChange(bv, true);
1045 case LFUN_ENDBUFSEL:
1047 return UNDISPATCHED;
1050 finishChange(bv, true);
1054 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1060 istringstream is(STRCONV(cmd.argument));
1063 lyxerr << "SETXY: Could not parse coordinates in '"
1064 << cmd.argument << std::endl;
1066 setCursorFromCoordinates(x, y);
1071 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1073 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1079 case LFUN_GETLAYOUT:
1080 cmd.message(tostr(cursor.par()->layout()));
1084 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1085 << cmd.argument << endl;
1087 // This is not the good solution to the empty argument
1088 // problem, but it will hopefully suffice for 1.2.0.
1089 // The correct solution would be to augument the
1090 // function list/array with information about what
1091 // functions needs arguments and their type.
1092 if (cmd.argument.empty()) {
1093 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1097 // Derive layout number from given argument (string)
1098 // and current buffer's textclass (number)
1099 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1100 bool hasLayout = tclass.hasLayout(cmd.argument);
1101 string layout = cmd.argument;
1103 // If the entry is obsolete, use the new one instead.
1105 string const & obs = tclass[layout]->obsoleted_by();
1111 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1116 bool change_layout = (current_layout != layout);
1118 if (!change_layout && selection.set() &&
1119 selection.start.par() != selection.end.par())
1121 ParagraphList::iterator spit = selection.start.par();
1122 ParagraphList::iterator epit = boost::next(selection.end.par());
1123 while (spit != epit) {
1124 if (spit->layout()->name() != current_layout) {
1125 change_layout = true;
1132 if (change_layout) {
1133 current_layout = layout;
1136 bv->owner()->setLayout(layout);
1143 case LFUN_PASTESELECTION: {
1146 // this was originally a beforeChange(bv->text), i.e
1147 // the outermost LyXText!
1148 bv->beforeChange(this);
1149 string const clip = bv->getClipboard();
1150 if (!clip.empty()) {
1151 if (cmd.argument == "paragraph")
1152 insertStringAsParagraphs(clip);
1154 insertStringAsLines(clip);
1161 case LFUN_GOTOERROR:
1162 gotoInset(InsetOld::ERROR_CODE, false);
1166 gotoInset(InsetOld::NOTE_CODE, false);
1169 case LFUN_REFERENCE_GOTO:
1171 vector<InsetOld::Code> tmp;
1172 tmp.push_back(InsetOld::LABEL_CODE);
1173 tmp.push_back(InsetOld::REF_CODE);
1174 gotoInset(tmp, true);
1179 replaceSelection(bv->getLyXText());
1180 ParagraphList::iterator pit = cursor.par();
1181 lyx::pos_type pos = cursor.pos();
1185 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1188 c = pit->getChar(pos - 1);
1190 LyXLayout_ptr const & style = pit->layout();
1192 if (style->pass_thru ||
1193 pit->getFontSettings(bv->buffer()->params,
1194 pos).language()->lang() == "hebrew" ||
1195 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1196 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1200 case LFUN_DATE_INSERT: {
1201 replaceSelection(bv->getLyXText());
1202 time_t now_time_t = time(NULL);
1203 struct tm * now_tm = localtime(&now_time_t);
1204 setlocale(LC_TIME, "");
1206 if (!cmd.argument.empty())
1209 arg = lyxrc.date_insert_format;
1211 int const datetmp_len =
1212 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1214 for (int i = 0; i < datetmp_len; i++) {
1215 insertChar(datetmp[i]);
1218 selection.cursor = cursor;
1219 moveCursorUpdate(bv, false);
1223 case LFUN_MOUSE_TRIPLE:
1226 if (!isInInset() && bv->theLockingInset())
1228 if (cmd.button() == mouse_button::button1) {
1230 bv->screen().toggleSelection(this, bv);
1232 selection.cursor = cursor;
1236 bv->screen().toggleSelection(this, bv, false);
1238 bv->haveSelection(selection.set());
1242 case LFUN_MOUSE_DOUBLE:
1245 if (!isInInset() && bv->theLockingInset())
1247 if (cmd.button() == mouse_button::button1) {
1249 bv->screen().toggleSelection(this, bv);
1250 selectWord(lyx::WHOLE_WORD_STRICT);
1251 bv->screen().toggleSelection(this, bv, false);
1253 selectWord(lyx::WHOLE_WORD_STRICT);
1256 bv->haveSelection(selection.set());
1260 case LFUN_MOUSE_MOTION:
1262 // Only use motion with button 1
1263 //if (ev.button() != mouse_button::button1)
1269 // Check for inset locking
1270 if (bv->theLockingInset()) {
1271 InsetOld * tli = bv->theLockingInset();
1272 LyXCursor cursor = bv->text->cursor;
1273 LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
1274 int width = tli->width();
1275 int inset_x = font.isVisibleRightToLeft()
1276 ? cursor.ix() - width : cursor.ix();
1277 int start_x = inset_x + tli->scroll();
1278 FuncRequest cmd1 = cmd;
1279 cmd1.x = cmd.x - start_x;
1280 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1281 tli->localDispatch(cmd1);
1285 // The test for not selection possible is needed, that only motion
1286 // events are used, where the bottom press event was on
1287 // the drawing area too
1288 if (!selection_possible) {
1289 lyxerr[Debug::ACTION]
1290 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1294 RowList::iterator cursorrow = bv->text->cursorRow();
1295 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1297 // sorry for this but I have a strange error that the y value jumps at
1298 // a certain point. This seems like an error in my xforms library or
1299 // in some other local environment, but I would like to leave this here
1300 // for the moment until I can remove this (Jug 20020418)
1301 if (y_before < bv->text->cursor.y())
1302 lyxerr << y_before << ':'
1303 << bv->text->cursor.y() << endl;
1305 // This is to allow jumping over large insets
1306 if (cursorrow == bv->text->cursorRow()) {
1307 if (cmd.y >= bv->workHeight())
1308 bv->text->cursorDown(false);
1310 bv->text->cursorUp(false);
1313 bv->text->setSelection();
1319 // Single-click on work area
1320 case LFUN_MOUSE_PRESS:
1325 // ok ok, this is a hack (for xforms)
1326 // We shouldn't go further down as we really should only do the
1327 // scrolling and be done with this. Otherwise we may open some
1328 // dialogs (Jug 20020424).
1329 if (cmd.button() == mouse_button::button4) {
1330 bv->scroll(-lyxrc.wheel_jump);
1333 if (cmd.button() == mouse_button::button5) {
1334 bv->scroll(lyxrc.wheel_jump);
1340 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1342 // Middle button press pastes if we have a selection
1343 // We do this here as if the selection was inside an inset
1344 // it could get cleared on the unlocking of the inset so
1345 // we have to check this first
1346 bool paste_internally = false;
1347 if (cmd.button() == mouse_button::button2 && selection.set()) {
1348 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1349 paste_internally = true;
1352 int const screen_first = bv->text->top_y();
1354 if (bv->theLockingInset()) {
1355 // We are in inset locking mode
1357 // Check whether the inset was hit. If not reset mode,
1358 // otherwise give the event to the inset
1359 if (inset_hit == bv->theLockingInset()) {
1360 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1361 bv->theLockingInset()->localDispatch(cmd1);
1364 bv->unlockInset(bv->theLockingInset());
1368 selection_possible = true;
1370 // Clear the selection
1371 bv->screen().toggleSelection(bv->text, bv);
1372 bv->text->clearSelection();
1374 bv->updateScrollbar();
1376 // Single left click in math inset?
1377 if (isHighlyEditableInset(inset_hit)) {
1378 // Highly editable inset, like math
1379 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1380 selection_possible = false;
1381 bv->owner()->message(inset->editMessage());
1382 // We just have to lock the inset before calling a PressEvent on it!
1383 if (!bv->lockInset(inset))
1384 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1385 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1386 inset->localDispatch(cmd1);
1389 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1391 // Right click on a footnote flag opens float menu
1392 if (cmd.button() == mouse_button::button3) {
1393 selection_possible = false;
1397 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1398 bv->text->setCursorFromCoordinates(x, y + screen_first);
1400 bv->text->selection.cursor = bv->text->cursor;
1401 bv->text->cursor.x_fix(bv->text->cursor.x());
1403 if (bv->fitCursor())
1404 selection_possible = false;
1406 // Insert primary selection with middle mouse
1407 // if there is a local selection in the current buffer,
1409 if (cmd.button() == mouse_button::button2) {
1410 if (paste_internally)
1411 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1413 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1414 selection_possible = false;
1419 case LFUN_MOUSE_RELEASE:
1421 // do nothing if we used the mouse wheel
1425 if (cmd.button() == mouse_button::button4
1426 || cmd.button() == mouse_button::button5)
1429 // If we hit an inset, we have the inset coordinates in these
1430 // and inset_hit points to the inset. If we do not hit an
1431 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1434 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1436 if (bv->theLockingInset()) {
1437 // We are in inset locking mode.
1439 // LyX does a kind of work-area grabbing for insets.
1440 // Only a ButtonPress FuncRequest outside the inset will
1441 // force a insetUnlock.
1442 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1443 bv->theLockingInset()->localDispatch(cmd1);
1447 selection_possible = false;
1449 if (cmd.button() == mouse_button::button2)
1453 if (cmd.button() == mouse_button::button1)
1454 bv->haveSelection(selection.set());
1457 bv->owner()->view_state_changed();
1458 bv->owner()->updateMenubar();
1459 bv->owner()->updateToolbar();
1461 // Did we hit an editable inset?
1463 selection_possible = false;
1465 // if we reach this point with a selection, it
1466 // must mean we are currently selecting.
1467 // But we don't want to open the inset
1468 // because that is annoying for the user.
1469 // So just pretend we didn't hit it.
1470 // this is OK because a "kosher" ButtonRelease
1471 // will follow a ButtonPress that clears
1473 // Note this also fixes selection drawing
1474 // problems if we end up opening an inset
1475 if (selection.set())
1478 // CHECK fix this proper in 0.13
1479 // well, maybe 13.0 !!!!!!!!!
1481 // Following a ref shouldn't issue
1482 // a push on the undo-stack
1483 // anylonger, now that we have
1484 // keybindings for following
1485 // references and returning from
1486 // references. IMHO though, it
1487 // should be the inset's own business
1488 // to push or not push on the undo
1489 // stack. They don't *have* to
1490 // alter the document...
1492 // ...or maybe the SetCursorParUndo()
1493 // below isn't necessary at all anylonger?
1494 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1495 recordUndo(bv, Undo::ATOMIC);
1497 bv->owner()->message(inset_hit->editMessage());
1499 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1500 inset_hit->localDispatch(cmd1);
1506 case LFUN_SELFINSERT: {
1507 if (cmd.argument.empty())
1510 // Automatically delete the currently selected
1511 // text and replace it with what is being
1512 // typed in now. Depends on lyxrc settings
1513 // "auto_region_delete", which defaults to
1516 if (lyxrc.auto_region_delete) {
1517 if (selection.set())
1518 cutSelection(false, false);
1519 bv->haveSelection(false);
1522 bv->beforeChange(this);
1523 LyXFont const old_font(real_current_font);
1525 string::const_iterator cit = cmd.argument.begin();
1526 string::const_iterator end = cmd.argument.end();
1527 for (; cit != end; ++cit)
1528 bv->owner()->getIntl().getTransManager().
1529 TranslateAndInsert(*cit, this);
1532 selection.cursor = cursor;
1533 moveCursorUpdate(bv, false);
1535 // real_current_font.number can change so we need to
1536 // update the minibuffer
1537 if (old_font != real_current_font)
1538 bv->owner()->view_state_changed();
1542 case LFUN_HTMLURL: {
1543 InsetCommandParams p("htmlurl");
1544 string const data = InsetCommandMailer::params2string("url", p);
1545 bv->owner()->getDialogs().show("url", data, 0);
1550 InsetCommandParams p("url");
1551 string const data = InsetCommandMailer::params2string("url", p);
1552 bv->owner()->getDialogs().show("url", data, 0);
1558 case LFUN_INSET_LIST:
1559 case LFUN_INSET_THEOREM:
1560 case LFUN_INSET_CAPTION:
1562 case LFUN_INSERT_NOTE:
1563 case LFUN_INSERT_BIBITEM:
1564 case LFUN_INSET_ERT:
1565 case LFUN_INSET_FLOAT:
1566 case LFUN_INSET_FOOTNOTE:
1567 case LFUN_INSET_MARGINAL:
1568 case LFUN_INSET_MINIPAGE:
1569 case LFUN_INSET_OPTARG:
1570 case LFUN_INSET_WIDE_FLOAT:
1571 case LFUN_INSET_WRAP:
1572 case LFUN_TABULAR_INSERT:
1573 case LFUN_ENVIRONMENT_INSERT:
1574 // Open the inset, and move the current selection
1576 doInsertInset(this, cmd, true, true);
1579 case LFUN_INDEX_INSERT:
1580 // Just open the inset
1581 doInsertInset(this, cmd, true, false);
1584 case LFUN_INDEX_PRINT:
1585 case LFUN_TOC_INSERT:
1588 doInsertInset(this, cmd, false, false);
1592 return UNDISPATCHED;