mshtml: Win64 printf format warning fixes.
[wine] / dlls / mshtml / hlink.c
1 /*
2  * Copyright 2005-2006 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17
18 #include "config.h"
19
20 #include <stdarg.h>
21 #include <stdio.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 #include "mshtml_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 /**********************************************************
38  * IHlinkTarget implementation
39  */
40
41 #define HLINKTRG_THIS(iface) DEFINE_THIS(HTMLDocument, HlinkTarget, iface)
42
43 static HRESULT WINAPI HlinkTarget_QueryInterface(IHlinkTarget *iface, REFIID riid, void **ppv)
44 {
45     HTMLDocument *This = HLINKTRG_THIS(iface);
46     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
47 }
48
49 static ULONG WINAPI HlinkTarget_AddRef(IHlinkTarget *iface)
50 {
51     HTMLDocument *This = HLINKTRG_THIS(iface);
52     return IHTMLDocument2_AddRef(HTMLDOC(This));
53 }
54
55 static ULONG WINAPI HlinkTarget_Release(IHlinkTarget *iface)
56 {
57     HTMLDocument *This = HLINKTRG_THIS(iface);
58     return IHTMLDocument2_Release(HTMLDOC(This));
59 }
60
61 static HRESULT WINAPI HlinkTarget_SetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext *pihlbc)
62 {
63     HTMLDocument *This = HLINKTRG_THIS(iface);
64     FIXME("(%p)->(%p)\n", This, pihlbc);
65     return E_NOTIMPL;
66 }
67
68 static HRESULT WINAPI HlinkTarget_GetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext **ppihlbc)
69 {
70     HTMLDocument *This = HLINKTRG_THIS(iface);
71     FIXME("(%p)->(%p)\n", This, ppihlbc);
72     return E_NOTIMPL;
73 }
74
75 static HRESULT WINAPI HlinkTarget_Navigate(IHlinkTarget *iface, DWORD grfHLNF, LPCWSTR pwzJumpLocation)
76 {
77     HTMLDocument *This = HLINKTRG_THIS(iface);
78
79     TRACE("(%p)->(%08x %s)\n", This, grfHLNF, debugstr_w(pwzJumpLocation));
80
81     if(grfHLNF)
82         FIXME("Unsupported grfHLNF=%08x\n", grfHLNF);
83     if(pwzJumpLocation)
84         FIXME("JumpLocation not supported\n");
85
86     return IOleObject_DoVerb(OLEOBJ(This), OLEIVERB_SHOW, NULL, NULL, -1, NULL, NULL);
87 }
88
89 static HRESULT WINAPI HlinkTarget_GetMoniker(IHlinkTarget *iface, LPCWSTR pwzLocation, DWORD dwAssign,
90         IMoniker **ppimkLocation)
91 {
92     HTMLDocument *This = HLINKTRG_THIS(iface);
93     FIXME("(%p)->(%s %08x %p)\n", This, debugstr_w(pwzLocation), dwAssign, ppimkLocation);
94     return E_NOTIMPL;
95 }
96
97 static HRESULT WINAPI HlinkTarget_GetFriendlyName(IHlinkTarget *iface, LPCWSTR pwzLocation,
98         LPWSTR *ppwzFriendlyName)
99 {
100     HTMLDocument *This = HLINKTRG_THIS(iface);
101     FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwzLocation), ppwzFriendlyName);
102     return E_NOTIMPL;
103 }
104
105 static const IHlinkTargetVtbl HlinkTargetVtbl = {
106     HlinkTarget_QueryInterface,
107     HlinkTarget_AddRef,
108     HlinkTarget_Release,
109     HlinkTarget_SetBrowseContext,
110     HlinkTarget_GetBrowseContext,
111     HlinkTarget_Navigate,
112     HlinkTarget_GetMoniker,
113     HlinkTarget_GetFriendlyName
114 };
115
116 void HTMLDocument_Hlink_Init(HTMLDocument *This)
117 {
118     This->lpHlinkTargetVtbl = &HlinkTargetVtbl;
119 }
120
121 typedef struct {
122     const IHlinkVtbl  *lpHlinkVtbl;
123
124     LONG ref;
125
126     IMoniker *mon;
127     LPWSTR location;
128 } Hlink;
129
130 #define HLINK(x)  ((IHlink*)  &(x)->lpHlinkVtbl)
131
132 #define HLINK_THIS(iface) DEFINE_THIS(Hlink, Hlink, iface)
133
134 static HRESULT WINAPI Hlink_QueryInterface(IHlink *iface, REFIID riid, void **ppv)
135 {
136     Hlink *This = HLINK_THIS(iface);
137
138     *ppv = NULL;
139
140     if(IsEqualGUID(&IID_IUnknown, riid)) {
141         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
142         *ppv = HLINK(This);
143     }else if(IsEqualGUID(&IID_IHlink, riid)) {
144         TRACE("(%p)->(IID_IHlink %p)\n", This, ppv);
145         *ppv = HLINK(This);
146     }
147
148     if(*ppv) {
149         IHlink_AddRef(HLINK(This));
150         return S_OK;
151     }
152
153     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
154     return E_NOINTERFACE;
155 }
156
157 static ULONG WINAPI Hlink_AddRef(IHlink *iface)
158 {
159     Hlink *This = HLINK_THIS(iface);
160     LONG ref = InterlockedIncrement(&This->ref);
161
162     TRACE("(%p) ref=%d\n", This, ref);
163
164     return ref;
165 }
166
167 static ULONG WINAPI Hlink_Release(IHlink *iface)
168 {
169     Hlink *This = HLINK_THIS(iface);
170     LONG ref = InterlockedDecrement(&This->ref);
171
172     TRACE("(%p) ref=%d\n", This, ref);
173
174     if(!ref) {
175         if(This->mon)
176             IMoniker_Release(This->mon);
177         mshtml_free(This->location);
178         mshtml_free(This);
179     }
180
181     return ref;
182 }
183
184 static HRESULT WINAPI Hlink_SetHlinkSite(IHlink *iface, IHlinkSite *pihlSite, DWORD dwSiteData)
185 {
186     Hlink *This = HLINK_THIS(iface);
187     FIXME("(%p)->(%p %d)\n", This, pihlSite, dwSiteData);
188     return E_NOTIMPL;
189 }
190
191 static HRESULT WINAPI Hlink_GetHlinkSite(IHlink *iface, IHlinkSite **ppihlSite,
192                                          DWORD *pdwSiteData)
193 {
194     Hlink *This = HLINK_THIS(iface);
195
196     TRACE("(%p)->(%p %p)\n", This, ppihlSite, pdwSiteData);
197
198     *ppihlSite = NULL;
199     return S_OK;
200 }
201
202 static HRESULT WINAPI Hlink_SetMonikerReference(IHlink *iface, DWORD grfHLSETF,
203                                                 IMoniker *pimkTarget, LPCWSTR pwzLocation)
204 {
205     Hlink *This = HLINK_THIS(iface);
206
207     TRACE("(%p)->(%08x %p %s)\n", This, grfHLSETF, pimkTarget, debugstr_w(pwzLocation));
208
209     if(grfHLSETF)
210         FIXME("unsupported grfHLSETF=%08x\n", grfHLSETF);
211
212     if(This->mon)
213         IMoniker_Release(This->mon);
214     mshtml_free(This->location);
215
216     if(pimkTarget)
217         IMoniker_AddRef(pimkTarget);
218     This->mon = pimkTarget;
219
220     if(pwzLocation) {
221         DWORD len = strlenW(pwzLocation)+1;
222
223         This->location = mshtml_alloc(len*sizeof(WCHAR));
224         memcpy(This->location, pwzLocation, len*sizeof(WCHAR));
225     }else {
226         This->location = NULL;
227     }
228
229     return S_OK;
230 }
231
232 static HRESULT WINAPI Hlink_GetMonikerReference(IHlink *iface, DWORD dwWhichRef,
233                                                 IMoniker **ppimkTarget, LPWSTR *ppwzLocation)
234 {
235     Hlink *This = HLINK_THIS(iface);
236
237     TRACE("(%p)->(%d %p %p)\n", This, dwWhichRef, ppimkTarget, ppwzLocation);
238
239     if(dwWhichRef != 1)
240         FIXME("upsupported dwWhichRef = %d\n", dwWhichRef);
241
242     if(This->mon)
243         IMoniker_AddRef(This->mon);
244     *ppimkTarget = This->mon;
245
246     if(This->location) {
247         DWORD len = strlenW(This->location)+1;
248
249         *ppwzLocation = CoTaskMemAlloc(len*sizeof(WCHAR));
250         memcpy(*ppwzLocation, This->location, len*sizeof(WCHAR));
251     }else {
252         *ppwzLocation = NULL;
253     }
254
255     return S_OK;
256 }
257
258 static HRESULT WINAPI Hlink_SetStringReference(IHlink *iface, DWORD grfHLSETF,
259                                                LPCWSTR pwzTarget, LPCWSTR pwzLocation)
260 {
261     Hlink *This = HLINK_THIS(iface);
262     FIXME("(%p)->(%08x %s %s)\n", This, grfHLSETF, debugstr_w(pwzTarget),
263           debugstr_w(pwzLocation));
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI Hlink_GetStringReference(IHlink *iface, DWORD dwWhichRef,
268                                                LPWSTR *ppwzTarget, LPWSTR *ppwzLocation)
269 {
270     Hlink *This = HLINK_THIS(iface);
271     FIXME("(%p)->(%d %p %p)\n", This, dwWhichRef, ppwzTarget, ppwzLocation);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI Hlink_SetFriendlyName(IHlink *iface, LPCWSTR pwzFriendlyName)
276 {
277     Hlink *This = HLINK_THIS(iface);
278     FIXME("(%p)->(%s)\n", This, debugstr_w(pwzFriendlyName));
279     return E_NOTIMPL;
280 }
281
282 static HRESULT WINAPI Hlink_GetFriendlyName(IHlink *iface, DWORD grfHLNAMEF,
283                                             LPWSTR *ppwzFriendlyName)
284 {
285     Hlink *This = HLINK_THIS(iface);
286
287     TRACE("(%p)->(%08x %p)\n", This, grfHLNAMEF, ppwzFriendlyName);
288
289     *ppwzFriendlyName = NULL;
290     return S_FALSE;
291 }
292
293 static HRESULT WINAPI Hlink_SetTargetFrameName(IHlink *iface, LPCWSTR pwzTargetFrameName)
294 {
295     Hlink *This = HLINK_THIS(iface);
296     FIXME("(%p)->(%s)\n", This, debugstr_w(pwzTargetFrameName));
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI Hlink_GetTargetFrameName(IHlink *iface, LPWSTR *ppwzTargetFrameName)
301 {
302     Hlink *This = HLINK_THIS(iface);
303
304     TRACE("(%p)->(%p)\n", This, ppwzTargetFrameName);
305
306     *ppwzTargetFrameName = NULL;
307     return S_FALSE;
308 }
309
310 static HRESULT WINAPI Hlink_GetMiscStatus(IHlink *iface, DWORD *pdwStatus)
311 {
312     Hlink *This = HLINK_THIS(iface);
313     FIXME("(%p)->(%p)\n", This, pdwStatus);
314     return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI Hlink_Navigate(IHlink *iface, DWORD grfHLNF, LPBC pibc,
318         IBindStatusCallback *pibsc, IHlinkBrowseContext *pihlbc)
319 {
320     Hlink *This = HLINK_THIS(iface);
321     FIXME("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pibc, pibsc, pihlbc);
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI Hlink_SetAdditionalParams(IHlink *iface, LPCWSTR pwzAdditionalParams)
326 {
327     Hlink *This = HLINK_THIS(iface);
328     FIXME("(%p)->(%s)\n", This, debugstr_w(pwzAdditionalParams));
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI Hlink_GetAdditionalParams(IHlink *iface, LPWSTR *ppwzAdditionalParams)
333 {
334     Hlink *This = HLINK_THIS(iface);
335     FIXME("(%p)->(%p)\n", This, ppwzAdditionalParams);
336     return E_NOTIMPL;
337 }
338
339 #undef HLINK_THIS
340
341 static const IHlinkVtbl HlinkVtbl = {
342     Hlink_QueryInterface,
343     Hlink_AddRef,
344     Hlink_Release,
345     Hlink_SetHlinkSite,
346     Hlink_GetHlinkSite,
347     Hlink_SetMonikerReference,
348     Hlink_GetMonikerReference,
349     Hlink_SetStringReference,
350     Hlink_GetStringReference,
351     Hlink_SetFriendlyName,
352     Hlink_GetFriendlyName,
353     Hlink_SetTargetFrameName,
354     Hlink_GetTargetFrameName,
355     Hlink_GetMiscStatus,
356     Hlink_Navigate,
357     Hlink_SetAdditionalParams,
358     Hlink_GetAdditionalParams
359 };
360
361 IHlink *Hlink_Create(void)
362 {
363     Hlink *ret = mshtml_alloc(sizeof(Hlink));
364
365     ret->lpHlinkVtbl = &HlinkVtbl;
366     ret->ref = 1;
367     ret->mon = NULL;
368     ret->location = NULL;
369
370     return HLINK(ret);
371 }