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