3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
19 #include "paragraph.h"
20 #include "BufferView.h"
21 #include "funcrequest.h"
25 #include "bufferparams.h"
27 #include "bufferview_funcs.h"
28 #include "ParagraphParameters.h"
34 #include "support/tostr.h"
35 #include "support/lstrings.h"
36 #include "support/LAssert.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/screen.h"
39 #include "frontends/Dialogs.h"
40 #include "insets/insetspecialchar.h"
41 #include "insets/insettext.h"
42 #include "insets/insetquotes.h"
43 #include "insets/insetcommand.h"
44 #include "insets/insetnewline.h"
45 #include "undo_funcs.h"
46 #include "text_funcs.h"
52 using namespace lyx::support;
53 using namespace bv_funcs;
60 extern string current_layout;
61 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
63 // the selection possible is needed, that only motion events are
64 // used, where the bottom press event was on the drawing area too
65 bool selection_possible = false;
70 void moveCursorUpdate(BufferView * bv, bool selecting)
72 LyXText * lt = bv->getLyXText();
74 //if (!lt->selection.set())
75 // lt->selection.cursor = lt->cursor;
77 if (selecting || lt->selection.mark())
80 if (!lt->selection.set())
81 bv->haveSelection(false);
88 void finishChange(BufferView * bv, bool selecting = false)
91 moveCursorUpdate(bv, selecting);
92 bv->owner()->view_state_changed();
95 // check if the given co-ordinates are inside an inset at the
96 // given cursor, if one exists. If so, the inset is returned,
97 // and the co-ordinates are made relative. Otherwise, 0 is returned.
98 InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
99 LyXCursor const & cur, int & x, int & y)
101 lyx::pos_type const pos = cur.pos();
102 ParagraphList::iterator par = cur.par();
104 if (pos >= par->size() || !par->isInset(pos))
107 InsetOld /*const*/ * inset = par->getInset(pos);
109 if (!isEditableInset(inset))
112 // get inset dimensions
113 Assert(par->getInset(pos));
115 LyXFont const & font = text.getFont(par, pos);
117 int const width = inset->width();
118 int const inset_x = font.isVisibleRightToLeft()
119 ? (cur.x() - width) : cur.x();
122 inset_x + inset->scroll(),
124 cur.y() - inset->ascent(),
125 cur.y() + inset->descent()
128 if (!b.contains(x, y)) {
129 lyxerr[Debug::GUI] << "Missed inset at x,y "
131 << " box " << b << endl;
135 text.setCursor(par, pos, true);
138 // The origin of an inset is on the baseline
139 y -= text.cursor.y();
147 InsetOld * LyXText::checkInsetHit(int & x, int & y)
149 int y_tmp = y + bv_owner->top_y();
152 setCursorFromCoordinates(cur, x, y_tmp);
154 InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
160 // look at previous position
165 setCursor(cur, cur.par(), cur.pos() - 1, true);
167 inset = checkInset(bv(), *this, cur, x, y_tmp);
174 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
175 string const & contents)
177 ParagraphList::iterator end = ownerParagraphs().end();
178 ParagraphList::iterator pit = cursor.par();
179 pos_type pos = cursor.pos();
183 if (pos + 1 < pit->size()) {
190 } while (pit != end &&
191 !(pit->isInset(pos) &&
192 (inset = pit->getInset(pos)) != 0 &&
193 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
195 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
199 setCursor(pit, pos, false);
206 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
209 bv()->beforeChange(this);
212 if (same_content && cursor.pos() < cursor.par()->size()
213 && cursor.par()->isInset(cursor.pos())) {
214 InsetOld const * inset = cursor.par()->getInset(cursor.pos());
215 if (find(codes.begin(), codes.end(), inset->lyxCode())
217 contents = static_cast<InsetCommand const *>(inset)->getContents();
220 if (!gotoNextInset(codes, contents)) {
221 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
222 LyXCursor tmp = cursor;
223 cursor.par(ownerParagraphs().begin());
225 if (!gotoNextInset(codes, contents)) {
227 bv()->owner()->message(_("No more insets"));
230 bv()->owner()->message(_("No more insets"));
234 selection.cursor = cursor;
238 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
240 gotoInset(vector<InsetOld::Code>(1, code), same_content);
244 void LyXText::cursorPrevious()
246 int y = bv_owner->top_y();
248 RowList::iterator rit = cursorRow();
250 if (rit == firstRow()) {
252 bv()->updateScrollbar();
256 setCursorFromCoordinates(cursor.x_fix(), y);
260 if (rit == bv()->text->cursorRow()) {
261 // we have a row which is taller than the workarea. The
262 // simplest solution is to move to the previous row instead.
265 // This is what we used to do, so we wouldn't skip right past
266 // tall rows, but it's not working right now.
269 new_y = bv()->text->cursor.y()
270 + bv()->theLockingInset()->insetInInsetY() + y
272 - bv()->workHeight() + 1;
277 - bv()->workHeight() + 1;
282 ParagraphList::iterator pit = cursor.par();
283 previousRow(pit, rit);
284 setCursor(cur, pit, rit->pos(), false);
285 if (cur.y() > bv_owner->top_y())
287 bv()->updateScrollbar();
291 void LyXText::cursorNext()
293 int topy = bv_owner->top_y();
295 RowList::iterator rit = cursorRow();
296 if (rit == lastRow()) {
297 int y = cursor.y() - rit->baseline() + cursorRow()->height();
298 if (y > topy + bv()->workHeight())
299 bv_owner->updateScrollbar();
303 int y = topy + bv_owner->workHeight();
304 if (inset_owner && !topy) {
305 y -= (bv_owner->text->cursor.y()
307 + bv_owner->theLockingInset()->insetInInsetY());
310 ParagraphList::iterator dummypit;
311 y = getRowNearY(y, dummypit)->y();
313 setCursorFromCoordinates(cursor.x_fix(), y);
314 // + bv->workHeight());
318 if (rit == bv_owner->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->top_y() + bv->workHeight();
330 new_y = bv()->text->cursor.y()
331 + bv()->theLockingInset()->insetInInsetY()
332 + y - rit->baseline();
334 new_y = cursor.y() - cursorRow()->baseline();
338 ParagraphList::iterator pit = cursor.par();
341 setCursor(cur, pit, rit->pos(), false);
342 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
344 bv()->updateScrollbar();
350 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
353 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
354 replaceSelection(lt);
355 if (!bv->insertInset(new_inset))
358 bv->updateInset(new_inset);
362 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
363 bool edit, bool pastesel)
365 InsetOld * inset = createInset(cmd);
366 BufferView * bv = cmd.view();
370 if (lt->selection.set()) {
371 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
374 if (bv->insertInset(inset)) {
376 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
377 inset->localDispatch(cmd);
379 if (gotsel && pastesel)
380 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
389 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
391 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
392 <<"] arg[" << cmd.argument << ']' << "xy[" <<
393 cmd.x << ',' << cmd.y << ']' << endl;
395 BufferView * bv = cmd.view();
397 switch (cmd.action) {
399 case LFUN_APPENDIX: {
400 ParagraphList::iterator pit = cursor.par();
401 bool start = !pit->params().startOfAppendix();
403 // ensure that we have only one start_of_appendix in this document
404 ParagraphList::iterator tmp = ownerParagraphs().begin();
405 ParagraphList::iterator end = ownerParagraphs().end();
407 for (; tmp != end; ++tmp) {
408 if (tmp->params().startOfAppendix()) {
409 recordUndo(bv, Undo::ATOMIC, tmp);
410 tmp->params().startOfAppendix(false);
416 recordUndo(bv, Undo::ATOMIC, pit);
417 pit->params().startOfAppendix(start);
419 // we can set the refreshing parameters now
421 redoParagraph(cursor.par());
422 setCursor(cursor.par(), cursor.pos());
427 case LFUN_DELETE_WORD_FORWARD:
428 bv->beforeChange(this);
433 case LFUN_DELETE_WORD_BACKWARD:
434 bv->beforeChange(this);
435 deleteWordBackward();
439 case LFUN_DELETE_LINE_FORWARD:
440 bv->beforeChange(this);
446 if (!selection.mark())
447 bv->beforeChange(this);
448 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
451 cursorRightOneWord();
456 if (!selection.mark())
457 bv->beforeChange(this);
458 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
459 cursorRightOneWord();
465 case LFUN_BEGINNINGBUF:
466 if (!selection.mark())
467 bv->beforeChange(this);
473 if (selection.mark())
474 bv->beforeChange(this);
480 if (!selection.set())
481 selection.cursor = cursor;
482 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
486 finishChange(bv, true);
490 if (!selection.set())
491 selection.cursor = cursor;
492 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
496 finishChange(bv, true);
500 if (!selection.set())
501 selection.cursor = cursor;
503 finishChange(bv, true);
507 if (!selection.set())
508 selection.cursor = cursor;
510 finishChange(bv, true);
513 case LFUN_UP_PARAGRAPHSEL:
514 if (!selection.set())
515 selection.cursor = cursor;
517 finishChange(bv, true);
520 case LFUN_DOWN_PARAGRAPHSEL:
521 if (!selection.set())
522 selection.cursor = cursor;
523 cursorDownParagraph();
524 finishChange(bv, true);
528 if (!selection.set())
529 selection.cursor = cursor;
531 finishChange(bv, true);
535 if (!selection.set())
536 selection.cursor = cursor;
538 finishChange(bv, true);
542 if (!selection.set())
543 selection.cursor = cursor;
545 finishChange(bv, true);
549 if (!selection.set())
550 selection.cursor = cursor;
552 finishChange(bv, true);
555 case LFUN_WORDRIGHTSEL:
556 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
559 cursorRightOneWord();
560 finishChange(bv, true);
563 case LFUN_WORDLEFTSEL:
564 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
565 cursorRightOneWord();
568 finishChange(bv, true);
572 LyXCursor cur1 = cursor;
574 ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
575 setCursor(cur1.par(), cur1.pos());
576 bv->beforeChange(this);
577 setCursor(cur2.par(), cur2.pos());
578 finishChange(bv, true);
583 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
584 if (!selection.mark())
585 bv->beforeChange(this);
588 if (cursor.pos() < cursor.par()->size()
589 && cursor.par()->isInset(cursor.pos())
590 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
591 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
592 cmd.message(tmpinset->editMessage());
593 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
594 tmpinset->localDispatch(cmd1);
604 // This is soooo ugly. Isn`t it possible to make
606 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
607 if (!selection.mark())
608 bv->beforeChange(this);
609 LyXCursor const cur = cursor;
612 if ((is_rtl || cur != cursor) && // only if really moved!
613 cursor.pos() < cursor.par()->size() &&
614 cursor.par()->isInset(cursor.pos()) &&
615 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
616 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
617 cmd.message(tmpinset->editMessage());
618 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
619 tmpinset->localDispatch(cmd1);
629 if (!selection.mark())
630 bv->beforeChange(this);
636 if (!selection.mark())
637 bv->beforeChange(this);
642 case LFUN_UP_PARAGRAPH:
643 if (!selection.mark())
644 bv->beforeChange(this);
649 case LFUN_DOWN_PARAGRAPH:
650 if (!selection.mark())
651 bv->beforeChange(this);
652 cursorDownParagraph();
653 finishChange(bv, false);
657 if (!selection.mark())
658 bv->beforeChange(this);
660 finishChange(bv, false);
664 if (!selection.mark())
665 bv->beforeChange(this);
667 finishChange(bv, false);
671 if (!selection.mark())
672 bv->beforeChange(this);
674 finishChange(bv, false);
678 if (!selection.mark())
679 bv->beforeChange(this);
681 finishChange(bv, false);
684 case LFUN_BREAKLINE: {
685 lyx::pos_type body = cursor.par()->beginningOfBody();
687 // Not allowed by LaTeX (labels or empty par)
688 if (cursor.pos() <= body)
691 replaceSelection(bv->getLyXText());
692 insertInset(new InsetNewline);
693 setCursor(cursor.par(), cursor.pos());
694 moveCursorUpdate(bv, false);
699 if (!selection.set()) {
701 selection.cursor = cursor;
702 // It is possible to make it a lot faster still
703 // just comment out the line below...
705 cutSelection(true, false);
707 moveCursorUpdate(bv, false);
708 bv->owner()->view_state_changed();
711 case LFUN_DELETE_SKIP:
712 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
713 if (!selection.set()) {
714 LyXCursor cur = cursor;
715 if (cur.pos() == cur.par()->size()) {
719 && !(cur.par()->params().spaceTop()
720 == VSpace (VSpace::NONE))) {
722 cur.par()->params().lineTop(),
723 cur.par()->params().lineBottom(),
724 cur.par()->params().pagebreakTop(),
725 cur.par()->params().pagebreakBottom(),
726 VSpace(VSpace::NONE),
727 cur.par()->params().spaceBottom(),
728 cur.par()->params().spacing(),
729 cur.par()->params().align(),
730 cur.par()->params().labelWidthString(), 0);
735 selection.cursor = cursor;
739 selection.cursor = cursor;
742 cutSelection(true, false);
749 if (!selection.set()) {
750 if (bv->owner()->getIntl().getTransManager().backspace()) {
752 selection.cursor = cursor;
753 // It is possible to make it a lot faster still
754 // just comment out the line below...
757 cutSelection(true, false);
759 bv->owner()->view_state_changed();
764 case LFUN_BACKSPACE_SKIP:
765 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
766 if (!selection.set()) {
767 LyXCursor cur = cursor;
769 && !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
771 cur.par()->params().lineTop(),
772 cur.par()->params().lineBottom(),
773 cur.par()->params().pagebreakTop(),
774 cur.par()->params().pagebreakBottom(),
775 VSpace(VSpace::NONE),
776 cur.par()->params().spaceBottom(),
777 cur.par()->params().spacing(),
778 cur.par()->params().align(),
779 cur.par()->params().labelWidthString(), 0);
782 selection.cursor = cur;
785 cutSelection(true, false);
790 case LFUN_BREAKPARAGRAPH:
791 replaceSelection(bv->getLyXText());
792 breakParagraph(bv->buffer()->paragraphs, 0);
794 selection.cursor = cursor;
796 bv->owner()->view_state_changed();
799 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
800 replaceSelection(bv->getLyXText());
801 breakParagraph(bv->buffer()->paragraphs, 1);
803 selection.cursor = cursor;
805 bv->owner()->view_state_changed();
808 case LFUN_BREAKPARAGRAPH_SKIP: {
809 // When at the beginning of a paragraph, remove
810 // indentation and add a "defskip" at the top.
811 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
812 LyXCursor cur = cursor;
813 replaceSelection(bv->getLyXText());
814 if (cur.pos() == 0) {
815 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
817 cur.par()->params().lineTop(),
818 cur.par()->params().lineBottom(),
819 cur.par()->params().pagebreakTop(),
820 cur.par()->params().pagebreakBottom(),
821 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
822 cur.par()->params().spacing(),
823 cur.par()->params().align(),
824 cur.par()->params().labelWidthString(), 1);
828 breakParagraph(bv->buffer()->paragraphs, 0);
831 selection.cursor = cur;
833 bv->owner()->view_state_changed();
837 case LFUN_PARAGRAPH_SPACING: {
838 ParagraphList::iterator pit = cursor.par();
839 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
840 float cur_value = 1.0;
841 if (cur_spacing == Spacing::Other)
842 cur_value = pit->params().spacing().getValue();
844 istringstream is(STRCONV(cmd.argument));
847 Spacing::Space new_spacing = cur_spacing;
848 float new_value = cur_value;
850 lyxerr << "Missing argument to `paragraph-spacing'"
852 } else if (tmp == "single") {
853 new_spacing = Spacing::Single;
854 } else if (tmp == "onehalf") {
855 new_spacing = Spacing::Onehalf;
856 } else if (tmp == "double") {
857 new_spacing = Spacing::Double;
858 } else if (tmp == "other") {
859 new_spacing = Spacing::Other;
862 lyxerr << "new_value = " << tmpval << endl;
865 } else if (tmp == "default") {
866 new_spacing = Spacing::Default;
868 lyxerr << _("Unknown spacing argument: ")
869 << cmd.argument << endl;
871 if (cur_spacing != new_spacing || cur_value != new_value) {
872 pit->params().spacing(Spacing(new_spacing, new_value));
879 case LFUN_INSET_SETTINGS:
880 Assert(bv->theLockingInset());
881 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
884 case LFUN_INSET_TOGGLE:
885 bv->beforeChange(this);
891 case LFUN_SPACE_INSERT:
892 if (cursor.par()->layout()->free_spacing)
895 doInsertInset(this, cmd, false, false);
896 moveCursorUpdate(bv, false);
899 case LFUN_HYPHENATION:
900 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
903 case LFUN_LIGATURE_BREAK:
904 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
908 specialChar(this, bv, InsetSpecialChar::LDOTS);
911 case LFUN_END_OF_SENTENCE:
912 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
915 case LFUN_MENU_SEPARATOR:
916 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
920 bv->beforeChange(this);
922 selection.cursor = cursor;
923 cmd.message(N_("Mark off"));
927 bv->beforeChange(this);
928 selection.mark(true);
930 selection.cursor = cursor;
931 cmd.message(N_("Mark on"));
935 bv->beforeChange(this);
936 if (selection.mark()) {
937 cmd.message(N_("Mark removed"));
939 selection.mark(true);
940 cmd.message(N_("Mark set"));
942 selection.cursor = cursor;
946 case LFUN_UPCASE_WORD:
947 changeCase(LyXText::text_uppercase);
951 case LFUN_LOWCASE_WORD:
952 changeCase(LyXText::text_lowercase);
956 case LFUN_CAPITALIZE_WORD:
957 changeCase(LyXText::text_capitalization);
961 case LFUN_TRANSPOSE_CHARS:
962 recordUndo(bv, Undo::ATOMIC, cursor.par());
968 cmd.message(_("Paste"));
969 replaceSelection(bv->getLyXText());
970 size_t sel_index = 0;
971 string const & arg = cmd.argument;
972 if (isStrUnsignedInt(arg)) {
973 size_t const paste_arg = strToUnsignedInt(arg);
974 #warning FIXME Check if the arg is in the domain of available selections.
975 sel_index = paste_arg;
977 pasteSelection(sel_index);
978 clearSelection(); // bug 393
985 cutSelection(true, true);
986 cmd.message(_("Cut"));
992 cmd.message(_("Copy"));
995 case LFUN_BEGINNINGBUFSEL:
999 finishChange(bv, true);
1002 case LFUN_ENDBUFSEL:
1004 return UNDISPATCHED;
1006 finishChange(bv, true);
1010 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1016 istringstream is(STRCONV(cmd.argument));
1019 lyxerr << "SETXY: Could not parse coordinates in '"
1020 << cmd.argument << std::endl;
1022 setCursorFromCoordinates(x, y);
1027 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1029 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1035 case LFUN_GETLAYOUT:
1036 cmd.message(tostr(cursor.par()->layout()));
1040 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1041 << cmd.argument << endl;
1043 // This is not the good solution to the empty argument
1044 // problem, but it will hopefully suffice for 1.2.0.
1045 // The correct solution would be to augument the
1046 // function list/array with information about what
1047 // functions needs arguments and their type.
1048 if (cmd.argument.empty()) {
1049 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1053 // Derive layout number from given argument (string)
1054 // and current buffer's textclass (number)
1055 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1056 bool hasLayout = tclass.hasLayout(cmd.argument);
1057 string layout = cmd.argument;
1059 // If the entry is obsolete, use the new one instead.
1061 string const & obs = tclass[layout]->obsoleted_by();
1067 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1072 bool change_layout = (current_layout != layout);
1074 if (!change_layout && selection.set() &&
1075 selection.start.par() != selection.end.par())
1077 ParagraphList::iterator spit = selection.start.par();
1078 ParagraphList::iterator epit = boost::next(selection.end.par());
1079 while (spit != epit) {
1080 if (spit->layout()->name() != current_layout) {
1081 change_layout = true;
1088 if (change_layout) {
1089 current_layout = layout;
1091 bv->owner()->setLayout(layout);
1098 case LFUN_PASTESELECTION: {
1099 // this was originally a beforeChange(bv->text), i.e
1100 // the outermost LyXText!
1101 bv->beforeChange(this);
1102 string const clip = bv->getClipboard();
1103 if (!clip.empty()) {
1104 if (cmd.argument == "paragraph")
1105 insertStringAsParagraphs(clip);
1107 insertStringAsLines(clip);
1114 case LFUN_GOTOERROR:
1115 gotoInset(InsetOld::ERROR_CODE, false);
1119 gotoInset(InsetOld::NOTE_CODE, false);
1122 case LFUN_REFERENCE_GOTO:
1124 vector<InsetOld::Code> tmp;
1125 tmp.push_back(InsetOld::LABEL_CODE);
1126 tmp.push_back(InsetOld::REF_CODE);
1127 gotoInset(tmp, true);
1132 replaceSelection(bv->getLyXText());
1133 ParagraphList::iterator pit = cursor.par();
1134 lyx::pos_type pos = cursor.pos();
1138 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1141 c = pit->getChar(pos - 1);
1143 LyXLayout_ptr const & style = pit->layout();
1145 if (style->pass_thru ||
1146 pit->getFontSettings(bv->buffer()->params,
1147 pos).language()->lang() == "hebrew" ||
1148 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1149 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1153 case LFUN_DATE_INSERT: {
1154 replaceSelection(bv->getLyXText());
1155 time_t now_time_t = time(NULL);
1156 struct tm * now_tm = localtime(&now_time_t);
1157 setlocale(LC_TIME, "");
1159 if (!cmd.argument.empty())
1162 arg = lyxrc.date_insert_format;
1164 int const datetmp_len =
1165 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1167 for (int i = 0; i < datetmp_len; i++)
1168 insertChar(datetmp[i]);
1170 selection.cursor = cursor;
1171 moveCursorUpdate(bv, false);
1175 case LFUN_MOUSE_TRIPLE:
1178 if (!isInInset() && bv->theLockingInset())
1180 if (cmd.button() == mouse_button::button1) {
1182 selection.cursor = cursor;
1186 bv->haveSelection(selection.set());
1190 case LFUN_MOUSE_DOUBLE:
1193 if (!isInInset() && bv->theLockingInset())
1195 if (cmd.button() == mouse_button::button1) {
1196 selectWord(lyx::WHOLE_WORD_STRICT);
1198 bv->haveSelection(selection.set());
1202 case LFUN_MOUSE_MOTION:
1204 // Only use motion with button 1
1205 //if (ev.button() != mouse_button::button1)
1211 // Check for inset locking
1212 if (bv->theLockingInset()) {
1213 InsetOld * tli = bv->theLockingInset();
1214 LyXCursor cursor = bv->text->cursor;
1215 LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
1216 int width = tli->width();
1217 int inset_x = font.isVisibleRightToLeft()
1218 ? cursor.x() - width : cursor.x();
1219 int start_x = inset_x + tli->scroll();
1220 FuncRequest cmd1 = cmd;
1221 cmd1.x = cmd.x - start_x;
1222 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1223 tli->localDispatch(cmd1);
1227 // The test for not selection possible is needed, that only motion
1228 // events are used, where the bottom press event was on
1229 // the drawing area too
1230 if (!selection_possible) {
1231 lyxerr[Debug::ACTION]
1232 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1236 RowList::iterator cursorrow = bv->text->cursorRow();
1237 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1239 // sorry for this but I have a strange error that the y value jumps at
1240 // a certain point. This seems like an error in my xforms library or
1241 // in some other local environment, but I would like to leave this here
1242 // for the moment until I can remove this (Jug 20020418)
1243 if (y_before < bv->text->cursor.y())
1244 lyxerr << y_before << ':'
1245 << bv->text->cursor.y() << endl;
1247 // This is to allow jumping over large insets
1248 if (cursorrow == bv->text->cursorRow()) {
1249 if (cmd.y >= bv->workHeight())
1250 bv->text->cursorDown(false);
1252 bv->text->cursorUp(false);
1255 bv->text->setSelection();
1260 // Single-click on work area
1261 case LFUN_MOUSE_PRESS:
1266 // ok ok, this is a hack (for xforms)
1267 // We shouldn't go further down as we really should only do the
1268 // scrolling and be done with this. Otherwise we may open some
1269 // dialogs (Jug 20020424).
1270 if (cmd.button() == mouse_button::button4) {
1271 bv->scroll(-lyxrc.wheel_jump);
1274 if (cmd.button() == mouse_button::button5) {
1275 bv->scroll(lyxrc.wheel_jump);
1281 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1283 // Middle button press pastes if we have a selection
1284 // We do this here as if the selection was inside an inset
1285 // it could get cleared on the unlocking of the inset so
1286 // we have to check this first
1287 bool paste_internally = false;
1288 if (cmd.button() == mouse_button::button2 && selection.set()) {
1289 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1290 paste_internally = true;
1293 int const screen_first = bv->top_y();
1295 if (bv->theLockingInset()) {
1296 // We are in inset locking mode
1298 // Check whether the inset was hit. If not reset mode,
1299 // otherwise give the event to the inset
1300 if (inset_hit == bv->theLockingInset()) {
1301 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1302 bv->theLockingInset()->localDispatch(cmd1);
1305 bv->unlockInset(bv->theLockingInset());
1309 selection_possible = true;
1311 // Clear the selection
1312 bv->text->clearSelection();
1314 bv->updateScrollbar();
1316 // Single left click in math inset?
1317 if (isHighlyEditableInset(inset_hit)) {
1318 // Highly editable inset, like math
1319 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1320 selection_possible = false;
1321 bv->owner()->message(inset->editMessage());
1322 // We just have to lock the inset before calling a PressEvent on it!
1323 if (!bv->lockInset(inset))
1324 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1325 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1326 inset->localDispatch(cmd1);
1329 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1331 // Right click on a footnote flag opens float menu
1332 if (cmd.button() == mouse_button::button3) {
1333 selection_possible = false;
1337 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1338 bv->text->setCursorFromCoordinates(x, y + screen_first);
1340 bv->text->selection.cursor = bv->text->cursor;
1341 bv->text->cursor.x_fix(bv->text->cursor.x());
1343 if (bv->fitCursor())
1344 selection_possible = false;
1346 // Insert primary selection with middle mouse
1347 // if there is a local selection in the current buffer,
1349 if (cmd.button() == mouse_button::button2) {
1350 if (paste_internally)
1351 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1353 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1354 selection_possible = false;
1359 case LFUN_MOUSE_RELEASE:
1361 // do nothing if we used the mouse wheel
1365 if (cmd.button() == mouse_button::button4
1366 || cmd.button() == mouse_button::button5)
1369 // If we hit an inset, we have the inset coordinates in these
1370 // and inset_hit points to the inset. If we do not hit an
1371 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1374 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1376 if (bv->theLockingInset()) {
1377 // We are in inset locking mode.
1379 // LyX does a kind of work-area grabbing for insets.
1380 // Only a ButtonPress FuncRequest outside the inset will
1381 // force a insetUnlock.
1382 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1383 bv->theLockingInset()->localDispatch(cmd1);
1387 selection_possible = false;
1389 if (cmd.button() == mouse_button::button2)
1393 if (cmd.button() == mouse_button::button1)
1394 bv->haveSelection(selection.set());
1397 bv->owner()->view_state_changed();
1398 bv->owner()->updateMenubar();
1399 bv->owner()->updateToolbar();
1401 // Did we hit an editable inset?
1403 selection_possible = false;
1405 // if we reach this point with a selection, it
1406 // must mean we are currently selecting.
1407 // But we don't want to open the inset
1408 // because that is annoying for the user.
1409 // So just pretend we didn't hit it.
1410 // this is OK because a "kosher" ButtonRelease
1411 // will follow a ButtonPress that clears
1413 // Note this also fixes selection drawing
1414 // problems if we end up opening an inset
1415 if (selection.set())
1418 // CHECK fix this proper in 0.13
1419 // well, maybe 13.0 !!!!!!!!!
1421 // Following a ref shouldn't issue
1422 // a push on the undo-stack
1423 // anylonger, now that we have
1424 // keybindings for following
1425 // references and returning from
1426 // references. IMHO though, it
1427 // should be the inset's own business
1428 // to push or not push on the undo
1429 // stack. They don't *have* to
1430 // alter the document...
1432 // ...or maybe the recordUndo()
1433 // below isn't necessary at all anylonger?
1434 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1435 recordUndo(bv, Undo::ATOMIC);
1437 bv->owner()->message(inset_hit->editMessage());
1439 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1440 inset_hit->localDispatch(cmd1);
1446 case LFUN_SELFINSERT: {
1447 if (cmd.argument.empty())
1450 // Automatically delete the currently selected
1451 // text and replace it with what is being
1452 // typed in now. Depends on lyxrc settings
1453 // "auto_region_delete", which defaults to
1456 if (lyxrc.auto_region_delete) {
1457 if (selection.set())
1458 cutSelection(false, false);
1459 bv->haveSelection(false);
1462 bv->beforeChange(this);
1463 LyXFont const old_font = real_current_font;
1465 string::const_iterator cit = cmd.argument.begin();
1466 string::const_iterator end = cmd.argument.end();
1467 for (; cit != end; ++cit)
1468 bv->owner()->getIntl().getTransManager().
1469 TranslateAndInsert(*cit, this);
1471 selection.cursor = cursor;
1472 moveCursorUpdate(bv, false);
1474 // real_current_font.number can change so we need to
1475 // update the minibuffer
1476 if (old_font != real_current_font)
1477 bv->owner()->view_state_changed();
1478 bv->updateScrollbar();
1482 case LFUN_HTMLURL: {
1483 InsetCommandParams p("htmlurl");
1484 string const data = InsetCommandMailer::params2string("url", p);
1485 bv->owner()->getDialogs().show("url", data, 0);
1490 InsetCommandParams p("url");
1491 string const data = InsetCommandMailer::params2string("url", p);
1492 bv->owner()->getDialogs().show("url", data, 0);
1498 case LFUN_INSET_LIST:
1499 case LFUN_INSET_THEOREM:
1500 case LFUN_INSET_CAPTION:
1502 case LFUN_INSERT_NOTE:
1503 case LFUN_INSERT_BRANCH:
1504 case LFUN_INSERT_BIBITEM:
1505 case LFUN_INSET_ERT:
1506 case LFUN_INSET_FLOAT:
1507 case LFUN_INSET_FOOTNOTE:
1508 case LFUN_INSET_MARGINAL:
1509 case LFUN_INSET_MINIPAGE:
1510 case LFUN_INSET_OPTARG:
1511 case LFUN_INSET_WIDE_FLOAT:
1512 case LFUN_INSET_WRAP:
1513 case LFUN_TABULAR_INSERT:
1514 case LFUN_ENVIRONMENT_INSERT:
1515 // Open the inset, and move the current selection
1517 doInsertInset(this, cmd, true, true);
1520 case LFUN_INDEX_INSERT:
1521 // Just open the inset
1522 doInsertInset(this, cmd, true, false);
1525 case LFUN_INDEX_PRINT:
1526 case LFUN_TOC_INSERT:
1529 doInsertInset(this, cmd, false, false);
1533 return UNDISPATCHED;