d3dx9/tests: Add ID3DXEffect::Get/SetStateManager() test.
[wine] / dlls / hlink / browse_ctx.c
1 /*
2  * Implementation of hyperlinking (hlink.dll)
3  *
4  * Copyright 2005 Aric Stewart for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "hlink_private.h"
22
23 #include "wine/debug.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
26
27 static const IHlinkBrowseContextVtbl hlvt;
28
29 typedef struct
30 {
31     IHlinkBrowseContext IHlinkBrowseContext_iface;
32     LONG        ref;
33     HLBWINFO*   BrowseWindowInfo;
34     IHlink*     CurrentPage;
35 } HlinkBCImpl;
36
37 static inline HlinkBCImpl *impl_from_IHlinkBrowseContext(IHlinkBrowseContext *iface)
38 {
39     return CONTAINING_RECORD(iface, HlinkBCImpl, IHlinkBrowseContext_iface);
40 }
41
42
43 HRESULT WINAPI HLinkBrowseContext_Constructor(IUnknown *pUnkOuter, REFIID riid,
44         LPVOID *ppv)
45 {
46     HlinkBCImpl * hl;
47
48     TRACE("unkOut=%p riid=%s\n", pUnkOuter, debugstr_guid(riid));
49     *ppv = NULL;
50
51     if (pUnkOuter)
52         return CLASS_E_NOAGGREGATION;
53
54     hl = heap_alloc_zero(sizeof(HlinkBCImpl));
55     if (!hl)
56         return E_OUTOFMEMORY;
57
58     hl->ref = 1;
59     hl->IHlinkBrowseContext_iface.lpVtbl = &hlvt;
60
61     *ppv = hl;
62     return S_OK;
63 }
64
65 static HRESULT WINAPI IHlinkBC_fnQueryInterface( IHlinkBrowseContext *iface,
66         REFIID riid, LPVOID* ppvObj)
67 {
68     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
69     TRACE ("(%p)->(%s,%p)\n", This, debugstr_guid (riid), ppvObj);
70
71     if (IsEqualIID(riid, &IID_IUnknown) ||
72         IsEqualIID(riid, &IID_IHlinkBrowseContext))
73         *ppvObj = This;
74
75     if (*ppvObj)
76     {
77         IUnknown_AddRef((IUnknown*)(*ppvObj));
78         return S_OK;
79     }
80     return E_NOINTERFACE;
81 }
82
83 static ULONG WINAPI IHlinkBC_fnAddRef (IHlinkBrowseContext* iface)
84 {
85     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
86     ULONG refCount = InterlockedIncrement(&This->ref);
87
88     TRACE("(%p)->(count=%u)\n", This, refCount - 1);
89
90     return refCount;
91 }
92
93 static ULONG WINAPI IHlinkBC_fnRelease (IHlinkBrowseContext* iface)
94 {
95     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
96     ULONG refCount = InterlockedDecrement(&This->ref);
97
98     TRACE("(%p)->(count=%u)\n", This, refCount + 1);
99     if (refCount)
100         return refCount;
101
102     TRACE("-- destroying IHlinkBrowseContext (%p)\n", This);
103     heap_free(This->BrowseWindowInfo);
104     if (This->CurrentPage)
105         IHlink_Release(This->CurrentPage);
106     heap_free(This);
107     return 0;
108 }
109
110 static HRESULT WINAPI IHlinkBC_Register(IHlinkBrowseContext* iface,
111         DWORD dwReserved, IUnknown *piunk, IMoniker *pimk, DWORD *pdwRegister)
112 {
113     static const WCHAR szIdent[] = {'W','I','N','E','H','L','I','N','K',0};
114     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
115     IMoniker *mon;
116     IMoniker *composite;
117     IRunningObjectTable *ROT;
118
119     FIXME("(%p)->(%i %p %p %p)\n", This, dwReserved, piunk, pimk, pdwRegister);
120
121     CreateItemMoniker(NULL, szIdent, &mon);
122     CreateGenericComposite(mon, pimk, &composite);
123
124     GetRunningObjectTable(0, &ROT);
125     IRunningObjectTable_Register(ROT, 0, piunk, composite, pdwRegister);
126
127     IRunningObjectTable_Release(ROT);
128     IMoniker_Release(composite);
129     IMoniker_Release(mon);
130
131     return S_OK;
132 }
133
134 static HRESULT WINAPI IHlinkBC_GetObject(IHlinkBrowseContext* face,
135         IMoniker *pimk, BOOL fBindifRootRegistered, IUnknown **ppiunk)
136 {
137     FIXME("\n");
138     return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI IHlinkBC_Revoke(IHlinkBrowseContext* iface,
142         DWORD dwRegister)
143 {
144     HRESULT r = S_OK;
145     IRunningObjectTable *ROT;
146     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
147
148     FIXME("(%p)->(%i)\n", This, dwRegister);
149
150     GetRunningObjectTable(0, &ROT);
151     r = IRunningObjectTable_Revoke(ROT, dwRegister);
152     IRunningObjectTable_Release(ROT);
153
154     return r;
155 }
156
157 static HRESULT WINAPI IHlinkBC_SetBrowseWindowInfo(IHlinkBrowseContext* iface,
158         HLBWINFO *phlbwi)
159 {
160     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
161     TRACE("(%p)->(%p)\n", This, phlbwi);
162
163     if(!phlbwi)
164         return E_INVALIDARG;
165
166     heap_free(This->BrowseWindowInfo);
167     This->BrowseWindowInfo = heap_alloc(phlbwi->cbSize);
168     memcpy(This->BrowseWindowInfo, phlbwi, phlbwi->cbSize);
169
170     return S_OK;
171 }
172
173 static HRESULT WINAPI IHlinkBC_GetBrowseWindowInfo(IHlinkBrowseContext* iface,
174         HLBWINFO *phlbwi)
175 {
176     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
177     TRACE("(%p)->(%p)\n", This, phlbwi);
178
179     if(!phlbwi)
180         return E_INVALIDARG;
181
182     if(!This->BrowseWindowInfo)
183         phlbwi->cbSize = 0;
184     else
185         memcpy(phlbwi, This->BrowseWindowInfo, This->BrowseWindowInfo->cbSize);
186
187     return S_OK;
188 }
189
190 static HRESULT WINAPI IHlinkBC_SetInitialHlink(IHlinkBrowseContext* iface,
191         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
192 {
193     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
194
195     FIXME("(%p)->(%p %s %s)\n", This, pimkTarget,
196             debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName));
197
198     if (This->CurrentPage)
199         IHlink_Release(This->CurrentPage);
200
201     HlinkCreateFromMoniker(pimkTarget, pwzLocation, pwzFriendlyName, NULL,
202             0, NULL, &IID_IHlink, (LPVOID*) &This->CurrentPage);
203
204     return S_OK;
205 }
206
207 static HRESULT WINAPI IHlinkBC_OnNavigateHlink(IHlinkBrowseContext *iface,
208         DWORD grfHLNF, IMoniker* pmkTarget, LPCWSTR pwzLocation, LPCWSTR
209         pwzFriendlyName, ULONG *puHLID)
210 {
211     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
212
213     FIXME("(%p)->(%i %p %s %s %p)\n", This, grfHLNF, pmkTarget,
214             debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), puHLID);
215
216     return S_OK;
217 }
218
219 static HRESULT WINAPI IHlinkBC_UpdateHlink(IHlinkBrowseContext* iface,
220         ULONG uHLID, IMoniker* pimkTarget, LPCWSTR pwzLocation,
221         LPCWSTR pwzFriendlyName)
222 {
223     FIXME("\n");
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI IHlinkBC_EnumNavigationStack( IHlinkBrowseContext *iface,
228         DWORD dwReserved, DWORD grfHLFNAMEF, IEnumHLITEM** ppienumhlitem)
229 {
230     FIXME("\n");
231     return E_NOTIMPL;
232 }
233
234 static HRESULT WINAPI IHlinkBC_QueryHlink( IHlinkBrowseContext* iface,
235         DWORD grfHLONG, ULONG uHLID)
236 {
237     FIXME("\n");
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI IHlinkBC_GetHlink( IHlinkBrowseContext* iface,
242         ULONG uHLID, IHlink** ppihl)
243 {
244     HlinkBCImpl  *This = impl_from_IHlinkBrowseContext(iface);
245
246     TRACE("(%p)->(%x %p)\n", This, uHLID, ppihl);
247
248     if(uHLID != HLID_CURRENT) {
249         FIXME("Only HLID_CURRENT implemented, given: %x\n", uHLID);
250         return E_NOTIMPL;
251     }
252
253     *ppihl = This->CurrentPage;
254     IHlink_AddRef(*ppihl);
255
256     return S_OK;
257 }
258
259 static HRESULT WINAPI IHlinkBC_SetCurrentHlink( IHlinkBrowseContext* iface,
260         ULONG uHLID)
261 {
262     FIXME("\n");
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI IHlinkBC_Clone( IHlinkBrowseContext* iface,
267         IUnknown* piunkOuter, REFIID riid, IUnknown** ppiunkOjb)
268 {
269     FIXME("\n");
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI IHlinkBC_Close(IHlinkBrowseContext* iface,
274         DWORD reserverd)
275 {
276     FIXME("\n");
277     return E_NOTIMPL;
278 }
279
280 static const IHlinkBrowseContextVtbl hlvt =
281 {
282     IHlinkBC_fnQueryInterface,
283     IHlinkBC_fnAddRef,
284     IHlinkBC_fnRelease,
285     IHlinkBC_Register,
286     IHlinkBC_GetObject,
287     IHlinkBC_Revoke,
288     IHlinkBC_SetBrowseWindowInfo,
289     IHlinkBC_GetBrowseWindowInfo,
290     IHlinkBC_SetInitialHlink,
291     IHlinkBC_OnNavigateHlink,
292     IHlinkBC_UpdateHlink,
293     IHlinkBC_EnumNavigationStack,
294     IHlinkBC_QueryHlink,
295     IHlinkBC_GetHlink,
296     IHlinkBC_SetCurrentHlink,
297     IHlinkBC_Clone,
298     IHlinkBC_Close
299 };