Qt 4.8
Macros | Functions | Variables
qximinputcontext_x11.cpp File Reference
#include "qplatformdefs.h"
#include "qdebug.h"
#include "qximinputcontext_p.h"
#include "qapplication.h"
#include "qwidget.h"
#include "qstring.h"
#include "qlist.h"
#include "qtextcodec.h"
#include "qevent.h"
#include "qtextformat.h"
#include "qx11info_x11.h"
#include <stdlib.h>
#include <limits.h>

Go to the source code of this file.

Macros

#define XIM_DEBUG   if (0) qDebug
 

Functions

static XFontSet getFontSet (const QFont &f)
 
QLocale q_getKeyboardLocale (const QByteArray &layoutName, const QByteArray &variantName)
 
static int xic_done_callback (XIC, XPointer client_data, XPointer)
 
static int xic_draw_callback (XIC, XPointer client_data, XPointer call_data)
 
static int xic_start_callback (XIC, XPointer client_data, XPointer)
 

Variables

static XFontSet fontsetCache [8] = { 0, 0, 0, 0, 0, 0, 0, 0 }
 
static const char *const fontsetnames []
 
static int fontsetRefCount = 0
 
QTextCodecqt_input_mapper
 
bool qt_use_rtl_extensions
 
XIMStyle qt_xim_preferred_style
 
int qt_ximComposingKeycode
 
char * qt_ximServer
 
static const XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing
 

Macro Definition Documentation

◆ XIM_DEBUG

#define XIM_DEBUG   if (0) qDebug

Function Documentation

◆ getFontSet()

static XFontSet getFontSet ( const QFont f)
static

Definition at line 318 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::createICData(), and QXIMInputContext::update().

319 {
320  int i = 0;
321  if (f.italic())
322  i |= 1;
323  if (f.bold())
324  i |= 2;
325 
326  if (f.pointSize() > 20)
327  i += 4;
328 
329  if (!fontsetCache[i]) {
330  Display* dpy = X11->display;
331  int missCount;
332  char** missList;
333  fontsetCache[i] = XCreateFontSet(dpy, fontsetnames[i], &missList, &missCount, 0);
334  if(missCount > 0)
335  XFreeStringList(missList);
336  if (!fontsetCache[i]) {
337  fontsetCache[i] = XCreateFontSet(dpy, "-*-fixed-*-*-*-*-16-*", &missList, &missCount, 0);
338  if(missCount > 0)
339  XFreeStringList(missList);
340  if (!fontsetCache[i])
341  fontsetCache[i] = (XFontSet)-1;
342  }
343  }
344  return (fontsetCache[i] == (XFontSet)-1) ? 0 : fontsetCache[i];
345 }
static const char *const fontsetnames[]
#define X11
Definition: qt_x11_p.h:724
static XFontSet fontsetCache[8]
bool bold() const
Returns true if weight() is a value greater than QFont::Normal ; otherwise returns false...
Definition: qfont.h:348
struct _XDisplay Display
Definition: qwindowdefs.h:115
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition: qfont.h:355
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981

◆ q_getKeyboardLocale()

QLocale q_getKeyboardLocale ( const QByteArray layoutName,
const QByteArray variantName 
)

Definition at line 83 of file qkeymapper_x11.cpp.

Referenced by getFontSet(), and QXIMInputContext::QXIMInputContext().

84 {
85  int i = 0;
86  while (xkbLayoutData[i].layout != 0) {
87  if (layoutName == xkbLayoutData[i].layout && variantName == xkbLayoutData[i].variant)
89  ++i;
90  }
91  return QLocale::c();
92 }
QLocale::Language language
const char * layout
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
Definition: qlocale.h:773
static struct @202 xkbLayoutData[]
const char * variant
QLocale::Country country

◆ xic_done_callback()

static int xic_done_callback ( XIC  ,
XPointer  client_data,
XPointer   
)
static

Definition at line 274 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::createICData().

274  {
275  QXIMInputContext *qic = (QXIMInputContext *) client_data;
276  if (!qic)
277  return 0;
278 
279  XIM_DEBUG("xic_done_callback");
280  // Don't send InputMethodEnd here. QXIMInputContext::x11FilterEvent()
281  // handles InputMethodEnd with commit string.
282  return 0;
283  }
#define XIM_DEBUG

◆ xic_draw_callback()

static int xic_draw_callback ( XIC  ,
XPointer  client_data,
XPointer  call_data 
)
static

Definition at line 144 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::createICData().

144  {
145  QXIMInputContext *qic = (QXIMInputContext *) client_data;
146  if (!qic) {
147  XIM_DEBUG("xic_draw_callback: no qic");
148  return 0;
149  }
151  if (!data) {
152  XIM_DEBUG("xic_draw_callback: no ic data");
153  return 0;
154  }
155  XIM_DEBUG("xic_draw_callback");
156 
157 
158  if(!data->composing) {
159  data->clear();
160  data->composing = true;
161  }
162 
163  XIMPreeditDrawCallbackStruct *drawstruct = (XIMPreeditDrawCallbackStruct *) call_data;
164  XIMText *text = (XIMText *) drawstruct->text;
165  int cursor = drawstruct->caret, sellen = 0, selstart = 0;
166 
167  if (!drawstruct->caret && !drawstruct->chg_first && !drawstruct->chg_length && !text) {
168  if(data->text.isEmpty()) {
169  XIM_DEBUG("compose emptied");
170  // if the composition string has been emptied, we need
171  // to send an InputMethodEnd event
173  qic->sendEvent(e);
174  data->clear();
175 
176  // if the commit string has coming after here, InputMethodStart
177  // will be sent dynamically
178  }
179  return 0;
180  }
181 
182  if (text) {
183  char *str = 0;
184  if (text->encoding_is_wchar) {
185  int l = wcstombs(NULL, text->string.wide_char, text->length);
186  if (l != -1) {
187  str = new char[l + 1];
188  wcstombs(str, text->string.wide_char, l);
189  str[l] = 0;
190  }
191  } else
192  str = text->string.multi_byte;
193 
194  if (!str)
195  return 0;
196 
198 
199  if (text->encoding_is_wchar)
200  delete [] str;
201 
202  if (drawstruct->chg_length < 0)
203  data->text.replace(drawstruct->chg_first, INT_MAX, s);
204  else
205  data->text.replace(drawstruct->chg_first, drawstruct->chg_length, s);
206 
207  if (data->selectedChars.size() < data->text.length()) {
208  // expand the selectedChars array if the compose string is longer
209  int from = data->selectedChars.size();
210  data->selectedChars.resize(data->text.length());
211  for (int x = from; x < data->selectedChars.size(); ++x)
212  data->selectedChars.clearBit(x);
213  }
214 
215  // determine if the changed chars are selected based on text->feedback
216  for (int x = 0; x < text->length; ++x)
217  data->selectedChars.setBit(x + drawstruct->chg_first,
218  (text->feedback ? (text->feedback[x] & XIMReverse) : 0));
219 
220  // figure out where the selection starts, and how long it is
221  bool started = false;
222  for (int x = 0; x < qMin(data->selectedChars.size(), data->text.length()); ++x) {
223  if (started) {
224  if (data->selectedChars.testBit(x)) ++sellen;
225  else break;
226  } else {
227  if (data->selectedChars.testBit(x)) {
228  selstart = x;
229  started = true;
230  sellen = 1;
231  }
232  }
233  }
234  } else {
235  if (drawstruct->chg_length == 0)
236  drawstruct->chg_length = -1;
237 
238  data->text.remove(drawstruct->chg_first, drawstruct->chg_length);
239  bool qt_compose_emptied = data->text.isEmpty();
240  if (qt_compose_emptied) {
241  XIM_DEBUG("compose emptied 2 text=%s", data->text.toUtf8().constData());
242  // if the composition string has been emptied, we need
243  // to send an InputMethodEnd event
245  qic->sendEvent(e);
246  data->clear();
247  // if the commit string has coming after here, InputMethodStart
248  // will be sent dynamically
249  return 0;
250  }
251  }
252 
253  XIM_DEBUG("sending compose: '%s', cursor=%d, sellen=%d",
254  data->text.toUtf8().constData(), cursor, sellen);
256  if (selstart > 0)
259  if (sellen)
262  if (selstart + sellen < data->text.length())
264  selstart + sellen, data->text.length() - selstart - sellen,
266  attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, sellen ? 0 : 1, QVariant());
267  QInputMethodEvent e(data->text, attrs);
268  data->preeditEmpty = data->text.isEmpty();
269  qic->sendEvent(e);
270 
271  return 0;
272  }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
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
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void setBit(int i)
Sets the bit at index position i to 1.
Definition: qbitarray.h:128
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
Definition: qbitarray.h:124
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QTextFormat standardFormat(StandardFormat s) const
Returns a QTextFormat object that specifies the format for component s.
void resize(int size)
Resizes the bit array to size bits.
Definition: qbitarray.cpp:214
static const char * data(const QByteArray &arr)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
void sendEvent(const QInputMethodEvent &event)
Sends an input method event specified by event to the current focus widget.
if(void) toggleToolbarShown
QFactoryLoader * l
#define XIM_DEBUG
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
int size() const
Returns the number of bits stored in the bit array.
Definition: qbitarray.h:73
void clearBit(int i)
Sets the bit at index position i to 0.
Definition: qbitarray.h:132
#define INT_MAX
#define text
Definition: qobjectdefs.h:80
ICData * icData() const

◆ xic_start_callback()

static int xic_start_callback ( XIC  ,
XPointer  client_data,
XPointer   
)
static

Definition at line 125 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::createICData().

125  {
126  QXIMInputContext *qic = (QXIMInputContext *) client_data;
127  if (!qic) {
128  XIM_DEBUG("xic_start_callback: no qic");
129  return 0;
130  }
132  if (!data) {
133  XIM_DEBUG("xic_start_callback: no ic data");
134  return 0;
135  }
136  XIM_DEBUG("xic_start_callback");
137 
138  data->clear();
139  data->composing = true;
140 
141  return 0;
142  }
static const char * data(const QByteArray &arr)
#define XIM_DEBUG
ICData * icData() const

Variable Documentation

◆ fontsetCache

XFontSet fontsetCache[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }
static

Definition at line 304 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::close_xim(), and getFontSet().

◆ fontsetnames

const char* const fontsetnames[]
static
Initial value:
= {
"-*-fixed-medium-r-*-*-16-*,-*-*-medium-r-*-*-16-*",
"-*-fixed-medium-i-*-*-16-*,-*-*-medium-i-*-*-16-*",
"-*-fixed-bold-r-*-*-16-*,-*-*-bold-r-*-*-16-*",
"-*-fixed-bold-i-*-*-16-*,-*-*-bold-i-*-*-16-*",
"-*-fixed-medium-r-*-*-24-*,-*-*-medium-r-*-*-24-*",
"-*-fixed-medium-i-*-*-24-*,-*-*-medium-i-*-*-24-*",
"-*-fixed-bold-r-*-*-24-*,-*-*-bold-r-*-*-24-*",
"-*-fixed-bold-i-*-*-24-*,-*-*-bold-i-*-*-24-*"
}

Definition at line 307 of file qximinputcontext_x11.cpp.

Referenced by getFontSet().

◆ fontsetRefCount

int fontsetRefCount = 0
static

◆ qt_input_mapper

QTextCodec* qt_input_mapper

Definition at line 443 of file qapplication_x11.cpp.

Referenced by translateKeySym().

◆ qt_use_rtl_extensions

bool qt_use_rtl_extensions

Definition at line 266 of file qapplication_win.cpp.

Referenced by getFontSet(), and QXIMInputContext::QXIMInputContext().

◆ qt_xim_preferred_style

XIMStyle qt_xim_preferred_style

◆ qt_ximComposingKeycode

int qt_ximComposingKeycode

Definition at line 442 of file qapplication_x11.cpp.

Referenced by translateKeySym(), and QXIMInputContext::x11FilterEvent().

◆ qt_ximServer

char* qt_ximServer

Definition at line 345 of file qapplication_x11.cpp.

Referenced by qt_init(), and QXIMInputContext::QXIMInputContext().

◆ xim_default_style

const XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing
static

Definition at line 99 of file qximinputcontext_x11.cpp.

Referenced by QXIMInputContext::QXIMInputContext().