Link with libdl only where needed.
[wine] / objects / dcvalues.c
1 /*
2  * DC device-independent Get/SetXXX functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
6  */
7
8 #include "config.h"
9
10 #include "winbase.h"
11 #include "winerror.h"
12
13 #include "gdi.h"
14
15
16 /***********************************************************************
17  *              SetBkMode (GDI32.@)
18  */
19 INT WINAPI SetBkMode( HDC hdc, INT mode )
20 {
21     INT ret;
22     DC *dc;
23     if ((mode <= 0) || (mode > BKMODE_LAST))
24     {
25         SetLastError(ERROR_INVALID_PARAMETER);
26         return 0;
27     }
28     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
29     if (dc->funcs->pSetBkMode)
30         ret = dc->funcs->pSetBkMode( dc, mode );
31     else
32     {
33         ret = dc->backgroundMode;
34         dc->backgroundMode = mode;
35     }
36     GDI_ReleaseObj( hdc );
37     return ret;
38 }
39
40
41 /***********************************************************************
42  *              SetROP2 (GDI32.@)
43  */
44 INT WINAPI SetROP2( HDC hdc, INT mode )
45 {
46     INT ret;
47     DC *dc;
48     if ((mode < R2_BLACK) || (mode > R2_WHITE))
49     {
50         SetLastError(ERROR_INVALID_PARAMETER);
51         return 0;
52     }
53     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
54     if (dc->funcs->pSetROP2)
55         ret = dc->funcs->pSetROP2( dc, mode );
56     else
57     {
58         ret = dc->ROPmode;
59         dc->ROPmode = mode;
60     }
61     GDI_ReleaseObj( hdc );
62     return ret;
63 }
64
65
66 /***********************************************************************
67  *              SetRelAbs (GDI32.@)
68  */
69 INT WINAPI SetRelAbs( HDC hdc, INT mode )
70 {
71     INT ret;
72     DC *dc;
73     if ((mode != ABSOLUTE) && (mode != RELATIVE))
74     {
75         SetLastError(ERROR_INVALID_PARAMETER);
76         return 0;
77     }
78     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
79     if (dc->funcs->pSetRelAbs)
80         ret = dc->funcs->pSetRelAbs( dc, mode );
81     else
82     {
83         ret = dc->relAbsMode;
84         dc->relAbsMode = mode;
85     }
86     GDI_ReleaseObj( hdc );
87     return ret;
88 }
89
90
91 /***********************************************************************
92  *              SetPolyFillMode (GDI32.@)
93  */
94 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
95 {
96     INT ret;
97     DC *dc;
98     if ((mode <= 0) || (mode > POLYFILL_LAST))
99     {
100         SetLastError(ERROR_INVALID_PARAMETER);
101         return 0;
102     }
103     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
104     if (dc->funcs->pSetPolyFillMode)
105         ret = dc->funcs->pSetPolyFillMode( dc, mode );
106     else
107     {
108         ret = dc->polyFillMode;
109         dc->polyFillMode = mode;
110     }
111     GDI_ReleaseObj( hdc );
112     return ret;
113 }
114
115
116 /***********************************************************************
117  *              SetStretchBltMode (GDI32.@)
118  */
119 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
120 {
121     INT ret;
122     DC *dc;
123     if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
124     {
125         SetLastError(ERROR_INVALID_PARAMETER);
126         return 0;
127     }
128     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
129     if (dc->funcs->pSetStretchBltMode)
130         ret = dc->funcs->pSetStretchBltMode( dc, mode );
131     else
132     {
133         ret = dc->stretchBltMode;
134         dc->stretchBltMode = mode;
135     }
136     GDI_ReleaseObj( hdc );
137     return ret;
138 }
139
140
141 /***********************************************************************
142  *              GetBkColor (GDI32.@)
143  */
144 COLORREF WINAPI GetBkColor( HDC hdc )
145 {
146     COLORREF ret = 0;
147     DC * dc = DC_GetDCPtr( hdc );
148     if (dc)
149     {
150         ret = dc->backgroundColor;
151         GDI_ReleaseObj( hdc );
152     }
153     return ret;
154 }
155
156
157 /***********************************************************************
158  *              GetBkMode (GDI32.@)
159  */
160 INT WINAPI GetBkMode( HDC hdc )
161 {
162     INT ret = 0;
163     DC * dc = DC_GetDCPtr( hdc );
164     if (dc)
165     {
166         ret = dc->backgroundMode;
167         GDI_ReleaseObj( hdc );
168     }
169     return ret;
170 }
171
172
173 /***********************************************************************
174  *              GetMapMode (GDI32.@)
175  */
176 INT WINAPI GetMapMode( HDC hdc )
177 {
178     INT ret = 0;
179     DC * dc = DC_GetDCPtr( hdc );
180     if (dc)
181     {
182         ret = dc->MapMode;
183         GDI_ReleaseObj( hdc );
184     }
185     return ret;
186 }
187
188
189 /***********************************************************************
190  *              GetPolyFillMode (GDI32.@)
191  */
192 INT WINAPI GetPolyFillMode( HDC hdc )
193 {
194     INT ret = 0;
195     DC * dc = DC_GetDCPtr( hdc );
196     if (dc)
197     {
198         ret = dc->polyFillMode;
199         GDI_ReleaseObj( hdc );
200     }
201     return ret;
202 }
203
204
205 /***********************************************************************
206  *              GetROP2 (GDI32.@)
207  */
208 INT WINAPI GetROP2( HDC hdc )
209 {
210     INT ret = 0;
211     DC * dc = DC_GetDCPtr( hdc );
212     if (dc)
213     {
214         ret = dc->ROPmode;
215         GDI_ReleaseObj( hdc );
216     }
217     return ret;
218 }
219
220
221 /***********************************************************************
222  *              GetStretchBltMode (GDI32.@)
223  */
224 INT WINAPI GetStretchBltMode( HDC hdc )
225 {
226     INT ret = 0;
227     DC * dc = DC_GetDCPtr( hdc );
228     if (dc)
229     {
230         ret = dc->stretchBltMode;
231         GDI_ReleaseObj( hdc );
232     }
233     return ret;
234 }
235
236
237 /***********************************************************************
238  *              GetTextColor (GDI32.@)
239  */
240 COLORREF WINAPI GetTextColor( HDC hdc )
241 {
242     COLORREF ret = 0;
243     DC * dc = DC_GetDCPtr( hdc );
244     if (dc)
245     {
246         ret = dc->textColor;
247         GDI_ReleaseObj( hdc );
248     }
249     return ret;
250 }
251
252
253 /***********************************************************************
254  *              GetTextAlign (GDI32.@)
255  */
256 UINT WINAPI GetTextAlign( HDC hdc )
257 {
258     UINT ret = 0;
259     DC * dc = DC_GetDCPtr( hdc );
260     if (dc)
261     {
262         ret = dc->textAlign;
263         GDI_ReleaseObj( hdc );
264     }
265     return ret;
266 }
267
268
269 /***********************************************************************
270  *              GetArcDirection (GDI32.@)
271  */
272 INT WINAPI GetArcDirection( HDC hdc )
273 {
274     INT ret = 0;
275     DC * dc = DC_GetDCPtr( hdc );
276     if (dc)
277     {
278         ret = dc->ArcDirection;
279         GDI_ReleaseObj( hdc );
280     }
281     return ret;
282 }
283
284
285 /***********************************************************************
286  *              GetGraphicsMode (GDI32.@)
287  */
288 INT WINAPI GetGraphicsMode( HDC hdc )
289 {
290     INT ret = 0;
291     DC * dc = DC_GetDCPtr( hdc );
292     if (dc)
293     {
294         ret = dc->GraphicsMode;
295         GDI_ReleaseObj( hdc );
296     }
297     return ret;
298 }
299
300
301 /***********************************************************************
302  *              GetBrushOrgEx (GDI32.@)
303  */
304 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
305 {
306     DC * dc = DC_GetDCPtr( hdc );
307     if (!dc) return FALSE;
308     pt->x = dc->brushOrgX;
309     pt->y = dc->brushOrgY;
310     GDI_ReleaseObj( hdc );
311     return TRUE;
312 }
313
314
315 /***********************************************************************
316  *              GetCurrentPositionEx (GDI32.@)
317  */
318 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
319 {
320     DC * dc = DC_GetDCPtr( hdc );
321     if (!dc) return FALSE;
322     pt->x = dc->CursPosX;
323     pt->y = dc->CursPosY;
324     GDI_ReleaseObj( hdc );
325     return TRUE;
326 }
327
328
329 /***********************************************************************
330  *              GetViewportExtEx (GDI32.@)
331  */
332 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
333 {
334     DC * dc = DC_GetDCPtr( hdc );
335     if (!dc) return FALSE;
336     size->cx = dc->vportExtX;
337     size->cy = dc->vportExtY;
338     GDI_ReleaseObj( hdc );
339     return TRUE;
340 }
341
342
343 /***********************************************************************
344  *              GetViewportOrgEx (GDI32.@)
345  */
346 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
347 {
348     DC * dc = DC_GetDCPtr( hdc );
349     if (!dc) return FALSE;
350     pt->x = dc->vportOrgX;
351     pt->y = dc->vportOrgY;
352     GDI_ReleaseObj( hdc );
353     return TRUE;
354 }
355
356
357 /***********************************************************************
358  *              GetWindowExtEx (GDI32.@)
359  */
360 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
361 {
362     DC * dc = DC_GetDCPtr( hdc );
363     if (!dc) return FALSE;
364     size->cx = dc->wndExtX;
365     size->cy = dc->wndExtY;
366     GDI_ReleaseObj( hdc );
367     return TRUE;
368 }
369
370
371 /***********************************************************************
372  *              GetWindowOrgEx (GDI32.@)
373  */
374 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
375 {
376     DC * dc = DC_GetDCPtr( hdc );
377     if (!dc) return FALSE;
378     pt->x = dc->wndOrgX;
379     pt->y = dc->wndOrgY;
380     GDI_ReleaseObj( hdc );
381     return TRUE;
382 }
383
384
385 /**** 16-bit functions ****/
386
387
388 /***********************************************************************
389  *              SetBkMode (GDI.2)
390  */
391 INT16 WINAPI SetBkMode16( HDC16 hdc, INT16 mode )
392 {
393     return SetBkMode( hdc, mode );
394 }
395
396 /***********************************************************************
397  *              SetROP2 (GDI.4)
398  */
399 INT16 WINAPI SetROP216( HDC16 hdc, INT16 mode )
400 {
401     return SetROP2( hdc, mode );
402 }
403
404 /***********************************************************************
405  *              SetRelAbs (GDI.5)
406  */
407 INT16 WINAPI SetRelAbs16( HDC16 hdc, INT16 mode )
408 {
409     return SetRelAbs( hdc, mode );
410 }
411
412 /***********************************************************************
413  *              SetPolyFillMode (GDI.6)
414  */
415 INT16 WINAPI SetPolyFillMode16( HDC16 hdc, INT16 mode )
416 {
417     return SetPolyFillMode( hdc, mode );
418 }
419
420 /***********************************************************************
421  *              SetStretchBltMode (GDI.7)
422  */
423 INT16 WINAPI SetStretchBltMode16( HDC16 hdc, INT16 mode )
424 {
425     return SetStretchBltMode( hdc, mode );
426 }
427
428 /***********************************************************************
429  *              GetBkColor (GDI.75)
430  */
431 COLORREF WINAPI GetBkColor16( HDC16 hdc )
432 {
433     return GetBkColor( hdc );
434 }
435
436 /***********************************************************************
437  *              GetBkMode (GDI.76)
438  */
439 INT16 WINAPI GetBkMode16( HDC16 hdc )
440 {
441     return GetBkMode( hdc );
442 }
443
444 /***********************************************************************
445  *              GetCurrentPosition (GDI.78)
446  */
447 DWORD WINAPI GetCurrentPosition16( HDC16 hdc )
448 {
449     POINT pt32;
450     if (!GetCurrentPositionEx( hdc, &pt32 )) return 0;
451     return MAKELONG( pt32.x, pt32.y );
452 }
453
454 /***********************************************************************
455  *              GetMapMode (GDI.81)
456  */
457 INT16 WINAPI GetMapMode16( HDC16 hdc )
458 {
459     return GetMapMode( hdc );
460 }
461
462 /***********************************************************************
463  *              GetPolyFillMode (GDI.84)
464  */
465 INT16 WINAPI GetPolyFillMode16( HDC16 hdc )
466 {
467     return GetPolyFillMode( hdc );
468 }
469
470 /***********************************************************************
471  *              GetROP2 (GDI.85)
472  */
473 INT16 WINAPI GetROP216( HDC16 hdc )
474 {
475     return GetROP2( hdc );
476 }
477
478 /***********************************************************************
479  *              GetRelAbs (GDI.86)
480  */
481 INT16 WINAPI GetRelAbs16( HDC16 hdc )
482 {
483     return GetRelAbs( hdc, 0 );
484 }
485
486 /***********************************************************************
487  *              GetStretchBltMode (GDI.88)
488  */
489 INT16 WINAPI GetStretchBltMode16( HDC16 hdc )
490 {
491     return GetStretchBltMode( hdc );
492 }
493
494 /***********************************************************************
495  *              GetTextColor (GDI.90)
496  */
497 COLORREF WINAPI GetTextColor16( HDC16 hdc )
498 {
499     return GetTextColor( hdc );
500 }
501
502 /***********************************************************************
503  *              GetViewportExt (GDI.94)
504  */
505 DWORD WINAPI GetViewportExt16( HDC16 hdc )
506 {
507     SIZE size;
508     if (!GetViewportExtEx( hdc, &size )) return 0;
509     return MAKELONG( size.cx, size.cy );
510 }
511
512 /***********************************************************************
513  *              GetViewportOrg (GDI.95)
514  */
515 DWORD WINAPI GetViewportOrg16( HDC16 hdc )
516 {
517     POINT pt;
518     if (!GetViewportOrgEx( hdc, &pt )) return 0;
519     return MAKELONG( pt.x, pt.y );
520 }
521
522
523 /***********************************************************************
524  *              GetWindowExt (GDI.96)
525  */
526 DWORD WINAPI GetWindowExt16( HDC16 hdc )
527 {
528     SIZE size;
529     if (!GetWindowExtEx( hdc, &size )) return 0;
530     return MAKELONG( size.cx, size.cy );
531 }
532
533 /***********************************************************************
534  *              GetWindowOrg (GDI.97)
535  */
536 DWORD WINAPI GetWindowOrg16( HDC16 hdc )
537 {
538     POINT pt;
539     if (!GetWindowOrgEx( hdc, &pt )) return 0;
540     return MAKELONG( pt.x, pt.y );
541 }
542
543 /***********************************************************************
544  *              InquireVisRgn (GDI.131)
545  */
546 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
547 {
548     HRGN16 ret = 0;
549     DC * dc = DC_GetDCPtr( hdc );
550     if (dc)
551     {
552         ret = dc->hVisRgn;
553         GDI_ReleaseObj( hdc );
554     }
555     return ret;
556 }
557
558 /***********************************************************************
559  *              GetBrushOrg (GDI.149)
560  */
561 DWORD WINAPI GetBrushOrg16( HDC16 hdc )
562 {
563     POINT pt;
564     if (!GetBrushOrgEx( hdc, &pt )) return 0;
565     return MAKELONG( pt.x, pt.y );
566 }
567
568 /***********************************************************************
569  *              GetClipRgn (GDI.173)
570  */
571 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
572 {
573     HRGN16 ret = 0;
574     DC * dc = DC_GetDCPtr( hdc );
575     if (dc)
576     {
577         ret = dc->hClipRgn;
578         GDI_ReleaseObj( hdc );
579     }
580     return ret;
581 }
582
583 /***********************************************************************
584  *              GetTextAlign (GDI.345)
585  */
586 UINT16 WINAPI GetTextAlign16( HDC16 hdc )
587 {
588     return GetTextAlign( hdc );
589 }
590
591 /***********************************************************************
592  *              GetCurLogFont (GDI.411)
593  */
594 HFONT16 WINAPI GetCurLogFont16( HDC16 hdc )
595 {
596     HFONT16 ret = 0;
597     DC * dc = DC_GetDCPtr( hdc );
598     if (dc)
599     {
600         ret = dc->hFont;
601         GDI_ReleaseObj( hdc );
602     }
603     return ret;
604 }
605
606 /***********************************************************************
607  *              GetBrushOrgEx (GDI.469)
608  */
609 BOOL16 WINAPI GetBrushOrgEx16( HDC16 hdc, LPPOINT16 pt )
610 {
611     POINT pt32;
612     if (!GetBrushOrgEx( hdc, &pt32 )) return FALSE;
613     pt->x = pt32.x;
614     pt->y = pt32.y;
615     return TRUE;
616 }
617
618 /***********************************************************************
619  *              GetCurrentPositionEx (GDI.470)
620  */
621 BOOL16 WINAPI GetCurrentPositionEx16( HDC16 hdc, LPPOINT16 pt )
622 {
623     POINT pt32;
624     if (!GetCurrentPositionEx( hdc, &pt32 )) return FALSE;
625     pt->x = pt32.x;
626     pt->y = pt32.y;
627     return TRUE;
628 }
629
630 /***********************************************************************
631  *              GetViewportExtEx (GDI.472)
632  */
633 BOOL16 WINAPI GetViewportExtEx16( HDC16 hdc, LPSIZE16 size )
634 {
635     SIZE size32;
636     if (!GetViewportExtEx( hdc, &size32 )) return FALSE;
637     size->cx = size32.cx;
638     size->cy = size32.cy;
639     return TRUE;
640 }
641
642 /***********************************************************************
643  *              GetViewportOrgEx (GDI.473)
644  */
645 BOOL16 WINAPI GetViewportOrgEx16( HDC16 hdc, LPPOINT16 pt )
646 {
647     POINT pt32;
648     if (!GetViewportOrgEx( hdc, &pt32 )) return FALSE;
649     pt->x = pt32.x;
650     pt->y = pt32.y;
651     return TRUE;
652 }
653
654 /***********************************************************************
655  *              GetWindowExtEx (GDI.474)
656  */
657 BOOL16 WINAPI GetWindowExtEx16( HDC16 hdc, LPSIZE16 size )
658 {
659     SIZE size32;
660     if (!GetWindowExtEx( hdc, &size32 )) return FALSE;
661     size->cx = size32.cx;
662     size->cy = size32.cy;
663     return TRUE;
664 }
665
666 /***********************************************************************
667  *              GetWindowOrgEx (GDI.475)
668  */
669 BOOL16 WINAPI GetWindowOrgEx16( HDC16 hdc, LPPOINT16 pt )
670 {
671     POINT pt32;
672     if (!GetWindowOrgEx( hdc, &pt32 )) return FALSE;
673     pt->x = pt32.x;
674     pt->y = pt32.y;
675     return TRUE;
676 }
677
678 /***********************************************************************
679  *              GetArcDirection (GDI.524)
680  */
681 INT16 WINAPI GetArcDirection16( HDC16 hdc )
682 {
683     return GetArcDirection( hdc );
684 }