advapi32: Explicitly initialize nested array element.
[wine] / dlls / mshtml / selection.c
1 /*
2  * Copyright 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  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34
35 #include "mshtml_private.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 typedef struct {
40     const IHTMLSelectionObjectVtbl *lpHTMLSelectionObjectVtbl;
41
42     LONG ref;
43
44     nsISelection *nsselection;
45 } HTMLSelectionObject;
46
47 #define HTMLSELOBJ(x)  ((IHTMLSelectionObject*) &(x)->lpHTMLSelectionObjectVtbl)
48
49 #define HTMLSELOBJ_THIS(iface) DEFINE_THIS(HTMLSelectionObject, HTMLSelectionObject, iface)
50
51 static HRESULT WINAPI HTMLSelectionObject_QueryInterface(IHTMLSelectionObject *iface,
52                                                          REFIID riid, void **ppv)
53 {
54     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
55
56     *ppv = NULL;
57
58     if(IsEqualGUID(&IID_IUnknown, riid)) {
59         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60         *ppv = HTMLSELOBJ(This);
61     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
62         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
63         *ppv = HTMLSELOBJ(This);
64     }else if(IsEqualGUID(&IID_IHTMLSelectionObject, riid)) {
65         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
66         *ppv = HTMLSELOBJ(This);
67     }
68
69     if(*ppv) {
70         IUnknown_AddRef((IUnknown*)*ppv);
71         return S_OK;
72     }
73
74     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
75     return E_NOINTERFACE;
76 }
77
78 static ULONG WINAPI HTMLSelectionObject_AddRef(IHTMLSelectionObject *iface)
79 {
80     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
81     LONG ref = InterlockedIncrement(&This->ref);
82
83     TRACE("(%p) ref=%d\n", This, ref);
84
85     return ref;
86 }
87
88 static ULONG WINAPI HTMLSelectionObject_Release(IHTMLSelectionObject *iface)
89 {
90     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
91     LONG ref = InterlockedDecrement(&This->ref);
92
93     TRACE("(%p) ref=%d\n", This, ref);
94
95     if(!ref) {
96         if(This->nsselection)
97             nsISelection_Release(This->nsselection);
98         mshtml_free(This);
99     }
100
101     return ref;
102 }
103
104 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfoCount(IHTMLSelectionObject *iface, UINT *pctinfo)
105 {
106     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
107     FIXME("(%p)->(%p)\n", This, pctinfo);
108     return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI HTMLSelectionObject_GetTypeInfo(IHTMLSelectionObject *iface, UINT iTInfo,
112                                               LCID lcid, ITypeInfo **ppTInfo)
113 {
114     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
115     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI HTMLSelectionObject_GetIDsOfNames(IHTMLSelectionObject *iface, REFIID riid,
120                                                 LPOLESTR *rgszNames, UINT cNames,
121                                                 LCID lcid, DISPID *rgDispId)
122 {
123     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
124     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
125           lcid, rgDispId);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DISPID dispIdMember,
130                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
131                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
132 {
133     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
134     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
135           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
136     return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
140 {
141     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
142
143     TRACE("(%p)->(%p)\n", This, range);
144
145     *range = (IDispatch*)HTMLTxtRange_Create(This->nsselection);
146     return S_OK;
147 }
148
149 static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface)
150 {
151     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
152     FIXME("(%p)\n", This);
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI HTMLSelectionObject_clear(IHTMLSelectionObject *iface)
157 {
158     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
159     FIXME("(%p)\n", This);
160     return E_NOTIMPL;
161 }
162
163 static HRESULT WINAPI HTMLSelectionObject_get_type(IHTMLSelectionObject *iface, BSTR *p)
164 {
165     HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
166     PRInt32 range_cnt = 0;
167
168     static const WCHAR wszNone[] = {'N','o','n','e',0};
169     static const WCHAR wszText[] = {'T','e','x','t',0};
170
171     TRACE("(%p)->(%p)\n", This, p);
172
173     if(This->nsselection)
174         nsISelection_GetRangeCount(This->nsselection, &range_cnt);
175
176     *p = SysAllocString(range_cnt ? wszText : wszNone); /* FIXME: control */
177     return S_OK;
178 }
179
180 #undef HTMLSELOBJ_THIS
181
182 static const IHTMLSelectionObjectVtbl HTMLSelectionObjectVtbl = {
183     HTMLSelectionObject_QueryInterface,
184     HTMLSelectionObject_AddRef,
185     HTMLSelectionObject_Release,
186     HTMLSelectionObject_GetTypeInfoCount,
187     HTMLSelectionObject_GetTypeInfo,
188     HTMLSelectionObject_GetIDsOfNames,
189     HTMLSelectionObject_Invoke,
190     HTMLSelectionObject_createRange,
191     HTMLSelectionObject_empty,
192     HTMLSelectionObject_clear,
193     HTMLSelectionObject_get_type
194 };
195
196 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection *nsselection)
197 {
198     HTMLSelectionObject *ret = mshtml_alloc(sizeof(HTMLSelectionObject));
199
200     ret->lpHTMLSelectionObjectVtbl = &HTMLSelectionObjectVtbl;
201     ret->ref = 1;
202     ret->nsselection = nsselection; /* We shouldn't call AddRef here */
203
204     return HTMLSELOBJ(ret);
205 }