- Improve LVM_GETITEMRECT values for LVS_ICON style. Now mostly
[wine] / objects / dcvalues.c
1 /*
2  * DC device-independent Get/SetXXX functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "winbase.h"
24 #include "winerror.h"
25
26 #include "gdi.h"
27
28
29 /***********************************************************************
30  *              SetBkMode (GDI32.@)
31  */
32 INT WINAPI SetBkMode( HDC hdc, INT mode )
33 {
34     INT ret;
35     DC *dc;
36     if ((mode <= 0) || (mode > BKMODE_LAST))
37     {
38         SetLastError(ERROR_INVALID_PARAMETER);
39         return 0;
40     }
41     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
42     if (dc->funcs->pSetBkMode)
43         ret = dc->funcs->pSetBkMode( dc->physDev, mode );
44     else
45     {
46         ret = dc->backgroundMode;
47         dc->backgroundMode = mode;
48     }
49     GDI_ReleaseObj( hdc );
50     return ret;
51 }
52
53
54 /***********************************************************************
55  *              SetROP2 (GDI32.@)
56  */
57 INT WINAPI SetROP2( HDC hdc, INT mode )
58 {
59     INT ret;
60     DC *dc;
61     if ((mode < R2_BLACK) || (mode > R2_WHITE))
62     {
63         SetLastError(ERROR_INVALID_PARAMETER);
64         return 0;
65     }
66     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
67     if (dc->funcs->pSetROP2)
68         ret = dc->funcs->pSetROP2( dc->physDev, mode );
69     else
70     {
71         ret = dc->ROPmode;
72         dc->ROPmode = mode;
73     }
74     GDI_ReleaseObj( hdc );
75     return ret;
76 }
77
78
79 /***********************************************************************
80  *              SetRelAbs (GDI32.@)
81  */
82 INT WINAPI SetRelAbs( HDC hdc, INT mode )
83 {
84     INT ret;
85     DC *dc;
86     if ((mode != ABSOLUTE) && (mode != RELATIVE))
87     {
88         SetLastError(ERROR_INVALID_PARAMETER);
89         return 0;
90     }
91     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
92     if (dc->funcs->pSetRelAbs)
93         ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
94     else
95     {
96         ret = dc->relAbsMode;
97         dc->relAbsMode = mode;
98     }
99     GDI_ReleaseObj( hdc );
100     return ret;
101 }
102
103
104 /***********************************************************************
105  *              SetPolyFillMode (GDI32.@)
106  */
107 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
108 {
109     INT ret;
110     DC *dc;
111     if ((mode <= 0) || (mode > POLYFILL_LAST))
112     {
113         SetLastError(ERROR_INVALID_PARAMETER);
114         return 0;
115     }
116     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
117     if (dc->funcs->pSetPolyFillMode)
118         ret = dc->funcs->pSetPolyFillMode( dc->physDev, mode );
119     else
120     {
121         ret = dc->polyFillMode;
122         dc->polyFillMode = mode;
123     }
124     GDI_ReleaseObj( hdc );
125     return ret;
126 }
127
128
129 /***********************************************************************
130  *              SetStretchBltMode (GDI32.@)
131  */
132 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
133 {
134     INT ret;
135     DC *dc;
136     if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
137     {
138         SetLastError(ERROR_INVALID_PARAMETER);
139         return 0;
140     }
141     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
142     if (dc->funcs->pSetStretchBltMode)
143         ret = dc->funcs->pSetStretchBltMode( dc->physDev, mode );
144     else
145     {
146         ret = dc->stretchBltMode;
147         dc->stretchBltMode = mode;
148     }
149     GDI_ReleaseObj( hdc );
150     return ret;
151 }
152
153
154 /***********************************************************************
155  *              GetBkColor (GDI32.@)
156  */
157 COLORREF WINAPI GetBkColor( HDC hdc )
158 {
159     COLORREF ret = 0;
160     DC * dc = DC_GetDCPtr( hdc );
161     if (dc)
162     {
163         ret = dc->backgroundColor;
164         GDI_ReleaseObj( hdc );
165     }
166     return ret;
167 }
168
169
170 /***********************************************************************
171  *              GetBkMode (GDI32.@)
172  */
173 INT WINAPI GetBkMode( HDC hdc )
174 {
175     INT ret = 0;
176     DC * dc = DC_GetDCPtr( hdc );
177     if (dc)
178     {
179         ret = dc->backgroundMode;
180         GDI_ReleaseObj( hdc );
181     }
182     return ret;
183 }
184
185
186 /***********************************************************************
187  *              GetMapMode (GDI32.@)
188  */
189 INT WINAPI GetMapMode( HDC hdc )
190 {
191     INT ret = 0;
192     DC * dc = DC_GetDCPtr( hdc );
193     if (dc)
194     {
195         ret = dc->MapMode;
196         GDI_ReleaseObj( hdc );
197     }
198     return ret;
199 }
200
201
202 /***********************************************************************
203  *              GetPolyFillMode (GDI32.@)
204  */
205 INT WINAPI GetPolyFillMode( HDC hdc )
206 {
207     INT ret = 0;
208     DC * dc = DC_GetDCPtr( hdc );
209     if (dc)
210     {
211         ret = dc->polyFillMode;
212         GDI_ReleaseObj( hdc );
213     }
214     return ret;
215 }
216
217
218 /***********************************************************************
219  *              GetROP2 (GDI32.@)
220  */
221 INT WINAPI GetROP2( HDC hdc )
222 {
223     INT ret = 0;
224     DC * dc = DC_GetDCPtr( hdc );
225     if (dc)
226     {
227         ret = dc->ROPmode;
228         GDI_ReleaseObj( hdc );
229     }
230     return ret;
231 }
232
233
234 /***********************************************************************
235  *              GetStretchBltMode (GDI32.@)
236  */
237 INT WINAPI GetStretchBltMode( HDC hdc )
238 {
239     INT ret = 0;
240     DC * dc = DC_GetDCPtr( hdc );
241     if (dc)
242     {
243         ret = dc->stretchBltMode;
244         GDI_ReleaseObj( hdc );
245     }
246     return ret;
247 }
248
249
250 /***********************************************************************
251  *              GetTextColor (GDI32.@)
252  */
253 COLORREF WINAPI GetTextColor( HDC hdc )
254 {
255     COLORREF ret = 0;
256     DC * dc = DC_GetDCPtr( hdc );
257     if (dc)
258     {
259         ret = dc->textColor;
260         GDI_ReleaseObj( hdc );
261     }
262     return ret;
263 }
264
265
266 /***********************************************************************
267  *              GetTextAlign (GDI32.@)
268  */
269 UINT WINAPI GetTextAlign( HDC hdc )
270 {
271     UINT ret = 0;
272     DC * dc = DC_GetDCPtr( hdc );
273     if (dc)
274     {
275         ret = dc->textAlign;
276         GDI_ReleaseObj( hdc );
277     }
278     return ret;
279 }
280
281
282 /***********************************************************************
283  *              GetArcDirection (GDI32.@)
284  */
285 INT WINAPI GetArcDirection( HDC hdc )
286 {
287     INT ret = 0;
288     DC * dc = DC_GetDCPtr( hdc );
289     if (dc)
290     {
291         ret = dc->ArcDirection;
292         GDI_ReleaseObj( hdc );
293     }
294     return ret;
295 }
296
297
298 /***********************************************************************
299  *              GetGraphicsMode (GDI32.@)
300  */
301 INT WINAPI GetGraphicsMode( HDC hdc )
302 {
303     INT ret = 0;
304     DC * dc = DC_GetDCPtr( hdc );
305     if (dc)
306     {
307         ret = dc->GraphicsMode;
308         GDI_ReleaseObj( hdc );
309     }
310     return ret;
311 }
312
313
314 /***********************************************************************
315  *              GetBrushOrgEx (GDI32.@)
316  */
317 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
318 {
319     DC * dc = DC_GetDCPtr( hdc );
320     if (!dc) return FALSE;
321     pt->x = dc->brushOrgX;
322     pt->y = dc->brushOrgY;
323     GDI_ReleaseObj( hdc );
324     return TRUE;
325 }
326
327
328 /***********************************************************************
329  *              GetCurrentPositionEx (GDI32.@)
330  */
331 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
332 {
333     DC * dc = DC_GetDCPtr( hdc );
334     if (!dc) return FALSE;
335     pt->x = dc->CursPosX;
336     pt->y = dc->CursPosY;
337     GDI_ReleaseObj( hdc );
338     return TRUE;
339 }
340
341
342 /***********************************************************************
343  *              GetViewportExtEx (GDI32.@)
344  */
345 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
346 {
347     DC * dc = DC_GetDCPtr( hdc );
348     if (!dc) return FALSE;
349     size->cx = dc->vportExtX;
350     size->cy = dc->vportExtY;
351     GDI_ReleaseObj( hdc );
352     return TRUE;
353 }
354
355
356 /***********************************************************************
357  *              GetViewportOrgEx (GDI32.@)
358  */
359 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
360 {
361     DC * dc = DC_GetDCPtr( hdc );
362     if (!dc) return FALSE;
363     pt->x = dc->vportOrgX;
364     pt->y = dc->vportOrgY;
365     GDI_ReleaseObj( hdc );
366     return TRUE;
367 }
368
369
370 /***********************************************************************
371  *              GetWindowExtEx (GDI32.@)
372  */
373 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
374 {
375     DC * dc = DC_GetDCPtr( hdc );
376     if (!dc) return FALSE;
377     size->cx = dc->wndExtX;
378     size->cy = dc->wndExtY;
379     GDI_ReleaseObj( hdc );
380     return TRUE;
381 }
382
383
384 /***********************************************************************
385  *              GetWindowOrgEx (GDI32.@)
386  */
387 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
388 {
389     DC * dc = DC_GetDCPtr( hdc );
390     if (!dc) return FALSE;
391     pt->x = dc->wndOrgX;
392     pt->y = dc->wndOrgY;
393     GDI_ReleaseObj( hdc );
394     return TRUE;
395 }
396
397
398 /**** 16-bit functions ***/
399
400 /***********************************************************************
401  *              InquireVisRgn   (GDI.131)
402  *              InquireVisRgn16 (GDI32.@)
403  */
404 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
405 {
406     HRGN16 ret = 0;
407     DC * dc = DC_GetDCPtr( hdc );
408     if (dc)
409     {
410         ret = dc->hVisRgn;
411         GDI_ReleaseObj( hdc );
412     }
413     return ret;
414 }
415
416
417 /***********************************************************************
418  *              GetClipRgn (GDI.173)
419  */
420 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
421 {
422     HRGN16 ret = 0;
423     DC * dc = DC_GetDCPtr( hdc );
424     if (dc)
425     {
426         ret = dc->hClipRgn;
427         GDI_ReleaseObj( hdc );
428     }
429     return ret;
430 }