2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
8 #include "debugtools.h"
10 DEFAULT_DEBUG_CHANNEL(gdi
);
13 /***********************************************************************
14 * MAPPING_FixIsotropic
16 * Fix viewport extensions for isotropic mode.
18 void MAPPING_FixIsotropic( DC
* dc
)
20 double xdim
= (double)dc
->vportExtX
* GetDeviceCaps( dc
->hSelf
, HORZSIZE
) /
21 (GetDeviceCaps( dc
->hSelf
, HORZRES
) * dc
->wndExtX
);
22 double ydim
= (double)dc
->vportExtY
* GetDeviceCaps( dc
->hSelf
, VERTSIZE
) /
23 (GetDeviceCaps( dc
->hSelf
, VERTRES
) * dc
->wndExtY
);
26 dc
->vportExtX
= dc
->vportExtX
* fabs( ydim
/ xdim
);
27 if (!dc
->vportExtX
) dc
->vportExtX
= 1;
31 dc
->vportExtY
= dc
->vportExtY
* fabs( xdim
/ ydim
);
32 if (!dc
->vportExtY
) dc
->vportExtY
= 1;
37 /***********************************************************************
40 BOOL16 WINAPI
DPtoLP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
42 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
43 if (!dc
) return FALSE
;
47 points
->x
= XDPTOLP( dc
, points
->x
);
48 points
->y
= YDPTOLP( dc
, points
->y
);
51 GDI_ReleaseObj( hdc
);
56 /***********************************************************************
59 BOOL WINAPI
DPtoLP( HDC hdc
, LPPOINT points
, INT count
)
61 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
62 if (!dc
) return FALSE
;
66 if (!INTERNAL_DPTOLP( dc
, points
))
70 GDI_ReleaseObj( hdc
);
75 /***********************************************************************
78 BOOL16 WINAPI
LPtoDP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
80 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
81 if (!dc
) return FALSE
;
85 points
->x
= XLPTODP( dc
, points
->x
);
86 points
->y
= YLPTODP( dc
, points
->y
);
89 GDI_ReleaseObj( hdc
);
94 /***********************************************************************
97 BOOL WINAPI
LPtoDP( HDC hdc
, LPPOINT points
, INT count
)
99 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
100 if (!dc
) return FALSE
;
104 INTERNAL_LPTODP( dc
, points
);
107 GDI_ReleaseObj( hdc
);
112 /***********************************************************************
115 INT16 WINAPI
SetMapMode16( HDC16 hdc
, INT16 mode
)
117 return SetMapMode( hdc
, mode
);
121 /***********************************************************************
122 * SetMapMode (GDI32.@)
124 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
127 INT horzSize
, vertSize
, horzRes
, vertRes
;
129 DC
* dc
= DC_GetDCPtr( hdc
);
131 if (dc
->funcs
->pSetMapMode
)
133 prevMode
= dc
->funcs
->pSetMapMode( dc
, mode
);
137 TRACE("%04x %d\n", hdc
, mode
);
139 prevMode
= dc
->MapMode
;
140 horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
141 vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
142 horzRes
= GetDeviceCaps( hdc
, HORZRES
);
143 vertRes
= GetDeviceCaps( hdc
, VERTRES
);
154 dc
->wndExtX
= horzSize
;
155 dc
->wndExtY
= vertSize
;
156 dc
->vportExtX
= horzRes
/ 10;
157 dc
->vportExtY
= vertRes
/ -10;
160 dc
->wndExtX
= horzSize
* 10;
161 dc
->wndExtY
= vertSize
* 10;
162 dc
->vportExtX
= horzRes
/ 10;
163 dc
->vportExtY
= vertRes
/ -10;
166 dc
->wndExtX
= horzSize
;
167 dc
->wndExtY
= vertSize
;
168 dc
->vportExtX
= 254L * horzRes
/ 1000;
169 dc
->vportExtY
= -254L * vertRes
/ 1000;
172 dc
->wndExtX
= horzSize
* 10;
173 dc
->wndExtY
= vertSize
* 10;
174 dc
->vportExtX
= 254L * horzRes
/ 1000;
175 dc
->vportExtY
= -254L * vertRes
/ 1000;
178 dc
->wndExtX
= 144L * horzSize
/ 10;
179 dc
->wndExtY
= 144L * vertSize
/ 10;
180 dc
->vportExtX
= 254L * horzRes
/ 1000;
181 dc
->vportExtY
= -254L * vertRes
/ 1000;
189 DC_UpdateXforms( dc
);
191 GDI_ReleaseObj( hdc
);
196 /***********************************************************************
197 * SetViewportExt (GDI.14)
199 DWORD WINAPI
SetViewportExt16( HDC16 hdc
, INT16 x
, INT16 y
)
202 if (!SetViewportExtEx( hdc
, x
, y
, &size
)) return 0;
203 return MAKELONG( size
.cx
, size
.cy
);
207 /***********************************************************************
208 * SetViewportExtEx (GDI.479)
210 BOOL16 WINAPI
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
213 BOOL16 ret
= SetViewportExtEx( hdc
, x
, y
, &size32
);
214 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
219 /***********************************************************************
220 * SetViewportExtEx (GDI32.@)
222 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
225 DC
* dc
= DC_GetDCPtr( hdc
);
226 if (!dc
) return FALSE
;
227 if (dc
->funcs
->pSetViewportExt
)
229 ret
= dc
->funcs
->pSetViewportExt( dc
, x
, y
);
234 size
->cx
= dc
->vportExtX
;
235 size
->cy
= dc
->vportExtY
;
237 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
246 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
247 DC_UpdateXforms( dc
);
249 GDI_ReleaseObj( hdc
);
254 /***********************************************************************
255 * SetViewportOrg (GDI.13)
257 DWORD WINAPI
SetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
260 if (!SetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
261 return MAKELONG( pt
.x
, pt
.y
);
265 /***********************************************************************
266 * SetViewportOrgEx (GDI.480)
268 BOOL16 WINAPI
SetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
271 BOOL16 ret
= SetViewportOrgEx( hdc
, x
, y
, &pt32
);
272 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
277 /***********************************************************************
278 * SetViewportOrgEx (GDI32.@)
280 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
283 DC
* dc
= DC_GetDCPtr( hdc
);
284 if (!dc
) return FALSE
;
285 if (dc
->funcs
->pSetViewportOrg
)
286 ret
= dc
->funcs
->pSetViewportOrg( dc
, x
, y
);
291 pt
->x
= dc
->vportOrgX
;
292 pt
->y
= dc
->vportOrgY
;
296 DC_UpdateXforms( dc
);
298 GDI_ReleaseObj( hdc
);
303 /***********************************************************************
304 * SetWindowExt (GDI.12)
306 DWORD WINAPI
SetWindowExt16( HDC16 hdc
, INT16 x
, INT16 y
)
309 if (!SetWindowExtEx( hdc
, x
, y
, &size
)) return 0;
310 return MAKELONG( size
.cx
, size
.cy
);
314 /***********************************************************************
315 * SetWindowExtEx (GDI.481)
317 BOOL16 WINAPI
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
320 BOOL16 ret
= SetWindowExtEx( hdc
, x
, y
, &size32
);
321 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
326 /***********************************************************************
327 * SetWindowExtEx (GDI32.@)
329 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
332 DC
* dc
= DC_GetDCPtr( hdc
);
333 if (!dc
) return FALSE
;
334 if (dc
->funcs
->pSetWindowExt
)
336 ret
= dc
->funcs
->pSetWindowExt( dc
, x
, y
);
341 size
->cx
= dc
->wndExtX
;
342 size
->cy
= dc
->wndExtY
;
344 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
353 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
354 DC_UpdateXforms( dc
);
356 GDI_ReleaseObj( hdc
);
361 /***********************************************************************
362 * SetWindowOrg (GDI.11)
364 DWORD WINAPI
SetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
367 if (!SetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
368 return MAKELONG( pt
.x
, pt
.y
);
372 /***********************************************************************
373 * SetWindowOrgEx (GDI.482)
375 BOOL16 WINAPI
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
378 BOOL16 ret
= SetWindowOrgEx( hdc
, x
, y
, &pt32
);
379 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
384 /***********************************************************************
385 * SetWindowOrgEx (GDI32.@)
387 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
390 DC
* dc
= DC_GetDCPtr( hdc
);
391 if (!dc
) return FALSE
;
392 if (dc
->funcs
->pSetWindowOrg
) ret
= dc
->funcs
->pSetWindowOrg( dc
, x
, y
);
402 DC_UpdateXforms( dc
);
404 GDI_ReleaseObj( hdc
);
409 /***********************************************************************
410 * OffsetViewportOrg (GDI.17)
412 DWORD WINAPI
OffsetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
415 if (!OffsetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
416 return MAKELONG( pt
.x
, pt
.y
);
420 /***********************************************************************
421 * OffsetViewportOrgEx (GDI.476)
423 BOOL16 WINAPI
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
426 BOOL16 ret
= OffsetViewportOrgEx( hdc
, x
, y
, &pt32
);
427 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
432 /***********************************************************************
433 * OffsetViewportOrgEx (GDI32.@)
435 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
438 DC
* dc
= DC_GetDCPtr( hdc
);
439 if (!dc
) return FALSE
;
440 if (dc
->funcs
->pOffsetViewportOrg
)
441 ret
= dc
->funcs
->pOffsetViewportOrg( dc
, x
, y
);
446 pt
->x
= dc
->vportOrgX
;
447 pt
->y
= dc
->vportOrgY
;
451 DC_UpdateXforms( dc
);
453 GDI_ReleaseObj( hdc
);
458 /***********************************************************************
459 * OffsetWindowOrg (GDI.15)
461 DWORD WINAPI
OffsetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
464 if (!OffsetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
465 return MAKELONG( pt
.x
, pt
.y
);
469 /***********************************************************************
470 * OffsetWindowOrgEx (GDI.477)
472 BOOL16 WINAPI
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
475 BOOL16 ret
= OffsetWindowOrgEx( hdc
, x
, y
, &pt32
);
476 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
481 /***********************************************************************
482 * OffsetWindowOrgEx (GDI32.@)
484 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
487 DC
* dc
= DC_GetDCPtr( hdc
);
488 if (!dc
) return FALSE
;
489 if (dc
->funcs
->pOffsetWindowOrg
)
490 ret
= dc
->funcs
->pOffsetWindowOrg( dc
, x
, y
);
500 DC_UpdateXforms( dc
);
502 GDI_ReleaseObj( hdc
);
507 /***********************************************************************
508 * ScaleViewportExt (GDI.18)
510 DWORD WINAPI
ScaleViewportExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
511 INT16 yNum
, INT16 yDenom
)
514 if (!ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
516 return MAKELONG( size
.cx
, size
.cy
);
520 /***********************************************************************
521 * ScaleViewportExtEx (GDI.484)
523 BOOL16 WINAPI
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
524 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
527 BOOL16 ret
= ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
529 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
534 /***********************************************************************
535 * ScaleViewportExtEx (GDI32.@)
537 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
538 INT yNum
, INT yDenom
, LPSIZE size
)
541 DC
* dc
= DC_GetDCPtr( hdc
);
542 if (!dc
) return FALSE
;
543 if (dc
->funcs
->pScaleViewportExt
)
545 ret
= dc
->funcs
->pScaleViewportExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
550 size
->cx
= dc
->vportExtX
;
551 size
->cy
= dc
->vportExtY
;
553 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
555 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
560 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
561 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
562 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
563 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
564 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
565 DC_UpdateXforms( dc
);
567 GDI_ReleaseObj( hdc
);
572 /***********************************************************************
573 * ScaleWindowExt (GDI.16)
575 DWORD WINAPI
ScaleWindowExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
576 INT16 yNum
, INT16 yDenom
)
579 if (!ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
581 return MAKELONG( size
.cx
, size
.cy
);
585 /***********************************************************************
586 * ScaleWindowExtEx (GDI.485)
588 BOOL16 WINAPI
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
589 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
592 BOOL16 ret
= ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
594 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
599 /***********************************************************************
600 * ScaleWindowExtEx (GDI32.@)
602 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
603 INT yNum
, INT yDenom
, LPSIZE size
)
606 DC
* dc
= DC_GetDCPtr( hdc
);
607 if (!dc
) return FALSE
;
608 if (dc
->funcs
->pScaleWindowExt
)
610 ret
= dc
->funcs
->pScaleWindowExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
615 size
->cx
= dc
->wndExtX
;
616 size
->cy
= dc
->wndExtY
;
618 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
620 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
625 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
626 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
627 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
628 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
629 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
630 DC_UpdateXforms( dc
);
632 GDI_ReleaseObj( hdc
);