po: Update Japanese translation.
[wine.git] / dlls / uxtheme / buffer.c
blobb07284f8e06ce1f2551b0a879ce3ac148ec974f0
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 if (!handle)
56 return NULL;
57 return handle;
60 /***********************************************************************
61 * BufferedPaintInit (UXTHEME.@)
63 HRESULT WINAPI BufferedPaintInit(VOID)
65 FIXME("Stub ()\n");
66 return S_OK;
69 /***********************************************************************
70 * BufferedPaintUnInit (UXTHEME.@)
72 HRESULT WINAPI BufferedPaintUnInit(VOID)
74 FIXME("Stub ()\n");
75 return S_OK;
78 /***********************************************************************
79 * BeginBufferedPaint (UXTHEME.@)
81 HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect,
82 BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
84 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
85 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
86 struct paintbuffer *buffer;
88 TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
89 params, retdc);
91 if (retdc)
92 *retdc = NULL;
94 if (!targetdc || IsRectEmpty(rect))
95 return NULL;
97 if (params)
98 FIXME("painting parameters are ignored\n");
100 buffer = heap_alloc(sizeof(*buffer));
101 buffer->targetdc = targetdc;
102 buffer->rect = *rect;
103 buffer->memorydc = CreateCompatibleDC(targetdc);
105 switch (format)
107 case BPBF_COMPATIBLEBITMAP:
108 buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
109 buffer->bits = NULL;
110 break;
111 case BPBF_DIB:
112 case BPBF_TOPDOWNDIB:
113 case BPBF_TOPDOWNMONODIB:
114 /* create DIB section */
115 memset(bmi, 0, sizeof(bmibuf));
116 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
117 bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
118 -(rect->bottom - rect->top);
119 bmi->bmiHeader.biWidth = rect->right - rect->left;
120 bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
121 bmi->bmiHeader.biPlanes = 1;
122 bmi->bmiHeader.biCompression = BI_RGB;
123 buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
124 break;
125 default:
126 WARN("Unknown buffer format %d\n", format);
127 buffer->bitmap = NULL;
128 free_paintbuffer(buffer);
129 return NULL;
132 if (!buffer->bitmap)
134 WARN("Failed to create buffer bitmap\n");
135 free_paintbuffer(buffer);
136 return NULL;
139 SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
140 IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
141 DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));
143 *retdc = buffer->memorydc;
145 return (HPAINTBUFFER)buffer;
148 /***********************************************************************
149 * EndBufferedPaint (UXTHEME.@)
151 HRESULT WINAPI EndBufferedPaint(HPAINTBUFFER bufferhandle, BOOL update)
153 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
155 TRACE("(%p %d)\n", bufferhandle, update);
157 if (!buffer)
158 return E_INVALIDARG;
160 if (update)
162 if (!BitBlt(buffer->targetdc, buffer->rect.left, buffer->rect.top,
163 buffer->rect.right - buffer->rect.left, buffer->rect.bottom - buffer->rect.top,
164 buffer->memorydc, buffer->rect.left, buffer->rect.top, SRCCOPY))
166 WARN("BitBlt() failed\n");
170 free_paintbuffer(buffer);
171 return S_OK;
174 /***********************************************************************
175 * BufferedPaintClear (UXTHEME.@)
177 HRESULT WINAPI BufferedPaintClear(HPAINTBUFFER hBufferedPaint, const RECT *prc)
179 FIXME("Stub (%p %p)\n", hBufferedPaint, prc);
180 return E_NOTIMPL;
183 /***********************************************************************
184 * BufferedPaintSetAlpha (UXTHEME.@)
186 HRESULT WINAPI BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha)
188 FIXME("Stub (%p %p %u)\n", hBufferedPaint, prc, alpha);
189 return E_NOTIMPL;
192 /***********************************************************************
193 * GetBufferedPaintBits (UXTHEME.@)
195 HRESULT WINAPI GetBufferedPaintBits(HPAINTBUFFER bufferhandle, RGBQUAD **bits, int *width)
197 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
199 TRACE("(%p %p %p)\n", buffer, bits, width);
201 if (!bits || !width)
202 return E_POINTER;
204 if (!buffer || !buffer->bits)
205 return E_FAIL;
207 *bits = buffer->bits;
208 *width = buffer->rect.right - buffer->rect.left;
210 return S_OK;
213 /***********************************************************************
214 * GetBufferedPaintDC (UXTHEME.@)
216 HDC WINAPI GetBufferedPaintDC(HPAINTBUFFER bufferhandle)
218 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
220 TRACE("(%p)\n", buffer);
222 return buffer ? buffer->memorydc : NULL;
225 /***********************************************************************
226 * GetBufferedPaintTargetDC (UXTHEME.@)
228 HDC WINAPI GetBufferedPaintTargetDC(HPAINTBUFFER bufferhandle)
230 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
232 TRACE("(%p)\n", buffer);
234 return buffer ? buffer->targetdc : NULL;
237 /***********************************************************************
238 * GetBufferedPaintTargetRect (UXTHEME.@)
240 HRESULT WINAPI GetBufferedPaintTargetRect(HPAINTBUFFER bufferhandle, RECT *rect)
242 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
244 TRACE("(%p %p)\n", buffer, rect);
246 if (!rect)
247 return E_POINTER;
249 if (!buffer)
250 return E_FAIL;
252 *rect = buffer->rect;
253 return S_OK;
256 /***********************************************************************
257 * BeginBufferedAnimation (UXTHEME.@)
259 HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget,
260 BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams,
261 BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom,
262 HDC *phdcTo)
264 FIXME("Stub (%p %p %p %u %p %p %p %p)\n", hwnd, hdcTarget, rcTarget, dwFormat,
265 pPaintParams, pAnimationParams, phdcFrom, phdcTo);
267 return NULL;
270 /***********************************************************************
271 * BufferedPaintRenderAnimation (UXTHEME.@)
273 BOOL WINAPI BufferedPaintRenderAnimation(HWND hwnd, HDC hdcTarget)
275 FIXME("Stub (%p %p)\n", hwnd, hdcTarget);
277 return FALSE;
280 /***********************************************************************
281 * BufferedPaintStopAllAnimations (UXTHEME.@)
283 HRESULT WINAPI BufferedPaintStopAllAnimations(HWND hwnd)
285 FIXME("Stub (%p)\n", hwnd);
287 return E_NOTIMPL;
290 /***********************************************************************
291 * EndBufferedAnimation (UXTHEME.@)
293 HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
295 FIXME("Stub (%p %u)\n", hbpAnimation, fUpdateTarget);
297 return E_NOTIMPL;