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
;
53 static CookieInternal
*cookies
;
55 static UINT array_size
;
59 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};
61 typedef HRESULT (*LPFNCONSTRUCTOR
)(IUnknown
*pUnkOuter
, IUnknown
**ppvOut
);
67 {&CLSID_TF_ThreadMgr
, ThreadMgr_Constructor
},
68 {&CLSID_TF_InputProcessorProfiles
, InputProcessorProfiles_Constructor
},
69 {&CLSID_TF_CategoryMgr
, CategoryMgr_Constructor
},
73 typedef struct tagClassFactory
75 const IClassFactoryVtbl
*vtbl
;
80 static void ClassFactory_Destructor(ClassFactory
*This
)
82 TRACE("Destroying class factory %p\n", This
);
83 HeapFree(GetProcessHeap(),0,This
);
87 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppvOut
)
90 if (IsEqualIID(riid
, &IID_IClassFactory
) || IsEqualIID(riid
, &IID_IUnknown
)) {
91 IClassFactory_AddRef(iface
);
96 WARN("Unknown interface %s\n", debugstr_guid(riid
));
100 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
102 ClassFactory
*This
= (ClassFactory
*)iface
;
103 return InterlockedIncrement(&This
->ref
);
106 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
108 ClassFactory
*This
= (ClassFactory
*)iface
;
109 ULONG ret
= InterlockedDecrement(&This
->ref
);
112 ClassFactory_Destructor(This
);
116 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID iid
, LPVOID
*ppvOut
)
118 ClassFactory
*This
= (ClassFactory
*)iface
;
122 TRACE("(%p, %p, %s, %p)\n", iface
, punkOuter
, debugstr_guid(iid
), ppvOut
);
123 ret
= This
->ctor(punkOuter
, &obj
);
126 ret
= IUnknown_QueryInterface(obj
, iid
, ppvOut
);
127 IUnknown_Release(obj
);
131 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
133 ClassFactory
*This
= (ClassFactory
*)iface
;
135 TRACE("(%p)->(%x)\n", This
, fLock
);
138 InterlockedIncrement(&MSCTF_refCount
);
140 InterlockedDecrement(&MSCTF_refCount
);
145 static const IClassFactoryVtbl ClassFactoryVtbl
= {
147 ClassFactory_QueryInterface
,
149 ClassFactory_Release
,
152 ClassFactory_CreateInstance
,
153 ClassFactory_LockServer
156 static HRESULT
ClassFactory_Constructor(LPFNCONSTRUCTOR ctor
, LPVOID
*ppvOut
)
158 ClassFactory
*This
= HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory
));
159 This
->vtbl
= &ClassFactoryVtbl
;
163 TRACE("Created class factory %p\n", This
);
168 /*************************************************************************
169 * DWORD Cookie Management
171 DWORD
generate_Cookie(DWORD magic
, LPVOID data
)
175 /* try to reuse IDs if possible */
176 for (i
= 0; i
< id_last
; i
++)
177 if (cookies
[i
].id
== 0) break;
183 cookies
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(CookieInternal
) * 10);
186 ERR("Out of memory, Unable to alloc cookies array\n");
193 CookieInternal
*new_cookies
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cookies
,
194 sizeof(CookieInternal
) * (array_size
* 2));
197 ERR("Out of memory, Unable to realloc cookies array\n");
200 cookies
= new_cookies
;
205 cookies
[i
].id
= i
+ 1; /* a return of 0 is used for failure */
206 cookies
[i
].magic
= magic
;
207 cookies
[i
].data
= data
;
212 return cookies
[i
].id
;
215 DWORD
get_Cookie_magic(DWORD id
)
219 if (index
>= id_last
)
222 if (cookies
[index
].id
== 0)
225 return cookies
[index
].magic
;
228 LPVOID
get_Cookie_data(DWORD id
)
232 if (index
>= id_last
)
235 if (cookies
[index
].id
== 0)
238 return cookies
[index
].data
;
241 LPVOID
remove_Cookie(DWORD id
)
245 if (index
>= id_last
)
248 if (cookies
[index
].id
== 0)
251 cookies
[index
].id
= 0;
252 return cookies
[index
].data
;
255 /*************************************************************************
258 BOOL WINAPI
DllMain(HINSTANCE hinst
, DWORD fdwReason
, LPVOID fImpLoad
)
260 TRACE("%p 0x%x %p\n", hinst
, fdwReason
, fImpLoad
);
263 case DLL_WINE_PREATTACH
:
264 return FALSE
; /* prefer native version */
265 case DLL_PROCESS_ATTACH
:
266 MSCTF_hinstance
= hinst
;
267 tlsIndex
= TlsAlloc();
269 case DLL_PROCESS_DETACH
:
276 /*************************************************************************
277 * DllCanUnloadNow (MSCTF.@)
279 HRESULT WINAPI
DllCanUnloadNow(void)
281 return MSCTF_refCount
? S_FALSE
: S_OK
;
284 /***********************************************************************
285 * DllGetClassObject (MSCTF.@)
287 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID iid
, LPVOID
*ppvOut
)
292 if (!IsEqualIID(iid
, &IID_IUnknown
) && !IsEqualIID(iid
, &IID_IClassFactory
))
293 return E_NOINTERFACE
;
295 for (i
= 0; ClassesTable
[i
].clsid
!= NULL
; i
++)
296 if (IsEqualCLSID(ClassesTable
[i
].clsid
, clsid
)) {
297 return ClassFactory_Constructor(ClassesTable
[i
].ctor
, ppvOut
);
299 FIXME("CLSID %s not supported\n", debugstr_guid(clsid
));
300 return CLASS_E_CLASSNOTAVAILABLE
;
303 /***********************************************************************
304 * TF_CreateThreadMgr (MSCTF.@)
306 HRESULT WINAPI
TF_CreateThreadMgr(ITfThreadMgr
**pptim
)
309 return ThreadMgr_Constructor(NULL
,(IUnknown
**)pptim
);
312 /***********************************************************************
313 * TF_GetThreadMgr (MSCTF.@)
315 HRESULT WINAPI
TF_GetThreadMgr(ITfThreadMgr
**pptim
)
318 *pptim
= TlsGetValue(tlsIndex
);
321 ITfThreadMgr_AddRef(*pptim
);
326 /***********************************************************************
327 * SetInputScope(MSCTF.@)
329 HRESULT WINAPI
SetInputScope(HWND hwnd
, INT inputscope
)
331 FIXME("STUB: %p %i\n",hwnd
,inputscope
);
335 /***********************************************************************
336 * SetInputScopes(MSCTF.@)
338 HRESULT WINAPI
SetInputScopes(HWND hwnd
, const INT
*pInputScopes
,
339 UINT cInputScopes
, WCHAR
**ppszPhraseList
,
340 UINT cPhrases
, WCHAR
*pszRegExp
, WCHAR
*pszSRGS
)
343 FIXME("STUB: %p ... %s %s\n",hwnd
, debugstr_w(pszRegExp
), debugstr_w(pszSRGS
));
344 for (i
= 0; i
< cInputScopes
; i
++)
345 TRACE("\tScope[%i] = %i\n",i
,pInputScopes
[i
]);
346 for (i
= 0; i
< cPhrases
; i
++)
347 TRACE("\tPhrase[%i] = %s\n",i
,debugstr_w(ppszPhraseList
[i
]));