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