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
)
40 ULONG xdim
= EngMulDiv(dc
->vportExtX
, dc
->GDIInfo
->ulHorzSize
, dc
->GDIInfo
->ulHorzRes
) / dc
->wndExtX
;
41 ULONG ydim
= EngMulDiv(dc
->vportExtY
, dc
->GDIInfo
->ulVertSize
, dc
->GDIInfo
->ulVertRes
) / dc
->wndExtY
;
45 dc
->vportExtX
= dc
->vportExtX
* abs(ydim
/ xdim
);
46 if (!dc
->vportExtX
) dc
->vportExtX
= 1;
50 dc
->vportExtY
= dc
->vportExtY
* abs(xdim
/ ydim
);
51 if (!dc
->vportExtY
) dc
->vportExtY
= 1;
56 IntGdiCombineTransform(LPXFORM XFormResult
,
60 /* Check for illegal parameters */
61 if (!XFormResult
|| !xform1
|| !xform2
)
66 /* Create the result in a temporary XFORM, since xformResult may be
67 * equal to xform1 or xform2 */
68 XFormResult
->eM11
= xform1
->eM11
* xform2
->eM11
+ xform1
->eM12
* xform2
->eM21
;
69 XFormResult
->eM12
= xform1
->eM11
* xform2
->eM12
+ xform1
->eM12
* xform2
->eM22
;
70 XFormResult
->eM21
= xform1
->eM21
* xform2
->eM11
+ xform1
->eM22
* xform2
->eM21
;
71 XFormResult
->eM22
= xform1
->eM21
* xform2
->eM12
+ xform1
->eM22
* xform2
->eM22
;
72 XFormResult
->eDx
= xform1
->eDx
* xform2
->eM11
+ xform1
->eDy
* xform2
->eM21
+ xform2
->eDx
;
73 XFormResult
->eDy
= xform1
->eDx
* xform2
->eM12
+ xform1
->eDy
* xform2
->eM22
+ xform2
->eDy
;
78 BOOL STDCALL
NtGdiCombineTransform(LPXFORM UnsafeXFormResult
,
79 CONST LPXFORM Unsafexform1
,
80 CONST LPXFORM Unsafexform2
)
83 XFORM xform1
= {0}, xform2
= {0};
84 NTSTATUS Status
= STATUS_SUCCESS
;
89 ProbeForWrite(UnsafeXFormResult
,
92 ProbeForRead(Unsafexform1
,
95 ProbeForRead(Unsafexform2
,
98 xform1
= *Unsafexform1
;
99 xform2
= *Unsafexform2
;
103 Status
= _SEH_GetExceptionCode();
107 if(!NT_SUCCESS(Status
))
109 SetLastNtError(Status
);
113 Ret
= IntGdiCombineTransform(&xformTemp
, &xform1
, &xform2
);
115 /* Copy the result to xformResult */
118 /* pointer was already probed! */
119 *UnsafeXFormResult
= xformTemp
;
123 Status
= _SEH_GetExceptionCode();
127 if(!NT_SUCCESS(Status
))
129 SetLastNtError(Status
);
137 CoordDPtoLP(PDC Dc
, LPPOINT Point
)
142 Point
->x
= x
* Dc
->w
.xformVport2World
.eM11
+
143 y
* Dc
->w
.xformVport2World
.eM21
+ Dc
->w
.xformVport2World
.eDx
;
144 Point
->y
= x
* Dc
->w
.xformVport2World
.eM12
+
145 y
* Dc
->w
.xformVport2World
.eM22
+ Dc
->w
.xformVport2World
.eDy
;
150 IntDPtoLP ( PDC dc
, LPPOINT Points
, INT Count
)
156 for ( i
= 0; i
< Count
; i
++ )
157 CoordDPtoLP ( dc
, &Points
[i
] );
161 * Converts points from device coordinates into logical coordinates. Conversion depends on the mapping mode,
162 * world transfrom, viewport origin settings for the given device context.
163 * \param hDC device context.
164 * \param Points an array of POINT structures (in/out).
165 * \param Count number of elements in the array of POINT structures.
166 * \return TRUE if success.
170 LPPOINT UnsafePoints
,
174 NTSTATUS Status
= STATUS_SUCCESS
;
175 LPPOINT Points
= NULL
;
181 SetLastWin32Error(ERROR_INVALID_HANDLE
);
185 if (!UnsafePoints
|| Count
<= 0)
188 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
192 Size
= Count
* sizeof(POINT
);
194 Points
= (LPPOINT
)ExAllocatePoolWithTag(PagedPool
, Size
, TAG_COORD
);
198 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
204 ProbeForWrite(UnsafePoints
,
207 RtlCopyMemory(Points
,
213 Status
= _SEH_GetExceptionCode();
217 if(!NT_SUCCESS(Status
))
221 SetLastNtError(Status
);
225 IntDPtoLP(dc
, Points
, Count
);
229 /* pointer was already probed! */
230 RtlCopyMemory(UnsafePoints
,
236 Status
= _SEH_GetExceptionCode();
240 if(!NT_SUCCESS(Status
))
244 SetLastNtError(Status
);
255 IntGetGraphicsMode ( PDC dc
)
258 return dc
->w
.GraphicsMode
;
263 IntGdiModifyWorldTransform(PDC pDc
,
264 CONST LPXFORM lpXForm
,
267 ASSERT(pDc
&& lpXForm
);
272 pDc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
273 pDc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
274 pDc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
275 pDc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
276 pDc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
277 pDc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
280 case MWT_LEFTMULTIPLY
:
281 IntGdiCombineTransform(&pDc
->w
.xformWorld2Wnd
, lpXForm
, &pDc
->w
.xformWorld2Wnd
);
284 case MWT_RIGHTMULTIPLY
:
285 IntGdiCombineTransform(&pDc
->w
.xformWorld2Wnd
, &pDc
->w
.xformWorld2Wnd
, lpXForm
);
289 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
293 DC_UpdateXforms(pDc
);
300 NtGdiGetGraphicsMode ( HDC hDC
)
303 int GraphicsMode
; // default to failure
305 dc
= DC_LockDc ( hDC
);
308 SetLastWin32Error(ERROR_INVALID_HANDLE
);
312 GraphicsMode
= dc
->w
.GraphicsMode
;
320 NtGdiGetWorldTransform(HDC hDC
,
324 NTSTATUS Status
= STATUS_SUCCESS
;
326 dc
= DC_LockDc ( hDC
);
329 SetLastWin32Error(ERROR_INVALID_HANDLE
);
335 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
344 *XForm
= dc
->w
.xformWorld2Wnd
;
348 Status
= _SEH_GetExceptionCode();
353 return NT_SUCCESS(Status
);
358 CoordLPtoDP ( PDC Dc
, LPPOINT Point
)
367 Point
->x
= x
* Dc
->w
.xformWorld2Vport
.eM11
+
368 y
* Dc
->w
.xformWorld2Vport
.eM21
+ Dc
->w
.xformWorld2Vport
.eDx
;
369 Point
->y
= x
* Dc
->w
.xformWorld2Vport
.eM12
+
370 y
* Dc
->w
.xformWorld2Vport
.eM22
+ Dc
->w
.xformWorld2Vport
.eDy
;
375 IntLPtoDP ( PDC dc
, LPPOINT Points
, INT Count
)
381 for ( i
= 0; i
< Count
; i
++ )
382 CoordLPtoDP ( dc
, &Points
[i
] );
386 * Converts points from logical coordinates into device coordinates. Conversion depends on the mapping mode,
387 * world transfrom, viewport origin settings for the given device context.
388 * \param hDC device context.
389 * \param Points an array of POINT structures (in/out).
390 * \param Count number of elements in the array of POINT structures.
391 * \return TRUE if success.
394 NtGdiLPtoDP ( HDC hDC
, LPPOINT UnsafePoints
, INT Count
)
397 NTSTATUS Status
= STATUS_SUCCESS
;
398 LPPOINT Points
= NULL
;
404 SetLastWin32Error(ERROR_INVALID_HANDLE
);
408 if (!UnsafePoints
|| Count
<= 0)
411 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
415 Size
= Count
* sizeof(POINT
);
417 Points
= (LPPOINT
)ExAllocatePoolWithTag(PagedPool
, Size
, TAG_COORD
);
421 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
427 ProbeForWrite(UnsafePoints
,
430 RtlCopyMemory(Points
,
436 Status
= _SEH_GetExceptionCode();
440 if(!NT_SUCCESS(Status
))
444 SetLastNtError(Status
);
448 IntLPtoDP(dc
, Points
, Count
);
452 /* pointer was already probed! */
453 RtlCopyMemory(UnsafePoints
,
459 Status
= _SEH_GetExceptionCode();
463 if(!NT_SUCCESS(Status
))
467 SetLastNtError(Status
);
478 NtGdiModifyWorldTransform(HDC hDC
,
479 CONST LPXFORM UnsafeXForm
,
488 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
495 SetLastWin32Error(ERROR_INVALID_HANDLE
);
501 ProbeForRead(UnsafeXForm
, sizeof(XFORM
), 1);
502 RtlCopyMemory(&SafeXForm
, UnsafeXForm
, sizeof(XFORM
));
504 Ret
= IntGdiModifyWorldTransform(dc
, &SafeXForm
, Mode
);
508 SetLastNtError(_SEH_GetExceptionCode());
518 NtGdiOffsetViewportOrgEx(HDC hDC
,
524 NTSTATUS Status
= STATUS_SUCCESS
;
526 dc
= DC_LockDc ( hDC
);
529 SetLastWin32Error(ERROR_INVALID_HANDLE
);
537 ProbeForWrite(UnsafePoint
,
540 UnsafePoint
->x
= dc
->vportOrgX
;
541 UnsafePoint
->y
= dc
->vportOrgY
;
545 Status
= _SEH_GetExceptionCode();
549 if ( !NT_SUCCESS(Status
) )
551 SetLastNtError(Status
);
557 dc
->vportOrgX
+= XOffset
;
558 dc
->vportOrgY
+= YOffset
;
567 NtGdiOffsetWindowOrgEx(HDC hDC
,
577 SetLastWin32Error(ERROR_INVALID_HANDLE
);
583 NTSTATUS Status
= STATUS_SUCCESS
;
590 Point
->x
= dc
->wndOrgX
;
591 Point
->y
= dc
->wndOrgY
;
595 Status
= _SEH_GetExceptionCode();
599 if(!NT_SUCCESS(Status
))
601 SetLastNtError(Status
);
607 dc
->wndOrgX
+= XOffset
;
608 dc
->wndOrgY
+= YOffset
;
618 NtGdiScaleViewportExtEx(HDC hDC
,
631 NtGdiScaleWindowExtEx(HDC hDC
,
644 NtGdiSetGraphicsMode(HDC hDC
,
650 dc
= DC_LockDc (hDC
);
653 SetLastWin32Error(ERROR_INVALID_HANDLE
);
657 /* One would think that setting the graphics mode to GM_COMPATIBLE
658 * would also reset the world transformation matrix to the unity
659 * matrix. However, in Windows, this is not the case. This doesn't
660 * make a lot of sense to me, but that's the way it is.
663 if ((Mode
!= GM_COMPATIBLE
) && (Mode
!= GM_ADVANCED
))
666 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
670 ret
= dc
->w
.GraphicsMode
;
671 dc
->w
.GraphicsMode
= Mode
;
678 NtGdiSetMapMode(HDC hDC
,
687 SetLastWin32Error(ERROR_INVALID_HANDLE
);
691 PrevMapMode
= dc
->w
.MapMode
;
693 if (MapMode
!= dc
->w
.MapMode
|| (MapMode
!= MM_ISOTROPIC
&& MapMode
!= MM_ANISOTROPIC
))
695 dc
->w
.MapMode
= MapMode
;
708 dc
->wndExtX
= dc
->GDIInfo
->ulHorzSize
* 10;
709 dc
->wndExtY
= dc
->GDIInfo
->ulVertSize
* 10;
710 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
711 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
715 dc
->wndExtX
= dc
->GDIInfo
->ulHorzSize
* 100;
716 dc
->wndExtY
= dc
->GDIInfo
->ulVertSize
* 100;
717 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
718 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
722 dc
->wndExtX
= EngMulDiv(1000, dc
->GDIInfo
->ulHorzSize
, 254);
723 dc
->wndExtY
= EngMulDiv(1000, dc
->GDIInfo
->ulVertSize
, 254);
724 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
725 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
729 dc
->wndExtX
= EngMulDiv(10000, dc
->GDIInfo
->ulHorzSize
, 254);
730 dc
->wndExtY
= EngMulDiv(10000, dc
->GDIInfo
->ulVertSize
, 254);
731 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
732 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
736 dc
->wndExtX
= EngMulDiv(14400, dc
->GDIInfo
->ulHorzSize
, 254);
737 dc
->wndExtY
= EngMulDiv(14400, dc
->GDIInfo
->ulVertSize
, 254);
738 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
739 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
756 NtGdiSetViewportExtEx(HDC hDC
,
766 SetLastWin32Error(ERROR_INVALID_HANDLE
);
770 switch (dc
->w
.MapMode
)
782 // Here we should (probably) check that SetWindowExtEx *really* has
789 NTSTATUS Status
= STATUS_SUCCESS
;
796 Size
->cx
= dc
->vportExtX
;
797 Size
->cy
= dc
->vportExtY
;
799 dc
->vportExtX
= XExtent
;
800 dc
->vportExtY
= YExtent
;
802 if (dc
->w
.MapMode
== MM_ISOTROPIC
)
803 IntFixIsotropicMapping(dc
);
807 Status
= _SEH_GetExceptionCode();
811 if(!NT_SUCCESS(Status
))
813 SetLastNtError(Status
);
828 NtGdiSetViewportOrgEx(HDC hDC
,
838 SetLastWin32Error(ERROR_INVALID_HANDLE
);
844 NTSTATUS Status
= STATUS_SUCCESS
;
851 Point
->x
= dc
->vportOrgX
;
852 Point
->y
= dc
->vportOrgY
;
856 Status
= _SEH_GetExceptionCode();
860 if(!NT_SUCCESS(Status
))
862 SetLastNtError(Status
);
879 NtGdiSetWindowExtEx(HDC hDC
,
889 SetLastWin32Error(ERROR_INVALID_HANDLE
);
893 switch (dc
->w
.MapMode
)
907 NTSTATUS Status
= STATUS_SUCCESS
;
914 Size
->cx
= dc
->wndExtX
;
915 Size
->cy
= dc
->wndExtY
;
919 Status
= _SEH_GetExceptionCode();
923 if(!NT_SUCCESS(Status
))
925 SetLastNtError(Status
);
931 dc
->wndExtX
= XExtent
;
932 dc
->wndExtY
= YExtent
;
942 NtGdiSetWindowOrgEx(HDC hDC
,
952 SetLastWin32Error(ERROR_INVALID_HANDLE
);
958 NTSTATUS Status
= STATUS_SUCCESS
;
965 Point
->x
= dc
->wndOrgX
;
966 Point
->y
= dc
->wndOrgY
;
970 Status
= _SEH_GetExceptionCode();
974 if(!NT_SUCCESS(Status
))
976 SetLastNtError(Status
);
993 NtGdiSetWorldTransform(HDC hDC
,
997 NTSTATUS Status
= STATUS_SUCCESS
;
999 dc
= DC_LockDc (hDC
);
1002 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1009 /* Win doesn't set LastError */
1013 /* Check that graphics mode is GM_ADVANCED */
1014 if ( dc
->w
.GraphicsMode
!= GM_ADVANCED
)
1025 dc
->w
.xformWorld2Wnd
= *XForm
;
1029 Status
= _SEH_GetExceptionCode();
1033 if(!NT_SUCCESS(Status
))
1039 DC_UpdateXforms(dc
);