home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / WKFRAME / UILINES / PMLINES.HPP < prev    next >
Text File  |  1993-03-30  |  11KB  |  192 lines

  1. #ifndef _PMLINES_HPP_INCLUDED_
  2. #define _PMLINES_HPP_INCLUDED_
  3. /*+--------------------------------------------------------------------------+*/
  4. /*|                                                                          |*/
  5. /*| PROGRAM NAME: PMLINES                                                    |*/
  6. /*| -------------                                                            |*/
  7. /*|  A Simple OS/2 Presentation Manager Graphics Demonstration Program       |*/
  8. /*|                                                                          |*/
  9. /*| COPYRIGHT:                                                               |*/
  10. /*| ----------                                                               |*/
  11. /*|  Copyright (C) International Business Machines Corp., 1992,1993.         |*/
  12. /*|                                                                          |*/
  13. /*| DISCLAIMER OF WARRANTIES:                                                |*/
  14. /*| -------------------------                                                |*/
  15. /*|  The following [enclosed] code is sample code created by IBM Corporation.|*/
  16. /*|  This sample code is not part of any standard IBM product and is provided|*/
  17. /*|  to you solely for the purpose of assisting you in the development of    |*/
  18. /*|  your applications.  The code is provided "AS IS", without warranty of   |*/
  19. /*|  any kind.  IBM shall not be liable for any damages arising out of your  |*/
  20. /*|  use of the sample code, even if they have been advised of the           |*/
  21. /*|  possibility of such damages.                                            |*/
  22. /*|                                                                          |*/
  23. /*| REVISION LEVEL: 1.0                                                      |*/
  24. /*| ---------------                                                          |*/
  25. /*|                                                                          |*/
  26. /*+--------------------------------------------------------------------------+*/
  27.  
  28.  
  29. /* ----------------------------------------------------------- */
  30. /* This version is a port of the PMLINES program. The original */
  31. /* PMLINES program was coded in C and PM. This port has been   */
  32. /* coded in C++. The PM interface is the User Interface Library*/
  33. /* that comes with the compiler.                               */
  34. /*                                                             */
  35. /* The following Library features are demonstrated by this     */
  36. /* program.                                                    */
  37. /*  1. Window Creation.                                        */
  38. /*  2. Event Handling                                          */
  39. /*  3. Simple multitasking                                     */
  40. /*  4. Use of GPI or native PM API with User Interface Library */
  41. /*     Objects                                                 */
  42. /*                                                             */
  43. /*                                                             */
  44. /* Change History:                                             */
  45. /* Rel Programmer        Stamp Date     Description            */
  46. /* --- ----------------- ----- -------- ---------------------- */
  47. /* 1.0 Noel Sales        njCs  16/12/92 Creation               */
  48. /* ----------------------------------------------------------- */
  49.  
  50. /* ----------------------------------------------------------- */
  51. /* Include IBMCLASS headers                                    */
  52. /* ----------------------------------------------------------- */
  53. // include IBMCLASS headers
  54. #include <iframe.hpp>           /* IFrameWindow                */
  55. #include <icanvas.hpp>
  56. #include <icmdhdr.hpp>          /* ICommandHandler             */
  57. #include <ipainhdr.hpp>         /* IPaintHandler               */
  58. #include <ipainevt.hpp>         /* IPaintEvent                 */
  59. #include <isizehdr.hpp>         /* Resize event handler        */
  60. #include <imenubar.hpp>         /* IActionBarMenu              */
  61. #include <ithread.hpp>          /* Thread utilization          */
  62. #include <imchdr.hpp>           /* Mouse commands              */
  63.  
  64. /* ----------------------------------------------------------- */
  65. /* Class:   MyWindow                                           */
  66. /*                                                             */
  67. /* Purpose: This is the sample application's main window       */
  68. /*          It is a subclass of IFrameWindow. The frame has    */
  69. /*          a command menu and needs to handle the WM_PAINT    */
  70. /*          and MOUSE CLICK events.                            */
  71. /*                                                             */
  72. /* Change History:                                             */
  73. /* Rel Programmer        Stamp Date     Description            */
  74. /* --- ----------------- ----- -------- ---------------------- */
  75. /* 1.0 Noel Sales        njCs  16/12/92 Creation               */
  76. /* ----------------------------------------------------------- */
  77.  
  78. class MyClientWindow;          /* forward declare this class   */
  79.  
  80. class MyWindow : public IFrameWindow, public ICommandHandler,
  81.                  public IPaintHandler, public IMouseClickHandler
  82. {
  83. public:
  84.    /* -------------------------------------------------------- */
  85.    /* declare the constructor                                  */
  86.    /* -------------------------------------------------------- */
  87.    MyWindow(unsigned long windowId);
  88.  
  89. protected:
  90.    /* -------------------------------------------------------- */
  91.    /* declare the event handlers. These event handlers are all */
  92.    /* pure virtual functions in their respective base classes  */
  93.    /* -------------------------------------------------------- */
  94.    Boolean command(ICommandEvent&);
  95.    Boolean paintWindow(IPaintEvent &);
  96.    Boolean mouseClicked(IMouseClickEvent &);
  97.  
  98. private:
  99.    MyClientWindow   *pMyClient; /* declare the client pointer  */
  100.    IMenuBar*        pabmnMain;  /* declare an action bar ptr   */
  101.    IThread          Thread;     /* define an IThread object    */
  102. };
  103.  
  104.  
  105. /* ----------------------------------------------------------- */
  106. /* Class:   MyClientWindow                                     */
  107. /*                                                             */
  108. /* Purpose: This is the sample application's Client Window.    */
  109. /*          It is a subclass of IFrameWindow. It also contains */
  110. /*          the member function responsible in 'drawing' the   */
  111. /*          lines on the screen. It also provides the functions*/
  112. /*          needed to set window dimensions, window colors and */
  113. /*          to issue events to the parallel thread.            */
  114. /*                                                             */
  115. /* Change History:                                             */
  116. /* Rel Programmer        Stamp Date     Description            */
  117. /* --- ----------------- ----- -------- ---------------------- */
  118. /* 1.0 Noel Sales        njCs  16/12/92 Creation               */
  119. /* ----------------------------------------------------------- */
  120. class MyClientWindow : public ICanvas
  121. {
  122. public:
  123.    /* -------------------------------------------------------- */
  124.    /* declare the constructor                                  */
  125.    /* -------------------------------------------------------- */
  126.    MyClientWindow(unsigned long windowId,
  127.                         IWindow   *parentWindow,
  128.                         IWindow   *ownerWindow);
  129.    /* -------------------------------------------------------- */
  130.    /* DrawLines() is the line drawing function. It runs under  */
  131.    /* a separate thread.                                       */
  132.    /* -------------------------------------------------------- */
  133.    void DrawLines( );
  134.    /* -------------------------------------------------------- */
  135.    /* SetThreadMessage() and GetThreadMessage() are elementary */
  136.    /* 'inter thread' communication routines. In the real world */
  137.    /* they must be guarded by semaphores. The application is   */
  138.    /* quite simple however so the use of semaphores was        */
  139.    /* dispensed with.                                          */
  140.    /* -------------------------------------------------------- */
  141.    void SetThreadMessage(long Tmsg) {ThreadMsg= Tmsg; }
  142.    long GetThreadMessage()          {return ThreadMsg; }
  143.  
  144.    /* -------------------------------------------------------- */
  145.    /* the following functions support the Line Drawing         */
  146.    /* Function. SetcxClient and SetcyClient respectively set   */
  147.    /* x and y dimensions of the Client rectangle.              */
  148.    /* -------------------------------------------------------- */
  149.    void SetcxClient(long cx) {cxClient= cx; }
  150.    void SetcyClient(long cy) {cyClient= cy; }
  151.  
  152.    /* -------------------------------------------------------- */
  153.    /* Set the initial begin and end points of a line           */
  154.    /* -------------------------------------------------------- */
  155.    void SetBeginPoint(IPoint Begin) {ptl1= Begin.asPOINTL() ;}
  156.    void SetEndPoint  (IPoint End)   {ptl2= End.asPOINTL() ;}
  157.  
  158.    /* -------------------------------------------------------- */
  159.    /* Increment and obtain the color counter                   */
  160.    /* -------------------------------------------------------- */
  161.    void IncColorCount()                {fcolourcounter++;      }
  162.    long GetColorCount()                {return fcolourcounter; }
  163.    void SetColorCount(long Value)      {fcolourcounter= Value; }
  164.  
  165.    /* -------------------------------------------------------- */
  166.    /* Set and obtain the background color                      */
  167.    /* -------------------------------------------------------- */
  168.    void SetBcolor(long value)          {lBcolour= value; }
  169.    long GetBcolor()                    {return lBcolour; }
  170.  
  171.    /* -------------------------------------------------------- */
  172.    /* Set and obtain the foreground color                      */
  173.    /* -------------------------------------------------------- */
  174.    void SetFcolor(long value)          {lFcolour= value; }
  175.    long GetFcolor()                    {return lFcolour; }
  176.  
  177. protected:
  178.    const IWindow   *MyParent;
  179.    long            cxClient, cyClient;
  180.    long            fcolourcounter, lBcolour, lFcolour;
  181.    long            ThreadMsg;
  182.    POINTL          ptl1, ptl2;
  183.  
  184.    HAB                habThread2;  /* thread anchor block      */
  185.    IPresSpaceHandle   hps;
  186.  
  187.    RECTL rclClient;                /* rectangle for client     */
  188. // IMsgQueueHandle qmsgThread2;    /* message queue structure  */
  189. };
  190.  
  191. #endif
  192.