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"
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
51 #include "mathed/formulabase.h"
55 using bv_funcs::replaceSelection;
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
65 using std::istringstream;
69 extern string current_layout;
70 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
72 // the selection possible is needed, that only motion events are
73 // used, where the bottom press event was on the drawing area too
74 bool selection_possible = false;
80 LyXFont freefont(LyXFont::ALL_IGNORE);
81 bool toggleall = false;
84 void toggleAndShow(BufferView * bv, LyXText * text,
85 LyXFont const & font, bool toggleall = true)
90 text->toggleFree(font, toggleall);
93 if (font.language() != ignore_language ||
94 font.number() != LyXFont::IGNORE) {
95 LyXCursor & cursor = text->cursor;
96 Paragraph & par = *text->cursorPar();
97 text->bidi.computeTables(par, *bv->buffer(),
98 *par.getRow(cursor.pos()));
99 if (cursor.boundary() !=
100 text->bidi.isBoundary(*bv->buffer(), par,
102 text->real_current_font))
103 text->setCursor(cursor.par(), cursor.pos(),
104 false, !cursor.boundary());
109 /// Apply the contents of freefont at the current cursor location.
110 void apply_freefont(BufferView * bv, LyXText * text)
112 toggleAndShow(bv, text, freefont, toggleall);
113 bv->owner()->view_state_changed();
114 bv->owner()->message(_("Character set"));
118 /** Set the freefont using the contents of \param data dispatched from
119 * the frontends and apply it at the current cursor location.
121 void update_and_apply_freefont(BufferView * bv, LyXText * text,
126 if (bv_funcs::string2font(data, font, toggle)) {
129 apply_freefont(bv, text);
134 void emph(BufferView * bv, LyXText * text)
136 LyXFont font(LyXFont::ALL_IGNORE);
137 font.setEmph(LyXFont::TOGGLE);
138 toggleAndShow(bv, text, font);
142 void bold(BufferView * bv, LyXText * text)
144 LyXFont font(LyXFont::ALL_IGNORE);
145 font.setSeries(LyXFont::BOLD_SERIES);
146 toggleAndShow(bv, text, font);
150 void noun(BufferView * bv, LyXText * text)
152 LyXFont font(LyXFont::ALL_IGNORE);
153 font.setNoun(LyXFont::TOGGLE);
154 toggleAndShow(bv, text, font);
158 void lang(BufferView * bv, string const & l, LyXText * text)
160 Language const * lang = languages.getLanguage(l);
164 LyXFont font(LyXFont::ALL_IGNORE);
165 font.setLanguage(lang);
166 toggleAndShow(bv, text, font);
170 void code(BufferView * bv, LyXText * text)
172 LyXFont font(LyXFont::ALL_IGNORE);
173 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
174 toggleAndShow(bv, text, font);
178 void sans(BufferView * bv, LyXText * text)
180 LyXFont font(LyXFont::ALL_IGNORE);
181 font.setFamily(LyXFont::SANS_FAMILY);
182 toggleAndShow(bv, text, font);
186 void roman(BufferView * bv, LyXText * text)
188 LyXFont font(LyXFont::ALL_IGNORE);
189 font.setFamily(LyXFont::ROMAN_FAMILY);
190 toggleAndShow(bv, text, font);
194 void styleReset(BufferView * bv, LyXText * text)
196 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
197 toggleAndShow(bv, text, font);
201 void underline(BufferView * bv, LyXText * text)
203 LyXFont font(LyXFont::ALL_IGNORE);
204 font.setUnderbar(LyXFont::TOGGLE);
205 toggleAndShow(bv, text, font);
209 void fontSize(BufferView * bv, string const & size, LyXText * text)
211 LyXFont font(LyXFont::ALL_IGNORE);
212 font.setLyXSize(size);
213 toggleAndShow(bv, text, font);
217 void moveCursorUpdate(BufferView * bv, bool selecting)
219 LyXText * lt = bv->getLyXText();
221 // if (!lt->selection.set())
222 // lt->selection.cursor = lt->cursor;
224 if (selecting || lt->selection.mark())
227 if (!lt->selection.set())
228 bv->haveSelection(false);
235 void finishChange(BufferView * bv, bool selecting = false)
238 moveCursorUpdate(bv, selecting);
239 bv->owner()->view_state_changed();
247 string const freefont2string()
250 if (font2string(freefont, toggleall, data))
259 InsetOld * LyXText::checkInsetHit(int x, int y)
261 ParagraphList::iterator pit;
262 ParagraphList::iterator end;
264 getParsInRange(ownerParagraphs(),
265 bv()->top_y(), bv()->top_y() + bv()->workHeight(),
268 lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
269 for ( ; pit != end; ++pit) {
270 InsetList::iterator iit = pit->insetlist.begin();
271 InsetList::iterator iend = pit->insetlist.end();
272 for ( ; iit != iend; ++iit) {
273 InsetOld * inset = iit->inset;
274 //lyxerr << "examining inset " << inset
275 // << " xy: " << inset->x() << "/" << inset->y()
276 // << " x: " << inset->x() << "..." << inset->x() + inset->width()
277 // << " y: " << inset->y() - inset->ascent() << "..."
278 // << inset->y() + inset->descent()
281 && x <= inset->x() + inset->width()
282 && y >= inset->y() - inset->ascent()
283 && y <= inset->y() + inset->descent())
285 lyxerr << "Hit inset: " << inset << endl;
290 lyxerr << "No inset hit. " << endl;
295 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
296 string const & contents)
298 ParagraphList::iterator end = ownerParagraphs().end();
299 ParagraphList::iterator pit = cursorPar();
300 pos_type pos = cursor.pos();
304 if (pos + 1 < pit->size()) {
311 } while (pit != end &&
312 !(pit->isInset(pos) &&
313 (inset = pit->getInset(pos)) != 0 &&
314 find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
316 static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
322 setCursor(parOffset(pit), pos, false);
327 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
333 if (same_content && cursor.pos() < cursorPar()->size()
334 && cursorPar()->isInset(cursor.pos())) {
335 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
336 if (find(codes.begin(), codes.end(), inset->lyxCode())
338 contents = static_cast<InsetCommand const *>(inset)->getContents();
341 if (!gotoNextInset(codes, contents)) {
342 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
343 LyXCursor tmp = cursor;
346 if (!gotoNextInset(codes, contents)) {
348 bv()->owner()->message(_("No more insets"));
351 bv()->owner()->message(_("No more insets"));
355 selection.cursor = cursor;
359 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
361 gotoInset(vector<InsetOld::Code>(1, code), same_content);
365 void LyXText::cursorPrevious()
367 int y = bv()->top_y();
369 ParagraphList::iterator cpit = cursorPar();
370 RowList::iterator crit = cpit->getRow(cursor.pos());
372 if (isFirstRow(cpit, *crit)) {
374 bv()->updateScrollbar();
378 setCursorFromCoordinates(bv()->x_target(), y);
381 if (crit == bv()->text->cursorRow()) {
382 // we have a row which is taller than the workarea. The
383 // simplest solution is to move to the previous row instead.
388 int new_y = + crit->height() - bv()->workHeight() + 1;
391 new_y += bv()->text->cursor.y()
392 + bv()->cursor().innerInset()->insetInInsetY()
395 new_y += cursor.y() - crit->baseline();
398 previousRow(cpit, crit);
400 setCursor(cur, parOffset(cpit), crit->pos(), false);
401 if (cur.y() > bv()->top_y())
403 bv()->updateScrollbar();
407 void LyXText::cursorNext()
409 int topy = bv()->top_y();
411 ParagraphList::iterator cpit = cursorPar();
412 RowList::iterator crit = cpit->getRow(cursor.pos());
414 if (isLastRow(cpit, *crit)) {
415 int y = cursor.y() - crit->baseline() + crit->height();
416 if (y > topy + bv()->workHeight())
417 bv()->updateScrollbar();
421 int y = topy + bv()->workHeight();
422 if (inset_owner && !topy) {
423 y += - bv()->text->cursor.y()
425 - bv()->cursor().innerInset()->insetInInsetY();
428 ParagraphList::iterator dummypit;
429 Row const & row = *getRowNearY(y, dummypit);
430 y = dummypit->y + row.y_offset();
432 setCursorFromCoordinates(bv()->x_target(), y);
433 // + bv->workHeight());
437 if (crit == bv()->text->cursorRow()) {
438 // we have a row which is taller than the workarea. The
439 // simplest solution is to move to the next row instead.
442 // This is what we used to do, so we wouldn't skip right past
443 // tall rows, but it's not working right now.
445 new_y = bv->top_y() + bv->workHeight();
450 new_y = bv()->text->cursor.y()
451 + bv()->cursor().innerInset()->insetInInsetY()
452 + y - crit->baseline();
454 new_y = cursor.y() - crit->baseline();
460 setCursor(cur, parOffset(cpit), crit->pos(), false);
461 if (cur.y() < bv()->top_y() + bv()->workHeight())
463 bv()->updateScrollbar();
469 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
472 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
473 replaceSelection(lt);
474 if (!bv->insertInset(new_inset))
481 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
482 bool edit, bool pastesel)
484 InsetOld * inset = createInset(cmd);
485 BufferView * bv = cmd.view();
489 if (lt->selection.set()) {
490 bv->owner()->dispatch(FuncRequest(LFUN_CUT));
493 if (bv->insertInset(inset)) {
495 inset->edit(bv, true);
496 if (gotsel && pastesel)
497 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
507 void LyXText::number()
509 LyXFont font(LyXFont::ALL_IGNORE);
510 font.setNumber(LyXFont::TOGGLE);
511 toggleAndShow(bv(), this, font);
515 bool LyXText::rtl() const
517 return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
521 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
523 //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
524 lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
526 BufferView * bv = cmd.view();
528 switch (cmd.action) {
530 case LFUN_APPENDIX: {
531 ParagraphList::iterator pit = cursorPar();
532 bool start = !pit->params().startOfAppendix();
534 // ensure that we have only one start_of_appendix in this document
535 ParagraphList::iterator tmp = ownerParagraphs().begin();
536 ParagraphList::iterator end = ownerParagraphs().end();
538 for (; tmp != end; ++tmp) {
539 if (tmp->params().startOfAppendix()) {
540 recUndo(parOffset(tmp));
541 tmp->params().startOfAppendix(false);
547 recUndo(parOffset(pit));
548 pit->params().startOfAppendix(start);
550 // we can set the refreshing parameters now
552 redoParagraph(cursorPar());
553 setCursor(cursorPar(), cursor.pos());
558 case LFUN_DELETE_WORD_FORWARD:
564 case LFUN_DELETE_WORD_BACKWARD:
566 deleteWordBackward();
570 case LFUN_DELETE_LINE_FORWARD:
577 if (!selection.mark())
582 cursorRightOneWord();
587 if (!selection.mark())
590 cursorRightOneWord();
596 case LFUN_BEGINNINGBUF:
597 if (!selection.mark())
604 if (selection.mark())
611 if (!selection.set())
612 selection.cursor = cursor;
617 finishChange(bv, true);
621 if (!selection.set())
622 selection.cursor = cursor;
627 finishChange(bv, true);
631 if (!selection.set())
632 selection.cursor = cursor;
634 finishChange(bv, true);
638 if (!selection.set())
639 selection.cursor = cursor;
641 finishChange(bv, true);
644 case LFUN_UP_PARAGRAPHSEL:
645 if (!selection.set())
646 selection.cursor = cursor;
648 finishChange(bv, true);
651 case LFUN_DOWN_PARAGRAPHSEL:
652 if (!selection.set())
653 selection.cursor = cursor;
654 cursorDownParagraph();
655 finishChange(bv, true);
659 if (!selection.set())
660 selection.cursor = cursor;
662 finishChange(bv, true);
666 if (!selection.set())
667 selection.cursor = cursor;
669 finishChange(bv, true);
673 if (!selection.set())
674 selection.cursor = cursor;
676 finishChange(bv, true);
680 if (!selection.set())
681 selection.cursor = cursor;
683 finishChange(bv, true);
686 case LFUN_WORDRIGHTSEL:
690 cursorRightOneWord();
691 finishChange(bv, true);
694 case LFUN_WORDLEFTSEL:
696 cursorRightOneWord();
699 finishChange(bv, true);
703 LyXCursor cur1 = cursor;
705 getWord(cur1, cur2, lyx::WHOLE_WORD);
706 setCursor(cur1.par(), cur1.pos());
708 setCursor(cur2.par(), cur2.pos());
709 finishChange(bv, true);
715 if (!selection.mark())
719 if (cursor.pos() < cursorPar()->size()
720 && cursorPar()->isInset(cursor.pos())
721 && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
722 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
723 cmd.message(tmpinset->editMessage());
724 tmpinset->edit(bv, !is_rtl);
734 // This is soooo ugly. Isn't it possible to make
736 bool const is_rtl = rtl();
737 if (!selection.mark())
739 LyXCursor const cur = cursor;
742 if ((is_rtl || cur != cursor) && // only if really moved!
743 cursor.pos() < cursorPar()->size() &&
744 cursorPar()->isInset(cursor.pos()) &&
745 isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
746 InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
747 cmd.message(tmpinset->editMessage());
748 tmpinset->edit(bv, is_rtl);
758 if (!selection.mark())
765 if (!selection.mark())
771 case LFUN_UP_PARAGRAPH:
772 if (!selection.mark())
778 case LFUN_DOWN_PARAGRAPH:
779 if (!selection.mark())
781 cursorDownParagraph();
782 finishChange(bv, false);
786 if (!selection.mark())
789 finishChange(bv, false);
793 if (!selection.mark())
796 finishChange(bv, false);
800 if (!selection.mark())
803 finishChange(bv, false);
807 if (!selection.mark())
810 finishChange(bv, false);
813 case LFUN_BREAKLINE: {
814 lyx::pos_type body = cursorPar()->beginningOfBody();
816 // Not allowed by LaTeX (labels or empty par)
817 if (cursor.pos() <= body)
820 replaceSelection(bv->getLyXText());
821 insertInset(new InsetNewline);
822 setCursor(cursorPar(), cursor.pos());
823 moveCursorUpdate(bv, false);
828 if (!selection.set()) {
830 selection.cursor = cursor;
831 // It is possible to make it a lot faster still
832 // just comment out the line below...
834 cutSelection(true, false);
836 moveCursorUpdate(bv, false);
837 bv->owner()->view_state_changed();
840 case LFUN_DELETE_SKIP:
841 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
842 if (!selection.set()) {
843 if (cursor.pos() == cursorPar()->size()) {
845 ParagraphParameters & params = cursorPar()->params();
846 if (cursor.pos() == 0
847 && !(params.spaceTop() == VSpace (VSpace::NONE))) {
849 VSpace(VSpace::NONE),
850 params.spaceBottom(),
853 params.labelWidthString(), 0);
858 selection.cursor = cursor;
862 selection.cursor = cursor;
865 cutSelection(true, false);
872 if (!selection.set()) {
873 if (bv->owner()->getIntl().getTransManager().backspace()) {
875 selection.cursor = cursor;
876 // It is possible to make it a lot faster still
877 // just comment out the line below...
880 cutSelection(true, false);
882 bv->owner()->view_state_changed();
887 case LFUN_BACKSPACE_SKIP:
888 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
889 if (!selection.set()) {
890 ParagraphParameters & params = cursorPar()->params();
891 if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
893 VSpace(VSpace::NONE),
894 params.spaceBottom(),
897 params.labelWidthString(), 0);
899 LyXCursor cur = cursor;
901 selection.cursor = cur;
904 cutSelection(true, false);
909 case LFUN_BREAKPARAGRAPH:
910 replaceSelection(bv->getLyXText());
911 breakParagraph(bv->buffer()->paragraphs(), 0);
913 selection.cursor = cursor;
915 bv->owner()->view_state_changed();
918 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
919 replaceSelection(bv->getLyXText());
920 breakParagraph(bv->buffer()->paragraphs(), 1);
922 selection.cursor = cursor;
924 bv->owner()->view_state_changed();
927 case LFUN_BREAKPARAGRAPH_SKIP: {
928 // When at the beginning of a paragraph, remove
929 // indentation and add a "defskip" at the top.
930 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
931 LyXCursor cur = cursor;
932 replaceSelection(bv->getLyXText());
933 if (cur.pos() == 0) {
934 ParagraphParameters & params = getPar(cur)->params();
935 if (params.spaceTop() == VSpace(VSpace::NONE)) {
937 VSpace(VSpace::DEFSKIP), params.spaceBottom(),
940 params.labelWidthString(), 1);
944 breakParagraph(bv->buffer()->paragraphs(), 0);
947 selection.cursor = cur;
949 bv->owner()->view_state_changed();
953 case LFUN_PARAGRAPH_SPACING: {
954 ParagraphList::iterator pit = cursorPar();
955 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
956 float cur_value = 1.0;
957 if (cur_spacing == Spacing::Other)
958 cur_value = pit->params().spacing().getValue();
960 istringstream is(cmd.argument);
963 Spacing::Space new_spacing = cur_spacing;
964 float new_value = cur_value;
966 lyxerr << "Missing argument to `paragraph-spacing'"
968 } else if (tmp == "single") {
969 new_spacing = Spacing::Single;
970 } else if (tmp == "onehalf") {
971 new_spacing = Spacing::Onehalf;
972 } else if (tmp == "double") {
973 new_spacing = Spacing::Double;
974 } else if (tmp == "other") {
975 new_spacing = Spacing::Other;
978 lyxerr << "new_value = " << tmpval << endl;
981 } else if (tmp == "default") {
982 new_spacing = Spacing::Default;
984 lyxerr << _("Unknown spacing argument: ")
985 << cmd.argument << endl;
987 if (cur_spacing != new_spacing || cur_value != new_value) {
988 pit->params().spacing(Spacing(new_spacing, new_value));
995 case LFUN_INSET_SETTINGS:
996 bv->cursor().innerInset()->showInsetDialog(bv);
999 case LFUN_INSET_TOGGLE:
1006 case LFUN_SPACE_INSERT:
1007 if (cursorPar()->layout()->free_spacing)
1010 doInsertInset(this, cmd, false, false);
1011 moveCursorUpdate(bv, false);
1014 case LFUN_HYPHENATION:
1015 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
1018 case LFUN_LIGATURE_BREAK:
1019 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
1023 specialChar(this, bv, InsetSpecialChar::LDOTS);
1026 case LFUN_END_OF_SENTENCE:
1027 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
1030 case LFUN_MENU_SEPARATOR:
1031 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
1037 selection.cursor = cursor;
1038 cmd.message(N_("Mark off"));
1043 selection.mark(true);
1045 selection.cursor = cursor;
1046 cmd.message(N_("Mark on"));
1051 if (selection.mark()) {
1052 cmd.message(N_("Mark removed"));
1054 selection.mark(true);
1055 cmd.message(N_("Mark set"));
1057 selection.cursor = cursor;
1061 case LFUN_UPCASE_WORD:
1062 changeCase(LyXText::text_uppercase);
1066 case LFUN_LOWCASE_WORD:
1067 changeCase(LyXText::text_lowercase);
1071 case LFUN_CAPITALIZE_WORD:
1072 changeCase(LyXText::text_capitalization);
1076 case LFUN_TRANSPOSE_CHARS:
1077 recUndo(cursor.par());
1083 cmd.message(_("Paste"));
1084 replaceSelection(bv->getLyXText());
1085 #warning FIXME Check if the arg is in the domain of available selections.
1086 if (isStrUnsignedInt(cmd.argument))
1087 pasteSelection(strToUnsignedInt(cmd.argument));
1090 clearSelection(); // bug 393
1097 cutSelection(true, true);
1098 cmd.message(_("Cut"));
1104 cmd.message(_("Copy"));
1107 case LFUN_BEGINNINGBUFSEL:
1109 return DispatchResult(false);
1111 finishChange(bv, true);
1114 case LFUN_ENDBUFSEL:
1116 return DispatchResult(false);
1118 finishChange(bv, true);
1122 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1128 istringstream is(cmd.argument);
1131 lyxerr << "SETXY: Could not parse coordinates in '"
1132 << cmd.argument << std::endl;
1134 setCursorFromCoordinates(x, y);
1139 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1141 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1147 case LFUN_GETLAYOUT:
1148 cmd.message(tostr(cursorPar()->layout()));
1152 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1153 << cmd.argument << endl;
1155 // This is not the good solution to the empty argument
1156 // problem, but it will hopefully suffice for 1.2.0.
1157 // The correct solution would be to augument the
1158 // function list/array with information about what
1159 // functions needs arguments and their type.
1160 if (cmd.argument.empty()) {
1161 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1165 // Derive layout number from given argument (string)
1166 // and current buffer's textclass (number)
1167 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1168 bool hasLayout = tclass.hasLayout(cmd.argument);
1169 string layout = cmd.argument;
1171 // If the entry is obsolete, use the new one instead.
1173 string const & obs = tclass[layout]->obsoleted_by();
1179 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1184 bool change_layout = (current_layout != layout);
1186 if (!change_layout && selection.set() &&
1187 selection.start.par() != selection.end.par())
1189 ParagraphList::iterator spit = getPar(selection.start);
1190 ParagraphList::iterator epit = boost::next(getPar(selection.end));
1191 while (spit != epit) {
1192 if (spit->layout()->name() != current_layout) {
1193 change_layout = true;
1200 if (change_layout) {
1201 current_layout = layout;
1203 bv->owner()->setLayout(layout);
1210 case LFUN_PASTESELECTION: {
1211 // this was originally a bv->text->clearSelection(), i.e
1212 // the outermost LyXText!
1214 string const clip = bv->getClipboard();
1215 if (!clip.empty()) {
1216 if (cmd.argument == "paragraph")
1217 insertStringAsParagraphs(clip);
1219 insertStringAsLines(clip);
1225 case LFUN_GOTOERROR:
1226 gotoInset(InsetOld::ERROR_CODE, false);
1230 gotoInset(InsetOld::NOTE_CODE, false);
1233 case LFUN_REFERENCE_GOTO: {
1234 vector<InsetOld::Code> tmp;
1235 tmp.push_back(InsetOld::LABEL_CODE);
1236 tmp.push_back(InsetOld::REF_CODE);
1237 gotoInset(tmp, true);
1242 replaceSelection(bv->getLyXText());
1243 ParagraphList::iterator pit = cursorPar();
1244 lyx::pos_type pos = cursor.pos();
1248 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1251 c = pit->getChar(pos - 1);
1253 LyXLayout_ptr const & style = pit->layout();
1255 BufferParams const & bufparams = bv->buffer()->params();
1256 if (style->pass_thru ||
1257 pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1258 !bv->insertInset(new InsetQuotes(c, bufparams)))
1259 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1263 case LFUN_DATE_INSERT: {
1264 replaceSelection(bv->getLyXText());
1265 time_t now_time_t = time(NULL);
1266 struct tm * now_tm = localtime(&now_time_t);
1267 setlocale(LC_TIME, "");
1269 if (!cmd.argument.empty())
1272 arg = lyxrc.date_insert_format;
1274 int const datetmp_len =
1275 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1277 for (int i = 0; i < datetmp_len; i++)
1278 insertChar(datetmp[i]);
1280 selection.cursor = cursor;
1281 moveCursorUpdate(bv, false);
1285 case LFUN_MOUSE_TRIPLE:
1288 if (cmd.button() == mouse_button::button1) {
1290 selection.cursor = cursor;
1294 bv->haveSelection(selection.set());
1298 case LFUN_MOUSE_DOUBLE:
1301 if (cmd.button() == mouse_button::button1) {
1302 selectWord(lyx::WHOLE_WORD_STRICT);
1304 bv->haveSelection(selection.set());
1308 case LFUN_MOUSE_MOTION: {
1309 // Only use motion with button 1
1310 //if (ev.button() != mouse_button::button1)
1316 // Check for inset locking
1318 if (bv->innerInset()) {
1319 InsetOld * tli = bv->innerInset();
1320 LyXCursor cursor = bv->text->cursor;
1321 LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1322 int width = tli->width();
1323 int inset_x = font.isVisibleRightToLeft()
1324 ? cursor.x() - width : cursor.x();
1325 int start_x = inset_x + tli->scroll();
1326 FuncRequest cmd1 = cmd;
1327 cmd1.x = cmd.x - start_x;
1328 cmd1.y = cmd.y - cursor.y() + bv->top_y();
1329 tli->dispatch(cmd1);
1334 // The test for not selection possible is needed, that only motion
1335 // events are used, where the bottom press event was on
1336 // the drawing area too
1337 if (!selection_possible) {
1338 lyxerr[Debug::ACTION]
1339 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1343 RowList::iterator cursorrow = bv->text->cursorRow();
1344 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1346 // sorry for this but I have a strange error that the y value jumps at
1347 // a certain point. This seems like an error in my xforms library or
1348 // in some other local environment, but I would like to leave this here
1349 // for the moment until I can remove this (Jug 20020418)
1350 if (y_before < bv->text->cursor.y())
1351 lyxerr << y_before << ':'
1352 << bv->text->cursor.y() << endl;
1354 // This is to allow jumping over large insets
1355 if (cursorrow == bv->text->cursorRow()) {
1356 if (cmd.y >= bv->workHeight())
1357 bv->text->cursorDown(false);
1359 bv->text->cursorUp(false);
1362 bv->text->setSelection();
1367 // Single-click on work area
1368 case LFUN_MOUSE_PRESS: {
1372 // ok ok, this is a hack (for xforms)
1373 // We shouldn't go further down as we really should only do the
1374 // scrolling and be done with this. Otherwise we may open some
1375 // dialogs (Jug 20020424).
1376 if (cmd.button() == mouse_button::button4) {
1377 bv->scroll(-lyxrc.wheel_jump);
1380 if (cmd.button() == mouse_button::button5) {
1381 bv->scroll(lyxrc.wheel_jump);
1385 // Middle button press pastes if we have a selection
1386 // We do this here as if the selection was inside an inset
1387 // it could get cleared on the unlocking of the inset so
1388 // we have to check this first
1389 bool paste_internally = false;
1390 if (cmd.button() == mouse_button::button2 && selection.set()) {
1391 bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1392 paste_internally = true;
1395 int const screen_first = bv->top_y();
1396 selection_possible = true;
1398 // Clear the selection
1399 bv->text->clearSelection();
1401 bv->updateScrollbar();
1403 // Right click on a footnote flag opens float menu
1404 if (cmd.button() == mouse_button::button3) {
1405 selection_possible = false;
1409 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first);
1411 bv->text->selection.cursor = bv->text->cursor;
1412 bv->x_target(bv->text->cursor.x());
1414 if (bv->fitCursor())
1415 selection_possible = false;
1417 // Insert primary selection with middle mouse
1418 // if there is a local selection in the current buffer,
1420 if (cmd.button() == mouse_button::button2) {
1421 if (paste_internally)
1422 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1424 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1425 selection_possible = false;
1430 case LFUN_MOUSE_RELEASE: {
1431 // do nothing if we used the mouse wheel
1435 if (cmd.button() == mouse_button::button4
1436 || cmd.button() == mouse_button::button5)
1439 selection_possible = false;
1441 if (cmd.button() == mouse_button::button2)
1445 if (cmd.button() == mouse_button::button1)
1446 bv->haveSelection(selection.set());
1449 bv->owner()->view_state_changed();
1450 bv->owner()->updateMenubar();
1451 bv->owner()->updateToolbar();
1455 case LFUN_SELFINSERT: {
1456 if (cmd.argument.empty())
1459 // Automatically delete the currently selected
1460 // text and replace it with what is being
1461 // typed in now. Depends on lyxrc settings
1462 // "auto_region_delete", which defaults to
1465 if (lyxrc.auto_region_delete) {
1466 if (selection.set())
1467 cutSelection(false, false);
1468 bv->haveSelection(false);
1472 LyXFont const old_font = real_current_font;
1474 string::const_iterator cit = cmd.argument.begin();
1475 string::const_iterator end = cmd.argument.end();
1476 for (; cit != end; ++cit)
1477 bv->owner()->getIntl().getTransManager().
1478 TranslateAndInsert(*cit, this);
1480 selection.cursor = cursor;
1481 moveCursorUpdate(bv, false);
1483 // real_current_font.number can change so we need to
1484 // update the minibuffer
1485 if (old_font != real_current_font)
1486 bv->owner()->view_state_changed();
1487 bv->updateScrollbar();
1492 doInsertInset(this, cmd, true, false);
1493 InsetCommandParams p("url");
1494 string const data = InsetCommandMailer::params2string("url", p);
1495 bv->owner()->getDialogs().show("url", data, 0);
1499 case LFUN_HTMLURL: {
1500 doInsertInset(this, cmd, true, false);
1501 InsetCommandParams p("htmlurl");
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_CHARSTYLE:
1515 case LFUN_INSERT_BOX:
1516 case LFUN_INSERT_BRANCH:
1517 case LFUN_INSERT_BIBITEM:
1518 case LFUN_INSET_ERT:
1519 case LFUN_INSET_FLOAT:
1520 case LFUN_INSET_FOOTNOTE:
1521 case LFUN_INSET_MARGINAL:
1522 case LFUN_INSET_MINIPAGE:
1523 case LFUN_INSET_OPTARG:
1524 case LFUN_INSET_WIDE_FLOAT:
1525 case LFUN_INSET_WRAP:
1526 case LFUN_TABULAR_INSERT:
1527 case LFUN_ENVIRONMENT_INSERT:
1528 // Open the inset, and move the current selection
1530 doInsertInset(this, cmd, true, true);
1533 case LFUN_INDEX_INSERT:
1534 // Just open the inset
1535 doInsertInset(this, cmd, true, false);
1538 case LFUN_INDEX_PRINT:
1539 case LFUN_TOC_INSERT:
1541 case LFUN_INSERT_LINE:
1542 case LFUN_INSERT_PAGEBREAK:
1544 doInsertInset(this, cmd, false, false);
1547 case LFUN_DEPTH_MIN:
1549 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1553 case LFUN_DEPTH_PLUS:
1555 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1559 case LFUN_MATH_DELIM:
1560 case LFUN_MATH_DISPLAY:
1561 case LFUN_INSERT_MATH:
1562 case LFUN_MATH_LIMITS:
1563 case LFUN_MATH_MACRO:
1564 case LFUN_MATH_MUTATE:
1565 case LFUN_MATH_SPACE:
1566 case LFUN_MATH_IMPORT_SELECTION:
1567 case LFUN_MATH_MODE:
1568 case LFUN_MATH_NONUMBER:
1569 case LFUN_MATH_NUMBER:
1570 case LFUN_MATH_EXTERN:
1571 case LFUN_MATH_SIZE:
1577 bv->owner()->view_state_changed();
1582 bv->owner()->view_state_changed();
1587 bv->owner()->view_state_changed();
1592 bv->owner()->view_state_changed();
1597 bv->owner()->view_state_changed();
1602 bv->owner()->view_state_changed();
1606 styleReset(bv, this);
1607 bv->owner()->view_state_changed();
1610 case LFUN_UNDERLINE:
1611 underline(bv, this);
1612 bv->owner()->view_state_changed();
1615 case LFUN_FONT_SIZE:
1616 fontSize(bv, cmd.argument, this);
1617 bv->owner()->view_state_changed();
1621 lang(bv, cmd.argument, this);
1623 bv->owner()->view_state_changed();
1626 case LFUN_FREEFONT_APPLY:
1627 apply_freefont(bv, this);
1630 case LFUN_FREEFONT_UPDATE:
1631 update_and_apply_freefont(bv, this, cmd.argument);
1634 case LFUN_FINISHED_LEFT:
1635 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1640 case LFUN_FINISHED_RIGHT:
1641 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1646 case LFUN_FINISHED_UP:
1647 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1650 case LFUN_FINISHED_DOWN:
1651 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1656 return DispatchResult(false);
1659 return DispatchResult(true, true);