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