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