notepad: Fix the position of the Encoding combobox.
[wine/multimedia.git] / dlls / ddraw / clipper.c
blobdb9c3838285617b4a1c3d19c7a7f1e09402e729c
1 /* DirectDrawClipper implementation
3 * Copyright 2000 (c) Marcus Meissner
4 * Copyright 2000 (c) TransGaming Technologies Inc.
5 * Copyright 2006 (c) Stefan Dösinger
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include "ddraw_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
29 static inline struct ddraw_clipper *impl_from_IDirectDrawClipper(IDirectDrawClipper *iface)
31 return CONTAINING_RECORD(iface, struct ddraw_clipper, IDirectDrawClipper_iface);
34 static HRESULT WINAPI ddraw_clipper_QueryInterface(IDirectDrawClipper *iface, REFIID iid, void **object)
36 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
38 TRACE("iface %p, iid %s, object %p.\n", iface, debugstr_guid(iid), object);
40 if (IsEqualGUID(&IID_IDirectDrawClipper, iid)
41 || IsEqualGUID(&IID_IUnknown, iid))
43 IDirectDrawClipper_AddRef(&clipper->IDirectDrawClipper_iface);
44 *object = &clipper->IDirectDrawClipper_iface;
45 return S_OK;
48 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
49 *object = NULL;
51 return E_NOINTERFACE;
54 static ULONG WINAPI ddraw_clipper_AddRef(IDirectDrawClipper *iface)
56 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
57 ULONG refcount = InterlockedIncrement(&clipper->ref);
59 TRACE("%p increasing refcount to %u.\n", clipper, refcount);
61 return refcount;
64 static ULONG WINAPI ddraw_clipper_Release(IDirectDrawClipper *iface)
66 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
67 ULONG refcount = InterlockedDecrement(&clipper->ref);
69 TRACE("%p decreasing refcount to %u.\n", clipper, refcount);
71 if (!refcount)
73 if (clipper->region)
74 DeleteObject(clipper->region);
75 HeapFree(GetProcessHeap(), 0, clipper);
78 return refcount;
81 static HRESULT WINAPI ddraw_clipper_SetHWnd(IDirectDrawClipper *iface, DWORD flags, HWND window)
83 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
85 TRACE("iface %p, flags %#x, window %p.\n", iface, flags, window);
87 if (flags)
89 FIXME("flags %#x, not supported.\n", flags);
90 return DDERR_INVALIDPARAMS;
93 wined3d_mutex_lock();
94 clipper->window = window;
95 wined3d_mutex_unlock();
97 return DD_OK;
100 static HRGN get_window_region(HWND window)
102 POINT origin;
103 HRGN rgn;
104 HDC dc;
106 if (!(dc = GetDC(window)))
108 WARN("Failed to get dc.\n");
109 return NULL;
112 if (!(rgn = CreateRectRgn(0, 0, 0, 0)))
114 ERR("Failed to create region.\n");
115 ReleaseDC(window, dc);
116 return NULL;
119 if (GetRandomRgn(dc, rgn, SYSRGN) != 1)
121 ERR("Failed to get window region.\n");
122 DeleteObject(rgn);
123 ReleaseDC(window, dc);
124 return NULL;
127 if (GetVersion() & 0x80000000)
129 GetDCOrgEx(dc, &origin);
130 OffsetRgn(rgn, origin.x, origin.y);
133 ReleaseDC(window, dc);
134 return rgn;
137 /*****************************************************************************
138 * IDirectDrawClipper::GetClipList
140 * Retrieve a copy of the clip list
142 * Arguments:
143 * rect: Rectangle to be used to clip the clip list or NULL for the
144 * entire clip list.
145 * clip_list: structure for the resulting copy of the clip list.
146 * If NULL, fills Size up to the number of bytes necessary to hold
147 * the entire clip.
148 * clip_list_size: Size of resulting clip list; size of the buffer at clip_list
149 * or, if clip_list is NULL, receives the required size of the buffer
150 * in bytes.
152 * RETURNS
153 * Either DD_OK or DDERR_*
154 ************************************************************************/
155 static HRESULT WINAPI ddraw_clipper_GetClipList(IDirectDrawClipper *iface, RECT *rect,
156 RGNDATA *clip_list, DWORD *clip_list_size)
158 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
159 HRGN region;
161 TRACE("iface %p, rect %s, clip_list %p, clip_list_size %p.\n",
162 iface, wine_dbgstr_rect(rect), clip_list, clip_list_size);
164 wined3d_mutex_lock();
166 if (clipper->window)
168 if (!(region = get_window_region(clipper->window)))
170 wined3d_mutex_unlock();
171 WARN("Failed to get window region.\n");
172 return E_FAIL;
175 else
177 if (!(region = clipper->region))
179 wined3d_mutex_unlock();
180 WARN("No clip list set.\n");
181 return DDERR_NOCLIPLIST;
185 if (rect)
187 HRGN clip_region;
189 if (!(clip_region = CreateRectRgnIndirect(rect)))
191 wined3d_mutex_unlock();
192 ERR("Failed to create region.\n");
193 if (clipper->window)
194 DeleteObject(region);
195 return E_FAIL;
198 if (CombineRgn(clip_region, region, clip_region, RGN_AND) == ERROR)
200 wined3d_mutex_unlock();
201 ERR("Failed to combine regions.\n");
202 DeleteObject(clip_region);
203 if (clipper->window)
204 DeleteObject(region);
205 return E_FAIL;
208 if (clipper->window)
209 DeleteObject(region);
210 region = clip_region;
213 *clip_list_size = GetRegionData(region, *clip_list_size, clip_list);
214 if (rect || clipper->window)
215 DeleteObject(region);
217 wined3d_mutex_unlock();
218 return DD_OK;
221 /*****************************************************************************
222 * IDirectDrawClipper::SetClipList
224 * Sets or deletes (if region is NULL) the clip list
226 * This implementation is a stub and returns DD_OK always to make the app
227 * happy.
229 * PARAMS
230 * region Pointer to a LRGNDATA structure or NULL
231 * flags not used, must be 0
232 * RETURNS
233 * Either DD_OK or DDERR_*
234 *****************************************************************************/
235 static HRESULT WINAPI ddraw_clipper_SetClipList(IDirectDrawClipper *iface, RGNDATA *region, DWORD flags)
237 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
239 TRACE("iface %p, region %p, flags %#x.\n", iface, region, flags);
241 wined3d_mutex_lock();
243 if (clipper->window)
245 wined3d_mutex_unlock();
246 return DDERR_CLIPPERISUSINGHWND;
249 if (clipper->region)
250 DeleteObject(clipper->region);
251 if (!region)
252 clipper->region = NULL;
253 else if (!(clipper->region = ExtCreateRegion(NULL, 0, region)))
255 wined3d_mutex_unlock();
256 ERR("Failed to create region.\n");
257 return E_FAIL;
260 wined3d_mutex_unlock();
262 return DD_OK;
265 static HRESULT WINAPI ddraw_clipper_GetHWnd(IDirectDrawClipper *iface, HWND *window)
267 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
269 TRACE("iface %p, window %p.\n", iface, window);
271 wined3d_mutex_lock();
272 *window = clipper->window;
273 wined3d_mutex_unlock();
275 return DD_OK;
278 static HRESULT WINAPI ddraw_clipper_Initialize(IDirectDrawClipper *iface,
279 IDirectDraw *ddraw, DWORD flags)
281 struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
283 TRACE("iface %p, ddraw %p, flags %#x.\n", iface, ddraw, flags);
285 wined3d_mutex_lock();
286 if (clipper->initialized)
288 wined3d_mutex_unlock();
289 return DDERR_ALREADYINITIALIZED;
292 clipper->initialized = TRUE;
293 wined3d_mutex_unlock();
295 return DD_OK;
298 static HRESULT WINAPI ddraw_clipper_IsClipListChanged(IDirectDrawClipper *iface, BOOL *changed)
300 FIXME("iface %p, changed %p stub!\n", iface, changed);
302 /* XXX What is safest? */
303 *changed = FALSE;
305 return DD_OK;
308 static const struct IDirectDrawClipperVtbl ddraw_clipper_vtbl =
310 ddraw_clipper_QueryInterface,
311 ddraw_clipper_AddRef,
312 ddraw_clipper_Release,
313 ddraw_clipper_GetClipList,
314 ddraw_clipper_GetHWnd,
315 ddraw_clipper_Initialize,
316 ddraw_clipper_IsClipListChanged,
317 ddraw_clipper_SetClipList,
318 ddraw_clipper_SetHWnd,
321 HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper)
323 clipper->IDirectDrawClipper_iface.lpVtbl = &ddraw_clipper_vtbl;
324 clipper->ref = 1;
326 return DD_OK;
329 struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface)
331 if (!iface)
332 return NULL;
333 assert(iface->lpVtbl == &ddraw_clipper_vtbl);
335 return impl_from_IDirectDrawClipper(iface);