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