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