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()->top_y();
253 ParagraphList::iterator cpit = cursorPar();
254 RowList::iterator crit = cpit->getRow(cursor.pos());
256 if (isFirstRow(cpit, *crit)) {
258 bv()->updateScrollbar();
262 setCursorFromCoordinates(cursor.x_fix(), y);
265 if (crit == 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.
272 int new_y = + crit->height() - bv()->workHeight() + 1;
275 new_y += bv()->text->cursor.y()
276 + bv()->theLockingInset()->insetInInsetY() + y;
278 new_y += cursor.y() - crit->baseline();
281 previousRow(cpit, crit);
283 setCursor(cur, parOffset(cpit), crit->pos(), false);
284 if (cur.y() > bv()->top_y())
286 bv()->updateScrollbar();
290 void LyXText::cursorNext()
292 int topy = bv()->top_y();
294 ParagraphList::iterator cpit = cursorPar();
295 RowList::iterator crit = cpit->getRow(cursor.pos());
297 if (isLastRow(cpit, *crit)) {
298 int y = cursor.y() - crit->baseline() + crit->height();
299 if (y > topy + bv()->workHeight())
300 bv()->updateScrollbar();
304 int y = topy + bv()->workHeight();
305 if (inset_owner && !topy) {
306 y -= (bv()->text->cursor.y()
308 + bv()->theLockingInset()->insetInInsetY());
311 ParagraphList::iterator dummypit;
312 Row const & rr = *getRowNearY(y, dummypit);
313 y = dummypit->y + rr.y_offset();
315 setCursorFromCoordinates(cursor.x_fix(), y);
316 // + bv->workHeight());
320 if (crit == bv()->text->cursorRow()) {
321 // we have a row which is taller than the workarea. The
322 // simplest solution is to move to the next row instead.
325 // This is what we used to do, so we wouldn't skip right past
326 // tall rows, but it's not working right now.
328 new_y = bv->top_y() + bv->workHeight();
333 new_y = bv()->text->cursor.y()
334 + bv()->theLockingInset()->insetInInsetY()
335 + y - crit->baseline();
337 new_y = cursor.y() - crit->baseline();
343 setCursor(cur, parOffset(cpit), crit->pos(), false);
344 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
346 bv()->updateScrollbar();
352 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
355 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
356 replaceSelection(lt);
357 if (!bv->insertInset(new_inset))
360 bv->updateInset(new_inset);
364 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
365 bool edit, bool pastesel)
367 InsetOld * inset = createInset(cmd);
368 BufferView * bv = cmd.view();
372 if (lt->selection.set()) {
373 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
376 if (bv->insertInset(inset)) {
378 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
379 inset->dispatch(cmd);
381 if (gotsel && pastesel)
382 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
392 dispatch_result LyXText::dispatch(FuncRequest const & cmd)
394 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
395 <<"] arg[" << cmd.argument << ']' << "xy[" <<
396 cmd.x << ',' << cmd.y << ']' << endl;
398 BufferView * bv = cmd.view();
400 switch (cmd.action) {
402 case LFUN_APPENDIX: {
403 ParagraphList::iterator pit = cursorPar();
404 bool start = !pit->params().startOfAppendix();
406 // ensure that we have only one start_of_appendix in this document
407 ParagraphList::iterator tmp = ownerParagraphs().begin();
408 ParagraphList::iterator end = ownerParagraphs().end();
410 for (; tmp != end; ++tmp) {
411 if (tmp->params().startOfAppendix()) {
412 recUndo(parOffset(tmp));
413 tmp->params().startOfAppendix(false);
419 recUndo(parOffset(pit));
420 pit->params().startOfAppendix(start);
422 // we can set the refreshing parameters now
424 redoParagraph(cursorPar());
425 setCursor(cursorPar(), cursor.pos());
430 case LFUN_DELETE_WORD_FORWARD:
431 bv->beforeChange(this);
436 case LFUN_DELETE_WORD_BACKWARD:
437 bv->beforeChange(this);
438 deleteWordBackward();
442 case LFUN_DELETE_LINE_FORWARD:
443 bv->beforeChange(this);
449 if (!selection.mark())
450 bv->beforeChange(this);
451 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
454 cursorRightOneWord();
459 if (!selection.mark())
460 bv->beforeChange(this);
461 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
462 cursorRightOneWord();
468 case LFUN_BEGINNINGBUF:
469 if (!selection.mark())
470 bv->beforeChange(this);
476 if (selection.mark())
477 bv->beforeChange(this);
483 if (!selection.set())
484 selection.cursor = cursor;
485 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
489 finishChange(bv, true);
493 if (!selection.set())
494 selection.cursor = cursor;
495 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
499 finishChange(bv, true);
503 if (!selection.set())
504 selection.cursor = cursor;
506 finishChange(bv, true);
510 if (!selection.set())
511 selection.cursor = cursor;
513 finishChange(bv, true);
516 case LFUN_UP_PARAGRAPHSEL:
517 if (!selection.set())
518 selection.cursor = cursor;
520 finishChange(bv, true);
523 case LFUN_DOWN_PARAGRAPHSEL:
524 if (!selection.set())
525 selection.cursor = cursor;
526 cursorDownParagraph();
527 finishChange(bv, true);
531 if (!selection.set())
532 selection.cursor = cursor;
534 finishChange(bv, true);
538 if (!selection.set())
539 selection.cursor = cursor;
541 finishChange(bv, true);
545 if (!selection.set())
546 selection.cursor = cursor;
548 finishChange(bv, true);
552 if (!selection.set())
553 selection.cursor = cursor;
555 finishChange(bv, true);
558 case LFUN_WORDRIGHTSEL:
559 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
562 cursorRightOneWord();
563 finishChange(bv, true);
566 case LFUN_WORDLEFTSEL:
567 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
568 cursorRightOneWord();
571 finishChange(bv, true);
575 LyXCursor cur1 = cursor;
577 ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
578 setCursor(cur1.par(), cur1.pos());
579 bv->beforeChange(this);
580 setCursor(cur2.par(), cur2.pos());
581 finishChange(bv, true);
586 bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
587 if (!selection.mark())
588 bv->beforeChange(this);
591 if (cursor.pos() < cursorPar()->size()
592 && cursorPar()->isInset(cursor.pos())
593 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
594 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
595 cmd.message(tmpinset->editMessage());
596 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
597 tmpinset->dispatch(cmd1);
607 // This is soooo ugly. Isn`t it possible to make
609 bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
610 if (!selection.mark())
611 bv->beforeChange(this);
612 LyXCursor const cur = cursor;
615 if ((is_rtl || cur != cursor) && // only if really moved!
616 cursor.pos() < cursorPar()->size() &&
617 cursorPar()->isInset(cursor.pos()) &&
618 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
619 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
620 cmd.message(tmpinset->editMessage());
621 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
622 tmpinset->dispatch(cmd1);
632 if (!selection.mark())
633 bv->beforeChange(this);
639 if (!selection.mark())
640 bv->beforeChange(this);
645 case LFUN_UP_PARAGRAPH:
646 if (!selection.mark())
647 bv->beforeChange(this);
652 case LFUN_DOWN_PARAGRAPH:
653 if (!selection.mark())
654 bv->beforeChange(this);
655 cursorDownParagraph();
656 finishChange(bv, false);
660 if (!selection.mark())
661 bv->beforeChange(this);
663 finishChange(bv, false);
667 if (!selection.mark())
668 bv->beforeChange(this);
670 finishChange(bv, false);
674 if (!selection.mark())
675 bv->beforeChange(this);
677 finishChange(bv, false);
681 if (!selection.mark())
682 bv->beforeChange(this);
684 finishChange(bv, false);
687 case LFUN_BREAKLINE: {
688 lyx::pos_type body = cursorPar()->beginningOfBody();
690 // Not allowed by LaTeX (labels or empty par)
691 if (cursor.pos() <= body)
694 replaceSelection(bv->getLyXText());
695 insertInset(new InsetNewline);
696 setCursor(cursorPar(), cursor.pos());
697 moveCursorUpdate(bv, false);
702 if (!selection.set()) {
704 selection.cursor = cursor;
705 // It is possible to make it a lot faster still
706 // just comment out the line below...
708 cutSelection(true, false);
710 moveCursorUpdate(bv, false);
711 bv->owner()->view_state_changed();
714 case LFUN_DELETE_SKIP:
715 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
716 if (!selection.set()) {
717 if (cursor.pos() == cursorPar()->size()) {
719 ParagraphParameters & params = cursorPar()->params();
720 if (cursor.pos() == 0
721 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
725 params.pagebreakTop(),
726 params.pagebreakBottom(),
727 VSpace(VSpace::NONE),
728 params.spaceBottom(),
731 params.labelWidthString(), 0);
736 selection.cursor = cursor;
740 selection.cursor = cursor;
743 cutSelection(true, false);
750 if (!selection.set()) {
751 if (bv->owner()->getIntl().getTransManager().backspace()) {
753 selection.cursor = cursor;
754 // It is possible to make it a lot faster still
755 // just comment out the line below...
758 cutSelection(true, false);
760 bv->owner()->view_state_changed();
765 case LFUN_BACKSPACE_SKIP:
766 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
767 if (!selection.set()) {
768 ParagraphParameters & params = cursorPar()->params();
769 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
773 params.pagebreakTop(),
774 params.pagebreakBottom(),
775 VSpace(VSpace::NONE),
776 params.spaceBottom(),
779 params.labelWidthString(), 0);
781 LyXCursor cur = cursor;
783 selection.cursor = cur;
786 cutSelection(true, false);
791 case LFUN_BREAKPARAGRAPH:
792 replaceSelection(bv->getLyXText());
793 breakParagraph(bv->buffer()->paragraphs(), 0);
795 selection.cursor = cursor;
797 bv->owner()->view_state_changed();
800 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
801 replaceSelection(bv->getLyXText());
802 breakParagraph(bv->buffer()->paragraphs(), 1);
804 selection.cursor = cursor;
806 bv->owner()->view_state_changed();
809 case LFUN_BREAKPARAGRAPH_SKIP: {
810 // When at the beginning of a paragraph, remove
811 // indentation and add a "defskip" at the top.
812 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
813 LyXCursor cur = cursor;
814 replaceSelection(bv->getLyXText());
815 if (cur.pos() == 0) {
816 ParagraphParameters & params = getPar(cur)->params();
817 if (params.spaceTop() == VSpace(VSpace::NONE)) {
821 params.pagebreakTop(),
822 params.pagebreakBottom(),
823 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
826 params.labelWidthString(), 1);
830 breakParagraph(bv->buffer()->paragraphs(), 0);
833 selection.cursor = cur;
835 bv->owner()->view_state_changed();
839 case LFUN_PARAGRAPH_SPACING: {
840 ParagraphList::iterator pit = cursorPar();
841 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
842 float cur_value = 1.0;
843 if (cur_spacing == Spacing::Other)
844 cur_value = pit->params().spacing().getValue();
846 istringstream is(cmd.argument);
849 Spacing::Space new_spacing = cur_spacing;
850 float new_value = cur_value;
852 lyxerr << "Missing argument to `paragraph-spacing'"
854 } else if (tmp == "single") {
855 new_spacing = Spacing::Single;
856 } else if (tmp == "onehalf") {
857 new_spacing = Spacing::Onehalf;
858 } else if (tmp == "double") {
859 new_spacing = Spacing::Double;
860 } else if (tmp == "other") {
861 new_spacing = Spacing::Other;
864 lyxerr << "new_value = " << tmpval << endl;
867 } else if (tmp == "default") {
868 new_spacing = Spacing::Default;
870 lyxerr << _("Unknown spacing argument: ")
871 << cmd.argument << endl;
873 if (cur_spacing != new_spacing || cur_value != new_value) {
874 pit->params().spacing(Spacing(new_spacing, new_value));
881 case LFUN_INSET_SETTINGS:
882 BOOST_ASSERT(bv->theLockingInset());
883 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
886 case LFUN_INSET_TOGGLE:
887 bv->beforeChange(this);
893 case LFUN_SPACE_INSERT:
894 if (cursorPar()->layout()->free_spacing)
897 doInsertInset(this, cmd, false, false);
898 moveCursorUpdate(bv, false);
901 case LFUN_HYPHENATION:
902 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
905 case LFUN_LIGATURE_BREAK:
906 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
910 specialChar(this, bv, InsetSpecialChar::LDOTS);
913 case LFUN_END_OF_SENTENCE:
914 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
917 case LFUN_MENU_SEPARATOR:
918 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
922 bv->beforeChange(this);
924 selection.cursor = cursor;
925 cmd.message(N_("Mark off"));
929 bv->beforeChange(this);
930 selection.mark(true);
932 selection.cursor = cursor;
933 cmd.message(N_("Mark on"));
937 bv->beforeChange(this);
938 if (selection.mark()) {
939 cmd.message(N_("Mark removed"));
941 selection.mark(true);
942 cmd.message(N_("Mark set"));
944 selection.cursor = cursor;
948 case LFUN_UPCASE_WORD:
949 changeCase(LyXText::text_uppercase);
953 case LFUN_LOWCASE_WORD:
954 changeCase(LyXText::text_lowercase);
958 case LFUN_CAPITALIZE_WORD:
959 changeCase(LyXText::text_capitalization);
963 case LFUN_TRANSPOSE_CHARS:
964 recUndo(cursor.par());
970 cmd.message(_("Paste"));
971 replaceSelection(bv->getLyXText());
972 #warning FIXME Check if the arg is in the domain of available selections.
973 if (isStrUnsignedInt(cmd.argument))
974 pasteSelection(strToUnsignedInt(cmd.argument));
977 clearSelection(); // bug 393
984 cutSelection(true, true);
985 cmd.message(_("Cut"));
991 cmd.message(_("Copy"));
994 case LFUN_BEGINNINGBUFSEL:
998 finishChange(bv, true);
1001 case LFUN_ENDBUFSEL:
1003 return UNDISPATCHED;
1005 finishChange(bv, true);
1009 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1015 istringstream is(cmd.argument);
1018 lyxerr << "SETXY: Could not parse coordinates in '"
1019 << cmd.argument << std::endl;
1021 setCursorFromCoordinates(x, y);
1026 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1028 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1034 case LFUN_GETLAYOUT:
1035 cmd.message(tostr(cursorPar()->layout()));
1039 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1040 << cmd.argument << endl;
1042 // This is not the good solution to the empty argument
1043 // problem, but it will hopefully suffice for 1.2.0.
1044 // The correct solution would be to augument the
1045 // function list/array with information about what
1046 // functions needs arguments and their type.
1047 if (cmd.argument.empty()) {
1048 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1052 // Derive layout number from given argument (string)
1053 // and current buffer's textclass (number)
1054 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1055 bool hasLayout = tclass.hasLayout(cmd.argument);
1056 string layout = cmd.argument;
1058 // If the entry is obsolete, use the new one instead.
1060 string const & obs = tclass[layout]->obsoleted_by();
1066 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1071 bool change_layout = (current_layout != layout);
1073 if (!change_layout && selection.set() &&
1074 selection.start.par() != selection.end.par())
1076 ParagraphList::iterator spit = getPar(selection.start);
1077 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1078 while (spit != epit) {
1079 if (spit->layout()->name() != current_layout) {
1080 change_layout = true;
1087 if (change_layout) {
1088 current_layout = layout;
1090 bv->owner()->setLayout(layout);
1097 case LFUN_PASTESELECTION: {
1098 // this was originally a beforeChange(bv->text), i.e
1099 // the outermost LyXText!
1100 bv->beforeChange(this);
1101 string const clip = bv->getClipboard();
1102 if (!clip.empty()) {
1103 if (cmd.argument == "paragraph")
1104 insertStringAsParagraphs(clip);
1106 insertStringAsLines(clip);
1113 case LFUN_GOTOERROR:
1114 gotoInset(InsetOld::ERROR_CODE, false);
1118 gotoInset(InsetOld::NOTE_CODE, false);
1121 case LFUN_REFERENCE_GOTO:
1123 vector<InsetOld::Code> tmp;
1124 tmp.push_back(InsetOld::LABEL_CODE);
1125 tmp.push_back(InsetOld::REF_CODE);
1126 gotoInset(tmp, true);
1131 replaceSelection(bv->getLyXText());
1132 ParagraphList::iterator pit = cursorPar();
1133 lyx::pos_type pos = cursor.pos();
1137 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1140 c = pit->getChar(pos - 1);
1142 LyXLayout_ptr const & style = pit->layout();
1144 BufferParams const & bufparams = bv->buffer()->params();
1145 if (style->pass_thru ||
1146 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1147 !bv->insertInset(new InsetQuotes(c, bufparams)))
1148 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1152 case LFUN_DATE_INSERT: {
1153 replaceSelection(bv->getLyXText());
1154 time_t now_time_t = time(NULL);
1155 struct tm * now_tm = localtime(&now_time_t);
1156 setlocale(LC_TIME, "");
1158 if (!cmd.argument.empty())
1161 arg = lyxrc.date_insert_format;
1163 int const datetmp_len =
1164 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1166 for (int i = 0; i < datetmp_len; i++)
1167 insertChar(datetmp[i]);
1169 selection.cursor = cursor;
1170 moveCursorUpdate(bv, false);
1174 case LFUN_MOUSE_TRIPLE:
1177 if (!isInInset() && bv->theLockingInset())
1179 if (cmd.button() == mouse_button::button1) {
1181 selection.cursor = cursor;
1185 bv->haveSelection(selection.set());
1189 case LFUN_MOUSE_DOUBLE:
1192 if (!isInInset() && bv->theLockingInset())
1194 if (cmd.button() == mouse_button::button1) {
1195 selectWord(lyx::WHOLE_WORD_STRICT);
1197 bv->haveSelection(selection.set());
1201 case LFUN_MOUSE_MOTION:
1203 // Only use motion with button 1
1204 //if (ev.button() != mouse_button::button1)
1210 // Check for inset locking
1211 if (bv->theLockingInset()) {
1212 InsetOld * tli = bv->theLockingInset();
1213 LyXCursor cursor = bv->text->cursor;
1214 LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1215 int width = tli->width();
1216 int inset_x = font.isVisibleRightToLeft()
1217 ? cursor.x() - width : cursor.x();
1218 int start_x = inset_x + tli->scroll();
1219 FuncRequest cmd1 = cmd;
1220 cmd1.x = cmd.x - start_x;
1221 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1222 tli->dispatch(cmd1);
1226 // The test for not selection possible is needed, that only motion
1227 // events are used, where the bottom press event was on
1228 // the drawing area too
1229 if (!selection_possible) {
1230 lyxerr[Debug::ACTION]
1231 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1235 RowList::iterator cursorrow = bv->text->cursorRow();
1236 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1238 // sorry for this but I have a strange error that the y value jumps at
1239 // a certain point. This seems like an error in my xforms library or
1240 // in some other local environment, but I would like to leave this here
1241 // for the moment until I can remove this (Jug 20020418)
1242 if (y_before < bv->text->cursor.y())
1243 lyxerr << y_before << ':'
1244 << bv->text->cursor.y() << endl;
1246 // This is to allow jumping over large insets
1247 if (cursorrow == bv->text->cursorRow()) {
1248 if (cmd.y >= bv->workHeight())
1249 bv->text->cursorDown(false);
1251 bv->text->cursorUp(false);
1254 bv->text->setSelection();
1259 // Single-click on work area
1260 case LFUN_MOUSE_PRESS:
1265 // ok ok, this is a hack (for xforms)
1266 // We shouldn't go further down as we really should only do the
1267 // scrolling and be done with this. Otherwise we may open some
1268 // dialogs (Jug 20020424).
1269 if (cmd.button() == mouse_button::button4) {
1270 bv->scroll(-lyxrc.wheel_jump);
1273 if (cmd.button() == mouse_button::button5) {
1274 bv->scroll(lyxrc.wheel_jump);
1280 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1282 // Middle button press pastes if we have a selection
1283 // We do this here as if the selection was inside an inset
1284 // it could get cleared on the unlocking of the inset so
1285 // we have to check this first
1286 bool paste_internally = false;
1287 if (cmd.button() == mouse_button::button2 && selection.set()) {
1288 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1289 paste_internally = true;
1292 int const screen_first = bv->top_y();
1294 if (bv->theLockingInset()) {
1295 // We are in inset locking mode
1297 // Check whether the inset was hit. If not reset mode,
1298 // otherwise give the event to the inset
1299 if (inset_hit == bv->theLockingInset()) {
1300 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1301 bv->theLockingInset()->dispatch(cmd1);
1304 bv->unlockInset(bv->theLockingInset());
1308 selection_possible = true;
1310 // Clear the selection
1311 bv->text->clearSelection();
1313 bv->updateScrollbar();
1315 // Single left click in math inset?
1316 if (isHighlyEditableInset(inset_hit)) {
1317 // Highly editable inset, like math
1318 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1319 selection_possible = false;
1320 bv->owner()->message(inset->editMessage());
1321 // We just have to lock the inset before calling a PressEvent on it!
1322 if (!bv->lockInset(inset))
1323 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1324 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1325 inset->dispatch(cmd1);
1328 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1330 // Right click on a footnote flag opens float menu
1331 if (cmd.button() == mouse_button::button3) {
1332 selection_possible = false;
1336 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1337 bv->text->setCursorFromCoordinates(x, y + screen_first);
1339 bv->text->selection.cursor = bv->text->cursor;
1340 bv->text->cursor.x_fix(bv->text->cursor.x());
1342 if (bv->fitCursor())
1343 selection_possible = false;
1345 // Insert primary selection with middle mouse
1346 // if there is a local selection in the current buffer,
1348 if (cmd.button() == mouse_button::button2) {
1349 if (paste_internally)
1350 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1352 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1353 selection_possible = false;
1358 case LFUN_MOUSE_RELEASE:
1360 // do nothing if we used the mouse wheel
1364 if (cmd.button() == mouse_button::button4
1365 || cmd.button() == mouse_button::button5)
1368 // If we hit an inset, we have the inset coordinates in these
1369 // and inset_hit points to the inset. If we do not hit an
1370 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1373 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1375 if (bv->theLockingInset()) {
1376 // We are in inset locking mode.
1378 // LyX does a kind of work-area grabbing for insets.
1379 // Only a ButtonPress FuncRequest outside the inset will
1380 // force a insetUnlock.
1381 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1382 bv->theLockingInset()->dispatch(cmd1);
1386 selection_possible = false;
1388 if (cmd.button() == mouse_button::button2)
1392 if (cmd.button() == mouse_button::button1)
1393 bv->haveSelection(selection.set());
1396 bv->owner()->view_state_changed();
1397 bv->owner()->updateMenubar();
1398 bv->owner()->updateToolbar();
1400 // Did we hit an editable inset?
1402 selection_possible = false;
1404 // if we reach this point with a selection, it
1405 // must mean we are currently selecting.
1406 // But we don't want to open the inset
1407 // because that is annoying for the user.
1408 // So just pretend we didn't hit it.
1409 // this is OK because a "kosher" ButtonRelease
1410 // will follow a ButtonPress that clears
1412 // Note this also fixes selection drawing
1413 // problems if we end up opening an inset
1414 if (selection.set())
1417 // CHECK fix this proper in 0.13
1418 // well, maybe 13.0 !!!!!!!!!
1420 // Following a ref shouldn't issue
1421 // a push on the undo-stack
1422 // anylonger, now that we have
1423 // keybindings for following
1424 // references and returning from
1425 // references. IMHO though, it
1426 // should be the inset's own business
1427 // to push or not push on the undo
1428 // stack. They don't *have* to
1429 // alter the document...
1431 // ...or maybe the recordUndo()
1432 // below isn't necessary at all anylonger?
1433 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1434 recUndo(cursor.par());
1436 bv->owner()->message(inset_hit->editMessage());
1438 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1439 inset_hit->dispatch(cmd1);
1445 case LFUN_SELFINSERT: {
1446 if (cmd.argument.empty())
1449 // Automatically delete the currently selected
1450 // text and replace it with what is being
1451 // typed in now. Depends on lyxrc settings
1452 // "auto_region_delete", which defaults to
1455 if (lyxrc.auto_region_delete) {
1456 if (selection.set())
1457 cutSelection(false, false);
1458 bv->haveSelection(false);
1461 bv->beforeChange(this);
1462 LyXFont const old_font = real_current_font;
1464 string::const_iterator cit = cmd.argument.begin();
1465 string::const_iterator end = cmd.argument.end();
1466 for (; cit != end; ++cit)
1467 bv->owner()->getIntl().getTransManager().
1468 TranslateAndInsert(*cit, this);
1470 selection.cursor = cursor;
1471 moveCursorUpdate(bv, false);
1473 // real_current_font.number can change so we need to
1474 // update the minibuffer
1475 if (old_font != real_current_font)
1476 bv->owner()->view_state_changed();
1477 bv->updateScrollbar();
1481 case LFUN_HTMLURL: {
1482 InsetCommandParams p("htmlurl");
1483 string const data = InsetCommandMailer::params2string("url", p);
1484 bv->owner()->getDialogs().show("url", data, 0);
1489 InsetCommandParams p("url");
1490 string const data = InsetCommandMailer::params2string("url", p);
1491 bv->owner()->getDialogs().show("url", data, 0);
1497 case LFUN_INSET_LIST:
1498 case LFUN_INSET_THEOREM:
1499 case LFUN_INSET_CAPTION:
1501 case LFUN_INSERT_NOTE:
1502 case LFUN_INSERT_BOX:
1503 case LFUN_INSERT_BRANCH:
1504 case LFUN_INSERT_BIBITEM:
1505 case LFUN_INSET_ERT:
1506 case LFUN_INSET_FLOAT:
1507 case LFUN_INSET_FOOTNOTE:
1508 case LFUN_INSET_MARGINAL:
1509 case LFUN_INSET_MINIPAGE:
1510 case LFUN_INSET_OPTARG:
1511 case LFUN_INSET_WIDE_FLOAT:
1512 case LFUN_INSET_WRAP:
1513 case LFUN_TABULAR_INSERT:
1514 case LFUN_ENVIRONMENT_INSERT:
1515 // Open the inset, and move the current selection
1517 doInsertInset(this, cmd, true, true);
1520 case LFUN_INDEX_INSERT:
1521 // Just open the inset
1522 doInsertInset(this, cmd, true, false);
1525 case LFUN_INDEX_PRINT:
1526 case LFUN_TOC_INSERT:
1529 doInsertInset(this, cmd, false, false);
1532 case LFUN_DEPTH_MIN:
1533 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1538 case LFUN_DEPTH_PLUS:
1540 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1546 return UNDISPATCHED;