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