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