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