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