1
/***************************************************************************
2
* Copyright (C) 2011~2012 by CSSlayer *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18
***************************************************************************/
20
#ifndef __FCITX_INPUT_CONTEXT_H_
21
#define __FCITX_INPUT_CONTEXT_H_
25
#include <QInputContext>
27
#include <QDBusConnection>
29
#include <QApplication>
30
#include <QWeakPointer>
32
#include "fcitx-qt/fcitxqtinputcontextproxy.h"
33
#include "fcitx-qt/fcitxqtinputmethodproxy.h"
34
#include "fcitx-config/hotkey.h"
35
#include "fcitx/ime.h"
39
#include "fcitx/frontend.h"
41
struct FcitxQtICData {
42
FcitxQtICData() : capacity(0), proxy(0), surroundingAnchor(-1), surroundingCursor(-1) {}
44
if (proxy && proxy->isValid()) {
49
QFlags<FcitxCapacityFlags> capacity;
50
QPointer<FcitxQtInputContextProxy> proxy;
52
QString surroundingText;
53
int surroundingAnchor;
54
int surroundingCursor;
57
class FcitxQtConnection;
59
class ProcessKeyWatcher : public QDBusPendingCallWatcher
63
ProcessKeyWatcher(XEvent* e, KeySym s, const QDBusPendingCall &call, QObject *parent = 0) : QDBusPendingCallWatcher(call, parent) {
64
event = static_cast<XEvent*>(malloc(sizeof(XEvent)));
69
virtual ~ProcessKeyWatcher() {
75
qApp->x11ProcessEvent(event);
85
#define FCITX_IDENTIFIER_NAME "fcitx"
86
#define FCITX_MAX_COMPOSE_LEN 7
88
class QFcitxInputContext : public QInputContext
93
~QFcitxInputContext();
95
virtual QString identifierName();
96
virtual QString language();
98
virtual bool isComposing() const;
99
virtual void update();
100
virtual void setFocusWidget(QWidget *w);
102
virtual void widgetDestroyed(QWidget *w);
104
#if defined(Q_WS_X11) && defined(ENABLE_X11)
105
virtual bool x11FilterEvent(QWidget *keywidget, XEvent *event);
107
virtual bool filterEvent(const QEvent* event);
108
virtual void mouseHandler(int x, QMouseEvent* event);
112
void createInputContext(WId w);
114
void commitString(const QString& str);
115
void updateFormattedPreedit(const FcitxQtFormattedPreeditList& preeditList, int cursorPos);
116
void forwardKey(uint keyval, uint state, int type);
117
void deleteSurroundingText(int offset, uint nchar);
118
void createInputContextFinished(QDBusPendingCallWatcher* watcher);
120
#if defined(Q_WS_X11) && defined(ENABLE_X11)
121
void x11ProcessKeyEventCallback(QDBusPendingCallWatcher* watcher);
124
QWidget* validFocusWidget();
125
bool processCompose(uint keyval, uint state, FcitxKeyEventType event);
126
bool checkAlgorithmically();
127
bool checkCompactTable(const struct _FcitxComposeTableCompact *table);
128
#if defined(Q_WS_X11) && defined(ENABLE_X11)
129
bool x11FilterEventFallback(XEvent *event, KeySym sym);
130
XEvent* createXEvent(Display* dpy, WId wid, uint keyval, uint state, int type);
132
QKeyEvent* createKeyEvent(uint keyval, uint state, int type);
134
FcitxQtInputContextProxy* validIC();
135
FcitxQtInputContextProxy* validICByWidget(QWidget* w);
137
void addCapacity(FcitxQtICData* data, QFlags<FcitxCapacityFlags> capacity, bool forceUpdate = false)
139
QFlags< FcitxCapacityFlags > newcaps = data->capacity | capacity;
140
if (data->capacity != newcaps || forceUpdate) {
141
data->capacity = newcaps;
142
updateCapacity(data);
146
void removeCapacity(FcitxQtICData* data, QFlags<FcitxCapacityFlags> capacity, bool forceUpdate = false)
148
QFlags< FcitxCapacityFlags > newcaps = data->capacity & (~capacity);
149
if (data->capacity != newcaps || forceUpdate) {
150
data->capacity = newcaps;
151
updateCapacity(data);
155
void updateCapacity(FcitxQtICData* data);
156
void commitPreedit();
157
void createICData(QWidget* w);
159
FcitxQtInputMethodProxy* m_improxy;
160
uint m_compose_buffer[FCITX_MAX_COMPOSE_LEN + 1];
163
QString m_commitPreedit;
164
FcitxQtFormattedPreeditList m_preeditList;
166
bool m_useSurroundingText;
168
FcitxQtConnection* m_connection;
169
QHash<WId, FcitxQtICData*> m_icMap;
172
#endif //__FCITX_INPUT_CONTEXT_H_
174
// kate: indent-mode cstyle; space-indent on; indent-width 0;