4 * Copyright 2008 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
38 #include "msctf_internal.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
42 static LONG MSCTF_refCount;
44 static HINSTANCE MSCTF_hinstance;
48 const WCHAR szwSystemTIPKey[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','C','T','F','\\','T','I','P',0};
50 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
56 {&CLSID_TF_ThreadMgr, ThreadMgr_Constructor},
57 {&CLSID_TF_InputProcessorProfiles, InputProcessorProfiles_Constructor},
58 {&CLSID_TF_CategoryMgr, CategoryMgr_Constructor},
62 typedef struct tagClassFactory
64 const IClassFactoryVtbl *vtbl;
69 static void ClassFactory_Destructor(ClassFactory *This)
71 TRACE("Destroying class factory %p\n", This);
72 HeapFree(GetProcessHeap(),0,This);
76 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
79 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
80 IClassFactory_AddRef(iface);
85 WARN("Unknown interface %s\n", debugstr_guid(riid));
89 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
91 ClassFactory *This = (ClassFactory *)iface;
92 return InterlockedIncrement(&This->ref);
95 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
97 ClassFactory *This = (ClassFactory *)iface;
98 ULONG ret = InterlockedDecrement(&This->ref);
101 ClassFactory_Destructor(This);
105 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
107 ClassFactory *This = (ClassFactory *)iface;
111 TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
112 ret = This->ctor(punkOuter, &obj);
115 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
116 IUnknown_Release(obj);
120 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
122 ClassFactory *This = (ClassFactory *)iface;
124 TRACE("(%p)->(%x)\n", This, fLock);
127 InterlockedIncrement(&MSCTF_refCount);
129 InterlockedDecrement(&MSCTF_refCount);
134 static const IClassFactoryVtbl ClassFactoryVtbl = {
136 ClassFactory_QueryInterface,
138 ClassFactory_Release,
141 ClassFactory_CreateInstance,
142 ClassFactory_LockServer
145 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
147 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
148 This->vtbl = &ClassFactoryVtbl;
151 *ppvOut = (LPVOID)This;
152 TRACE("Created class factory %p\n", This);
157 /*************************************************************************
160 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
162 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
165 case DLL_WINE_PREATTACH:
166 return FALSE; /* prefer native version */
167 case DLL_PROCESS_ATTACH:
168 MSCTF_hinstance = hinst;
169 tlsIndex = TlsAlloc();
171 case DLL_PROCESS_DETACH:
178 /*************************************************************************
179 * DllCanUnloadNow (MSCTF.@)
181 HRESULT WINAPI DllCanUnloadNow(void)
183 return MSCTF_refCount ? S_FALSE : S_OK;
186 /***********************************************************************
187 * DllGetClassObject (MSCTF.@)
189 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
194 if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
195 return E_NOINTERFACE;
197 for (i = 0; ClassesTable[i].clsid != NULL; i++)
198 if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
199 return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
201 FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
202 return CLASS_E_CLASSNOTAVAILABLE;
205 /***********************************************************************
206 * TF_CreateThreadMgr (MSCTF.@)
208 HRESULT WINAPI TF_CreateThreadMgr(ITfThreadMgr **pptim)
211 return ThreadMgr_Constructor(NULL,(IUnknown**)pptim);
214 /***********************************************************************
215 * TF_GetThreadMgr (MSCTF.@)
217 HRESULT WINAPI TF_GetThreadMgr(ITfThreadMgr **pptim)
220 *pptim = (ITfThreadMgr*)TlsGetValue(tlsIndex);
223 ITfThreadMgr_AddRef(*pptim);
228 /***********************************************************************
229 * SetInputScope(MSCTF.@)
231 HRESULT WINAPI SetInputScope(HWND hwnd, INT inputscope)
233 FIXME("STUB: %p %i\n",hwnd,inputscope);
237 /***********************************************************************
238 * SetInputScopes(MSCTF.@)
240 HRESULT WINAPI SetInputScopes(HWND hwnd, const INT *pInputScopes,
241 UINT cInputScopes, WCHAR **ppszPhraseList,
242 UINT cPhrases, WCHAR *pszRegExp, WCHAR *pszSRGS)
245 FIXME("STUB: %p ... %s %s\n",hwnd, debugstr_w(pszRegExp), debugstr_w(pszSRGS));
246 for (i = 0; i < cInputScopes; i++)
247 TRACE("\tScope[%i] = %i\n",i,pInputScopes[i]);
248 for (i = 0; i < cPhrases; i++)
249 TRACE("\tPhrase[%i] = %s\n",i,debugstr_w(ppszPhraseList[i]));