Improve error reporting.
[wine/multimedia.git] / graphics / mapping.c
blob43038dae9a81808e3023b393e804c90f99905176
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 "wownt32.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
28 /***********************************************************************
29 * MAPPING_FixIsotropic
31 * Fix viewport extensions for isotropic mode.
33 void MAPPING_FixIsotropic( DC * dc )
35 double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
36 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
37 double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
38 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
39 if (xdim > ydim)
41 dc->vportExtX = floor(dc->vportExtX * fabs( ydim / xdim ) + 0.5);
42 if (!dc->vportExtX) dc->vportExtX = 1;
44 else
46 dc->vportExtY = floor(dc->vportExtY * fabs( xdim / ydim ) + 0.5);
47 if (!dc->vportExtY) dc->vportExtY = 1;
52 /***********************************************************************
53 * DPtoLP (GDI.67)
55 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
57 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
58 if (!dc) return FALSE;
60 while (count--)
62 points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
63 points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
64 points++;
66 GDI_ReleaseObj( HDC_32(hdc) );
67 return TRUE;
71 /***********************************************************************
72 * DPtoLP (GDI32.@)
74 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
76 DC * dc = DC_GetDCPtr( hdc );
77 if (!dc) return FALSE;
79 if (dc->vport2WorldValid)
81 while (count--)
83 FLOAT x = points->x;
84 FLOAT y = points->y;
85 points->x = floor( x * dc->xformVport2World.eM11 +
86 y * dc->xformVport2World.eM21 +
87 dc->xformVport2World.eDx + 0.5 );
88 points->y = floor( x * dc->xformVport2World.eM12 +
89 y * dc->xformVport2World.eM22 +
90 dc->xformVport2World.eDy + 0.5 );
91 points++;
94 GDI_ReleaseObj( hdc );
95 return (count < 0);
99 /***********************************************************************
100 * LPtoDP (GDI.99)
102 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
104 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
105 if (!dc) return FALSE;
107 while (count--)
109 points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
110 points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
111 points++;
113 GDI_ReleaseObj( HDC_32(hdc) );
114 return TRUE;
118 /***********************************************************************
119 * LPtoDP (GDI32.@)
121 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
123 DC * dc = DC_GetDCPtr( hdc );
124 if (!dc) return FALSE;
126 while (count--)
128 FLOAT x = points->x;
129 FLOAT y = points->y;
130 points->x = floor( x * dc->xformWorld2Vport.eM11 +
131 y * dc->xformWorld2Vport.eM21 +
132 dc->xformWorld2Vport.eDx + 0.5 );
133 points->y = floor( x * dc->xformWorld2Vport.eM12 +
134 y * dc->xformWorld2Vport.eM22 +
135 dc->xformWorld2Vport.eDy + 0.5 );
136 points++;
138 GDI_ReleaseObj( hdc );
139 return TRUE;
143 /***********************************************************************
144 * SetMapMode (GDI32.@)
146 INT WINAPI SetMapMode( HDC hdc, INT mode )
148 INT ret;
149 INT horzSize, vertSize, horzRes, vertRes;
151 DC * dc = DC_GetDCPtr( hdc );
152 if (!dc) return 0;
153 if (dc->funcs->pSetMapMode)
155 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
157 if(ret == GDI_NO_MORE_WORK)
158 ret = TRUE;
159 goto done;
163 TRACE("%p %d\n", hdc, mode );
165 ret = dc->MapMode;
167 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
168 goto done;
170 horzSize = GetDeviceCaps( hdc, HORZSIZE );
171 vertSize = GetDeviceCaps( hdc, VERTSIZE );
172 horzRes = GetDeviceCaps( hdc, HORZRES );
173 vertRes = GetDeviceCaps( hdc, VERTRES );
174 switch(mode)
176 case MM_TEXT:
177 dc->wndExtX = 1;
178 dc->wndExtY = 1;
179 dc->vportExtX = 1;
180 dc->vportExtY = 1;
181 break;
182 case MM_LOMETRIC:
183 case MM_ISOTROPIC:
184 dc->wndExtX = horzSize * 10;
185 dc->wndExtY = vertSize * 10;
186 dc->vportExtX = horzRes;
187 dc->vportExtY = -vertRes;
188 break;
189 case MM_HIMETRIC:
190 dc->wndExtX = horzSize * 100;
191 dc->wndExtY = vertSize * 100;
192 dc->vportExtX = horzRes;
193 dc->vportExtY = -vertRes;
194 break;
195 case MM_LOENGLISH:
196 dc->wndExtX = MulDiv(1000, horzSize, 254);
197 dc->wndExtY = MulDiv(1000, vertSize, 254);
198 dc->vportExtX = horzRes;
199 dc->vportExtY = -vertRes;
200 break;
201 case MM_HIENGLISH:
202 dc->wndExtX = MulDiv(10000, horzSize, 254);
203 dc->wndExtY = MulDiv(10000, vertSize, 254);
204 dc->vportExtX = horzRes;
205 dc->vportExtY = -vertRes;
206 break;
207 case MM_TWIPS:
208 dc->wndExtX = MulDiv(14400, horzSize, 254);
209 dc->wndExtY = MulDiv(14400, vertSize, 254);
210 dc->vportExtX = horzRes;
211 dc->vportExtY = -vertRes;
212 break;
213 case MM_ANISOTROPIC:
214 break;
215 default:
216 goto done;
218 dc->MapMode = mode;
219 DC_UpdateXforms( dc );
220 done:
221 GDI_ReleaseObj( hdc );
222 return ret;
226 /***********************************************************************
227 * SetViewportExtEx (GDI32.@)
229 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
231 INT ret = TRUE;
232 DC * dc = DC_GetDCPtr( hdc );
233 if (!dc) return FALSE;
234 if (dc->funcs->pSetViewportExt)
236 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
238 if(ret == GDI_NO_MORE_WORK)
239 ret = TRUE;
240 goto done;
243 if (size)
245 size->cx = dc->vportExtX;
246 size->cy = dc->vportExtY;
248 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
249 goto done;
250 if (!x || !y)
252 ret = FALSE;
253 goto done;
255 dc->vportExtX = x;
256 dc->vportExtY = y;
257 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
258 DC_UpdateXforms( dc );
259 done:
260 GDI_ReleaseObj( hdc );
261 return ret;
265 /***********************************************************************
266 * SetViewportOrgEx (GDI32.@)
268 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
270 INT ret = TRUE;
271 DC * dc = DC_GetDCPtr( hdc );
272 if (!dc) return FALSE;
273 if (dc->funcs->pSetViewportOrg)
275 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
277 if(ret == GDI_NO_MORE_WORK)
278 ret = TRUE;
279 goto done;
282 if (pt)
284 pt->x = dc->vportOrgX;
285 pt->y = dc->vportOrgY;
287 dc->vportOrgX = x;
288 dc->vportOrgY = y;
289 DC_UpdateXforms( dc );
291 done:
292 GDI_ReleaseObj( hdc );
293 return ret;
297 /***********************************************************************
298 * SetWindowExtEx (GDI32.@)
300 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
302 INT ret = TRUE;
303 DC * dc = DC_GetDCPtr( hdc );
304 if (!dc) return FALSE;
305 if (dc->funcs->pSetWindowExt)
307 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
309 if(ret == GDI_NO_MORE_WORK)
310 ret = TRUE;
311 goto done;
314 if (size)
316 size->cx = dc->wndExtX;
317 size->cy = dc->wndExtY;
319 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
320 goto done;
321 if (!x || !y)
323 ret = FALSE;
324 goto done;
326 dc->wndExtX = x;
327 dc->wndExtY = y;
328 /* Windows fixes MM_ISOTROPIC mode only in SetViewportExtEx() */
329 DC_UpdateXforms( dc );
330 done:
331 GDI_ReleaseObj( hdc );
332 return ret;
336 /***********************************************************************
337 * SetWindowOrgEx (GDI32.@)
339 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
341 INT ret = TRUE;
342 DC * dc = DC_GetDCPtr( hdc );
343 if (!dc) return FALSE;
344 if (dc->funcs->pSetWindowOrg)
346 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
348 if(ret == GDI_NO_MORE_WORK)
349 ret = TRUE;
350 goto done;
353 if (pt)
355 pt->x = dc->wndOrgX;
356 pt->y = dc->wndOrgY;
358 dc->wndOrgX = x;
359 dc->wndOrgY = y;
360 DC_UpdateXforms( dc );
361 done:
362 GDI_ReleaseObj( hdc );
363 return ret;
367 /***********************************************************************
368 * OffsetViewportOrgEx (GDI32.@)
370 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
372 INT ret = TRUE;
373 DC * dc = DC_GetDCPtr( hdc );
374 if (!dc) return FALSE;
375 if (dc->funcs->pOffsetViewportOrg)
377 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
379 if(ret == GDI_NO_MORE_WORK)
380 ret = TRUE;
381 goto done;
384 if (pt)
386 pt->x = dc->vportOrgX;
387 pt->y = dc->vportOrgY;
389 dc->vportOrgX += x;
390 dc->vportOrgY += y;
391 DC_UpdateXforms( dc );
392 done:
393 GDI_ReleaseObj( hdc );
394 return ret;
398 /***********************************************************************
399 * OffsetWindowOrgEx (GDI32.@)
401 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
403 INT ret = TRUE;
404 DC * dc = DC_GetDCPtr( hdc );
405 if (!dc) return FALSE;
406 if (dc->funcs->pOffsetWindowOrg)
408 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
410 if(ret == GDI_NO_MORE_WORK)
411 ret = TRUE;
412 goto done;
415 if (pt)
417 pt->x = dc->wndOrgX;
418 pt->y = dc->wndOrgY;
420 dc->wndOrgX += x;
421 dc->wndOrgY += y;
422 DC_UpdateXforms( dc );
423 done:
424 GDI_ReleaseObj( hdc );
425 return ret;
429 /***********************************************************************
430 * ScaleViewportExtEx (GDI32.@)
432 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
433 INT yNum, INT yDenom, LPSIZE size )
435 INT ret = TRUE;
436 DC * dc = DC_GetDCPtr( hdc );
437 if (!dc) return FALSE;
438 if (dc->funcs->pScaleViewportExt)
440 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
442 if(ret == GDI_NO_MORE_WORK)
443 ret = TRUE;
444 goto done;
447 if (size)
449 size->cx = dc->vportExtX;
450 size->cy = dc->vportExtY;
452 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
453 goto done;
454 if (!xNum || !xDenom || !xNum || !yDenom)
456 ret = FALSE;
457 goto done;
459 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
460 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
461 if (dc->vportExtX == 0) dc->vportExtX = 1;
462 if (dc->vportExtY == 0) dc->vportExtY = 1;
463 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
464 DC_UpdateXforms( dc );
465 done:
466 GDI_ReleaseObj( hdc );
467 return ret;
471 /***********************************************************************
472 * ScaleWindowExtEx (GDI32.@)
474 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
475 INT yNum, INT yDenom, LPSIZE size )
477 INT ret = TRUE;
478 DC * dc = DC_GetDCPtr( hdc );
479 if (!dc) return FALSE;
480 if (dc->funcs->pScaleWindowExt)
482 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
484 if(ret == GDI_NO_MORE_WORK)
485 ret = TRUE;
486 goto done;
489 if (size)
491 size->cx = dc->wndExtX;
492 size->cy = dc->wndExtY;
494 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
495 goto done;
496 if (!xNum || !xDenom || !xNum || !yDenom)
498 ret = FALSE;
499 goto done;
501 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
502 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
503 if (dc->wndExtX == 0) dc->wndExtX = 1;
504 if (dc->wndExtY == 0) dc->wndExtY = 1;
505 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
506 DC_UpdateXforms( dc );
507 done:
508 GDI_ReleaseObj( hdc );
509 return ret;