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 (!lt->selection.set())
71 // lt->selection.cursor = lt->cursor;
73 if (selecting || lt->selection.mark())
76 if (!lt->selection.set())
77 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))
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 redoParagraph(cursor.par());
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();
477 case LFUN_BEGINNINGBUF:
478 if (!selection.mark())
479 bv->beforeChange(this);
485 if (selection.mark())
486 bv->beforeChange(this);
492 if (!selection.set())
493 selection.cursor = cursor;
494 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
498 finishChange(bv, true);
502 if (!selection.set())
503 selection.cursor = cursor;
504 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
508 finishChange(bv, true);
512 if (!selection.set())
513 selection.cursor = cursor;
515 finishChange(bv, true);
519 if (!selection.set())
520 selection.cursor = cursor;
522 finishChange(bv, true);
525 case LFUN_UP_PARAGRAPHSEL:
526 if (!selection.set())
527 selection.cursor = cursor;
529 finishChange(bv, true);
532 case LFUN_DOWN_PARAGRAPHSEL:
533 if (!selection.set())
534 selection.cursor = cursor;
535 cursorDownParagraph();
536 finishChange(bv, true);
540 if (!selection.set())
541 selection.cursor = cursor;
543 finishChange(bv, true);
547 if (!selection.set())
548 selection.cursor = cursor;
550 finishChange(bv, true);
554 if (!selection.set())
555 selection.cursor = cursor;
557 finishChange(bv, true);
561 if (!selection.set())
562 selection.cursor = cursor;
564 finishChange(bv, true);
567 case LFUN_WORDRIGHTSEL:
568 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
571 cursorRightOneWord();
572 finishChange(bv, true);
575 case LFUN_WORDLEFTSEL:
576 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
577 cursorRightOneWord();
580 finishChange(bv, true);
584 LyXCursor cur1 = cursor;
586 ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
587 setCursor(cur1.par(), cur1.pos());
588 bv->beforeChange(this);
589 setCursor(cur2.par(), cur2.pos());
590 finishChange(bv, true);
595 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
596 if (!selection.mark())
597 bv->beforeChange(this);
600 if (cursor.pos() < cursor.par()->size()
601 && cursor.par()->isInset(cursor.pos())
602 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
603 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
604 cmd.message(tmpinset->editMessage());
605 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
606 tmpinset->localDispatch(cmd1);
616 // This is soooo ugly. Isn`t it possible to make
618 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
619 if (!selection.mark())
620 bv->beforeChange(this);
621 LyXCursor const cur = cursor;
624 if ((is_rtl || cur != cursor) && // only if really moved!
625 cursor.pos() < cursor.par()->size() &&
626 cursor.par()->isInset(cursor.pos()) &&
627 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
628 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
629 cmd.message(tmpinset->editMessage());
630 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
631 tmpinset->localDispatch(cmd1);
641 if (!selection.mark())
642 bv->beforeChange(this);
648 if (!selection.mark())
649 bv->beforeChange(this);
654 case LFUN_UP_PARAGRAPH:
655 if (!selection.mark())
656 bv->beforeChange(this);
661 case LFUN_DOWN_PARAGRAPH:
662 if (!selection.mark())
663 bv->beforeChange(this);
664 cursorDownParagraph();
665 finishChange(bv, false);
669 if (!selection.mark())
670 bv->beforeChange(this);
672 finishChange(bv, false);
676 if (!selection.mark())
677 bv->beforeChange(this);
679 finishChange(bv, false);
683 if (!selection.mark())
684 bv->beforeChange(this);
686 finishChange(bv, false);
690 if (!selection.mark())
691 bv->beforeChange(this);
693 finishChange(bv, false);
696 case LFUN_BREAKLINE: {
697 lyx::pos_type body = cursor.par()->beginningOfBody();
699 // Not allowed by LaTeX (labels or empty par)
700 if (cursor.pos() <= body)
703 replaceSelection(bv->getLyXText());
704 insertInset(new InsetNewline);
705 setCursor(cursor.par(), cursor.pos());
706 moveCursorUpdate(bv, false);
711 if (!selection.set()) {
713 selection.cursor = cursor;
714 // It is possible to make it a lot faster still
715 // just comment out the line below...
717 cutSelection(true, false);
719 moveCursorUpdate(bv, false);
720 bv->owner()->view_state_changed();
724 case LFUN_DELETE_SKIP:
725 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
726 if (!selection.set()) {
727 LyXCursor cur = cursor;
728 if (cur.pos() == cur.par()->size()) {
732 && !(cur.par()->params().spaceTop()
733 == VSpace (VSpace::NONE))) {
735 cur.par()->params().lineTop(),
736 cur.par()->params().lineBottom(),
737 cur.par()->params().pagebreakTop(),
738 cur.par()->params().pagebreakBottom(),
739 VSpace(VSpace::NONE),
740 cur.par()->params().spaceBottom(),
741 cur.par()->params().spacing(),
742 cur.par()->params().align(),
743 cur.par()->params().labelWidthString(), 0);
748 selection.cursor = cursor;
752 selection.cursor = cursor;
755 cutSelection(true, false);
762 if (!selection.set()) {
763 if (bv->owner()->getIntl().getTransManager().backspace()) {
765 selection.cursor = cursor;
766 // It is possible to make it a lot faster still
767 // just comment out the line below...
770 cutSelection(true, false);
772 bv->owner()->view_state_changed();
777 case LFUN_BACKSPACE_SKIP:
778 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
779 if (!selection.set()) {
780 LyXCursor cur = cursor;
782 && !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
784 cur.par()->params().lineTop(),
785 cur.par()->params().lineBottom(),
786 cur.par()->params().pagebreakTop(),
787 cur.par()->params().pagebreakBottom(),
788 VSpace(VSpace::NONE),
789 cur.par()->params().spaceBottom(),
790 cur.par()->params().spacing(),
791 cur.par()->params().align(),
792 cur.par()->params().labelWidthString(), 0);
795 selection.cursor = cur;
799 cutSelection(true, false);
804 case LFUN_BREAKPARAGRAPH:
805 replaceSelection(bv->getLyXText());
806 breakParagraph(bv->buffer()->paragraphs, 0);
808 selection.cursor = cursor;
810 bv->owner()->view_state_changed();
813 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
814 replaceSelection(bv->getLyXText());
815 breakParagraph(bv->buffer()->paragraphs, 1);
817 selection.cursor = cursor;
819 bv->owner()->view_state_changed();
822 case LFUN_BREAKPARAGRAPH_SKIP: {
823 // When at the beginning of a paragraph, remove
824 // indentation and add a "defskip" at the top.
825 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
826 LyXCursor cur = cursor;
827 replaceSelection(bv->getLyXText());
828 if (cur.pos() == 0) {
829 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
831 cur.par()->params().lineTop(),
832 cur.par()->params().lineBottom(),
833 cur.par()->params().pagebreakTop(),
834 cur.par()->params().pagebreakBottom(),
835 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
836 cur.par()->params().spacing(),
837 cur.par()->params().align(),
838 cur.par()->params().labelWidthString(), 1);
842 breakParagraph(bv->buffer()->paragraphs, 0);
845 selection.cursor = cur;
847 bv->owner()->view_state_changed();
851 case LFUN_PARAGRAPH_SPACING: {
852 ParagraphList::iterator pit = cursor.par();
853 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
854 float cur_value = 1.0;
855 if (cur_spacing == Spacing::Other)
856 cur_value = pit->params().spacing().getValue();
858 istringstream is(STRCONV(cmd.argument));
861 Spacing::Space new_spacing = cur_spacing;
862 float new_value = cur_value;
864 lyxerr << "Missing argument to `paragraph-spacing'"
866 } else if (tmp == "single") {
867 new_spacing = Spacing::Single;
868 } else if (tmp == "onehalf") {
869 new_spacing = Spacing::Onehalf;
870 } else if (tmp == "double") {
871 new_spacing = Spacing::Double;
872 } else if (tmp == "other") {
873 new_spacing = Spacing::Other;
876 lyxerr << "new_value = " << tmpval << endl;
879 } else if (tmp == "default") {
880 new_spacing = Spacing::Default;
882 lyxerr << _("Unknown spacing argument: ")
883 << cmd.argument << endl;
885 if (cur_spacing != new_spacing || cur_value != new_value) {
886 pit->params().spacing(Spacing(new_spacing, new_value));
893 case LFUN_INSET_SETTINGS:
894 Assert(bv->theLockingInset());
895 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
898 case LFUN_INSET_TOGGLE:
899 bv->beforeChange(this);
906 case LFUN_SPACE_INSERT:
907 if (cursor.par()->layout()->free_spacing) {
911 doInsertInset(this, cmd, false, false);
913 moveCursorUpdate(bv, false);
916 case LFUN_HYPHENATION:
917 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
920 case LFUN_LIGATURE_BREAK:
921 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
925 specialChar(this, bv, InsetSpecialChar::LDOTS);
928 case LFUN_END_OF_SENTENCE:
929 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
932 case LFUN_MENU_SEPARATOR:
933 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
937 bv->beforeChange(this);
939 selection.cursor = cursor;
940 cmd.message(N_("Mark off"));
944 bv->beforeChange(this);
945 selection.mark(true);
947 selection.cursor = cursor;
948 cmd.message(N_("Mark on"));
952 bv->beforeChange(this);
953 if (selection.mark()) {
954 cmd.message(N_("Mark removed"));
956 selection.mark(true);
957 cmd.message(N_("Mark set"));
959 selection.cursor = cursor;
963 case LFUN_UPCASE_WORD:
965 changeCase(LyXText::text_uppercase);
971 case LFUN_LOWCASE_WORD:
972 changeCase(LyXText::text_lowercase);
978 case LFUN_CAPITALIZE_WORD:
979 changeCase(LyXText::text_capitalization);
985 case LFUN_TRANSPOSE_CHARS:
986 recordUndo(bv, Undo::ATOMIC, cursor.par());
994 cmd.message(_("Paste"));
995 replaceSelection(bv->getLyXText());
996 size_t sel_index = 0;
997 string const & arg = cmd.argument;
998 if (isStrUnsignedInt(arg)) {
999 size_t const paste_arg = strToUnsignedInt(arg);
1000 #warning FIXME Check if the arg is in the domain of available selections.
1001 sel_index = paste_arg;
1003 pasteSelection(sel_index);
1004 clearSelection(); // bug 393
1011 cutSelection(true, true);
1012 cmd.message(_("Cut"));
1018 cmd.message(_("Copy"));
1021 case LFUN_BEGINNINGBUFSEL:
1023 return UNDISPATCHED;
1025 finishChange(bv, true);
1029 case LFUN_ENDBUFSEL:
1031 return UNDISPATCHED;
1033 finishChange(bv, true);
1038 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1044 istringstream is(STRCONV(cmd.argument));
1047 lyxerr << "SETXY: Could not parse coordinates in '"
1048 << cmd.argument << std::endl;
1050 setCursorFromCoordinates(x, y);
1055 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1057 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1063 case LFUN_GETLAYOUT:
1064 cmd.message(tostr(cursor.par()->layout()));
1068 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1069 << cmd.argument << endl;
1071 // This is not the good solution to the empty argument
1072 // problem, but it will hopefully suffice for 1.2.0.
1073 // The correct solution would be to augument the
1074 // function list/array with information about what
1075 // functions needs arguments and their type.
1076 if (cmd.argument.empty()) {
1077 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1081 // Derive layout number from given argument (string)
1082 // and current buffer's textclass (number)
1083 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1084 bool hasLayout = tclass.hasLayout(cmd.argument);
1085 string layout = cmd.argument;
1087 // If the entry is obsolete, use the new one instead.
1089 string const & obs = tclass[layout]->obsoleted_by();
1095 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1100 bool change_layout = (current_layout != layout);
1102 if (!change_layout && selection.set() &&
1103 selection.start.par() != selection.end.par())
1105 ParagraphList::iterator spit = selection.start.par();
1106 ParagraphList::iterator epit = boost::next(selection.end.par());
1107 while (spit != epit) {
1108 if (spit->layout()->name() != current_layout) {
1109 change_layout = true;
1116 if (change_layout) {
1117 current_layout = layout;
1119 bv->owner()->setLayout(layout);
1126 case LFUN_PASTESELECTION: {
1127 // this was originally a beforeChange(bv->text), i.e
1128 // the outermost LyXText!
1129 bv->beforeChange(this);
1130 string const clip = bv->getClipboard();
1131 if (!clip.empty()) {
1132 if (cmd.argument == "paragraph")
1133 insertStringAsParagraphs(clip);
1135 insertStringAsLines(clip);
1142 case LFUN_GOTOERROR:
1143 gotoInset(InsetOld::ERROR_CODE, false);
1147 gotoInset(InsetOld::NOTE_CODE, false);
1150 case LFUN_REFERENCE_GOTO:
1152 vector<InsetOld::Code> tmp;
1153 tmp.push_back(InsetOld::LABEL_CODE);
1154 tmp.push_back(InsetOld::REF_CODE);
1155 gotoInset(tmp, true);
1160 replaceSelection(bv->getLyXText());
1161 ParagraphList::iterator pit = cursor.par();
1162 lyx::pos_type pos = cursor.pos();
1166 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1169 c = pit->getChar(pos - 1);
1171 LyXLayout_ptr const & style = pit->layout();
1173 if (style->pass_thru ||
1174 pit->getFontSettings(bv->buffer()->params,
1175 pos).language()->lang() == "hebrew" ||
1176 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1177 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1181 case LFUN_DATE_INSERT: {
1182 replaceSelection(bv->getLyXText());
1183 time_t now_time_t = time(NULL);
1184 struct tm * now_tm = localtime(&now_time_t);
1185 setlocale(LC_TIME, "");
1187 if (!cmd.argument.empty())
1190 arg = lyxrc.date_insert_format;
1192 int const datetmp_len =
1193 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1195 for (int i = 0; i < datetmp_len; i++) {
1196 insertChar(datetmp[i]);
1199 selection.cursor = cursor;
1200 moveCursorUpdate(bv, false);
1204 case LFUN_MOUSE_TRIPLE:
1207 if (!isInInset() && bv->theLockingInset())
1209 if (cmd.button() == mouse_button::button1) {
1211 bv->screen().toggleSelection(this, bv);
1213 selection.cursor = cursor;
1217 bv->screen().toggleSelection(this, bv, false);
1219 bv->haveSelection(selection.set());
1223 case LFUN_MOUSE_DOUBLE:
1226 if (!isInInset() && bv->theLockingInset())
1228 if (cmd.button() == mouse_button::button1) {
1230 bv->screen().toggleSelection(this, bv);
1231 selectWord(lyx::WHOLE_WORD_STRICT);
1232 bv->screen().toggleSelection(this, bv, false);
1234 selectWord(lyx::WHOLE_WORD_STRICT);
1237 bv->haveSelection(selection.set());
1241 case LFUN_MOUSE_MOTION:
1243 // Only use motion with button 1
1244 //if (ev.button() != mouse_button::button1)
1250 // Check for inset locking
1251 if (bv->theLockingInset()) {
1252 InsetOld * tli = bv->theLockingInset();
1253 LyXCursor cursor = bv->text->cursor;
1254 LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
1255 int width = tli->width();
1256 int inset_x = font.isVisibleRightToLeft()
1257 ? cursor.ix() - width : cursor.ix();
1258 int start_x = inset_x + tli->scroll();
1259 FuncRequest cmd1 = cmd;
1260 cmd1.x = cmd.x - start_x;
1261 cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1262 tli->localDispatch(cmd1);
1266 // The test for not selection possible is needed, that only motion
1267 // events are used, where the bottom press event was on
1268 // the drawing area too
1269 if (!selection_possible) {
1270 lyxerr[Debug::ACTION]
1271 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1275 RowList::iterator cursorrow = bv->text->cursorRow();
1276 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1278 // sorry for this but I have a strange error that the y value jumps at
1279 // a certain point. This seems like an error in my xforms library or
1280 // in some other local environment, but I would like to leave this here
1281 // for the moment until I can remove this (Jug 20020418)
1282 if (y_before < bv->text->cursor.y())
1283 lyxerr << y_before << ':'
1284 << bv->text->cursor.y() << endl;
1286 // This is to allow jumping over large insets
1287 if (cursorrow == bv->text->cursorRow()) {
1288 if (cmd.y >= bv->workHeight())
1289 bv->text->cursorDown(false);
1291 bv->text->cursorUp(false);
1294 bv->text->setSelection();
1300 // Single-click on work area
1301 case LFUN_MOUSE_PRESS:
1306 // ok ok, this is a hack (for xforms)
1307 // We shouldn't go further down as we really should only do the
1308 // scrolling and be done with this. Otherwise we may open some
1309 // dialogs (Jug 20020424).
1310 if (cmd.button() == mouse_button::button4) {
1311 bv->scroll(-lyxrc.wheel_jump);
1314 if (cmd.button() == mouse_button::button5) {
1315 bv->scroll(lyxrc.wheel_jump);
1321 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1323 // Middle button press pastes if we have a selection
1324 // We do this here as if the selection was inside an inset
1325 // it could get cleared on the unlocking of the inset so
1326 // we have to check this first
1327 bool paste_internally = false;
1328 if (cmd.button() == mouse_button::button2 && selection.set()) {
1329 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1330 paste_internally = true;
1333 int const screen_first = bv->text->top_y();
1335 if (bv->theLockingInset()) {
1336 // We are in inset locking mode
1338 // Check whether the inset was hit. If not reset mode,
1339 // otherwise give the event to the inset
1340 if (inset_hit == bv->theLockingInset()) {
1341 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1342 bv->theLockingInset()->localDispatch(cmd1);
1345 bv->unlockInset(bv->theLockingInset());
1349 selection_possible = true;
1351 // Clear the selection
1352 bv->screen().toggleSelection(bv->text, bv);
1353 bv->text->clearSelection();
1355 bv->updateScrollbar();
1357 // Single left click in math inset?
1358 if (isHighlyEditableInset(inset_hit)) {
1359 // Highly editable inset, like math
1360 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1361 selection_possible = false;
1362 bv->owner()->message(inset->editMessage());
1363 // We just have to lock the inset before calling a PressEvent on it!
1364 if (!bv->lockInset(inset))
1365 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1366 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1367 inset->localDispatch(cmd1);
1370 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1372 // Right click on a footnote flag opens float menu
1373 if (cmd.button() == mouse_button::button3) {
1374 selection_possible = false;
1378 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1379 bv->text->setCursorFromCoordinates(x, y + screen_first);
1381 bv->text->selection.cursor = bv->text->cursor;
1382 bv->text->cursor.x_fix(bv->text->cursor.x());
1384 if (bv->fitCursor())
1385 selection_possible = false;
1387 // Insert primary selection with middle mouse
1388 // if there is a local selection in the current buffer,
1390 if (cmd.button() == mouse_button::button2) {
1391 if (paste_internally)
1392 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1394 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1395 selection_possible = false;
1400 case LFUN_MOUSE_RELEASE:
1402 // do nothing if we used the mouse wheel
1406 if (cmd.button() == mouse_button::button4
1407 || cmd.button() == mouse_button::button5)
1410 // If we hit an inset, we have the inset coordinates in these
1411 // and inset_hit points to the inset. If we do not hit an
1412 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1415 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1417 if (bv->theLockingInset()) {
1418 // We are in inset locking mode.
1420 // LyX does a kind of work-area grabbing for insets.
1421 // Only a ButtonPress FuncRequest outside the inset will
1422 // force a insetUnlock.
1423 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1424 bv->theLockingInset()->localDispatch(cmd1);
1428 selection_possible = false;
1430 if (cmd.button() == mouse_button::button2)
1434 if (cmd.button() == mouse_button::button1)
1435 bv->haveSelection(selection.set());
1438 bv->owner()->view_state_changed();
1439 bv->owner()->updateMenubar();
1440 bv->owner()->updateToolbar();
1442 // Did we hit an editable inset?
1444 selection_possible = false;
1446 // if we reach this point with a selection, it
1447 // must mean we are currently selecting.
1448 // But we don't want to open the inset
1449 // because that is annoying for the user.
1450 // So just pretend we didn't hit it.
1451 // this is OK because a "kosher" ButtonRelease
1452 // will follow a ButtonPress that clears
1454 // Note this also fixes selection drawing
1455 // problems if we end up opening an inset
1456 if (selection.set())
1459 // CHECK fix this proper in 0.13
1460 // well, maybe 13.0 !!!!!!!!!
1462 // Following a ref shouldn't issue
1463 // a push on the undo-stack
1464 // anylonger, now that we have
1465 // keybindings for following
1466 // references and returning from
1467 // references. IMHO though, it
1468 // should be the inset's own business
1469 // to push or not push on the undo
1470 // stack. They don't *have* to
1471 // alter the document...
1473 // ...or maybe the SetCursorParUndo()
1474 // below isn't necessary at all anylonger?
1475 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1476 recordUndo(bv, Undo::ATOMIC);
1478 bv->owner()->message(inset_hit->editMessage());
1480 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1481 inset_hit->localDispatch(cmd1);
1487 case LFUN_SELFINSERT: {
1488 if (cmd.argument.empty())
1491 // Automatically delete the currently selected
1492 // text and replace it with what is being
1493 // typed in now. Depends on lyxrc settings
1494 // "auto_region_delete", which defaults to
1497 if (lyxrc.auto_region_delete) {
1498 if (selection.set())
1499 cutSelection(false, false);
1500 bv->haveSelection(false);
1503 bv->beforeChange(this);
1504 LyXFont const old_font(real_current_font);
1506 string::const_iterator cit = cmd.argument.begin();
1507 string::const_iterator end = cmd.argument.end();
1508 for (; cit != end; ++cit)
1509 bv->owner()->getIntl().getTransManager().
1510 TranslateAndInsert(*cit, this);
1513 selection.cursor = cursor;
1514 moveCursorUpdate(bv, false);
1516 // real_current_font.number can change so we need to
1517 // update the minibuffer
1518 if (old_font != real_current_font)
1519 bv->owner()->view_state_changed();
1523 case LFUN_HTMLURL: {
1524 InsetCommandParams p("htmlurl");
1525 string const data = InsetCommandMailer::params2string("url", p);
1526 bv->owner()->getDialogs().show("url", data, 0);
1531 InsetCommandParams p("url");
1532 string const data = InsetCommandMailer::params2string("url", p);
1533 bv->owner()->getDialogs().show("url", data, 0);
1539 case LFUN_INSET_LIST:
1540 case LFUN_INSET_THEOREM:
1541 case LFUN_INSET_CAPTION:
1543 case LFUN_INSERT_NOTE:
1544 case LFUN_INSERT_BIBITEM:
1545 case LFUN_INSET_ERT:
1546 case LFUN_INSET_FLOAT:
1547 case LFUN_INSET_FOOTNOTE:
1548 case LFUN_INSET_MARGINAL:
1549 case LFUN_INSET_MINIPAGE:
1550 case LFUN_INSET_OPTARG:
1551 case LFUN_INSET_WIDE_FLOAT:
1552 case LFUN_INSET_WRAP:
1553 case LFUN_TABULAR_INSERT:
1554 case LFUN_ENVIRONMENT_INSERT:
1555 // Open the inset, and move the current selection
1557 doInsertInset(this, cmd, true, true);
1560 case LFUN_INDEX_INSERT:
1561 // Just open the inset
1562 doInsertInset(this, cmd, true, false);
1565 case LFUN_INDEX_PRINT:
1566 case LFUN_TOC_INSERT:
1569 doInsertInset(this, cmd, false, false);
1573 return UNDISPATCHED;