]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.cpp
don't process generated key events if the system is busy
[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
16 #include "GuiApplication.h"
17 #include "QLPainter.h"
18 #include "QKeySymbol.h"
19 #include "qt_helpers.h"
20
21 #include "LyXView.h"
22
23 #include "BufferView.h"
24 #include "rowpainter.h"
25 #include "debug.h"
26 #include "FuncRequest.h"
27 #include "Color.h"
28 #include "version.h"
29 #include "LyXRC.h"
30
31 #include "support/filetools.h" // LibFileSearch
32 #include "support/os.h"
33 #include "support/convert.h"
34
35 #include "graphics/GraphicsImage.h"
36 #include "graphics/GraphicsLoader.h"
37
38 #include <QLayout>
39 #include <QMainWindow>
40 #include <QMimeData>
41 #include <QUrl>
42 #include <QDragEnterEvent>
43 #include <QPainter>
44 #include <QScrollBar>
45 #include <QTimer>
46 #include <QInputContext>
47
48 #include <boost/bind.hpp>
49 #include <boost/current_function.hpp>
50
51 #ifdef Q_WS_WIN
52 int const CursorWidth = 2;
53 #else
54 int const CursorWidth = 1;
55 #endif
56
57
58 using std::endl;
59 using std::string;
60
61 namespace os = lyx::support::os;
62
63
64 namespace lyx {
65
66 using support::FileName;
67
68 /// return the LyX key state from Qt's
69 static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
70 {
71         key_modifier::state k = key_modifier::none;
72         if (state & Qt::ControlModifier)
73                 k |= key_modifier::ctrl;
74         if (state & Qt::ShiftModifier)
75                 k |= key_modifier::shift;
76         if (state & Qt::AltModifier || state & Qt::MetaModifier)
77                 k |= key_modifier::alt;
78         return k;
79 }
80
81
82 /// return the LyX mouse button state from Qt's
83 static mouse_button::state q_button_state(Qt::MouseButton button)
84 {
85         mouse_button::state b = mouse_button::none;
86         switch (button) {
87                 case Qt::LeftButton:
88                         b = mouse_button::button1;
89                         break;
90                 case Qt::MidButton:
91                         b = mouse_button::button2;
92                         break;
93                 case Qt::RightButton:
94                         b = mouse_button::button3;
95                         break;
96                 default:
97                         break;
98         }
99         return b;
100 }
101
102
103 /// return the LyX mouse button state from Qt's
104 mouse_button::state q_motion_state(Qt::MouseButtons state)
105 {
106         mouse_button::state b = mouse_button::none;
107         if (state & Qt::LeftButton)
108                 b |= mouse_button::button1;
109         if (state & Qt::MidButton)
110                 b |= mouse_button::button2;
111         if (state & Qt::RightButton)
112                 b |= mouse_button::button3;
113         return b;
114 }
115
116
117 namespace frontend {
118
119 class CursorWidget {
120 public:
121         CursorWidget() {}
122
123         void draw(QPainter & painter)
124         {
125                 // FIXME: do something depending on the cursor shape.
126                 if (show_ && rect_.isValid())
127                         painter.fillRect(rect_, color_);
128         }
129
130         void update(int x, int y, int h, CursorShape shape)
131         {
132                 color_ = guiApp->colorCache().get(Color::cursor);
133                 rect_ = QRect(x, y, CursorWidth, h);
134                 shape_ = shape;
135         }
136
137         void show(bool set_show = true) { show_ = set_show; }
138         void hide() { show_ = false; }
139
140         QRect const & rect() { return rect_; }
141
142 private:
143         ///
144         CursorShape shape_;
145         ///
146         bool show_;
147         ///
148         QColor color_;
149         ///
150         QRect rect_;
151 };
152
153
154 // This is a 'heartbeat' generating synthetic mouse move events when the
155 // cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
156 SyntheticMouseEvent::SyntheticMouseEvent()
157         : timeout(200), restart_timeout(true),
158           x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
159 {}
160
161
162 GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
163         : WorkArea(id, lyx_view), need_resize_(false), schedule_redraw_(false),
164           preedit_lines_(1)
165 {
166         screen_ = QPixmap(viewport()->width(), viewport()->height());
167         cursor_ = new frontend::CursorWidget();
168         cursor_->hide();
169
170         setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
171         setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
172         setAcceptDrops(true);
173         setMouseTracking(true);
174         setMinimumSize(100, 70);
175
176         viewport()->setAutoFillBackground(false);
177         // We don't need double-buffering nor SystemBackground on
178         // the viewport because we have our own backing pixmap.
179         viewport()->setAttribute(Qt::WA_NoSystemBackground);
180
181         setFocusPolicy(Qt::WheelFocus);
182
183         viewport()->setCursor(Qt::IBeamCursor);
184
185         resize(w, h);
186
187         synthetic_mouse_event_.timeout.timeout.connect(
188                 boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
189                             this));
190
191         // Initialize the vertical Scroll Bar
192         QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
193                 this, SLOT(adjustViewWithScrollBar(int)));
194
195         // disable context menu for the scrollbar
196         verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
197
198         // PageStep only depends on the viewport height.
199         verticalScrollBar()->setPageStep(viewport()->height());
200
201         LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
202                 << "\n Area width\t" << width()
203                 << "\n Area height\t" << height()
204                 << "\n viewport width\t" << viewport()->width()
205                 << "\n viewport height\t" << viewport()->height()
206                 << endl;
207
208         // Enables input methods for asian languages.
209         // Must be set when creating custom text editing widgets.
210         setAttribute(Qt::WA_InputMethodEnabled, true);
211 }
212
213
214 void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
215 {
216         if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn)
217                 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
218
219         verticalScrollBar()->setTracking(false);
220
221         // do what cursor movement does (some grey)
222         h += height() / 4;
223         int scroll_max_ = std::max(0, h - height());
224
225         verticalScrollBar()->setRange(0, scroll_max_);
226         verticalScrollBar()->setSliderPosition(scroll_pos);
227         verticalScrollBar()->setSingleStep(scroll_line_step);
228         verticalScrollBar()->setValue(scroll_pos);
229
230         verticalScrollBar()->setTracking(true);
231 }
232
233
234 void GuiWorkArea::adjustViewWithScrollBar(int)
235 {
236         scrollBufferView(verticalScrollBar()->sliderPosition());
237 }
238
239
240 void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
241 {
242         if (event->mimeData()->hasUrls())
243                 event->accept();
244         /// \todo Ask lyx-devel is this is enough:
245         /// if (event->mimeData()->hasFormat("text/plain"))
246         ///     event->acceptProposedAction();
247 }
248
249
250 void GuiWorkArea::dropEvent(QDropEvent* event)
251 {
252         QList<QUrl> files = event->mimeData()->urls();
253         if (files.isEmpty())
254                 return;
255
256         LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl;
257         for (int i = 0; i!=files.size(); ++i) {
258                 string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
259                 if (!file.empty())
260                         dispatch(FuncRequest(LFUN_FILE_OPEN, file));
261         }
262 }
263
264
265 void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
266 {
267         // No need to do anything if we didn't change views...
268 //      if (theApp() == 0 || &lyx_view_ == theApp()->currentView())
269 //              return;
270
271         theApp()->setCurrentView(lyx_view_);
272
273         // Repaint the whole screen.
274         // Note: this is different from redraw() as only the backing pixmap
275         // will be redrawn, which is cheap.
276         viewport()->repaint();
277
278         // FIXME: it would be better to send a signal "newBuffer()"
279         // in BufferList that could be connected to the different tabbars.
280         lyx_view_.updateTab();
281
282         startBlinkingCursor();
283 }
284
285
286 void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
287 {
288         stopBlinkingCursor();
289 }
290
291
292 void GuiWorkArea::mousePressEvent(QMouseEvent * e)
293 {
294         if (dc_event_.active && dc_event_ == *e) {
295                 dc_event_.active = false;
296                 FuncRequest cmd(LFUN_MOUSE_TRIPLE,
297                         e->x(), e->y(),
298                         q_button_state(e->button()));
299                 dispatch(cmd);
300                 return;
301         }
302
303         inputContext()->reset();
304
305         FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
306                 q_button_state(e->button()));
307         dispatch(cmd, q_key_state(e->modifiers()));
308 }
309
310
311 void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
312 {
313         if (synthetic_mouse_event_.timeout.running())
314                 synthetic_mouse_event_.timeout.stop();
315
316         FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
317                               q_button_state(e->button()));
318         dispatch(cmd);
319 }
320
321
322 void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
323 {
324         // we kill the triple click if we move
325         doubleClickTimeout();
326         FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
327                               q_motion_state(e->buttons()));
328
329         // If we're above or below the work area...
330         if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
331                 // Make sure only a synthetic event can cause a page scroll,
332                 // so they come at a steady rate:
333                 if (e->y() <= 20)
334                         // _Force_ a scroll up:
335                         cmd.y = -40;
336                 else
337                         cmd.y = viewport()->height();
338                 // Store the event, to be handled when the timeout expires.
339                 synthetic_mouse_event_.cmd = cmd;
340
341                 if (synthetic_mouse_event_.timeout.running())
342                         // Discard the event. Note that it _may_ be handled
343                         // when the timeout expires if
344                         // synthetic_mouse_event_.cmd has not been overwritten.
345                         // Ie, when the timeout expires, we handle the
346                         // most recent event but discard all others that
347                         // occurred after the one used to start the timeout
348                         // in the first place.
349                         return;
350                 else {
351                         synthetic_mouse_event_.restart_timeout = true;
352                         synthetic_mouse_event_.timeout.start();
353                         // Fall through to handle this event...
354                 }
355
356         } else if (synthetic_mouse_event_.timeout.running()) {
357                 // Store the event, to be possibly handled when the timeout
358                 // expires.
359                 // Once the timeout has expired, normal control is returned
360                 // to mouseMoveEvent (restart_timeout = false).
361                 // This results in a much smoother 'feel' when moving the
362                 // mouse back into the work area.
363                 synthetic_mouse_event_.cmd = cmd;
364                 synthetic_mouse_event_.restart_timeout = false;
365                 return;
366         }
367
368         // Has anything changed on-screen since the last QMouseEvent
369         // was received?
370         double const scrollbar_value = verticalScrollBar()->value();
371         if (e->x() != synthetic_mouse_event_.x_old ||
372             e->y() != synthetic_mouse_event_.y_old ||
373             scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
374                 // Yes it has. Store the params used to check this.
375                 synthetic_mouse_event_.x_old = e->x();
376                 synthetic_mouse_event_.y_old = e->y();
377                 synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
378
379                 // ... and dispatch the event to the LyX core.
380                 dispatch(cmd);
381         }
382 }
383
384
385 void GuiWorkArea::wheelEvent(QWheelEvent * e)
386 {
387         // Wheel rotation by one notch results in a delta() of 120 (see
388         // documentation of QWheelEvent)
389         int const lines = qApp->wheelScrollLines() * e->delta() / 120;
390         verticalScrollBar()->setValue(verticalScrollBar()->value() -
391                         lines *  verticalScrollBar()->singleStep());
392         adjustViewWithScrollBar();
393 }
394
395
396 void GuiWorkArea::generateSyntheticMouseEvent()
397 {
398 // Set things off to generate the _next_ 'pseudo' event.
399         if (synthetic_mouse_event_.restart_timeout)
400                 synthetic_mouse_event_.timeout.start();
401
402         // Has anything changed on-screen since the last timeout signal
403         // was received?
404         double const scrollbar_value = verticalScrollBar()->value();
405         if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
406                 // Yes it has. Store the params used to check this.
407                 synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
408
409                 // ... and dispatch the event to the LyX core.
410                 dispatch(synthetic_mouse_event_.cmd);
411         }
412 }
413
414
415 void GuiWorkArea::keyPressEvent(QKeyEvent * e)
416 {
417         // do nothing if there are other events
418         // (the auto repeated events come too fast)
419         if(e->isAutoRepeat() && QCoreApplication::hasPendingEvents()) {
420                 LYXERR(Debug::KEY)      << BOOST_CURRENT_FUNCTION << endl
421                                                         << "key ignored" << endl;
422                 e->ignore();
423                 return;
424         }
425
426         LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
427                 << " count=" << e->count()
428                 << " text=" << fromqstr(e->text())
429                 << " isAutoRepeat=" << e->isAutoRepeat()
430                 << " key=" << e->key()
431                 << endl;
432
433         boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
434         sym->set(e);
435         processKeySym(sym, q_key_state(e->modifiers()));
436 }
437
438 void GuiWorkArea::doubleClickTimeout() {
439         dc_event_.active = false;
440 }
441
442 void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
443 {
444         dc_event_ = double_click(e);
445         QTimer::singleShot(QApplication::doubleClickInterval(), this,
446                            SLOT(doubleClickTimeout()));
447         FuncRequest cmd(LFUN_MOUSE_DOUBLE,
448                         e->x(), e->y(),
449                         q_button_state(e->button()));
450         dispatch(cmd);
451 }
452
453
454 void GuiWorkArea::resizeEvent(QResizeEvent * ev)
455 {
456         QAbstractScrollArea::resizeEvent(ev);
457         need_resize_ = true;
458 }
459
460
461 void GuiWorkArea::update(int x, int y, int w, int h)
462 {
463         viewport()->repaint(x, y, w, h);
464 }
465
466
467 void GuiWorkArea::doGreyOut(QLPainter & pain)
468 {
469         pain.fillRectangle(0, 0, width(), height(),
470                 Color::bottomarea);
471
472         //if (!lyxrc.show_banner)
473         //      return;
474         LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl;
475         /// The text to be written on top of the pixmap
476         QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
477         FileName const file = support::libFileSearch("images", "banner", "png");
478         if (file.empty())
479                 return;
480
481         QPixmap pm(toqstr(file.absFilename()));
482         if (!pm) {
483                 lyxerr << "could not load splash screen: '" << file << "'" << endl;
484                 return;
485         }
486
487         QFont font;
488         // The font used to display the version info
489         font.setStyleHint(QFont::SansSerif);
490         font.setWeight(QFont::Bold);
491         font.setPointSize(convert<int>(lyxrc.font_sizes[Font::SIZE_LARGE]));
492
493         int const w = pm.width();
494         int const h = pm.height();
495
496         int x = (width() - w) / 2;
497         int y = (height() - h) / 2;
498
499         pain.drawPixmap(x, y, pm);
500
501         x += 260;
502         y += 270;
503
504         pain.setPen(QColor(255, 255, 0));
505         pain.setFont(font);
506         pain.drawText(x, y, text);
507 }
508
509
510 void GuiWorkArea::paintEvent(QPaintEvent * ev)
511 {
512         QRect const rc = ev->rect(); 
513         /*
514         LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
515                 << " y: " << rc.y()
516                 << " w: " << rc.width()
517                 << " h: " << rc.height() << endl;
518         */
519
520         if (need_resize_) {
521                 verticalScrollBar()->setPageStep(viewport()->height());
522                 screen_ = QPixmap(viewport()->width(), viewport()->height());
523                 resizeBufferView();
524                 updateScreen();
525                 need_resize_ = false;
526         }
527
528         QPainter pain(viewport());
529         pain.drawPixmap(rc, screen_, rc);
530         cursor_->draw(pain);
531 }
532
533
534 void GuiWorkArea::expose(int x, int y, int w, int h)
535 {
536         updateScreen();
537         update(x, y, w, h);
538 }
539
540
541 void GuiWorkArea::updateScreen()
542 {
543         QLPainter pain(&screen_);
544
545         if (greyed_out_) {
546                 LYXERR(Debug::GUI) << "splash screen requested" << endl;
547                 verticalScrollBar()->hide();
548                 doGreyOut(pain);
549                 return;
550         }
551
552         verticalScrollBar()->show();
553         paintText(*buffer_view_, pain);
554 }
555
556
557 void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
558 {
559         if (schedule_redraw_) {
560                 if (buffer_view_ && buffer_view_->buffer()) {
561                         buffer_view_->update(Update::Force);
562                         updateScreen();
563                         viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
564                 }
565                 schedule_redraw_ = false;
566                 // Show the cursor immediately after the update.
567                 hideCursor();
568                 toggleCursor();
569                 return;
570         }
571
572         cursor_->update(x, y, h, shape);
573         cursor_->show();
574         viewport()->update(cursor_->rect());
575 }
576
577
578 void GuiWorkArea::removeCursor()
579 {
580         cursor_->hide();
581         //if (!qApp->focusWidget())
582                 viewport()->update(cursor_->rect());
583 }
584
585
586 void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
587 {
588         QString const & commit_string = e->commitString();
589         docstring const & preedit_string
590                 = qstring_to_ucs4(e->preeditString());
591
592         if(greyed_out_) {
593                 e->ignore();
594                 return;
595         }
596
597         if (!commit_string.isEmpty()) {
598
599                 LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
600                         << " preeditString =" << fromqstr(e->preeditString())
601                         << " commitString  =" << fromqstr(e->commitString())
602                         << endl;
603
604                 int key = 0;
605
606                 // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
607                 for (int i = 0; i < commit_string.size(); ++i) {
608                         QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
609                         keyPressEvent(&ev);
610                 }
611         }
612
613         // Hide the cursor during the kana-kanji transformation. 
614         if (preedit_string.empty())
615                 startBlinkingCursor();
616         else
617                 stopBlinkingCursor();
618
619         // last_width : for checking if last preedit string was/wasn't empty.
620         static bool last_width = false;
621         if (!last_width && preedit_string.empty()) {
622                 // if last_width is last length of preedit string. 
623                 e->accept();
624                 return;
625         }
626
627         QLPainter pain(&screen_);
628         buffer_view_->updateMetrics(false);
629         paintText(*buffer_view_, pain);
630         Font font = buffer_view_->cursor().getFont();
631         FontMetrics const & fm = theFontMetrics(font);
632         int height = fm.maxHeight();
633         int cur_x = cursor_->rect().left();
634         int cur_y = cursor_->rect().bottom();
635
636         // redraw area of preedit string.
637         update(0, cur_y - height, GuiWorkArea::width(),
638                 (height + 1) * preedit_lines_);
639
640         if (preedit_string.empty()) {
641                 last_width = false;
642                 preedit_lines_ = 1;
643                 e->accept();
644                 return;
645         }
646         last_width = true;
647
648         // att : stores an IM attribute.
649         QList<QInputMethodEvent::Attribute> const & att = e->attributes();
650
651         // get attributes of input method cursor.
652         // cursor_pos : cursor position in preedit string.
653         size_t cursor_pos = 0;
654         bool cursor_is_visible = false;
655         for (int i = 0; i < att.size(); ++i) {
656                 if (att.at(i).type == QInputMethodEvent::Cursor) {
657                         cursor_pos = att.at(i).start;
658                         cursor_is_visible = att.at(i).length != 0;
659                         break;
660                 }
661         }
662
663         size_t preedit_length = preedit_string.length();
664
665         // get position of selection in input method.
666         // FIXME: isn't there a way to do this simplier?
667         // rStart : cursor position in selected string in IM.
668         size_t rStart = 0;
669         // rLength : selected string length in IM.
670         size_t rLength = 0;
671         if (cursor_pos < preedit_length) {
672                 for (int i = 0; i < att.size(); ++i) {
673                         if (att.at(i).type == QInputMethodEvent::TextFormat) {
674                                 if (att.at(i).start <= int(cursor_pos)
675                                         && int(cursor_pos) < att.at(i).start + att.at(i).length) {
676                                                 rStart = att.at(i).start;
677                                                 rLength = att.at(i).length;
678                                                 if (!cursor_is_visible)
679                                                         cursor_pos += rLength;
680                                                 break;
681                                 }
682                         }
683                 }
684         }
685         else {
686                 rStart = cursor_pos;
687                 rLength = 0;
688         }
689
690         int const right_margin = rightMargin();
691         Painter::preedit_style ps;
692         // Most often there would be only one line:
693         preedit_lines_ = 1;
694         for (size_t pos = 0; pos != preedit_length; ++pos) {
695                 char_type const typed_char = preedit_string[pos];
696                 // reset preedit string style
697                 ps = Painter::preedit_default;
698
699                 // if we reached the right extremity of the screen, go to next line.
700                 if (cur_x + fm.width(typed_char) > GuiWorkArea::width() - right_margin) {
701                         cur_x = right_margin;
702                         cur_y += height + 1;
703                         ++preedit_lines_;
704                 }
705                 // preedit strings are displayed with dashed underline
706                 // and partial strings are displayed white on black indicating
707                 // that we are in selecting mode in the input method.
708                 // FIXME: rLength == preedit_length is not a changing condition
709                 // FIXME: should be put out of the loop.
710                 if (pos >= rStart 
711                         && pos < rStart + rLength
712                         && !(cursor_pos < rLength && rLength == preedit_length))
713                         ps = Painter::preedit_selecting;
714
715                 if (pos == cursor_pos
716                         && (cursor_pos < rLength && rLength == preedit_length))
717                         ps = Painter::preedit_cursor;
718
719                 // draw one character and update cur_x.
720                 cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
721         }
722
723         // update the preedit string screen area.
724         update(0, cur_y - preedit_lines_*height, GuiWorkArea::width(),
725                 (height + 1) * preedit_lines_);
726
727         // Don't forget to accept the event!
728         e->accept();
729 }
730
731
732 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
733 {
734         QRect cur_r(0,0,0,0);
735         switch (query) {
736                 // this is the CJK-specific composition window position.
737                 case Qt::ImMicroFocus:
738                         cur_r = cursor_->rect();
739                         if (preedit_lines_ != 1)
740                                 cur_r.moveLeft(10);
741                         cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
742                         // return lower right of cursor in LyX.
743                         return cur_r;
744                 default:
745                         return QWidget::inputMethodQuery(query);
746         }
747 }
748
749 } // namespace frontend
750 } // namespace lyx
751
752 #include "GuiWorkArea_moc.cpp"