Define environment variable TMP as an alias for TEMP.
[wine.git] / graphics / mapping.c
blob4bf481550b01124860aed4936c1998bb3399a7f1
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "gdi.h"
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);
24 if (xdim > ydim)
26 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
27 if (!dc->vportExtX) dc->vportExtX = 1;
29 else
31 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
32 if (!dc->vportExtY) dc->vportExtY = 1;
37 /***********************************************************************
38 * DPtoLP16 (GDI.67)
40 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
42 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
43 if (!dc) return FALSE;
45 while (count--)
47 points->x = XDPTOLP( dc, points->x );
48 points->y = YDPTOLP( dc, points->y );
49 points++;
51 GDI_ReleaseObj( hdc );
52 return TRUE;
56 /***********************************************************************
57 * DPtoLP (GDI32.65)
59 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
61 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
62 if (!dc) return FALSE;
64 while (count--)
66 if (!INTERNAL_DPTOLP( dc, points ))
67 break;
68 points++;
70 GDI_ReleaseObj( hdc );
71 return (count < 0);
75 /***********************************************************************
76 * LPtoDP16 (GDI.99)
78 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
80 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
81 if (!dc) return FALSE;
83 while (count--)
85 points->x = XLPTODP( dc, points->x );
86 points->y = YLPTODP( dc, points->y );
87 points++;
89 GDI_ReleaseObj( hdc );
90 return TRUE;
94 /***********************************************************************
95 * LPtoDP (GDI32.247)
97 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
99 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
100 if (!dc) return FALSE;
102 while (count--)
104 INTERNAL_LPTODP( dc, points );
105 points++;
107 GDI_ReleaseObj( hdc );
108 return TRUE;
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 )
126 INT prevMode;
127 DC * dc = DC_GetDCPtr( hdc );
128 if (!dc) return 0;
129 if (dc->funcs->pSetMapMode)
131 prevMode = dc->funcs->pSetMapMode( dc, mode );
132 goto done;
135 TRACE("%04x %d\n", hdc, mode );
137 prevMode = dc->MapMode;
138 switch(mode)
140 case MM_TEXT:
141 dc->wndExtX = 1;
142 dc->wndExtY = 1;
143 dc->vportExtX = 1;
144 dc->vportExtY = 1;
145 break;
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;
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;
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;
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;
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;
183 case MM_ANISOTROPIC:
184 break;
186 default:
187 goto done;
189 dc->MapMode = mode;
190 DC_UpdateXforms( dc );
191 done:
192 GDI_ReleaseObj( hdc );
193 return prevMode;
197 /***********************************************************************
198 * SetViewportExt (GDI.14)
200 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
202 SIZE size;
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 )
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;
220 /***********************************************************************
221 * SetViewportExtEx (GDI32.340)
223 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
225 BOOL ret = TRUE;
226 DC * dc = DC_GetDCPtr( hdc );
227 if (!dc) return FALSE;
228 if (dc->funcs->pSetViewportExt)
230 ret = dc->funcs->pSetViewportExt( dc, x, y );
231 goto done;
233 if (size)
235 size->cx = dc->vportExtX;
236 size->cy = dc->vportExtY;
238 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
239 goto done;
240 if (!x || !y)
242 ret = FALSE;
243 goto done;
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;
255 /***********************************************************************
256 * SetViewportOrg (GDI.13)
258 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
260 POINT pt;
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 )
271 POINT pt32;
272 BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
273 if (pt) CONV_POINT32TO16( &pt32, pt );
274 return ret;
278 /***********************************************************************
279 * SetViewportOrgEx (GDI32.341)
281 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
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
290 if (pt)
292 pt->x = dc->vportOrgX;
293 pt->y = dc->vportOrgY;
295 dc->vportOrgX = x;
296 dc->vportOrgY = y;
297 DC_UpdateXforms( dc );
299 GDI_ReleaseObj( hdc );
300 return ret;
304 /***********************************************************************
305 * SetWindowExt (GDI.12)
307 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
309 SIZE size;
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 )
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;
327 /***********************************************************************
328 * SetWindowExtEx (GDI32.344)
330 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
332 BOOL ret = TRUE;
333 DC * dc = DC_GetDCPtr( hdc );
334 if (!dc) return FALSE;
335 if (dc->funcs->pSetWindowExt)
337 ret = dc->funcs->pSetWindowExt( dc, x, y );
338 goto done;
340 if (size)
342 size->cx = dc->wndExtX;
343 size->cy = dc->wndExtY;
345 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
346 goto done;
347 if (!x || !y)
349 ret = FALSE;
350 goto done;
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;
362 /***********************************************************************
363 * SetWindowOrg (GDI.11)
365 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
367 POINT pt;
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 )
378 POINT pt32;
379 BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
380 if (pt) CONV_POINT32TO16( &pt32, pt );
381 return ret;
385 /***********************************************************************
386 * SetWindowOrgEx (GDI32.345)
388 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
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
396 if (pt)
398 pt->x = dc->wndOrgX;
399 pt->y = dc->wndOrgY;
401 dc->wndOrgX = x;
402 dc->wndOrgY = y;
403 DC_UpdateXforms( dc );
405 GDI_ReleaseObj( hdc );
406 return ret;
410 /***********************************************************************
411 * OffsetViewportOrg (GDI.17)
413 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
415 POINT pt;
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)
426 POINT pt32;
427 BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
428 if (pt) CONV_POINT32TO16( &pt32, pt );
429 return ret;
433 /***********************************************************************
434 * OffsetViewportOrgEx (GDI32.257)
436 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
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
445 if (pt)
447 pt->x = dc->vportOrgX;
448 pt->y = dc->vportOrgY;
450 dc->vportOrgX += x;
451 dc->vportOrgY += y;
452 DC_UpdateXforms( dc );
454 GDI_ReleaseObj( hdc );
455 return ret;
459 /***********************************************************************
460 * OffsetWindowOrg (GDI.15)
462 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
464 POINT pt;
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 )
475 POINT pt32;
476 BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
477 if (pt) CONV_POINT32TO16( &pt32, pt );
478 return ret;
482 /***********************************************************************
483 * OffsetWindowOrgEx (GDI32.258)
485 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
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
494 if (pt)
496 pt->x = dc->wndOrgX;
497 pt->y = dc->wndOrgY;
499 dc->wndOrgX += x;
500 dc->wndOrgY += y;
501 DC_UpdateXforms( dc );
503 GDI_ReleaseObj( hdc );
504 return ret;
508 /***********************************************************************
509 * ScaleViewportExt (GDI.18)
511 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
512 INT16 yNum, INT16 yDenom )
514 SIZE size;
515 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
516 return FALSE;
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 )
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;
535 /***********************************************************************
536 * ScaleViewportExtEx (GDI32.293)
538 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
539 INT yNum, INT yDenom, LPSIZE size )
541 BOOL ret = TRUE;
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 );
547 goto done;
549 if (size)
551 size->cx = dc->vportExtX;
552 size->cy = dc->vportExtY;
554 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
555 goto done;
556 if (!xNum || !xDenom || !xNum || !yDenom)
558 ret = FALSE;
559 goto done;
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;
573 /***********************************************************************
574 * ScaleWindowExt (GDI.16)
576 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
577 INT16 yNum, INT16 yDenom )
579 SIZE size;
580 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
581 return FALSE;
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 )
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;
600 /***********************************************************************
601 * ScaleWindowExtEx (GDI32.294)
603 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
604 INT yNum, INT yDenom, LPSIZE size )
606 BOOL ret = TRUE;
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 );
612 goto done;
614 if (size)
616 size->cx = dc->wndExtX;
617 size->cy = dc->wndExtY;
619 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
620 goto done;
621 if (!xNum || !xDenom || !xNum || !yDenom)
623 ret = FALSE;
624 goto done;
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;