]> git.lyx.org Git - lyx.git/blob - src/text3.C
setFont rework + some code simplification
[lyx.git] / src / text3.C
1 /**
2  * \file text3.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "lyxtext.h"
19
20 #include "buffer.h"
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "cursor.h"
24 #include "debug.h"
25 #include "dispatchresult.h"
26 #include "factory.h"
27 #include "funcrequest.h"
28 #include "gettext.h"
29 #include "intl.h"
30 #include "language.h"
31 #include "lyxrc.h"
32 #include "lyxrow.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
36 #include "undo.h"
37 #include "vspace.h"
38
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
41
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
46
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
50
51 #include "mathed/formulabase.h"
52
53 #include <clocale>
54
55 using bv_funcs::replaceSelection;
56
57 using lyx::pos_type;
58
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
61
62 using std::endl;
63 using std::find;
64 using std::string;
65 using std::istringstream;
66 using std::vector;
67
68
69 extern string current_layout;
70
71 // the selection possible is needed, that only motion events are
72 // used, where the bottom press event was on the drawing area too
73 bool selection_possible = false;
74
75
76 namespace {
77
78         // globals...
79         LyXFont freefont(LyXFont::ALL_IGNORE);
80         bool toggleall = false;
81
82
83         void toggleAndShow(BufferView * bv, LyXText * text,
84                 LyXFont const & font, bool toggleall = true)
85         {
86                 if (!bv->available())
87                         return;
88
89                 text->toggleFree(font, toggleall);
90                 bv->update();
91
92                 if (font.language() != ignore_language ||
93                                 font.number() != LyXFont::IGNORE) {
94                         LyXCursor & cursor = text->cursor;
95                         Paragraph & par = *text->cursorPar();
96                         text->bidi.computeTables(par, *bv->buffer(),
97                                 *par.getRow(cursor.pos()));
98                         if (cursor.boundary() !=
99                                         text->bidi.isBoundary(*bv->buffer(), par,
100                                                         cursor.pos(),
101                                                         text->real_current_font))
102                                 text->setCursor(cursor.par(), cursor.pos(),
103                                                 false, !cursor.boundary());
104                 }
105         }
106
107
108         /// Apply the contents of freefont at the current cursor location.
109         void apply_freefont(BufferView * bv, LyXText * text)
110         {
111                 toggleAndShow(bv, text, freefont, toggleall);
112                 bv->owner()->view_state_changed();
113                 bv->owner()->message(_("Character set"));
114         }
115
116
117         /** Set the freefont using the contents of \param data dispatched from
118          *  the frontends and apply it at the current cursor location.
119          */
120         void update_and_apply_freefont(BufferView * bv, LyXText * text,
121                 string const & data)
122         {
123                 LyXFont font;
124                 bool toggle;
125                 if (bv_funcs::string2font(data, font, toggle)) {
126                         freefont = font;
127                         toggleall = toggle;
128                         apply_freefont(bv, text);
129                 }
130         }
131
132
133         void emph(BufferView * bv, LyXText * text)
134         {
135                 LyXFont font(LyXFont::ALL_IGNORE);
136                 font.setEmph(LyXFont::TOGGLE);
137                 toggleAndShow(bv, text, font);
138         }
139
140
141         void bold(BufferView * bv, LyXText * text)
142         {
143                 LyXFont font(LyXFont::ALL_IGNORE);
144                 font.setSeries(LyXFont::BOLD_SERIES);
145                 toggleAndShow(bv, text, font);
146         }
147
148
149         void noun(BufferView * bv, LyXText * text)
150         {
151                 LyXFont font(LyXFont::ALL_IGNORE);
152                 font.setNoun(LyXFont::TOGGLE);
153                 toggleAndShow(bv, text, font);
154         }
155
156
157         void lang(BufferView * bv, string const & l, LyXText * text)
158         {
159                 Language const * lang = languages.getLanguage(l);
160                 if (!lang)
161                         return;
162
163                 LyXFont font(LyXFont::ALL_IGNORE);
164                 font.setLanguage(lang);
165                 toggleAndShow(bv, text, font);
166         }
167
168
169         void code(BufferView * bv, LyXText * text)
170         {
171                 LyXFont font(LyXFont::ALL_IGNORE);
172                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
173                 toggleAndShow(bv, text, font);
174         }
175
176
177         void sans(BufferView * bv, LyXText * text)
178         {
179                 LyXFont font(LyXFont::ALL_IGNORE);
180                 font.setFamily(LyXFont::SANS_FAMILY);
181                 toggleAndShow(bv, text, font);
182         }
183
184
185         void roman(BufferView * bv, LyXText * text)
186         {
187                 LyXFont font(LyXFont::ALL_IGNORE);
188                 font.setFamily(LyXFont::ROMAN_FAMILY);
189                 toggleAndShow(bv, text, font);
190         }
191
192
193         void styleReset(BufferView * bv, LyXText * text)
194         {
195                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
196                 toggleAndShow(bv, text, font);
197         }
198
199
200         void underline(BufferView * bv, LyXText * text)
201         {
202                 LyXFont font(LyXFont::ALL_IGNORE);
203                 font.setUnderbar(LyXFont::TOGGLE);
204                 toggleAndShow(bv, text, font);
205         }
206
207
208         void fontSize(BufferView * bv, string const & size, LyXText * text)
209         {
210                 LyXFont font(LyXFont::ALL_IGNORE);
211                 font.setLyXSize(size);
212                 toggleAndShow(bv, text, font);
213         }
214
215
216         void moveCursor(BufferView * bv, bool selecting)
217         {
218                 LyXText * lt = bv->getLyXText();
219
220 //              if (!lt->selection.set())
221 //                      lt->selection.cursor = lt->cursor;
222
223                 if (selecting || lt->selection.mark())
224                         lt->setSelection();
225
226                 if (!lt->selection.set())
227                         bv->haveSelection(false);
228                 bv->switchKeyMap();
229         }
230
231
232         void finishChange(BufferView * bv, bool selecting = false)
233         {
234                 finishUndo();
235                 moveCursor(bv, selecting);
236                 bv->owner()->view_state_changed();
237         }
238
239 } // anon namespace
240
241
242 namespace bv_funcs {
243
244 string const freefont2string()
245 {
246         string data;
247         if (font2string(freefont, toggleall, data))
248                 return data;
249         return string();
250 }
251
252 }
253
254
255
256 InsetOld * LyXText::checkInsetHit(int x, int y)
257 {
258         ParagraphList::iterator pit;
259         ParagraphList::iterator end;
260
261         getParsInRange(ownerParagraphs(),
262                        bv()->top_y() - yo_,
263                        bv()->top_y() - yo_ + bv()->workHeight(),
264                        pit, end);
265
266         lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
267         for ( ; pit != end; ++pit) {
268                 InsetList::iterator iit = pit->insetlist.begin();
269                 InsetList::iterator iend = pit->insetlist.end();
270                 for ( ; iit != iend; ++iit) {
271                         InsetOld * inset = iit->inset;
272                         //lyxerr << "examining inset " << inset
273                         //      << " xy: " << inset->x() << "/" << inset->y()
274                         //      << " x: " << inset->x() << "..." << inset->x() + inset->width()
275                         //      << " y: " << inset->y() - inset->ascent() << "..."
276                         //      << inset->y() + inset->descent()
277                         //      << endl;
278                         if (x >= inset->x()
279                             && x <= inset->x() + inset->width()
280                             && y >= inset->y() - inset->ascent()
281                             && y <= inset->y() + inset->descent())
282                         {
283                                 lyxerr << "Hit inset: " << inset << endl;
284                                 return inset;
285                         }
286                 }
287         }
288         lyxerr << "No inset hit. " << endl;
289         return 0;
290 }
291
292
293 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
294                             string const & contents)
295 {
296         ParagraphList::iterator end = ownerParagraphs().end();
297         ParagraphList::iterator pit = cursorPar();
298         pos_type pos = cursor.pos();
299
300         InsetOld * inset;
301         do {
302                 if (pos + 1 < pit->size()) {
303                         ++pos;
304                 } else  {
305                         ++pit;
306                         pos = 0;
307                 }
308
309         } while (pit != end &&
310                  !(pit->isInset(pos) &&
311                    (inset = pit->getInset(pos)) != 0 &&
312                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
313                    (contents.empty() ||
314                     static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
315                     == contents)));
316
317         if (pit == end)
318                 return false;
319
320         setCursor(parOffset(pit), pos, false);
321         return true;
322 }
323
324
325 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
326                         bool same_content)
327 {
328         clearSelection();
329
330         string contents;
331         if (same_content && cursor.pos() < cursorPar()->size()
332             && cursorPar()->isInset(cursor.pos())) {
333                 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
334                 if (find(codes.begin(), codes.end(), inset->lyxCode())
335                     != codes.end())
336                         contents = static_cast<InsetCommand const *>(inset)->getContents();
337         }
338
339         if (!gotoNextInset(codes, contents)) {
340                 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
341                         LyXCursor tmp = cursor;
342                         cursor.par(0);
343                         cursor.pos(0);
344                         if (!gotoNextInset(codes, contents)) {
345                                 cursor = tmp;
346                                 bv()->owner()->message(_("No more insets"));
347                         }
348                 } else {
349                         bv()->owner()->message(_("No more insets"));
350                 }
351         }
352         bv()->update();
353         selection.cursor = cursor;
354 }
355
356
357 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
358 {
359         gotoInset(vector<InsetOld::Code>(1, code), same_content);
360 }
361
362
363 void LyXText::cursorPrevious()
364 {
365
366         RowList::iterator crit = cursorRow();
367         ParagraphList::iterator cpar = cursorPar();
368
369         int x = bv()->x_target() - xo_;
370         int y = bv()->top_y() - yo_;
371         setCursorFromCoordinates(x, y);
372
373         if (cpar == cursorPar() && crit == cursorRow()) {
374                 // we have a row which is taller than the workarea. The
375                 // simplest solution is to move to the previous row instead.
376                 cursorUp(true);
377         }
378
379         bv()->updateScrollbar();
380         finishUndo();
381 }
382
383
384 void LyXText::cursorNext()
385 {
386         RowList::iterator crit = cursorRow();
387         ParagraphList::iterator cpar = cursorPar();
388
389         int x = bv()->x_target() - xo_;
390         int y = bv()->top_y() + bv()->workHeight() - yo_;
391         setCursorFromCoordinates(x, y);
392
393         if (cpar == cursorPar() && crit == cursorRow()) {
394                 // we have a row which is taller than the workarea. The
395                 // simplest solution is to move to the next row instead.
396                 cursorDown(true);
397         }
398
399         bv()->updateScrollbar();
400         finishUndo();
401 }
402
403
404 namespace {
405
406 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
407 {
408         bv->update();
409         InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
410         replaceSelection(lt);
411         if (!bv->insertInset(new_inset))
412                 delete new_inset;
413         else
414                 bv->update();
415 }
416
417
418 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
419                    bool edit, bool pastesel)
420 {
421         InsetOld * inset = createInset(cmd);
422         BufferView * bv = cmd.view();
423
424         if (inset) {
425                 bool gotsel = false;
426                 if (lt->selection.set()) {
427                         bv->owner()->dispatch(FuncRequest(LFUN_CUT));
428                         gotsel = true;
429                 }
430                 if (bv->insertInset(inset)) {
431                         if (edit)
432                                 inset->edit(bv, true);
433                         if (gotsel && pastesel)
434                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
435                 } else
436                         delete inset;
437         }
438 }
439
440 } // anon namespace
441
442
443 void LyXText::number()
444 {
445         LyXFont font(LyXFont::ALL_IGNORE);
446         font.setNumber(LyXFont::TOGGLE);
447         toggleAndShow(bv(), this, font);
448 }
449
450
451 bool LyXText::rtl() const
452 {
453         return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
454 }
455
456
457 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
458 {
459         //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
460
461         BufferView * bv = cmd.view();
462
463         switch (cmd.action) {
464
465         case LFUN_APPENDIX: {
466                 ParagraphList::iterator pit = cursorPar();
467                 bool start = !pit->params().startOfAppendix();
468
469                 // ensure that we have only one start_of_appendix in this document
470                 ParagraphList::iterator tmp = ownerParagraphs().begin();
471                 ParagraphList::iterator end = ownerParagraphs().end();
472
473                 for (; tmp != end; ++tmp) {
474                         if (tmp->params().startOfAppendix()) {
475                                 recUndo(parOffset(tmp));
476                                 tmp->params().startOfAppendix(false);
477                                 redoParagraph(tmp);
478                                 break;
479                         }
480                 }
481
482                 recUndo(parOffset(pit));
483                 pit->params().startOfAppendix(start);
484
485                 // we can set the refreshing parameters now
486                 updateCounters();
487                 redoParagraph(cursorPar());
488                 setCursor(cursorPar(), cursor.pos());
489                 bv->update();
490                 break;
491         }
492
493         case LFUN_DELETE_WORD_FORWARD:
494                 clearSelection();
495                 deleteWordForward();
496                 finishChange(bv);
497                 break;
498
499         case LFUN_DELETE_WORD_BACKWARD:
500                 clearSelection();
501                 deleteWordBackward();
502                 finishChange(bv);
503                 break;
504
505         case LFUN_DELETE_LINE_FORWARD:
506                 clearSelection();
507                 deleteLineForward();
508                 finishChange(bv);
509                 break;
510
511         case LFUN_WORDRIGHT:
512                 if (!selection.mark())
513                         clearSelection();
514                 if (rtl())
515                         cursorLeftOneWord();
516                 else
517                         cursorRightOneWord();
518                 finishChange(bv);
519                 break;
520
521         case LFUN_WORDLEFT:
522                 if (!selection.mark())
523                         clearSelection();
524                 if (rtl())
525                         cursorRightOneWord();
526                 else
527                         cursorLeftOneWord();
528                 finishChange(bv);
529                 break;
530
531         case LFUN_BEGINNINGBUF:
532                 if (!selection.mark())
533                         clearSelection();
534                 cursorTop();
535                 finishChange(bv);
536                 break;
537
538         case LFUN_ENDBUF:
539                 if (selection.mark())
540                         clearSelection();
541                 cursorBottom();
542                 finishChange(bv);
543                 break;
544
545         case LFUN_RIGHTSEL:
546                 if (!selection.set())
547                         selection.cursor = cursor;
548                 if (rtl())
549                         cursorLeft(bv);
550                 else
551                         cursorRight(bv);
552                 finishChange(bv, true);
553                 break;
554
555         case LFUN_LEFTSEL:
556                 if (!selection.set())
557                         selection.cursor = cursor;
558                 if (rtl())
559                         cursorRight(bv);
560                 else
561                         cursorLeft(bv);
562                 finishChange(bv, true);
563                 break;
564
565         case LFUN_UPSEL:
566                 if (!selection.set())
567                         selection.cursor = cursor;
568                 cursorUp(true);
569                 finishChange(bv, true);
570                 break;
571
572         case LFUN_DOWNSEL:
573                 if (!selection.set())
574                         selection.cursor = cursor;
575                 cursorDown(true);
576                 finishChange(bv, true);
577                 break;
578
579         case LFUN_UP_PARAGRAPHSEL:
580                 if (!selection.set())
581                         selection.cursor = cursor;
582                 cursorUpParagraph();
583                 finishChange(bv, true);
584                 break;
585
586         case LFUN_DOWN_PARAGRAPHSEL:
587                 if (!selection.set())
588                         selection.cursor = cursor;
589                 cursorDownParagraph();
590                 finishChange(bv, true);
591                 break;
592
593         case LFUN_PRIORSEL:
594                 if (!selection.set())
595                         selection.cursor = cursor;
596                 cursorPrevious();
597                 finishChange(bv, true);
598                 break;
599
600         case LFUN_NEXTSEL:
601                 if (!selection.set())
602                         selection.cursor = cursor;
603                 cursorNext();
604                 finishChange(bv, true);
605                 break;
606
607         case LFUN_HOMESEL:
608                 if (!selection.set())
609                         selection.cursor = cursor;
610                 cursorHome();
611                 finishChange(bv, true);
612                 break;
613
614         case LFUN_ENDSEL:
615                 if (!selection.set())
616                         selection.cursor = cursor;
617                 cursorEnd();
618                 finishChange(bv, true);
619                 break;
620
621         case LFUN_WORDRIGHTSEL:
622                 if (rtl())
623                         cursorLeftOneWord();
624                 else
625                         cursorRightOneWord();
626                 finishChange(bv, true);
627                 break;
628
629         case LFUN_WORDLEFTSEL:
630                 if (rtl())
631                         cursorRightOneWord();
632                 else
633                         cursorLeftOneWord();
634                 finishChange(bv, true);
635                 break;
636
637         case LFUN_WORDSEL: {
638                 LyXCursor cur1 = cursor;
639                 LyXCursor cur2;
640                 getWord(cur1, cur2, lyx::WHOLE_WORD);
641                 setCursor(cur1.par(), cur1.pos());
642                 clearSelection();
643                 setCursor(cur2.par(), cur2.pos());
644                 finishChange(bv, true);
645                 break;
646         }
647
648         case LFUN_RIGHT:
649                 finishChange(bv);
650                 return moveRight();
651
652         case LFUN_LEFT:
653                 finishChange(bv);
654                 return moveLeft();
655
656         case LFUN_UP:
657                 finishChange(bv);
658                 return moveUp();
659
660         case LFUN_DOWN:
661                 finishChange(bv);
662                 return moveDown();
663
664         case LFUN_UP_PARAGRAPH:
665                 if (!selection.mark())
666                         clearSelection();
667                 cursorUpParagraph();
668                 finishChange(bv);
669                 break;
670
671         case LFUN_DOWN_PARAGRAPH:
672                 if (!selection.mark())
673                         clearSelection();
674                 cursorDownParagraph();
675                 finishChange(bv, false);
676                 break;
677
678         case LFUN_PRIOR:
679                 if (!selection.mark())
680                         clearSelection();
681                 finishChange(bv, false);
682                 if (cursorPar() == firstPar() && cursorRow() == firstRow())
683                         return DispatchResult(false, FINISHED_UP);
684                 cursorPrevious();
685                 break;
686
687         case LFUN_NEXT:
688                 if (!selection.mark())
689                         clearSelection();
690                 finishChange(bv, false);
691                 if (cursorPar() == lastPar() && cursorRow() == lastRow())
692                         return DispatchResult(false, FINISHED_DOWN);
693                 cursorNext();
694                 break;
695
696         case LFUN_HOME:
697                 if (!selection.mark())
698                         clearSelection();
699                 cursorHome();
700                 finishChange(bv, false);
701                 break;
702
703         case LFUN_END:
704                 if (!selection.mark())
705                         clearSelection();
706                 cursorEnd();
707                 finishChange(bv, false);
708                 break;
709
710         case LFUN_BREAKLINE: {
711                 lyx::pos_type body = cursorPar()->beginOfBody();
712
713                 // Not allowed by LaTeX (labels or empty par)
714                 if (cursor.pos() <= body)
715                         break;
716
717                 replaceSelection(bv->getLyXText());
718                 insertInset(new InsetNewline);
719                 setCursor(cursorPar(), cursor.pos());
720                 moveCursor(bv, false);
721                 break;
722         }
723
724         case LFUN_DELETE:
725                 if (!selection.set()) {
726                         Delete();
727                         selection.cursor = cursor;
728                         // It is possible to make it a lot faster still
729                         // just comment out the line below...
730                 } else {
731                         cutSelection(true, false);
732                 }
733                 moveCursor(bv, false);
734                 bv->owner()->view_state_changed();
735                 break;
736
737         case LFUN_DELETE_SKIP:
738                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
739                 if (!selection.set()) {
740                         if (cursor.pos() == cursorPar()->size()) {
741                                 cursorRight(bv);
742                                 ParagraphParameters & params = cursorPar()->params();
743                                 if (cursor.pos() == 0
744                                     && !(params.spaceTop() == VSpace (VSpace::NONE))) {
745                                         setParagraph(
746                                                  VSpace(VSpace::NONE),
747                                                  params.spaceBottom(),
748                                                  params.spacing(),
749                                                  params.align(),
750                                                  params.labelWidthString(), 0);
751                                         cursorLeft(bv);
752                                 } else {
753                                         cursorLeft(bv);
754                                         Delete();
755                                         selection.cursor = cursor;
756                                 }
757                         } else {
758                                 Delete();
759                                 selection.cursor = cursor;
760                         }
761                 } else {
762                         cutSelection(true, false);
763                 }
764                 bv->update();
765                 break;
766
767
768         case LFUN_BACKSPACE:
769                 if (!selection.set()) {
770                         if (bv->owner()->getIntl().getTransManager().backspace()) {
771                                 backspace();
772                                 selection.cursor = cursor;
773                                 // It is possible to make it a lot faster still
774                                 // just comment out the line below...
775                         }
776                 } else {
777                         cutSelection(true, false);
778                 }
779                 bv->owner()->view_state_changed();
780                 bv->switchKeyMap();
781                 bv->update();
782                 break;
783
784         case LFUN_BACKSPACE_SKIP:
785                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
786                 if (!selection.set()) {
787                         ParagraphParameters & params = cursorPar()->params();
788                         if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
789                                 setParagraph(
790                                          VSpace(VSpace::NONE),
791                                    params.spaceBottom(),
792                                          params.spacing(),
793                                          params.align(),
794                                          params.labelWidthString(), 0);
795                         } else {
796                                 LyXCursor cur = cursor;
797                                 backspace();
798                                 selection.cursor = cur;
799                         }
800                 } else {
801                         cutSelection(true, false);
802                 }
803                 bv->update();
804                 break;
805
806         case LFUN_BREAKPARAGRAPH:
807                 replaceSelection(bv->getLyXText());
808                 breakParagraph(bv->buffer()->paragraphs(), 0);
809                 bv->update();
810                 selection.cursor = cursor;
811                 bv->switchKeyMap();
812                 bv->owner()->view_state_changed();
813                 break;
814
815         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
816                 replaceSelection(bv->getLyXText());
817                 breakParagraph(bv->buffer()->paragraphs(), 1);
818                 bv->update();
819                 selection.cursor = cursor;
820                 bv->switchKeyMap();
821                 bv->owner()->view_state_changed();
822                 break;
823
824         case LFUN_BREAKPARAGRAPH_SKIP: {
825                 // When at the beginning of a paragraph, remove
826                 // indentation and add a "defskip" at the top.
827                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
828                 LyXCursor cur = cursor;
829                 replaceSelection(bv->getLyXText());
830                 if (cur.pos() == 0) {
831                         ParagraphParameters & params = getPar(cur)->params();
832                         if (params.spaceTop() == VSpace(VSpace::NONE)) {
833                                 setParagraph(
834                                          VSpace(VSpace::DEFSKIP), params.spaceBottom(),
835                                          params.spacing(),
836                                          params.align(),
837                                          params.labelWidthString(), 1);
838                         }
839                 }
840                 else {
841                         breakParagraph(bv->buffer()->paragraphs(), 0);
842                 }
843                 bv->update();
844                 selection.cursor = cur;
845                 bv->switchKeyMap();
846                 bv->owner()->view_state_changed();
847                 break;
848         }
849
850         case LFUN_PARAGRAPH_SPACING: {
851                 ParagraphList::iterator pit = cursorPar();
852                 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
853                 float cur_value = 1.0;
854                 if (cur_spacing == Spacing::Other)
855                         cur_value = pit->params().spacing().getValue();
856
857                 istringstream is(cmd.argument);
858                 string tmp;
859                 is >> tmp;
860                 Spacing::Space new_spacing = cur_spacing;
861                 float new_value = cur_value;
862                 if (tmp.empty()) {
863                         lyxerr << "Missing argument to `paragraph-spacing'"
864                                << endl;
865                 } else if (tmp == "single") {
866                         new_spacing = Spacing::Single;
867                 } else if (tmp == "onehalf") {
868                         new_spacing = Spacing::Onehalf;
869                 } else if (tmp == "double") {
870                         new_spacing = Spacing::Double;
871                 } else if (tmp == "other") {
872                         new_spacing = Spacing::Other;
873                         float tmpval = 0.0;
874                         is >> tmpval;
875                         lyxerr << "new_value = " << tmpval << endl;
876                         if (tmpval != 0.0)
877                                 new_value = tmpval;
878                 } else if (tmp == "default") {
879                         new_spacing = Spacing::Default;
880                 } else {
881                         lyxerr << _("Unknown spacing argument: ")
882                                << cmd.argument << endl;
883                 }
884                 if (cur_spacing != new_spacing || cur_value != new_value) {
885                         pit->params().spacing(Spacing(new_spacing, new_value));
886                         redoParagraph();
887                         bv->update();
888                 }
889                 break;
890         }
891
892         case LFUN_INSET_APPLY: {
893                 string const name = cmd.getArg(0);
894                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
895                 if (inset) {
896                         FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
897                         inset->dispatch(fr);
898                 } else {
899                         FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
900                         dispatch(fr);
901                 }
902                 break;
903         }
904
905         case LFUN_INSET_INSERT: {
906                 InsetOld * inset = createInset(cmd);
907                 if (!inset || !bv->insertInset(inset))
908                         delete inset;
909                 break;
910                 }
911
912         case LFUN_INSET_SETTINGS:
913                 bv->cursor().innerInset()->showInsetDialog(bv);
914                 break;
915
916         case LFUN_INSET_TOGGLE:
917                 clearSelection();
918                 toggleInset();
919                 bv->update();
920                 bv->switchKeyMap();
921                 break;
922
923         case LFUN_SPACE_INSERT:
924                 if (cursorPar()->layout()->free_spacing)
925                         insertChar(' ');
926                 else
927                         doInsertInset(this, cmd, false, false);
928                 moveCursor(bv, false);
929                 break;
930
931         case LFUN_HYPHENATION:
932                 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
933                 break;
934
935         case LFUN_LIGATURE_BREAK:
936                 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
937                 break;
938
939         case LFUN_LDOTS:
940                 specialChar(this, bv, InsetSpecialChar::LDOTS);
941                 break;
942
943         case LFUN_END_OF_SENTENCE:
944                 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
945                 break;
946
947         case LFUN_MENU_SEPARATOR:
948                 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
949                 break;
950
951         case LFUN_MARK_OFF:
952                 clearSelection();
953                 bv->update();
954                 selection.cursor = cursor;
955                 cmd.message(N_("Mark off"));
956                 break;
957
958         case LFUN_MARK_ON:
959                 clearSelection();
960                 selection.mark(true);
961                 bv->update();
962                 selection.cursor = cursor;
963                 cmd.message(N_("Mark on"));
964                 break;
965
966         case LFUN_SETMARK:
967                 clearSelection();
968                 if (selection.mark()) {
969                         cmd.message(N_("Mark removed"));
970                 } else {
971                         selection.mark(true);
972                         cmd.message(N_("Mark set"));
973                 }
974                 selection.cursor = cursor;
975                 bv->update();
976                 break;
977
978         case LFUN_UPCASE_WORD:
979                 changeCase(LyXText::text_uppercase);
980                 bv->update();
981                 break;
982
983         case LFUN_LOWCASE_WORD:
984                 changeCase(LyXText::text_lowercase);
985                 bv->update();
986                 break;
987
988         case LFUN_CAPITALIZE_WORD:
989                 changeCase(LyXText::text_capitalization);
990                 bv->update();
991                 break;
992
993         case LFUN_TRANSPOSE_CHARS:
994                 recUndo(cursor.par());
995                 redoParagraph();
996                 bv->update();
997                 break;
998
999         case LFUN_PASTE:
1000                 cmd.message(_("Paste"));
1001                 replaceSelection(bv->getLyXText());
1002 #warning FIXME Check if the arg is in the domain of available selections.
1003                 if (isStrUnsignedInt(cmd.argument))
1004                         pasteSelection(strToUnsignedInt(cmd.argument));
1005                 else
1006                         pasteSelection(0);
1007                 clearSelection(); // bug 393
1008                 bv->update();
1009                 bv->switchKeyMap();
1010                 finishUndo();
1011                 break;
1012
1013         case LFUN_CUT:
1014                 cutSelection(true, true);
1015                 cmd.message(_("Cut"));
1016                 bv->update();
1017                 break;
1018
1019         case LFUN_COPY:
1020                 copySelection();
1021                 cmd.message(_("Copy"));
1022                 break;
1023
1024         case LFUN_BEGINNINGBUFSEL:
1025                 if (inset_owner)
1026                         return DispatchResult(false);
1027                 cursorTop();
1028                 finishChange(bv, true);
1029                 break;
1030
1031         case LFUN_ENDBUFSEL:
1032                 if (inset_owner)
1033                         return DispatchResult(false);
1034                 cursorBottom();
1035                 finishChange(bv, true);
1036                 break;
1037
1038         case LFUN_GETXY:
1039                 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1040                 break;
1041
1042         case LFUN_SETXY: {
1043                 int x = 0;
1044                 int y = 0;
1045                 istringstream is(cmd.argument);
1046                 is >> x >> y;
1047                 if (!is)
1048                         lyxerr << "SETXY: Could not parse coordinates in '"
1049                                << cmd.argument << std::endl;
1050                 else
1051                         setCursorFromCoordinates(x, y);
1052                 break;
1053         }
1054
1055         case LFUN_GETFONT:
1056                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1057                         cmd.message("E");
1058                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1059                         cmd.message("N");
1060                 else
1061                         cmd.message("0");
1062                 break;
1063
1064         case LFUN_GETLAYOUT:
1065                 cmd.message(tostr(cursorPar()->layout()));
1066                 break;
1067
1068         case LFUN_LAYOUT: {
1069                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1070                   << cmd.argument << endl;
1071
1072                 // This is not the good solution to the empty argument
1073                 // problem, but it will hopefully suffice for 1.2.0.
1074                 // The correct solution would be to augument the
1075                 // function list/array with information about what
1076                 // functions needs arguments and their type.
1077                 if (cmd.argument.empty()) {
1078                         cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1079                         break;
1080                 }
1081
1082                 // Derive layout number from given argument (string)
1083                 // and current buffer's textclass (number)
1084                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1085                 bool hasLayout = tclass.hasLayout(cmd.argument);
1086                 string layout = cmd.argument;
1087
1088                 // If the entry is obsolete, use the new one instead.
1089                 if (hasLayout) {
1090                         string const & obs = tclass[layout]->obsoleted_by();
1091                         if (!obs.empty())
1092                                 layout = obs;
1093                 }
1094
1095                 if (!hasLayout) {
1096                         cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1097                                 N_(" not known"));
1098                         break;
1099                 }
1100
1101                 bool change_layout = (current_layout != layout);
1102
1103                 if (!change_layout && selection.set() &&
1104                         selection.start.par() != selection.end.par())
1105                 {
1106                         ParagraphList::iterator spit = getPar(selection.start);
1107                         ParagraphList::iterator epit = boost::next(getPar(selection.end));
1108                         while (spit != epit) {
1109                                 if (spit->layout()->name() != current_layout) {
1110                                         change_layout = true;
1111                                         break;
1112                                 }
1113                                 ++spit;
1114                         }
1115                 }
1116
1117                 if (change_layout) {
1118                         current_layout = layout;
1119                         setLayout(layout);
1120                         bv->owner()->setLayout(layout);
1121                         bv->update();
1122                         bv->switchKeyMap();
1123                 }
1124                 break;
1125         }
1126
1127         case LFUN_PASTESELECTION: {
1128                 // this was originally a bv->text->clearSelection(), i.e
1129                 // the outermost LyXText!
1130                 clearSelection();
1131                 string const clip = bv->getClipboard();
1132                 if (!clip.empty()) {
1133                         if (cmd.argument == "paragraph")
1134                                 insertStringAsParagraphs(clip);
1135                         else
1136                                 insertStringAsLines(clip);
1137                         bv->update();
1138                 }
1139                 break;
1140         }
1141
1142         case LFUN_GOTOERROR:
1143                 gotoInset(InsetOld::ERROR_CODE, false);
1144                 break;
1145
1146         case LFUN_GOTONOTE:
1147                 gotoInset(InsetOld::NOTE_CODE, false);
1148                 break;
1149
1150         case LFUN_REFERENCE_GOTO: {
1151                 vector<InsetOld::Code> tmp;
1152                 tmp.push_back(InsetOld::LABEL_CODE);
1153                 tmp.push_back(InsetOld::REF_CODE);
1154                 gotoInset(tmp, true);
1155                 break;
1156         }
1157
1158         case LFUN_QUOTE: {
1159                 replaceSelection(bv->getLyXText());
1160                 ParagraphList::iterator pit = cursorPar();
1161                 lyx::pos_type pos = cursor.pos();
1162                 char c;
1163                 if (!pos)
1164                         c = ' ';
1165                 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1166                         c = ' ';
1167                 else
1168                         c = pit->getChar(pos - 1);
1169
1170                 LyXLayout_ptr const & style = pit->layout();
1171
1172                 BufferParams const & bufparams = bv->buffer()->params();
1173                 if (style->pass_thru ||
1174                     pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1175                     !bv->insertInset(new InsetQuotes(c, bufparams)))
1176                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1177                 break;
1178         }
1179
1180         case LFUN_DATE_INSERT: {
1181                 replaceSelection(bv->getLyXText());
1182                 time_t now_time_t = time(NULL);
1183                 struct tm * now_tm = localtime(&now_time_t);
1184                 setlocale(LC_TIME, "");
1185                 string arg;
1186                 if (!cmd.argument.empty())
1187                         arg = cmd.argument;
1188                 else
1189                         arg = lyxrc.date_insert_format;
1190                 char datetmp[32];
1191                 int const datetmp_len =
1192                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1193
1194                 for (int i = 0; i < datetmp_len; i++)
1195                         insertChar(datetmp[i]);
1196
1197                 selection.cursor = cursor;
1198                 moveCursor(bv, false);
1199                 break;
1200         }
1201
1202         case LFUN_MOUSE_TRIPLE:
1203                 if (!bv->buffer())
1204                         break;
1205                 if (cmd.button() == mouse_button::button1) {
1206                         selection_possible = true;
1207                         cursorHome();
1208                         selection.cursor = cursor;
1209                         cursorEnd();
1210                         setSelection();
1211                         bv->haveSelection(selection.set());
1212                 }
1213                 break;
1214
1215         case LFUN_MOUSE_DOUBLE:
1216                 if (!bv->buffer())
1217                         break;
1218                 if (cmd.button() == mouse_button::button1) {
1219                         selection_possible = true;
1220                         selectWord(lyx::WHOLE_WORD_STRICT);
1221                         bv->haveSelection(selection.set());
1222                 }
1223                 break;
1224
1225         case LFUN_MOUSE_MOTION: {
1226                 // Only use motion with button 1
1227                 //if (ev.button() != mouse_button::button1)
1228                 //      return false;
1229
1230                 if (!bv->buffer())
1231                         break;
1232                 // The test for not selection possible is needed, that
1233                 // only motion events are used, where the bottom press
1234                 // event was on the drawing area too
1235                 if (!selection_possible) {
1236                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1237                                 "Dispatch: no selection possible\n";
1238                         break;
1239                 }
1240                 RowList::iterator cursorrow = cursorRow();
1241
1242                 setCursorFromCoordinates(cmd.x, cmd.y);
1243
1244                 // This is to allow jumping over large insets
1245                 // FIXME: shouldn't be top-text-specific
1246                 if (cursorrow == cursorRow() && !in_inset_) {
1247                         if (cmd.y - bv->top_y() >= bv->workHeight())
1248                                 cursorDown(true);
1249                         else if (cmd.y - bv->top_y() < 0)
1250                                 cursorUp(true);
1251                 }
1252                 setSelection();
1253                 break;
1254         }
1255
1256         // Single-click on work area
1257         case LFUN_MOUSE_PRESS: {
1258                 if (!bv->buffer())
1259                         break;
1260
1261                 // ok ok, this is a hack (for xforms)
1262                 // We shouldn't go further down as we really should only do the
1263                 // scrolling and be done with this. Otherwise we may open some
1264                 // dialogs (Jug 20020424).
1265                 if (cmd.button() == mouse_button::button4) {
1266                         bv->scroll(-lyxrc.wheel_jump);
1267                         break;
1268                 }
1269                 if (cmd.button() == mouse_button::button5) {
1270                         bv->scroll(lyxrc.wheel_jump);
1271                         break;
1272                 }
1273
1274                 // Middle button press pastes if we have a selection
1275                 // We do this here as if the selection was inside an inset
1276                 // it could get cleared on the unlocking of the inset so
1277                 // we have to check this first
1278                 bool paste_internally = false;
1279                 if (cmd.button() == mouse_button::button2 && selection.set()) {
1280                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1281                         paste_internally = true;
1282                 }
1283
1284                 selection_possible = true;
1285
1286                 // Clear the selection
1287                 clearSelection();
1288
1289                 // Right click on a footnote flag opens float menu
1290                 if (cmd.button() == mouse_button::button3) {
1291                         selection_possible = false;
1292                         break;
1293                 }
1294
1295                 setCursorFromCoordinates(cmd.x, cmd.y);
1296                 selection.cursor = cursor;
1297                 finishUndo();
1298                 bv->x_target(cursor.x() + xo_);
1299
1300                 if (bv->fitCursor())
1301                         selection_possible = false;
1302
1303                 // Insert primary selection with middle mouse
1304                 // if there is a local selection in the current buffer,
1305                 // insert this
1306                 if (cmd.button() == mouse_button::button2) {
1307                         if (paste_internally)
1308                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1309                         else
1310                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1311                         selection_possible = false;
1312                 }
1313                 break;
1314         }
1315
1316         case LFUN_MOUSE_RELEASE: {
1317                 if (!bv->buffer())
1318                         break;
1319
1320                 // do nothing if we used the mouse wheel
1321                 if (cmd.button() == mouse_button::button4
1322                  || cmd.button() == mouse_button::button5)
1323                         return DispatchResult(true, false);
1324
1325                 selection_possible = false;
1326
1327                 if (cmd.button() == mouse_button::button2)
1328                         break;
1329
1330                 // finish selection
1331                 if (cmd.button() == mouse_button::button1)
1332                         bv->haveSelection(selection.set());
1333
1334                 bv->switchKeyMap();
1335                 bv->owner()->view_state_changed();
1336                 bv->owner()->updateMenubar();
1337                 bv->owner()->updateToolbar();
1338                 break;
1339         }
1340
1341         case LFUN_SELFINSERT: {
1342                 if (cmd.argument.empty())
1343                         break;
1344
1345                 // Automatically delete the currently selected
1346                 // text and replace it with what is being
1347                 // typed in now. Depends on lyxrc settings
1348                 // "auto_region_delete", which defaults to
1349                 // true (on).
1350
1351                 if (lyxrc.auto_region_delete) {
1352                         if (selection.set())
1353                                 cutSelection(false, false);
1354                         bv->haveSelection(false);
1355                 }
1356
1357                 clearSelection();
1358                 LyXFont const old_font = real_current_font;
1359
1360                 string::const_iterator cit = cmd.argument.begin();
1361                 string::const_iterator end = cmd.argument.end();
1362                 for (; cit != end; ++cit)
1363                         bv->owner()->getIntl().getTransManager().
1364                                 TranslateAndInsert(*cit, this);
1365
1366                 selection.cursor = cursor;
1367                 moveCursor(bv, false);
1368
1369                 // real_current_font.number can change so we need to
1370                 // update the minibuffer
1371                 if (old_font != real_current_font)
1372                         bv->owner()->view_state_changed();
1373                 bv->updateScrollbar();
1374                 break;
1375         }
1376
1377         case LFUN_URL: {
1378                 InsetCommandParams p("url");
1379                 string const data = InsetCommandMailer::params2string("url", p);
1380                 bv->owner()->getDialogs().show("url", data, 0);
1381                 break;
1382         }
1383
1384         case LFUN_HTMLURL: {
1385                 InsetCommandParams p("htmlurl");
1386                 string const data = InsetCommandMailer::params2string("url", p);
1387                 bv->owner()->getDialogs().show("url", data, 0);
1388                 break;
1389         }
1390
1391         case LFUN_INSERT_LABEL: {
1392                 InsetCommandParams p("label");
1393                 string const data = InsetCommandMailer::params2string("label", p);
1394                 bv->owner()->getDialogs().show("label", data, 0);
1395                 break;
1396         }
1397
1398
1399 #if 0
1400         case LFUN_INSET_LIST:
1401         case LFUN_INSET_THEOREM:
1402         case LFUN_INSET_CAPTION:
1403 #endif
1404         case LFUN_INSERT_NOTE:
1405         case LFUN_INSERT_CHARSTYLE:
1406         case LFUN_INSERT_BOX:
1407         case LFUN_INSERT_BRANCH:
1408         case LFUN_INSERT_BIBITEM:
1409         case LFUN_INSET_ERT:
1410         case LFUN_INSET_FLOAT:
1411         case LFUN_INSET_FOOTNOTE:
1412         case LFUN_INSET_MARGINAL:
1413         case LFUN_INSET_MINIPAGE:
1414         case LFUN_INSET_OPTARG:
1415         case LFUN_INSET_WIDE_FLOAT:
1416         case LFUN_INSET_WRAP:
1417         case LFUN_TABULAR_INSERT:
1418         case LFUN_ENVIRONMENT_INSERT:
1419                 // Open the inset, and move the current selection
1420                 // inside it.
1421                 doInsertInset(this, cmd, true, true);
1422                 break;
1423
1424         case LFUN_INDEX_INSERT:
1425                 // Just open the inset
1426                 doInsertInset(this, cmd, true, false);
1427                 break;
1428
1429         case LFUN_INDEX_PRINT:
1430         case LFUN_TOC_INSERT:
1431         case LFUN_HFILL:
1432         case LFUN_INSERT_LINE:
1433         case LFUN_INSERT_PAGEBREAK:
1434                 // do nothing fancy
1435                 doInsertInset(this, cmd, false, false);
1436                 break;
1437
1438         case LFUN_DEPTH_MIN:
1439                 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
1440                 bv->update();
1441                 break;
1442
1443         case LFUN_DEPTH_PLUS:
1444                 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
1445                 bv->update();
1446                 break;
1447
1448         case LFUN_MATH_DELIM:
1449         case LFUN_MATH_DISPLAY:
1450         case LFUN_INSERT_MATH:
1451         case LFUN_MATH_LIMITS:
1452         case LFUN_MATH_MACRO:
1453         case LFUN_MATH_MUTATE:
1454         case LFUN_MATH_SPACE:
1455         case LFUN_MATH_IMPORT_SELECTION:
1456         case LFUN_MATH_MODE:
1457         case LFUN_MATH_NONUMBER:
1458         case LFUN_MATH_NUMBER:
1459         case LFUN_MATH_EXTERN:
1460         case LFUN_MATH_SIZE:
1461                 mathDispatch(cmd);
1462                 break;
1463
1464         case LFUN_EMPH:
1465                 emph(bv, this);
1466                 bv->owner()->view_state_changed();
1467                 break;
1468
1469         case LFUN_BOLD:
1470                 bold(bv, this);
1471                 bv->owner()->view_state_changed();
1472                 break;
1473
1474         case LFUN_NOUN:
1475                 noun(bv, this);
1476                 bv->owner()->view_state_changed();
1477                 break;
1478
1479         case LFUN_CODE:
1480                 code(bv, this);
1481                 bv->owner()->view_state_changed();
1482                 break;
1483
1484         case LFUN_SANS:
1485                 sans(bv, this);
1486                 bv->owner()->view_state_changed();
1487                 break;
1488
1489         case LFUN_ROMAN:
1490                 roman(bv, this);
1491                 bv->owner()->view_state_changed();
1492                 break;
1493
1494         case LFUN_DEFAULT:
1495                 styleReset(bv, this);
1496                 bv->owner()->view_state_changed();
1497                 break;
1498
1499         case LFUN_UNDERLINE:
1500                 underline(bv, this);
1501                 bv->owner()->view_state_changed();
1502                 break;
1503
1504         case LFUN_FONT_SIZE:
1505                 fontSize(bv, cmd.argument, this);
1506                 bv->owner()->view_state_changed();
1507                 break;
1508
1509         case LFUN_LANGUAGE:
1510                 lang(bv, cmd.argument, this);
1511                 bv->switchKeyMap();
1512                 bv->owner()->view_state_changed();
1513                 break;
1514
1515         case LFUN_FREEFONT_APPLY:
1516                 apply_freefont(bv, this);
1517                 break;
1518
1519         case LFUN_FREEFONT_UPDATE:
1520                 update_and_apply_freefont(bv, this, cmd.argument);
1521                 break;
1522
1523         case LFUN_FINISHED_LEFT:
1524                 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1525                 if (rtl())
1526                         cursorRight(true);
1527                 break;
1528
1529         case LFUN_FINISHED_RIGHT:
1530                 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1531                 if (!rtl())
1532                         cursorRight(true);
1533                 break;
1534
1535         case LFUN_FINISHED_UP:
1536                 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1537                 cursorUp(true);
1538                 break;
1539
1540         case LFUN_FINISHED_DOWN:
1541                 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1542                 cursorDown(true);
1543                 break;
1544
1545         default:
1546                 return DispatchResult(false);
1547         }
1548
1549         return DispatchResult(true, true);
1550 }