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