Qt 4.8
Classes | Public Functions | Protected Functions | Private Functions | Properties | Static Private Attributes | List of all members
QXIMInputContext Class Reference

#include <qximinputcontext_p.h>

Inheritance diagram for QXIMInputContext:
QInputContext QObject

Classes

struct  ICData
 

Public Functions

void close_xim ()
 
void create_xim ()
 
ICDataicData () const
 
QString identifierName ()
 This function must be implemented in any subclasses to return the identifier name of the input method. More...
 
bool isComposing () const
 This function indicates whether InputMethodStart event had been sent to the current focus widget. More...
 
QString language ()
 This function must be implemented in any subclasses to return a language code (e. More...
 
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...
 
 QXIMInputContext ()
 
void reset ()
 This function can be reimplemented in a subclass to reset the state of the input method. More...
 
void setFocusWidget (QWidget *w)
 Sets the widget that has an input focus for this input context. More...
 
void update ()
 This virtual function is called when a state in the focus widget has changed. More...
 
void widgetDestroyed (QWidget *w)
 This virtual function is called when the specified widget is destroyed. More...
 
 ~QXIMInputContext ()
 
- 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 ~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...
 

Protected Functions

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...
 
- 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...
 

Private Functions

ICDatacreateICData (QWidget *w)
 

Properties

QString _language
 
XIM xim
 
QHash< WId, ICData * > ximData
 

Static Private Attributes

static XIMStyle xim_style = 0
 

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 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)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 90 of file qximinputcontext_p.h.

Constructors and Destructors

◆ QXIMInputContext()

QXIMInputContext::QXIMInputContext ( )

Definition at line 352 of file qximinputcontext_x11.cpp.

353 {
354  if (!qt_xim_preferred_style) // no configured input style, use the default
356 
357  xim = 0;
358  QByteArray ximServerName(qt_ximServer);
359  if (qt_ximServer)
360  ximServerName.prepend("@im=");
361  else
362  ximServerName = "";
363 
364  if (!XSupportsLocale())
365 #ifndef QT_NO_DEBUG
366  qWarning("Qt: Locale not supported on X server")
367 #endif
368  ;
369 #ifdef USE_X11R6_XIM
370  else if (XSetLocaleModifiers (ximServerName.constData()) == 0)
371  qWarning("Qt: Cannot set locale modifiers: %s", ximServerName.constData());
372  else
373  XRegisterIMInstantiateCallback(X11->display, 0, 0, 0,
374  (XIMProc) xim_create_callback, reinterpret_cast<char *>(this));
375 #else // !USE_X11R6_XIM
376  else if (XSetLocaleModifiers ("") == 0)
377  qWarning("Qt: Cannot set locale modifiers");
378  else
380 #endif // USE_X11R6_XIM
381 
382 #ifndef QT_NO_XKB
383  if (X11->use_xkb) {
384  QByteArray layoutName;
385  QByteArray variantName;
386 
387  Atom type = XNone;
388  int format = 0;
389  ulong nitems = 0;
390  ulong bytesAfter = 0;
391  uchar *data = 0;
392  if (XGetWindowProperty(X11->display, RootWindow(X11->display, 0), ATOM(_XKB_RULES_NAMES), 0, 1024,
393  false, XA_STRING, &type, &format, &nitems, &bytesAfter, &data) == Success
394  && type == XA_STRING && format == 8 && nitems > 2) {
395 
396  char *names[5] = { 0, 0, 0, 0, 0 };
397  char *p = reinterpret_cast<char *>(data), *end = p + nitems;
398  int i = 0;
399  do {
400  names[i++] = p;
401  p += qstrlen(p) + 1;
402  } while (p < end);
403 
404  QList<QByteArray> layoutNames = QByteArray::fromRawData(names[2], qstrlen(names[2])).split(',');
405  QList<QByteArray> variantNames = QByteArray::fromRawData(names[3], qstrlen(names[3])).split(',');
406  for (int i = 0; i < qMin(layoutNames.count(), variantNames.count()); ++i ) {
407  QByteArray variantName = variantNames.at(i);
408  const int dashPos = variantName.indexOf("-");
409  if (dashPos >= 0)
410  variantName.truncate(dashPos);
411  QLocale keyboardInputLocale = q_getKeyboardLocale(layoutNames.at(i), variantName);
412  if (keyboardInputLocale.textDirection() == Qt::RightToLeft)
413  qt_use_rtl_extensions = true;
414  }
415  }
416 
417  if (data)
418  XFree(data);
419  }
420 #endif // QT_NO_XKB
421 
422 }
Qt::LayoutDirection textDirection() const
Returns the text direction of the language.
Definition: qlocale.cpp:2286
int type
Definition: qmetatype.cpp:239
void truncate(int pos)
Truncates the byte array at index position pos.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Bool XRegisterIMInstantiateCallback(Display *, struct _XrmHashBucketRec *, char *, char *, XIMProc, XPointer)
XIMStyle qt_xim_preferred_style
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
char * qt_ximServer
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QLocale q_getKeyboardLocale(const QByteArray &layoutName, const QByteArray &variantName)
#define X11
Definition: qt_x11_p.h:724
bool qt_use_rtl_extensions
static const XIMStyle xim_default_style
#define ATOM(x)
Definition: qt_x11_p.h:723
unsigned char uchar
Definition: qglobal.h:994
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
unsigned long ulong
Definition: qglobal.h:997
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
uint qstrlen(const char *str)
Definition: qbytearray.h:79
static const KeyPair *const end

◆ ~QXIMInputContext()

QXIMInputContext::~QXIMInputContext ( )

Definition at line 539 of file qximinputcontext_x11.cpp.

Referenced by update().

540 {
541  XIM old_xim = xim; // close_xim clears xim pointer.
542  close_xim();
543  if (old_xim)
544  XCloseIM(old_xim);
545 }

Functions

◆ close_xim()

void QXIMInputContext::close_xim ( )
Warning
This function is not part of the public interface. Closes the application input method.

Definition at line 512 of file qximinputcontext_x11.cpp.

Referenced by create_xim(), and ~QXIMInputContext().

513 {
514  for(QHash<WId, ICData *>::const_iterator i = ximData.constBegin(),
515  e = ximData.constEnd(); i != e; ++i) {
516  ICData *data = i.value();
517  if (data->ic)
518  XDestroyIC(data->ic);
519  delete data;
520  }
521  ximData.clear();
522 
523  if ( --fontsetRefCount == 0 ) {
524  Display *dpy = X11->display;
525  for ( int i = 0; i < 8; i++ ) {
526  if ( fontsetCache[i] && fontsetCache[i] != (XFontSet)-1 ) {
527  XFreeFontSet(dpy, fontsetCache[i]);
528  fontsetCache[i] = 0;
529  }
530  }
531  }
532 
533  setFocusWidget(0);
534  xim = 0;
535 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define X11
Definition: qt_x11_p.h:724
static XFontSet fontsetCache[8]
static const char * data(const QByteArray &arr)
struct _XDisplay Display
Definition: qwindowdefs.h:115
QHash< WId, ICData * > ximData
static int fontsetRefCount
void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.

◆ create_xim()

void QXIMInputContext::create_xim ( )
Warning
This function is not part of the public interface. Creates the application input method.

Definition at line 428 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext().

429 {
430  ++fontsetRefCount;
431 #ifndef QT_NO_XIM
432  xim = XOpenIM(X11->display, 0, 0, 0);
433  if (xim) {
434 
435 #ifdef USE_X11R6_XIM
436  XIMCallback destroy;
437  destroy.callback = (XIMProc) xim_destroy_callback;
438  destroy.client_data = XPointer(this);
439  if (XSetIMValues(xim, XNDestroyCallback, &destroy, (char *) 0) != 0)
440  qWarning("Xlib doesn't support destroy callback");
441 #endif // USE_X11R6_XIM
442 
443  XIMStyles *styles = 0;
444  XGetIMValues(xim, XNQueryInputStyle, &styles, (char *) 0, (char *) 0);
445  if (styles) {
446  int i;
447  for (i = 0; !xim_style && i < styles->count_styles; i++) {
448  if (styles->supported_styles[i] == qt_xim_preferred_style) {
450  break;
451  }
452  }
453  // if the preferred input style couldn't be found, look for
454  // Nothing
455  for (i = 0; !xim_style && i < styles->count_styles; i++) {
456  if (styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) {
457  xim_style = XIMPreeditNothing | XIMStatusNothing;
458  break;
459  }
460  }
461  // ... and failing that, None.
462  for (i = 0; !xim_style && i < styles->count_styles; i++) {
463  if (styles->supported_styles[i] == (XIMPreeditNone |
464  XIMStatusNone)) {
465  xim_style = XIMPreeditNone | XIMStatusNone;
466  break;
467  }
468  }
469 
470  // qDebug("QApplication: using im style %lx", xim_style);
471  XFree((char *)styles);
472  }
473 
474  if (xim_style) {
475 
476 #ifdef USE_X11R6_XIM
477  XUnregisterIMInstantiateCallback(X11->display, 0, 0, 0,
478  (XIMProc) xim_create_callback, reinterpret_cast<char *>(this));
479 #endif // USE_X11R6_XIM
480 
482  // reinitialize input context after the input method
483  // server (like SCIM) has been launched without
484  // requiring the user to manually switch focus.
487  && focusWidget->isEnabled())
489  }
490  // following code fragment is not required for immodule
491  // version of XIM
492 #if 0
493  QWidgetList list = qApp->topLevelWidgets();
494  for (int i = 0; i < list.size(); ++i) {
495  QWidget *w = list.at(i);
496  w->d->createTLSysExtra();
497  }
498 #endif
499  } else {
500  // Give up
501  qWarning("No supported input style found."
502  " See InputMethod documentation.");
503  close_xim();
504  }
505  }
506 #endif // QT_NO_XIM
507 }
XIMStyle qt_xim_preferred_style
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 X11
Definition: qt_x11_p.h:724
#define XSetIMValues
Definition: qt_x11_p.h:69
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
bool isEnabled() const
Definition: qwidget.h:948
char * XPointer
Definition: qt_x11_p.h:180
static int fontsetRefCount
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
Bool XUnregisterIMInstantiateCallback(Display *, struct _XrmHashBucketRec *, char *, char *, XIMProc, XPointer)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static XIMStyle xim_style

◆ createICData()

QXIMInputContext::ICData * QXIMInputContext::createICData ( QWidget w)
private

Definition at line 737 of file qximinputcontext_x11.cpp.

Referenced by setFocusWidget().

738 {
739  ICData *data = new ICData;
740  data->widget = w;
741  data->preeditEmpty = true;
742 
743  XVaNestedList preedit_attr = 0;
744  XIMCallback startcallback, drawcallback, donecallback;
745 
746  QFont font = w->font();
747  data->fontset = getFontSet(font);
748 
749  if (xim_style & XIMPreeditArea) {
750  XRectangle rect;
751  rect.x = 0;
752  rect.y = 0;
753  rect.width = w->width();
754  rect.height = w->height();
755 
756  preedit_attr = XVaCreateNestedList(0,
757  XNArea, &rect,
758  XNFontSet, data->fontset,
759  (char *) 0);
760  } else if (xim_style & XIMPreeditPosition) {
761  XPoint spot;
762  spot.x = 1;
763  spot.y = 1;
764 
765  preedit_attr = XVaCreateNestedList(0,
766  XNSpotLocation, &spot,
767  XNFontSet, data->fontset,
768  (char *) 0);
769  } else if (xim_style & XIMPreeditCallbacks) {
770  startcallback.client_data = (XPointer) this;
771  startcallback.callback = (XIMProc) xic_start_callback;
772  drawcallback.client_data = (XPointer) this;
773  drawcallback.callback = (XIMProc)xic_draw_callback;
774  donecallback.client_data = (XPointer) this;
775  donecallback.callback = (XIMProc) xic_done_callback;
776 
777  preedit_attr = XVaCreateNestedList(0,
778  XNPreeditStartCallback, &startcallback,
779  XNPreeditDrawCallback, &drawcallback,
780  XNPreeditDoneCallback, &donecallback,
781  (char *) 0);
782  }
783 
784  if (preedit_attr) {
785  data->ic = XCreateIC(xim,
786  XNInputStyle, xim_style,
787  XNClientWindow, w->effectiveWinId(),
788  XNPreeditAttributes, preedit_attr,
789  (char *) 0);
790  XFree(preedit_attr);
791  } else {
792  data->ic = XCreateIC(xim,
793  XNInputStyle, xim_style,
794  XNClientWindow, w->effectiveWinId(),
795  (char *) 0);
796  }
797 
798  if (data->ic) {
799  // when resetting the input context, preserve the input state
800  (void) XSetICValues(data->ic, XNResetState, XIMPreserveState, (char *) 0);
801  } else {
802  qWarning("Failed to create XIC");
803  }
804 
805  ximData[w->effectiveWinId()] = data;
806  return data;
807 }
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
static int xic_start_callback(XIC, XPointer client_data, XPointer)
QFont font
the font currently set for the widget
Definition: qwidget.h:181
static int xic_draw_callback(XIC, XPointer client_data, XPointer call_data)
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
virtual QFont font() const
Returns the font of the current input widget.
char * XPointer
Definition: qt_x11_p.h:180
QHash< WId, ICData * > ximData
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static int xic_done_callback(XIC, XPointer client_data, XPointer)
static XFontSet getFontSet(const QFont &f)
static XIMStyle xim_style

◆ icData()

QXIMInputContext::ICData * QXIMInputContext::icData ( ) const

Definition at line 294 of file qximinputcontext_x11.cpp.

Referenced by xic_draw_callback(), and xic_start_callback().

295 {
296  if (QWidget *w = focusWidget())
297  return ximData.value(w->effectiveWinId());
298  return 0;
299 }
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.
QHash< WId, ICData * > ximData

◆ identifierName()

QString QXIMInputContext::identifierName ( )
virtual

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 548 of file qximinputcontext_x11.cpp.

Referenced by update().

549 {
550  // the name should be "xim" rather than "XIM" to be consistent
551  // with corresponding immodule of GTK+
552  return QLatin1String("xim");
553 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ isComposing()

bool QXIMInputContext::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 628 of file qximinputcontext_x11.cpp.

Referenced by update(), and x11FilterEvent().

629 {
630  QWidget *w = focusWidget();
631  if (!w)
632  return false;
633 
634  ICData *data = ximData.value(w->effectiveWinId());
635  if (!data)
636  return false;
637  return data->composing;
638 }
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.
static const char * data(const QByteArray &arr)
QHash< WId, ICData * > ximData

◆ language()

QString QXIMInputContext::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 556 of file qximinputcontext_x11.cpp.

Referenced by setFocusWidget(), and update().

557 {
559  if (xim) {
560  QByteArray locale(XLocaleOfIM(xim));
561 
562  if (locale.startsWith("zh")) {
563  // Chinese language should be formed as "zh_CN", "zh_TW", "zh_HK"
564  language = QLatin1String(locale.left(5));
565  } else {
566  // other languages should be two-letter ISO 639 language code
567  language = QLatin1String(locale.left(2));
568  }
569  }
570  return language;
571 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString language()
This function must be implemented in any subclasses to return a language code (e. ...

◆ mouseHandler()

void QXIMInputContext::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 612 of file qximinputcontext_x11.cpp.

Referenced by update().

613 {
614  if(e->type() != QEvent::MouseButtonPress)
615  return;
616 
617  XIM_DEBUG("QXIMInputContext::mouseHandler pos=%d", pos);
618  if (QWidget *w = focusWidget()) {
619  ICData *data = ximData.value(w->effectiveWinId());
620  if (!data)
621  return;
622  if (pos < 0 || pos > data->text.length())
623  reset();
624  // ##### handle mouse position
625  }
626 }
void reset()
This function can be reimplemented in a subclass to reset the state of the input method.
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 const char * data(const QByteArray &arr)
QHash< WId, ICData * > ximData
#define XIM_DEBUG

◆ reset()

void QXIMInputContext::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 573 of file qximinputcontext_x11.cpp.

Referenced by mouseHandler(), setFocusWidget(), and update().

574 {
575  QWidget *w = focusWidget();
576  if (!w)
577  return;
578 
579  ICData *data = ximData.value(w->effectiveWinId());
580  if (!data)
581  return;
582 
583  if (data->ic) {
584  char *mb = XmbResetIC(data->ic);
586  if (mb) {
588  XFree(mb);
589  data->preeditEmpty = false; // force sending an event
590  }
591  if (!data->preeditEmpty) {
592  sendEvent(e);
593  update();
594  }
595  }
596  data->clear();
597 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
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.
static const char * data(const QByteArray &arr)
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
QHash< WId, ICData * > ximData
void sendEvent(const QInputMethodEvent &event)
Sends an input method event specified by event to the current focus widget.
void update()
This virtual function is called when a state in the focus widget has changed.

◆ setFocusWidget()

void QXIMInputContext::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 640 of file qximinputcontext_x11.cpp.

Referenced by close_xim(), create_xim(), and update().

641 {
642  if (!xim)
643  return;
644  QWidget *oldFocus = focusWidget();
645  if (oldFocus == w)
646  return;
647 
648  if (language() != QLatin1String("ja"))
649  reset();
650 
651  if (oldFocus) {
652  ICData *data = ximData.value(oldFocus->effectiveWinId());
653  if (data && data->ic)
654  XUnsetICFocus(data->ic);
655  }
656 
658 
659  if (!w || w->inputMethodHints() & (Qt::ImhExclusiveInputMask | Qt::ImhHiddenText))
660  return;
661 
662  ICData *data = ximData.value(w->effectiveWinId());
663  if (!data)
664  data = createICData(w);
665 
666  if (data->ic)
667  XSetICFocus(data->ic);
668 
669  update();
670 }
void reset()
This function can be reimplemented in a subclass to reset the state of the input method.
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
QString language()
This function must be implemented in any subclasses to return a language code (e. ...
static const char * data(const QByteArray &arr)
ICData * createICData(QWidget *w)
QHash< WId, ICData * > ximData
virtual void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
void update()
This virtual function is called when a state in the focus widget has changed.

◆ update()

void QXIMInputContext::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 809 of file qximinputcontext_x11.cpp.

Referenced by reset(), setFocusWidget(), and x11FilterEvent().

810 {
811  QWidget *w = focusWidget();
812  if (!w)
813  return;
814 
815  ICData *data = ximData.value(w->effectiveWinId());
816  if (!data || !data->ic)
817  return;
818 
820  QPoint p;
821  if (w->nativeParentWidget())
822  p = w->mapTo(w->nativeParentWidget(), QPoint((r.left() + r.right() + 1)/2, r.bottom()));
823  else
824  p = QPoint((r.left() + r.right() + 1)/2, r.bottom());
825  XPoint spot;
826  spot.x = p.x();
827  spot.y = p.y();
828 
829  r = w->rect();
830  XRectangle area;
831  area.x = r.x();
832  area.y = r.y();
833  area.width = r.width();
834  area.height = r.height();
835 
836  XFontSet fontset = getFontSet(qvariant_cast<QFont>(w->inputMethodQuery(Qt::ImFont)));
837  if (data->fontset == fontset)
838  fontset = 0;
839  else
840  data->fontset = fontset;
841 
842  XVaNestedList preedit_attr;
843  if (fontset)
844  preedit_attr = XVaCreateNestedList(0,
845  XNSpotLocation, &spot,
846  XNArea, &area,
847  XNFontSet, fontset,
848  (char *) 0);
849  else
850  preedit_attr = XVaCreateNestedList(0,
851  XNSpotLocation, &spot,
852  XNArea, &area,
853  (char *) 0);
854 
855  XSetICValues(data->ic, XNPreeditAttributes, preedit_attr, (char *) 0);
856  XFree(preedit_attr);
857 }
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
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 left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
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.
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QWidget * nativeParentWidget() const
Returns the native parent for this widget, i.
Definition: qwidget.cpp:4514
static const char * data(const QByteArray &arr)
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QHash< WId, ICData * > ximData
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
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
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
static XFontSet getFontSet(const QFont &f)
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ widgetDestroyed()

void QXIMInputContext::widgetDestroyed ( QWidget widget)
virtual

This virtual function is called when the specified widget is destroyed.

The widget is a widget on which this input context is installed.

Reimplemented from QInputContext.

Definition at line 599 of file qximinputcontext_x11.cpp.

Referenced by update().

600 {
602  ICData *data = ximData.take(w->effectiveWinId());
603  if (!data)
604  return;
605 
606  data->clear();
607  if (data->ic)
608  XDestroyIC(data->ic);
609  delete data;
610 }
virtual void widgetDestroyed(QWidget *w)
This virtual function is called when the specified widget is destroyed.
static const char * data(const QByteArray &arr)
QHash< WId, ICData * > ximData

◆ x11FilterEvent()

bool QXIMInputContext::x11FilterEvent ( QWidget keywidget,
XEvent event 
)
protectedvirtual

This function may be overridden only if input method is depending on X11 and you need raw XEvent.

Otherwise, this function must not.

This function is designed to filter raw key events for XIM, but other input methods may use this to implement some special features such as distinguishing Shift_L and Shift_R.

Return true if the event has been consumed. Otherwise, the unfiltered event will be translated into QEvent and forwarded to filterEvent(). Filtering at both x11FilterEvent() and filterEvent() in single input method is allowed.

keywidget is a client widget into which a text is inputted. event is inputted XEvent.

See also
filterEvent()

Reimplemented from QInputContext.

Definition at line 673 of file qximinputcontext_x11.cpp.

Referenced by update().

674 {
675  int xkey_keycode = event->xkey.keycode;
676  if (!keywidget->testAttribute(Qt::WA_WState_Created))
677  return false;
678  if (XFilterEvent(event, keywidget->effectiveWinId())) {
679  qt_ximComposingKeycode = xkey_keycode; // ### not documented in xlib
680 
681  update();
682 
683  return true;
684  }
685  if (event->type != XKeyPress || event->xkey.keycode != 0)
686  return false;
687 
688  QWidget *w = focusWidget();
689  if (keywidget != w)
690  return false;
691  ICData *data = ximData.value(w->effectiveWinId());
692  if (!data)
693  return false;
694 
695  // input method has sent us a commit string
696  QByteArray string;
697  string.resize(513);
698  KeySym key; // unused
699  Status status; // unused
700  QString text;
701  int count = XmbLookupString(data->ic, &event->xkey, string.data(), string.size(),
702  &key, &status);
703 
704  if (status == XBufferOverflow) {
705  string.resize(count + 1);
706  count = XmbLookupString(data->ic, &event->xkey, string.data(), string.size(),
707  &key, &status);
708  }
709  if (count > 0) {
710  // XmbLookupString() gave us some text, convert it to unicode
711  text = qt_input_mapper->toUnicode(string.constData() , count);
712  if (text.isEmpty()) {
713  // codec couldn't convert to unicode? this can happen when running in the
714  // C locale (or with no LANG set). try converting from latin-1
715  text = QString::fromLatin1(string.constData(), count);
716  }
717  }
718 
719 #if 0
720  if (!(xim_style & XIMPreeditCallbacks) || !isComposing()) {
721  // ############### send a regular key event here!
722  ;
723  }
724 #endif
725 
727  e.setCommitString(text);
728  sendEvent(e);
729  data->clear();
730 
731  update();
732 
733  return true;
734 }
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
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
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
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QTextCodec * qt_input_mapper
static const char * data(const QByteArray &arr)
bool isComposing() const
This function indicates whether InputMethodStart event had been sent to the current focus widget...
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QHash< WId, ICData * > ximData
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void sendEvent(const QInputMethodEvent &event)
Sends an input method event specified by event to the current focus widget.
int key
void resize(int size)
Sets the size of the byte array to size bytes.
void update()
This virtual function is called when a state in the focus widget has changed.
#define Status
Definition: qcursor_x11.cpp:59
int qt_ximComposingKeycode
#define text
Definition: qobjectdefs.h:80
static XIMStyle xim_style

Properties

◆ _language

QString QXIMInputContext::_language
private

Definition at line 131 of file qximinputcontext_p.h.

◆ xim

XIM QXIMInputContext::xim
private

◆ xim_style

XIMStyle QXIMInputContext::xim_style = 0
staticprivate

Definition at line 129 of file qximinputcontext_p.h.

Referenced by create_xim(), createICData(), and x11FilterEvent().

◆ ximData

QHash<WId, ICData *> QXIMInputContext::ximData
private

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