]> git.lyx.org Git - lyx.git/blob - src/Text3.cpp
* compile fix
[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                         current_layout = layout;
951                         setLayout(cur, layout);
952                         // inform the GUI that the layout has changed.
953                         bv->layoutChanged(layout);
954                 }
955                 break;
956         }
957
958         case LFUN_CLIPBOARD_PASTE:
959                 cur.clearSelection();
960                 pasteClipboard(cur, bv->buffer()->errorList("Paste"),
961                                cmd.argument() == "paragraph");
962                 bv->buffer()->errors("Paste");
963                 break;
964
965         case LFUN_PRIMARY_SELECTION_PASTE:
966                 pasteString(cur, theSelection().get(),
967                             cmd.argument() == "paragraph");
968                 break;
969
970         case LFUN_UNICODE_INSERT: {
971                 if (cmd.argument().empty())
972                         break;
973                 docstring hexstring = cmd.argument();
974                 if (lyx::support::isHex(hexstring)) {
975                         char_type c = lyx::support::hexToInt(hexstring);
976                         if (c > 32 && c < 0x10ffff) {
977                                 lyxerr << "Inserting c: " << c << endl;
978                                 docstring s = docstring(1, c);
979                                 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
980                         }
981                 }
982                 break;
983         }
984
985         case LFUN_QUOTE_INSERT: {
986                 Paragraph & par = cur.paragraph();
987                 pos_type pos = cur.pos();
988                 BufferParams const & bufparams = bv->buffer()->params();
989                 Layout_ptr const & style = par.layout();
990                 if (!style->pass_thru
991                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
992                         // this avoids a double undo
993                         // FIXME: should not be needed, ideally
994                         if (!cur.selection())
995                                 recordUndo(cur);
996                         cap::replaceSelection(cur);
997                         pos = cur.pos();
998                         char_type c;
999                         if (pos == 0)
1000                                 c = ' ';
1001                         else if (cur.prevInset() && cur.prevInset()->isSpace())
1002                                 c = ' ';
1003                         else
1004                                 c = par.getChar(pos - 1);
1005                         string arg = to_utf8(cmd.argument());
1006                         if (arg == "single")
1007                                 cur.insert(new InsetQuotes(c,
1008                                     bufparams.quotes_language,
1009                                     InsetQuotes::SingleQ));
1010                         else
1011                                 cur.insert(new InsetQuotes(c,
1012                                     bufparams.quotes_language,
1013                                     InsetQuotes::DoubleQ));
1014                         cur.posRight();
1015                 }
1016                 else
1017                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
1018                 break;
1019         }
1020
1021         case LFUN_DATE_INSERT:
1022                 if (cmd.argument().empty())
1023                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1024                                 formatted_time(current_time())));
1025                 else
1026                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
1027                                 formatted_time(current_time(), to_utf8(cmd.argument()))));
1028                 break;
1029
1030         case LFUN_MOUSE_TRIPLE:
1031                 if (cmd.button() == mouse_button::button1) {
1032                         cursorHome(cur);
1033                         cur.resetAnchor();
1034                         cursorEnd(cur);
1035                         cur.setSelection();
1036                         bv->cursor() = cur;
1037                         saveSelection(cur);
1038                 }
1039                 break;
1040
1041         case LFUN_MOUSE_DOUBLE:
1042                 if (cmd.button() == mouse_button::button1) {
1043                         selectWord(cur, WHOLE_WORD_STRICT);
1044                         bv->cursor() = cur;
1045                 }
1046                 break;
1047
1048         // Single-click on work area
1049         case LFUN_MOUSE_PRESS: {
1050                 // Right click on a footnote flag opens float menu
1051                 if (cmd.button() == mouse_button::button3)
1052                         cur.clearSelection();
1053
1054                 // Middle button press pastes if we have a selection
1055                 // We do this here as if the selection was inside an inset
1056                 // it could get cleared on the unlocking of the inset so
1057                 // we have to check this first
1058                 bool paste_internally = false;
1059                 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1060                         // Copy the selection buffer to the clipboard
1061                         // stack, because we want it to appear in the
1062                         // "Edit->Paste recent" menu.
1063                         cap::copySelectionToStack();
1064                         paste_internally = true;
1065                 }
1066
1067                 // Insert primary selection with middle mouse
1068                 // if there is a local selection in the current buffer,
1069                 // insert this
1070                 if (cmd.button() == mouse_button::button2) {
1071                         if (paste_internally) {
1072                                 cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
1073                                 bv->buffer()->errors("Paste");
1074                                 cur.clearSelection(); // bug 393
1075                                 bv->buffer()->markDirty();
1076                                 finishUndo();
1077                         } else {
1078                                 bv->mouseSetCursor(cur);
1079                                 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1080                         }
1081                 }
1082
1083                 // we have to update after dePM triggered
1084                 bool update = bv->mouseSetCursor(cur);
1085
1086                 if (!update && cmd.button() == mouse_button::button1) {
1087                         needsUpdate = false;
1088                         cur.noUpdate();
1089                 }
1090
1091                 break;
1092         }
1093
1094         case LFUN_MOUSE_MOTION: {
1095                 // Only use motion with button 1
1096                 //if (cmd.button() != mouse_button::button1)
1097                 //      return false;
1098
1099                 // ignore motions deeper nested than the real anchor
1100                 Cursor & bvcur = cur.bv().cursor();
1101                 if (bvcur.anchor_.hasPart(cur)) {
1102                         CursorSlice old = bvcur.top();
1103
1104                         int const wh = bv->workHeight();
1105                         int const y = std::max(0, std::min(wh - 1, cmd.y));
1106
1107                         setCursorFromCoordinates(cur, cmd.x, y);
1108                         cur.setTargetX(cmd.x);
1109                         if (cmd.y >= wh)
1110                                 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1111                         else if (cmd.y < 0)
1112                                 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1113                         // This is to allow jumping over large insets
1114                         if (cur.top() == old) {
1115                                 if (cmd.y >= wh)
1116                                         lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1117                                 else if (cmd.y < 0)
1118                                         lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1119                         }
1120
1121                         if (cur.top() == old)
1122                                 cur.noUpdate();
1123                         else {
1124                                 // don't set anchor_
1125                                 bvcur.setCursor(cur);
1126                                 bvcur.selection() = true;
1127                                 //lyxerr << "MOTION: " << bv->cursor() << endl;
1128                         }
1129
1130                 } else
1131                         cur.undispatched();
1132                 break;
1133         }
1134
1135         case LFUN_MOUSE_RELEASE: {
1136                 if (cmd.button() == mouse_button::button2)
1137                         break;
1138
1139                 if (cmd.button() == mouse_button::button1) {
1140                         // if there is new selection, update persistent
1141                         // selection, otherwise, single click does not
1142                         // clear persistent selection buffer
1143                         if (cur.selection()) {
1144                                 // finish selection
1145                                 // if double click, cur is moved to the end of word by selectWord
1146                                 // but bvcur is current mouse position
1147                                 Cursor & bvcur = cur.bv().cursor();
1148                                 bvcur.selection() = true;
1149                                 saveSelection(bvcur);
1150                         }
1151                         needsUpdate = false;
1152                         cur.noUpdate();
1153                 }
1154
1155                 break;
1156         }
1157
1158         case LFUN_SELF_INSERT: {
1159                 if (cmd.argument().empty())
1160                         break;
1161
1162                 // Automatically delete the currently selected
1163                 // text and replace it with what is being
1164                 // typed in now. Depends on lyxrc settings
1165                 // "auto_region_delete", which defaults to
1166                 // true (on).
1167
1168                 if (lyxrc.auto_region_delete)
1169                         if (cur.selection())
1170                                 cutSelection(cur, false, false);
1171
1172                 cur.clearSelection();
1173                 Font const old_font = real_current_font;
1174
1175                 docstring::const_iterator cit = cmd.argument().begin();
1176                 docstring::const_iterator end = cmd.argument().end();
1177                 for (; cit != end; ++cit)
1178                         bv->translateAndInsert(*cit, this, cur);
1179
1180                 cur.resetAnchor();
1181                 moveCursor(cur, false);
1182                 break;
1183         }
1184
1185         case LFUN_URL_INSERT: {
1186                 InsetCommandParams p("url");
1187                 string const data = InsetCommandMailer::params2string("url", p);
1188                 bv->showInsetDialog("url", data, 0);
1189                 break;
1190         }
1191
1192         case LFUN_HTML_INSERT: {
1193                 InsetCommandParams p("htmlurl");
1194                 string const data = InsetCommandMailer::params2string("url", p);
1195                 bv->showInsetDialog("url", data, 0);
1196                 break;
1197         }
1198
1199         case LFUN_LABEL_INSERT: {
1200                 InsetCommandParams p("label");
1201                 // Try to generate a valid label
1202                 p["name"] = (cmd.argument().empty()) ?
1203                         cur.getPossibleLabel() :
1204                         cmd.argument();
1205                 string const data = InsetCommandMailer::params2string("label", p);
1206
1207                 if (cmd.argument().empty()) {
1208                         bv->showInsetDialog("label", data, 0);
1209                 } else {
1210                         FuncRequest fr(LFUN_INSET_INSERT, data);
1211                         dispatch(cur, fr);
1212                 }
1213                 break;
1214         }
1215
1216
1217 #if 0
1218         case LFUN_LIST_INSERT:
1219         case LFUN_THEOREM_INSERT:
1220 #endif
1221         case LFUN_CAPTION_INSERT:
1222                 // Open the inset, and move the current selection
1223                 // inside it.
1224                 doInsertInset(cur, this, cmd, true, true);
1225                 cur.posRight();
1226                 updateLabels(*bv->buffer());
1227                 break;
1228         case LFUN_NOTE_INSERT:
1229         case LFUN_CHARSTYLE_INSERT:
1230         case LFUN_BOX_INSERT:
1231         case LFUN_BRANCH_INSERT:
1232         case LFUN_BIBITEM_INSERT:
1233         case LFUN_ERT_INSERT:
1234         case LFUN_LISTING_INSERT:
1235         case LFUN_FOOTNOTE_INSERT:
1236         case LFUN_MARGINALNOTE_INSERT:
1237         case LFUN_OPTIONAL_INSERT:
1238         case LFUN_ENVIRONMENT_INSERT:
1239                 // Open the inset, and move the current selection
1240                 // inside it.
1241                 doInsertInset(cur, this, cmd, true, true);
1242                 cur.posRight();
1243                 break;
1244
1245         case LFUN_TABULAR_INSERT:
1246                 // if there were no arguments, just open the dialog
1247                 if (doInsertInset(cur, this, cmd, false, true))
1248                         cur.posRight();
1249                 else
1250                         bv->showDialog("tabularcreate");
1251
1252                 break;
1253
1254         case LFUN_FLOAT_INSERT:
1255         case LFUN_FLOAT_WIDE_INSERT:
1256         case LFUN_WRAP_INSERT: {
1257                 bool content = cur.selection();  // will some text be moved into the inset?
1258
1259                 doInsertInset(cur, this, cmd, true, true);
1260                 cur.posRight();
1261                 ParagraphList & pars = cur.text()->paragraphs();
1262
1263                 TextClass const & tclass = bv->buffer()->params().getTextClass();
1264
1265                 // add a separate paragraph for the caption inset
1266                 pars.push_back(Paragraph());
1267                 pars.back().setInsetOwner(pars[0].inInset());
1268                 pars.back().layout(tclass.defaultLayout());
1269
1270                 int cap_pit = pars.size() - 1;
1271
1272                 // if an empty inset was created, we create an additional empty
1273                 // paragraph at the bottom so that the user can choose where to put
1274                 // the graphics (or table).
1275                 if (!content) {
1276                         pars.push_back(Paragraph());
1277                         pars.back().setInsetOwner(pars[0].inInset());
1278                         pars.back().layout(tclass.defaultLayout());
1279
1280                 }
1281
1282                 // reposition the cursor to the caption
1283                 cur.pit() = cap_pit;
1284                 cur.pos() = 0;
1285                 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1286                 // FIXME: When leaving the Float (or Wrap) inset we should
1287                 // delete any empty paragraph left above or below the
1288                 // caption.
1289                 break;
1290         }
1291
1292         case LFUN_INDEX_INSERT:
1293         case LFUN_NOMENCL_INSERT: {
1294                 Inset * inset = createInset(&cur.bv(), cmd);
1295                 if (!inset)
1296                         break;
1297                 recordUndo(cur);
1298                 cur.clearSelection();
1299                 insertInset(cur, inset);
1300                 inset->edit(cur, true);
1301                 // Show the dialog for the nomenclature entry, since the
1302                 // description entry still needs to be filled in.
1303                 if (cmd.action == LFUN_NOMENCL_INSERT)
1304                         InsetCommandMailer("nomenclature",
1305                                 *reinterpret_cast<InsetCommand *>(inset)).showDialog(&cur.bv());
1306                 cur.posRight();
1307                 break;
1308         }
1309
1310         case LFUN_INDEX_PRINT:
1311         case LFUN_NOMENCL_PRINT:
1312         case LFUN_TOC_INSERT:
1313         case LFUN_HFILL_INSERT:
1314         case LFUN_LINE_INSERT:
1315         case LFUN_PAGEBREAK_INSERT:
1316         case LFUN_CLEARPAGE_INSERT:
1317         case LFUN_CLEARDOUBLEPAGE_INSERT:
1318                 // do nothing fancy
1319                 doInsertInset(cur, this, cmd, false, false);
1320                 cur.posRight();
1321                 break;
1322
1323         case LFUN_DEPTH_DECREMENT:
1324                 changeDepth(cur, DEC_DEPTH);
1325                 break;
1326
1327         case LFUN_DEPTH_INCREMENT:
1328                 changeDepth(cur, INC_DEPTH);
1329                 break;
1330
1331         case LFUN_MATH_DISPLAY:
1332                 mathDispatch(cur, cmd, true);
1333                 break;
1334
1335         case LFUN_MATH_IMPORT_SELECTION:
1336         case LFUN_MATH_MODE:
1337                 if (cmd.argument() == "on")
1338                         // don't pass "on" as argument
1339                         mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1340                 else
1341                         mathDispatch(cur, cmd, false);
1342                 break;
1343
1344         case LFUN_MATH_MACRO:
1345                 if (cmd.argument().empty())
1346                         cur.errorMessage(from_utf8(N_("Missing argument")));
1347                 else {
1348                         string s = to_utf8(cmd.argument());
1349                         string const s1 = token(s, ' ', 1);
1350                         int const nargs = s1.empty() ? 0 : convert<int>(s1);
1351                         string const s2 = token(s, ' ', 2);
1352                         string const type = s2.empty() ? "newcommand" : s2;
1353                         cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type)));
1354                         //cur.nextInset()->edit(cur, true);
1355                 }
1356                 break;
1357
1358         // passthrough hat and underscore outside mathed:
1359         case LFUN_MATH_SUBSCRIPT:
1360                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
1361                 break;
1362         case LFUN_MATH_SUPERSCRIPT:
1363                 mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
1364                 break;
1365
1366         case LFUN_MATH_INSERT:
1367         case LFUN_MATH_MATRIX:
1368         case LFUN_MATH_DELIM:
1369         case LFUN_MATH_BIGDELIM: {
1370                 cur.insert(new InsetMathHull(hullSimple));
1371                 checkAndActivateInset(cur, true);
1372                 BOOST_ASSERT(cur.inMathed());
1373                 cur.dispatch(cmd);
1374                 break;
1375         }
1376
1377         case LFUN_FONT_EMPH: {
1378                 Font font(Font::ALL_IGNORE);
1379                 font.setEmph(Font::TOGGLE);
1380                 toggleAndShow(cur, this, font);
1381                 break;
1382         }
1383
1384         case LFUN_FONT_BOLD: {
1385                 Font font(Font::ALL_IGNORE);
1386                 font.setSeries(Font::BOLD_SERIES);
1387                 toggleAndShow(cur, this, font);
1388                 break;
1389         }
1390
1391         case LFUN_FONT_NOUN: {
1392                 Font font(Font::ALL_IGNORE);
1393                 font.setNoun(Font::TOGGLE);
1394                 toggleAndShow(cur, this, font);
1395                 break;
1396         }
1397
1398         case LFUN_FONT_CODE: {
1399                 Font font(Font::ALL_IGNORE);
1400                 font.setFamily(Font::TYPEWRITER_FAMILY); // no good
1401                 toggleAndShow(cur, this, font);
1402                 break;
1403         }
1404
1405         case LFUN_FONT_SANS: {
1406                 Font font(Font::ALL_IGNORE);
1407                 font.setFamily(Font::SANS_FAMILY);
1408                 toggleAndShow(cur, this, font);
1409                 break;
1410         }
1411
1412         case LFUN_FONT_ROMAN: {
1413                 Font font(Font::ALL_IGNORE);
1414                 font.setFamily(Font::ROMAN_FAMILY);
1415                 toggleAndShow(cur, this, font);
1416                 break;
1417         }
1418
1419         case LFUN_FONT_DEFAULT: {
1420                 Font font(Font::ALL_INHERIT, ignore_language);
1421                 toggleAndShow(cur, this, font);
1422                 break;
1423         }
1424
1425         case LFUN_FONT_UNDERLINE: {
1426                 Font font(Font::ALL_IGNORE);
1427                 font.setUnderbar(Font::TOGGLE);
1428                 toggleAndShow(cur, this, font);
1429                 break;
1430         }
1431
1432         case LFUN_FONT_SIZE: {
1433                 Font font(Font::ALL_IGNORE);
1434                 font.setLyXSize(to_utf8(cmd.argument()));
1435                 toggleAndShow(cur, this, font);
1436                 break;
1437         }
1438
1439         case LFUN_LANGUAGE: {
1440                 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1441                 if (!lang)
1442                         break;
1443                 Font font(Font::ALL_IGNORE);
1444                 font.setLanguage(lang);
1445                 toggleAndShow(cur, this, font);
1446                 break;
1447         }
1448
1449         case LFUN_FONT_FREE_APPLY:
1450                 toggleAndShow(cur, this, freefont, toggleall);
1451                 cur.message(_("Character set"));
1452                 break;
1453
1454         // Set the freefont using the contents of \param data dispatched from
1455         // the frontends and apply it at the current cursor location.
1456         case LFUN_FONT_FREE_UPDATE: {
1457                 Font font;
1458                 bool toggle;
1459                 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1460                         freefont = font;
1461                         toggleall = toggle;
1462                         toggleAndShow(cur, this, freefont, toggleall);
1463                         cur.message(_("Character set"));
1464                 }
1465                 break;
1466         }
1467
1468         case LFUN_FINISHED_LEFT:
1469                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1470                 if (reverseDirectionNeeded(cur))
1471                         ++cur.pos();
1472                 break;
1473
1474         case LFUN_FINISHED_RIGHT:
1475                 LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1476                 if (!reverseDirectionNeeded(cur))
1477                         ++cur.pos();
1478                 break;
1479
1480         case LFUN_LAYOUT_PARAGRAPH: {
1481                 string data;
1482                 params2string(cur.paragraph(), data);
1483                 data = "show\n" + data;
1484                 bv->showDialogWithData("paragraph", data);
1485                 break;
1486         }
1487
1488         case LFUN_PARAGRAPH_UPDATE: {
1489                 string data;
1490                 params2string(cur.paragraph(), data);
1491
1492                 // Will the paragraph accept changes from the dialog?
1493                 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1494
1495                 data = "update " + convert<string>(accept) + '\n' + data;
1496                 bv->updateDialog("paragraph", data);
1497                 break;
1498         }
1499
1500         case LFUN_ACCENT_UMLAUT:
1501         case LFUN_ACCENT_CIRCUMFLEX:
1502         case LFUN_ACCENT_GRAVE:
1503         case LFUN_ACCENT_ACUTE:
1504         case LFUN_ACCENT_TILDE:
1505         case LFUN_ACCENT_CEDILLA:
1506         case LFUN_ACCENT_MACRON:
1507         case LFUN_ACCENT_DOT:
1508         case LFUN_ACCENT_UNDERDOT:
1509         case LFUN_ACCENT_UNDERBAR:
1510         case LFUN_ACCENT_CARON:
1511         case LFUN_ACCENT_SPECIAL_CARON:
1512         case LFUN_ACCENT_BREVE:
1513         case LFUN_ACCENT_TIE:
1514         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1515         case LFUN_ACCENT_CIRCLE:
1516         case LFUN_ACCENT_OGONEK:
1517                 theLyXFunc().handleKeyFunc(cmd.action);
1518                 if (!cmd.argument().empty())
1519                         // FIXME: Are all these characters encoded in one byte in utf8?
1520                         bv->translateAndInsert(cmd.argument()[0], this, cur);
1521                 break;
1522
1523         case LFUN_FLOAT_LIST: {
1524                 TextClass const & tclass = bv->buffer()->params().getTextClass();
1525                 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1526                         // not quite sure if we want this...
1527                         recordUndo(cur);
1528                         cur.clearSelection();
1529                         breakParagraph(cur);
1530
1531                         if (cur.lastpos() != 0) {
1532                                 cursorLeft(cur);
1533                                 breakParagraph(cur);
1534                         }
1535
1536                         setLayout(cur, tclass.defaultLayoutName());
1537                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1538                         insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1539                         cur.posRight();
1540                 } else {
1541                         lyxerr << "Non-existent float type: "
1542                                << to_utf8(cmd.argument()) << endl;
1543                 }
1544                 break;
1545         }
1546
1547         case LFUN_CHANGE_ACCEPT: {
1548                 acceptOrRejectChanges(cur, ACCEPT);
1549                 break;
1550         }
1551
1552         case LFUN_CHANGE_REJECT: {
1553                 acceptOrRejectChanges(cur, REJECT);
1554                 break;
1555         }
1556
1557         case LFUN_THESAURUS_ENTRY: {
1558                 docstring arg = cmd.argument();
1559                 if (arg.empty()) {
1560                         arg = cur.selectionAsString(false);
1561                         // FIXME
1562                         if (arg.size() > 100 || arg.empty()) {
1563                                 // Get word or selection
1564                                 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1565                                 arg = cur.selectionAsString(false);
1566                         }
1567                 }
1568                 bv->showDialogWithData("thesaurus", to_utf8(arg));
1569                 break;
1570         }
1571
1572         case LFUN_PARAGRAPH_PARAMS_APPLY: {
1573                 // Given data, an encoding of the ParagraphParameters
1574                 // generated in the Paragraph dialog, this function sets
1575                 // the current paragraph appropriately.
1576                 istringstream is(to_utf8(cmd.argument()));
1577                 Lexer lex(0, 0);
1578                 lex.setStream(is);
1579                 ParagraphParameters params;
1580                 params.read(lex);
1581                 setParagraph(cur,
1582                              params.spacing(),
1583                              params.align(),
1584                              params.labelWidthString(),
1585                              params.noindent());
1586                 cur.message(_("Paragraph layout set"));
1587                 break;
1588         }
1589
1590         case LFUN_ESCAPE:
1591                 if (cur.selection()) {
1592                         cur.selection() = false;
1593                         saveSelection(cur);
1594                 } else {
1595                         cur.undispatched();
1596                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1597                 }
1598                 break;
1599
1600         default:
1601                 LYXERR(Debug::ACTION)
1602                         << BOOST_CURRENT_FUNCTION
1603                         << ": Command " << cmd
1604                         << " not DISPATCHED by Text" << endl;
1605                 cur.undispatched();
1606                 break;
1607         }
1608
1609         needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1610
1611         // FIXME: The cursor flag is reset two lines below
1612         // so we need to check here if some of the LFUN did touch that.
1613         // for now only Text::erase() and Text::backspace() do that.
1614         // The plan is to verify all the LFUNs and then to remove this
1615         // singleParUpdate boolean altogether.
1616         if (cur.result().update() & Update::Force) {
1617                 singleParUpdate = false;
1618                 needsUpdate = true;
1619         }
1620
1621         // FIXME: the following code should go in favor of fine grained
1622         // update flag treatment.
1623         if (singleParUpdate) {
1624                 // Inserting characters does not change par height
1625                 ParagraphMetrics const & pms
1626                         = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1627                 if (pms.dim().height()
1628                     == olddim.height()) {
1629                         // if so, update _only_ this paragraph
1630                         cur.updateFlags(Update::SinglePar |
1631                                 Update::FitCursor |
1632                                 Update::MultiParSel);
1633                         return;
1634                 } else
1635                         needsUpdate = true;
1636         }
1637
1638         if (!needsUpdate
1639             && &oldTopSlice.inset() == &cur.inset()
1640             && oldTopSlice.idx() == cur.idx()
1641             && !sel // sel is a backup of cur.selection() at the biginning of the function.
1642             && !cur.selection())
1643                 // FIXME: it would be better if we could just do this
1644                 //
1645                 //if (cur.result().update() != Update::FitCursor)
1646                 //      cur.noUpdate();
1647                 //
1648                 // But some LFUNs do not set Update::FitCursor when needed, so we
1649                 // do it for all. This is not very harmfull as FitCursor will provoke
1650                 // a full redraw only if needed but still, a proper review of all LFUN
1651                 // should be done and this needsUpdate boolean can then be removed.
1652                 cur.updateFlags(Update::FitCursor);
1653         else
1654                 cur.updateFlags(Update::Force | Update::FitCursor);
1655 }
1656
1657
1658 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
1659                         FuncStatus & flag) const
1660 {
1661         BOOST_ASSERT(cur.text() == this);
1662
1663         Font const & font = real_current_font;
1664         bool enable = true;
1665         Inset::Code code = Inset::NO_CODE;
1666
1667         switch (cmd.action) {
1668
1669         case LFUN_DEPTH_DECREMENT:
1670                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1671                 break;
1672
1673         case LFUN_DEPTH_INCREMENT:
1674                 enable = changeDepthAllowed(cur, INC_DEPTH);
1675                 break;
1676
1677         case LFUN_APPENDIX:
1678                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1679                 return true;
1680
1681         case LFUN_BIBITEM_INSERT:
1682                 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
1683                           && cur.pos() == 0);
1684                 break;
1685
1686         case LFUN_DIALOG_SHOW_NEW_INSET:
1687                 if (cmd.argument() == "bibitem")
1688                         code = Inset::BIBITEM_CODE;
1689                 else if (cmd.argument() == "bibtex")
1690                         code = Inset::BIBTEX_CODE;
1691                 else if (cmd.argument() == "box")
1692                         code = Inset::BOX_CODE;
1693                 else if (cmd.argument() == "branch")
1694                         code = Inset::BRANCH_CODE;
1695                 else if (cmd.argument() == "citation")
1696                         code = Inset::CITE_CODE;
1697                 else if (cmd.argument() == "ert")
1698                         code = Inset::ERT_CODE;
1699                 else if (cmd.argument() == "external")
1700                         code = Inset::EXTERNAL_CODE;
1701                 else if (cmd.argument() == "float")
1702                         code = Inset::FLOAT_CODE;
1703                 else if (cmd.argument() == "graphics")
1704                         code = Inset::GRAPHICS_CODE;
1705                 else if (cmd.argument() == "include")
1706                         code = Inset::INCLUDE_CODE;
1707                 else if (cmd.argument() == "index")
1708                         code = Inset::INDEX_CODE;
1709                 else if (cmd.argument() == "nomenclature")
1710                         code = Inset::NOMENCL_CODE;
1711                 else if (cmd.argument() == "label")
1712                         code = Inset::LABEL_CODE;
1713                 else if (cmd.argument() == "note")
1714                         code = Inset::NOTE_CODE;
1715                 else if (cmd.argument() == "ref")
1716                         code = Inset::REF_CODE;
1717                 else if (cmd.argument() == "toc")
1718                         code = Inset::TOC_CODE;
1719                 else if (cmd.argument() == "url")
1720                         code = Inset::URL_CODE;
1721                 else if (cmd.argument() == "vspace")
1722                         code = Inset::VSPACE_CODE;
1723                 else if (cmd.argument() == "wrap")
1724                         code = Inset::WRAP_CODE;
1725                 else if (cmd.argument() == "listings")
1726                         code = Inset::LISTINGS_CODE;
1727                 break;
1728
1729         case LFUN_ERT_INSERT:
1730                 code = Inset::ERT_CODE;
1731                 break;
1732         case LFUN_LISTING_INSERT:
1733             code = Inset::LISTINGS_CODE;
1734                 break;
1735         case LFUN_FOOTNOTE_INSERT:
1736                 code = Inset::FOOT_CODE;
1737                 break;
1738         case LFUN_TABULAR_INSERT:
1739                 code = Inset::TABULAR_CODE;
1740                 break;
1741         case LFUN_MARGINALNOTE_INSERT:
1742                 code = Inset::MARGIN_CODE;
1743                 break;
1744         case LFUN_FLOAT_INSERT:
1745         case LFUN_FLOAT_WIDE_INSERT:
1746                 code = Inset::FLOAT_CODE;
1747                 break;
1748         case LFUN_WRAP_INSERT:
1749                 code = Inset::WRAP_CODE;
1750                 break;
1751         case LFUN_FLOAT_LIST:
1752                 code = Inset::FLOAT_LIST_CODE;
1753                 break;
1754 #if 0
1755         case LFUN_LIST_INSERT:
1756                 code = Inset::LIST_CODE;
1757                 break;
1758         case LFUN_THEOREM_INSERT:
1759                 code = Inset::THEOREM_CODE;
1760                 break;
1761 #endif
1762         case LFUN_CAPTION_INSERT:
1763                 code = Inset::CAPTION_CODE;
1764                 break;
1765         case LFUN_NOTE_INSERT:
1766                 code = Inset::NOTE_CODE;
1767                 break;
1768         case LFUN_CHARSTYLE_INSERT:
1769                 code = Inset::CHARSTYLE_CODE;
1770                 if (cur.buffer().params().getTextClass().charstyles().empty())
1771                         enable = false;
1772                 break;
1773         case LFUN_BOX_INSERT:
1774                 code = Inset::BOX_CODE;
1775                 break;
1776         case LFUN_BRANCH_INSERT:
1777                 code = Inset::BRANCH_CODE;
1778                 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1779                         enable = false;
1780                 break;
1781         case LFUN_LABEL_INSERT:
1782                 code = Inset::LABEL_CODE;
1783                 break;
1784         case LFUN_OPTIONAL_INSERT:
1785                 code = Inset::OPTARG_CODE;
1786                 enable = numberOfOptArgs(cur.paragraph())
1787                         < cur.paragraph().layout()->optionalargs;
1788                 break;
1789         case LFUN_ENVIRONMENT_INSERT:
1790                 code = Inset::BOX_CODE;
1791                 break;
1792         case LFUN_INDEX_INSERT:
1793                 code = Inset::INDEX_CODE;
1794                 break;
1795         case LFUN_INDEX_PRINT:
1796                 code = Inset::INDEX_PRINT_CODE;
1797                 break;
1798         case LFUN_NOMENCL_INSERT:
1799                 code = Inset::NOMENCL_CODE;
1800                 break;
1801         case LFUN_NOMENCL_PRINT:
1802                 code = Inset::NOMENCL_PRINT_CODE;
1803                 break;
1804         case LFUN_TOC_INSERT:
1805                 code = Inset::TOC_CODE;
1806                 break;
1807         case LFUN_HTML_INSERT:
1808         case LFUN_URL_INSERT:
1809                 code = Inset::URL_CODE;
1810                 break;
1811         case LFUN_QUOTE_INSERT:
1812                 // always allow this, since we will inset a raw quote
1813                 // if an inset is not allowed.
1814                 break;
1815         case LFUN_HYPHENATION_POINT_INSERT:
1816         case LFUN_LIGATURE_BREAK_INSERT:
1817         case LFUN_HFILL_INSERT:
1818         case LFUN_MENU_SEPARATOR_INSERT:
1819         case LFUN_DOTS_INSERT:
1820         case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
1821                 code = Inset::SPECIALCHAR_CODE;
1822                 break;
1823         case LFUN_SPACE_INSERT:
1824                 // slight hack: we know this is allowed in math mode
1825                 if (cur.inTexted())
1826                         code = Inset::SPACE_CODE;
1827                 break;
1828
1829         case LFUN_INSET_MODIFY:
1830                 // We need to disable this, because we may get called for a
1831                 // tabular cell via
1832                 // InsetTabular::getStatus() -> InsetText::getStatus()
1833                 // and we don't handle LFUN_INSET_MODIFY.
1834                 enable = false;
1835                 break;
1836
1837         case LFUN_FONT_EMPH:
1838                 flag.setOnOff(font.emph() == Font::ON);
1839                 return true;
1840
1841         case LFUN_FONT_NOUN:
1842                 flag.setOnOff(font.noun() == Font::ON);
1843                 return true;
1844
1845         case LFUN_FONT_BOLD:
1846                 flag.setOnOff(font.series() == Font::BOLD_SERIES);
1847                 return true;
1848
1849         case LFUN_FONT_SANS:
1850                 flag.setOnOff(font.family() == Font::SANS_FAMILY);
1851                 return true;
1852
1853         case LFUN_FONT_ROMAN:
1854                 flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
1855                 return true;
1856
1857         case LFUN_FONT_CODE:
1858                 flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
1859                 return true;
1860
1861         case LFUN_CUT:
1862         case LFUN_COPY:
1863                 enable = cur.selection();
1864                 break;
1865
1866         case LFUN_PASTE:
1867                 if (cmd.argument().empty()) {
1868                         if (theClipboard().isInternal())
1869                                 enable = cap::numberOfSelections() > 0;
1870                         else
1871                                 enable = !theClipboard().empty();
1872                 } else {
1873                         string const arg = to_utf8(cmd.argument());
1874                         if (isStrUnsignedInt(arg)) {
1875                                 unsigned int n = convert<unsigned int>(arg);
1876                                 enable = cap::numberOfSelections() > n;
1877                         } else
1878                                 // unknown argument
1879                                 enable = false;
1880                 }
1881                 break;
1882
1883         case LFUN_CLIPBOARD_PASTE:
1884                 enable = !theClipboard().empty();
1885                 break;
1886
1887         case LFUN_PRIMARY_SELECTION_PASTE:
1888                 enable = cur.selection() || !theSelection().empty();
1889                 break;
1890
1891         case LFUN_PARAGRAPH_MOVE_UP:
1892                 enable = cur.pit() > 0 && !cur.selection();
1893                 break;
1894
1895         case LFUN_PARAGRAPH_MOVE_DOWN:
1896                 enable = cur.pit() < cur.lastpit() && !cur.selection();
1897                 break;
1898
1899         case LFUN_INSET_DISSOLVE:
1900                 enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
1901                 break;
1902
1903         case LFUN_CHANGE_ACCEPT:
1904         case LFUN_CHANGE_REJECT:
1905                 // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
1906                 // In principle, these LFUNs should only be enabled if there
1907                 // is a change at the current position/in the current selection.
1908                 // However, without proper optimizations, this will inevitably
1909                 // result in unacceptable performance - just imagine a user who
1910                 // wants to select the complete content of a long document.
1911                 enable = true;
1912                 break;
1913
1914         case LFUN_WORD_DELETE_FORWARD:
1915         case LFUN_WORD_DELETE_BACKWARD:
1916         case LFUN_LINE_DELETE:
1917         case LFUN_WORD_FORWARD:
1918         case LFUN_WORD_BACKWARD:
1919         case LFUN_CHAR_FORWARD:
1920         case LFUN_CHAR_FORWARD_SELECT:
1921         case LFUN_CHAR_BACKWARD:
1922         case LFUN_CHAR_BACKWARD_SELECT:
1923         case LFUN_UP:
1924         case LFUN_UP_SELECT:
1925         case LFUN_DOWN:
1926         case LFUN_DOWN_SELECT:
1927         case LFUN_PARAGRAPH_UP_SELECT:
1928         case LFUN_PARAGRAPH_DOWN_SELECT:
1929         case LFUN_SCREEN_UP_SELECT:
1930         case LFUN_SCREEN_DOWN_SELECT:
1931         case LFUN_LINE_BEGIN_SELECT:
1932         case LFUN_LINE_END_SELECT:
1933         case LFUN_WORD_FORWARD_SELECT:
1934         case LFUN_WORD_BACKWARD_SELECT:
1935         case LFUN_WORD_SELECT:
1936         case LFUN_PARAGRAPH_UP:
1937         case LFUN_PARAGRAPH_DOWN:
1938         case LFUN_SCREEN_UP:
1939         case LFUN_SCREEN_DOWN:
1940         case LFUN_LINE_BEGIN:
1941         case LFUN_LINE_END:
1942         case LFUN_BREAK_LINE:
1943         case LFUN_CHAR_DELETE_FORWARD:
1944         case LFUN_DELETE_FORWARD_SKIP:
1945         case LFUN_CHAR_DELETE_BACKWARD:
1946         case LFUN_DELETE_BACKWARD_SKIP:
1947         case LFUN_BREAK_PARAGRAPH:
1948         case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
1949         case LFUN_BREAK_PARAGRAPH_SKIP:
1950         case LFUN_PARAGRAPH_SPACING:
1951         case LFUN_INSET_INSERT:
1952         case LFUN_WORD_UPCASE:
1953         case LFUN_WORD_LOWCASE:
1954         case LFUN_WORD_CAPITALIZE:
1955         case LFUN_CHARS_TRANSPOSE:
1956         case LFUN_SERVER_GET_XY:
1957         case LFUN_SERVER_SET_XY:
1958         case LFUN_SERVER_GET_FONT:
1959         case LFUN_SERVER_GET_LAYOUT:
1960         case LFUN_LAYOUT:
1961         case LFUN_DATE_INSERT:
1962         case LFUN_SELF_INSERT:
1963         case LFUN_LINE_INSERT:
1964         case LFUN_PAGEBREAK_INSERT:
1965         case LFUN_CLEARPAGE_INSERT:
1966         case LFUN_CLEARDOUBLEPAGE_INSERT:
1967         case LFUN_MATH_DISPLAY:
1968         case LFUN_MATH_IMPORT_SELECTION:
1969         case LFUN_MATH_MODE:
1970         case LFUN_MATH_MACRO:
1971         case LFUN_MATH_MATRIX:
1972         case LFUN_MATH_DELIM:
1973         case LFUN_MATH_BIGDELIM:
1974         case LFUN_MATH_SUBSCRIPT:
1975         case LFUN_MATH_SUPERSCRIPT:
1976         case LFUN_FONT_DEFAULT:
1977         case LFUN_FONT_UNDERLINE:
1978         case LFUN_FONT_SIZE:
1979         case LFUN_LANGUAGE:
1980         case LFUN_FONT_FREE_APPLY:
1981         case LFUN_FONT_FREE_UPDATE:
1982         case LFUN_LAYOUT_PARAGRAPH:
1983         case LFUN_PARAGRAPH_UPDATE:
1984         case LFUN_ACCENT_UMLAUT:
1985         case LFUN_ACCENT_CIRCUMFLEX:
1986         case LFUN_ACCENT_GRAVE:
1987         case LFUN_ACCENT_ACUTE:
1988         case LFUN_ACCENT_TILDE:
1989         case LFUN_ACCENT_CEDILLA:
1990         case LFUN_ACCENT_MACRON:
1991         case LFUN_ACCENT_DOT:
1992         case LFUN_ACCENT_UNDERDOT:
1993         case LFUN_ACCENT_UNDERBAR:
1994         case LFUN_ACCENT_CARON:
1995         case LFUN_ACCENT_SPECIAL_CARON:
1996         case LFUN_ACCENT_BREVE:
1997         case LFUN_ACCENT_TIE:
1998         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1999         case LFUN_ACCENT_CIRCLE:
2000         case LFUN_ACCENT_OGONEK:
2001         case LFUN_THESAURUS_ENTRY:
2002         case LFUN_PARAGRAPH_PARAMS_APPLY:
2003         case LFUN_ESCAPE:
2004         case LFUN_BUFFER_END:
2005         case LFUN_BUFFER_BEGIN:
2006         case LFUN_BUFFER_BEGIN_SELECT:
2007         case LFUN_BUFFER_END_SELECT:
2008         case LFUN_UNICODE_INSERT:
2009                 // these are handled in our dispatch()
2010                 enable = true;
2011                 break;
2012
2013         default:
2014                 return false;
2015         }
2016
2017         if (code != Inset::NO_CODE
2018             && (cur.empty() || !cur.inset().insetAllowed(code)))
2019                 enable = false;
2020
2021         flag.enabled(enable);
2022         return true;
2023 }
2024
2025
2026 void Text::pasteString(Cursor & cur, docstring const & clip,
2027                 bool asParagraphs)
2028 {
2029         cur.clearSelection();
2030         if (!clip.empty()) {
2031                 recordUndo(cur);
2032                 if (asParagraphs)
2033                         insertStringAsParagraphs(cur, clip);
2034                 else
2035                         insertStringAsLines(cur, clip);
2036         }
2037 }
2038
2039 } // namespace lyx