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