]> git.lyx.org Git - lyx.git/blob - src/text3.C
Fix bug 3143 by Richard Heck. Background information from Richard:
[lyx.git] / src / text3.C
1 /**
2  * \file text3.C
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 "lyxtext.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 "lyxlex.h"
42 #include "lyxrc.h"
43 #include "lyxrow.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         LyXFont freefont(LyXFont::ALL_IGNORE);
100         bool toggleall = false;
101
102
103         void toggleAndShow(LCursor & cur, LyXText * text,
104                 LyXFont const & font, bool toggleall = true)
105         {
106                 text->toggleFree(cur, font, toggleall);
107
108                 if (font.language() != ignore_language ||
109                                 font.number() != LyXFont::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(LCursor & 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(LCursor & cur, bool selecting)
132         {
133                 finishUndo();
134                 moveCursor(cur, selecting);
135         }
136
137
138         void mathDispatch(LCursor & 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                                 LyXLex 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 LyXText::cursorPrevious(LCursor & 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 LyXText::cursorNext(LCursor & 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(LCursor & cur, InsetSpecialChar::Kind kind)
246 {
247         cap::replaceSelection(cur);
248         cur.insert(new InsetSpecialChar(kind));
249         cur.posRight();
250 }
251
252
253 bool doInsertInset(LCursor & cur, LyXText * text,
254         FuncRequest const & cmd, bool edit, bool pastesel)
255 {
256         InsetBase * inset = createInset(&cur.bv(), cmd);
257         if (!inset)
258                 return false;
259
260         recordUndo(cur);
261         bool gotsel = false;
262         if (cur.selection()) {
263                 lyx::dispatch(FuncRequest(LFUN_CUT));
264                 gotsel = true;
265         }
266         text->insertInset(cur, inset);
267
268         if (edit)
269                 inset->edit(cur, true);
270
271         if (gotsel && pastesel) {
272                 lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
273                 // reset first par to default
274                 if (cur.lastpit() != 0 || cur.lastpos() != 0) {
275                         LyXLayout_ptr const layout =
276                                 cur.buffer().params().getLyXTextClass().defaultLayout();
277                         cur.text()->paragraphs().begin()->layout(layout);
278                 }
279         }
280         return true;
281 }
282
283
284 } // anon namespace
285
286
287 void LyXText::number(LCursor & cur)
288 {
289         LyXFont font(LyXFont::ALL_IGNORE);
290         font.setNumber(LyXFont::TOGGLE);
291         toggleAndShow(cur, this, font);
292 }
293
294
295 bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
296 {
297         return par.isRightToLeftPar(buffer.params());
298 }
299
300
301 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
302 {
303         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
304
305         // FIXME: We use the update flag to indicates wether a singlePar or a
306         // full screen update is needed. We reset it here but shall we restore it
307         // at the end?
308         cur.noUpdate();
309
310         BOOST_ASSERT(cur.text() == this);
311         BufferView * bv = &cur.bv();
312         CursorSlice oldTopSlice = cur.top();
313         bool oldBoundary = cur.boundary();
314         bool sel = cur.selection();
315         // Signals that, even if needsUpdate == false, an update of the
316         // cursor paragraph is required
317         bool singleParUpdate = lyxaction.funcHasFlag(cmd.action,
318                 LyXAction::SingleParUpdate);
319         // Signals that a full-screen update is required
320         bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
321                 LyXAction::NoUpdate) || singleParUpdate);
322         // Remember the old paragraph metric (_outer_ paragraph!)
323         ParagraphMetrics const & pm = cur.bv().parMetrics(
324                 cur.bottom().text(), cur.bottom().pit());
325         Dimension olddim = pm.dim();
326
327         switch (cmd.action) {
328
329         case LFUN_PARAGRAPH_MOVE_DOWN: {
330                 pit_type const pit = cur.pit();
331                 recUndo(cur, pit, pit + 1);
332                 finishUndo();
333                 std::swap(pars_[pit], pars_[pit + 1]);
334
335                 ParIterator begin(cur);
336                 ++cur.pit();
337                 ParIterator end = boost::next(ParIterator(cur));
338                 updateLabels(cur.buffer(), begin, end);
339
340                 needsUpdate = true;
341                 break;
342         }
343
344         case LFUN_PARAGRAPH_MOVE_UP: {
345                 pit_type const pit = cur.pit();
346                 recUndo(cur, pit - 1, pit);
347                 finishUndo();
348                 std::swap(pars_[pit], pars_[pit - 1]);
349
350                 ParIterator end = boost::next(ParIterator(cur));
351                 --cur.pit();
352                 ParIterator begin(cur);
353                 updateLabels(cur.buffer(), begin, end);
354
355                 needsUpdate = true;
356                 break;
357         }
358
359         case LFUN_APPENDIX: {
360                 Paragraph & par = cur.paragraph();
361                 bool start = !par.params().startOfAppendix();
362
363 #ifdef WITH_WARNINGS
364 #warning The code below only makes sense at top level.
365 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
366 #endif
367                 // ensure that we have only one start_of_appendix in this document
368                 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
369                         if (pars_[tmp].params().startOfAppendix()) {
370                                 recUndo(cur, tmp);
371                                 pars_[tmp].params().startOfAppendix(false);
372                                 break;
373                         }
374                 }
375
376                 recordUndo(cur);
377                 par.params().startOfAppendix(start);
378
379                 // we can set the refreshing parameters now
380                 updateLabels(cur.buffer());
381                 break;
382         }
383
384         case LFUN_WORD_DELETE_FORWARD:
385                 cur.clearSelection();
386                 deleteWordForward(cur);
387                 finishChange(cur, false);
388                 break;
389
390         case LFUN_WORD_DELETE_BACKWARD:
391                 cur.clearSelection();
392                 deleteWordBackward(cur);
393                 finishChange(cur, false);
394                 break;
395
396         case LFUN_LINE_DELETE:
397                 cur.clearSelection();
398                 deleteLineForward(cur);
399                 finishChange(cur, false);
400                 break;
401
402         case LFUN_BUFFER_BEGIN:
403         case LFUN_BUFFER_BEGIN_SELECT:
404                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
405                 if (cur.depth() == 1) {
406                         needsUpdate |= cursorTop(cur);
407                 } else {
408                         cur.undispatched();
409                 }
410                 break;
411
412         case LFUN_BUFFER_END:
413         case LFUN_BUFFER_END_SELECT:
414                 needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
415                 if (cur.depth() == 1) {
416                         needsUpdate |= cursorBottom(cur);
417                 } else {
418                         cur.undispatched();
419                 }
420                 break;
421
422         case LFUN_CHAR_FORWARD:
423         case LFUN_CHAR_FORWARD_SELECT:
424                 //lyxerr << BOOST_CURRENT_FUNCTION
425                 //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
426                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
427                 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
428                         needsUpdate |= cursorLeft(cur);
429                 else
430                         needsUpdate |= cursorRight(cur);
431
432                 if (!needsUpdate && oldTopSlice == cur.top()
433                                 && cur.boundary() == oldBoundary) {
434                         cur.undispatched();
435                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
436                 }
437                 if (cur.selection())
438                         saveSelection(cur);
439                 break;
440
441         case LFUN_CHAR_BACKWARD:
442         case LFUN_CHAR_BACKWARD_SELECT:
443                 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
444                 needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
445                 if (isRTL(*cur.bv().buffer(), cur.paragraph()))
446                         needsUpdate |= cursorRight(cur);
447                 else
448                         needsUpdate |= cursorLeft(cur);
449
450                 if (!needsUpdate && oldTopSlice == cur.top()
451                         && cur.boundary() == oldBoundary) {
452                         cur.undispatched();
453                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
454                 }
455                 if (cur.selection())
456                         saveSelection(cur);
457                 break;
458
459         case LFUN_UP:
460         case LFUN_UP_SELECT:
461                 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
462                 needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
463
464                 needsUpdate |= cursorUp(cur);
465
466                 if (!needsUpdate && oldTopSlice == cur.top()
467                           && cur.boundary() == oldBoundary) {
468                         cur.undispatched();
469                         cmd = FuncRequest(LFUN_FINISHED_UP);
470                 }
471                 if (cur.selection())
472                         saveSelection(cur);
473                 break;
474
475         case LFUN_DOWN:
476         case LFUN_DOWN_SELECT:
477                 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
478                 needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
479                 needsUpdate |= cursorDown(cur);
480
481                 if (!needsUpdate && oldTopSlice == cur.top() &&
482                     cur.boundary() == oldBoundary)
483                 {
484                         cur.undispatched();
485                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
486                 }
487                 if (cur.selection())
488                         saveSelection(cur);
489                 break;
490
491         case LFUN_PARAGRAPH_UP:
492         case LFUN_PARAGRAPH_UP_SELECT:
493                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
494                 needsUpdate |= cursorUpParagraph(cur);
495                 if (cur.selection())
496                         saveSelection(cur);
497                 break;
498
499         case LFUN_PARAGRAPH_DOWN:
500         case LFUN_PARAGRAPH_DOWN_SELECT:
501                 needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
502                 needsUpdate |= cursorDownParagraph(cur);
503                 if (cur.selection())
504                         saveSelection(cur);
505                 break;
506
507         case LFUN_SCREEN_UP:
508         case LFUN_SCREEN_UP_SELECT:
509                 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
510                 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
511                         cur.undispatched();
512                         cmd = FuncRequest(LFUN_FINISHED_UP);
513                 } else {
514                         cursorPrevious(cur);
515                 }
516                 if (cur.selection())
517                         saveSelection(cur);
518                 break;
519
520         case LFUN_SCREEN_DOWN:
521         case LFUN_SCREEN_DOWN_SELECT:
522                 needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
523                 if (cur.pit() == cur.lastpit()
524                           && cur.textRow().endpos() == cur.lastpos()) {
525                         cur.undispatched();
526                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
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 (isRTL(*cur.bv().buffer(), cur.paragraph()))
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 (isRTL(*cur.bv().buffer(), cur.paragraph()))
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                         if (!cur.selection())
580                                 recordUndo(cur);
581                         cap::replaceSelection(cur);
582                         cur.insert(new InsetNewline);
583                         cur.posRight();
584                         moveCursor(cur, false);
585                 }
586                 break;
587         }
588
589         case LFUN_CHAR_DELETE_FORWARD:
590                 if (!cur.selection()) {
591                         if (cur.pos() == cur.paragraph().size())
592                                 // Par boundary, force full-screen update
593                                 singleParUpdate = false;
594                         needsUpdate |= erase(cur);
595                         cur.resetAnchor();
596                         // It is possible to make it a lot faster still
597                         // just comment out the line below...
598                 } else {
599                         cutSelection(cur, true, false);
600                         singleParUpdate = false;
601                 }
602                 moveCursor(cur, false);
603                 break;
604
605         case LFUN_DELETE_FORWARD_SKIP:
606                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
607                 if (!cur.selection()) {
608                         if (cur.pos() == cur.lastpos()) {
609                                 cursorRight(cur);
610                                 cursorLeft(cur);
611                         }
612                         erase(cur);
613                         cur.resetAnchor();
614                 } else {
615                         cutSelection(cur, true, false);
616                 }
617                 break;
618
619
620         case LFUN_CHAR_DELETE_BACKWARD:
621                 if (!cur.selection()) {
622                         if (bv->getIntl().getTransManager().backspace()) {
623                                 // Par boundary, full-screen update
624                                 if (cur.pos() == 0)
625                                         singleParUpdate = false;
626                                 needsUpdate |= backspace(cur);
627                                 cur.resetAnchor();
628                                 // It is possible to make it a lot faster still
629                                 // just comment out the line below...
630                         }
631                 } else {
632                         cutSelection(cur, true, false);
633                         singleParUpdate = false;
634                 }
635                 bv->switchKeyMap();
636                 break;
637
638         case LFUN_DELETE_BACKWARD_SKIP:
639                 // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
640                 if (!cur.selection()) {
641 #ifdef WITH_WARNINGS
642 #warning look here
643 #endif
644                         //CursorSlice cur = cursor();
645                         backspace(cur);
646                         //anchor() = cur;
647                 } else {
648                         cutSelection(cur, true, false);
649                 }
650                 break;
651
652         case LFUN_BREAK_PARAGRAPH:
653                 cap::replaceSelection(cur);
654                 breakParagraph(cur, 0);
655                 //Reset text style to default
656                 setFont(cur, LyXFont(LyXFont::ALL_INHERIT), 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                 InsetBase * 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() == InsetBase::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, LyXText::text_uppercase);
792                 break;
793
794         case LFUN_WORD_LOWCASE:
795                 changeCase(cur, LyXText::text_lowercase);
796                 break;
797
798         case LFUN_WORD_CAPITALIZE:
799                 changeCase(cur, LyXText::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() == LyXFont::ITALIC_SHAPE)
855                         cur.message(from_ascii("E"));
856                 else if (current_font.shape() == LyXFont::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                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
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                 cap::replaceSelection(cur);
945                 Paragraph & par = cur.paragraph();
946                 pos_type pos = cur.pos();
947                 char_type c;
948                 if (pos == 0)
949                         c = ' ';
950                 else if (cur.prevInset() && cur.prevInset()->isSpace())
951                         c = ' ';
952                 else
953                         c = par.getChar(pos - 1);
954
955                 LyXLayout_ptr const & style = par.layout();
956
957                 BufferParams const & bufparams = bv->buffer()->params();
958                 if (!style->pass_thru
959                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
960                         string arg = to_utf8(cmd.argument());
961                         if (arg == "single")
962                                 cur.insert(new InsetQuotes(c,
963                                     bufparams.quotes_language,
964                                     InsetQuotes::SingleQ));
965                         else
966                                 cur.insert(new InsetQuotes(c,
967                                     bufparams.quotes_language,
968                                     InsetQuotes::DoubleQ));
969                         cur.posRight();
970                 }
971                 else
972                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
973                 break;
974         }
975
976         case LFUN_DATE_INSERT:
977                 if (cmd.argument().empty())
978                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
979                                 formatted_time(current_time())));
980                 else
981                         lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
982                                 formatted_time(current_time(), to_utf8(cmd.argument()))));
983                 break;
984
985         case LFUN_MOUSE_TRIPLE:
986                 if (cmd.button() == mouse_button::button1) {
987                         cursorHome(cur);
988                         cur.resetAnchor();
989                         cursorEnd(cur);
990                         cur.setSelection();
991                         bv->cursor() = cur;
992                         saveSelection(cur);
993                 }
994                 break;
995
996         case LFUN_MOUSE_DOUBLE:
997                 if (cmd.button() == mouse_button::button1) {
998                         selectWord(cur, WHOLE_WORD_STRICT);
999                         bv->cursor() = cur;
1000                 }
1001                 break;
1002
1003         // Single-click on work area
1004         case LFUN_MOUSE_PRESS: {
1005                 // Right click on a footnote flag opens float menu
1006                 if (cmd.button() == mouse_button::button3)
1007                         cur.clearSelection();
1008
1009                 // Middle button press pastes if we have a selection
1010                 // We do this here as if the selection was inside an inset
1011                 // it could get cleared on the unlocking of the inset so
1012                 // we have to check this first
1013                 bool paste_internally = false;
1014                 if (cmd.button() == mouse_button::button2 && cap::selection()) {
1015                         // Copy the selection buffer to the clipboard
1016                         // stack, because we want it to appear in the
1017                         // "Edit->Paste recent" menu.
1018                         cap::copySelectionToStack();
1019                         paste_internally = true;
1020                 }
1021
1022                 // we have to update after dePM triggered
1023                 bool update = bv->mouseSetCursor(cur);
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                                 finishUndo();
1035                         } else
1036                                 lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
1037                 }
1038
1039                 if (!update && cmd.button() == mouse_button::button1) {
1040                         needsUpdate = false;
1041                         cur.noUpdate();
1042                 }
1043
1044                 break;
1045         }
1046
1047         case LFUN_MOUSE_MOTION: {
1048                 // Only use motion with button 1
1049                 //if (cmd.button() != mouse_button::button1)
1050                 //      return false;
1051
1052                 // ignore motions deeper nested than the real anchor
1053                 LCursor & bvcur = cur.bv().cursor();
1054                 if (bvcur.anchor_.hasPart(cur)) {
1055                         CursorSlice old = bvcur.top();
1056
1057                         int const wh = bv->workHeight();
1058                         int const y = std::max(0, std::min(wh - 1, cmd.y));
1059
1060                         setCursorFromCoordinates(cur, cmd.x, y);
1061                         cur.x_target() = cmd.x;
1062                         if (cmd.y >= wh)
1063                                 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1064                         else if (cmd.y < 0)
1065                                 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1066                         // This is to allow jumping over large insets
1067                         if (cur.top() == old) {
1068                                 if (cmd.y >= wh)
1069                                         lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1070                                 else if (cmd.y < 0)
1071                                         lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1072                         }
1073
1074                         if (cur.top() == old)
1075                                 cur.noUpdate();
1076                         else {
1077                                 // don't set anchor_
1078                                 bvcur.setCursor(cur);
1079                                 bvcur.selection() = true;
1080                                 //lyxerr << "MOTION: " << bv->cursor() << endl;
1081                         }
1082
1083                 } else
1084                         cur.undispatched();
1085                 break;
1086         }
1087
1088         case LFUN_MOUSE_RELEASE: {
1089                 if (cmd.button() == mouse_button::button2)
1090                         break;
1091
1092                 if (cmd.button() == mouse_button::button1) {
1093                         // if there is new selection, update persistent
1094                         // selection, otherwise, single click does not
1095                         // clear persistent selection buffer
1096                         if (cur.selection()) {
1097                                 // finish selection
1098                                 // if double click, cur is moved to the end of word by selectWord
1099                                 // but bvcur is current mouse position
1100                                 LCursor & bvcur = cur.bv().cursor();
1101                                 bvcur.selection() = true;
1102                                 saveSelection(bvcur);
1103                         }
1104                         needsUpdate = false;
1105                         cur.noUpdate();
1106                 }
1107
1108                 bv->switchKeyMap();
1109                 break;
1110         }
1111
1112         case LFUN_SELF_INSERT: {
1113                 if (cmd.argument().empty())
1114                         break;
1115
1116                 // Automatically delete the currently selected
1117                 // text and replace it with what is being
1118                 // typed in now. Depends on lyxrc settings
1119                 // "auto_region_delete", which defaults to
1120                 // true (on).
1121
1122                 if (lyxrc.auto_region_delete)
1123                         if (cur.selection())
1124                                 cutSelection(cur, false, false);
1125
1126                 cur.clearSelection();
1127                 LyXFont const old_font = real_current_font;
1128
1129                 docstring::const_iterator cit = cmd.argument().begin();
1130                 docstring::const_iterator end = cmd.argument().end();
1131                 for (; cit != end; ++cit)
1132 #if 0
1133                         bv->getIntl().getTransManager().
1134                                 translateAndInsert(*cit, this);
1135 #else
1136                         insertChar(bv->cursor(), *cit);
1137 #endif
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_FOOTNOTE_INSERT:
1194         case LFUN_MARGINALNOTE_INSERT:
1195         case LFUN_OPTIONAL_INSERT:
1196         case LFUN_ENVIRONMENT_INSERT:
1197                 // Open the inset, and move the current selection
1198                 // inside it.
1199                 doInsertInset(cur, this, cmd, true, true);
1200                 cur.posRight();
1201                 break;
1202
1203         case LFUN_TABULAR_INSERT:
1204                 // if there were no arguments, just open the dialog
1205                 if (doInsertInset(cur, this, cmd, false, true))
1206                         cur.posRight();
1207                 else
1208                         bv->showDialog("tabularcreate");
1209
1210                 break;
1211
1212         case LFUN_FLOAT_INSERT:
1213         case LFUN_FLOAT_WIDE_INSERT:
1214         case LFUN_WRAP_INSERT: {
1215                 bool content = cur.selection();  // will some text be moved into the inset?
1216
1217                 doInsertInset(cur, this, cmd, true, true);
1218                 cur.posRight();
1219                 ParagraphList & pars = cur.text()->paragraphs();
1220
1221                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1222
1223                 // add a separate paragraph for the caption inset
1224                 pars.push_back(Paragraph());
1225                 pars.back().setInsetOwner(pars[0].inInset());
1226                 pars.back().layout(tclass.defaultLayout());
1227
1228                 int cap_pit = pars.size() - 1;
1229
1230                 // if an empty inset was created, we create an additional empty
1231                 // paragraph at the bottom so that the user can choose where to put
1232                 // the graphics (or table).
1233                 if (!content) {
1234                         pars.push_back(Paragraph());
1235                         pars.back().setInsetOwner(pars[0].inInset());
1236                         pars.back().layout(tclass.defaultLayout());
1237                         
1238                 }
1239
1240                 // reposition the cursor to the caption
1241                 cur.pit() = cap_pit;
1242                 cur.pos() = 0;
1243                 cur.dispatch(FuncRequest(LFUN_CAPTION_INSERT));
1244                 // FIXME: When leaving the Float (or Wrap) inset we should
1245                 // delete any empty paragraph left above or below the
1246                 // caption.
1247                 break;
1248         }
1249
1250         case LFUN_INDEX_INSERT:
1251         case LFUN_NOMENCL_INSERT: {
1252                 InsetBase * inset = createInset(&cur.bv(), cmd);
1253                 if (!inset)
1254                         break;
1255
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                 cur.dispatch(cmd);
1332                 break;
1333         }
1334
1335         case LFUN_FONT_EMPH: {
1336                 LyXFont font(LyXFont::ALL_IGNORE);
1337                 font.setEmph(LyXFont::TOGGLE);
1338                 toggleAndShow(cur, this, font);
1339                 break;
1340         }
1341
1342         case LFUN_FONT_BOLD: {
1343                 LyXFont font(LyXFont::ALL_IGNORE);
1344                 font.setSeries(LyXFont::BOLD_SERIES);
1345                 toggleAndShow(cur, this, font);
1346                 break;
1347         }
1348
1349         case LFUN_FONT_NOUN: {
1350                 LyXFont font(LyXFont::ALL_IGNORE);
1351                 font.setNoun(LyXFont::TOGGLE);
1352                 toggleAndShow(cur, this, font);
1353                 break;
1354         }
1355
1356         case LFUN_FONT_CODE: {
1357                 LyXFont font(LyXFont::ALL_IGNORE);
1358                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1359                 toggleAndShow(cur, this, font);
1360                 break;
1361         }
1362
1363         case LFUN_FONT_SANS: {
1364                 LyXFont font(LyXFont::ALL_IGNORE);
1365                 font.setFamily(LyXFont::SANS_FAMILY);
1366                 toggleAndShow(cur, this, font);
1367                 break;
1368         }
1369
1370         case LFUN_FONT_ROMAN: {
1371                 LyXFont font(LyXFont::ALL_IGNORE);
1372                 font.setFamily(LyXFont::ROMAN_FAMILY);
1373                 toggleAndShow(cur, this, font);
1374                 break;
1375         }
1376
1377         case LFUN_FONT_DEFAULT: {
1378                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1379                 toggleAndShow(cur, this, font);
1380                 break;
1381         }
1382
1383         case LFUN_FONT_UNDERLINE: {
1384                 LyXFont font(LyXFont::ALL_IGNORE);
1385                 font.setUnderbar(LyXFont::TOGGLE);
1386                 toggleAndShow(cur, this, font);
1387                 break;
1388         }
1389
1390         case LFUN_FONT_SIZE: {
1391                 LyXFont font(LyXFont::ALL_IGNORE);
1392                 font.setLyXSize(to_utf8(cmd.argument()));
1393                 toggleAndShow(cur, this, font);
1394                 break;
1395         }
1396
1397         case LFUN_LANGUAGE: {
1398                 Language const * lang = languages.getLanguage(to_utf8(cmd.argument()));
1399                 if (!lang)
1400                         break;
1401                 LyXFont font(LyXFont::ALL_IGNORE);
1402                 font.setLanguage(lang);
1403                 toggleAndShow(cur, this, font);
1404                 bv->switchKeyMap();
1405                 break;
1406         }
1407
1408         case LFUN_FONT_FREE_APPLY:
1409                 toggleAndShow(cur, this, freefont, toggleall);
1410                 cur.message(_("Character set"));
1411                 break;
1412
1413         // Set the freefont using the contents of \param data dispatched from
1414         // the frontends and apply it at the current cursor location.
1415         case LFUN_FONT_FREE_UPDATE: {
1416                 LyXFont font;
1417                 bool toggle;
1418                 if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
1419                         freefont = font;
1420                         toggleall = toggle;
1421                         toggleAndShow(cur, this, freefont, toggleall);
1422                         cur.message(_("Character set"));
1423                 }
1424                 break;
1425         }
1426
1427         case LFUN_FINISHED_LEFT:
1428                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1429                 break;
1430
1431         case LFUN_FINISHED_RIGHT:
1432                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1433                 ++cur.pos();
1434                 break;
1435
1436         case LFUN_FINISHED_UP:
1437                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1438                 cursorUp(cur);
1439                 break;
1440
1441         case LFUN_FINISHED_DOWN:
1442                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1443                 cursorDown(cur);
1444                 break;
1445
1446         case LFUN_LAYOUT_PARAGRAPH: {
1447                 string data;
1448                 params2string(cur.paragraph(), data);
1449                 data = "show\n" + data;
1450                 bv->showDialogWithData("paragraph", data);
1451                 break;
1452         }
1453
1454         case LFUN_PARAGRAPH_UPDATE: {
1455                 string data;
1456                 params2string(cur.paragraph(), data);
1457
1458                 // Will the paragraph accept changes from the dialog?
1459                 bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx());
1460
1461                 data = "update " + convert<string>(accept) + '\n' + data;
1462                 bv->updateDialog("paragraph", data);
1463                 break;
1464         }
1465
1466         case LFUN_ACCENT_UMLAUT:
1467         case LFUN_ACCENT_CIRCUMFLEX:
1468         case LFUN_ACCENT_GRAVE:
1469         case LFUN_ACCENT_ACUTE:
1470         case LFUN_ACCENT_TILDE:
1471         case LFUN_ACCENT_CEDILLA:
1472         case LFUN_ACCENT_MACRON:
1473         case LFUN_ACCENT_DOT:
1474         case LFUN_ACCENT_UNDERDOT:
1475         case LFUN_ACCENT_UNDERBAR:
1476         case LFUN_ACCENT_CARON:
1477         case LFUN_ACCENT_SPECIAL_CARON:
1478         case LFUN_ACCENT_BREVE:
1479         case LFUN_ACCENT_TIE:
1480         case LFUN_ACCENT_HUNGARIAN_UMLAUT:
1481         case LFUN_ACCENT_CIRCLE:
1482         case LFUN_ACCENT_OGONEK:
1483                 theLyXFunc().handleKeyFunc(cmd.action);
1484                 if (!cmd.argument().empty())
1485                         // FIXME: Are all these characters encoded in one byte in utf8?
1486                         bv->getIntl().getTransManager()
1487                                 .translateAndInsert(cmd.argument()[0], this, cur);
1488                 break;
1489
1490         case LFUN_FLOAT_LIST: {
1491                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1492                 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
1493                         // not quite sure if we want this...
1494                         recordUndo(cur);
1495                         cur.clearSelection();
1496                         breakParagraph(cur);
1497
1498                         if (cur.lastpos() != 0) {
1499                                 cursorLeft(cur);
1500                                 breakParagraph(cur);
1501                         }
1502
1503                         setLayout(cur, tclass.defaultLayoutName());
1504                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
1505                         insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
1506                         cur.posRight();
1507                 } else {
1508                         lyxerr << "Non-existent float type: "
1509                                << to_utf8(cmd.argument()) << endl;
1510                 }
1511                 break;
1512         }
1513
1514         case LFUN_CHANGE_ACCEPT: {
1515                 acceptOrRejectChanges(cur, ACCEPT);
1516                 break;
1517         }
1518
1519         case LFUN_CHANGE_REJECT: {
1520                 acceptOrRejectChanges(cur, REJECT);
1521                 break;
1522         }
1523
1524         case LFUN_THESAURUS_ENTRY: {
1525                 docstring arg = cmd.argument();
1526                 if (arg.empty()) {
1527                         arg = cur.selectionAsString(false);
1528                         // FIXME
1529                         if (arg.size() > 100 || arg.empty()) {
1530                                 // Get word or selection
1531                                 selectWordWhenUnderCursor(cur, WHOLE_WORD);
1532                                 arg = cur.selectionAsString(false);
1533                         }
1534                 }
1535                 bv->showDialogWithData("thesaurus", to_utf8(arg));
1536                 break;
1537         }
1538
1539         case LFUN_PARAGRAPH_PARAMS_APPLY: {
1540                 // Given data, an encoding of the ParagraphParameters
1541                 // generated in the Paragraph dialog, this function sets
1542                 // the current paragraph appropriately.
1543                 istringstream is(to_utf8(cmd.argument()));
1544                 LyXLex lex(0, 0);
1545                 lex.setStream(is);
1546                 ParagraphParameters params;
1547                 params.read(lex);
1548                 setParagraph(cur,
1549                              params.spacing(),
1550                              params.align(),
1551                              params.labelWidthString(),
1552                              params.noindent());
1553                 cur.message(_("Paragraph layout set"));
1554                 break;
1555         }
1556
1557         case LFUN_ESCAPE:
1558                 if (cur.selection()) {
1559                         cur.selection() = false;
1560                         saveSelection(cur);
1561                 } else {
1562                         cur.undispatched();
1563                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1564                 }
1565                 break;
1566
1567         default:
1568                 lyxerr[Debug::ACTION]
1569                         << BOOST_CURRENT_FUNCTION
1570                         << ": Command " << cmd
1571                         << " not DISPATCHED by LyXText" << endl;
1572                 cur.undispatched();
1573                 break;
1574         }
1575
1576         needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
1577
1578         // FIXME: The cursor flag is reset two lines below
1579         // so we need to check here if some of the LFUN did touch that.
1580         // for now only LyXText::erase() and LyXText::backspace() do that.
1581         // The plan is to verify all the LFUNs and then to remove this
1582         // singleParUpdate boolean altogether.
1583         if (cur.result().update() & Update::Force) {
1584                 singleParUpdate = false;
1585                 needsUpdate = true;
1586         }
1587
1588         // FIXME: the following code should go in favor of fine grained
1589         // update flag treatment.
1590         if (singleParUpdate) {
1591                 // Inserting characters does not change par height
1592                 ParagraphMetrics const & pms 
1593                         = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
1594                 if (pms.dim().height()
1595                     == olddim.height()) {
1596                         // if so, update _only_ this paragraph
1597                         cur.updateFlags(Update::SinglePar |
1598                                 Update::FitCursor |
1599                                 Update::MultiParSel);
1600                         return;
1601                 } else
1602                         needsUpdate = true;
1603         }
1604
1605         if (!needsUpdate
1606             && &oldTopSlice.inset() == &cur.inset()
1607             && oldTopSlice.idx() == cur.idx()
1608             && !sel // sel is a backup of cur.selection() at the biginning of the function.
1609             && !cur.selection())
1610                 // FIXME: it would be better if we could just do this
1611                 //
1612                 //if (cur.result().update() != Update::FitCursor)
1613                 //      cur.noUpdate();
1614                 // 
1615                 // But some LFUNs do not set Update::FitCursor when needed, so we
1616                 // do it for all. This is not very harmfull as FitCursor will provoke
1617                 // a full redraw only if needed but still, a proper review of all LFUN
1618                 // should be done and this needsUpdate boolean can then be removed.
1619                 cur.updateFlags(Update::FitCursor);
1620         else
1621                 cur.updateFlags(Update::Force | Update::FitCursor);
1622 }
1623
1624
1625 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1626                         FuncStatus & flag) const
1627 {
1628         BOOST_ASSERT(cur.text() == this);
1629
1630         LyXFont const & font = real_current_font;
1631         bool enable = true;
1632         InsetBase::Code code = InsetBase::NO_CODE;
1633
1634         switch (cmd.action) {
1635
1636         case LFUN_DEPTH_DECREMENT:
1637                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1638                 break;
1639
1640         case LFUN_DEPTH_INCREMENT:
1641                 enable = changeDepthAllowed(cur, INC_DEPTH);
1642                 break;
1643
1644         case LFUN_APPENDIX:
1645                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1646                 return true;
1647
1648         case LFUN_BIBITEM_INSERT:
1649                 enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
1650                 break;
1651
1652         case LFUN_DIALOG_SHOW_NEW_INSET:
1653                 if (cmd.argument() == "bibitem")
1654                         code = InsetBase::BIBITEM_CODE;
1655                 else if (cmd.argument() == "bibtex")
1656                         code = InsetBase::BIBTEX_CODE;
1657                 else if (cmd.argument() == "box")
1658                         code = InsetBase::BOX_CODE;
1659                 else if (cmd.argument() == "branch")
1660                         code = InsetBase::BRANCH_CODE;
1661                 else if (cmd.argument() == "citation")
1662                         code = InsetBase::CITE_CODE;
1663                 else if (cmd.argument() == "ert")
1664                         code = InsetBase::ERT_CODE;
1665                 else if (cmd.argument() == "external")
1666                         code = InsetBase::EXTERNAL_CODE;
1667                 else if (cmd.argument() == "float")
1668                         code = InsetBase::FLOAT_CODE;
1669                 else if (cmd.argument() == "graphics")
1670                         code = InsetBase::GRAPHICS_CODE;
1671                 else if (cmd.argument() == "include")
1672                         code = InsetBase::INCLUDE_CODE;
1673                 else if (cmd.argument() == "index")
1674                         code = InsetBase::INDEX_CODE;
1675                 else if (cmd.argument() == "nomenclature")
1676                         code = InsetBase::NOMENCL_CODE;
1677                 else if (cmd.argument() == "label")
1678                         code = InsetBase::LABEL_CODE;
1679                 else if (cmd.argument() == "note")
1680                         code = InsetBase::NOTE_CODE;
1681                 else if (cmd.argument() == "ref")
1682                         code = InsetBase::REF_CODE;
1683                 else if (cmd.argument() == "toc")
1684                         code = InsetBase::TOC_CODE;
1685                 else if (cmd.argument() == "url")
1686                         code = InsetBase::URL_CODE;
1687                 else if (cmd.argument() == "vspace")
1688                         code = InsetBase::VSPACE_CODE;
1689                 else if (cmd.argument() == "wrap")
1690                         code = InsetBase::WRAP_CODE;
1691                 break;
1692
1693         case LFUN_ERT_INSERT:
1694                 code = InsetBase::ERT_CODE;
1695                 break;
1696         case LFUN_FOOTNOTE_INSERT:
1697                 code = InsetBase::FOOT_CODE;
1698                 break;
1699         case LFUN_TABULAR_INSERT:
1700                 code = InsetBase::TABULAR_CODE;
1701                 break;
1702         case LFUN_MARGINALNOTE_INSERT:
1703                 code = InsetBase::MARGIN_CODE;
1704                 break;
1705         case LFUN_FLOAT_INSERT:
1706         case LFUN_FLOAT_WIDE_INSERT:
1707                 code = InsetBase::FLOAT_CODE;
1708                 break;
1709         case LFUN_WRAP_INSERT:
1710                 code = InsetBase::WRAP_CODE;
1711                 break;
1712         case LFUN_FLOAT_LIST:
1713                 code = InsetBase::FLOAT_LIST_CODE;
1714                 break;
1715 #if 0
1716         case LFUN_LIST_INSERT:
1717                 code = InsetBase::LIST_CODE;
1718                 break;
1719         case LFUN_THEOREM_INSERT:
1720                 code = InsetBase::THEOREM_CODE;
1721                 break;
1722 #endif
1723         case LFUN_CAPTION_INSERT:
1724                 code = InsetBase::CAPTION_CODE;
1725                 break;
1726         case LFUN_NOTE_INSERT:
1727                 code = InsetBase::NOTE_CODE;
1728                 break;
1729         case LFUN_CHARSTYLE_INSERT:
1730                 code = InsetBase::CHARSTYLE_CODE;
1731                 if (cur.buffer().params().getLyXTextClass().charstyles().empty())
1732                         enable = false;
1733                 break;
1734         case LFUN_BOX_INSERT:
1735                 code = InsetBase::BOX_CODE;
1736                 break;
1737         case LFUN_BRANCH_INSERT:
1738                 code = InsetBase::BRANCH_CODE;
1739                 if (cur.buffer().getMasterBuffer()->params().branchlist().empty())
1740                         enable = false;
1741                 break;
1742         case LFUN_LABEL_INSERT:
1743                 code = InsetBase::LABEL_CODE;
1744                 break;
1745         case LFUN_OPTIONAL_INSERT:
1746                 code = InsetBase::OPTARG_CODE;
1747                 enable = numberOfOptArgs(cur.paragraph())
1748                         < cur.paragraph().layout()->optionalargs;
1749                 break;
1750         case LFUN_ENVIRONMENT_INSERT:
1751                 code = InsetBase::BOX_CODE;
1752                 break;
1753         case LFUN_INDEX_INSERT:
1754                 code = InsetBase::INDEX_CODE;
1755                 break;
1756         case LFUN_INDEX_PRINT:
1757                 code = InsetBase::INDEX_PRINT_CODE;
1758                 break;
1759         case LFUN_NOMENCL_INSERT:
1760                 code = InsetBase::NOMENCL_CODE;
1761                 break;
1762         case LFUN_NOMENCL_PRINT:
1763                 code = InsetBase::NOMENCL_PRINT_CODE;
1764                 break;
1765         case LFUN_TOC_INSERT:
1766                 code = InsetBase::TOC_CODE;
1767                 break;
1768         case LFUN_HTML_INSERT:
1769         case LFUN_URL_INSERT:
1770                 code = InsetBase::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 = InsetBase::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 = InsetBase::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() == LyXFont::ON);
1800                 return true;
1801
1802         case LFUN_FONT_NOUN:
1803                 flag.setOnOff(font.noun() == LyXFont::ON);
1804                 return true;
1805
1806         case LFUN_FONT_BOLD:
1807                 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1808                 return true;
1809
1810         case LFUN_FONT_SANS:
1811                 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1812                 return true;
1813
1814         case LFUN_FONT_ROMAN:
1815                 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1816                 return true;
1817
1818         case LFUN_FONT_CODE:
1819                 flag.setOnOff(font.family() == LyXFont::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 != InsetBase::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 LyXText::pasteString(LCursor & 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