]> git.lyx.org Git - lyx.git/blob - src/text3.C
refrain from computing width in setHeightOfRow as this happens already
[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                                                  params.lineTop(),
724                                                  params.lineBottom(),
725                                                  params.pagebreakTop(),
726                                                  params.pagebreakBottom(),
727                                                  VSpace(VSpace::NONE),
728                                                  params.spaceBottom(),
729                                                  params.spacing(),
730                                                  params.align(),
731                                                  params.labelWidthString(), 0);
732                                         cursorLeft(bv);
733                                 } else {
734                                         cursorLeft(bv);
735                                         Delete();
736                                         selection.cursor = cursor;
737                                 }
738                         } else {
739                                 Delete();
740                                 selection.cursor = cursor;
741                         }
742                 } else {
743                         cutSelection(true, false);
744                 }
745                 bv->update();
746                 break;
747
748
749         case LFUN_BACKSPACE:
750                 if (!selection.set()) {
751                         if (bv->owner()->getIntl().getTransManager().backspace()) {
752                                 backspace();
753                                 selection.cursor = cursor;
754                                 // It is possible to make it a lot faster still
755                                 // just comment out the line below...
756                         }
757                 } else {
758                         cutSelection(true, false);
759                 }
760                 bv->owner()->view_state_changed();
761                 bv->switchKeyMap();
762                 bv->update();
763                 break;
764
765         case LFUN_BACKSPACE_SKIP:
766                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
767                 if (!selection.set()) {
768                         ParagraphParameters & params = cursorPar()->params();
769                         if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
770                                 setParagraph(
771                                          params.lineTop(),
772                                          params.lineBottom(),
773                                          params.pagebreakTop(),
774                                          params.pagebreakBottom(),
775                                          VSpace(VSpace::NONE),
776                                    params.spaceBottom(),
777                                          params.spacing(),
778                                          params.align(),
779                                          params.labelWidthString(), 0);
780                         } else {
781                                 LyXCursor cur = cursor;
782                                 backspace();
783                                 selection.cursor = cur;
784                         }
785                 } else {
786                         cutSelection(true, false);
787                 }
788                 bv->update();
789                 break;
790
791         case LFUN_BREAKPARAGRAPH:
792                 replaceSelection(bv->getLyXText());
793                 breakParagraph(bv->buffer()->paragraphs(), 0);
794                 bv->update();
795                 selection.cursor = cursor;
796                 bv->switchKeyMap();
797                 bv->owner()->view_state_changed();
798                 break;
799
800         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
801                 replaceSelection(bv->getLyXText());
802                 breakParagraph(bv->buffer()->paragraphs(), 1);
803                 bv->update();
804                 selection.cursor = cursor;
805                 bv->switchKeyMap();
806                 bv->owner()->view_state_changed();
807                 break;
808
809         case LFUN_BREAKPARAGRAPH_SKIP: {
810                 // When at the beginning of a paragraph, remove
811                 // indentation and add a "defskip" at the top.
812                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
813                 LyXCursor cur = cursor;
814                 replaceSelection(bv->getLyXText());
815                 if (cur.pos() == 0) {
816                         ParagraphParameters & params = getPar(cur)->params();
817                         if (params.spaceTop() == VSpace(VSpace::NONE)) {
818                                 setParagraph(
819                                          params.lineTop(),
820                                          params.lineBottom(),
821                                          params.pagebreakTop(),
822                                          params.pagebreakBottom(),
823                                          VSpace(VSpace::DEFSKIP), params.spaceBottom(),
824                                          params.spacing(),
825                                          params.align(),
826                                          params.labelWidthString(), 1);
827                         }
828                 }
829                 else {
830                         breakParagraph(bv->buffer()->paragraphs(), 0);
831                 }
832                 bv->update();
833                 selection.cursor = cur;
834                 bv->switchKeyMap();
835                 bv->owner()->view_state_changed();
836                 break;
837         }
838
839         case LFUN_PARAGRAPH_SPACING: {
840                 ParagraphList::iterator pit = cursorPar();
841                 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
842                 float cur_value = 1.0;
843                 if (cur_spacing == Spacing::Other)
844                         cur_value = pit->params().spacing().getValue();
845
846                 istringstream is(cmd.argument);
847                 string tmp;
848                 is >> tmp;
849                 Spacing::Space new_spacing = cur_spacing;
850                 float new_value = cur_value;
851                 if (tmp.empty()) {
852                         lyxerr << "Missing argument to `paragraph-spacing'"
853                                << endl;
854                 } else if (tmp == "single") {
855                         new_spacing = Spacing::Single;
856                 } else if (tmp == "onehalf") {
857                         new_spacing = Spacing::Onehalf;
858                 } else if (tmp == "double") {
859                         new_spacing = Spacing::Double;
860                 } else if (tmp == "other") {
861                         new_spacing = Spacing::Other;
862                         float tmpval = 0.0;
863                         is >> tmpval;
864                         lyxerr << "new_value = " << tmpval << endl;
865                         if (tmpval != 0.0)
866                                 new_value = tmpval;
867                 } else if (tmp == "default") {
868                         new_spacing = Spacing::Default;
869                 } else {
870                         lyxerr << _("Unknown spacing argument: ")
871                                << cmd.argument << endl;
872                 }
873                 if (cur_spacing != new_spacing || cur_value != new_value) {
874                         pit->params().spacing(Spacing(new_spacing, new_value));
875                         redoParagraph();
876                         bv->update();
877                 }
878                 break;
879         }
880
881         case LFUN_INSET_SETTINGS:
882                 BOOST_ASSERT(bv->theLockingInset());
883                 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
884                 break;
885
886         case LFUN_INSET_TOGGLE:
887                 bv->beforeChange(this);
888                 toggleInset();
889                 bv->update();
890                 bv->switchKeyMap();
891                 break;
892
893         case LFUN_SPACE_INSERT:
894                 if (cursorPar()->layout()->free_spacing)
895                         insertChar(' ');
896                 else
897                         doInsertInset(this, cmd, false, false);
898                 moveCursorUpdate(bv, false);
899                 break;
900
901         case LFUN_HYPHENATION:
902                 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
903                 break;
904
905         case LFUN_LIGATURE_BREAK:
906                 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
907                 break;
908
909         case LFUN_LDOTS:
910                 specialChar(this, bv, InsetSpecialChar::LDOTS);
911                 break;
912
913         case LFUN_END_OF_SENTENCE:
914                 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
915                 break;
916
917         case LFUN_MENU_SEPARATOR:
918                 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
919                 break;
920
921         case LFUN_MARK_OFF:
922                 bv->beforeChange(this);
923                 bv->update();
924                 selection.cursor = cursor;
925                 cmd.message(N_("Mark off"));
926                 break;
927
928         case LFUN_MARK_ON:
929                 bv->beforeChange(this);
930                 selection.mark(true);
931                 bv->update();
932                 selection.cursor = cursor;
933                 cmd.message(N_("Mark on"));
934                 break;
935
936         case LFUN_SETMARK:
937                 bv->beforeChange(this);
938                 if (selection.mark()) {
939                         cmd.message(N_("Mark removed"));
940                 } else {
941                         selection.mark(true);
942                         cmd.message(N_("Mark set"));
943                 }
944                 selection.cursor = cursor;
945                 bv->update();
946                 break;
947
948         case LFUN_UPCASE_WORD:
949                 changeCase(LyXText::text_uppercase);
950                 bv->update();
951                 break;
952
953         case LFUN_LOWCASE_WORD:
954                 changeCase(LyXText::text_lowercase);
955                 bv->update();
956                 break;
957
958         case LFUN_CAPITALIZE_WORD:
959                 changeCase(LyXText::text_capitalization);
960                 bv->update();
961                 break;
962
963         case LFUN_TRANSPOSE_CHARS:
964                 recUndo(cursor.par());
965                 redoParagraph();
966                 bv->update();
967                 break;
968
969         case LFUN_PASTE:
970                 cmd.message(_("Paste"));
971                 replaceSelection(bv->getLyXText());
972 #warning FIXME Check if the arg is in the domain of available selections.
973                 if (isStrUnsignedInt(cmd.argument))
974                         pasteSelection(strToUnsignedInt(cmd.argument));
975                 else
976                         pasteSelection(0);
977                 clearSelection(); // bug 393
978                 bv->update();
979                 bv->switchKeyMap();
980                 finishUndo();
981                 break;
982
983         case LFUN_CUT:
984                 cutSelection(true, true);
985                 cmd.message(_("Cut"));
986                 bv->update();
987                 break;
988
989         case LFUN_COPY:
990                 copySelection();
991                 cmd.message(_("Copy"));
992                 break;
993
994         case LFUN_BEGINNINGBUFSEL:
995                 if (inset_owner)
996                         return UNDISPATCHED;
997                 cursorTop();
998                 finishChange(bv, true);
999                 break;
1000
1001         case LFUN_ENDBUFSEL:
1002                 if (inset_owner)
1003                         return UNDISPATCHED;
1004                 cursorBottom();
1005                 finishChange(bv, true);
1006                 break;
1007
1008         case LFUN_GETXY:
1009                 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1010                 break;
1011
1012         case LFUN_SETXY: {
1013                 int x = 0;
1014                 int y = 0;
1015                 istringstream is(cmd.argument);
1016                 is >> x >> y;
1017                 if (!is)
1018                         lyxerr << "SETXY: Could not parse coordinates in '"
1019                                << cmd.argument << std::endl;
1020                 else
1021                         setCursorFromCoordinates(x, y);
1022                 break;
1023         }
1024
1025         case LFUN_GETFONT:
1026                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1027                         cmd.message("E");
1028                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1029                         cmd.message("N");
1030                 else
1031                         cmd.message("0");
1032                 break;
1033
1034         case LFUN_GETLAYOUT:
1035                 cmd.message(tostr(cursorPar()->layout()));
1036                 break;
1037
1038         case LFUN_LAYOUT: {
1039                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1040                   << cmd.argument << endl;
1041
1042                 // This is not the good solution to the empty argument
1043                 // problem, but it will hopefully suffice for 1.2.0.
1044                 // The correct solution would be to augument the
1045                 // function list/array with information about what
1046                 // functions needs arguments and their type.
1047                 if (cmd.argument.empty()) {
1048                         cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1049                         break;
1050                 }
1051
1052                 // Derive layout number from given argument (string)
1053                 // and current buffer's textclass (number)
1054                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1055                 bool hasLayout = tclass.hasLayout(cmd.argument);
1056                 string layout = cmd.argument;
1057
1058                 // If the entry is obsolete, use the new one instead.
1059                 if (hasLayout) {
1060                         string const & obs = tclass[layout]->obsoleted_by();
1061                         if (!obs.empty())
1062                                 layout = obs;
1063                 }
1064
1065                 if (!hasLayout) {
1066                         cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1067                                 N_(" not known"));
1068                         break;
1069                 }
1070
1071                 bool change_layout = (current_layout != layout);
1072
1073                 if (!change_layout && selection.set() &&
1074                         selection.start.par() != selection.end.par())
1075                 {
1076                         ParagraphList::iterator spit = getPar(selection.start);
1077                         ParagraphList::iterator epit = boost::next(getPar(selection.end));
1078                         while (spit != epit) {
1079                                 if (spit->layout()->name() != current_layout) {
1080                                         change_layout = true;
1081                                         break;
1082                                 }
1083                                 ++spit;
1084                         }
1085                 }
1086
1087                 if (change_layout) {
1088                         current_layout = layout;
1089                         setLayout(layout);
1090                         bv->owner()->setLayout(layout);
1091                         bv->update();
1092                         bv->switchKeyMap();
1093                 }
1094                 break;
1095         }
1096
1097         case LFUN_PASTESELECTION: {
1098                 // this was originally a beforeChange(bv->text), i.e
1099                 // the outermost LyXText!
1100                 bv->beforeChange(this);
1101                 string const clip = bv->getClipboard();
1102                 if (!clip.empty()) {
1103                         if (cmd.argument == "paragraph")
1104                                 insertStringAsParagraphs(clip);
1105                         else
1106                                 insertStringAsLines(clip);
1107                         clearSelection();
1108                         bv->update();
1109                 }
1110                 break;
1111         }
1112
1113         case LFUN_GOTOERROR:
1114                 gotoInset(InsetOld::ERROR_CODE, false);
1115                 break;
1116
1117         case LFUN_GOTONOTE:
1118                 gotoInset(InsetOld::NOTE_CODE, false);
1119                 break;
1120
1121         case LFUN_REFERENCE_GOTO:
1122         {
1123                 vector<InsetOld::Code> tmp;
1124                 tmp.push_back(InsetOld::LABEL_CODE);
1125                 tmp.push_back(InsetOld::REF_CODE);
1126                 gotoInset(tmp, true);
1127                 break;
1128         }
1129
1130         case LFUN_QUOTE: {
1131                 replaceSelection(bv->getLyXText());
1132                 ParagraphList::iterator pit = cursorPar();
1133                 lyx::pos_type pos = cursor.pos();
1134                 char c;
1135                 if (!pos)
1136                         c = ' ';
1137                 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1138                         c = ' ';
1139                 else
1140                         c = pit->getChar(pos - 1);
1141
1142                 LyXLayout_ptr const & style = pit->layout();
1143
1144                 BufferParams const & bufparams = bv->buffer()->params();
1145                 if (style->pass_thru ||
1146                     pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1147                     !bv->insertInset(new InsetQuotes(c, bufparams)))
1148                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1149                 break;
1150         }
1151
1152         case LFUN_DATE_INSERT: {
1153                 replaceSelection(bv->getLyXText());
1154                 time_t now_time_t = time(NULL);
1155                 struct tm * now_tm = localtime(&now_time_t);
1156                 setlocale(LC_TIME, "");
1157                 string arg;
1158                 if (!cmd.argument.empty())
1159                         arg = cmd.argument;
1160                 else
1161                         arg = lyxrc.date_insert_format;
1162                 char datetmp[32];
1163                 int const datetmp_len =
1164                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1165
1166                 for (int i = 0; i < datetmp_len; i++)
1167                         insertChar(datetmp[i]);
1168
1169                 selection.cursor = cursor;
1170                 moveCursorUpdate(bv, false);
1171                 break;
1172         }
1173
1174         case LFUN_MOUSE_TRIPLE:
1175                 if (!bv->buffer())
1176                         break;
1177                 if (!isInInset() && bv->theLockingInset())
1178                         break;
1179                 if (cmd.button() == mouse_button::button1) {
1180                         cursorHome();
1181                         selection.cursor = cursor;
1182                         cursorEnd();
1183                         setSelection();
1184                         bv->update();
1185                         bv->haveSelection(selection.set());
1186                 }
1187                 break;
1188
1189         case LFUN_MOUSE_DOUBLE:
1190                 if (!bv->buffer())
1191                         break;
1192                 if (!isInInset() && bv->theLockingInset())
1193                         break;
1194                 if (cmd.button() == mouse_button::button1) {
1195                         selectWord(lyx::WHOLE_WORD_STRICT);
1196                         bv->update();
1197                         bv->haveSelection(selection.set());
1198                 }
1199                 break;
1200
1201         case LFUN_MOUSE_MOTION:
1202         {
1203                 // Only use motion with button 1
1204                 //if (ev.button() != mouse_button::button1)
1205                 //      return false;
1206
1207                 if (!bv->buffer())
1208                         break;
1209
1210                 // Check for inset locking
1211                 if (bv->theLockingInset()) {
1212                         InsetOld * tli = bv->theLockingInset();
1213                         LyXCursor cursor = bv->text->cursor;
1214                         LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
1215                         int width = tli->width();
1216                         int inset_x = font.isVisibleRightToLeft()
1217                                 ? cursor.x() - width : cursor.x();
1218                         int start_x = inset_x + tli->scroll();
1219                         FuncRequest cmd1 = cmd;
1220                         cmd1.x = cmd.x - start_x;
1221                         cmd1.y = cmd.y - cursor.y() + bv->top_y();
1222                         tli->dispatch(cmd1);
1223                         break;
1224                 }
1225
1226                 // The test for not selection possible is needed, that only motion
1227                 // events are used, where the bottom press event was on
1228                 //  the drawing area too
1229                 if (!selection_possible) {
1230                         lyxerr[Debug::ACTION]
1231                                 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1232                         break;
1233                 }
1234
1235                 RowList::iterator cursorrow = bv->text->cursorRow();
1236                 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
1237         #if 0
1238                 // sorry for this but I have a strange error that the y value jumps at
1239                 // a certain point. This seems like an error in my xforms library or
1240                 // in some other local environment, but I would like to leave this here
1241                 // for the moment until I can remove this (Jug 20020418)
1242                 if (y_before < bv->text->cursor.y())
1243                         lyxerr << y_before << ':'
1244                                << bv->text->cursor.y() << endl;
1245         #endif
1246                 // This is to allow jumping over large insets
1247                 if (cursorrow == bv->text->cursorRow()) {
1248                         if (cmd.y >= bv->workHeight())
1249                                 bv->text->cursorDown(false);
1250                         else if (cmd.y < 0)
1251                                 bv->text->cursorUp(false);
1252                 }
1253
1254                 bv->text->setSelection();
1255                 bv->update();
1256                 break;
1257         }
1258
1259         // Single-click on work area
1260         case LFUN_MOUSE_PRESS:
1261         {
1262                 if (!bv->buffer())
1263                         break;
1264
1265                 // ok ok, this is a hack (for xforms)
1266                 // We shouldn't go further down as we really should only do the
1267                 // scrolling and be done with this. Otherwise we may open some
1268                 // dialogs (Jug 20020424).
1269                 if (cmd.button() == mouse_button::button4) {
1270                         bv->scroll(-lyxrc.wheel_jump);
1271                         break;
1272                 }
1273                 if (cmd.button() == mouse_button::button5) {
1274                         bv->scroll(lyxrc.wheel_jump);
1275                         break;
1276                 }
1277
1278                 int x = cmd.x;
1279                 int y = cmd.y;
1280                 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1281
1282                 // Middle button press pastes if we have a selection
1283                 // We do this here as if the selection was inside an inset
1284                 // it could get cleared on the unlocking of the inset so
1285                 // we have to check this first
1286                 bool paste_internally = false;
1287                 if (cmd.button() == mouse_button::button2 && selection.set()) {
1288                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1289                         paste_internally = true;
1290                 }
1291
1292                 int const screen_first = bv->top_y();
1293
1294                 if (bv->theLockingInset()) {
1295                         // We are in inset locking mode
1296
1297                         // Check whether the inset was hit. If not reset mode,
1298                         // otherwise give the event to the inset
1299                         if (inset_hit == bv->theLockingInset()) {
1300                                 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1301                                 bv->theLockingInset()->dispatch(cmd1);
1302                                 break;
1303                         }
1304                         bv->unlockInset(bv->theLockingInset());
1305                 }
1306
1307                 if (!inset_hit)
1308                         selection_possible = true;
1309
1310                 // Clear the selection
1311                 bv->text->clearSelection();
1312                 bv->update();
1313                 bv->updateScrollbar();
1314
1315                 // Single left click in math inset?
1316                 if (isHighlyEditableInset(inset_hit)) {
1317                         // Highly editable inset, like math
1318                         UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1319                         selection_possible = false;
1320                         bv->owner()->message(inset->editMessage());
1321                         // We just have to lock the inset before calling a PressEvent on it!
1322                         if (!bv->lockInset(inset))
1323                                 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1324                         FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1325                         inset->dispatch(cmd1);
1326                         break;
1327                 }
1328                 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1329
1330                 // Right click on a footnote flag opens float menu
1331                 if (cmd.button() == mouse_button::button3) {
1332                         selection_possible = false;
1333                         break;
1334                 }
1335
1336                 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1337                         bv->text->setCursorFromCoordinates(x, y + screen_first);
1338                 finishUndo();
1339                 bv->text->selection.cursor = bv->text->cursor;
1340                 bv->text->cursor.x_fix(bv->text->cursor.x());
1341
1342                 if (bv->fitCursor())
1343                         selection_possible = false;
1344
1345                 // Insert primary selection with middle mouse
1346                 // if there is a local selection in the current buffer,
1347                 // insert this
1348                 if (cmd.button() == mouse_button::button2) {
1349                         if (paste_internally)
1350                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1351                         else
1352                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1353                         selection_possible = false;
1354                 }
1355                 break;
1356         }
1357
1358         case LFUN_MOUSE_RELEASE:
1359         {
1360                 // do nothing if we used the mouse wheel
1361                 if (!bv->buffer())
1362                         break;
1363
1364                 if (cmd.button() == mouse_button::button4
1365                  || cmd.button() == mouse_button::button5)
1366                         break;
1367
1368                 // If we hit an inset, we have the inset coordinates in these
1369                 // and inset_hit points to the inset.  If we do not hit an
1370                 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1371                 int x = cmd.x;
1372                 int y = cmd.y;
1373                 InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
1374
1375                 if (bv->theLockingInset()) {
1376                         // We are in inset locking mode.
1377
1378                         // LyX does a kind of work-area grabbing for insets.
1379                         // Only a ButtonPress FuncRequest outside the inset will
1380                         // force a insetUnlock.
1381                         FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1382                         bv->theLockingInset()->dispatch(cmd1);
1383                         break;
1384                 }
1385
1386                 selection_possible = false;
1387
1388                 if (cmd.button() == mouse_button::button2)
1389                         break;
1390
1391                 // finish selection
1392                 if (cmd.button() == mouse_button::button1)
1393                         bv->haveSelection(selection.set());
1394
1395                 bv->switchKeyMap();
1396                 bv->owner()->view_state_changed();
1397                 bv->owner()->updateMenubar();
1398                 bv->owner()->updateToolbar();
1399
1400                 // Did we hit an editable inset?
1401                 if (inset_hit) {
1402                         selection_possible = false;
1403
1404                         // if we reach this point with a selection, it
1405                         // must mean we are currently selecting.
1406                         // But we don't want to open the inset
1407                         // because that is annoying for the user.
1408                         // So just pretend we didn't hit it.
1409                         // this is OK because a "kosher" ButtonRelease
1410                         // will follow a ButtonPress that clears
1411                         // the selection.
1412                         // Note this also fixes selection drawing
1413                         // problems if we end up opening an inset
1414                         if (selection.set())
1415                                 break;
1416
1417                         // CHECK fix this proper in 0.13
1418                         // well, maybe 13.0 !!!!!!!!!
1419
1420                         // Following a ref shouldn't issue
1421                         // a push on the undo-stack
1422                         // anylonger, now that we have
1423                         // keybindings for following
1424                         // references and returning from
1425                         // references.  IMHO though, it
1426                         // should be the inset's own business
1427                         // to push or not push on the undo
1428                         // stack. They don't *have* to
1429                         // alter the document...
1430                         // (Joacim)
1431                         // ...or maybe the recordUndo()
1432                         // below isn't necessary at all anylonger?
1433                         if (inset_hit->lyxCode() == InsetOld::REF_CODE)
1434                                 recUndo(cursor.par());
1435
1436                         bv->owner()->message(inset_hit->editMessage());
1437
1438                         FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1439                         inset_hit->dispatch(cmd1);
1440                 }
1441
1442                 break;
1443         }
1444
1445         case LFUN_SELFINSERT: {
1446                 if (cmd.argument.empty())
1447                         break;
1448
1449                 // Automatically delete the currently selected
1450                 // text and replace it with what is being
1451                 // typed in now. Depends on lyxrc settings
1452                 // "auto_region_delete", which defaults to
1453                 // true (on).
1454
1455                 if (lyxrc.auto_region_delete) {
1456                         if (selection.set())
1457                                 cutSelection(false, false);
1458                         bv->haveSelection(false);
1459                 }
1460
1461                 bv->beforeChange(this);
1462                 LyXFont const old_font = real_current_font;
1463
1464                 string::const_iterator cit = cmd.argument.begin();
1465                 string::const_iterator end = cmd.argument.end();
1466                 for (; cit != end; ++cit)
1467                         bv->owner()->getIntl().getTransManager().
1468                                 TranslateAndInsert(*cit, this);
1469
1470                 selection.cursor = cursor;
1471                 moveCursorUpdate(bv, false);
1472
1473                 // real_current_font.number can change so we need to
1474                 // update the minibuffer
1475                 if (old_font != real_current_font)
1476                         bv->owner()->view_state_changed();
1477                 bv->updateScrollbar();
1478                 break;
1479         }
1480
1481         case LFUN_HTMLURL: {
1482                 InsetCommandParams p("htmlurl");
1483                 string const data = InsetCommandMailer::params2string("url", p);
1484                 bv->owner()->getDialogs().show("url", data, 0);
1485                 break;
1486         }
1487
1488         case LFUN_URL: {
1489                 InsetCommandParams p("url");
1490                 string const data = InsetCommandMailer::params2string("url", p);
1491                 bv->owner()->getDialogs().show("url", data, 0);
1492                 break;
1493         }
1494
1495
1496 #if 0
1497         case LFUN_INSET_LIST:
1498         case LFUN_INSET_THEOREM:
1499         case LFUN_INSET_CAPTION:
1500 #endif
1501         case LFUN_INSERT_NOTE:
1502         case LFUN_INSERT_BOX:
1503         case LFUN_INSERT_BRANCH:
1504         case LFUN_INSERT_BIBITEM:
1505         case LFUN_INSET_ERT:
1506         case LFUN_INSET_FLOAT:
1507         case LFUN_INSET_FOOTNOTE:
1508         case LFUN_INSET_MARGINAL:
1509         case LFUN_INSET_MINIPAGE:
1510         case LFUN_INSET_OPTARG:
1511         case LFUN_INSET_WIDE_FLOAT:
1512         case LFUN_INSET_WRAP:
1513         case LFUN_TABULAR_INSERT:
1514         case LFUN_ENVIRONMENT_INSERT:
1515                 // Open the inset, and move the current selection
1516                 // inside it.
1517                 doInsertInset(this, cmd, true, true);
1518                 break;
1519
1520         case LFUN_INDEX_INSERT:
1521                 // Just open the inset
1522                 doInsertInset(this, cmd, true, false);
1523                 break;
1524
1525         case LFUN_INDEX_PRINT:
1526         case LFUN_TOC_INSERT:
1527         case LFUN_HFILL:
1528                 // do nothing fancy
1529                 doInsertInset(this, cmd, false, false);
1530                 break;
1531
1532         case LFUN_DEPTH_MIN:
1533                 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1534                 clearSelection();
1535                 bv->update();
1536                 break;
1537
1538         case LFUN_DEPTH_PLUS:
1539                 clearSelection();
1540                 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1541                 clearSelection();
1542                 bv->update();
1543                 break;
1544
1545         default:
1546                 return UNDISPATCHED;
1547         }
1548
1549         return DISPATCHED;
1550 }