Added ability to turn on/off debug channels.
[wine.git] / graphics / mapping.c
blob143873389202a9af7e94873608b521a7feb08659
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "gdi.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
27 /***********************************************************************
28 * MAPPING_FixIsotropic
30 * Fix viewport extensions for isotropic mode.
32 void MAPPING_FixIsotropic( DC * dc )
34 double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
35 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
36 double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
37 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
38 if (xdim > ydim)
40 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
41 if (!dc->vportExtX) dc->vportExtX = 1;
43 else
45 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
46 if (!dc->vportExtY) dc->vportExtY = 1;
51 /***********************************************************************
52 * DPtoLP (GDI.67)
54 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
56 DC * dc = DC_GetDCPtr( hdc );
57 if (!dc) return FALSE;
59 while (count--)
61 points->x = XDPTOLP( dc, points->x );
62 points->y = YDPTOLP( dc, points->y );
63 points++;
65 GDI_ReleaseObj( hdc );
66 return TRUE;
70 /***********************************************************************
71 * DPtoLP (GDI32.@)
73 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
75 DC * dc = DC_GetDCPtr( hdc );
76 if (!dc) return FALSE;
78 while (count--)
80 if (!INTERNAL_DPTOLP( dc, points ))
81 break;
82 points++;
84 GDI_ReleaseObj( hdc );
85 return (count < 0);
89 /***********************************************************************
90 * LPtoDP (GDI.99)
92 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
94 DC * dc = DC_GetDCPtr( hdc );
95 if (!dc) return FALSE;
97 while (count--)
99 points->x = XLPTODP( dc, points->x );
100 points->y = YLPTODP( dc, points->y );
101 points++;
103 GDI_ReleaseObj( hdc );
104 return TRUE;
108 /***********************************************************************
109 * LPtoDP (GDI32.@)
111 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
113 DC * dc = DC_GetDCPtr( hdc );
114 if (!dc) return FALSE;
116 while (count--)
118 INTERNAL_LPTODP( dc, points );
119 points++;
121 GDI_ReleaseObj( hdc );
122 return TRUE;
126 /***********************************************************************
127 * SetMapMode (GDI.3)
129 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
131 return SetMapMode( hdc, mode );
135 /***********************************************************************
136 * SetMapMode (GDI32.@)
138 INT WINAPI SetMapMode( HDC hdc, INT mode )
140 INT prevMode;
141 INT horzSize, vertSize, horzRes, vertRes;
143 DC * dc = DC_GetDCPtr( hdc );
144 if (!dc) return 0;
145 if (dc->funcs->pSetMapMode)
147 prevMode = dc->funcs->pSetMapMode( dc->physDev, mode );
148 goto done;
151 TRACE("%04x %d\n", hdc, mode );
153 prevMode = dc->MapMode;
154 horzSize = GetDeviceCaps( hdc, HORZSIZE );
155 vertSize = GetDeviceCaps( hdc, VERTSIZE );
156 horzRes = GetDeviceCaps( hdc, HORZRES );
157 vertRes = GetDeviceCaps( hdc, VERTRES );
158 switch(mode)
160 case MM_TEXT:
161 dc->wndExtX = 1;
162 dc->wndExtY = 1;
163 dc->vportExtX = 1;
164 dc->vportExtY = 1;
165 break;
166 case MM_LOMETRIC:
167 case MM_ISOTROPIC:
168 dc->wndExtX = horzSize;
169 dc->wndExtY = vertSize;
170 dc->vportExtX = horzRes / 10;
171 dc->vportExtY = vertRes / -10;
172 break;
173 case MM_HIMETRIC:
174 dc->wndExtX = horzSize * 10;
175 dc->wndExtY = vertSize * 10;
176 dc->vportExtX = horzRes / 10;
177 dc->vportExtY = vertRes / -10;
178 break;
179 case MM_LOENGLISH:
180 dc->wndExtX = horzSize;
181 dc->wndExtY = vertSize;
182 dc->vportExtX = 254L * horzRes / 1000;
183 dc->vportExtY = -254L * vertRes / 1000;
184 break;
185 case MM_HIENGLISH:
186 dc->wndExtX = horzSize * 10;
187 dc->wndExtY = vertSize * 10;
188 dc->vportExtX = 254L * horzRes / 1000;
189 dc->vportExtY = -254L * vertRes / 1000;
190 break;
191 case MM_TWIPS:
192 dc->wndExtX = 144L * horzSize / 10;
193 dc->wndExtY = 144L * vertSize / 10;
194 dc->vportExtX = 254L * horzRes / 1000;
195 dc->vportExtY = -254L * vertRes / 1000;
196 break;
197 case MM_ANISOTROPIC:
198 break;
199 default:
200 goto done;
202 dc->MapMode = mode;
203 DC_UpdateXforms( dc );
204 done:
205 GDI_ReleaseObj( hdc );
206 return prevMode;
210 /***********************************************************************
211 * SetViewportExt (GDI.14)
213 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
215 SIZE size;
216 if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
217 return MAKELONG( size.cx, size.cy );
221 /***********************************************************************
222 * SetViewportExtEx (GDI.479)
224 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
226 SIZE size32;
227 BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
228 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
229 return ret;
233 /***********************************************************************
234 * SetViewportExtEx (GDI32.@)
236 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
238 BOOL ret = TRUE;
239 DC * dc = DC_GetDCPtr( hdc );
240 if (!dc) return FALSE;
241 if (dc->funcs->pSetViewportExt)
243 ret = dc->funcs->pSetViewportExt( dc->physDev, x, y );
244 goto done;
246 if (size)
248 size->cx = dc->vportExtX;
249 size->cy = dc->vportExtY;
251 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
252 goto done;
253 if (!x || !y)
255 ret = FALSE;
256 goto done;
258 dc->vportExtX = x;
259 dc->vportExtY = y;
260 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
261 DC_UpdateXforms( dc );
262 done:
263 GDI_ReleaseObj( hdc );
264 return ret;
268 /***********************************************************************
269 * SetViewportOrg (GDI.13)
271 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
273 POINT pt;
274 if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
275 return MAKELONG( pt.x, pt.y );
279 /***********************************************************************
280 * SetViewportOrgEx (GDI.480)
282 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
284 POINT pt32;
285 BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
286 if (pt) CONV_POINT32TO16( &pt32, pt );
287 return ret;
291 /***********************************************************************
292 * SetViewportOrgEx (GDI32.@)
294 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
296 BOOL ret = TRUE;
297 DC * dc = DC_GetDCPtr( hdc );
298 if (!dc) return FALSE;
299 if (dc->funcs->pSetViewportOrg)
300 ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y );
301 else
303 if (pt)
305 pt->x = dc->vportOrgX;
306 pt->y = dc->vportOrgY;
308 dc->vportOrgX = x;
309 dc->vportOrgY = y;
310 DC_UpdateXforms( dc );
312 GDI_ReleaseObj( hdc );
313 return ret;
317 /***********************************************************************
318 * SetWindowExt (GDI.12)
320 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
322 SIZE size;
323 if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
324 return MAKELONG( size.cx, size.cy );
328 /***********************************************************************
329 * SetWindowExtEx (GDI.481)
331 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
333 SIZE size32;
334 BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
335 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
336 return ret;
340 /***********************************************************************
341 * SetWindowExtEx (GDI32.@)
343 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
345 BOOL ret = TRUE;
346 DC * dc = DC_GetDCPtr( hdc );
347 if (!dc) return FALSE;
348 if (dc->funcs->pSetWindowExt)
350 ret = dc->funcs->pSetWindowExt( dc->physDev, x, y );
351 goto done;
353 if (size)
355 size->cx = dc->wndExtX;
356 size->cy = dc->wndExtY;
358 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
359 goto done;
360 if (!x || !y)
362 ret = FALSE;
363 goto done;
365 dc->wndExtX = x;
366 dc->wndExtY = y;
367 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
368 DC_UpdateXforms( dc );
369 done:
370 GDI_ReleaseObj( hdc );
371 return ret;
375 /***********************************************************************
376 * SetWindowOrg (GDI.11)
378 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
380 POINT pt;
381 if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
382 return MAKELONG( pt.x, pt.y );
386 /***********************************************************************
387 * SetWindowOrgEx (GDI.482)
389 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
391 POINT pt32;
392 BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
393 if (pt) CONV_POINT32TO16( &pt32, pt );
394 return ret;
398 /***********************************************************************
399 * SetWindowOrgEx (GDI32.@)
401 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
403 BOOL ret = TRUE;
404 DC * dc = DC_GetDCPtr( hdc );
405 if (!dc) return FALSE;
406 if (dc->funcs->pSetWindowOrg) ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y );
407 else
409 if (pt)
411 pt->x = dc->wndOrgX;
412 pt->y = dc->wndOrgY;
414 dc->wndOrgX = x;
415 dc->wndOrgY = y;
416 DC_UpdateXforms( dc );
418 GDI_ReleaseObj( hdc );
419 return ret;
423 /***********************************************************************
424 * OffsetViewportOrg (GDI.17)
426 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
428 POINT pt;
429 if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
430 return MAKELONG( pt.x, pt.y );
434 /***********************************************************************
435 * OffsetViewportOrgEx (GDI.476)
437 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
439 POINT pt32;
440 BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
441 if (pt) CONV_POINT32TO16( &pt32, pt );
442 return ret;
446 /***********************************************************************
447 * OffsetViewportOrgEx (GDI32.@)
449 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
451 BOOL ret = TRUE;
452 DC * dc = DC_GetDCPtr( hdc );
453 if (!dc) return FALSE;
454 if (dc->funcs->pOffsetViewportOrg)
455 ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y );
456 else
458 if (pt)
460 pt->x = dc->vportOrgX;
461 pt->y = dc->vportOrgY;
463 dc->vportOrgX += x;
464 dc->vportOrgY += y;
465 DC_UpdateXforms( dc );
467 GDI_ReleaseObj( hdc );
468 return ret;
472 /***********************************************************************
473 * OffsetWindowOrg (GDI.15)
475 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
477 POINT pt;
478 if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
479 return MAKELONG( pt.x, pt.y );
483 /***********************************************************************
484 * OffsetWindowOrgEx (GDI.477)
486 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
488 POINT pt32;
489 BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
490 if (pt) CONV_POINT32TO16( &pt32, pt );
491 return ret;
495 /***********************************************************************
496 * OffsetWindowOrgEx (GDI32.@)
498 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
500 BOOL ret = TRUE;
501 DC * dc = DC_GetDCPtr( hdc );
502 if (!dc) return FALSE;
503 if (dc->funcs->pOffsetWindowOrg)
504 ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y );
505 else
507 if (pt)
509 pt->x = dc->wndOrgX;
510 pt->y = dc->wndOrgY;
512 dc->wndOrgX += x;
513 dc->wndOrgY += y;
514 DC_UpdateXforms( dc );
516 GDI_ReleaseObj( hdc );
517 return ret;
521 /***********************************************************************
522 * ScaleViewportExt (GDI.18)
524 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
525 INT16 yNum, INT16 yDenom )
527 SIZE size;
528 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
529 return FALSE;
530 return MAKELONG( size.cx, size.cy );
534 /***********************************************************************
535 * ScaleViewportExtEx (GDI.484)
537 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
538 INT16 yNum, INT16 yDenom, LPSIZE16 size )
540 SIZE size32;
541 BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
542 &size32 );
543 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
544 return ret;
548 /***********************************************************************
549 * ScaleViewportExtEx (GDI32.@)
551 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
552 INT yNum, INT yDenom, LPSIZE size )
554 BOOL ret = TRUE;
555 DC * dc = DC_GetDCPtr( hdc );
556 if (!dc) return FALSE;
557 if (dc->funcs->pScaleViewportExt)
559 ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom );
560 goto done;
562 if (size)
564 size->cx = dc->vportExtX;
565 size->cy = dc->vportExtY;
567 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
568 goto done;
569 if (!xNum || !xDenom || !xNum || !yDenom)
571 ret = FALSE;
572 goto done;
574 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
575 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
576 if (dc->vportExtX == 0) dc->vportExtX = 1;
577 if (dc->vportExtY == 0) dc->vportExtY = 1;
578 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
579 DC_UpdateXforms( dc );
580 done:
581 GDI_ReleaseObj( hdc );
582 return ret;
586 /***********************************************************************
587 * ScaleWindowExt (GDI.16)
589 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
590 INT16 yNum, INT16 yDenom )
592 SIZE size;
593 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
594 return FALSE;
595 return MAKELONG( size.cx, size.cy );
599 /***********************************************************************
600 * ScaleWindowExtEx (GDI.485)
602 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
603 INT16 yNum, INT16 yDenom, LPSIZE16 size )
605 SIZE size32;
606 BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
607 &size32 );
608 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
609 return ret;
613 /***********************************************************************
614 * ScaleWindowExtEx (GDI32.@)
616 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
617 INT yNum, INT yDenom, LPSIZE size )
619 BOOL ret = TRUE;
620 DC * dc = DC_GetDCPtr( hdc );
621 if (!dc) return FALSE;
622 if (dc->funcs->pScaleWindowExt)
624 ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom );
625 goto done;
627 if (size)
629 size->cx = dc->wndExtX;
630 size->cy = dc->wndExtY;
632 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
633 goto done;
634 if (!xNum || !xDenom || !xNum || !yDenom)
636 ret = FALSE;
637 goto done;
639 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
640 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
641 if (dc->wndExtX == 0) dc->wndExtX = 1;
642 if (dc->wndExtY == 0) dc->wndExtY = 1;
643 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
644 DC_UpdateXforms( dc );
645 done:
646 GDI_ReleaseObj( hdc );
647 return ret;