home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / XFORM.ADB < prev    next >
Encoding:
Text File  |  1995-12-05  |  11.2 KB  |  322 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/xform.adb,v $ 
  2. -- $Revision: 1.1 $ $Date: 95/02/11 13:50:23 $ $Author: mg $ 
  3. -- $Id: xform.adb 1.2 1995/01/25 15:57:09 teg Exp teg $
  4. --
  5. --  This is a translation of xform.c which is a member of the Microsoft
  6. --  gdidemo sample application.  I believe that this collection of routines
  7. --  was under development and was not completely implemented (since the
  8. --  c version doesn't exercise this code).  
  9.  
  10.  
  11. with Win32;
  12. with Win32.WinDef;
  13. with Win32.WinUser;
  14. with Win32.WinGdi;
  15. with WinInfo;
  16. with Unchecked_Conversion;
  17. with Convert;
  18. with Gdidemo_Util;
  19.  
  20.  
  21. package body Xform is
  22.  
  23.   use Interfaces.C;
  24.  
  25.   use type System.Address;
  26.   use type Win32.LONG;
  27.   use type Win32.BOOL;
  28.  
  29.   --  Dummy function return values
  30.   bResult : Win32.BOOL;
  31.   uResult : Win32.UINT;
  32.   iResult : Win32.INT;
  33.   lReturn : Win32.LRESULT;
  34.  
  35.   -- aliased variables
  36.   mcs       : aliased Win32.WinUser.MDICREATESTRUCT;
  37.   rect_p    : aliased Win32.WinDef.RECT;
  38.   rect2_p   : aliased Win32.WinDef.RECT;
  39.   old_point : aliased Win32.WinDef.POINT;
  40.   poly_pts  : aliased pt_array;  --Win32.WinDef.POINT_A;
  41.   old_pt    : aliased Win32.WinDef.POINT;
  42.   poly2_pts : aliased pt_array;  --WinDef.POINT_A;
  43.   xForm_p   : aliased Win32.WinGdi.XFORM;
  44.   rect3_p   : aliased Win32.WinDef.RECT; 
  45.   ps        : aliased Win32.WinUser.PAINTSTRUCT;
  46.  
  47.  
  48.   -- Unchecked conversion utility functions
  49.   function HANDLE_TO_PXFORMDATA is new Unchecked_Conversion (Win32.Winnt.HANDLE,
  50.                                                              PXFORMDATA);
  51.   function PT_ARRAY_TO_PT is new Unchecked_Conversion (pt_array,
  52.                                                        Win32.Wingdi.ac_POINT_t);
  53.  
  54.   --  Local functions to this package body
  55.   procedure ResetXForm (hWnd_p : Win32.WinDef.HWND);
  56.   procedure DrawXForm (hWnd_p : Win32.WinDef.HWND);
  57.  
  58.  
  59. -- | CREATE XFORM WINDOW PROCEDURE
  60. procedure CreateXFormWindow (hWndClient : Win32.WinDef.HWND;
  61.                              nItem      : Win32.INT) is
  62.   hInst : Win32.Winnt.HANDLE;
  63.   mcs_p : Win32.WinUser.LPMDICREATESTRUCT;
  64. begin
  65.   hInst := Gdidemo_Util.GETINSTANCE (hWndClient);
  66.  
  67.   --  Initialize the MDI create struct for creation of the
  68.   --  test window.
  69.   mcs.szClass := XFORMCLASS;
  70.   mcs.szTitle := XFORMTITLE;
  71.   mcs.hOwner  := hInst;
  72.   mcs.x       := Win32.WinUser.CW_USEDEFAULT;
  73.   mcs.y       := Win32.WinUser.CW_USEDEFAULT;
  74.   mcs.cx      := Win32.WinUser.CW_USEDEFAULT;
  75.   mcs.cy      := Win32.WinUser.CW_USEDEFAULT;
  76.   mcs.style   := 0;
  77.   mcs.lParam  := Win32.LPARAM (nItem);
  78.  
  79.   mcs_p := mcs'Access;
  80.  
  81.   lReturn := Win32.WinUser.SendMessage
  82.                                 (hWndClient,
  83.                                  Win32.WinUser.WM_MDICREATE,
  84.                                  0,
  85.                                  Convert.LPMDICREATESTRUCT_TO_LPARAM (mcs_p));
  86.                                               
  87.  
  88. end CreateXFormWindow;
  89.  
  90.  
  91. -- | XFORM WINDOW PROCEDURE
  92. function XFormProc (hWnd_p   : Win32.WinDef.HWND;
  93.                     wMsg     : Win32.UINT;
  94.                     wParam_p : Win32.WPARAM;
  95.                     lParam_p : Win32.LPARAM) return Win32.LRESULT is
  96. begin
  97.   case wMsg is
  98.  
  99.     when Win32.WinUser.WM_CREATE =>
  100.       bResult := XFormCreateProc(hWnd_p);
  101.  
  102.     when Win32.WinUser.WM_MOVE =>
  103.       ResetXForm(hWnd_p);
  104.  
  105.     when Win32.WinUser.WM_TIMER =>
  106.       DrawXForm(hWnd_p);
  107.  
  108.     when Win32.WinUser.WM_COMMAND =>
  109.       bResult := XFormCommandProc(hWnd_p,wParam_p,lParam_p);
  110.  
  111.     when Win32.WinUser.WM_PAINT =>
  112.       XFormPaintProc(hWnd_p);
  113.  
  114.     when Win32.WinUser.WM_DESTROY =>
  115.       XFormDestroyProc(hWnd_p);
  116.  
  117.     when others =>
  118.       return Win32.WinUser.DefMDIChildProc(hWnd_p,wMsg,wParam_p,lParam_p);
  119.   end case;
  120.   return 0;
  121. end XFormProc;
  122.  
  123.  
  124. -- | XFORM CREATE PROCEDURE
  125. function XFormCreateProc (hWnd_p : Win32.WinDef.HWND) return Win32.BOOL is
  126.   pxd : PXFORMDATA := new XFORMDATA;
  127.   pxd_handle : Win32.Winnt.HANDLE;
  128.   dx, dy : Win32.LONG;
  129. begin
  130.   if WinInfo.AllocWindowInfo(hWnd_p,(XFORMDATA'size / 8)) = 
  131.      Win32.TRUE then
  132.     pxd_handle := WinInfo.LockWindowInfo (hWnd_p);
  133.     if pxd_handle /= System.Null_Address then 
  134.       pxd := HANDLE_TO_PXFORMDATA (pxd_handle);
  135.       bResult := Win32.WinUser.GetClientRect(hWnd_p,rect_p'Access);
  136.  
  137.       dx := (rect_p.right + rect_p.left) / 16; 
  138.       dy := (rect_p.bottom + rect_p.top) / 16; 
  139.  
  140.       pxd.pObject(0).x := dx * 2;  -- dx << 1;
  141.       pxd.pObject(0).y := 0;
  142.       pxd.pObject(1).x := dx;
  143.       pxd.pObject(1).y := dy;
  144.       pxd.pObject(2).x := 0;
  145.       pxd.pObject(2).y := dy;
  146.       pxd.pObject(3).x := dx * 2;  -- dx << 1;
  147.       pxd.pObject(3).y := 0;
  148.       pxd.nObject      := 4;
  149.  
  150.       pxd.xForm.eM11 := 0.866;
  151.       pxd.xForm.eM12 := 0.5;
  152.       pxd.xForm.eM21 := -0.5;
  153.       pxd.xForm.eM22 := 0.866;
  154.       pxd.xForm.eDx  := 0.0;
  155.       pxd.xForm.eDy  := 0.0;
  156.  
  157.       bResult := WinInfo.UnlockWindowInfo(hWnd_p);
  158.       uResult := Win32.WinUser.SetTimer (hWnd_p,1,500,null);
  159.       return Win32.TRUE;
  160.     end if;
  161.     bResult := WinInfo.FreeWindowInfo(hWnd_p);
  162.   end if;
  163.   return Win32.FALSE;
  164. end XFormCreateProc;
  165.  
  166.  
  167. -- | XFORM COMMAND PROCEDURE
  168. function XFormCommandProc (hWnd_p   : Win32.WinDef.HWND;
  169.                           wParam_p : Win32.WPARAM;
  170.                           lParam_p : Win32.LPARAM) return Win32.BOOL is
  171. begin
  172.   return Win32.TRUE;
  173. end XFormCommandProc;
  174.  
  175.  
  176. -- | XFORM PAINT PROCEDURE
  177. procedure XFormPaintProc (hWnd_p : Win32.WinDef.HWND) is
  178.   hDC_p : Win32.WinDef.HDC;
  179. begin
  180.   hDC_p := Win32.WinUser.BeginPaint (hWnd_p, ps'Access);
  181.   if hDC_p /= System.Null_Address then 
  182.     bResult := Win32.WinUser.EndPaint (hWnd_p, ps'Access);
  183.   end if;
  184.   ResetXForm (hWnd_p);
  185. end XFormPaintProc;
  186.  
  187.  
  188. -- | XFORM DESTROY PROCEDURE
  189. procedure XFormDestroyProc (hWnd_p : Win32.WinDef.HWND) is
  190. begin
  191.   bResult := Win32.WinUser.KillTimer(hWnd_p,1);
  192.   bResult := WinInfo.FreeWindowInfo(hWnd_p);
  193. end XFormDestroyProc;
  194.  
  195.  
  196. procedure ResetXForm (hWnd_p : Win32.WinDef.HWND) is
  197.   pxd       : PXFORMDATA;
  198.   pxd_handle: Win32.Winnt.HANDLE;
  199.   hDC_p     : Win32.WinDef.HDC;
  200. begin
  201.   pxd_handle := WinInfo.LockWindowInfo (hWnd_p);
  202.   if pxd_handle /= System.Null_Address then 
  203.     pxd := HANDLE_TO_PXFORMDATA (pxd_handle);
  204.     hDC_p := Win32.WinUser.GetDC (hWnd_p);
  205.     if hDC_p /= System.Null_Address then 
  206. -- #ifndef NOT_IMPLEMENTED
  207.       bResult := Win32.WinUser.GetClientRect(hWnd_p,rect2_p'Access);
  208.       bResult := Win32.WinGdi.BitBlt(hDC_p,0,0,Win32.INT(rect2_p.right),
  209.                                      Win32.INT(rect2_p.bottom),
  210.                                      System.Null_Address,0,0,0);
  211.       bResult := Win32.WinGdi.SetViewportOrgEx(hDC_p,
  212.                        -- rect.right >> 1,rect.bottom >> 1,NULL);
  213.                        Win32.INT (rect2_p.right / 2), 
  214.                        Win32.INT (rect2_p.bottom / 2), old_point'Access);
  215.       bResult := Win32.WinGdi.SetWorldTransform(hDC_p,pxd.xForm'Access);
  216.       --  create an array of points,
  217.       for I in 0 .. 3 loop
  218.         poly_pts (I).x := pxd.pObject (I).x;
  219.         poly_pts (I).y := pxd.pObject (I).y;
  220.       end loop;
  221.       bResult := Win32.WinGdi.Polyline(hDC_p, --poly_pts'Access, pxd.nObject);
  222.                  PT_ARRAY_TO_PT (poly_pts), pxd.nObject);
  223.       bResult := Win32.WinGdi.ModifyWorldTransform(hDC_p,pxd.xForm'Access,
  224.                                                    Win32.WinGdi.MWT_IDENTITY);
  225.  
  226.       --             // I have to put this in since GDI currently doesn't
  227.       --             // reset the drawing attributes -- 5/24/91
  228.       --             //
  229.       bResult := Win32.WinGdi.SetViewportOrgEx(hDC_p,0,0,old_point'Access);
  230.  
  231. -- #endif
  232.  
  233.       iResult := Win32.WinUser.ReleaseDC(hWnd_p,hDC_p);
  234.     end if;
  235.     bResult := WinInfo.UnlockWindowInfo(hWnd_p);
  236.   end if;
  237. end ResetXForm;
  238.  
  239.  
  240. procedure DrawXForm (hWnd_p : Win32.WinDef.HWND) is
  241.   pxd : PXFORMDATA;
  242.   pxd_handle : Win32.Winnt.HANDLE;
  243.   hDC_p : Win32.WinDef.HDC;
  244. -- #ifndef NOT_IMPLEMENTED
  245. -- #endif
  246. begin
  247.   pxd_handle := WinInfo.LockWindowInfo (hWnd_p);
  248.   if pxd_handle /= System.Null_Address then 
  249.     pxd := HANDLE_TO_PXFORMDATA (pxd_handle); 
  250.     hDC_p := Win32.WinUser.GetDC (hWnd_p);
  251.     if hDC_p /= System.Null_Address then 
  252.  
  253. -- #ifndef NOT_IMPLEMENTED
  254.  
  255.       bResult := Win32.WinUser.GetClientRect(hWnd_p,rect3_p'Access);
  256.       bResult := Win32.WinGdi.SetViewportOrgEx(hDC_p,
  257.                                                Win32.INT (rect3_p.right/2), 
  258.                                                Win32.INT (rect3_p.bottom/2), 
  259.                                                old_pt'access);
  260.  
  261.       bResult := Win32.WinGdi.SetWorldTransform(hDC_p,pxd.xForm'Access);
  262.       --  create a real array of points
  263.       for I in 0 .. 3 loop
  264.         poly2_pts (I).x := pxd.pObject (I).x;
  265.         poly2_pts (I).y := pxd.pObject (I).y;
  266.       end loop;
  267.       bResult := Win32.WinGdi.Polyline(hDC_p, --poly2_pts'Access, pxd.nObject);
  268.                  PT_ARRAY_TO_PT (poly2_pts), pxd.nObject);
  269.  
  270.       bResult := Win32.WinGdi.ModifyWorldTransform(hDC_p,
  271.              pxd.xForm'Access,Win32.WinGdi.MWT_RIGHTMULTIPLY);
  272.       --  create a real array of points
  273.       for I in 0 .. 3 loop
  274.         poly2_pts (I).x := pxd.pObject (I).x;
  275.         poly2_pts (I).y := pxd.pObject (I).y;
  276.       end loop;
  277.       bResult := Win32.WinGdi.Polyline(hDC_p,  --poly2_pts'Access, pxd.nObject);
  278.                  PT_ARRAY_TO_PT (poly2_pts), pxd.nObject);
  279.  
  280.       bResult := Win32.WinGdi.GetWorldTransform(hDC_p,xForm_p'Access);
  281.       pxd.xForm.eM11 := xForm_p.eM11;
  282.       pxd.xForm.eM12 := xForm_p.eM12;
  283.       pxd.xForm.eM21 := xForm_p.eM21;
  284.       pxd.xForm.eM22 := xForm_p.eM22;
  285.       pxd.xForm.eDx  := xForm_p.eDx;
  286.       pxd.xForm.eDy  := xForm_p.eDy;
  287.  
  288.       bResult := Win32.WinGdi.ModifyWorldTransform(hDC_p,pxd.xForm'Access,
  289.                                                    Win32.WinGdi.MWT_IDENTITY);
  290.  
  291.       --             // I have to put this in since GDI currently doesn't
  292.       --             // reset the drawing attributes -- 5/24/91
  293.       --             //
  294.       bResult := Win32.WinGdi.SetViewportOrgEx(hDC_p,0,0,old_pt'access);
  295.  
  296. -- #endif
  297.       iResult := Win32.WinUser.ReleaseDC(hWnd_p,hDC_p);
  298.     end if;
  299.     bResult := WinInfo.UnlockWindowInfo(hWnd_p);
  300.   end if;
  301. end DrawXForm;
  302.  
  303. -------------------------------------------------------------------------------
  304. --
  305. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
  306. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  307. -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR 
  308. -- A PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
  309. -- and the use of this file.  This file may be used only by licensees of 
  310. -- Microsoft Corporation's WIN32 Software Development Kit in accordance with 
  311. -- the terms of the licensee's End-User License Agreement for Microsoft 
  312. -- Software for the WIN32 Development Kit.
  313. --
  314. -- Copyright (c) Intermetrics, Inc. 1995
  315. -- Portions (c) 1985-1994 Microsoft Corporation with permission.
  316. -- Microsoft is a registered trademark and Windows and Windows NT are 
  317. -- trademarks of Microsoft Corporation.
  318. --
  319. -------------------------------------------------------------------------------
  320.  
  321. end Xform;
  322.