Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | List of all members
QWinInputContext Class Reference

#include <qwininputcontext_p.h>

Inheritance diagram for QWinInputContext:
QInputContext QObject

Public Functions

bool composition (LPARAM lparam)
 
bool endComposition ()
 
virtual QString identifierName ()
 This function must be implemented in any subclasses to return the identifier name of the input method. More...
 
virtual bool isComposing () const
 This function indicates whether InputMethodStart event had been sent to the current focus widget. More...
 
virtual QString language ()
 This function must be implemented in any subclasses to return a language code (e. More...
 
virtual 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. More...
 
 QWinInputContext (QObject *parent=0)
 
int reconvertString (RECONVERTSTRING *reconv)
 
virtual void reset ()
 This function can be reimplemented in a subclass to reset the state of the input method. More...
 
virtual void setFocusWidget (QWidget *w)
 Sets the widget that has an input focus for this input context. More...
 
bool startComposition ()
 
virtual void update ()
 This virtual function is called when a state in the focus widget has changed. More...
 
virtual ~QWinInputContext ()
 
- Public Functions inherited from QInputContext
virtual QList< QAction * > actions ()
 This is a preliminary interface for Qt 4. More...
 
virtual bool filterEvent (const QEvent *event)
 This function can be reimplemented in a subclass to filter input events. More...
 
QWidgetfocusWidget () const
 Returns the widget that has an input focus for this input context. More...
 
virtual QFont font () const
 Returns the font of the current input widget. More...
 
 QInputContext (QObject *parent=0)
 Constructs an input context with the given parent. More...
 
void sendEvent (const QInputMethodEvent &event)
 Sends an input method event specified by event to the current focus widget. More...
 
QTextFormat standardFormat (StandardFormat s) const
 Returns a QTextFormat object that specifies the format for component s. More...
 
virtual void widgetDestroyed (QWidget *w)
 This virtual function is called when the specified widget is destroyed. More...
 
virtual bool x11FilterEvent (QWidget *keywidget, XEvent *event)
 This function may be overridden only if input method is depending on X11 and you need raw XEvent. More...
 
virtual ~QInputContext ()
 Destroys the input context. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static LRESULT DefWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static void enable (QWidget *w, bool e)
 
static void enablePopupChild (QWidget *w, bool e)
 
static void TranslateMessage (const MSG *msg)
 
static void updateImeStatus (QWidget *w, bool hasFocus)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Private Functions

void init ()
 

Properties

bool recursionGuard
 

Additional Inherited Members

- Public Types inherited from QInputContext
enum  StandardFormat { PreeditFormat, SelectionFormat }
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 76 of file qwininputcontext_p.h.

Constructors and Destructors

◆ QWinInputContext()

QWinInputContext::QWinInputContext ( QObject parent = 0)
explicit

Definition at line 215 of file qwininputcontext_win.cpp.

216  : QInputContext(parent), recursionGuard(false)
217 {
218 #ifndef Q_WS_WINCE
220  if (ver & QSysInfo::WV_NT_based && ver >= QSysInfo::WV_VISTA) {
221  // Since the IsValidLanguageGroup/IsValidLocale functions always return true on
222  // Vista, check the Keyboard Layouts for enabling RTL.
223  UINT nLayouts = GetKeyboardLayoutList(0, 0);
224  if (nLayouts) {
225  HKL *lpList = new HKL[nLayouts];
226  GetKeyboardLayoutList(nLayouts, lpList);
227  for (int i = 0; i<(int)nLayouts; i++) {
228  WORD plangid = PRIMARYLANGID((quintptr)lpList[i]);
229  if (plangid == LANG_ARABIC
230  || plangid == LANG_HEBREW
231  || plangid == LANG_FARSI
232 #ifdef LANG_SYRIAC
233  || plangid == LANG_SYRIAC
234 #endif
235  ) {
236  qt_use_rtl_extensions = true;
237  break;
238  }
239  }
240  delete []lpList;
241  }
242  } else {
243  // figure out whether a RTL language is installed
244  qt_use_rtl_extensions = IsValidLanguageGroup(LGRPID_ARABIC, LGRPID_INSTALLED)
245  || IsValidLanguageGroup(LGRPID_HEBREW, LGRPID_INSTALLED)
246  || IsValidLocale(MAKELCID(MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
247  || IsValidLocale(MAKELCID(MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
248 #ifdef LANG_SYRIAC
249  || IsValidLocale(MAKELCID(MAKELANGID(LANG_SYRIAC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
250 #endif
251  || IsValidLocale(MAKELCID(MAKELANGID(LANG_FARSI, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED);
252  }
253 #else
254  qt_use_rtl_extensions = false;
255 #endif
256 
257  WM_MSIME_MOUSE = RegisterWindowMessage(L"MSIMEMouseOperation");
258 }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
#define LGRPID_ARABIC
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
#define LGRPID_HEBREW
QInputContext(QObject *parent=0)
Constructs an input context with the given parent.
static DWORD WM_MSIME_MOUSE
#define LANG_SYRIAC
bool qt_use_rtl_extensions
WinVersion
This enum provides symbolic names for the various versions of the Windows operating system...
Definition: qglobal.h:1579
#define LGRPID_INSTALLED

◆ ~QWinInputContext()

QWinInputContext::~QWinInputContext ( )
virtual

Definition at line 260 of file qwininputcontext_win.cpp.

261 {
262  // release active input method if we have one
263  if (aimm) {
264  aimmpump->End();
265  aimmpump->Release();
266  aimm->Deactivate();
267  aimm->Release();
268  aimm = 0;
269  aimmpump = 0;
270  }
271  delete imeComposition;
272  imeComposition = 0;
273 }
static QString * imeComposition
static IActiveIMMMessagePumpOwner * aimmpump
static IActiveIMMApp * aimm

Functions

◆ composition()

bool QWinInputContext::composition ( LPARAM  lparam)

Definition at line 536 of file qwininputcontext_win.cpp.

Referenced by QtWndProc().

537 {
538 #ifdef Q_IME_DEBUG
539  QString str;
540  if (lParam & GCS_RESULTSTR)
541  str += "RESULTSTR ";
542  if (lParam & GCS_COMPSTR)
543  str += "COMPSTR ";
544  if (lParam & GCS_COMPATTR)
545  str += "COMPATTR ";
546  if (lParam & GCS_CURSORPOS)
547  str += "CURSORPOS ";
548  if (lParam & GCS_COMPCLAUSE)
549  str += "COMPCLAUSE ";
550  if (lParam & CS_INSERTCHAR)
551  str += "INSERTCHAR ";
552  if (lParam & CS_NOMOVECARET)
553  str += "NOMOVECARET ";
554  qDebug("composition, lParam=(%x) %s imePosition=%d", lParam, str.latin1(), imePosition);
555 #endif
556 
557  bool result = true;
558 
559  if(!lParam)
560  // bogus event
561  return true;
562 
564  if (fw) {
566  HIMC imc = getContext(fw->effectiveWinId());
568  if (lParam & (GCS_COMPSTR | GCS_COMPATTR | GCS_CURSORPOS)) {
569  if (imePosition == -1)
570  // need to send a start event
572 
573  // some intermediate composition result
574  int selStart, selLength;
575  *imeComposition = getString(imc, GCS_COMPSTR, &selStart, &selLength);
577  if (lParam & CS_INSERTCHAR && lParam & CS_NOMOVECARET) {
578  // make korean work correctly. Hope this is correct for all IMEs
579  selStart = 0;
580  selLength = imeComposition->length();
581  }
582  if(selLength == 0)
583  selStart = 0;
584 
586  if (selStart > 0)
589  if (selLength)
590  attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, selStart, selLength,
592  if (selStart + selLength < imeComposition->length())
593  attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, selStart + selLength,
594  imeComposition->length() - selStart - selLength,
596  if(imePosition >= 0)
598 
599  e = QInputMethodEvent(*imeComposition, attrs);
600  }
601  if (lParam & GCS_RESULTSTR) {
602  if(imePosition == -1)
604  // a fixed result, return the converted string
605  *imeComposition = getString(imc, GCS_RESULTSTR);
606  imePosition = -1;
607  e.setCommitString(*imeComposition);
609  }
610  result = qt_sendSpontaneousEvent(fw, &e);
611  update();
612  releaseContext(fw->effectiveWinId(), imc);
613  }
614 #ifdef Q_IME_DEBUG
615  qDebug("imecomposition: cursor pos at %d, str=%x", imePosition, str[0].unicode());
616 #endif
617  return result;
618 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static int imePosition
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
static QString * imeComposition
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
virtual void update()
This virtual function is called when a state in the focus widget has changed.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int getCursorPosition(HIMC himc)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
QTextFormat standardFormat(StandardFormat s) const
Returns a QTextFormat object that specifies the format for component s.
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
static HIMC getContext(HWND wnd)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static void releaseContext(HWND wnd, HIMC imc)
static QString getString(HIMC himc, DWORD dwindex, int *selStart=0, int *selLength=0)
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ DefWindowProc()

LRESULT QWinInputContext::DefWindowProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 361 of file qwininputcontext_win.cpp.

Referenced by QtWndProc().

362 {
363  LRESULT retval;
364  if (!aimm || aimm->OnDefWindowProc(hwnd, msg, wParam, lParam, &retval) != S_OK)
365  {
366  retval = ::DefWindowProc(hwnd, msg, wParam, lParam);
367  }
368  return retval;
369 }
static IActiveIMMApp * aimm
static LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

◆ enable()

void QWinInputContext::enable ( QWidget w,
bool  e 
)
static

Definition at line 727 of file qwininputcontext_win.cpp.

Referenced by enablePopupChild(), and updateImeStatus().

728 {
729  if(w) {
730 #ifdef Q_IME_DEBUG
731  qDebug("enable: w=%s, enable = %s", w ? w->className() : "(null)" , e ? "true" : "false");
732 #endif
734  return;
735  if(aimm) {
736  HIMC oldimc;
737  if (!e) {
738  aimm->AssociateContext(w->effectiveWinId(), 0, &oldimc);
739  if (!defaultContext)
740  defaultContext = oldimc;
741  } else if (defaultContext) {
742  aimm->AssociateContext(w->effectiveWinId(), defaultContext, &oldimc);
743  }
744  } else {
745  // update ime status on the widget
747  if (p)
748  enableIme(p, e);
749  }
750  }
751 }
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
void enableIme(QWidget *w, bool value)
static HIMC defaultContext
static IActiveIMMApp * aimm

◆ enablePopupChild()

void QWinInputContext::enablePopupChild ( QWidget w,
bool  e 
)
static

Definition at line 703 of file qwininputcontext_win.cpp.

Referenced by updateImeStatus().

704 {
705  if (aimm) {
706  enable(w, e);
707  return;
708  }
709 
710  if (!w || !isInPopup(w))
711  return;
712 #ifdef Q_IME_DEBUG
713  qDebug("enablePopupChild: w=%s, enable = %s", w ? w->className() : "(null)" , e ? "true" : "false");
714 #endif
716  if (parent) {
717  // update ime status of the normal toplevel parent of the popup
718  enableIme(parent, e);
719  }
720  QWidget *toplevel = w->window();
721  if (toplevel) {
722  // update ime status of the toplevel popup
723  enableIme(toplevel, e);
724  }
725 }
static void enable(QWidget *w, bool e)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Q_CORE_EXPORT void qDebug(const char *,...)
void enableIme(QWidget *w, bool value)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static IActiveIMMApp * aimm
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
bool isInPopup(QWidget *w)
QWidget * findParentforPopup(QWidget *w)

◆ endComposition()

bool QWinInputContext::endComposition ( )

Definition at line 438 of file qwininputcontext_win.cpp.

Referenced by QtWndProc().

439 {
440  QWidget *fw = focusWidget();
441 #ifdef Q_IME_DEBUG
442  qDebug("endComposition! fw = %s", fw ? fw->className() : "(null)");
443 #endif
444  bool result = true;
445  if(imePosition == -1 || recursionGuard)
446  return result;
447 
448  // Googles Pinyin Input Method likes to call endComposition again
449  // when we call notifyIME with CPS_CANCEL, so protect ourselves
450  // against that.
451  recursionGuard = true;
452 
453  if (fw) {
455  HIMC imc = getContext(fw->effectiveWinId());
456  notifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
457  releaseContext(fw->effectiveWinId(), imc);
458  if(haveCaret) {
459  DestroyCaret();
460  haveCaret = false;
461  }
462  }
463 
464  if (!fw)
466 
467  if (fw) {
469  result = qt_sendSpontaneousEvent(fw, &e);
470  }
471 
472  if (imeComposition)
474  imePosition = -1;
475 
476  recursionGuard = false;
477 
478  return result;
479 }
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static int imePosition
static QString * imeComposition
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
static HIMC getContext(HWND wnd)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static void releaseContext(HWND wnd, HIMC imc)
static void notifyIME(HIMC imc, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
static bool haveCaret
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ identifierName()

virtual QString QWinInputContext::identifierName ( )
inlinevirtual

This function must be implemented in any subclasses to return the identifier name of the input method.

Return value is the name to identify and specify input methods for the input method switching mechanism and so on. The name has to be consistent with QInputContextPlugin::keys(). The name has to consist of ASCII characters only.

There are two different names with different responsibility in the input method domain. This function returns one of them. Another name is called 'display name' that stands for the name for endusers appeared in a menu and so on.

See also
QInputContextPlugin::keys(), QInputContextPlugin::displayName()

Implements QInputContext.

Definition at line 83 of file qwininputcontext_p.h.

83 { return QLatin1String("win"); }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ init()

void QWinInputContext::init ( )
private

◆ isComposing()

bool QWinInputContext::isComposing ( ) const
virtual

This function indicates whether InputMethodStart event had been sent to the current focus widget.

It is ensured that an input context can send InputMethodCompose or InputMethodEnd event safely if this function returned true.

The state is automatically being tracked through sendEvent().

See also
sendEvent()

Implements QInputContext.

Definition at line 768 of file qwininputcontext_win.cpp.

769 {
770  return imeComposition && !imeComposition->isEmpty();
771 }
static QString * imeComposition
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704

◆ language()

QString QWinInputContext::language ( )
virtual

This function must be implemented in any subclasses to return a language code (e.

g. "zh_CN", "zh_TW", "zh_HK", "ja", "ko", ...) of the input context. If the input context can handle multiple languages, return the currently used one. The name has to be consistent with QInputContextPlugin::language().

This information will be used by language tagging feature in QInputMethodEvent. It is required to distinguish unified han characters correctly. It enables proper font and character code handling. Suppose CJK-awared multilingual web browser (that automatically modifies fonts in CJK-mixed text) and XML editor (that automatically inserts lang attr).

Implements QInputContext.

Definition at line 795 of file qwininputcontext_win.cpp.

796 {
797  return QString();
798 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ mouseHandler()

void QWinInputContext::mouseHandler ( int  x,
QMouseEvent event 
)
virtual

This function can be reimplemented in a subclass to handle mouse press, release, double-click, and move events within the preedit text.

You can use the function to implement mouse-oriented user interface such as text selection or popup menu for candidate selection.

The x parameter is the offset within the string that was sent with the InputMethodCompose event. The alteration boundary of x is ensured as character boundary of preedit string accurately.

The event parameter is the event that was sent to the editor widget. The event type is QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick or QEvent::MouseMove. The event's button and state indicate the kind of operation that was performed.

Reimplemented from QInputContext.

Definition at line 773 of file qwininputcontext_win.cpp.

774 {
775  if(e->type() != QEvent::MouseButtonPress)
776  return;
777 
778  if (pos < 0 || pos > imeComposition->length())
779  reset();
780 
781  // Probably should pass the correct button, but it seems to work fine like this.
782  DWORD button = MK_LBUTTON;
783 
784  QWidget *fw = focusWidget();
785  if (fw) {
787  HIMC himc = getContext(fw->effectiveWinId());
788  HWND ime_wnd = getDefaultIMEWnd(fw->effectiveWinId());
789  SendMessage(ime_wnd, WM_MSIME_MOUSE, MAKELONG(MAKEWORD(button, pos == 0 ? 2 : 1), pos), (LPARAM)himc);
790  releaseContext(fw->effectiveWinId(), himc);
791  }
792  //qDebug("mouseHandler: got value %d pos=%d", ret,pos);
793 }
static QString * imeComposition
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
virtual void reset()
This function can be reimplemented in a subclass to reset the state of the input method.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static DWORD WM_MSIME_MOUSE
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static HIMC getContext(HWND wnd)
static HWND getDefaultIMEWnd(HWND wnd)
static void releaseContext(HWND wnd, HIMC imc)

◆ reconvertString()

int QWinInputContext::reconvertString ( RECONVERTSTRING reconv)

Definition at line 800 of file qwininputcontext_win.cpp.

Referenced by QtWndProc().

801 {
802  QWidget *w = focusWidget();
803  if(!w)
804  return -1;
805 
808  int memSize = sizeof(RECONVERTSTRING)+(surroundingText.length()+1)*sizeof(ushort);
809  // If memory is not allocated, return the required size.
810  if (!reconv) {
811  if (surroundingText.isEmpty())
812  return -1;
813  else
814  return memSize;
815  }
817  // find the word in the surrounding text.
818  QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText);
819  bounds.setPosition(pos);
820  if (bounds.isAtBoundary()) {
821  if (QTextBoundaryFinder::EndWord == bounds.boundaryReasons())
822  bounds.toPreviousBoundary();
823  } else {
824  bounds.toPreviousBoundary();
825  }
826  int startPos = bounds.position();
827  bounds.toNextBoundary();
828  int endPos = bounds.position();
829  // select the text, this will be overwritten by following ime events.
831  attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, startPos, endPos-startPos, QVariant());
832  QInputMethodEvent e(QString(), attrs);
834 
835  reconv->dwSize = memSize;
836  reconv->dwVersion = 0;
837 
838  reconv->dwStrLen = surroundingText.length();
839  reconv->dwStrOffset = sizeof(RECONVERTSTRING);
840  reconv->dwCompStrLen = endPos-startPos;
841  reconv->dwCompStrOffset = startPos*sizeof(ushort);
842  reconv->dwTargetStrLen = reconv->dwCompStrLen;
843  reconv->dwTargetStrOffset = reconv->dwCompStrOffset;
844  memcpy((char*)(reconv+1), surroundingText.utf16(), surroundingText.length()*sizeof(ushort));
845  return memSize;
846 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
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
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
struct tagRECONVERTSTRING RECONVERTSTRING
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
unsigned short ushort
Definition: qglobal.h:995
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QTextBoundaryFinder class provides a way of finding Unicode text boundaries in a string...

◆ reset()

void QWinInputContext::reset ( )
virtual

This function can be reimplemented in a subclass to reset the state of the input method.

This function is called by several widgets to reset input state. For example, a text widget call this function before inserting a text to make widget ready to accept a text.

Default implementation is sufficient for simple input method. You can override this function to reset external input method engines in complex input method. In the case, call QInputContext::reset() to ensure proper termination of inputting.

In a reimplementation of reset(), you must not send any QInputMethodEvent containing preedit text. You can only commit string and attributes; otherwise, you risk breaking input state consistency.

Implements QInputContext.

Definition at line 481 of file qwininputcontext_win.cpp.

Referenced by mouseHandler().

482 {
483  QWidget *fw = focusWidget();
484 
485 #ifdef Q_IME_DEBUG
486  qDebug("sending accept to focus widget %s", fw ? fw->className() : "(null)");
487 #endif
488 
489  if (fw && imePosition != -1) {
491  if (imeComposition)
493  imePosition = -1;
494  qt_sendSpontaneousEvent(fw, &e);
495  }
496 
497  if (imeComposition)
499  imePosition = -1;
500 
501  if (fw) {
503  HIMC imc = getContext(fw->effectiveWinId());
504  notifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
505  releaseContext(fw->effectiveWinId(), imc);
506  }
507 
508 }
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static int imePosition
static QString * imeComposition
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setCommitString(const QString &commitString, int replaceFrom=0, int replaceLength=0)
Sets the commit string to commitString.
Definition: qevent.cpp:2042
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
static HIMC getContext(HWND wnd)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static void releaseContext(HWND wnd, HIMC imc)
static void notifyIME(HIMC imc, DWORD dwAction, DWORD dwIndex, DWORD dwValue)

◆ setFocusWidget()

void QWinInputContext::setFocusWidget ( QWidget widget)
virtual

Sets the widget that has an input focus for this input context.

Warning
Ordinary input methods must not call this function directly.
See also
focusWidget()

Reimplemented from QInputContext.

Definition at line 753 of file qwininputcontext_win.cpp.

754 {
755  QWidget *oldFocus = focusWidget();
756  if (oldFocus == w)
757  return;
758  if (w) {
760  } else {
761  if (oldFocus)
762  QWinInputContext::updateImeStatus(oldFocus , false);
763  }
765  update();
766 }
virtual void update()
This virtual function is called when a state in the focus widget has changed.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
static void updateImeStatus(QWidget *w, bool hasFocus)
virtual void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.

◆ startComposition()

bool QWinInputContext::startComposition ( )

Definition at line 511 of file qwininputcontext_win.cpp.

Referenced by composition(), and QtWndProc().

512 {
513 #ifdef Q_IME_DEBUG
514  qDebug("startComposition");
515 #endif
516 
517  if (!imeComposition)
518  imeComposition = new QString();
519 
520  QWidget *fw = focusWidget();
521  if (fw) {
523  imePosition = 0;
524  haveCaret = CreateCaret(fw->effectiveWinId(), 0, 1, 1);
525  HideCaret(fw->effectiveWinId());
526  update();
527  }
528  return fw != 0;
529 }
static int imePosition
static QString * imeComposition
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
virtual void update()
This virtual function is called when a state in the focus widget has changed.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
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
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool haveCaret

◆ TranslateMessage()

void QWinInputContext::TranslateMessage ( const MSG msg)
static

Definition at line 355 of file qwininputcontext_win.cpp.

356 {
357  if (!aimmpump || aimmpump->OnTranslateMessage(msg) != S_OK)
358  ::TranslateMessage(msg);
359 }
static void TranslateMessage(const MSG *msg)
static IActiveIMMMessagePumpOwner * aimmpump

◆ update()

void QWinInputContext::update ( )
virtual

This virtual function is called when a state in the focus widget has changed.

QInputContext can then use QWidget::inputMethodQuery() to query the new state of the widget.

Reimplemented from QInputContext.

Definition at line 372 of file qwininputcontext_win.cpp.

Referenced by composition(), setFocusWidget(), and startComposition().

373 {
374  QWidget *w = focusWidget();
375  if(!w)
376  return;
377 
379  HIMC imc = getContext(w->effectiveWinId());
380 
381  if (!imc)
382  return;
383 
385  HFONT hf;
386  hf = f.handle();
387 
388  LOGFONT lf;
389  if (GetObject(hf, sizeof(lf), &lf)) {
390  if (aimm)
391  aimm->SetCompositionFontW(imc, &lf);
392  else
393  ImmSetCompositionFont(imc, &lf);
394  }
395 
397 
398  // The ime window positions are based on the WinId with active focus.
399  QWidget *imeWnd = QWidget::find(::GetFocus());
400  if (imeWnd && !aimm) {
401  QPoint pt (r.topLeft());
402  pt = w->mapToGlobal(pt);
403  pt = imeWnd->mapFromGlobal(pt);
404  r.moveTo(pt);
405  }
406 
407  COMPOSITIONFORM cf;
408  // ### need X-like inputStyle config settings
409  cf.dwStyle = CFS_FORCE_POSITION;
410  cf.ptCurrentPos.x = r.x();
411  cf.ptCurrentPos.y = r.y();
412 
413  CANDIDATEFORM candf;
414  candf.dwIndex = 0;
415  candf.dwStyle = CFS_EXCLUDE;
416  candf.ptCurrentPos.x = r.x();
417  candf.ptCurrentPos.y = r.y() + r.height();
418  candf.rcArea.left = r.x();
419  candf.rcArea.top = r.y();
420  candf.rcArea.right = r.x() + r.width();
421  candf.rcArea.bottom = r.y() + r.height();
422 
423  if(haveCaret)
424  SetCaretPos(r.x(), r.y());
425 
426  if (aimm) {
427  aimm->SetCompositionWindow(imc, &cf);
428  aimm->SetCandidateWindow(imc, &candf);
429  } else {
430  ImmSetCompositionWindow(imc, &cf);
431  ImmSetCandidateWindow(imc, &candf);
432  }
433 
434  releaseContext(w->effectiveWinId(), imc);
435 }
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
HFONT handle() const
Returns the window system handle to the font, for low-level access.
Definition: qfont_mac.cpp:121
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
static HIMC getContext(HWND wnd)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static IActiveIMMApp * aimm
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static void releaseContext(HWND wnd, HIMC imc)
static bool haveCaret
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ updateImeStatus()

void QWinInputContext::updateImeStatus ( QWidget w,
bool  hasFocus 
)
static

Definition at line 681 of file qwininputcontext_win.cpp.

Referenced by setFocusWidget().

682 {
683  if (!w)
684  return;
685  // It's always the proxy that carries the hints.
686  QWidget *focusProxyWidget = w->focusProxy();
687  if (!focusProxyWidget)
688  focusProxyWidget = w;
690  && !(focusProxyWidget->inputMethodHints() & (Qt::ImhExclusiveInputMask | Qt::ImhHiddenText));
691  bool hasIme = e && hasFocus;
692 #ifdef Q_IME_DEBUG
693  qDebug("%s HasFocus = %d hasIme = %d e = %d ", w->className(), hasFocus, hasIme, e);
694 #endif
695  if (hasFocus || e) {
696  if (isInPopup(w))
698  else
699  QWinInputContext::enable(w, hasIme);
700  }
701 }
static void enable(QWidget *w, bool e)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * focusProxy() const
Returns the focus proxy, or 0 if there is no focus proxy.
Definition: qwidget.cpp:6561
Q_CORE_EXPORT void qDebug(const char *,...)
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool isEnabled() const
Definition: qwidget.h:948
static void enablePopupChild(QWidget *w, bool e)
bool isInPopup(QWidget *w)
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition: qwidget.h:224

Properties

◆ recursionGuard

bool QWinInputContext::recursionGuard
private

Definition at line 108 of file qwininputcontext_p.h.

Referenced by endComposition().


The documentation for this class was generated from the following files: