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