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 "dispatchresult.h"
27 #include "funcrequest.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
36 #include "text_funcs.h"
40 #include "frontends/Dialogs.h"
41 #include "frontends/LyXView.h"
43 #include "insets/insetcommand.h"
44 #include "insets/insetnewline.h"
45 #include "insets/insetspecialchar.h"
46 #include "insets/insettext.h"
48 #include "support/lstrings.h"
49 #include "support/tostr.h"
50 #include "support/std_sstream.h"
52 #include "mathed/formulabase.h"
56 using bv_funcs::replaceSelection;
60 using lyx::support::isStrUnsignedInt;
61 using lyx::support::strToUnsignedInt;
66 using std::istringstream;
70 extern string current_layout;
71 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
73 // the selection possible is needed, that only motion events are
74 // used, where the bottom press event was on the drawing area too
75 bool selection_possible = false;
81 LyXFont freefont(LyXFont::ALL_IGNORE);
82 bool toggleall = false;
85 void toggleAndShow(BufferView * bv, LyXText * text,
86 LyXFont const & font, bool toggleall = true)
91 text->toggleFree(font, toggleall);
94 if (font.language() != ignore_language ||
95 font.number() != LyXFont::IGNORE) {
96 LyXCursor & cursor = text->cursor;
97 Paragraph & par = *text->cursorPar();
98 text->bidi.computeTables(par, *bv->buffer(),
99 *par.getRow(cursor.pos()));
100 if (cursor.boundary() !=
101 text->bidi.isBoundary(*bv->buffer(), par,
103 text->real_current_font))
104 text->setCursor(cursor.par(), cursor.pos(),
105 false, !cursor.boundary());
110 /// Apply the contents of freefont at the current cursor location.
111 void apply_freefont(BufferView * bv, LyXText * text)
113 toggleAndShow(bv, text, freefont, toggleall);
114 bv->owner()->view_state_changed();
115 bv->owner()->message(_("Character set"));
119 /** Set the freefont using the contents of \param data dispatched from
120 * the frontends and apply it at the current cursor location.
122 void update_and_apply_freefont(BufferView * bv, LyXText * text,
127 if (bv_funcs::string2font(data, font, toggle)) {
130 apply_freefont(bv, text);
135 void emph(BufferView * bv, LyXText * text)
137 LyXFont font(LyXFont::ALL_IGNORE);
138 font.setEmph(LyXFont::TOGGLE);
139 toggleAndShow(bv, text, font);
143 void bold(BufferView * bv, LyXText * text)
145 LyXFont font(LyXFont::ALL_IGNORE);
146 font.setSeries(LyXFont::BOLD_SERIES);
147 toggleAndShow(bv, text, font);
151 void noun(BufferView * bv, LyXText * text)
153 LyXFont font(LyXFont::ALL_IGNORE);
154 font.setNoun(LyXFont::TOGGLE);
155 toggleAndShow(bv, text, font);
159 void lang(BufferView * bv, string const & l, LyXText * text)
161 Language const * lang = languages.getLanguage(l);
165 LyXFont font(LyXFont::ALL_IGNORE);
166 font.setLanguage(lang);
167 toggleAndShow(bv, text, font);
171 void code(BufferView * bv, LyXText * text)
173 LyXFont font(LyXFont::ALL_IGNORE);
174 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
175 toggleAndShow(bv, text, font);
179 void sans(BufferView * bv, LyXText * text)
181 LyXFont font(LyXFont::ALL_IGNORE);
182 font.setFamily(LyXFont::SANS_FAMILY);
183 toggleAndShow(bv, text, font);
187 void roman(BufferView * bv, LyXText * text)
189 LyXFont font(LyXFont::ALL_IGNORE);
190 font.setFamily(LyXFont::ROMAN_FAMILY);
191 toggleAndShow(bv, text, font);
195 void styleReset(BufferView * bv, LyXText * text)
197 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
198 toggleAndShow(bv, text, font);
202 void underline(BufferView * bv, LyXText * text)
204 LyXFont font(LyXFont::ALL_IGNORE);
205 font.setUnderbar(LyXFont::TOGGLE);
206 toggleAndShow(bv, text, font);
210 void fontSize(BufferView * bv, string const & size, LyXText * text)
212 LyXFont font(LyXFont::ALL_IGNORE);
213 font.setLyXSize(size);
214 toggleAndShow(bv, text, font);
218 void moveCursorUpdate(BufferView * bv, bool selecting)
220 LyXText * lt = bv->getLyXText();
222 // if (!lt->selection.set())
223 // lt->selection.cursor = lt->cursor;
225 if (selecting || lt->selection.mark())
228 if (!lt->selection.set())
229 bv->haveSelection(false);
236 void finishChange(BufferView * bv, bool selecting = false)
239 moveCursorUpdate(bv, selecting);
240 bv->owner()->view_state_changed();
248 string const freefont2string()
251 if (font2string(freefont, toggleall, data))
260 InsetOld * LyXText::checkInsetHit(int x, int y)
262 ParagraphList::iterator pit;
263 ParagraphList::iterator end;
265 getParsInRange(ownerParagraphs(),
266 bv()->top_y(), bv()->top_y() + bv()->workHeight(),
269 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
270 for ( ; pit != end; ++pit) {
271 InsetList::iterator iit = pit->insetlist.begin();
272 InsetList::iterator iend = pit->insetlist.end();
273 for ( ; iit != iend; ++iit) {
274 InsetOld * inset = iit->inset;
275 //lyxerr << "examining inset " << inset
276 // << " xy: " << inset->x() << "/" << inset->y()
277 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
278 // << " y: " << inset->y() - inset->ascent() << "..."
279 // << inset->y() + inset->descent()
282 && x <= inset->x() + inset->width()
283 && y >= inset->y() - inset->ascent()
284 && y <= inset->y() + inset->descent())
286 lyxerr << "Hit inset: " << inset << endl;
291 lyxerr << "No inset hit. " << endl;
296 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
297 string const & contents)
299 ParagraphList::iterator end = ownerParagraphs().end();
300 ParagraphList::iterator pit = cursorPar();
301 pos_type pos = cursor.pos();
305 if (pos + 1 < pit->size()) {
312 } while (pit != end &&
313 !(pit->isInset(pos) &&
314 (inset = pit->getInset(pos)) != 0 &&
315 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
317 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
323 setCursor(parOffset(pit), pos, false);
328 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
334 if (same_content && cursor.pos() < cursorPar()->size()
335 && cursorPar()->isInset(cursor.pos())) {
336 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
337 if (find(codes.begin(), codes.end(), inset->lyxCode())
339 contents = static_cast<InsetCommand const *>(inset)->getContents();
342 if (!gotoNextInset(codes, contents)) {
343 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
344 LyXCursor tmp = cursor;
347 if (!gotoNextInset(codes, contents)) {
349 bv()->owner()->message(_("No more insets"));
352 bv()->owner()->message(_("No more insets"));
356 selection.cursor = cursor;
360 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
362 gotoInset(vector<InsetOld::Code>(1, code), same_content);
366 void LyXText::cursorPrevious()
368 int y = bv()->top_y();
370 ParagraphList::iterator cpit = cursorPar();
371 RowList::iterator crit = cpit->getRow(cursor.pos());
373 if (isFirstRow(cpit, *crit)) {
375 bv()->updateScrollbar();
379 setCursorFromCoordinates(bv()->x_target(), y);
382 if (crit == bv()->text->cursorRow()) {
383 // we have a row which is taller than the workarea. The
384 // simplest solution is to move to the previous row instead.
389 int new_y = + crit->height() - bv()->workHeight() + 1;
392 new_y += bv()->text->cursor.y()
393 + bv()->cursor().innerInset()->insetInInsetY()
396 new_y += cursor.y() - crit->baseline();
399 previousRow(cpit, crit);
401 setCursor(cur, parOffset(cpit), crit->pos(), false);
402 if (cur.y() > bv()->top_y())
404 bv()->updateScrollbar();
408 void LyXText::cursorNext()
410 int topy = bv()->top_y();
412 ParagraphList::iterator cpit = cursorPar();
413 RowList::iterator crit = cpit->getRow(cursor.pos());
415 if (isLastRow(cpit, *crit)) {
416 int y = cursor.y() - crit->baseline() + crit->height();
417 if (y > topy + bv()->workHeight())
418 bv()->updateScrollbar();
422 int y = topy + bv()->workHeight();
423 if (inset_owner && !topy) {
424 y += - bv()->text->cursor.y()
426 - bv()->cursor().innerInset()->insetInInsetY();
429 ParagraphList::iterator dummypit;
430 Row const & row = *getRowNearY(y, dummypit);
431 y = dummypit->y + row.y_offset();
433 setCursorFromCoordinates(bv()->x_target(), y);
434 // + bv->workHeight());
438 if (crit == bv()->text->cursorRow()) {
439 // we have a row which is taller than the workarea. The
440 // simplest solution is to move to the next row instead.
443 // This is what we used to do, so we wouldn't skip right past
444 // tall rows, but it's not working right now.
446 new_y = bv->top_y() + bv->workHeight();
451 new_y = bv()->text->cursor.y()
452 + bv()->cursor().innerInset()->insetInInsetY()
453 + y - crit->baseline();
455 new_y = cursor.y() - crit->baseline();
461 setCursor(cur, parOffset(cpit), crit->pos(), false);
462 if (cur.y() < bv()->top_y() + bv()->workHeight())
464 bv()->updateScrollbar();
470 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
473 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
474 replaceSelection(lt);
475 if (!bv->insertInset(new_inset))
482 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
483 bool edit, bool pastesel)
485 InsetOld * inset = createInset(cmd);
486 BufferView * bv = cmd.view();
490 if (lt->selection.set()) {
491 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
494 if (bv->insertInset(inset)) {
496 inset->edit(bv, true);
497 if (gotsel && pastesel)
498 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
508 void LyXText::number()
510 LyXFont font(LyXFont::ALL_IGNORE);
511 font.setNumber(LyXFont::TOGGLE);
512 toggleAndShow(bv(), this, font);
516 bool LyXText::rtl() const
518 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
522 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
524 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
525 lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
527 BufferView * bv = cmd.view();
529 switch (cmd.action) {
531 case LFUN_APPENDIX: {
532 ParagraphList::iterator pit = cursorPar();
533 bool start = !pit->params().startOfAppendix();
535 // ensure that we have only one start_of_appendix in this document
536 ParagraphList::iterator tmp = ownerParagraphs().begin();
537 ParagraphList::iterator end = ownerParagraphs().end();
539 for (; tmp != end; ++tmp) {
540 if (tmp->params().startOfAppendix()) {
541 recUndo(parOffset(tmp));
542 tmp->params().startOfAppendix(false);
548 recUndo(parOffset(pit));
549 pit->params().startOfAppendix(start);
551 // we can set the refreshing parameters now
553 redoParagraph(cursorPar());
554 setCursor(cursorPar(), cursor.pos());
559 case LFUN_DELETE_WORD_FORWARD:
565 case LFUN_DELETE_WORD_BACKWARD:
567 deleteWordBackward();
571 case LFUN_DELETE_LINE_FORWARD:
578 if (!selection.mark())
583 cursorRightOneWord();
588 if (!selection.mark())
591 cursorRightOneWord();
597 case LFUN_BEGINNINGBUF:
598 if (!selection.mark())
605 if (selection.mark())
612 if (!selection.set())
613 selection.cursor = cursor;
618 finishChange(bv, true);
622 if (!selection.set())
623 selection.cursor = cursor;
628 finishChange(bv, true);
632 if (!selection.set())
633 selection.cursor = cursor;
635 finishChange(bv, true);
639 if (!selection.set())
640 selection.cursor = cursor;
642 finishChange(bv, true);
645 case LFUN_UP_PARAGRAPHSEL:
646 if (!selection.set())
647 selection.cursor = cursor;
649 finishChange(bv, true);
652 case LFUN_DOWN_PARAGRAPHSEL:
653 if (!selection.set())
654 selection.cursor = cursor;
655 cursorDownParagraph();
656 finishChange(bv, true);
660 if (!selection.set())
661 selection.cursor = cursor;
663 finishChange(bv, true);
667 if (!selection.set())
668 selection.cursor = cursor;
670 finishChange(bv, true);
674 if (!selection.set())
675 selection.cursor = cursor;
677 finishChange(bv, true);
681 if (!selection.set())
682 selection.cursor = cursor;
684 finishChange(bv, true);
687 case LFUN_WORDRIGHTSEL:
691 cursorRightOneWord();
692 finishChange(bv, true);
695 case LFUN_WORDLEFTSEL:
697 cursorRightOneWord();
700 finishChange(bv, true);
704 LyXCursor cur1 = cursor;
706 ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
707 setCursor(cur1.par(), cur1.pos());
709 setCursor(cur2.par(), cur2.pos());
710 finishChange(bv, true);
716 if (!selection.mark())
720 if (cursor.pos() < cursorPar()->size()
721 && cursorPar()->isInset(cursor.pos())
722 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
723 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
724 cmd.message(tmpinset->editMessage());
725 tmpinset->edit(bv, !is_rtl);
735 // This is soooo ugly. Isn't it possible to make
737 bool const is_rtl = rtl();
738 if (!selection.mark())
740 LyXCursor const cur = cursor;
743 if ((is_rtl || cur != cursor) && // only if really moved!
744 cursor.pos() < cursorPar()->size() &&
745 cursorPar()->isInset(cursor.pos()) &&
746 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
747 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
748 cmd.message(tmpinset->editMessage());
749 tmpinset->edit(bv, is_rtl);
759 if (!selection.mark())
766 if (!selection.mark())
772 case LFUN_UP_PARAGRAPH:
773 if (!selection.mark())
779 case LFUN_DOWN_PARAGRAPH:
780 if (!selection.mark())
782 cursorDownParagraph();
783 finishChange(bv, false);
787 if (!selection.mark())
790 finishChange(bv, false);
794 if (!selection.mark())
797 finishChange(bv, false);
801 if (!selection.mark())
804 finishChange(bv, false);
808 if (!selection.mark())
811 finishChange(bv, false);
814 case LFUN_BREAKLINE: {
815 lyx::pos_type body = cursorPar()->beginningOfBody();
817 // Not allowed by LaTeX (labels or empty par)
818 if (cursor.pos() <= body)
821 replaceSelection(bv->getLyXText());
822 insertInset(new InsetNewline);
823 setCursor(cursorPar(), cursor.pos());
824 moveCursorUpdate(bv, false);
829 if (!selection.set()) {
831 selection.cursor = cursor;
832 // It is possible to make it a lot faster still
833 // just comment out the line below...
835 cutSelection(true, false);
837 moveCursorUpdate(bv, false);
838 bv->owner()->view_state_changed();
841 case LFUN_DELETE_SKIP:
842 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
843 if (!selection.set()) {
844 if (cursor.pos() == cursorPar()->size()) {
846 ParagraphParameters & params = cursorPar()->params();
847 if (cursor.pos() == 0
848 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
850 VSpace(VSpace::NONE),
851 params.spaceBottom(),
854 params.labelWidthString(), 0);
859 selection.cursor = cursor;
863 selection.cursor = cursor;
866 cutSelection(true, false);
873 if (!selection.set()) {
874 if (bv->owner()->getIntl().getTransManager().backspace()) {
876 selection.cursor = cursor;
877 // It is possible to make it a lot faster still
878 // just comment out the line below...
881 cutSelection(true, false);
883 bv->owner()->view_state_changed();
888 case LFUN_BACKSPACE_SKIP:
889 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
890 if (!selection.set()) {
891 ParagraphParameters & params = cursorPar()->params();
892 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
894 VSpace(VSpace::NONE),
895 params.spaceBottom(),
898 params.labelWidthString(), 0);
900 LyXCursor cur = cursor;
902 selection.cursor = cur;
905 cutSelection(true, false);
910 case LFUN_BREAKPARAGRAPH:
911 replaceSelection(bv->getLyXText());
912 breakParagraph(bv->buffer()->paragraphs(), 0);
914 selection.cursor = cursor;
916 bv->owner()->view_state_changed();
919 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
920 replaceSelection(bv->getLyXText());
921 breakParagraph(bv->buffer()->paragraphs(), 1);
923 selection.cursor = cursor;
925 bv->owner()->view_state_changed();
928 case LFUN_BREAKPARAGRAPH_SKIP: {
929 // When at the beginning of a paragraph, remove
930 // indentation and add a "defskip" at the top.
931 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
932 LyXCursor cur = cursor;
933 replaceSelection(bv->getLyXText());
934 if (cur.pos() == 0) {
935 ParagraphParameters & params = getPar(cur)->params();
936 if (params.spaceTop() == VSpace(VSpace::NONE)) {
938 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
941 params.labelWidthString(), 1);
945 breakParagraph(bv->buffer()->paragraphs(), 0);
948 selection.cursor = cur;
950 bv->owner()->view_state_changed();
954 case LFUN_PARAGRAPH_SPACING: {
955 ParagraphList::iterator pit = cursorPar();
956 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
957 float cur_value = 1.0;
958 if (cur_spacing == Spacing::Other)
959 cur_value = pit->params().spacing().getValue();
961 istringstream is(cmd.argument);
964 Spacing::Space new_spacing = cur_spacing;
965 float new_value = cur_value;
967 lyxerr << "Missing argument to `paragraph-spacing'"
969 } else if (tmp == "single") {
970 new_spacing = Spacing::Single;
971 } else if (tmp == "onehalf") {
972 new_spacing = Spacing::Onehalf;
973 } else if (tmp == "double") {
974 new_spacing = Spacing::Double;
975 } else if (tmp == "other") {
976 new_spacing = Spacing::Other;
979 lyxerr << "new_value = " << tmpval << endl;
982 } else if (tmp == "default") {
983 new_spacing = Spacing::Default;
985 lyxerr << _("Unknown spacing argument: ")
986 << cmd.argument << endl;
988 if (cur_spacing != new_spacing || cur_value != new_value) {
989 pit->params().spacing(Spacing(new_spacing, new_value));
996 case LFUN_INSET_SETTINGS:
997 bv->cursor().innerInset()->showInsetDialog(bv);
1000 case LFUN_INSET_TOGGLE:
1007 case LFUN_SPACE_INSERT:
1008 if (cursorPar()->layout()->free_spacing)
1011 doInsertInset(this, cmd, false, false);
1012 moveCursorUpdate(bv, false);
1015 case LFUN_HYPHENATION:
1016 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
1019 case LFUN_LIGATURE_BREAK:
1020 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
1024 specialChar(this, bv, InsetSpecialChar::LDOTS);
1027 case LFUN_END_OF_SENTENCE:
1028 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
1031 case LFUN_MENU_SEPARATOR:
1032 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
1038 selection.cursor = cursor;
1039 cmd.message(N_("Mark off"));
1044 selection.mark(true);
1046 selection.cursor = cursor;
1047 cmd.message(N_("Mark on"));
1052 if (selection.mark()) {
1053 cmd.message(N_("Mark removed"));
1055 selection.mark(true);
1056 cmd.message(N_("Mark set"));
1058 selection.cursor = cursor;
1062 case LFUN_UPCASE_WORD:
1063 changeCase(LyXText::text_uppercase);
1067 case LFUN_LOWCASE_WORD:
1068 changeCase(LyXText::text_lowercase);
1072 case LFUN_CAPITALIZE_WORD:
1073 changeCase(LyXText::text_capitalization);
1077 case LFUN_TRANSPOSE_CHARS:
1078 recUndo(cursor.par());
1084 cmd.message(_("Paste"));
1085 replaceSelection(bv->getLyXText());
1086 #warning FIXME Check if the arg is in the domain of available selections.
1087 if (isStrUnsignedInt(cmd.argument))
1088 pasteSelection(strToUnsignedInt(cmd.argument));
1091 clearSelection(); // bug 393
1098 cutSelection(true, true);
1099 cmd.message(_("Cut"));
1105 cmd.message(_("Copy"));
1108 case LFUN_BEGINNINGBUFSEL:
1110 return DispatchResult(false);
1112 finishChange(bv, true);
1115 case LFUN_ENDBUFSEL:
1117 return DispatchResult(false);
1119 finishChange(bv, true);
1123 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1129 istringstream is(cmd.argument);
1132 lyxerr << "SETXY: Could not parse coordinates in '"
1133 << cmd.argument << std::endl;
1135 setCursorFromCoordinates(x, y);
1140 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1142 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1148 case LFUN_GETLAYOUT:
1149 cmd.message(tostr(cursorPar()->layout()));
1153 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1154 << cmd.argument << endl;
1156 // This is not the good solution to the empty argument
1157 // problem, but it will hopefully suffice for 1.2.0.
1158 // The correct solution would be to augument the
1159 // function list/array with information about what
1160 // functions needs arguments and their type.
1161 if (cmd.argument.empty()) {
1162 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1166 // Derive layout number from given argument (string)
1167 // and current buffer's textclass (number)
1168 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1169 bool hasLayout = tclass.hasLayout(cmd.argument);
1170 string layout = cmd.argument;
1172 // If the entry is obsolete, use the new one instead.
1174 string const & obs = tclass[layout]->obsoleted_by();
1180 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1185 bool change_layout = (current_layout != layout);
1187 if (!change_layout && selection.set() &&
1188 selection.start.par() != selection.end.par())
1190 ParagraphList::iterator spit = getPar(selection.start);
1191 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1192 while (spit != epit) {
1193 if (spit->layout()->name() != current_layout) {
1194 change_layout = true;
1201 if (change_layout) {
1202 current_layout = layout;
1204 bv->owner()->setLayout(layout);
1211 case LFUN_PASTESELECTION: {
1212 // this was originally a bv->text->clearSelection(), i.e
1213 // the outermost LyXText!
1215 string const clip = bv->getClipboard();
1216 if (!clip.empty()) {
1217 if (cmd.argument == "paragraph")
1218 insertStringAsParagraphs(clip);
1220 insertStringAsLines(clip);
1226 case LFUN_GOTOERROR:
1227 gotoInset(InsetOld::ERROR_CODE, false);
1231 gotoInset(InsetOld::NOTE_CODE, false);
1234 case LFUN_REFERENCE_GOTO:
1236 vector<InsetOld::Code> tmp;
1237 tmp.push_back(InsetOld::LABEL_CODE);
1238 tmp.push_back(InsetOld::REF_CODE);
1239 gotoInset(tmp, true);
1244 replaceSelection(bv->getLyXText());
1245 ParagraphList::iterator pit = cursorPar();
1246 lyx::pos_type pos = cursor.pos();
1250 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1253 c = pit->getChar(pos - 1);
1255 LyXLayout_ptr const & style = pit->layout();
1257 BufferParams const & bufparams = bv->buffer()->params();
1258 if (style->pass_thru ||
1259 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1260 !bv->insertInset(new InsetQuotes(c, bufparams)))
1261 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1265 case LFUN_DATE_INSERT: {
1266 replaceSelection(bv->getLyXText());
1267 time_t now_time_t = time(NULL);
1268 struct tm * now_tm = localtime(&now_time_t);
1269 setlocale(LC_TIME, "");
1271 if (!cmd.argument.empty())
1274 arg = lyxrc.date_insert_format;
1276 int const datetmp_len =
1277 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1279 for (int i = 0; i < datetmp_len; i++)
1280 insertChar(datetmp[i]);
1282 selection.cursor = cursor;
1283 moveCursorUpdate(bv, false);
1287 case LFUN_MOUSE_TRIPLE:
1290 if (cmd.button() == mouse_button::button1) {
1292 selection.cursor = cursor;
1296 bv->haveSelection(selection.set());
1300 case LFUN_MOUSE_DOUBLE:
1303 if (cmd.button() == mouse_button::button1) {
1304 selectWord(lyx::WHOLE_WORD_STRICT);
1306 bv->haveSelection(selection.set());
1310 case LFUN_MOUSE_MOTION: {
1311 // Only use motion with button 1
1312 //if (ev.button() != mouse_button::button1)
1318 // Check for inset locking
1320 if (bv->innerInset()) {
1321 InsetOld * tli = bv->innerInset();
1322 LyXCursor cursor = bv->text->cursor;
1323 LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1324 int width = tli->width();
1325 int inset_x = font.isVisibleRightToLeft()
1326 ? cursor.x() - width : cursor.x();
1327 int start_x = inset_x + tli->scroll();
1328 FuncRequest cmd1 = cmd;
1329 cmd1.x = cmd.x - start_x;
1330 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1331 tli->dispatch(cmd1);
1336 // The test for not selection possible is needed, that only motion
1337 // events are used, where the bottom press event was on
1338 // the drawing area too
1339 if (!selection_possible) {
1340 lyxerr[Debug::ACTION]
1341 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1345 RowList::iterator cursorrow = bv->text->cursorRow();
1346 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1348 // sorry for this but I have a strange error that the y value jumps at
1349 // a certain point. This seems like an error in my xforms library or
1350 // in some other local environment, but I would like to leave this here
1351 // for the moment until I can remove this (Jug 20020418)
1352 if (y_before < bv->text->cursor.y())
1353 lyxerr << y_before << ':'
1354 << bv->text->cursor.y() << endl;
1356 // This is to allow jumping over large insets
1357 if (cursorrow == bv->text->cursorRow()) {
1358 if (cmd.y >= bv->workHeight())
1359 bv->text->cursorDown(false);
1361 bv->text->cursorUp(false);
1364 bv->text->setSelection();
1369 // Single-click on work area
1370 case LFUN_MOUSE_PRESS: {
1374 // ok ok, this is a hack (for xforms)
1375 // We shouldn't go further down as we really should only do the
1376 // scrolling and be done with this. Otherwise we may open some
1377 // dialogs (Jug 20020424).
1378 if (cmd.button() == mouse_button::button4) {
1379 bv->scroll(-lyxrc.wheel_jump);
1382 if (cmd.button() == mouse_button::button5) {
1383 bv->scroll(lyxrc.wheel_jump);
1387 // Middle button press pastes if we have a selection
1388 // We do this here as if the selection was inside an inset
1389 // it could get cleared on the unlocking of the inset so
1390 // we have to check this first
1391 bool paste_internally = false;
1392 if (cmd.button() == mouse_button::button2 && selection.set()) {
1393 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1394 paste_internally = true;
1397 int const screen_first = bv->top_y();
1398 selection_possible = true;
1400 // Clear the selection
1401 bv->text->clearSelection();
1403 bv->updateScrollbar();
1405 // Right click on a footnote flag opens float menu
1406 if (cmd.button() == mouse_button::button3) {
1407 selection_possible = false;
1411 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first);
1413 bv->text->selection.cursor = bv->text->cursor;
1414 bv->x_target(bv->text->cursor.x());
1416 if (bv->fitCursor())
1417 selection_possible = false;
1419 // Insert primary selection with middle mouse
1420 // if there is a local selection in the current buffer,
1422 if (cmd.button() == mouse_button::button2) {
1423 if (paste_internally)
1424 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1426 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1427 selection_possible = false;
1432 case LFUN_MOUSE_RELEASE: {
1433 // do nothing if we used the mouse wheel
1437 if (cmd.button() == mouse_button::button4
1438 || cmd.button() == mouse_button::button5)
1441 selection_possible = false;
1443 if (cmd.button() == mouse_button::button2)
1447 if (cmd.button() == mouse_button::button1)
1448 bv->haveSelection(selection.set());
1451 bv->owner()->view_state_changed();
1452 bv->owner()->updateMenubar();
1453 bv->owner()->updateToolbar();
1457 case LFUN_SELFINSERT: {
1458 if (cmd.argument.empty())
1461 // Automatically delete the currently selected
1462 // text and replace it with what is being
1463 // typed in now. Depends on lyxrc settings
1464 // "auto_region_delete", which defaults to
1467 if (lyxrc.auto_region_delete) {
1468 if (selection.set())
1469 cutSelection(false, false);
1470 bv->haveSelection(false);
1474 LyXFont const old_font = real_current_font;
1476 string::const_iterator cit = cmd.argument.begin();
1477 string::const_iterator end = cmd.argument.end();
1478 for (; cit != end; ++cit)
1479 bv->owner()->getIntl().getTransManager().
1480 TranslateAndInsert(*cit, this);
1482 selection.cursor = cursor;
1483 moveCursorUpdate(bv, false);
1485 // real_current_font.number can change so we need to
1486 // update the minibuffer
1487 if (old_font != real_current_font)
1488 bv->owner()->view_state_changed();
1489 bv->updateScrollbar();
1493 case LFUN_HTMLURL: {
1494 InsetCommandParams p("htmlurl");
1495 string const data = InsetCommandMailer::params2string("url", p);
1496 bv->owner()->getDialogs().show("url", data, 0);
1501 InsetCommandParams p("url");
1502 string const data = InsetCommandMailer::params2string("url", p);
1503 bv->owner()->getDialogs().show("url", data, 0);
1509 case LFUN_INSET_LIST:
1510 case LFUN_INSET_THEOREM:
1511 case LFUN_INSET_CAPTION:
1513 case LFUN_INSERT_NOTE:
1514 case LFUN_INSERT_BOX:
1515 case LFUN_INSERT_BRANCH:
1516 case LFUN_INSERT_BIBITEM:
1517 case LFUN_INSET_ERT:
1518 case LFUN_INSET_FLOAT:
1519 case LFUN_INSET_FOOTNOTE:
1520 case LFUN_INSET_MARGINAL:
1521 case LFUN_INSET_MINIPAGE:
1522 case LFUN_INSET_OPTARG:
1523 case LFUN_INSET_WIDE_FLOAT:
1524 case LFUN_INSET_WRAP:
1525 case LFUN_TABULAR_INSERT:
1526 case LFUN_ENVIRONMENT_INSERT:
1527 // Open the inset, and move the current selection
1529 doInsertInset(this, cmd, true, true);
1532 case LFUN_INDEX_INSERT:
1533 // Just open the inset
1534 doInsertInset(this, cmd, true, false);
1537 case LFUN_INDEX_PRINT:
1538 case LFUN_TOC_INSERT:
1540 case LFUN_INSERT_LINE:
1541 case LFUN_INSERT_PAGEBREAK:
1543 doInsertInset(this, cmd, false, false);
1546 case LFUN_DEPTH_MIN:
1548 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1552 case LFUN_DEPTH_PLUS:
1554 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1558 case LFUN_MATH_DELIM:
1559 case LFUN_MATH_DISPLAY:
1560 case LFUN_INSERT_MATH:
1561 case LFUN_MATH_LIMITS:
1562 case LFUN_MATH_MACRO:
1563 case LFUN_MATH_MUTATE:
1564 case LFUN_MATH_SPACE:
1565 case LFUN_MATH_IMPORT_SELECTION:
1566 case LFUN_MATH_MODE:
1567 case LFUN_MATH_NONUMBER:
1568 case LFUN_MATH_NUMBER:
1569 case LFUN_MATH_EXTERN:
1570 case LFUN_MATH_SIZE:
1576 bv->owner()->view_state_changed();
1581 bv->owner()->view_state_changed();
1586 bv->owner()->view_state_changed();
1591 bv->owner()->view_state_changed();
1596 bv->owner()->view_state_changed();
1601 bv->owner()->view_state_changed();
1605 styleReset(bv, this);
1606 bv->owner()->view_state_changed();
1609 case LFUN_UNDERLINE:
1610 underline(bv, this);
1611 bv->owner()->view_state_changed();
1614 case LFUN_FONT_SIZE:
1615 fontSize(bv, cmd.argument, this);
1616 bv->owner()->view_state_changed();
1620 lang(bv, cmd.argument, this);
1622 bv->owner()->view_state_changed();
1625 case LFUN_FREEFONT_APPLY:
1626 apply_freefont(bv, this);
1629 case LFUN_FREEFONT_UPDATE:
1630 update_and_apply_freefont(bv, this, cmd.argument);
1633 case LFUN_FINISHED_LEFT:
1634 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1639 case LFUN_FINISHED_RIGHT:
1640 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1645 case LFUN_FINISHED_UP:
1646 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1649 case LFUN_FINISHED_DOWN:
1650 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1655 return DispatchResult(false);
1658 return DispatchResult(true, true);