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