]> git.lyx.org Git - lyx.git/blob - src/text3.C
Spell 'Urlichs' correctly
[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 "FloatList.h"
21 #include "FuncStatus.h"
22 #include "buffer.h"
23 #include "bufferparams.h"
24 #include "BufferView.h"
25 #include "cursor.h"
26 #include "coordcache.h"
27 #include "CutAndPaste.h"
28 #include "debug.h"
29 #include "dispatchresult.h"
30 #include "factory.h"
31 #include "funcrequest.h"
32 #include "gettext.h"
33 #include "intl.h"
34 #include "language.h"
35 #include "LyXAction.h"
36 #include "lyxfunc.h"
37 #include "lyxlex.h"
38 #include "lyxrc.h"
39 #include "lyxrow.h"
40 #include "paragraph.h"
41 #include "paragraph_funcs.h"
42 #include "ParagraphParameters.h"
43 #include "undo.h"
44 #include "vspace.h"
45
46 #include "frontends/Dialogs.h"
47 #include "frontends/LyXView.h"
48
49 #include "insets/insetcommand.h"
50 #include "insets/insetfloatlist.h"
51 #include "insets/insetnewline.h"
52 #include "insets/insetquotes.h"
53 #include "insets/insetspecialchar.h"
54 #include "insets/insettext.h"
55
56 #include "support/lstrings.h"
57 #include "support/lyxlib.h"
58 #include "support/convert.h"
59
60 #include "mathed/math_hullinset.h"
61 #include "mathed/math_macrotemplate.h"
62
63 #include <clocale>
64 #include <sstream>
65
66 using lyx::pos_type;
67
68 using lyx::cap::copySelection;
69 using lyx::cap::cutSelection;
70 using lyx::cap::pasteSelection;
71 using lyx::cap::replaceSelection;
72
73 using lyx::support::isStrUnsignedInt;
74 using lyx::support::token;
75
76 using std::endl;
77 using std::string;
78 using std::istringstream;
79
80
81 extern string current_layout;
82
83
84 namespace {
85
86         // globals...
87         LyXFont freefont(LyXFont::ALL_IGNORE);
88         bool toggleall = false;
89
90
91         void toggleAndShow(LCursor & cur, LyXText * text,
92                 LyXFont const & font, bool toggleall = true)
93         {
94                 text->toggleFree(cur, font, toggleall);
95
96                 if (font.language() != ignore_language ||
97                                 font.number() != LyXFont::IGNORE) {
98                         Paragraph & par = cur.paragraph();
99                         text->bidi.computeTables(par, cur.buffer(), cur.textRow());
100                         if (cur.boundary() !=
101                                         text->bidi.isBoundary(cur.buffer(), par,
102                                                         cur.pos(),
103                                                         text->real_current_font))
104                                 text->setCursor(cur, cur.pit(), cur.pos(),
105                                                 false, !cur.boundary());
106                 }
107         }
108
109
110         void moveCursor(LCursor & cur, bool selecting)
111         {
112                 if (selecting || cur.mark())
113                         cur.setSelection();
114                 if (!cur.selection())
115                         cur.bv().haveSelection(false);
116                 cur.bv().switchKeyMap();
117         }
118
119
120         void finishChange(LCursor & cur, bool selecting)
121         {
122                 finishUndo();
123                 moveCursor(cur, selecting);
124         }
125
126
127         void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
128         {
129                 recordUndo(cur);
130                 string sel = cur.selectionAsString(false);
131                 lyxerr << "selection is: '" << sel << "'" << endl;
132
133                 if (sel.empty()) {
134                         const int old_pos = cur.pos();
135                         cur.insert(new MathHullInset);
136                         BOOST_ASSERT(old_pos == cur.pos());
137                         cur.nextInset()->edit(cur, true);
138                         cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
139                         // don't do that also for LFUN_MATH_MODE
140                         // unless you want end up with always changing
141                         // to mathrm when opening an inlined inset --
142                         // I really hate "LyXfunc overloading"...
143                         if (display)
144                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
145                         cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
146                 } else {
147                         // create a macro if we see "\\newcommand"
148                         // somewhere, and an ordinary formula
149                         // otherwise
150                         cutSelection(cur, true, true);
151                         if (sel.find("\\newcommand") == string::npos
152                             && sel.find("\\def") == string::npos)
153                         {
154                                 cur.insert(new MathHullInset);
155                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
156                                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
157                                 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
158                         } else {
159                                 istringstream is(sel);
160                                 cur.insert(new MathMacroTemplate(is));
161                         }
162                 }
163                 cur.message(N_("Math editor mode"));
164         }
165
166 } // namespace anon
167
168
169
170 namespace bv_funcs {
171
172 string const freefont2string()
173 {
174         string data;
175         if (font2string(freefont, toggleall, data))
176                 return data;
177         return string();
178 }
179
180 }
181
182 bool LyXText::cursorPrevious(LCursor & cur)
183 {
184         pos_type cpos = cur.pos();
185         lyx::pit_type cpar = cur.pit();
186
187         int x = cur.x_target();
188
189         setCursorFromCoordinates(cur, x, 0);
190         bool updated = cursorUp(cur);
191
192         if (cpar == cur.pit() && cpos == cur.pos()) {
193                 // we have a row which is taller than the workarea. The
194                 // simplest solution is to move to the previous row instead.
195                 updated |= cursorUp(cur);
196         }
197
198         cur.bv().updateScrollbar();
199         finishUndo();
200         return updated;
201 }
202
203
204 bool LyXText::cursorNext(LCursor & cur)
205 {
206         pos_type cpos = cur.pos();
207         lyx::pit_type cpar = cur.pit();
208
209         int x = cur.x_target();
210         setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
211         bool updated = cursorDown(cur);
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 next row instead.
216                 updated |= cursorDown(cur);
217         }
218
219         cur.bv().updateScrollbar();
220         finishUndo();
221         return updated;
222 }
223
224
225 namespace {
226
227 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
228 {
229         lyx::cap::replaceSelection(cur);
230         cur.insert(new InsetSpecialChar(kind));
231         cur.posRight();
232 }
233
234
235 void doInsertInset(LCursor & cur, LyXText * text,
236         FuncRequest const & cmd, bool edit, bool pastesel)
237 {
238         InsetBase * inset = createInset(&cur.bv(), cmd);
239         if (!inset)
240                 return;
241
242         recordUndo(cur);
243         bool gotsel = false;
244         if (cur.selection()) {
245                 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
246                 gotsel = true;
247         }
248         text->insertInset(cur, inset);
249
250         if (edit)
251                 inset->edit(cur, true);
252
253         if (gotsel && pastesel)
254                 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
255 }
256
257
258 void update(LCursor & cur)
259 {
260         //we don't call update(true, false) directly to save a metrics call
261         if (cur.bv().fitCursor())
262                 cur.bv().update(false, true);
263 }
264
265
266 } // anon namespace
267
268
269 void LyXText::number(LCursor & cur)
270 {
271         LyXFont font(LyXFont::ALL_IGNORE);
272         font.setNumber(LyXFont::TOGGLE);
273         toggleAndShow(cur, this, font);
274 }
275
276
277 bool LyXText::isRTL(Paragraph const & par) const
278 {
279         return par.isRightToLeftPar(bv()->buffer()->params());
280 }
281
282
283 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
284 {
285         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
286         lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
287
288         BOOST_ASSERT(cur.text() == this);
289         BufferView * bv = &cur.bv();
290         CursorSlice oldTopSlice = cur.top();
291         bool sel = cur.selection();
292         bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
293
294         switch (cmd.action) {
295
296         case LFUN_APPENDIX: {
297                 Paragraph & par = cur.paragraph();
298                 bool start = !par.params().startOfAppendix();
299
300                 // ensure that we have only one start_of_appendix in this document
301                 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
302                         if (pars_[tmp].params().startOfAppendix()) {
303                                 recUndo(tmp);
304                                 pars_[tmp].params().startOfAppendix(false);
305                                 break;
306                         }
307                 }
308
309                 recordUndo(cur);
310                 par.params().startOfAppendix(start);
311
312                 // we can set the refreshing parameters now
313                 updateCounters();
314                 break;
315         }
316
317         case LFUN_DELETE_WORD_FORWARD:
318                 cur.clearSelection();
319                 deleteWordForward(cur);
320                 finishChange(cur, false);
321                 break;
322
323         case LFUN_DELETE_WORD_BACKWARD:
324                 cur.clearSelection();
325                 deleteWordBackward(cur);
326                 finishChange(cur, false);
327                 break;
328
329         case LFUN_DELETE_LINE_FORWARD:
330                 cur.clearSelection();
331                 deleteLineForward(cur);
332                 finishChange(cur, false);
333                 break;
334
335         case LFUN_WORDRIGHT:
336                 if (!cur.mark())
337                         cur.clearSelection();
338                 if (isRTL(cur.paragraph()))
339                         needsUpdate = cursorLeftOneWord(cur);
340                 else
341                         needsUpdate = cursorRightOneWord(cur);
342                 finishChange(cur, false);
343                 break;
344
345         case LFUN_WORDLEFT:
346                 if (!cur.mark())
347                         cur.clearSelection();
348                 if (isRTL(cur.paragraph()))
349                         needsUpdate = cursorRightOneWord(cur);
350                 else
351                         needsUpdate = cursorLeftOneWord(cur);
352                 finishChange(cur, false);
353                 break;
354
355         case LFUN_BEGINNINGBUF:
356                 if (cur.depth() == 1) {
357                         if (!cur.mark())
358                                 cur.clearSelection();
359                         cursorTop(cur);
360                         finishChange(cur, false);
361                 } else {
362                         cur.undispatched();
363                 }
364                 break;
365
366         case LFUN_BEGINNINGBUFSEL:
367                 if (cur.depth() == 1) {
368                         if (!cur.selection())
369                                 cur.resetAnchor();
370                         cursorTop(cur);
371                         finishChange(cur, true);
372                 } else {
373                         cur.undispatched();
374                 }
375                 break;
376
377         case LFUN_ENDBUF:
378                 if (cur.depth() == 1) {
379                         if (!cur.mark())
380                                 cur.clearSelection();
381                         cursorBottom(cur);
382                         finishChange(cur, false);
383                 } else {
384                         cur.undispatched();
385                 }
386                 break;
387
388         case LFUN_ENDBUFSEL:
389                 if (cur.depth() == 1) {
390                         if (!cur.selection())
391                                 cur.resetAnchor();
392                         cursorBottom(cur);
393                         finishChange(cur, true);
394                 } else {
395                         cur.undispatched();
396                 }
397                 break;
398
399         case LFUN_RIGHT:
400         case LFUN_RIGHTSEL:
401                 lyxerr << BOOST_CURRENT_FUNCTION
402                        << " LFUN_RIGHT[SEL]:\n" << cur << endl;
403                 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
404                 if (isRTL(cur.paragraph()))
405                         needsUpdate = cursorLeft(cur);
406                 else
407                         needsUpdate = cursorRight(cur);
408                 if (!needsUpdate && oldTopSlice == cur.top()) {
409                         cur.undispatched();
410                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
411                 }
412                 break;
413
414         case LFUN_LEFT:
415         case LFUN_LEFTSEL:
416                 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
417                 cur.selHandle(cmd.action == LFUN_LEFTSEL);
418                 if (isRTL(cur.paragraph()))
419                         needsUpdate = cursorRight(cur);
420                 else
421                         needsUpdate = cursorLeft(cur);
422                 if (oldTopSlice == cur.top()) {
423                         cur.undispatched();
424                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
425                 }
426                 break;
427
428         case LFUN_UP:
429         case LFUN_UPSEL:
430                 update(cur);
431                 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
432                 cur.selHandle(cmd.action == LFUN_UPSEL);
433                 needsUpdate = cursorUp(cur);
434                 if (oldTopSlice == cur.top()) {
435                         cur.undispatched();
436                         cmd = FuncRequest(LFUN_FINISHED_UP);
437                 }
438                 break;
439
440         case LFUN_DOWN:
441         case LFUN_DOWNSEL:
442                 update(cur);
443                 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
444                 cur.selHandle(cmd.action == LFUN_DOWNSEL);
445                 needsUpdate = cursorDown(cur);
446                 if (oldTopSlice == cur.top()) {
447                         cur.undispatched();
448                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
449                 }
450                 break;
451
452         case LFUN_UP_PARAGRAPH:
453                 if (!cur.mark())
454                         cur.clearSelection();
455                 needsUpdate = cursorUpParagraph(cur);
456                 finishChange(cur, false);
457                 break;
458
459         case LFUN_UP_PARAGRAPHSEL:
460                 if (!cur.selection())
461                         cur.resetAnchor();
462                 cursorUpParagraph(cur);
463                 finishChange(cur, true);
464                 break;
465
466         case LFUN_DOWN_PARAGRAPH:
467                 if (!cur.mark())
468                         cur.clearSelection();
469                 needsUpdate = cursorDownParagraph(cur);
470                 finishChange(cur, false);
471                 break;
472
473         case LFUN_DOWN_PARAGRAPHSEL:
474                 if (!cur.selection())
475                         cur.resetAnchor();
476                 cursorDownParagraph(cur);
477                 finishChange(cur, true);
478                 break;
479
480         case LFUN_PRIORSEL:
481                 update(cur);
482                 if (!cur.selection())
483                         cur.resetAnchor();
484                 cursorPrevious(cur);
485                 finishChange(cur, true);
486                 break;
487
488         case LFUN_NEXTSEL:
489                 update(cur);
490                 if (!cur.selection())
491                         cur.resetAnchor();
492                 cursorNext(cur);
493                 finishChange(cur, true);
494                 break;
495
496         case LFUN_HOMESEL:
497                 update(cur);
498                 if (!cur.selection())
499                         cur.resetAnchor();
500                 cursorHome(cur);
501                 finishChange(cur, true);
502                 break;
503
504         case LFUN_ENDSEL:
505                 update(cur);
506                 if (!cur.selection())
507                         cur.resetAnchor();
508                 cursorEnd(cur);
509                 finishChange(cur, true);
510                 break;
511
512         case LFUN_WORDRIGHTSEL:
513                 if (!cur.selection())
514                         cur.resetAnchor();
515                 if (isRTL(cur.paragraph()))
516                         cursorLeftOneWord(cur);
517                 else
518                         cursorRightOneWord(cur);
519                 finishChange(cur, true);
520                 break;
521
522         case LFUN_WORDLEFTSEL:
523                 if (!cur.selection())
524                         cur.resetAnchor();
525                 if (isRTL(cur.paragraph()))
526                         cursorRightOneWord(cur);
527                 else
528                         cursorLeftOneWord(cur);
529                 finishChange(cur, true);
530                 break;
531
532         case LFUN_WORDSEL: {
533                 selectWord(cur, lyx::WHOLE_WORD);
534                 finishChange(cur, true);
535                 break;
536         }
537
538         case LFUN_PRIOR:
539                 update(cur);
540                 if (!cur.mark())
541                         cur.clearSelection();
542                 finishChange(cur, false);
543                 if (cur.pit() == 0 && cur.textRow().pos() == 0) {
544                         cur.undispatched();
545                         cmd = FuncRequest(LFUN_FINISHED_UP);
546                 } else {
547                         needsUpdate = cursorPrevious(cur);
548                 }
549                 break;
550
551         case LFUN_NEXT:
552                 update(cur);
553                 if (!cur.mark())
554                         cur.clearSelection();
555                 finishChange(cur, false);
556                 if (cur.pit() == cur.lastpit()
557                           && cur.textRow().endpos() == cur.lastpos()) {
558                         cur.undispatched();
559                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
560                 } else {
561                         needsUpdate = cursorNext(cur);
562                 }
563                 break;
564
565         case LFUN_HOME:
566                 if (!cur.mark())
567                         cur.clearSelection();
568                 cursorHome(cur);
569                 finishChange(cur, false);
570                 break;
571
572         case LFUN_END:
573                 if (!cur.mark())
574                         cur.clearSelection();
575                 cursorEnd(cur);
576                 finishChange(cur, false);
577                 break;
578
579         case LFUN_BREAKLINE: {
580                 // Not allowed by LaTeX (labels or empty par)
581                 if (cur.pos() > cur.paragraph().beginOfBody()) {
582                         lyx::cap::replaceSelection(cur);
583                         cur.insert(new InsetNewline);
584                         cur.posRight();
585                         moveCursor(cur, false);
586                 }
587                 break;
588         }
589
590         case LFUN_DELETE:
591                 if (!cur.selection()) {
592                         Delete(cur);
593                         cur.resetAnchor();
594                         // It is possible to make it a lot faster still
595                         // just comment out the line below...
596                 } else {
597                         cutSelection(cur, true, false);
598                 }
599                 moveCursor(cur, false);
600                 break;
601
602         case LFUN_DELETE_SKIP:
603                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
604                 if (!cur.selection()) {
605                         if (cur.pos() == cur.lastpos()) {
606                                 cursorRight(cur);
607                                 cursorLeft(cur);
608                         }
609                         Delete(cur);
610                         cur.resetAnchor();
611                 } else {
612                         cutSelection(cur, true, false);
613                 }
614                 break;
615
616
617         case LFUN_BACKSPACE:
618                 if (!cur.selection()) {
619                         if (bv->owner()->getIntl().getTransManager().backspace()) {
620                                 backspace(cur);
621                                 cur.resetAnchor();
622                                 // It is possible to make it a lot faster still
623                                 // just comment out the line below...
624                         }
625                 } else {
626                         cutSelection(cur, true, false);
627                 }
628                 bv->switchKeyMap();
629                 break;
630
631         case LFUN_BACKSPACE_SKIP:
632                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
633                 if (!cur.selection()) {
634 #ifdef WITH_WARNINGS
635 #warning look here
636 #endif
637                         //CursorSlice cur = cursor();
638                         backspace(cur);
639                         //anchor() = cur;
640                 } else {
641                         cutSelection(cur, true, false);
642                 }
643                 break;
644
645         case LFUN_BREAKPARAGRAPH:
646                 lyx::cap::replaceSelection(cur);
647                 breakParagraph(cur, 0);
648                 cur.resetAnchor();
649                 bv->switchKeyMap();
650                 break;
651
652         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
653                 lyx::cap::replaceSelection(cur);
654                 breakParagraph(cur, 1);
655                 cur.resetAnchor();
656                 bv->switchKeyMap();
657                 break;
658
659         case LFUN_BREAKPARAGRAPH_SKIP: {
660                 // When at the beginning of a paragraph, remove
661                 // indentation.  Otherwise, do the same as LFUN_BREAKPARAGRAPH.
662                 lyx::cap::replaceSelection(cur);
663                 if (cur.pos() == 0)
664                         cur.paragraph().params().labelWidthString(string());
665                 else
666                         breakParagraph(cur, 0);
667                 cur.resetAnchor();
668                 bv->switchKeyMap();
669                 break;
670         }
671
672         case LFUN_PARAGRAPH_SPACING: {
673                 Paragraph & par = cur.paragraph();
674                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
675                 string cur_value = "1.0";
676                 if (cur_spacing == Spacing::Other)
677                         cur_value = par.params().spacing().getValueAsString();
678
679                 istringstream is(cmd.argument);
680                 string tmp;
681                 is >> tmp;
682                 Spacing::Space new_spacing = cur_spacing;
683                 string new_value = cur_value;
684                 if (tmp.empty()) {
685                         lyxerr << "Missing argument to `paragraph-spacing'"
686                                << endl;
687                 } else if (tmp == "single") {
688                         new_spacing = Spacing::Single;
689                 } else if (tmp == "onehalf") {
690                         new_spacing = Spacing::Onehalf;
691                 } else if (tmp == "double") {
692                         new_spacing = Spacing::Double;
693                 } else if (tmp == "other") {
694                         new_spacing = Spacing::Other;
695                         string tmpval = "0.0";
696                         is >> tmpval;
697                         lyxerr << "new_value = " << tmpval << endl;
698                         if (tmpval != "0.0")
699                                 new_value = tmpval;
700                 } else if (tmp == "default") {
701                         new_spacing = Spacing::Default;
702                 } else {
703                         lyxerr << _("Unknown spacing argument: ")
704                                << cmd.argument << endl;
705                 }
706                 if (cur_spacing != new_spacing || cur_value != new_value)
707                         par.params().spacing(Spacing(new_spacing, new_value));
708                 break;
709         }
710
711         case LFUN_INSET_APPLY: {
712                 string const name = cmd.getArg(0);
713                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
714                 if (inset) {
715                         FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
716                         inset->dispatch(cur, fr);
717                 } else {
718                         FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
719                         dispatch(cur, fr);
720                 }
721                 break;
722         }
723
724         case LFUN_INSET_INSERT: {
725                 recordUndo(cur);
726                 InsetBase * inset = createInset(bv, cmd);
727                 if (inset) {
728                         insertInset(cur, inset);
729                         cur.posRight();
730                 }
731                 break;
732         }
733
734         case LFUN_INSET_SETTINGS:
735                 if (cur.inset().asUpdatableInset())
736                         cur.inset().asUpdatableInset()->showInsetDialog(bv);
737                 break;
738
739         case LFUN_NEXT_INSET_TOGGLE: {
740                 InsetBase * inset = cur.nextInset();
741                 if (inset) {
742                         cur.clearSelection();
743                         FuncRequest fr = cmd;
744                         fr.action = LFUN_INSET_TOGGLE;
745                         inset->dispatch(cur, fr);
746                 }
747                 break;
748         }
749
750         case LFUN_KEYMAP_TOGGLE:
751                 cur.clearSelection();
752                 bv->switchKeyMap();
753                 break;
754
755         case LFUN_SPACE_INSERT:
756                 if (cur.paragraph().layout()->free_spacing)
757                         insertChar(cur, ' ');
758                 else {
759                         doInsertInset(cur, this, cmd, false, false);
760                         cur.posRight();
761                 }
762                 moveCursor(cur, false);
763                 break;
764
765         case LFUN_HYPHENATION:
766                 specialChar(cur, InsetSpecialChar::HYPHENATION);
767                 break;
768
769         case LFUN_LIGATURE_BREAK:
770                 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
771                 break;
772
773         case LFUN_LDOTS:
774                 specialChar(cur, InsetSpecialChar::LDOTS);
775                 break;
776
777         case LFUN_END_OF_SENTENCE:
778                 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
779                 break;
780
781         case LFUN_MENU_SEPARATOR:
782                 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
783                 break;
784
785         case LFUN_UPCASE_WORD:
786                 changeCase(cur, LyXText::text_uppercase);
787                 break;
788
789         case LFUN_LOWCASE_WORD:
790                 changeCase(cur, LyXText::text_lowercase);
791                 break;
792
793         case LFUN_CAPITALIZE_WORD:
794                 changeCase(cur, LyXText::text_capitalization);
795                 break;
796
797         case LFUN_TRANSPOSE_CHARS:
798                 recordUndo(cur);
799                 break;
800
801         case LFUN_PASTE:
802                 cur.message(_("Paste"));
803                 lyx::cap::replaceSelection(cur);
804 #ifdef WITH_WARNINGS
805 #warning FIXME Check if the arg is in the domain of available selections.
806 #endif
807                 if (isStrUnsignedInt(cmd.argument))
808                         pasteSelection(cur, convert<unsigned int>(cmd.argument));
809                 else
810                         pasteSelection(cur, 0);
811                 cur.clearSelection(); // bug 393
812                 bv->switchKeyMap();
813                 finishUndo();
814                 break;
815
816         case LFUN_CUT:
817                 cutSelection(cur, true, true);
818                 cur.message(_("Cut"));
819                 break;
820
821         case LFUN_COPY:
822                 copySelection(cur);
823                 cur.message(_("Copy"));
824                 break;
825
826         case LFUN_GETXY:
827                 cur.message(convert<string>(cursorX(cur.top())) + ' '
828                           + convert<string>(cursorY(cur.top())));
829                 break;
830
831         case LFUN_SETXY: {
832                 int x = 0;
833                 int y = 0;
834                 istringstream is(cmd.argument);
835                 is >> x >> y;
836                 if (!is)
837                         lyxerr << "SETXY: Could not parse coordinates in '"
838                                << cmd.argument << std::endl;
839                 else
840                         setCursorFromCoordinates(cur, x, y);
841                 break;
842         }
843
844         case LFUN_GETFONT:
845                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
846                         cur.message("E");
847                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
848                         cur.message("N");
849                 else
850                         cur.message("0");
851                 break;
852
853         case LFUN_GETLAYOUT:
854                 cur.message(cur.paragraph().layout()->name());
855                 break;
856
857         case LFUN_LAYOUT: {
858                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
859                   << cmd.argument << endl;
860
861                 // This is not the good solution to the empty argument
862                 // problem, but it will hopefully suffice for 1.2.0.
863                 // The correct solution would be to augument the
864                 // function list/array with information about what
865                 // functions needs arguments and their type.
866                 if (cmd.argument.empty()) {
867                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
868                         break;
869                 }
870
871                 // Derive layout number from given argument (string)
872                 // and current buffer's textclass (number)
873                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
874                 bool hasLayout = tclass.hasLayout(cmd.argument);
875                 string layout = cmd.argument;
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(string(N_("Layout ")) + cmd.argument +
886                                 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                         bv->owner()->setLayout(layout);
910                         bv->switchKeyMap();
911                 }
912                 break;
913         }
914
915         case LFUN_PASTESELECTION: {
916                 cur.clearSelection();
917                 string const clip = bv->getClipboard();
918                 if (!clip.empty()) {
919                         if (cmd.argument == "paragraph")
920                                 insertStringAsParagraphs(cur, clip);
921                         else
922                                 insertStringAsLines(cur, clip);
923                 }
924                 break;
925         }
926
927         case LFUN_QUOTE: {
928                 lyx::cap::replaceSelection(cur);
929                 Paragraph & par = cur.paragraph();
930                 lyx::pos_type pos = cur.pos();
931                 char c;
932                 if (pos == 0)
933                         c = ' ';
934                 else if (cur.prevInset() && cur.prevInset()->isSpace())
935                         c = ' ';
936                 else
937                         c = par.getChar(pos - 1);
938
939                 LyXLayout_ptr const & style = par.layout();
940
941                 BufferParams const & bufparams = bv->buffer()->params();
942                 if (!style->pass_thru
943                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
944                         string arg = cmd.argument;
945                         if (arg == "single")
946                                 cur.insert(new InsetQuotes(c,
947                                     bufparams.quotes_language,
948                                     InsetQuotes::SingleQ));
949                         else if (arg == "double")
950                                 cur.insert(new InsetQuotes(c,
951                                     bufparams.quotes_language,
952                                     InsetQuotes::DoubleQ));
953                         else
954                                 cur.insert(new InsetQuotes(c, bufparams));
955                         cur.posRight();
956                 }
957                 else
958                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
959                 break;
960         }
961
962         case LFUN_DATE_INSERT: {
963                 lyx::cap::replaceSelection(cur);
964                 time_t now_time_t = time(NULL);
965                 struct tm * now_tm = localtime(&now_time_t);
966                 setlocale(LC_TIME, "");
967                 string arg;
968                 if (!cmd.argument.empty())
969                         arg = cmd.argument;
970                 else
971                         arg = lyxrc.date_insert_format;
972                 char datetmp[32];
973                 int const datetmp_len =
974                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
975
976                 for (int i = 0; i < datetmp_len; i++)
977                         insertChar(cur, datetmp[i]);
978
979                 cur.resetAnchor();
980                 moveCursor(cur, false);
981                 break;
982         }
983
984         case LFUN_MOUSE_TRIPLE:
985                 if (cmd.button() == mouse_button::button1) {
986                         cursorHome(cur);
987                         cur.resetAnchor();
988                         cursorEnd(cur);
989                         cur.setSelection();
990                         bv->haveSelection(cur.selection());
991                 }
992                 break;
993
994         case LFUN_MOUSE_DOUBLE:
995                 if (cmd.button() == mouse_button::button1) {
996                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
997                         bv->haveSelection(cur.selection());
998                 }
999                 break;
1000
1001         // Single-click on work area
1002         case LFUN_MOUSE_PRESS: {
1003                 // Right click on a footnote flag opens float menu
1004                 if (cmd.button() == mouse_button::button3) {
1005                         cur.clearSelection();
1006                         break;
1007                 }
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 && cur.selection()) {
1015                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1016                         paste_internally = true;
1017                 }
1018
1019                 // Clear the selection
1020                 cur.clearSelection();
1021
1022                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1023                 cur.resetAnchor();
1024                 finishUndo();
1025                 cur.setTargetX();
1026
1027                 // Has the cursor just left the inset?
1028                 if (bv->cursor().inMathed() && !cur.inMathed())
1029                         bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1030
1031                 // Set cursor here.
1032                 bv->cursor() = cur;
1033
1034                 // Insert primary selection with middle mouse
1035                 // if there is a local selection in the current buffer,
1036                 // insert this
1037                 if (cmd.button() == mouse_button::button2) {
1038                         if (paste_internally)
1039                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1040                         else
1041                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
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                                 cursorDown(cur);
1064                         else if (cmd.y < 0)
1065                                 cursorUp(cur);
1066                         // This is to allow jumping over large insets
1067                         if (cur.top() == old) {
1068                                 if (cmd.y >= wh)
1069                                         cursorDown(cur);
1070                                 else if (cmd.y < 0)
1071                                         cursorUp(cur);
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                 // finish selection
1093                 if (cmd.button() == mouse_button::button1)
1094                         bv->haveSelection(cur.selection());
1095
1096                 bv->switchKeyMap();
1097                 bv->owner()->updateMenubar();
1098                 bv->owner()->updateToolbars();
1099                 break;
1100         }
1101
1102         case LFUN_SELFINSERT: {
1103                 if (cmd.argument.empty())
1104                         break;
1105
1106                 // Automatically delete the currently selected
1107                 // text and replace it with what is being
1108                 // typed in now. Depends on lyxrc settings
1109                 // "auto_region_delete", which defaults to
1110                 // true (on).
1111
1112                 if (lyxrc.auto_region_delete) {
1113                         if (cur.selection())
1114                                 cutSelection(cur, false, false);
1115                         bv->haveSelection(false);
1116                 }
1117
1118                 cur.clearSelection();
1119                 LyXFont const old_font = real_current_font;
1120
1121                 string::const_iterator cit = cmd.argument.begin();
1122                 string::const_iterator end = cmd.argument.end();
1123                 for (; cit != end; ++cit)
1124                         bv->owner()->getIntl().getTransManager().
1125                                 TranslateAndInsert(*cit, this);
1126
1127                 cur.resetAnchor();
1128                 moveCursor(cur, false);
1129
1130                 // real_current_font.number can change so we need to
1131                 // update the minibuffer
1132                 if (old_font != real_current_font)
1133                 bv->updateScrollbar();
1134                 break;
1135         }
1136
1137         case LFUN_URL: {
1138                 InsetCommandParams p("url");
1139                 string const data = InsetCommandMailer::params2string("url", p);
1140                 bv->owner()->getDialogs().show("url", data, 0);
1141                 break;
1142         }
1143
1144         case LFUN_HTMLURL: {
1145                 InsetCommandParams p("htmlurl");
1146                 string const data = InsetCommandMailer::params2string("url", p);
1147                 bv->owner()->getDialogs().show("url", data, 0);
1148                 break;
1149         }
1150
1151         case LFUN_INSERT_LABEL: {
1152                 // Try to generate a valid label
1153                 string const contents = cmd.argument.empty() ?
1154                         cur.getPossibleLabel() : cmd.argument;
1155
1156                 InsetCommandParams p("label", contents);
1157                 string const data = InsetCommandMailer::params2string("label", p);
1158
1159                 if (cmd.argument.empty()) {
1160                         bv->owner()->getDialogs().show("label", data, 0);
1161                 } else {
1162                         FuncRequest fr(LFUN_INSET_INSERT, data);
1163                         dispatch(cur, fr);
1164                 }
1165                 break;
1166         }
1167
1168
1169 #if 0
1170         case LFUN_INSET_LIST:
1171         case LFUN_INSET_THEOREM:
1172         case LFUN_INSET_CAPTION:
1173 #endif
1174         case LFUN_INSERT_NOTE:
1175         case LFUN_INSERT_CHARSTYLE:
1176         case LFUN_INSERT_BOX:
1177         case LFUN_INSERT_BRANCH:
1178         case LFUN_INSERT_BIBITEM:
1179         case LFUN_INSET_ERT:
1180         case LFUN_INSET_FLOAT:
1181         case LFUN_INSET_FOOTNOTE:
1182         case LFUN_INSET_MARGINAL:
1183         case LFUN_INSET_OPTARG:
1184         case LFUN_INSET_WIDE_FLOAT:
1185         case LFUN_INSET_WRAP:
1186         case LFUN_TABULAR_INSERT:
1187         case LFUN_ENVIRONMENT_INSERT:
1188                 // Open the inset, and move the current selection
1189                 // inside it.
1190                 doInsertInset(cur, this, cmd, true, true);
1191                 cur.posRight();
1192                 break;
1193
1194         case LFUN_INDEX_INSERT:
1195                 // Just open the inset
1196                 doInsertInset(cur, this, cmd, true, false);
1197                 cur.posRight();
1198                 break;
1199
1200         case LFUN_INDEX_PRINT:
1201         case LFUN_TOC_INSERT:
1202         case LFUN_HFILL:
1203         case LFUN_INSERT_LINE:
1204         case LFUN_INSERT_PAGEBREAK:
1205                 // do nothing fancy
1206                 doInsertInset(cur, this, cmd, false, false);
1207                 cur.posRight();
1208                 break;
1209
1210         case LFUN_DEPTH_MIN:
1211                 changeDepth(cur, DEC_DEPTH);
1212                 break;
1213
1214         case LFUN_DEPTH_PLUS:
1215                 changeDepth(cur, INC_DEPTH);
1216                 break;
1217
1218         case LFUN_MATH_DISPLAY:
1219                 mathDispatch(cur, cmd, true);
1220                 break;
1221
1222         case LFUN_MATH_IMPORT_SELECTION:
1223         case LFUN_MATH_MODE:
1224                 if (cmd.argument == "on")
1225                         // don't pass "on" as argument
1226                         mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
1227                 else
1228                         mathDispatch(cur, cmd, false);
1229                 break;
1230
1231         case LFUN_MATH_MACRO:
1232                 if (cmd.argument.empty())
1233                         cur.errorMessage(N_("Missing argument"));
1234                 else {
1235                         string s = cmd.argument;
1236                         string const s1 = token(s, ' ', 1);
1237                         int const nargs = s1.empty() ? 0 : convert<int>(s1);
1238                         string const s2 = token(s, ' ', 2);
1239                         string const type = s2.empty() ? "newcommand" : s2;
1240                         cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1241                         //cur.nextInset()->edit(cur, true);
1242                 }
1243                 break;
1244
1245         // passthrough hat and underscore outside mathed:
1246         case LFUN_SUBSCRIPT:
1247                 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
1248                 break;
1249         case LFUN_SUPERSCRIPT:
1250                 mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
1251                 break;
1252
1253         case LFUN_INSERT_MATH:
1254         case LFUN_INSERT_MATRIX:
1255         case LFUN_MATH_DELIM: {
1256                 cur.insert(new MathHullInset);
1257                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1258                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1259                 cur.dispatch(cmd);
1260                 break;
1261         }
1262
1263         case LFUN_EMPH: {
1264                 LyXFont font(LyXFont::ALL_IGNORE);
1265                 font.setEmph(LyXFont::TOGGLE);
1266                 toggleAndShow(cur, this, font);
1267                 break;
1268         }
1269
1270         case LFUN_BOLD: {
1271                 LyXFont font(LyXFont::ALL_IGNORE);
1272                 font.setSeries(LyXFont::BOLD_SERIES);
1273                 toggleAndShow(cur, this, font);
1274                 break;
1275         }
1276
1277         case LFUN_NOUN: {
1278                 LyXFont font(LyXFont::ALL_IGNORE);
1279                 font.setNoun(LyXFont::TOGGLE);
1280                 toggleAndShow(cur, this, font);
1281                 break;
1282         }
1283
1284         case LFUN_CODE: {
1285                 LyXFont font(LyXFont::ALL_IGNORE);
1286                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1287                 toggleAndShow(cur, this, font);
1288                 break;
1289         }
1290
1291         case LFUN_SANS: {
1292                 LyXFont font(LyXFont::ALL_IGNORE);
1293                 font.setFamily(LyXFont::SANS_FAMILY);
1294                 toggleAndShow(cur, this, font);
1295                 break;
1296         }
1297
1298         case LFUN_ROMAN: {
1299                 LyXFont font(LyXFont::ALL_IGNORE);
1300                 font.setFamily(LyXFont::ROMAN_FAMILY);
1301                 toggleAndShow(cur, this, font);
1302                 break;
1303         }
1304
1305         case LFUN_DEFAULT: {
1306                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1307                 toggleAndShow(cur, this, font);
1308                 break;
1309         }
1310
1311         case LFUN_UNDERLINE: {
1312                 LyXFont font(LyXFont::ALL_IGNORE);
1313                 font.setUnderbar(LyXFont::TOGGLE);
1314                 toggleAndShow(cur, this, font);
1315                 break;
1316         }
1317
1318         case LFUN_FONT_SIZE: {
1319                 LyXFont font(LyXFont::ALL_IGNORE);
1320                 font.setLyXSize(cmd.argument);
1321                 toggleAndShow(cur, this, font);
1322                 break;
1323         }
1324
1325         case LFUN_LANGUAGE: {
1326                 Language const * lang = languages.getLanguage(cmd.argument);
1327                 if (!lang)
1328                         break;
1329                 LyXFont font(LyXFont::ALL_IGNORE);
1330                 font.setLanguage(lang);
1331                 toggleAndShow(cur, this, font);
1332                 bv->switchKeyMap();
1333                 break;
1334         }
1335
1336         case LFUN_FREEFONT_APPLY:
1337                 toggleAndShow(cur, this, freefont, toggleall);
1338                 cur.message(_("Character set"));
1339                 break;
1340
1341         // Set the freefont using the contents of \param data dispatched from
1342         // the frontends and apply it at the current cursor location.
1343         case LFUN_FREEFONT_UPDATE: {
1344                 LyXFont font;
1345                 bool toggle;
1346                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1347                         freefont = font;
1348                         toggleall = toggle;
1349                         toggleAndShow(cur, this, freefont, toggleall);
1350                         cur.message(_("Character set"));
1351                 }
1352                 break;
1353         }
1354
1355         case LFUN_FINISHED_LEFT:
1356                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1357                 break;
1358
1359         case LFUN_FINISHED_RIGHT:
1360                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1361                 ++cur.pos();
1362                 break;
1363
1364         case LFUN_FINISHED_UP:
1365                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1366                 cursorUp(cur);
1367                 break;
1368
1369         case LFUN_FINISHED_DOWN:
1370                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1371                 cursorDown(cur);
1372                 break;
1373
1374         case LFUN_LAYOUT_PARAGRAPH: {
1375                 string data;
1376                 params2string(cur.paragraph(), data);
1377                 data = "show\n" + data;
1378                 bv->owner()->getDialogs().show("paragraph", data);
1379                 break;
1380         }
1381
1382         case LFUN_PARAGRAPH_UPDATE: {
1383                 if (!bv->owner()->getDialogs().visible("paragraph"))
1384                         break;
1385                 string data;
1386                 params2string(cur.paragraph(), data);
1387
1388                 // Will the paragraph accept changes from the dialog?
1389                 InsetBase & inset = cur.inset();
1390                 bool const accept = !inset.forceDefaultParagraphs(&inset);
1391
1392                 data = "update " + convert<string>(accept) + '\n' + data;
1393                 bv->owner()->getDialogs().update("paragraph", data);
1394                 break;
1395         }
1396
1397         case LFUN_UMLAUT:
1398         case LFUN_CIRCUMFLEX:
1399         case LFUN_GRAVE:
1400         case LFUN_ACUTE:
1401         case LFUN_TILDE:
1402         case LFUN_CEDILLA:
1403         case LFUN_MACRON:
1404         case LFUN_DOT:
1405         case LFUN_UNDERDOT:
1406         case LFUN_UNDERBAR:
1407         case LFUN_CARON:
1408         case LFUN_SPECIAL_CARON:
1409         case LFUN_BREVE:
1410         case LFUN_TIE:
1411         case LFUN_HUNG_UMLAUT:
1412         case LFUN_CIRCLE:
1413         case LFUN_OGONEK:
1414                 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1415                 if (!cmd.argument.empty())
1416                         bv->owner()->getIntl().getTransManager()
1417                                 .TranslateAndInsert(cmd.argument[0], this);
1418                 break;
1419
1420         case LFUN_FLOAT_LIST: {
1421                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1422                 if (tclass.floats().typeExist(cmd.argument)) {
1423                         // not quite sure if we want this...
1424                         recordUndo(cur);
1425                         cur.clearSelection();
1426                         breakParagraph(cur);
1427
1428                         if (cur.lastpos() != 0) {
1429                                 cursorLeft(cur);
1430                                 breakParagraph(cur);
1431                         }
1432
1433                         setLayout(cur, tclass.defaultLayoutName());
1434                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1435                         insertInset(cur, new InsetFloatList(cmd.argument));
1436                         cur.posRight();
1437                 } else {
1438                         lyxerr << "Non-existent float type: "
1439                                << cmd.argument << endl;
1440                 }
1441                 break;
1442         }
1443
1444         case LFUN_ACCEPT_CHANGE: {
1445                 acceptChange(cur);
1446                 break;
1447         }
1448
1449         case LFUN_REJECT_CHANGE: {
1450                 rejectChange(cur);
1451                 break;
1452         }
1453
1454         case LFUN_THESAURUS_ENTRY: {
1455                 string arg = cmd.argument;
1456                 if (arg.empty()) {
1457                         arg = cur.selectionAsString(false);
1458                         // FIXME
1459                         if (arg.size() > 100 || arg.empty()) {
1460                                 // Get word or selection
1461                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1462                                 arg = cur.selectionAsString(false);
1463                         }
1464                 }
1465                 bv->owner()->getDialogs().show("thesaurus", arg);
1466                 break;
1467         }
1468
1469         case LFUN_PARAGRAPH_APPLY: {
1470                 // Given data, an encoding of the ParagraphParameters
1471                 // generated in the Paragraph dialog, this function sets
1472                 // the current paragraph appropriately.
1473                 istringstream is(cmd.argument);
1474                 LyXLex lex(0, 0);
1475                 lex.setStream(is);
1476                 ParagraphParameters params;
1477                 params.read(lex);
1478                 setParagraph(cur,
1479                                          params.spacing(),
1480                                          params.align(),
1481                                          params.labelWidthString(),
1482                                          params.noindent());
1483                 cur.message(_("Paragraph layout set"));
1484                 break;
1485         }
1486
1487         case LFUN_INSET_DIALOG_SHOW: {
1488                 InsetBase * inset = cur.nextInset();
1489                 if (inset) {
1490                         FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1491                         inset->dispatch(cur, fr);
1492                 }
1493                 break;
1494         }
1495
1496         case LFUN_ESCAPE:
1497                 if (cur.selection()) {
1498                         cur.selection() = false;
1499                 } else {
1500                         cur.undispatched();
1501                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
1502                 }
1503                 break;
1504
1505         default:
1506                 lyxerr << BOOST_CURRENT_FUNCTION
1507                        << " Not DISPATCHED by LyXText" << endl;
1508                 cur.undispatched();
1509                 break;
1510         }
1511
1512         if (!needsUpdate
1513             && &oldTopSlice.inset() == &cur.inset()
1514             && oldTopSlice.idx() == cur.idx()
1515             && !sel
1516             && !cur.selection())
1517                 cur.noUpdate();
1518         else
1519                 cur.needsUpdate();
1520 }
1521
1522
1523 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1524                         FuncStatus & flag) const
1525 {
1526         BOOST_ASSERT(cur.text() == this);
1527         LyXFont const & font = real_current_font;
1528         bool enable = true;
1529
1530         switch (cmd.action) {
1531
1532         case LFUN_DEPTH_MIN:
1533                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1534                 break;
1535
1536         case LFUN_DEPTH_PLUS:
1537                 enable = changeDepthAllowed(cur, INC_DEPTH);
1538                 break;
1539
1540         case LFUN_INSET_OPTARG:
1541                 enable = numberOfOptArgs(cur.paragraph())
1542                         < cur.paragraph().layout()->optionalargs;
1543                 break;
1544
1545         case LFUN_APPENDIX:
1546                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1547                 break;
1548
1549 #if 0
1550         // the functions which insert insets
1551         InsetBase::Code code = InsetBase::NO_CODE;
1552         switch (cmd.action) {
1553         case LFUN_DIALOG_SHOW_NEW_INSET:
1554                 if (cmd.argument == "bibitem")
1555                         code = InsetBase::BIBITEM_CODE;
1556                 else if (cmd.argument == "bibtex")
1557                         code = InsetBase::BIBTEX_CODE;
1558                 else if (cmd.argument == "box")
1559                         code = InsetBase::BOX_CODE;
1560                 else if (cmd.argument == "branch")
1561                         code = InsetBase::BRANCH_CODE;
1562                 else if (cmd.argument == "citation")
1563                         code = InsetBase::CITE_CODE;
1564                 else if (cmd.argument == "ert")
1565                         code = InsetBase::ERT_CODE;
1566                 else if (cmd.argument == "external")
1567                         code = InsetBase::EXTERNAL_CODE;
1568                 else if (cmd.argument == "float")
1569                         code = InsetBase::FLOAT_CODE;
1570                 else if (cmd.argument == "graphics")
1571                         code = InsetBase::GRAPHICS_CODE;
1572                 else if (cmd.argument == "include")
1573                         code = InsetBase::INCLUDE_CODE;
1574                 else if (cmd.argument == "index")
1575                         code = InsetBase::INDEX_CODE;
1576                 else if (cmd.argument == "label")
1577                         code = InsetBase::LABEL_CODE;
1578                 else if (cmd.argument == "note")
1579                         code = InsetBase::NOTE_CODE;
1580                 else if (cmd.argument == "ref")
1581                         code = InsetBase::REF_CODE;
1582                 else if (cmd.argument == "toc")
1583                         code = InsetBase::TOC_CODE;
1584                 else if (cmd.argument == "url")
1585                         code = InsetBase::URL_CODE;
1586                 else if (cmd.argument == "vspace")
1587                         code = InsetBase::VSPACE_CODE;
1588                 else if (cmd.argument == "wrap")
1589                         code = InsetBase::WRAP_CODE;
1590                 break;
1591
1592         case LFUN_INSET_ERT:
1593                 code = InsetBase::ERT_CODE;
1594                 break;
1595         case LFUN_INSET_FOOTNOTE:
1596                 code = InsetBase::FOOT_CODE;
1597                 break;
1598         case LFUN_TABULAR_INSERT:
1599                 code = InsetBase::TABULAR_CODE;
1600                 break;
1601         case LFUN_INSET_MARGINAL:
1602                 code = InsetBase::MARGIN_CODE;
1603                 break;
1604         case LFUN_INSET_FLOAT:
1605         case LFUN_INSET_WIDE_FLOAT:
1606                 code = InsetBase::FLOAT_CODE;
1607                 break;
1608         case LFUN_INSET_WRAP:
1609                 code = InsetBase::WRAP_CODE;
1610                 break;
1611         case LFUN_FLOAT_LIST:
1612                 code = InsetBase::FLOAT_LIST_CODE;
1613                 break;
1614 #if 0
1615         case LFUN_INSET_LIST:
1616                 code = InsetBase::LIST_CODE;
1617                 break;
1618         case LFUN_INSET_THEOREM:
1619                 code = InsetBase::THEOREM_CODE;
1620                 break;
1621 #endif
1622         case LFUN_INSET_CAPTION:
1623                 code = InsetBase::CAPTION_CODE;
1624                 break;
1625         case LFUN_INSERT_NOTE:
1626                 code = InsetBase::NOTE_CODE;
1627                 break;
1628         case LFUN_INSERT_CHARSTYLE:
1629                 code = InsetBase::CHARSTYLE_CODE;
1630                 if (buf->params().getLyXTextClass().charstyles().empty())
1631                         enable = false;
1632                 break;
1633         case LFUN_INSERT_BOX:
1634                 code = InsetBase::BOX_CODE;
1635                 break;
1636         case LFUN_INSERT_BRANCH:
1637                 code = InsetBase::BRANCH_CODE;
1638                 if (buf->params().branchlist().empty())
1639                         enable = false;
1640                 break;
1641         case LFUN_INSERT_LABEL:
1642                 code = InsetBase::LABEL_CODE;
1643                 break;
1644         case LFUN_INSET_OPTARG:
1645                 code = InsetBase::OPTARG_CODE;
1646                 break;
1647         case LFUN_ENVIRONMENT_INSERT:
1648                 code = InsetBase::BOX_CODE;
1649                 break;
1650         case LFUN_INDEX_INSERT:
1651                 code = InsetBase::INDEX_CODE;
1652                 break;
1653         case LFUN_INDEX_PRINT:
1654                 code = InsetBase::INDEX_PRINT_CODE;
1655                 break;
1656         case LFUN_TOC_INSERT:
1657                 code = InsetBase::TOC_CODE;
1658                 break;
1659         case LFUN_HTMLURL:
1660         case LFUN_URL:
1661                 code = InsetBase::URL_CODE;
1662                 break;
1663         case LFUN_QUOTE:
1664                 // always allow this, since we will inset a raw quote
1665                 // if an inset is not allowed.
1666                 break;
1667         case LFUN_HYPHENATION:
1668         case LFUN_LIGATURE_BREAK:
1669         case LFUN_HFILL:
1670         case LFUN_MENU_SEPARATOR:
1671         case LFUN_LDOTS:
1672         case LFUN_END_OF_SENTENCE:
1673                 code = InsetBase::SPECIALCHAR_CODE;
1674                 break;
1675         case LFUN_SPACE_INSERT:
1676                 // slight hack: we know this is allowed in math mode
1677                 if (cur.inTexted())
1678                         code = InsetBase::SPACE_CODE;
1679                 break;
1680         case LFUN_INSET_DIALOG_SHOW: {
1681                 InsetBase * inset = cur.nextInset();
1682                 enable = inset;
1683                 if (inset) {
1684                         code = inset->lyxCode();
1685                         if (!(code == InsetBase::INCLUDE_CODE
1686                                 || code == InsetBase::BIBTEX_CODE
1687                                 || code == InsetBase::FLOAT_LIST_CODE
1688                                 || code == InsetBase::TOC_CODE))
1689                                 enable = false;
1690                 }
1691                 break;
1692         }
1693         default:
1694                 break;
1695         }
1696
1697         if (code != InsetBase::NO_CODE
1698                         && (cur.empty() || !cur.inset().insetAllowed(code)))
1699                 enable = false;
1700
1701 #endif
1702
1703         case LFUN_DIALOG_SHOW_NEW_INSET:
1704         case LFUN_INSET_ERT:
1705         case LFUN_INSERT_BOX:
1706         case LFUN_INSERT_BRANCH:
1707         case LFUN_ENVIRONMENT_INSERT:
1708         case LFUN_INDEX_INSERT:
1709         case LFUN_INDEX_PRINT:
1710         case LFUN_TOC_INSERT:
1711         case LFUN_HTMLURL:
1712         case LFUN_URL:
1713         case LFUN_QUOTE:
1714         case LFUN_HYPHENATION:
1715         case LFUN_LIGATURE_BREAK:
1716         case LFUN_HFILL:
1717         case LFUN_MENU_SEPARATOR:
1718         case LFUN_LDOTS:
1719         case LFUN_END_OF_SENTENCE:
1720         case LFUN_SPACE_INSERT:
1721         case LFUN_INSET_DIALOG_SHOW:
1722                 break;
1723
1724         case LFUN_EMPH:
1725                 flag.setOnOff(font.emph() == LyXFont::ON);
1726                 break;
1727
1728         case LFUN_NOUN:
1729                 flag.setOnOff(font.noun() == LyXFont::ON);
1730                 break;
1731
1732         case LFUN_BOLD:
1733                 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1734                 break;
1735
1736         case LFUN_SANS:
1737                 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1738                 break;
1739
1740         case LFUN_ROMAN:
1741                 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1742                 break;
1743
1744         case LFUN_CODE:
1745                 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1746                 break;
1747
1748         case LFUN_DELETE_WORD_FORWARD:
1749         case LFUN_DELETE_WORD_BACKWARD:
1750         case LFUN_DELETE_LINE_FORWARD:
1751         case LFUN_WORDRIGHT:
1752         case LFUN_WORDLEFT:
1753         case LFUN_RIGHT:
1754         case LFUN_RIGHTSEL:
1755         case LFUN_LEFT:
1756         case LFUN_LEFTSEL:
1757         case LFUN_UP:
1758         case LFUN_UPSEL:
1759         case LFUN_DOWN:
1760         case LFUN_DOWNSEL:
1761         case LFUN_UP_PARAGRAPHSEL:
1762         case LFUN_DOWN_PARAGRAPHSEL:
1763         case LFUN_PRIORSEL:
1764         case LFUN_NEXTSEL:
1765         case LFUN_HOMESEL:
1766         case LFUN_ENDSEL:
1767         case LFUN_WORDRIGHTSEL:
1768         case LFUN_WORDLEFTSEL:
1769         case LFUN_WORDSEL:
1770         case LFUN_UP_PARAGRAPH:
1771         case LFUN_DOWN_PARAGRAPH:
1772         case LFUN_PRIOR:
1773         case LFUN_NEXT:
1774         case LFUN_HOME:
1775         case LFUN_END:
1776         case LFUN_BREAKLINE:
1777         case LFUN_DELETE:
1778         case LFUN_DELETE_SKIP:
1779         case LFUN_BACKSPACE:
1780         case LFUN_BACKSPACE_SKIP:
1781         case LFUN_BREAKPARAGRAPH:
1782         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1783         case LFUN_BREAKPARAGRAPH_SKIP:
1784         case LFUN_PARAGRAPH_SPACING:
1785         case LFUN_INSET_APPLY:
1786         case LFUN_INSET_INSERT:
1787         case LFUN_NEXT_INSET_TOGGLE:
1788         case LFUN_UPCASE_WORD:
1789         case LFUN_LOWCASE_WORD:
1790         case LFUN_CAPITALIZE_WORD:
1791         case LFUN_TRANSPOSE_CHARS:
1792         case LFUN_PASTE:
1793         case LFUN_CUT:
1794         case LFUN_COPY:
1795         case LFUN_GETXY:
1796         case LFUN_SETXY:
1797         case LFUN_GETFONT:
1798         case LFUN_GETLAYOUT:
1799         case LFUN_LAYOUT:
1800         case LFUN_PASTESELECTION:
1801         case LFUN_DATE_INSERT:
1802         case LFUN_SELFINSERT:
1803         case LFUN_INSERT_LABEL:
1804         case LFUN_INSERT_NOTE:
1805         case LFUN_INSERT_CHARSTYLE:
1806         case LFUN_INSERT_BIBITEM:
1807         case LFUN_INSET_FLOAT:
1808         case LFUN_INSET_FOOTNOTE:
1809         case LFUN_INSET_MARGINAL:
1810         case LFUN_INSET_WIDE_FLOAT:
1811         case LFUN_INSET_WRAP:
1812         case LFUN_TABULAR_INSERT:
1813         case LFUN_INSERT_LINE:
1814         case LFUN_INSERT_PAGEBREAK:
1815         case LFUN_MATH_DISPLAY:
1816         case LFUN_MATH_IMPORT_SELECTION:
1817         case LFUN_MATH_MODE:
1818         case LFUN_MATH_MACRO:
1819         case LFUN_INSERT_MATH:
1820         case LFUN_INSERT_MATRIX:
1821         case LFUN_MATH_DELIM:
1822         case LFUN_SUBSCRIPT:
1823         case LFUN_SUPERSCRIPT:
1824         case LFUN_DEFAULT:
1825         case LFUN_UNDERLINE:
1826         case LFUN_FONT_SIZE:
1827         case LFUN_LANGUAGE:
1828         case LFUN_FREEFONT_APPLY:
1829         case LFUN_FREEFONT_UPDATE:
1830         case LFUN_LAYOUT_PARAGRAPH:
1831         case LFUN_PARAGRAPH_UPDATE:
1832         case LFUN_UMLAUT:
1833         case LFUN_CIRCUMFLEX:
1834         case LFUN_GRAVE:
1835         case LFUN_ACUTE:
1836         case LFUN_TILDE:
1837         case LFUN_CEDILLA:
1838         case LFUN_MACRON:
1839         case LFUN_DOT:
1840         case LFUN_UNDERDOT:
1841         case LFUN_UNDERBAR:
1842         case LFUN_CARON:
1843         case LFUN_SPECIAL_CARON:
1844         case LFUN_BREVE:
1845         case LFUN_TIE:
1846         case LFUN_HUNG_UMLAUT:
1847         case LFUN_CIRCLE:
1848         case LFUN_OGONEK:
1849         case LFUN_FLOAT_LIST:
1850         case LFUN_ACCEPT_CHANGE:
1851         case LFUN_REJECT_CHANGE:
1852         case LFUN_THESAURUS_ENTRY:
1853         case LFUN_PARAGRAPH_APPLY:
1854         case LFUN_ESCAPE:
1855         case LFUN_KEYMAP_TOGGLE:
1856         case LFUN_ENDBUF:
1857         case LFUN_BEGINNINGBUF:
1858         case LFUN_BEGINNINGBUFSEL:
1859         case LFUN_ENDBUFSEL:
1860                 // these are handled in our dispatch()
1861                 enable = true;
1862                 break;
1863
1864         default:
1865                 return false;
1866         }
1867         flag.enabled(enable);
1868         return true;
1869 }