dinput: Clear action mapping with SetDataFormat().
[wine.git] / dlls / uxtheme / buffer.c
blobf159d5c1be0a87370c2749b7b790e34824c3e43c
1 /*
2 * uxtheme Double-buffered Drawing API
4 * Copyright (C) 2008 Reece H. Dunn
5 * Copyright 2017 Nikolay Sivov for CodeWeavers
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 <stdlib.h>
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "vfwmsgs.h"
30 #include "uxtheme.h"
32 #include "wine/debug.h"
33 #include "wine/heap.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
37 struct paintbuffer
39 HDC targetdc;
40 HDC memorydc;
41 HBITMAP bitmap;
42 RECT rect;
43 void *bits;
46 static void free_paintbuffer(struct paintbuffer *buffer)
48 DeleteObject(buffer->bitmap);
49 DeleteDC(buffer->memorydc);
50 heap_free(buffer);
53 static struct paintbuffer *get_buffer_obj(HPAINTBUFFER handle)
55 return handle;
58 /***********************************************************************
59 * BufferedPaintInit (UXTHEME.@)
61 HRESULT WINAPI BufferedPaintInit(VOID)
63 FIXME("Stub ()\n");
64 return S_OK;
67 /***********************************************************************
68 * BufferedPaintUnInit (UXTHEME.@)
70 HRESULT WINAPI BufferedPaintUnInit(VOID)
72 FIXME("Stub ()\n");
73 return S_OK;
76 /***********************************************************************
77 * BeginBufferedPaint (UXTHEME.@)
79 HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect,
80 BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
82 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
83 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
84 struct paintbuffer *buffer;
86 TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
87 params, retdc);
89 if (retdc)
90 *retdc = NULL;
92 if (!targetdc || IsRectEmpty(rect))
93 return NULL;
95 if (params)
96 FIXME("painting parameters are ignored\n");
98 buffer = heap_alloc(sizeof(*buffer));
99 buffer->targetdc = targetdc;
100 buffer->rect = *rect;
101 buffer->memorydc = CreateCompatibleDC(targetdc);
103 switch (format)
105 case BPBF_COMPATIBLEBITMAP:
106 buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
107 buffer->bits = NULL;
108 break;
109 case BPBF_DIB:
110 case BPBF_TOPDOWNDIB:
111 case BPBF_TOPDOWNMONODIB:
112 /* create DIB section */
113 memset(bmi, 0, sizeof(bmibuf));
114 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
115 bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
116 -(rect->bottom - rect->top);
117 bmi->bmiHeader.biWidth = rect->right - rect->left;
118 bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
119 bmi->bmiHeader.biPlanes = 1;
120 bmi->bmiHeader.biCompression = BI_RGB;
121 buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
122 break;
123 default:
124 WARN("Unknown buffer format %d\n", format);
125 buffer->bitmap = NULL;
126 free_paintbuffer(buffer);
127 return NULL;
130 if (!buffer->bitmap)
132 WARN("Failed to create buffer bitmap\n");
133 free_paintbuffer(buffer);
134 return NULL;
137 SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
138 IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
139 DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));
141 *retdc = buffer->memorydc;
143 return (HPAINTBUFFER)buffer;
146 /***********************************************************************
147 * EndBufferedPaint (UXTHEME.@)
149 HRESULT WINAPI EndBufferedPaint(HPAINTBUFFER bufferhandle, BOOL update)
151 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
153 TRACE("(%p %d)\n", bufferhandle, update);
155 if (!buffer)
156 return E_INVALIDARG;
158 if (update)
160 if (!BitBlt(buffer->targetdc, buffer->rect.left, buffer->rect.top,
161 buffer->rect.right - buffer->rect.left, buffer->rect.bottom - buffer->rect.top,
162 buffer->memorydc, buffer->rect.left, buffer->rect.top, SRCCOPY))
164 WARN("BitBlt() failed\n");
168 free_paintbuffer(buffer);
169 return S_OK;
172 /***********************************************************************
173 * BufferedPaintClear (UXTHEME.@)
175 HRESULT WINAPI BufferedPaintClear(HPAINTBUFFER hBufferedPaint, const RECT *prc)
177 FIXME("Stub (%p %p)\n", hBufferedPaint, prc);
178 return E_NOTIMPL;
181 /***********************************************************************
182 * BufferedPaintSetAlpha (UXTHEME.@)
184 HRESULT WINAPI BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha)
186 FIXME("Stub (%p %p %u)\n", hBufferedPaint, prc, alpha);
187 return E_NOTIMPL;
190 /***********************************************************************
191 * GetBufferedPaintBits (UXTHEME.@)
193 HRESULT WINAPI GetBufferedPaintBits(HPAINTBUFFER bufferhandle, RGBQUAD **bits, int *width)
195 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
197 TRACE("(%p %p %p)\n", buffer, bits, width);
199 if (!bits || !width)
200 return E_POINTER;
202 if (!buffer || !buffer->bits)
203 return E_FAIL;
205 *bits = buffer->bits;
206 *width = buffer->rect.right - buffer->rect.left;
208 return S_OK;
211 /***********************************************************************
212 * GetBufferedPaintDC (UXTHEME.@)
214 HDC WINAPI GetBufferedPaintDC(HPAINTBUFFER bufferhandle)
216 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
218 TRACE("(%p)\n", buffer);
220 return buffer ? buffer->memorydc : NULL;
223 /***********************************************************************
224 * GetBufferedPaintTargetDC (UXTHEME.@)
226 HDC WINAPI GetBufferedPaintTargetDC(HPAINTBUFFER bufferhandle)
228 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
230 TRACE("(%p)\n", buffer);
232 return buffer ? buffer->targetdc : NULL;
235 /***********************************************************************
236 * GetBufferedPaintTargetRect (UXTHEME.@)
238 HRESULT WINAPI GetBufferedPaintTargetRect(HPAINTBUFFER bufferhandle, RECT *rect)
240 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
242 TRACE("(%p %p)\n", buffer, rect);
244 if (!rect)
245 return E_POINTER;
247 if (!buffer)
248 return E_FAIL;
250 *rect = buffer->rect;
251 return S_OK;
254 /***********************************************************************
255 * BeginBufferedAnimation (UXTHEME.@)
257 HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget,
258 BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams,
259 BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom,
260 HDC *phdcTo)
262 FIXME("Stub (%p %p %p %u %p %p %p %p)\n", hwnd, hdcTarget, rcTarget, dwFormat,
263 pPaintParams, pAnimationParams, phdcFrom, phdcTo);
265 return NULL;
268 /***********************************************************************
269 * BufferedPaintRenderAnimation (UXTHEME.@)
271 BOOL WINAPI BufferedPaintRenderAnimation(HWND hwnd, HDC hdcTarget)
273 FIXME("Stub (%p %p)\n", hwnd, hdcTarget);
275 return FALSE;
278 /***********************************************************************
279 * BufferedPaintStopAllAnimations (UXTHEME.@)
281 HRESULT WINAPI BufferedPaintStopAllAnimations(HWND hwnd)
283 FIXME("Stub (%p)\n", hwnd);
285 return E_NOTIMPL;
288 /***********************************************************************
289 * EndBufferedAnimation (UXTHEME.@)
291 HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
293 FIXME("Stub (%p %u)\n", hbpAnimation, fUpdateTarget);
295 return E_NOTIMPL;