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