forked from EasyIME/libIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImeEngine.h
161 lines (120 loc) · 4.6 KB
/
ImeEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef IME_IME_ENGINE_H
#define IME_IME_ENGINE_H
#include "libIME.h"
#include <msctf.h>
#include "EditSession.h"
#include "KeyEvent.h"
#include "ComPtr.h"
#include <vector>
#include <list>
// for Windows 8 support
#ifndef TF_TMF_IMMERSIVEMODE // this is defined in Win 8 SDK
#define TF_TMF_IMMERSIVEMODE 0x40000000
#endif
namespace Ime {
class ImeModule;
class CandidateWindow;
class LangBarButton;
class ImeEngine {
public:
enum CommandType { // used in onCommand()
COMMAND_LEFT_CLICK,
COMMAND_RIGHT_CLICK,
COMMAND_MENU
};
ImeEngine(ImeModule* module);
virtual ~ImeEngine();
// public methods
ImeModule* imeModule() const;
ITfThreadMgr* threadMgr() const;
TfClientId clientId() const;
ITfContext* currentContext();
bool isActivated() const {
return (threadMgr() != NULL);
}
DWORD activateFlags() const {
return activateFlags_;
}
// running in Windows 8 app mode
bool isImmersive() const {
return (activateFlags_ & TF_TMF_IMMERSIVEMODE) != 0;
}
DWORD langBarStatus() const;
// language bar buttons
void addButton(LangBarButton* button);
void removeButton(LangBarButton* button);
// preserved keys
void addPreservedKey(UINT keyCode, UINT modifiers, const GUID& guid);
void removePreservedKey(const GUID& guid);
// text composition handling
bool isComposing();
// is keyboard disabled for the context (NULL means current context)
bool isKeyboardDisabled(ITfContext* context = NULL);
// is keyboard opened for the whole thread
bool isKeyboardOpened();
void setKeyboardOpen(bool open);
bool isInsertionAllowed(EditSession* session);
void startComposition(ITfContext* context);
void endComposition(ITfContext* context);
bool compositionRect(EditSession* session, RECT* rect);
bool selectionRect(EditSession* session, RECT* rect);
HWND compositionWindow(EditSession* session);
void setCompositionString(EditSession* session, const wchar_t* str, int len);
void setCompositionCursor(EditSession* session, int pos);
// compartment handling
ComPtr<ITfCompartment> globalCompartment(const GUID& key);
ComPtr<ITfCompartment> threadCompartment(const GUID& key);
ComPtr<ITfCompartment> contextCompartment(const GUID& key, ITfContext* context = NULL);
DWORD globalCompartmentValue(const GUID& key);
DWORD threadCompartmentValue(const GUID& key);
DWORD contextCompartmentValue(const GUID& key, ITfContext* context = NULL);
void setGlobalCompartmentValue(const GUID& key, DWORD value);
void setThreadCompartmentValue(const GUID& key, DWORD value);
void setContextCompartmentValue(const GUID& key, DWORD value, ITfContext* context = NULL);
// manage sinks to global or thread compartment (context specific compartment is not used)
void addCompartmentMonitor(const GUID key, bool isGlobal = false);
void removeCompartmentMonitor(const GUID key);
// virtual functions that IME implementors may need to override
virtual void onActivate();
virtual void onDeactivate();
virtual void onSetFocus();
virtual void onKillFocus();
virtual bool filterKeyDown(KeyEvent& keyEvent);
virtual bool onKeyDown(KeyEvent& keyEvent, EditSession* session);
virtual bool filterKeyUp(KeyEvent& keyEvent);
virtual bool onKeyUp(KeyEvent& keyEvent, EditSession* session);
virtual bool onPreservedKey(const GUID& guid);
// called when a language button or menu item is clicked
virtual bool onCommand(UINT id, CommandType type);
// called when a value in the global or thread compartment changed.
virtual void onCompartmentChanged(const GUID& key);
virtual void onLangBarStatusChanged(int newStatus);
// called when the keyboard is opened or closed
virtual void onKeyboardStatusChanged(bool opened);
// called just before current composition is terminated for doing cleanup.
// if forced is true, the composition is terminated by others, such as
// the input focus is grabbed by another application.
// if forced is false, the composition is terminated gracefully by endComposition().
virtual void onCompositionTerminated(bool forced);
private:
ComPtr<ImeModule> module_;
ComPtr<ITfThreadMgr> threadMgr_;
TfClientId clientId_;
DWORD activateFlags_;
bool isKeyboardOpened_;
// event sink cookies
DWORD threadMgrEventSinkCookie_;
DWORD textEditSinkCookie_;
DWORD compositionSinkCookie_;
DWORD keyboardOpenEventSinkCookie_;
DWORD globalCompartmentEventSinkCookie_;
DWORD langBarSinkCookie_;
ITfComposition* composition_; // acquired when starting composition, released when ending composition
CandidateWindow* candidateWindow_;
ComPtr<ITfLangBarMgr> langBarMgr_;
std::vector<LangBarButton*> langBarButtons_;
std::vector<PreservedKey> preservedKeys_;
std::vector<CompartmentMonitor> compartmentMonitors_;
};
}
#endif