]> git.lyx.org Git - lyx.git/blob - src/text3.C
fix compile
[lyx.git] / src / text3.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2002 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include "lyxtext.h"
14 #include "lyxrow.h"
15 #include "paragraph.h"
16 #include "BufferView.h"
17 #include "funcrequest.h"
18 #include "lyxrc.h"
19 #include "Lsstream.h"
20 #include "debug.h"
21 #include "bufferparams.h"
22 #include "buffer.h"
23 #include "ParagraphParameters.h"
24 #include "gettext.h"
25 #include "factory.h"
26 #include "intl.h"
27 #include "box.h"
28 #include "language.h"
29 #include "support/tostr.h"
30 #include "frontends/LyXView.h"
31 #include "frontends/screen.h"
32 #include "frontends/Dialogs.h"
33 #include "insets/insetspecialchar.h"
34 #include "insets/insettext.h"
35 #include "insets/insetquotes.h"
36 #include "insets/insetcommand.h"
37 #include "insets/insetnewline.h"
38 #include "undo_funcs.h"
39 #include "text_funcs.h"
40 #include "Lsstream.h"
41
42 #include <ctime>
43 #include <clocale>
44
45 using std::endl;
46 using std::find;
47 using std::vector;
48 using lyx::pos_type;
49
50 extern string current_layout;
51 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
52
53 // the selection possible is needed, that only motion events are
54 // used, where the bottom press event was on the drawing area too
55 bool selection_possible = false;
56
57
58 namespace {
59
60         void moveCursorUpdate(BufferView * bv, bool selecting)
61         {
62                 LyXText * lt = bv->getLyXText();
63
64                 if (selecting || lt->selection.mark()) {
65                         lt->setSelection();
66                         if (lt->isInInset())
67                                 bv->updateInset(lt->inset_owner);
68                         else
69                                 bv->toggleToggle();
70                 }
71                 if (!lt->isInInset()) {
72                         bv->update(lt, BufferView::SELECT);
73                 } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
74                         bv->update(BufferView::SELECT);
75                 }
76
77                 if (!lt->selection.set())
78                         bv->haveSelection(false);
79
80                 bv->switchKeyMap();
81         }
82
83
84         void finishChange(BufferView * bv, bool selecting = false)
85         {
86                 finishUndo();
87                 moveCursorUpdate(bv, selecting);
88                 bv->owner()->view_state_changed();
89         }
90
91         // check if the given co-ordinates are inside an inset at the
92         // given cursor, if one exists. If so, the inset is returned,
93         // and the co-ordinates are made relative. Otherwise, 0 is returned.
94         Inset * checkInset(BufferView * bv, LyXText & text,
95                 LyXCursor const & cur, int & x, int & y)
96         {
97                 lyx::pos_type const pos = cur.pos();
98                 Paragraph /*const*/ & par = *cur.par();
99
100                 if (pos >= par.size() || !par.isInset(pos))
101                         return 0;
102
103                 Inset /*const*/ * inset = par.getInset(pos);
104
105                 if (!isEditableInset(inset))
106                         return 0;
107
108                 // get inset dimensions
109                 lyx::Assert(par.getInset(pos));
110
111                 LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
112
113                 int const width = inset->width(bv, font);
114                 int const inset_x = font.isVisibleRightToLeft()
115                         ? (cur.ix() - width) : cur.ix();
116
117                 Box b(
118                         inset_x + inset->scroll(),
119                         inset_x + width,
120                         cur.iy() - inset->ascent(bv, font),
121                         cur.iy() + inset->descent(bv, font)
122                 );
123
124                 if (!b.contained(x, y)) {
125                         lyxerr[Debug::GUI] << "Missed inset at x,y "
126                                            << x << ',' << y
127                                            << " box " << b << endl;
128                         return 0;
129                 }
130
131                 text.setCursor(&par, pos, true);
132
133                 x -= b.x1;
134                 // The origin of an inset is on the baseline
135                 y -= text.cursor.iy();
136
137                 return inset;
138         }
139
140 } // anon namespace
141
142
143 Inset * LyXText::checkInsetHit(int & x, int & y)
144 {
145         int y_tmp = y + top_y();
146
147         LyXCursor cur;
148         setCursorFromCoordinates(cur, x, y_tmp);
149
150         Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
151         if (inset) {
152                 y = y_tmp;
153                 return inset;
154         }
155
156         // look at previous position
157         if (cur.pos() == 0)
158                 return 0;
159
160         // move back one
161         setCursor(cur, cur.par(), cur.pos() - 1, true);
162
163         inset = checkInset(bv(), *this, cur, x, y_tmp);
164         if (inset)
165                 y = y_tmp;
166         return inset;
167 }
168
169
170 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
171                             string const & contents)
172 {
173         ParagraphList::iterator end = ownerParagraphs().end();
174         ParagraphList::iterator pit = cursor.par();
175         pos_type pos = cursor.pos();
176
177         Inset * inset;
178         do {
179                 if (pos + 1 < pit->size()) {
180                         ++pos;
181                 } else  {
182                         ++pit;
183                         pos = 0;
184                 }
185
186         } while (pit != end &&
187                  !(pit->isInset(pos) &&
188                    (inset = pit->getInset(pos)) != 0 &&
189                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
190                    (contents.empty() ||
191                     static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
192                     == contents)));
193
194         if (pit != end) {
195                 setCursor(pit, pos, false);
196                 return true;
197         }
198         return false;
199 }
200
201
202 void LyXText::gotoInset(vector<Inset::Code> const & codes,
203                         bool same_content)
204 {
205         bv()->beforeChange(this);
206         update();
207
208         string contents;
209         if (same_content && cursor.pos() < cursor.par()->size()
210             && cursor.par()->isInset(cursor.pos())) {
211                 Inset const * inset = cursor.par()->getInset(cursor.pos());
212                 if (find(codes.begin(), codes.end(), inset->lyxCode())
213                     != codes.end())
214                         contents = static_cast<InsetCommand const *>(inset)->getContents();
215         }
216
217         if (!gotoNextInset(codes, contents)) {
218                 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
219                         LyXCursor tmp = cursor;
220                         cursor.par(ownerParagraphs().begin());
221                         cursor.pos(0);
222                         if (!gotoNextInset(codes, contents)) {
223                                 cursor = tmp;
224                                 bv()->owner()->message(_("No more insets"));
225                         }
226                 } else {
227                         bv()->owner()->message(_("No more insets"));
228                 }
229         }
230         update();
231         selection.cursor = cursor;
232 }
233
234
235 void LyXText::gotoInset(Inset::Code code, bool same_content)
236 {
237         gotoInset(vector<Inset::Code>(1, code), same_content);
238 }
239
240
241 void LyXText::cursorPrevious()
242 {
243         int y = top_y();
244
245         if (cursor.row() == rows().begin()) {
246                 if (y > 0) {
247                         int new_y = bv()->text->top_y() - bv()->workHeight();
248                         bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
249                         bv()->updateScrollbar();
250                 }
251                 return;
252         }
253
254         RowList::iterator cursorrow = cursor.row();
255
256         setCursorFromCoordinates(cursor.x_fix(), y);
257         finishUndo();
258
259         int new_y;
260         if (cursorrow == bv()->text->cursor.row()) {
261                 // we have a row which is taller than the workarea. The
262                 // simplest solution is to move to the previous row instead.
263                 cursorUp(true);
264                 return;
265                 // This is what we used to do, so we wouldn't skip right past
266                 // tall rows, but it's not working right now.
267 #if 0
268                 new_y = bv->text->top_y() - bv->workHeight();
269 #endif
270         } else {
271                 if (inset_owner) {
272                         new_y = bv()->text->cursor.iy()
273                                 + bv()->theLockingInset()->insetInInsetY() + y
274                                 + cursor.row()->height()
275                                 - bv()->workHeight() + 1;
276                 } else {
277                         new_y = cursor.y()
278                                 - cursor.row()->baseline()
279                                 + cursor.row()->height()
280                                 - bv()->workHeight() + 1;
281                 }
282         }
283         bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
284         if (cursor.row() != rows().begin()) {
285                 LyXCursor cur;
286                 setCursor(cur, boost::prior(cursor.row())->par(),
287                           boost::prior(cursor.row())->pos(), false);
288                 if (cur.y() > top_y()) {
289                         cursorUp(true);
290                 }
291         }
292         bv()->updateScrollbar();
293 }
294
295
296 void LyXText::cursorNext()
297 {
298         int topy = top_y();
299
300         if (boost::next(cursor.row()) == rows().end()) {
301                 int y = cursor.y() - cursor.row()->baseline() +
302                         cursor.row()->height();
303                 if (y > topy + bv()->workHeight()) {
304                         bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
305                         bv()->updateScrollbar();
306                 }
307                 return;
308         }
309
310         int y = topy + bv()->workHeight();
311         if (inset_owner && !topy) {
312                 y -= (bv()->text->cursor.iy()
313                           - bv()->text->top_y()
314                           + bv()->theLockingInset()->insetInInsetY());
315         }
316
317         getRowNearY(y);
318
319         RowList::iterator cursorrow = cursor.row();
320         setCursorFromCoordinates(cursor.x_fix(), y);
321         // + bv->workHeight());
322         finishUndo();
323
324         int new_y;
325         if (cursorrow == bv()->text->cursor.row()) {
326                 // we have a row which is taller than the workarea. The
327                 // simplest solution is to move to the next row instead.
328                 cursorDown(true);
329                 return;
330                 // This is what we used to do, so we wouldn't skip right past
331                 // tall rows, but it's not working right now.
332 #if 0
333                 new_y = bv->text->top_y() + bv->workHeight();
334 #endif
335         } else {
336                 if (inset_owner) {
337                         new_y = bv()->text->cursor.iy()
338                                 + bv()->theLockingInset()->insetInInsetY()
339                                 + y - cursor.row()->baseline();
340                 } else {
341                         new_y =  cursor.y() - cursor.row()->baseline();
342                 }
343         }
344         bv()->screen().draw(bv()->text, bv(), new_y);
345         if (boost::next(cursor.row()) != rows().end()) {
346                 LyXCursor cur;
347                 setCursor(cur, boost::next(cursor.row())->par(),
348                           boost::next(cursor.row())->pos(), false);
349                 if (cur.y() < top_y() + bv()->workHeight()) {
350                         cursorDown(true);
351                 }
352         }
353         bv()->updateScrollbar();
354 }
355
356
357 void LyXText::update()
358 {
359         bv()->update(this, BufferView::SELECT);
360 }
361
362 namespace {
363
364 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
365 {
366         lt->update();
367         InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
368         if (!bv->insertInset(new_inset))
369                 delete new_inset;
370         else
371                 bv->updateInset(new_inset);
372 }
373
374
375 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
376                    bool edit, bool pastesel)
377 {
378         Inset * inset = createInset(cmd);
379         BufferView * bv = cmd.view();
380
381         if (inset) {
382                 bool gotsel = false;
383                 if (lt->selection.set()) {
384                         lt->cutSelection(true, false);
385                         gotsel = true;
386                 }
387                 if (bv->insertInset(inset)) {
388                         if (edit)
389                                 inset->edit(bv);
390                         if (gotsel && pastesel)
391                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
392                 }
393                 else
394                         delete inset;
395         }
396 }
397
398 }
399
400 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
401 {
402         lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
403                               <<"] arg[" << cmd.argument << ']' << endl;
404
405         BufferView * bv = cmd.view();
406
407         switch (cmd.action) {
408
409         case LFUN_APPENDIX: {
410                 ParagraphList::iterator pit = cursor.par();
411                 bool start = !pit->params().startOfAppendix();
412
413                 // ensure that we have only one start_of_appendix in this document
414                 ParagraphList::iterator tmp = ownerParagraphs().begin();
415                 ParagraphList::iterator end = ownerParagraphs().end();
416
417                 for (; tmp != end; ++tmp) {
418                         if (tmp->params().startOfAppendix()) {
419                                 setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
420                                 tmp->params().startOfAppendix(false);
421                                 int tmpy;
422                                 setHeightOfRow(getRow(tmp, 0, tmpy));
423                                 break;
424                         }
425                 }
426
427                 setUndo(bv, Undo::EDIT, pit, boost::next(pit));
428                 pit->params().startOfAppendix(start);
429
430                 // we can set the refreshing parameters now
431                 updateCounters();
432                 redoHeightOfParagraph();
433                 postPaint(0);
434                 setCursor(cursor.par(), cursor.pos());
435                 update();
436                 break;
437         }
438
439         case LFUN_DELETE_WORD_FORWARD:
440                 bv->beforeChange(this);
441                 update();
442                 deleteWordForward();
443                 update();
444                 finishChange(bv);
445                 break;
446
447         case LFUN_DELETE_WORD_BACKWARD:
448                 bv->beforeChange(this);
449                 update();
450                 deleteWordBackward();
451                 update();
452                 finishChange(bv);
453                 break;
454
455         case LFUN_DELETE_LINE_FORWARD:
456                 bv->beforeChange(this);
457                 update();
458                 deleteLineForward();
459                 update();
460                 finishChange(bv);
461                 break;
462
463         case LFUN_WORDRIGHT:
464                 if (!selection.mark())
465                         bv->beforeChange(this);
466                 update();
467                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
468                         cursorLeftOneWord();
469                 else
470                         cursorRightOneWord();
471                 finishChange(bv);
472                 break;
473
474         case LFUN_WORDLEFT:
475                 if (!selection.mark())
476                         bv->beforeChange(this);
477                 update();
478                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
479                         cursorRightOneWord();
480                 else
481                         cursorLeftOneWord();
482                 finishChange(bv);
483                 break;
484
485         case LFUN_BEGINNINGBUF:
486                 if (!selection.mark())
487                         bv->beforeChange(this);
488                 update();
489                 cursorTop();
490                 finishChange(bv);
491                 break;
492
493         case LFUN_ENDBUF:
494                 if (selection.mark())
495                         bv->beforeChange(this);
496                 update();
497                 cursorBottom();
498                 finishChange(bv);
499                 break;
500
501         case LFUN_RIGHTSEL:
502                 update();
503                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
504                         cursorLeft(bv);
505                 else
506                         cursorRight(bv);
507                 finishChange(bv, true);
508                 break;
509
510         case LFUN_LEFTSEL:
511                 update();
512                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
513                         cursorRight(bv);
514                 else
515                         cursorLeft(bv);
516                 finishChange(bv, true);
517                 break;
518
519         case LFUN_UPSEL:
520                 update();
521                 cursorUp(true);
522                 finishChange(bv, true);
523                 break;
524
525         case LFUN_DOWNSEL:
526                 update();
527                 cursorDown(true);
528                 finishChange(bv, true);
529                 break;
530
531         case LFUN_UP_PARAGRAPHSEL:
532                 update();
533                 cursorUpParagraph();
534                 finishChange(bv, true);
535                 break;
536
537         case LFUN_DOWN_PARAGRAPHSEL:
538                 update();
539                 cursorDownParagraph();
540                 finishChange(bv, true);
541                 break;
542
543         case LFUN_PRIORSEL:
544                 update();
545                 cursorPrevious();
546                 finishChange(bv, true);
547                 break;
548
549         case LFUN_NEXTSEL:
550                 update();
551                 cursorNext();
552                 finishChange(bv, true);
553                 break;
554
555         case LFUN_HOMESEL:
556                 update();
557                 cursorHome();
558                 finishChange(bv, true);
559                 break;
560
561         case LFUN_ENDSEL:
562                 update();
563                 cursorEnd();
564                 finishChange(bv, true);
565                 break;
566
567         case LFUN_WORDRIGHTSEL:
568                 update();
569                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
570                         cursorLeftOneWord();
571                 else
572                         cursorRightOneWord();
573                 finishChange(bv, true);
574                 break;
575
576         case LFUN_WORDLEFTSEL:
577                 update();
578                 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
579                         cursorRightOneWord();
580                 else
581                         cursorLeftOneWord();
582                 finishChange(bv, true);
583                 break;
584
585         case LFUN_WORDSEL: {
586                 update();
587                 LyXCursor cur1;
588                 LyXCursor cur2;
589                 getWord(cur1, cur2, WHOLE_WORD);
590                 setCursor(cur1.par(), cur1.pos());
591                 bv->beforeChange(this);
592                 setCursor(cur2.par(), cur2.pos());
593                 finishChange(bv, true);
594                 break;
595         }
596
597         case LFUN_RIGHT: {
598                 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
599                 if (!selection.mark())
600                         bv->beforeChange(this);
601                 update();
602                 if (is_rtl)
603                         cursorLeft(false);
604                 if (cursor.pos() < cursor.par()->size()
605                     && cursor.par()->isInset(cursor.pos())
606                     && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
607                         Inset * tmpinset = cursor.par()->getInset(cursor.pos());
608                         cmd.message(tmpinset->editMessage());
609                         tmpinset->edit(bv, !is_rtl);
610                         break;
611                 }
612                 if (!is_rtl)
613                         cursorRight(false);
614                 finishChange(bv);
615                 break;
616         }
617
618         case LFUN_LEFT: {
619                 // This is soooo ugly. Isn`t it possible to make
620                 // it simpler? (Lgb)
621                 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
622                 if (!selection.mark())
623                         bv->beforeChange(this);
624                 update();
625                 LyXCursor const cur = cursor;
626                 if (!is_rtl)
627                         cursorLeft(false);
628                 if ((is_rtl || cur != cursor) && // only if really moved!
629                     cursor.pos() < cursor.par()->size() &&
630                     cursor.par()->isInset(cursor.pos()) &&
631                     isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
632                         Inset * tmpinset = cursor.par()->getInset(cursor.pos());
633                         cmd.message(tmpinset->editMessage());
634                         tmpinset->edit(bv, is_rtl);
635                         break;
636                 }
637                 if (is_rtl)
638                         cursorRight(false);
639                 finishChange(bv);
640                 break;
641         }
642
643         case LFUN_UP:
644                 if (!selection.mark())
645                         bv->beforeChange(this);
646                 bv->update(this, BufferView::UPDATE);
647                 cursorUp(bv);
648                 finishChange(bv);
649                 break;
650
651         case LFUN_DOWN:
652                 if (!selection.mark())
653                         bv->beforeChange(this);
654                 bv->update(this, BufferView::UPDATE);
655                 cursorDown(bv);
656                 finishChange(bv);
657                 break;
658
659         case LFUN_UP_PARAGRAPH:
660                 if (!selection.mark())
661                         bv->beforeChange(this);
662                 bv->update(this, BufferView::UPDATE);
663                 cursorUpParagraph();
664                 finishChange(bv);
665                 break;
666
667         case LFUN_DOWN_PARAGRAPH:
668                 if (!selection.mark())
669                         bv->beforeChange(this);
670                 bv->update(this, BufferView::UPDATE);
671                 cursorDownParagraph();
672                 finishChange(bv, false);
673                 break;
674
675         case LFUN_PRIOR:
676                 if (!selection.mark())
677                         bv->beforeChange(this);
678                 bv->update(this, BufferView::UPDATE);
679                 cursorPrevious();
680                 finishChange(bv, false);
681                 // was:
682                 // finishUndo();
683                 // moveCursorUpdate(bv, false, false);
684                 // owner_->view_state_changed();
685                 break;
686
687         case LFUN_NEXT:
688                 if (!selection.mark())
689                         bv->beforeChange(this);
690                 bv->update(this, BufferView::UPDATE);
691                 cursorNext();
692                 finishChange(bv, false);
693                 break;
694
695         case LFUN_HOME:
696                 if (!selection.mark())
697                         bv->beforeChange(this);
698                 update();
699                 cursorHome();
700                 finishChange(bv, false);
701                 break;
702
703         case LFUN_END:
704                 if (!selection.mark())
705                         bv->beforeChange(this);
706                 update();
707                 cursorEnd();
708                 finishChange(bv, false);
709                 break;
710
711         case LFUN_BREAKLINE: {
712                 lyx::pos_type body = cursor.par()->beginningOfBody();
713
714                 // Not allowed by LaTeX (labels or empty par)
715                 if (cursor.pos() <= body)
716                         break;
717
718                 bv->beforeChange(this);
719                 insertInset(new InsetNewline);
720                 update();
721                 setCursor(cursor.par(), cursor.pos());
722                 moveCursorUpdate(bv, false);
723                 break;
724         }
725
726         case LFUN_DELETE:
727                 if (!selection.set()) {
728                         Delete();
729                         selection.cursor = cursor;
730                         update();
731                         // It is possible to make it a lot faster still
732                         // just comment out the line below...
733                 } else {
734                         update();
735                         cutSelection(bv, true);
736                         update();
737                 }
738                 moveCursorUpdate(bv, false);
739                 bv->owner()->view_state_changed();
740                 bv->switchKeyMap();
741                 break;
742
743         case LFUN_DELETE_SKIP:
744                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
745                 if (!selection.set()) {
746                         LyXCursor cur = cursor;
747                         if (cur.pos() == cur.par()->size()) {
748                                 cursorRight(bv);
749                                 cur = cursor;
750                                 if (cur.pos() == 0
751                                     && !(cur.par()->params().spaceTop()
752                                          == VSpace (VSpace::NONE))) {
753                                         setParagraph(
754                                                  cur.par()->params().lineTop(),
755                                                  cur.par()->params().lineBottom(),
756                                                  cur.par()->params().pagebreakTop(),
757                                                  cur.par()->params().pagebreakBottom(),
758                                                  VSpace(VSpace::NONE),
759                                                  cur.par()->params().spaceBottom(),
760                                                  cur.par()->params().spacing(),
761                                                  cur.par()->params().align(),
762                                                  cur.par()->params().labelWidthString(), 0);
763                                         cursorLeft(bv);
764                                         update();
765                                 } else {
766                                         cursorLeft(bv);
767                                         Delete();
768                                         selection.cursor = cursor;
769                                 }
770                         } else {
771                                 Delete();
772                                 selection.cursor = cursor;
773                         }
774                 } else {
775                         update();
776                         cutSelection(bv, true);
777                 }
778                 update();
779                 break;
780
781
782         case LFUN_BACKSPACE:
783                 if (!selection.set()) {
784                         if (bv->owner()->getIntl().getTransManager().backspace()) {
785                                 backspace();
786                                 selection.cursor = cursor;
787                                 update();
788                                 // It is possible to make it a lot faster still
789                                 // just comment out the line below...
790                         }
791                 } else {
792                         update();
793                         cutSelection(bv, true);
794                         update();
795                 }
796                 bv->owner()->view_state_changed();
797                 bv->switchKeyMap();
798                 break;
799
800         case LFUN_BACKSPACE_SKIP:
801                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
802                 if (!selection.set()) {
803                         LyXCursor cur = cursor;
804                         if (cur.pos() == 0
805                             && !(cur.par()->params().spaceTop()
806                                  == VSpace (VSpace::NONE))) {
807                                 setParagraph(
808                                          cur.par()->params().lineTop(),
809                                          cur.par()->params().lineBottom(),
810                                          cur.par()->params().pagebreakTop(),
811                                          cur.par()->params().pagebreakBottom(),
812                                          VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
813                                          cur.par()->params().spacing(),
814                                          cur.par()->params().align(),
815                                          cur.par()->params().labelWidthString(), 0);
816                         } else {
817                                 backspace();
818                                 selection.cursor = cur;
819                         }
820                 } else {
821                         update();
822                         cutSelection(bv, true);
823                 }
824                 update();
825                 break;
826
827         case LFUN_BREAKPARAGRAPH:
828                 bv->beforeChange(this);
829                 breakParagraph(bv->buffer()->paragraphs, 0);
830                 update();
831                 selection.cursor = cursor;
832                 bv->switchKeyMap();
833                 bv->owner()->view_state_changed();
834                 break;
835
836         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
837                 bv->beforeChange(this);
838                 breakParagraph(bv->buffer()->paragraphs, 1);
839                 update();
840                 selection.cursor = cursor;
841                 bv->switchKeyMap();
842                 bv->owner()->view_state_changed();
843                 break;
844
845         case LFUN_BREAKPARAGRAPH_SKIP: {
846                 // When at the beginning of a paragraph, remove
847                 // indentation and add a "defskip" at the top.
848                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
849                 LyXCursor cur = cursor;
850                 bv->beforeChange(this);
851                 if (cur.pos() == 0) {
852                         if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
853                                 setParagraph(
854                                          cur.par()->params().lineTop(),
855                                          cur.par()->params().lineBottom(),
856                                          cur.par()->params().pagebreakTop(),
857                                          cur.par()->params().pagebreakBottom(),
858                                          VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
859                                          cur.par()->params().spacing(),
860                                          cur.par()->params().align(),
861                                          cur.par()->params().labelWidthString(), 1);
862                         }
863                 }
864                 else {
865                         breakParagraph(bv->buffer()->paragraphs, 0);
866                 }
867                 update();
868                 selection.cursor = cur;
869                 bv->switchKeyMap();
870                 bv->owner()->view_state_changed();
871                 break;
872         }
873
874         case LFUN_PARAGRAPH_SPACING: {
875                 ParagraphList::iterator pit = cursor.par();
876                 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
877                 float cur_value = 1.0;
878                 if (cur_spacing == Spacing::Other)
879                         cur_value = pit->params().spacing().getValue();
880
881                 istringstream is(STRCONV(cmd.argument));
882                 string tmp;
883                 is >> tmp;
884                 Spacing::Space new_spacing = cur_spacing;
885                 float new_value = cur_value;
886                 if (tmp.empty()) {
887                         lyxerr << "Missing argument to `paragraph-spacing'"
888                                << endl;
889                 } else if (tmp == "single") {
890                         new_spacing = Spacing::Single;
891                 } else if (tmp == "onehalf") {
892                         new_spacing = Spacing::Onehalf;
893                 } else if (tmp == "double") {
894                         new_spacing = Spacing::Double;
895                 } else if (tmp == "other") {
896                         new_spacing = Spacing::Other;
897                         float tmpval = 0.0;
898                         is >> tmpval;
899                         lyxerr << "new_value = " << tmpval << endl;
900                         if (tmpval != 0.0)
901                                 new_value = tmpval;
902                 } else if (tmp == "default") {
903                         new_spacing = Spacing::Default;
904                 } else {
905                         lyxerr << _("Unknown spacing argument: ")
906                                << cmd.argument << endl;
907                 }
908                 if (cur_spacing != new_spacing || cur_value != new_value) {
909                         pit->params().spacing(Spacing(new_spacing, new_value));
910                         redoParagraph();
911                         update();
912                 }
913                 break;
914         }
915
916         case LFUN_INSET_SETTINGS:
917                 lyx::Assert(bv->theLockingInset());
918                 bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
919                 break;
920
921         case LFUN_INSET_TOGGLE:
922                 bv->beforeChange(this);
923                 update();
924                 toggleInset();
925                 update();
926                 bv->switchKeyMap();
927                 break;
928
929         case LFUN_PROTECTEDSPACE:
930                 if (cursor.par()->layout()->free_spacing) {
931                         insertChar(' ');
932                         update();
933                 } else {
934                         specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
935                 }
936                 moveCursorUpdate(bv, false);
937                 break;
938
939         case LFUN_HYPHENATION:
940                 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
941                 break;
942
943         case LFUN_LIGATURE_BREAK:
944                 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
945                 break;
946
947         case LFUN_LDOTS:
948                 specialChar(this, bv, InsetSpecialChar::LDOTS);
949                 break;
950
951         case LFUN_END_OF_SENTENCE:
952                 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
953                 break;
954
955         case LFUN_MENU_SEPARATOR:
956                 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
957                 break;
958
959         case LFUN_MARK_OFF:
960                 bv->beforeChange(this);
961                 update();
962                 selection.cursor = cursor;
963                 cmd.message(N_("Mark off"));
964                 break;
965
966         case LFUN_MARK_ON:
967                 bv->beforeChange(this);
968                 selection.mark(true);
969                 update();
970                 selection.cursor = cursor;
971                 cmd.message(N_("Mark on"));
972                 break;
973
974         case LFUN_SETMARK:
975                 bv->beforeChange(this);
976                 if (selection.mark()) {
977                         update();
978                         cmd.message(N_("Mark removed"));
979                 } else {
980                         selection.mark(true);
981                         update();
982                         cmd.message(N_("Mark set"));
983                 }
984                 selection.cursor = cursor;
985                 break;
986
987         case LFUN_UPCASE_WORD:
988                 update();
989                 changeCase(LyXText::text_uppercase);
990                 if (inset_owner)
991                         bv->updateInset(inset_owner);
992                 update();
993                 break;
994
995         case LFUN_LOWCASE_WORD:
996                 update();
997                 changeCase(LyXText::text_lowercase);
998                 if (inset_owner)
999                         bv->updateInset(inset_owner);
1000                 update();
1001                 break;
1002
1003         case LFUN_CAPITALIZE_WORD:
1004                 update();
1005                 changeCase(LyXText::text_capitalization);
1006                 if (inset_owner)
1007                         bv->updateInset(inset_owner);
1008                 update();
1009                 break;
1010
1011         case LFUN_TRANSPOSE_CHARS:
1012                 update();
1013                 transposeChars(*this, cursor);
1014                 if (inset_owner)
1015                         bv->updateInset(inset_owner);
1016                 update();
1017                 break;
1018
1019         case LFUN_PASTE:
1020                 cmd.message(_("Paste"));
1021                 // clear the selection
1022                 bv->toggleSelection();
1023                 clearSelection();
1024                 update();
1025                 pasteSelection();
1026                 clearSelection(); // bug 393
1027                 update();
1028                 bv->switchKeyMap();
1029                 break;
1030
1031         case LFUN_CUT:
1032                 update();
1033                 cutSelection(bv, true);
1034                 update();
1035                 cmd.message(_("Cut"));
1036                 break;
1037
1038         case LFUN_COPY:
1039                 copySelection();
1040                 cmd.message(_("Copy"));
1041                 break;
1042
1043         case LFUN_BEGINNINGBUFSEL:
1044                 if (inset_owner)
1045                         return UNDISPATCHED;
1046                 update();
1047                 cursorTop();
1048                 finishChange(bv, true);
1049                 break;
1050
1051         case LFUN_ENDBUFSEL:
1052                 if (inset_owner)
1053                         return UNDISPATCHED;
1054                 update();
1055                 cursorBottom();
1056                 finishChange(bv, true);
1057                 break;
1058
1059         case LFUN_GETXY:
1060                 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1061                 break;
1062
1063         case LFUN_SETXY: {
1064                 int x = 0;
1065                 int y = 0;
1066                 istringstream is(STRCONV(cmd.argument));
1067                 is >> x >> y;
1068                 if (!is)
1069                         lyxerr << "SETXY: Could not parse coordinates in '"
1070                                << cmd.argument << std::endl;
1071                 else
1072                         setCursorFromCoordinates(x, y);
1073                 break;
1074         }
1075
1076         case LFUN_GETFONT:
1077                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1078                         cmd.message("E");
1079                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1080                         cmd.message("N");
1081                 else
1082                         cmd.message("0");
1083                 break;
1084
1085         case LFUN_GETLAYOUT:
1086                 cmd.message(tostr(cursor.par()->layout()));
1087                 break;
1088
1089         case LFUN_LAYOUT: {
1090                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1091                   << cmd.argument << endl;
1092
1093                 // This is not the good solution to the empty argument
1094                 // problem, but it will hopefully suffice for 1.2.0.
1095                 // The correct solution would be to augument the
1096                 // function list/array with information about what
1097                 // functions needs arguments and their type.
1098                 if (cmd.argument.empty()) {
1099                         cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1100                         break;
1101                 }
1102
1103                 // Derive layout number from given argument (string)
1104                 // and current buffer's textclass (number)
1105                 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
1106                 bool hasLayout = tclass.hasLayout(cmd.argument);
1107                 string layout = cmd.argument;
1108
1109                 // If the entry is obsolete, use the new one instead.
1110                 if (hasLayout) {
1111                         string const & obs = tclass[layout]->obsoleted_by();
1112                         if (!obs.empty())
1113                                 layout = obs;
1114                 }
1115
1116                 if (!hasLayout) {
1117                         cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1118                                 N_(" not known"));
1119                         break;
1120                 }
1121
1122                 bool change_layout = (current_layout != layout);
1123                 if (!change_layout && selection.set() &&
1124                         selection.start.par() != selection.end.par())
1125                 {
1126                         ParagraphList::iterator spit = selection.start.par();
1127                         ParagraphList::iterator epit = boost::next(selection.end.par());
1128                         while (spit != epit) {
1129                                 if (spit->layout()->name() != current_layout) {
1130                                         change_layout = true;
1131                                         break;
1132                                 }
1133                                 ++spit;
1134                         }
1135                 }
1136                 if (change_layout) {
1137                         current_layout = layout;
1138                         update();
1139                         setLayout(layout);
1140                         bv->owner()->setLayout(layout);
1141                         update();
1142                         bv->switchKeyMap();
1143                 }
1144                 break;
1145         }
1146
1147         case LFUN_PASTESELECTION: {
1148                 if (!bv->buffer())
1149                         break;
1150                 // this was originally a beforeChange(bv->text), i.e
1151                 // the outermost LyXText!
1152                 bv->beforeChange(this);
1153                 string const clip = bv->getClipboard();
1154                 if (!clip.empty()) {
1155                         if (cmd.argument == "paragraph")
1156                                 insertStringAsParagraphs(clip);
1157                         else
1158                                 insertStringAsLines(clip);
1159                         clearSelection();
1160                         update();
1161                 }
1162                 break;
1163         }
1164
1165         case LFUN_GOTOERROR:
1166                 gotoInset(Inset::ERROR_CODE, false);
1167                 break;
1168
1169         case LFUN_GOTONOTE:
1170                 gotoInset(Inset::NOTE_CODE, false);
1171                 break;
1172
1173         case LFUN_REFERENCE_GOTO:
1174         {
1175                 vector<Inset::Code> tmp;
1176                 tmp.push_back(Inset::LABEL_CODE);
1177                 tmp.push_back(Inset::REF_CODE);
1178                 gotoInset(tmp, true);
1179                 break;
1180         }
1181
1182         case LFUN_QUOTE: {
1183                 ParagraphList::iterator pit = cursor.par();
1184                 lyx::pos_type pos = cursor.pos();
1185                 char c;
1186                 if (!pos)
1187                         c = ' ';
1188                 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1189                         c = ' ';
1190                 else
1191                         c = pit->getChar(pos - 1);
1192
1193                 LyXLayout_ptr const & style = pit->layout();
1194
1195                 if (style->pass_thru ||
1196                                 pit->getFontSettings(bv->buffer()->params,
1197                                          pos).language()->lang() == "hebrew" ||
1198                         (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1199                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1200                 break;
1201         }
1202
1203         case LFUN_DATE_INSERT: {
1204                 time_t now_time_t = time(NULL);
1205                 struct tm * now_tm = localtime(&now_time_t);
1206                 setlocale(LC_TIME, "");
1207                 string arg;
1208                 if (!cmd.argument.empty())
1209                         arg = cmd.argument;
1210                 else
1211                         arg = lyxrc.date_insert_format;
1212                 char datetmp[32];
1213                 int const datetmp_len =
1214                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1215
1216                 for (int i = 0; i < datetmp_len; i++) {
1217                         insertChar(datetmp[i]);
1218                         update();
1219                 }
1220                 selection.cursor = cursor;
1221                 moveCursorUpdate(bv, false);
1222                 break;
1223         }
1224
1225         case LFUN_MOUSE_TRIPLE:
1226                 if (!bv->buffer())
1227                         break;
1228                 if (!isInInset() && bv->theLockingInset())
1229                         break;
1230                 if (cmd.button() == mouse_button::button1) {
1231                         if (!isInInset()) {
1232                                 bv->screen().toggleSelection(this, bv);
1233                         }
1234                         cursorHome();
1235                         selection.cursor = cursor;
1236                         cursorEnd();
1237                         setSelection();
1238                         if (!isInInset())
1239                                 bv->screen().toggleSelection(this, bv, false);
1240                         update();
1241                         bv->haveSelection(selection.set());
1242                 }
1243                 break;
1244
1245         case LFUN_MOUSE_DOUBLE:
1246                 if (!bv->buffer())
1247                         break;
1248                 if (!isInInset() && bv->theLockingInset())
1249                         break;
1250                 if (cmd.button() == mouse_button::button1) {
1251                         if (!isInInset()) {
1252                                 bv->screen().toggleSelection(this, bv);
1253                                 selectWord(LyXText::WHOLE_WORD_STRICT);
1254                                 bv->screen().toggleSelection(this, bv, false);
1255                         } else {
1256                                 selectWord(LyXText::WHOLE_WORD_STRICT);
1257                         }
1258                         update();
1259                         bv->haveSelection(selection.set());
1260                 }
1261                 break;
1262
1263         case LFUN_MOUSE_MOTION:
1264         {
1265                 // Only use motion with button 1
1266                 //if (ev.button() != mouse_button::button1)
1267                 //      return false;
1268
1269                 if (!bv->buffer())
1270                         break;
1271
1272                 // Check for inset locking
1273                 if (bv->theLockingInset()) {
1274                         Inset * tli = bv->theLockingInset();
1275                         LyXCursor cursor = bv->text->cursor;
1276                         LyXFont font = bv->text->getFont(bv->buffer(),
1277                                                          cursor.par(), cursor.pos());
1278                         int width = tli->width(bv, font);
1279                         int inset_x = font.isVisibleRightToLeft()
1280                                 ? cursor.ix() - width : cursor.ix();
1281                         int start_x = inset_x + tli->scroll();
1282                         FuncRequest cmd1 = cmd;
1283                         cmd1.x = cmd.x - start_x;
1284                         cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
1285                         tli->localDispatch(cmd1);
1286                         break;
1287                 }
1288
1289                 // The test for not selection possible is needed, that only motion
1290                 // events are used, where the bottom press event was on
1291                 //  the drawing area too
1292                 if (!selection_possible) {
1293                         lyxerr[Debug::ACTION]
1294                                 << "BufferView::Pimpl::Dispatch: no selection possible\n";
1295                         break;
1296                 }
1297
1298                 RowList::iterator cursorrow = bv->text->cursor.row();
1299                 bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
1300         #if 0
1301                 // sorry for this but I have a strange error that the y value jumps at
1302                 // a certain point. This seems like an error in my xforms library or
1303                 // in some other local environment, but I would like to leave this here
1304                 // for the moment until I can remove this (Jug 20020418)
1305                 if (y_before < bv->text->cursor.y())
1306                         lyxerr << y_before << ':'
1307                                << bv->text->cursor.y() << endl;
1308         #endif
1309                 // This is to allow jumping over large insets
1310                 if (cursorrow == bv->text->cursor.row()) {
1311                         if (cmd.y >= bv->workHeight())
1312                                 bv->text->cursorDown(false);
1313                         else if (cmd.y < 0)
1314                                 bv->text->cursorUp(false);
1315                 }
1316
1317                 // Maybe an empty line was deleted
1318                 if (!bv->text->selection.set())
1319                         bv->update(BufferView::UPDATE);
1320                 bv->text->setSelection();
1321                 bv->screen().toggleToggle(bv->text, bv);
1322                 bv->fitCursor();
1323                 break;
1324         }
1325
1326         // Single-click on work area
1327         case LFUN_MOUSE_PRESS:
1328         {
1329                 if (!bv->buffer())
1330                         break;
1331
1332                 // ok ok, this is a hack (for xforms)
1333                 // We shouldn't go further down as we really should only do the
1334                 // scrolling and be done with this. Otherwise we may open some
1335                 // dialogs (Jug 20020424).
1336                 if (cmd.button() == mouse_button::button4) {
1337                         bv->scroll(-lyxrc.wheel_jump);
1338                         break;
1339                 }
1340                 if (cmd.button() == mouse_button::button5) {
1341                         bv->scroll(lyxrc.wheel_jump);
1342                         break;
1343                 }
1344
1345                 int x = cmd.x;
1346                 int y = cmd.y;
1347                 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1348
1349                 // Middle button press pastes if we have a selection
1350                 // We do this here as if the selection was inside an inset
1351                 // it could get cleared on the unlocking of the inset so
1352                 // we have to check this first
1353                 bool paste_internally = false;
1354                 if (cmd.button() == mouse_button::button2 && selection.set()) {
1355                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1356                         paste_internally = true;
1357                 }
1358
1359                 int const screen_first = bv->text->top_y();
1360
1361                 if (bv->theLockingInset()) {
1362                         // We are in inset locking mode
1363
1364                         // Check whether the inset was hit. If not reset mode,
1365                         // otherwise give the event to the inset
1366                         if (inset_hit == bv->theLockingInset()) {
1367                                 FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1368                                 bv->theLockingInset()->localDispatch(cmd1);
1369                                 break;
1370                         }
1371                         bv->unlockInset(bv->theLockingInset());
1372                 }
1373
1374                 if (!inset_hit)
1375                         selection_possible = true;
1376
1377                 // Clear the selection
1378                 bv->screen().toggleSelection(bv->text, bv);
1379                 bv->text->clearSelection();
1380                 bv->text->fullRebreak();
1381                 bv->update();
1382                 bv->updateScrollbar();
1383
1384                 // Single left click in math inset?
1385                 if (isHighlyEditableInset(inset_hit)) {
1386                         // Highly editable inset, like math
1387                         UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
1388                         selection_possible = false;
1389                         bv->owner()->message(inset->editMessage());
1390                         // We just have to lock the inset before calling a PressEvent on it!
1391                         if (!bv->lockInset(inset))
1392                                 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
1393                         FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
1394                         inset->localDispatch(cmd1);
1395                         break;
1396                 }
1397                 // I'm not sure we should continue here if we hit an inset (Jug20020403)
1398
1399                 // Right click on a footnote flag opens float menu
1400                 if (cmd.button() == mouse_button::button3) {
1401                         selection_possible = false;
1402                         break;
1403                 }
1404
1405                 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
1406                         bv->text->setCursorFromCoordinates(x, y + screen_first);
1407                 finishUndo();
1408                 bv->text->selection.cursor = bv->text->cursor;
1409                 bv->text->cursor.x_fix(bv->text->cursor.x());
1410
1411                 if (bv->fitCursor())
1412                         selection_possible = false;
1413
1414                 // Insert primary selection with middle mouse
1415                 // if there is a local selection in the current buffer,
1416                 // insert this
1417                 if (cmd.button() == mouse_button::button2) {
1418                         if (paste_internally)
1419                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1420                         else
1421                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1422                         selection_possible = false;
1423                 }
1424                 break;
1425         }
1426
1427         case LFUN_MOUSE_RELEASE:
1428         {
1429                 // do nothing if we used the mouse wheel
1430                 if (!bv->buffer())
1431                         break;
1432
1433                 if (cmd.button() == mouse_button::button4
1434                  || cmd.button() == mouse_button::button5)
1435                         break;
1436
1437                 // If we hit an inset, we have the inset coordinates in these
1438                 // and inset_hit points to the inset.  If we do not hit an
1439                 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1440                 int x = cmd.x;
1441                 int y = cmd.y;
1442                 Inset * inset_hit = bv->text->checkInsetHit(x, y);
1443
1444                 if (bv->theLockingInset()) {
1445                         // We are in inset locking mode.
1446
1447                         // LyX does a kind of work-area grabbing for insets.
1448                         // Only a ButtonPress FuncRequest outside the inset will
1449                         // force a insetUnlock.
1450                         FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1451                         bv->theLockingInset()->localDispatch(cmd1);
1452                         break;
1453                 }
1454
1455                 selection_possible = false;
1456
1457                 if (cmd.button() == mouse_button::button2)
1458                         break;
1459
1460                 // finish selection
1461                 if (cmd.button() == mouse_button::button1)
1462                         bv->haveSelection(selection.set());
1463
1464                 bv->switchKeyMap();
1465                 bv->owner()->view_state_changed();
1466                 bv->owner()->updateMenubar();
1467                 bv->owner()->updateToolbar();
1468
1469                 // Did we hit an editable inset?
1470                 if (inset_hit) {
1471                         selection_possible = false;
1472
1473                         // if we reach this point with a selection, it
1474                         // must mean we are currently selecting.
1475                         // But we don't want to open the inset
1476                         // because that is annoying for the user.
1477                         // So just pretend we didn't hit it.
1478                         // this is OK because a "kosher" ButtonRelease
1479                         // will follow a ButtonPress that clears
1480                         // the selection.
1481                         // Note this also fixes selection drawing
1482                         // problems if we end up opening an inset
1483                         if (selection.set())
1484                                 break;
1485
1486                         // CHECK fix this proper in 0.13
1487                         // well, maybe 13.0 !!!!!!!!!
1488
1489                         // Following a ref shouldn't issue
1490                         // a push on the undo-stack
1491                         // anylonger, now that we have
1492                         // keybindings for following
1493                         // references and returning from
1494                         // references.  IMHO though, it
1495                         // should be the inset's own business
1496                         // to push or not push on the undo
1497                         // stack. They don't *have* to
1498                         // alter the document...
1499                         // (Joacim)
1500                         // ...or maybe the SetCursorParUndo()
1501                         // below isn't necessary at all anylonger?
1502                         if (inset_hit->lyxCode() == Inset::REF_CODE)
1503                                 setCursorParUndo(bv);
1504
1505                         bv->owner()->message(inset_hit->editMessage());
1506
1507                         FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
1508                         inset_hit->localDispatch(cmd1);
1509                 }
1510
1511                 break;
1512         }
1513
1514         case LFUN_SELFINSERT: {
1515                 if (cmd.argument.empty())
1516                         break;
1517
1518                 // Automatically delete the currently selected
1519                 // text and replace it with what is being
1520                 // typed in now. Depends on lyxrc settings
1521                 // "auto_region_delete", which defaults to
1522                 // true (on).
1523
1524                 if (lyxrc.auto_region_delete) {
1525                         if (selection.set()) {
1526                                 cutSelection(false, false);
1527                                 update();
1528                         }
1529                         bv->haveSelection(false);
1530                 }
1531
1532                 bv->beforeChange(this);
1533                 LyXFont const old_font(real_current_font);
1534
1535                 string::const_iterator cit = cmd.argument.begin();
1536                 string::const_iterator end = cmd.argument.end();
1537                 for (; cit != end; ++cit)
1538                         bv->owner()->getIntl().getTransManager().
1539                                 TranslateAndInsert(*cit, this);
1540
1541                 update();
1542                 selection.cursor = cursor;
1543                 moveCursorUpdate(bv, false);
1544
1545                 // real_current_font.number can change so we need to
1546                 // update the minibuffer
1547                 if (old_font != real_current_font)
1548                         bv->owner()->view_state_changed();
1549                 break;
1550         }
1551
1552         case LFUN_HTMLURL: {
1553                 InsetCommandParams p("htmlurl");
1554                 string const data = InsetCommandMailer::params2string("url", p);
1555                 bv->owner()->getDialogs().show("url", data, 0);
1556                 break;
1557         }
1558
1559         case LFUN_URL: {
1560                 InsetCommandParams p("url");
1561                 string const data = InsetCommandMailer::params2string("url", p);
1562                 bv->owner()->getDialogs().show("url", data, 0);
1563                 break;
1564         }
1565
1566
1567 #if 0
1568         case LFUN_INSET_LIST:
1569         case LFUN_INSET_THEOREM:
1570         case LFUN_INSET_CAPTION:
1571 #endif
1572         case LFUN_INSERT_NOTE:
1573         case LFUN_INSERT_BIBITEM:
1574         case LFUN_INSET_ERT:
1575         case LFUN_INSET_FLOAT:
1576         case LFUN_INSET_FOOTNOTE:
1577         case LFUN_INSET_MARGINAL:
1578         case LFUN_INSET_MINIPAGE:
1579         case LFUN_INSET_OPTARG:
1580         case LFUN_INSET_WIDE_FLOAT:
1581         case LFUN_INSET_WRAP:
1582         case LFUN_TABULAR_INSERT:
1583         case LFUN_ENVIRONMENT_INSERT:
1584                 // Open the inset, and move the current selection
1585                 // inside it.
1586                 doInsertInset(this, cmd, true, true);
1587                 break;
1588
1589         case LFUN_INDEX_INSERT:
1590                 // Just open the inset
1591                 doInsertInset(this, cmd, true, false);
1592                 break;
1593
1594         case LFUN_INDEX_PRINT:
1595         case LFUN_PARENTINSERT:
1596         case LFUN_TOC_INSERT:
1597         case LFUN_HFILL:
1598                 // do nothing fancy
1599                 doInsertInset(this, cmd, false, false);
1600                 break;
1601
1602         default:
1603                 return UNDISPATCHED;
1604         }
1605
1606         return DISPATCHED;
1607 }