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.
275 new_y = bv()->text->cursor.y()
276 + bv()->theLockingInset()->insetInInsetY() + y
278 - bv()->workHeight() + 1;
283 - bv()->workHeight() + 1;
287 ParagraphList::iterator pit = cursorPar();
289 if (isFirstRow(pit, *rit))
292 previousRow(pit, rit);
293 setCursor(cur, parOffset(pit), rit->pos(), false);
294 if (cur.y() > bv_owner->top_y())
296 bv()->updateScrollbar();
300 void LyXText::cursorNext()
302 int topy = bv_owner->top_y();
304 RowList::iterator rit = cursorRow();
305 if (isLastRow(cursorPar(), *cursorRow())) {
306 int y = cursor.y() - rit->baseline() + cursorRow()->height();
307 if (y > topy + bv()->workHeight())
308 bv_owner->updateScrollbar();
312 int y = topy + bv_owner->workHeight();
313 if (inset_owner && !topy) {
314 y -= (bv_owner->text->cursor.y()
316 + bv_owner->theLockingInset()->insetInInsetY());
319 ParagraphList::iterator dummypit;
320 Row const & rr = *getRowNearY(y, dummypit);
321 y = dummypit->y + rr.y_offset();
323 setCursorFromCoordinates(cursor.x_fix(), y);
324 // + bv->workHeight());
328 if (rit == bv_owner->text->cursorRow()) {
329 // we have a row which is taller than the workarea. The
330 // simplest solution is to move to the next row instead.
333 // This is what we used to do, so we wouldn't skip right past
334 // tall rows, but it's not working right now.
336 new_y = bv->top_y() + bv->workHeight();
340 new_y = bv()->text->cursor.y()
341 + bv()->theLockingInset()->insetInInsetY()
342 + y - rit->baseline();
344 new_y = cursor.y() - cursorRow()->baseline();
348 ParagraphList::iterator pit = cursorPar();
352 setCursor(cur, parOffset(pit), rit->pos(), false);
353 if (cur.y() < bv_owner->top_y() + bv()->workHeight())
355 bv()->updateScrollbar();
361 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
364 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
365 replaceSelection(lt);
366 if (!bv->insertInset(new_inset))
369 bv->updateInset(new_inset);
373 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
374 bool edit, bool pastesel)
376 InsetOld * inset = createInset(cmd);
377 BufferView * bv = cmd.view();
381 if (lt->selection.set()) {
382 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
385 if (bv->insertInset(inset)) {
387 FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
388 inset->dispatch(cmd);
390 if (gotsel && pastesel)
391 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
401 dispatch_result LyXText::dispatch(FuncRequest const & cmd)
403 lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
404 <<"] arg[" << cmd.argument << ']' << "xy[" <<
405 cmd.x << ',' << cmd.y << ']' << endl;
407 BufferView * bv = cmd.view();
409 switch (cmd.action) {
411 case LFUN_APPENDIX: {
412 ParagraphList::iterator pit = cursorPar();
413 bool start = !pit->params().startOfAppendix();
415 // ensure that we have only one start_of_appendix in this document
416 ParagraphList::iterator tmp = ownerParagraphs().begin();
417 ParagraphList::iterator end = ownerParagraphs().end();
419 for (; tmp != end; ++tmp) {
420 if (tmp->params().startOfAppendix()) {
421 recUndo(parOffset(tmp));
422 tmp->params().startOfAppendix(false);
428 recUndo(parOffset(pit));
429 pit->params().startOfAppendix(start);
431 // we can set the refreshing parameters now
433 redoParagraph(cursorPar());
434 setCursor(cursorPar(), cursor.pos());
439 case LFUN_DELETE_WORD_FORWARD:
440 bv->beforeChange(this);
445 case LFUN_DELETE_WORD_BACKWARD:
446 bv->beforeChange(this);
447 deleteWordBackward();
451 case LFUN_DELETE_LINE_FORWARD:
452 bv->beforeChange(this);
458 if (!selection.mark())
459 bv->beforeChange(this);
460 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
463 cursorRightOneWord();
468 if (!selection.mark())
469 bv->beforeChange(this);
470 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
471 cursorRightOneWord();
477 case LFUN_BEGINNINGBUF:
478 if (!selection.mark())
479 bv->beforeChange(this);
485 if (selection.mark())
486 bv->beforeChange(this);
492 if (!selection.set())
493 selection.cursor = cursor;
494 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
498 finishChange(bv, true);
502 if (!selection.set())
503 selection.cursor = cursor;
504 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
508 finishChange(bv, true);
512 if (!selection.set())
513 selection.cursor = cursor;
515 finishChange(bv, true);
519 if (!selection.set())
520 selection.cursor = cursor;
522 finishChange(bv, true);
525 case LFUN_UP_PARAGRAPHSEL:
526 if (!selection.set())
527 selection.cursor = cursor;
529 finishChange(bv, true);
532 case LFUN_DOWN_PARAGRAPHSEL:
533 if (!selection.set())
534 selection.cursor = cursor;
535 cursorDownParagraph();
536 finishChange(bv, true);
540 if (!selection.set())
541 selection.cursor = cursor;
543 finishChange(bv, true);
547 if (!selection.set())
548 selection.cursor = cursor;
550 finishChange(bv, true);
554 if (!selection.set())
555 selection.cursor = cursor;
557 finishChange(bv, true);
561 if (!selection.set())
562 selection.cursor = cursor;
564 finishChange(bv, true);
567 case LFUN_WORDRIGHTSEL:
568 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
571 cursorRightOneWord();
572 finishChange(bv, true);
575 case LFUN_WORDLEFTSEL:
576 if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
577 cursorRightOneWord();
580 finishChange(bv, true);
584 LyXCursor cur1 = cursor;
586 ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
587 setCursor(cur1.par(), cur1.pos());
588 bv->beforeChange(this);
589 setCursor(cur2.par(), cur2.pos());
590 finishChange(bv, true);
595 bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
596 if (!selection.mark())
597 bv->beforeChange(this);
600 if (cursor.pos() < cursorPar()->size()
601 && cursorPar()->isInset(cursor.pos())
602 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
603 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
604 cmd.message(tmpinset->editMessage());
605 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
606 tmpinset->dispatch(cmd1);
616 // This is soooo ugly. Isn`t it possible to make
618 bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
619 if (!selection.mark())
620 bv->beforeChange(this);
621 LyXCursor const cur = cursor;
624 if ((is_rtl || cur != cursor) && // only if really moved!
625 cursor.pos() < cursorPar()->size() &&
626 cursorPar()->isInset(cursor.pos()) &&
627 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
628 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
629 cmd.message(tmpinset->editMessage());
630 FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
631 tmpinset->dispatch(cmd1);
641 if (!selection.mark())
642 bv->beforeChange(this);
648 if (!selection.mark())
649 bv->beforeChange(this);
654 case LFUN_UP_PARAGRAPH:
655 if (!selection.mark())
656 bv->beforeChange(this);
661 case LFUN_DOWN_PARAGRAPH:
662 if (!selection.mark())
663 bv->beforeChange(this);
664 cursorDownParagraph();
665 finishChange(bv, false);
669 if (!selection.mark())
670 bv->beforeChange(this);
672 finishChange(bv, false);
676 if (!selection.mark())
677 bv->beforeChange(this);
679 finishChange(bv, false);
683 if (!selection.mark())
684 bv->beforeChange(this);
686 finishChange(bv, false);
690 if (!selection.mark())
691 bv->beforeChange(this);
693 finishChange(bv, false);
696 case LFUN_BREAKLINE: {
697 lyx::pos_type body = cursorPar()->beginningOfBody();
699 // Not allowed by LaTeX (labels or empty par)
700 if (cursor.pos() <= body)
703 replaceSelection(bv->getLyXText());
704 insertInset(new InsetNewline);
705 setCursor(cursorPar(), cursor.pos());
706 moveCursorUpdate(bv, false);
711 if (!selection.set()) {
713 selection.cursor = cursor;
714 // It is possible to make it a lot faster still
715 // just comment out the line below...
717 cutSelection(true, false);
719 moveCursorUpdate(bv, false);
720 bv->owner()->view_state_changed();
723 case LFUN_DELETE_SKIP:
724 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
725 if (!selection.set()) {
726 if (cursor.pos() == cursorPar()->size()) {
728 ParagraphParameters & params = cursorPar()->params();
729 if (cursor.pos() == 0
730 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
734 params.pagebreakTop(),
735 params.pagebreakBottom(),
736 VSpace(VSpace::NONE),
737 params.spaceBottom(),
740 params.labelWidthString(), 0);
745 selection.cursor = cursor;
749 selection.cursor = cursor;
752 cutSelection(true, false);
759 if (!selection.set()) {
760 if (bv->owner()->getIntl().getTransManager().backspace()) {
762 selection.cursor = cursor;
763 // It is possible to make it a lot faster still
764 // just comment out the line below...
767 cutSelection(true, false);
769 bv->owner()->view_state_changed();
774 case LFUN_BACKSPACE_SKIP:
775 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
776 if (!selection.set()) {
777 ParagraphParameters & params = cursorPar()->params();
778 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
782 params.pagebreakTop(),
783 params.pagebreakBottom(),
784 VSpace(VSpace::NONE),
785 params.spaceBottom(),
788 params.labelWidthString(), 0);
790 LyXCursor cur = cursor;
792 selection.cursor = cur;
795 cutSelection(true, false);
800 case LFUN_BREAKPARAGRAPH:
801 replaceSelection(bv->getLyXText());
802 breakParagraph(bv->buffer()->paragraphs(), 0);
804 selection.cursor = cursor;
806 bv->owner()->view_state_changed();
809 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
810 replaceSelection(bv->getLyXText());
811 breakParagraph(bv->buffer()->paragraphs(), 1);
813 selection.cursor = cursor;
815 bv->owner()->view_state_changed();
818 case LFUN_BREAKPARAGRAPH_SKIP: {
819 // When at the beginning of a paragraph, remove
820 // indentation and add a "defskip" at the top.
821 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
822 LyXCursor cur = cursor;
823 replaceSelection(bv->getLyXText());
824 if (cur.pos() == 0) {
825 ParagraphParameters & params = getPar(cur)->params();
826 if (params.spaceTop() == VSpace(VSpace::NONE)) {
830 params.pagebreakTop(),
831 params.pagebreakBottom(),
832 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
835 params.labelWidthString(), 1);
839 breakParagraph(bv->buffer()->paragraphs(), 0);
842 selection.cursor = cur;
844 bv->owner()->view_state_changed();
848 case LFUN_PARAGRAPH_SPACING: {
849 ParagraphList::iterator pit = cursorPar();
850 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
851 float cur_value = 1.0;
852 if (cur_spacing == Spacing::Other)
853 cur_value = pit->params().spacing().getValue();
855 istringstream is(cmd.argument);
858 Spacing::Space new_spacing = cur_spacing;
859 float new_value = cur_value;
861 lyxerr << "Missing argument to `paragraph-spacing'"
863 } else if (tmp == "single") {
864 new_spacing = Spacing::Single;
865 } else if (tmp == "onehalf") {
866 new_spacing = Spacing::Onehalf;
867 } else if (tmp == "double") {
868 new_spacing = Spacing::Double;
869 } else if (tmp == "other") {
870 new_spacing = Spacing::Other;
873 lyxerr << "new_value = " << tmpval << endl;
876 } else if (tmp == "default") {
877 new_spacing = Spacing::Default;
879 lyxerr << _("Unknown spacing argument: ")
880 << cmd.argument << endl;
882 if (cur_spacing != new_spacing || cur_value != new_value) {
883 pit->params().spacing(Spacing(new_spacing, new_value));
890 case LFUN_INSET_SETTINGS:
891 BOOST_ASSERT(bv->theLockingInset());
892 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
895 case LFUN_INSET_TOGGLE:
896 bv->beforeChange(this);
902 case LFUN_SPACE_INSERT:
903 if (cursorPar()->layout()->free_spacing)
906 doInsertInset(this, cmd, false, false);
907 moveCursorUpdate(bv, false);
910 case LFUN_HYPHENATION:
911 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
914 case LFUN_LIGATURE_BREAK:
915 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
919 specialChar(this, bv, InsetSpecialChar::LDOTS);
922 case LFUN_END_OF_SENTENCE:
923 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
926 case LFUN_MENU_SEPARATOR:
927 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
931 bv->beforeChange(this);
933 selection.cursor = cursor;
934 cmd.message(N_("Mark off"));
938 bv->beforeChange(this);
939 selection.mark(true);
941 selection.cursor = cursor;
942 cmd.message(N_("Mark on"));
946 bv->beforeChange(this);
947 if (selection.mark()) {
948 cmd.message(N_("Mark removed"));
950 selection.mark(true);
951 cmd.message(N_("Mark set"));
953 selection.cursor = cursor;
957 case LFUN_UPCASE_WORD:
958 changeCase(LyXText::text_uppercase);
962 case LFUN_LOWCASE_WORD:
963 changeCase(LyXText::text_lowercase);
967 case LFUN_CAPITALIZE_WORD:
968 changeCase(LyXText::text_capitalization);
972 case LFUN_TRANSPOSE_CHARS:
973 recUndo(cursor.par());
979 cmd.message(_("Paste"));
980 replaceSelection(bv->getLyXText());
981 #warning FIXME Check if the arg is in the domain of available selections.
982 if (isStrUnsignedInt(cmd.argument))
983 pasteSelection(strToUnsignedInt(cmd.argument));
986 clearSelection(); // bug 393
993 cutSelection(true, true);
994 cmd.message(_("Cut"));
1000 cmd.message(_("Copy"));
1003 case LFUN_BEGINNINGBUFSEL:
1005 return UNDISPATCHED;
1007 finishChange(bv, true);
1010 case LFUN_ENDBUFSEL:
1012 return UNDISPATCHED;
1014 finishChange(bv, true);
1018 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1024 istringstream is(cmd.argument);
1027 lyxerr << "SETXY: Could not parse coordinates in '"
1028 << cmd.argument << std::endl;
1030 setCursorFromCoordinates(x, y);
1035 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1037 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1043 case LFUN_GETLAYOUT:
1044 cmd.message(tostr(cursorPar()->layout()));
1048 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1049 << cmd.argument << endl;
1051 // This is not the good solution to the empty argument
1052 // problem, but it will hopefully suffice for 1.2.0.
1053 // The correct solution would be to augument the
1054 // function list/array with information about what
1055 // functions needs arguments and their type.
1056 if (cmd.argument.empty()) {
1057 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1061 // Derive layout number from given argument (string)
1062 // and current buffer's textclass (number)
1063 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1064 bool hasLayout = tclass.hasLayout(cmd.argument);
1065 string layout = cmd.argument;
1067 // If the entry is obsolete, use the new one instead.
1069 string const & obs = tclass[layout]->obsoleted_by();
1075 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1080 bool change_layout = (current_layout != layout);
1082 if (!change_layout && selection.set() &&
1083 selection.start.par() != selection.end.par())
1085 ParagraphList::iterator spit = getPar(selection.start);
1086 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1087 while (spit != epit) {
1088 if (spit->layout()->name() != current_layout) {
1089 change_layout = true;
1096 if (change_layout) {
1097 current_layout = layout;
1099 bv->owner()->setLayout(layout);
1106 case LFUN_PASTESELECTION: {
1107 // this was originally a beforeChange(bv->text), i.e
1108 // the outermost LyXText!
1109 bv->beforeChange(this);
1110 string const clip = bv->getClipboard();
1111 if (!clip.empty()) {
1112 if (cmd.argument == "paragraph")
1113 insertStringAsParagraphs(clip);
1115 insertStringAsLines(clip);
1122 case LFUN_GOTOERROR:
1123 gotoInset(InsetOld::ERROR_CODE, false);
1127 gotoInset(InsetOld::NOTE_CODE, false);
1130 case LFUN_REFERENCE_GOTO:
1132 vector<InsetOld::Code> tmp;
1133 tmp.push_back(InsetOld::LABEL_CODE);
1134 tmp.push_back(InsetOld::REF_CODE);
1135 gotoInset(tmp, true);
1140 replaceSelection(bv->getLyXText());
1141 ParagraphList::iterator pit = cursorPar();
1142 lyx::pos_type pos = cursor.pos();
1146 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1149 c = pit->getChar(pos - 1);
1151 LyXLayout_ptr const & style = pit->layout();
1153 BufferParams const & bufparams = bv->buffer()->params();
1154 if (style->pass_thru ||
1155 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1156 !bv->insertInset(new InsetQuotes(c, bufparams)))
1157 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1161 case LFUN_DATE_INSERT: {
1162 replaceSelection(bv->getLyXText());
1163 time_t now_time_t = time(NULL);
1164 struct tm * now_tm = localtime(&now_time_t);
1165 setlocale(LC_TIME, "");
1167 if (!cmd.argument.empty())
1170 arg = lyxrc.date_insert_format;
1172 int const datetmp_len =
1173 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1175 for (int i = 0; i < datetmp_len; i++)
1176 insertChar(datetmp[i]);
1178 selection.cursor = cursor;
1179 moveCursorUpdate(bv, false);
1183 case LFUN_MOUSE_TRIPLE:
1186 if (!isInInset() && bv->theLockingInset())
1188 if (cmd.button() == mouse_button::button1) {
1190 selection.cursor = cursor;
1194 bv->haveSelection(selection.set());
1198 case LFUN_MOUSE_DOUBLE:
1201 if (!isInInset() && bv->theLockingInset())
1203 if (cmd.button() == mouse_button::button1) {
1204 selectWord(lyx::WHOLE_WORD_STRICT);
1206 bv->haveSelection(selection.set());
1210 case LFUN_MOUSE_MOTION:
1212 // Only use motion with button 1
1213 //if (ev.button() != mouse_button::button1)
1219 // Check for inset locking
1220 if (bv->theLockingInset()) {
1221 InsetOld * tli = bv->theLockingInset();
1222 LyXCursor cursor = bv->text->cursor;
1223 LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1224 int width = tli->width();
1225 int inset_x = font.isVisibleRightToLeft()
1226 ? cursor.x() - width : cursor.x();
1227 int start_x = inset_x + tli->scroll();
1228 FuncRequest cmd1 = cmd;
1229 cmd1.x = cmd.x - start_x;
1230 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1231 tli->dispatch(cmd1);
1235 // The test for not selection possible is needed, that only motion
1236 // events are used, where the bottom press event was on
1237 // the drawing area too
1238 if (!selection_possible) {
1239 lyxerr[Debug::ACTION]
1240 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1244 RowList::iterator cursorrow = bv->text->cursorRow();
1245 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1247 // sorry for this but I have a strange error that the y value jumps at
1248 // a certain point. This seems like an error in my xforms library or
1249 // in some other local environment, but I would like to leave this here
1250 // for the moment until I can remove this (Jug 20020418)
1251 if (y_before < bv->text->cursor.y())
1252 lyxerr << y_before << ':'
1253 << bv->text->cursor.y() << endl;
1255 // This is to allow jumping over large insets
1256 if (cursorrow == bv->text->cursorRow()) {
1257 if (cmd.y >= bv->workHeight())
1258 bv->text->cursorDown(false);
1260 bv->text->cursorUp(false);
1263 bv->text->setSelection();
1268 // Single-click on work area
1269 case LFUN_MOUSE_PRESS:
1274 // ok ok, this is a hack (for xforms)
1275 // We shouldn't go further down as we really should only do the
1276 // scrolling and be done with this. Otherwise we may open some
1277 // dialogs (Jug 20020424).
1278 if (cmd.button() == mouse_button::button4) {
1279 bv->scroll(-lyxrc.wheel_jump);
1282 if (cmd.button() == mouse_button::button5) {
1283 bv->scroll(lyxrc.wheel_jump);
1289 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1291 // Middle button press pastes if we have a selection
1292 // We do this here as if the selection was inside an inset
1293 // it could get cleared on the unlocking of the inset so
1294 // we have to check this first
1295 bool paste_internally = false;
1296 if (cmd.button() == mouse_button::button2 && selection.set()) {
1297 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1298 paste_internally = true;
1301 int const screen_first = bv->top_y();
1303 if (bv->theLockingInset()) {
1304 // We are in inset locking mode
1306 // Check whether the inset was hit. If not reset mode,
1307 // otherwise give the event to the inset
1308 if (inset_hit == bv->theLockingInset()) {
1309 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1310 bv->theLockingInset()->dispatch(cmd1);
1313 bv->unlockInset(bv->theLockingInset());
1317 selection_possible = true;
1319 // Clear the selection
1320 bv->text->clearSelection();
1322 bv->updateScrollbar();
1324 // Single left click in math inset?
1325 if (isHighlyEditableInset(inset_hit)) {
1326 // Highly editable inset, like math
1327 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1328 selection_possible = false;
1329 bv->owner()->message(inset->editMessage());
1330 // We just have to lock the inset before calling a PressEvent on it!
1331 if (!bv->lockInset(inset))
1332 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1333 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1334 inset->dispatch(cmd1);
1337 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1339 // Right click on a footnote flag opens float menu
1340 if (cmd.button() == mouse_button::button3) {
1341 selection_possible = false;
1345 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1346 bv->text->setCursorFromCoordinates(x, y + screen_first);
1348 bv->text->selection.cursor = bv->text->cursor;
1349 bv->text->cursor.x_fix(bv->text->cursor.x());
1351 if (bv->fitCursor())
1352 selection_possible = false;
1354 // Insert primary selection with middle mouse
1355 // if there is a local selection in the current buffer,
1357 if (cmd.button() == mouse_button::button2) {
1358 if (paste_internally)
1359 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1361 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1362 selection_possible = false;
1367 case LFUN_MOUSE_RELEASE:
1369 // do nothing if we used the mouse wheel
1373 if (cmd.button() == mouse_button::button4
1374 || cmd.button() == mouse_button::button5)
1377 // If we hit an inset, we have the inset coordinates in these
1378 // and inset_hit points to the inset. If we do not hit an
1379 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1382 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1384 if (bv->theLockingInset()) {
1385 // We are in inset locking mode.
1387 // LyX does a kind of work-area grabbing for insets.
1388 // Only a ButtonPress FuncRequest outside the inset will
1389 // force a insetUnlock.
1390 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1391 bv->theLockingInset()->dispatch(cmd1);
1395 selection_possible = false;
1397 if (cmd.button() == mouse_button::button2)
1401 if (cmd.button() == mouse_button::button1)
1402 bv->haveSelection(selection.set());
1405 bv->owner()->view_state_changed();
1406 bv->owner()->updateMenubar();
1407 bv->owner()->updateToolbar();
1409 // Did we hit an editable inset?
1411 selection_possible = false;
1413 // if we reach this point with a selection, it
1414 // must mean we are currently selecting.
1415 // But we don't want to open the inset
1416 // because that is annoying for the user.
1417 // So just pretend we didn't hit it.
1418 // this is OK because a "kosher" ButtonRelease
1419 // will follow a ButtonPress that clears
1421 // Note this also fixes selection drawing
1422 // problems if we end up opening an inset
1423 if (selection.set())
1426 // CHECK fix this proper in 0.13
1427 // well, maybe 13.0 !!!!!!!!!
1429 // Following a ref shouldn't issue
1430 // a push on the undo-stack
1431 // anylonger, now that we have
1432 // keybindings for following
1433 // references and returning from
1434 // references. IMHO though, it
1435 // should be the inset's own business
1436 // to push or not push on the undo
1437 // stack. They don't *have* to
1438 // alter the document...
1440 // ...or maybe the recordUndo()
1441 // below isn't necessary at all anylonger?
1442 if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1443 recUndo(cursor.par());
1445 bv->owner()->message(inset_hit->editMessage());
1447 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1448 inset_hit->dispatch(cmd1);
1454 case LFUN_SELFINSERT: {
1455 if (cmd.argument.empty())
1458 // Automatically delete the currently selected
1459 // text and replace it with what is being
1460 // typed in now. Depends on lyxrc settings
1461 // "auto_region_delete", which defaults to
1464 if (lyxrc.auto_region_delete) {
1465 if (selection.set())
1466 cutSelection(false, false);
1467 bv->haveSelection(false);
1470 bv->beforeChange(this);
1471 LyXFont const old_font = real_current_font;
1473 string::const_iterator cit = cmd.argument.begin();
1474 string::const_iterator end = cmd.argument.end();
1475 for (; cit != end; ++cit)
1476 bv->owner()->getIntl().getTransManager().
1477 TranslateAndInsert(*cit, this);
1479 selection.cursor = cursor;
1480 moveCursorUpdate(bv, false);
1482 // real_current_font.number can change so we need to
1483 // update the minibuffer
1484 if (old_font != real_current_font)
1485 bv->owner()->view_state_changed();
1486 bv->updateScrollbar();
1490 case LFUN_HTMLURL: {
1491 InsetCommandParams p("htmlurl");
1492 string const data = InsetCommandMailer::params2string("url", p);
1493 bv->owner()->getDialogs().show("url", data, 0);
1498 InsetCommandParams p("url");
1499 string const data = InsetCommandMailer::params2string("url", p);
1500 bv->owner()->getDialogs().show("url", data, 0);
1506 case LFUN_INSET_LIST:
1507 case LFUN_INSET_THEOREM:
1508 case LFUN_INSET_CAPTION:
1510 case LFUN_INSERT_NOTE:
1511 case LFUN_INSERT_BOX:
1512 case LFUN_INSERT_BRANCH:
1513 case LFUN_INSERT_BIBITEM:
1514 case LFUN_INSET_ERT:
1515 case LFUN_INSET_FLOAT:
1516 case LFUN_INSET_FOOTNOTE:
1517 case LFUN_INSET_MARGINAL:
1518 case LFUN_INSET_MINIPAGE:
1519 case LFUN_INSET_OPTARG:
1520 case LFUN_INSET_WIDE_FLOAT:
1521 case LFUN_INSET_WRAP:
1522 case LFUN_TABULAR_INSERT:
1523 case LFUN_ENVIRONMENT_INSERT:
1524 // Open the inset, and move the current selection
1526 doInsertInset(this, cmd, true, true);
1529 case LFUN_INDEX_INSERT:
1530 // Just open the inset
1531 doInsertInset(this, cmd, true, false);
1534 case LFUN_INDEX_PRINT:
1535 case LFUN_TOC_INSERT:
1538 doInsertInset(this, cmd, false, false);
1541 case LFUN_DEPTH_MIN:
1542 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1547 case LFUN_DEPTH_PLUS:
1549 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1555 return UNDISPATCHED;