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