1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2002 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
16 #include "BufferView.h"
17 #include "funcrequest.h"
20 #include "bufferparams.h"
22 #include "ParagraphParameters.h"
28 #include "support/lstrings.h"
29 #include "frontends/LyXView.h"
30 #include "frontends/screen.h"
31 #include "frontends/Dialogs.h"
32 #include "insets/insetspecialchar.h"
33 #include "insets/insettext.h"
34 #include "insets/insetquotes.h"
35 #include "insets/insetcommand.h"
36 #include "undo_funcs.h"
45 extern string current_layout;
46 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
48 // the selection possible is needed, that only motion events are
49 // used, where the bottom press event was on the drawing area too
50 bool selection_possible = false;
55 void moveCursorUpdate(BufferView * bv, bool selecting)
57 LyXText * lt = bv->getLyXText();
59 if (selecting || lt->selection.mark()) {
64 bv->updateInset(lt->inset_owner, false);
66 if (lt->isTopLevel()) {
68 // bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
70 bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
72 } else if (bv->text->status() != LyXText::UNCHANGED) {
73 bv->theLockingInset()->hideInsetCursor(bv);
74 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
78 if (!lt->selection.set())
79 bv->haveSelection(false);
85 void finishChange(BufferView * bv, bool selecting = false)
88 moveCursorUpdate(bv, selecting);
89 bv->owner()->view_state_changed();
92 // check if the given co-ordinates are inside an inset at the
93 // given cursor, if one exists. If so, the inset is returned,
94 // and the co-ordinates are made relative. Otherwise, 0 is returned.
95 Inset * checkInset(BufferView * bv, LyXText const & text,
96 LyXCursor const & cur, int & x, int & y)
98 lyx::pos_type const pos = cur.pos();
99 Paragraph /*const*/ & par = *cur.par();
101 if (pos >= par.size() || !par.isInset(pos))
104 Inset /*const*/ * inset = par.getInset(pos);
106 if (!isEditableInset(inset))
109 // get inset dimensions
110 lyx::Assert(par.getInset(pos));
112 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
114 int const width = inset->width(bv, font);
115 int const inset_x = font.isVisibleRightToLeft()
116 ? (cur.ix() - width) : cur.ix();
119 inset_x + inset->scroll(),
121 cur.iy() - inset->ascent(bv, font),
122 cur.iy() + inset->descent(bv, font)
125 if (!b.contained(x, y)) {
126 lyxerr[Debug::GUI] << "Missed inset at x,y "
128 << " box " << b << endl;
132 text.setCursor(bv, &par, pos, true);
135 // The origin of an inset is on the baseline
136 y -= text.cursor.iy();
144 Inset * LyXText::checkInsetHit(BufferView * bv, int & x, int & y) const
146 int y_tmp = y + first_y;
149 setCursorFromCoordinates(bv, cur, x, y_tmp);
151 Inset * inset = checkInset(bv, *this, cur, x, y_tmp);
157 // look at previous position
162 setCursor(bv, cur, cur.par(), cur.pos() - 1, true);
164 inset = checkInset(bv, *this, cur, x, y_tmp);
171 bool LyXText::gotoNextInset(BufferView * bv,
172 vector<Inset::Code> const & codes, string const & contents) const
174 LyXCursor res = cursor;
177 if (res.pos() < res.par()->size() - 1) {
178 res.pos(res.pos() + 1);
180 res.par(res.par()->next());
184 } while (res.par() &&
185 !(res.par()->isInset(res.pos())
186 && (inset = res.par()->getInset(res.pos())) != 0
187 && find(codes.begin(), codes.end(), inset->lyxCode())
189 && (contents.empty() ||
190 static_cast<InsetCommand *>(
191 res.par()->getInset(res.pos()))->getContents()
195 setCursor(bv, res.par(), res.pos(), false);
202 void LyXText::gotoInset(BufferView * bv, vector<Inset::Code> const & codes,
206 bv->beforeChange(this);
210 if (same_content && cursor.par()->isInset(cursor.pos())) {
211 Inset const * inset = cursor.par()->getInset(cursor.pos());
212 if (find(codes.begin(), codes.end(), inset->lyxCode())
214 contents = static_cast<InsetCommand const *>(inset)->getContents();
217 if (!gotoNextInset(bv, codes, contents)) {
218 if (cursor.pos() || cursor.par() != ownerParagraph()) {
219 LyXCursor tmp = cursor;
220 cursor.par(ownerParagraph());
222 if (!gotoNextInset(bv, codes, contents)) {
224 bv->owner()->message(_("No more insets"));
227 bv->owner()->message(_("No more insets"));
231 selection.cursor = cursor;
235 void LyXText::gotoInset(BufferView * bv, Inset::Code code, bool same_content)
237 gotoInset(bv, vector<Inset::Code>(1, code), same_content);
241 void LyXText::cursorPrevious(BufferView * bv)
243 if (!cursor.row()->previous()) {
245 int new_y = bv->text->first_y - bv->workHeight();
246 bv->screen().draw(bv->text, bv, new_y < 0 ? 0 : new_y);
247 bv->updateScrollbar();
253 Row * cursorrow = cursor.row();
255 setCursorFromCoordinates(bv, cursor.x_fix(), y);
259 if (cursorrow == bv->text->cursor.row()) {
260 // we have a row which is taller than the workarea. The
261 // simplest solution is to move to the previous row instead.
264 // This is what we used to do, so we wouldn't skip right past
265 // tall rows, but it's not working right now.
267 new_y = bv->text->first_y - bv->workHeight();
271 new_y = bv->text->cursor.iy()
272 + bv->theLockingInset()->insetInInsetY() + y
273 + cursor.row()->height()
274 - bv->workHeight() + 1;
277 - cursor.row()->baseline()
278 + cursor.row()->height()
279 - bv->workHeight() + 1;
282 bv->screen().draw(bv->text, bv, new_y < 0 ? 0 : new_y);
283 if (cursor.row()->previous()) {
285 setCursor(bv, cur, cursor.row()->previous()->par(),
286 cursor.row()->previous()->pos(), false);
287 if (cur.y() > first_y) {
291 bv->updateScrollbar();
295 void LyXText::cursorNext(BufferView * bv)
297 if (!cursor.row()->next()) {
298 int y = cursor.y() - cursor.row()->baseline() +
299 cursor.row()->height();
300 if (y > int(first_y + bv->workHeight())) {
301 bv->screen().draw(bv->text, bv,
302 bv->text->first_y + bv->workHeight());
303 bv->updateScrollbar();
308 int y = first_y + bv->workHeight();
309 if (inset_owner && !first_y) {
310 y -= (bv->text->cursor.iy()
312 + bv->theLockingInset()->insetInInsetY());
317 Row * cursorrow = cursor.row();
318 setCursorFromCoordinates(bv, cursor.x_fix(), y);
319 // + bv->workHeight());
323 if (cursorrow == bv->text->cursor.row()) {
324 // we have a row which is taller than the workarea. The
325 // simplest solution is to move to the next row instead.
326 cursorDown(bv, true);
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->text->first_y + bv->workHeight();
335 new_y = bv->text->cursor.iy()
336 + bv->theLockingInset()->insetInInsetY()
337 + y - cursor.row()->baseline();
339 new_y = cursor.y() - cursor.row()->baseline();
342 bv->screen().draw(bv->text, bv, new_y);
343 if (cursor.row()->next()) {
345 setCursor(bv, cur, cursor.row()->next()->par(),
346 cursor.row()->next()->pos(), false);
347 if (cur.y() < int(first_y + bv->workHeight())) {
348 cursorDown(bv, true);
351 bv->updateScrollbar();
355 void LyXText::update(BufferView * bv, bool changed)
357 BufferView::UpdateCodes c = BufferView::SELECT | BufferView::FITCUR;
359 bv->update(this, c | BufferView::CHANGE);
366 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
370 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
371 if (!bv->insertInset(new_inset))
374 bv->updateInset(new_inset, true);
378 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
379 bool edit, bool pastesel)
381 Inset * inset = createInset(cmd);
382 BufferView * bv = cmd.view();
386 if (lt->selection.set()) {
387 lt->cutSelection(bv, true, false);
390 if (bv->insertInset(inset)) {
393 if (gotsel && pastesel)
394 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
403 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
405 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
406 <<"] arg[" << cmd.argument << ']' << endl;
408 BufferView * bv = cmd.view();
410 switch (cmd.action) {
412 case LFUN_APPENDIX: {
413 Paragraph * par = cursor.par();
414 bool start = !par->params().startOfAppendix();
416 // ensure that we have only one start_of_appendix in this document
417 Paragraph * tmp = ownerParagraph();
418 for (; tmp; tmp = tmp->next()) {
419 if (tmp->params().startOfAppendix()) {
420 setUndo(bv, Undo::EDIT, tmp, tmp->next());
421 tmp->params().startOfAppendix(false);
426 setUndo(bv, Undo::EDIT, par, par->next());
427 par->params().startOfAppendix(start);
429 // we can set the refreshing parameters now
430 status(cmd.view(), LyXText::NEED_MORE_REFRESH);
432 refresh_row = 0; // not needed for full update
433 updateCounters(cmd.view());
434 setCursor(cmd.view(), cursor.par(), cursor.pos());
439 case LFUN_DELETE_WORD_FORWARD:
440 bv->beforeChange(this);
442 deleteWordForward(bv);
447 case LFUN_DELETE_WORD_BACKWARD:
448 bv->beforeChange(this);
450 deleteWordBackward(bv);
455 case LFUN_DELETE_LINE_FORWARD:
456 bv->beforeChange(this);
458 deleteLineForward(bv);
465 if (!selection.mark())
466 bv->beforeChange(this);
473 if (!selection.mark())
474 bv->beforeChange(this);
476 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
477 cursorLeftOneWord(bv);
479 cursorRightOneWord(bv);
484 if (!selection.mark())
485 bv->beforeChange(this);
487 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
488 cursorRightOneWord(bv);
490 cursorLeftOneWord(bv);
494 case LFUN_BEGINNINGBUF:
495 if (!selection.mark())
496 bv->beforeChange(this);
503 if (selection.mark())
504 bv->beforeChange(this);
512 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
516 finishChange(bv, true);
521 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
525 finishChange(bv, true);
531 finishChange(bv, true);
536 cursorDown(bv, true);
537 finishChange(bv, true);
540 case LFUN_UP_PARAGRAPHSEL:
542 cursorUpParagraph(bv);
543 finishChange(bv, true);
546 case LFUN_DOWN_PARAGRAPHSEL:
548 cursorDownParagraph(bv);
549 finishChange(bv, true);
555 finishChange(bv, true);
561 finishChange(bv, true);
567 finishChange(bv, true);
573 finishChange(bv, true);
576 case LFUN_WORDRIGHTSEL:
578 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
579 cursorLeftOneWord(bv);
581 cursorRightOneWord(bv);
582 finishChange(bv, true);
585 case LFUN_WORDLEFTSEL:
587 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
588 cursorRightOneWord(bv);
590 cursorLeftOneWord(bv);
591 finishChange(bv, true);
598 getWord(cur1, cur2, WHOLE_WORD);
599 setCursor(bv, cur1.par(), cur1.pos());
600 bv->beforeChange(this);
601 setCursor(bv, cur2.par(), cur2.pos());
602 finishChange(bv, true);
607 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
608 if (!selection.mark())
609 bv->beforeChange(this);
612 cursorLeft(bv, false);
613 if (cursor.pos() < cursor.par()->size()
614 && cursor.par()->isInset(cursor.pos())
615 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
616 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
617 cmd.message(tmpinset->editMessage());
618 tmpinset->edit(bv, !is_rtl);
622 cursorRight(bv, false);
628 // This is soooo ugly. Isn`t it possible to make
630 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
631 if (!selection.mark())
632 bv->beforeChange(this);
634 LyXCursor const cur = cursor;
636 cursorLeft(bv, false);
637 if ((is_rtl || cur != cursor) && // only if really moved!
638 cursor.pos() < cursor.par()->size() &&
639 cursor.par()->isInset(cursor.pos()) &&
640 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
641 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
642 cmd.message(tmpinset->editMessage());
643 tmpinset->edit(bv, is_rtl);
647 cursorRight(bv, false);
653 if (!selection.mark())
654 bv->beforeChange(this);
655 bv->update(this, BufferView::UPDATE);
661 if (!selection.mark())
662 bv->beforeChange(this);
663 bv->update(this, BufferView::UPDATE);
668 case LFUN_UP_PARAGRAPH:
669 if (!selection.mark())
670 bv->beforeChange(this);
671 bv->update(this, BufferView::UPDATE);
672 cursorUpParagraph(bv);
676 case LFUN_DOWN_PARAGRAPH:
677 if (!selection.mark())
678 bv->beforeChange(this);
679 bv->update(this, BufferView::UPDATE);
680 cursorDownParagraph(bv);
681 finishChange(bv, false);
685 if (!selection.mark())
686 bv->beforeChange(this);
687 bv->update(this, BufferView::UPDATE);
689 finishChange(bv, false);
692 // moveCursorUpdate(bv, false, false);
693 // owner_->view_state_changed();
697 if (!selection.mark())
698 bv->beforeChange(this);
699 bv->update(this, BufferView::UPDATE);
701 finishChange(bv, false);
705 if (!selection.mark())
706 bv->beforeChange(this);
709 finishChange(bv, false);
713 if (!selection.mark())
714 bv->beforeChange(this);
717 finishChange(bv, false);
721 bv->beforeChange(this);
722 insertChar(bv, Paragraph::META_NEWLINE);
724 setCursor(bv, cursor.par(), cursor.pos());
725 moveCursorUpdate(bv, false);
729 if (!selection.set()) {
731 selection.cursor = cursor;
733 // It is possible to make it a lot faster still
734 // just comment out the line below...
738 cutSelection(bv, true);
741 moveCursorUpdate(bv, false);
742 bv->owner()->view_state_changed();
746 case LFUN_DELETE_SKIP:
747 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
748 if (!selection.set()) {
749 LyXCursor cur = cursor;
750 if (cur.pos() == cur.par()->size()) {
754 && !(cur.par()->params().spaceTop()
755 == VSpace (VSpace::NONE))) {
757 cur.par()->params().lineTop(),
758 cur.par()->params().lineBottom(),
759 cur.par()->params().pagebreakTop(),
760 cur.par()->params().pagebreakBottom(),
761 VSpace(VSpace::NONE),
762 cur.par()->params().spaceBottom(),
763 cur.par()->params().spacing(),
764 cur.par()->params().align(),
765 cur.par()->params().labelWidthString(), 0);
771 selection.cursor = cursor;
775 selection.cursor = cursor;
779 cutSelection(bv, true);
786 if (!selection.set()) {
787 if (bv->owner()->getIntl().getTransManager().backspace()) {
789 selection.cursor = cursor;
791 // It is possible to make it a lot faster still
792 // just comment out the line below...
797 cutSelection(bv, true);
800 bv->owner()->view_state_changed();
804 case LFUN_BACKSPACE_SKIP:
805 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
806 if (!selection.set()) {
807 LyXCursor cur = cursor;
809 && !(cur.par()->params().spaceTop()
810 == VSpace (VSpace::NONE))) {
812 cur.par()->params().lineTop(),
813 cur.par()->params().lineBottom(),
814 cur.par()->params().pagebreakTop(),
815 cur.par()->params().pagebreakBottom(),
816 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
817 cur.par()->params().spacing(),
818 cur.par()->params().align(),
819 cur.par()->params().labelWidthString(), 0);
822 selection.cursor = cur;
826 cutSelection(bv, true);
831 case LFUN_BREAKPARAGRAPH:
832 bv->beforeChange(this);
833 breakParagraph(bv, 0);
835 selection.cursor = cursor;
837 bv->owner()->view_state_changed();
840 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
841 bv->beforeChange(this);
842 breakParagraph(bv, 1);
844 selection.cursor = cursor;
846 bv->owner()->view_state_changed();
849 case LFUN_BREAKPARAGRAPH_SKIP: {
850 // When at the beginning of a paragraph, remove
851 // indentation and add a "defskip" at the top.
852 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
853 LyXCursor cur = cursor;
854 bv->beforeChange(this);
855 if (cur.pos() == 0) {
856 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
858 cur.par()->params().lineTop(),
859 cur.par()->params().lineBottom(),
860 cur.par()->params().pagebreakTop(),
861 cur.par()->params().pagebreakBottom(),
862 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
863 cur.par()->params().spacing(),
864 cur.par()->params().align(),
865 cur.par()->params().labelWidthString(), 1);
870 breakParagraph(bv, 0);
874 selection.cursor = cur;
876 bv->owner()->view_state_changed();
880 case LFUN_PARAGRAPH_SPACING: {
881 Paragraph * par = cursor.par();
882 Spacing::Space cur_spacing = par->params().spacing().getSpace();
883 float cur_value = 1.0;
884 if (cur_spacing == Spacing::Other)
885 cur_value = par->params().spacing().getValue();
887 istringstream is(cmd.argument.c_str());
890 Spacing::Space new_spacing = cur_spacing;
891 float new_value = cur_value;
893 lyxerr << "Missing argument to `paragraph-spacing'"
895 } else if (tmp == "single") {
896 new_spacing = Spacing::Single;
897 } else if (tmp == "onehalf") {
898 new_spacing = Spacing::Onehalf;
899 } else if (tmp == "double") {
900 new_spacing = Spacing::Double;
901 } else if (tmp == "other") {
902 new_spacing = Spacing::Other;
905 lyxerr << "new_value = " << tmpval << endl;
908 } else if (tmp == "default") {
909 new_spacing = Spacing::Default;
911 lyxerr << _("Unknown spacing argument: ")
912 << cmd.argument << endl;
914 if (cur_spacing != new_spacing || cur_value != new_value) {
915 par->params().spacing(Spacing(new_spacing, new_value));
922 case LFUN_INSET_TOGGLE:
924 bv->beforeChange(this);
931 case LFUN_PROTECTEDSPACE:
932 if (cursor.par()->layout()->free_spacing) {
936 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
938 moveCursorUpdate(bv, false);
941 case LFUN_HYPHENATION:
942 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
945 case LFUN_LIGATURE_BREAK:
946 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
950 specialChar(this, bv, InsetSpecialChar::LDOTS);
956 insertChar(bv, Paragraph::META_HFILL);
960 case LFUN_END_OF_SENTENCE:
961 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
964 case LFUN_MENU_SEPARATOR:
965 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
969 bv->beforeChange(this);
971 selection.cursor = cursor;
972 cmd.message(N_("Mark off"));
976 bv->beforeChange(this);
977 selection.mark(true);
979 selection.cursor = cursor;
980 cmd.message(N_("Mark on"));
984 bv->beforeChange(this);
985 if (selection.mark()) {
987 cmd.message(N_("Mark removed"));
989 selection.mark(true);
991 cmd.message(N_("Mark set"));
993 selection.cursor = cursor;
996 case LFUN_UPCASE_WORD:
998 changeCase(bv, LyXText::text_uppercase);
1000 bv->updateInset(inset_owner, true);
1004 case LFUN_LOWCASE_WORD:
1006 changeCase(bv, LyXText::text_lowercase);
1008 bv->updateInset(inset_owner, true);
1012 case LFUN_CAPITALIZE_WORD:
1014 changeCase(bv, LyXText::text_capitalization);
1016 bv->updateInset(inset_owner, true);
1020 case LFUN_TRANSPOSE_CHARS:
1022 transposeChars(*bv);
1024 bv->updateInset(inset_owner, true);
1029 cmd.message(_("Paste"));
1031 // clear the selection
1032 bv->toggleSelection();
1036 clearSelection(); // bug 393
1045 cutSelection(bv, true);
1047 cmd.message(_("Cut"));
1052 cmd.message(_("Copy"));
1055 case LFUN_BEGINNINGBUFSEL:
1057 return UNDISPATCHED;
1060 finishChange(bv, true);
1063 case LFUN_ENDBUFSEL:
1065 return UNDISPATCHED;
1068 finishChange(bv, true);
1072 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1078 istringstream is(cmd.argument.c_str());
1081 lyxerr << "SETXY: Could not parse coordinates in '"
1082 << cmd.argument << std::endl;
1084 setCursorFromCoordinates(bv, x, y);
1089 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1091 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1097 case LFUN_GETLAYOUT:
1098 cmd.message(tostr(cursor.par()->layout()));
1102 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1103 << cmd.argument << endl;
1105 // This is not the good solution to the empty argument
1106 // problem, but it will hopefully suffice for 1.2.0.
1107 // The correct solution would be to augument the
1108 // function list/array with information about what
1109 // functions needs arguments and their type.
1110 if (cmd.argument.empty()) {
1111 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1115 // Derive layout number from given argument (string)
1116 // and current buffer's textclass (number)
1117 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1118 bool hasLayout = tclass.hasLayout(cmd.argument);
1119 string layout = cmd.argument;
1121 // If the entry is obsolete, use the new one instead.
1123 string const & obs = tclass[layout]->obsoleted_by();
1129 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1134 bool change_layout = (current_layout != layout);
1135 if (!change_layout && selection.set() &&
1136 selection.start.par() != selection.end.par())
1138 Paragraph * spar = selection.start.par();
1139 Paragraph * epar = selection.end.par()->next();
1140 while (spar != epar) {
1141 if (spar->layout()->name() != current_layout) {
1142 change_layout = true;
1145 spar = spar->next();
1148 if (change_layout) {
1150 current_layout = layout;
1152 setLayout(bv, layout);
1153 bv->owner()->setLayout(layout);
1160 case LFUN_PASTESELECTION: {
1164 // this was originally a beforeChange(bv->text), i.e
1165 // the outermost LyXText!
1166 bv->beforeChange(this);
1167 string const clip = bv->getClipboard();
1168 if (!clip.empty()) {
1169 if (cmd.argument == "paragraph")
1170 insertStringAsParagraphs(bv, clip);
1172 insertStringAsLines(bv, clip);
1179 case LFUN_GOTOERROR:
1180 gotoInset(bv, Inset::ERROR_CODE, false);
1184 gotoInset(bv, Inset::NOTE_CODE, false);
1187 case LFUN_REFERENCE_GOTO:
1189 vector<Inset::Code> tmp;
1190 tmp.push_back(Inset::LABEL_CODE);
1191 tmp.push_back(Inset::REF_CODE);
1192 gotoInset(bv, tmp, true);
1197 Paragraph const * par = cursor.par();
1198 lyx::pos_type pos = cursor.pos();
1202 else if (par->isInset(pos - 1) && par->getInset(pos - 1)->isSpace())
1205 c = par->getChar(pos - 1);
1208 LyXLayout_ptr const & style = par->layout();
1210 if (style->pass_thru ||
1211 par->getFontSettings(bv->buffer()->params,
1212 pos).language()->lang() == "hebrew" ||
1213 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1214 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1218 case LFUN_DATE_INSERT: {
1219 time_t now_time_t = time(NULL);
1220 struct tm * now_tm = localtime(&now_time_t);
1221 setlocale(LC_TIME, "");
1223 if (!cmd.argument.empty())
1226 arg = lyxrc.date_insert_format;
1228 int const datetmp_len =
1229 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1231 for (int i = 0; i < datetmp_len; i++) {
1232 insertChar(bv, datetmp[i]);
1235 selection.cursor = cursor;
1236 moveCursorUpdate(bv, false);
1240 case LFUN_MOUSE_TRIPLE:
1243 if (isTopLevel() && bv->theLockingInset())
1245 if (cmd.button() == mouse_button::button1) {
1247 bv->screen().hideCursor();
1248 bv->screen().toggleSelection(this, bv);
1251 selection.cursor = cursor;
1255 bv->screen().toggleSelection(this, bv, false);
1257 bv->haveSelection(selection.set());
1261 case LFUN_MOUSE_DOUBLE:
1264 if (isTopLevel() && bv->theLockingInset())
1266 if (cmd.button() == mouse_button::button1) {
1268 bv->screen().hideCursor();
1269 bv->screen().toggleSelection(this, bv);
1270 selectWord(bv, LyXText::WHOLE_WORD_STRICT);
1271 bv->screen().toggleSelection(this, bv, false);
1273 selectWord(bv, LyXText::WHOLE_WORD_STRICT);
1276 bv->haveSelection(selection.set());
1280 case LFUN_MOUSE_MOTION:
1282 // Only use motion with button 1
1283 //if (ev.button() != mouse_button::button1)
1289 // Check for inset locking
1290 if (bv->theLockingInset()) {
1291 Inset * tli = bv->theLockingInset();
1292 LyXCursor cursor = bv->text->cursor;
1293 LyXFont font = bv->text->getFont(bv->buffer(),
1294 cursor.par(), cursor.pos());
1295 int width = tli->width(bv, font);
1296 int inset_x = font.isVisibleRightToLeft()
1297 ? cursor.ix() - width : cursor.ix();
1298 int start_x = inset_x + tli->scroll();
1299 FuncRequest cmd1 = cmd;
1300 cmd1.x = cmd.x - start_x;
1301 cmd1.y = cmd.y - cursor.iy() + bv->text->first_y;
1302 tli->localDispatch(cmd1);
1306 // The test for not selection possible is needed, that only motion
1307 // events are used, where the bottom press event was on
1308 // the drawing area too
1309 if (!selection_possible) {
1310 lyxerr[Debug::ACTION]
1311 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1315 bv->screen().hideCursor();
1317 Row * cursorrow = bv->text->cursor.row();
1318 bv->text->setCursorFromCoordinates(bv, cmd.x, cmd.y + bv->text->first_y);
1320 // sorry for this but I have a strange error that the y value jumps at
1321 // a certain point. This seems like an error in my xforms library or
1322 // in some other local environment, but I would like to leave this here
1323 // for the moment until I can remove this (Jug 20020418)
1324 if (y_before < bv->text->cursor.y())
1325 lyxerr << y_before << ':'
1326 << bv->text->cursor.y() << endl;
1328 // This is to allow jumping over large insets
1329 if (cursorrow == bv->text->cursor.row()) {
1330 if (cmd.y >= int(bv->workHeight()))
1331 bv->text->cursorDown(bv, false);
1333 bv->text->cursorUp(bv, false);
1336 // Maybe an empty line was deleted
1337 if (!bv->text->selection.set())
1338 bv->update(bv->text, BufferView::UPDATE);
1339 bv->text->setSelection(bv);
1340 bv->screen().toggleToggle(bv->text, bv);
1346 // Single-click on work area
1347 case LFUN_MOUSE_PRESS:
1352 // ok ok, this is a hack (for xforms)
1353 // We shouldn't go further down as we really should only do the
1354 // scrolling and be done with this. Otherwise we may open some
1355 // dialogs (Jug 20020424).
1356 if (cmd.button() == mouse_button::button4) {
1357 bv->scroll(-lyxrc.wheel_jump);
1360 if (cmd.button() == mouse_button::button5) {
1361 bv->scroll(lyxrc.wheel_jump);
1367 Inset * inset_hit = bv->text->checkInsetHit(bv, x, y);
1369 // Middle button press pastes if we have a selection
1370 // We do this here as if the selection was inside an inset
1371 // it could get cleared on the unlocking of the inset so
1372 // we have to check this first
1373 bool paste_internally = false;
1374 if (cmd.button() == mouse_button::button2 && selection.set()) {
1375 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1376 paste_internally = true;
1379 int const screen_first = bv->text->first_y;
1381 if (bv->theLockingInset()) {
1382 // We are in inset locking mode
1384 // Check whether the inset was hit. If not reset mode,
1385 // otherwise give the event to the inset
1386 if (inset_hit == bv->theLockingInset()) {
1387 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1388 bv->theLockingInset()->localDispatch(cmd1);
1391 bv->unlockInset(bv->theLockingInset());
1395 selection_possible = true;
1396 bv->screen().hideCursor();
1398 // Clear the selection
1399 bv->screen().toggleSelection(bv->text, bv);
1400 bv->text->clearSelection();
1401 bv->text->fullRebreak(bv);
1403 bv->updateScrollbar();
1405 // Single left click in math inset?
1406 if (isHighlyEditableInset(inset_hit)) {
1407 // Highly editable inset, like math
1408 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1409 selection_possible = false;
1410 bv->owner()->updateLayoutChoice();
1411 bv->owner()->message(inset->editMessage());
1412 //inset->edit(bv, x, y, cmd.button());
1413 // We just have to lock the inset before calling a PressEvent on it!
1414 // we don't need the edit() call here! (Jug20020329)
1415 if (!bv->lockInset(inset))
1416 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1417 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1418 inset->localDispatch(cmd1);
1421 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1423 // Right click on a footnote flag opens float menu
1424 if (cmd.button() == mouse_button::button3) {
1425 selection_possible = false;
1429 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1430 bv->text->setCursorFromCoordinates(bv, x, y + screen_first);
1432 bv->text->selection.cursor = bv->text->cursor;
1433 bv->text->cursor.x_fix(bv->text->cursor.x());
1435 bv->owner()->updateLayoutChoice();
1436 if (bv->fitCursor())
1437 selection_possible = false;
1439 // Insert primary selection with middle mouse
1440 // if there is a local selection in the current buffer,
1442 if (cmd.button() == mouse_button::button2) {
1443 if (paste_internally)
1444 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1446 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1447 selection_possible = false;
1452 case LFUN_MOUSE_RELEASE:
1454 // do nothing if we used the mouse wheel
1458 if (cmd.button() == mouse_button::button4
1459 || cmd.button() == mouse_button::button5)
1462 // If we hit an inset, we have the inset coordinates in these
1463 // and inset_hit points to the inset. If we do not hit an
1464 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1467 Inset * inset_hit = bv->text->checkInsetHit(bv, x, y);
1469 if (bv->theLockingInset()) {
1470 // We are in inset locking mode.
1472 // LyX does a kind of work-area grabbing for insets.
1473 // Only a ButtonPress FuncRequest outside the inset will
1474 // force a insetUnlock.
1475 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1476 bv->theLockingInset()->localDispatch(cmd1);
1480 selection_possible = false;
1482 if (cmd.button() == mouse_button::button2)
1486 if (cmd.button() == mouse_button::button1)
1487 bv->haveSelection(selection.set());
1490 bv->owner()->view_state_changed();
1491 bv->owner()->updateMenubar();
1492 bv->owner()->updateToolbar();
1494 // Did we hit an editable inset?
1496 selection_possible = false;
1498 // if we reach this point with a selection, it
1499 // must mean we are currently selecting.
1500 // But we don't want to open the inset
1501 // because that is annoying for the user.
1502 // So just pretend we didn't hit it.
1503 // this is OK because a "kosher" ButtonRelease
1504 // will follow a ButtonPress that clears
1506 // Note this also fixes selection drawing
1507 // problems if we end up opening an inset
1508 if (selection.set())
1511 // CHECK fix this proper in 0.13
1512 // well, maybe 13.0 !!!!!!!!!
1514 // Following a ref shouldn't issue
1515 // a push on the undo-stack
1516 // anylonger, now that we have
1517 // keybindings for following
1518 // references and returning from
1519 // references. IMHO though, it
1520 // should be the inset's own business
1521 // to push or not push on the undo
1522 // stack. They don't *have* to
1523 // alter the document...
1525 // ...or maybe the SetCursorParUndo()
1526 // below isn't necessary at all anylonger?
1527 if (inset_hit->lyxCode() == Inset::REF_CODE)
1528 setCursorParUndo(bv);
1530 bv->owner()->message(inset_hit->editMessage());
1532 if (isHighlyEditableInset(inset_hit)) {
1533 // Highly editable inset, like math
1534 UpdatableInset * inset = (UpdatableInset *) inset_hit;
1535 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1536 inset->localDispatch(cmd1);
1538 FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1539 inset_hit->localDispatch(cmd1);
1540 // IMO this is a gross hack! Insets should be changed so that
1541 // they call the actions they have to do with the insetButtonRel.
1542 // function and not in the edit(). This should be changed
1544 #ifdef WITH_WARNINGS
1545 #warning Please remove donot call inset->edit() here (Jug 20020812)
1547 inset_hit->edit(bv, x, y, cmd.button());
1555 case LFUN_SELFINSERT: {
1556 if (cmd.argument.empty())
1559 // Automatically delete the currently selected
1560 // text and replace it with what is being
1561 // typed in now. Depends on lyxrc settings
1562 // "auto_region_delete", which defaults to
1565 if (lyxrc.auto_region_delete) {
1566 if (selection.set()) {
1567 cutSelection(bv, false, false);
1570 bv->haveSelection(false);
1573 bv->beforeChange(this);
1574 LyXFont const old_font(real_current_font);
1576 string::const_iterator cit = cmd.argument.begin();
1577 string::const_iterator end = cmd.argument.end();
1578 for (; cit != end; ++cit)
1579 bv->owner()->getIntl().getTransManager().
1580 TranslateAndInsert(*cit, this);
1583 selection.cursor = cursor;
1584 moveCursorUpdate(bv, false);
1586 // real_current_font.number can change so we need to
1587 // update the minibuffer
1588 if (old_font != real_current_font)
1589 bv->owner()->view_state_changed();
1593 case LFUN_HTMLURL: {
1594 InsetCommandParams p("htmlurl");
1595 string const data = InsetCommandMailer::params2string(p);
1596 bv->owner()->getDialogs().show("url", data, 0);
1601 InsetCommandParams p("url");
1602 string const data = InsetCommandMailer::params2string(p);
1603 bv->owner()->getDialogs().show("url", data, 0);
1609 case LFUN_INSET_LIST:
1610 case LFUN_INSET_THEOREM:
1611 case LFUN_INSET_CAPTION:
1613 case LFUN_INSERT_NOTE:
1614 case LFUN_INSERT_BIBITEM:
1615 case LFUN_INSET_ERT:
1616 case LFUN_INSET_FLOAT:
1617 case LFUN_INSET_FOOTNOTE:
1618 case LFUN_INSET_MARGINAL:
1619 case LFUN_INSET_MINIPAGE:
1620 case LFUN_INSET_OPTARG:
1621 case LFUN_INSET_WIDE_FLOAT:
1622 case LFUN_INSET_WRAP:
1623 case LFUN_TABULAR_INSERT:
1624 // Open the inset, and move the current selection
1626 doInsertInset(this, cmd, true, true);
1629 case LFUN_INSERT_URL:
1630 case LFUN_INSET_EXTERNAL:
1631 case LFUN_INDEX_INSERT:
1632 // Just open the inset
1633 doInsertInset(this, cmd, true, false);
1636 case LFUN_INDEX_PRINT:
1637 case LFUN_PARENTINSERT:
1638 case LFUN_TOC_INSERT:
1640 doInsertInset(this, cmd, false, false);
1644 return UNDISPATCHED;