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