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