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