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 DWORD
enumerate_Cookie(DWORD magic
, DWORD
*index
)
258 for (i
= *index
; i
< id_last
; i
++)
259 if (cookies
[i
].id
!= 0 && cookies
[i
].magic
== magic
)
262 return cookies
[i
].id
;
267 /*************************************************************************
270 BOOL WINAPI
DllMain(HINSTANCE hinst
, DWORD fdwReason
, LPVOID fImpLoad
)
272 TRACE("%p 0x%x %p\n", hinst
, fdwReason
, fImpLoad
);
275 case DLL_WINE_PREATTACH
:
276 return FALSE
; /* prefer native version */
277 case DLL_PROCESS_ATTACH
:
278 MSCTF_hinstance
= hinst
;
279 tlsIndex
= TlsAlloc();
281 case DLL_PROCESS_DETACH
:
288 /*************************************************************************
289 * DllCanUnloadNow (MSCTF.@)
291 HRESULT WINAPI
DllCanUnloadNow(void)
293 return MSCTF_refCount
? S_FALSE
: S_OK
;
296 /***********************************************************************
297 * DllGetClassObject (MSCTF.@)
299 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID iid
, LPVOID
*ppvOut
)
304 if (!IsEqualIID(iid
, &IID_IUnknown
) && !IsEqualIID(iid
, &IID_IClassFactory
))
305 return E_NOINTERFACE
;
307 for (i
= 0; ClassesTable
[i
].clsid
!= NULL
; i
++)
308 if (IsEqualCLSID(ClassesTable
[i
].clsid
, clsid
)) {
309 return ClassFactory_Constructor(ClassesTable
[i
].ctor
, ppvOut
);
311 FIXME("CLSID %s not supported\n", debugstr_guid(clsid
));
312 return CLASS_E_CLASSNOTAVAILABLE
;
315 /***********************************************************************
316 * TF_CreateThreadMgr (MSCTF.@)
318 HRESULT WINAPI
TF_CreateThreadMgr(ITfThreadMgr
**pptim
)
321 return ThreadMgr_Constructor(NULL
,(IUnknown
**)pptim
);
324 /***********************************************************************
325 * TF_GetThreadMgr (MSCTF.@)
327 HRESULT WINAPI
TF_GetThreadMgr(ITfThreadMgr
**pptim
)
330 *pptim
= TlsGetValue(tlsIndex
);
333 ITfThreadMgr_AddRef(*pptim
);
338 /***********************************************************************
339 * SetInputScope(MSCTF.@)
341 HRESULT WINAPI
SetInputScope(HWND hwnd
, INT inputscope
)
343 FIXME("STUB: %p %i\n",hwnd
,inputscope
);
347 /***********************************************************************
348 * SetInputScopes(MSCTF.@)
350 HRESULT WINAPI
SetInputScopes(HWND hwnd
, const INT
*pInputScopes
,
351 UINT cInputScopes
, WCHAR
**ppszPhraseList
,
352 UINT cPhrases
, WCHAR
*pszRegExp
, WCHAR
*pszSRGS
)
355 FIXME("STUB: %p ... %s %s\n",hwnd
, debugstr_w(pszRegExp
), debugstr_w(pszSRGS
));
356 for (i
= 0; i
< cInputScopes
; i
++)
357 TRACE("\tScope[%i] = %i\n",i
,pInputScopes
[i
]);
358 for (i
= 0; i
< cPhrases
; i
++)
359 TRACE("\tPhrase[%i] = %s\n",i
,debugstr_w(ppszPhraseList
[i
]));