msxml3/tests: Added IServerXMLHTTPRequest tests.
[wine.git] / dlls / uxtheme / buffer.c
blob32d341cb7f9050c1266546577a6bd35d259e20fa
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 "config.h"
24 #include <stdlib.h>
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wingdi.h"
31 #include "vfwmsgs.h"
32 #include "uxtheme.h"
34 #include "wine/debug.h"
35 #include "wine/heap.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
39 struct paintbuffer
41 HDC targetdc;
42 HDC memorydc;
43 HBITMAP bitmap;
44 RECT rect;
45 void *bits;
48 static void free_paintbuffer(struct paintbuffer *buffer)
50 DeleteObject(buffer->bitmap);
51 DeleteDC(buffer->memorydc);
52 heap_free(buffer);
55 static struct paintbuffer *get_buffer_obj(HPAINTBUFFER handle)
57 if (!handle)
58 return NULL;
59 return handle;
62 /***********************************************************************
63 * BufferedPaintInit (UXTHEME.@)
65 HRESULT WINAPI BufferedPaintInit(VOID)
67 FIXME("Stub ()\n");
68 return S_OK;
71 /***********************************************************************
72 * BufferedPaintUnInit (UXTHEME.@)
74 HRESULT WINAPI BufferedPaintUnInit(VOID)
76 FIXME("Stub ()\n");
77 return S_OK;
80 /***********************************************************************
81 * BeginBufferedPaint (UXTHEME.@)
83 HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect,
84 BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
86 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
87 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
88 struct paintbuffer *buffer;
90 TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
91 params, retdc);
93 if (retdc)
94 *retdc = NULL;
96 if (!targetdc || IsRectEmpty(rect))
97 return NULL;
99 if (params)
100 FIXME("painting parameters are ignored\n");
102 buffer = heap_alloc(sizeof(*buffer));
103 buffer->targetdc = targetdc;
104 buffer->rect = *rect;
105 buffer->memorydc = CreateCompatibleDC(targetdc);
107 switch (format)
109 case BPBF_COMPATIBLEBITMAP:
110 buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
111 buffer->bits = NULL;
112 break;
113 case BPBF_DIB:
114 case BPBF_TOPDOWNDIB:
115 case BPBF_TOPDOWNMONODIB:
116 /* create DIB section */
117 memset(bmi, 0, sizeof(bmibuf));
118 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
119 bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
120 -(rect->bottom - rect->top);
121 bmi->bmiHeader.biWidth = rect->right - rect->left;
122 bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
123 bmi->bmiHeader.biPlanes = 1;
124 bmi->bmiHeader.biCompression = BI_RGB;
125 buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
126 break;
127 default:
128 WARN("Unknown buffer format %d\n", format);
129 buffer->bitmap = NULL;
130 free_paintbuffer(buffer);
131 return NULL;
134 if (!buffer->bitmap)
136 WARN("Failed to create buffer bitmap\n");
137 free_paintbuffer(buffer);
138 return NULL;
141 SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
142 IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
143 DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));
145 *retdc = buffer->memorydc;
147 return (HPAINTBUFFER)buffer;
150 /***********************************************************************
151 * EndBufferedPaint (UXTHEME.@)
153 HRESULT WINAPI EndBufferedPaint(HPAINTBUFFER bufferhandle, BOOL update)
155 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
157 TRACE("(%p %d)\n", bufferhandle, update);
159 if (!buffer)
160 return E_INVALIDARG;
162 if (update)
164 if (!BitBlt(buffer->targetdc, buffer->rect.left, buffer->rect.top,
165 buffer->rect.right - buffer->rect.left, buffer->rect.bottom - buffer->rect.top,
166 buffer->memorydc, buffer->rect.left, buffer->rect.top, SRCCOPY))
168 WARN("BitBlt() failed\n");
172 free_paintbuffer(buffer);
173 return S_OK;
176 /***********************************************************************
177 * BufferedPaintClear (UXTHEME.@)
179 HRESULT WINAPI BufferedPaintClear(HPAINTBUFFER hBufferedPaint, const RECT *prc)
181 FIXME("Stub (%p %p)\n", hBufferedPaint, prc);
182 return E_NOTIMPL;
185 /***********************************************************************
186 * BufferedPaintSetAlpha (UXTHEME.@)
188 HRESULT WINAPI BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha)
190 FIXME("Stub (%p %p %u)\n", hBufferedPaint, prc, alpha);
191 return E_NOTIMPL;
194 /***********************************************************************
195 * GetBufferedPaintBits (UXTHEME.@)
197 HRESULT WINAPI GetBufferedPaintBits(HPAINTBUFFER bufferhandle, RGBQUAD **bits, int *width)
199 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
201 TRACE("(%p %p %p)\n", buffer, bits, width);
203 if (!bits || !width)
204 return E_POINTER;
206 if (!buffer || !buffer->bits)
207 return E_FAIL;
209 *bits = buffer->bits;
210 *width = buffer->rect.right - buffer->rect.left;
212 return S_OK;
215 /***********************************************************************
216 * GetBufferedPaintDC (UXTHEME.@)
218 HDC WINAPI GetBufferedPaintDC(HPAINTBUFFER bufferhandle)
220 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
222 TRACE("(%p)\n", buffer);
224 return buffer ? buffer->memorydc : NULL;
227 /***********************************************************************
228 * GetBufferedPaintTargetDC (UXTHEME.@)
230 HDC WINAPI GetBufferedPaintTargetDC(HPAINTBUFFER bufferhandle)
232 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
234 TRACE("(%p)\n", buffer);
236 return buffer ? buffer->targetdc : NULL;
239 /***********************************************************************
240 * GetBufferedPaintTargetRect (UXTHEME.@)
242 HRESULT WINAPI GetBufferedPaintTargetRect(HPAINTBUFFER bufferhandle, RECT *rect)
244 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
246 TRACE("(%p %p)\n", buffer, rect);
248 if (!rect)
249 return E_POINTER;
251 if (!buffer)
252 return E_FAIL;
254 *rect = buffer->rect;
255 return S_OK;
258 /***********************************************************************
259 * BeginBufferedAnimation (UXTHEME.@)
261 HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget,
262 BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams,
263 BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom,
264 HDC *phdcTo)
266 FIXME("Stub (%p %p %p %u %p %p %p %p)\n", hwnd, hdcTarget, rcTarget, dwFormat,
267 pPaintParams, pAnimationParams, phdcFrom, phdcTo);
269 return NULL;
272 /***********************************************************************
273 * BufferedPaintRenderAnimation (UXTHEME.@)
275 BOOL WINAPI BufferedPaintRenderAnimation(HWND hwnd, HDC hdcTarget)
277 FIXME("Stub (%p %p)\n", hwnd, hdcTarget);
279 return FALSE;
282 /***********************************************************************
283 * BufferedPaintStopAllAnimations (UXTHEME.@)
285 HRESULT WINAPI BufferedPaintStopAllAnimations(HWND hwnd)
287 FIXME("Stub (%p)\n", hwnd);
289 return E_NOTIMPL;
292 /***********************************************************************
293 * EndBufferedAnimation (UXTHEME.@)
295 HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
297 FIXME("Stub (%p %u)\n", hbpAnimation, fUpdateTarget);
299 return E_NOTIMPL;