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