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
;
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 NtGdiGetGraphicsMode ( HDC hDC
)
266 int GraphicsMode
; // default to failure
268 dc
= DC_LockDc ( hDC
);
271 SetLastWin32Error(ERROR_INVALID_HANDLE
);
275 GraphicsMode
= dc
->w
.GraphicsMode
;
283 NtGdiGetWorldTransform(HDC hDC
,
287 NTSTATUS Status
= STATUS_SUCCESS
;
289 dc
= DC_LockDc ( hDC
);
292 SetLastWin32Error(ERROR_INVALID_HANDLE
);
298 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
307 *XForm
= dc
->w
.xformWorld2Wnd
;
311 Status
= _SEH_GetExceptionCode();
316 return NT_SUCCESS(Status
);
321 CoordLPtoDP ( PDC Dc
, LPPOINT Point
)
330 Point
->x
= x
* Dc
->w
.xformWorld2Vport
.eM11
+
331 y
* Dc
->w
.xformWorld2Vport
.eM21
+ Dc
->w
.xformWorld2Vport
.eDx
;
332 Point
->y
= x
* Dc
->w
.xformWorld2Vport
.eM12
+
333 y
* Dc
->w
.xformWorld2Vport
.eM22
+ Dc
->w
.xformWorld2Vport
.eDy
;
338 IntLPtoDP ( PDC dc
, LPPOINT Points
, INT Count
)
344 for ( i
= 0; i
< Count
; i
++ )
345 CoordLPtoDP ( dc
, &Points
[i
] );
349 * Converts points from logical coordinates into device coordinates. Conversion depends on the mapping mode,
350 * world transfrom, viewport origin settings for the given device context.
351 * \param hDC device context.
352 * \param Points an array of POINT structures (in/out).
353 * \param Count number of elements in the array of POINT structures.
354 * \return TRUE if success.
357 NtGdiLPtoDP ( HDC hDC
, LPPOINT UnsafePoints
, INT Count
)
360 NTSTATUS Status
= STATUS_SUCCESS
;
367 SetLastWin32Error(ERROR_INVALID_HANDLE
);
371 if (!UnsafePoints
|| Count
<= 0)
374 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
378 Size
= Count
* sizeof(POINT
);
380 Points
= (LPPOINT
)ExAllocatePoolWithTag(PagedPool
, Size
, TAG_COORD
);
384 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
390 ProbeForWrite(UnsafePoints
,
393 RtlCopyMemory(Points
,
399 Status
= _SEH_GetExceptionCode();
403 if(!NT_SUCCESS(Status
))
407 SetLastNtError(Status
);
411 IntLPtoDP(dc
, Points
, Count
);
415 /* pointer was already probed! */
416 RtlCopyMemory(UnsafePoints
,
422 Status
= _SEH_GetExceptionCode();
426 if(!NT_SUCCESS(Status
))
430 SetLastNtError(Status
);
441 NtGdiModifyWorldTransform(HDC hDC
,
442 CONST LPXFORM UnsafeXForm
,
446 XFORM SafeXForm
= {0};
447 NTSTATUS Status
= STATUS_SUCCESS
;
452 SetLastWin32Error(ERROR_INVALID_HANDLE
);
459 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
465 ProbeForRead(UnsafeXForm
,
468 SafeXForm
= *UnsafeXForm
;
472 Status
= _SEH_GetExceptionCode();
476 if(!NT_SUCCESS(Status
))
479 SetLastNtError(Status
);
486 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
487 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
488 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
489 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
490 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
491 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
494 case MWT_LEFTMULTIPLY
:
495 IntGdiCombineTransform(&dc
->w
.xformWorld2Wnd
, &SafeXForm
, &dc
->w
.xformWorld2Wnd
);
498 case MWT_RIGHTMULTIPLY
:
499 IntGdiCombineTransform(&dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
, &SafeXForm
);
504 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
515 NtGdiOffsetViewportOrgEx(HDC hDC
,
521 NTSTATUS Status
= STATUS_SUCCESS
;
523 dc
= DC_LockDc ( hDC
);
526 SetLastWin32Error(ERROR_INVALID_HANDLE
);
534 ProbeForWrite(UnsafePoint
,
537 UnsafePoint
->x
= dc
->vportOrgX
;
538 UnsafePoint
->y
= dc
->vportOrgY
;
542 Status
= _SEH_GetExceptionCode();
546 if ( !NT_SUCCESS(Status
) )
548 SetLastNtError(Status
);
554 dc
->vportOrgX
+= XOffset
;
555 dc
->vportOrgY
+= YOffset
;
564 NtGdiOffsetWindowOrgEx(HDC hDC
,
574 SetLastWin32Error(ERROR_INVALID_HANDLE
);
580 NTSTATUS Status
= STATUS_SUCCESS
;
587 Point
->x
= dc
->wndOrgX
;
588 Point
->y
= dc
->wndOrgY
;
592 Status
= _SEH_GetExceptionCode();
596 if(!NT_SUCCESS(Status
))
598 SetLastNtError(Status
);
604 dc
->wndOrgX
+= XOffset
;
605 dc
->wndOrgY
+= YOffset
;
615 NtGdiScaleViewportExtEx(HDC hDC
,
628 NtGdiScaleWindowExtEx(HDC hDC
,
641 NtGdiSetGraphicsMode(HDC hDC
,
647 dc
= DC_LockDc (hDC
);
650 SetLastWin32Error(ERROR_INVALID_HANDLE
);
654 /* One would think that setting the graphics mode to GM_COMPATIBLE
655 * would also reset the world transformation matrix to the unity
656 * matrix. However, in Windows, this is not the case. This doesn't
657 * make a lot of sense to me, but that's the way it is.
660 if ((Mode
!= GM_COMPATIBLE
) && (Mode
!= GM_ADVANCED
))
663 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
667 ret
= dc
->w
.GraphicsMode
;
668 dc
->w
.GraphicsMode
= Mode
;
675 NtGdiSetMapMode(HDC hDC
,
684 SetLastWin32Error(ERROR_INVALID_HANDLE
);
688 PrevMapMode
= dc
->w
.MapMode
;
690 if (MapMode
!= dc
->w
.MapMode
|| (MapMode
!= MM_ISOTROPIC
&& MapMode
!= MM_ANISOTROPIC
))
692 dc
->w
.MapMode
= MapMode
;
705 dc
->wndExtX
= dc
->GDIInfo
->ulHorzSize
* 10;
706 dc
->wndExtY
= dc
->GDIInfo
->ulVertSize
* 10;
707 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
708 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
712 dc
->wndExtX
= dc
->GDIInfo
->ulHorzSize
* 100;
713 dc
->wndExtY
= dc
->GDIInfo
->ulVertSize
* 100;
714 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
715 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
719 dc
->wndExtX
= EngMulDiv(1000, dc
->GDIInfo
->ulHorzSize
, 254);
720 dc
->wndExtY
= EngMulDiv(1000, dc
->GDIInfo
->ulVertSize
, 254);
721 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
722 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
726 dc
->wndExtX
= EngMulDiv(10000, dc
->GDIInfo
->ulHorzSize
, 254);
727 dc
->wndExtY
= EngMulDiv(10000, dc
->GDIInfo
->ulVertSize
, 254);
728 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
729 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
733 dc
->wndExtX
= EngMulDiv(14400, dc
->GDIInfo
->ulHorzSize
, 254);
734 dc
->wndExtY
= EngMulDiv(14400, dc
->GDIInfo
->ulVertSize
, 254);
735 dc
->vportExtX
= dc
->GDIInfo
->ulHorzRes
;
736 dc
->vportExtY
= -dc
->GDIInfo
->ulVertRes
;
753 NtGdiSetViewportExtEx(HDC hDC
,
763 SetLastWin32Error(ERROR_INVALID_HANDLE
);
767 switch (dc
->w
.MapMode
)
779 // Here we should (probably) check that SetWindowExtEx *really* has
786 NTSTATUS Status
= STATUS_SUCCESS
;
793 Size
->cx
= dc
->vportExtX
;
794 Size
->cy
= dc
->vportExtY
;
798 Status
= _SEH_GetExceptionCode();
802 if(!NT_SUCCESS(Status
))
804 SetLastNtError(Status
);
810 dc
->vportExtX
= XExtent
;
811 dc
->vportExtY
= YExtent
;
813 if (dc
->w
.MapMode
== MM_ISOTROPIC
)
814 IntFixIsotropicMapping(dc
);
823 NtGdiSetViewportOrgEx(HDC hDC
,
833 SetLastWin32Error(ERROR_INVALID_HANDLE
);
839 NTSTATUS Status
= STATUS_SUCCESS
;
846 Point
->x
= dc
->vportOrgX
;
847 Point
->y
= dc
->vportOrgY
;
851 Status
= _SEH_GetExceptionCode();
855 if(!NT_SUCCESS(Status
))
857 SetLastNtError(Status
);
874 NtGdiSetWindowExtEx(HDC hDC
,
884 SetLastWin32Error(ERROR_INVALID_HANDLE
);
888 switch (dc
->w
.MapMode
)
902 NTSTATUS Status
= STATUS_SUCCESS
;
909 Size
->cx
= dc
->wndExtX
;
910 Size
->cy
= dc
->wndExtY
;
914 Status
= _SEH_GetExceptionCode();
918 if(!NT_SUCCESS(Status
))
920 SetLastNtError(Status
);
926 dc
->wndExtX
= XExtent
;
927 dc
->wndExtY
= YExtent
;
937 NtGdiSetWindowOrgEx(HDC hDC
,
947 SetLastWin32Error(ERROR_INVALID_HANDLE
);
953 NTSTATUS Status
= STATUS_SUCCESS
;
960 Point
->x
= dc
->wndOrgX
;
961 Point
->y
= dc
->wndOrgY
;
965 Status
= _SEH_GetExceptionCode();
969 if(!NT_SUCCESS(Status
))
971 SetLastNtError(Status
);
988 NtGdiSetWorldTransform(HDC hDC
,
992 NTSTATUS Status
= STATUS_SUCCESS
;
994 dc
= DC_LockDc (hDC
);
997 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1004 /* Win doesn't set LastError */
1008 /* Check that graphics mode is GM_ADVANCED */
1009 if ( dc
->w
.GraphicsMode
!= GM_ADVANCED
)
1020 dc
->w
.xformWorld2Wnd
= *XForm
;
1024 Status
= _SEH_GetExceptionCode();
1028 if(!NT_SUCCESS(Status
))
1034 DC_UpdateXforms(dc
);