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
->w
.devCaps
->horzSize
/
21 (dc
->w
.devCaps
->horzRes
* dc
->wndExtX
);
22 double ydim
= (double)dc
->vportExtY
* dc
->w
.devCaps
->vertSize
/
23 (dc
->w
.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
);
55 /***********************************************************************
58 BOOL WINAPI
DPtoLP( HDC hdc
, LPPOINT points
, INT count
)
60 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
61 if (!dc
) return FALSE
;
65 if (!INTERNAL_DPTOLP( dc
, points
))
73 /***********************************************************************
76 BOOL16 WINAPI
LPtoDP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
78 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
79 if (!dc
) return FALSE
;
83 points
->x
= XLPTODP( dc
, points
->x
);
84 points
->y
= YLPTODP( dc
, points
->y
);
91 /***********************************************************************
92 * LPtoDP32 (GDI32.247)
94 BOOL WINAPI
LPtoDP( HDC hdc
, LPPOINT points
, INT count
)
96 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
97 if (!dc
) return FALSE
;
101 INTERNAL_LPTODP( dc
, points
);
108 /***********************************************************************
109 * SetMapMode16 (GDI.3)
111 INT16 WINAPI
SetMapMode16( HDC16 hdc
, INT16 mode
)
113 return SetMapMode( hdc
, mode
);
117 /***********************************************************************
118 * SetMapMode32 (GDI32.321)
120 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
123 DC
* dc
= DC_GetDCPtr( hdc
);
125 if (dc
->funcs
->pSetMapMode
) return dc
->funcs
->pSetMapMode( dc
, mode
);
127 TRACE("%04x %d\n", hdc
, mode
);
129 prevMode
= dc
->w
.MapMode
;
141 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
142 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
143 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
144 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
148 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
149 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
150 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
151 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
155 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
156 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
157 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
158 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
162 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
163 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
164 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
165 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
169 dc
->wndExtX
= 144L * dc
->w
.devCaps
->horzSize
/ 10;
170 dc
->wndExtY
= 144L * dc
->w
.devCaps
->vertSize
/ 10;
171 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
172 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
181 dc
->w
.MapMode
= mode
;
182 DC_UpdateXforms( dc
);
187 /***********************************************************************
188 * SetViewportExt (GDI.14)
190 DWORD WINAPI
SetViewportExt16( HDC16 hdc
, INT16 x
, INT16 y
)
193 if (!SetViewportExtEx( hdc
, x
, y
, &size
)) return 0;
194 return MAKELONG( size
.cx
, size
.cy
);
198 /***********************************************************************
199 * SetViewportExtEx16 (GDI.479)
201 BOOL16 WINAPI
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
204 BOOL16 ret
= SetViewportExtEx( hdc
, x
, y
, &size32
);
205 if (size
) CONV_SIZE32TO16( &size32
, size
);
210 /***********************************************************************
211 * SetViewportExtEx32 (GDI32.340)
213 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
215 DC
* dc
= DC_GetDCPtr( hdc
);
216 if (!dc
) return FALSE
;
217 if (dc
->funcs
->pSetViewportExt
)
218 return dc
->funcs
->pSetViewportExt( dc
, x
, y
);
221 size
->cx
= dc
->vportExtX
;
222 size
->cy
= dc
->vportExtY
;
224 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
226 if (!x
|| !y
) return FALSE
;
229 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
230 DC_UpdateXforms( dc
);
235 /***********************************************************************
236 * SetViewportOrg (GDI.13)
238 DWORD WINAPI
SetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
241 if (!SetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
242 return MAKELONG( pt
.x
, pt
.y
);
246 /***********************************************************************
247 * SetViewportOrgEx16 (GDI.480)
249 BOOL16 WINAPI
SetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
252 BOOL16 ret
= SetViewportOrgEx( hdc
, x
, y
, &pt32
);
253 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
258 /***********************************************************************
259 * SetViewportOrgEx32 (GDI32.341)
261 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
263 DC
* dc
= DC_GetDCPtr( hdc
);
264 if (!dc
) return FALSE
;
265 if (dc
->funcs
->pSetViewportOrg
)
266 return dc
->funcs
->pSetViewportOrg( dc
, x
, y
);
269 pt
->x
= dc
->vportOrgX
;
270 pt
->y
= dc
->vportOrgY
;
274 DC_UpdateXforms( dc
);
279 /***********************************************************************
280 * SetWindowExt (GDI.12)
282 DWORD WINAPI
SetWindowExt16( HDC16 hdc
, INT16 x
, INT16 y
)
285 if (!SetWindowExtEx( hdc
, x
, y
, &size
)) return 0;
286 return MAKELONG( size
.cx
, size
.cy
);
290 /***********************************************************************
291 * SetWindowExtEx16 (GDI.481)
293 BOOL16 WINAPI
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
296 BOOL16 ret
= SetWindowExtEx( hdc
, x
, y
, &size32
);
297 if (size
) CONV_SIZE32TO16( &size32
, size
);
302 /***********************************************************************
303 * SetWindowExtEx32 (GDI32.344)
305 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
307 DC
* dc
= DC_GetDCPtr( hdc
);
308 if (!dc
) return FALSE
;
309 if (dc
->funcs
->pSetWindowExt
) return dc
->funcs
->pSetWindowExt( dc
, x
, y
);
312 size
->cx
= dc
->wndExtX
;
313 size
->cy
= dc
->wndExtY
;
315 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
317 if (!x
|| !y
) return FALSE
;
320 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
321 DC_UpdateXforms( dc
);
326 /***********************************************************************
327 * SetWindowOrg (GDI.11)
329 DWORD WINAPI
SetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
332 if (!SetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
333 return MAKELONG( pt
.x
, pt
.y
);
337 /***********************************************************************
338 * SetWindowOrgEx16 (GDI.482)
340 BOOL16 WINAPI
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
343 BOOL16 ret
= SetWindowOrgEx( hdc
, x
, y
, &pt32
);
344 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
349 /***********************************************************************
350 * SetWindowOrgEx32 (GDI32.345)
352 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
354 DC
* dc
= DC_GetDCPtr( hdc
);
355 if (!dc
) return FALSE
;
356 if (dc
->funcs
->pSetWindowOrg
) return dc
->funcs
->pSetWindowOrg( dc
, x
, y
);
364 DC_UpdateXforms( dc
);
369 /***********************************************************************
370 * OffsetViewportOrg (GDI.17)
372 DWORD WINAPI
OffsetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
375 if (!OffsetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
376 return MAKELONG( pt
.x
, pt
.y
);
380 /***********************************************************************
381 * OffsetViewportOrgEx16 (GDI.476)
383 BOOL16 WINAPI
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
386 BOOL16 ret
= OffsetViewportOrgEx( hdc
, x
, y
, &pt32
);
387 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
392 /***********************************************************************
393 * OffsetViewportOrgEx32 (GDI32.257)
395 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
397 DC
* dc
= DC_GetDCPtr( hdc
);
398 if (!dc
) return FALSE
;
399 if (dc
->funcs
->pOffsetViewportOrg
)
400 return dc
->funcs
->pOffsetViewportOrg( dc
, x
, y
);
403 pt
->x
= dc
->vportOrgX
;
404 pt
->y
= dc
->vportOrgY
;
408 DC_UpdateXforms( dc
);
413 /***********************************************************************
414 * OffsetWindowOrg (GDI.15)
416 DWORD WINAPI
OffsetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
419 if (!OffsetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
420 return MAKELONG( pt
.x
, pt
.y
);
424 /***********************************************************************
425 * OffsetWindowOrgEx16 (GDI.477)
427 BOOL16 WINAPI
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
430 BOOL16 ret
= OffsetWindowOrgEx( hdc
, x
, y
, &pt32
);
431 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
436 /***********************************************************************
437 * OffsetWindowOrgEx32 (GDI32.258)
439 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
441 DC
* dc
= DC_GetDCPtr( hdc
);
442 if (!dc
) return FALSE
;
443 if (dc
->funcs
->pOffsetWindowOrg
)
444 return dc
->funcs
->pOffsetWindowOrg( dc
, x
, y
);
452 DC_UpdateXforms( dc
);
457 /***********************************************************************
458 * ScaleViewportExt (GDI.18)
460 DWORD WINAPI
ScaleViewportExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
461 INT16 yNum
, INT16 yDenom
)
464 if (!ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
466 return MAKELONG( size
.cx
, size
.cy
);
470 /***********************************************************************
471 * ScaleViewportExtEx16 (GDI.484)
473 BOOL16 WINAPI
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
474 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
477 BOOL16 ret
= ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
479 if (size
) CONV_SIZE32TO16( &size32
, size
);
484 /***********************************************************************
485 * ScaleViewportExtEx32 (GDI32.293)
487 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
488 INT yNum
, INT yDenom
, LPSIZE size
)
490 DC
* dc
= DC_GetDCPtr( hdc
);
491 if (!dc
) return FALSE
;
492 if (dc
->funcs
->pScaleViewportExt
)
493 return dc
->funcs
->pScaleViewportExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
496 size
->cx
= dc
->vportExtX
;
497 size
->cy
= dc
->vportExtY
;
499 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
501 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
502 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
503 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
504 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
505 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
506 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
507 DC_UpdateXforms( dc
);
512 /***********************************************************************
513 * ScaleWindowExt (GDI.16)
515 DWORD WINAPI
ScaleWindowExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
516 INT16 yNum
, INT16 yDenom
)
519 if (!ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
521 return MAKELONG( size
.cx
, size
.cy
);
525 /***********************************************************************
526 * ScaleWindowExtEx16 (GDI.485)
528 BOOL16 WINAPI
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
529 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
532 BOOL16 ret
= ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
534 if (size
) CONV_SIZE32TO16( &size32
, size
);
539 /***********************************************************************
540 * ScaleWindowExtEx32 (GDI32.294)
542 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
543 INT yNum
, INT yDenom
, LPSIZE size
)
545 DC
* dc
= DC_GetDCPtr( hdc
);
546 if (!dc
) return FALSE
;
547 if (dc
->funcs
->pScaleWindowExt
)
548 return dc
->funcs
->pScaleWindowExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
551 size
->cx
= dc
->wndExtX
;
552 size
->cy
= dc
->wndExtY
;
554 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
556 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
557 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
558 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
559 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
560 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
561 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
562 DC_UpdateXforms( dc
);