2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Coordinate systems
24 * FILE: subsys/win32k/objects/coord.c
28 /* INCLUDES ******************************************************************/
35 /* FUNCTIONS *****************************************************************/
38 IntFixIsotropicMapping(PDC dc
)
42 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
43 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
45 xdim
= EngMulDiv(Dc_Attr
->szlViewportExt
.cx
,
46 ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
,
47 ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
) /
48 Dc_Attr
->szlWindowExt
.cx
;
49 ydim
= EngMulDiv(Dc_Attr
->szlViewportExt
.cy
,
50 ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
,
51 ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
) /
52 Dc_Attr
->szlWindowExt
.cy
;
56 Dc_Attr
->szlViewportExt
.cx
= Dc_Attr
->szlViewportExt
.cx
* abs(ydim
/ xdim
);
57 if (!Dc_Attr
->szlViewportExt
.cx
) Dc_Attr
->szlViewportExt
.cx
= 1;
61 Dc_Attr
->szlViewportExt
.cy
= Dc_Attr
->szlViewportExt
.cy
* abs(xdim
/ ydim
);
62 if (!Dc_Attr
->szlViewportExt
.cy
) Dc_Attr
->szlViewportExt
.cy
= 1;
67 IntGdiCombineTransform(LPXFORM XFormResult
,
71 /* Check for illegal parameters */
72 if (!XFormResult
|| !xform1
|| !xform2
)
77 /* Create the result in a temporary XFORM, since xformResult may be
78 * equal to xform1 or xform2 */
79 XFormResult
->eM11
= xform1
->eM11
* xform2
->eM11
+ xform1
->eM12
* xform2
->eM21
;
80 XFormResult
->eM12
= xform1
->eM11
* xform2
->eM12
+ xform1
->eM12
* xform2
->eM22
;
81 XFormResult
->eM21
= xform1
->eM21
* xform2
->eM11
+ xform1
->eM22
* xform2
->eM21
;
82 XFormResult
->eM22
= xform1
->eM21
* xform2
->eM12
+ xform1
->eM22
* xform2
->eM22
;
83 XFormResult
->eDx
= xform1
->eDx
* xform2
->eM11
+ xform1
->eDy
* xform2
->eM21
+ xform2
->eDx
;
84 XFormResult
->eDy
= xform1
->eDx
* xform2
->eM12
+ xform1
->eDy
* xform2
->eM22
+ xform2
->eDy
;
89 BOOL STDCALL
NtGdiCombineTransform(LPXFORM UnsafeXFormResult
,
94 XFORM xform1
= {0}, xform2
= {0};
95 NTSTATUS Status
= STATUS_SUCCESS
;
100 ProbeForWrite(UnsafeXFormResult
,
103 ProbeForRead(Unsafexform1
,
106 ProbeForRead(Unsafexform2
,
109 xform1
= *Unsafexform1
;
110 xform2
= *Unsafexform2
;
114 Status
= _SEH_GetExceptionCode();
118 if(!NT_SUCCESS(Status
))
120 SetLastNtError(Status
);
124 Ret
= IntGdiCombineTransform(&xformTemp
, &xform1
, &xform2
);
126 /* Copy the result to xformResult */
129 /* pointer was already probed! */
130 *UnsafeXFormResult
= xformTemp
;
134 Status
= _SEH_GetExceptionCode();
138 if(!NT_SUCCESS(Status
))
140 SetLastNtError(Status
);
148 CoordDPtoLP(PDC Dc
, LPPOINT Point
)
153 Point
->x
= x
* Dc
->w
.xformVport2World
.eM11
+
154 y
* Dc
->w
.xformVport2World
.eM21
+ Dc
->w
.xformVport2World
.eDx
;
155 Point
->y
= x
* Dc
->w
.xformVport2World
.eM12
+
156 y
* Dc
->w
.xformVport2World
.eM22
+ Dc
->w
.xformVport2World
.eDy
;
161 IntDPtoLP ( PDC dc
, LPPOINT Points
, INT Count
)
167 for ( i
= 0; i
< Count
; i
++ )
168 CoordDPtoLP ( dc
, &Points
[i
] );
173 IntGetGraphicsMode ( PDC dc
)
177 Dc_Attr
= dc
->pDc_Attr
;
178 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
179 return Dc_Attr
->iGraphicsMode
;
184 IntGdiModifyWorldTransform(PDC pDc
,
185 CONST LPXFORM lpXForm
,
188 ASSERT(pDc
&& lpXForm
);
193 pDc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
194 pDc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
195 pDc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
196 pDc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
197 pDc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
198 pDc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
201 case MWT_LEFTMULTIPLY
:
202 IntGdiCombineTransform(&pDc
->w
.xformWorld2Wnd
, lpXForm
, &pDc
->w
.xformWorld2Wnd
);
205 case MWT_RIGHTMULTIPLY
:
206 IntGdiCombineTransform(&pDc
->w
.xformWorld2Wnd
, &pDc
->w
.xformWorld2Wnd
, lpXForm
);
209 case MWT_MAX
+1: // Must be MWT_SET????
210 pDc
->w
.xformWorld2Wnd
= *lpXForm
; // Do it like Wine.
214 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
217 DC_UpdateXforms(pDc
);
223 NtGdiGetTransform(HDC hDC
,
228 NTSTATUS Status
= STATUS_SUCCESS
;
230 dc
= DC_LockDc ( hDC
);
233 SetLastWin32Error(ERROR_INVALID_HANDLE
);
239 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
250 case GdiWorldSpaceToPageSpace
:
251 *XForm
= dc
->w
.xformWorld2Wnd
;
259 Status
= _SEH_GetExceptionCode();
264 return NT_SUCCESS(Status
);
269 CoordLPtoDP ( PDC Dc
, LPPOINT Point
)
278 Point
->x
= x
* Dc
->w
.xformWorld2Vport
.eM11
+
279 y
* Dc
->w
.xformWorld2Vport
.eM21
+ Dc
->w
.xformWorld2Vport
.eDx
;
280 Point
->y
= x
* Dc
->w
.xformWorld2Vport
.eM12
+
281 y
* Dc
->w
.xformWorld2Vport
.eM22
+ Dc
->w
.xformWorld2Vport
.eDy
;
286 IntLPtoDP ( PDC dc
, LPPOINT Points
, INT Count
)
292 for ( i
= 0; i
< Count
; i
++ )
293 CoordLPtoDP ( dc
, &Points
[i
] );
297 * Converts points from logical coordinates into device coordinates. Conversion depends on the mapping mode,
298 * world transfrom, viewport origin settings for the given device context.
299 * \param hDC device context.
300 * \param Points an array of POINT structures (in/out).
301 * \param Count number of elements in the array of POINT structures.
302 * \return TRUE if success.
306 NtGdiTransformPoints( HDC hDC
,
313 NTSTATUS Status
= STATUS_SUCCESS
;
320 SetLastWin32Error(ERROR_INVALID_HANDLE
);
324 if (!UnsafePtsIn
|| !UnsafePtOut
|| Count
<= 0)
327 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
331 Size
= Count
* sizeof(POINT
);
333 Points
= (LPPOINT
)ExAllocatePoolWithTag(PagedPool
, Size
, TAG_COORD
);
337 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
343 ProbeForWrite(UnsafePtOut
,
346 ProbeForRead(UnsafePtsIn
,
349 RtlCopyMemory(Points
,
355 Status
= _SEH_GetExceptionCode();
359 if(!NT_SUCCESS(Status
))
363 SetLastNtError(Status
);
370 IntDPtoLP(dc
, Points
, Count
);
373 IntLPtoDP(dc
, Points
, Count
);
375 case 2: // Not supported yet. Need testing.
380 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
387 /* pointer was already probed! */
388 RtlCopyMemory(UnsafePtOut
,
394 Status
= _SEH_GetExceptionCode();
398 if(!NT_SUCCESS(Status
))
402 SetLastNtError(Status
);
406 // If we are getting called that means User XForms is a mess!
415 NtGdiModifyWorldTransform(HDC hDC
,
425 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
432 SetLastWin32Error(ERROR_INVALID_HANDLE
);
438 ProbeForRead(UnsafeXForm
, sizeof(XFORM
), 1);
439 RtlCopyMemory(&SafeXForm
, UnsafeXForm
, sizeof(XFORM
));
443 SetLastNtError(_SEH_GetExceptionCode());
447 // Safe to handle kernel mode data.
448 Ret
= IntGdiModifyWorldTransform(dc
, &SafeXForm
, Mode
);
455 NtGdiOffsetViewportOrgEx(HDC hDC
,
462 NTSTATUS Status
= STATUS_SUCCESS
;
464 dc
= DC_LockDc ( hDC
);
467 SetLastWin32Error(ERROR_INVALID_HANDLE
);
470 Dc_Attr
= dc
->pDc_Attr
;
471 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
477 ProbeForWrite(UnsafePoint
,
480 UnsafePoint
->x
= Dc_Attr
->ptlViewportOrg
.x
;
481 UnsafePoint
->y
= Dc_Attr
->ptlViewportOrg
.y
;
485 Status
= _SEH_GetExceptionCode();
489 if ( !NT_SUCCESS(Status
) )
491 SetLastNtError(Status
);
497 Dc_Attr
->ptlViewportOrg
.x
+= XOffset
;
498 Dc_Attr
->ptlViewportOrg
.y
+= YOffset
;
506 NtGdiOffsetWindowOrgEx(HDC hDC
,
517 SetLastWin32Error(ERROR_INVALID_HANDLE
);
520 Dc_Attr
= dc
->pDc_Attr
;
521 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
525 NTSTATUS Status
= STATUS_SUCCESS
;
532 Point
->x
= Dc_Attr
->ptlWindowOrg
.x
;
533 Point
->y
= Dc_Attr
->ptlWindowOrg
.y
;
537 Status
= _SEH_GetExceptionCode();
541 if(!NT_SUCCESS(Status
))
543 SetLastNtError(Status
);
549 Dc_Attr
->ptlWindowOrg
.x
+= XOffset
;
550 Dc_Attr
->ptlWindowOrg
.y
+= YOffset
;
560 NtGdiScaleViewportExtEx(HDC hDC
,
573 NtGdiScaleWindowExtEx(HDC hDC
,
586 IntGdiSetMapMode(PDC dc
,
590 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
591 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
593 PrevMapMode
= Dc_Attr
->iMapMode
;
595 if (MapMode
!= Dc_Attr
->iMapMode
|| (MapMode
!= MM_ISOTROPIC
&& MapMode
!= MM_ANISOTROPIC
))
597 Dc_Attr
->iMapMode
= MapMode
;
602 Dc_Attr
->szlWindowExt
.cx
= 1;
603 Dc_Attr
->szlWindowExt
.cy
= 1;
604 Dc_Attr
->szlViewportExt
.cx
= 1;
605 Dc_Attr
->szlViewportExt
.cy
= 1;
610 Dc_Attr
->szlWindowExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
* 10;
611 Dc_Attr
->szlWindowExt
.cy
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
* 10;
612 Dc_Attr
->szlViewportExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
;
613 Dc_Attr
->szlViewportExt
.cy
= -((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
;
617 Dc_Attr
->szlWindowExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
* 100;
618 Dc_Attr
->szlWindowExt
.cy
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
* 100;
619 Dc_Attr
->szlViewportExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
;
620 Dc_Attr
->szlViewportExt
.cy
= -((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
;
624 Dc_Attr
->szlWindowExt
.cx
= EngMulDiv(1000, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
, 254);
625 Dc_Attr
->szlWindowExt
.cy
= EngMulDiv(1000, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
, 254);
626 Dc_Attr
->szlViewportExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
;
627 Dc_Attr
->szlViewportExt
.cy
= -((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
;
631 Dc_Attr
->szlWindowExt
.cx
= EngMulDiv(10000, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
, 254);
632 Dc_Attr
->szlWindowExt
.cy
= EngMulDiv(10000, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
, 254);
633 Dc_Attr
->szlViewportExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
;
634 Dc_Attr
->szlViewportExt
.cy
= -((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
;
638 Dc_Attr
->szlWindowExt
.cx
= EngMulDiv(14400, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzSize
, 254);
639 Dc_Attr
->szlWindowExt
.cy
= EngMulDiv(14400, ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertSize
, 254);
640 Dc_Attr
->szlViewportExt
.cx
= ((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulHorzRes
;
641 Dc_Attr
->szlViewportExt
.cy
= -((PGDIDEVICE
)dc
->pPDev
)->GDIInfo
.ulVertRes
;
656 NtGdiSetViewportExtEx(HDC hDC
,
667 SetLastWin32Error(ERROR_INVALID_HANDLE
);
670 Dc_Attr
= dc
->pDc_Attr
;
671 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
673 switch (Dc_Attr
->iMapMode
)
685 // Here we should (probably) check that SetWindowExtEx *really* has
692 NTSTATUS Status
= STATUS_SUCCESS
;
699 Size
->cx
= Dc_Attr
->szlViewportExt
.cx
;
700 Size
->cy
= Dc_Attr
->szlViewportExt
.cy
;
702 Dc_Attr
->szlViewportExt
.cx
= XExtent
;
703 Dc_Attr
->szlViewportExt
.cy
= YExtent
;
705 if (Dc_Attr
->iMapMode
== MM_ISOTROPIC
)
706 IntFixIsotropicMapping(dc
);
710 Status
= _SEH_GetExceptionCode();
714 if(!NT_SUCCESS(Status
))
716 SetLastNtError(Status
);
731 NtGdiSetViewportOrgEx(HDC hDC
,
742 SetLastWin32Error(ERROR_INVALID_HANDLE
);
745 Dc_Attr
= dc
->pDc_Attr
;
746 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
750 NTSTATUS Status
= STATUS_SUCCESS
;
757 Point
->x
= Dc_Attr
->ptlViewportOrg
.x
;
758 Point
->y
= Dc_Attr
->ptlViewportOrg
.y
;
762 Status
= _SEH_GetExceptionCode();
766 if(!NT_SUCCESS(Status
))
768 SetLastNtError(Status
);
774 Dc_Attr
->ptlViewportOrg
.x
= X
;
775 Dc_Attr
->ptlViewportOrg
.y
= Y
;
785 NtGdiSetWindowExtEx(HDC hDC
,
796 SetLastWin32Error(ERROR_INVALID_HANDLE
);
799 Dc_Attr
= dc
->pDc_Attr
;
800 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
802 switch (Dc_Attr
->iMapMode
)
816 NTSTATUS Status
= STATUS_SUCCESS
;
823 Size
->cx
= Dc_Attr
->szlWindowExt
.cx
;
824 Size
->cy
= Dc_Attr
->szlWindowExt
.cy
;
828 Status
= _SEH_GetExceptionCode();
832 if(!NT_SUCCESS(Status
))
834 SetLastNtError(Status
);
840 Dc_Attr
->szlWindowExt
.cx
= XExtent
;
841 Dc_Attr
->szlWindowExt
.cy
= YExtent
;
851 NtGdiSetWindowOrgEx(HDC hDC
,
862 SetLastWin32Error(ERROR_INVALID_HANDLE
);
865 Dc_Attr
= dc
->pDc_Attr
;
866 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
870 NTSTATUS Status
= STATUS_SUCCESS
;
877 Point
->x
= Dc_Attr
->ptlWindowOrg
.x
;
878 Point
->y
= Dc_Attr
->ptlWindowOrg
.y
;
882 Status
= _SEH_GetExceptionCode();
886 if(!NT_SUCCESS(Status
))
888 SetLastNtError(Status
);
894 Dc_Attr
->ptlWindowOrg
.x
= X
;
895 Dc_Attr
->ptlWindowOrg
.y
= Y
;
904 // Mirror Window function.
908 IntMirrorWindowOrg(PDC dc
)
913 Dc_Attr
= dc
->pDc_Attr
;
914 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
916 if (!(Dc_Attr
->dwLayout
& LAYOUT_RTL
))
918 Dc_Attr
->ptlWindowOrg
.x
= Dc_Attr
->lWindowOrgx
; // Flip it back.
921 if (!Dc_Attr
->szlViewportExt
.cx
) return;
923 // WOrgx = wox - (Width - 1) * WExtx / VExtx
925 X
= (dc
->erclWindow
.right
- dc
->erclWindow
.left
) - 1; // Get device width - 1
927 X
= ( X
* Dc_Attr
->szlWindowExt
.cx
) / Dc_Attr
->szlViewportExt
.cx
;
929 Dc_Attr
->ptlWindowOrg
.x
= Dc_Attr
->lWindowOrgx
- X
; // Now set the inverted win origion.
936 // The default is left to right. This function changes it to right to left, which
937 // is the standard in Arabic and Hebrew cultures.
956 SetLastWin32Error(ERROR_INVALID_HANDLE
);
959 Dc_Attr
= dc
->pDc_Attr
;
960 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
962 Dc_Attr
->dwLayout
= dwLayout
;
963 oLayout
= Dc_Attr
->dwLayout
;
965 if (!(dwLayout
& LAYOUT_ORIENTATIONMASK
))
971 if (dwLayout
& LAYOUT_RTL
) Dc_Attr
->iMapMode
= MM_ANISOTROPIC
;
973 Dc_Attr
->szlWindowExt
.cy
= -Dc_Attr
->szlWindowExt
.cy
;
974 Dc_Attr
->ptlWindowOrg
.x
= -Dc_Attr
->ptlWindowOrg
.x
;
977 IntMirrorWindowOrg(dc
);
979 Dc_Attr
->ptlWindowOrg
.x
= wox
- Dc_Attr
->ptlWindowOrg
.x
;
981 if (!(Dc_Attr
->flTextAlign
& TA_CENTER
)) Dc_Attr
->flTextAlign
|= TA_RIGHT
;
983 if (dc
->DcLevel
.flPath
& DCPATH_CLOCKWISE
)
984 dc
->DcLevel
.flPath
&= ~DCPATH_CLOCKWISE
;
986 dc
->DcLevel
.flPath
|= DCPATH_CLOCKWISE
;
988 Dc_Attr
->flXform
|= (PAGE_EXTENTS_CHANGED
|INVALIDATE_ATTRIBUTES
|DEVICE_TO_WORLD_INVALID
);
990 // DC_UpdateXforms(dc);
1000 NtGdiGetDeviceWidth(
1005 dc
= DC_LockDc(hdc
);
1008 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1011 Ret
= dc
->erclWindow
.right
- dc
->erclWindow
.left
;
1021 NtGdiMirrorWindowOrg(
1025 dc
= DC_LockDc(hdc
);
1028 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1031 IntMirrorWindowOrg(dc
);