Fixed bug introduced in WIN_FindWindow.
[wine/multimedia.git] / graphics / mapping.c
blobee9a090b0012b474808ead07496e6bb07a310805
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "dc.h"
8 #include "debug.h"
11 /***********************************************************************
12 * MAPPING_FixIsotropic
14 * Fix viewport extensions for isotropic mode.
16 void MAPPING_FixIsotropic( DC * dc )
18 double xdim = (double)dc->vportExtX * dc->w.devCaps->horzSize /
19 (dc->w.devCaps->horzRes * dc->wndExtX);
20 double ydim = (double)dc->vportExtY * dc->w.devCaps->vertSize /
21 (dc->w.devCaps->vertRes * dc->wndExtY);
22 if (xdim > ydim)
24 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
25 if (!dc->vportExtX) dc->vportExtX = 1;
27 else
29 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
30 if (!dc->vportExtY) dc->vportExtY = 1;
35 /***********************************************************************
36 * DPtoLP16 (GDI.67)
38 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
40 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
41 if (!dc) return FALSE;
43 while (count--)
45 points->x = XDPTOLP( dc, points->x );
46 points->y = YDPTOLP( dc, points->y );
47 points++;
49 return TRUE;
53 /***********************************************************************
54 * DPtoLP32 (GDI32.65)
56 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
58 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
59 if (!dc) return FALSE;
61 while (count--)
63 if (!INTERNAL_DPTOLP( dc, points ))
64 return FALSE;
65 points++;
67 return TRUE;
71 /***********************************************************************
72 * LPtoDP16 (GDI.99)
74 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
76 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
77 if (!dc) return FALSE;
79 while (count--)
81 points->x = XLPTODP( dc, points->x );
82 points->y = YLPTODP( dc, points->y );
83 points++;
85 return TRUE;
89 /***********************************************************************
90 * LPtoDP32 (GDI32.247)
92 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
94 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
95 if (!dc) return FALSE;
97 while (count--)
99 INTERNAL_LPTODP( dc, points );
100 points++;
102 return TRUE;
106 /***********************************************************************
107 * SetMapMode16 (GDI.3)
109 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
111 return SetMapMode( hdc, mode );
115 /***********************************************************************
116 * SetMapMode32 (GDI32.321)
118 INT WINAPI SetMapMode( HDC hdc, INT mode )
120 INT prevMode;
121 DC * dc = DC_GetDCPtr( hdc );
122 if (!dc) return 0;
123 if (dc->funcs->pSetMapMode) return dc->funcs->pSetMapMode( dc, mode );
125 TRACE(gdi, "%04x %d\n", hdc, mode );
127 prevMode = dc->w.MapMode;
128 switch(mode)
130 case MM_TEXT:
131 dc->wndOrgX = dc->wndOrgY = 0;
132 dc->vportOrgX = dc->vportOrgY = 0;
133 dc->wndExtX = 1;
134 dc->wndExtY = 1;
135 dc->vportExtX = 1;
136 dc->vportExtY = 1;
137 break;
139 case MM_LOMETRIC:
140 case MM_ISOTROPIC:
141 dc->wndOrgX = dc->wndOrgY = 0;
142 dc->vportOrgX = dc->vportOrgY = 0;
143 dc->wndExtX = dc->w.devCaps->horzSize;
144 dc->wndExtY = dc->w.devCaps->vertSize;
145 dc->vportExtX = dc->w.devCaps->horzRes / 10;
146 dc->vportExtY = dc->w.devCaps->vertRes / -10;
147 break;
149 case MM_HIMETRIC:
150 dc->wndOrgX = dc->wndOrgY = 0;
151 dc->vportOrgX = dc->vportOrgY = 0;
152 dc->wndExtX = dc->w.devCaps->horzSize * 10;
153 dc->wndExtY = dc->w.devCaps->vertSize * 10;
154 dc->vportExtX = dc->w.devCaps->horzRes / 10;
155 dc->vportExtY = dc->w.devCaps->vertRes / -10;
156 break;
158 case MM_LOENGLISH:
159 dc->wndOrgX = dc->wndOrgY = 0;
160 dc->vportOrgX = dc->vportOrgY = 0;
161 dc->wndExtX = dc->w.devCaps->horzSize;
162 dc->wndExtY = dc->w.devCaps->vertSize;
163 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
164 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
165 break;
167 case MM_HIENGLISH:
168 dc->wndOrgX = dc->wndOrgY = 0;
169 dc->vportOrgX = dc->vportOrgY = 0;
170 dc->wndExtX = dc->w.devCaps->horzSize * 10;
171 dc->wndExtY = dc->w.devCaps->vertSize * 10;
172 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
173 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
174 break;
176 case MM_TWIPS:
177 dc->wndOrgX = dc->wndOrgY = 0;
178 dc->vportOrgX = dc->vportOrgY = 0;
179 dc->wndExtX = 144L * dc->w.devCaps->horzSize / 10;
180 dc->wndExtY = 144L * dc->w.devCaps->vertSize / 10;
181 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
182 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
183 break;
185 case MM_ANISOTROPIC:
186 break;
188 default:
189 return prevMode;
191 dc->w.MapMode = mode;
192 DC_UpdateXforms( dc );
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) CONV_SIZE32TO16( &size32, size );
216 return ret;
220 /***********************************************************************
221 * SetViewportExtEx32 (GDI32.340)
223 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)
228 return dc->funcs->pSetViewportExt( dc, x, y );
229 if (size)
231 size->cx = dc->vportExtX;
232 size->cy = dc->vportExtY;
234 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
235 return TRUE;
236 if (!x || !y) return FALSE;
237 dc->vportExtX = x;
238 dc->vportExtY = y;
239 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
240 DC_UpdateXforms( dc );
241 return TRUE;
245 /***********************************************************************
246 * SetViewportOrg (GDI.13)
248 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
250 POINT pt;
251 if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
252 return MAKELONG( pt.x, pt.y );
256 /***********************************************************************
257 * SetViewportOrgEx16 (GDI.480)
259 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
261 POINT pt32;
262 BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
263 if (pt) CONV_POINT32TO16( &pt32, pt );
264 return ret;
268 /***********************************************************************
269 * SetViewportOrgEx32 (GDI32.341)
271 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
273 DC * dc = DC_GetDCPtr( hdc );
274 if (!dc) return FALSE;
275 if (dc->funcs->pSetViewportOrg)
276 return dc->funcs->pSetViewportOrg( dc, x, y );
277 if (pt)
279 pt->x = dc->vportOrgX;
280 pt->y = dc->vportOrgY;
282 dc->vportOrgX = x;
283 dc->vportOrgY = y;
284 DC_UpdateXforms( dc );
285 return TRUE;
289 /***********************************************************************
290 * SetWindowExt (GDI.12)
292 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
294 SIZE size;
295 if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
296 return MAKELONG( size.cx, size.cy );
300 /***********************************************************************
301 * SetWindowExtEx16 (GDI.481)
303 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
305 SIZE size32;
306 BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
307 if (size) CONV_SIZE32TO16( &size32, size );
308 return ret;
312 /***********************************************************************
313 * SetWindowExtEx32 (GDI32.344)
315 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
317 DC * dc = DC_GetDCPtr( hdc );
318 if (!dc) return FALSE;
319 if (dc->funcs->pSetWindowExt) return dc->funcs->pSetWindowExt( dc, x, y );
320 if (size)
322 size->cx = dc->wndExtX;
323 size->cy = dc->wndExtY;
325 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
326 return TRUE;
327 if (!x || !y) return FALSE;
328 dc->wndExtX = x;
329 dc->wndExtY = y;
330 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
331 DC_UpdateXforms( dc );
332 return TRUE;
336 /***********************************************************************
337 * SetWindowOrg (GDI.11)
339 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
341 POINT pt;
342 if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
343 return MAKELONG( pt.x, pt.y );
347 /***********************************************************************
348 * SetWindowOrgEx16 (GDI.482)
350 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
352 POINT pt32;
353 BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
354 if (pt) CONV_POINT32TO16( &pt32, pt );
355 return ret;
359 /***********************************************************************
360 * SetWindowOrgEx32 (GDI32.345)
362 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
364 DC * dc = DC_GetDCPtr( hdc );
365 if (!dc) return FALSE;
366 if (dc->funcs->pSetWindowOrg) return dc->funcs->pSetWindowOrg( dc, x, y );
367 if (pt)
369 pt->x = dc->wndOrgX;
370 pt->y = dc->wndOrgY;
372 dc->wndOrgX = x;
373 dc->wndOrgY = y;
374 DC_UpdateXforms( dc );
375 return TRUE;
379 /***********************************************************************
380 * OffsetViewportOrg (GDI.17)
382 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
384 POINT pt;
385 if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
386 return MAKELONG( pt.x, pt.y );
390 /***********************************************************************
391 * OffsetViewportOrgEx16 (GDI.476)
393 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
395 POINT pt32;
396 BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
397 if (pt) CONV_POINT32TO16( &pt32, pt );
398 return ret;
402 /***********************************************************************
403 * OffsetViewportOrgEx32 (GDI32.257)
405 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
407 DC * dc = DC_GetDCPtr( hdc );
408 if (!dc) return FALSE;
409 if (dc->funcs->pOffsetViewportOrg)
410 return dc->funcs->pOffsetViewportOrg( dc, x, y );
411 if (pt)
413 pt->x = dc->vportOrgX;
414 pt->y = dc->vportOrgY;
416 dc->vportOrgX += x;
417 dc->vportOrgY += y;
418 DC_UpdateXforms( dc );
419 return TRUE;
423 /***********************************************************************
424 * OffsetWindowOrg (GDI.15)
426 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
428 POINT pt;
429 if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
430 return MAKELONG( pt.x, pt.y );
434 /***********************************************************************
435 * OffsetWindowOrgEx16 (GDI.477)
437 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
439 POINT pt32;
440 BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
441 if (pt) CONV_POINT32TO16( &pt32, pt );
442 return ret;
446 /***********************************************************************
447 * OffsetWindowOrgEx32 (GDI32.258)
449 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
451 DC * dc = DC_GetDCPtr( hdc );
452 if (!dc) return FALSE;
453 if (dc->funcs->pOffsetWindowOrg)
454 return dc->funcs->pOffsetWindowOrg( dc, x, y );
455 if (pt)
457 pt->x = dc->wndOrgX;
458 pt->y = dc->wndOrgY;
460 dc->wndOrgX += x;
461 dc->wndOrgY += y;
462 DC_UpdateXforms( dc );
463 return TRUE;
467 /***********************************************************************
468 * ScaleViewportExt (GDI.18)
470 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
471 INT16 yNum, INT16 yDenom )
473 SIZE size;
474 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
475 return FALSE;
476 return MAKELONG( size.cx, size.cy );
480 /***********************************************************************
481 * ScaleViewportExtEx16 (GDI.484)
483 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
484 INT16 yNum, INT16 yDenom, LPSIZE16 size )
486 SIZE size32;
487 BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
488 &size32 );
489 if (size) CONV_SIZE32TO16( &size32, size );
490 return ret;
494 /***********************************************************************
495 * ScaleViewportExtEx32 (GDI32.293)
497 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
498 INT yNum, INT yDenom, LPSIZE size )
500 DC * dc = DC_GetDCPtr( hdc );
501 if (!dc) return FALSE;
502 if (dc->funcs->pScaleViewportExt)
503 return dc->funcs->pScaleViewportExt( dc, xNum, xDenom, yNum, yDenom );
504 if (size)
506 size->cx = dc->vportExtX;
507 size->cy = dc->vportExtY;
509 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
510 return TRUE;
511 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
512 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
513 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
514 if (dc->vportExtX == 0) dc->vportExtX = 1;
515 if (dc->vportExtY == 0) dc->vportExtY = 1;
516 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
517 DC_UpdateXforms( dc );
518 return TRUE;
522 /***********************************************************************
523 * ScaleWindowExt (GDI.16)
525 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
526 INT16 yNum, INT16 yDenom )
528 SIZE size;
529 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
530 return FALSE;
531 return MAKELONG( size.cx, size.cy );
535 /***********************************************************************
536 * ScaleWindowExtEx16 (GDI.485)
538 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
539 INT16 yNum, INT16 yDenom, LPSIZE16 size )
541 SIZE size32;
542 BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
543 &size32 );
544 if (size) CONV_SIZE32TO16( &size32, size );
545 return ret;
549 /***********************************************************************
550 * ScaleWindowExtEx32 (GDI32.294)
552 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
553 INT yNum, INT yDenom, LPSIZE size )
555 DC * dc = DC_GetDCPtr( hdc );
556 if (!dc) return FALSE;
557 if (dc->funcs->pScaleWindowExt)
558 return dc->funcs->pScaleWindowExt( dc, xNum, xDenom, yNum, yDenom );
559 if (size)
561 size->cx = dc->wndExtX;
562 size->cy = dc->wndExtY;
564 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
565 return TRUE;
566 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
567 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
568 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
569 if (dc->wndExtX == 0) dc->wndExtX = 1;
570 if (dc->wndExtY == 0) dc->wndExtY = 1;
571 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
572 DC_UpdateXforms( dc );
573 return TRUE;