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