OSDN Git Service

Fix a bug where shift key combinations cancel the mark
[xkeymacs/xkeymacs.git] / xkeymacs / imelist.cpp
1 #include "imelist.h"\r
2 #include <vector>\r
3 #include <Imm.h>\r
4 #include <msctf.h>\r
5 \r
6 IMEListIterator IMEList::begin()\r
7 {\r
8         if (list.empty())\r
9                 GetIMEList();\r
10         return list.begin();\r
11 }\r
12 \r
13 IMEListIterator IMEList::end()\r
14 {\r
15         return list.end();\r
16 }\r
17 \r
18 void IMEList::GetIMEList()\r
19 {\r
20         GetIMM();\r
21         GetTSF();\r
22 }\r
23 \r
24 void IMEList::GetIMM()\r
25 {\r
26         const int n = GetKeyboardLayoutList(0, NULL);\r
27         if (!n)\r
28                 return;\r
29         std::vector<HKL> hkls(n);\r
30         GetKeyboardLayoutList(n, &hkls[0]);\r
31         for (std::vector<HKL>::const_iterator p = hkls.begin(); p != hkls.end(); ++p) {\r
32                 IMEInfo info;\r
33                 if (ImmGetDescription(*p, info.description, WINDOW_TEXT_LENGTH) &&\r
34                                 ImmGetIMEFileName(*p, info.filename, MAX_PATH))\r
35                         list.push_back(info);\r
36         }\r
37 }\r
38 \r
39 void IMEList::GetTSF()\r
40 {\r
41         CoInitialize(NULL);\r
42         ITfInputProcessorProfiles *ipp;\r
43         if (FAILED(CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ipp)))) {\r
44                 CoUninitialize();\r
45                 return;\r
46         }\r
47         ITfInputProcessorProfileMgr *mgr;\r
48         if (FAILED(ipp->QueryInterface(&mgr)))\r
49                 goto fail;\r
50         TF_INPUTPROCESSORPROFILE prof;\r
51         if (FAILED(mgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &prof))) {\r
52                 mgr->Release();\r
53                 goto fail;\r
54         }\r
55         mgr->Release();\r
56         if (prof.dwProfileType != TF_PROFILETYPE_INPUTPROCESSOR) // current IME is not TIP\r
57                 goto fail;\r
58         BSTR bstr;\r
59         if (FAILED(ipp->GetLanguageProfileDescription(prof.clsid, prof.langid, prof.guidProfile, &bstr)))\r
60                 goto fail;\r
61         IMEInfo info;\r
62 #ifdef _MBCS\r
63         WideCharToMultiByte(CP_ACP, 0, bstr, -1, info.description, WINDOW_TEXT_LENGTH, NULL, NULL);\r
64 #else\r
65         wcscpy_s(info.description, WINDOW_TEXT_LENGTH, bstr);\r
66 #endif\r
67         _tcscpy_s(info.filename, _T("IME"));\r
68         list.push_back(info);\r
69 fail:\r
70         ipp->Release();\r
71         CoUninitialize();\r
72 }\r