StgOpenStorage16: correct arguments to the CreateFile call.
[wine.git] / graphics / mapping.c
blob4cab2048f30b74525dc69c14d0fd010aea81c23a
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "dc.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->w.devCaps->horzSize /
21 (dc->w.devCaps->horzRes * dc->wndExtX);
22 double ydim = (double)dc->vportExtY * dc->w.devCaps->vertSize /
23 (dc->w.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 return TRUE;
55 /***********************************************************************
56 * DPtoLP (GDI32.65)
58 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
60 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
61 if (!dc) return FALSE;
63 while (count--)
65 if (!INTERNAL_DPTOLP( dc, points ))
66 return FALSE;
67 points++;
69 return TRUE;
73 /***********************************************************************
74 * LPtoDP16 (GDI.99)
76 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
78 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
79 if (!dc) return FALSE;
81 while (count--)
83 points->x = XLPTODP( dc, points->x );
84 points->y = YLPTODP( dc, points->y );
85 points++;
87 return TRUE;
91 /***********************************************************************
92 * LPtoDP (GDI32.247)
94 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
96 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
97 if (!dc) return FALSE;
99 while (count--)
101 INTERNAL_LPTODP( dc, points );
102 points++;
104 return TRUE;
108 /***********************************************************************
109 * SetMapMode16 (GDI.3)
111 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
113 return SetMapMode( hdc, mode );
117 /***********************************************************************
118 * SetMapMode (GDI32.321)
120 INT WINAPI SetMapMode( HDC hdc, INT mode )
122 INT prevMode;
123 DC * dc = DC_GetDCPtr( hdc );
124 if (!dc) return 0;
125 if (dc->funcs->pSetMapMode) return dc->funcs->pSetMapMode( dc, mode );
127 TRACE("%04x %d\n", hdc, mode );
129 prevMode = dc->w.MapMode;
130 switch(mode)
132 case MM_TEXT:
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->wndExtX = dc->w.devCaps->horzSize;
142 dc->wndExtY = dc->w.devCaps->vertSize;
143 dc->vportExtX = dc->w.devCaps->horzRes / 10;
144 dc->vportExtY = dc->w.devCaps->vertRes / -10;
145 break;
147 case MM_HIMETRIC:
148 dc->wndExtX = dc->w.devCaps->horzSize * 10;
149 dc->wndExtY = dc->w.devCaps->vertSize * 10;
150 dc->vportExtX = dc->w.devCaps->horzRes / 10;
151 dc->vportExtY = dc->w.devCaps->vertRes / -10;
152 break;
154 case MM_LOENGLISH:
155 dc->wndExtX = dc->w.devCaps->horzSize;
156 dc->wndExtY = dc->w.devCaps->vertSize;
157 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
158 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
159 break;
161 case MM_HIENGLISH:
162 dc->wndExtX = dc->w.devCaps->horzSize * 10;
163 dc->wndExtY = dc->w.devCaps->vertSize * 10;
164 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
165 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
166 break;
168 case MM_TWIPS:
169 dc->wndExtX = 144L * dc->w.devCaps->horzSize / 10;
170 dc->wndExtY = 144L * dc->w.devCaps->vertSize / 10;
171 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
172 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
173 break;
175 case MM_ANISOTROPIC:
176 break;
178 default:
179 return prevMode;
181 dc->w.MapMode = mode;
182 DC_UpdateXforms( dc );
183 return prevMode;
187 /***********************************************************************
188 * SetViewportExt (GDI.14)
190 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
192 SIZE size;
193 if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
194 return MAKELONG( size.cx, size.cy );
198 /***********************************************************************
199 * SetViewportExtEx16 (GDI.479)
201 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
203 SIZE size32;
204 BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
205 if (size) CONV_SIZE32TO16( &size32, size );
206 return ret;
210 /***********************************************************************
211 * SetViewportExtEx (GDI32.340)
213 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
215 DC * dc = DC_GetDCPtr( hdc );
216 if (!dc) return FALSE;
217 if (dc->funcs->pSetViewportExt)
218 return dc->funcs->pSetViewportExt( dc, x, y );
219 if (size)
221 size->cx = dc->vportExtX;
222 size->cy = dc->vportExtY;
224 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
225 return TRUE;
226 if (!x || !y) return FALSE;
227 dc->vportExtX = x;
228 dc->vportExtY = y;
229 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
230 DC_UpdateXforms( dc );
231 return TRUE;
235 /***********************************************************************
236 * SetViewportOrg (GDI.13)
238 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
240 POINT pt;
241 if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
242 return MAKELONG( pt.x, pt.y );
246 /***********************************************************************
247 * SetViewportOrgEx16 (GDI.480)
249 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
251 POINT pt32;
252 BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
253 if (pt) CONV_POINT32TO16( &pt32, pt );
254 return ret;
258 /***********************************************************************
259 * SetViewportOrgEx (GDI32.341)
261 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
263 DC * dc = DC_GetDCPtr( hdc );
264 if (!dc) return FALSE;
265 if (dc->funcs->pSetViewportOrg)
266 return dc->funcs->pSetViewportOrg( dc, x, y );
267 if (pt)
269 pt->x = dc->vportOrgX;
270 pt->y = dc->vportOrgY;
272 dc->vportOrgX = x;
273 dc->vportOrgY = y;
274 DC_UpdateXforms( dc );
275 return TRUE;
279 /***********************************************************************
280 * SetWindowExt (GDI.12)
282 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
284 SIZE size;
285 if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
286 return MAKELONG( size.cx, size.cy );
290 /***********************************************************************
291 * SetWindowExtEx16 (GDI.481)
293 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
295 SIZE size32;
296 BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
297 if (size) CONV_SIZE32TO16( &size32, size );
298 return ret;
302 /***********************************************************************
303 * SetWindowExtEx (GDI32.344)
305 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
307 DC * dc = DC_GetDCPtr( hdc );
308 if (!dc) return FALSE;
309 if (dc->funcs->pSetWindowExt) return dc->funcs->pSetWindowExt( dc, x, y );
310 if (size)
312 size->cx = dc->wndExtX;
313 size->cy = dc->wndExtY;
315 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
316 return TRUE;
317 if (!x || !y) return FALSE;
318 dc->wndExtX = x;
319 dc->wndExtY = y;
320 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
321 DC_UpdateXforms( dc );
322 return TRUE;
326 /***********************************************************************
327 * SetWindowOrg (GDI.11)
329 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
331 POINT pt;
332 if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
333 return MAKELONG( pt.x, pt.y );
337 /***********************************************************************
338 * SetWindowOrgEx16 (GDI.482)
340 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
342 POINT pt32;
343 BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
344 if (pt) CONV_POINT32TO16( &pt32, pt );
345 return ret;
349 /***********************************************************************
350 * SetWindowOrgEx (GDI32.345)
352 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
354 DC * dc = DC_GetDCPtr( hdc );
355 if (!dc) return FALSE;
356 if (dc->funcs->pSetWindowOrg) return dc->funcs->pSetWindowOrg( dc, x, y );
357 if (pt)
359 pt->x = dc->wndOrgX;
360 pt->y = dc->wndOrgY;
362 dc->wndOrgX = x;
363 dc->wndOrgY = y;
364 DC_UpdateXforms( dc );
365 return TRUE;
369 /***********************************************************************
370 * OffsetViewportOrg (GDI.17)
372 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
374 POINT pt;
375 if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
376 return MAKELONG( pt.x, pt.y );
380 /***********************************************************************
381 * OffsetViewportOrgEx16 (GDI.476)
383 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
385 POINT pt32;
386 BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
387 if (pt) CONV_POINT32TO16( &pt32, pt );
388 return ret;
392 /***********************************************************************
393 * OffsetViewportOrgEx (GDI32.257)
395 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
397 DC * dc = DC_GetDCPtr( hdc );
398 if (!dc) return FALSE;
399 if (dc->funcs->pOffsetViewportOrg)
400 return dc->funcs->pOffsetViewportOrg( dc, x, y );
401 if (pt)
403 pt->x = dc->vportOrgX;
404 pt->y = dc->vportOrgY;
406 dc->vportOrgX += x;
407 dc->vportOrgY += y;
408 DC_UpdateXforms( dc );
409 return TRUE;
413 /***********************************************************************
414 * OffsetWindowOrg (GDI.15)
416 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
418 POINT pt;
419 if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
420 return MAKELONG( pt.x, pt.y );
424 /***********************************************************************
425 * OffsetWindowOrgEx16 (GDI.477)
427 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
429 POINT pt32;
430 BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
431 if (pt) CONV_POINT32TO16( &pt32, pt );
432 return ret;
436 /***********************************************************************
437 * OffsetWindowOrgEx (GDI32.258)
439 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
441 DC * dc = DC_GetDCPtr( hdc );
442 if (!dc) return FALSE;
443 if (dc->funcs->pOffsetWindowOrg)
444 return dc->funcs->pOffsetWindowOrg( dc, x, y );
445 if (pt)
447 pt->x = dc->wndOrgX;
448 pt->y = dc->wndOrgY;
450 dc->wndOrgX += x;
451 dc->wndOrgY += y;
452 DC_UpdateXforms( dc );
453 return TRUE;
457 /***********************************************************************
458 * ScaleViewportExt (GDI.18)
460 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
461 INT16 yNum, INT16 yDenom )
463 SIZE size;
464 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
465 return FALSE;
466 return MAKELONG( size.cx, size.cy );
470 /***********************************************************************
471 * ScaleViewportExtEx16 (GDI.484)
473 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
474 INT16 yNum, INT16 yDenom, LPSIZE16 size )
476 SIZE size32;
477 BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
478 &size32 );
479 if (size) CONV_SIZE32TO16( &size32, size );
480 return ret;
484 /***********************************************************************
485 * ScaleViewportExtEx (GDI32.293)
487 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
488 INT yNum, INT yDenom, LPSIZE size )
490 DC * dc = DC_GetDCPtr( hdc );
491 if (!dc) return FALSE;
492 if (dc->funcs->pScaleViewportExt)
493 return dc->funcs->pScaleViewportExt( dc, xNum, xDenom, yNum, yDenom );
494 if (size)
496 size->cx = dc->vportExtX;
497 size->cy = dc->vportExtY;
499 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
500 return TRUE;
501 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
502 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
503 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
504 if (dc->vportExtX == 0) dc->vportExtX = 1;
505 if (dc->vportExtY == 0) dc->vportExtY = 1;
506 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
507 DC_UpdateXforms( dc );
508 return TRUE;
512 /***********************************************************************
513 * ScaleWindowExt (GDI.16)
515 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
516 INT16 yNum, INT16 yDenom )
518 SIZE size;
519 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
520 return FALSE;
521 return MAKELONG( size.cx, size.cy );
525 /***********************************************************************
526 * ScaleWindowExtEx16 (GDI.485)
528 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
529 INT16 yNum, INT16 yDenom, LPSIZE16 size )
531 SIZE size32;
532 BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
533 &size32 );
534 if (size) CONV_SIZE32TO16( &size32, size );
535 return ret;
539 /***********************************************************************
540 * ScaleWindowExtEx (GDI32.294)
542 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
543 INT yNum, INT yDenom, LPSIZE size )
545 DC * dc = DC_GetDCPtr( hdc );
546 if (!dc) return FALSE;
547 if (dc->funcs->pScaleWindowExt)
548 return dc->funcs->pScaleWindowExt( dc, xNum, xDenom, yNum, yDenom );
549 if (size)
551 size->cx = dc->wndExtX;
552 size->cy = dc->wndExtY;
554 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
555 return TRUE;
556 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
557 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
558 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
559 if (dc->wndExtX == 0) dc->wndExtX = 1;
560 if (dc->wndExtY == 0) dc->wndExtY = 1;
561 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
562 DC_UpdateXforms( dc );
563 return TRUE;