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