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