annotate EXCLUDE/GLTSF/src/TSF.cpp @ 4734:0c7c67d4e6ee

Added On_Char method to Window_Listener for WM_CHAR messages. Removed a lot of TSF code because part of it was wrong and part was too complicated. Added Clear method to clear the window. IME input should work in both windowed mode and fullscreen mode with these changes. I have tested on Windows XP SP3 and Windows 7 Ultimate in VirtualBox. When you type a character (with an IME or not), the console will show the code point as U+XXXX. You use Left Alt+Shift (or whatever you have it set to) to switch input languages as usual. Hit ESC to exit (or close the window in windowed mode). The program will pause before exiting so you can review the console output (press a key to exit).
author dewyatt
date Wed, 09 Jun 2010 00:03:54 -0400
parents e1307be6cb9e
children f51a9f01b508
rev   line source
4731
bfc8ad7234b6 Adding some initial TSF code
dewyatt
parents:
diff changeset
1 #include "TSF.hpp"
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
2 #include <stdexcept>
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
3
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
4 bool TSF::COM_Initialized = false;
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
5 CComPtr<ITfThreadMgr> TSF::Thread_Manager;
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
6
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
7 void TSF::Initialize()
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
8 {
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
9 if (!COM_Initialized)
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
10 {
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
11 HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
12 if (S_OK != hr && S_FALSE != hr)
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
13 throw std::runtime_error("Failed to initialize COM");
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
14
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
15 COM_Initialized = true;
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
16 }
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
17 if (!Thread_Manager)
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
18 {
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
19 if (FAILED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<void **>(&Thread_Manager))))
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
20 throw std::runtime_error("Failed to create ITfThreadMgr instance");
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
21
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
22 TfClientId ClientId;
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
23 if (FAILED(Thread_Manager->Activate(&ClientId)))
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
24 throw std::runtime_error("ITfThreadMgr::Activate failed");
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
25 }
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
26 }
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
27
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
28 void TSF::Finalize()
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
29 {
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
30 if (Thread_Manager)
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
31 {
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
32 Thread_Manager->Deactivate();
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
33 Thread_Manager = NULL;
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
34 }
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
35 if (COM_Initialized)
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
36 {
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
37 CoUninitialize();
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4732
diff changeset
38 COM_Initialized = false;
4732
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
39 }
e1307be6cb9e Implementing base parts of TSF
dewyatt
parents: 4731
diff changeset
40 }