Release 940201
[wine.git] / windows / mapping.c
blobe361a0f8aea4bac7a510c0f59a2553f170975b95
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
9 #include "gdi.h"
12 /***********************************************************************
13 * MAPPING_FixIsotropic
15 * Fix viewport extensions for isotropic mode.
17 void MAPPING_FixIsotropic( DC * dc )
19 double xdim = (double)dc->w.VportExtX * dc->w.devCaps->horzSize /
20 (dc->w.devCaps->horzRes * dc->w.WndExtX);
21 double ydim = (double)dc->w.VportExtY * dc->w.devCaps->vertSize /
22 (dc->w.devCaps->vertRes * dc->w.WndExtY);
23 if (xdim > ydim)
25 dc->w.VportExtX = dc->w.VportExtX * ydim / xdim;
26 if (!dc->w.VportExtX) dc->w.VportExtX = 1;
28 else
30 dc->w.VportExtY = dc->w.VportExtY * xdim / ydim;
31 if (!dc->w.VportExtY) dc->w.VportExtY = 1;
35 /***********************************************************************
36 * DPtoLP (GDI.67)
38 BOOL DPtoLP( HDC hdc, LPPOINT points, int count )
40 POINT * pt;
41 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
42 if (!dc) return FALSE;
44 for (pt = points; count > 0; pt++, count--)
46 pt->x = XDPTOLP( dc, pt->x );
47 pt->y = YDPTOLP( dc, pt->y );
49 return TRUE;
53 /***********************************************************************
54 * LPtoDP (GDI.99)
56 BOOL LPtoDP( HDC hdc, LPPOINT points, int count )
58 POINT * pt;
59 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
60 if (!dc) return FALSE;
62 for (pt = points; count > 0; pt++, count--)
64 pt->x = XLPTODP( dc, pt->x );
65 pt->y = YLPTODP( dc, pt->y );
67 return TRUE;
71 /***********************************************************************
72 * SetMapMode (GDI.3)
74 WORD SetMapMode( HDC hdc, WORD mode )
76 WORD prevMode;
77 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
78 if (!dc) return 0;
80 #ifdef DEBUG_GDI
81 printf( "SetMapMode: %d %d\n", hdc, mode );
82 #endif
84 prevMode = dc->w.MapMode;
85 switch(mode)
87 case MM_TEXT:
88 dc->w.WndOrgX = dc->w.WndOrgY = 0;
89 dc->w.VportOrgX = dc->w.VportOrgY = 0;
90 dc->w.WndExtX = 1;
91 dc->w.WndExtY = 1;
92 dc->w.VportExtX = 1;
93 dc->w.VportExtY = 1;
94 break;
96 case MM_LOMETRIC:
97 case MM_ISOTROPIC:
98 dc->w.WndOrgX = dc->w.WndOrgY = 0;
99 dc->w.VportOrgX = dc->w.VportOrgY = 0;
100 dc->w.WndExtX = dc->w.devCaps->horzSize;
101 dc->w.WndExtY = dc->w.devCaps->vertSize;
102 dc->w.VportExtX = dc->w.devCaps->horzRes / 10;
103 dc->w.VportExtY = dc->w.devCaps->vertRes / -10;
104 break;
106 case MM_HIMETRIC:
107 dc->w.WndOrgX = dc->w.WndOrgY = 0;
108 dc->w.VportOrgX = dc->w.VportOrgY = 0;
109 dc->w.WndExtX = dc->w.devCaps->horzSize * 10;
110 dc->w.WndExtY = dc->w.devCaps->vertSize * 10;
111 dc->w.VportExtX = dc->w.devCaps->horzRes / 10;
112 dc->w.VportExtY = dc->w.devCaps->vertRes / -10;
113 break;
115 case MM_LOENGLISH:
116 dc->w.WndOrgX = dc->w.WndOrgY = 0;
117 dc->w.VportOrgX = dc->w.VportOrgY = 0;
118 dc->w.WndExtX = dc->w.devCaps->horzSize;
119 dc->w.WndExtY = dc->w.devCaps->vertSize;
120 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
121 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
122 break;
124 case MM_HIENGLISH:
125 dc->w.WndOrgX = dc->w.WndOrgY = 0;
126 dc->w.VportOrgX = dc->w.VportOrgY = 0;
127 dc->w.WndExtX = dc->w.devCaps->horzSize * 10;
128 dc->w.WndExtY = dc->w.devCaps->vertSize * 10;
129 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
130 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
131 break;
133 case MM_TWIPS:
134 dc->w.WndOrgX = dc->w.WndOrgY = 0;
135 dc->w.VportOrgX = dc->w.VportOrgY = 0;
136 dc->w.WndExtX = (short)(144L * dc->w.devCaps->horzSize / 10);
137 dc->w.WndExtY = (short)(144L * dc->w.devCaps->vertSize / 10);
138 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
139 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
140 break;
142 case MM_ANISOTROPIC:
143 break;
145 default:
146 return prevMode;
148 dc->w.MapMode = mode;
149 return prevMode;
153 /***********************************************************************
154 * SetViewportExt (GDI.14)
156 DWORD SetViewportExt( HDC hdc, short x, short y )
158 SIZE size;
159 if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
160 return size.cx | (size.cy << 16);
164 /***********************************************************************
165 * SetViewportExtEx (GDI.479)
167 BOOL SetViewportExtEx( HDC hdc, short x, short y, LPSIZE size )
169 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
170 if (!dc) return FALSE;
171 if (size)
173 size->cx = dc->w.VportExtX;
174 size->cy = dc->w.VportExtY;
176 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
177 return TRUE;
178 if (!x || !y) return FALSE;
179 dc->w.VportExtX = x;
180 dc->w.VportExtY = y;
181 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
182 return TRUE;
186 /***********************************************************************
187 * SetViewportOrg (GDI.13)
189 DWORD SetViewportOrg( HDC hdc, short x, short y )
191 POINT pt;
192 if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
193 return pt.x | (pt.y << 16);
197 /***********************************************************************
198 * SetViewportOrgEx (GDI.480)
200 BOOL SetViewportOrgEx( HDC hdc, short x, short y, LPPOINT pt )
202 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
203 if (!dc) return FALSE;
204 if (pt)
206 pt->x = dc->w.VportOrgX;
207 pt->y = dc->w.VportOrgY;
209 dc->w.VportOrgX = x;
210 dc->w.VportOrgY = y;
211 return TRUE;
215 /***********************************************************************
216 * SetWindowExt (GDI.12)
218 DWORD SetWindowExt( HDC hdc, short x, short y )
220 SIZE size;
221 if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
222 return size.cx | (size.cy << 16);
226 /***********************************************************************
227 * SetWindowExtEx (GDI.481)
229 BOOL SetWindowExtEx( HDC hdc, short x, short y, LPSIZE size )
231 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
232 if (!dc) return FALSE;
233 if (size)
235 size->cx = dc->w.WndExtX;
236 size->cy = dc->w.WndExtY;
238 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
239 return TRUE;
240 if (!x || !y) return FALSE;
241 dc->w.WndExtX = x;
242 dc->w.WndExtY = y;
243 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
244 return TRUE;
248 /***********************************************************************
249 * SetWindowOrg (GDI.11)
251 DWORD SetWindowOrg( HDC hdc, short x, short y )
253 POINT pt;
254 if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
255 return pt.x | (pt.y << 16);
259 /***********************************************************************
260 * SetWindowOrgEx (GDI.482)
262 BOOL SetWindowOrgEx( HDC hdc, short x, short y, LPPOINT pt )
264 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
265 if (!dc) return FALSE;
266 if (pt)
268 pt->x = dc->w.WndOrgX;
269 pt->y = dc->w.WndOrgY;
271 dc->w.WndOrgX = x;
272 dc->w.WndOrgY = y;
273 return TRUE;
277 /***********************************************************************
278 * OffsetViewportOrg (GDI.17)
280 DWORD OffsetViewportOrg( HDC hdc, short x, short y )
282 POINT pt;
283 if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
284 return pt.x | (pt.y << 16);
288 /***********************************************************************
289 * OffsetViewportOrgEx (GDI.476)
291 BOOL OffsetViewportOrgEx( HDC hdc, short x, short y, LPPOINT pt )
293 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
294 if (!dc) return FALSE;
295 if (pt)
297 pt->x = dc->w.VportOrgX;
298 pt->y = dc->w.VportOrgY;
300 dc->w.VportOrgX += x;
301 dc->w.VportOrgY += y;
302 return TRUE;
306 /***********************************************************************
307 * OffsetWindowOrg (GDI.15)
309 DWORD OffsetWindowOrg( HDC hdc, short x, short y )
311 POINT pt;
312 if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
313 return pt.x | (pt.y << 16);
317 /***********************************************************************
318 * OffsetWindowOrgEx (GDI.477)
320 BOOL OffsetWindowOrgEx( HDC hdc, short x, short y, LPPOINT pt )
322 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
323 if (!dc) return FALSE;
324 if (pt)
326 pt->x = dc->w.WndOrgX;
327 pt->y = dc->w.WndOrgY;
329 dc->w.WndOrgX += x;
330 dc->w.WndOrgY += y;
331 return TRUE;
335 /***********************************************************************
336 * ScaleViewportExt (GDI.18)
338 DWORD ScaleViewportExt( HDC hdc, short xNum, short xDenom,
339 short yNum, short yDenom )
341 SIZE size;
342 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
343 return 0;
344 return size.cx | (size.cy << 16);
348 /***********************************************************************
349 * ScaleViewportExtEx (GDI.484)
351 BOOL ScaleViewportExtEx( HDC hdc, short xNum, short xDenom,
352 short yNum, short yDenom, LPSIZE size )
354 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
355 if (!dc) return FALSE;
356 if (size)
358 size->cx = dc->w.VportExtX;
359 size->cy = dc->w.VportExtY;
361 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
362 return TRUE;
363 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
364 dc->w.VportExtX = (dc->w.VportExtX * xNum) / xDenom;
365 dc->w.VportExtY = (dc->w.VportExtY * yNum) / yDenom;
366 if (dc->w.VportExtX == 0) dc->w.VportExtX = 1;
367 if (dc->w.VportExtY == 0) dc->w.VportExtY = 1;
368 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
369 return TRUE;
373 /***********************************************************************
374 * ScaleWindowExt (GDI.16)
376 DWORD ScaleWindowExt( HDC hdc, short xNum, short xDenom,
377 short yNum, short yDenom )
379 SIZE size;
380 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
381 return 0;
382 return size.cx | (size.cy << 16);
386 /***********************************************************************
387 * ScaleWindowExtEx (GDI.485)
389 BOOL ScaleWindowExtEx( HDC hdc, short xNum, short xDenom,
390 short yNum, short yDenom, LPSIZE size )
392 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
393 if (!dc) return FALSE;
394 if (size)
396 size->cx = dc->w.WndExtX;
397 size->cy = dc->w.WndExtY;
399 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
400 return TRUE;
401 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
402 dc->w.WndExtX = (dc->w.WndExtX * xNum) / xDenom;
403 dc->w.WndExtY = (dc->w.WndExtY * yNum) / yDenom;
404 if (dc->w.WndExtX == 0) dc->w.WndExtX = 1;
405 if (dc->w.WndExtY == 0) dc->w.WndExtY = 1;
406 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
407 return TRUE;