Qt 4.8
qwsinputcontext_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwsinputcontext_p.h"
43 #include "qinputcontext_p.h"
44 #include "qwsdisplay_qws.h"
45 #include "qwsevent_qws.h"
46 #include "private/qwscommand_qws_p.h"
47 #include "qwindowsystem_qws.h"
48 #include "qevent.h"
49 #include "qtextformat.h"
50 
51 #include <qbuffer.h>
52 
53 #include <qdebug.h>
54 
55 #ifndef QT_NO_QWS_INPUTMETHODS
56 
58 
59 static QWidget* activeWidget = 0;
60 
61 //#define EXTRA_DEBUG
62 
64  :QInputContext(parent)
65 {
66 }
67 
69 {
71 }
72 
73 
75 {
76  QWidget *oldFocus = focusWidget();
77  if (oldFocus == w)
78  return;
79 
80  if (w) {
82  } else {
83  if (oldFocus)
84  QWSInputContext::updateImeStatus(oldFocus, false);
85  }
86 
87  if (oldFocus) {
88  QWidget *tlw = oldFocus->window();
89  int winid = tlw->internalWinId();
90 
91  int widgetid = oldFocus->internalWinId();
93  }
94 
96 
97  if (!w)
98  return;
99 
100  QWidget *tlw = w->window();
101  int winid = tlw->winId();
102 
103  int widgetid = w->winId();
105 
106  //setfocus ???
107 
108  update();
109 }
110 
111 
113 {
114  if (w == QT_PREPEND_NAMESPACE(activeWidget))
115  QT_PREPEND_NAMESPACE(activeWidget) = 0;
117 }
118 
120 {
121  QWidget *w = focusWidget();
122  if (!w)
123  return;
124 
125  QWidget *tlw = w->window();
126  int winid = tlw->winId();
127 
128  int widgetid = w->winId();
130 
131 }
132 
134 {
135  if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)
137 }
138 
140 {
141  return QT_PREPEND_NAMESPACE(activeWidget);
142 }
143 
144 
146 {
147  return QT_PREPEND_NAMESPACE(activeWidget) != 0;
148 }
149 
151 {
153  QVariant result = w->inputMethodQuery(type);
154  QWidget *tlw = w->window();
155  int winId = tlw->winId();
156 
157  if ( type == Qt::ImMicroFocus ) {
158  // translate to relative to tlw
159  QRect mf = result.toRect();
160  mf.moveTopLeft(w->mapTo(tlw,mf.topLeft()));
161  result = mf;
162  }
163 
165 
166  return false;
167 }
168 
170 {
171  Q_UNUSED(e);
172  qDebug("### QWSInputContext::translateIMInitEvent not implemented ###");
173  return false;
174 }
175 
177 {
179  QString preedit;
180  QString commit;
181 
182  stream >> preedit;
183  stream >> commit;
184 
185  if (preedit.isEmpty() && QT_PREPEND_NAMESPACE(activeWidget))
186  w = QT_PREPEND_NAMESPACE(activeWidget);
187 
188  QInputContext *qic = w->inputContext();
189  if (!qic)
190  return false;
191 
193 
194 
195  while (!stream.atEnd()) {
196  int type = -1;
197  int start = -1;
198  int length = -1;
199  QVariant data;
200  stream >> type >> start >> length >> data;
201  if (stream.status() != QDataStream::Ok) {
202  qWarning("corrupted QWSIMEvent");
203  //qic->reset(); //???
204  return false;
205  }
206  if (type == QInputMethodEvent::TextFormat)
207  data = qic->standardFormat(static_cast<QInputContext::StandardFormat>(data.toInt()));
208  attrs << QInputMethodEvent::Attribute(static_cast<QInputMethodEvent::AttributeType>(type), start, length, data);
209  }
210 #ifdef EXTRA_DEBUG
211  qDebug() << "preedit" << preedit << "len" << preedit.length() <<"commit" << commit << "len" << commit.length()
212  << "n attr" << attrs.count();
213 #endif
214 
215  if (preedit.isEmpty())
216  QT_PREPEND_NAMESPACE(activeWidget) = 0;
217  else
218  QT_PREPEND_NAMESPACE(activeWidget) = w;
219 
220 
221  QInputMethodEvent ime(preedit, attrs);
222  if (!commit.isEmpty() || e->simpleData.replaceLength > 0)
224 
225 
226  extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_qws.cpp
227  qt_sendSpontaneousEvent(w, &ime);
228 
229  return true;
230 }
231 
233 
235 {
236  Q_UNUSED(hasFocus);
237 
239  return;
241 }
242 
243 
245 
246 #endif // QT_NO_QWS_INPUTMETHODS
void mouseHandler(int x, QMouseEvent *event)
This function can be reimplemented in a subclass to handle mouse press, release, double-click, and move events within the preedit text.
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Status status() const
Returns the status of the data stream.
int type
Definition: qmetatype.cpp:239
static bool translateIMQueryEvent(QWidget *w, const QWSIMQueryEvent *e)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
static QWSDisplay * qwsDisplay()
static QWidget * activeWidget()
void sendIMResponse(int winId, int property, const QVariant &result)
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void sendIMUpdate(int type, int winId, int widgetid)
void setCommitString(const QString &commitString, int replaceFrom=0, int replaceLength=0)
Sets the commit string to commitString.
Definition: qevent.cpp:2042
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QWSInputContext(QObject *parent=0)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
Q_CORE_EXPORT void qDebug(const char *,...)
void sendIMMouseEvent(int index, bool isPress)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void widgetDestroyed(QWidget *w)
This virtual function is called when the specified widget is destroyed.
static FILE * stream
static void updateImeStatus(QWidget *w, bool hasFocus)
QTextFormat standardFormat(StandardFormat s) const
Returns a QTextFormat object that specifies the format for component s.
QByteArray streamingData
Definition: qwsevent_qws.h:388
void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
Q_CORE_EXPORT void qWarning(const char *,...)
struct QWSIMQueryEvent::SimpleData simpleData
static const char * data(const QByteArray &arr)
bool isComposing() const
This function indicates whether InputMethodStart event had been sent to the current focus widget...
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
static bool translateIMEvent(QWidget *w, const QWSIMEvent *e)
Q_GUI_EXPORT void(* qt_qws_inputMethodStatusChanged)(QWidget *)=0
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
void reset()
This function can be reimplemented in a subclass to reset the state of the input method.
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static QWidget * activeWidget
virtual void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
static bool translateIMInitEvent(const QWSIMInitEvent *e)
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void widgetDestroyed(QWidget *w)
This virtual function is called when the specified widget is destroyed.
struct QWSIMEvent::SimpleData simpleData
void update()
This virtual function is called when a state in the focus widget has changed.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288