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