]> git.lyx.org Git - lyx.git/blob - src/Text3.cpp
eb84631e572eb6a19a7b48d3513b866fcd564b57
[lyx.git] / src / Text3.cpp
1 /**
2  * \file text3.cpp
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 "Text.h"
19
20 #include "BranchList.h"
21 #include "FloatList.h"
22 #include "FuncStatus.h"
23 #include "Buffer.h"
24 #include "buffer_funcs.h"
25 #include "BufferParams.h"
26 #include "BufferView.h"
27 #include "bufferview_funcs.h"
28 #include "Cursor.h"
29 #include "CoordCache.h"
30 #include "CutAndPaste.h"
31 #include "debug.h"
32 #include "DispatchResult.h"
33 #include "ErrorList.h"
34 #include "factory.h"
35 #include "FuncRequest.h"
36 #include "gettext.h"
37 #include "Intl.h"
38 #include "Language.h"
39 #include "LyXAction.h"
40 #include "LyXFunc.h"
41 #include "Lexer.h"
42 #include "LyXRC.h"
43 #include "Row.h"
44 #include "Paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
47 #include "Undo.h"
48 #include "VSpace.h"
49 #include "ParIterator.h"
50
51 #include "frontends/Clipboard.h"
52 #include "frontends/Selection.h"
53
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetFloatList.h"
56 #include "insets/InsetNewline.h"
57 #include "insets/InsetQuotes.h"
58 #include "insets/InsetSpecialChar.h"
59 #include "insets/InsetText.h"
60
61 #include "support/lstrings.h"
62 #include "support/lyxlib.h"
63 #include "support/convert.h"
64 #include "support/lyxtime.h"
65
66 #include "mathed/InsetMathHull.h"
67 #include "mathed/MathMacroTemplate.h"
68
69 #include <boost/current_function.hpp>
70
71 #include <clocale>
72 #include <sstream>
73
74
75 namespace lyx {
76
77 using cap::copySelection;
78 using cap::cutSelection;
79 using cap::pasteFromStack;
80 using cap::pasteClipboard;
81 using cap::replaceSelection;
82 using cap::saveSelection;
83
84 using support::isStrUnsignedInt;
85 using support::token;
86
87 using std::endl;
88 using std::string;
89 using std::istringstream;
90 using std::ostringstream;
91
92
93 extern string current_layout;
94
95
96 namespace {
97
98         // globals...
99         Font freefont(Font::ALL_IGNORE);
100         bool toggleall = false;
101
102         void toggleAndShow(Cursor & cur, Text * text,
103                 Font const & font, bool toggleall = true)
104         {
105                 text->toggleFree(cur, font, toggleall);
106
107                 if (font.language() != ignore_language ||
108                                 font.number() != Font::IGNORE) {
109                         Paragraph & par = cur.paragraph();
110                         if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
111                                                 cur.pos(), text->real_current_font))
112                                 text->setCursor(cur, cur.pit(), cur.pos(),
113                                                 false, !cur.boundary());
114                 }
115         }
116
117
118         void moveCursor(Cursor & cur, bool selecting)
119         {
120                 if (selecting || cur.mark())
121                         cur.setSelection();
122                 saveSelection(cur);
123         }
124
125
126         void finishChange(Cursor & cur, bool selecting)
127         {
128                 finishUndo();
129                 moveCursor(cur, selecting);
130         }
131
132
133         void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
134         {
135                 recordUndo(cur);
136                 docstring sel = cur.selectionAsString(false);
137
138                 // It may happen that sel is empty but there is a selection
139                 replaceSelection(cur);
140
141                 if (sel.empty()) {
142 #ifdef ENABLE_ASSERTIONS
143                         const int old_pos = cur.pos();
144 #endif
145                         cur.insert(new InsetMathHull(hullSimple));
146                         BOOST_ASSERT(old_pos == cur.pos());
147                         cur.nextInset()->edit(cur, true);
148                         // don't do that also for LFUN_MATH_MODE
149                         // unless you want end up with always changing
150                         // to mathrm when opening an inlined inset --
151                         // I really hate "LyXfunc overloading"...
152                         if (display)
153                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
154                         // Avoid an unnecessary undo step if cmd.argument
155                         // is empty
156                         if (!cmd.argument().empty())
157                                 cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
158                                                          cmd.argument()));
159                 } else {
160                         // create a macro if we see "\\newcommand"
161                         // somewhere, and an ordinary formula
162                         // otherwise
163                         if (sel.find(from_ascii("\\newcommand")) == string::npos
164                             && sel.find(from_ascii("\\def")) == string::npos)
165                         {
166                                 InsetMathHull * formula = new InsetMathHull;
167                                 istringstream is(to_utf8(sel));
168                                 Lexer lex(0, 0);
169                                 lex.setStream(is);
170                                 formula->read(cur.buffer(), lex);
171                                 if (formula->getType() == hullNone)
172                                         // Don't create pseudo formulas if
173                                         // delimiters are left out
174                                         formula->mutate(hullSimple);
175                                 cur.insert(formula);
176                         } else {
177                                 cur.insert(new MathMacroTemplate(sel));
178                         }
179                 }
180                 cur.message(from_utf8(N_("Math editor mode")));
181         }
182
183 } // namespace anon
184
185
186
187 namespace bv_funcs {
188
189 string const freefont2string()
190 {
191         string data;
192         if (font2string(freefont, toggleall, data))
193                 return data;
194         return string();
195 }
196
197 }
198
199 void Text::cursorPrevious(Cursor & cur)
200 {
201         pos_type cpos = cur.pos();
202         pit_type cpar = cur.pit();
203
204         int x = cur.x_target();
205         setCursorFromCoordinates(cur, x, 0);
206         cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
207
208         if (cpar == cur.pit() && cpos == cur.pos())
209                 // we have a row which is taller than the workarea. The
210                 // simplest solution is to move to the previous row instead.
211                 cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
212
213         finishUndo();
214         cur.updateFlags(Update::Force | Update::FitCursor);
215 }
216
217
218 void Text::cursorNext(Cursor & cur)
219 {
220         pos_type cpos = cur.pos();
221         pit_type cpar = cur.pit();
222
223         int x = cur.x_target();
224         setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
225         cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
226
227         if (cpar == cur.pit() && cpos == cur.pos())
228                 // we have a row which is taller than the workarea. The
229                 // simplest solution is to move to the next row instead.
230                 cur.dispatch(
231                         FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
232
233         finishUndo();
234         cur.updateFlags(Update::Force | Update::FitCursor);
235 }
236
237
238 namespace {
239
240 void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
241 {
242         recordUndo(cur);
243         cap::replaceSelection(cur);
244         cur.insert(new InsetSpecialChar(kind));
245         cur.posRight();
246 }
247
248
249 bool doInsertInset(Cursor & cur, Text * text,
250         FuncRequest const & cmd, bool edit, bool pastesel)
251 {
252         Inset * inset = createInset(&cur.bv(), cmd);
253         if (!inset)
254                 return false;
255
256         recordUndo(cur);
257         bool gotsel = false;
258         if (cur.selection()) {
259                 lyx::dispatch(FuncRequest(LFUN_CUT));
260                 gotsel = true;
261         }
262         text->insertInset(cur, inset);
263
264         if (edit)
265                 inset->edit(cur, true);
266
267         if (gotsel && pastesel) {
268                 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
269                 // reset first par to default
270                 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
271                         Layout_ptr const layout =
272                                 cur.buffer().params().getTextClass().defaultLayout();
273                         cur.text()->paragraphs().begin()->layout(layout);
274                 }
275         }
276         return true;
277 }
278
279
280 } // anon namespace
281
282
283 void Text::number(Cursor & cur)
284 {
285         Font font(Font::ALL_IGNORE);
286         font.setNumber(Font::TOGGLE);
287         toggleAndShow(cur, this, font);
288 }
289
290
291 bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
292 {
293         return par.isRightToLeftPar(buffer.params());
294 }
295
296
297 bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
298 {
299         if (!lyxrc.rtl_support && !sl.text())
300                 return false;
301
302         int correction = 0;
303         if (boundary && sl.pos() > 0)
304                 correction = -1;
305                 
306         Paragraph const & par = getPar(sl.pit());
307         return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
308 }
309
310
311 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
312                          pos_type pos) const
313 {
314         if (!lyxrc.rtl_support)
315                 return false;
316
317         // no RTL boundary at line start
318         if (pos == 0)
319                 return false;
320
321         bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
322         bool right;
323         if (pos == par.size())
324                 right = par.isRightToLeftPar(buffer.params());
325         else
326                 right = getFont(buffer, par, pos).isVisibleRightToLeft();
327         return left != right;
328 }
329
330
331 bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
332                          pos_type pos, Font const & font) const
333 {
334         if (!lyxrc.rtl_support)
335                 return false;
336
337         bool left = font.isVisibleRightToLeft();
338         bool right;
339         if (pos == par.size())
340                 right = par.isRightToLeftPar(buffer.params());
341         else
342                 right = getFont(buffer, par, pos).isVisibleRightToLeft();
343         return left != right;
344 }
345
346
347 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
348 {
349         LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
350
351         // FIXME: We use the update flag to indicates wether a singlePar or a
352         // full screen update is needed. We reset it here but shall we restore it
353         // at the end?
354         cur.noUpdate();
355
356         BOOST_ASSERT(cur.text() == this);
357         BufferView * bv = &cur.bv();
358         CursorSlice oldTopSlice = cur.top();
359         bool oldBoundary = cur.boundary();
360         bool sel = cur.selection();
361         // Signals that, even if needsUpdate == false, an update of the
362         // cursor paragraph is required
363         bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
364                 LyXAction::SingleParUpdate);
365         // Signals that a full-screen update is required
366         bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
367                 LyXAction::NoUpdate) || singleParUpdate);
368         // Remember the old paragraph metric (_outer_ paragraph!)
369         ParagraphMetrics const & pm = cur.bv().parMetrics(
370                 cur.bottom().text(), cur.bottom().pit());
371         Dimension olddim = pm.dim();
372
373         switch (cmd.action) {
374
375         case LFUN_PARAGRAPH_MOVE_DOWN: {
376                 pit_type const pit = cur.pit();
377                 recUndo(cur, pit, pit + 1);
378                 finishUndo();
379                 std::swap(pars_[pit], pars_[pit + 1]);
380
381                 ParIterator begin(cur);
382                 // begin.pos() (== cur.pos()) may point beyond the end of the
383                 // paragraph referenced by begin. This would cause a crash
384                 // in updateLabels()
385                 begin.pos() = 0;
386                 ++cur.pit();
387                 ParIterator end = boost::next(ParIterator(cur));
388                 updateLabels(cur.buffer(), begin, end);
389
390                 needsUpdate = true;
391                 break;
392         }
393
394         case LFUN_PARAGRAPH_MOVE_UP: {
395                 pit_type const pit = cur.pit();
396                 recUndo(cur, pit - 1, pit);
397                 finishUndo();
398                 std::swap(pars_[pit], pars_[pit - 1]);
399
400                 ParIterator end = ParIterator(cur);
401                 // end.pos() (== cur.pos()) may point beyond the end of the
402                 // paragraph referenced by end. This would cause a crash
403                 // in boost::next()
404                 end.pos() = 0;
405                 end = boost::next(end);
406                 --cur.pit();
407                 ParIterator begin(cur);
408                 updateLabels(cur.buffer(), begin, end);
409
410                 needsUpdate = true;
411                 break;
412         }
413
414         case LFUN_APPENDIX: {
415                 Paragraph & par = cur.paragraph();
416                 bool start = !par.params().startOfAppendix();
417
418 #ifdef WITH_WARNINGS
419 #warning The code below only makes sense at top level.
420 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
421 #endif
422                 // ensure that we have only one start_of_appendix in this document
423                 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
424                         if (pars_[tmp].params().startOfAppendix()) {
425                                 recUndo(cur, tmp);
426                                 pars_[tmp].params().startOfAppendix(false);
427                                 break;
428                         }
429                 }
430
431                 recordUndo(cur);
432                 par.params().startOfAppendix(start);
433
434                 // we can set the refreshing parameters now
435                 updateLabels(cur.buffer());
436                 break;
437         }
438
439         case LFUN_WORD_DELETE_FORWARD:
440                 cur.clearSelection();
441                 deleteWordForward(cur);
442                 finishChange(cur, false);
443                 break;
444
445         case LFUN_WORD_DELETE_BACKWARD:
446                 cur.clearSelection();
447                 deleteWordBackward(cur);
448                 finishChange(cur, false);
449                 break;
450
451         case LFUN_LINE_DELETE:
452                 cur.clearSelection();
453                 deleteLineForward(cur);
454                 finishChange(cur, false);
455                 break;
456
457         case LFUN_BUFFER_BEGIN:
458         case LFUN_BUFFER_BEGIN_SELECT:
459                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
460                 if (cur.depth() == 1) {
461                         needsUpdate |= cursorTop(cur);
462                 } else {
463                         cur.undispatched();
464                 }
465                 break;
466
467         case LFUN_BUFFER_END:
468         case LFUN_BUFFER_END_SELECT:
469                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
470                 if (cur.depth() == 1) {
471                         needsUpdate |= cursorBottom(cur);
472                 } else {
473                         cur.undispatched();
474                 }
475                 break;
476
477         case LFUN_CHAR_FORWARD:
478         case LFUN_CHAR_FORWARD_SELECT:
479                 //lyxerr << BOOST_CURRENT_FUNCTION
480                 //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
481                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
482                 if (reverseDirectionNeeded(cur))
483                         needsUpdate |= cursorLeft(cur);
484                 else
485                         needsUpdate |= cursorRight(cur);
486
487                 if (!needsUpdate && oldTopSlice == cur.top()
488                                 && cur.boundary() == oldBoundary) {
489                         cur.undispatched();
490                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
491                 } else if (cur.selection())
492                         saveSelection(cur);
493                 break;
494
495         case LFUN_CHAR_BACKWARD:
496         case LFUN_CHAR_BACKWARD_SELECT:
497                 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
498                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
499                 if (reverseDirectionNeeded(cur))
500                         needsUpdate |= cursorRight(cur);
501                 else
502                         needsUpdate |= cursorLeft(cur);
503
504                 if (!needsUpdate && oldTopSlice == cur.top()
505                         && cur.boundary() == oldBoundary) {
506                         cur.undispatched();
507                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
508                 }
509                 if (cur.selection())
510                         saveSelection(cur);
511                 break;
512
513         case LFUN_UP_SELECT:
514         case LFUN_DOWN_SELECT:
515         case LFUN_UP:
516         case LFUN_DOWN: {
517                 // stop/start the selection
518                 bool select = cmd.action == LFUN_DOWN_SELECT ||
519                         cmd.action == LFUN_UP_SELECT;
520                 cur.selHandle(select);
521                 
522                 // move cursor up/down
523                 bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
524                 bool const successful = cur.upDownInText(up, needsUpdate);
525                 if (successful) {
526                         // notify insets which were left and get their update flags 
527                         notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
528                         cur.fixIfBroken();
529                         
530                         // redraw if you leave mathed (for the decorations)
531                         needsUpdate |= cur.beforeDispatchCursor().inMathed();
532                 } else
533                         cur.undispatched();
534                 
535                 // save new selection
536                 if (cur.selection())
537                         saveSelection(cur);
538                 break;
539         }
540
541         case LFUN_PARAGRAPH_UP:
542         case LFUN_PARAGRAPH_UP_SELECT:
543                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
544                 needsUpdate |= cursorUpParagraph(cur);
545                 if (cur.selection())
546                         saveSelection(cur);
547                 break;
548
549         case LFUN_PARAGRAPH_DOWN:
550         case LFUN_PARAGRAPH_DOWN_SELECT:
551                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
552                 needsUpdate |= cursorDownParagraph(cur);
553                 if (cur.selection())
554                         saveSelection(cur);
555                 break;
556
557         case LFUN_SCREEN_UP:
558         case LFUN_SCREEN_UP_SELECT:
559                 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
560                 if (cur.pit() == 0 && cur.textRow().pos() == 0)
561                         cur.undispatched();
562                 else {
563                         cursorPrevious(cur);
564                 }
565                 if (cur.selection())
566                         saveSelection(cur);
567                 break;
568
569         case LFUN_SCREEN_DOWN:
570         case LFUN_SCREEN_DOWN_SELECT:
571                 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
572                 if (cur.pit() == cur.lastpit()
573                           && cur.textRow().endpos() == cur.lastpos())
574                         cur.undispatched();
575                 else {
576                         cursorNext(cur);
577                 }
578                 if (cur.selection())
579                         saveSelection(cur);
580                 break;
581
582         case LFUN_LINE_BEGIN:
583         case LFUN_LINE_BEGIN_SELECT:
584                 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
585                 needsUpdate |= cursorHome(cur);
586                 break;
587
588         case LFUN_LINE_END:
589         case LFUN_LINE_END_SELECT:
590                 needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
591                 needsUpdate |= cursorEnd(cur);
592                 if (cur.selection())
593                         saveSelection(cur);
594                 break;
595
596         case LFUN_WORD_FORWARD:
597         case LFUN_WORD_FORWARD_SELECT:
598                 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
599                 if (reverseDirectionNeeded(cur))
600                         needsUpdate |= cursorLeftOneWord(cur);
601                 else
602                         needsUpdate |= cursorRightOneWord(cur);
603                 if (cur.selection())
604                         saveSelection(cur);
605                 break;
606
607         case LFUN_WORD_BACKWARD:
608         case LFUN_WORD_BACKWARD_SELECT:
609                 needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
610                 if (reverseDirectionNeeded(cur))
611                         needsUpdate |= cursorRightOneWord(cur);
612                 else
613                         needsUpdate |= cursorLeftOneWord(cur);
614                 if (cur.selection())
615                         saveSelection(cur);
616                 break;
617
618         case LFUN_WORD_SELECT: {
619                 selectWord(cur, WHOLE_WORD);
620                 finishChange(cur, true);
621                 break;
622         }
623
624         case LFUN_BREAK_LINE: {
625                 // Not allowed by LaTeX (labels or empty par)
626                 if (cur.pos() > cur.paragraph().beginOfBody()) {
627                         // this avoids a double undo
628                         // FIXME: should not be needed, ideally
629                         if (!cur.selection())
630                                 recordUndo(cur);
631                         cap::replaceSelection(cur);
632                         cur.insert(new InsetNewline);
633                         cur.posRight();
634                         moveCursor(cur, false);
635                 }
636                 break;
637         }
638
639         case LFUN_CHAR_DELETE_FORWARD:
640                 if (!cur.selection()) {
641                         if (cur.pos() == cur.paragraph().size())
642                                 // Par boundary, force full-screen update
643                                 singleParUpdate = false;
644                         needsUpdate |= erase(cur);
645                         cur.resetAnchor();
646                         // It is possible to make it a lot faster still
647                         // just comment out the line below...
648                 } else {
649                         cutSelection(cur, true, false);
650                         singleParUpdate = false;
651                 }
652                 moveCursor(cur, false);
653                 break;
654
655         case LFUN_DELETE_FORWARD_SKIP:
656                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
657                 if (!cur.selection()) {
658                         if (cur.pos() == cur.lastpos()) {
659                                 cursorRight(cur);
660                                 cursorLeft(cur);
661                         }
662                         erase(cur);
663                         cur.resetAnchor();
664                 } else {
665                         cutSelection(cur, true, false);
666                 }
667                 break;
668
669
670         case LFUN_CHAR_DELETE_BACKWARD:
671                 if (!cur.selection()) {
672                         if (bv->getIntl().getTransManager().backspace()) {
673                                 // Par boundary, full-screen update
674                                 if (cur.pos() == 0)
675                                         singleParUpdate = false;
676                                 needsUpdate |= backspace(cur);
677                                 cur.resetAnchor();
678                                 // It is possible to make it a lot faster still
679                                 // just comment out the line below...
680                         }
681                 } else {
682                         cutSelection(cur, true, false);
683                         singleParUpdate = false;
684                 }
685                 break;
686
687         case LFUN_DELETE_BACKWARD_SKIP:
688                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
689                 if (!cur.selection()) {
690 #ifdef WITH_WARNINGS
691 #warning look here
692 #endif
693                         //CursorSlice cur = cursor();
694                         backspace(cur);
695                         //anchor() = cur;
696                 } else {
697                         cutSelection(cur, true, false);
698                 }
699                 break;
700
701         case LFUN_BREAK_PARAGRAPH:
702                 cap::replaceSelection(cur);
703                 breakParagraph(cur, 0);
704                 cur.resetAnchor();
705                 break;
706
707         case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
708                 cap::replaceSelection(cur);
709                 breakParagraph(cur, 1);
710                 cur.resetAnchor();
711                 break;
712
713         case LFUN_BREAK_PARAGRAPH_SKIP: {
714                 // When at the beginning of a paragraph, remove
715                 // indentation.  Otherwise, do the same as LFUN_BREAK_PARAGRAPH.
716                 cap::replaceSelection(cur);
717                 if (cur.pos() == 0)
718                         cur.paragraph().params().labelWidthString(docstring());
719                 else
720                         breakParagraph(cur, 0);
721                 cur.resetAnchor();
722                 break;
723         }
724
725         case LFUN_PARAGRAPH_SPACING: {
726                 Paragraph & par = cur.paragraph();
727                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
728                 string cur_value = "1.0";
729                 if (cur_spacing == Spacing::Other)
730                         cur_value = par.params().spacing().getValueAsString();
731
732                 istringstream is(to_utf8(cmd.argument()));
733                 string tmp;
734                 is >> tmp;
735                 Spacing::Space new_spacing = cur_spacing;
736                 string new_value = cur_value;
737                 if (tmp.empty()) {
738                         lyxerr << "Missing argument to `paragraph-spacing'"
739                                << endl;
740                 } else if (tmp == "single") {
741                         new_spacing = Spacing::Single;
742                 } else if (tmp == "onehalf") {
743                         new_spacing = Spacing::Onehalf;
744                 } else if (tmp == "double") {
745                         new_spacing = Spacing::Double;
746                 } else if (tmp == "other") {
747                         new_spacing = Spacing::Other;
748                         string tmpval = "0.0";
749                         is >> tmpval;
750                         lyxerr << "new_value = " << tmpval << endl;
751                         if (tmpval != "0.0")
752                                 new_value = tmpval;
753                 } else if (tmp == "default") {
754                         new_spacing = Spacing::Default;
755                 } else {
756                         lyxerr << to_utf8(_("Unknown spacing argument: "))
757                                << to_utf8(cmd.argument()) << endl;
758                 }
759                 if (cur_spacing != new_spacing || cur_value != new_value)
760                         par.params().spacing(Spacing(new_spacing, new_value));
761                 break;
762         }
763
764         case LFUN_INSET_INSERT: {
765                 recordUndo(cur);
766                 Inset * inset = createInset(bv, cmd);
767                 if (inset) {
768                         // FIXME (Abdel 01/02/2006):
769                         // What follows would be a partial fix for bug 2154:
770                         //   http://bugzilla.lyx.org/show_bug.cgi?id=2154
771                         // This automatically put the label inset _after_ a
772                         // numbered section. It should be possible to extend the mechanism
773                         // to any kind of LateX environement.
774                         // The correct way to fix that bug would be at LateX generation.
775                         // I'll let the code here for reference as it could be used for some
776                         // other feature like "automatic labelling".
777                         /*
778                         Paragraph & par = pars_[cur.pit()];
779                         if (inset->lyxCode() == Inset::LABEL_CODE
780                                 && par.layout()->labeltype == LABEL_COUNTER) {
781                                 // Go to the end of the paragraph
782                                 // Warning: Because of Change-Tracking, the last
783                                 // position is 'size()' and not 'size()-1':
784                                 cur.pos() = par.size();
785                                 // Insert a new paragraph
786                                 FuncRequest fr(LFUN_BREAK_PARAGRAPH);
787                                 dispatch(cur, fr);
788                         }
789                         */
790                         insertInset(cur, inset);
791                         cur.posRight();
792                 }
793                 break;
794         }
795
796         case LFUN_INSET_DISSOLVE:
797                 needsUpdate |= dissolveInset(cur);
798                 break;
799
800         case LFUN_INSET_SETTINGS:
801                 cur.inset().showInsetDialog(bv);
802                 break;
803
804         case LFUN_SPACE_INSERT:
805                 if (cur.paragraph().layout()->free_spacing)
806                         insertChar(cur, ' ');
807                 else {
808                         doInsertInset(cur, this, cmd, false, false);
809                         cur.posRight();
810                 }
811                 moveCursor(cur, false);
812                 break;
813
814         case LFUN_HYPHENATION_POINT_INSERT:
815                 specialChar(cur, InsetSpecialChar::HYPHENATION);
816                 break;
817
818         case LFUN_LIGATURE_BREAK_INSERT:
819                 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
820                 break;
821
822         case LFUN_DOTS_INSERT:
823                 specialChar(cur, InsetSpecialChar::LDOTS);
824                 break;
825
826         case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
827                 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
828                 break;
829
830         case LFUN_MENU_SEPARATOR_INSERT:
831                 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
832                 break;
833
834         case LFUN_WORD_UPCASE:
835                 changeCase(cur, Text::text_uppercase);
836                 break;
837
838         case LFUN_WORD_LOWCASE:
839                 changeCase(cur, Text::text_lowercase);
840                 break;
841
842         case LFUN_WORD_CAPITALIZE:
843                 changeCase(cur, Text::text_capitalization);
844                 break;
845
846         case LFUN_CHARS_TRANSPOSE:
847                 charsTranspose(cur);
848                 break;
849
850         case LFUN_PASTE:
851                 cur.message(_("Paste"));
852                 cap::replaceSelection(cur);
853                 if (cmd.argument().empty() && !theClipboard().isInternal())
854                         pasteClipboard(cur, bv->buffer()->errorList("Paste"));
855                 else {
856                         string const arg(to_utf8(cmd.argument()));
857                         pasteFromStack(cur, bv->buffer()->errorList("Paste"),
858                                         isStrUnsignedInt(arg) ?
859                                                 convert<unsigned int>(arg) :
860                                                 0);
861                 }
862                 bv->buffer()->errors("Paste");
863                 cur.clearSelection(); // bug 393
864                 finishUndo();
865                 break;
866
867         case LFUN_CUT:
868                 cutSelection(cur, true, true);
869                 cur.message(_("Cut"));
870                 break;
871
872         case LFUN_COPY:
873                 copySelection(cur);
874                 cur.message(_("Copy"));
875                 break;
876
877         case LFUN_SERVER_GET_XY:
878                 cur.message(from_utf8(
879                         convert<string>(cursorX(cur.bv(), cur.top(), cur.boundary()))
880                         + ' ' + convert<string>(cursorY(cur.bv(), cur.top(), cur.boundary()))));
881                 break;
882
883         case LFUN_SERVER_SET_XY: {
884                 int x = 0;
885                 int y = 0;
886                 istringstream is(to_utf8(cmd.argument()));
887                 is >> x >> y;
888                 if (!is)
889                         lyxerr << "SETXY: Could not parse coordinates in '"
890                                << to_utf8(cmd.argument()) << std::endl;
891                 else
892                         setCursorFromCoordinates(cur, x, y);
893                 break;
894         }
895
896         case LFUN_SERVER_GET_FONT:
897                 if (current_font.shape() == Font::ITALIC_SHAPE)
898                         cur.message(from_ascii("E"));
899                 else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
900                         cur.message(from_ascii("N"));
901                 else
902                         cur.message(from_ascii("0"));
903                 break;
904
905         case LFUN_SERVER_GET_LAYOUT:
906                 cur.message(from_utf8(cur.paragraph().layout()->name()));
907                 break;
908
909         case LFUN_LAYOUT: {
910                 string layout = to_ascii(cmd.argument());
911                 LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
912
913                 // Derive layout number from given argument (string)
914                 // and current buffer's textclass (number)
915                 TextClass const & tclass = bv->buffer()->params().getTextClass();
916                 if (layout.empty())
917                         layout = tclass.defaultLayoutName();
918                 bool hasLayout = tclass.hasLayout(layout);
919
920                 // If the entry is obsolete, use the new one instead.
921                 if (hasLayout) {
922                         string const & obs = tclass[layout]->obsoleted_by();
923                         if (!obs.empty())
924                                 layout = obs;
925                 }
926
927                 if (!hasLayout) {
928                         cur.errorMessage(from_utf8(N_("Layout ")) + cmd.argument() +
929                                 from_utf8(N_(" not known")));
930                         break;
931                 }
932
933                 bool change_layout = (current_layout != layout);
934
935                 if (!change_layout && cur.selection() &&
936                         cur.selBegin().pit() != cur.selEnd().pit())
937                 {
938                         pit_type spit = cur.selBegin().pit();
939                         pit_type epit = cur.selEnd().pit() + 1;
940                         while (spit != epit) {
941                                 if (pars_[spit].layout()->name() != current_layout) {
942                                         change_layout = true;
943                                         break;
944                                 }
945                                 ++spit;
946                         }
947                 }
948
949                 if (change_layout) {
950                         setLayout(cur, layout);
951                         // inform the GUI that the layout has changed.
952                         bv->layoutChanged(layout);
953                 }
954                 break;
955         }
956
957         case LFUN_CLIPBOARD_PASTE:
958                 cur.clearSelection();
959                 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
960                                cmd.argument() == "paragraph");
961                 bv->buffer()->errors("Paste");
962                 break;
963
964         case LFUN_PRIMARY_SELECTION_PASTE:
965                 pasteString(cur, theSelection().get(),
966                             cmd.argument() == "paragraph");
967                 break;
968
969         case LFUN_UNICODE_INSERT: {
970                 if (cmd.argument().empty())
971                         break;
972                 docstring hexstring = cmd.argument();
973                 if (lyx::support::isHex(hexstring)) {
974                         char_type c = lyx::support::hexToInt(hexstring);
975                         if (c >= 32 && c < 0x10ffff) {
976                                 lyxerr << "Inserting c: " << c << endl;
977                                 docstring s = docstring(1, c);
978                                 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
979                         }
980                 }
981                 break;
982         }
983
984         case LFUN_QUOTE_INSERT: {
985                 Paragraph & par = cur.paragraph();
986                 pos_type pos = cur.pos();
987                 BufferParams const & bufparams = bv->buffer()->params();
988                 Layout_ptr const & style = par.layout();
989                 if (!style->pass_thru
990                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
991                         // this avoids a double undo
992                         // FIXME: should not be needed, ideally
993                         if (!cur.selection())
994                                 recordUndo(cur);
995                         cap::replaceSelection(cur);
996                         pos = cur.pos();
997                         char_type c;
998                         if (pos == 0)
999                                 c = ' ';
1000                         else if (cur.prevInset() && cur.prevInset()->isSpace())
1001                                 c = ' ';
1002                         else
1003                                 c = par.getChar(pos - 1);
1004                         string arg = to_utf8(cmd.argument());
1005                         if (arg == "single")
1006                                 cur.insert(new InsetQuotes(c,
1007                                     bufparams.quotes_language,
1008                                     InsetQuotes::SingleQ));
1009                         else
1010                                 cur.insert(new InsetQuotes(c,
1011                                     bufparams.quotes_language,
1012                                     InsetQuotes::DoubleQ));
1013                         cur.posRight();
1014                 }
1015                 else
1016                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1017                 break;
1018         }
1019
1020         case LFUN_DATE_INSERT:
1021                 if (cmd.argument().empty())
1022                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1023                                 formatted_time(current_time())));
1024                 else
1025                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1026                                 formatted_time(current_time(), to_utf8(cmd.argument()))));
1027                 break;
1028
1029         case LFUN_MOUSE_TRIPLE:
1030                 if (cmd.button() == mouse_button::button1) {
1031                         cursorHome(cur);
1032                         cur.resetAnchor();
1033                         cursorEnd(cur);
1034                         cur.setSelection();
1035                         bv->cursor() = cur;
1036                         saveSelection(cur);
1037                 }
1038                 break;
1039
1040         case LFUN_MOUSE_DOUBLE:
1041                 if (cmd.button() == mouse_button::button1) {
1042                         selectWord(cur, WHOLE_WORD_STRICT);
1043                         bv->cursor() = cur;
1044                 }
1045                 break;
1046
1047         // Single-click on work area
1048         case LFUN_MOUSE_PRESS: {
1049                 // Right click on a footnote flag opens float menu
1050                 if (cmd.button() == mouse_button::button3)
1051                         cur.clearSelection();
1052
1053                 // Middle button press pastes if we have a selection
1054                 // We do this here as if the selection was inside an inset
1055                 // it could get cleared on the unlocking of the inset so
1056                 // we have to check this first
1057                 bool paste_internally = false;
1058                 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1059                         // Copy the selection buffer to the clipboard
1060                         // stack, because we want it to appear in the
1061                         // "Edit->Paste recent" menu.
1062                         cap::copySelectionToStack();
1063                         paste_internally = true;
1064                 }
1065
1066                 // Insert primary selection with middle mouse
1067                 // if there is a local selection in the current buffer,
1068                 // insert this
1069                 if (cmd.button() == mouse_button::button2) {
1070                         if (paste_internally) {
1071                                 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1072                                 bv->buffer()->errors("Paste");
1073                                 cur.clearSelection(); // bug 393
1074                                 bv->buffer()->markDirty();
1075                                 finishUndo();
1076                         } else {
1077                                 bv->mouseSetCursor(cur);
1078                                 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1079                         }
1080                 }
1081
1082                 // we have to update after dePM triggered
1083                 bool update = bv->mouseSetCursor(cur);
1084
1085                 if (!update && cmd.button() == mouse_button::button1) {
1086                         needsUpdate = false;
1087                         cur.noUpdate();
1088                 }
1089
1090                 break;
1091         }
1092
1093         case LFUN_MOUSE_MOTION: {
1094                 // Only use motion with button 1
1095                 //if (cmd.button() != mouse_button::button1)
1096                 //      return false;
1097
1098                 // ignore motions deeper nested than the real anchor
1099                 Cursor & bvcur = cur.bv().cursor();
1100                 if (bvcur.anchor_.hasPart(cur)) {
1101                         CursorSlice old = bvcur.top();
1102
1103                         int const wh = bv->workHeight();
1104                         int const y = std::max(0, std::min(wh - 1, cmd.y));
1105
1106                         setCursorFromCoordinates(cur, cmd.x, y);
1107                         cur.setTargetX(cmd.x);
1108                         if (cmd.y >= wh)
1109                                 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1110                         else if (cmd.y < 0)
1111                                 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1112                         // This is to allow jumping over large insets
1113                         if (cur.top() == old) {
1114                                 if (cmd.y >= wh)
1115                                         lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1116                                 else if (cmd.y < 0)
1117                                         lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1118                         }
1119
1120                         if (cur.top() == old)
1121                                 cur.noUpdate();
1122                         else {
1123                                 // don't set anchor_
1124                                 bvcur.setCursor(cur);
1125                                 bvcur.selection() = true;
1126                                 //lyxerr << "MOTION: " << bv->cursor() << endl;
1127                         }
1128
1129                 } else
1130                         cur.undispatched();
1131                 break;
1132         }
1133
1134         case LFUN_MOUSE_RELEASE: {
1135                 if (cmd.button() == mouse_button::button2)
1136                         break;
1137
1138                 if (cmd.button() == mouse_button::button1) {
1139                         // if there is new selection, update persistent
1140                         // selection, otherwise, single click does not
1141                         // clear persistent selection buffer
1142                         if (cur.selection()) {
1143                                 // finish selection
1144                                 // if double click, cur is moved to the end of word by selectWord
1145                                 // but bvcur is current mouse position
1146                                 Cursor & bvcur = cur.bv().cursor();
1147                                 bvcur.selection() = true;
1148                                 saveSelection(bvcur);
1149                         }
1150                         needsUpdate = false;
1151                         cur.noUpdate();
1152                 }
1153
1154                 break;
1155         }
1156
1157         case LFUN_SELF_INSERT: {
1158                 if (cmd.argument().empty())
1159                         break;
1160
1161                 // Automatically delete the currently selected
1162                 // text and replace it with what is being
1163                 // typed in now. Depends on lyxrc settings
1164                 // "auto_region_delete", which defaults to
1165                 // true (on).
1166
1167                 if (lyxrc.auto_region_delete)
1168                         if (cur.selection())
1169                                 cutSelection(cur, false, false);
1170
1171                 cur.clearSelection();
1172                 Font const old_font = real_current_font;
1173
1174                 docstring::const_iterator cit = cmd.argument().begin();
1175                 docstring::const_iterator end = cmd.argument().end();
1176                 for (; cit != end; ++cit)
1177                         bv->translateAndInsert(*cit, this, cur);
1178
1179                 cur.resetAnchor();
1180                 moveCursor(cur, false);
1181                 break;
1182         }
1183
1184         case LFUN_URL_INSERT: {
1185                 InsetCommandParams p("url");
1186                 string const data = InsetCommandMailer::params2string("url", p);
1187                 bv->showInsetDialog("url", data, 0);
1188                 break;
1189         }
1190
1191         case LFUN_HTML_INSERT: {
1192                 InsetCommandParams p("htmlurl");
1193                 string const data = InsetCommandMailer::params2string("url", p);
1194                 bv->showInsetDialog("url", data, 0);
1195                 break;
1196         }
1197
1198         case LFUN_LABEL_INSERT: {
1199                 InsetCommandParams p("label");
1200                 // Try to generate a valid label
1201                 p["name"] = (cmd.argument().empty()) ?
1202                         cur.getPossibleLabel() :
1203                         cmd.argument();
1204                 string const data = InsetCommandMailer::params2string("label", p);
1205
1206                 if (cmd.argument().empty()) {
1207                         bv->showInsetDialog("label", data, 0);
1208                 } else {
1209                         FuncRequest fr(LFUN_INSET_INSERT, data);
1210                         dispatch(cur, fr);
1211                 }
1212                 break;
1213         }
1214
1215
1216 #if 0
1217         case LFUN_LIST_INSERT:
1218         case LFUN_THEOREM_INSERT:
1219 #endif
1220         case LFUN_CAPTION_INSERT:
1221                 // Open the inset, and move the current selection
1222                 // inside it.
1223                 doInsertInset(cur, this, cmd, true, true);
1224                 cur.posRight();
1225                 updateLabels(*bv->buffer());
1226                 break;
1227         case LFUN_NOTE_INSERT:
1228         case LFUN_CHARSTYLE_INSERT:
1229         case LFUN_BOX_INSERT:
1230         case LFUN_BRANCH_INSERT:
1231         case LFUN_BIBITEM_INSERT:
1232         case LFUN_ERT_INSERT:
1233         case LFUN_LISTING_INSERT:
1234         case LFUN_FOOTNOTE_INSERT:
1235         case LFUN_MARGINALNOTE_INSERT:
1236         case LFUN_OPTIONAL_INSERT:
1237         case LFUN_ENVIRONMENT_INSERT:
1238                 // Open the inset, and move the current selection
1239                 // inside it.
1240                 doInsertInset(cur, this, cmd, true, true);
1241                 cur.posRight();
1242                 break;
1243
1244         case LFUN_TABULAR_INSERT:
1245                 // if there were no arguments, just open the dialog
1246                 if (doInsertInset(cur, this, cmd, false, true))
1247                         cur.posRight();
1248                 else
1249                         bv->showDialog("tabularcreate");
1250
1251                 break;
1252
1253         case LFUN_FLOAT_INSERT:
1254         case LFUN_FLOAT_WIDE_INSERT:
1255         case LFUN_WRAP_INSERT: {
1256                 bool content = cur.selection();  // will some text be moved into the inset?
1257
1258                 doInsertInset(cur, this, cmd, true, true);
1259                 cur.posRight();
1260                 ParagraphList & pars = cur.text()->paragraphs();
1261
1262                 TextClass const & tclass = bv->buffer()->params().getTextClass();
1263
1264                 // add a separate paragraph for the caption inset
1265                 pars.push_back(Paragraph());
1266                 pars.back().setInsetOwner(pars[0].inInset());
1267                 pars.back().layout(tclass.defaultLayout());
1268
1269                 int cap_pit = pars.size() - 1;
1270
1271                 // if an empty inset was created, we create an additional empty
1272                 // paragraph at the bottom so that the user can choose where to put
1273                 // the graphics (or table).
1274                 if (!content) {
1275                         pars.push_back(Paragraph());
1276                         pars.back().setInsetOwner(pars[0].inInset());
1277                         pars.back().layout(tclass.defaultLayout());
1278
1279                 }
1280
1281                 // reposition the cursor to the caption
1282                 cur.pit() = cap_pit;
1283                 cur.pos() = 0;
1284                 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1285                 // FIXME: When leaving the Float (or Wrap) inset we should
1286                 // delete any empty paragraph left above or below the
1287                 // caption.
1288                 break;
1289         }
1290
1291         case LFUN_INDEX_INSERT:
1292         case LFUN_NOMENCL_INSERT: {
1293                 Inset * inset = createInset(&cur.bv(), cmd);
1294                 if (!inset)
1295                         break;
1296                 recordUndo(cur);
1297                 cur.clearSelection();
1298                 insertInset(cur, inset);
1299                 inset->edit(cur, true);
1300                 // Show the dialog for the nomenclature entry, since the
1301                 // description entry still needs to be filled in.
1302                 if (cmd.action == LFUN_NOMENCL_INSERT)
1303                         InsetCommandMailer("nomenclature",
1304                                 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1305                 cur.posRight();
1306                 break;
1307         }
1308
1309         case LFUN_INDEX_PRINT:
1310         case LFUN_NOMENCL_PRINT:
1311         case LFUN_TOC_INSERT:
1312         case LFUN_HFILL_INSERT:
1313         case LFUN_LINE_INSERT:
1314         case LFUN_PAGEBREAK_INSERT:
1315         case LFUN_CLEARPAGE_INSERT:
1316         case LFUN_CLEARDOUBLEPAGE_INSERT:
1317                 // do nothing fancy
1318                 doInsertInset(cur, this, cmd, false, false);
1319                 cur.posRight();
1320                 break;
1321
1322         case LFUN_DEPTH_DECREMENT:
1323                 changeDepth(cur, DEC_DEPTH);
1324                 break;
1325
1326         case LFUN_DEPTH_INCREMENT:
1327                 changeDepth(cur, INC_DEPTH);
1328                 break;
1329
1330         case LFUN_MATH_DISPLAY:
1331                 mathDispatch(cur, cmd, true);
1332                 break;
1333
1334         case LFUN_MATH_IMPORT_SELECTION:
1335         case LFUN_MATH_MODE:
1336                 if (cmd.argument() == "on")
1337                         // don't pass "on" as argument
1338                         mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1339                 else
1340                         mathDispatch(cur, cmd, false);
1341                 break;
1342
1343         case LFUN_MATH_MACRO:
1344                 if (cmd.argument().empty())
1345                         cur.errorMessage(from_utf8(N_("Missing argument")));
1346                 else {
1347                         string s = to_utf8(cmd.argument());
1348                         string const s1 = token(s, ' ', 1);
1349                         int const nargs = s1.empty() ? 0 : convert<int>(s1);
1350                         string const s2 = token(s, ' ', 2);
1351                         string const type = s2.empty() ? "newcommand" : s2;
1352                         cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1353                         //cur.nextInset()->edit(cur, true);
1354                 }
1355                 break;
1356
1357         // passthrough hat and underscore outside mathed:
1358         case LFUN_MATH_SUBSCRIPT:
1359                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1360                 break;
1361         case LFUN_MATH_SUPERSCRIPT:
1362                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1363                 break;
1364
1365         case LFUN_MATH_INSERT:
1366         case LFUN_MATH_MATRIX:
1367         case LFUN_MATH_DELIM:
1368         case LFUN_MATH_BIGDELIM: {
1369                 cur.insert(new InsetMathHull(hullSimple));
1370                 checkAndActivateInset(cur, true);
1371                 BOOST_ASSERT(cur.inMathed());
1372                 cur.dispatch(cmd);
1373                 break;
1374         }
1375
1376         case LFUN_FONT_EMPH: {
1377                 Font font(Font::ALL_IGNORE);
1378                 font.setEmph(Font::TOGGLE);
1379                 toggleAndShow(cur, this, font);
1380                 break;
1381         }
1382
1383         case LFUN_FONT_BOLD: {
1384                 Font font(Font::ALL_IGNORE);
1385                 font.setSeries(Font::BOLD_SERIES);
1386                 toggleAndShow(cur, this, font);
1387                 break;
1388         }
1389
1390         case LFUN_FONT_NOUN: {
1391                 Font font(Font::ALL_IGNORE);
1392                 font.setNoun(Font::TOGGLE);
1393                 toggleAndShow(cur, this, font);
1394                 break;
1395         }
1396
1397         case LFUN_FONT_CODE: {
1398                 Font font(Font::ALL_IGNORE);
1399                 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1400                 toggleAndShow(cur, this, font);
1401                 break;
1402         }
1403
1404         case LFUN_FONT_SANS: {
1405                 Font font(Font::ALL_IGNORE);
1406                 font.setFamily(Font::SANS_FAMILY);
1407                 toggleAndShow(cur, this, font);
1408                 break;
1409         }
1410
1411         case LFUN_FONT_ROMAN: {
1412                 Font font(Font::ALL_IGNORE);
1413                 font.setFamily(Font::ROMAN_FAMILY);
1414                 toggleAndShow(cur, this, font);
1415                 break;
1416         }
1417
1418         case LFUN_FONT_DEFAULT: {
1419                 Font font(Font::ALL_INHERIT, ignore_language);
1420                 toggleAndShow(cur, this, font);
1421                 break;
1422         }
1423
1424         case LFUN_FONT_UNDERLINE: {
1425                 Font font(Font::ALL_IGNORE);
1426                 font.setUnderbar(Font::TOGGLE);
1427                 toggleAndShow(cur, this, font);
1428                 break;
1429         }
1430
1431         case LFUN_FONT_SIZE: {
1432                 Font font(Font::ALL_IGNORE);
1433                 font.setLyXSize(to_utf8(cmd.argument()));
1434                 toggleAndShow(cur, this, font);
1435                 break;
1436         }
1437
1438         case LFUN_LANGUAGE: {
1439                 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1440                 if (!lang)
1441                         break;
1442                 Font font(Font::ALL_IGNORE);
1443                 font.setLanguage(lang);
1444                 toggleAndShow(cur, this, font);
1445                 break;
1446         }
1447
1448         case LFUN_FONT_FREE_APPLY:
1449                 toggleAndShow(cur, this, freefont, toggleall);
1450                 cur.message(_("Character set"));
1451                 break;
1452
1453         // Set the freefont using the contents of \param data dispatched from
1454         // the frontends and apply it at the current cursor location.
1455         case LFUN_FONT_FREE_UPDATE: {
1456                 Font font;
1457                 bool toggle;
1458                 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1459                         freefont = font;
1460                         toggleall = toggle;
1461                         toggleAndShow(cur, this, freefont, toggleall);
1462                         cur.message(_("Character set"));
1463                 }
1464                 break;
1465         }
1466
1467         case LFUN_FINISHED_LEFT:
1468                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1469                 if (reverseDirectionNeeded(cur))
1470                         ++cur.pos();
1471                 break;
1472
1473         case LFUN_FINISHED_RIGHT:
1474                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1475                 if (!reverseDirectionNeeded(cur))
1476                         ++cur.pos();
1477                 break;
1478
1479         case LFUN_LAYOUT_PARAGRAPH: {
1480                 string data;
1481                 params2string(cur.paragraph(), data);
1482                 data = "show\n" + data;
1483                 bv->showDialogWithData("paragraph", data);
1484                 break;
1485         }
1486
1487         case LFUN_PARAGRAPH_UPDATE: {
1488                 string data;
1489                 params2string(cur.paragraph(), data);
1490
1491                 // Will the paragraph accept changes from the dialog?
1492                 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1493
1494                 data = "update " + convert<string>(accept) + '\n' + data;
1495                 bv->updateDialog("paragraph", data);
1496                 break;
1497         }
1498
1499         case LFUN_ACCENT_UMLAUT:
1500         case LFUN_ACCENT_CIRCUMFLEX:
1501         case LFUN_ACCENT_GRAVE:
1502         case LFUN_ACCENT_ACUTE:
1503         case LFUN_ACCENT_TILDE:
1504         case LFUN_ACCENT_CEDILLA:
1505         case LFUN_ACCENT_MACRON:
1506         case LFUN_ACCENT_DOT:
1507         case LFUN_ACCENT_UNDERDOT:
1508         case LFUN_ACCENT_UNDERBAR:
1509         case LFUN_ACCENT_CARON:
1510         case LFUN_ACCENT_SPECIAL_CARON:
1511         case LFUN_ACCENT_BREVE:
1512         case LFUN_ACCENT_TIE:
1513         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1514         case LFUN_ACCENT_CIRCLE:
1515         case LFUN_ACCENT_OGONEK:
1516                 theLyXFunc().handleKeyFunc(cmd.action);
1517                 if (!cmd.argument().empty())
1518                         // FIXME: Are all these characters encoded in one byte in utf8?
1519                         bv->translateAndInsert(cmd.argument()[0], this, cur);
1520                 break;
1521
1522         case LFUN_FLOAT_LIST: {
1523                 TextClass const & tclass = bv->buffer()->params().getTextClass();
1524                 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1525                         // not quite sure if we want this...
1526                         recordUndo(cur);
1527                         cur.clearSelection();
1528                         breakParagraph(cur);
1529
1530                         if (cur.lastpos() != 0) {
1531                                 cursorLeft(cur);
1532                                 breakParagraph(cur);
1533                         }
1534
1535                         setLayout(cur, tclass.defaultLayoutName());
1536                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1537                         insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1538                         cur.posRight();
1539                 } else {
1540                         lyxerr << "Non-existent float type: "
1541                                << to_utf8(cmd.argument()) << endl;
1542                 }
1543                 break;
1544         }
1545
1546         case LFUN_CHANGE_ACCEPT: {
1547                 acceptOrRejectChanges(cur, ACCEPT);
1548                 break;
1549         }
1550
1551         case LFUN_CHANGE_REJECT: {
1552                 acceptOrRejectChanges(cur, REJECT);
1553                 break;
1554         }
1555
1556         case LFUN_THESAURUS_ENTRY: {
1557                 docstring arg = cmd.argument();
1558                 if (arg.empty()) {
1559                         arg = cur.selectionAsString(false);
1560                         // FIXME
1561                         if (arg.size() > 100 || arg.empty()) {
1562                                 // Get word or selection
1563                                 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1564                                 arg = cur.selectionAsString(false);
1565                         }
1566                 }
1567                 bv->showDialogWithData("thesaurus", to_utf8(arg));
1568                 break;
1569         }
1570
1571         case LFUN_PARAGRAPH_PARAMS_APPLY: {
1572                 // Given data, an encoding of the ParagraphParameters
1573                 // generated in the Paragraph dialog, this function sets
1574                 // the current paragraph appropriately.
1575                 istringstream is(to_utf8(cmd.argument()));
1576                 Lexer lex(0, 0);
1577                 lex.setStream(is);
1578                 ParagraphParameters params;
1579                 params.read(lex);
1580                 setParagraph(cur,
1581                              params.spacing(),
1582                              params.align(),
1583                              params.labelWidthString(),
1584                              params.noindent());
1585                 cur.message(_("Paragraph layout set"));
1586                 break;
1587         }
1588
1589         case LFUN_ESCAPE:
1590                 if (cur.selection()) {
1591                         cur.selection() = false;
1592                         saveSelection(cur);
1593                 } else {
1594                         cur.undispatched();
1595                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1596                 }
1597                 break;
1598
1599         default:
1600                 LYXERR(Debug::ACTION)
1601                         << BOOST_CURRENT_FUNCTION
1602                         << ": Command " << cmd
1603                         << " not DISPATCHED by Text" << endl;
1604                 cur.undispatched();
1605                 break;
1606         }
1607
1608         needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1609
1610         // FIXME: The cursor flag is reset two lines below
1611         // so we need to check here if some of the LFUN did touch that.
1612         // for now only Text::erase() and Text::backspace() do that.
1613         // The plan is to verify all the LFUNs and then to remove this
1614         // singleParUpdate boolean altogether.
1615         if (cur.result().update() & Update::Force) {
1616                 singleParUpdate = false;
1617                 needsUpdate = true;
1618         }
1619
1620         // FIXME: the following code should go in favor of fine grained
1621         // update flag treatment.
1622         if (singleParUpdate) {
1623                 // Inserting characters does not change par height
1624                 ParagraphMetrics const & pms
1625                         = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1626                 if (pms.dim().height()
1627                     == olddim.height()) {
1628                         // if so, update _only_ this paragraph
1629                         cur.updateFlags(Update::SinglePar |
1630                                 Update::FitCursor |
1631                                 Update::MultiParSel);
1632                         return;
1633                 } else
1634                         needsUpdate = true;
1635         }
1636
1637         if (!needsUpdate
1638             && &oldTopSlice.inset() == &cur.inset()
1639             && oldTopSlice.idx() == cur.idx()
1640             && !sel // sel is a backup of cur.selection() at the biginning of the function.
1641             && !cur.selection())
1642                 // FIXME: it would be better if we could just do this
1643                 //
1644                 //if (cur.result().update() != Update::FitCursor)
1645                 //      cur.noUpdate();
1646                 //
1647                 // But some LFUNs do not set Update::FitCursor when needed, so we
1648                 // do it for all. This is not very harmfull as FitCursor will provoke
1649                 // a full redraw only if needed but still, a proper review of all LFUN
1650                 // should be done and this needsUpdate boolean can then be removed.
1651                 cur.updateFlags(Update::FitCursor);
1652         else
1653                 cur.updateFlags(Update::Force | Update::FitCursor);
1654 }
1655
1656
1657 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1658                         FuncStatus & flag) const
1659 {
1660         BOOST_ASSERT(cur.text() == this);
1661
1662         Font const & font = real_current_font;
1663         bool enable = true;
1664         Inset::Code code = Inset::NO_CODE;
1665
1666         switch (cmd.action) {
1667
1668         case LFUN_DEPTH_DECREMENT:
1669                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1670                 break;
1671
1672         case LFUN_DEPTH_INCREMENT:
1673                 enable = changeDepthAllowed(cur, INC_DEPTH);
1674                 break;
1675
1676         case LFUN_APPENDIX:
1677                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1678                 return true;
1679
1680         case LFUN_BIBITEM_INSERT:
1681                 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1682                           && cur.pos() == 0);
1683                 break;
1684
1685         case LFUN_DIALOG_SHOW_NEW_INSET:
1686                 if (cmd.argument() == "bibitem")
1687                         code = Inset::BIBITEM_CODE;
1688                 else if (cmd.argument() == "bibtex")
1689                         code = Inset::BIBTEX_CODE;
1690                 else if (cmd.argument() == "box")
1691                         code = Inset::BOX_CODE;
1692                 else if (cmd.argument() == "branch")
1693                         code = Inset::BRANCH_CODE;
1694                 else if (cmd.argument() == "citation")
1695                         code = Inset::CITE_CODE;
1696                 else if (cmd.argument() == "ert")
1697                         code = Inset::ERT_CODE;
1698                 else if (cmd.argument() == "external")
1699                         code = Inset::EXTERNAL_CODE;
1700                 else if (cmd.argument() == "float")
1701                         code = Inset::FLOAT_CODE;
1702                 else if (cmd.argument() == "graphics")
1703                         code = Inset::GRAPHICS_CODE;
1704                 else if (cmd.argument() == "include")
1705                         code = Inset::INCLUDE_CODE;
1706                 else if (cmd.argument() == "index")
1707                         code = Inset::INDEX_CODE;
1708                 else if (cmd.argument() == "nomenclature")
1709                         code = Inset::NOMENCL_CODE;
1710                 else if (cmd.argument() == "label")
1711                         code = Inset::LABEL_CODE;
1712                 else if (cmd.argument() == "note")
1713                         code = Inset::NOTE_CODE;
1714                 else if (cmd.argument() == "ref")
1715                         code = Inset::REF_CODE;
1716                 else if (cmd.argument() == "toc")
1717                         code = Inset::TOC_CODE;
1718                 else if (cmd.argument() == "url")
1719                         code = Inset::URL_CODE;
1720                 else if (cmd.argument() == "vspace")
1721                         code = Inset::VSPACE_CODE;
1722                 else if (cmd.argument() == "wrap")
1723                         code = Inset::WRAP_CODE;
1724                 else if (cmd.argument() == "listings")
1725                         code = Inset::LISTINGS_CODE;
1726                 break;
1727
1728         case LFUN_ERT_INSERT:
1729                 code = Inset::ERT_CODE;
1730                 break;
1731         case LFUN_LISTING_INSERT:
1732             code = Inset::LISTINGS_CODE;
1733                 break;
1734         case LFUN_FOOTNOTE_INSERT:
1735                 code = Inset::FOOT_CODE;
1736                 break;
1737         case LFUN_TABULAR_INSERT:
1738                 code = Inset::TABULAR_CODE;
1739                 break;
1740         case LFUN_MARGINALNOTE_INSERT:
1741                 code = Inset::MARGIN_CODE;
1742                 break;
1743         case LFUN_FLOAT_INSERT:
1744         case LFUN_FLOAT_WIDE_INSERT:
1745                 code = Inset::FLOAT_CODE;
1746                 break;
1747         case LFUN_WRAP_INSERT:
1748                 code = Inset::WRAP_CODE;
1749                 break;
1750         case LFUN_FLOAT_LIST:
1751                 code = Inset::FLOAT_LIST_CODE;
1752                 break;
1753 #if 0
1754         case LFUN_LIST_INSERT:
1755                 code = Inset::LIST_CODE;
1756                 break;
1757         case LFUN_THEOREM_INSERT:
1758                 code = Inset::THEOREM_CODE;
1759                 break;
1760 #endif
1761         case LFUN_CAPTION_INSERT:
1762                 code = Inset::CAPTION_CODE;
1763                 break;
1764         case LFUN_NOTE_INSERT:
1765                 code = Inset::NOTE_CODE;
1766                 break;
1767         case LFUN_CHARSTYLE_INSERT:
1768                 code = Inset::CHARSTYLE_CODE;
1769                 if (cur.buffer().params().getTextClass().charstyles().empty())
1770                         enable = false;
1771                 break;
1772         case LFUN_BOX_INSERT:
1773                 code = Inset::BOX_CODE;
1774                 break;
1775         case LFUN_BRANCH_INSERT:
1776                 code = Inset::BRANCH_CODE;
1777                 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1778                         enable = false;
1779                 break;
1780         case LFUN_LABEL_INSERT:
1781                 code = Inset::LABEL_CODE;
1782                 break;
1783         case LFUN_OPTIONAL_INSERT:
1784                 code = Inset::OPTARG_CODE;
1785                 enable = numberOfOptArgs(cur.paragraph())
1786                         < cur.paragraph().layout()->optionalargs;
1787                 break;
1788         case LFUN_ENVIRONMENT_INSERT:
1789                 code = Inset::BOX_CODE;
1790                 break;
1791         case LFUN_INDEX_INSERT:
1792                 code = Inset::INDEX_CODE;
1793                 break;
1794         case LFUN_INDEX_PRINT:
1795                 code = Inset::INDEX_PRINT_CODE;
1796                 break;
1797         case LFUN_NOMENCL_INSERT:
1798                 code = Inset::NOMENCL_CODE;
1799                 break;
1800         case LFUN_NOMENCL_PRINT:
1801                 code = Inset::NOMENCL_PRINT_CODE;
1802                 break;
1803         case LFUN_TOC_INSERT:
1804                 code = Inset::TOC_CODE;
1805                 break;
1806         case LFUN_HTML_INSERT:
1807         case LFUN_URL_INSERT:
1808                 code = Inset::URL_CODE;
1809                 break;
1810         case LFUN_QUOTE_INSERT:
1811                 // always allow this, since we will inset a raw quote
1812                 // if an inset is not allowed.
1813                 break;
1814         case LFUN_HYPHENATION_POINT_INSERT:
1815         case LFUN_LIGATURE_BREAK_INSERT:
1816         case LFUN_HFILL_INSERT:
1817         case LFUN_MENU_SEPARATOR_INSERT:
1818         case LFUN_DOTS_INSERT:
1819         case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1820                 code = Inset::SPECIALCHAR_CODE;
1821                 break;
1822         case LFUN_SPACE_INSERT:
1823                 // slight hack: we know this is allowed in math mode
1824                 if (cur.inTexted())
1825                         code = Inset::SPACE_CODE;
1826                 break;
1827
1828         case LFUN_INSET_MODIFY:
1829                 // We need to disable this, because we may get called for a
1830                 // tabular cell via
1831                 // InsetTabular::getStatus() -> InsetText::getStatus()
1832                 // and we don't handle LFUN_INSET_MODIFY.
1833                 enable = false;
1834                 break;
1835
1836         case LFUN_FONT_EMPH:
1837                 flag.setOnOff(font.emph() == Font::ON);
1838                 return true;
1839
1840         case LFUN_FONT_NOUN:
1841                 flag.setOnOff(font.noun() == Font::ON);
1842                 return true;
1843
1844         case LFUN_FONT_BOLD:
1845                 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1846                 return true;
1847
1848         case LFUN_FONT_SANS:
1849                 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1850                 return true;
1851
1852         case LFUN_FONT_ROMAN:
1853                 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1854                 return true;
1855
1856         case LFUN_FONT_CODE:
1857                 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1858                 return true;
1859
1860         case LFUN_CUT:
1861         case LFUN_COPY:
1862                 enable = cur.selection();
1863                 break;
1864
1865         case LFUN_PASTE:
1866                 if (cmd.argument().empty()) {
1867                         if (theClipboard().isInternal())
1868                                 enable = cap::numberOfSelections() > 0;
1869                         else
1870                                 enable = !theClipboard().empty();
1871                 } else {
1872                         string const arg = to_utf8(cmd.argument());
1873                         if (isStrUnsignedInt(arg)) {
1874                                 unsigned int n = convert<unsigned int>(arg);
1875                                 enable = cap::numberOfSelections() > n;
1876                         } else
1877                                 // unknown argument
1878                                 enable = false;
1879                 }
1880                 break;
1881
1882         case LFUN_CLIPBOARD_PASTE:
1883                 enable = !theClipboard().empty();
1884                 break;
1885
1886         case LFUN_PRIMARY_SELECTION_PASTE:
1887                 enable = cur.selection() || !theSelection().empty();
1888                 break;
1889
1890         case LFUN_PARAGRAPH_MOVE_UP:
1891                 enable = cur.pit() > 0 && !cur.selection();
1892                 break;
1893
1894         case LFUN_PARAGRAPH_MOVE_DOWN:
1895                 enable = cur.pit() < cur.lastpit() && !cur.selection();
1896                 break;
1897
1898         case LFUN_INSET_DISSOLVE:
1899                 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1900                 break;
1901
1902         case LFUN_CHANGE_ACCEPT:
1903         case LFUN_CHANGE_REJECT:
1904                 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1905                 // In principle, these LFUNs should only be enabled if there
1906                 // is a change at the current position/in the current selection.
1907                 // However, without proper optimizations, this will inevitably
1908                 // result in unacceptable performance - just imagine a user who
1909                 // wants to select the complete content of a long document.
1910                 enable = true;
1911                 break;
1912
1913         case LFUN_WORD_DELETE_FORWARD:
1914         case LFUN_WORD_DELETE_BACKWARD:
1915         case LFUN_LINE_DELETE:
1916         case LFUN_WORD_FORWARD:
1917         case LFUN_WORD_BACKWARD:
1918         case LFUN_CHAR_FORWARD:
1919         case LFUN_CHAR_FORWARD_SELECT:
1920         case LFUN_CHAR_BACKWARD:
1921         case LFUN_CHAR_BACKWARD_SELECT:
1922         case LFUN_UP:
1923         case LFUN_UP_SELECT:
1924         case LFUN_DOWN:
1925         case LFUN_DOWN_SELECT:
1926         case LFUN_PARAGRAPH_UP_SELECT:
1927         case LFUN_PARAGRAPH_DOWN_SELECT:
1928         case LFUN_SCREEN_UP_SELECT:
1929         case LFUN_SCREEN_DOWN_SELECT:
1930         case LFUN_LINE_BEGIN_SELECT:
1931         case LFUN_LINE_END_SELECT:
1932         case LFUN_WORD_FORWARD_SELECT:
1933         case LFUN_WORD_BACKWARD_SELECT:
1934         case LFUN_WORD_SELECT:
1935         case LFUN_PARAGRAPH_UP:
1936         case LFUN_PARAGRAPH_DOWN:
1937         case LFUN_SCREEN_UP:
1938         case LFUN_SCREEN_DOWN:
1939         case LFUN_LINE_BEGIN:
1940         case LFUN_LINE_END:
1941         case LFUN_BREAK_LINE:
1942         case LFUN_CHAR_DELETE_FORWARD:
1943         case LFUN_DELETE_FORWARD_SKIP:
1944         case LFUN_CHAR_DELETE_BACKWARD:
1945         case LFUN_DELETE_BACKWARD_SKIP:
1946         case LFUN_BREAK_PARAGRAPH:
1947         case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1948         case LFUN_BREAK_PARAGRAPH_SKIP:
1949         case LFUN_PARAGRAPH_SPACING:
1950         case LFUN_INSET_INSERT:
1951         case LFUN_WORD_UPCASE:
1952         case LFUN_WORD_LOWCASE:
1953         case LFUN_WORD_CAPITALIZE:
1954         case LFUN_CHARS_TRANSPOSE:
1955         case LFUN_SERVER_GET_XY:
1956         case LFUN_SERVER_SET_XY:
1957         case LFUN_SERVER_GET_FONT:
1958         case LFUN_SERVER_GET_LAYOUT:
1959         case LFUN_LAYOUT:
1960         case LFUN_DATE_INSERT:
1961         case LFUN_SELF_INSERT:
1962         case LFUN_LINE_INSERT:
1963         case LFUN_PAGEBREAK_INSERT:
1964         case LFUN_CLEARPAGE_INSERT:
1965         case LFUN_CLEARDOUBLEPAGE_INSERT:
1966         case LFUN_MATH_DISPLAY:
1967         case LFUN_MATH_IMPORT_SELECTION:
1968         case LFUN_MATH_MODE:
1969         case LFUN_MATH_MACRO:
1970         case LFUN_MATH_MATRIX:
1971         case LFUN_MATH_DELIM:
1972         case LFUN_MATH_BIGDELIM:
1973         case LFUN_MATH_SUBSCRIPT:
1974         case LFUN_MATH_SUPERSCRIPT:
1975         case LFUN_FONT_DEFAULT:
1976         case LFUN_FONT_UNDERLINE:
1977         case LFUN_FONT_SIZE:
1978         case LFUN_LANGUAGE:
1979         case LFUN_FONT_FREE_APPLY:
1980         case LFUN_FONT_FREE_UPDATE:
1981         case LFUN_LAYOUT_PARAGRAPH:
1982         case LFUN_PARAGRAPH_UPDATE:
1983         case LFUN_ACCENT_UMLAUT:
1984         case LFUN_ACCENT_CIRCUMFLEX:
1985         case LFUN_ACCENT_GRAVE:
1986         case LFUN_ACCENT_ACUTE:
1987         case LFUN_ACCENT_TILDE:
1988         case LFUN_ACCENT_CEDILLA:
1989         case LFUN_ACCENT_MACRON:
1990         case LFUN_ACCENT_DOT:
1991         case LFUN_ACCENT_UNDERDOT:
1992         case LFUN_ACCENT_UNDERBAR:
1993         case LFUN_ACCENT_CARON:
1994         case LFUN_ACCENT_SPECIAL_CARON:
1995         case LFUN_ACCENT_BREVE:
1996         case LFUN_ACCENT_TIE:
1997         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1998         case LFUN_ACCENT_CIRCLE:
1999         case LFUN_ACCENT_OGONEK:
2000         case LFUN_THESAURUS_ENTRY:
2001         case LFUN_PARAGRAPH_PARAMS_APPLY:
2002         case LFUN_ESCAPE:
2003         case LFUN_BUFFER_END:
2004         case LFUN_BUFFER_BEGIN:
2005         case LFUN_BUFFER_BEGIN_SELECT:
2006         case LFUN_BUFFER_END_SELECT:
2007         case LFUN_UNICODE_INSERT:
2008                 // these are handled in our dispatch()
2009                 enable = true;
2010                 break;
2011
2012         default:
2013                 return false;
2014         }
2015
2016         if (code != Inset::NO_CODE
2017             && (cur.empty() || !cur.inset().insetAllowed(code)))
2018                 enable = false;
2019
2020         flag.enabled(enable);
2021         return true;
2022 }
2023
2024
2025 void Text::pasteString(Cursor & cur, docstring const & clip,
2026                 bool asParagraphs)
2027 {
2028         cur.clearSelection();
2029         if (!clip.empty()) {
2030                 recordUndo(cur);
2031                 if (asParagraphs)
2032                         insertStringAsParagraphs(cur, clip);
2033                 else
2034                         insertStringAsLines(cur, clip);
2035         }
2036 }
2037
2038 } // namespace lyx