msvcrt: Don't include MSVC 7.0+ exception functions in SOs for older DLLs.
[wine.git] / dlls / uxtheme / buffer.c
blob664515c2783f91cea1c1043df526cea6393e93e8
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"
36 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
38 struct paintbuffer
40 HDC targetdc;
41 HDC memorydc;
42 HBITMAP bitmap;
43 RECT rect;
44 void *bits;
47 static void free_paintbuffer(struct paintbuffer *buffer)
49 DeleteObject(buffer->bitmap);
50 DeleteDC(buffer->memorydc);
51 HeapFree(GetProcessHeap(), 0, buffer);
54 static struct paintbuffer *get_buffer_obj(HPAINTBUFFER handle)
56 if (!handle)
57 return NULL;
58 return handle;
61 /***********************************************************************
62 * BufferedPaintInit (UXTHEME.@)
64 HRESULT WINAPI BufferedPaintInit(VOID)
66 FIXME("Stub ()\n");
67 return S_OK;
70 /***********************************************************************
71 * BufferedPaintUnInit (UXTHEME.@)
73 HRESULT WINAPI BufferedPaintUnInit(VOID)
75 FIXME("Stub ()\n");
76 return S_OK;
79 /***********************************************************************
80 * BeginBufferedPaint (UXTHEME.@)
82 HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect,
83 BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
85 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
86 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
87 struct paintbuffer *buffer;
89 TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
90 params, retdc);
92 if (retdc)
93 *retdc = NULL;
95 if (!targetdc || IsRectEmpty(rect))
96 return NULL;
98 if (params)
99 FIXME("painting parameters are ignored\n");
101 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer));
102 buffer->targetdc = targetdc;
103 buffer->rect = *rect;
104 buffer->memorydc = CreateCompatibleDC(targetdc);
106 switch (format)
108 case BPBF_COMPATIBLEBITMAP:
109 buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
110 buffer->bits = NULL;
111 break;
112 case BPBF_DIB:
113 case BPBF_TOPDOWNDIB:
114 case BPBF_TOPDOWNMONODIB:
115 /* create DIB section */
116 memset(bmi, 0, sizeof(bmibuf));
117 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
118 bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
119 -(rect->bottom - rect->top);
120 bmi->bmiHeader.biWidth = rect->right - rect->left;
121 bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
122 bmi->bmiHeader.biPlanes = 1;
123 bmi->bmiHeader.biCompression = BI_RGB;
124 buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
125 break;
126 default:
127 WARN("Unknown buffer format %d\n", format);
128 buffer->bitmap = NULL;
129 free_paintbuffer(buffer);
130 return NULL;
133 if (!buffer->bitmap)
135 WARN("Failed to create buffer bitmap\n");
136 free_paintbuffer(buffer);
137 return NULL;
140 SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
141 IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
142 DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));
144 *retdc = buffer->memorydc;
146 return (HPAINTBUFFER)buffer;
149 /***********************************************************************
150 * EndBufferedPaint (UXTHEME.@)
152 HRESULT WINAPI EndBufferedPaint(HPAINTBUFFER bufferhandle, BOOL update)
154 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
156 TRACE("(%p %d)\n", bufferhandle, update);
158 if (!buffer)
159 return E_INVALIDARG;
161 if (update)
163 if (!BitBlt(buffer->targetdc, buffer->rect.left, buffer->rect.top,
164 buffer->rect.right - buffer->rect.left, buffer->rect.bottom - buffer->rect.top,
165 buffer->memorydc, buffer->rect.left, buffer->rect.top, SRCCOPY))
167 WARN("BitBlt() failed\n");
171 free_paintbuffer(buffer);
172 return S_OK;
175 /***********************************************************************
176 * BufferedPaintClear (UXTHEME.@)
178 HRESULT WINAPI BufferedPaintClear(HPAINTBUFFER hBufferedPaint, const RECT *prc)
180 FIXME("Stub (%p %p)\n", hBufferedPaint, prc);
181 return E_NOTIMPL;
184 /***********************************************************************
185 * BufferedPaintSetAlpha (UXTHEME.@)
187 HRESULT WINAPI BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha)
189 FIXME("Stub (%p %p %u)\n", hBufferedPaint, prc, alpha);
190 return E_NOTIMPL;
193 /***********************************************************************
194 * GetBufferedPaintBits (UXTHEME.@)
196 HRESULT WINAPI GetBufferedPaintBits(HPAINTBUFFER bufferhandle, RGBQUAD **bits, int *width)
198 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
200 TRACE("(%p %p %p)\n", buffer, bits, width);
202 if (!bits || !width)
203 return E_POINTER;
205 if (!buffer || !buffer->bits)
206 return E_FAIL;
208 *bits = buffer->bits;
209 *width = buffer->rect.right - buffer->rect.left;
211 return S_OK;
214 /***********************************************************************
215 * GetBufferedPaintDC (UXTHEME.@)
217 HDC WINAPI GetBufferedPaintDC(HPAINTBUFFER bufferhandle)
219 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
221 TRACE("(%p)\n", buffer);
223 return buffer ? buffer->memorydc : NULL;
226 /***********************************************************************
227 * GetBufferedPaintTargetDC (UXTHEME.@)
229 HDC WINAPI GetBufferedPaintTargetDC(HPAINTBUFFER bufferhandle)
231 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
233 TRACE("(%p)\n", buffer);
235 return buffer ? buffer->targetdc : NULL;
238 /***********************************************************************
239 * GetBufferedPaintTargetRect (UXTHEME.@)
241 HRESULT WINAPI GetBufferedPaintTargetRect(HPAINTBUFFER bufferhandle, RECT *rect)
243 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
245 TRACE("(%p %p)\n", buffer, rect);
247 if (!rect)
248 return E_POINTER;
250 if (!buffer)
251 return E_FAIL;
253 *rect = buffer->rect;
254 return S_OK;
257 /***********************************************************************
258 * BeginBufferedAnimation (UXTHEME.@)
260 HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget,
261 BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams,
262 BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom,
263 HDC *phdcTo)
265 FIXME("Stub (%p %p %p %u %p %p %p %p)\n", hwnd, hdcTarget, rcTarget, dwFormat,
266 pPaintParams, pAnimationParams, phdcFrom, phdcTo);
268 return NULL;
271 /***********************************************************************
272 * BufferedPaintRenderAnimation (UXTHEME.@)
274 BOOL WINAPI BufferedPaintRenderAnimation(HWND hwnd, HDC hdcTarget)
276 FIXME("Stub (%p %p)\n", hwnd, hdcTarget);
278 return FALSE;
281 /***********************************************************************
282 * BufferedPaintStopAllAnimations (UXTHEME.@)
284 HRESULT WINAPI BufferedPaintStopAllAnimations(HWND hwnd)
286 FIXME("Stub (%p)\n", hwnd);
288 return E_NOTIMPL;
291 /***********************************************************************
292 * EndBufferedAnimation (UXTHEME.@)
294 HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
296 FIXME("Stub (%p %u)\n", hbpAnimation, fUpdateTarget);
298 return E_NOTIMPL;