Starcraft was confused by a wrong FALSE BitBlt return.
[wine] / graphics / mapping.c
1 /*
2  * GDI mapping mode functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include "gdi.h"
8 #include "debugtools.h"
9
10 DEFAULT_DEBUG_CHANNEL(gdi);
11
12
13 /***********************************************************************
14  *           MAPPING_FixIsotropic
15  *
16  * Fix viewport extensions for isotropic mode.
17  */
18 void MAPPING_FixIsotropic( DC * dc )
19 {
20     double xdim = (double)dc->vportExtX * dc->devCaps->horzSize /
21                   (dc->devCaps->horzRes * dc->wndExtX);
22     double ydim = (double)dc->vportExtY * dc->devCaps->vertSize /
23                   (dc->devCaps->vertRes * dc->wndExtY);
24     if (xdim > ydim)
25     {
26         dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
27         if (!dc->vportExtX) dc->vportExtX = 1;
28     }
29     else
30     {
31         dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
32         if (!dc->vportExtY) dc->vportExtY = 1;
33     }   
34 }
35
36
37 /***********************************************************************
38  *           DPtoLP16    (GDI.67)
39  */
40 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
41 {
42     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
43     if (!dc) return FALSE;
44
45     while (count--)
46     {
47         points->x = XDPTOLP( dc, points->x );
48         points->y = YDPTOLP( dc, points->y );
49         points++;
50     }
51     GDI_ReleaseObj( hdc );
52     return TRUE;
53 }
54
55
56 /***********************************************************************
57  *           DPtoLP    (GDI32.65)
58  */
59 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
60 {
61     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
62     if (!dc) return FALSE;
63
64     while (count--)
65     {
66         if (!INTERNAL_DPTOLP( dc, points ))
67             break;
68         points++;
69     }
70     GDI_ReleaseObj( hdc );
71     return (count < 0);
72 }
73
74
75 /***********************************************************************
76  *           LPtoDP16    (GDI.99)
77  */
78 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
79 {
80     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
81     if (!dc) return FALSE;
82
83     while (count--)
84     {
85         points->x = XLPTODP( dc, points->x );
86         points->y = YLPTODP( dc, points->y );
87         points++;
88     }
89     GDI_ReleaseObj( hdc );
90     return TRUE;
91 }
92
93
94 /***********************************************************************
95  *           LPtoDP    (GDI32.247)
96  */
97 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
98 {
99     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
100     if (!dc) return FALSE;
101
102     while (count--)
103     {
104         INTERNAL_LPTODP( dc, points );
105         points++;
106     }
107     GDI_ReleaseObj( hdc );
108     return TRUE;
109 }
110
111
112 /***********************************************************************
113  *           SetMapMode16    (GDI.3)
114  */
115 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
116 {
117     return SetMapMode( hdc, mode );
118 }
119
120
121 /***********************************************************************
122  *           SetMapMode    (GDI32.321)
123  */
124 INT WINAPI SetMapMode( HDC hdc, INT mode )
125 {
126     INT prevMode;
127     DC * dc = DC_GetDCPtr( hdc );
128     if (!dc) return 0;
129     if (dc->funcs->pSetMapMode)
130     {
131         prevMode = dc->funcs->pSetMapMode( dc, mode );
132         goto done;
133     }
134
135     TRACE("%04x %d\n", hdc, mode );
136     
137     prevMode = dc->MapMode;
138     switch(mode)
139     {
140       case MM_TEXT:
141           dc->wndExtX   = 1;
142           dc->wndExtY   = 1;
143           dc->vportExtX = 1;
144           dc->vportExtY = 1;
145           break;
146           
147       case MM_LOMETRIC:
148       case MM_ISOTROPIC:
149           dc->wndExtX   = dc->devCaps->horzSize;
150           dc->wndExtY   = dc->devCaps->vertSize;
151           dc->vportExtX = dc->devCaps->horzRes / 10;
152           dc->vportExtY = dc->devCaps->vertRes / -10;
153           break;
154           
155       case MM_HIMETRIC:
156           dc->wndExtX   = dc->devCaps->horzSize * 10;
157           dc->wndExtY   = dc->devCaps->vertSize * 10;
158           dc->vportExtX = dc->devCaps->horzRes / 10;
159           dc->vportExtY = dc->devCaps->vertRes / -10;
160           break;
161           
162       case MM_LOENGLISH:
163           dc->wndExtX   = dc->devCaps->horzSize;
164           dc->wndExtY   = dc->devCaps->vertSize;
165           dc->vportExtX = 254L * dc->devCaps->horzRes / 1000;
166           dc->vportExtY = -254L * dc->devCaps->vertRes / 1000;
167           break;          
168           
169       case MM_HIENGLISH:
170           dc->wndExtX   = dc->devCaps->horzSize * 10;
171           dc->wndExtY   = dc->devCaps->vertSize * 10;
172           dc->vportExtX = 254L * dc->devCaps->horzRes / 1000;
173           dc->vportExtY = -254L * dc->devCaps->vertRes / 1000;
174           break;
175           
176       case MM_TWIPS:
177           dc->wndExtX   = 144L * dc->devCaps->horzSize / 10;
178           dc->wndExtY   = 144L * dc->devCaps->vertSize / 10;
179           dc->vportExtX = 254L * dc->devCaps->horzRes / 1000;
180           dc->vportExtY = -254L * dc->devCaps->vertRes / 1000;
181           break;
182           
183       case MM_ANISOTROPIC:
184           break;
185
186       default:
187           goto done;
188     }
189     dc->MapMode = mode;
190     DC_UpdateXforms( dc );
191  done:
192     GDI_ReleaseObj( hdc );
193     return prevMode;
194 }
195
196
197 /***********************************************************************
198  *           SetViewportExt    (GDI.14)
199  */
200 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
201 {
202     SIZE size;
203     if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
204     return MAKELONG( size.cx, size.cy );
205 }
206
207
208 /***********************************************************************
209  *           SetViewportExtEx16    (GDI.479)
210  */
211 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
212 {
213     SIZE size32;
214     BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
215     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
216     return ret;
217 }
218
219
220 /***********************************************************************
221  *           SetViewportExtEx    (GDI32.340)
222  */
223 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
224 {
225     BOOL ret = TRUE;
226     DC * dc = DC_GetDCPtr( hdc );
227     if (!dc) return FALSE;
228     if (dc->funcs->pSetViewportExt)
229     {
230         ret = dc->funcs->pSetViewportExt( dc, x, y );
231         goto done;
232     }
233     if (size)
234     {
235         size->cx = dc->vportExtX;
236         size->cy = dc->vportExtY;
237     }
238     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
239         goto done;
240     if (!x || !y)
241     {
242         ret = FALSE;
243         goto done;
244     }
245     dc->vportExtX = x;
246     dc->vportExtY = y;
247     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
248     DC_UpdateXforms( dc );
249  done:
250     GDI_ReleaseObj( hdc );
251     return ret;
252 }
253
254
255 /***********************************************************************
256  *           SetViewportOrg    (GDI.13)
257  */
258 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
259 {
260     POINT pt;
261     if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
262     return MAKELONG( pt.x, pt.y );
263 }
264
265
266 /***********************************************************************
267  *           SetViewportOrgEx16    (GDI.480)
268  */
269 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
270 {
271     POINT pt32;
272     BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
273     if (pt) CONV_POINT32TO16( &pt32, pt );
274     return ret;
275 }
276
277
278 /***********************************************************************
279  *           SetViewportOrgEx    (GDI32.341)
280  */
281 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
282 {
283     BOOL ret = TRUE;
284     DC * dc = DC_GetDCPtr( hdc );
285     if (!dc) return FALSE;
286     if (dc->funcs->pSetViewportOrg)
287         ret = dc->funcs->pSetViewportOrg( dc, x, y );
288     else
289     {
290         if (pt)
291         {
292             pt->x = dc->vportOrgX;
293             pt->y = dc->vportOrgY;
294         }
295         dc->vportOrgX = x;
296         dc->vportOrgY = y;
297         DC_UpdateXforms( dc );
298     }
299     GDI_ReleaseObj( hdc );
300     return ret;
301 }
302
303
304 /***********************************************************************
305  *           SetWindowExt    (GDI.12)
306  */
307 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
308 {
309     SIZE size;
310     if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
311     return MAKELONG( size.cx, size.cy );
312 }
313
314
315 /***********************************************************************
316  *           SetWindowExtEx16    (GDI.481)
317  */
318 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
319 {
320     SIZE size32;
321     BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
322     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
323     return ret;
324 }
325
326
327 /***********************************************************************
328  *           SetWindowExtEx    (GDI32.344)
329  */
330 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
331 {
332     BOOL ret = TRUE;
333     DC * dc = DC_GetDCPtr( hdc );
334     if (!dc) return FALSE;
335     if (dc->funcs->pSetWindowExt)
336     {
337         ret = dc->funcs->pSetWindowExt( dc, x, y );
338         goto done;
339     }
340     if (size)
341     {
342         size->cx = dc->wndExtX;
343         size->cy = dc->wndExtY;
344     }
345     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
346         goto done;
347     if (!x || !y)
348     {
349         ret = FALSE;
350         goto done;
351     }
352     dc->wndExtX = x;
353     dc->wndExtY = y;
354     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
355     DC_UpdateXforms( dc );
356  done:
357     GDI_ReleaseObj( hdc );
358     return ret;
359 }
360
361
362 /***********************************************************************
363  *           SetWindowOrg    (GDI.11)
364  */
365 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
366 {
367     POINT pt;
368     if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
369     return MAKELONG( pt.x, pt.y );
370 }
371
372
373 /***********************************************************************
374  *           SetWindowOrgEx16    (GDI.482)
375  */
376 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
377 {
378     POINT pt32;
379     BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
380     if (pt) CONV_POINT32TO16( &pt32, pt );
381     return ret;
382 }
383
384
385 /***********************************************************************
386  *           SetWindowOrgEx    (GDI32.345)
387  */
388 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
389 {
390     BOOL ret = TRUE;
391     DC * dc = DC_GetDCPtr( hdc );
392     if (!dc) return FALSE;
393     if (dc->funcs->pSetWindowOrg) ret = dc->funcs->pSetWindowOrg( dc, x, y );
394     else
395     {
396         if (pt)
397         {
398             pt->x = dc->wndOrgX;
399             pt->y = dc->wndOrgY;
400         }
401         dc->wndOrgX = x;
402         dc->wndOrgY = y;
403         DC_UpdateXforms( dc );
404     }
405     GDI_ReleaseObj( hdc );
406     return ret;
407 }
408
409
410 /***********************************************************************
411  *           OffsetViewportOrg    (GDI.17)
412  */
413 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
414 {
415     POINT pt;
416     if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
417     return MAKELONG( pt.x, pt.y );
418 }
419
420
421 /***********************************************************************
422  *           OffsetViewportOrgEx16    (GDI.476)
423  */
424 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
425 {
426     POINT pt32;
427     BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
428     if (pt) CONV_POINT32TO16( &pt32, pt );
429     return ret;
430 }
431
432
433 /***********************************************************************
434  *           OffsetViewportOrgEx    (GDI32.257)
435  */
436 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
437 {
438     BOOL ret = TRUE;
439     DC * dc = DC_GetDCPtr( hdc );
440     if (!dc) return FALSE;
441     if (dc->funcs->pOffsetViewportOrg)
442         ret = dc->funcs->pOffsetViewportOrg( dc, x, y );
443     else
444     {
445         if (pt)
446         {
447             pt->x = dc->vportOrgX;
448             pt->y = dc->vportOrgY;
449         }
450         dc->vportOrgX += x;
451         dc->vportOrgY += y;
452         DC_UpdateXforms( dc );
453     }
454     GDI_ReleaseObj( hdc );
455     return ret;
456 }
457
458
459 /***********************************************************************
460  *           OffsetWindowOrg    (GDI.15)
461  */
462 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
463 {
464     POINT pt;
465     if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
466     return MAKELONG( pt.x, pt.y );
467 }
468
469
470 /***********************************************************************
471  *           OffsetWindowOrgEx16    (GDI.477)
472  */
473 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
474 {
475     POINT pt32;
476     BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
477     if (pt) CONV_POINT32TO16( &pt32, pt );
478     return ret;
479 }
480
481
482 /***********************************************************************
483  *           OffsetWindowOrgEx    (GDI32.258)
484  */
485 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
486 {
487     BOOL ret = TRUE;
488     DC * dc = DC_GetDCPtr( hdc );
489     if (!dc) return FALSE;
490     if (dc->funcs->pOffsetWindowOrg)
491         ret = dc->funcs->pOffsetWindowOrg( dc, x, y );
492     else
493     {
494         if (pt)
495         {
496             pt->x = dc->wndOrgX;
497             pt->y = dc->wndOrgY;
498         }
499         dc->wndOrgX += x;
500         dc->wndOrgY += y;
501         DC_UpdateXforms( dc );
502     }
503     GDI_ReleaseObj( hdc );
504     return ret;
505 }
506
507
508 /***********************************************************************
509  *           ScaleViewportExt    (GDI.18)
510  */
511 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
512                                INT16 yNum, INT16 yDenom )
513 {
514     SIZE size;
515     if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
516         return FALSE;
517     return MAKELONG( size.cx,  size.cy );
518 }
519
520
521 /***********************************************************************
522  *           ScaleViewportExtEx16    (GDI.484)
523  */
524 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
525                                     INT16 yNum, INT16 yDenom, LPSIZE16 size )
526 {
527     SIZE size32;
528     BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
529                                        &size32 );
530     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
531     return ret;
532 }
533
534
535 /***********************************************************************
536  *           ScaleViewportExtEx    (GDI32.293)
537  */
538 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
539                                     INT yNum, INT yDenom, LPSIZE size )
540 {
541     BOOL ret = TRUE;
542     DC * dc = DC_GetDCPtr( hdc );
543     if (!dc) return FALSE;
544     if (dc->funcs->pScaleViewportExt)
545     {
546         ret = dc->funcs->pScaleViewportExt( dc, xNum, xDenom, yNum, yDenom );
547         goto done;
548     }
549     if (size)
550     {
551         size->cx = dc->vportExtX;
552         size->cy = dc->vportExtY;
553     }
554     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
555         goto done;
556     if (!xNum || !xDenom || !xNum || !yDenom)
557     {
558         ret = FALSE;
559         goto done;
560     }
561     dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
562     dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
563     if (dc->vportExtX == 0) dc->vportExtX = 1;
564     if (dc->vportExtY == 0) dc->vportExtY = 1;
565     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
566     DC_UpdateXforms( dc );
567  done:
568     GDI_ReleaseObj( hdc );
569     return ret;
570 }
571
572
573 /***********************************************************************
574  *           ScaleWindowExt    (GDI.16)
575  */
576 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
577                              INT16 yNum, INT16 yDenom )
578 {
579     SIZE size;
580     if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
581         return FALSE;
582     return MAKELONG( size.cx,  size.cy );
583 }
584
585
586 /***********************************************************************
587  *           ScaleWindowExtEx16    (GDI.485)
588  */
589 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
590                                   INT16 yNum, INT16 yDenom, LPSIZE16 size )
591 {
592     SIZE size32;
593     BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
594                                      &size32 );
595     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
596     return ret;
597 }
598
599
600 /***********************************************************************
601  *           ScaleWindowExtEx    (GDI32.294)
602  */
603 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
604                                   INT yNum, INT yDenom, LPSIZE size )
605 {
606     BOOL ret = TRUE;
607     DC * dc = DC_GetDCPtr( hdc );
608     if (!dc) return FALSE;
609     if (dc->funcs->pScaleWindowExt)
610     {
611         ret = dc->funcs->pScaleWindowExt( dc, xNum, xDenom, yNum, yDenom );
612         goto done;
613     }
614     if (size)
615     {
616         size->cx = dc->wndExtX;
617         size->cy = dc->wndExtY;
618     }
619     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
620         goto done;
621     if (!xNum || !xDenom || !xNum || !yDenom)
622     {
623         ret = FALSE;
624         goto done;
625     }
626     dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
627     dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
628     if (dc->wndExtX == 0) dc->wndExtX = 1;
629     if (dc->wndExtY == 0) dc->wndExtY = 1;
630     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
631     DC_UpdateXforms( dc );
632  done:
633     GDI_ReleaseObj( hdc );
634     return ret;
635 }