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