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"
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(LyXText & text,
104 LyXCursor const & cur, int & x, int & y)
106 lyx::pos_type const pos = cur.pos();
107 ParagraphList::iterator par = text.getPar(cur);
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(cur.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(*this, cur, x, y_tmp);
165 // look at previous position
170 setCursor(cur, cur.par(), cur.pos() - 1, true);
172 inset = checkInset(*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 = cursorPar();
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()
206 setCursor(parOffset(pit), pos, false);
211 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
214 bv()->beforeChange(this);
217 if (same_content && cursor.pos() < cursorPar()->size()
218 && cursorPar()->isInset(cursor.pos())) {
219 InsetOld const * inset = cursorPar()->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() || cursorPar() != ownerParagraphs().begin()) {
227 LyXCursor tmp = cursor;
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 = cursorPar();
288 previousRow(pit, rit);
289 setCursor(cur, parOffset(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 = cursorPar();
346 setCursor(cur, parOffset(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));
395 dispatch_result LyXText::dispatch(FuncRequest const & cmd)
397 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
398 <<"] arg[" << cmd.argument << ']' << "xy[" <<
399 cmd.x << ',' << cmd.y << ']' << endl;
401 BufferView * bv = cmd.view();
403 switch (cmd.action) {
405 case LFUN_APPENDIX: {
406 ParagraphList::iterator pit = cursorPar();
407 bool start = !pit->params().startOfAppendix();
409 // ensure that we have only one start_of_appendix in this document
410 ParagraphList::iterator tmp = ownerParagraphs().begin();
411 ParagraphList::iterator end = ownerParagraphs().end();
413 for (; tmp != end; ++tmp) {
414 if (tmp->params().startOfAppendix()) {
415 recUndo(parOffset(tmp));
416 tmp->params().startOfAppendix(false);
422 recUndo(parOffset(pit));
423 pit->params().startOfAppendix(start);
425 // we can set the refreshing parameters now
427 redoParagraph(cursorPar());
428 setCursor(cursorPar(), cursor.pos());
433 case LFUN_DELETE_WORD_FORWARD:
434 bv->beforeChange(this);
439 case LFUN_DELETE_WORD_BACKWARD:
440 bv->beforeChange(this);
441 deleteWordBackward();
445 case LFUN_DELETE_LINE_FORWARD:
446 bv->beforeChange(this);
452 if (!selection.mark())
453 bv->beforeChange(this);
454 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
457 cursorRightOneWord();
462 if (!selection.mark())
463 bv->beforeChange(this);
464 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
465 cursorRightOneWord();
471 case LFUN_BEGINNINGBUF:
472 if (!selection.mark())
473 bv->beforeChange(this);
479 if (selection.mark())
480 bv->beforeChange(this);
486 if (!selection.set())
487 selection.cursor = cursor;
488 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
492 finishChange(bv, true);
496 if (!selection.set())
497 selection.cursor = cursor;
498 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
502 finishChange(bv, true);
506 if (!selection.set())
507 selection.cursor = cursor;
509 finishChange(bv, true);
513 if (!selection.set())
514 selection.cursor = cursor;
516 finishChange(bv, true);
519 case LFUN_UP_PARAGRAPHSEL:
520 if (!selection.set())
521 selection.cursor = cursor;
523 finishChange(bv, true);
526 case LFUN_DOWN_PARAGRAPHSEL:
527 if (!selection.set())
528 selection.cursor = cursor;
529 cursorDownParagraph();
530 finishChange(bv, true);
534 if (!selection.set())
535 selection.cursor = cursor;
537 finishChange(bv, true);
541 if (!selection.set())
542 selection.cursor = cursor;
544 finishChange(bv, true);
548 if (!selection.set())
549 selection.cursor = cursor;
551 finishChange(bv, true);
555 if (!selection.set())
556 selection.cursor = cursor;
558 finishChange(bv, true);
561 case LFUN_WORDRIGHTSEL:
562 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
565 cursorRightOneWord();
566 finishChange(bv, true);
569 case LFUN_WORDLEFTSEL:
570 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
571 cursorRightOneWord();
574 finishChange(bv, true);
578 LyXCursor cur1 = cursor;
580 ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
581 setCursor(cur1.par(), cur1.pos());
582 bv->beforeChange(this);
583 setCursor(cur2.par(), cur2.pos());
584 finishChange(bv, true);
589 bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
590 if (!selection.mark())
591 bv->beforeChange(this);
594 if (cursor.pos() < cursorPar()->size()
595 && cursorPar()->isInset(cursor.pos())
596 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
597 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
598 cmd.message(tmpinset->editMessage());
599 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
600 tmpinset->localDispatch(cmd1);
610 // This is soooo ugly. Isn`t it possible to make
612 bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
613 if (!selection.mark())
614 bv->beforeChange(this);
615 LyXCursor const cur = cursor;
618 if ((is_rtl || cur != cursor) && // only if really moved!
619 cursor.pos() < cursorPar()->size() &&
620 cursorPar()->isInset(cursor.pos()) &&
621 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
622 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
623 cmd.message(tmpinset->editMessage());
624 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
625 tmpinset->localDispatch(cmd1);
635 if (!selection.mark())
636 bv->beforeChange(this);
642 if (!selection.mark())
643 bv->beforeChange(this);
648 case LFUN_UP_PARAGRAPH:
649 if (!selection.mark())
650 bv->beforeChange(this);
655 case LFUN_DOWN_PARAGRAPH:
656 if (!selection.mark())
657 bv->beforeChange(this);
658 cursorDownParagraph();
659 finishChange(bv, false);
663 if (!selection.mark())
664 bv->beforeChange(this);
666 finishChange(bv, false);
670 if (!selection.mark())
671 bv->beforeChange(this);
673 finishChange(bv, false);
677 if (!selection.mark())
678 bv->beforeChange(this);
680 finishChange(bv, false);
684 if (!selection.mark())
685 bv->beforeChange(this);
687 finishChange(bv, false);
690 case LFUN_BREAKLINE: {
691 lyx::pos_type body = cursorPar()->beginningOfBody();
693 // Not allowed by LaTeX (labels or empty par)
694 if (cursor.pos() <= body)
697 replaceSelection(bv->getLyXText());
698 insertInset(new InsetNewline);
699 setCursor(cursorPar(), cursor.pos());
700 moveCursorUpdate(bv, false);
705 if (!selection.set()) {
707 selection.cursor = cursor;
708 // It is possible to make it a lot faster still
709 // just comment out the line below...
711 cutSelection(true, false);
713 moveCursorUpdate(bv, false);
714 bv->owner()->view_state_changed();
717 case LFUN_DELETE_SKIP:
718 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
719 if (!selection.set()) {
720 if (cursor.pos() == cursorPar()->size()) {
722 ParagraphParameters & params = cursorPar()->params();
723 if (cursor.pos() == 0
724 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
728 params.pagebreakTop(),
729 params.pagebreakBottom(),
730 VSpace(VSpace::NONE),
731 params.spaceBottom(),
734 params.labelWidthString(), 0);
739 selection.cursor = cursor;
743 selection.cursor = cursor;
746 cutSelection(true, false);
753 if (!selection.set()) {
754 if (bv->owner()->getIntl().getTransManager().backspace()) {
756 selection.cursor = cursor;
757 // It is possible to make it a lot faster still
758 // just comment out the line below...
761 cutSelection(true, false);
763 bv->owner()->view_state_changed();
768 case LFUN_BACKSPACE_SKIP:
769 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
770 if (!selection.set()) {
771 ParagraphParameters & params = cursorPar()->params();
772 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
776 params.pagebreakTop(),
777 params.pagebreakBottom(),
778 VSpace(VSpace::NONE),
779 params.spaceBottom(),
782 params.labelWidthString(), 0);
784 LyXCursor cur = cursor;
786 selection.cursor = cur;
789 cutSelection(true, false);
794 case LFUN_BREAKPARAGRAPH:
795 replaceSelection(bv->getLyXText());
796 breakParagraph(bv->buffer()->paragraphs(), 0);
798 selection.cursor = cursor;
800 bv->owner()->view_state_changed();
803 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
804 replaceSelection(bv->getLyXText());
805 breakParagraph(bv->buffer()->paragraphs(), 1);
807 selection.cursor = cursor;
809 bv->owner()->view_state_changed();
812 case LFUN_BREAKPARAGRAPH_SKIP: {
813 // When at the beginning of a paragraph, remove
814 // indentation and add a "defskip" at the top.
815 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
816 LyXCursor cur = cursor;
817 replaceSelection(bv->getLyXText());
818 if (cur.pos() == 0) {
819 ParagraphParameters & params = getPar(cur)->params();
820 if (params.spaceTop() == VSpace(VSpace::NONE)) {
824 params.pagebreakTop(),
825 params.pagebreakBottom(),
826 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
829 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 = cursorPar();
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 (cursorPar()->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 recUndo(cursor.par());
973 cmd.message(_("Paste"));
974 replaceSelection(bv->getLyXText());
975 #warning FIXME Check if the arg is in the domain of available selections.
976 if (isStrUnsignedInt(cmd.argument))
977 pasteSelection(strToUnsignedInt(cmd.argument));
980 clearSelection(); // bug 393
987 cutSelection(true, true);
988 cmd.message(_("Cut"));
994 cmd.message(_("Copy"));
997 case LFUN_BEGINNINGBUFSEL:
1001 finishChange(bv, true);
1004 case LFUN_ENDBUFSEL:
1006 return UNDISPATCHED;
1008 finishChange(bv, true);
1012 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1018 istringstream is(cmd.argument);
1021 lyxerr << "SETXY: Could not parse coordinates in '"
1022 << cmd.argument << std::endl;
1024 setCursorFromCoordinates(x, y);
1029 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1031 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1037 case LFUN_GETLAYOUT:
1038 cmd.message(tostr(cursorPar()->layout()));
1042 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1043 << cmd.argument << endl;
1045 // This is not the good solution to the empty argument
1046 // problem, but it will hopefully suffice for 1.2.0.
1047 // The correct solution would be to augument the
1048 // function list/array with information about what
1049 // functions needs arguments and their type.
1050 if (cmd.argument.empty()) {
1051 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1055 // Derive layout number from given argument (string)
1056 // and current buffer's textclass (number)
1057 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1058 bool hasLayout = tclass.hasLayout(cmd.argument);
1059 string layout = cmd.argument;
1061 // If the entry is obsolete, use the new one instead.
1063 string const & obs = tclass[layout]->obsoleted_by();
1069 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1074 bool change_layout = (current_layout != layout);
1076 if (!change_layout && selection.set() &&
1077 selection.start.par() != selection.end.par())
1079 ParagraphList::iterator spit = getPar(selection.start);
1080 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1081 while (spit != epit) {
1082 if (spit->layout()->name() != current_layout) {
1083 change_layout = true;
1090 if (change_layout) {
1091 current_layout = layout;
1093 bv->owner()->setLayout(layout);
1100 case LFUN_PASTESELECTION: {
1101 // this was originally a beforeChange(bv->text), i.e
1102 // the outermost LyXText!
1103 bv->beforeChange(this);
1104 string const clip = bv->getClipboard();
1105 if (!clip.empty()) {
1106 if (cmd.argument == "paragraph")
1107 insertStringAsParagraphs(clip);
1109 insertStringAsLines(clip);
1116 case LFUN_GOTOERROR:
1117 gotoInset(InsetOld::ERROR_CODE, false);
1121 gotoInset(InsetOld::NOTE_CODE, false);
1124 case LFUN_REFERENCE_GOTO:
1126 vector<InsetOld::Code> tmp;
1127 tmp.push_back(InsetOld::LABEL_CODE);
1128 tmp.push_back(InsetOld::REF_CODE);
1129 gotoInset(tmp, true);
1134 replaceSelection(bv->getLyXText());
1135 ParagraphList::iterator pit = cursorPar();
1136 lyx::pos_type pos = cursor.pos();
1140 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1143 c = pit->getChar(pos - 1);
1145 LyXLayout_ptr const & style = pit->layout();
1147 BufferParams const & bufparams = bv->buffer()->params();
1148 if (style->pass_thru ||
1149 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1150 !bv->insertInset(new InsetQuotes(c, bufparams)))
1151 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1155 case LFUN_DATE_INSERT: {
1156 replaceSelection(bv->getLyXText());
1157 time_t now_time_t = time(NULL);
1158 struct tm * now_tm = localtime(&now_time_t);
1159 setlocale(LC_TIME, "");
1161 if (!cmd.argument.empty())
1164 arg = lyxrc.date_insert_format;
1166 int const datetmp_len =
1167 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1169 for (int i = 0; i < datetmp_len; i++)
1170 insertChar(datetmp[i]);
1172 selection.cursor = cursor;
1173 moveCursorUpdate(bv, false);
1177 case LFUN_MOUSE_TRIPLE:
1180 if (!isInInset() && bv->theLockingInset())
1182 if (cmd.button() == mouse_button::button1) {
1184 selection.cursor = cursor;
1188 bv->haveSelection(selection.set());
1192 case LFUN_MOUSE_DOUBLE:
1195 if (!isInInset() && bv->theLockingInset())
1197 if (cmd.button() == mouse_button::button1) {
1198 selectWord(lyx::WHOLE_WORD_STRICT);
1200 bv->haveSelection(selection.set());
1204 case LFUN_MOUSE_MOTION:
1206 // Only use motion with button 1
1207 //if (ev.button() != mouse_button::button1)
1213 // Check for inset locking
1214 if (bv->theLockingInset()) {
1215 InsetOld * tli = bv->theLockingInset();
1216 LyXCursor cursor = bv->text->cursor;
1217 LyXFont font = bv->text->getFont(cursorPar(), cursor.pos());
1218 int width = tli->width();
1219 int inset_x = font.isVisibleRightToLeft()
1220 ? cursor.x() - width : cursor.x();
1221 int start_x = inset_x + tli->scroll();
1222 FuncRequest cmd1 = cmd;
1223 cmd1.x = cmd.x - start_x;
1224 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1225 tli->localDispatch(cmd1);
1229 // The test for not selection possible is needed, that only motion
1230 // events are used, where the bottom press event was on
1231 // the drawing area too
1232 if (!selection_possible) {
1233 lyxerr[Debug::ACTION]
1234 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1238 RowList::iterator cursorrow = bv->text->cursorRow();
1239 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1241 // sorry for this but I have a strange error that the y value jumps at
1242 // a certain point. This seems like an error in my xforms library or
1243 // in some other local environment, but I would like to leave this here
1244 // for the moment until I can remove this (Jug 20020418)
1245 if (y_before < bv->text->cursor.y())
1246 lyxerr << y_before << ':'
1247 << bv->text->cursor.y() << endl;
1249 // This is to allow jumping over large insets
1250 if (cursorrow == bv->text->cursorRow()) {
1251 if (cmd.y >= bv->workHeight())
1252 bv->text->cursorDown(false);
1254 bv->text->cursorUp(false);
1257 bv->text->setSelection();
1262 // Single-click on work area
1263 case LFUN_MOUSE_PRESS:
1268 // ok ok, this is a hack (for xforms)
1269 // We shouldn't go further down as we really should only do the
1270 // scrolling and be done with this. Otherwise we may open some
1271 // dialogs (Jug 20020424).
1272 if (cmd.button() == mouse_button::button4) {
1273 bv->scroll(-lyxrc.wheel_jump);
1276 if (cmd.button() == mouse_button::button5) {
1277 bv->scroll(lyxrc.wheel_jump);
1283 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1285 // Middle button press pastes if we have a selection
1286 // We do this here as if the selection was inside an inset
1287 // it could get cleared on the unlocking of the inset so
1288 // we have to check this first
1289 bool paste_internally = false;
1290 if (cmd.button() == mouse_button::button2 && selection.set()) {
1291 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1292 paste_internally = true;
1295 int const screen_first = bv->top_y();
1297 if (bv->theLockingInset()) {
1298 // We are in inset locking mode
1300 // Check whether the inset was hit. If not reset mode,
1301 // otherwise give the event to the inset
1302 if (inset_hit == bv->theLockingInset()) {
1303 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1304 bv->theLockingInset()->localDispatch(cmd1);
1307 bv->unlockInset(bv->theLockingInset());
1311 selection_possible = true;
1313 // Clear the selection
1314 bv->text->clearSelection();
1316 bv->updateScrollbar();
1318 // Single left click in math inset?
1319 if (isHighlyEditableInset(inset_hit)) {
1320 // Highly editable inset, like math
1321 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1322 selection_possible = false;
1323 bv->owner()->message(inset->editMessage());
1324 // We just have to lock the inset before calling a PressEvent on it!
1325 if (!bv->lockInset(inset))
1326 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1327 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1328 inset->localDispatch(cmd1);
1331 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1333 // Right click on a footnote flag opens float menu
1334 if (cmd.button() == mouse_button::button3) {
1335 selection_possible = false;
1339 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1340 bv->text->setCursorFromCoordinates(x, y + screen_first);
1342 bv->text->selection.cursor = bv->text->cursor;
1343 bv->text->cursor.x_fix(bv->text->cursor.x());
1345 if (bv->fitCursor())
1346 selection_possible = false;
1348 // Insert primary selection with middle mouse
1349 // if there is a local selection in the current buffer,
1351 if (cmd.button() == mouse_button::button2) {
1352 if (paste_internally)
1353 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1355 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1356 selection_possible = false;
1361 case LFUN_MOUSE_RELEASE:
1363 // do nothing if we used the mouse wheel
1367 if (cmd.button() == mouse_button::button4
1368 || cmd.button() == mouse_button::button5)
1371 // If we hit an inset, we have the inset coordinates in these
1372 // and inset_hit points to the inset. If we do not hit an
1373 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1376 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1378 if (bv->theLockingInset()) {
1379 // We are in inset locking mode.
1381 // LyX does a kind of work-area grabbing for insets.
1382 // Only a ButtonPress FuncRequest outside the inset will
1383 // force a insetUnlock.
1384 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1385 bv->theLockingInset()->localDispatch(cmd1);
1389 selection_possible = false;
1391 if (cmd.button() == mouse_button::button2)
1395 if (cmd.button() == mouse_button::button1)
1396 bv->haveSelection(selection.set());
1399 bv->owner()->view_state_changed();
1400 bv->owner()->updateMenubar();
1401 bv->owner()->updateToolbar();
1403 // Did we hit an editable inset?
1405 selection_possible = false;
1407 // if we reach this point with a selection, it
1408 // must mean we are currently selecting.
1409 // But we don't want to open the inset
1410 // because that is annoying for the user.
1411 // So just pretend we didn't hit it.
1412 // this is OK because a "kosher" ButtonRelease
1413 // will follow a ButtonPress that clears
1415 // Note this also fixes selection drawing
1416 // problems if we end up opening an inset
1417 if (selection.set())
1420 // CHECK fix this proper in 0.13
1421 // well, maybe 13.0 !!!!!!!!!
1423 // Following a ref shouldn't issue
1424 // a push on the undo-stack
1425 // anylonger, now that we have
1426 // keybindings for following
1427 // references and returning from
1428 // references. IMHO though, it
1429 // should be the inset's own business
1430 // to push or not push on the undo
1431 // stack. They don't *have* to
1432 // alter the document...
1434 // ...or maybe the recordUndo()
1435 // below isn't necessary at all anylonger?
1436 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1437 recUndo(cursor.par());
1439 bv->owner()->message(inset_hit->editMessage());
1441 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1442 inset_hit->localDispatch(cmd1);
1448 case LFUN_SELFINSERT: {
1449 if (cmd.argument.empty())
1452 // Automatically delete the currently selected
1453 // text and replace it with what is being
1454 // typed in now. Depends on lyxrc settings
1455 // "auto_region_delete", which defaults to
1458 if (lyxrc.auto_region_delete) {
1459 if (selection.set())
1460 cutSelection(false, false);
1461 bv->haveSelection(false);
1464 bv->beforeChange(this);
1465 LyXFont const old_font = real_current_font;
1467 string::const_iterator cit = cmd.argument.begin();
1468 string::const_iterator end = cmd.argument.end();
1469 for (; cit != end; ++cit)
1470 bv->owner()->getIntl().getTransManager().
1471 TranslateAndInsert(*cit, this);
1473 selection.cursor = cursor;
1474 moveCursorUpdate(bv, false);
1476 // real_current_font.number can change so we need to
1477 // update the minibuffer
1478 if (old_font != real_current_font)
1479 bv->owner()->view_state_changed();
1480 bv->updateScrollbar();
1484 case LFUN_HTMLURL: {
1485 InsetCommandParams p("htmlurl");
1486 string const data = InsetCommandMailer::params2string("url", p);
1487 bv->owner()->getDialogs().show("url", data, 0);
1492 InsetCommandParams p("url");
1493 string const data = InsetCommandMailer::params2string("url", p);
1494 bv->owner()->getDialogs().show("url", data, 0);
1500 case LFUN_INSET_LIST:
1501 case LFUN_INSET_THEOREM:
1502 case LFUN_INSET_CAPTION:
1504 case LFUN_INSERT_NOTE:
1505 case LFUN_INSERT_BOX:
1506 case LFUN_INSERT_BRANCH:
1507 case LFUN_INSERT_BIBITEM:
1508 case LFUN_INSET_ERT:
1509 case LFUN_INSET_FLOAT:
1510 case LFUN_INSET_FOOTNOTE:
1511 case LFUN_INSET_MARGINAL:
1512 case LFUN_INSET_MINIPAGE:
1513 case LFUN_INSET_OPTARG:
1514 case LFUN_INSET_WIDE_FLOAT:
1515 case LFUN_INSET_WRAP:
1516 case LFUN_TABULAR_INSERT:
1517 case LFUN_ENVIRONMENT_INSERT:
1518 // Open the inset, and move the current selection
1520 doInsertInset(this, cmd, true, true);
1523 case LFUN_INDEX_INSERT:
1524 // Just open the inset
1525 doInsertInset(this, cmd, true, false);
1528 case LFUN_INDEX_PRINT:
1529 case LFUN_TOC_INSERT:
1532 doInsertInset(this, cmd, false, false);
1535 case LFUN_DEPTH_MIN:
1536 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1541 case LFUN_DEPTH_PLUS:
1543 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1549 return UNDISPATCHED;