- ...mised this one
[reactos.git] / reactos / dll / win32 / gdi32 / objects / coord.c
1 #include "precomp.h"
2
3 /* the following deal with IEEE single-precision numbers */
4 #define EXCESS 126L
5 #define SIGNBIT 0x80000000L
6 #define SIGN(fp) ((fp) & SIGNBIT)
7 #define EXP(fp) (((fp) >> 23L) & 0xFF)
8 #define MANT(fp) ((fp) & 0x7FFFFFL)
9 #define PACK(s,e,m) ((s) | ((e) << 23L) | (m))
10
11 // Sames as lrintf.
12 #ifdef __GNUC__
13 #define FLOAT_TO_INT(in,out) \
14 __asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st");
15 #else
16 #define FLOAT_TO_INT(in,out) \
17 __asm fld in; \
18 __asm fistp out;
19 #endif
20
21 LONG
22 FASTCALL
23 EFtoF( EFLOAT_S * efp)
24 {
25 long Mant, Exp, Sign = 0;
26
27 if (!efp->lMant) return 0;
28
29 Mant = efp->lMant;
30 Exp = efp->lExp;
31 Sign = SIGN(Mant);
32
33 //// M$ storage emulation
34 if( Sign ) Mant = -Mant;
35 Mant = ((Mant & 0x3fffffff) >> 7);
36 Exp += (EXCESS-1);
37 ////
38 Mant = MANT(Mant);
39 return PACK(Sign, Exp, Mant);
40 }
41
42 VOID
43 FASTCALL
44 FtoEF( EFLOAT_S * efp, FLOATL f)
45 {
46 long Mant, Exp, Sign = 0;
47 gxf_long worker;
48
49 #ifdef _X86_
50 worker.l = f; // It's a float stored in a long.
51 #else
52 worker.f = f;
53 #endif
54
55 Exp = EXP(worker.l);
56 Mant = MANT(worker.l);
57 if (SIGN(worker.l)) Sign = -1;
58 //// M$ storage emulation
59 Mant = ((Mant << 7) | 0x40000000);
60 Mant ^= Sign;
61 Mant -= Sign;
62 Exp -= (EXCESS-1);
63 ////
64 efp->lMant = Mant;
65 efp->lExp = Exp;
66 }
67
68
69 VOID FASTCALL
70 CoordCnvP(MATRIX_S * mx, LPPOINT Point)
71 {
72 FLOAT x, y;
73 gxf_long a, b, c;
74
75 x = (FLOAT)Point->x;
76 y = (FLOAT)Point->y;
77
78 a.l = EFtoF( &mx->efM11 );
79 b.l = EFtoF( &mx->efM21 );
80 c.l = EFtoF( &mx->efDx );
81 x = x * a.f + y * b.f + c.f;
82
83 a.l = EFtoF( &mx->efM12 );
84 b.l = EFtoF( &mx->efM22 );
85 c.l = EFtoF( &mx->efDy );
86 y = x * a.f + y * b.f + c.f;
87
88 FLOAT_TO_INT(x, Point->x );
89 FLOAT_TO_INT(y, Point->y );
90 }
91
92
93 BOOL
94 WINAPI
95 DPtoLP ( HDC hDC, LPPOINT Points, INT Count )
96 {
97 #if 0
98 INT i;
99 PDC_ATTR Dc_Attr;
100
101 if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
102
103 if (Dc_Attr->flXform & ( DEVICE_TO_WORLD_INVALID | // Force a full recalibration!
104 PAGE_XLATE_CHANGED | // Changes or Updates have been made,
105 PAGE_EXTENTS_CHANGED | // do processing in kernel space.
106 WORLD_XFORM_CHANGED ))
107 #endif
108 return NtGdiTransformPoints( hDC, Points, Points, Count, GdiDpToLp); // DPtoLP mode.
109 #if 0
110 else
111 {
112 for ( i = 0; i < Count; i++ )
113 CoordCnvP ( &Dc_Attr->mxDeviceToWorld, &Points[i] );
114 }
115 return TRUE;
116 #endif
117 }
118
119
120 BOOL
121 WINAPI
122 LPtoDP ( HDC hDC, LPPOINT Points, INT Count )
123 {
124 #if 0
125 INT i;
126 PDC_ATTR Dc_Attr;
127
128 if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
129
130 if (Dc_Attr->flXform & ( PAGE_XLATE_CHANGED | // Check for Changes and Updates
131 PAGE_EXTENTS_CHANGED |
132 WORLD_XFORM_CHANGED ))
133 #endif
134 return NtGdiTransformPoints( hDC, Points, Points, Count, GdiLpToDp); // LPtoDP mode
135 #if 0
136 else
137 {
138 for ( i = 0; i < Count; i++ )
139 CoordCnvP ( &Dc_Attr->mxWorldToDevice, &Points[i] );
140 }
141 return TRUE;
142 #endif
143 }
144
145 /*
146 * @implemented
147 *
148 */
149 BOOL
150 WINAPI
151 GetCurrentPositionEx(HDC hdc,
152 LPPOINT lpPoint)
153 {
154 PDC_ATTR Dc_Attr;
155
156 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
157
158 if ( lpPoint )
159 {
160 if ( Dc_Attr->ulDirty_ & DIRTY_PTLCURRENT ) // have a hit!
161 {
162 lpPoint->x = Dc_Attr->ptfxCurrent.x;
163 lpPoint->y = Dc_Attr->ptfxCurrent.y;
164 DPtoLP ( hdc, lpPoint, 1); // reconvert back.
165 Dc_Attr->ptlCurrent.x = lpPoint->x; // save it
166 Dc_Attr->ptlCurrent.y = lpPoint->y;
167 Dc_Attr->ulDirty_ &= ~DIRTY_PTLCURRENT; // clear bit
168 }
169 else
170 {
171 lpPoint->x = Dc_Attr->ptlCurrent.x;
172 lpPoint->y = Dc_Attr->ptlCurrent.y;
173 }
174 }
175 else
176 {
177 SetLastError(ERROR_INVALID_PARAMETER);
178 return FALSE;
179 }
180 return TRUE;
181 }
182
183 /*
184 * @implemented
185 */
186 BOOL
187 WINAPI
188 GetWorldTransform( HDC hDC, LPXFORM lpXform )
189 {
190 return NtGdiGetTransform( hDC, GdiWorldSpaceToPageSpace, lpXform);
191 }
192
193
194 BOOL
195 WINAPI
196 SetWorldTransform( HDC hDC, CONST XFORM *Xform )
197 {
198 /* FIXME shall we add undoc #define MWT_SETXFORM 4 ?? */
199 return ModifyWorldTransform( hDC, Xform, MWT_MAX+1);
200 }
201
202
203 BOOL
204 WINAPI
205 ModifyWorldTransform(
206 HDC hDC,
207 CONST XFORM *Xform,
208 DWORD iMode
209 )
210 {
211 #if 0
212 // Handle something other than a normal dc object.
213 if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)
214 {
215 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
216 return FALSE;
217 else
218 {
219 PLDC pLDC = GdiGetLDC(hDC);
220 if ( !pLDC )
221 {
222 SetLastError(ERROR_INVALID_HANDLE);
223 return FALSE;
224 }
225 if (pLDC->iType == LDC_EMFLDC)
226 {
227 if (iMode == MWT_MAX+1)
228 if (!EMFDRV_SetWorldTransform( hDC, Xform) ) return FALSE;
229 return EMFDRV_ModifyWorldTransform( hDC, Xform, iMode); // Ported from wine.
230 }
231 return FALSE;
232 }
233 }
234 #endif
235 PDC_ATTR Dc_Attr;
236
237 if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
238
239 /* Check that graphics mode is GM_ADVANCED */
240 if ( Dc_Attr->iGraphicsMode != GM_ADVANCED ) return FALSE;
241
242 return NtGdiModifyWorldTransform(hDC, (CONST LPXFORM) Xform, iMode);
243 }
244
245 BOOL
246 WINAPI
247 GetViewportExtEx(
248 HDC hdc,
249 LPSIZE lpSize
250 )
251 {
252 PDC_ATTR Dc_Attr;
253
254 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
255
256 if ((Dc_Attr->flXform & PAGE_EXTENTS_CHANGED) && (Dc_Attr->iMapMode == MM_ISOTROPIC))
257 // Something was updated, go to kernel.
258 return NtGdiGetDCPoint( hdc, GdiGetViewPortExt, (LPPOINT) lpSize );
259 else
260 {
261 lpSize->cx = Dc_Attr->szlViewportExt.cx;
262 lpSize->cy = Dc_Attr->szlViewportExt.cy;
263 }
264 return TRUE;
265 }
266
267
268 BOOL
269 WINAPI
270 GetViewportOrgEx(
271 HDC hdc,
272 LPPOINT lpPoint
273 )
274 {
275 PDC_ATTR Dc_Attr;
276
277 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
278 lpPoint->x = Dc_Attr->ptlViewportOrg.x;
279 lpPoint->y = Dc_Attr->ptlViewportOrg.y;
280 if (Dc_Attr->dwLayout & LAYOUT_RTL) lpPoint->x = -lpPoint->x;
281 return TRUE;
282 // return NtGdiGetDCPoint( hdc, GdiGetViewPortOrg, lpPoint );
283 }
284
285
286 BOOL
287 WINAPI
288 GetWindowExtEx(
289 HDC hdc,
290 LPSIZE lpSize
291 )
292 {
293 PDC_ATTR Dc_Attr;
294
295 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
296 lpSize->cx = Dc_Attr->szlWindowExt.cx;
297 lpSize->cy = Dc_Attr->szlWindowExt.cy;
298 if (Dc_Attr->dwLayout & LAYOUT_RTL) lpSize->cx = -lpSize->cx;
299 return TRUE;
300 // return NtGdiGetDCPoint( hdc, GdiGetWindowExt, (LPPOINT) lpSize );
301 }
302
303
304 BOOL
305 WINAPI
306 GetWindowOrgEx(
307 HDC hdc,
308 LPPOINT lpPoint
309 )
310 {
311 PDC_ATTR Dc_Attr;
312
313 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
314 lpPoint->x = Dc_Attr->ptlWindowOrg.x;
315 lpPoint->y = Dc_Attr->ptlWindowOrg.y;
316 return TRUE;
317 //return NtGdiGetDCPoint( hdc, GdiGetWindowOrg, lpPoint );
318 }
319
320 /*
321 * @unimplemented
322 */
323 BOOL
324 WINAPI
325 SetViewportExtEx(HDC hdc,
326 int nXExtent,
327 int nYExtent,
328 LPSIZE lpSize)
329 {
330 PDC_ATTR Dc_Attr;
331 #if 0
332 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
333 {
334 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
335 return MFDRV_SetViewportExtEx();
336 else
337 {
338 PLDC pLDC = GdiGetLDC(hdc);
339 if ( !pLDC )
340 {
341 SetLastError(ERROR_INVALID_HANDLE);
342 return FALSE;
343 }
344 if (pLDC->iType == LDC_EMFLDC)
345 {
346 return EMFDRV_SetViewportExtEx();
347 }
348 }
349 }
350 #endif
351 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr))
352 {
353 return FALSE;
354 }
355
356 if (lpSize)
357 {
358 lpSize->cx = Dc_Attr->szlViewportExt.cx;
359 lpSize->cy = Dc_Attr->szlViewportExt.cy;
360 }
361
362 if ((Dc_Attr->szlViewportExt.cx == nXExtent) && (Dc_Attr->szlViewportExt.cy == nYExtent))
363 return TRUE;
364
365 if ((Dc_Attr->iMapMode == MM_ISOTROPIC) || (Dc_Attr->iMapMode == MM_ANISOTROPIC))
366 {
367 if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
368 {
369 if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
370 {
371 NtGdiFlush(); // Sync up Dc_Attr from Kernel space.
372 Dc_Attr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
373 }
374 }
375 Dc_Attr->szlViewportExt.cx = nXExtent;
376 Dc_Attr->szlViewportExt.cy = nYExtent;
377 if (Dc_Attr->dwLayout & LAYOUT_RTL) NtGdiMirrorWindowOrg(hdc);
378 Dc_Attr->flXform |= (PAGE_EXTENTS_CHANGED|INVALIDATE_ATTRIBUTES|DEVICE_TO_WORLD_INVALID);
379 }
380 return TRUE;
381 }
382
383 /*
384 * @unimplemented
385 */
386 BOOL
387 WINAPI
388 SetWindowOrgEx(HDC hdc,
389 int X,
390 int Y,
391 LPPOINT lpPoint)
392 {
393 #if 0
394 PDC_ATTR Dc_Attr;
395 #if 0
396 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
397 {
398 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
399 return MFDRV_SetWindowOrgEx();
400 else
401 {
402 PLDC pLDC = GdiGetLDC(hdc);
403 if ( !pLDC )
404 {
405 SetLastError(ERROR_INVALID_HANDLE);
406 return FALSE;
407 }
408 if (pLDC->iType == LDC_EMFLDC)
409 {
410 return EMFDRV_SetWindowOrgEx();
411 }
412 }
413 }
414 #endif
415 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
416
417 if (lpPoint)
418 {
419 lpPoint->x = Dc_Attr->ptlWindowOrg.x;
420 lpPoint->y = Dc_Attr->ptlWindowOrg.y;
421 }
422
423 if ((Dc_Attr->ptlWindowOrg.x == X) && (Dc_Attr->ptlWindowOrg.y == Y))
424 return TRUE;
425
426 if (NtCurrentTeb()->GdiTebBatch.HDC == (ULONG)hdc)
427 {
428 if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
429 {
430 NtGdiFlush(); // Sync up Dc_Attr from Kernel space.
431 Dc_Attr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
432 }
433 }
434
435 Dc_Attr->ptlWindowOrg.x = X;
436 Dc_Attr->lWindowOrgx = X;
437 Dc_Attr->ptlWindowOrg.y = Y;
438 if (Dc_Attr->dwLayout & LAYOUT_RTL) NtGdiMirrorWindowOrg(hdc);
439 Dc_Attr->flXform |= (PAGE_XLATE_CHANGED|DEVICE_TO_WORLD_INVALID);
440 return TRUE;
441 #endif
442 return NtGdiSetWindowOrgEx(hdc,X,Y,lpPoint);
443 }
444
445 /*
446 * @unimplemented
447 */
448 BOOL
449 WINAPI
450 SetWindowExtEx(HDC hdc,
451 int nXExtent,
452 int nYExtent,
453 LPSIZE lpSize)
454 {
455 PDC_ATTR Dc_Attr;
456 #if 0
457 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
458 {
459 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
460 return MFDRV_SetWindowExtEx();
461 else
462 {
463 PLDC pLDC = GdiGetLDC(hdc);
464 if ( !pLDC )
465 {
466 SetLastError(ERROR_INVALID_HANDLE);
467 return FALSE;
468 }
469 if (pLDC->iType == LDC_EMFLDC)
470 {
471 return EMFDRV_SetWindowExtEx();
472 }
473 }
474 }
475 #endif
476 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
477
478 if (lpSize)
479 {
480 lpSize->cx = Dc_Attr->szlWindowExt.cx;
481 lpSize->cy = Dc_Attr->szlWindowExt.cy;
482 if (Dc_Attr->dwLayout & LAYOUT_RTL) lpSize->cx = -lpSize->cx;
483 }
484
485 if (Dc_Attr->dwLayout & LAYOUT_RTL)
486 {
487 NtGdiMirrorWindowOrg(hdc);
488 Dc_Attr->flXform |= (PAGE_EXTENTS_CHANGED|INVALIDATE_ATTRIBUTES|DEVICE_TO_WORLD_INVALID);
489 }
490 else if ((Dc_Attr->iMapMode == MM_ISOTROPIC) || (Dc_Attr->iMapMode == MM_ANISOTROPIC))
491 {
492 if ((Dc_Attr->szlWindowExt.cx == nXExtent) && (Dc_Attr->szlWindowExt.cy == nYExtent))
493 return TRUE;
494
495 if ((!nXExtent) || (!nYExtent)) return FALSE;
496
497 if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
498 {
499 if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
500 {
501 NtGdiFlush(); // Sync up Dc_Attr from Kernel space.
502 Dc_Attr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
503 }
504 }
505 Dc_Attr->szlWindowExt.cx = nXExtent;
506 Dc_Attr->szlWindowExt.cy = nYExtent;
507 if (Dc_Attr->dwLayout & LAYOUT_RTL) NtGdiMirrorWindowOrg(hdc);
508 Dc_Attr->flXform |= (PAGE_EXTENTS_CHANGED|INVALIDATE_ATTRIBUTES|DEVICE_TO_WORLD_INVALID);
509 }
510 return TRUE; // Return TRUE.
511 }
512
513 /*
514 * @unimplemented
515 */
516 BOOL
517 WINAPI
518 SetViewportOrgEx(HDC hdc,
519 int X,
520 int Y,
521 LPPOINT lpPoint)
522 {
523 #if 0
524 PDC_ATTR Dc_Attr;
525 #if 0
526 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
527 {
528 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
529 return MFDRV_SetViewportOrgEx();
530 else
531 {
532 PLDC pLDC = GdiGetLDC(hdc);
533 if ( !pLDC )
534 {
535 SetLastError(ERROR_INVALID_HANDLE);
536 return FALSE;
537 }
538 if (pLDC->iType == LDC_EMFLDC)
539 {
540 return EMFDRV_SetViewportOrgEx();
541 }
542 }
543 }
544 #endif
545 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
546
547 if (lpPoint)
548 {
549 lpPoint->x = Dc_Attr->ptlViewportOrg.x;
550 lpPoint->y = Dc_Attr->ptlViewportOrg.y;
551 if (Dc_Attr->dwLayout & LAYOUT_RTL) lpPoint->x = -lpPoint->x;
552 }
553 Dc_Attr->flXform |= (PAGE_XLATE_CHANGED|DEVICE_TO_WORLD_INVALID);
554 if (Dc_Attr->dwLayout & LAYOUT_RTL) X = -X;
555 Dc_Attr->ptlViewportOrg.x = X;
556 Dc_Attr->ptlViewportOrg.y = Y;
557 return TRUE;
558 #endif
559 return NtGdiSetViewportOrgEx(hdc,X,Y,lpPoint);
560 }
561
562 /*
563 * @implemented
564 */
565 BOOL
566 WINAPI
567 ScaleViewportExtEx(
568 HDC a0,
569 int a1,
570 int a2,
571 int a3,
572 int a4,
573 LPSIZE a5
574 )
575 {
576 #if 0
577 if (GDI_HANDLE_GET_TYPE(a0) != GDI_OBJECT_TYPE_DC)
578 {
579 if (GDI_HANDLE_GET_TYPE(a0) == GDI_OBJECT_TYPE_METADC)
580 return MFDRV_;
581 else
582 {
583 PLDC pLDC = GdiGetLDC(a0);
584 if ( !pLDC )
585 {
586 SetLastError(ERROR_INVALID_HANDLE);
587 return FALSE;
588 }
589 if (pLDC->iType == LDC_EMFLDC)
590 {
591 return EMFDRV_;
592 }
593 }
594 }
595 #endif
596 if (!GdiIsHandleValid((HGDIOBJ) a0) ||
597 (GDI_HANDLE_GET_TYPE(a0) != GDI_OBJECT_TYPE_DC)) return FALSE;
598
599 return NtGdiScaleViewportExtEx(a0, a1, a2, a3, a4, a5);
600 }
601
602 /*
603 * @implemented
604 */
605 BOOL
606 WINAPI
607 ScaleWindowExtEx(
608 HDC a0,
609 int a1,
610 int a2,
611 int a3,
612 int a4,
613 LPSIZE a5
614 )
615 {
616 #if 0
617 if (GDI_HANDLE_GET_TYPE(a0) != GDI_OBJECT_TYPE_DC)
618 {
619 if (GDI_HANDLE_GET_TYPE(a0) == GDI_OBJECT_TYPE_METADC)
620 return MFDRV_;
621 else
622 {
623 PLDC pLDC = GdiGetLDC(a0);
624 if ( !pLDC )
625 {
626 SetLastError(ERROR_INVALID_HANDLE);
627 return FALSE;
628 }
629 if (pLDC->iType == LDC_EMFLDC)
630 {
631 return EMFDRV_;
632 }
633 }
634 }
635 #endif
636 if (!GdiIsHandleValid((HGDIOBJ) a0) ||
637 (GDI_HANDLE_GET_TYPE(a0) != GDI_OBJECT_TYPE_DC)) return FALSE;
638
639 return NtGdiScaleWindowExtEx(a0, a1, a2, a3, a4, a5);
640 }
641
642 /*
643 * @implemented
644 */
645 DWORD
646 WINAPI
647 GetLayout(HDC hdc
648 )
649 {
650 PDC_ATTR Dc_Attr;
651 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return GDI_ERROR;
652 return Dc_Attr->dwLayout;
653 }
654
655
656 /*
657 * @implemented
658 */
659 DWORD
660 WINAPI
661 SetLayout(HDC hdc,
662 DWORD dwLayout)
663 {
664 #if 0
665 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
666 {
667 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
668 return MFDRV_SetLayout( hdc, dwLayout);
669 else
670 {
671 PLDC pLDC = GdiGetLDC(hdc);
672 if ( !pLDC )
673 {
674 SetLastError(ERROR_INVALID_HANDLE);
675 return 0;
676 }
677 if (pLDC->iType == LDC_EMFLDC)
678 {
679 return EMFDRV_SetLayout( hdc, dwLayout);
680 }
681 }
682 }
683 #endif
684 if (!GdiIsHandleValid((HGDIOBJ) hdc) ||
685 (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return GDI_ERROR;
686 return NtGdiSetLayout( hdc, -1, dwLayout);
687 }
688
689 /*
690 * @implemented
691 */
692 DWORD
693 WINAPI
694 SetLayoutWidth(HDC hdc,LONG wox,DWORD dwLayout)
695 {
696 if (!GdiIsHandleValid((HGDIOBJ) hdc) ||
697 (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return GDI_ERROR;
698 return NtGdiSetLayout( hdc, wox, dwLayout);
699 }
700
701 /*
702 * @implemented
703 *
704 */
705 BOOL
706 WINAPI
707 OffsetViewportOrgEx(HDC hdc,
708 int nXOffset,
709 int nYOffset,
710 LPPOINT lpPoint)
711 {
712 #if 0
713 PDC_ATTR Dc_Attr;
714 #if 0
715 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
716 {
717 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
718 return MFDRV_OffsetViewportOrgEx(hdc, nXOffset, nYOffset, lpPoint);
719 else
720 {
721 PLDC pLDC = GdiGetLDC(hdc);
722 if ( !pLDC )
723 {
724 SetLastError(ERROR_INVALID_HANDLE);
725 return FALSE;
726 }
727 if (pLDC->iType == LDC_EMFLDC)
728 {
729 return EMFDRV_OffsetWindowOrgEx(hdc, nXOffset, nYOffset, lpPoint);
730 }
731 }
732 }
733 #endif
734 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
735
736 if ( lpPoint )
737 {
738 *lpPoint = (POINT)Dc_Attr->ptlViewportOrg;
739 if ( Dc_Attr->dwLayout & LAYOUT_RTL) lpPoint->x = -lpPoint->x;
740 }
741
742 if ( nXOffset || nYOffset != nXOffset )
743 {
744 if (NtCurrentTeb()->GdiTebBatch.HDC == (ULONG)hdc)
745 {
746 if (Dc_Attr->ulDirty_ & DC_MODE_DIRTY)
747 {
748 NtGdiFlush();
749 Dc_Attr->ulDirty_ &= ~DC_MODE_DIRTY;
750 }
751 }
752 Dc_Attr->flXform |= (PAGE_XLATE_CHANGED|DEVICE_TO_WORLD_INVALID);
753 if ( Dc_Attr->dwLayout & LAYOUT_RTL) nXOffset = -nXOffset;
754 Dc_Attr->ptlViewportOrg.x += nXOffset;
755 Dc_Attr->ptlViewportOrg.y += nYOffset;
756 }
757 return TRUE;
758 #endif
759 return NtGdiOffsetViewportOrgEx(hdc, nXOffset, nYOffset, lpPoint);
760 }
761
762 /*
763 * @implemented
764 *
765 */
766 BOOL
767 WINAPI
768 OffsetWindowOrgEx(HDC hdc,
769 int nXOffset,
770 int nYOffset,
771 LPPOINT lpPoint)
772 {
773 #if 0
774 PDC_ATTR Dc_Attr;
775 #if 0
776 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)
777 {
778 if (GDI_HANDLE_GET_TYPE(hdc) == GDI_OBJECT_TYPE_METADC)
779 return MFDRV_OffsetWindowOrgEx(hdc, nXOffset, nYOffset, lpPoint);
780 else
781 {
782 PLDC pLDC = GdiGetLDC(hdc);
783 if ( !pLDC )
784 {
785 SetLastError(ERROR_INVALID_HANDLE);
786 return FALSE;
787 }
788 if (pLDC->iType == LDC_EMFLDC)
789 {
790 return EMFDRV_OffsetWindowOrgEx(hdc, nXOffset, nYOffset, lpPoint);
791 }
792 }
793 }
794 #endif
795 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
796
797 if ( lpPoint )
798 {
799 *lpPoint = (POINT)Dc_Attr->ptlWindowOrg;
800 lpPoint->x = Dc_Attr->lWindowOrgx;
801 }
802
803 if ( nXOffset || nYOffset != nXOffset )
804 {
805 if (NtCurrentTeb()->GdiTebBatch.HDC == (ULONG)hdc)
806 {
807 if (Dc_Attr->ulDirty_ & DC_MODE_DIRTY)
808 {
809 NtGdiFlush();
810 Dc_Attr->ulDirty_ &= ~DC_MODE_DIRTY;
811 }
812 }
813 Dc_Attr->flXform |= (PAGE_XLATE_CHANGED|DEVICE_TO_WORLD_INVALID);
814 Dc_Attr->ptlWindowOrg.x += nXOffset;
815 Dc_Attr->ptlWindowOrg.y += nYOffset;
816 Dc_Attr->lWindowOrgx += nXOffset;
817 }
818 return TRUE;
819 #endif
820 return NtGdiOffsetWindowOrgEx(hdc, nXOffset, nYOffset, lpPoint);
821 }
822