comdlg32: Add IExplorerBrowserEvents stub to Item Dialog.
[wine.git] / dlls / gdi32 / mapping.c
bloba9dc1b414617a9445a4ab4b50c20c4b948b5e276
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "gdi_private.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dc);
32 /***********************************************************************
33 * MAPPING_FixIsotropic
35 * Fix viewport extensions for isotropic mode.
37 static void MAPPING_FixIsotropic( DC * dc )
39 double xdim = fabs((double)dc->vportExtX * dc->virtual_size.cx /
40 (dc->virtual_res.cx * dc->wndExtX));
41 double ydim = fabs((double)dc->vportExtY * dc->virtual_size.cy /
42 (dc->virtual_res.cy * dc->wndExtY));
44 if (xdim > ydim)
46 INT mincx = (dc->vportExtX >= 0) ? 1 : -1;
47 dc->vportExtX = floor(dc->vportExtX * ydim / xdim + 0.5);
48 if (!dc->vportExtX) dc->vportExtX = mincx;
50 else
52 INT mincy = (dc->vportExtY >= 0) ? 1 : -1;
53 dc->vportExtY = floor(dc->vportExtY * xdim / ydim + 0.5);
54 if (!dc->vportExtY) dc->vportExtY = mincy;
59 /***********************************************************************
60 * null driver fallback implementations
63 BOOL CDECL nulldrv_OffsetViewportOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
65 DC *dc = get_nulldrv_dc( dev );
67 if (pt)
69 pt->x = dc->vportOrgX;
70 pt->y = dc->vportOrgY;
72 dc->vportOrgX += x;
73 dc->vportOrgY += y;
74 DC_UpdateXforms( dc );
75 return TRUE;
78 BOOL CDECL nulldrv_OffsetWindowOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
80 DC *dc = get_nulldrv_dc( dev );
82 if (pt)
84 pt->x = dc->wndOrgX;
85 pt->y = dc->wndOrgY;
87 dc->wndOrgX += x;
88 dc->wndOrgY += y;
89 DC_UpdateXforms( dc );
90 return TRUE;
93 BOOL CDECL nulldrv_ScaleViewportExtEx( PHYSDEV dev, INT x_num, INT x_denom, INT y_num, INT y_denom,
94 SIZE *size )
96 DC *dc = get_nulldrv_dc( dev );
98 if (size)
100 size->cx = dc->vportExtX;
101 size->cy = dc->vportExtY;
103 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
104 if (!x_num || !x_denom || !y_num || !y_denom) return FALSE;
106 dc->vportExtX = (dc->vportExtX * x_num) / x_denom;
107 dc->vportExtY = (dc->vportExtY * y_num) / y_denom;
108 if (dc->vportExtX == 0) dc->vportExtX = 1;
109 if (dc->vportExtY == 0) dc->vportExtY = 1;
110 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
111 DC_UpdateXforms( dc );
112 return TRUE;
115 BOOL CDECL nulldrv_ScaleWindowExtEx( PHYSDEV dev, INT x_num, INT x_denom, INT y_num, INT y_denom,
116 SIZE *size )
118 DC *dc = get_nulldrv_dc( dev );
120 if (size)
122 size->cx = dc->wndExtX;
123 size->cy = dc->wndExtY;
125 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
126 if (!x_num || !x_denom || !y_num || !y_denom) return FALSE;
128 dc->wndExtX = (dc->wndExtX * x_num) / x_denom;
129 dc->wndExtY = (dc->wndExtY * y_num) / y_denom;
130 if (dc->wndExtX == 0) dc->wndExtX = 1;
131 if (dc->wndExtY == 0) dc->wndExtY = 1;
132 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
133 DC_UpdateXforms( dc );
134 return TRUE;
137 INT CDECL nulldrv_SetMapMode( PHYSDEV dev, INT mode )
139 DC *dc = get_nulldrv_dc( dev );
140 INT ret = dc->MapMode;
141 INT horzSize, vertSize, horzRes, vertRes;
143 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC)) return ret;
145 horzSize = dc->virtual_size.cx;
146 vertSize = dc->virtual_size.cy;
147 horzRes = dc->virtual_res.cx;
148 vertRes = dc->virtual_res.cy;
149 switch (mode)
151 case MM_TEXT:
152 dc->wndExtX = 1;
153 dc->wndExtY = 1;
154 dc->vportExtX = 1;
155 dc->vportExtY = 1;
156 break;
157 case MM_LOMETRIC:
158 case MM_ISOTROPIC:
159 dc->wndExtX = horzSize * 10;
160 dc->wndExtY = vertSize * 10;
161 dc->vportExtX = horzRes;
162 dc->vportExtY = -vertRes;
163 break;
164 case MM_HIMETRIC:
165 dc->wndExtX = horzSize * 100;
166 dc->wndExtY = vertSize * 100;
167 dc->vportExtX = horzRes;
168 dc->vportExtY = -vertRes;
169 break;
170 case MM_LOENGLISH:
171 dc->wndExtX = MulDiv(1000, horzSize, 254);
172 dc->wndExtY = MulDiv(1000, vertSize, 254);
173 dc->vportExtX = horzRes;
174 dc->vportExtY = -vertRes;
175 break;
176 case MM_HIENGLISH:
177 dc->wndExtX = MulDiv(10000, horzSize, 254);
178 dc->wndExtY = MulDiv(10000, vertSize, 254);
179 dc->vportExtX = horzRes;
180 dc->vportExtY = -vertRes;
181 break;
182 case MM_TWIPS:
183 dc->wndExtX = MulDiv(14400, horzSize, 254);
184 dc->wndExtY = MulDiv(14400, vertSize, 254);
185 dc->vportExtX = horzRes;
186 dc->vportExtY = -vertRes;
187 break;
188 case MM_ANISOTROPIC:
189 break;
190 default:
191 return 0;
193 /* RTL layout is always MM_ANISOTROPIC */
194 if (!(dc->layout & LAYOUT_RTL)) dc->MapMode = mode;
195 DC_UpdateXforms( dc );
196 return ret;
199 BOOL CDECL nulldrv_SetViewportExtEx( PHYSDEV dev, INT cx, INT cy, SIZE *size )
201 DC *dc = get_nulldrv_dc( dev );
203 if (size)
205 size->cx = dc->vportExtX;
206 size->cy = dc->vportExtY;
208 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
209 if (!cx || !cy) return FALSE;
210 dc->vportExtX = cx;
211 dc->vportExtY = cy;
212 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
213 DC_UpdateXforms( dc );
214 return TRUE;
217 BOOL CDECL nulldrv_SetViewportOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
219 DC *dc = get_nulldrv_dc( dev );
221 if (pt)
223 pt->x = dc->vportOrgX;
224 pt->y = dc->vportOrgY;
226 dc->vportOrgX = x;
227 dc->vportOrgY = y;
228 DC_UpdateXforms( dc );
229 return TRUE;
232 BOOL CDECL nulldrv_SetWindowExtEx( PHYSDEV dev, INT cx, INT cy, SIZE *size )
234 DC *dc = get_nulldrv_dc( dev );
236 if (size)
238 size->cx = dc->wndExtX;
239 size->cy = dc->wndExtY;
241 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
242 if (!cx || !cy) return FALSE;
243 dc->wndExtX = cx;
244 dc->wndExtY = cy;
245 /* The API docs say that you should call SetWindowExtEx before
246 SetViewportExtEx. This advice does not imply that Windows
247 doesn't ensure the isotropic mapping after SetWindowExtEx! */
248 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
249 DC_UpdateXforms( dc );
250 return TRUE;
253 BOOL CDECL nulldrv_SetWindowOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
255 DC *dc = get_nulldrv_dc( dev );
257 if (pt)
259 pt->x = dc->wndOrgX;
260 pt->y = dc->wndOrgY;
262 dc->wndOrgX = x;
263 dc->wndOrgY = y;
264 DC_UpdateXforms( dc );
265 return TRUE;
268 BOOL CDECL nulldrv_ModifyWorldTransform( PHYSDEV dev, const XFORM *xform, DWORD mode )
270 DC *dc = get_nulldrv_dc( dev );
272 switch (mode)
274 case MWT_IDENTITY:
275 dc->xformWorld2Wnd.eM11 = 1.0f;
276 dc->xformWorld2Wnd.eM12 = 0.0f;
277 dc->xformWorld2Wnd.eM21 = 0.0f;
278 dc->xformWorld2Wnd.eM22 = 1.0f;
279 dc->xformWorld2Wnd.eDx = 0.0f;
280 dc->xformWorld2Wnd.eDy = 0.0f;
281 break;
282 case MWT_LEFTMULTIPLY:
283 CombineTransform( &dc->xformWorld2Wnd, xform, &dc->xformWorld2Wnd );
284 break;
285 case MWT_RIGHTMULTIPLY:
286 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd, xform );
287 break;
288 default:
289 return FALSE;
291 DC_UpdateXforms( dc );
292 return TRUE;
295 BOOL CDECL nulldrv_SetWorldTransform( PHYSDEV dev, const XFORM *xform )
297 DC *dc = get_nulldrv_dc( dev );
299 dc->xformWorld2Wnd = *xform;
300 DC_UpdateXforms( dc );
301 return TRUE;
304 /***********************************************************************
305 * DPtoLP (GDI32.@)
307 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
309 DC * dc = get_dc_ptr( hdc );
310 if (!dc) return FALSE;
312 if (dc->vport2WorldValid)
314 while (count--)
316 double x = points->x;
317 double y = points->y;
318 points->x = floor( x * dc->xformVport2World.eM11 +
319 y * dc->xformVport2World.eM21 +
320 dc->xformVport2World.eDx + 0.5 );
321 points->y = floor( x * dc->xformVport2World.eM12 +
322 y * dc->xformVport2World.eM22 +
323 dc->xformVport2World.eDy + 0.5 );
324 points++;
327 release_dc_ptr( dc );
328 return (count < 0);
332 /***********************************************************************
333 * LPtoDP (GDI32.@)
335 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
337 DC * dc = get_dc_ptr( hdc );
338 if (!dc) return FALSE;
340 while (count--)
342 double x = points->x;
343 double y = points->y;
344 points->x = floor( x * dc->xformWorld2Vport.eM11 +
345 y * dc->xformWorld2Vport.eM21 +
346 dc->xformWorld2Vport.eDx + 0.5 );
347 points->y = floor( x * dc->xformWorld2Vport.eM12 +
348 y * dc->xformWorld2Vport.eM22 +
349 dc->xformWorld2Vport.eDy + 0.5 );
350 points++;
352 release_dc_ptr( dc );
353 return TRUE;
357 /***********************************************************************
358 * SetMapMode (GDI32.@)
360 INT WINAPI SetMapMode( HDC hdc, INT mode )
362 INT ret = 0;
363 DC * dc = get_dc_ptr( hdc );
365 TRACE("%p %d\n", hdc, mode );
367 if (dc)
369 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetMapMode );
370 ret = physdev->funcs->pSetMapMode( physdev, mode );
371 release_dc_ptr( dc );
373 return ret;
377 /***********************************************************************
378 * SetViewportExtEx (GDI32.@)
380 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
382 INT ret = FALSE;
383 DC * dc = get_dc_ptr( hdc );
385 if (dc)
387 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetViewportExtEx );
388 ret = physdev->funcs->pSetViewportExtEx( physdev, x, y, size );
389 release_dc_ptr( dc );
391 return ret;
395 /***********************************************************************
396 * SetViewportOrgEx (GDI32.@)
398 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
400 INT ret = FALSE;
401 DC * dc = get_dc_ptr( hdc );
403 if (dc)
405 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetViewportOrgEx );
406 ret = physdev->funcs->pSetViewportOrgEx( physdev, x, y, pt );
407 release_dc_ptr( dc );
409 return ret;
413 /***********************************************************************
414 * SetWindowExtEx (GDI32.@)
416 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
418 INT ret = FALSE;
419 DC * dc = get_dc_ptr( hdc );
421 if (dc)
423 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetWindowExtEx );
424 ret = physdev->funcs->pSetWindowExtEx( physdev, x, y, size );
425 release_dc_ptr( dc );
427 return ret;
431 /***********************************************************************
432 * SetWindowOrgEx (GDI32.@)
434 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
436 INT ret = FALSE;
437 DC * dc = get_dc_ptr( hdc );
439 if (dc)
441 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetWindowOrgEx );
442 ret = physdev->funcs->pSetWindowOrgEx( physdev, x, y, pt );
443 release_dc_ptr( dc );
445 return ret;
449 /***********************************************************************
450 * OffsetViewportOrgEx (GDI32.@)
452 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
454 INT ret = FALSE;
455 DC * dc = get_dc_ptr( hdc );
457 if (dc)
459 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pOffsetViewportOrgEx );
460 ret = physdev->funcs->pOffsetViewportOrgEx( physdev, x, y, pt );
461 release_dc_ptr( dc );
463 return ret;
467 /***********************************************************************
468 * OffsetWindowOrgEx (GDI32.@)
470 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
472 INT ret = FALSE;
473 DC * dc = get_dc_ptr( hdc );
475 if (dc)
477 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pOffsetWindowOrgEx );
478 ret = physdev->funcs->pOffsetWindowOrgEx( physdev, x, y, pt );
479 release_dc_ptr( dc );
481 return ret;
485 /***********************************************************************
486 * ScaleViewportExtEx (GDI32.@)
488 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
489 INT yNum, INT yDenom, LPSIZE size )
491 INT ret = FALSE;
492 DC * dc = get_dc_ptr( hdc );
494 if (dc)
496 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pScaleViewportExtEx );
497 ret = physdev->funcs->pScaleViewportExtEx( physdev, xNum, xDenom, yNum, yDenom, size );
498 release_dc_ptr( dc );
500 return ret;
504 /***********************************************************************
505 * ScaleWindowExtEx (GDI32.@)
507 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
508 INT yNum, INT yDenom, LPSIZE size )
510 INT ret = FALSE;
511 DC * dc = get_dc_ptr( hdc );
513 if (dc)
515 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pScaleWindowExtEx );
516 ret = physdev->funcs->pScaleWindowExtEx( physdev, xNum, xDenom, yNum, yDenom, size );
517 release_dc_ptr( dc );
519 return ret;
523 /****************************************************************************
524 * ModifyWorldTransform (GDI32.@)
526 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform, DWORD mode )
528 BOOL ret = FALSE;
529 DC *dc;
531 if (!xform && mode != MWT_IDENTITY) return FALSE;
532 if ((dc = get_dc_ptr( hdc )))
534 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pModifyWorldTransform );
535 if (dc->GraphicsMode == GM_ADVANCED)
536 ret = physdev->funcs->pModifyWorldTransform( physdev, xform, mode );
537 release_dc_ptr( dc );
539 return ret;
543 /***********************************************************************
544 * SetWorldTransform (GDI32.@)
546 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
548 BOOL ret = FALSE;
549 DC *dc;
551 if (!xform) return FALSE;
552 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
553 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) return FALSE;
555 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
556 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
558 if ((dc = get_dc_ptr( hdc )))
560 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetWorldTransform );
561 if (dc->GraphicsMode == GM_ADVANCED)
562 ret = physdev->funcs->pSetWorldTransform( physdev, xform );
563 release_dc_ptr( dc );
565 return ret;
569 /***********************************************************************
570 * SetVirtualResolution (GDI32.@)
572 * Undocumented on msdn.
574 * Changes the values of screen size in pixels and millimeters used by
575 * the mapping mode functions.
577 * PARAMS
578 * hdc [I] Device context
579 * horz_res [I] Width in pixels (equivalent to HORZRES device cap).
580 * vert_res [I] Height in pixels (equivalent to VERTRES device cap).
581 * horz_size [I] Width in mm (equivalent to HORZSIZE device cap).
582 * vert_size [I] Height in mm (equivalent to VERTSIZE device cap).
584 * RETURNS
585 * TRUE if successful.
586 * FALSE if any (but not all) of the last four params are zero.
588 * NOTES
589 * This doesn't change the values returned by GetDeviceCaps, just the
590 * scaling of the mapping modes.
592 * Calling with the last four params equal to zero sets the values
593 * back to their defaults obtained by calls to GetDeviceCaps.
595 BOOL WINAPI SetVirtualResolution(HDC hdc, DWORD horz_res, DWORD vert_res,
596 DWORD horz_size, DWORD vert_size)
598 DC * dc;
599 TRACE("(%p %d %d %d %d)\n", hdc, horz_res, vert_res, horz_size, vert_size);
601 if(horz_res == 0 && vert_res == 0 && horz_size == 0 && vert_size == 0)
603 horz_res = GetDeviceCaps(hdc, HORZRES);
604 vert_res = GetDeviceCaps(hdc, VERTRES);
605 horz_size = GetDeviceCaps(hdc, HORZSIZE);
606 vert_size = GetDeviceCaps(hdc, VERTSIZE);
608 else if(horz_res == 0 || vert_res == 0 || horz_size == 0 || vert_size == 0)
609 return FALSE;
611 dc = get_dc_ptr( hdc );
612 if (!dc) return FALSE;
614 dc->virtual_res.cx = horz_res;
615 dc->virtual_res.cy = vert_res;
616 dc->virtual_size.cx = horz_size;
617 dc->virtual_size.cy = vert_size;
619 release_dc_ptr( dc );
620 return TRUE;