Moved lpClipper into common_directdrawsurface struct
[wine] / graphics / mapping.c
1 /*
2  * GDI mapping mode functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include "dc.h"
8 #include "debugtools.h"
9
10 DEFAULT_DEBUG_CHANNEL(gdi)
11
12
13 /***********************************************************************
14  *           MAPPING_FixIsotropic
15  *
16  * Fix viewport extensions for isotropic mode.
17  */
18 void MAPPING_FixIsotropic( DC * dc )
19 {
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)
25     {
26         dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
27         if (!dc->vportExtX) dc->vportExtX = 1;
28     }
29     else
30     {
31         dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
32         if (!dc->vportExtY) dc->vportExtY = 1;
33     }   
34 }
35
36
37 /***********************************************************************
38  *           DPtoLP16    (GDI.67)
39  */
40 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
41 {
42     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
43     if (!dc) return FALSE;
44
45     while (count--)
46     {
47         points->x = XDPTOLP( dc, points->x );
48         points->y = YDPTOLP( dc, points->y );
49         points++;
50     }
51     return TRUE;
52 }
53
54
55 /***********************************************************************
56  *           DPtoLP32    (GDI32.65)
57  */
58 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
59 {
60     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
61     if (!dc) return FALSE;
62
63     while (count--)
64     {
65         if (!INTERNAL_DPTOLP( dc, points ))
66             return FALSE;
67         points++;
68     }
69     return TRUE;
70 }
71
72
73 /***********************************************************************
74  *           LPtoDP16    (GDI.99)
75  */
76 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
77 {
78     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
79     if (!dc) return FALSE;
80
81     while (count--)
82     {
83         points->x = XLPTODP( dc, points->x );
84         points->y = YLPTODP( dc, points->y );
85         points++;
86     }
87     return TRUE;
88 }
89
90
91 /***********************************************************************
92  *           LPtoDP32    (GDI32.247)
93  */
94 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
95 {
96     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
97     if (!dc) return FALSE;
98
99     while (count--)
100     {
101         INTERNAL_LPTODP( dc, points );
102         points++;
103     }
104     return TRUE;
105 }
106
107
108 /***********************************************************************
109  *           SetMapMode16    (GDI.3)
110  */
111 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
112 {
113     return SetMapMode( hdc, mode );
114 }
115
116
117 /***********************************************************************
118  *           SetMapMode32    (GDI32.321)
119  */
120 INT WINAPI SetMapMode( HDC hdc, INT mode )
121 {
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 );
126
127     TRACE("%04x %d\n", hdc, mode );
128     
129     prevMode = dc->w.MapMode;
130     switch(mode)
131     {
132       case MM_TEXT:
133           dc->wndExtX   = 1;
134           dc->wndExtY   = 1;
135           dc->vportExtX = 1;
136           dc->vportExtY = 1;
137           break;
138           
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;
146           
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;
153           
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;          
160           
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;
167           
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;
174           
175       case MM_ANISOTROPIC:
176           break;
177
178       default:
179           return prevMode;
180     }
181     dc->w.MapMode = mode;
182     DC_UpdateXforms( dc );
183     return prevMode;
184 }
185
186
187 /***********************************************************************
188  *           SetViewportExt    (GDI.14)
189  */
190 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
191 {
192     SIZE size;
193     if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
194     return MAKELONG( size.cx, size.cy );
195 }
196
197
198 /***********************************************************************
199  *           SetViewportExtEx16    (GDI.479)
200  */
201 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
202 {
203     SIZE size32;
204     BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
205     if (size) CONV_SIZE32TO16( &size32, size );
206     return ret;
207 }
208
209
210 /***********************************************************************
211  *           SetViewportExtEx32    (GDI32.340)
212  */
213 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
214 {
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)
220     {
221         size->cx = dc->vportExtX;
222         size->cy = dc->vportExtY;
223     }
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;
232 }
233
234
235 /***********************************************************************
236  *           SetViewportOrg    (GDI.13)
237  */
238 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
239 {
240     POINT pt;
241     if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
242     return MAKELONG( pt.x, pt.y );
243 }
244
245
246 /***********************************************************************
247  *           SetViewportOrgEx16    (GDI.480)
248  */
249 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
250 {
251     POINT pt32;
252     BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
253     if (pt) CONV_POINT32TO16( &pt32, pt );
254     return ret;
255 }
256
257
258 /***********************************************************************
259  *           SetViewportOrgEx32    (GDI32.341)
260  */
261 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
262 {
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)
268     {
269         pt->x = dc->vportOrgX;
270         pt->y = dc->vportOrgY;
271     }
272     dc->vportOrgX = x;
273     dc->vportOrgY = y;
274     DC_UpdateXforms( dc );
275     return TRUE;
276 }
277
278
279 /***********************************************************************
280  *           SetWindowExt    (GDI.12)
281  */
282 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
283 {
284     SIZE size;
285     if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
286     return MAKELONG( size.cx, size.cy );
287 }
288
289
290 /***********************************************************************
291  *           SetWindowExtEx16    (GDI.481)
292  */
293 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
294 {
295     SIZE size32;
296     BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
297     if (size) CONV_SIZE32TO16( &size32, size );
298     return ret;
299 }
300
301
302 /***********************************************************************
303  *           SetWindowExtEx32    (GDI32.344)
304  */
305 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
306 {
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)
311     {
312         size->cx = dc->wndExtX;
313         size->cy = dc->wndExtY;
314     }
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;
323 }
324
325
326 /***********************************************************************
327  *           SetWindowOrg    (GDI.11)
328  */
329 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
330 {
331     POINT pt;
332     if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
333     return MAKELONG( pt.x, pt.y );
334 }
335
336
337 /***********************************************************************
338  *           SetWindowOrgEx16    (GDI.482)
339  */
340 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
341 {
342     POINT pt32;
343     BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
344     if (pt) CONV_POINT32TO16( &pt32, pt );
345     return ret;
346 }
347
348
349 /***********************************************************************
350  *           SetWindowOrgEx32    (GDI32.345)
351  */
352 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
353 {
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)
358     {
359         pt->x = dc->wndOrgX;
360         pt->y = dc->wndOrgY;
361     }
362     dc->wndOrgX = x;
363     dc->wndOrgY = y;
364     DC_UpdateXforms( dc );
365     return TRUE;
366 }
367
368
369 /***********************************************************************
370  *           OffsetViewportOrg    (GDI.17)
371  */
372 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
373 {
374     POINT pt;
375     if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
376     return MAKELONG( pt.x, pt.y );
377 }
378
379
380 /***********************************************************************
381  *           OffsetViewportOrgEx16    (GDI.476)
382  */
383 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
384 {
385     POINT pt32;
386     BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
387     if (pt) CONV_POINT32TO16( &pt32, pt );
388     return ret;
389 }
390
391
392 /***********************************************************************
393  *           OffsetViewportOrgEx32    (GDI32.257)
394  */
395 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
396 {
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)
402     {
403         pt->x = dc->vportOrgX;
404         pt->y = dc->vportOrgY;
405     }
406     dc->vportOrgX += x;
407     dc->vportOrgY += y;
408     DC_UpdateXforms( dc );
409     return TRUE;
410 }
411
412
413 /***********************************************************************
414  *           OffsetWindowOrg    (GDI.15)
415  */
416 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
417 {
418     POINT pt;
419     if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
420     return MAKELONG( pt.x, pt.y );
421 }
422
423
424 /***********************************************************************
425  *           OffsetWindowOrgEx16    (GDI.477)
426  */
427 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
428 {
429     POINT pt32;
430     BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
431     if (pt) CONV_POINT32TO16( &pt32, pt );
432     return ret;
433 }
434
435
436 /***********************************************************************
437  *           OffsetWindowOrgEx32    (GDI32.258)
438  */
439 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
440 {
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)
446     {
447         pt->x = dc->wndOrgX;
448         pt->y = dc->wndOrgY;
449     }
450     dc->wndOrgX += x;
451     dc->wndOrgY += y;
452     DC_UpdateXforms( dc );
453     return TRUE;
454 }
455
456
457 /***********************************************************************
458  *           ScaleViewportExt    (GDI.18)
459  */
460 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
461                                INT16 yNum, INT16 yDenom )
462 {
463     SIZE size;
464     if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
465         return FALSE;
466     return MAKELONG( size.cx,  size.cy );
467 }
468
469
470 /***********************************************************************
471  *           ScaleViewportExtEx16    (GDI.484)
472  */
473 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
474                                     INT16 yNum, INT16 yDenom, LPSIZE16 size )
475 {
476     SIZE size32;
477     BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
478                                        &size32 );
479     if (size) CONV_SIZE32TO16( &size32, size );
480     return ret;
481 }
482
483
484 /***********************************************************************
485  *           ScaleViewportExtEx32    (GDI32.293)
486  */
487 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
488                                     INT yNum, INT yDenom, LPSIZE size )
489 {
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)
495     {
496         size->cx = dc->vportExtX;
497         size->cy = dc->vportExtY;
498     }
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;
509 }
510
511
512 /***********************************************************************
513  *           ScaleWindowExt    (GDI.16)
514  */
515 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
516                              INT16 yNum, INT16 yDenom )
517 {
518     SIZE size;
519     if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
520         return FALSE;
521     return MAKELONG( size.cx,  size.cy );
522 }
523
524
525 /***********************************************************************
526  *           ScaleWindowExtEx16    (GDI.485)
527  */
528 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
529                                   INT16 yNum, INT16 yDenom, LPSIZE16 size )
530 {
531     SIZE size32;
532     BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
533                                      &size32 );
534     if (size) CONV_SIZE32TO16( &size32, size );
535     return ret;
536 }
537
538
539 /***********************************************************************
540  *           ScaleWindowExtEx32    (GDI32.294)
541  */
542 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
543                                   INT yNum, INT yDenom, LPSIZE size )
544 {
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)
550     {
551         size->cx = dc->wndExtX;
552         size->cy = dc->wndExtY;
553     }
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;
564 }