]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.cpp
Don't be so cute with VSpace: We just output it inline now for
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
1 /**
2  * \file GuiWorkArea.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiWorkArea.h"
15 #include "GuiWorkArea_Private.h"
16
17 #include "ColorCache.h"
18 #include "FontLoader.h"
19 #include "Menus.h"
20
21 #include "Buffer.h"
22 #include "BufferList.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
25 #include "CoordCache.h"
26 #include "Cursor.h"
27 #include "Font.h"
28 #include "FuncRequest.h"
29 #include "GuiApplication.h"
30 #include "GuiCompleter.h"
31 #include "GuiKeySymbol.h"
32 #include "GuiPainter.h"
33 #include "GuiView.h"
34 #include "KeySymbol.h"
35 #include "Language.h"
36 #include "LyX.h"
37 #include "LyXRC.h"
38 #include "LyXVC.h"
39 #include "qt_helpers.h"
40 #include "Text.h"
41 #include "TextMetrics.h"
42 #include "version.h"
43
44 #include "graphics/GraphicsImage.h"
45 #include "graphics/GraphicsLoader.h"
46
47 #include "support/convert.h"
48 #include "support/debug.h"
49 #include "support/gettext.h"
50 #include "support/FileName.h"
51 #include "support/lassert.h"
52 #include "support/TempFile.h"
53
54 #include "frontends/Application.h"
55 #include "frontends/FontMetrics.h"
56 #include "frontends/WorkAreaManager.h"
57
58 #include <QContextMenuEvent>
59 #if (QT_VERSION < 0x050000)
60 #include <QInputContext>
61 #endif
62 #include <QDrag>
63 #include <QHelpEvent>
64 #ifdef Q_OS_MAC
65 #include <QProxyStyle>
66 #endif
67 #include <QMainWindow>
68 #include <QMimeData>
69 #include <QMenu>
70 #include <QPainter>
71 #include <QPalette>
72 #include <QPixmapCache>
73 #include <QScrollBar>
74 #include <QStyleOption>
75 #include <QStylePainter>
76 #include <QTimer>
77 #include <QToolButton>
78 #include <QToolTip>
79 #include <QMenuBar>
80
81 #include "support/bind.h"
82
83 #include <cmath>
84
85 int const TabIndicatorWidth = 3;
86
87 #undef KeyPress
88 #undef NoModifier
89
90 using namespace std;
91 using namespace lyx::support;
92
93 namespace lyx {
94
95
96 /// return the LyX mouse button state from Qt's
97 static mouse_button::state q_button_state(Qt::MouseButton button)
98 {
99         mouse_button::state b = mouse_button::none;
100         switch (button) {
101                 case Qt::LeftButton:
102                         b = mouse_button::button1;
103                         break;
104                 case Qt::MidButton:
105                         b = mouse_button::button2;
106                         break;
107                 case Qt::RightButton:
108                         b = mouse_button::button3;
109                         break;
110                 default:
111                         break;
112         }
113         return b;
114 }
115
116
117 /// return the LyX mouse button state from Qt's
118 mouse_button::state q_motion_state(Qt::MouseButtons state)
119 {
120         mouse_button::state b = mouse_button::none;
121         if (state & Qt::LeftButton)
122                 b |= mouse_button::button1;
123         if (state & Qt::MidButton)
124                 b |= mouse_button::button2;
125         if (state & Qt::RightButton)
126                 b |= mouse_button::button3;
127         return b;
128 }
129
130
131 namespace frontend {
132
133 class CursorWidget {
134 public:
135         CursorWidget() : rtl_(false), l_shape_(false), completable_(false),
136                 show_(false), x_(0), cursor_width_(0)
137         {
138                 recomputeWidth();
139         }
140
141         void draw(QPainter & painter)
142         {
143                 if (!show_ || !rect_.isValid())
144                         return;
145
146                 int y = rect_.top();
147                 int l = x_ - rect_.left();
148                 int r = rect_.right() - x_;
149                 int bot = rect_.bottom();
150
151                 // draw vertical line
152                 painter.fillRect(x_, y, cursor_width_, rect_.height(), color_);
153
154                 // draw RTL/LTR indication
155                 painter.setPen(color_);
156                 if (l_shape_) {
157                         if (rtl_)
158                                 painter.drawLine(x_, bot, x_ - l, bot);
159                         else
160                                 painter.drawLine(x_, bot, x_ + cursor_width_ + r, bot);
161                 }
162
163                 // draw completion triangle
164                 if (completable_) {
165                         int m = y + rect_.height() / 2;
166                         int d = TabIndicatorWidth - 1;
167                         if (rtl_) {
168                                 painter.drawLine(x_ - 1, m - d, x_ - 1 - d, m);
169                                 painter.drawLine(x_ - 1, m + d, x_ - 1 - d, m);
170                         } else {
171                                 painter.drawLine(x_ + cursor_width_, m - d, x_ + cursor_width_ + d, m);
172                                 painter.drawLine(x_ + cursor_width_, m + d, x_ + cursor_width_ + d, m);
173                         }
174                 }
175         }
176
177         void update(int x, int y, int h, bool l_shape,
178                 bool rtl, bool completable)
179         {
180                 color_ = guiApp->colorCache().get(Color_cursor);
181                 l_shape_ = l_shape;
182                 rtl_ = rtl;
183                 completable_ = completable;
184                 x_ = x;
185
186                 // extension to left and right
187                 int l = 0;
188                 int r = 0;
189
190                 // RTL/LTR indication
191                 if (l_shape_) {
192                         if (rtl)
193                                 l += h / 3;
194                         else
195                                 r += h / 3;
196                 }
197
198                 // completion triangle
199                 if (completable_) {
200                         if (rtl)
201                                 l = max(l, TabIndicatorWidth);
202                         else
203                                 r = max(r, TabIndicatorWidth);
204                 }
205
206                 // compute overall rectangle
207                 rect_ = QRect(x - l, y, cursor_width_ + r + l, h);
208         }
209
210         void show(bool set_show = true) { show_ = set_show; }
211         void hide() { show_ = false; }
212         int cursorWidth() const { return cursor_width_; }
213         void recomputeWidth() {
214                 cursor_width_ = lyxrc.cursor_width
215                         ? lyxrc.cursor_width 
216                         : 1 + int((lyxrc.zoom + 50) / 200.0);
217         }
218
219         QRect const & rect() { return rect_; }
220
221 private:
222         /// cursor is in RTL or LTR text
223         bool rtl_;
224         /// indication for RTL or LTR
225         bool l_shape_;
226         /// triangle to show that a completion is available
227         bool completable_;
228         ///
229         bool show_;
230         ///
231         QColor color_;
232         /// rectangle, possibly with l_shape and completion triangle
233         QRect rect_;
234         /// x position (were the vertical line is drawn)
235         int x_;
236         
237         int cursor_width_;
238 };
239
240
241 // This is a 'heartbeat' generating synthetic mouse move events when the
242 // cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
243 SyntheticMouseEvent::SyntheticMouseEvent()
244         : timeout(200), restart_timeout(true)
245 {}
246
247
248 GuiWorkArea::Private::Private(GuiWorkArea * parent)
249 : p(parent), screen_(0), buffer_view_(0), read_only_(false), lyx_view_(0),
250 cursor_visible_(false), cursor_(0),
251 need_resize_(false), schedule_redraw_(false), preedit_lines_(1),
252 pixel_ratio_(1.0),
253 completer_(new GuiCompleter(p, p)), dialog_mode_(false)
254 {
255 }
256
257
258 GuiWorkArea::GuiWorkArea(QWidget * /* w */)
259 : d(new Private(this)) 
260 {
261 }
262
263
264 GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
265 : d(new Private(this))
266 {
267         setGuiView(gv);
268         buffer.params().display_pixel_ratio = theGuiApp()->pixelRatio();
269         setBuffer(buffer);
270         init();
271 }
272
273
274 double GuiWorkArea::pixelRatio() const
275 {
276 #if QT_VERSION >= 0x050000
277         return devicePixelRatio();
278 #else
279         return 1.0;
280 #endif
281 }
282
283
284 void GuiWorkArea::init()
285 {
286         // Setup the signals
287         connect(&d->cursor_timeout_, SIGNAL(timeout()),
288                 this, SLOT(toggleCursor()));
289
290         int const time = QApplication::cursorFlashTime() / 2;
291         if (time > 0) {
292                 d->cursor_timeout_.setInterval(time);
293                 d->cursor_timeout_.start();
294         } else {
295                 // let's initialize this just to be safe
296                 d->cursor_timeout_.setInterval(500);
297         }
298
299         d->resetScreen();
300         // With Qt4.5 a mouse event will happen before the first paint event
301         // so make sure that the buffer view has an up to date metrics.
302         d->buffer_view_->resize(viewport()->width(), viewport()->height());
303         d->cursor_ = new frontend::CursorWidget();
304         d->cursor_->hide();
305
306         setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
307         setAcceptDrops(true);
308         setMouseTracking(true);
309         setMinimumSize(100, 70);
310         setFrameStyle(QFrame::NoFrame);
311         updateWindowTitle();
312
313         viewport()->setAutoFillBackground(false);
314         // We don't need double-buffering nor SystemBackground on
315         // the viewport because we have our own backing pixmap.
316         viewport()->setAttribute(Qt::WA_NoSystemBackground);
317
318         setFocusPolicy(Qt::StrongFocus);
319
320         d->setCursorShape(Qt::IBeamCursor);
321
322         d->synthetic_mouse_event_.timeout.timeout.connect(
323                 bind(&GuiWorkArea::generateSyntheticMouseEvent,
324                                         this));
325
326         // Initialize the vertical Scroll Bar
327         QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
328                 this, SLOT(scrollTo(int)));
329
330         LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
331                 << "  viewport height: " << viewport()->height());
332
333         // Enables input methods for asian languages.
334         // Must be set when creating custom text editing widgets.
335         setAttribute(Qt::WA_InputMethodEnabled, true);
336
337         d->dialog_mode_ = false;
338 }
339
340
341 GuiWorkArea::~GuiWorkArea()
342 {
343         d->buffer_view_->buffer().workAreaManager().remove(this);
344         delete d->screen_;
345         delete d->buffer_view_;
346         delete d->cursor_;
347         // Completer has a QObject parent and is thus automatically destroyed.
348         // See #4758.
349         // delete completer_;
350         delete d;
351 }
352
353
354 Qt::CursorShape GuiWorkArea::cursorShape() const
355 {
356         return viewport()->cursor().shape();
357 }
358
359
360 void GuiWorkArea::Private::setCursorShape(Qt::CursorShape shape)
361 {
362         p->viewport()->setCursor(shape);
363 }
364
365
366 void GuiWorkArea::Private::updateCursorShape()
367 {
368         setCursorShape(buffer_view_->clickableInset() 
369                 ? Qt::PointingHandCursor : Qt::IBeamCursor);
370 }
371
372
373 void GuiWorkArea::setGuiView(GuiView & gv)
374 {
375         d->lyx_view_ = &gv;
376 }
377
378
379 void GuiWorkArea::setBuffer(Buffer & buffer)
380 {
381         delete d->buffer_view_;
382         d->buffer_view_ = new BufferView(buffer);
383         buffer.workAreaManager().add(this);
384
385         // HACK: Prevents an additional redraw when the scrollbar pops up
386         // which regularily happens on documents with more than one page.
387         // The policy  should be set to "Qt::ScrollBarAsNeeded" soon.
388         // Since we have no geometry information yet, we assume that
389         // a document needs a scrollbar if there is more then four
390         // paragraph in the outermost text.
391         if (buffer.text().paragraphs().size() > 4)
392                 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
393         QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
394 }
395
396
397 void GuiWorkArea::fixVerticalScrollBar()
398 {
399         if (!isFullScreen())
400                 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
401 }
402
403
404 void GuiWorkArea::close()
405 {
406         d->lyx_view_->removeWorkArea(this);
407 }
408
409
410 void GuiWorkArea::setFullScreen(bool full_screen)
411 {
412         d->buffer_view_->setFullScreen(full_screen);
413         setFrameStyle(QFrame::NoFrame);
414         if (full_screen) {
415                 setFrameStyle(QFrame::NoFrame);
416                 if (lyxrc.full_screen_scrollbar)
417                         setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
418         } else
419                 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
420 }
421
422
423 BufferView & GuiWorkArea::bufferView()
424 {
425         return *d->buffer_view_;
426 }
427
428
429 BufferView const & GuiWorkArea::bufferView() const
430 {
431         return *d->buffer_view_;
432 }
433
434
435 void GuiWorkArea::stopBlinkingCursor()
436 {
437         d->cursor_timeout_.stop();
438         d->hideCursor();
439 }
440
441
442 void GuiWorkArea::startBlinkingCursor()
443 {
444         // do not show the cursor if the view is busy
445         if (view().busy())
446                 return;
447
448         Point p;
449         int h = 0;
450         d->buffer_view_->cursorPosAndHeight(p, h);
451         // Don't start blinking if the cursor isn't on screen.
452         if (!d->buffer_view_->cursorInView(p, h))
453                 return;
454
455         d->showCursor();
456
457         //we're not supposed to cache this value.
458         int const time = QApplication::cursorFlashTime() / 2;
459         if (time <= 0)
460                 return;
461         d->cursor_timeout_.setInterval(time);
462         d->cursor_timeout_.start();
463 }
464
465
466 void GuiWorkArea::redraw(bool update_metrics)
467 {
468         if (!isVisible())
469                 // No need to redraw in this case.
470                 return;
471
472         // No need to do anything if this is the current view. The BufferView
473         // metrics are already up to date.
474         if (update_metrics || d->lyx_view_ != guiApp->currentView()
475                 || d->lyx_view_->currentWorkArea() != this) {
476                 // FIXME: it would be nice to optimize for the off-screen case.
477                 d->buffer_view_->cursor().fixIfBroken();
478                 d->buffer_view_->updateMetrics();
479                 d->buffer_view_->cursor().fixIfBroken();
480         }
481
482         // update cursor position, because otherwise it has to wait until
483         // the blinking interval is over
484         if (d->cursor_visible_) {
485                 d->hideCursor();
486                 d->showCursor();
487         }
488
489         LYXERR(Debug::WORKAREA, "WorkArea::redraw screen");
490         d->updateScreen();
491         update(0, 0, viewport()->width(), viewport()->height());
492
493         /// \warning: scrollbar updating *must* be done after the BufferView is drawn
494         /// because \c BufferView::updateScrollbar() is called in \c BufferView::draw().
495         d->updateScrollbar();
496         d->lyx_view_->updateStatusBar();
497
498         if (lyxerr.debugging(Debug::WORKAREA))
499                 d->buffer_view_->coordCache().dump();
500
501         updateWindowTitle();
502
503         d->updateCursorShape();
504 }
505
506
507 void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
508 {
509         if (d->lyx_view_->isFullScreen() && d->lyx_view_->menuBar()->isVisible()
510                 && lyxrc.full_screen_menubar) {
511                 // FIXME HACK: we should not have to do this here. See related comment
512                 // in GuiView::event() (QEvent::ShortcutOverride)
513                 d->lyx_view_->menuBar()->hide();
514         }
515
516         // In order to avoid bad surprise in the middle of an operation,
517         // we better stop the blinking cursor...
518         // the cursor gets restarted in GuiView::restartCursor()
519         stopBlinkingCursor();
520         guiApp->processKeySym(key, mod);
521 }
522
523
524 void GuiWorkArea::Private::dispatch(FuncRequest const & cmd)
525 {
526         // Handle drag&drop
527         if (cmd.action() == LFUN_FILE_OPEN) {
528                 DispatchResult dr;
529                 lyx_view_->dispatch(cmd, dr);
530                 return;
531         }
532
533         bool const notJustMovingTheMouse =
534                 cmd.action() != LFUN_MOUSE_MOTION || cmd.button() != mouse_button::none;
535
536         // In order to avoid bad surprise in the middle of an operation, we better stop
537         // the blinking cursor.
538         if (notJustMovingTheMouse)
539                 p->stopBlinkingCursor();
540
541         buffer_view_->mouseEventDispatch(cmd);
542
543         // Skip these when selecting
544         // FIXME: let GuiView take care of those.
545         if (cmd.action() != LFUN_MOUSE_MOTION) {
546                 completer_->updateVisibility(false, false);
547                 lyx_view_->updateDialogs();
548                 lyx_view_->updateStatusBar();
549         }
550
551         // GUI tweaks except with mouse motion with no button pressed.
552         if (notJustMovingTheMouse) {
553                 // Slight hack: this is only called currently when we
554                 // clicked somewhere, so we force through the display
555                 // of the new status here.
556                 // FIXME: let GuiView take care of those.
557                 lyx_view_->clearMessage();
558
559                 // Show the cursor immediately after any operation
560                 p->startBlinkingCursor();
561         }
562
563         updateCursorShape();
564 }
565
566
567 void GuiWorkArea::Private::resizeBufferView()
568 {
569         // WARNING: Please don't put any code that will trigger a repaint here!
570         // We are already inside a paint event.
571         p->stopBlinkingCursor();
572         // Warn our container (GuiView).
573         p->busy(true);
574
575         Point point;
576         int h = 0;
577         buffer_view_->cursorPosAndHeight(point, h);
578         bool const cursor_in_view = buffer_view_->cursorInView(point, h);
579         buffer_view_->resize(p->viewport()->width(), p->viewport()->height());
580         if (cursor_in_view)
581                 buffer_view_->scrollToCursor();
582         updateScreen();
583
584         // Update scrollbars which might have changed due different
585         // BufferView dimension. This is especially important when the
586         // BufferView goes from zero-size to the real-size for the first time,
587         // as the scrollbar paramters are then set for the first time.
588         updateScrollbar();
589
590         need_resize_ = false;
591         p->busy(false);
592         // Eventually, restart the cursor after the resize event.
593         // We might be resizing even if the focus is on another widget so we only
594         // restart the cursor if we have the focus.
595         if (p->hasFocus())
596                 QTimer::singleShot(50, p, SLOT(startBlinkingCursor()));
597 }
598
599
600 void GuiWorkArea::Private::showCursor()
601 {
602         if (cursor_visible_)
603                 return;
604
605         Point p;
606         int h = 0;
607         buffer_view_->cursorPosAndHeight(p, h);
608         if (!buffer_view_->cursorInView(p, h))
609                 return;
610
611         // RTL or not RTL
612         bool l_shape = false;
613         Font const & realfont = buffer_view_->cursor().real_current_font;
614         BufferParams const & bp = buffer_view_->buffer().params();
615         bool const samelang = realfont.language() == bp.language;
616         bool const isrtl = realfont.isVisibleRightToLeft();
617
618         if (!samelang || isrtl != bp.language->rightToLeft())
619                 l_shape = true;
620
621         // The ERT language hack needs fixing up
622         if (realfont.language() == latex_language)
623                 l_shape = false;
624
625         // show cursor on screen
626         Cursor & cur = buffer_view_->cursor();
627         bool completable = cur.inset().showCompletionCursor()
628                 && completer_->completionAvailable()
629                 && !completer_->popupVisible()
630                 && !completer_->inlineVisible();
631         cursor_visible_ = true;
632         cursor_->recomputeWidth();
633
634         //int cur_x = buffer_view_->getPos(cur).x_;
635         // We may have decided to slide the cursor row so that cursor
636         // is visible.
637         p.x_ -= buffer_view_->horizScrollOffset();
638
639         showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
640 }
641
642
643 void GuiWorkArea::Private::hideCursor()
644 {
645         if (!cursor_visible_)
646                 return;
647
648         cursor_visible_ = false;
649         removeCursor();
650 }
651
652
653 void GuiWorkArea::toggleCursor()
654 {
655         if (d->cursor_visible_)
656                 d->hideCursor();
657         else
658                 d->showCursor();
659 }
660
661
662 void GuiWorkArea::Private::updateScrollbar()
663 {
664         ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
665         // WARNING: don't touch at the scrollbar value like this:
666         //   verticalScrollBar()->setValue(scroll_.position);
667         // because this would cause a recursive signal/slot calling with
668         // GuiWorkArea::scrollTo
669         p->verticalScrollBar()->setRange(scroll_.min, scroll_.max);
670         p->verticalScrollBar()->setPageStep(scroll_.page_step);
671         p->verticalScrollBar()->setSingleStep(scroll_.single_step);
672         p->verticalScrollBar()->setSliderPosition(0);
673 }
674
675
676 void GuiWorkArea::scrollTo(int value)
677 {
678         stopBlinkingCursor();
679         d->buffer_view_->scrollDocView(value, true);
680
681         if (lyxrc.cursor_follows_scrollbar) {
682                 d->buffer_view_->setCursorFromScrollbar();
683                 // FIXME: let GuiView take care of those.
684                 d->lyx_view_->updateLayoutList();
685         }
686         // Show the cursor immediately after any operation.
687         startBlinkingCursor();
688         // FIXME QT5
689 #ifdef Q_WS_X11
690         QApplication::syncX();
691 #endif
692 }
693
694
695 bool GuiWorkArea::event(QEvent * e)
696 {
697         switch (e->type()) {
698         case QEvent::ToolTip: {
699                 QHelpEvent * helpEvent = static_cast<QHelpEvent *>(e);
700                 if (lyxrc.use_tooltip) {
701                         QPoint pos = helpEvent->pos();
702                         if (pos.x() < viewport()->width()) {
703                                 QString s = toqstr(d->buffer_view_->toolTip(pos.x(), pos.y()));
704                                 QToolTip::showText(helpEvent->globalPos(), s);
705                         }
706                         else
707                                 QToolTip::hideText();
708                 }
709                 // Don't forget to accept the event!
710                 e->accept();
711                 return true;
712         }
713
714         case QEvent::KeyPress: {
715                 // We catch this event in order to catch the Tab or Shift+Tab key press
716                 // which are otherwise reserved to focus switching between controls
717                 // within a dialog.
718                 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
719                 if ((ke->key() == Qt::Key_Tab && ke->modifiers() == Qt::NoModifier)
720                         || (ke->key() == Qt::Key_Backtab && (
721                                 ke->modifiers() == Qt::ShiftModifier
722                                 || ke->modifiers() == Qt::NoModifier))) {
723                         keyPressEvent(ke);
724                         return true;
725                 }
726                 return QAbstractScrollArea::event(e);
727         }
728
729         default:
730                 return QAbstractScrollArea::event(e);
731         }
732         return false;
733 }
734
735
736 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
737 {
738         string name;
739         if (e->reason() == QContextMenuEvent::Mouse)
740                 // the menu name is set on mouse press
741                 name = d->context_menu_name_;
742         else {
743                 QPoint pos = e->pos();
744                 Cursor const & cur = d->buffer_view_->cursor();
745                 if (e->reason() == QContextMenuEvent::Keyboard && cur.inTexted()) {
746                         // Do not access the context menu of math right in front of before
747                         // the cursor. This does not work when the cursor is in text.
748                         Inset * inset = cur.paragraph().getInset(cur.pos());
749                         if (inset && inset->asInsetMath())
750                                 --pos.rx();
751                         else if (cur.pos() > 0) {
752                                 Inset * inset = cur.paragraph().getInset(cur.pos() - 1);
753                                 if (inset)
754                                         ++pos.rx();
755                         }
756                 }
757                 name = d->buffer_view_->contextMenu(pos.x(), pos.y());
758         }
759         
760         if (name.empty()) {
761                 QAbstractScrollArea::contextMenuEvent(e);
762                 return;
763         }
764         // always show mnemonics when the keyboard is used to show the context menu
765         // FIXME: This should be fixed in Qt itself
766         bool const keyboard = (e->reason() == QContextMenuEvent::Keyboard);
767         QMenu * menu = guiApp->menus().menu(toqstr(name), *d->lyx_view_, keyboard);
768         if (!menu) {
769                 QAbstractScrollArea::contextMenuEvent(e);
770                 return;
771         }
772         // Position the menu to the right.
773         // FIXME: menu position should be different for RTL text.
774         menu->exec(e->globalPos());
775         e->accept();
776 }
777
778
779 void GuiWorkArea::focusInEvent(QFocusEvent * e)
780 {
781         LYXERR(Debug::DEBUG, "GuiWorkArea::focusInEvent(): " << this << endl);
782         if (d->lyx_view_->currentWorkArea() != this) {
783                 d->lyx_view_->setCurrentWorkArea(this);
784                 d->lyx_view_->currentWorkArea()->bufferView().buffer().updateBuffer();
785         }
786
787         startBlinkingCursor();
788         QAbstractScrollArea::focusInEvent(e);
789 }
790
791
792 void GuiWorkArea::focusOutEvent(QFocusEvent * e)
793 {
794         LYXERR(Debug::DEBUG, "GuiWorkArea::focusOutEvent(): " << this << endl);
795         stopBlinkingCursor();
796         QAbstractScrollArea::focusOutEvent(e);
797 }
798
799
800 void GuiWorkArea::mousePressEvent(QMouseEvent * e)
801 {
802         if (d->dc_event_.active && d->dc_event_ == *e) {
803                 d->dc_event_.active = false;
804                 FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
805                         q_button_state(e->button()), q_key_state(e->modifiers()));
806                 d->dispatch(cmd);
807                 e->accept();
808                 return;
809         }
810
811 #if (QT_VERSION < 0x050000) && !defined(__HAIKU__)
812         inputContext()->reset();
813 #endif
814
815         FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
816                         q_button_state(e->button()), q_key_state(e->modifiers()));
817         d->dispatch(cmd);
818
819         // Save the context menu on mouse press, because also the mouse
820         // cursor is set on mouse press. Afterwards, we can either release
821         // the mousebutton somewhere else, or the cursor might have moved
822         // due to the DEPM. We need to do this after the mouse has been
823         // set in dispatch(), because the selection state might change.
824         if (e->button() == Qt::RightButton)
825                 d->context_menu_name_ = d->buffer_view_->contextMenu(e->x(), e->y());
826
827         e->accept();
828 }
829
830
831 void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
832 {
833         if (d->synthetic_mouse_event_.timeout.running())
834                 d->synthetic_mouse_event_.timeout.stop();
835
836         FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
837                         q_button_state(e->button()), q_key_state(e->modifiers()));
838         d->dispatch(cmd);
839         e->accept();
840 }
841
842
843 void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
844 {
845         // we kill the triple click if we move
846         doubleClickTimeout();
847         FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
848                         q_motion_state(e->buttons()), q_key_state(e->modifiers()));
849
850         e->accept();
851
852         // If we're above or below the work area...
853         if ((e->y() <= 20 || e->y() >= viewport()->height() - 20)
854                         && e->buttons() == mouse_button::button1) {
855                 // Make sure only a synthetic event can cause a page scroll,
856                 // so they come at a steady rate:
857                 if (e->y() <= 20)
858                         // _Force_ a scroll up:
859                         cmd.set_y(e->y() - 21);
860                 else
861                         cmd.set_y(e->y() + 21);
862                 // Store the event, to be handled when the timeout expires.
863                 d->synthetic_mouse_event_.cmd = cmd;
864
865                 if (d->synthetic_mouse_event_.timeout.running()) {
866                         // Discard the event. Note that it _may_ be handled
867                         // when the timeout expires if
868                         // synthetic_mouse_event_.cmd has not been overwritten.
869                         // Ie, when the timeout expires, we handle the
870                         // most recent event but discard all others that
871                         // occurred after the one used to start the timeout
872                         // in the first place.
873                         return;
874                 }
875                 
876                 d->synthetic_mouse_event_.restart_timeout = true;
877                 d->synthetic_mouse_event_.timeout.start();
878                 // Fall through to handle this event...
879
880         } else if (d->synthetic_mouse_event_.timeout.running()) {
881                 // Store the event, to be possibly handled when the timeout
882                 // expires.
883                 // Once the timeout has expired, normal control is returned
884                 // to mouseMoveEvent (restart_timeout = false).
885                 // This results in a much smoother 'feel' when moving the
886                 // mouse back into the work area.
887                 d->synthetic_mouse_event_.cmd = cmd;
888                 d->synthetic_mouse_event_.restart_timeout = false;
889                 return;
890         }
891         d->dispatch(cmd);
892 }
893
894
895 void GuiWorkArea::wheelEvent(QWheelEvent * ev)
896 {
897         // Wheel rotation by one notch results in a delta() of 120 (see
898         // documentation of QWheelEvent)
899         double const delta = ev->delta() / 120.0;
900         bool zoom = false;
901         switch (lyxrc.scroll_wheel_zoom) {
902         case LyXRC::SCROLL_WHEEL_ZOOM_CTRL:
903                 zoom = ev->modifiers() & Qt::ControlModifier;
904                 zoom &= !(ev->modifiers() & (Qt::ShiftModifier | Qt::AltModifier));
905                 break;
906         case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT:
907                 zoom = ev->modifiers() & Qt::ShiftModifier;
908                 zoom &= !(ev->modifiers() & (Qt::ControlModifier | Qt::AltModifier));
909                 break;
910         case LyXRC::SCROLL_WHEEL_ZOOM_ALT:
911                 zoom = ev->modifiers() & Qt::AltModifier;
912                 zoom &= !(ev->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier));
913                 break;
914         case LyXRC::SCROLL_WHEEL_ZOOM_OFF:
915                 break;
916         }
917         if (zoom) {
918                 docstring arg = convert<docstring>(int(5 * delta));
919                 lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg));
920                 return;
921         }
922
923         // Take into account the desktop wide settings.
924         int const lines = qApp->wheelScrollLines();
925         int const page_step = verticalScrollBar()->pageStep();
926         // Test if the wheel mouse is set to one screen at a time.
927         // This is according to
928         // https://doc.qt.io/qt-5/qapplication.html#wheelScrollLines-prop
929         int scroll_value =
930                 min(lines * verticalScrollBar()->singleStep(), page_step);
931
932         // Take into account the rotation and the user preferences.
933         scroll_value = int(scroll_value * delta * lyxrc.mouse_wheel_speed);
934         LYXERR(Debug::SCROLLING, "wheelScrollLines = " << lines
935                         << " delta = " << delta << " scroll_value = " << scroll_value
936                         << " page_step = " << page_step);
937         // Now scroll.
938         verticalScrollBar()->setValue(verticalScrollBar()->value() - scroll_value);
939
940         ev->accept();
941 }
942
943
944 void GuiWorkArea::generateSyntheticMouseEvent()
945 {
946         int const e_y = d->synthetic_mouse_event_.cmd.y();
947         int const wh = d->buffer_view_->workHeight();
948         bool const up = e_y < 0;
949         bool const down = e_y > wh;
950
951         // Set things off to generate the _next_ 'pseudo' event.
952         int step = 50;
953         if (d->synthetic_mouse_event_.restart_timeout) {
954                 // This is some magic formulae to determine the speed
955                 // of scrolling related to the position of the mouse.
956                 int time = 200;
957                 if (up || down) {
958                         int dist = up ? -e_y : e_y - wh;
959                         time = max(min(200, 250000 / (dist * dist)), 1) ;
960                         
961                         if (time < 40) {
962                                 step = 80000 / (time * time);
963                                 time = 40;
964                         }
965                 }
966                 d->synthetic_mouse_event_.timeout.setTimeout(time);
967                 d->synthetic_mouse_event_.timeout.start();
968         }
969
970         // Can we scroll further ?
971         int const value = verticalScrollBar()->value();
972         if (value == verticalScrollBar()->maximum()
973                   || value == verticalScrollBar()->minimum()) {
974                 d->synthetic_mouse_event_.timeout.stop();
975                 return;
976         }
977
978         // Scroll
979         if (step <= 2 * wh) {
980                 d->buffer_view_->scroll(up ? -step : step);
981                 d->buffer_view_->updateMetrics();
982         } else {
983                 d->buffer_view_->scrollDocView(value + (up ? -step : step), false);
984         }
985
986         // In which paragraph do we have to set the cursor ?
987         Cursor & cur = d->buffer_view_->cursor();
988         // FIXME: we don't know howto handle math.
989         Text * text = cur.text();
990         if (!text)
991                 return;
992         TextMetrics const & tm = d->buffer_view_->textMetrics(text);
993
994         pair<pit_type, const ParagraphMetrics *> pp = up ? tm.first() : tm.last();
995         ParagraphMetrics const & pm = *pp.second;
996         pit_type const pit = pp.first;
997
998         if (pm.rows().empty())
999                 return;
1000
1001         // Find the row at which we set the cursor.
1002         RowList::const_iterator rit = pm.rows().begin();
1003         RowList::const_iterator rlast = pm.rows().end();
1004         int yy = pm.position() - pm.ascent();
1005         for (--rlast; rit != rlast; ++rit) {
1006                 int h = rit->height();
1007                 if ((up && yy + h > 0)
1008                           || (!up && yy + h > wh - defaultRowHeight()))
1009                         break;
1010                 yy += h;
1011         }
1012
1013         // Find the position of the cursor
1014         bool bound;
1015         int x = d->synthetic_mouse_event_.cmd.x();
1016         pos_type const pos = tm.getPosNearX(*rit, x, bound);
1017
1018         // Set the cursor
1019         cur.pit() = pit;
1020         cur.pos() = pos;
1021         cur.boundary(bound);
1022
1023         d->buffer_view_->buffer().changed(false);
1024         return;
1025 }
1026
1027
1028 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
1029 {
1030         // Do not process here some keys if dialog_mode_ is set
1031         if (d->dialog_mode_
1032                 && (ev->modifiers() == Qt::NoModifier
1033                     || ev->modifiers() == Qt::ShiftModifier)
1034                 && (ev->key() == Qt::Key_Escape
1035                     || ev->key() == Qt::Key_Enter
1036                     || ev->key() == Qt::Key_Return)
1037             ) {
1038                 ev->ignore();
1039                 return;
1040         }
1041
1042         // intercept some keys if completion popup is visible
1043         if (d->completer_->popupVisible()) {
1044                 switch (ev->key()) {
1045                 case Qt::Key_Enter:
1046                 case Qt::Key_Return:
1047                         d->completer_->activate();
1048                         ev->accept();
1049                         return;
1050                 }
1051         }
1052
1053         // do nothing if there are other events
1054         // (the auto repeated events come too fast)
1055         // it looks like this is only needed on X11
1056 #if defined(Q_WS_X11) || defined(QPA_XCB)
1057         if (qApp->hasPendingEvents() && ev->isAutoRepeat()) {
1058                 switch (ev->key()) {
1059                 case Qt::Key_PageDown:
1060                 case Qt::Key_PageUp:
1061                 case Qt::Key_Left:
1062                 case Qt::Key_Right:
1063                 case Qt::Key_Up:
1064                 case Qt::Key_Down:
1065                         LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
1066                         ev->ignore();
1067                         return;
1068                 }
1069         }
1070 #endif
1071
1072         KeyModifier m = q_key_state(ev->modifiers());
1073
1074         std::string str;
1075         if (m & ShiftModifier)
1076                 str += "Shift-";
1077         if (m & ControlModifier)
1078                 str += "Control-";
1079         if (m & AltModifier)
1080                 str += "Alt-";
1081         if (m & MetaModifier)
1082                 str += "Meta-";
1083         
1084         LYXERR(Debug::KEY, " count: " << ev->count() << " text: " << ev->text()
1085                 << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key()
1086                 << " keyState: " << str);
1087
1088         KeySymbol sym;
1089         setKeySymbol(&sym, ev);
1090         if (sym.isOK()) {
1091                 processKeySym(sym, q_key_state(ev->modifiers()));
1092                 ev->accept();
1093         } else {
1094                 ev->ignore();
1095         }
1096 }
1097
1098
1099 void GuiWorkArea::doubleClickTimeout()
1100 {
1101         d->dc_event_.active = false;
1102 }
1103
1104
1105 void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
1106 {
1107         d->dc_event_ = DoubleClick(ev);
1108         QTimer::singleShot(QApplication::doubleClickInterval(), this,
1109                         SLOT(doubleClickTimeout()));
1110         FuncRequest cmd(LFUN_MOUSE_DOUBLE, ev->x(), ev->y(),
1111                         q_button_state(ev->button()), q_key_state(ev->modifiers()));
1112         d->dispatch(cmd);
1113         ev->accept();
1114 }
1115
1116
1117 void GuiWorkArea::resizeEvent(QResizeEvent * ev)
1118 {
1119         QAbstractScrollArea::resizeEvent(ev);
1120         d->need_resize_ = true;
1121         ev->accept();
1122 }
1123
1124
1125 void GuiWorkArea::Private::update(int x, int y, int w, int h)
1126 {
1127         p->viewport()->update(x, y, w, h);
1128 }
1129
1130
1131 void GuiWorkArea::paintEvent(QPaintEvent * ev)
1132 {
1133         QRectF const rc = ev->rect();
1134         // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
1135         //      << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
1136
1137         if (d->needResize()) {
1138                 d->resetScreen();
1139                 d->resizeBufferView();
1140                 if (d->cursor_visible_) {
1141                         d->hideCursor();
1142                         d->showCursor();
1143                 }
1144         }
1145
1146         QPainter pain(viewport());
1147         double const pr = pixelRatio();
1148         QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr, rc.width() * pr, rc.height() * pr);
1149
1150         if (lyxrc.use_qimage) {
1151                 QImage const & image = static_cast<QImage const &>(*d->screen_);
1152                 pain.drawImage(rc, image, rcs);
1153         } else {
1154                 QPixmap const & pixmap = static_cast<QPixmap const &>(*d->screen_);
1155                 pain.drawPixmap(rc, pixmap, rcs);
1156         }
1157         d->cursor_->draw(pain);
1158         ev->accept();
1159 }
1160
1161
1162 void GuiWorkArea::Private::updateScreen()
1163 {
1164         GuiPainter pain(screen_, p->pixelRatio());
1165         buffer_view_->draw(pain);
1166 }
1167
1168
1169 void GuiWorkArea::Private::showCursor(int x, int y, int h,
1170         bool l_shape, bool rtl, bool completable)
1171 {
1172         if (schedule_redraw_) {
1173                 // This happens when a graphic conversion is finished. As we don't know
1174                 // the size of the new graphics, it's better the update everything.
1175                 // We can't use redraw() here because this would trigger a infinite
1176                 // recursive loop with showCursor().
1177                 buffer_view_->resize(p->viewport()->width(), p->viewport()->height());
1178                 updateScreen();
1179                 updateScrollbar();
1180                 p->viewport()->update(QRect(0, 0, p->viewport()->width(), p->viewport()->height()));
1181                 schedule_redraw_ = false;
1182                 // Show the cursor immediately after the update.
1183                 hideCursor();
1184                 p->toggleCursor();
1185                 return;
1186         }
1187
1188         cursor_->update(x, y, h, l_shape, rtl, completable);
1189         cursor_->show();
1190         p->viewport()->update(cursor_->rect());
1191 }
1192
1193
1194 void GuiWorkArea::Private::removeCursor()
1195 {
1196         cursor_->hide();
1197         //if (!qApp->focusWidget())
1198                 p->viewport()->update(cursor_->rect());
1199 }
1200
1201
1202 void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
1203 {
1204         QString const & commit_string = e->commitString();
1205         docstring const & preedit_string
1206                 = qstring_to_ucs4(e->preeditString());
1207
1208         if (!commit_string.isEmpty()) {
1209
1210                 LYXERR(Debug::KEY, "preeditString: " << e->preeditString()
1211                         << " commitString: " << e->commitString());
1212
1213                 int key = 0;
1214
1215                 // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
1216                 for (int i = 0; i != commit_string.size(); ++i) {
1217                         QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
1218                         keyPressEvent(&ev);
1219                 }
1220         }
1221
1222         // Hide the cursor during the kana-kanji transformation.
1223         if (preedit_string.empty())
1224                 startBlinkingCursor();
1225         else
1226                 stopBlinkingCursor();
1227
1228         // last_width : for checking if last preedit string was/wasn't empty.
1229         // FIXME THREAD
1230         // We could have more than one work area, right?
1231         static bool last_width = false;
1232         if (!last_width && preedit_string.empty()) {
1233                 // if last_width is last length of preedit string.
1234                 e->accept();
1235                 return;
1236         }
1237
1238         GuiPainter pain(d->screen_, pixelRatio());
1239         d->buffer_view_->updateMetrics();
1240         d->buffer_view_->draw(pain);
1241         FontInfo font = d->buffer_view_->cursor().getFont().fontInfo();
1242         FontMetrics const & fm = theFontMetrics(font);
1243         int height = fm.maxHeight();
1244         int cur_x = d->cursor_->rect().left();
1245         int cur_y = d->cursor_->rect().bottom();
1246
1247         // redraw area of preedit string.
1248         update(0, cur_y - height, viewport()->width(),
1249                 (height + 1) * d->preedit_lines_);
1250
1251         if (preedit_string.empty()) {
1252                 last_width = false;
1253                 d->preedit_lines_ = 1;
1254                 e->accept();
1255                 return;
1256         }
1257         last_width = true;
1258
1259         // att : stores an IM attribute.
1260         QList<QInputMethodEvent::Attribute> const & att = e->attributes();
1261
1262         // get attributes of input method cursor.
1263         // cursor_pos : cursor position in preedit string.
1264         size_t cursor_pos = 0;
1265         bool cursor_is_visible = false;
1266         for (int i = 0; i != att.size(); ++i) {
1267                 if (att.at(i).type == QInputMethodEvent::Cursor) {
1268                         cursor_pos = att.at(i).start;
1269                         cursor_is_visible = att.at(i).length != 0;
1270                         break;
1271                 }
1272         }
1273
1274         size_t preedit_length = preedit_string.length();
1275
1276         // get position of selection in input method.
1277         // FIXME: isn't there a way to do this simplier?
1278         // rStart : cursor position in selected string in IM.
1279         size_t rStart = 0;
1280         // rLength : selected string length in IM.
1281         size_t rLength = 0;
1282         if (cursor_pos < preedit_length) {
1283                 for (int i = 0; i != att.size(); ++i) {
1284                         if (att.at(i).type == QInputMethodEvent::TextFormat) {
1285                                 if (att.at(i).start <= int(cursor_pos)
1286                                         && int(cursor_pos) < att.at(i).start + att.at(i).length) {
1287                                                 rStart = att.at(i).start;
1288                                                 rLength = att.at(i).length;
1289                                                 if (!cursor_is_visible)
1290                                                         cursor_pos += rLength;
1291                                                 break;
1292                                 }
1293                         }
1294                 }
1295         }
1296         else {
1297                 rStart = cursor_pos;
1298                 rLength = 0;
1299         }
1300
1301         int const right_margin = d->buffer_view_->rightMargin();
1302         Painter::preedit_style ps;
1303         // Most often there would be only one line:
1304         d->preedit_lines_ = 1;
1305         for (size_t pos = 0; pos != preedit_length; ++pos) {
1306                 char_type const typed_char = preedit_string[pos];
1307                 // reset preedit string style
1308                 ps = Painter::preedit_default;
1309
1310                 // if we reached the right extremity of the screen, go to next line.
1311                 if (cur_x + fm.width(typed_char) > viewport()->width() - right_margin) {
1312                         cur_x = right_margin;
1313                         cur_y += height + 1;
1314                         ++d->preedit_lines_;
1315                 }
1316                 // preedit strings are displayed with dashed underline
1317                 // and partial strings are displayed white on black indicating
1318                 // that we are in selecting mode in the input method.
1319                 // FIXME: rLength == preedit_length is not a changing condition
1320                 // FIXME: should be put out of the loop.
1321                 if (pos >= rStart
1322                         && pos < rStart + rLength
1323                         && !(cursor_pos < rLength && rLength == preedit_length))
1324                         ps = Painter::preedit_selecting;
1325
1326                 if (pos == cursor_pos
1327                         && (cursor_pos < rLength && rLength == preedit_length))
1328                         ps = Painter::preedit_cursor;
1329
1330                 // draw one character and update cur_x.
1331                 cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
1332         }
1333
1334         // update the preedit string screen area.
1335         update(0, cur_y - d->preedit_lines_*height, viewport()->width(),
1336                 (height + 1) * d->preedit_lines_);
1337
1338         // Don't forget to accept the event!
1339         e->accept();
1340 }
1341
1342
1343 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
1344 {
1345         QRect cur_r(0, 0, 0, 0);
1346         switch (query) {
1347                 // this is the CJK-specific composition window position and
1348                 // the context menu position when the menu key is pressed.
1349                 case Qt::ImMicroFocus:
1350                         cur_r = d->cursor_->rect();
1351                         if (d->preedit_lines_ != 1)
1352                                 cur_r.moveLeft(10);
1353                         cur_r.moveBottom(cur_r.bottom()
1354                                 + cur_r.height() * (d->preedit_lines_ - 1));
1355                         // return lower right of cursor in LyX.
1356                         return cur_r;
1357                 default:
1358                         return QWidget::inputMethodQuery(query);
1359         }
1360 }
1361
1362
1363 void GuiWorkArea::updateWindowTitle()
1364 {
1365         docstring maximize_title;
1366         docstring minimize_title;
1367
1368         Buffer const & buf = d->buffer_view_->buffer();
1369         FileName const file_name = buf.fileName();
1370         if (!file_name.empty()) {
1371                 maximize_title = file_name.displayName(130);
1372                 minimize_title = from_utf8(file_name.onlyFileName());
1373                 if (buf.lyxvc().inUse()) {
1374                         if (buf.lyxvc().locking())
1375                                 maximize_title +=  _(" (version control, locking)");
1376                         else
1377                                 maximize_title +=  _(" (version control)");
1378                 }
1379                 if (!buf.isClean()) {
1380                         maximize_title += _(" (changed)");
1381                         minimize_title += char_type('*');
1382                 }
1383                 if (buf.isReadonly())
1384                         maximize_title += _(" (read only)");
1385         }
1386
1387         QString const new_title = toqstr(maximize_title);
1388         if (new_title != windowTitle()) {
1389                 QWidget::setWindowTitle(new_title);
1390                 QWidget::setWindowIconText(toqstr(minimize_title));
1391                 titleChanged(this);
1392         }
1393 }
1394
1395
1396 bool GuiWorkArea::isFullScreen() const
1397 {
1398         return d->lyx_view_ && d->lyx_view_->isFullScreen();
1399 }
1400
1401
1402 void GuiWorkArea::scheduleRedraw()
1403 {
1404         d->schedule_redraw_ = true;
1405 }
1406
1407
1408 bool GuiWorkArea::inDialogMode() const
1409 {
1410         return d->dialog_mode_;
1411 }
1412
1413
1414 void GuiWorkArea::setDialogMode(bool mode)
1415 {
1416         d->dialog_mode_ = mode;
1417 }
1418
1419
1420 GuiCompleter & GuiWorkArea::completer()
1421 {
1422         return *d->completer_;
1423 }
1424
1425 GuiView const & GuiWorkArea::view() const
1426 {
1427         return *d->lyx_view_;
1428 }
1429
1430
1431 GuiView & GuiWorkArea::view()
1432 {
1433         return *d->lyx_view_;
1434 }
1435
1436 ////////////////////////////////////////////////////////////////////
1437 //
1438 // EmbeddedWorkArea
1439 //
1440 ////////////////////////////////////////////////////////////////////
1441
1442
1443 EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
1444 {
1445         support::TempFile tempfile("embedded.internal");
1446         tempfile.setAutoRemove(false);
1447         buffer_ = theBufferList().newInternalBuffer(tempfile.name().absFileName());
1448         buffer_->setUnnamed(true);
1449         buffer_->setFullyLoaded(true);
1450         setBuffer(*buffer_);
1451         setDialogMode(true);
1452 }
1453
1454
1455 EmbeddedWorkArea::~EmbeddedWorkArea()
1456 {
1457         // No need to destroy buffer and bufferview here, because it is done
1458         // in theBufferList() destruction loop at application exit
1459 }
1460
1461
1462 void EmbeddedWorkArea::closeEvent(QCloseEvent * ev)
1463 {
1464         disable();
1465         GuiWorkArea::closeEvent(ev);
1466 }
1467
1468
1469 void EmbeddedWorkArea::hideEvent(QHideEvent * ev)
1470 {
1471         disable();
1472         GuiWorkArea::hideEvent(ev);
1473 }
1474
1475
1476 QSize EmbeddedWorkArea::sizeHint () const
1477 {
1478         // FIXME(?):
1479         // GuiWorkArea sets the size to the screen's viewport
1480         // by returning a value this gets overridden
1481         // EmbeddedWorkArea is now sized to fit in the layout
1482         // of the parent, and has a minimum size set in GuiWorkArea
1483         // which is what we return here
1484         return QSize(100, 70);
1485 }
1486
1487
1488 void EmbeddedWorkArea::disable()
1489 {
1490         stopBlinkingCursor();
1491         if (view().currentWorkArea() != this)
1492                 return;
1493         // No problem if currentMainWorkArea() is 0 (setCurrentWorkArea()
1494         // tolerates it and shows the background logo), what happens if
1495         // an EmbeddedWorkArea is closed after closing all document WAs
1496         view().setCurrentWorkArea(view().currentMainWorkArea());
1497 }
1498
1499 ////////////////////////////////////////////////////////////////////
1500 //
1501 // TabWorkArea
1502 //
1503 ////////////////////////////////////////////////////////////////////
1504
1505 #ifdef Q_OS_MAC
1506 class NoTabFrameMacStyle : public QProxyStyle {
1507 public:
1508         ///
1509         QRect subElementRect(SubElement element, const QStyleOption * option,
1510                              const QWidget * widget = 0) const
1511         {
1512                 QRect rect = QProxyStyle::subElementRect(element, option, widget);
1513                 bool noBar = static_cast<QTabWidget const *>(widget)->count() <= 1;
1514
1515                 // The Qt Mac style puts the contents into a 3 pixel wide box
1516                 // which looks very ugly and not like other Mac applications.
1517                 // Hence we remove this here, and moreover the 16 pixel round
1518                 // frame above if the tab bar is hidden.
1519                 if (element == QStyle::SE_TabWidgetTabContents) {
1520                         rect.adjust(- rect.left(), 0, rect.left(), 0);
1521                         if (noBar)
1522                                 rect.setTop(0);
1523                 }
1524
1525                 return rect;
1526         }
1527 };
1528
1529 NoTabFrameMacStyle noTabFrameMacStyle;
1530 #endif
1531
1532
1533 TabWorkArea::TabWorkArea(QWidget * parent)
1534         : QTabWidget(parent), clicked_tab_(-1)
1535 {
1536 #ifdef Q_OS_MAC
1537         setStyle(&noTabFrameMacStyle);
1538 #endif
1539
1540         QPalette pal = palette();
1541         pal.setColor(QPalette::Active, QPalette::Button,
1542                 pal.color(QPalette::Active, QPalette::Window));
1543         pal.setColor(QPalette::Disabled, QPalette::Button,
1544                 pal.color(QPalette::Disabled, QPalette::Window));
1545         pal.setColor(QPalette::Inactive, QPalette::Button,
1546                 pal.color(QPalette::Inactive, QPalette::Window));
1547
1548         QObject::connect(this, SIGNAL(currentChanged(int)),
1549                 this, SLOT(on_currentTabChanged(int)));
1550
1551         closeBufferButton = new QToolButton(this);
1552         closeBufferButton->setPalette(pal);
1553         // FIXME: rename the icon to closebuffer.png
1554         closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "svgz,png")));
1555         closeBufferButton->setText("Close File");
1556         closeBufferButton->setAutoRaise(true);
1557         closeBufferButton->setCursor(Qt::ArrowCursor);
1558         closeBufferButton->setToolTip(qt_("Close File"));
1559         closeBufferButton->setEnabled(true);
1560         QObject::connect(closeBufferButton, SIGNAL(clicked()),
1561                 this, SLOT(closeCurrentBuffer()));
1562         setCornerWidget(closeBufferButton, Qt::TopRightCorner);
1563
1564         // setup drag'n'drop
1565         QTabBar* tb = new DragTabBar;
1566         connect(tb, SIGNAL(tabMoveRequested(int, int)),
1567                 this, SLOT(moveTab(int, int)));
1568         tb->setElideMode(Qt::ElideNone);
1569         setTabBar(tb);
1570
1571         // make us responsible for the context menu of the tabbar
1572         tb->setContextMenuPolicy(Qt::CustomContextMenu);
1573         connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
1574                 this, SLOT(showContextMenu(const QPoint &)));
1575         connect(tb, SIGNAL(tabCloseRequested(int)),
1576                 this, SLOT(closeTab(int)));
1577
1578         setUsesScrollButtons(true);
1579 }
1580
1581
1582 void TabWorkArea::paintEvent(QPaintEvent * event)
1583 {
1584         if (tabBar()->isVisible()) {
1585                 QTabWidget::paintEvent(event);
1586         } else {
1587                 // Prevent the selected tab to influence the 
1588                 // painting of the frame of the tab widget.
1589                 // This is needed for gtk style in Qt.
1590                 QStylePainter p(this);
1591 #if QT_VERSION < 0x050000
1592                 QStyleOptionTabWidgetFrameV2 opt;
1593 #else
1594                 QStyleOptionTabWidgetFrame opt;
1595 #endif
1596                 initStyleOption(&opt);
1597                 opt.rect = style()->subElementRect(QStyle::SE_TabWidgetTabPane,
1598                         &opt, this);
1599                 opt.selectedTabRect = QRect();
1600                 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt);
1601         }
1602 }
1603
1604
1605 void TabWorkArea::mouseDoubleClickEvent(QMouseEvent * event)
1606 {
1607         if (event->button() != Qt::LeftButton)
1608                 return;
1609
1610         // return early if double click on existing tabs
1611         for (int i = 0; i < count(); ++i)
1612                 if (tabBar()->tabRect(i).contains(event->pos()))
1613                         return;
1614
1615         dispatch(FuncRequest(LFUN_BUFFER_NEW));
1616 }
1617
1618
1619 void TabWorkArea::setFullScreen(bool full_screen)
1620 {
1621         for (int i = 0; i != count(); ++i) {
1622                 if (GuiWorkArea * wa = workArea(i))
1623                         wa->setFullScreen(full_screen);
1624         }
1625
1626         if (lyxrc.full_screen_tabbar)
1627                 showBar(!full_screen && count() > 1);
1628         else
1629                 showBar(count() > 1);
1630 }
1631
1632
1633 void TabWorkArea::showBar(bool show)
1634 {
1635         tabBar()->setEnabled(show);
1636         tabBar()->setVisible(show);
1637         closeBufferButton->setVisible(show && lyxrc.single_close_tab_button);
1638         setTabsClosable(!lyxrc.single_close_tab_button);
1639 }
1640
1641
1642 GuiWorkArea * TabWorkArea::currentWorkArea()
1643 {
1644         if (count() == 0)
1645                 return 0;
1646
1647         GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(currentWidget());
1648         LATTEST(wa);
1649         return wa;
1650 }
1651
1652
1653 GuiWorkArea * TabWorkArea::workArea(int index)
1654 {
1655         return dynamic_cast<GuiWorkArea *>(widget(index));
1656 }
1657
1658
1659 GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
1660 {
1661         // FIXME: this method doesn't work if we have more than work area
1662         // showing the same buffer.
1663         for (int i = 0; i != count(); ++i) {
1664                 GuiWorkArea * wa = workArea(i);
1665                 LASSERT(wa, return 0);
1666                 if (&wa->bufferView().buffer() == &buffer)
1667                         return wa;
1668         }
1669         return 0;
1670 }
1671
1672
1673 void TabWorkArea::closeAll()
1674 {
1675         while (count()) {
1676                 GuiWorkArea * wa = workArea(0);
1677                 LASSERT(wa, return);
1678                 removeTab(0);
1679                 delete wa;
1680         }
1681 }
1682
1683
1684 bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
1685 {
1686         LASSERT(work_area, return false);
1687         int index = indexOf(work_area);
1688         if (index == -1)
1689                 return false;
1690
1691         if (index == currentIndex())
1692                 // Make sure the work area is up to date.
1693                 on_currentTabChanged(index);
1694         else
1695                 // Switch to the work area.
1696                 setCurrentIndex(index);
1697         work_area->setFocus();
1698
1699         return true;
1700 }
1701
1702
1703 GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
1704 {
1705         GuiWorkArea * wa = new GuiWorkArea(buffer, view);
1706         wa->setUpdatesEnabled(false);
1707         // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
1708         // when hiding it again below).
1709         if (!(currentWorkArea() && currentWorkArea()->isFullScreen()))
1710                 showBar(count() > 0);
1711         addTab(wa, wa->windowTitle());
1712         QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
1713                 this, SLOT(updateTabTexts()));
1714         if (currentWorkArea() && currentWorkArea()->isFullScreen())
1715                 setFullScreen(true);
1716         else
1717                 // Hide tabbar if there's only one tab.
1718                 showBar(count() > 1);
1719
1720         updateTabTexts();
1721
1722         return wa;
1723 }
1724
1725
1726 bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
1727 {
1728         LASSERT(work_area, return false);
1729         int index = indexOf(work_area);
1730         if (index == -1)
1731                 return false;
1732
1733         work_area->setUpdatesEnabled(false);
1734         removeTab(index);
1735         delete work_area;
1736
1737         if (count()) {
1738                 // make sure the next work area is enabled.
1739                 currentWidget()->setUpdatesEnabled(true);
1740                 if (currentWorkArea() && currentWorkArea()->isFullScreen())
1741                         setFullScreen(true);
1742                 else
1743                         // Show tabbar only if there's more than one tab.
1744                         showBar(count() > 1);
1745         } else
1746                 lastWorkAreaRemoved();
1747
1748         updateTabTexts();
1749
1750         return true;
1751 }
1752
1753
1754 void TabWorkArea::on_currentTabChanged(int i)
1755 {
1756         // returns e.g. on application destruction
1757         if (i == -1)
1758                 return;
1759         GuiWorkArea * wa = workArea(i);
1760         LASSERT(wa, return);
1761         wa->setUpdatesEnabled(true);
1762         wa->redraw(true);
1763         wa->setFocus();
1764         ///
1765         currentWorkAreaChanged(wa);
1766
1767         LYXERR(Debug::GUI, "currentTabChanged " << i
1768                 << " File: " << wa->bufferView().buffer().absFileName());
1769 }
1770
1771
1772 void TabWorkArea::closeCurrentBuffer()
1773 {
1774         GuiWorkArea * wa;
1775         if (clicked_tab_ == -1)
1776                 wa = currentWorkArea();
1777         else {
1778                 wa = workArea(clicked_tab_);
1779                 LASSERT(wa, return);
1780         }
1781         wa->view().closeWorkArea(wa);
1782 }
1783
1784
1785 void TabWorkArea::hideCurrentTab()
1786 {
1787         GuiWorkArea * wa;
1788         if (clicked_tab_ == -1)
1789                 wa = currentWorkArea();
1790         else {
1791                 wa = workArea(clicked_tab_);
1792                 LASSERT(wa, return);
1793         }
1794         wa->view().hideWorkArea(wa);
1795 }
1796
1797
1798 void TabWorkArea::closeTab(int index)
1799 {
1800         on_currentTabChanged(index);
1801         GuiWorkArea * wa;
1802         if (index == -1)
1803                 wa = currentWorkArea();
1804         else {
1805                 wa = workArea(index);
1806                 LASSERT(wa, return);
1807         }
1808         wa->view().closeWorkArea(wa);
1809 }
1810
1811
1812 ///
1813 class DisplayPath {
1814 public:
1815         /// make vector happy
1816         // coverity[UNINIT_CTOR]
1817         DisplayPath() {}
1818         ///
1819         DisplayPath(int tab, FileName const & filename)
1820                 : tab_(tab)
1821         {
1822                 filename_ = (filename.extension() == "lyx") ?
1823                         toqstr(filename.onlyFileNameWithoutExt())
1824                         : toqstr(filename.onlyFileName());
1825                 postfix_ = toqstr(filename.absoluteFilePath()).
1826                         split("/", QString::SkipEmptyParts);
1827                 postfix_.pop_back();
1828                 abs_ = toqstr(filename.absoluteFilePath());
1829                 dottedPrefix_ = false;
1830         }
1831
1832         /// Absolute path for debugging.
1833         QString abs() const
1834         {
1835                 return abs_;
1836         }
1837         /// Add the first segment from the postfix or three dots to the prefix.
1838         /// Merge multiple dot tripples. In fact dots are added lazily, i.e. only
1839         /// when really needed.
1840         void shiftPathSegment(bool dotted)
1841         {
1842                 if (postfix_.count() <= 0)
1843                         return;
1844
1845                 if (!dotted) {
1846                         if (dottedPrefix_ && !prefix_.isEmpty())
1847                                 prefix_ += ellipsisSlash_;
1848                         prefix_ += postfix_.front() + "/";
1849                 }
1850                 dottedPrefix_ = dotted && !prefix_.isEmpty();
1851                 postfix_.pop_front();
1852         }
1853         ///
1854         QString displayString() const
1855         {
1856                 if (prefix_.isEmpty())
1857                         return filename_;
1858
1859                 bool dots = dottedPrefix_ || !postfix_.isEmpty();
1860                 return prefix_ + (dots ? ellipsisSlash_ : "") + filename_;
1861         }
1862         ///
1863         QString forecastPathString() const
1864         {
1865                 if (postfix_.count() == 0)
1866                         return displayString();
1867
1868                 return prefix_
1869                         + (dottedPrefix_ ? ellipsisSlash_ : "")
1870                         + postfix_.front() + "/";
1871         }
1872         ///
1873         bool final() const { return postfix_.empty(); }
1874         ///
1875         int tab() const { return tab_; }
1876
1877 private:
1878         /// ".../"
1879         static QString const ellipsisSlash_;
1880         ///
1881         QString prefix_;
1882         ///
1883         QStringList postfix_;
1884         ///
1885         QString filename_;
1886         ///
1887         QString abs_;
1888         ///
1889         int tab_;
1890         ///
1891         bool dottedPrefix_;
1892 };
1893
1894
1895 QString const DisplayPath::ellipsisSlash_ = QString(QChar(0x2026)) + "/";
1896
1897
1898 ///
1899 bool operator<(DisplayPath const & a, DisplayPath const & b)
1900 {
1901         return a.displayString() < b.displayString();
1902 }
1903
1904 ///
1905 bool operator==(DisplayPath const & a, DisplayPath const & b)
1906 {
1907         return a.displayString() == b.displayString();
1908 }
1909
1910
1911 void TabWorkArea::updateTabTexts()
1912 {
1913         size_t n = count();
1914         if (n == 0)
1915                 return;
1916         std::list<DisplayPath> paths;
1917         typedef std::list<DisplayPath>::iterator It;
1918
1919         // collect full names first: path into postfix, empty prefix and
1920         // filename without extension
1921         for (size_t i = 0; i < n; ++i) {
1922                 GuiWorkArea * i_wa = workArea(i);
1923                 FileName const fn = i_wa->bufferView().buffer().fileName();
1924                 paths.push_back(DisplayPath(i, fn));
1925         }
1926
1927         // go through path segments and see if it helps to make the path more unique
1928         bool somethingChanged = true;
1929         bool allFinal = false;
1930         while (somethingChanged && !allFinal) {
1931                 // adding path segments changes order
1932                 paths.sort();
1933
1934                 LYXERR(Debug::GUI, "updateTabTexts() iteration start");
1935                 somethingChanged = false;
1936                 allFinal = true;
1937
1938                 // find segments which are not unique (i.e. non-atomic)
1939                 It it = paths.begin();
1940                 It segStart = it;
1941                 QString segString = it->displayString();
1942                 for (; it != paths.end(); ++it) {
1943                         // look to the next item
1944                         It next = it;
1945                         ++next;
1946
1947                         // final?
1948                         allFinal = allFinal && it->final();
1949
1950                         LYXERR(Debug::GUI, "it = " << it->abs()
1951                                << " => " << it->displayString());
1952
1953                         // still the same segment?
1954                         QString nextString;
1955                         if ((next != paths.end()
1956                              && (nextString = next->displayString()) == segString))
1957                                 continue;
1958                         LYXERR(Debug::GUI, "segment ended");
1959
1960                         // only a trivial one with one element?
1961                         if (it == segStart) {
1962                                 // start new segment
1963                                 segStart = next;
1964                                 segString = nextString;
1965                                 continue;
1966                         }
1967
1968                         // we found a non-atomic segment segStart <= sit <= it < next.
1969                         // Shift path segments and hope for the best
1970                         // that it makes the path more unique.
1971                         somethingChanged = true;
1972                         It sit = segStart;
1973                         // this is ok for the reason mentioned  in the previous comment.
1974                         // coverity[INVALIDATE_ITERATOR]
1975                         QString dspString = sit->forecastPathString();
1976                         LYXERR(Debug::GUI, "first forecast found for "
1977                                << sit->abs() << " => " << dspString);
1978                         ++sit;
1979                         bool moreUnique = false;
1980                         for (; sit != next; ++sit) {
1981                                 if (sit->forecastPathString() != dspString) {
1982                                         LYXERR(Debug::GUI, "different forecast found for "
1983                                                 << sit->abs() << " => " << sit->forecastPathString());
1984                                         moreUnique = true;
1985                                         break;
1986                                 }
1987                                 LYXERR(Debug::GUI, "same forecast found for "
1988                                         << sit->abs() << " => " << dspString);
1989                         }
1990
1991                         // if the path segment helped, add it. Otherwise add dots
1992                         bool dots = !moreUnique;
1993                         LYXERR(Debug::GUI, "using dots = " << dots);
1994                         for (sit = segStart; sit != next; ++sit) {
1995                                 sit->shiftPathSegment(dots);
1996                                 LYXERR(Debug::GUI, "shifting "
1997                                         << sit->abs() << " => " << sit->displayString());
1998                         }
1999
2000                         // start new segment
2001                         segStart = next;
2002                         segString = nextString;
2003                 }
2004         }
2005
2006         // set new tab titles
2007         for (It it = paths.begin(); it != paths.end(); ++it) {
2008                 int const tab_index = it->tab();
2009                 Buffer const & buf = workArea(tab_index)->bufferView().buffer();
2010                 QString tab_text = it->displayString().replace("&", "&&");
2011                 if (!buf.fileName().empty() && !buf.isClean())
2012                         tab_text += "*";
2013                 QString tab_tooltip = it->abs();
2014                 if (buf.isReadonly()) {
2015                         setTabIcon(tab_index, QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")));
2016                         tab_tooltip = qt_("%1 (read only)").arg(it->abs());
2017                 } else
2018                         setTabIcon(tab_index, QIcon());
2019                 setTabText(tab_index, tab_text);
2020                 setTabToolTip(tab_index, tab_tooltip);
2021         }
2022 }
2023
2024
2025 void TabWorkArea::showContextMenu(const QPoint & pos)
2026 {
2027         // which tab?
2028         clicked_tab_ = static_cast<DragTabBar *>(tabBar())->tabAt(pos);
2029         if (clicked_tab_ == -1)
2030                 return;
2031
2032         // show tab popup
2033         QMenu popup;
2034         popup.addAction(QIcon(getPixmap("images/", "hidetab", "svgz,png")),
2035                 qt_("Hide tab"), this, SLOT(hideCurrentTab()));
2036         popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")),
2037                 qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
2038         popup.exec(tabBar()->mapToGlobal(pos));
2039
2040         clicked_tab_ = -1;
2041 }
2042
2043
2044 void TabWorkArea::moveTab(int fromIndex, int toIndex)
2045 {
2046         QWidget * w = widget(fromIndex);
2047         QIcon icon = tabIcon(fromIndex);
2048         QString text = tabText(fromIndex);
2049
2050         setCurrentIndex(fromIndex);
2051         removeTab(fromIndex);
2052         insertTab(toIndex, w, icon, text);
2053         setCurrentIndex(toIndex);
2054 }
2055
2056
2057 DragTabBar::DragTabBar(QWidget* parent)
2058         : QTabBar(parent)
2059 {
2060         setAcceptDrops(true);
2061         setTabsClosable(!lyxrc.single_close_tab_button);
2062 }
2063
2064
2065 void DragTabBar::mousePressEvent(QMouseEvent * event)
2066 {
2067         if (event->button() == Qt::LeftButton)
2068                 dragStartPos_ = event->pos();
2069         QTabBar::mousePressEvent(event);
2070 }
2071
2072
2073 void DragTabBar::mouseMoveEvent(QMouseEvent * event)
2074 {
2075         // If the left button isn't pressed anymore then return
2076         if (!(event->buttons() & Qt::LeftButton))
2077                 return;
2078
2079         // If the distance is too small then return
2080         if ((event->pos() - dragStartPos_).manhattanLength()
2081             < QApplication::startDragDistance())
2082                 return;
2083
2084         // did we hit something after all?
2085         int tab = tabAt(dragStartPos_);
2086         if (tab == -1)
2087                 return;
2088
2089         // simulate button release to remove highlight from button
2090         int i = currentIndex();
2091         QMouseEvent me(QEvent::MouseButtonRelease, dragStartPos_,
2092                 event->button(), event->buttons(), 0);
2093         QTabBar::mouseReleaseEvent(&me);
2094         setCurrentIndex(i);
2095
2096         // initiate Drag
2097         QDrag * drag = new QDrag(this);
2098         QMimeData * mimeData = new QMimeData;
2099         // a crude way to distinguish tab-reodering drops from other ones
2100         mimeData->setData("action", "tab-reordering") ;
2101         drag->setMimeData(mimeData);
2102
2103         // get tab pixmap as cursor
2104         QRect r = tabRect(tab);
2105         QPixmap pixmap(r.size());
2106         render(&pixmap, - r.topLeft());
2107         drag->setPixmap(pixmap);
2108         drag->exec();
2109 }
2110
2111
2112 void DragTabBar::dragEnterEvent(QDragEnterEvent * event)
2113 {
2114         // Only accept if it's an tab-reordering request
2115         QMimeData const * m = event->mimeData();
2116         QStringList formats = m->formats();
2117         if (formats.contains("action")
2118             && m->data("action") == "tab-reordering")
2119                 event->acceptProposedAction();
2120 }
2121
2122
2123 void DragTabBar::dropEvent(QDropEvent * event)
2124 {
2125         int fromIndex = tabAt(dragStartPos_);
2126         int toIndex = tabAt(event->pos());
2127
2128         // Tell interested objects that
2129         if (fromIndex != toIndex)
2130                 tabMoveRequested(fromIndex, toIndex);
2131         event->acceptProposedAction();
2132 }
2133
2134
2135 } // namespace frontend
2136 } // namespace lyx
2137
2138 #include "moc_GuiWorkArea.cpp"