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