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.
21 #include "bufferparams.h"
22 #include "BufferView.h"
25 #include "funcrequest.h"
31 #include "paragraph.h"
32 #include "ParagraphParameters.h"
33 #include "text_funcs.h"
34 #include "undo_funcs.h"
37 #include "frontends/Dialogs.h"
38 #include "frontends/LyXView.h"
40 #include "insets/insetcommand.h"
41 #include "insets/insetnewline.h"
42 #include "insets/insetspecialchar.h"
43 #include "insets/insettext.h"
45 #include "support/lstrings.h"
46 #include "support/tostr.h"
48 #include "support/std_sstream.h"
51 using bv_funcs::replaceSelection;
55 using lyx::support::isStrUnsignedInt;
56 using lyx::support::strToUnsignedInt;
61 using std::istringstream;
65 extern string current_layout;
66 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
68 // the selection possible is needed, that only motion events are
69 // used, where the bottom press event was on the drawing area too
70 bool selection_possible = false;
75 void moveCursorUpdate(BufferView * bv, bool selecting)
77 LyXText * lt = bv->getLyXText();
79 //if (!lt->selection.set())
80 // lt->selection.cursor = lt->cursor;
82 if (selecting || lt->selection.mark())
85 if (!lt->selection.set())
86 bv->haveSelection(false);
93 void finishChange(BufferView * bv, bool selecting = false)
96 moveCursorUpdate(bv, selecting);
97 bv->owner()->view_state_changed();
100 // check if the given co-ordinates are inside an inset at the
101 // given cursor, if one exists. If so, the inset is returned,
102 // and the co-ordinates are made relative. Otherwise, 0 is returned.
103 InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
104 LyXCursor const & cur, int & x, int & y)
106 lyx::pos_type const pos = cur.pos();
107 ParagraphList::iterator par = cur.par();
109 if (pos >= par->size() || !par->isInset(pos))
112 InsetOld /*const*/ * inset = par->getInset(pos);
114 if (!isEditableInset(inset))
117 // get inset dimensions
118 BOOST_ASSERT(par->getInset(pos));
120 LyXFont const & font = text.getFont(par, pos);
122 int const width = inset->width();
123 int const inset_x = font.isVisibleRightToLeft()
124 ? (cur.x() - width) : cur.x();
127 inset_x + inset->scroll(),
129 cur.y() - inset->ascent(),
130 cur.y() + inset->descent()
133 if (!b.contains(x, y)) {
134 lyxerr[Debug::GUI] << "Missed inset at x,y "
136 << " box " << b << endl;
140 text.setCursor(par, pos, true);
143 // The origin of an inset is on the baseline
144 y -= text.cursor.y();
152 InsetOld * LyXText::checkInsetHit(int & x, int & y)
154 int y_tmp = y + bv_owner->top_y();
157 setCursorFromCoordinates(cur, x, y_tmp);
159 InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
165 // look at previous position
170 setCursor(cur, cur.par(), cur.pos() - 1, true);
172 inset = checkInset(bv(), *this, cur, x, y_tmp);
179 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
180 string const & contents)
182 ParagraphList::iterator end = ownerParagraphs().end();
183 ParagraphList::iterator pit = cursor.par();
184 pos_type pos = cursor.pos();
188 if (pos + 1 < pit->size()) {
195 } while (pit != end &&
196 !(pit->isInset(pos) &&
197 (inset = pit->getInset(pos)) != 0 &&
198 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
200 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
204 setCursor(pit, pos, false);
211 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
214 bv()->beforeChange(this);
217 if (same_content && cursor.pos() < cursor.par()->size()
218 && cursor.par()->isInset(cursor.pos())) {
219 InsetOld const * inset = cursor.par()->getInset(cursor.pos());
220 if (find(codes.begin(), codes.end(), inset->lyxCode())
222 contents = static_cast<InsetCommand const *>(inset)->getContents();
225 if (!gotoNextInset(codes, contents)) {
226 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
227 LyXCursor tmp = cursor;
228 cursor.par(ownerParagraphs().begin());
230 if (!gotoNextInset(codes, contents)) {
232 bv()->owner()->message(_("No more insets"));
235 bv()->owner()->message(_("No more insets"));
239 selection.cursor = cursor;
243 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
245 gotoInset(vector<InsetOld::Code>(1, code), same_content);
249 void LyXText::cursorPrevious()
251 int y = bv_owner->top_y();
253 RowList::iterator rit = cursorRow();
255 if (rit == firstRow()) {
257 bv()->updateScrollbar();
261 setCursorFromCoordinates(cursor.x_fix(), y);
265 if (rit == bv()->text->cursorRow()) {
266 // we have a row which is taller than the workarea. The
267 // simplest solution is to move to the previous row instead.
270 // This is what we used to do, so we wouldn't skip right past
271 // tall rows, but it's not working right now.
274 new_y = bv()->text->cursor.y()
275 + bv()->theLockingInset()->insetInInsetY() + y
277 - bv()->workHeight() + 1;
282 - bv()->workHeight() + 1;
287 ParagraphList::iterator pit = cursor.par();
288 previousRow(pit, rit);
289 setCursor(cur, pit, rit->pos(), false);
290 if (cur.y() > bv_owner->top_y())
292 bv()->updateScrollbar();
296 void LyXText::cursorNext()
298 int topy = bv_owner->top_y();
300 RowList::iterator rit = cursorRow();
301 if (rit == lastRow()) {
302 int y = cursor.y() - rit->baseline() + cursorRow()->height();
303 if (y > topy + bv()->workHeight())
304 bv_owner->updateScrollbar();
308 int y = topy + bv_owner->workHeight();
309 if (inset_owner && !topy) {
310 y -= (bv_owner->text->cursor.y()
312 + bv_owner->theLockingInset()->insetInInsetY());
315 ParagraphList::iterator dummypit;
316 y = getRowNearY(y, dummypit)->y();
318 setCursorFromCoordinates(cursor.x_fix(), y);
319 // + bv->workHeight());
323 if (rit == bv_owner->text->cursorRow()) {
324 // we have a row which is taller than the workarea. The
325 // simplest solution is to move to the next row instead.
328 // This is what we used to do, so we wouldn't skip right past
329 // tall rows, but it's not working right now.
331 new_y = bv->top_y() + bv->workHeight();
335 new_y = bv()->text->cursor.y()
336 + bv()->theLockingInset()->insetInInsetY()
337 + y - rit->baseline();
339 new_y = cursor.y() - cursorRow()->baseline();
343 ParagraphList::iterator pit = cursor.par();
346 setCursor(cur, pit, rit->pos(), false);
347 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
349 bv()->updateScrollbar();
355 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
358 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
359 replaceSelection(lt);
360 if (!bv->insertInset(new_inset))
363 bv->updateInset(new_inset);
367 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
368 bool edit, bool pastesel)
370 InsetOld * inset = createInset(cmd);
371 BufferView * bv = cmd.view();
375 if (lt->selection.set()) {
376 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
379 if (bv->insertInset(inset)) {
381 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
382 inset->localDispatch(cmd);
384 if (gotsel && pastesel)
385 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
394 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
396 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
397 <<"] arg[" << cmd.argument << ']' << "xy[" <<
398 cmd.x << ',' << cmd.y << ']' << endl;
400 BufferView * bv = cmd.view();
402 switch (cmd.action) {
404 case LFUN_APPENDIX: {
405 ParagraphList::iterator pit = cursor.par();
406 bool start = !pit->params().startOfAppendix();
408 // ensure that we have only one start_of_appendix in this document
409 ParagraphList::iterator tmp = ownerParagraphs().begin();
410 ParagraphList::iterator end = ownerParagraphs().end();
412 for (; tmp != end; ++tmp) {
413 if (tmp->params().startOfAppendix()) {
414 recordUndo(bv, Undo::ATOMIC, tmp);
415 tmp->params().startOfAppendix(false);
421 recordUndo(bv, Undo::ATOMIC, pit);
422 pit->params().startOfAppendix(start);
424 // we can set the refreshing parameters now
426 redoParagraph(cursor.par());
427 setCursor(cursor.par(), cursor.pos());
432 case LFUN_DELETE_WORD_FORWARD:
433 bv->beforeChange(this);
438 case LFUN_DELETE_WORD_BACKWARD:
439 bv->beforeChange(this);
440 deleteWordBackward();
444 case LFUN_DELETE_LINE_FORWARD:
445 bv->beforeChange(this);
451 if (!selection.mark())
452 bv->beforeChange(this);
453 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
456 cursorRightOneWord();
461 if (!selection.mark())
462 bv->beforeChange(this);
463 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
464 cursorRightOneWord();
470 case LFUN_BEGINNINGBUF:
471 if (!selection.mark())
472 bv->beforeChange(this);
478 if (selection.mark())
479 bv->beforeChange(this);
485 if (!selection.set())
486 selection.cursor = cursor;
487 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
491 finishChange(bv, true);
495 if (!selection.set())
496 selection.cursor = cursor;
497 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
501 finishChange(bv, true);
505 if (!selection.set())
506 selection.cursor = cursor;
508 finishChange(bv, true);
512 if (!selection.set())
513 selection.cursor = cursor;
515 finishChange(bv, true);
518 case LFUN_UP_PARAGRAPHSEL:
519 if (!selection.set())
520 selection.cursor = cursor;
522 finishChange(bv, true);
525 case LFUN_DOWN_PARAGRAPHSEL:
526 if (!selection.set())
527 selection.cursor = cursor;
528 cursorDownParagraph();
529 finishChange(bv, true);
533 if (!selection.set())
534 selection.cursor = cursor;
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);
560 case LFUN_WORDRIGHTSEL:
561 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
564 cursorRightOneWord();
565 finishChange(bv, true);
568 case LFUN_WORDLEFTSEL:
569 if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
570 cursorRightOneWord();
573 finishChange(bv, true);
577 LyXCursor cur1 = cursor;
579 ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
580 setCursor(cur1.par(), cur1.pos());
581 bv->beforeChange(this);
582 setCursor(cur2.par(), cur2.pos());
583 finishChange(bv, true);
588 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
589 if (!selection.mark())
590 bv->beforeChange(this);
593 if (cursor.pos() < cursor.par()->size()
594 && cursor.par()->isInset(cursor.pos())
595 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
596 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
597 cmd.message(tmpinset->editMessage());
598 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
599 tmpinset->localDispatch(cmd1);
609 // This is soooo ugly. Isn`t it possible to make
611 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
612 if (!selection.mark())
613 bv->beforeChange(this);
614 LyXCursor const cur = cursor;
617 if ((is_rtl || cur != cursor) && // only if really moved!
618 cursor.pos() < cursor.par()->size() &&
619 cursor.par()->isInset(cursor.pos()) &&
620 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
621 InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
622 cmd.message(tmpinset->editMessage());
623 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
624 tmpinset->localDispatch(cmd1);
634 if (!selection.mark())
635 bv->beforeChange(this);
641 if (!selection.mark())
642 bv->beforeChange(this);
647 case LFUN_UP_PARAGRAPH:
648 if (!selection.mark())
649 bv->beforeChange(this);
654 case LFUN_DOWN_PARAGRAPH:
655 if (!selection.mark())
656 bv->beforeChange(this);
657 cursorDownParagraph();
658 finishChange(bv, false);
662 if (!selection.mark())
663 bv->beforeChange(this);
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);
689 case LFUN_BREAKLINE: {
690 lyx::pos_type body = cursor.par()->beginningOfBody();
692 // Not allowed by LaTeX (labels or empty par)
693 if (cursor.pos() <= body)
696 replaceSelection(bv->getLyXText());
697 insertInset(new InsetNewline);
698 setCursor(cursor.par(), cursor.pos());
699 moveCursorUpdate(bv, false);
704 if (!selection.set()) {
706 selection.cursor = cursor;
707 // It is possible to make it a lot faster still
708 // just comment out the line below...
710 cutSelection(true, false);
712 moveCursorUpdate(bv, false);
713 bv->owner()->view_state_changed();
716 case LFUN_DELETE_SKIP:
717 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
718 if (!selection.set()) {
719 LyXCursor cur = cursor;
720 if (cur.pos() == cur.par()->size()) {
724 && !(cur.par()->params().spaceTop()
725 == VSpace (VSpace::NONE))) {
727 cur.par()->params().lineTop(),
728 cur.par()->params().lineBottom(),
729 cur.par()->params().pagebreakTop(),
730 cur.par()->params().pagebreakBottom(),
731 VSpace(VSpace::NONE),
732 cur.par()->params().spaceBottom(),
733 cur.par()->params().spacing(),
734 cur.par()->params().align(),
735 cur.par()->params().labelWidthString(), 0);
740 selection.cursor = cursor;
744 selection.cursor = cursor;
747 cutSelection(true, false);
754 if (!selection.set()) {
755 if (bv->owner()->getIntl().getTransManager().backspace()) {
757 selection.cursor = cursor;
758 // It is possible to make it a lot faster still
759 // just comment out the line below...
762 cutSelection(true, false);
764 bv->owner()->view_state_changed();
769 case LFUN_BACKSPACE_SKIP:
770 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
771 if (!selection.set()) {
772 LyXCursor cur = cursor;
774 && !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
776 cur.par()->params().lineTop(),
777 cur.par()->params().lineBottom(),
778 cur.par()->params().pagebreakTop(),
779 cur.par()->params().pagebreakBottom(),
780 VSpace(VSpace::NONE),
781 cur.par()->params().spaceBottom(),
782 cur.par()->params().spacing(),
783 cur.par()->params().align(),
784 cur.par()->params().labelWidthString(), 0);
787 selection.cursor = cur;
790 cutSelection(true, false);
795 case LFUN_BREAKPARAGRAPH:
796 replaceSelection(bv->getLyXText());
797 breakParagraph(bv->buffer()->paragraphs(), 0);
799 selection.cursor = cursor;
801 bv->owner()->view_state_changed();
804 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
805 replaceSelection(bv->getLyXText());
806 breakParagraph(bv->buffer()->paragraphs(), 1);
808 selection.cursor = cursor;
810 bv->owner()->view_state_changed();
813 case LFUN_BREAKPARAGRAPH_SKIP: {
814 // When at the beginning of a paragraph, remove
815 // indentation and add a "defskip" at the top.
816 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
817 LyXCursor cur = cursor;
818 replaceSelection(bv->getLyXText());
819 if (cur.pos() == 0) {
820 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
822 cur.par()->params().lineTop(),
823 cur.par()->params().lineBottom(),
824 cur.par()->params().pagebreakTop(),
825 cur.par()->params().pagebreakBottom(),
826 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
827 cur.par()->params().spacing(),
828 cur.par()->params().align(),
829 cur.par()->params().labelWidthString(), 1);
833 breakParagraph(bv->buffer()->paragraphs(), 0);
836 selection.cursor = cur;
838 bv->owner()->view_state_changed();
842 case LFUN_PARAGRAPH_SPACING: {
843 ParagraphList::iterator pit = cursor.par();
844 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
845 float cur_value = 1.0;
846 if (cur_spacing == Spacing::Other)
847 cur_value = pit->params().spacing().getValue();
849 istringstream is(cmd.argument);
852 Spacing::Space new_spacing = cur_spacing;
853 float new_value = cur_value;
855 lyxerr << "Missing argument to `paragraph-spacing'"
857 } else if (tmp == "single") {
858 new_spacing = Spacing::Single;
859 } else if (tmp == "onehalf") {
860 new_spacing = Spacing::Onehalf;
861 } else if (tmp == "double") {
862 new_spacing = Spacing::Double;
863 } else if (tmp == "other") {
864 new_spacing = Spacing::Other;
867 lyxerr << "new_value = " << tmpval << endl;
870 } else if (tmp == "default") {
871 new_spacing = Spacing::Default;
873 lyxerr << _("Unknown spacing argument: ")
874 << cmd.argument << endl;
876 if (cur_spacing != new_spacing || cur_value != new_value) {
877 pit->params().spacing(Spacing(new_spacing, new_value));
884 case LFUN_INSET_SETTINGS:
885 BOOST_ASSERT(bv->theLockingInset());
886 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
889 case LFUN_INSET_TOGGLE:
890 bv->beforeChange(this);
896 case LFUN_SPACE_INSERT:
897 if (cursor.par()->layout()->free_spacing)
900 doInsertInset(this, cmd, false, false);
901 moveCursorUpdate(bv, false);
904 case LFUN_HYPHENATION:
905 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
908 case LFUN_LIGATURE_BREAK:
909 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
913 specialChar(this, bv, InsetSpecialChar::LDOTS);
916 case LFUN_END_OF_SENTENCE:
917 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
920 case LFUN_MENU_SEPARATOR:
921 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
925 bv->beforeChange(this);
927 selection.cursor = cursor;
928 cmd.message(N_("Mark off"));
932 bv->beforeChange(this);
933 selection.mark(true);
935 selection.cursor = cursor;
936 cmd.message(N_("Mark on"));
940 bv->beforeChange(this);
941 if (selection.mark()) {
942 cmd.message(N_("Mark removed"));
944 selection.mark(true);
945 cmd.message(N_("Mark set"));
947 selection.cursor = cursor;
951 case LFUN_UPCASE_WORD:
952 changeCase(LyXText::text_uppercase);
956 case LFUN_LOWCASE_WORD:
957 changeCase(LyXText::text_lowercase);
961 case LFUN_CAPITALIZE_WORD:
962 changeCase(LyXText::text_capitalization);
966 case LFUN_TRANSPOSE_CHARS:
967 recordUndo(bv, Undo::ATOMIC, cursor.par());
973 cmd.message(_("Paste"));
974 replaceSelection(bv->getLyXText());
975 size_t sel_index = 0;
976 string const & arg = cmd.argument;
977 if (isStrUnsignedInt(arg)) {
978 size_t const paste_arg = strToUnsignedInt(arg);
979 #warning FIXME Check if the arg is in the domain of available selections.
980 sel_index = paste_arg;
982 pasteSelection(sel_index);
983 clearSelection(); // bug 393
990 cutSelection(true, true);
991 cmd.message(_("Cut"));
997 cmd.message(_("Copy"));
1000 case LFUN_BEGINNINGBUFSEL:
1002 return UNDISPATCHED;
1004 finishChange(bv, true);
1007 case LFUN_ENDBUFSEL:
1009 return UNDISPATCHED;
1011 finishChange(bv, true);
1015 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1021 istringstream is(cmd.argument);
1024 lyxerr << "SETXY: Could not parse coordinates in '"
1025 << cmd.argument << std::endl;
1027 setCursorFromCoordinates(x, y);
1032 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1034 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1040 case LFUN_GETLAYOUT:
1041 cmd.message(tostr(cursor.par()->layout()));
1045 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1046 << cmd.argument << endl;
1048 // This is not the good solution to the empty argument
1049 // problem, but it will hopefully suffice for 1.2.0.
1050 // The correct solution would be to augument the
1051 // function list/array with information about what
1052 // functions needs arguments and their type.
1053 if (cmd.argument.empty()) {
1054 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1058 // Derive layout number from given argument (string)
1059 // and current buffer's textclass (number)
1060 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1061 bool hasLayout = tclass.hasLayout(cmd.argument);
1062 string layout = cmd.argument;
1064 // If the entry is obsolete, use the new one instead.
1066 string const & obs = tclass[layout]->obsoleted_by();
1072 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1077 bool change_layout = (current_layout != layout);
1079 if (!change_layout && selection.set() &&
1080 selection.start.par() != selection.end.par())
1082 ParagraphList::iterator spit = selection.start.par();
1083 ParagraphList::iterator epit = boost::next(selection.end.par());
1084 while (spit != epit) {
1085 if (spit->layout()->name() != current_layout) {
1086 change_layout = true;
1093 if (change_layout) {
1094 current_layout = layout;
1096 bv->owner()->setLayout(layout);
1103 case LFUN_PASTESELECTION: {
1104 // this was originally a beforeChange(bv->text), i.e
1105 // the outermost LyXText!
1106 bv->beforeChange(this);
1107 string const clip = bv->getClipboard();
1108 if (!clip.empty()) {
1109 if (cmd.argument == "paragraph")
1110 insertStringAsParagraphs(clip);
1112 insertStringAsLines(clip);
1119 case LFUN_GOTOERROR:
1120 gotoInset(InsetOld::ERROR_CODE, false);
1124 gotoInset(InsetOld::NOTE_CODE, false);
1127 case LFUN_REFERENCE_GOTO:
1129 vector<InsetOld::Code> tmp;
1130 tmp.push_back(InsetOld::LABEL_CODE);
1131 tmp.push_back(InsetOld::REF_CODE);
1132 gotoInset(tmp, true);
1137 replaceSelection(bv->getLyXText());
1138 ParagraphList::iterator pit = cursor.par();
1139 lyx::pos_type pos = cursor.pos();
1143 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1146 c = pit->getChar(pos - 1);
1148 LyXLayout_ptr const & style = pit->layout();
1150 BufferParams const & bufparams = bv->buffer()->params();
1151 if (style->pass_thru ||
1152 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1153 !bv->insertInset(new InsetQuotes(c, bufparams)))
1154 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1158 case LFUN_DATE_INSERT: {
1159 replaceSelection(bv->getLyXText());
1160 time_t now_time_t = time(NULL);
1161 struct tm * now_tm = localtime(&now_time_t);
1162 setlocale(LC_TIME, "");
1164 if (!cmd.argument.empty())
1167 arg = lyxrc.date_insert_format;
1169 int const datetmp_len =
1170 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1172 for (int i = 0; i < datetmp_len; i++)
1173 insertChar(datetmp[i]);
1175 selection.cursor = cursor;
1176 moveCursorUpdate(bv, false);
1180 case LFUN_MOUSE_TRIPLE:
1183 if (!isInInset() && bv->theLockingInset())
1185 if (cmd.button() == mouse_button::button1) {
1187 selection.cursor = cursor;
1191 bv->haveSelection(selection.set());
1195 case LFUN_MOUSE_DOUBLE:
1198 if (!isInInset() && bv->theLockingInset())
1200 if (cmd.button() == mouse_button::button1) {
1201 selectWord(lyx::WHOLE_WORD_STRICT);
1203 bv->haveSelection(selection.set());
1207 case LFUN_MOUSE_MOTION:
1209 // Only use motion with button 1
1210 //if (ev.button() != mouse_button::button1)
1216 // Check for inset locking
1217 if (bv->theLockingInset()) {
1218 InsetOld * tli = bv->theLockingInset();
1219 LyXCursor cursor = bv->text->cursor;
1220 LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
1221 int width = tli->width();
1222 int inset_x = font.isVisibleRightToLeft()
1223 ? cursor.x() - width : cursor.x();
1224 int start_x = inset_x + tli->scroll();
1225 FuncRequest cmd1 = cmd;
1226 cmd1.x = cmd.x - start_x;
1227 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1228 tli->localDispatch(cmd1);
1232 // The test for not selection possible is needed, that only motion
1233 // events are used, where the bottom press event was on
1234 // the drawing area too
1235 if (!selection_possible) {
1236 lyxerr[Debug::ACTION]
1237 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1241 RowList::iterator cursorrow = bv->text->cursorRow();
1242 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1244 // sorry for this but I have a strange error that the y value jumps at
1245 // a certain point. This seems like an error in my xforms library or
1246 // in some other local environment, but I would like to leave this here
1247 // for the moment until I can remove this (Jug 20020418)
1248 if (y_before < bv->text->cursor.y())
1249 lyxerr << y_before << ':'
1250 << bv->text->cursor.y() << endl;
1252 // This is to allow jumping over large insets
1253 if (cursorrow == bv->text->cursorRow()) {
1254 if (cmd.y >= bv->workHeight())
1255 bv->text->cursorDown(false);
1257 bv->text->cursorUp(false);
1260 bv->text->setSelection();
1265 // Single-click on work area
1266 case LFUN_MOUSE_PRESS:
1271 // ok ok, this is a hack (for xforms)
1272 // We shouldn't go further down as we really should only do the
1273 // scrolling and be done with this. Otherwise we may open some
1274 // dialogs (Jug 20020424).
1275 if (cmd.button() == mouse_button::button4) {
1276 bv->scroll(-lyxrc.wheel_jump);
1279 if (cmd.button() == mouse_button::button5) {
1280 bv->scroll(lyxrc.wheel_jump);
1286 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1288 // Middle button press pastes if we have a selection
1289 // We do this here as if the selection was inside an inset
1290 // it could get cleared on the unlocking of the inset so
1291 // we have to check this first
1292 bool paste_internally = false;
1293 if (cmd.button() == mouse_button::button2 && selection.set()) {
1294 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1295 paste_internally = true;
1298 int const screen_first = bv->top_y();
1300 if (bv->theLockingInset()) {
1301 // We are in inset locking mode
1303 // Check whether the inset was hit. If not reset mode,
1304 // otherwise give the event to the inset
1305 if (inset_hit == bv->theLockingInset()) {
1306 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1307 bv->theLockingInset()->localDispatch(cmd1);
1310 bv->unlockInset(bv->theLockingInset());
1314 selection_possible = true;
1316 // Clear the selection
1317 bv->text->clearSelection();
1319 bv->updateScrollbar();
1321 // Single left click in math inset?
1322 if (isHighlyEditableInset(inset_hit)) {
1323 // Highly editable inset, like math
1324 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1325 selection_possible = false;
1326 bv->owner()->message(inset->editMessage());
1327 // We just have to lock the inset before calling a PressEvent on it!
1328 if (!bv->lockInset(inset))
1329 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1330 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1331 inset->localDispatch(cmd1);
1334 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1336 // Right click on a footnote flag opens float menu
1337 if (cmd.button() == mouse_button::button3) {
1338 selection_possible = false;
1342 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1343 bv->text->setCursorFromCoordinates(x, y + screen_first);
1345 bv->text->selection.cursor = bv->text->cursor;
1346 bv->text->cursor.x_fix(bv->text->cursor.x());
1348 if (bv->fitCursor())
1349 selection_possible = false;
1351 // Insert primary selection with middle mouse
1352 // if there is a local selection in the current buffer,
1354 if (cmd.button() == mouse_button::button2) {
1355 if (paste_internally)
1356 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1358 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1359 selection_possible = false;
1364 case LFUN_MOUSE_RELEASE:
1366 // do nothing if we used the mouse wheel
1370 if (cmd.button() == mouse_button::button4
1371 || cmd.button() == mouse_button::button5)
1374 // If we hit an inset, we have the inset coordinates in these
1375 // and inset_hit points to the inset. If we do not hit an
1376 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1379 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1381 if (bv->theLockingInset()) {
1382 // We are in inset locking mode.
1384 // LyX does a kind of work-area grabbing for insets.
1385 // Only a ButtonPress FuncRequest outside the inset will
1386 // force a insetUnlock.
1387 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1388 bv->theLockingInset()->localDispatch(cmd1);
1392 selection_possible = false;
1394 if (cmd.button() == mouse_button::button2)
1398 if (cmd.button() == mouse_button::button1)
1399 bv->haveSelection(selection.set());
1402 bv->owner()->view_state_changed();
1403 bv->owner()->updateMenubar();
1404 bv->owner()->updateToolbar();
1406 // Did we hit an editable inset?
1408 selection_possible = false;
1410 // if we reach this point with a selection, it
1411 // must mean we are currently selecting.
1412 // But we don't want to open the inset
1413 // because that is annoying for the user.
1414 // So just pretend we didn't hit it.
1415 // this is OK because a "kosher" ButtonRelease
1416 // will follow a ButtonPress that clears
1418 // Note this also fixes selection drawing
1419 // problems if we end up opening an inset
1420 if (selection.set())
1423 // CHECK fix this proper in 0.13
1424 // well, maybe 13.0 !!!!!!!!!
1426 // Following a ref shouldn't issue
1427 // a push on the undo-stack
1428 // anylonger, now that we have
1429 // keybindings for following
1430 // references and returning from
1431 // references. IMHO though, it
1432 // should be the inset's own business
1433 // to push or not push on the undo
1434 // stack. They don't *have* to
1435 // alter the document...
1437 // ...or maybe the recordUndo()
1438 // below isn't necessary at all anylonger?
1439 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1440 recordUndo(bv, Undo::ATOMIC);
1442 bv->owner()->message(inset_hit->editMessage());
1444 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1445 inset_hit->localDispatch(cmd1);
1451 case LFUN_SELFINSERT: {
1452 if (cmd.argument.empty())
1455 // Automatically delete the currently selected
1456 // text and replace it with what is being
1457 // typed in now. Depends on lyxrc settings
1458 // "auto_region_delete", which defaults to
1461 if (lyxrc.auto_region_delete) {
1462 if (selection.set())
1463 cutSelection(false, false);
1464 bv->haveSelection(false);
1467 bv->beforeChange(this);
1468 LyXFont const old_font = real_current_font;
1470 string::const_iterator cit = cmd.argument.begin();
1471 string::const_iterator end = cmd.argument.end();
1472 for (; cit != end; ++cit)
1473 bv->owner()->getIntl().getTransManager().
1474 TranslateAndInsert(*cit, this);
1476 selection.cursor = cursor;
1477 moveCursorUpdate(bv, false);
1479 // real_current_font.number can change so we need to
1480 // update the minibuffer
1481 if (old_font != real_current_font)
1482 bv->owner()->view_state_changed();
1483 bv->updateScrollbar();
1487 case LFUN_HTMLURL: {
1488 InsetCommandParams p("htmlurl");
1489 string const data = InsetCommandMailer::params2string("url", p);
1490 bv->owner()->getDialogs().show("url", data, 0);
1495 InsetCommandParams p("url");
1496 string const data = InsetCommandMailer::params2string("url", p);
1497 bv->owner()->getDialogs().show("url", data, 0);
1503 case LFUN_INSET_LIST:
1504 case LFUN_INSET_THEOREM:
1505 case LFUN_INSET_CAPTION:
1507 case LFUN_INSERT_NOTE:
1508 case LFUN_INSERT_BRANCH:
1509 case LFUN_INSERT_BIBITEM:
1510 case LFUN_INSET_ERT:
1511 case LFUN_INSET_FLOAT:
1512 case LFUN_INSET_FOOTNOTE:
1513 case LFUN_INSET_MARGINAL:
1514 case LFUN_INSET_MINIPAGE:
1515 case LFUN_INSET_OPTARG:
1516 case LFUN_INSET_WIDE_FLOAT:
1517 case LFUN_INSET_WRAP:
1518 case LFUN_TABULAR_INSERT:
1519 case LFUN_ENVIRONMENT_INSERT:
1520 // Open the inset, and move the current selection
1522 doInsertInset(this, cmd, true, true);
1525 case LFUN_INDEX_INSERT:
1526 // Just open the inset
1527 doInsertInset(this, cmd, true, false);
1530 case LFUN_INDEX_PRINT:
1531 case LFUN_TOC_INSERT:
1534 doInsertInset(this, cmd, false, false);
1538 return UNDISPATCHED;