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
* dc
->devCaps
->horzSize
/
21 (dc
->devCaps
->horzRes
* dc
->wndExtX
);
22 double ydim
= (double)dc
->vportExtY
* dc
->devCaps
->vertSize
/
23 (dc
->devCaps
->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 /***********************************************************************
113 * SetMapMode16 (GDI.3)
115 INT16 WINAPI
SetMapMode16( HDC16 hdc
, INT16 mode
)
117 return SetMapMode( hdc
, mode
);
121 /***********************************************************************
122 * SetMapMode (GDI32.321)
124 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
127 DC
* dc
= DC_GetDCPtr( hdc
);
129 if (dc
->funcs
->pSetMapMode
)
131 prevMode
= dc
->funcs
->pSetMapMode( dc
, mode
);
135 TRACE("%04x %d\n", hdc
, mode
);
137 prevMode
= dc
->MapMode
;
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;
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;
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;
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;
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;
190 DC_UpdateXforms( dc
);
192 GDI_ReleaseObj( hdc
);
197 /***********************************************************************
198 * SetViewportExt (GDI.14)
200 DWORD WINAPI
SetViewportExt16( HDC16 hdc
, INT16 x
, INT16 y
)
203 if (!SetViewportExtEx( hdc
, x
, y
, &size
)) return 0;
204 return MAKELONG( size
.cx
, size
.cy
);
208 /***********************************************************************
209 * SetViewportExtEx16 (GDI.479)
211 BOOL16 WINAPI
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
214 BOOL16 ret
= SetViewportExtEx( hdc
, x
, y
, &size32
);
215 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
220 /***********************************************************************
221 * SetViewportExtEx (GDI32.340)
223 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
226 DC
* dc
= DC_GetDCPtr( hdc
);
227 if (!dc
) return FALSE
;
228 if (dc
->funcs
->pSetViewportExt
)
230 ret
= dc
->funcs
->pSetViewportExt( dc
, x
, y
);
235 size
->cx
= dc
->vportExtX
;
236 size
->cy
= dc
->vportExtY
;
238 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
247 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
248 DC_UpdateXforms( dc
);
250 GDI_ReleaseObj( hdc
);
255 /***********************************************************************
256 * SetViewportOrg (GDI.13)
258 DWORD WINAPI
SetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
261 if (!SetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
262 return MAKELONG( pt
.x
, pt
.y
);
266 /***********************************************************************
267 * SetViewportOrgEx16 (GDI.480)
269 BOOL16 WINAPI
SetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
272 BOOL16 ret
= SetViewportOrgEx( hdc
, x
, y
, &pt32
);
273 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
278 /***********************************************************************
279 * SetViewportOrgEx (GDI32.341)
281 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
284 DC
* dc
= DC_GetDCPtr( hdc
);
285 if (!dc
) return FALSE
;
286 if (dc
->funcs
->pSetViewportOrg
)
287 ret
= dc
->funcs
->pSetViewportOrg( dc
, x
, y
);
292 pt
->x
= dc
->vportOrgX
;
293 pt
->y
= dc
->vportOrgY
;
297 DC_UpdateXforms( dc
);
299 GDI_ReleaseObj( hdc
);
304 /***********************************************************************
305 * SetWindowExt (GDI.12)
307 DWORD WINAPI
SetWindowExt16( HDC16 hdc
, INT16 x
, INT16 y
)
310 if (!SetWindowExtEx( hdc
, x
, y
, &size
)) return 0;
311 return MAKELONG( size
.cx
, size
.cy
);
315 /***********************************************************************
316 * SetWindowExtEx16 (GDI.481)
318 BOOL16 WINAPI
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
321 BOOL16 ret
= SetWindowExtEx( hdc
, x
, y
, &size32
);
322 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
327 /***********************************************************************
328 * SetWindowExtEx (GDI32.344)
330 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
333 DC
* dc
= DC_GetDCPtr( hdc
);
334 if (!dc
) return FALSE
;
335 if (dc
->funcs
->pSetWindowExt
)
337 ret
= dc
->funcs
->pSetWindowExt( dc
, x
, y
);
342 size
->cx
= dc
->wndExtX
;
343 size
->cy
= dc
->wndExtY
;
345 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
354 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
355 DC_UpdateXforms( dc
);
357 GDI_ReleaseObj( hdc
);
362 /***********************************************************************
363 * SetWindowOrg (GDI.11)
365 DWORD WINAPI
SetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
368 if (!SetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
369 return MAKELONG( pt
.x
, pt
.y
);
373 /***********************************************************************
374 * SetWindowOrgEx16 (GDI.482)
376 BOOL16 WINAPI
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
379 BOOL16 ret
= SetWindowOrgEx( hdc
, x
, y
, &pt32
);
380 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
385 /***********************************************************************
386 * SetWindowOrgEx (GDI32.345)
388 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
391 DC
* dc
= DC_GetDCPtr( hdc
);
392 if (!dc
) return FALSE
;
393 if (dc
->funcs
->pSetWindowOrg
) ret
= dc
->funcs
->pSetWindowOrg( dc
, x
, y
);
403 DC_UpdateXforms( dc
);
405 GDI_ReleaseObj( hdc
);
410 /***********************************************************************
411 * OffsetViewportOrg (GDI.17)
413 DWORD WINAPI
OffsetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
416 if (!OffsetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
417 return MAKELONG( pt
.x
, pt
.y
);
421 /***********************************************************************
422 * OffsetViewportOrgEx16 (GDI.476)
424 BOOL16 WINAPI
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
427 BOOL16 ret
= OffsetViewportOrgEx( hdc
, x
, y
, &pt32
);
428 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
433 /***********************************************************************
434 * OffsetViewportOrgEx (GDI32.257)
436 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
439 DC
* dc
= DC_GetDCPtr( hdc
);
440 if (!dc
) return FALSE
;
441 if (dc
->funcs
->pOffsetViewportOrg
)
442 ret
= dc
->funcs
->pOffsetViewportOrg( dc
, x
, y
);
447 pt
->x
= dc
->vportOrgX
;
448 pt
->y
= dc
->vportOrgY
;
452 DC_UpdateXforms( dc
);
454 GDI_ReleaseObj( hdc
);
459 /***********************************************************************
460 * OffsetWindowOrg (GDI.15)
462 DWORD WINAPI
OffsetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
465 if (!OffsetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
466 return MAKELONG( pt
.x
, pt
.y
);
470 /***********************************************************************
471 * OffsetWindowOrgEx16 (GDI.477)
473 BOOL16 WINAPI
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
476 BOOL16 ret
= OffsetWindowOrgEx( hdc
, x
, y
, &pt32
);
477 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
482 /***********************************************************************
483 * OffsetWindowOrgEx (GDI32.258)
485 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
488 DC
* dc
= DC_GetDCPtr( hdc
);
489 if (!dc
) return FALSE
;
490 if (dc
->funcs
->pOffsetWindowOrg
)
491 ret
= dc
->funcs
->pOffsetWindowOrg( dc
, x
, y
);
501 DC_UpdateXforms( dc
);
503 GDI_ReleaseObj( hdc
);
508 /***********************************************************************
509 * ScaleViewportExt (GDI.18)
511 DWORD WINAPI
ScaleViewportExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
512 INT16 yNum
, INT16 yDenom
)
515 if (!ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
517 return MAKELONG( size
.cx
, size
.cy
);
521 /***********************************************************************
522 * ScaleViewportExtEx16 (GDI.484)
524 BOOL16 WINAPI
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
525 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
528 BOOL16 ret
= ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
530 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
535 /***********************************************************************
536 * ScaleViewportExtEx (GDI32.293)
538 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
539 INT yNum
, INT yDenom
, LPSIZE size
)
542 DC
* dc
= DC_GetDCPtr( hdc
);
543 if (!dc
) return FALSE
;
544 if (dc
->funcs
->pScaleViewportExt
)
546 ret
= dc
->funcs
->pScaleViewportExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
551 size
->cx
= dc
->vportExtX
;
552 size
->cy
= dc
->vportExtY
;
554 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
556 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
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
);
568 GDI_ReleaseObj( hdc
);
573 /***********************************************************************
574 * ScaleWindowExt (GDI.16)
576 DWORD WINAPI
ScaleWindowExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
577 INT16 yNum
, INT16 yDenom
)
580 if (!ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
582 return MAKELONG( size
.cx
, size
.cy
);
586 /***********************************************************************
587 * ScaleWindowExtEx16 (GDI.485)
589 BOOL16 WINAPI
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
590 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
593 BOOL16 ret
= ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
595 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
600 /***********************************************************************
601 * ScaleWindowExtEx (GDI32.294)
603 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
604 INT yNum
, INT yDenom
, LPSIZE size
)
607 DC
* dc
= DC_GetDCPtr( hdc
);
608 if (!dc
) return FALSE
;
609 if (dc
->funcs
->pScaleWindowExt
)
611 ret
= dc
->funcs
->pScaleWindowExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
616 size
->cx
= dc
->wndExtX
;
617 size
->cy
= dc
->wndExtY
;
619 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
621 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
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
);
633 GDI_ReleaseObj( hdc
);