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

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/draw.adb,v $ 
  2. -- $Revision: 1.3 $ $Date: 95/12/18 19:44:25 $ $Author: mg $ 
  3. -- $Id: draw.adb 1.2 1995/01/25 15:53:12 teg Exp teg $
  4. --
  5. --  package Draw body
  6. -- 
  7. --  This package body is a translation of the collection of C functions in
  8. --  draw.c which is part of the gdidemo sample application.
  9.  
  10.  
  11. with Win32;         use Win32;
  12. with Win32.WinDef;  use Win32.WinDef;
  13. with Win32.WinUser; use Win32.WinUser;
  14. with Win32.WinGdi;  use Win32.WinGdi;
  15. with Win32.WinBase; use Win32.WinBase;
  16. with Win32.Winnt;   use Win32.Winnt;
  17. with Convert;
  18. with Gdidemo_Util;
  19. with Wininfo;
  20. with Unchecked_Conversion;
  21. with Interfaces.C; use Interfaces.C;  -- with and use only for type operations
  22.  
  23. package body Draw is
  24.  
  25.   use type System.Address;
  26.  
  27.   -- Used in CreateDrawWindow
  28.   mcs   : aliased Win32.WinUser.MDICREATESTRUCT;
  29.   
  30.   -- Used in DrawPaintProc
  31.   ps    : aliased Win32.WinUser.PAINTSTRUCT;
  32.  
  33.   -- Used in DrawObject
  34.   rect_p : aliased Win32.WinDef.RECT;
  35.   
  36.   -- Dummy function return values
  37.   bResult : Win32.BOOL;
  38.   iResult : Win32.INT;
  39.   uResult : Win32.UINT;
  40.   lReturn : Win32.LRESULT;
  41.  
  42.   -- Unchecked conversion utility functions
  43.   function HANDLE_TO_PDRAWDATA is new Unchecked_Conversion (Win32.Winnt.HANDLE,
  44.                                                             PDRAWDATA);
  45.  
  46. -- | CREATE DRAW WINDOW PROCEDURE
  47. procedure CreateDrawWindow (hWndClient : Win32.WinDef.HWND;
  48.                             nItem      : Win32.INT) is 
  49.   hInst : Win32.Winnt.HANDLE;
  50.   mcs_p : Win32.WinUser.LPMDICREATESTRUCT;
  51. begin 
  52.   hInst := Gdidemo_Util.GETINSTANCE (hWndClient);
  53.  
  54.   -- ** Initialize the MDI create struct for creation of the
  55.   -- ** test window.
  56.   mcs.szClass := DRAWCLASS;
  57.   mcs.szTitle := DRAWTITLE;
  58.   mcs.hOwner  := hInst;
  59.   mcs.x       := Win32.WinUser.CW_USEDEFAULT;
  60.   mcs.y       := Win32.WinUser.CW_USEDEFAULT;
  61.   mcs.cx      := Win32.WinUser.CW_USEDEFAULT;
  62.   mcs.cy      := Win32.WinUser.CW_USEDEFAULT;
  63.   mcs.style   := 0;
  64.   mcs.lParam  := Win32.LPARAM (nItem);
  65.  
  66.   mcs_p := mcs'Access;
  67.  
  68.   lReturn := Win32.WinUser.SendMessage
  69.                                 (hWndClient,
  70.                                  Win32.WinUser.WM_MDICREATE,
  71.                                  0,
  72.                                  Convert.LPMDICREATESTRUCT_TO_LPARAM (mcs_p));
  73.  
  74. end CreateDrawWindow;
  75.  
  76.  
  77. -- | DRAW WINDOW PROCEDURE
  78. function DrawProc (hWnd_p   : Win32.WinDef.HWND;
  79.                    wMsg     : Win32.UINT;
  80.                    wParam_p : Win32.WPARAM;
  81.                    lParam_p : Win32.LPARAM) return Win32.LRESULT is
  82. begin
  83.   case wMsg is
  84.  
  85.     when Win32.WinUser.WM_CREATE =>
  86.       bResult := DrawCreateProc(hWnd_p);
  87.  
  88.     when Win32.WinUser.WM_COMMAND =>
  89.       bResult := DrawCommandProc(hWnd_p,wParam_p,lParam_p);
  90.  
  91.     when Win32.WinUser.WM_TIMER =>
  92.       DrawObject(hWnd_p);
  93.  
  94.     when Win32.WinUser.WM_PAINT =>
  95.       DrawPaintProc(hWnd_p);
  96.  
  97.     when Win32.WinUser.WM_DESTROY =>
  98.       DrawDestroyProc(hWnd_p);
  99.  
  100.     when others =>
  101.       return Win32.WinUser.DefMDIChildProc (hWnd_p, wMsg, wParam_p, lParam_p);
  102.  
  103.   end case; 
  104.  
  105.   return (0);
  106.  
  107. end DrawProc; 
  108.  
  109.  
  110. -- | DRAW CREATE PROCEDURE
  111. function DrawCreateProc (hWnd_p : Win32.WinDef.HWND) return Win32.BOOL is
  112.   pdd : PDRAWDATA := new DRAWDATA;
  113.   pdd_handle : Win32.Winnt.HANDLE;
  114. begin
  115.   if WinInfo.AllocWindowInfo (hWnd_p, (DRAWDATA'size / 8)) = 
  116.      Win32.True then 
  117.     pdd_handle := WinInfo.LockWindowInfo (hWnd_p);
  118.     if pdd_handle /= System.Null_Address then 
  119.       pdd := HANDLE_TO_PDRAWDATA (pdd_handle);
  120.       pdd.nObject := 0;
  121.       bResult := Wininfo.UnlockWindowInfo(hWnd_p);
  122.  
  123.       uResult := Win32.WinUser.SetTimer(hWnd_p,1,50,null);
  124.       return Win32.TRUE;
  125.     end if;
  126.     bResult := Wininfo.FreeWindowInfo(hWnd_p);
  127.   end if;
  128.   return Win32.FALSE;
  129. end DrawCreateProc;
  130.  
  131.  
  132. -- | DRAW COMMAND PROCEDURE
  133. function DrawCommandProc (hWnd_p   : Win32.WinDef.HWND;
  134.                           wParam_p : Win32.WPARAM;
  135.                           lParam_p : Win32.LPARAM) return Win32.BOOL is
  136. begin
  137.   return Win32.TRUE; 
  138. end DrawCommandProc;
  139.  
  140.  
  141. -- | DRAW PAINT PROCEDURE
  142. procedure DrawPaintProc (hWnd_p : Win32.WinDef.HWND) is
  143.   hDC_p : Win32.WinDef.HDC;
  144. begin
  145.   hDC_p := Win32.WinUser.BeginPaint (hWnd_p, ps'Access);
  146.   if hDC_p /= System.Null_Address then 
  147.     bResult := Win32.WinUser.EndPaint (hWnd_p, ps'Access);
  148.   end if;
  149. end DrawPaintProc;
  150.  
  151. -- | DRAW DESTROY PROCEDURE
  152. procedure DrawDestroyProc (hWnd_p : Win32.WinDef.HWND) is
  153. begin
  154.   bResult := Win32.WinUser.KillTimer(hWnd_p,1);
  155.   bResult := Wininfo.FreeWindowInfo(hWnd_p);
  156. end DrawDestroyProc;
  157.  
  158.  
  159. procedure DrawObject (hWnd_p : Win32.WinDef.HWND) is
  160.   pdd        : PDRAWDATA; -- := new DRAWDATA;
  161.   hDC_p      : Win32.WinDef.HDC;
  162.   x1,y1,x2,y2,x3,y3,x4,y4,nObject : Win32.INT;
  163.   r,g,b      : Win32.BYTE;
  164.   hBrush_p   : Win32.WinDef.HGDIOBJ;
  165.   pdd_handle : Win32.Winnt.HANDLE;
  166.   dw         : Win32.DWORD;
  167. begin
  168.   pdd_handle := Wininfo.LockWindowInfo (hWnd_p);
  169.   if pdd_handle /= System.Null_Address then 
  170.     pdd := HANDLE_TO_PDRAWDATA (pdd_handle);
  171.     hDC_p := Win32.WinUser.GetDC (hWnd_p);
  172.     if hDC_p /= System.Null_Address then 
  173.       bResult := Win32.WinUser.GetClientRect(hWnd_p,rect_p'Access);
  174.       dw := Gdidemo_Util.lRandom rem 255;
  175.       r := Win32.BYTE (dw);
  176.       dw := Gdidemo_Util.lRandom rem 255;
  177.       g := Win32.BYTE (dw);
  178.       dw := Gdidemo_Util.lRandom rem 255;
  179.       b := Win32.BYTE (dw);
  180.  
  181.       hBrush_p := Win32.WinGdi.SelectObject (hDC_p, Win32.Windef.HGDIOBJ (
  182.             Win32.WinGdi.CreateSolidBrush (Win32.WinGdi.RGB (r,g,b))));
  183.       if hBrush_p /= System.Null_Address then 
  184.         x1 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.right);
  185.         y1 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.bottom);
  186.         x2 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.right);
  187.         y2 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.bottom);
  188.         x3 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.right);
  189.         y3 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.bottom);
  190.         x4 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.right);
  191.         y4 := Win32.INT(Gdidemo_Util.lRandom rem rect_p.bottom);
  192.  
  193.         -- Since the computed x,y values may be negative, make them positive
  194.         -- so that all objects fit in the client area.
  195.         if x1 < 0 then
  196.           x1 := -x1;
  197.         end if;
  198.         if y1 < 0 then
  199.           y1 := -y1;
  200.         end if;
  201.         if x2 < 0 then
  202.           x2 := -x2;
  203.         end if;
  204.         if y2 < 0 then
  205.           y2 := -y2;
  206.         end if;
  207.         if x3 < 0 then
  208.           x3 := -x3;
  209.         end if;
  210.         if y3 < 0 then
  211.           y3 := -y3;
  212.         end if;
  213.         if x4 < 0 then
  214.           x4 := -x4;
  215.         end if;
  216.         if y4 < 0 then
  217.           y4 := -y4;
  218.         end if;
  219.  
  220.         nObject := Win32.INT(Gdidemo_Util.lRandom rem 5);
  221.  
  222.         case nObject is
  223.           when OBJ_RECTANGLE =>
  224.             bResult := Win32.WinGdi.Rectangle(hDC_p,x1,y1,x2,y2);
  225.  
  226.           when OBJ_ELLIPSE =>
  227.             bResult := Win32.WinGdi.Ellipse(hDC_p,x1,y1,x2,y2);
  228.  
  229.           when OBJ_ROUNDRECT =>
  230.             bResult := Win32.WinGdi.RoundRect(hDC_p,x1,y1,x2,y2,x3,y3);
  231.  
  232.           when OBJ_CHORD =>
  233.             bResult := Win32.WinGdi.Chord(hDC_p,x1,y1,x2,y2,x3,y3,x4,y4);
  234.  
  235.           when OBJ_PIE =>
  236.             bResult := Win32.WinGdi.Pie(hDC_p,x1,y1,x2,y2,x3,y3,x4,y4);
  237.     
  238.           when others =>
  239.             bResult := Win32.WinGdi.Rectangle(hDC_p,x1,y1,x2,y2);
  240.  
  241.  
  242.         end case;
  243.  
  244.         bResult := Win32.WinGdi.DeleteObject(
  245.                      Win32.WinGdi.SelectObject(hDC_p,hBrush_p));
  246.  
  247.       end if;
  248.       iResult := Win32.WinUser.ReleaseDC(hWnd_p,hDC_p);
  249.     end if;
  250.     bResult := Wininfo.UnlockWindowInfo(hWnd_p);
  251.   end if;
  252.  
  253. end DrawObject;
  254.  
  255. -------------------------------------------------------------------------------
  256. --
  257. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
  258. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  259. -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR 
  260. -- A PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
  261. -- and the use of this file.  This file may be used only by licensees of 
  262. -- Microsoft Corporation's WIN32 Software Development Kit in accordance with 
  263. -- the terms of the licensee's End-User License Agreement for Microsoft 
  264. -- Software for the WIN32 Development Kit.
  265. --
  266. -- Copyright (c) Intermetrics, Inc. 1995
  267. -- Portions (c) 1985-1994 Microsoft Corporation with permission.
  268. -- Microsoft is a registered trademark and Windows and Windows NT are 
  269. -- trademarks of Microsoft Corporation.
  270. --
  271. -------------------------------------------------------------------------------
  272.  
  273. end Draw;
  274.