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