├── LICENSE.TXT ├── README.TXT ├── README_JA.TXT ├── build.bat ├── common ├── common.cpp ├── common.h ├── common.vcxproj ├── common.vcxproj.filters ├── common.vcxproj.user ├── configxml.cpp ├── configxml.h ├── stdafx.cpp └── stdafx.h ├── imcrvtip ├── Compartment.cpp ├── CompartmentEventSink.cpp ├── DllMain.cpp ├── EditSession.h ├── FnConfigure.cpp ├── FunctionProvider.cpp ├── Globals.cpp ├── Icon │ ├── vim.ico │ ├── xDefault.ico │ ├── xInsert.ico │ ├── zDefault.ico │ └── zInsert.ico ├── KeyEventSink.cpp ├── KeyHandler.cpp ├── KeyHandlerConv.cpp ├── KeyHandlerDictionary.cpp ├── LanguageBar.cpp ├── LanguageBar.h ├── Register.cpp ├── Server.cpp ├── TextService.cpp ├── TextService.h ├── ThreadMgrEventSink.cpp ├── ViCharStream.cpp ├── ViCharStream.h ├── ViCmd.cpp ├── ViCmd.h ├── ViKeyHandler.cpp ├── ViKeyHandler.h ├── ViMulti.cpp ├── ViMulti.h ├── ViUtil.cpp ├── ViUtil.h ├── VimCharStream.cpp ├── VimCharStream.h ├── VimMByte.cpp ├── VimMByte.h ├── imcrvtip.def ├── imcrvtip.h ├── imcrvtip.rc ├── imcrvtip.vcxproj ├── imcrvtip.vcxproj.filters ├── imcrvtip.vcxproj.user ├── mozc │ ├── base │ │ ├── base.h │ │ ├── compiler_specific.h │ │ ├── flags.h │ │ ├── init.h │ │ ├── logging.h │ │ ├── namespace.h │ │ ├── port.h │ │ └── scoped_ptr.h │ └── win32 │ │ ├── atl_wrapper │ │ └── atlbase_mozc.h │ │ ├── base │ │ ├── imm_reconvert_string.cc │ │ ├── imm_reconvert_string.h │ │ ├── input_state.cc │ │ ├── input_state.h │ │ ├── keyboard.cc │ │ └── keyboard.h │ │ └── tip │ │ ├── tip_composition_util.cc │ │ ├── tip_composition_util.h │ │ ├── tip_range_util.cc │ │ ├── tip_range_util.h │ │ ├── tip_ref_count.cc │ │ ├── tip_ref_count.h │ │ ├── tip_surrounding_text.cc │ │ ├── tip_surrounding_text.h │ │ ├── tip_transitory_extension.cc │ │ └── tip_transitory_extension.h ├── resource.h ├── stdafx.cpp └── stdafx.h ├── imvimcnf ├── ConfigCnf.cpp ├── DlgProcBehavior2.cpp ├── DlgProcPreservedKey.cpp ├── PropertyConfConv.cpp ├── imvimcnf.cpp ├── imvimcnf.h ├── imvimcnf.ico ├── imvimcnf.rc ├── imvimcnf.vcxproj ├── imvimcnf.vcxproj.filters ├── resource.h ├── stdafx.cpp └── stdafx.h ├── installer ├── _clean.cmd ├── _mkarc.cmd ├── installer.vcxproj ├── installer.vcxproj.filters ├── installer.vcxproj.user ├── ms-pl.rtf ├── tsfvim-x64.wxs └── tsfvim-x86.wxs └── tsf-vim.sln /README.TXT: -------------------------------------------------------------------------------- 1 |  2 | ================================================================================ 3 | tsf-vim version 0.1.1 (2014-03-23) 4 | 5 | https://github.com/deton/tsf-vim 6 | deton@m1.interq.or.jp 7 | ================================================================================ 8 | 9 | Windows IME to edit text like the Vi editor. 10 | 11 | 12 | -------------------------------------------------------------------------------- 13 | Install 14 | -------------------------------------------------------------------------------- 15 | 16 | 17 | * Required Library 18 | 19 | Install x64 and x86 packages for 64bit Windows. 20 | 21 | Microsoft Visual C++ 2010 SP1 Redistributable Package (x86) 22 | http://www.microsoft.com/en-us/download/details.aspx?id=8328 23 | 24 | Microsoft Visual C++ 2010 SP1 Redistributable Package (x64) 25 | http://www.microsoft.com/en-us/download/details.aspx?id=13523 26 | 27 | 28 | -------------------------------------------------------------------------------- 29 | Vi Commands 30 | -------------------------------------------------------------------------------- 31 | 32 | tsf-vim sends some keys on each Vi command. 33 | Example: When user presses 'h' key, tsf-vim sends VK_LEFT to application. 34 | 35 | tsf-vim acquires text using TSF(Text Services Framework) for 36 | f,t,F,T,),(,w,e,b,W,E,B commands. 37 | If application does not support TSF, tsf-vim uses IMR_DOCUMENTFEED to 38 | acquire text. 39 | If application does not support IMR_DOCUMENTFEED, 40 | these commands does not work. 41 | 42 | Supported applications: 43 | + Word 2010 44 | + Outlook 2010 45 | + (f etc. does not works on PowerPoint 2010, Excel 2010, Visual Studio 2010/2012) 46 | + WordPad 47 | + notepad 48 | 49 | Command Key sequences to send 50 | 0 HOME 51 | g$ END (count not supported) 52 | $ to newline(*) RIGHT (count not supported) 53 | c CTRL-X,tsf-vim OFF 54 | d CTRL-X 55 | y CTRL-C 56 | cc [count-1]DOWN,END,RIGHT,start selection,[count-1]UP,CTRL-X,tsf-vim OFF 57 | cj [count]DOWN,END,RIGHT,start selection,[count]UP,CTRL-X,tsf-vim OFF 58 | ck END,RIGHT,start selection,[count]UP,CTRL-X,tsf-vim OFF 59 | dd [count-1]DOWN,END,RIGHT,start selection,[count-1]UP,CTRL-X 60 | dj [count]DOWN,END,RIGHT,start selection,[count]UP,CTRL-X 61 | dk END,RIGHT,start selection,[count]UP,CTRL-X 62 | yy [count-1]DOWN,END,RIGHT,start selection,[count-1]UP,CTRL-C 63 | yj [count]DOWN,END,RIGHT,start selection,[count]UP,CTRL-C 64 | yk END,RIGHT,start selection,[count]UP,CTRL-C 65 | C start selection,END,CTRL-X,tsf-vim OFF 66 | D start selection,END,CTRL-X 67 | f{char} to {char}(*)RIGHT 68 | t{char} before {char}(*)RIGHT 69 | F{char} to {char}(*)LEFT 70 | T{char} after {char}(*)LEFT 71 | ; repeat latest f, t, F or T 72 | , repeat latest f, t, F or T in opposite direction 73 | r{char} DELETE,{char} 74 | s start selection,RIGHT,CTRL-X,tsf-vim OFF 75 | gg CTRL-HOME 76 | G CTRL-END,HOME (same as gg when count is specified) 77 | CTRL-F PageDown 78 | CTRL-B PageUp 79 | h LEFT 80 | l RIGHT 81 | RIGHT 82 | j DOWN 83 | k UP 84 | + next line and to first non-blank character(*)RIGHT 85 | CTRL-M next line and to first non-blank character(*)RIGHT 86 | i tsf-vim OFF 87 | I to first non-blank character(*)RIGHT or LEFT,tsf-vim OFF 88 | a RIGHT,tsf-vim OFF 89 | A END,tsf-vim OFF 90 | o END,RETURN,tsf-vim OFF 91 | O HOME,RETURN,UP,tsf-vim OFF 92 | p RIGHT,CTRL-V 93 | P CTRL-V 94 | u CTRL-Z 95 | x start selection,RIGHT,CTRL-X 96 | X start selection,LEFT,CTRL-X 97 | w to next word(*)RIGHT 98 | W to next WORD(*)RIGHT 99 | e to the end of word(*)RIGHT 100 | E to the end of WORD(*)RIGHT 101 | b to previous word(*)LEFT 102 | B to previous WORD(*)LEFT 103 | ) to next sentence(*)RIGHT 104 | ( to previous sentence(*)LEFT 105 | J to the end of line(*)RIGHT, 106 | to first non-blank character on next line(*)DELETE 107 | (count not supported) 108 | 109 | You can combine c,d,y and motion commands(h,f{char},w,$,etc.). 110 | Some commands support count. 111 | Commands marked (*) do not work for application which does not support TSF. 112 | 113 | 114 | -------------------------------------------------------------------------------- 115 | Misc 116 | -------------------------------------------------------------------------------- 117 | 118 | 119 | * Source 120 | 121 | * IME functions from CorvusSKK. 122 | http://code.google.com/p/corvus-skk/ 123 | * Surrounding text functions to acquire text around cursor position by TSF 124 | from Mozc. 125 | http://code.google.com/p/mozc/ 126 | 127 | * BUGS 128 | 129 | * 'dd' on last line deletes last line and upper line. 130 | * 'yy' on last line yanks last line and upper line. 131 | * 'cc' on last line changes last line and upper line. 132 | * Many unsupported commands(includes text-objects, Visual mode). 133 | 134 | * Development tools 135 | 136 | Visual C++ 2010 Express + SP1 137 | Windows SDK 7.1 138 | Windows Driver Kit 7.1.0 (for ATL used by Mozc) 139 | WiX 3.8 140 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | set PF=%1 2 | if "%PF%"=="" set PF=Win32 3 | msbuild tsf-vim.sln /p:Configuration=Release /p:Platform=%PF% 4 | -------------------------------------------------------------------------------- /common/common.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "common.h" 3 | 4 | LPCWSTR fnconfigxml = L"config.xml"; //設定 5 | 6 | BOOL IsVersion62AndOver() 7 | { 8 | OSVERSIONINFOEXW osvi; 9 | DWORDLONG mask = 0; 10 | 11 | ZeroMemory(&osvi, sizeof(osvi)); 12 | osvi.dwOSVersionInfoSize = sizeof(osvi); 13 | osvi.dwMajorVersion = 6; 14 | osvi.dwMinorVersion = 2; 15 | 16 | VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL); 17 | VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL); 18 | 19 | return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, mask); 20 | } 21 | 22 | BOOL GetMD5(MD5_DIGEST *digest, CONST BYTE *data, DWORD datalen) 23 | { 24 | BOOL bRet = FALSE; 25 | HCRYPTPROV hProv = NULL; 26 | HCRYPTHASH hHash = NULL; 27 | BYTE *pbData; 28 | DWORD dwDataLen; 29 | 30 | if(digest == NULL || data == NULL) 31 | { 32 | return FALSE; 33 | } 34 | 35 | ZeroMemory(digest, sizeof(digest)); 36 | pbData = digest->digest; 37 | dwDataLen = sizeof(digest->digest); 38 | 39 | if(CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) 40 | { 41 | if(CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) 42 | { 43 | if(CryptHashData(hHash, data, datalen, 0)) 44 | { 45 | if(CryptGetHashParam(hHash, HP_HASHVAL, pbData, &dwDataLen, 0)) 46 | { 47 | bRet = TRUE; 48 | } 49 | } 50 | CryptDestroyHash(hHash); 51 | } 52 | CryptReleaseContext(hProv, 0); 53 | } 54 | 55 | return bRet; 56 | } 57 | 58 | BOOL GetUserSid(LPWSTR *ppszUserSid) 59 | { 60 | BOOL bRet = FALSE; 61 | HANDLE hToken; 62 | PTOKEN_USER pTokenUser; 63 | DWORD dwLength; 64 | 65 | if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) 66 | { 67 | GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength); 68 | pTokenUser = (PTOKEN_USER)LocalAlloc(LPTR, dwLength); 69 | if(GetTokenInformation(hToken, TokenUser, pTokenUser, dwLength, &dwLength)) 70 | { 71 | if(ConvertSidToStringSidW(pTokenUser->User.Sid, ppszUserSid)) 72 | { 73 | bRet = TRUE; 74 | } 75 | } 76 | LocalFree(pTokenUser); 77 | CloseHandle(hToken); 78 | } 79 | 80 | return bRet; 81 | } 82 | -------------------------------------------------------------------------------- /common/common.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef COMMON_H 3 | #define COMMON_H 4 | 5 | #define TEXTSERVICE_NAME L"tsf-vim" 6 | #define TEXTSERVICE_VER L"0.1.1" 7 | 8 | #ifndef _DEBUG 9 | #define TEXTSERVICE_DESC TEXTSERVICE_NAME 10 | #else 11 | #define TEXTSERVICE_DESC TEXTSERVICE_NAME L"_DEBUG" 12 | #endif 13 | 14 | //for resource 15 | #define RC_AUTHOR "KIHARA Hideto" 16 | #define RC_PRODUCT "tsf-vim" 17 | #define RC_VERSION "0.1.1" 18 | #define RC_VERSION_D 0,1,1,0 19 | 20 | #define MAX_KRNLOBJNAME 256 21 | #define MAX_PRESERVEDKEY 8 22 | 23 | #define VIMCNFEXE L"imvimcnf.exe" 24 | #ifndef _DEBUG 25 | #define VIMKRNLOBJ L"tsf-vim-" 26 | #else 27 | #define VIMKRNLOBJ L"tsf-vim-debug-" 28 | #endif 29 | #define VIMCNFMUTEX VIMKRNLOBJ L"cnf-" 30 | 31 | typedef struct { 32 | BYTE digest[16]; 33 | } MD5_DIGEST; 34 | 35 | extern LPCWSTR fnconfigxml; //設定 36 | 37 | BOOL IsVersion62AndOver(); 38 | BOOL GetMD5(MD5_DIGEST *digest, CONST BYTE *data, DWORD datalen); 39 | BOOL GetUserSid(LPWSTR *ppszUserSid); 40 | 41 | #endif //COMMON_H 42 | -------------------------------------------------------------------------------- /common/common.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /common/common.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /common/configxml.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef CONFIGXML_H 3 | #define CONFIGXML_H 4 | 5 | #define NOT_S_OK not_s_ok 6 | #define EXIT_NOT_S_OK(hr) if((hr) != S_OK) goto NOT_S_OK 7 | 8 | typedef std::pair APPDATAXMLATTR; 9 | typedef std::vector APPDATAXMLROW; 10 | typedef std::vector APPDATAXMLLIST; 11 | 12 | HRESULT CreateStreamReader(LPCWSTR path, IXmlReader **ppReader, IStream **ppFileStream); 13 | void CloseStreamReader(IXmlReader *pReader, IStream *pFileStream); 14 | 15 | HRESULT ReadList(LPCWSTR path, LPCWSTR section, APPDATAXMLLIST &list); 16 | HRESULT ReadValue(LPCWSTR path, LPCWSTR section, LPCWSTR key, std::wstring &strxmlval, LPCWSTR defval = L""); 17 | 18 | HRESULT CreateStreamWriter(LPCWSTR path, IXmlWriter **ppWriter, IStream **ppFileStream); 19 | void CloseStreamWriter(IXmlWriter *pWriter, IStream *pFileStream); 20 | 21 | HRESULT WriterInit(LPCWSTR path, IXmlWriter **ppWriter, IStream **ppFileStream, BOOL indent = TRUE); 22 | HRESULT WriterFinal(IXmlWriter **ppWriter, IStream **ppFileStream); 23 | 24 | HRESULT WriterNewLine(IXmlWriter *pWriter); 25 | HRESULT WriterStartElement(IXmlWriter *pWriter, LPCWSTR element); 26 | HRESULT WriterEndElement(IXmlWriter *pWriter); 27 | HRESULT WriterAttribute(IXmlWriter *pWriter, LPCWSTR name, LPCWSTR value); 28 | 29 | HRESULT WriterStartSection(IXmlWriter *pWriter, LPCWSTR name); 30 | HRESULT WriterEndSection(IXmlWriter *pWriter); 31 | HRESULT WriterKey(IXmlWriter *pWriter, LPCWSTR key, LPCWSTR value); 32 | HRESULT WriterRow(IXmlWriter *pWriter, const APPDATAXMLROW &row); 33 | HRESULT WriterList(IXmlWriter *pWriter, const APPDATAXMLLIST &list, BOOL newline = FALSE); 34 | 35 | //tag 36 | extern LPCWSTR TagRoot; 37 | extern LPCWSTR TagSection; 38 | extern LPCWSTR TagKey; 39 | extern LPCWSTR TagEntry; 40 | extern LPCWSTR TagList; 41 | extern LPCWSTR TagRow; 42 | 43 | //attribute 44 | extern LPCWSTR AttributeName; 45 | extern LPCWSTR AttributeValue; 46 | extern LPCWSTR AttributeKey; 47 | extern LPCWSTR AttributeVKey; 48 | extern LPCWSTR AttributeMKey; 49 | 50 | //behavior section 51 | 52 | extern LPCWSTR SectionBehavior; 53 | 54 | //behavior keys 55 | 56 | extern LPCWSTR ValueOtherIme1; 57 | extern LPCWSTR ValueOtherIme2; 58 | extern LPCWSTR ValueOtherImeOffWait; 59 | 60 | //preservedkey section 61 | 62 | extern LPCWSTR SectionPreservedKeyNormal; 63 | extern LPCWSTR SectionPreservedKeyOtherIme; 64 | extern LPCWSTR SectionPreservedKeyOtherImeOff; 65 | 66 | #endif //CONFIGXML_H 67 | -------------------------------------------------------------------------------- /common/stdafx.cpp: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /common/stdafx.h: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /imcrvtip/Compartment.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | HRESULT CTextService::_SetCompartment(REFGUID rguid, const VARIANT *pvar) 6 | { 7 | ITfCompartmentMgr *pCompartmentMgr; 8 | ITfCompartment *pCompartment; 9 | HRESULT hr = E_FAIL; 10 | 11 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 12 | { 13 | if(pCompartmentMgr->GetCompartment(rguid, &pCompartment) == S_OK) 14 | { 15 | hr = pCompartment->SetValue(_ClientId, pvar); 16 | } 17 | pCompartmentMgr->Release(); 18 | } 19 | 20 | return hr; 21 | } 22 | 23 | HRESULT CTextService::_GetCompartment(REFGUID rguid, VARIANT *pvar) 24 | { 25 | ITfCompartmentMgr *pCompartmentMgr; 26 | ITfCompartment *pCompartment; 27 | HRESULT hr = E_FAIL; 28 | 29 | if(pvar == NULL) 30 | { 31 | return hr; 32 | } 33 | 34 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 35 | { 36 | if(pCompartmentMgr->GetCompartment(rguid, &pCompartment) == S_OK) 37 | { 38 | VARIANT var; 39 | if(pCompartment->GetValue(&var) == S_OK) 40 | { 41 | if(var.vt == VT_I4) 42 | { 43 | *pvar = var; 44 | hr = S_OK; 45 | } 46 | } 47 | } 48 | pCompartmentMgr->Release(); 49 | } 50 | 51 | return hr; 52 | } 53 | 54 | BOOL CTextService::_IsKeyboardDisabled() 55 | { 56 | ITfDocumentMgr *pDocumentMgrFocus = NULL; 57 | ITfContext *pContext = NULL; 58 | ITfCompartmentMgr *pCompartmentMgr = NULL; 59 | BOOL fDisabled = FALSE; 60 | 61 | if((_pThreadMgr->GetFocus(&pDocumentMgrFocus) != S_OK) || (pDocumentMgrFocus == NULL)) 62 | { 63 | fDisabled = TRUE; 64 | goto exit; 65 | } 66 | 67 | if((pDocumentMgrFocus->GetTop(&pContext) != S_OK) || (pContext == NULL)) 68 | { 69 | fDisabled = TRUE; 70 | goto exit; 71 | } 72 | 73 | if(pContext->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 74 | { 75 | ITfCompartment *pCompartmentDisabled; 76 | ITfCompartment *pCompartmentEmptyContext; 77 | 78 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_DISABLED, &pCompartmentDisabled) == S_OK) 79 | { 80 | VARIANT var; 81 | if(pCompartmentDisabled->GetValue(&var) == S_OK) 82 | { 83 | if(var.vt == VT_I4) 84 | { 85 | fDisabled = (BOOL)var.lVal; 86 | } 87 | } 88 | pCompartmentDisabled->Release(); 89 | } 90 | 91 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_EMPTYCONTEXT, &pCompartmentEmptyContext) == S_OK) 92 | { 93 | VARIANT var; 94 | if(pCompartmentEmptyContext->GetValue(&var) == S_OK) 95 | { 96 | if(var.vt == VT_I4) 97 | { 98 | fDisabled = (BOOL)var.lVal; 99 | } 100 | } 101 | pCompartmentEmptyContext->Release(); 102 | } 103 | 104 | pCompartmentMgr->Release(); 105 | } 106 | 107 | exit: 108 | if(pContext) 109 | { 110 | pContext->Release(); 111 | } 112 | 113 | if(pDocumentMgrFocus) 114 | { 115 | pDocumentMgrFocus->Release(); 116 | } 117 | 118 | return fDisabled; 119 | } 120 | 121 | BOOL CTextService::_IsKeyboardOpen() 122 | { 123 | ITfCompartmentMgr *pCompartmentMgr; 124 | BOOL fOpen = FALSE; 125 | 126 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 127 | { 128 | ITfCompartment *pCompartment; 129 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK) 130 | { 131 | VARIANT var; 132 | if(S_OK == pCompartment->GetValue(&var)) 133 | { 134 | if(var.vt == VT_I4) 135 | { 136 | fOpen = (BOOL)var.lVal; 137 | } 138 | } 139 | } 140 | pCompartmentMgr->Release(); 141 | } 142 | 143 | return fOpen; 144 | } 145 | 146 | HRESULT CTextService::_SetKeyboardOpen(BOOL fOpen) 147 | { 148 | ITfCompartmentMgr *pCompartmentMgr; 149 | ITfCompartment *pCompartment; 150 | HRESULT hr = E_FAIL; 151 | 152 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 153 | { 154 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK) 155 | { 156 | VARIANT var; 157 | var.vt = VT_I4; 158 | var.lVal = fOpen; 159 | hr = pCompartment->SetValue(_ClientId, &var); 160 | } 161 | pCompartmentMgr->Release(); 162 | } 163 | 164 | return hr; 165 | } 166 | -------------------------------------------------------------------------------- /imcrvtip/CompartmentEventSink.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | #include "LanguageBar.h" 5 | 6 | STDAPI CTextService::OnChange(REFGUID rguid) 7 | { 8 | if(IsEqualGUID(rguid, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE)) 9 | { 10 | _KeyboardOpenCloseChanged(); 11 | } 12 | else if(IsEqualGUID(rguid, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION)) 13 | { 14 | _KeyboardInputConversionChanged(); 15 | } 16 | 17 | return S_OK; 18 | } 19 | 20 | BOOL CTextService::_InitCompartmentEventSink() 21 | { 22 | ITfCompartmentMgr *pCompartmentMgr; 23 | ITfCompartment *pCompartment; 24 | ITfSource *pSource; 25 | 26 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 27 | { 28 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK) 29 | { 30 | if(pCompartment->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 31 | { 32 | if(pSource->AdviseSink(IID_IUNK_ARGS((ITfCompartmentEventSink *)this), 33 | &_dwCompartmentEventSinkOpenCloseCookie) != S_OK) 34 | { 35 | _dwCompartmentEventSinkOpenCloseCookie = TF_INVALID_COOKIE; 36 | } 37 | pSource->Release(); 38 | } 39 | pCompartment->Release(); 40 | } 41 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION, &pCompartment) == S_OK) 42 | { 43 | if(pCompartment->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 44 | { 45 | if(pSource->AdviseSink(IID_IUNK_ARGS((ITfCompartmentEventSink *)this), 46 | &_dwCompartmentEventSinkInputmodeConversionCookie) != S_OK) 47 | { 48 | _dwCompartmentEventSinkInputmodeConversionCookie = TF_INVALID_COOKIE; 49 | } 50 | pSource->Release(); 51 | } 52 | pCompartment->Release(); 53 | } 54 | pCompartmentMgr->Release(); 55 | } 56 | 57 | return (_dwCompartmentEventSinkOpenCloseCookie != TF_INVALID_COOKIE && 58 | _dwCompartmentEventSinkInputmodeConversionCookie != TF_INVALID_COOKIE); 59 | } 60 | 61 | void CTextService::_UninitCompartmentEventSink() 62 | { 63 | ITfCompartmentMgr *pCompartmentMgr; 64 | ITfCompartment *pCompartment; 65 | ITfSource *pSource; 66 | 67 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pCompartmentMgr)) == S_OK) 68 | { 69 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK) 70 | { 71 | if(pCompartment->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 72 | { 73 | pSource->UnadviseSink(_dwCompartmentEventSinkOpenCloseCookie); 74 | } 75 | pCompartment->Release(); 76 | } 77 | if(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION, &pCompartment) == S_OK) 78 | { 79 | if(pCompartment->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 80 | { 81 | pSource->UnadviseSink(_dwCompartmentEventSinkInputmodeConversionCookie); 82 | } 83 | pCompartment->Release(); 84 | } 85 | pCompartmentMgr->Release(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /imcrvtip/DllMain.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | 4 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 5 | { 6 | switch(fdwReason) 7 | { 8 | case DLL_PROCESS_ATTACH: 9 | g_hInst = hinstDLL; 10 | break; 11 | 12 | case DLL_PROCESS_DETACH: 13 | break; 14 | 15 | default: 16 | break; 17 | } 18 | 19 | return TRUE; 20 | } 21 | -------------------------------------------------------------------------------- /imcrvtip/EditSession.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef EDITSESSION_H 3 | #define EDITSESSION_H 4 | 5 | #include "imcrvtip.h" 6 | #include "TextService.h" 7 | 8 | class CEditSessionBase : public ITfEditSession 9 | { 10 | public: 11 | CEditSessionBase(CTextService *pTextService, ITfContext *pContext) 12 | { 13 | _cRef = 1; 14 | _pContext = pContext; 15 | _pContext->AddRef(); 16 | 17 | _pTextService = pTextService; 18 | _pTextService->AddRef(); 19 | } 20 | virtual ~CEditSessionBase() 21 | { 22 | _pContext->Release(); 23 | _pTextService->Release(); 24 | } 25 | 26 | // IUnknown 27 | STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj) 28 | { 29 | if(ppvObj == NULL) 30 | { 31 | return E_INVALIDARG; 32 | } 33 | 34 | *ppvObj = NULL; 35 | 36 | if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfEditSession)) 37 | { 38 | *ppvObj = (ITfLangBarItemButton *)this; 39 | } 40 | 41 | if(*ppvObj) 42 | { 43 | AddRef(); 44 | return S_OK; 45 | } 46 | 47 | return E_NOINTERFACE; 48 | } 49 | STDMETHODIMP_(ULONG) AddRef(void) 50 | { 51 | return ++_cRef; 52 | } 53 | STDMETHODIMP_(ULONG) Release(void) 54 | { 55 | if(--_cRef == 0) 56 | { 57 | delete this; 58 | return 0; 59 | } 60 | 61 | return _cRef; 62 | } 63 | 64 | // ITfEditSession 65 | virtual STDMETHODIMP DoEditSession(TfEditCookie ec) = 0; 66 | 67 | protected: 68 | ITfContext *_pContext; 69 | CTextService *_pTextService; 70 | 71 | private: 72 | LONG _cRef; 73 | }; 74 | 75 | #endif //EDITSESSION_H 76 | -------------------------------------------------------------------------------- /imcrvtip/FnConfigure.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "configxml.h" 3 | #include "imcrvtip.h" 4 | #include "TextService.h" 5 | 6 | //EscapeキーをNormal mode移行用に登録 7 | static const TF_PRESERVEDKEY configpreservedkeynormal[] = 8 | { 9 | { VK_ESCAPE/*0x1B*/, TF_MOD_IGNORE_ALL_MODIFIER } 10 | ,{ 0, 0 } 11 | }; 12 | 13 | //半/全キー等は、他IME切替に使用 14 | static const TF_PRESERVEDKEY configpreservedkeyotherime[] = 15 | { 16 | { VK_OEM_3/*0xC0*/, TF_MOD_ALT } 17 | ,{ VK_KANJI/*0x19*/, TF_MOD_IGNORE_ALL_MODIFIER } 18 | ,{ VK_OEM_AUTO/*0xF3*/, TF_MOD_IGNORE_ALL_MODIFIER } 19 | ,{ VK_OEM_ENLW/*0xF4*/, TF_MOD_IGNORE_ALL_MODIFIER } 20 | ,{ 0, 0 } 21 | }; 22 | 23 | //他IMEに切り替えて、他IMEをオフ状態にする 24 | static const TF_PRESERVEDKEY configpreservedkeyotherimeoff[] = 25 | { 26 | { VK_OEM_ATTN/*VK_DBE_ALPHANUMERIC 0xF0*/, TF_MOD_IGNORE_ALL_MODIFIER } 27 | ,{ 0, 0 } 28 | }; 29 | 30 | void CTextService::_CreateConfigPath() 31 | { 32 | WCHAR appdata[MAX_PATH]; 33 | 34 | pathconfigxml[0] = L'\0'; 35 | 36 | if(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, appdata) != S_OK) 37 | { 38 | appdata[0] = L'\0'; 39 | return; 40 | } 41 | 42 | wcsncat_s(appdata, L"\\", _TRUNCATE); 43 | wcsncat_s(appdata, TextServiceDesc, _TRUNCATE); 44 | wcsncat_s(appdata, L"\\", _TRUNCATE); 45 | 46 | _snwprintf_s(pathconfigxml, _TRUNCATE, L"%s%s", appdata, fnconfigxml); 47 | 48 | LPWSTR pszUserSid; 49 | WCHAR szDigest[32+1]; 50 | MD5_DIGEST digest; 51 | int i; 52 | 53 | ZeroMemory(szDigest, sizeof(szDigest)); 54 | 55 | if(GetUserSid(&pszUserSid)) 56 | { 57 | if(GetMD5(&digest, (CONST BYTE *)pszUserSid, (DWORD)wcslen(pszUserSid) * sizeof(WCHAR))) 58 | { 59 | for(i = 0; i < _countof(digest.digest); i++) 60 | { 61 | _snwprintf_s(&szDigest[i * 2], _countof(szDigest) - i * 2, _TRUNCATE, L"%02x", digest.digest[i]); 62 | } 63 | } 64 | 65 | LocalFree(pszUserSid); 66 | } 67 | 68 | _snwprintf_s(cnfmutexname, _TRUNCATE, L"%s%s", VIMCNFMUTEX, szDigest); 69 | } 70 | 71 | void CTextService::_LoadBehavior() 72 | { 73 | std::wstring strxmlval; 74 | 75 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherIme1, strxmlval); 76 | if(strxmlval == L"Alt+Shift") 77 | { 78 | c_otherime1 = L'A'; 79 | } 80 | else if(strxmlval == L"Ctrl+Shift") 81 | { 82 | c_otherime1 = L'C'; 83 | } 84 | else if(strxmlval == L"Win+Space") 85 | { 86 | c_otherime1 = L'W'; 87 | } 88 | else 89 | { 90 | if (IsVersion62AndOver()) // Windows 8 91 | { 92 | c_otherime1 = L'W'; 93 | } 94 | else 95 | { 96 | c_otherime1 = L'A'; 97 | } 98 | } 99 | 100 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherIme2, strxmlval); 101 | if(strxmlval.size() < 2) 102 | { 103 | c_otherime2 = 0; 104 | } 105 | else if(strxmlval[0] == L'*' && iswdigit(strxmlval[1])) 106 | { 107 | c_otherime2 = -(strxmlval[1] - L'0'); 108 | } 109 | else if(strxmlval[0] == L'+' && iswdigit(strxmlval[1])) 110 | { 111 | c_otherime2 = strxmlval[1]; 112 | } 113 | else 114 | { 115 | c_otherime2 = 0; 116 | } 117 | 118 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval); 119 | c_otherimeoffwait = wcstol(strxmlval.c_str(), NULL, 0); 120 | } 121 | static bool operator ==(const TF_PRESERVEDKEY &a, const TF_PRESERVEDKEY &b) 122 | { 123 | return a.uVKey == b.uVKey && a.uModifiers == b.uModifiers; 124 | } 125 | 126 | void CTextService::_LoadPreservedKey() 127 | { 128 | _LoadPreservedKeySub(SectionPreservedKeyNormal, preservedkeynormal, configpreservedkeynormal); 129 | _LoadPreservedKeySub(SectionPreservedKeyOtherIme, preservedkeyotherime, configpreservedkeyotherime); 130 | _LoadPreservedKeySub(SectionPreservedKeyOtherImeOff, preservedkeyotherimeoff, configpreservedkeyotherimeoff); 131 | vihandler.SetPreservedKeyNormal(preservedkeynormal); 132 | } 133 | 134 | void CTextService::_LoadPreservedKeySub(LPCWSTR SectionPreservedKey, TF_PRESERVEDKEY preservedkey[], const TF_PRESERVEDKEY configpreservedkey[]) 135 | { 136 | APPDATAXMLLIST list; 137 | APPDATAXMLLIST::iterator l_itr; 138 | APPDATAXMLROW::iterator r_itr; 139 | int i = 0; 140 | 141 | ZeroMemory(preservedkey, sizeof(TF_PRESERVEDKEY) * MAX_PRESERVEDKEY); 142 | 143 | if(ReadList(pathconfigxml, SectionPreservedKey, list) == S_OK && list.size() != 0) 144 | { 145 | for(l_itr = list.begin(); l_itr != list.end() && i < MAX_PRESERVEDKEY; l_itr++) 146 | { 147 | for(r_itr = l_itr->begin(); r_itr != l_itr->end(); r_itr++) 148 | { 149 | if(r_itr->first == AttributeVKey) 150 | { 151 | preservedkey[i].uVKey = wcstoul(r_itr->second.c_str(), NULL, 0); 152 | } 153 | else if(r_itr->first == AttributeMKey) 154 | { 155 | preservedkey[i].uModifiers = 156 | wcstoul(r_itr->second.c_str(), NULL, 0) & (TF_MOD_ALT | TF_MOD_CONTROL | TF_MOD_SHIFT); 157 | if((preservedkey[i].uModifiers & (TF_MOD_ALT | TF_MOD_CONTROL | TF_MOD_SHIFT)) == 0) 158 | { 159 | preservedkey[i].uModifiers = TF_MOD_IGNORE_ALL_MODIFIER; 160 | } 161 | } 162 | } 163 | 164 | i++; 165 | } 166 | } 167 | else 168 | { 169 | for(i = 0; configpreservedkey[i].uVKey != 0; i++) 170 | { 171 | preservedkey[i] = configpreservedkey[i]; 172 | } 173 | } 174 | } 175 | 176 | -------------------------------------------------------------------------------- /imcrvtip/FunctionProvider.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | HRESULT CTextService::GetType(GUID *pguid) 6 | { 7 | if(pguid == NULL) 8 | { 9 | return E_INVALIDARG; 10 | } 11 | 12 | *pguid = c_clsidTextService; 13 | 14 | return S_OK; 15 | } 16 | 17 | HRESULT CTextService::GetDescription(BSTR *pbstrDesc) 18 | { 19 | BSTR bstrDesc; 20 | 21 | if(pbstrDesc == NULL) 22 | { 23 | return E_INVALIDARG; 24 | } 25 | 26 | *pbstrDesc = NULL; 27 | 28 | bstrDesc = SysAllocString(TextServiceDesc); 29 | 30 | if(bstrDesc == NULL) 31 | { 32 | return E_OUTOFMEMORY; 33 | } 34 | 35 | *pbstrDesc = bstrDesc; 36 | 37 | return S_OK; 38 | } 39 | 40 | HRESULT CTextService::GetFunction(REFGUID rguid, REFIID riid, IUnknown **ppunk) 41 | { 42 | if(ppunk == NULL) 43 | { 44 | return E_INVALIDARG; 45 | } 46 | 47 | *ppunk = NULL; 48 | 49 | //This value can be GUID_NULL. 50 | if(!IsEqualGUID(rguid, GUID_NULL) && !IsEqualGUID(rguid, c_clsidTextService)) 51 | { 52 | return E_INVALIDARG; 53 | } 54 | 55 | if(IsEqualIID(riid, IID_ITfFnConfigure)) 56 | { 57 | *ppunk = (ITfFnConfigure *)this; 58 | } 59 | else if(IsEqualIID(riid, IID_ITfFnShowHelp)) 60 | { 61 | *ppunk = (ITfFnShowHelp *)this; 62 | } 63 | else 64 | { 65 | return E_INVALIDARG; 66 | } 67 | 68 | if(*ppunk) 69 | { 70 | AddRef(); 71 | return S_OK; 72 | } 73 | 74 | return E_NOINTERFACE; 75 | } 76 | 77 | HRESULT CTextService::GetDisplayName(BSTR *pbstrName) 78 | { 79 | BSTR bstrName; 80 | 81 | if(pbstrName == NULL) 82 | { 83 | return E_INVALIDARG; 84 | } 85 | 86 | *pbstrName = NULL; 87 | 88 | bstrName = SysAllocString(L"設定"); 89 | 90 | if(bstrName == NULL) 91 | { 92 | return E_OUTOFMEMORY; 93 | } 94 | 95 | *pbstrName = bstrName; 96 | 97 | return S_OK; 98 | } 99 | 100 | HRESULT CTextService::Show(HWND hwndParent, LANGID langid, REFGUID rguidProfile) 101 | { 102 | if(IsEqualGUID(rguidProfile, c_guidProfile)) 103 | { 104 | _StartConfigure(); 105 | } 106 | else 107 | { 108 | return E_INVALIDARG; 109 | } 110 | 111 | return S_OK; 112 | } 113 | 114 | HRESULT CTextService::Show(HWND hwndParent) 115 | { 116 | _StartConfigure(); 117 | return S_OK; 118 | } 119 | 120 | BOOL CTextService::_InitFunctionProvider() 121 | { 122 | ITfSourceSingle *pSourceSingle; 123 | HRESULT hr = E_FAIL; 124 | 125 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pSourceSingle)) == S_OK) 126 | { 127 | hr = pSourceSingle->AdviseSingleSink(_ClientId, IID_ITfFunctionProvider, (ITfFnConfigure *)this); 128 | pSourceSingle->Release(); 129 | } 130 | 131 | return (hr == S_OK); 132 | } 133 | 134 | void CTextService::_UninitFunctionProvider() 135 | { 136 | ITfSourceSingle *pSourceSingle; 137 | 138 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pSourceSingle)) == S_OK) 139 | { 140 | pSourceSingle->UnadviseSingleSink(_ClientId, IID_ITfFunctionProvider); 141 | pSourceSingle->Release(); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /imcrvtip/Globals.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | 4 | HINSTANCE g_hInst; 5 | 6 | LPCWSTR TextServiceDesc = TEXTSERVICE_DESC; 7 | LPCWSTR LangbarItemDesc = L"ver. " TEXTSERVICE_VER; 8 | 9 | // for Windows 8 10 | #if 1 11 | const GUID GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT = 12 | { 0x13A016DF, 0x560B, 0x46CD, { 0x94, 0x7A, 0x4C, 0x3A, 0xF1, 0xE0, 0xE3, 0x5D } }; 13 | const GUID GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT = 14 | { 0x25504FB4, 0x7BAB, 0x4BC1, { 0x9C, 0x69, 0xCF, 0x81, 0x89, 0x0F, 0x0E, 0xF5 } }; 15 | const GUID GUID_LBI_INPUTMODE = 16 | { 0x2C77A81E, 0x41CC, 0x4178, { 0xA3, 0xA7, 0x5F, 0x8A, 0x98, 0x75, 0x68, 0xE6 } }; 17 | #endif 18 | 19 | #ifndef _DEBUG 20 | 21 | // {75651692-5DBE-4f19-ACF7-E51848CDCAB1} 22 | const GUID c_clsidTextService = 23 | { 0x75651692, 0x5dbe, 0x4f19, { 0xac, 0xf7, 0xe5, 0x18, 0x48, 0xcd, 0xca, 0xb1 } }; 24 | 25 | // {5610A424-C061-4009-BCB8-39C24424D54E} 26 | const GUID c_guidProfile = 27 | { 0x5610a424, 0xc061, 0x4009, { 0xbc, 0xb8, 0x39, 0xc2, 0x44, 0x24, 0xd5, 0x4e } }; 28 | 29 | // {128434DD-F967-4d5b-9877-64FA4AC9DA35} 30 | const GUID c_guidPreservedKeyNormal = 31 | { 0x128434dd, 0xf967, 0x4d5b, { 0x98, 0x77, 0x64, 0xfa, 0x4a, 0xc9, 0xda, 0x35 } }; 32 | 33 | // {CC3C23D8-9E40-4135-80BB-576519CFBEAC} 34 | const GUID c_guidPreservedKeyOtherIme = 35 | { 0xcc3c23d8, 0x9e40, 0x4135, { 0x80, 0xbb, 0x57, 0x65, 0x19, 0xcf, 0xbe, 0xac } }; 36 | 37 | // {F31B570C-A68F-4160-BBB0-3811CA2B41CA} 38 | static const GUID c_guidPreservedKeyOtherImeOff = 39 | { 0xf31b570c, 0xa68f, 0x4160, { 0xbb, 0xb0, 0x38, 0x11, 0xca, 0x2b, 0x41, 0xca } }; 40 | 41 | // {5A18B688-A76C-4c07-A095-BEE6DB141D6D} 42 | const GUID c_guidLangBarItemButton = 43 | { 0x5a18b688, 0xa76c, 0x4c07, { 0xa0, 0x95, 0xbe, 0xe6, 0xdb, 0x14, 0x1d, 0x6d } }; 44 | 45 | #else 46 | 47 | // {4D97960C-1D59-4466-BEFE-4C1328D2550D} 48 | const GUID c_clsidTextService = 49 | { 0x4d97960c, 0x1d59, 0x4466, { 0xbe, 0xfe, 0x4c, 0x13, 0x28, 0xd2, 0x55, 0x0d } }; 50 | 51 | // {820E9894-024B-4bd1-98AF-3942B772CFF1} 52 | const GUID c_guidProfile = 53 | { 0x820e9894, 0x024b, 0x4bd1, { 0x98, 0xaf, 0x39, 0x42, 0xb7, 0x72, 0xcf, 0xf1 } }; 54 | 55 | // {F4BF0D3C-D4CE-456f-837E-FE6712C6A8C3} 56 | const GUID c_guidLangBarItemButton = 57 | { 0xf4bf0d3c, 0xd4ce, 0x456f, { 0x83, 0x7e, 0xfe, 0x67, 0x12, 0xc6, 0xa8, 0xc3 } }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /imcrvtip/Icon/vim.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/Icon/vim.ico -------------------------------------------------------------------------------- /imcrvtip/Icon/xDefault.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/Icon/xDefault.ico -------------------------------------------------------------------------------- /imcrvtip/Icon/xInsert.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/Icon/xInsert.ico -------------------------------------------------------------------------------- /imcrvtip/Icon/zDefault.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/Icon/zDefault.ico -------------------------------------------------------------------------------- /imcrvtip/Icon/zInsert.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/Icon/zInsert.ico -------------------------------------------------------------------------------- /imcrvtip/KeyEventSink.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | #include "LanguageBar.h" 5 | #include "mozc/win32/base/keyboard.h" 6 | 7 | static LPCWSTR c_PreservedKeyNormalDesc = L"Normal"; 8 | static LPCWSTR c_PreservedKeyOtherImeDesc = L"OtherIme"; 9 | static LPCWSTR c_PreservedKeyOtherImeOffDesc = L"OtherImeOff"; 10 | 11 | int CTextService::_IsKeyEaten(ITfContext *pContext, WPARAM wParam, LPARAM lParam, bool isKeyDown, bool isTest) 12 | { 13 | if(_IsKeyboardDisabled()) 14 | { 15 | return FALSE; 16 | } 17 | 18 | if(!_IsKeyboardOpen()) 19 | { 20 | return FALSE; 21 | } 22 | 23 | if(vihandler.IsThroughSelfSentKey()) 24 | { 25 | return FALSE; 26 | } 27 | 28 | if(vihandler.IsWaitingNextKey()) 29 | { 30 | return TRUE; 31 | } 32 | 33 | SHORT vk_ctrl = GetKeyState(VK_CONTROL) & 0x8000; 34 | 35 | WCHAR ch = _GetCh((BYTE)wParam); 36 | 37 | //TODO: 処理するキーを一か所で管理 38 | if(ch == CTRL('F') || ch == CTRL('B') || ch == CTRL('M')) 39 | { 40 | return TRUE; 41 | } 42 | 43 | //処理しないCtrlキー 44 | if(vk_ctrl) 45 | { 46 | vihandler.Reset(); 47 | return FALSE; 48 | } 49 | 50 | if(ch >= L'\x20') 51 | { 52 | return TRUE; 53 | } 54 | 55 | vihandler.Reset(); 56 | return FALSE; 57 | } 58 | 59 | STDAPI CTextService::OnSetFocus(BOOL fForeground) 60 | { 61 | return S_OK; 62 | } 63 | 64 | STDAPI CTextService::OnTestKeyDown(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) 65 | { 66 | int eaten = _IsKeyEaten(pic, wParam, lParam, TRUE, TRUE); 67 | if(eaten == -1) 68 | { 69 | *pfEaten = TRUE; 70 | return S_OK; 71 | } 72 | *pfEaten = (eaten == TRUE); 73 | return S_OK; 74 | } 75 | 76 | STDAPI CTextService::OnKeyDown(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) 77 | { 78 | int eaten = _IsKeyEaten(pic, wParam, lParam, TRUE, FALSE); 79 | if(eaten == -1) 80 | { 81 | *pfEaten = TRUE; 82 | return S_OK; 83 | } 84 | *pfEaten = (eaten == TRUE); 85 | 86 | if(*pfEaten) 87 | { 88 | _InvokeKeyHandler(pic, wParam, lParam, 0); 89 | } 90 | return S_OK; 91 | } 92 | 93 | STDAPI CTextService::OnTestKeyUp(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) 94 | { 95 | int eaten = _IsKeyEaten(pic, wParam, lParam, FALSE, TRUE); 96 | if(eaten == -1) 97 | { 98 | *pfEaten = TRUE; 99 | return S_OK; 100 | } 101 | *pfEaten = (eaten == TRUE); 102 | return S_OK; 103 | } 104 | 105 | STDAPI CTextService::OnKeyUp(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) 106 | { 107 | int eaten = _IsKeyEaten(pic, wParam, lParam, FALSE, FALSE); 108 | if(eaten == -1) 109 | { 110 | *pfEaten = TRUE; 111 | return S_OK; 112 | } 113 | *pfEaten = (eaten == TRUE); 114 | return S_OK; 115 | } 116 | 117 | STDAPI CTextService::OnPreservedKey(ITfContext *pic, REFGUID rguid, BOOL *pfEaten) 118 | { 119 | if(IsEqualGUID(rguid, c_guidPreservedKeyNormal)) 120 | { 121 | BOOL fOpen = _IsKeyboardOpen(); 122 | if(fOpen) 123 | { 124 | vihandler.Reset(); 125 | } 126 | vihandler.ResetThroughSelfSentKey(); 127 | _SetKeyboardOpen(TRUE); 128 | *pfEaten = TRUE; 129 | } 130 | else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherIme)) 131 | { 132 | vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, FALSE, c_otherimeoffwait); 133 | _SetKeyboardOpen(FALSE); 134 | *pfEaten = TRUE; 135 | } 136 | else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherImeOff)) 137 | { 138 | vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, TRUE, c_otherimeoffwait); 139 | _SetKeyboardOpen(FALSE); 140 | *pfEaten = TRUE; 141 | } 142 | else 143 | { 144 | *pfEaten = FALSE; 145 | } 146 | 147 | return S_OK; 148 | } 149 | 150 | BOOL CTextService::_InitKeyEventSink() 151 | { 152 | ITfKeystrokeMgr *pKeystrokeMgr; 153 | HRESULT hr = E_FAIL; 154 | 155 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pKeystrokeMgr)) == S_OK) 156 | { 157 | hr = pKeystrokeMgr->AdviseKeyEventSink(_ClientId, (ITfKeyEventSink *)this, TRUE); 158 | pKeystrokeMgr->Release(); 159 | } 160 | 161 | return (hr == S_OK); 162 | } 163 | 164 | void CTextService::_UninitKeyEventSink() 165 | { 166 | ITfKeystrokeMgr *pKeystrokeMgr; 167 | 168 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pKeystrokeMgr)) == S_OK) 169 | { 170 | pKeystrokeMgr->UnadviseKeyEventSink(_ClientId); 171 | pKeystrokeMgr->Release(); 172 | } 173 | } 174 | 175 | #define _PRESERVE_KEY(preservedkey, c_guidPreservedKey, c_PreservedKeyDesc) \ 176 | do \ 177 | { \ 178 | for(i=0; iPreserveKey(_ClientId, c_guidPreservedKey, \ 185 | &preservedkey[i], c_PreservedKeyDesc, (ULONG)wcslen(c_PreservedKeyDesc)); \ 186 | } \ 187 | } while(0) 188 | 189 | BOOL CTextService::_InitPreservedKey() 190 | { 191 | ITfKeystrokeMgr *pKeystrokeMgr; 192 | HRESULT hr = E_FAIL; 193 | int i; 194 | 195 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pKeystrokeMgr)) == S_OK) 196 | { 197 | _PRESERVE_KEY(preservedkeynormal, c_guidPreservedKeyNormal, c_PreservedKeyNormalDesc); 198 | _PRESERVE_KEY(preservedkeyotherime, c_guidPreservedKeyOtherIme, c_PreservedKeyOtherImeDesc); 199 | _PRESERVE_KEY(preservedkeyotherimeoff, c_guidPreservedKeyOtherImeOff, c_PreservedKeyOtherImeOffDesc); 200 | 201 | pKeystrokeMgr->Release(); 202 | } 203 | 204 | return (hr == S_OK); 205 | } 206 | 207 | #define _UNPRESERVE_KEY(preservedkey, c_guidPreservedKey) \ 208 | do \ 209 | { \ 210 | for(i=0; iUnpreserveKey(c_guidPreservedKey, &preservedkey[i]); \ 217 | } \ 218 | } while(0) 219 | 220 | void CTextService::_UninitPreservedKey() 221 | { 222 | ITfKeystrokeMgr *pKeystrokeMgr; 223 | int i; 224 | 225 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pKeystrokeMgr)) == S_OK) 226 | { 227 | _UNPRESERVE_KEY(preservedkeynormal, c_guidPreservedKeyNormal); 228 | _UNPRESERVE_KEY(preservedkeyotherime, c_guidPreservedKeyOtherIme); 229 | _UNPRESERVE_KEY(preservedkeyotherimeoff, c_guidPreservedKeyOtherImeOff); 230 | 231 | pKeystrokeMgr->Release(); 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /imcrvtip/KeyHandler.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "EditSession.h" 4 | #include "TextService.h" 5 | #include "LanguageBar.h" 6 | 7 | class CKeyHandlerEditSession : public CEditSessionBase 8 | { 9 | public: 10 | CKeyHandlerEditSession(CTextService *pTextService, ITfContext *pContext, WPARAM wParam, BYTE bSf) : CEditSessionBase(pTextService, pContext) 11 | { 12 | _wParam = wParam; 13 | _bSf = bSf; 14 | } 15 | 16 | // ITfEditSession 17 | STDMETHODIMP DoEditSession(TfEditCookie ec) 18 | { 19 | #ifdef _DEBUG 20 | _pTextService->_HandleKey(ec, _pContext, _wParam, _bSf); 21 | #else 22 | __try 23 | { 24 | _pTextService->_HandleKey(ec, _pContext, _wParam, _bSf); 25 | } 26 | __except(EXCEPTION_EXECUTE_HANDLER) 27 | { 28 | _pTextService->_ResetStatus(); 29 | } 30 | 31 | #endif 32 | return S_OK; 33 | } 34 | 35 | private: 36 | WPARAM _wParam; 37 | BYTE _bSf; 38 | }; 39 | 40 | HRESULT CTextService::_InvokeKeyHandler(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BYTE bSf) 41 | { 42 | CKeyHandlerEditSession *pEditSession; 43 | HRESULT hr = E_FAIL; 44 | 45 | pEditSession = new CKeyHandlerEditSession(this, pContext, wParam, bSf); 46 | if(pEditSession != NULL) 47 | { 48 | hr = pContext->RequestEditSession(_ClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hr); 49 | pEditSession->Release(); 50 | } 51 | 52 | return hr; 53 | } 54 | 55 | HRESULT CTextService::_HandleKey(TfEditCookie ec, ITfContext *pContext, WPARAM wParam, BYTE bSf) 56 | { 57 | WCHAR ch; 58 | 59 | ch = _GetCh((BYTE)wParam); 60 | if(ch != L'\0') 61 | { 62 | vihandler.HandleKey(ec, pContext, ch, (BYTE)wParam); 63 | } 64 | 65 | return S_OK; 66 | } 67 | 68 | void CTextService::_KeyboardOpenCloseChanged() 69 | { 70 | if(_pThreadMgr == NULL) 71 | { 72 | return; 73 | } 74 | 75 | BOOL fOpen = _IsKeyboardOpen(); 76 | if(fOpen) 77 | { 78 | _ResetStatus(); 79 | 80 | _LoadBehavior(); 81 | 82 | _UninitPreservedKey(); 83 | _LoadPreservedKey(); 84 | _InitPreservedKey(); 85 | } 86 | else 87 | { 88 | _UninitPreservedKey(); 89 | _LoadPreservedKey(); 90 | _InitPreservedKey(); 91 | 92 | _ResetStatus(); 93 | } 94 | 95 | _UpdateLanguageBar(); 96 | } 97 | 98 | void CTextService::_KeyboardInputConversionChanged() 99 | { 100 | VARIANT var; 101 | 102 | if(_GetCompartment(GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION, &var) != S_OK) 103 | { 104 | var.vt = VT_I4; 105 | var.lVal = TF_CONVERSIONMODE_NATIVE | TF_CONVERSIONMODE_FULLSHAPE; 106 | _SetCompartment(GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION, &var); 107 | } 108 | } 109 | 110 | void CTextService::_ResetStatus() 111 | { 112 | vihandler.Reset(); 113 | } 114 | -------------------------------------------------------------------------------- /imcrvtip/KeyHandlerConv.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | WCHAR CTextService::_GetCh(BYTE vk, BYTE vkoff) 6 | { 7 | BYTE keystate[256]; 8 | WCHAR szU[4]; 9 | WCHAR u; 10 | 11 | GetKeyboardState(keystate); 12 | 13 | int retu = ToUnicode(vk, 0, keystate, szU, _countof(szU), 0); 14 | if(retu != 1) 15 | { 16 | u = L'\0'; 17 | } 18 | else 19 | { 20 | u = szU[0]; 21 | } 22 | 23 | return u; 24 | } 25 | -------------------------------------------------------------------------------- /imcrvtip/KeyHandlerDictionary.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | void CTextService::_StartConfigure() 6 | { 7 | HANDLE hMutex = OpenMutexW(SYNCHRONIZE, FALSE, cnfmutexname); 8 | if(hMutex != NULL) 9 | { 10 | CloseHandle(hMutex); 11 | return; 12 | } 13 | 14 | _StartProcess(VIMCNFEXE); 15 | } 16 | 17 | void CTextService::_StartProcess(LPCWSTR fname) 18 | { 19 | WCHAR path[MAX_PATH]; 20 | WCHAR drive[_MAX_DRIVE]; 21 | WCHAR dir[_MAX_DIR]; 22 | PROCESS_INFORMATION pi; 23 | STARTUPINFOW si; 24 | 25 | GetModuleFileNameW(g_hInst, path, _countof(path)); 26 | _wsplitpath_s(path, drive, _countof(drive), dir, _countof(dir), NULL, 0, NULL, 0); 27 | _snwprintf_s(path, _TRUNCATE, L"%s%s%s", drive, dir, fname); 28 | 29 | ZeroMemory(&pi, sizeof(pi)); 30 | ZeroMemory(&si, sizeof(si)); 31 | si.cb = sizeof(si); 32 | 33 | if(CreateProcessW(path, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 34 | { 35 | CloseHandle(pi.hProcess); 36 | CloseHandle(pi.hThread); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /imcrvtip/LanguageBar.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef LANGUAGEBAR_H 3 | #define LANGUAGEBAR_H 4 | 5 | class CLangBarItemButton : 6 | public ITfLangBarItemButton, 7 | public ITfSource 8 | { 9 | public: 10 | CLangBarItemButton(CTextService *pTextService, REFGUID guid); 11 | ~CLangBarItemButton(); 12 | 13 | // IUnknown 14 | STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); 15 | STDMETHODIMP_(ULONG) AddRef(void); 16 | STDMETHODIMP_(ULONG) Release(void); 17 | 18 | // ITfLangBarItem 19 | STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo); 20 | STDMETHODIMP GetStatus(DWORD *pdwStatus); 21 | STDMETHODIMP Show(BOOL fShow); 22 | STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip); 23 | 24 | // ITfLangBarItemButton 25 | STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea); 26 | STDMETHODIMP InitMenu(ITfMenu *pMenu); 27 | STDMETHODIMP OnMenuSelect(UINT wID); 28 | STDMETHODIMP GetIcon(HICON *phIcon); 29 | STDMETHODIMP GetText(BSTR *pbstrText); 30 | 31 | // ITfSource 32 | STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie); 33 | STDMETHODIMP UnadviseSink(DWORD dwCookie); 34 | 35 | STDMETHODIMP _Update(); 36 | 37 | private: 38 | LONG _cRef; 39 | 40 | CTextService *_pTextService; 41 | 42 | ITfLangBarItemSink *_pLangBarItemSink; 43 | TF_LANGBARITEMINFO _LangBarItemInfo; 44 | }; 45 | 46 | #endif //LANGUAGEBAR_H 47 | -------------------------------------------------------------------------------- /imcrvtip/Register.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | 4 | #define CLSID_STRLEN 38 5 | #define TEXTSERVICE_MODEL L"Apartment" 6 | #define TEXTSERVICE_LANGID MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) 7 | #ifndef _DEBUG 8 | #define TEXTSERVICE_ICON_INDEX 0 // see resource script file 9 | #else 10 | #define TEXTSERVICE_ICON_INDEX 1 11 | #endif 12 | 13 | static const WCHAR c_szInfoKeyPrefix[] = L"CLSID\\"; 14 | static const WCHAR c_szInProcSvr32[] = L"InProcServer32"; 15 | static const WCHAR c_szModelName[] = L"ThreadingModel"; 16 | 17 | static const GUID c_guidCategory[] = 18 | { 19 | GUID_TFCAT_TIP_KEYBOARD, 20 | GUID_TFCAT_TIPCAP_SECUREMODE, 21 | GUID_TFCAT_TIPCAP_UIELEMENTENABLED, 22 | GUID_TFCAT_TIPCAP_INPUTMODECOMPARTMENT, 23 | GUID_TFCAT_TIPCAP_COMLESS, 24 | GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER 25 | }; 26 | // for Windows 8 or later 27 | static const GUID c_guidCategory8[] = 28 | { 29 | GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT, 30 | GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT 31 | }; 32 | 33 | BOOL RegisterProfiles() 34 | { 35 | ITfInputProcessorProfiles *pInputProcessProfiles; 36 | WCHAR fileName[MAX_PATH]; 37 | HRESULT hr = E_FAIL; 38 | 39 | if(CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pInputProcessProfiles)) != S_OK) 40 | { 41 | goto exit; 42 | } 43 | 44 | if(pInputProcessProfiles->Register(c_clsidTextService) != S_OK) 45 | { 46 | goto exit_r; 47 | } 48 | 49 | GetModuleFileNameW(g_hInst, fileName, _countof(fileName)); 50 | 51 | hr = pInputProcessProfiles->AddLanguageProfile(c_clsidTextService, TEXTSERVICE_LANGID, 52 | c_guidProfile, TextServiceDesc, -1, fileName, -1, TEXTSERVICE_ICON_INDEX); 53 | 54 | exit_r: 55 | pInputProcessProfiles->Release(); 56 | 57 | exit: 58 | return (hr == S_OK); 59 | } 60 | 61 | void UnregisterProfiles() 62 | { 63 | ITfInputProcessorProfiles *pInputProcessProfiles; 64 | 65 | if(CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pInputProcessProfiles)) == S_OK) 66 | { 67 | pInputProcessProfiles->Unregister(c_clsidTextService); 68 | pInputProcessProfiles->Release(); 69 | } 70 | } 71 | 72 | BOOL RegisterCategories() 73 | { 74 | ITfCategoryMgr *pCategoryMgr; 75 | int i; 76 | 77 | if(CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCategoryMgr)) == S_OK) 78 | { 79 | for(i=0; i<_countof(c_guidCategory); i++) 80 | { 81 | pCategoryMgr->RegisterCategory(c_clsidTextService, c_guidCategory[i], c_clsidTextService); 82 | } 83 | // for Windows 8 or later 84 | if(IsVersion62AndOver()) 85 | { 86 | for(i=0; i<_countof(c_guidCategory8); i++) 87 | { 88 | pCategoryMgr->RegisterCategory(c_clsidTextService, c_guidCategory8[i], c_clsidTextService); 89 | } 90 | } 91 | 92 | pCategoryMgr->Release(); 93 | } 94 | else 95 | { 96 | return FALSE; 97 | } 98 | 99 | return TRUE; 100 | } 101 | 102 | void UnregisterCategories() 103 | { 104 | ITfCategoryMgr *pCategoryMgr; 105 | int i; 106 | 107 | if(CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCategoryMgr)) == S_OK) 108 | { 109 | for(i=0; i<_countof(c_guidCategory); i++) 110 | { 111 | pCategoryMgr->UnregisterCategory(c_clsidTextService, c_guidCategory[i], c_clsidTextService); 112 | } 113 | // for Windows 8 or later 114 | if(IsVersion62AndOver()) 115 | { 116 | for(i=0; i<_countof(c_guidCategory8); i++) 117 | { 118 | pCategoryMgr->UnregisterCategory(c_clsidTextService, c_guidCategory8[i], c_clsidTextService); 119 | } 120 | } 121 | 122 | pCategoryMgr->Release(); 123 | } 124 | } 125 | 126 | BOOL RegisterServer() 127 | { 128 | WCHAR szInfoKey[_countof(c_szInfoKeyPrefix) + CLSID_STRLEN]; 129 | HKEY hKey; 130 | HKEY hSubKey; 131 | BOOL fRet = FALSE; 132 | WCHAR fileName[MAX_PATH]; 133 | 134 | if(StringFromGUID2(c_clsidTextService, szInfoKey + _countof(c_szInfoKeyPrefix) - 1, CLSID_STRLEN + 1) == 0) 135 | { 136 | return FALSE; 137 | } 138 | 139 | wmemcpy_s(szInfoKey, _countof(szInfoKey), c_szInfoKeyPrefix, _countof(c_szInfoKeyPrefix) - 1); 140 | 141 | if(RegCreateKeyExW(HKEY_CLASSES_ROOT, szInfoKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) 142 | { 143 | return FALSE; 144 | } 145 | 146 | if(RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE *)TextServiceDesc, (DWORD)(wcslen(TextServiceDesc) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) 147 | { 148 | goto exit; 149 | } 150 | 151 | if(RegCreateKeyExW(hKey, c_szInProcSvr32, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, NULL) != ERROR_SUCCESS) 152 | { 153 | goto exit; 154 | } 155 | 156 | GetModuleFileNameW(g_hInst, fileName, _countof(fileName)); 157 | 158 | if(RegSetValueExW(hSubKey, NULL, 0, REG_SZ, (BYTE *)fileName, (DWORD)(wcslen(fileName) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) 159 | { 160 | goto exit_sub; 161 | } 162 | 163 | if(RegSetValueExW(hSubKey, c_szModelName, 0, REG_SZ, (BYTE *)TEXTSERVICE_MODEL, (DWORD)(wcslen(TEXTSERVICE_MODEL) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) 164 | { 165 | goto exit_sub; 166 | } 167 | 168 | fRet = TRUE; 169 | 170 | exit_sub: 171 | RegCloseKey(hSubKey); 172 | 173 | exit: 174 | RegCloseKey(hKey); 175 | 176 | return fRet; 177 | } 178 | 179 | void UnregisterServer() 180 | { 181 | WCHAR szInfoKey[_countof(c_szInfoKeyPrefix) + CLSID_STRLEN]; 182 | 183 | if(StringFromGUID2(c_clsidTextService, szInfoKey + _countof(c_szInfoKeyPrefix) - 1, CLSID_STRLEN + 1) == 0) 184 | { 185 | return; 186 | } 187 | 188 | wmemcpy_s(szInfoKey, _countof(szInfoKey), c_szInfoKeyPrefix, _countof(c_szInfoKeyPrefix) - 1); 189 | 190 | SHDeleteKeyW(HKEY_CLASSES_ROOT, szInfoKey); 191 | } 192 | -------------------------------------------------------------------------------- /imcrvtip/Server.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | // Register 6 | BOOL RegisterProfiles(); 7 | void UnregisterProfiles(); 8 | BOOL RegisterCategories(); 9 | void UnregisterCategories(); 10 | BOOL RegisterServer(); 11 | void UnregisterServer(); 12 | 13 | static LONG g_cRefDll = 0; 14 | 15 | class CClassFactory : public IClassFactory 16 | { 17 | public: 18 | // IUnknown 19 | STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); 20 | STDMETHODIMP_(ULONG) AddRef(void); 21 | STDMETHODIMP_(ULONG) Release(void); 22 | 23 | // IClassFactory 24 | STDMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj); 25 | STDMETHODIMP LockServer(BOOL fLock); 26 | }; 27 | 28 | STDAPI CClassFactory::QueryInterface(REFIID riid, void **ppvObj) 29 | { 30 | if(ppvObj == NULL) 31 | { 32 | return E_INVALIDARG; 33 | } 34 | 35 | *ppvObj = NULL; 36 | 37 | if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) 38 | { 39 | *ppvObj = this; 40 | DllAddRef(); 41 | } 42 | else 43 | { 44 | return E_NOINTERFACE; 45 | } 46 | 47 | return S_OK; 48 | } 49 | 50 | STDAPI_(ULONG) CClassFactory::AddRef() 51 | { 52 | return DllAddRef(); 53 | } 54 | 55 | STDAPI_(ULONG) CClassFactory::Release() 56 | { 57 | return DllRelease(); 58 | } 59 | 60 | STDAPI CClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj) 61 | { 62 | CTextService *pTextService; 63 | HRESULT hr; 64 | 65 | if(ppvObj == NULL) 66 | { 67 | return E_INVALIDARG; 68 | } 69 | 70 | *ppvObj = NULL; 71 | 72 | if(NULL != pUnkOuter) 73 | { 74 | return CLASS_E_NOAGGREGATION; 75 | } 76 | 77 | pTextService = new CTextService(); 78 | 79 | if(pTextService == NULL) 80 | { 81 | return E_OUTOFMEMORY; 82 | } 83 | 84 | hr = pTextService->QueryInterface(riid, ppvObj); 85 | 86 | pTextService->Release(); 87 | 88 | return hr; 89 | } 90 | 91 | STDAPI CClassFactory::LockServer(BOOL fLock) 92 | { 93 | if(fLock) 94 | { 95 | DllAddRef(); 96 | } 97 | else 98 | { 99 | DllRelease(); 100 | } 101 | 102 | return S_OK; 103 | } 104 | 105 | STDAPI DllCanUnloadNow(void) 106 | { 107 | return g_cRefDll <= 0 ? S_OK : S_FALSE; 108 | } 109 | 110 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppvObj) 111 | { 112 | static CClassFactory factory; 113 | 114 | if(ppvObj == NULL) 115 | { 116 | return E_INVALIDARG; 117 | } 118 | 119 | *ppvObj = NULL; 120 | 121 | if((IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) && 122 | IsEqualGUID(rclsid, c_clsidTextService)) 123 | { 124 | *ppvObj = &factory; 125 | DllAddRef(); 126 | return S_OK; 127 | } 128 | 129 | return CLASS_E_CLASSNOTAVAILABLE; 130 | } 131 | 132 | STDAPI DllRegisterServer(void) 133 | { 134 | if(!RegisterServer() || !RegisterCategories() || !RegisterProfiles()) 135 | { 136 | DllUnregisterServer(); 137 | return E_FAIL; 138 | } 139 | 140 | return S_OK; 141 | } 142 | 143 | STDAPI DllUnregisterServer(void) 144 | { 145 | UnregisterProfiles(); 146 | UnregisterCategories(); 147 | UnregisterServer(); 148 | 149 | return S_OK; 150 | } 151 | 152 | LONG DllAddRef(void) 153 | { 154 | return InterlockedIncrement(&g_cRefDll); 155 | } 156 | 157 | LONG DllRelease(void) 158 | { 159 | return InterlockedDecrement(&g_cRefDll); 160 | } 161 | -------------------------------------------------------------------------------- /imcrvtip/TextService.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | CTextService::CTextService() 6 | : vihandler(this), c_otherimeoffwait(0) 7 | { 8 | DllAddRef(); 9 | 10 | _cRef = 1; 11 | 12 | _pThreadMgr = NULL; 13 | _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE; 14 | _dwCompartmentEventSinkOpenCloseCookie = TF_INVALID_COOKIE; 15 | _dwCompartmentEventSinkInputmodeConversionCookie = TF_INVALID_COOKIE; 16 | 17 | _ResetStatus(); 18 | } 19 | 20 | CTextService::~CTextService() 21 | { 22 | DllRelease(); 23 | } 24 | 25 | STDAPI CTextService::QueryInterface(REFIID riid, void **ppvObj) 26 | { 27 | if(ppvObj == NULL) 28 | { 29 | return E_INVALIDARG; 30 | } 31 | 32 | *ppvObj = NULL; 33 | 34 | if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfTextInputProcessor)) 35 | { 36 | *ppvObj = (ITfTextInputProcessor *)this; 37 | } 38 | else if(IsEqualIID(riid, IID_ITfTextInputProcessorEx)) 39 | { 40 | *ppvObj = (ITfTextInputProcessorEx *)this; 41 | } 42 | else if(IsEqualIID(riid, IID_ITfThreadMgrEventSink)) 43 | { 44 | *ppvObj = (ITfThreadMgrEventSink *)this; 45 | } 46 | else if(IsEqualIID(riid, IID_ITfCompartmentEventSink)) 47 | { 48 | *ppvObj = (ITfCompartmentEventSink *)this; 49 | } 50 | else if(IsEqualIID(riid, IID_ITfKeyEventSink)) 51 | { 52 | *ppvObj = (ITfKeyEventSink *)this; 53 | } 54 | else if(IsEqualIID(riid, IID_ITfFunctionProvider)) 55 | { 56 | *ppvObj = (ITfFunctionProvider *)this; 57 | } 58 | else if(IsEqualIID(riid, IID_ITfFnConfigure)) 59 | { 60 | *ppvObj = (ITfFnConfigure *)this; 61 | } 62 | else if(IsEqualIID(riid, IID_ITfFnShowHelp)) 63 | { 64 | *ppvObj = (ITfFnShowHelp *)this; 65 | } 66 | 67 | if(*ppvObj) 68 | { 69 | AddRef(); 70 | return S_OK; 71 | } 72 | 73 | return E_NOINTERFACE; 74 | } 75 | 76 | STDAPI_(ULONG) CTextService::AddRef() 77 | { 78 | return ++_cRef; 79 | } 80 | 81 | STDAPI_(ULONG) CTextService::Release() 82 | { 83 | if(--_cRef == 0) 84 | { 85 | delete this; 86 | return 0; 87 | } 88 | 89 | return _cRef; 90 | } 91 | 92 | STDAPI CTextService::Activate(ITfThreadMgr *ptim, TfClientId tid) 93 | { 94 | return ActivateEx(ptim, tid, 0); 95 | } 96 | 97 | STDAPI CTextService::ActivateEx(ITfThreadMgr *ptim, TfClientId tid, DWORD dwFlags) 98 | { 99 | //_wsetlocale(LC_ALL, L"JPN"); 100 | 101 | _CreateConfigPath(); 102 | 103 | _pThreadMgr = ptim; 104 | _pThreadMgr->AddRef(); 105 | _ClientId = tid; 106 | 107 | if(!_InitThreadMgrEventSink()) 108 | { 109 | goto exit; 110 | } 111 | 112 | if(!_InitCompartmentEventSink()) 113 | { 114 | goto exit; 115 | } 116 | 117 | if(!_InitLanguageBar()) 118 | { 119 | goto exit; 120 | } 121 | 122 | if(!_InitKeyEventSink()) 123 | { 124 | goto exit; 125 | } 126 | 127 | _LoadPreservedKey(); 128 | 129 | if(!_InitPreservedKey()) 130 | { 131 | goto exit; 132 | } 133 | 134 | if(!_InitFunctionProvider()) 135 | { 136 | goto exit; 137 | } 138 | 139 | _SetKeyboardOpen(TRUE); 140 | _KeyboardOpenCloseChanged(); 141 | 142 | return S_OK; 143 | 144 | exit: 145 | Deactivate(); 146 | return E_FAIL; 147 | } 148 | 149 | STDAPI CTextService::Deactivate() 150 | { 151 | _UninitFunctionProvider(); 152 | 153 | _UninitPreservedKey(); 154 | 155 | _UninitKeyEventSink(); 156 | 157 | _UninitLanguageBar(); 158 | 159 | _UninitCompartmentEventSink(); 160 | 161 | _UninitThreadMgrEventSink(); 162 | 163 | if(_pThreadMgr != NULL) 164 | { 165 | _pThreadMgr->Release(); 166 | _pThreadMgr = NULL; 167 | } 168 | 169 | _ClientId = TF_CLIENTID_NULL; 170 | 171 | return S_OK; 172 | } 173 | -------------------------------------------------------------------------------- /imcrvtip/TextService.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef TEXTSERVICE_H 3 | #define TEXTSERVICE_H 4 | 5 | #include "imcrvtip.h" 6 | #include "ViKeyHandler.h" 7 | 8 | class CLangBarItemButton; 9 | 10 | class CTextService : 11 | public ITfTextInputProcessorEx, 12 | public ITfThreadMgrEventSink, 13 | public ITfCompartmentEventSink, 14 | public ITfKeyEventSink, 15 | public ITfFunctionProvider, 16 | public ITfFnConfigure, 17 | public ITfFnShowHelp 18 | { 19 | public: 20 | CTextService(); 21 | ~CTextService(); 22 | 23 | // IUnknown 24 | STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); 25 | STDMETHODIMP_(ULONG) AddRef(void); 26 | STDMETHODIMP_(ULONG) Release(void); 27 | 28 | // ITfTextInputProcessor 29 | STDMETHODIMP Activate(ITfThreadMgr *ptim, TfClientId tid); 30 | STDMETHODIMP Deactivate(); 31 | 32 | // ITfTextInputProcessorEx 33 | STDMETHODIMP ActivateEx(ITfThreadMgr *ptim, TfClientId tid, DWORD dwFlags); 34 | 35 | // ITfThreadMgrEventSink 36 | STDMETHODIMP OnInitDocumentMgr(ITfDocumentMgr *pdim); 37 | STDMETHODIMP OnUninitDocumentMgr(ITfDocumentMgr *pdim); 38 | STDMETHODIMP OnSetFocus(ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus); 39 | STDMETHODIMP OnPushContext(ITfContext *pic); 40 | STDMETHODIMP OnPopContext(ITfContext *pic); 41 | 42 | // ItfCompartmentEventSink 43 | STDMETHODIMP OnChange(REFGUID rguid); 44 | 45 | // ITfKeyEventSink 46 | STDMETHODIMP OnSetFocus(BOOL fForeground); 47 | STDMETHODIMP OnTestKeyDown(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten); 48 | STDMETHODIMP OnKeyDown(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten); 49 | STDMETHODIMP OnTestKeyUp(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten); 50 | STDMETHODIMP OnKeyUp(ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten); 51 | STDMETHODIMP OnPreservedKey(ITfContext *pic, REFGUID rguid, BOOL *pfEaten); 52 | 53 | // ITfCompositionSink 54 | STDMETHODIMP OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition *pComposition); 55 | 56 | // ITfFunctionProvider 57 | STDMETHODIMP GetType(GUID *pguid); 58 | STDMETHODIMP GetDescription(BSTR *pbstrDesc); 59 | STDMETHODIMP GetFunction(REFGUID rguid, REFIID riid, IUnknown **ppunk); 60 | 61 | // ITfFunction 62 | STDMETHODIMP GetDisplayName(BSTR *pbstrName); 63 | 64 | // ITfFnConfigure 65 | STDMETHODIMP Show(HWND hwndParent, LANGID langid, REFGUID rguidProfile); 66 | 67 | // ITfFnShowHelp 68 | STDMETHODIMP Show(HWND hwndParent); 69 | 70 | ITfThreadMgr *_GetThreadMgr() 71 | { 72 | return _pThreadMgr; 73 | } 74 | TfClientId _GetClientId() 75 | { 76 | return _ClientId; 77 | } 78 | 79 | // Compartment 80 | HRESULT _SetCompartment(REFGUID rguid, const VARIANT *pvar); 81 | HRESULT _GetCompartment(REFGUID rguid, VARIANT *pvar); 82 | BOOL _IsKeyboardDisabled(); 83 | BOOL _IsKeyboardOpen(); 84 | HRESULT _SetKeyboardOpen(BOOL fOpen); 85 | 86 | // LanguageBar 87 | void _UpdateLanguageBar(); 88 | 89 | // KeyHandler 90 | HRESULT _InvokeKeyHandler(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BYTE bSf); 91 | HRESULT _HandleKey(TfEditCookie ec, ITfContext *pContext, WPARAM wParam, BYTE bSf); 92 | void _KeyboardOpenCloseChanged(); 93 | void _KeyboardInputConversionChanged(); 94 | void _ResetStatus(); 95 | 96 | // KeyHandlerConv 97 | WCHAR _GetCh(BYTE vk, BYTE vkoff = 0); 98 | 99 | // KeyHandlerDictionary 100 | void _StartConfigure(); 101 | void _StartProcess(LPCWSTR fname); 102 | 103 | // FnConfigure 104 | void _CreateConfigPath(); 105 | void _LoadBehavior(); 106 | void _LoadPreservedKey(); 107 | void _LoadPreservedKeySub(LPCWSTR SectionPreservedKey, TF_PRESERVEDKEY preservedkey[], const TF_PRESERVEDKEY configpreservedkey[]); 108 | 109 | private: 110 | LONG _cRef; 111 | 112 | BOOL _InitThreadMgrEventSink(); 113 | void _UninitThreadMgrEventSink(); 114 | 115 | BOOL _InitCompartmentEventSink(); 116 | void _UninitCompartmentEventSink(); 117 | 118 | BOOL _InitKeyEventSink(); 119 | void _UninitKeyEventSink(); 120 | 121 | BOOL _InitPreservedKey(); 122 | void _UninitPreservedKey(); 123 | 124 | BOOL _InitLanguageBar(); 125 | void _UninitLanguageBar(); 126 | 127 | BOOL _InitFunctionProvider(); 128 | void _UninitFunctionProvider(); 129 | 130 | int _IsKeyEaten(ITfContext *pContext, WPARAM wParam, LPARAM lParam, bool isKeyDown, bool isTest); 131 | 132 | ITfThreadMgr *_pThreadMgr; 133 | TfClientId _ClientId; 134 | 135 | DWORD _dwThreadMgrEventSinkCookie; 136 | DWORD _dwCompartmentEventSinkOpenCloseCookie; 137 | DWORD _dwCompartmentEventSinkInputmodeConversionCookie; 138 | 139 | CLangBarItemButton *_pLangBarItem; 140 | CLangBarItemButton *_pLangBarItemI; 141 | 142 | private: 143 | //ファイルパス 144 | WCHAR pathconfigxml[MAX_PATH]; //設定 145 | 146 | //ミューテックス 147 | WCHAR cnfmutexname[MAX_KRNLOBJNAME]; 148 | 149 | public: 150 | //状態 151 | ViKeyHandler vihandler; //Viキー処理 152 | 153 | //動作設定 154 | WCHAR c_otherime1; //他IMEへの切替え用に送付するキーシーケンス1 155 | int c_otherime2; //他IMEへの切替え用に送付するキーシーケンス2 156 | int c_otherimeoffwait; //他IME切替後、OFFモード切替送付待ち時間[ms] 157 | 158 | //preserved key 159 | TF_PRESERVEDKEY preservedkeynormal[MAX_PRESERVEDKEY]; 160 | TF_PRESERVEDKEY preservedkeyotherime[MAX_PRESERVEDKEY]; 161 | TF_PRESERVEDKEY preservedkeyotherimeoff[MAX_PRESERVEDKEY]; 162 | }; 163 | 164 | #endif //TEXTSERVICE_H 165 | -------------------------------------------------------------------------------- /imcrvtip/ThreadMgrEventSink.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "imcrvtip.h" 3 | #include "TextService.h" 4 | 5 | STDAPI CTextService::OnInitDocumentMgr(ITfDocumentMgr *pdim) 6 | { 7 | return S_OK; 8 | } 9 | 10 | STDAPI CTextService::OnUninitDocumentMgr(ITfDocumentMgr *pdim) 11 | { 12 | return S_OK; 13 | } 14 | 15 | STDAPI CTextService::OnSetFocus(ITfDocumentMgr *pdim, ITfDocumentMgr *pdimPrevFocus) 16 | { 17 | _UpdateLanguageBar(); 18 | 19 | return S_OK; 20 | } 21 | 22 | STDAPI CTextService::OnPushContext(ITfContext *pic) 23 | { 24 | return S_OK; 25 | } 26 | 27 | STDAPI CTextService::OnPopContext(ITfContext *pic) 28 | { 29 | return S_OK; 30 | } 31 | 32 | BOOL CTextService::_InitThreadMgrEventSink() 33 | { 34 | ITfSource *pSource; 35 | BOOL fRet = FALSE; 36 | 37 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 38 | { 39 | if(pSource->AdviseSink(IID_IUNK_ARGS((ITfThreadMgrEventSink *)this), &_dwThreadMgrEventSinkCookie) == S_OK) 40 | { 41 | fRet = TRUE; 42 | } 43 | else 44 | { 45 | _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE; 46 | } 47 | pSource->Release(); 48 | } 49 | 50 | return fRet; 51 | } 52 | 53 | void CTextService::_UninitThreadMgrEventSink() 54 | { 55 | ITfSource *pSource; 56 | 57 | if(_dwThreadMgrEventSinkCookie != TF_INVALID_COOKIE) 58 | { 59 | if(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK) 60 | { 61 | pSource->UnadviseSink(_dwThreadMgrEventSinkCookie); 62 | pSource->Release(); 63 | } 64 | _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /imcrvtip/ViCharStream.cpp: -------------------------------------------------------------------------------- 1 | #include "ViCharStream.h" 2 | #include "ViUtil.h" 3 | #include "mozc/win32/tip/tip_surrounding_text.h" 4 | 5 | ViCharStream::ViCharStream(CTextService *textService, ITfContext *tfContext) 6 | : _textService(textService), _tfContext(tfContext), 7 | _orig(0), _index(0), _sol(0), _eol(0), _flags(CS_EOF), 8 | _preceding_count(0), _following_count(0), 9 | _index_save(0), _sol_save(0), _eol_save(0), _flags_save(CS_EOF) 10 | { 11 | mozc::win32::tsf::TipSurroundingTextInfo info; 12 | if (mozc::win32::tsf::TipSurroundingText::Get(_textService, _tfContext, &info)) 13 | { 14 | std::wstring tmp; 15 | ViUtil::NormalizeNewline(info.preceding_text, &tmp); 16 | _buf.append(tmp); 17 | _orig = _index = _index_save = _buf.size(); 18 | ViUtil::NormalizeNewline(info.following_text, &tmp); 19 | _buf.append(tmp); 20 | _preceding_count = info.preceding_text.size(); 21 | _following_count = info.following_text.size(); 22 | _update_sol(); 23 | _update_eol(); 24 | _update_flags(); 25 | _eol_save = _eol; 26 | _sol_save = _sol; 27 | _flags_save = _flags; 28 | } 29 | } 30 | 31 | // find start of line 32 | void ViCharStream::_update_sol() 33 | { 34 | _sol = _buf.rfind(L'\n', _index); 35 | if (_sol == std::wstring::npos) 36 | { 37 | _sol = 0; 38 | } 39 | else 40 | { 41 | _sol++; 42 | } 43 | } 44 | 45 | // find end of line 46 | void ViCharStream::_update_eol() 47 | { 48 | _eol = _buf.find(L'\n', _index); 49 | if (_eol == std::wstring::npos) 50 | { 51 | _eol = _buf.size(); 52 | } 53 | } 54 | 55 | void ViCharStream::_update_flags() 56 | { 57 | if (_buf.find_first_not_of(L" \t", _sol) >= _eol) 58 | { 59 | _index = _eol; 60 | _flags = CS_EMP; 61 | } 62 | else 63 | { 64 | _flags = CS_NONE; 65 | } 66 | } 67 | 68 | ViCharStream::~ViCharStream() 69 | { 70 | } 71 | 72 | int ViCharStream::_GetMore(bool backward) 73 | { 74 | int offset = _following_count; // includes '\r' 75 | if (backward) 76 | { 77 | offset = 0 - _preceding_count; 78 | } 79 | mozc::win32::tsf::TipSurroundingTextInfo info; 80 | if (!mozc::win32::tsf::TipSurroundingText::GetMore(_textService, _tfContext, offset, &info)) 81 | { 82 | return -1; 83 | } 84 | if (offset < 0) 85 | { 86 | if (info.preceding_text.size() == 0) 87 | { 88 | return -1; 89 | } 90 | size_t oldsize = _buf.size(); 91 | std::wstring tmp; 92 | ViUtil::NormalizeNewline(info.preceding_text, &tmp); 93 | _buf.insert(0, tmp); 94 | size_t addsize = _buf.size() - oldsize; 95 | _orig += addsize; 96 | _index += addsize; 97 | _index_save += addsize; 98 | _update_sol(); 99 | _sol_save += addsize; 100 | _eol += addsize; 101 | _eol_save += addsize; 102 | _preceding_count += info.preceding_text.size(); 103 | } 104 | else 105 | { 106 | if (info.following_text.size() == 0) 107 | { 108 | return -1; 109 | } 110 | std::wstring tmp; 111 | ViUtil::NormalizeNewline(info.following_text, &tmp); 112 | _buf.append(tmp); 113 | _update_eol(); 114 | _following_count += info.following_text.size(); 115 | } 116 | return 0; 117 | } 118 | 119 | 120 | wchar_t ViCharStream::ch() 121 | { 122 | return _buf[_index]; 123 | } 124 | 125 | ViCharStream::cs_flags ViCharStream::flags() 126 | { 127 | return _flags; 128 | } 129 | 130 | int ViCharStream::difference() 131 | { 132 | return _index - _orig; 133 | } 134 | 135 | void ViCharStream::save_state() 136 | { 137 | _index_save = _index; 138 | _sol_save = _sol; 139 | _eol_save = _eol; 140 | _flags_save = _flags; 141 | } 142 | 143 | void ViCharStream::restore_state() 144 | { 145 | _index = _index_save; 146 | _sol = _sol_save; 147 | _eol = _eol_save; 148 | _flags = _flags_save; 149 | } 150 | 151 | // Eat backward to the next non-whitespace character. 152 | int ViCharStream::bblank() 153 | { 154 | for (;;) 155 | { 156 | if (prev()) 157 | { 158 | return 1; 159 | } 160 | if (flags() == CS_EOL || flags() == CS_EMP || 161 | flags() == CS_NONE && iswblank(ch())) 162 | { 163 | continue; 164 | } 165 | break; 166 | } 167 | return 0; 168 | } 169 | 170 | // Eat forward to the next non-whitespace character. 171 | int ViCharStream::fblank() 172 | { 173 | for (;;) 174 | { 175 | if (next()) 176 | { 177 | return 1; 178 | } 179 | if (flags() == CS_EOL || flags() == CS_EMP || 180 | flags() == CS_NONE && iswblank(ch())) 181 | { 182 | continue; 183 | } 184 | break; 185 | } 186 | return 0; 187 | } 188 | 189 | /* 190 | * If on a space, eat forward until something other than a 191 | * whitespace character. 192 | */ 193 | int ViCharStream::fspace() 194 | { 195 | if (flags() != CS_NONE || !iswblank(ch())) 196 | { 197 | return 0; 198 | } 199 | for (;;) 200 | { 201 | if (next()) 202 | { 203 | return 1; 204 | } 205 | if (flags() != CS_NONE || !iswblank(ch())) 206 | { 207 | break; 208 | } 209 | } 210 | return 0; 211 | } 212 | 213 | // set current position to the next character. 214 | int ViCharStream::next() 215 | { 216 | // acquire more following text 217 | #define GETMORE_FOLLOWING(failflag) \ 218 | do { \ 219 | if (_GetMore(false) == -1 || _index >= _buf.size() - 1) \ 220 | { \ 221 | /* cannot get more text || get more text but emtpy */ \ 222 | _index++; \ 223 | _flags = (failflag); \ 224 | return 0; \ 225 | } \ 226 | } while (0) 227 | 228 | switch (flags()) 229 | { 230 | case CS_EMP: // EMP; get next line. 231 | while (_index >= _buf.size() - 1) 232 | { 233 | // here _index == _eol == _buf.size() 234 | GETMORE_FOLLOWING(CS_EOF); 235 | // yet EMP line or become non-EMP line 236 | _update_flags(); 237 | if (flags() != CS_EMP) 238 | { 239 | return 0; 240 | } 241 | } 242 | //FALLTHRU 243 | case CS_EOL: // EOL; get next line. 244 | if (_index >= _buf.size() - 1) 245 | { 246 | GETMORE_FOLLOWING(CS_EOF); 247 | } 248 | _index++; 249 | _sol = _index; 250 | _update_eol(); 251 | _update_flags(); 252 | break; 253 | case CS_NONE: 254 | if (_index >= _buf.size() - 1) 255 | { 256 | GETMORE_FOLLOWING(CS_EOL); 257 | } 258 | _index++; 259 | if (_index == _eol) 260 | { 261 | _flags = CS_EOL; 262 | } 263 | break; 264 | case CS_EOF: 265 | break; 266 | default: 267 | break; 268 | } 269 | return 0; 270 | } 271 | 272 | // set current position to the previous character. 273 | int ViCharStream::prev() 274 | { 275 | #define GETMORE_PRECEDING() \ 276 | do { \ 277 | /* acquire more preceding text */ \ 278 | if (_GetMore(true) == -1 || _index == 0) \ 279 | { \ 280 | /* cannot get more text || get more text but emtpy */ \ 281 | _index = 0; \ 282 | _flags = CS_SOF; \ 283 | return 0; \ 284 | } \ 285 | } while (0) 286 | 287 | switch (flags()) 288 | { 289 | case CS_EMP: /* EMP; get previous line. */ 290 | _index = _sol; 291 | while (_index == 0) 292 | { 293 | GETMORE_PRECEDING(); 294 | // yet EMP line or become non-EMP line 295 | _update_flags(); 296 | if (flags() != CS_EMP) 297 | { 298 | --_index; 299 | _flags = CS_NONE; 300 | return 0; 301 | } 302 | _index = _sol; 303 | } 304 | //FALLTHRU 305 | case CS_EOL: /* EOL; get previous line. */ 306 | --_index; 307 | _eol = _index; // '\n' 308 | if (_index == 0) /* SOF. */ 309 | { 310 | GETMORE_PRECEDING(); 311 | } 312 | --_index; 313 | _update_sol(); 314 | _update_flags(); 315 | break; 316 | case CS_EOF: /* EOF: get previous char. */ 317 | case CS_NONE: 318 | if (_index == _sol) 319 | { 320 | if (_index == 0) 321 | { 322 | GETMORE_PRECEDING(); 323 | --_index; 324 | _flags = CS_NONE; 325 | } 326 | else 327 | { 328 | _flags = CS_EOL; 329 | } 330 | } 331 | else 332 | { 333 | --_index; 334 | _flags = CS_NONE; 335 | } 336 | break; 337 | case CS_SOF: /* SOF. */ 338 | break; 339 | default: 340 | break; 341 | } 342 | return 0; 343 | } 344 | -------------------------------------------------------------------------------- /imcrvtip/ViCharStream.h: -------------------------------------------------------------------------------- 1 | #ifndef VICHARSTREAM_H 2 | #define VICHARSTREAM_H 3 | 4 | class CTextService; 5 | struct ITfContext; 6 | 7 | /* Character stream structure, prototypes. */ 8 | class ViCharStream 9 | { 10 | public: 11 | enum cs_flags 12 | { 13 | CS_NONE = 0, 14 | CS_EMP, /* Empty line. */ 15 | CS_EOF, /* End-of-file. */ 16 | CS_EOL, /* End-of-line. */ 17 | CS_SOF, /* Start-of-file. */ 18 | }; 19 | 20 | ViCharStream(CTextService *textService, ITfContext *tfContext); 21 | ~ViCharStream(); 22 | 23 | int bblank(); 24 | int fblank(); 25 | int fspace(); 26 | int next(); 27 | int prev(); 28 | wchar_t ch(); 29 | cs_flags flags(); 30 | int difference(); 31 | void save_state(); 32 | void restore_state(); 33 | 34 | private: 35 | int _GetMore(bool backward); 36 | void _update_sol(); 37 | void _update_eol(); 38 | void _update_flags(); 39 | 40 | CTextService *_textService; 41 | ITfContext *_tfContext; 42 | 43 | size_t _orig; // original index in buf 44 | size_t _index; // current index in buf 45 | size_t _sol; // start index of current line 46 | size_t _eol; // end index of current line. _buf[_eol] == '\n' || _buf.size() 47 | std::wstring _buf; 48 | cs_flags _flags; 49 | 50 | size_t _preceding_count; 51 | size_t _following_count; 52 | 53 | size_t _index_save; 54 | size_t _sol_save; 55 | size_t _eol_save; 56 | cs_flags _flags_save; 57 | }; 58 | #endif //VICHARSTREAM_H 59 | -------------------------------------------------------------------------------- /imcrvtip/ViCmd.cpp: -------------------------------------------------------------------------------- 1 | #include "ViCmd.h" 2 | 3 | ViCmd::ViCmd(): _operator_pending(0), _char_waiting(0), _count1(0), _count2(0) 4 | { 5 | } 6 | 7 | ViCmd::~ViCmd() 8 | { 9 | } 10 | 11 | void ViCmd::Reset() 12 | { 13 | SetOperatorPending(0); 14 | SetCharWaiting(0); 15 | _count1 = 0; 16 | _count2 = 0; 17 | } 18 | 19 | WCHAR ViCmd::GetOperatorPending() 20 | { 21 | return _operator_pending; 22 | } 23 | 24 | void ViCmd::SetOperatorPending(WCHAR op) 25 | { 26 | _operator_pending = op; 27 | } 28 | 29 | WCHAR ViCmd::GetCharWaiting() 30 | { 31 | return _char_waiting; 32 | } 33 | 34 | void ViCmd::SetCharWaiting(WCHAR cmdch) 35 | { 36 | _char_waiting = cmdch; 37 | } 38 | 39 | int ViCmd::GetCount() 40 | { 41 | return ((_count1 == 0) ? 1 : _count1) * ((_count2 == 0) ? 1 : _count2); 42 | } 43 | 44 | BOOL ViCmd::HasCount() 45 | { 46 | return (_count1 != 0 || _count2 != 0); 47 | } 48 | 49 | void ViCmd::AddCountChar(WCHAR ch) 50 | { 51 | if (GetOperatorPending()) 52 | { 53 | _count2 = _count2 * 10 + ch - L'0'; 54 | } 55 | else 56 | { 57 | _count1 = _count1 * 10 + ch - L'0'; 58 | } 59 | } 60 | 61 | BOOL ViCmd::IsEmpty() 62 | { 63 | return (GetOperatorPending() == 0 && GetCharWaiting() == 0 && !HasCount()); 64 | } 65 | -------------------------------------------------------------------------------- /imcrvtip/ViCmd.h: -------------------------------------------------------------------------------- 1 | #ifndef VICMD_H 2 | #define VICMD_H 3 | 4 | #define CTRL(c) ((c) & 0x1f) 5 | 6 | class ViCmd 7 | { 8 | public: 9 | ViCmd(); 10 | ~ViCmd(); 11 | 12 | void Reset(); 13 | WCHAR GetOperatorPending(); 14 | void SetOperatorPending(WCHAR op); 15 | WCHAR GetCharWaiting(); 16 | void SetCharWaiting(WCHAR cmdch); 17 | int GetCount(); 18 | BOOL HasCount(); 19 | void AddCountChar(WCHAR ch); 20 | BOOL IsEmpty(); 21 | 22 | private: 23 | WCHAR _operator_pending; // operator-pending mode(c,d,y) 24 | WCHAR _char_waiting; // waiting character(f,t) 25 | int _count1; // first count for operator or motion 26 | int _count2; // second count for motion 27 | }; 28 | #endif //VICMD_H 29 | -------------------------------------------------------------------------------- /imcrvtip/ViKeyHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef VIKEYHANDLER_H 2 | #define VIKEYHANDLER_H 3 | 4 | #include "mozc/win32/base/keyboard.h" 5 | #include "ViCmd.h" 6 | 7 | class CTextService; 8 | 9 | class ViKeyHandler 10 | { 11 | public: 12 | ViKeyHandler(CTextService *textService); 13 | ~ViKeyHandler(); 14 | void SetPreservedKeyNormal(const TF_PRESERVEDKEY preservedkey[]); 15 | 16 | void Reset(); 17 | void ResetThroughSelfSentKey(); 18 | void SwitchToOtherIme(WCHAR method, int param, BOOL imalnum, int otherimeoffwait); 19 | BOOL IsThroughSelfSentKey(); 20 | BOOL IsWaitingNextKey(); 21 | HRESULT HandleKey(TfEditCookie ec, ITfContext *pContext, WCHAR ch, BYTE vk); 22 | 23 | private: 24 | void _HandleFunc(TfEditCookie ec, ITfContext *pContext, WCHAR ch); 25 | void _QueueEndOfSelfSendKey(std::vector *inputs); 26 | void _SendInputs(std::vector *inputs, vector *inputs2 = NULL, int waitms = 0); 27 | void _SendKey(UINT vk, int count = 1); 28 | void _SendKeyWithControl(UINT vk); 29 | void _ViOp(std::vector *inputs); 30 | void _ViOpOrMove(UINT vk, int count); 31 | void _ViOpLines(int count); 32 | void _Vi_j(); 33 | void _ViDownFNB(ITfContext *pContext); 34 | void _Vi_k(); 35 | void _Vi_i(); 36 | void _Vi_I(ITfContext *pContext); 37 | BOOL _AtEndOfLine(ITfContext *pContext); 38 | void _Vi_a(ITfContext *pContext); 39 | void _Vi_A(); 40 | void _Vi_o(); 41 | void _Vi_O(); 42 | void _Vi_p(ITfContext *pContext); 43 | void _Vi_P(); 44 | void _ViNextWord(ITfContext *pContext, WCHAR type); 45 | void _ViNextWordE(ITfContext *pContext, WCHAR type); 46 | void _ViPrevWord(ITfContext *pContext, WCHAR type); 47 | void _VimForwardSent(ITfContext *pContext); 48 | void _VimBackwardSent(ITfContext *pContext); 49 | int _Vi_f_sub(ITfContext *pContext, WCHAR ch); 50 | void _Vi_f(ITfContext *pContext, WCHAR ch); 51 | void _Vi_t(ITfContext *pContext, WCHAR ch); 52 | int _Vi_F_sub(ITfContext *pContext, WCHAR ch); 53 | void _Vi_F(ITfContext *pContext, WCHAR ch); 54 | void _Vi_T(ITfContext *pContext, WCHAR ch); 55 | void _Vi_ft_repeat(ITfContext *pContext, BOOL samedir); 56 | void _ViEndOfLine(ITfContext *pContext); 57 | void _Vi_gg(); 58 | void _Vi_G(); 59 | void _Vi_J(ITfContext *pContext); 60 | void _Vi_r(BYTE vk); 61 | 62 | CTextService *_textService; 63 | ViCmd vicmd; 64 | std::unique_ptr keyboard_; 65 | BOOL isThroughSelfSentKey; 66 | TF_PRESERVEDKEY preservedkeynormal; 67 | WCHAR last_ft; 68 | WCHAR last_ft_ch; 69 | }; 70 | #endif //VIKEYHANDLER_H 71 | -------------------------------------------------------------------------------- /imcrvtip/ViMulti.cpp: -------------------------------------------------------------------------------- 1 | #include "ViMulti.h" 2 | 3 | ViMulti::ChClass ViMulti::chclass(wchar_t c, ViMulti::ChClass curchclass) 4 | { 5 | // cf. jis0208_chclass() in multi_chclass.c of nvi-m17n. 6 | const static std::wstring ch_kanji(L"〃仝々〆"); 7 | const static std::wstring ch_kana(L"ヽヾゝゞー~"); 8 | if (ch_kanji.find(c) != std::wstring::npos) 9 | { 10 | return KANJI; 11 | } 12 | if (ch_kana.find(c) != std::wstring::npos) 13 | { 14 | return (curchclass == HIRAGANA) ? HIRAGANA : KATAKANA; 15 | } 16 | 17 | // cf. Util::GetScriptType() in base/util.cc of mozc 18 | #define INRANGE(w, a, b) ((w) >= (a) && (w) <= (b)) 19 | if (INRANGE(c, 0x0030, 0x0039) || // ascii number 20 | INRANGE(c, 0xFF10, 0xFF19) || // full width number 21 | INRANGE(c, 0x0041, 0x005A) || // ascii upper 22 | INRANGE(c, 0x0061, 0x007A) || // ascii lower 23 | INRANGE(c, 0xFF21, 0xFF3A) || // fullwidth ascii upper 24 | INRANGE(c, 0xFF41, 0xFF5A)) { // fullwidth ascii lower 25 | return ALPHA; 26 | } else if ( 27 | INRANGE(c, 0x3400, 0x4DBF) || // CJK Unified Ideographs Extension A 28 | INRANGE(c, 0x4E00, 0x9FFF) || // CJK Unified Ideographs 29 | INRANGE(c, 0xF900, 0xFAFF)) { // CJK Compatibility Ideographs 30 | return KANJI; 31 | } else if (INRANGE(c, 0x3041, 0x309F)) { // hiragana 32 | return HIRAGANA; 33 | } else if ( 34 | INRANGE(c, 0x30A1, 0x30FF) || // full width katakana 35 | INRANGE(c, 0x31F0, 0x31FF) || // Katakana Phonetic Extensions for Ainu 36 | INRANGE(c, 0xFF65, 0xFF9F)) { // half width katakana 37 | return KATAKANA; 38 | } 39 | 40 | if (c < 0x3041) // hiragana start 41 | { 42 | return MARK; 43 | } 44 | return NONKANJI; 45 | } 46 | 47 | bool ViMulti::ismulti(wchar_t c) 48 | { 49 | return c >= 0x80; // XXX 50 | } 51 | 52 | bool ViMulti::Wordbound(ViMulti::ChClass oldchclass, ViMulti::ChClass curchclass, bool forward) 53 | { 54 | /* 55 | * if it is just beginning, we don't bother. 56 | */ 57 | if (oldchclass == _INIT) 58 | { 59 | return false; 60 | } 61 | 62 | /* 63 | * if we are going forward and next char is stronger, we've hit 64 | * word boundary. 65 | * if we are going backward, and lefthandside char is weaker, 66 | * we've hit word boundary. 67 | */ 68 | if (forward) 69 | { 70 | if (oldchclass < curchclass) 71 | { 72 | return true; 73 | } 74 | } 75 | else 76 | { 77 | if (oldchclass > curchclass) 78 | { 79 | return true; 80 | } 81 | } 82 | 83 | return false; 84 | } 85 | 86 | bool ViMulti::wordbound(ViMulti::ChClass oldchclass, ViMulti::ChClass curchclass, bool forward) 87 | { 88 | /* 89 | * if it is just beginning, we don't bother. 90 | */ 91 | if (oldchclass == _INIT) 92 | { 93 | return false; 94 | } 95 | 96 | /* 97 | * if they are in different character class, we've hit word boundary. 98 | */ 99 | if (oldchclass != curchclass) 100 | { 101 | return true; 102 | } 103 | 104 | return false; 105 | } 106 | -------------------------------------------------------------------------------- /imcrvtip/ViMulti.h: -------------------------------------------------------------------------------- 1 | #ifndef VIMULTI_H 2 | #define VIMULTI_H 3 | 4 | class ViMulti 5 | { 6 | public: 7 | enum ChClass 8 | { 9 | _INIT = 0, 10 | MARK = 1, 11 | ALPHA = 5, 12 | HIRAGANA = 2, 13 | KATAKANA = 10, 14 | KANJI = 20, 15 | NONKANJI = 100, 16 | }; 17 | 18 | // TODO: surrogate pair 19 | static ChClass chclass(wchar_t c, ChClass curchclass); 20 | static bool ismulti(wchar_t c); 21 | static bool Wordbound(ChClass oldchclass, ChClass curchclass, bool forward); 22 | static bool wordbound(ChClass oldchclass, ChClass curchclass, bool forward); 23 | }; 24 | #endif //VIMULTI_H 25 | -------------------------------------------------------------------------------- /imcrvtip/ViUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "ViUtil.h" 2 | 3 | void ViUtil::NormalizeNewline(const std::wstring src, std::wstring *dest) 4 | { 5 | dest->clear(); 6 | // \r\n: notepad 7 | *dest = std::regex_replace(src, std::wregex(L"\r\n"), std::wstring(L"\n")); 8 | // only \r: WordPad, Word, Outlook 9 | replace(dest->begin(), dest->end(), L'\r', L'\n'); 10 | } 11 | -------------------------------------------------------------------------------- /imcrvtip/ViUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef VIUTIL_H 2 | #define VIUTIL_H 3 | 4 | inline int iswblank(wchar_t c) 5 | { 6 | return c == L' ' || c == L'\t'; 7 | } 8 | 9 | class ViUtil 10 | { 11 | public: 12 | static void NormalizeNewline(const std::wstring src, std::wstring *dest); 13 | }; 14 | #endif // VIUTIL_H 15 | -------------------------------------------------------------------------------- /imcrvtip/VimCharStream.cpp: -------------------------------------------------------------------------------- 1 | #include "VimCharStream.h" 2 | #include "ViUtil.h" 3 | #include "mozc/win32/tip/tip_surrounding_text.h" 4 | //#define DEBUGLOG 1 5 | #if DEBUGLOG 6 | #include 7 | #endif 8 | 9 | VimCharStream::VimCharStream(CTextService *textService, ITfContext *tfContext) 10 | : _textService(textService), _tfContext(tfContext), 11 | _orig(0), _index(0), _eof(false), 12 | _preceding_count(0), _following_count(0), 13 | _index_save(0) 14 | { 15 | mozc::win32::tsf::TipSurroundingTextInfo info; 16 | if (mozc::win32::tsf::TipSurroundingText::Get(_textService, _tfContext, &info)) 17 | { 18 | std::wstring tmp; 19 | ViUtil::NormalizeNewline(info.preceding_text, &tmp); 20 | _buf.append(tmp); 21 | _orig = _index = _index_save = _buf.size(); 22 | ViUtil::NormalizeNewline(info.following_text, &tmp); 23 | _buf.append(tmp); 24 | _preceding_count = info.preceding_text.size(); 25 | _following_count = info.following_text.size(); 26 | _eof = false; 27 | #if DEBUGLOG 28 | std::wofstream log("c:\\tsfvim\\log"); 29 | log << info.preceding_text << '|' << info.following_text << std::endl; 30 | #endif 31 | } 32 | else 33 | { 34 | _eof = true; 35 | } 36 | } 37 | 38 | VimCharStream::~VimCharStream() 39 | { 40 | } 41 | 42 | int VimCharStream::_GetMore(bool backward) 43 | { 44 | int offset = _following_count; // includes '\r' 45 | if (backward) 46 | { 47 | offset = 0 - _preceding_count; 48 | } 49 | mozc::win32::tsf::TipSurroundingTextInfo info; 50 | if (!mozc::win32::tsf::TipSurroundingText::GetMore(_textService, _tfContext, offset, &info)) 51 | { 52 | return -1; 53 | } 54 | if (offset < 0) 55 | { 56 | if (info.preceding_text.size() == 0) 57 | { 58 | return -1; 59 | } 60 | size_t oldsize = _buf.size(); 61 | std::wstring tmp; 62 | ViUtil::NormalizeNewline(info.preceding_text, &tmp); 63 | _buf.insert(0, tmp); 64 | size_t addsize = _buf.size() - oldsize; 65 | _orig += addsize; 66 | _index += addsize; 67 | _index_save += addsize; 68 | _preceding_count += info.preceding_text.size(); 69 | } 70 | else 71 | { 72 | if (info.following_text.size() == 0) 73 | { 74 | return -1; 75 | } 76 | std::wstring tmp; 77 | ViUtil::NormalizeNewline(info.following_text, &tmp); 78 | _buf.append(tmp); 79 | _following_count += info.following_text.size(); 80 | } 81 | return 0; 82 | } 83 | 84 | wchar_t VimCharStream::gchar() 85 | { 86 | return _buf[_index]; 87 | } 88 | 89 | size_t VimCharStream::index() 90 | { 91 | return _index; 92 | } 93 | 94 | bool VimCharStream::eof() 95 | { 96 | return _eof; 97 | } 98 | 99 | int VimCharStream::difference() 100 | { 101 | return _index - _orig; 102 | } 103 | 104 | void VimCharStream::save_index() 105 | { 106 | _index_save = _index; 107 | } 108 | 109 | void VimCharStream::restore_index() 110 | { 111 | _index = _index_save; 112 | } 113 | 114 | /* 115 | * Increment the currnet index crossing line boundaries as necessary. 116 | * Return 1 when going to the next line. 117 | * Return 2 when moving forward onto a '\n' at the end of the line. 118 | * Return -1 when at the end of file. 119 | * Return 0 otherwise. 120 | */ 121 | int VimCharStream::inc() 122 | { 123 | if (_index >= _buf.size() - 1) 124 | { 125 | // acquire more following text 126 | if (_GetMore(false) == -1 || _index >= _buf.size() - 1) 127 | { 128 | _eof = true; 129 | return -1; // cannot get more text || get more text but emtpy 130 | } 131 | } 132 | if (gchar() == L'\n') 133 | { 134 | ++_index; 135 | return 1; 136 | } 137 | ++_index; 138 | return (gchar() == L'\n') ? 2 : 0; 139 | } 140 | 141 | /* 142 | * incl(): same as inc(), but skip the '\n' at the end of non-empty lines 143 | */ 144 | int VimCharStream::incl() 145 | { 146 | int r = inc(); 147 | if (r == 2) 148 | { 149 | r = inc(); 150 | } 151 | return r; 152 | } 153 | 154 | /* 155 | * Decrement the current index crossing line boundaries as necessary. 156 | * Return 1 when crossing a line, -1 when at start of file, 0 otherwise. 157 | */ 158 | int VimCharStream::dec() 159 | { 160 | if (_index == 0) 161 | { 162 | // acquire more preceding text 163 | if (_GetMore(true) == -1 || _index == 0) 164 | { 165 | return -1; // cannot get more text || get more text but emtpy 166 | } 167 | } 168 | _eof = false; 169 | --_index; 170 | if (gchar() == L'\n') 171 | { 172 | return 1; 173 | } 174 | return 0; 175 | } 176 | 177 | /* 178 | * decl(): same as dec(), but skip the '\n' at the end of non-empty lines. 179 | * Return 2 when moving onto empty line. 180 | */ 181 | int VimCharStream::decl() 182 | { 183 | int r = dec(); 184 | if (r == 1) 185 | { 186 | r = dec(); 187 | if (gchar() == L'\n') // empty line 188 | { 189 | inc(); 190 | return 2; 191 | } 192 | } 193 | return r; 194 | } 195 | 196 | int VimCharStream::fblankl() 197 | { 198 | while (iswblank(gchar())) 199 | { 200 | if (incl() == -1) 201 | { 202 | return -1; 203 | } 204 | } 205 | return 0; 206 | } 207 | 208 | int VimCharStream::fblank() 209 | { 210 | while (iswblank(gchar())) 211 | { 212 | if (inc() == -1) 213 | { 214 | return -1; 215 | } 216 | } 217 | return 0; 218 | } 219 | 220 | int VimCharStream::forward_eol() 221 | { 222 | if (gchar() == L'\n') 223 | { 224 | return 0; 225 | } 226 | 227 | for (int r = inc(); r != 2; r = inc()) 228 | { 229 | if (r == -1) // end of file 230 | { 231 | return -1; 232 | } 233 | } 234 | return 0; 235 | } 236 | 237 | -------------------------------------------------------------------------------- /imcrvtip/VimCharStream.h: -------------------------------------------------------------------------------- 1 | #ifndef VIMCHARSTREAM_H 2 | #define VIMCHARSTREAM_H 3 | 4 | class CTextService; 5 | struct ITfContext; 6 | 7 | class VimCharStream 8 | { 9 | public: 10 | VimCharStream(CTextService *textService, ITfContext *tfContext); 11 | ~VimCharStream(); 12 | 13 | int inc(); 14 | int incl(); 15 | int dec(); 16 | int decl(); 17 | int fblank(); 18 | int fblankl(); 19 | wchar_t gchar(); 20 | size_t index(); 21 | bool eof(); 22 | int difference(); 23 | int forward_eol(); 24 | void save_index(); 25 | void restore_index(); 26 | 27 | private: 28 | int _GetMore(bool backward); 29 | 30 | CTextService *_textService; 31 | ITfContext *_tfContext; 32 | 33 | size_t _orig; // original index in buf 34 | size_t _index; // current index in buf 35 | std::wstring _buf; 36 | bool _eof; 37 | 38 | size_t _preceding_count; 39 | size_t _following_count; 40 | 41 | size_t _index_save; 42 | }; 43 | #endif //VIMCHARSTREAM_H 44 | -------------------------------------------------------------------------------- /imcrvtip/VimMByte.cpp: -------------------------------------------------------------------------------- 1 | #include "VimMByte.h" 2 | #include "ViUtil.h" 3 | 4 | VimMByte::ChClass VimMByte::chclass(wchar_t c) 5 | { 6 | if (!ismulti(c)) 7 | { 8 | if (iswblank(c) || c == L'\n') 9 | { 10 | return VimMByte::BLANK_LF; 11 | } 12 | if (iswalnum(c) || c == L'_') 13 | { 14 | return VimMByte::ASCII_WORD; 15 | } 16 | return VimMByte::OTHER; 17 | } 18 | 19 | if (c == L'、' || c == L'。' || c == L',' || c == L'.') 20 | { 21 | return VimMByte::PUNCT; 22 | } 23 | // TODO: Support JA_KANJI etc. 24 | return VimMByte::OTHER; 25 | } 26 | 27 | bool VimMByte::ismulti(wchar_t c) 28 | { 29 | return c >= 0x80; 30 | } 31 | -------------------------------------------------------------------------------- /imcrvtip/VimMByte.h: -------------------------------------------------------------------------------- 1 | #ifndef VIMMBYTE_H 2 | #define VIMMBYTE_H 3 | 4 | class VimMByte 5 | { 6 | public: 7 | enum ChClass 8 | { 9 | BLANK_LF, 10 | PUNCT, 11 | ASCII_WORD, 12 | OTHER, 13 | JA_SYMBOLS, 14 | JA_ALPHANUM, 15 | JA_HIRAGANA, 16 | JA_KATAKANA, 17 | JA_GREEK, 18 | JA_RUSSIAN, 19 | JA_LINES, 20 | JA_KANJI, 21 | CHCLASS_SIZE 22 | }; 23 | 24 | // TODO: surrogate pair 25 | static ChClass chclass(wchar_t c); 26 | static bool ismulti(wchar_t c); 27 | }; 28 | #endif //VIMMBYTE_H 29 | -------------------------------------------------------------------------------- /imcrvtip/imcrvtip.def: -------------------------------------------------------------------------------- 1 | LIBRARY imcrvtip.dll 2 | 3 | EXPORTS 4 | DllCanUnloadNow PRIVATE 5 | DllGetClassObject PRIVATE 6 | DllRegisterServer PRIVATE 7 | DllUnregisterServer PRIVATE 8 | -------------------------------------------------------------------------------- /imcrvtip/imcrvtip.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef IMCRVTIP_H 3 | #define IMCRVTIP_H 4 | 5 | #include "common.h" 6 | 7 | extern LPCWSTR TextServiceDesc; 8 | extern LPCWSTR LangbarItemDesc; 9 | 10 | extern HINSTANCE g_hInst; 11 | 12 | extern const CLSID c_clsidTextService; 13 | extern const GUID c_guidProfile; 14 | extern const GUID c_guidPreservedKeyNormal; 15 | extern const GUID c_guidPreservedKeyOtherIme; 16 | extern const GUID c_guidPreservedKeyOtherImeOff; 17 | extern const GUID c_guidLangBarItemButton; 18 | 19 | LONG DllAddRef(); 20 | LONG DllRelease(); 21 | 22 | #define IID_IUNK_ARGS(pType) __uuidof(*(pType)), (IUnknown *)pType 23 | 24 | // for Windows 8 25 | #if 1 26 | #define EVENT_OBJECT_IME_SHOW 0x8027 27 | #define EVENT_OBJECT_IME_HIDE 0x8028 28 | #define EVENT_OBJECT_IME_CHANGE 0x8029 29 | 30 | #define TF_TMF_IMMERSIVEMODE 0x40000000 31 | 32 | #define TF_IPP_CAPS_IMMERSIVESUPPORT 0x00010000 33 | #define TF_IPP_CAPS_SYSTRAYSUPPORT 0x00020000 34 | 35 | extern const GUID GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT; 36 | extern const GUID GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT; 37 | extern const GUID GUID_LBI_INPUTMODE; 38 | #endif 39 | 40 | #endif //IMCRVTIP_H 41 | -------------------------------------------------------------------------------- /imcrvtip/imcrvtip.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deton/tsf-vim/185256f6acbe6917d41fe7d8a407500e632345a1/imcrvtip/imcrvtip.rc -------------------------------------------------------------------------------- /imcrvtip/imcrvtip.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | Source Files 103 | 104 | 105 | Source Files 106 | 107 | 108 | Source Files 109 | 110 | 111 | Source Files 112 | 113 | 114 | Source Files 115 | 116 | 117 | Source Files 118 | 119 | 120 | Source Files 121 | 122 | 123 | Source Files 124 | 125 | 126 | Source Files 127 | 128 | 129 | Source Files 130 | 131 | 132 | Source Files 133 | 134 | 135 | Source Files 136 | 137 | 138 | Source Files 139 | 140 | 141 | Source Files 142 | 143 | 144 | Source Files 145 | 146 | 147 | Source Files 148 | 149 | 150 | Source Files 151 | 152 | 153 | Source Files 154 | 155 | 156 | 157 | 158 | Resource Files 159 | 160 | 161 | Resource Files 162 | 163 | 164 | Resource Files 165 | 166 | 167 | Resource Files 168 | 169 | 170 | Resource Files 171 | 172 | 173 | Resource Files 174 | 175 | 176 | Resource Files 177 | 178 | 179 | Resource Files 180 | 181 | 182 | Resource Files 183 | 184 | 185 | Resource Files 186 | 187 | 188 | Resource Files 189 | 190 | 191 | Resource Files 192 | 193 | 194 | Resource Files 195 | 196 | 197 | Resource Files 198 | 199 | 200 | 201 | 202 | Resource Files 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /imcrvtip/imcrvtip.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /imcrvtip/mozc/base/base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_BASE_BASE_H_ 31 | #define MOZC_BASE_BASE_H_ 32 | 33 | #include "base/namespace.h" 34 | 35 | #include "base/compiler_specific.h" 36 | #include "base/port.h" 37 | 38 | #endif // MOZC_BASE_BASE_H_ 39 | -------------------------------------------------------------------------------- /imcrvtip/mozc/base/flags.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // This is a simple port of google flags 31 | 32 | #ifndef MOZC_BASE_FLAGS_H_ 33 | #define MOZC_BASE_FLAGS_H_ 34 | 35 | 36 | #include 37 | #include "base/port.h" 38 | 39 | namespace mozc_flags { 40 | 41 | enum { I, B, I64, U64, D, S }; 42 | 43 | struct Flag; 44 | 45 | class FlagRegister { 46 | public: 47 | FlagRegister(const char *name, 48 | void *storage, 49 | const void *default_storage, 50 | int shorttpe, 51 | const char *help); 52 | virtual ~FlagRegister(); 53 | private: 54 | Flag *flag_; 55 | }; 56 | 57 | uint32 ParseCommandLineFlags(int *argc, char*** argv, 58 | bool remove_flags); 59 | } // mozc_flags 60 | 61 | void InitGoogle(const char *arg0, 62 | int *argc, char ***argv, 63 | bool remove_flags); 64 | 65 | #define DEFINE_VARIABLE(type, shorttype, name, value, help) \ 66 | namespace fL##shorttype { \ 67 | using namespace mozc_flags; \ 68 | type FLAGS_##name = value; \ 69 | static const type FLAGS_DEFAULT_##name = value; \ 70 | static const mozc_flags::FlagRegister \ 71 | fL##name(#name, \ 72 | reinterpret_cast(&FLAGS_##name), \ 73 | reinterpret_cast(&FLAGS_DEFAULT_##name), \ 74 | shorttype, help); \ 75 | } \ 76 | using fL##shorttype::FLAGS_##name 77 | 78 | #define DECLARE_VARIABLE(type, shorttype, name) \ 79 | namespace fL##shorttype { \ 80 | extern type FLAGS_##name; \ 81 | } \ 82 | using fL##shorttype::FLAGS_##name 83 | 84 | #define DEFINE_int32(name, value, help) \ 85 | DEFINE_VARIABLE(int32, I, name, value, help) 86 | #define DECLARE_int32(name) \ 87 | DECLARE_VARIABLE(int32, I, name) 88 | 89 | #define DEFINE_int64(name, value, help) \ 90 | DEFINE_VARIABLE(int64, I64, name, value, help) 91 | #define DECLARE_int64(name) \ 92 | DECLARE_VARIABLE(int64, I64, name) 93 | 94 | #define DEFINE_uint64(name, value, help) \ 95 | DEFINE_VARIABLE(uint64, U64, name, value, help) 96 | #define DECLARE_uint64(name) \ 97 | DECLARE_VARIABLE(uint64, U64, name) 98 | 99 | #define DEFINE_double(name, value, help) \ 100 | DEFINE_VARIABLE(double, D, name, value, help) 101 | #define DECLARE_double(name) \ 102 | DECLARE_VARIABLE(double, D, name) 103 | 104 | #define DEFINE_bool(name, value, help) \ 105 | DEFINE_VARIABLE(bool, B, name, value, help) 106 | #define DECLARE_bool(name) \ 107 | DECLARE_VARIABLE(bool, B, name) 108 | 109 | #define DEFINE_string(name, value, help) \ 110 | DEFINE_VARIABLE(string, S, name, value, help) 111 | #define DECLARE_string(name) \ 112 | DECLARE_VARIABLE(string, S, name) 113 | 114 | #endif // MOZC_BASE_FLAGS_H_ 115 | -------------------------------------------------------------------------------- /imcrvtip/mozc/base/init.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // This is a simple port of googleinit 31 | 32 | // Example: 33 | // static const char* my_hostname = NULL; 34 | // REGISTER_MODULE_INITIALIZER(hostname, { 35 | // // Code to initialize "my_hostname" 36 | // }); 37 | // 38 | // static const char* my_hostname = NULL; 39 | // static void InitMyHostname() { 40 | // // Code to initialize "my_hostname" 41 | // } 42 | // REGISTER_MODULE_INITIALIZER(my_hostname, InitMyHostname()); 43 | 44 | 45 | #ifndef MOZC_BASE_INIT_H_ 46 | #define MOZC_BASE_INIT_H_ 47 | 48 | #include 49 | #include "base/port.h" 50 | 51 | typedef void (*RegisterModuleFunction)(); 52 | 53 | namespace mozc { 54 | 55 | class InitializerRegister { 56 | public: 57 | InitializerRegister(const char *name, 58 | RegisterModuleFunction function); 59 | }; 60 | 61 | // call all initialize functions 62 | void RunInitializers(); 63 | 64 | #define REGISTER_MODULE_INITIALIZER(name, body) \ 65 | static void mozc_initializer_##name() { body; } \ 66 | static const mozc::InitializerRegister \ 67 | initializer_##name(#name, mozc_initializer_##name); 68 | 69 | class ReloaderRegister { 70 | public: 71 | ReloaderRegister(const char *name, 72 | RegisterModuleFunction function); 73 | }; 74 | 75 | // Main thread can call finalizers at the end of main(). 76 | // You can register all cleanup routines with finalizer. 77 | class FinalizerRegister { 78 | public: 79 | FinalizerRegister(const char *name, 80 | RegisterModuleFunction function); 81 | }; 82 | 83 | // Can define callback functions which are called 84 | // when operating systems or installer/uninstaller 85 | // sends "shutdown" event to the converter/renderere. 86 | // Callback function MUST be thread safe, as 87 | // this handler may be called asynchronously. You may 88 | // not implement complicated operations with this handler. 89 | class ShutdownHandlerRegister { 90 | public: 91 | ShutdownHandlerRegister(const char *name, 92 | RegisterModuleFunction function); 93 | }; 94 | 95 | void RunReloaders(); 96 | void RunFinalizers(); 97 | void RunShutdownHandlers(); 98 | } // namespace mozc 99 | 100 | // Reloaders are also called after initializers are invoked. 101 | #define REGISTER_MODULE_RELOADER(name, body) \ 102 | static void mozc_reloader_##name() { body; } \ 103 | static const mozc::ReloaderRegister \ 104 | reloader_##name(#name, mozc_reloader_##name); 105 | 106 | #define REGISTER_MODULE_SHUTDOWN_HANDLER(name, body) \ 107 | static void mozc_shutdown_handler_##name() { body; } \ 108 | static const mozc::ShutdownHandlerRegister \ 109 | reloader_##name(#name, mozc_shutdown_handler_##name); 110 | 111 | #define REGISTER_MODULE_FINALIZER(name, body) \ 112 | static void mozc_finalizer_##name() { body; } \ 113 | static const mozc::FinalizerRegister \ 114 | finalizer_##name(#name, mozc_finalizer_##name); 115 | 116 | #endif // MOZC_BASE_INIT_H_ 117 | -------------------------------------------------------------------------------- /imcrvtip/mozc/base/namespace.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_BASE_NAMESPACE_H_ 31 | #define MOZC_BASE_NAMESPACE_H_ 32 | #ifdef __cplusplus 33 | namespace std {} 34 | using namespace std; 35 | #endif // __cplusplus 36 | #endif // MOZC_BASE_NAMESPACE_H_ 37 | -------------------------------------------------------------------------------- /imcrvtip/mozc/base/port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_BASE_PORT_H_ 31 | #define MOZC_BASE_PORT_H_ 32 | 33 | 34 | #include 35 | #include 36 | #include "base/compiler_specific.h" 37 | 38 | // basic macros 39 | typedef signed char int8; 40 | typedef short int16; 41 | typedef int int32; 42 | typedef unsigned char uint8; 43 | typedef unsigned short uint16; 44 | typedef unsigned int uint32; 45 | typedef unsigned int char32; 46 | #ifdef OS_WIN 47 | typedef unsigned __int64 uint64; 48 | typedef __int64 int64; 49 | #else 50 | typedef unsigned long long uint64; 51 | typedef long long int64; 52 | #endif // OS_WIN 53 | 54 | #define atoi32 atoi 55 | #define strto32 strtol 56 | #define strto64 strtoll 57 | 58 | #if !defined(COMPILER_MSVC) || MOZC_MSVC_VERSION_GE(16, 0) 59 | // MSVCs older than VC2010 don't have stdint.h header. 60 | #include 61 | #endif // !COMPILER_MSVC or MSVC 2010+ 62 | 63 | #ifdef OS_WIN 64 | #include 65 | #include 66 | #include 67 | #include // time() 68 | #define snprintf _snprintf_s 69 | #define strtoull _strtoui64 70 | #define strtoll _strtoi64 71 | 72 | // va_copy portability definitions 73 | #ifdef COMPILER_MSVC 74 | // MSVC doesn't have va_copy yet. 75 | // This is believed to work for 32-bit msvc. This may not work at all for 76 | // other platforms. 77 | // If va_list uses the single-element-array trick, you will probably get 78 | // a compiler error here. 79 | #include 80 | inline void va_copy(va_list& a, va_list& b) { 81 | a = b; 82 | } 83 | #endif // COMPILER_MSVC 84 | #endif // OS_WIN 85 | 86 | template 87 | char (&ArraySizeHelper(T (&array)[N]))[N]; 88 | 89 | #ifndef OS_WIN 90 | template 91 | char (&ArraySizeHelper(const T (&array)[N]))[N]; 92 | #endif // !OS_WIN 93 | 94 | #define arraysize(array) (sizeof(ArraySizeHelper(array))) 95 | 96 | #ifdef OS_WIN 97 | // I64/UI64 postfixes are equivalent to LL/ULL and "I64" is equivalent to 98 | // "ll" since Visual C++ 2005, so we no longer need Windows-specific hack 99 | // for these, but we keep using old hacks. The reasons are 100 | // - these hack support wider compilers including Visual C++ 2003 and prior. 101 | // (Despite the fact GG_LONGLONG and GG_ULONGLONG work well on Visual C++ 102 | // 2003, supporting Visual C++ 2003 is not a goal of Mozc. Please test 103 | // your code with Visual C++ 2008 in terms of Mozc on Windows.) 104 | // - despite the names of GG_LONGLONG and GG_LL_FORMAT, what we want are 105 | // for type int64, NOT for type long long. So the name of I64/UI64 should 106 | // be much more appropriate and safer against future changes. 107 | #define GG_LONGLONG(x) x##I64 108 | #define GG_ULONGLONG(x) x##UI64 109 | // Length modifier in printf format string for int64's (e.g. within %d) 110 | #define GG_LL_FORMAT "I64" // As in printf("%I64d", ...) 111 | #define GG_LL_FORMAT_W L"I64" 112 | #else 113 | #define GG_LONGLONG(x) x##LL 114 | #define GG_ULONGLONG(x) x##ULL 115 | #define GG_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. 116 | #define GG_LL_FORMAT_W L"ll" 117 | #endif // OS_WIN 118 | 119 | // INT_MIN, INT_MAX, UINT_MAX family at Google 120 | static const uint8 kuint8max = (( uint8) 0xFF); 121 | static const uint16 kuint16max = ((uint16) 0xFFFF); 122 | static const uint32 kuint32max = ((uint32) 0xFFFFFFFF); 123 | static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); 124 | static const int8 kint8min = (( int8) 0x80); 125 | static const int8 kint8max = (( int8) 0x7F); 126 | static const int16 kint16min = (( int16) 0x8000); 127 | static const int16 kint16max = (( int16) 0x7FFF); 128 | static const int32 kint32min = (( int32) 0x80000000); 129 | static const int32 kint32max = (( int32) 0x7FFFFFFF); 130 | static const int64 kint64min = (( int64) GG_LONGLONG(0x8000000000000000)); 131 | static const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); 132 | 133 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 134 | TypeName(const TypeName&); \ 135 | void operator=(const TypeName&) 136 | 137 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 138 | TypeName(); \ 139 | DISALLOW_COPY_AND_ASSIGN(TypeName) 140 | 141 | // Macro for annotating implicit fall-through 142 | // TODO(team): Implement this. 143 | #define FALLTHROUGH_INTENDED do { } while (0) 144 | 145 | #if (defined(COMPILER_GCC3) || defined(COMPILER_ICC) || defined(OS_MACOSX)) && !defined(SWIG) 146 | // Tell the compiler to do printf format string checking if the 147 | // compiler supports it; see the 'format' attribute in 148 | // . 149 | // 150 | // N.B.: As the GCC manual states, "[s]ince non-static C++ methods 151 | // have an implicit 'this' argument, the arguments of such methods 152 | // should be counted from two, not one." 153 | #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ 154 | __attribute__((__format__ (__printf__, string_index, first_to_check))) 155 | #define SCANF_ATTRIBUTE(string_index, first_to_check) \ 156 | __attribute__((__format__ (__scanf__, string_index, first_to_check))) 157 | #else 158 | #define PRINTF_ATTRIBUTE(string_index, first_to_check) 159 | #define SCANF_ATTRIBUTE(string_index, first_to_check) 160 | #endif // (COMPILER_GCC3 || COMPILER_ICC || OS_MACOSX) && !SWIG 161 | 162 | #ifndef SWIG 163 | # define ABSTRACT = 0 164 | #endif 165 | 166 | #define AS_STRING(x) AS_STRING_INTERNAL(x) 167 | #define AS_STRING_INTERNAL(x) #x 168 | 169 | 170 | #include "base/flags.h" 171 | #include "base/init.h" 172 | 173 | #endif // MOZC_BASE_PORT_H_ 174 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/atl_wrapper/atlbase_mozc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // This header file is made as a workaround againt 31 | // http://support.microsoft.com/kb/813540. 32 | // See the following thread for details. 33 | // http://connect.microsoft.com/VisualStudio/feedback/details/535704/atlcomcli-h-cvartypeinfo-char-cannot-be-compiled-with-j-or-char-unsigned-flage-enabled 34 | 35 | #ifndef MOZC_WIN32_ATL_WRAPPER_ATL_BASE_MOZC_H_ 36 | #define MOZC_WIN32_ATL_WRAPPER_ATL_BASE_MOZC_H_ 37 | 38 | #if _MSC_VER >= 1600 39 | #include 40 | #pragma push_macro("ATLSTATIC_ASSERT") 41 | #undef ATLSTATIC_ASSERT 42 | #define ATLSTATIC_ASSERT(a, b) 43 | #include 44 | #pragma pop_macro("ATLSTATIC_ASSERT") 45 | #endif // _MSC_VER >= 1600 46 | #include 47 | 48 | #endif // MOZC_WIN32_ATL_WRAPPER_ATL_BASE_MOZC_H_ 49 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/base/imm_reconvert_string.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_BASE_IMM_RECONVERT_STRING_H_ 31 | #define MOZC_WIN32_BASE_IMM_RECONVERT_STRING_H_ 32 | 33 | #include 34 | #include 35 | 36 | #include "base/port.h" 37 | #ifdef IMCRVTIP_EXPORTS 38 | #include "base/namespace.h" 39 | #endif 40 | 41 | namespace mozc { 42 | namespace win32 { 43 | // This class is designed to compose/decompose RECONVERTSTRING structure in 44 | // safe way. 45 | // According to MSDN http://msdn.microsoft.com/en-us/library/dd319107.aspx, 46 | // a valid RECONVERTSTRING satisfies following conditions: 47 | // - the target string range is a subset of the composition string range. 48 | // - the composition string range is a subset of the entire string range. 49 | // which means RECONVERTSTRING can always be decomposed into 5 substrings. 50 | // For example, "He[CB]llo[TB],[TE] worl[CE]d!" can be decomposed into 51 | // - preceding_text : "He" 52 | // - preceding_composition: "llo" 53 | // - target : "," 54 | // - following_composition: " worl" 55 | // - following_text : "d!" 56 | // where, 57 | // - [CB]: CompositionBegin 58 | // - [CE]: CompositionEnd 59 | // - [TB]: TargetBegin 60 | // - [TE]: TargetEnd 61 | class ReconvertString { 62 | public: 63 | // Returns true if given substrings are copied into |reconvert_string|. 64 | // The caller is responsible for allocating enough memory for 65 | // |reconvert_string|. 66 | static bool Compose(const wstring &preceding_text, 67 | const wstring &preceding_composition, 68 | const wstring &target, 69 | const wstring &following_composition, 70 | const wstring &following_text, 71 | RECONVERTSTRING *reconvert_string); 72 | 73 | // Returns true if substrings are copied from |reconvert_string|. 74 | static bool Decompose(const RECONVERTSTRING *reconvert_string, 75 | wstring *preceding_text, 76 | wstring *preceding_composition, 77 | wstring *target, 78 | wstring *following_composition, 79 | wstring *following_text); 80 | 81 | // Returns true if the given |reconvert_string| is valid. 82 | static bool Validate(const RECONVERTSTRING *reconvert_string); 83 | 84 | #ifndef IMCRVTIP_EXPORTS 85 | // If the composition range is empty, this function tries to update 86 | // |reconvert_string| so that characters in the compositoin consist of the 87 | // same script type. 88 | // If the composition range is not empty, this function does nothing. 89 | // Returns true if |reconvert_string| is valid and has a non-empty 90 | // composition range finally. 91 | static bool EnsureCompositionIsNotEmpty(RECONVERTSTRING *reconvert_string); 92 | #endif 93 | 94 | private: 95 | DISALLOW_COPY_AND_ASSIGN(ReconvertString); 96 | }; 97 | 98 | } // namespace win32 99 | } // namespace mozc 100 | #endif // MOZC_WIN32_BASE_IMM_RECONVERT_STRING_H_ 101 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/base/input_state.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "win32/base/input_state.h" 31 | 32 | namespace mozc { 33 | namespace win32 { 34 | 35 | InputState::InputState() 36 | : open(false), 37 | logical_conversion_mode(0), 38 | visible_conversion_mode(0) { 39 | } 40 | 41 | InputBehavior::InputBehavior() 42 | : disabled(false), 43 | prefer_kana_input(false), 44 | use_mode_indicator(false), 45 | use_romaji_key_to_toggle_input_style(false) {} 46 | 47 | } // namespace win32 48 | } // namespace mozc 49 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/base/input_state.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_BASE_INPUT_STATE_ 31 | #define MOZC_WIN32_BASE_INPUT_STATE_ 32 | 33 | #include 34 | 35 | #include "win32/base/keyboard.h" 36 | 37 | namespace mozc { 38 | namespace win32 { 39 | 40 | struct InputState { 41 | // Represents the IME is turned on or not. 42 | bool open; 43 | // Represents the expected conversion mode visible from the input method 44 | // framework (IMM32/TSF). 45 | DWORD logical_conversion_mode; 46 | // Represents the expected conversion mode visible from the user. So the 47 | // language bar should show this mode. 48 | DWORD visible_conversion_mode; 49 | // Tracks the last down key mainly for handling modifer key-up event. 50 | VirtualKey last_down_key; 51 | InputState(); 52 | }; 53 | 54 | struct InputBehavior { 55 | bool disabled; 56 | bool prefer_kana_input; 57 | bool use_mode_indicator; 58 | bool use_romaji_key_to_toggle_input_style; 59 | InputBehavior(); 60 | }; 61 | 62 | } // namespace win32 63 | } // namespace mozc 64 | #endif // MOZC_WIN32_BASE_INPUT_STATE_ 65 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/base/keyboard.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_IME_IME_KEYBOARD_ 31 | #define MOZC_WIN32_IME_IME_KEYBOARD_ 32 | 33 | #include 34 | 35 | #include 36 | 37 | #include "base/port.h" 38 | #ifdef IMCRVTIP_EXPORTS 39 | #include "base/namespace.h" 40 | #endif 41 | 42 | namespace mozc { 43 | namespace win32 { 44 | class KeyboardStatus { 45 | public: 46 | KeyboardStatus(); 47 | explicit KeyboardStatus(const BYTE key_status[256]); 48 | BYTE GetState(int virtual_key) const; 49 | void SetState(int virtual_key, BYTE value); 50 | bool IsToggled(int virtual_key) const; 51 | bool IsPressed(int virtual_key) const; 52 | const BYTE *status() const; 53 | BYTE *mutable_status(); 54 | size_t status_size() const; 55 | private: 56 | BYTE status_[256]; 57 | }; 58 | 59 | class LParamKeyInfo { 60 | public: 61 | LParamKeyInfo(); 62 | explicit LParamKeyInfo(LPARAM lparam); 63 | int GetKeyRepeatCount() const; 64 | BYTE GetScanCode() const; 65 | bool IsExtendedKey() const; 66 | bool HasContextCode() const; 67 | bool IsPreviousStateDwon() const; 68 | bool IsInTansitionState() const; 69 | // In ImeProcessKey callback, the highest bit represents if this is key-down 70 | // event or not. You should not use this value in other situations including 71 | // WM_KEYDOWN/WM_KEYUP event handler. 72 | // Returns true if this is key-down event assuming this is the LPARAM passed 73 | // to ImeProcessKey callback. 74 | bool IsKeyDownInImeProcessKey() const; 75 | LPARAM lparam() const; 76 | private: 77 | LPARAM lparam_; 78 | }; 79 | 80 | class VirtualKey { 81 | public: 82 | VirtualKey(); 83 | 84 | // Construct an instance from a given |virtual_key|. 85 | // You cannot specify VK_PACKET for |virtual_key|. 86 | static VirtualKey FromVirtualKey(BYTE virtual_key); 87 | // Construct an instance from a given |combined_virtual_key|. 88 | // If the low word of |combined_virtual_key| is VK_PACKET, 89 | // the high word will be used as |wide_char_|. 90 | // Otherwise, the lowest byte of |combined_virtual_key| will be 91 | // used as |virtual_key_|. 92 | static VirtualKey FromCombinedVirtualKey(UINT combined_virtual_key); 93 | // Construct an instance from a given ucs4 character. 94 | // In this case, |virtual_key_| will be set to VK_PACKET. 95 | static VirtualKey FromUnicode(char32 unicode); 96 | 97 | wchar_t wide_char() const; 98 | char32 unicode_char() const; 99 | BYTE virtual_key() const; 100 | 101 | private: 102 | VirtualKey(BYTE virtual_key, wchar_t wide_char, char32 unicode_char); 103 | char32 unicode_char_; 104 | wchar_t wide_char_; 105 | BYTE virtual_key_; 106 | }; 107 | 108 | // We intentionally wrap some APIs as virthal methods so that unit tests can 109 | // inject their own mock into the key handler. You can implement each method 110 | // as a redirector to the corresponding API for production, or implement it as 111 | // a mock which emulates the API predictably for unit tests. 112 | class Win32KeyboardInterface { 113 | public: 114 | virtual ~Win32KeyboardInterface() {} 115 | 116 | // Injection point for keyboard_state.IsPressed(VK_KANA). 117 | virtual bool IsKanaLocked(const KeyboardStatus &keyboard_state) = 0; 118 | 119 | // Injection point for SetKeyboardState API. 120 | virtual bool SetKeyboardState(const KeyboardStatus &keyboard_state) = 0; 121 | 122 | // Injection point for GetKeyboardState API. 123 | virtual bool GetKeyboardState(KeyboardStatus *keyboard_state) = 0; 124 | 125 | // Injection point for GetAsyncKeyState API. 126 | virtual bool AsyncIsKeyPressed(int virtual_key) = 0; 127 | 128 | // Injection point for ToUnicode API. 129 | virtual int ToUnicode( 130 | __in UINT wVirtKey, 131 | __in UINT wScanCode, 132 | __in_bcount_opt(256) CONST BYTE *lpKeyState, 133 | __out_ecount(cchBuff) LPWSTR pwszBuff, 134 | __in int cchBuff, 135 | __in UINT wFlags) = 0; 136 | 137 | // Injection point for SendInput API. 138 | virtual UINT SendInput(const vector &inputs) = 0; 139 | 140 | static Win32KeyboardInterface *CreateDefault(); 141 | }; 142 | 143 | class JapaneseKeyboardLayoutEmulator { 144 | public: 145 | // This methods emulates ToUnicode API as if the current keyboard layout was 146 | // Japanese keyboard. Currently this emulation ignores |scan_code|. 147 | static int ToUnicode( 148 | __in UINT virtual_key, 149 | __in UINT scan_code, 150 | __in_bcount_opt(256) CONST BYTE *key_state, 151 | __out_ecount(character_buffer_size) LPWSTR character_buffer, 152 | __in int character_buffer_size, 153 | __in UINT flags); 154 | 155 | // Returns generated character for Japanese keyboard layout based on the 156 | // given keyboard state. Returns '\0' if no character is generated. 157 | // Note that built-in Japanese keyboard layout generates at most 1 character 158 | // for any key combination, and there is no key to generate '\0', as far as 159 | // we have observed with the built-in layout on Windows Vista. 160 | static wchar_t GetCharacterForKeyDown( 161 | BYTE virtual_key, 162 | const BYTE keyboard_state[256], 163 | bool is_menu_active); 164 | private: 165 | DISALLOW_COPY_AND_ASSIGN(JapaneseKeyboardLayoutEmulator); 166 | }; 167 | } // namespace win32 168 | } // namespace mozc 169 | #endif // MOZC_WIN32_IME_IME_KEYBOARD_ 170 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_composition_util.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "win32/tip/tip_composition_util.h" 31 | 32 | #ifndef IMCRVTIP_EXPORTS 33 | #include "win32/base/tsf_profile.h" 34 | #include "win32/tip/tip_edit_session_impl.h" 35 | #else 36 | #include "../../../imcrvtip.h" 37 | #endif 38 | #include "win32/tip/tip_range_util.h" 39 | #ifndef IMCRVTIP_EXPORTS 40 | #include "win32/tip/tip_text_service.h" 41 | #endif 42 | 43 | namespace mozc { 44 | namespace win32 { 45 | namespace tsf { 46 | 47 | using ATL::CComPtr; 48 | 49 | CComPtr TipCompositionUtil::GetComposition( 50 | CComPtr context, TfEditCookie edit_cookie) { 51 | CComPtr context_composition; 52 | if (FAILED(context.QueryInterface(&context_composition))) { 53 | return nullptr; 54 | } 55 | 56 | CComPtr enum_composition; 57 | if (FAILED(context_composition->FindComposition(edit_cookie, nullptr, 58 | &enum_composition))) { 59 | return nullptr; 60 | } 61 | 62 | while (true) { 63 | CComPtr composition_view; 64 | ULONG num_fetched = 0; 65 | if (enum_composition->Next(1, &composition_view, &num_fetched) != S_OK) { 66 | return nullptr; 67 | } 68 | if (num_fetched != 1) { 69 | return nullptr; 70 | } 71 | GUID clsid = GUID_NULL; 72 | if (FAILED(composition_view->GetOwnerClsid(&clsid))) { 73 | continue; 74 | } 75 | #ifndef IMCRVTIP_EXPORTS 76 | if (!::IsEqualCLSID(TsfProfile::GetTextServiceGuid(), clsid)) { 77 | #else 78 | if (!::IsEqualCLSID(c_clsidTextService, clsid)) { 79 | #endif 80 | continue; 81 | } 82 | // Although TSF supports multiple composition, Mozc uses only one 83 | // composition at the same time. So the first one must be the only one. 84 | return composition_view; 85 | } 86 | } 87 | 88 | HRESULT TipCompositionUtil::ClearDisplayAttributes(ITfContext *context, 89 | ITfComposition *composition, 90 | TfEditCookie write_cookie) { 91 | HRESULT result = S_OK; 92 | 93 | // Retrieve the current composition range. 94 | CComPtr composition_range; 95 | result = composition->GetRange(&composition_range); 96 | if (FAILED(result)) { 97 | return result; 98 | } 99 | 100 | // Get out the display attribute property 101 | CComPtr display_attribute; 102 | result = context->GetProperty(GUID_PROP_ATTRIBUTE, &display_attribute); 103 | if (FAILED(result)) { 104 | return result; 105 | } 106 | // Clear existing attributes. 107 | result = display_attribute->Clear(write_cookie, composition_range); 108 | if (FAILED(result)) { 109 | return result; 110 | } 111 | return S_OK; 112 | } 113 | 114 | } // namespace tsf 115 | } // namespace win32 116 | } // namespace mozc 117 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_composition_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_TIP_TIP_COMPOSITION_UTIL_H_ 31 | #define MOZC_WIN32_TIP_TIP_COMPOSITION_UTIL_H_ 32 | 33 | #include 34 | #define _ATL_NO_AUTOMATIC_NAMESPACE 35 | #define _WTL_NO_AUTOMATIC_NAMESPACE 36 | // Workaround against KB813540 37 | #include 38 | #include 39 | #include 40 | 41 | #include "base/port.h" 42 | 43 | namespace mozc { 44 | namespace win32 { 45 | namespace tsf { 46 | 47 | class TipTextService; 48 | 49 | class TipCompositionUtil { 50 | public: 51 | // Returns composition view object if there is an composition which belongs 52 | // to Mozc in |context|. Otherwise returns NULL. 53 | static ATL::CComPtr GetComposition( 54 | ATL::CComPtr context, TfEditCookie edit_cookie); 55 | 56 | // Removes display attributes from |composition|. Returns the result. 57 | static HRESULT ClearDisplayAttributes(ITfContext *context, 58 | ITfComposition *composition, 59 | TfEditCookie write_cookie); 60 | 61 | private: 62 | DISALLOW_IMPLICIT_CONSTRUCTORS(TipCompositionUtil); 63 | }; 64 | 65 | } // namespace tsf 66 | } // namespace win32 67 | } // namespace mozc 68 | 69 | #endif // MOZC_WIN32_TIP_TIP_COMPOSITION_UTIL_H_ 70 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_range_util.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "win32/tip/tip_range_util.h" 31 | 32 | #define _ATL_NO_AUTOMATIC_NAMESPACE 33 | #define _WTL_NO_AUTOMATIC_NAMESPACE 34 | // Workaround against KB813540 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | namespace mozc { 41 | namespace win32 { 42 | namespace tsf { 43 | namespace { 44 | 45 | using ATL::CComPtr; 46 | using ATL::CComQIPtr; 47 | using ATL::CComVariant; 48 | using std::unique_ptr; 49 | 50 | // GUID_PROP_INPUTSCOPE 51 | GUID kGuidPropInputscope = { 52 | 0x1713dd5a, 0x68e7, 0x4a5b, {0x9a, 0xf6, 0x59, 0x2a, 0x59, 0x5c, 0x77, 0x8d} 53 | }; 54 | 55 | } // namespace 56 | 57 | HRESULT TipRangeUtil::SetSelection( 58 | ITfContext *context, TfEditCookie edit_cookie, ITfRange *range, 59 | TfActiveSelEnd active_sel_end) { 60 | if (context == nullptr) { 61 | return E_INVALIDARG; 62 | } 63 | TF_SELECTION selections[1] = {}; 64 | selections[0].range = range; 65 | selections[0].style.ase = active_sel_end; 66 | selections[0].style.fInterimChar = FALSE; 67 | return context->SetSelection(edit_cookie, arraysize(selections), selections); 68 | } 69 | 70 | HRESULT TipRangeUtil::GetDefaultSelection( 71 | ITfContext *context, TfEditCookie edit_cookie, ITfRange **range, 72 | TfActiveSelEnd *active_sel_end) { 73 | if (context == nullptr) { 74 | return E_INVALIDARG; 75 | } 76 | TF_SELECTION selections[1] = {}; 77 | ULONG fetched = 0; 78 | const HRESULT result = context->GetSelection( 79 | edit_cookie, TF_DEFAULT_SELECTION, arraysize(selections), selections, 80 | &fetched); 81 | if (FAILED(result)) { 82 | return result; 83 | } 84 | if (fetched != 1) { 85 | return E_FAIL; 86 | } 87 | if (range != nullptr) { 88 | *range = selections[0].range; 89 | (*range)->AddRef(); 90 | } 91 | if (active_sel_end != nullptr) { 92 | *active_sel_end = selections[0].style.ase; 93 | } 94 | 95 | return S_OK; 96 | } 97 | 98 | HRESULT TipRangeUtil::GetText( 99 | ITfRange *range, TfEditCookie edit_cookie, wstring *text) { 100 | if (range == nullptr) { 101 | return E_INVALIDARG; 102 | } 103 | if (text == nullptr) { 104 | return E_INVALIDARG; 105 | } 106 | text->clear(); 107 | 108 | // Create a clone of |range| so that we can move the start position while 109 | // reading the text via ITfRange::GetText with TF_TF_MOVESTART flag. 110 | CComPtr range_view; 111 | if (FAILED(range->Clone(&range_view))) { 112 | return E_FAIL; 113 | } 114 | 115 | // Use a buffer on stack for shorter size case. 116 | { 117 | wchar_t buffer[64]; 118 | ULONG fetched = 0; 119 | const HRESULT result = range_view->GetText( 120 | edit_cookie, TF_TF_MOVESTART, buffer, arraysize(buffer), &fetched); 121 | if (FAILED(result)) { 122 | return result; 123 | } 124 | if (fetched > arraysize(buffer)) { 125 | return E_UNEXPECTED; 126 | } 127 | text->append(buffer, fetched); 128 | if (fetched < arraysize(buffer)) { 129 | return S_OK; 130 | } 131 | } 132 | 133 | // Use a buffer on heap for longer size case. 134 | { 135 | const size_t kBufferSize = 1024; 136 | unique_ptr buffer(new wchar_t[kBufferSize]); 137 | while (true) { 138 | ULONG fetched = 0; 139 | const HRESULT result = range_view->GetText( 140 | edit_cookie, TF_TF_MOVESTART, buffer.get(), kBufferSize, &fetched); 141 | if (FAILED(result)) { 142 | return result; 143 | } 144 | if (fetched > kBufferSize) { 145 | return E_UNEXPECTED; 146 | } 147 | text->append(buffer.get(), fetched); 148 | if (fetched < kBufferSize) { 149 | break; 150 | } 151 | } 152 | } 153 | return S_OK; 154 | } 155 | 156 | HRESULT TipRangeUtil::GetInputScopes(ITfRange *range, 157 | TfEditCookie read_cookie, 158 | vector *input_scopes) { 159 | if (input_scopes == nullptr) { 160 | return E_FAIL; 161 | } 162 | input_scopes->clear(); 163 | 164 | HRESULT result = S_OK; 165 | CComPtr context; 166 | result = range->GetContext(&context); 167 | if (FAILED(result)) { 168 | return result; 169 | } 170 | 171 | CComPtr readonly_property; 172 | result = context->GetAppProperty(kGuidPropInputscope, &readonly_property); 173 | if (FAILED(result)) { 174 | return result; 175 | } 176 | if (!readonly_property) { 177 | return E_FAIL; 178 | } 179 | CComVariant variant; 180 | result = readonly_property->GetValue(read_cookie, range, &variant); 181 | if (FAILED(result)) { 182 | return result; 183 | } 184 | if (variant.vt != VT_UNKNOWN) { 185 | return S_OK; 186 | } 187 | 188 | CComQIPtr input_scope = variant.punkVal; 189 | InputScope *input_scopes_buffer = NULL; 190 | UINT num_input_scopes = 0; 191 | result = input_scope->GetInputScopes(&input_scopes_buffer, &num_input_scopes); 192 | if (FAILED(result)) { 193 | return result; 194 | } 195 | input_scopes->assign(input_scopes_buffer, 196 | input_scopes_buffer + num_input_scopes); 197 | ::CoTaskMemFree(input_scopes_buffer); 198 | return S_OK; 199 | } 200 | 201 | bool TipRangeUtil::IsRangeCovered(TfEditCookie edit_cookie, 202 | ITfRange* range_test, 203 | ITfRange* range_cover) { 204 | HRESULT result = S_OK; 205 | 206 | // Check if {the start position of |range_cover|) <= {the start position 207 | // of |range_test|}. 208 | LONG position = 0; 209 | result = range_cover->CompareStart(edit_cookie, range_test, TF_ANCHOR_START, 210 | &position); 211 | if (result != S_OK || position > 0) { 212 | return false; 213 | } 214 | 215 | // Check if {the end position of |range_cover|} >= {the end position of 216 | // |range_test|}. 217 | result = range_cover->CompareEnd(edit_cookie, range_test, TF_ANCHOR_END, 218 | &position); 219 | if (result != S_OK || position < 0) { 220 | return false; 221 | } 222 | 223 | return true; 224 | } 225 | 226 | } // namespace tsf 227 | } // namespace win32 228 | } // namespace mozc 229 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_range_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_TIP_TIP_RANGE_UTIL_H_ 31 | #define MOZC_WIN32_TIP_TIP_RANGE_UTIL_H_ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | #include "base/port.h" 41 | #ifdef IMCRVTIP_EXPORTS 42 | #include "base/namespace.h" 43 | #endif 44 | 45 | namespace mozc { 46 | namespace win32 { 47 | namespace tsf { 48 | 49 | // A utility class to handle ITfRange object. 50 | class TipRangeUtil { 51 | public: 52 | // Sets the specified |range| into |context|. 53 | // Returns the general result code. 54 | static HRESULT SetSelection( 55 | ITfContext *context, TfEditCookie edit_cookie, ITfRange *range, 56 | TfActiveSelEnd active_sel_end); 57 | 58 | // Retrieves the default selection from |context| into |range|. 59 | // Returns the general result code. 60 | static HRESULT GetDefaultSelection( 61 | ITfContext *context, TfEditCookie edit_cookie, ITfRange **range, 62 | TfActiveSelEnd *active_sel_end); 63 | 64 | // Retrieves the text from |range| into |text|. 65 | // Returns the general result code. 66 | static HRESULT GetText( 67 | ITfRange *range, TfEditCookie edit_cookie, wstring *text); 68 | 69 | // Retrieves the input scopes from |range| into |input_scopes|. 70 | // Returns the general result code. 71 | static HRESULT GetInputScopes(ITfRange *range, 72 | TfEditCookie read_cookie, 73 | vector *input_scopes); 74 | 75 | // Checks whether or not |range_test| becomes a subset of |range_cover|. 76 | static bool IsRangeCovered(TfEditCookie edit_cookie, 77 | ITfRange *range_test, 78 | ITfRange *range_cover); 79 | 80 | private: 81 | DISALLOW_IMPLICIT_CONSTRUCTORS(TipRangeUtil); 82 | }; 83 | 84 | } // namespace tsf 85 | } // namespace win32 86 | } // namespace mozc 87 | 88 | #endif // MOZC_WIN32_TIP_TIP_RANGE_UTIL_H_ 89 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_ref_count.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "win32/tip/tip_ref_count.h" 31 | 32 | #ifndef IMCRVTIP_EXPORTS 33 | #include "win32/tip/tip_dll_module.h" 34 | #endif 35 | 36 | namespace mozc { 37 | namespace win32 { 38 | namespace tsf { 39 | 40 | TipRefCount::TipRefCount() 41 | : reference_count_(0) { 42 | #ifndef IMCRVTIP_EXPORTS 43 | TipDllModule::AddRef(); 44 | #endif 45 | } 46 | 47 | TipRefCount::~TipRefCount() { 48 | #ifndef IMCRVTIP_EXPORTS 49 | TipDllModule::Release(); 50 | #endif 51 | } 52 | 53 | ULONG TipRefCount::AddRefImpl() { 54 | return ::InterlockedIncrement(&reference_count_); 55 | } 56 | 57 | ULONG TipRefCount::ReleaseImpl() { 58 | const LONG count = ::InterlockedDecrement(&reference_count_); 59 | if (reference_count_ <= 0) { 60 | return 0; 61 | } 62 | return count; 63 | } 64 | 65 | } // namespace tsf 66 | } // namespace win32 67 | } // namespace mozc 68 | 69 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_ref_count.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_TIP_TIP_REF_COUNT_H_ 31 | #define MOZC_WIN32_TIP_TIP_REF_COUNT_H_ 32 | 33 | #include 34 | 35 | #include "base/port.h" 36 | 37 | namespace mozc { 38 | namespace win32 { 39 | namespace tsf { 40 | 41 | // Implements base functionaries of reference counting for COM object. 42 | class TipRefCount { 43 | public: 44 | TipRefCount(); 45 | ~TipRefCount(); 46 | ULONG AddRefImpl(); 47 | ULONG ReleaseImpl(); 48 | 49 | private: 50 | volatile LONG reference_count_; 51 | 52 | DISALLOW_COPY_AND_ASSIGN(TipRefCount); 53 | }; 54 | 55 | } // namespace tsf 56 | } // namespace win32 57 | } // namespace mozc 58 | 59 | #endif // MOZC_WIN32_TIP_TIP_REF_COUNT_H_ 60 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_surrounding_text.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_TIP_TIP_SURROUNDING_TEXT_H_ 31 | #define MOZC_WIN32_TIP_TIP_SURROUNDING_TEXT_H_ 32 | 33 | #include 34 | 35 | #include "base/port.h" 36 | 37 | struct ITfContext; 38 | struct ITfEditSession; 39 | 40 | #ifdef IMCRVTIP_EXPORTS 41 | #include "base/namespace.h" // std:: for wstring 42 | class CTextService; 43 | #endif 44 | 45 | namespace mozc { 46 | 47 | namespace commands { 48 | class Output; 49 | } // namespace commands 50 | 51 | namespace win32 { 52 | namespace tsf { 53 | 54 | #ifndef IMCRVTIP_EXPORTS 55 | class TipTextService; 56 | #endif 57 | 58 | struct TipSurroundingTextInfo { 59 | TipSurroundingTextInfo(); 60 | 61 | wstring preceding_text; 62 | wstring selected_text; 63 | wstring following_text; 64 | bool has_preceding_text; 65 | bool has_selected_text; 66 | bool has_following_text; 67 | bool is_transitory; // context is a transitory context 68 | bool in_composition; // context has a composition owned by Mozc. 69 | }; 70 | 71 | class TipSurroundingText { 72 | public: 73 | // Returns true when succeeds to retrieve surrounding text information 74 | // from the context specified by |context|. 75 | // Caveats: This method internally depends on synchronous edit session. 76 | // You should call this method when and only when a synchronous edit 77 | // session is guaranteed to be safe. A keyevent hander is one of 78 | // examples. See the following document for details. 79 | // http://blogs.msdn.com/b/tsfaware/archive/2007/05/17/rules-of-text-services.aspx 80 | #ifndef IMCRVTIP_EXPORTS 81 | static bool Get(TipTextService *text_service, 82 | #else 83 | static bool Get(CTextService *text_service, 84 | #endif 85 | ITfContext *context, 86 | TipSurroundingTextInfo *info); 87 | 88 | #ifdef IMCRVTIP_EXPORTS 89 | static bool GetMore(CTextService *text_service, 90 | ITfContext *context, 91 | int offset, 92 | TipSurroundingTextInfo *info); 93 | #endif 94 | 95 | // A variant of TipSurroundingText::Get. One difference is that this method 96 | // moves the anchor position of the selection at the end of the range. 97 | // Another difference is that this method uses IMM32 message when fails to 98 | // retrieve/update the selection. 99 | // In order to emulate the IMM32 reconversion, we need to use async edit 100 | // session if |need_async_reconversion| is set to be true. See 101 | // IMN_PRIVATE/kNotifyReconvertFromIME in IMM32-Mozc about IMM32 reconversion. 102 | // TODO(yukawa): Consider to unify this method with TipSurroundingText::Get. 103 | #ifndef IMCRVTIP_EXPORTS 104 | static bool PrepareForReconversionFromIme(TipTextService *text_service, 105 | #else 106 | static bool PrepareForReconversionFromIme(CTextService *text_service, 107 | #endif 108 | ITfContext *context, 109 | TipSurroundingTextInfo *info, 110 | bool *need_async_reconversion); 111 | 112 | // Returns true when succeeds to delete preceeding text from the beginning of 113 | // the selected range. 114 | // Caveats: |num_characters_to_be_deleted_in_ucs4| is not the number of 115 | // elements in UTF16. Beware of surrogate pairs. 116 | // Caveats: This method internally depends on synchronous edit session. 117 | // You should call this method when and only when a synchronous edit 118 | // session is guaranteed to be safe. A keyevent hander is one of 119 | // examples. See the following document for details. 120 | // http://blogs.msdn.com/b/tsfaware/archive/2007/05/17/rules-of-text-services.aspx 121 | #ifndef IMCRVTIP_EXPORTS 122 | static bool DeletePrecedingText(TipTextService *text_service, 123 | #else 124 | static bool DeletePrecedingText(CTextService *text_service, 125 | #endif 126 | ITfContext *context, 127 | size_t num_characters_to_be_deleted_in_ucs4); 128 | 129 | private: 130 | DISALLOW_IMPLICIT_CONSTRUCTORS(TipSurroundingText); 131 | }; 132 | 133 | class TipSurroundingTextUtil { 134 | public: 135 | // Returns true if |text| has more than |characters_in_ucs4| characters. 136 | // When succeeds, the last |*characters_in_utf16| characters in |text| 137 | // can be measured as |characters_in_ucs4| in the unit of UCS4. 138 | static bool MeasureCharactersBackward(const wstring &text, 139 | size_t characters_in_ucs4, 140 | size_t *characters_in_utf16); 141 | }; 142 | 143 | } // namespace tsf 144 | } // namespace win32 145 | } // namespace mozc 146 | 147 | #endif // MOZC_WIN32_TIP_TIP_SURROUNDING_TEXT_H_ 148 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_transitory_extension.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "win32/tip/tip_transitory_extension.h" 31 | 32 | #include 33 | #define _ATL_NO_AUTOMATIC_NAMESPACE 34 | #define _WTL_NO_AUTOMATIC_NAMESPACE 35 | // Workaround against KB813540 36 | #include 37 | #include 38 | #include 39 | 40 | namespace mozc { 41 | namespace win32 { 42 | namespace tsf { 43 | 44 | using ATL::CComPtr; 45 | using ATL::CComQIPtr; 46 | using ATL::CComVariant; 47 | 48 | CComPtr TipTransitoryExtension::ToParentDocumentIfExists( 49 | ITfDocumentMgr *document_manager) { 50 | if (document_manager == nullptr) { 51 | return nullptr; 52 | } 53 | 54 | CComPtr context; 55 | if (FAILED(document_manager->GetTop(&context))) { 56 | return document_manager; 57 | } 58 | 59 | if (!context) { 60 | return document_manager; 61 | } 62 | 63 | TF_STATUS status = {}; 64 | if (FAILED(context->GetStatus(&status))) { 65 | return document_manager; 66 | } 67 | 68 | if ((status.dwStaticFlags & TF_SS_TRANSITORY) != TF_SS_TRANSITORY) { 69 | return document_manager; 70 | } 71 | 72 | CComQIPtr compartment_mgr(document_manager); 73 | if (!compartment_mgr) { 74 | return document_manager; 75 | } 76 | 77 | CComPtr compartment; 78 | if (FAILED(compartment_mgr->GetCompartment( 79 | GUID_COMPARTMENT_TRANSITORYEXTENSION_PARENT, &compartment))) { 80 | return document_manager; 81 | } 82 | 83 | CComVariant var; 84 | if (FAILED(compartment->GetValue(&var))) { 85 | return document_manager; 86 | } 87 | 88 | if (var.vt != VT_UNKNOWN || var.punkVal == nullptr) { 89 | return document_manager; 90 | } 91 | 92 | CComQIPtr parent_document_mgr = var.punkVal; 93 | if (!parent_document_mgr) { 94 | return document_manager; 95 | } 96 | 97 | return parent_document_mgr; 98 | } 99 | 100 | CComPtr TipTransitoryExtension::ToParentContextIfExists( 101 | ITfContext *context) { 102 | if (context == nullptr) { 103 | return nullptr; 104 | } 105 | 106 | CComPtr document_mgr; 107 | if (FAILED(context->GetDocumentMgr(&document_mgr))) { 108 | return context; 109 | } 110 | 111 | CComPtr parent_context; 112 | if (FAILED(ToParentDocumentIfExists(document_mgr)->GetTop( 113 | &parent_context))) { 114 | return context; 115 | } 116 | if (!parent_context) { 117 | return context; 118 | } 119 | return parent_context; 120 | } 121 | 122 | } // namespace tsf 123 | } // namespace win32 124 | } // namespace mozc 125 | -------------------------------------------------------------------------------- /imcrvtip/mozc/win32/tip/tip_transitory_extension.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef MOZC_WIN32_TIP_TIP_TRANSITORY_EXTENSION_H_ 31 | #define MOZC_WIN32_TIP_TIP_TRANSITORY_EXTENSION_H_ 32 | 33 | #include 34 | #define _ATL_NO_AUTOMATIC_NAMESPACE 35 | #define _WTL_NO_AUTOMATIC_NAMESPACE 36 | // Workaround against KB813540 37 | #include 38 | #include 39 | #include 40 | 41 | #include "base/port.h" 42 | 43 | namespace mozc { 44 | namespace win32 { 45 | namespace tsf { 46 | 47 | // This class provides utility methods to access parent object provided by 48 | // Transitory Extensions. 49 | // Starting with Windows Vista, CUAS provides Transitory Extensions with which 50 | // full text store support is available for edit control, rich edit control, 51 | // and Trident edit control. You can use these text stores mainly for one-shot 52 | // read/read-write access. For keyboard input, which may require text 53 | // composition, should use the original (transitory) text store. 54 | // See the following article for the details about Transitory Extensions. 55 | // http://blogs.msdn.com/b/tsfaware/archive/2007/05/21/transitory-extensions.aspx 56 | class TipTransitoryExtension { 57 | public: 58 | // Returns the parent (full-text-store) document manager if exists. 59 | // Returns |document_manager| otherwise. 60 | static ATL::CComPtr ToParentDocumentIfExists( 61 | ITfDocumentMgr *document_manager); 62 | 63 | // Returns the parent (full-text-store) context if exists. 64 | // Returns |context| otherwise. 65 | static ATL::CComPtr ToParentContextIfExists( 66 | ITfContext *context); 67 | 68 | private: 69 | DISALLOW_IMPLICIT_CONSTRUCTORS(TipTransitoryExtension); 70 | }; 71 | 72 | } // namespace tsf 73 | } // namespace win32 74 | } // namespace mozc 75 | 76 | #endif // MOZC_WIN32_TIP_TIP_TRANSITORY_EXTENSION_H_ 77 | -------------------------------------------------------------------------------- /imcrvtip/resource.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef RESOURCE_H 3 | #define RESOURCE_H 4 | 5 | #define IDI_0_SKK 100 6 | 7 | #define IDI_X_INSERT 200 8 | #define IDI_X_NORMAL 201 9 | 10 | #define IDI_Z_INSERT 300 11 | #define IDI_Z_NORMAL 301 12 | 13 | #define IDR_SYSTRAY_MENU 1000 14 | #define IDM_NONE 1001 15 | #define IDM_NORMAL 1010 16 | #define IDM_INSERT 1020 17 | #define IDM_CONFIG 1021 18 | 19 | #endif //RESOURCE_H 20 | -------------------------------------------------------------------------------- /imcrvtip/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // nothing 2 | -------------------------------------------------------------------------------- /imcrvtip/stdafx.h: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | -------------------------------------------------------------------------------- /imvimcnf/ConfigCnf.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "configxml.h" 3 | #include "imvimcnf.h" 4 | 5 | LPCWSTR TextServiceDesc = TEXTSERVICE_DESC; 6 | 7 | IXmlWriter *pXmlWriter; 8 | IStream *pXmlFileStream; 9 | 10 | WCHAR cnfmutexname[MAX_KRNLOBJNAME]; //ミューテックス 11 | 12 | // ファイルパス 13 | WCHAR pathconfigxml[MAX_PATH]; //設定 14 | 15 | void CreateConfigPath() 16 | { 17 | WCHAR appdata[MAX_PATH]; 18 | 19 | pathconfigxml[0] = L'\0'; 20 | 21 | if(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, appdata) != S_OK) 22 | { 23 | appdata[0] = L'\0'; 24 | return; 25 | } 26 | 27 | wcsncat_s(appdata, L"\\", _TRUNCATE); 28 | wcsncat_s(appdata, TextServiceDesc, _TRUNCATE); 29 | wcsncat_s(appdata, L"\\", _TRUNCATE); 30 | 31 | _wmkdir(appdata); 32 | SetCurrentDirectoryW(appdata); 33 | 34 | _snwprintf_s(pathconfigxml, _TRUNCATE, L"%s%s", appdata, fnconfigxml); 35 | 36 | LPWSTR pszUserSid; 37 | WCHAR szDigest[32+1]; 38 | MD5_DIGEST digest; 39 | int i; 40 | 41 | ZeroMemory(cnfmutexname, sizeof(cnfmutexname)); 42 | ZeroMemory(szDigest, sizeof(szDigest)); 43 | 44 | if(GetUserSid(&pszUserSid)) 45 | { 46 | if(GetMD5(&digest, (CONST BYTE *)pszUserSid, (DWORD)wcslen(pszUserSid)*sizeof(WCHAR))) 47 | { 48 | for(i=0; i<_countof(digest.digest); i++) 49 | { 50 | _snwprintf_s(&szDigest[i*2], _countof(szDigest)-i*2, _TRUNCATE, L"%02x", digest.digest[i]); 51 | } 52 | } 53 | 54 | LocalFree(pszUserSid); 55 | } 56 | 57 | _snwprintf_s(cnfmutexname, _TRUNCATE, L"%s%s", VIMCNFMUTEX, szDigest); 58 | } 59 | 60 | BOOL SetFileDacl(LPCWSTR path) 61 | { 62 | BOOL bRet = FALSE; 63 | WCHAR sddl[MAX_KRNLOBJNAME] = {L'\0'}; 64 | PSECURITY_DESCRIPTOR pSD = NULL; 65 | LPWSTR pszUserSid; 66 | 67 | if(GetUserSid(&pszUserSid)) 68 | { 69 | _snwprintf_s(sddl, _TRUNCATE, L"D:%s(A;;FR;;;RC)(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;%s)", 70 | (IsVersion62AndOver() ? L"(A;;FR;;;AC)" : L""), pszUserSid); 71 | LocalFree(pszUserSid); 72 | } 73 | 74 | if(ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl, SDDL_REVISION_1, &pSD, NULL)) 75 | { 76 | if(SetFileSecurityW(path, DACL_SECURITY_INFORMATION, pSD)) 77 | { 78 | bRet = TRUE; 79 | } 80 | LocalFree(pSD); 81 | } 82 | 83 | return bRet; 84 | } 85 | 86 | int GetScaledSizeX(HWND hwnd, int size) 87 | { 88 | HDC hdc = GetDC(hwnd); 89 | int dpiX = GetDeviceCaps(hdc, LOGPIXELSX); 90 | ReleaseDC(hwnd, hdc); 91 | return MulDiv(size, dpiX, 96); 92 | } 93 | -------------------------------------------------------------------------------- /imvimcnf/DlgProcBehavior2.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "configxml.h" 3 | #include "imvimcnf.h" 4 | #include "resource.h" 5 | 6 | static const LPCWSTR otherime2[] = 7 | { 8 | //Alt+Shift等を指定回数送り付け 9 | L"*1", L"*2", L"*3", L"*4", L"*5", L"*6", L"*7", L"*8", L"*9", 10 | //Alt+Shift+0, Alt+Shift+1, ...を送り付け 11 | L"+0", L"+1", L"+2", L"+3", L"+4", L"+5", L"+6", L"+7", L"+8", L"+9", 12 | NULL 13 | }; 14 | 15 | static LPCWSTR defaultWait = L"0"; 16 | 17 | INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 18 | { 19 | HWND hwnd; 20 | size_t i; 21 | WCHAR num[16]; 22 | std::wstring strxmlval; 23 | FILE *fp; 24 | 25 | switch(message) 26 | { 27 | case WM_INITDIALOG: 28 | hwnd = GetDlgItem(hDlg, IDC_COMBO_OTHERIME1); 29 | SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)L"Alt+Shift"); 30 | SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)L"Ctrl+Shift"); 31 | SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)L"Win+Space"); 32 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherIme1, strxmlval); 33 | if(strxmlval == L"Alt+Shift") 34 | { 35 | i = 0; 36 | } 37 | else if(strxmlval == L"Ctrl+Shift") 38 | { 39 | i = 1; 40 | } 41 | else if(strxmlval == L"Win+Space") 42 | { 43 | i = 2; 44 | } 45 | else 46 | { 47 | if (IsVersion62AndOver()) // Windows 8 48 | { 49 | i = 2; //default to "Win+Space" 50 | } 51 | else 52 | { 53 | i = 0; //default to "Alt+Shift" 54 | } 55 | } 56 | SendMessage(hwnd, CB_SETCURSEL, (WPARAM)i, 0); 57 | 58 | hwnd = GetDlgItem(hDlg, IDC_COMBO_OTHERIME2); 59 | for(i = 0; otherime2[i] != NULL; i++) 60 | { 61 | wcsncpy_s(num, _countof(num), otherime2[i], _TRUNCATE); 62 | SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)num); 63 | } 64 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherIme2, strxmlval); 65 | if(strxmlval.size() < 2) 66 | { 67 | i = 0; 68 | } 69 | else 70 | { 71 | for(i = 0; otherime2[i] != NULL; i++) 72 | { 73 | if(strxmlval == otherime2[i]) 74 | { 75 | break; 76 | } 77 | } 78 | if(otherime2[i] == NULL) 79 | { 80 | i = 0; 81 | } 82 | } 83 | SendMessage(hwnd, CB_SETCURSEL, (WPARAM)i, 0); 84 | 85 | ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval); 86 | if(strxmlval.empty()) strxmlval = defaultWait; 87 | SetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, strxmlval.c_str()); 88 | 89 | return TRUE; 90 | 91 | case WM_COMMAND: 92 | switch(LOWORD(wParam)) 93 | { 94 | case IDC_COMBO_OTHERIME1: 95 | case IDC_COMBO_OTHERIME2: 96 | switch(HIWORD(wParam)) 97 | { 98 | case CBN_SELCHANGE: 99 | PropSheet_Changed(GetParent(hDlg), hDlg); 100 | return TRUE; 101 | default: 102 | break; 103 | } 104 | break; 105 | 106 | case IDC_EDIT_OTHERIMEOFFWAIT: 107 | switch(HIWORD(wParam)) 108 | { 109 | case EN_CHANGE: 110 | PropSheet_Changed(GetParent(hDlg), hDlg); 111 | return TRUE; 112 | default: 113 | break; 114 | } 115 | break; 116 | 117 | default: 118 | break; 119 | } 120 | break; 121 | 122 | case WM_NOTIFY: 123 | switch(((LPNMHDR)lParam)->code) 124 | { 125 | case PSN_APPLY: 126 | _wfopen_s(&fp, pathconfigxml, L"ab"); 127 | if(fp != NULL) 128 | { 129 | fclose(fp); 130 | } 131 | SetFileDacl(pathconfigxml); 132 | 133 | WriterInit(pathconfigxml, &pXmlWriter, &pXmlFileStream); 134 | 135 | WriterStartElement(pXmlWriter, TagRoot); 136 | 137 | WriterStartSection(pXmlWriter, SectionBehavior); //Start of SectionBehavior -> End at DlgProcBehavior2 138 | 139 | hwnd = GetDlgItem(hDlg, IDC_COMBO_OTHERIME1); 140 | i = SendMessage(hwnd, CB_GETCURSEL, 0, 0); 141 | WriterKey(pXmlWriter, ValueOtherIme1, 142 | i == 1 ? L"Ctrl+Shift" : 143 | i == 2 ? L"Win+Space" : L"Alt+Shift"); 144 | 145 | hwnd = GetDlgItem(hDlg, IDC_COMBO_OTHERIME2); 146 | i = SendMessage(hwnd, CB_GETCURSEL, 0, 0); 147 | WriterKey(pXmlWriter, ValueOtherIme2, otherime2[i]); 148 | 149 | GetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, num, _countof(num)); 150 | WriterKey(pXmlWriter, ValueOtherImeOffWait, num); 151 | 152 | WriterEndSection(pXmlWriter); //End of SectionBehavior 153 | 154 | return TRUE; 155 | 156 | default: 157 | break; 158 | } 159 | break; 160 | 161 | default: 162 | break; 163 | } 164 | 165 | return FALSE; 166 | } 167 | -------------------------------------------------------------------------------- /imvimcnf/PropertyConfConv.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "configxml.h" 3 | #include "imvimcnf.h" 4 | #include "resource.h" 5 | 6 | TF_PRESERVEDKEY preservedkeynormal[MAX_PRESERVEDKEY]; 7 | TF_PRESERVEDKEY preservedkeyotherime[MAX_PRESERVEDKEY]; 8 | TF_PRESERVEDKEY preservedkeyotherimeoff[MAX_PRESERVEDKEY]; 9 | 10 | static const TF_PRESERVEDKEY defaultpreservedkeynormal[] = 11 | { 12 | { VK_ESCAPE/*0x1B*/, TF_MOD_IGNORE_ALL_MODIFIER } 13 | ,{ 0, 0 } 14 | }; 15 | 16 | static const TF_PRESERVEDKEY defaultpreservedkeyotherime[] = 17 | { 18 | { VK_OEM_3/*0xC0*/, TF_MOD_ALT } 19 | ,{ VK_KANJI/*0x19*/, TF_MOD_IGNORE_ALL_MODIFIER } 20 | ,{ VK_OEM_AUTO/*0xF3*/, TF_MOD_IGNORE_ALL_MODIFIER } 21 | ,{ VK_OEM_ENLW/*0xF4*/, TF_MOD_IGNORE_ALL_MODIFIER } 22 | ,{ 0, 0 } 23 | }; 24 | 25 | static const TF_PRESERVEDKEY defaultpreservedkeyotherimeoff[] = 26 | { 27 | { VK_OEM_ATTN/*VK_DBE_ALPHANUMERIC 0xF0*/, TF_MOD_IGNORE_ALL_MODIFIER } 28 | ,{ 0, 0 } 29 | }; 30 | 31 | static void LoadConfigPreservedKeySub(LPCWSTR SectionPreservedKey, TF_PRESERVEDKEY preservedkey[], const TF_PRESERVEDKEY defaultpreservedkey[]) 32 | { 33 | APPDATAXMLLIST list; 34 | APPDATAXMLLIST::iterator l_itr; 35 | APPDATAXMLROW::iterator r_itr; 36 | int i = 0; 37 | 38 | ZeroMemory(preservedkey, sizeof(TF_PRESERVEDKEY) * MAX_PRESERVEDKEY); 39 | 40 | if(ReadList(pathconfigxml, SectionPreservedKey, list) == S_OK && list.size() != 0) 41 | { 42 | for(l_itr = list.begin(); l_itr != list.end() && i < MAX_PRESERVEDKEY; l_itr++) 43 | { 44 | for(r_itr = l_itr->begin(); r_itr != l_itr->end(); r_itr++) 45 | { 46 | if(r_itr->first == AttributeVKey) 47 | { 48 | preservedkey[i].uVKey = wcstoul(r_itr->second.c_str(), NULL, 0); 49 | } 50 | else if(r_itr->first == AttributeMKey) 51 | { 52 | preservedkey[i].uModifiers = wcstoul(r_itr->second.c_str(), NULL, 0); 53 | if(preservedkey[i].uModifiers == 0) 54 | { 55 | preservedkey[i].uModifiers = TF_MOD_IGNORE_ALL_MODIFIER; 56 | } 57 | } 58 | } 59 | 60 | i++; 61 | } 62 | } 63 | else 64 | { 65 | for(i = 0; defaultpreservedkey[i].uVKey != 0; i++) 66 | { 67 | preservedkey[i] = defaultpreservedkey[i]; 68 | } 69 | } 70 | } 71 | 72 | void LoadConfigPreservedKey() 73 | { 74 | LoadConfigPreservedKeySub(SectionPreservedKeyNormal, preservedkeynormal, defaultpreservedkeynormal); 75 | LoadConfigPreservedKeySub(SectionPreservedKeyOtherIme, preservedkeyotherime, defaultpreservedkeyotherime); 76 | LoadConfigPreservedKeySub(SectionPreservedKeyOtherImeOff, preservedkeyotherimeoff, defaultpreservedkeyotherimeoff); 77 | } 78 | 79 | static void LoadPreservedKeySub(HWND hWndList, const TF_PRESERVEDKEY preservedkey[]) 80 | { 81 | int i; 82 | LVITEMW item; 83 | WCHAR num[8]; 84 | 85 | for(i=0; i 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Resource Files 20 | 21 | 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | 57 | 58 | Resource Files 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /imvimcnf/resource.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef RESOURCE_H 3 | #define RESOURCE_H 4 | 5 | #ifndef IDC_STATIC 6 | #define IDC_STATIC (-1) 7 | #endif 8 | 9 | #define IDD_DIALOG_BEHAVIOR2 112 10 | #define IDD_DIALOG_PRSRVKEY 117 11 | 12 | #define IDC_COMBO_OTHERIME1 1206 13 | #define IDC_COMBO_OTHERIME2 1207 14 | #define IDC_EDIT_OTHERIMEOFFWAIT 1208 15 | 16 | #define IDC_LIST_PRSRVKEY 1701 17 | #define IDC_EDIT_PRSRVKEY_VKEY 1702 18 | #define IDC_CHECKBOX_PRSRVKEY_MKEY_ALT 1703 19 | #define IDC_CHECKBOX_PRSRVKEY_MKEY_CTRL 1704 20 | #define IDC_CHECKBOX_PRSRVKEY_MKEY_SHIFT 1705 21 | #define IDC_BUTTON_PRSRVKEY_UP 1706 22 | #define IDC_BUTTON_PRSRVKEY_DOWN 1707 23 | #define IDC_BUTTON_PRSRVKEY_W 1708 24 | #define IDC_BUTTON_PRSRVKEY_D 1709 25 | #define IDC_LIST_PRSRVKEYOTHERIME 1710 26 | #define IDC_LIST_PRSRVKEYOTHERIMEOFF 1711 27 | #define IDC_COMBO_PRSRVKEY 1712 28 | 29 | #endif //RESOURCE_H 30 | -------------------------------------------------------------------------------- /imvimcnf/stdafx.cpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma comment(linker,"\"/manifestdependency:type='win32' \ 3 | name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ 4 | processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 5 | -------------------------------------------------------------------------------- /imvimcnf/stdafx.h: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | -------------------------------------------------------------------------------- /installer/_clean.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | pushd %~dp0 4 | 5 | del *.7z 6 | del *.msi 7 | del *.wixobj 8 | del *.wixpdb 9 | 10 | popd 11 | -------------------------------------------------------------------------------- /installer/_mkarc.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | pushd %~dp0 4 | 5 | 7z.exe a -tzip tsf-vim.zip tsfvim-x64.msi tsfvim-x86.msi ..\README.TXT ..\README_JA.TXT ..\LICENSE.TXT 6 | 7 | popd 8 | -------------------------------------------------------------------------------- /installer/installer.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Designer 27 | 28 | 29 | Designer 30 | 31 | 32 | 33 | {9DFDE531-8EF0-475B-BA69-5D2768B91187} 34 | Win32Proj 35 | installer 36 | 37 | 38 | 39 | Utility 40 | true 41 | Unicode 42 | Windows7.1SDK 43 | 44 | 45 | Utility 46 | true 47 | Unicode 48 | Windows7.1SDK 49 | 50 | 51 | Utility 52 | false 53 | true 54 | Unicode 55 | Windows7.1SDK 56 | 57 | 58 | Utility 59 | false 60 | true 61 | Unicode 62 | Windows7.1SDK 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | true 82 | $(SolutionDir)$(Platform)\$(Configuration)\ 83 | $(Platform)\$(Configuration)\ 84 | 85 | 86 | true 87 | $(SolutionDir)$(Platform)\$(Configuration)\ 88 | $(Platform)\$(Configuration)\ 89 | 90 | 91 | false 92 | $(SolutionDir)$(Platform)\$(Configuration)\ 93 | $(Platform)\$(Configuration)\ 94 | 95 | 96 | false 97 | $(SolutionDir)$(Platform)\$(Configuration)\ 98 | $(Platform)\$(Configuration)\ 99 | 100 | 101 | 102 | 103 | 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 107 | 108 | 109 | 110 | NotSet 111 | 112 | 113 | 114 | 115 | 116 | 117 | Level3 118 | Disabled 119 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | 121 | 122 | 123 | NotSet 124 | 125 | 126 | 127 | 128 | Level3 129 | 130 | 131 | MaxSpeed 132 | true 133 | true 134 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 135 | 136 | 137 | true 138 | true 139 | true 140 | NotSet 141 | 142 | 143 | "%WIX%bin\candle.exe" -nologo "tsfvim-x86.wxs" 144 | "%WIX%bin\light.exe" -nologo -ext WixUIExtension "tsfvim-x86.wixobj" 145 | 146 | 147 | 148 | 149 | 150 | Level3 151 | 152 | 153 | MaxSpeed 154 | true 155 | true 156 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 157 | 158 | 159 | true 160 | true 161 | true 162 | NotSet 163 | 164 | 165 | "%WIX%bin\candle.exe" -nologo "tsfvim-x64.wxs" 166 | "%WIX%bin\light.exe" -nologo -ext WixUIExtension "tsfvim-x64.wixobj" 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /installer/installer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /installer/installer.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /installer/ms-pl.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Verdana;}} 2 | {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sl240\slmult1\f0\fs16 Microsoft Public License (MS-PL)\par 3 | \par 4 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.\par 5 | \par 6 | 1. Definitions\par 7 | \par 8 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.\par 9 | \par 10 | A "contribution" is the original software, or any additions or changes to the software.\par 11 | \par 12 | A "contributor" is any person that distributes its contribution under this license.\par 13 | \par 14 | "Licensed patents" are a contributor's patent claims that read directly on its contribution.\par 15 | \par 16 | 2. Grant of Rights\par 17 | \par 18 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.\par 19 | \par 20 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.\par 21 | \par 22 | 3. Conditions and Limitations\par 23 | \par 24 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.\par 25 | \par 26 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.\par 27 | \par 28 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.\par 29 | \par 30 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.\par 31 | \par 32 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.\par 33 | \par 34 | } 35 | -------------------------------------------------------------------------------- /installer/tsfvim-x64.wxs: -------------------------------------------------------------------------------- 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 | NEWERFOUND 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /installer/tsfvim-x86.wxs: -------------------------------------------------------------------------------- 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 | NEWERFOUND 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /tsf-vim.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "installer", "installer\installer.vcxproj", "{9DFDE531-8EF0-475B-BA69-5D2768B91187}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {22523C04-5D55-4A25-B228-161A29344DA6} = {22523C04-5D55-4A25-B228-161A29344DA6} 7 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4} = {0D83E604-A285-475A-8FEE-F532A3BD4CF4} 8 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} = {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common\common.vcxproj", "{FBA02FED-84D0-4889-9039-EB0CFB5F26D5}" 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imcrvtip", "imcrvtip\imcrvtip.vcxproj", "{0D83E604-A285-475A-8FEE-F532A3BD4CF4}" 14 | ProjectSection(ProjectDependencies) = postProject 15 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} = {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} 16 | EndProjectSection 17 | EndProject 18 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imvimcnf", "imvimcnf\imvimcnf.vcxproj", "{22523C04-5D55-4A25-B228-161A29344DA6}" 19 | ProjectSection(ProjectDependencies) = postProject 20 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} = {FBA02FED-84D0-4889-9039-EB0CFB5F26D5} 21 | EndProjectSection 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Win32 = Debug|Win32 26 | Debug|x64 = Debug|x64 27 | Release|Win32 = Release|Win32 28 | Release|x64 = Release|x64 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Debug|Win32.ActiveCfg = Debug|Win32 32 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Debug|Win32.Build.0 = Debug|Win32 33 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Debug|x64.ActiveCfg = Debug|x64 34 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Debug|x64.Build.0 = Debug|x64 35 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Release|Win32.ActiveCfg = Release|Win32 36 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Release|Win32.Build.0 = Release|Win32 37 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Release|x64.ActiveCfg = Release|x64 38 | {9DFDE531-8EF0-475B-BA69-5D2768B91187}.Release|x64.Build.0 = Release|x64 39 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Debug|Win32.ActiveCfg = Debug|Win32 40 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Debug|Win32.Build.0 = Debug|Win32 41 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Debug|x64.ActiveCfg = Debug|x64 42 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Debug|x64.Build.0 = Debug|x64 43 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Release|Win32.ActiveCfg = Release|Win32 44 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Release|Win32.Build.0 = Release|Win32 45 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Release|x64.ActiveCfg = Release|x64 46 | {FBA02FED-84D0-4889-9039-EB0CFB5F26D5}.Release|x64.Build.0 = Release|x64 47 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Debug|Win32.ActiveCfg = Debug|Win32 48 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Debug|Win32.Build.0 = Debug|Win32 49 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Debug|x64.ActiveCfg = Debug|x64 50 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Debug|x64.Build.0 = Debug|x64 51 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Release|Win32.ActiveCfg = Release|Win32 52 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Release|Win32.Build.0 = Release|Win32 53 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Release|x64.ActiveCfg = Release|x64 54 | {0D83E604-A285-475A-8FEE-F532A3BD4CF4}.Release|x64.Build.0 = Release|x64 55 | {22523C04-5D55-4A25-B228-161A29344DA6}.Debug|Win32.ActiveCfg = Debug|Win32 56 | {22523C04-5D55-4A25-B228-161A29344DA6}.Debug|Win32.Build.0 = Debug|Win32 57 | {22523C04-5D55-4A25-B228-161A29344DA6}.Debug|x64.ActiveCfg = Debug|x64 58 | {22523C04-5D55-4A25-B228-161A29344DA6}.Debug|x64.Build.0 = Debug|x64 59 | {22523C04-5D55-4A25-B228-161A29344DA6}.Release|Win32.ActiveCfg = Release|Win32 60 | {22523C04-5D55-4A25-B228-161A29344DA6}.Release|Win32.Build.0 = Release|Win32 61 | {22523C04-5D55-4A25-B228-161A29344DA6}.Release|x64.ActiveCfg = Release|x64 62 | {22523C04-5D55-4A25-B228-161A29344DA6}.Release|x64.Build.0 = Release|x64 63 | EndGlobalSection 64 | GlobalSection(SolutionProperties) = preSolution 65 | HideSolutionNode = FALSE 66 | EndGlobalSection 67 | EndGlobal 68 | --------------------------------------------------------------------------------