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