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