]> git.lyx.org Git - lyx.git/blob - src/text3.C
Fix bug 886 and others not reported related with the document paper size.
[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 "FloatList.h"
21 #include "FuncStatus.h"
22 #include "buffer.h"
23 #include "buffer_funcs.h"
24 #include "bufferparams.h"
25 #include "BufferView.h"
26 #include "cursor.h"
27 #include "coordcache.h"
28 #include "CutAndPaste.h"
29 #include "debug.h"
30 #include "dispatchresult.h"
31 #include "factory.h"
32 #include "funcrequest.h"
33 #include "gettext.h"
34 #include "intl.h"
35 #include "language.h"
36 #include "LyXAction.h"
37 #include "lyxfunc.h"
38 #include "lyxlex.h"
39 #include "lyxrc.h"
40 #include "lyxrow.h"
41 #include "paragraph.h"
42 #include "paragraph_funcs.h"
43 #include "ParagraphParameters.h"
44 #include "undo.h"
45 #include "vspace.h"
46
47 #include "frontends/Dialogs.h"
48 #include "frontends/LyXView.h"
49
50 #include "insets/insetcommand.h"
51 #include "insets/insetfloatlist.h"
52 #include "insets/insetnewline.h"
53 #include "insets/insetquotes.h"
54 #include "insets/insetspecialchar.h"
55 #include "insets/insettext.h"
56
57 #include "support/lstrings.h"
58 #include "support/lyxlib.h"
59 #include "support/convert.h"
60 #include "support/lyxtime.h"
61
62 #include "mathed/math_hullinset.h"
63 #include "mathed/math_macrotemplate.h"
64
65 #include <boost/current_function.hpp>
66
67 #include <clocale>
68 #include <sstream>
69
70 using lyx::pos_type;
71
72 using lyx::cap::copySelection;
73 using lyx::cap::cutSelection;
74 using lyx::cap::pasteSelection;
75 using lyx::cap::replaceSelection;
76
77 using lyx::support::isStrUnsignedInt;
78 using lyx::support::token;
79
80 using std::endl;
81 using std::string;
82 using std::istringstream;
83
84
85 extern string current_layout;
86
87
88 namespace {
89
90         // globals...
91         LyXFont freefont(LyXFont::ALL_IGNORE);
92         bool toggleall = false;
93
94
95         void toggleAndShow(LCursor & cur, LyXText * text,
96                 LyXFont const & font, bool toggleall = true)
97         {
98                 text->toggleFree(cur, font, toggleall);
99
100                 if (font.language() != ignore_language ||
101                                 font.number() != LyXFont::IGNORE) {
102                         Paragraph & par = cur.paragraph();
103                         text->bidi.computeTables(par, cur.buffer(), cur.textRow());
104                         if (cur.boundary() !=
105                                         text->bidi.isBoundary(cur.buffer(), par,
106                                                         cur.pos(),
107                                                         text->real_current_font))
108                                 text->setCursor(cur, cur.pit(), cur.pos(),
109                                                 false, !cur.boundary());
110                 }
111         }
112
113
114         void moveCursor(LCursor & cur, bool selecting)
115         {
116                 if (selecting || cur.mark())
117                         cur.setSelection();
118                 if (!cur.selection())
119                         cur.bv().haveSelection(false);
120                 cur.bv().switchKeyMap();
121         }
122
123
124         void finishChange(LCursor & cur, bool selecting)
125         {
126                 finishUndo();
127                 moveCursor(cur, selecting);
128         }
129
130
131         void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
132         {
133                 recordUndo(cur);
134                 string sel = cur.selectionAsString(false);
135                 //lyxerr << "selection is: '" << sel << "'" << endl;
136
137                 if (sel.empty()) {
138                         const int old_pos = cur.pos();
139                         cur.insert(new MathHullInset);
140                         BOOST_ASSERT(old_pos == cur.pos());
141                         cur.nextInset()->edit(cur, true);
142                         cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
143                         // don't do that also for LFUN_MATH_MODE
144                         // unless you want end up with always changing
145                         // to mathrm when opening an inlined inset --
146                         // I really hate "LyXfunc overloading"...
147                         if (display)
148                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
149                         cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
150                 } else {
151                         // create a macro if we see "\\newcommand"
152                         // somewhere, and an ordinary formula
153                         // otherwise
154                         cutSelection(cur, true, true);
155                         if (sel.find("\\newcommand") == string::npos
156                             && sel.find("\\def") == string::npos)
157                         {
158                                 cur.insert(new MathHullInset);
159                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
160                                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
161                                 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
162                         } else {
163                                 istringstream is(sel);
164                                 cur.insert(new MathMacroTemplate(is));
165                         }
166                 }
167                 cur.message(N_("Math editor mode"));
168         }
169
170 } // namespace anon
171
172
173
174 namespace bv_funcs {
175
176 string const freefont2string()
177 {
178         string data;
179         if (font2string(freefont, toggleall, data))
180                 return data;
181         return string();
182 }
183
184 }
185
186 bool LyXText::cursorPrevious(LCursor & cur)
187 {
188         pos_type cpos = cur.pos();
189         lyx::pit_type cpar = cur.pit();
190
191         int x = cur.x_target();
192
193         setCursorFromCoordinates(cur, x, 0);
194         bool updated = cursorUp(cur);
195
196         if (cpar == cur.pit() && cpos == cur.pos()) {
197                 // we have a row which is taller than the workarea. The
198                 // simplest solution is to move to the previous row instead.
199                 updated |= cursorUp(cur);
200         }
201
202         cur.bv().updateScrollbar();
203         finishUndo();
204         return updated;
205 }
206
207
208 bool LyXText::cursorNext(LCursor & cur)
209 {
210         pos_type cpos = cur.pos();
211         lyx::pit_type cpar = cur.pit();
212
213         int x = cur.x_target();
214         setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
215         bool updated = cursorDown(cur);
216
217         if (cpar == cur.pit() && cpos == cur.pos()) {
218                 // we have a row which is taller than the workarea. The
219                 // simplest solution is to move to the next row instead.
220                 updated |= cursorDown(cur);
221         }
222
223         cur.bv().updateScrollbar();
224         finishUndo();
225         return updated;
226 }
227
228
229 namespace {
230
231 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
232 {
233         lyx::cap::replaceSelection(cur);
234         cur.insert(new InsetSpecialChar(kind));
235         cur.posRight();
236 }
237
238
239 bool doInsertInset(LCursor & cur, LyXText * text,
240         FuncRequest const & cmd, bool edit, bool pastesel)
241 {
242         InsetBase * inset = createInset(&cur.bv(), cmd);
243         if (!inset)
244                 return false;
245
246         recordUndo(cur);
247         bool gotsel = false;
248         if (cur.selection()) {
249                 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
250                 gotsel = true;
251         }
252         text->insertInset(cur, inset);
253
254         if (edit)
255                 inset->edit(cur, true);
256
257         if (gotsel && pastesel)
258                 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
259         return true;
260 }
261
262
263 void update(LCursor & cur)
264 {
265         //we don't call update(true, false) directly to save a metrics call
266         if (cur.bv().fitCursor())
267                 cur.bv().update(Update::Force);
268 }
269
270
271 } // anon namespace
272
273
274 void LyXText::number(LCursor & cur)
275 {
276         LyXFont font(LyXFont::ALL_IGNORE);
277         font.setNumber(LyXFont::TOGGLE);
278         toggleAndShow(cur, this, font);
279 }
280
281
282 bool LyXText::isRTL(Paragraph const & par) const
283 {
284         return par.isRightToLeftPar(bv()->buffer()->params());
285 }
286
287
288 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
289 {
290         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
291
292         BOOST_ASSERT(cur.text() == this);
293         BufferView * bv = &cur.bv();
294         CursorSlice oldTopSlice = cur.top();
295         bool oldBoundary = cur.boundary();
296         bool sel = cur.selection();
297         bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
298
299         switch (cmd.action) {
300
301         case LFUN_APPENDIX: {
302                 Paragraph & par = cur.paragraph();
303                 bool start = !par.params().startOfAppendix();
304
305 #ifdef WITH_WARNINGS
306 #warning The code below only makes sense at top level.
307 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
308 #endif
309                 // ensure that we have only one start_of_appendix in this document
310                 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
311                         if (pars_[tmp].params().startOfAppendix()) {
312                                 recUndo(tmp);
313                                 pars_[tmp].params().startOfAppendix(false);
314                                 break;
315                         }
316                 }
317
318                 recordUndo(cur);
319                 par.params().startOfAppendix(start);
320
321                 // we can set the refreshing parameters now
322                 updateCounters(cur.buffer());
323                 break;
324         }
325
326         case LFUN_DELETE_WORD_FORWARD:
327                 cur.clearSelection();
328                 deleteWordForward(cur);
329                 finishChange(cur, false);
330                 break;
331
332         case LFUN_DELETE_WORD_BACKWARD:
333                 cur.clearSelection();
334                 deleteWordBackward(cur);
335                 finishChange(cur, false);
336                 break;
337
338         case LFUN_DELETE_LINE_FORWARD:
339                 cur.clearSelection();
340                 deleteLineForward(cur);
341                 finishChange(cur, false);
342                 break;
343
344         case LFUN_WORDRIGHT:
345                 if (!cur.mark())
346                         cur.clearSelection();
347                 if (isRTL(cur.paragraph()))
348                         needsUpdate = cursorLeftOneWord(cur);
349                 else
350                         needsUpdate = cursorRightOneWord(cur);
351                 finishChange(cur, false);
352                 break;
353
354         case LFUN_WORDLEFT:
355                 if (!cur.mark())
356                         cur.clearSelection();
357                 if (isRTL(cur.paragraph()))
358                         needsUpdate = cursorRightOneWord(cur);
359                 else
360                         needsUpdate = cursorLeftOneWord(cur);
361                 finishChange(cur, false);
362                 break;
363
364         case LFUN_BEGINNINGBUF:
365                 if (cur.depth() == 1) {
366                         if (!cur.mark())
367                                 cur.clearSelection();
368                         cursorTop(cur);
369                         finishChange(cur, false);
370                 } else {
371                         cur.undispatched();
372                 }
373                 break;
374
375         case LFUN_BEGINNINGBUFSEL:
376                 if (cur.depth() == 1) {
377                         if (!cur.selection())
378                                 cur.resetAnchor();
379                         cursorTop(cur);
380                         finishChange(cur, true);
381                 } else {
382                         cur.undispatched();
383                 }
384                 break;
385
386         case LFUN_ENDBUF:
387                 if (cur.depth() == 1) {
388                         if (!cur.mark())
389                                 cur.clearSelection();
390                         cursorBottom(cur);
391                         finishChange(cur, false);
392                 } else {
393                         cur.undispatched();
394                 }
395                 break;
396
397         case LFUN_ENDBUFSEL:
398                 if (cur.depth() == 1) {
399                         if (!cur.selection())
400                                 cur.resetAnchor();
401                         cursorBottom(cur);
402                         finishChange(cur, true);
403                 } else {
404                         cur.undispatched();
405                 }
406                 break;
407
408         case LFUN_RIGHT:
409         case LFUN_RIGHTSEL:
410                 //lyxerr << BOOST_CURRENT_FUNCTION
411                 //       << " LFUN_RIGHT[SEL]:\n" << cur << endl;
412                 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
413                 if (isRTL(cur.paragraph()))
414                         needsUpdate = cursorLeft(cur);
415                 else
416                         needsUpdate = cursorRight(cur);
417
418                 if (!needsUpdate && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
419                         cur.undispatched();
420                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
421                 }
422                 break;
423
424         case LFUN_LEFT:
425         case LFUN_LEFTSEL:
426                 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
427                 cur.selHandle(cmd.action == LFUN_LEFTSEL);
428                 if (isRTL(cur.paragraph()))
429                         needsUpdate = cursorRight(cur);
430                 else
431                         needsUpdate = cursorLeft(cur);
432                 if (oldTopSlice == cur.top()) {
433                         cur.undispatched();
434                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
435                 }
436                 break;
437
438         case LFUN_UP:
439         case LFUN_UPSEL:
440                 update(cur);
441                 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
442                 cur.selHandle(cmd.action == LFUN_UPSEL);
443                 needsUpdate = cursorUp(cur);
444                 if (oldTopSlice == cur.top()) {
445                         cur.undispatched();
446                         cmd = FuncRequest(LFUN_FINISHED_UP);
447                 }
448                 break;
449
450         case LFUN_DOWN:
451         case LFUN_DOWNSEL:
452                 update(cur);
453                 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
454                 cur.selHandle(cmd.action == LFUN_DOWNSEL);
455                 needsUpdate = cursorDown(cur);
456                 if (oldTopSlice == cur.top()) {
457                         cur.undispatched();
458                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
459                 }
460                 break;
461
462         case LFUN_UP_PARAGRAPH:
463                 if (!cur.mark())
464                         cur.clearSelection();
465                 needsUpdate = cursorUpParagraph(cur);
466                 finishChange(cur, false);
467                 break;
468
469         case LFUN_UP_PARAGRAPHSEL:
470                 if (!cur.selection())
471                         cur.resetAnchor();
472                 cursorUpParagraph(cur);
473                 finishChange(cur, true);
474                 break;
475
476         case LFUN_DOWN_PARAGRAPH:
477                 if (!cur.mark())
478                         cur.clearSelection();
479                 needsUpdate = cursorDownParagraph(cur);
480                 finishChange(cur, false);
481                 break;
482
483         case LFUN_DOWN_PARAGRAPHSEL:
484                 if (!cur.selection())
485                         cur.resetAnchor();
486                 cursorDownParagraph(cur);
487                 finishChange(cur, true);
488                 break;
489
490         case LFUN_PRIORSEL:
491                 update(cur);
492                 if (!cur.selection())
493                         cur.resetAnchor();
494                 cursorPrevious(cur);
495                 finishChange(cur, true);
496                 break;
497
498         case LFUN_NEXTSEL:
499                 update(cur);
500                 if (!cur.selection())
501                         cur.resetAnchor();
502                 cursorNext(cur);
503                 finishChange(cur, true);
504                 break;
505
506         case LFUN_HOMESEL:
507                 update(cur);
508                 if (!cur.selection())
509                         cur.resetAnchor();
510                 cursorHome(cur);
511                 finishChange(cur, true);
512                 break;
513
514         case LFUN_ENDSEL:
515                 update(cur);
516                 if (!cur.selection())
517                         cur.resetAnchor();
518                 cursorEnd(cur);
519                 finishChange(cur, true);
520                 break;
521
522         case LFUN_WORDRIGHTSEL:
523                 if (!cur.selection())
524                         cur.resetAnchor();
525                 if (isRTL(cur.paragraph()))
526                         cursorLeftOneWord(cur);
527                 else
528                         cursorRightOneWord(cur);
529                 finishChange(cur, true);
530                 break;
531
532         case LFUN_WORDLEFTSEL:
533                 if (!cur.selection())
534                         cur.resetAnchor();
535                 if (isRTL(cur.paragraph()))
536                         cursorRightOneWord(cur);
537                 else
538                         cursorLeftOneWord(cur);
539                 finishChange(cur, true);
540                 break;
541
542         case LFUN_WORDSEL: {
543                 selectWord(cur, lyx::WHOLE_WORD);
544                 finishChange(cur, true);
545                 break;
546         }
547
548         case LFUN_PRIOR:
549                 update(cur);
550                 if (!cur.mark())
551                         cur.clearSelection();
552                 finishChange(cur, false);
553                 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
554                         cur.undispatched();
555                         cmd = FuncRequest(LFUN_FINISHED_UP);
556                 } else {
557                         needsUpdate = cursorPrevious(cur);
558                 }
559                 break;
560
561         case LFUN_NEXT:
562                 update(cur);
563                 if (!cur.mark())
564                         cur.clearSelection();
565                 finishChange(cur, false);
566                 if (cur.pit() == cur.lastpit()
567                           && cur.textRow().endpos() == cur.lastpos()) {
568                         cur.undispatched();
569                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
570                 } else {
571                         needsUpdate = cursorNext(cur);
572                 }
573                 break;
574
575         case LFUN_HOME:
576                 if (!cur.mark())
577                         cur.clearSelection();
578                 cursorHome(cur);
579                 finishChange(cur, false);
580                 break;
581
582         case LFUN_END:
583                 if (!cur.mark())
584                         cur.clearSelection();
585                 cursorEnd(cur);
586                 finishChange(cur, false);
587                 break;
588
589         case LFUN_BREAKLINE: {
590                 // Not allowed by LaTeX (labels or empty par)
591                 if (cur.pos() > cur.paragraph().beginOfBody()) {
592                         lyx::cap::replaceSelection(cur);
593                         cur.insert(new InsetNewline);
594                         cur.posRight();
595                         moveCursor(cur, false);
596                 }
597                 break;
598         }
599
600         case LFUN_DELETE:
601                 if (!cur.selection()) {
602                         Delete(cur);
603                         cur.resetAnchor();
604                         // It is possible to make it a lot faster still
605                         // just comment out the line below...
606                 } else {
607                         cutSelection(cur, true, false);
608                 }
609                 moveCursor(cur, false);
610                 break;
611
612         case LFUN_DELETE_SKIP:
613                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
614                 if (!cur.selection()) {
615                         if (cur.pos() == cur.lastpos()) {
616                                 cursorRight(cur);
617                                 cursorLeft(cur);
618                         }
619                         Delete(cur);
620                         cur.resetAnchor();
621                 } else {
622                         cutSelection(cur, true, false);
623                 }
624                 break;
625
626
627         case LFUN_BACKSPACE:
628                 if (!cur.selection()) {
629                         if (bv->owner()->getIntl().getTransManager().backspace()) {
630                                 backspace(cur);
631                                 cur.resetAnchor();
632                                 // It is possible to make it a lot faster still
633                                 // just comment out the line below...
634                         }
635                 } else {
636                         cutSelection(cur, true, false);
637                 }
638                 bv->switchKeyMap();
639                 break;
640
641         case LFUN_BACKSPACE_SKIP:
642                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
643                 if (!cur.selection()) {
644 #ifdef WITH_WARNINGS
645 #warning look here
646 #endif
647                         //CursorSlice cur = cursor();
648                         backspace(cur);
649                         //anchor() = cur;
650                 } else {
651                         cutSelection(cur, true, false);
652                 }
653                 break;
654
655         case LFUN_BREAKPARAGRAPH:
656                 lyx::cap::replaceSelection(cur);
657                 breakParagraph(cur, 0);
658                 cur.resetAnchor();
659                 bv->switchKeyMap();
660                 break;
661
662         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
663                 lyx::cap::replaceSelection(cur);
664                 breakParagraph(cur, 1);
665                 cur.resetAnchor();
666                 bv->switchKeyMap();
667                 break;
668
669         case LFUN_BREAKPARAGRAPH_SKIP: {
670                 // When at the beginning of a paragraph, remove
671                 // indentation.  Otherwise, do the same as LFUN_BREAKPARAGRAPH.
672                 lyx::cap::replaceSelection(cur);
673                 if (cur.pos() == 0)
674                         cur.paragraph().params().labelWidthString(string());
675                 else
676                         breakParagraph(cur, 0);
677                 cur.resetAnchor();
678                 bv->switchKeyMap();
679                 break;
680         }
681
682         case LFUN_PARAGRAPH_SPACING: {
683                 Paragraph & par = cur.paragraph();
684                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
685                 string cur_value = "1.0";
686                 if (cur_spacing == Spacing::Other)
687                         cur_value = par.params().spacing().getValueAsString();
688
689                 istringstream is(cmd.argument);
690                 string tmp;
691                 is >> tmp;
692                 Spacing::Space new_spacing = cur_spacing;
693                 string new_value = cur_value;
694                 if (tmp.empty()) {
695                         lyxerr << "Missing argument to `paragraph-spacing'"
696                                << endl;
697                 } else if (tmp == "single") {
698                         new_spacing = Spacing::Single;
699                 } else if (tmp == "onehalf") {
700                         new_spacing = Spacing::Onehalf;
701                 } else if (tmp == "double") {
702                         new_spacing = Spacing::Double;
703                 } else if (tmp == "other") {
704                         new_spacing = Spacing::Other;
705                         string tmpval = "0.0";
706                         is >> tmpval;
707                         lyxerr << "new_value = " << tmpval << endl;
708                         if (tmpval != "0.0")
709                                 new_value = tmpval;
710                 } else if (tmp == "default") {
711                         new_spacing = Spacing::Default;
712                 } else {
713                         lyxerr << _("Unknown spacing argument: ")
714                                << cmd.argument << endl;
715                 }
716                 if (cur_spacing != new_spacing || cur_value != new_value)
717                         par.params().spacing(Spacing(new_spacing, new_value));
718                 break;
719         }
720
721         case LFUN_INSET_INSERT: {
722                 recordUndo(cur);
723                 InsetBase * inset = createInset(bv, cmd);
724                 if (inset) {
725                         insertInset(cur, inset);
726                         cur.posRight();
727                 }
728                 break;
729         }
730
731         case LFUN_INSET_SETTINGS:
732                 cur.inset().showInsetDialog(bv);
733                 break;
734
735         case LFUN_NEXT_INSET_TOGGLE: {
736                 InsetBase * inset = cur.nextInset();
737                 if (inset) {
738                         cur.clearSelection();
739                         FuncRequest fr = cmd;
740                         fr.action = LFUN_INSET_TOGGLE;
741                         inset->dispatch(cur, fr);
742                 }
743                 break;
744         }
745
746         case LFUN_KEYMAP_TOGGLE:
747                 cur.clearSelection();
748                 bv->switchKeyMap();
749                 break;
750
751         case LFUN_SPACE_INSERT:
752                 if (cur.paragraph().layout()->free_spacing)
753                         insertChar(cur, ' ');
754                 else {
755                         doInsertInset(cur, this, cmd, false, false);
756                         cur.posRight();
757                 }
758                 moveCursor(cur, false);
759                 break;
760
761         case LFUN_HYPHENATION:
762                 specialChar(cur, InsetSpecialChar::HYPHENATION);
763                 break;
764
765         case LFUN_LIGATURE_BREAK:
766                 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
767                 break;
768
769         case LFUN_LDOTS:
770                 specialChar(cur, InsetSpecialChar::LDOTS);
771                 break;
772
773         case LFUN_END_OF_SENTENCE:
774                 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
775                 break;
776
777         case LFUN_MENU_SEPARATOR:
778                 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
779                 break;
780
781         case LFUN_UPCASE_WORD:
782                 changeCase(cur, LyXText::text_uppercase);
783                 break;
784
785         case LFUN_LOWCASE_WORD:
786                 changeCase(cur, LyXText::text_lowercase);
787                 break;
788
789         case LFUN_CAPITALIZE_WORD:
790                 changeCase(cur, LyXText::text_capitalization);
791                 break;
792
793         case LFUN_TRANSPOSE_CHARS:
794                 recordUndo(cur);
795                 break;
796
797         case LFUN_PASTE:
798                 cur.message(_("Paste"));
799                 lyx::cap::replaceSelection(cur);
800 #ifdef WITH_WARNINGS
801 #warning FIXME Check if the arg is in the domain of available selections.
802 #endif
803                 if (isStrUnsignedInt(cmd.argument))
804                         pasteSelection(cur, convert<unsigned int>(cmd.argument));
805                 else
806                         pasteSelection(cur, 0);
807                 cur.clearSelection(); // bug 393
808                 bv->switchKeyMap();
809                 finishUndo();
810                 break;
811
812         case LFUN_CUT:
813                 cutSelection(cur, true, true);
814                 cur.message(_("Cut"));
815                 break;
816
817         case LFUN_COPY:
818                 copySelection(cur);
819                 cur.message(_("Copy"));
820                 break;
821
822         case LFUN_GETXY:
823                 cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
824                           + convert<string>(cursorY(cur.top(), cur.boundary())));
825                 break;
826
827         case LFUN_SETXY: {
828                 int x = 0;
829                 int y = 0;
830                 istringstream is(cmd.argument);
831                 is >> x >> y;
832                 if (!is)
833                         lyxerr << "SETXY: Could not parse coordinates in '"
834                                << cmd.argument << std::endl;
835                 else
836                         setCursorFromCoordinates(cur, x, y);
837                 break;
838         }
839
840         case LFUN_GETFONT:
841                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
842                         cur.message("E");
843                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
844                         cur.message("N");
845                 else
846                         cur.message("0");
847                 break;
848
849         case LFUN_GETLAYOUT:
850                 cur.message(cur.paragraph().layout()->name());
851                 break;
852
853         case LFUN_LAYOUT: {
854                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
855                   << cmd.argument << endl;
856
857                 // This is not the good solution to the empty argument
858                 // problem, but it will hopefully suffice for 1.2.0.
859                 // The correct solution would be to augument the
860                 // function list/array with information about what
861                 // functions needs arguments and their type.
862                 if (cmd.argument.empty()) {
863                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
864                         break;
865                 }
866
867                 // Derive layout number from given argument (string)
868                 // and current buffer's textclass (number)
869                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
870                 bool hasLayout = tclass.hasLayout(cmd.argument);
871                 string layout = cmd.argument;
872
873                 // If the entry is obsolete, use the new one instead.
874                 if (hasLayout) {
875                         string const & obs = tclass[layout]->obsoleted_by();
876                         if (!obs.empty())
877                                 layout = obs;
878                 }
879
880                 if (!hasLayout) {
881                         cur.errorMessage(string(N_("Layout ")) + cmd.argument +
882                                 N_(" not known"));
883                         break;
884                 }
885
886                 bool change_layout = (current_layout != layout);
887
888                 if (!change_layout && cur.selection() &&
889                         cur.selBegin().pit() != cur.selEnd().pit())
890                 {
891                         pit_type spit = cur.selBegin().pit();
892                         pit_type epit = cur.selEnd().pit() + 1;
893                         while (spit != epit) {
894                                 if (pars_[spit].layout()->name() != current_layout) {
895                                         change_layout = true;
896                                         break;
897                                 }
898                                 ++spit;
899                         }
900                 }
901
902                 if (change_layout) {
903                         current_layout = layout;
904                         setLayout(cur, layout);
905                         bv->owner()->setLayout(layout);
906                         bv->switchKeyMap();
907                 }
908                 break;
909         }
910
911         case LFUN_PASTESELECTION: {
912                 cur.clearSelection();
913                 string const clip = bv->getClipboard();
914                 if (!clip.empty()) {
915                         if (cmd.argument == "paragraph")
916                                 insertStringAsParagraphs(cur, clip);
917                         else
918                                 insertStringAsLines(cur, clip);
919                 }
920                 break;
921         }
922
923         case LFUN_QUOTE: {
924                 lyx::cap::replaceSelection(cur);
925                 Paragraph & par = cur.paragraph();
926                 lyx::pos_type pos = cur.pos();
927                 char c;
928                 if (pos == 0)
929                         c = ' ';
930                 else if (cur.prevInset() && cur.prevInset()->isSpace())
931                         c = ' ';
932                 else
933                         c = par.getChar(pos - 1);
934
935                 LyXLayout_ptr const & style = par.layout();
936
937                 BufferParams const & bufparams = bv->buffer()->params();
938                 if (!style->pass_thru
939                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
940                         string arg = cmd.argument;
941                         if (arg == "single")
942                                 cur.insert(new InsetQuotes(c,
943                                     bufparams.quotes_language,
944                                     InsetQuotes::SingleQ));
945                         else if (arg == "double")
946                                 cur.insert(new InsetQuotes(c,
947                                     bufparams.quotes_language,
948                                     InsetQuotes::DoubleQ));
949                         else
950                                 cur.insert(new InsetQuotes(c, bufparams));
951                         cur.posRight();
952                 }
953                 else
954                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
955                 break;
956         }
957
958         case LFUN_DATE_INSERT: 
959                 if (cmd.argument.empty())
960                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
961                                 lyx::formatted_time(lyx::current_time())));
962                 else
963                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
964                                 lyx::formatted_time(lyx::current_time(), cmd.argument)));
965                 break;
966
967         case LFUN_MOUSE_TRIPLE:
968                 if (cmd.button() == mouse_button::button1) {
969                         cursorHome(cur);
970                         cur.resetAnchor();
971                         cursorEnd(cur);
972                         cur.setSelection();
973                         bv->cursor() = cur;
974                         bv->haveSelection(cur.selection());
975                 }
976                 break;
977
978         case LFUN_MOUSE_DOUBLE:
979                 if (cmd.button() == mouse_button::button1) {
980                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
981                         bv->cursor() = cur;
982                         bv->haveSelection(cur.selection());
983                 }
984                 break;
985
986         // Single-click on work area
987         case LFUN_MOUSE_PRESS: {
988                 // Right click on a footnote flag opens float menu
989                 if (cmd.button() == mouse_button::button3) {
990                         cur.clearSelection();
991                         break;
992                 }
993
994                 // Middle button press pastes if we have a selection
995                 // We do this here as if the selection was inside an inset
996                 // it could get cleared on the unlocking of the inset so
997                 // we have to check this first
998                 bool paste_internally = false;
999                 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1000                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1001                         paste_internally = true;
1002                 }
1003
1004                 // Clear the selection
1005                 cur.clearSelection();
1006
1007                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1008                 cur.resetAnchor();
1009                 finishUndo();
1010                 cur.setTargetX();
1011
1012                 // Has the cursor just left the inset?
1013                 if (bv->cursor().inMathed() && !cur.inMathed())
1014                         bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1015
1016                 // Set cursor here.
1017                 bv->cursor() = cur;
1018
1019                 // Insert primary selection with middle mouse
1020                 // if there is a local selection in the current buffer,
1021                 // insert this
1022                 if (cmd.button() == mouse_button::button2) {
1023                         if (paste_internally)
1024                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1025                         else
1026                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1027                 }
1028
1029                 break;
1030         }
1031
1032         case LFUN_MOUSE_MOTION: {
1033                 // Only use motion with button 1
1034                 //if (cmd.button() != mouse_button::button1)
1035                 //      return false;
1036
1037                 // ignore motions deeper nested than the real anchor
1038                 LCursor & bvcur = cur.bv().cursor();
1039                 if (bvcur.anchor_.hasPart(cur)) {
1040                         CursorSlice old = bvcur.top();
1041
1042                         int const wh = bv->workHeight();
1043                         int const y = std::max(0, std::min(wh - 1, cmd.y));
1044
1045                         setCursorFromCoordinates(cur, cmd.x, y);
1046                         cur.x_target() = cmd.x;
1047                         if (cmd.y >= wh)
1048                                 cursorDown(cur);
1049                         else if (cmd.y < 0)
1050                                 cursorUp(cur);
1051                         // This is to allow jumping over large insets
1052                         if (cur.top() == old) {
1053                                 if (cmd.y >= wh)
1054                                         cursorDown(cur);
1055                                 else if (cmd.y < 0)
1056                                         cursorUp(cur);
1057                         }
1058
1059                         if (cur.top() == old)
1060                                 cur.noUpdate();
1061                         else {
1062                                 // don't set anchor_
1063                                 bvcur.setCursor(cur);
1064                                 bvcur.selection() = true;
1065                                 //lyxerr << "MOTION: " << bv->cursor() << endl;
1066                         }
1067
1068                 } else
1069                         cur.undispatched();
1070                 break;
1071         }
1072
1073         case LFUN_MOUSE_RELEASE: {
1074                 if (cmd.button() == mouse_button::button2)
1075                         break;
1076
1077                 // finish selection
1078                 if (cmd.button() == mouse_button::button1)
1079                         bv->haveSelection(cur.selection());
1080
1081                 bv->switchKeyMap();
1082                 bv->owner()->updateMenubar();
1083                 bv->owner()->updateToolbars();
1084                 break;
1085         }
1086
1087         case LFUN_SELFINSERT: {
1088                 if (cmd.argument.empty())
1089                         break;
1090
1091                 // Automatically delete the currently selected
1092                 // text and replace it with what is being
1093                 // typed in now. Depends on lyxrc settings
1094                 // "auto_region_delete", which defaults to
1095                 // true (on).
1096
1097                 if (lyxrc.auto_region_delete) {
1098                         if (cur.selection())
1099                                 cutSelection(cur, false, false);
1100                         bv->haveSelection(false);
1101                 }
1102
1103                 cur.clearSelection();
1104                 LyXFont const old_font = real_current_font;
1105
1106                 // Prevents language turds in new lyxtexts under non-english
1107                 BufferParams const & bufparams = cur.buffer().params();
1108                 Language const * lang = cur.paragraph().getParLanguage(bufparams);
1109                 current_font.setLanguage(lang);
1110                 real_current_font.setLanguage(lang);
1111
1112                 string::const_iterator cit = cmd.argument.begin();
1113                 string::const_iterator end = cmd.argument.end();
1114                 for (; cit != end; ++cit)
1115                         bv->owner()->getIntl().getTransManager().
1116                                 TranslateAndInsert(*cit, this);
1117
1118                 cur.resetAnchor();
1119                 moveCursor(cur, false);
1120
1121                 needsUpdate = redoParagraph(cur.pit());
1122                 if (!needsUpdate) {
1123                         // update only this paragraph
1124                         cur.bv().update(Update::SinglePar | Update::Force);
1125                 }
1126
1127                 bv->updateScrollbar();
1128                 break;
1129         }
1130
1131         case LFUN_URL: {
1132                 InsetCommandParams p("url");
1133                 string const data = InsetCommandMailer::params2string("url", p);
1134                 bv->owner()->getDialogs().show("url", data, 0);
1135                 break;
1136         }
1137
1138         case LFUN_HTMLURL: {
1139                 InsetCommandParams p("htmlurl");
1140                 string const data = InsetCommandMailer::params2string("url", p);
1141                 bv->owner()->getDialogs().show("url", data, 0);
1142                 break;
1143         }
1144
1145         case LFUN_INSERT_LABEL: {
1146                 // Try to generate a valid label
1147                 string const contents = cmd.argument.empty() ?
1148                         cur.getPossibleLabel() : cmd.argument;
1149
1150                 InsetCommandParams p("label", contents);
1151                 string const data = InsetCommandMailer::params2string("label", p);
1152
1153                 if (cmd.argument.empty()) {
1154                         bv->owner()->getDialogs().show("label", data, 0);
1155                 } else {
1156                         FuncRequest fr(LFUN_INSET_INSERT, data);
1157                         dispatch(cur, fr);
1158                 }
1159                 break;
1160         }
1161
1162
1163 #if 0
1164         case LFUN_INSET_LIST:
1165         case LFUN_INSET_THEOREM:
1166         case LFUN_INSET_CAPTION:
1167 #endif
1168         case LFUN_INSERT_NOTE:
1169         case LFUN_INSERT_CHARSTYLE:
1170         case LFUN_INSERT_BOX:
1171         case LFUN_INSERT_BRANCH:
1172         case LFUN_INSERT_BIBITEM:
1173         case LFUN_INSET_ERT:
1174         case LFUN_INSET_FOOTNOTE:
1175         case LFUN_INSET_MARGINAL:
1176         case LFUN_INSET_OPTARG:
1177         case LFUN_ENVIRONMENT_INSERT:
1178                 // Open the inset, and move the current selection
1179                 // inside it.
1180                 doInsertInset(cur, this, cmd, true, true);
1181                 cur.posRight();
1182                 break;
1183
1184         case LFUN_TABULAR_INSERT:
1185                 // if there were no arguments, just open the dialog
1186                 if (doInsertInset(cur, this, cmd, false, true))
1187                         cur.posRight();
1188                 else
1189                         bv->owner()->getDialogs().show("tabularcreate");
1190
1191                 break;
1192
1193         case LFUN_INSET_FLOAT:
1194         case LFUN_INSET_WIDE_FLOAT:
1195         case LFUN_INSET_WRAP:
1196                 doInsertInset(cur, this, cmd, true, true);
1197                 cur.posRight();
1198                 // FIXME: the "Caption" name should not be hardcoded,
1199                 // but given by the float definition.
1200                 cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
1201                 break;
1202
1203         case LFUN_INDEX_INSERT:
1204                 // Just open the inset
1205                 doInsertInset(cur, this, cmd, true, false);
1206                 cur.posRight();
1207                 break;
1208
1209         case LFUN_INDEX_PRINT:
1210         case LFUN_TOC_INSERT:
1211         case LFUN_HFILL:
1212         case LFUN_INSERT_LINE:
1213         case LFUN_INSERT_PAGEBREAK:
1214                 // do nothing fancy
1215                 doInsertInset(cur, this, cmd, false, false);
1216                 cur.posRight();
1217                 break;
1218
1219         case LFUN_DEPTH_MIN:
1220                 changeDepth(cur, DEC_DEPTH);
1221                 break;
1222
1223         case LFUN_DEPTH_PLUS:
1224                 changeDepth(cur, INC_DEPTH);
1225                 break;
1226
1227         case LFUN_MATH_DISPLAY:
1228                 mathDispatch(cur, cmd, true);
1229                 break;
1230
1231         case LFUN_MATH_IMPORT_SELECTION:
1232         case LFUN_MATH_MODE:
1233                 if (cmd.argument == "on")
1234                         // don't pass "on" as argument
1235                         mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1236                 else
1237                         mathDispatch(cur, cmd, false);
1238                 break;
1239
1240         case LFUN_MATH_MACRO:
1241                 if (cmd.argument.empty())
1242                         cur.errorMessage(N_("Missing argument"));
1243                 else {
1244                         string s = cmd.argument;
1245                         string const s1 = token(s, ' ', 1);
1246                         int const nargs = s1.empty() ? 0 : convert<int>(s1);
1247                         string const s2 = token(s, ' ', 2);
1248                         string const type = s2.empty() ? "newcommand" : s2;
1249                         cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1250                         //cur.nextInset()->edit(cur, true);
1251                 }
1252                 break;
1253
1254         // passthrough hat and underscore outside mathed:
1255         case LFUN_SUBSCRIPT:
1256                 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1257                 break;
1258         case LFUN_SUPERSCRIPT:
1259                 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1260                 break;
1261
1262         case LFUN_INSERT_MATH:
1263         case LFUN_INSERT_MATRIX:
1264         case LFUN_MATH_DELIM: {
1265                 cur.insert(new MathHullInset);
1266                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1267                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1268                 cur.dispatch(cmd);
1269                 break;
1270         }
1271
1272         case LFUN_EMPH: {
1273                 LyXFont font(LyXFont::ALL_IGNORE);
1274                 font.setEmph(LyXFont::TOGGLE);
1275                 toggleAndShow(cur, this, font);
1276                 break;
1277         }
1278
1279         case LFUN_BOLD: {
1280                 LyXFont font(LyXFont::ALL_IGNORE);
1281                 font.setSeries(LyXFont::BOLD_SERIES);
1282                 toggleAndShow(cur, this, font);
1283                 break;
1284         }
1285
1286         case LFUN_NOUN: {
1287                 LyXFont font(LyXFont::ALL_IGNORE);
1288                 font.setNoun(LyXFont::TOGGLE);
1289                 toggleAndShow(cur, this, font);
1290                 break;
1291         }
1292
1293         case LFUN_CODE: {
1294                 LyXFont font(LyXFont::ALL_IGNORE);
1295                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1296                 toggleAndShow(cur, this, font);
1297                 break;
1298         }
1299
1300         case LFUN_SANS: {
1301                 LyXFont font(LyXFont::ALL_IGNORE);
1302                 font.setFamily(LyXFont::SANS_FAMILY);
1303                 toggleAndShow(cur, this, font);
1304                 break;
1305         }
1306
1307         case LFUN_ROMAN: {
1308                 LyXFont font(LyXFont::ALL_IGNORE);
1309                 font.setFamily(LyXFont::ROMAN_FAMILY);
1310                 toggleAndShow(cur, this, font);
1311                 break;
1312         }
1313
1314         case LFUN_DEFAULT: {
1315                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1316                 toggleAndShow(cur, this, font);
1317                 break;
1318         }
1319
1320         case LFUN_UNDERLINE: {
1321                 LyXFont font(LyXFont::ALL_IGNORE);
1322                 font.setUnderbar(LyXFont::TOGGLE);
1323                 toggleAndShow(cur, this, font);
1324                 break;
1325         }
1326
1327         case LFUN_FONT_SIZE: {
1328                 LyXFont font(LyXFont::ALL_IGNORE);
1329                 font.setLyXSize(cmd.argument);
1330                 toggleAndShow(cur, this, font);
1331                 break;
1332         }
1333
1334         case LFUN_LANGUAGE: {
1335                 Language const * lang = languages.getLanguage(cmd.argument);
1336                 if (!lang)
1337                         break;
1338                 LyXFont font(LyXFont::ALL_IGNORE);
1339                 font.setLanguage(lang);
1340                 toggleAndShow(cur, this, font);
1341                 bv->switchKeyMap();
1342                 break;
1343         }
1344
1345         case LFUN_FREEFONT_APPLY:
1346                 toggleAndShow(cur, this, freefont, toggleall);
1347                 cur.message(_("Character set"));
1348                 break;
1349
1350         // Set the freefont using the contents of \param data dispatched from
1351         // the frontends and apply it at the current cursor location.
1352         case LFUN_FREEFONT_UPDATE: {
1353                 LyXFont font;
1354                 bool toggle;
1355                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1356                         freefont = font;
1357                         toggleall = toggle;
1358                         toggleAndShow(cur, this, freefont, toggleall);
1359                         cur.message(_("Character set"));
1360                 }
1361                 break;
1362         }
1363
1364         case LFUN_FINISHED_LEFT:
1365                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1366                 break;
1367
1368         case LFUN_FINISHED_RIGHT:
1369                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1370                 ++cur.pos();
1371                 break;
1372
1373         case LFUN_FINISHED_UP:
1374                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1375                 cursorUp(cur);
1376                 break;
1377
1378         case LFUN_FINISHED_DOWN:
1379                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1380                 cursorDown(cur);
1381                 break;
1382
1383         case LFUN_LAYOUT_PARAGRAPH: {
1384                 string data;
1385                 params2string(cur.paragraph(), data);
1386                 data = "show\n" + data;
1387                 bv->owner()->getDialogs().show("paragraph", data);
1388                 break;
1389         }
1390
1391         case LFUN_PARAGRAPH_UPDATE: {
1392                 if (!bv->owner()->getDialogs().visible("paragraph"))
1393                         break;
1394                 string data;
1395                 params2string(cur.paragraph(), data);
1396
1397                 // Will the paragraph accept changes from the dialog?
1398                 InsetBase & inset = cur.inset();
1399                 bool const accept = !inset.forceDefaultParagraphs(&inset);
1400
1401                 data = "update " + convert<string>(accept) + '\n' + data;
1402                 bv->owner()->getDialogs().update("paragraph", data);
1403                 break;
1404         }
1405
1406         case LFUN_UMLAUT:
1407         case LFUN_CIRCUMFLEX:
1408         case LFUN_GRAVE:
1409         case LFUN_ACUTE:
1410         case LFUN_TILDE:
1411         case LFUN_CEDILLA:
1412         case LFUN_MACRON:
1413         case LFUN_DOT:
1414         case LFUN_UNDERDOT:
1415         case LFUN_UNDERBAR:
1416         case LFUN_CARON:
1417         case LFUN_SPECIAL_CARON:
1418         case LFUN_BREVE:
1419         case LFUN_TIE:
1420         case LFUN_HUNG_UMLAUT:
1421         case LFUN_CIRCLE:
1422         case LFUN_OGONEK:
1423                 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1424                 if (!cmd.argument.empty())
1425                         bv->owner()->getIntl().getTransManager()
1426                                 .TranslateAndInsert(cmd.argument[0], this);
1427                 break;
1428
1429         case LFUN_FLOAT_LIST: {
1430                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1431                 if (tclass.floats().typeExist(cmd.argument)) {
1432                         // not quite sure if we want this...
1433                         recordUndo(cur);
1434                         cur.clearSelection();
1435                         breakParagraph(cur);
1436
1437                         if (cur.lastpos() != 0) {
1438                                 cursorLeft(cur);
1439                                 breakParagraph(cur);
1440                         }
1441
1442                         setLayout(cur, tclass.defaultLayoutName());
1443                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1444                         insertInset(cur, new InsetFloatList(cmd.argument));
1445                         cur.posRight();
1446                 } else {
1447                         lyxerr << "Non-existent float type: "
1448                                << cmd.argument << endl;
1449                 }
1450                 break;
1451         }
1452
1453         case LFUN_ACCEPT_CHANGE: {
1454                 acceptChange(cur);
1455                 break;
1456         }
1457
1458         case LFUN_REJECT_CHANGE: {
1459                 rejectChange(cur);
1460                 break;
1461         }
1462
1463         case LFUN_THESAURUS_ENTRY: {
1464                 string arg = cmd.argument;
1465                 if (arg.empty()) {
1466                         arg = cur.selectionAsString(false);
1467                         // FIXME
1468                         if (arg.size() > 100 || arg.empty()) {
1469                                 // Get word or selection
1470                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1471                                 arg = cur.selectionAsString(false);
1472                         }
1473                 }
1474                 bv->owner()->getDialogs().show("thesaurus", arg);
1475                 break;
1476         }
1477
1478         case LFUN_PARAGRAPH_APPLY: {
1479                 // Given data, an encoding of the ParagraphParameters
1480                 // generated in the Paragraph dialog, this function sets
1481                 // the current paragraph appropriately.
1482                 istringstream is(cmd.argument);
1483                 LyXLex lex(0, 0);
1484                 lex.setStream(is);
1485                 ParagraphParameters params;
1486                 params.read(lex);
1487                 setParagraph(cur,
1488                                          params.spacing(),
1489                                          params.align(),
1490                                          params.labelWidthString(),
1491                                          params.noindent());
1492                 cur.message(_("Paragraph layout set"));
1493                 break;
1494         }
1495
1496         case LFUN_INSET_DIALOG_SHOW: {
1497                 InsetBase * inset = cur.nextInset();
1498                 if (inset) {
1499                         FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1500                         inset->dispatch(cur, fr);
1501                 }
1502                 break;
1503         }
1504
1505         case LFUN_ESCAPE:
1506                 if (cur.selection()) {
1507                         cur.selection() = false;
1508                 } else {
1509                         cur.undispatched();
1510                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
1511                 }
1512                 break;
1513
1514         default:
1515                 lyxerr << BOOST_CURRENT_FUNCTION
1516                        << " Not DISPATCHED by LyXText" << endl;
1517                 cur.undispatched();
1518                 break;
1519         }
1520
1521         if (!needsUpdate
1522             && &oldTopSlice.inset() == &cur.inset()
1523             && oldTopSlice.idx() == cur.idx()
1524             && !sel
1525             && !cur.selection())
1526                 cur.noUpdate();
1527         else
1528                 cur.needsUpdate();
1529 }
1530
1531
1532 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1533                         FuncStatus & flag) const
1534 {
1535         BOOST_ASSERT(cur.text() == this);
1536         LyXFont const & font = real_current_font;
1537         bool enable = true;
1538
1539         switch (cmd.action) {
1540
1541         case LFUN_DEPTH_MIN:
1542                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1543                 break;
1544
1545         case LFUN_DEPTH_PLUS:
1546                 enable = changeDepthAllowed(cur, INC_DEPTH);
1547                 break;
1548
1549         case LFUN_INSET_OPTARG:
1550                 enable = numberOfOptArgs(cur.paragraph())
1551                         < cur.paragraph().layout()->optionalargs;
1552                 break;
1553
1554         case LFUN_APPENDIX:
1555                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1556                 return true;
1557
1558         case LFUN_INSERT_BIBITEM:
1559                 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1560                 break;
1561
1562 #if 0
1563         // the functions which insert insets
1564         InsetBase::Code code = InsetBase::NO_CODE;
1565         switch (cmd.action) {
1566         case LFUN_DIALOG_SHOW_NEW_INSET:
1567                 if (cmd.argument == "bibitem")
1568                         code = InsetBase::BIBITEM_CODE;
1569                 else if (cmd.argument == "bibtex")
1570                         code = InsetBase::BIBTEX_CODE;
1571                 else if (cmd.argument == "box")
1572                         code = InsetBase::BOX_CODE;
1573                 else if (cmd.argument == "branch")
1574                         code = InsetBase::BRANCH_CODE;
1575                 else if (cmd.argument == "citation")
1576                         code = InsetBase::CITE_CODE;
1577                 else if (cmd.argument == "ert")
1578                         code = InsetBase::ERT_CODE;
1579                 else if (cmd.argument == "external")
1580                         code = InsetBase::EXTERNAL_CODE;
1581                 else if (cmd.argument == "float")
1582                         code = InsetBase::FLOAT_CODE;
1583                 else if (cmd.argument == "graphics")
1584                         code = InsetBase::GRAPHICS_CODE;
1585                 else if (cmd.argument == "include")
1586                         code = InsetBase::INCLUDE_CODE;
1587                 else if (cmd.argument == "index")
1588                         code = InsetBase::INDEX_CODE;
1589                 else if (cmd.argument == "label")
1590                         code = InsetBase::LABEL_CODE;
1591                 else if (cmd.argument == "note")
1592                         code = InsetBase::NOTE_CODE;
1593                 else if (cmd.argument == "ref")
1594                         code = InsetBase::REF_CODE;
1595                 else if (cmd.argument == "toc")
1596                         code = InsetBase::TOC_CODE;
1597                 else if (cmd.argument == "url")
1598                         code = InsetBase::URL_CODE;
1599                 else if (cmd.argument == "vspace")
1600                         code = InsetBase::VSPACE_CODE;
1601                 else if (cmd.argument == "wrap")
1602                         code = InsetBase::WRAP_CODE;
1603                 break;
1604
1605         case LFUN_INSET_ERT:
1606                 code = InsetBase::ERT_CODE;
1607                 break;
1608         case LFUN_INSET_FOOTNOTE:
1609                 code = InsetBase::FOOT_CODE;
1610                 break;
1611         case LFUN_TABULAR_INSERT:
1612                 code = InsetBase::TABULAR_CODE;
1613                 break;
1614         case LFUN_INSET_MARGINAL:
1615                 code = InsetBase::MARGIN_CODE;
1616                 break;
1617         case LFUN_INSET_FLOAT:
1618         case LFUN_INSET_WIDE_FLOAT:
1619                 code = InsetBase::FLOAT_CODE;
1620                 break;
1621         case LFUN_INSET_WRAP:
1622                 code = InsetBase::WRAP_CODE;
1623                 break;
1624         case LFUN_FLOAT_LIST:
1625                 code = InsetBase::FLOAT_LIST_CODE;
1626                 break;
1627 #if 0
1628         case LFUN_INSET_LIST:
1629                 code = InsetBase::LIST_CODE;
1630                 break;
1631         case LFUN_INSET_THEOREM:
1632                 code = InsetBase::THEOREM_CODE;
1633                 break;
1634 #endif
1635         case LFUN_INSET_CAPTION:
1636                 code = InsetBase::CAPTION_CODE;
1637                 break;
1638         case LFUN_INSERT_NOTE:
1639                 code = InsetBase::NOTE_CODE;
1640                 break;
1641         case LFUN_INSERT_CHARSTYLE:
1642                 code = InsetBase::CHARSTYLE_CODE;
1643                 if (buf->params().getLyXTextClass().charstyles().empty())
1644                         enable = false;
1645                 break;
1646         case LFUN_INSERT_BOX:
1647                 code = InsetBase::BOX_CODE;
1648                 break;
1649         case LFUN_INSERT_BRANCH:
1650                 code = InsetBase::BRANCH_CODE;
1651                 if (buf->params().branchlist().empty())
1652                         enable = false;
1653                 break;
1654         case LFUN_INSERT_LABEL:
1655                 code = InsetBase::LABEL_CODE;
1656                 break;
1657         case LFUN_INSET_OPTARG:
1658                 code = InsetBase::OPTARG_CODE;
1659                 break;
1660         case LFUN_ENVIRONMENT_INSERT:
1661                 code = InsetBase::BOX_CODE;
1662                 break;
1663         case LFUN_INDEX_INSERT:
1664                 code = InsetBase::INDEX_CODE;
1665                 break;
1666         case LFUN_INDEX_PRINT:
1667                 code = InsetBase::INDEX_PRINT_CODE;
1668                 break;
1669         case LFUN_TOC_INSERT:
1670                 code = InsetBase::TOC_CODE;
1671                 break;
1672         case LFUN_HTMLURL:
1673         case LFUN_URL:
1674                 code = InsetBase::URL_CODE;
1675                 break;
1676         case LFUN_QUOTE:
1677                 // always allow this, since we will inset a raw quote
1678                 // if an inset is not allowed.
1679                 break;
1680         case LFUN_HYPHENATION:
1681         case LFUN_LIGATURE_BREAK:
1682         case LFUN_HFILL:
1683         case LFUN_MENU_SEPARATOR:
1684         case LFUN_LDOTS:
1685         case LFUN_END_OF_SENTENCE:
1686                 code = InsetBase::SPECIALCHAR_CODE;
1687                 break;
1688         case LFUN_SPACE_INSERT:
1689                 // slight hack: we know this is allowed in math mode
1690                 if (cur.inTexted())
1691                         code = InsetBase::SPACE_CODE;
1692                 break;
1693         case LFUN_INSET_DIALOG_SHOW: {
1694                 InsetBase * inset = cur.nextInset();
1695                 enable = inset;
1696                 if (inset) {
1697                         code = inset->lyxCode();
1698                         if (!(code == InsetBase::INCLUDE_CODE
1699                                 || code == InsetBase::BIBTEX_CODE
1700                                 || code == InsetBase::FLOAT_LIST_CODE
1701                                 || code == InsetBase::TOC_CODE))
1702                                 enable = false;
1703                 }
1704                 break;
1705         }
1706         default:
1707                 break;
1708         }
1709
1710         if (code != InsetBase::NO_CODE
1711                         && (cur.empty() || !cur.inset().insetAllowed(code)))
1712                 enable = false;
1713
1714 #endif
1715
1716         case LFUN_DIALOG_SHOW_NEW_INSET:
1717         case LFUN_INSET_ERT:
1718         case LFUN_INSERT_BOX:
1719         case LFUN_INSERT_BRANCH:
1720         case LFUN_ENVIRONMENT_INSERT:
1721         case LFUN_INDEX_INSERT:
1722         case LFUN_INDEX_PRINT:
1723         case LFUN_TOC_INSERT:
1724         case LFUN_HTMLURL:
1725         case LFUN_URL:
1726         case LFUN_QUOTE:
1727         case LFUN_HYPHENATION:
1728         case LFUN_LIGATURE_BREAK:
1729         case LFUN_HFILL:
1730         case LFUN_MENU_SEPARATOR:
1731         case LFUN_LDOTS:
1732         case LFUN_END_OF_SENTENCE:
1733         case LFUN_SPACE_INSERT:
1734         case LFUN_INSET_DIALOG_SHOW:
1735                 break;
1736
1737         case LFUN_INSET_MODIFY:
1738                 // We need to disable this, because we may get called for a
1739                 // tabular cell via
1740                 // InsetTabular::getStatus() -> InsetText::getStatus()
1741                 // and we don't handle LFUN_INSET_MODIFY.
1742                 enable = false;
1743                 break;
1744
1745         case LFUN_EMPH:
1746                 flag.setOnOff(font.emph() == LyXFont::ON);
1747                 return true;
1748
1749         case LFUN_NOUN:
1750                 flag.setOnOff(font.noun() == LyXFont::ON);
1751                 return true;
1752
1753         case LFUN_BOLD:
1754                 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1755                 return true;
1756
1757         case LFUN_SANS:
1758                 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1759                 return true;
1760
1761         case LFUN_ROMAN:
1762                 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1763                 return true;
1764
1765         case LFUN_CODE:
1766                 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1767                 return true;
1768
1769         case LFUN_DELETE_WORD_FORWARD:
1770         case LFUN_DELETE_WORD_BACKWARD:
1771         case LFUN_DELETE_LINE_FORWARD:
1772         case LFUN_WORDRIGHT:
1773         case LFUN_WORDLEFT:
1774         case LFUN_RIGHT:
1775         case LFUN_RIGHTSEL:
1776         case LFUN_LEFT:
1777         case LFUN_LEFTSEL:
1778         case LFUN_UP:
1779         case LFUN_UPSEL:
1780         case LFUN_DOWN:
1781         case LFUN_DOWNSEL:
1782         case LFUN_UP_PARAGRAPHSEL:
1783         case LFUN_DOWN_PARAGRAPHSEL:
1784         case LFUN_PRIORSEL:
1785         case LFUN_NEXTSEL:
1786         case LFUN_HOMESEL:
1787         case LFUN_ENDSEL:
1788         case LFUN_WORDRIGHTSEL:
1789         case LFUN_WORDLEFTSEL:
1790         case LFUN_WORDSEL:
1791         case LFUN_UP_PARAGRAPH:
1792         case LFUN_DOWN_PARAGRAPH:
1793         case LFUN_PRIOR:
1794         case LFUN_NEXT:
1795         case LFUN_HOME:
1796         case LFUN_END:
1797         case LFUN_BREAKLINE:
1798         case LFUN_DELETE:
1799         case LFUN_DELETE_SKIP:
1800         case LFUN_BACKSPACE:
1801         case LFUN_BACKSPACE_SKIP:
1802         case LFUN_BREAKPARAGRAPH:
1803         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1804         case LFUN_BREAKPARAGRAPH_SKIP:
1805         case LFUN_PARAGRAPH_SPACING:
1806         case LFUN_INSET_INSERT:
1807         case LFUN_NEXT_INSET_TOGGLE:
1808         case LFUN_UPCASE_WORD:
1809         case LFUN_LOWCASE_WORD:
1810         case LFUN_CAPITALIZE_WORD:
1811         case LFUN_TRANSPOSE_CHARS:
1812         case LFUN_PASTE:
1813         case LFUN_CUT:
1814         case LFUN_COPY:
1815         case LFUN_GETXY:
1816         case LFUN_SETXY:
1817         case LFUN_GETFONT:
1818         case LFUN_GETLAYOUT:
1819         case LFUN_LAYOUT:
1820         case LFUN_PASTESELECTION:
1821         case LFUN_DATE_INSERT:
1822         case LFUN_SELFINSERT:
1823         case LFUN_INSERT_LABEL:
1824         case LFUN_INSERT_NOTE:
1825         case LFUN_INSERT_CHARSTYLE:
1826         case LFUN_INSET_FLOAT:
1827         case LFUN_INSET_FOOTNOTE:
1828         case LFUN_INSET_MARGINAL:
1829         case LFUN_INSET_WIDE_FLOAT:
1830         case LFUN_INSET_WRAP:
1831         case LFUN_TABULAR_INSERT:
1832         case LFUN_INSERT_LINE:
1833         case LFUN_INSERT_PAGEBREAK:
1834         case LFUN_MATH_DISPLAY:
1835         case LFUN_MATH_IMPORT_SELECTION:
1836         case LFUN_MATH_MODE:
1837         case LFUN_MATH_MACRO:
1838         case LFUN_INSERT_MATH:
1839         case LFUN_INSERT_MATRIX:
1840         case LFUN_MATH_DELIM:
1841         case LFUN_SUBSCRIPT:
1842         case LFUN_SUPERSCRIPT:
1843         case LFUN_DEFAULT:
1844         case LFUN_UNDERLINE:
1845         case LFUN_FONT_SIZE:
1846         case LFUN_LANGUAGE:
1847         case LFUN_FREEFONT_APPLY:
1848         case LFUN_FREEFONT_UPDATE:
1849         case LFUN_LAYOUT_PARAGRAPH:
1850         case LFUN_PARAGRAPH_UPDATE:
1851         case LFUN_UMLAUT:
1852         case LFUN_CIRCUMFLEX:
1853         case LFUN_GRAVE:
1854         case LFUN_ACUTE:
1855         case LFUN_TILDE:
1856         case LFUN_CEDILLA:
1857         case LFUN_MACRON:
1858         case LFUN_DOT:
1859         case LFUN_UNDERDOT:
1860         case LFUN_UNDERBAR:
1861         case LFUN_CARON:
1862         case LFUN_SPECIAL_CARON:
1863         case LFUN_BREVE:
1864         case LFUN_TIE:
1865         case LFUN_HUNG_UMLAUT:
1866         case LFUN_CIRCLE:
1867         case LFUN_OGONEK:
1868         case LFUN_FLOAT_LIST:
1869         case LFUN_ACCEPT_CHANGE:
1870         case LFUN_REJECT_CHANGE:
1871         case LFUN_THESAURUS_ENTRY:
1872         case LFUN_PARAGRAPH_APPLY:
1873         case LFUN_ESCAPE:
1874         case LFUN_KEYMAP_TOGGLE:
1875         case LFUN_ENDBUF:
1876         case LFUN_BEGINNINGBUF:
1877         case LFUN_BEGINNINGBUFSEL:
1878         case LFUN_ENDBUFSEL:
1879                 // these are handled in our dispatch()
1880                 enable = true;
1881                 break;
1882
1883         default:
1884                 return false;
1885         }
1886         flag.enabled(enable);
1887         return true;
1888 }