home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / COMPILER / UILINES / PMLINES.HPP < prev    next >
C/C++ Source or Header  |  1995-06-01  |  11KB  |  196 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.1                                                      |*/
  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. /* 1.1 Bill Sarantakos   bjs   09/05/95 Minor fixes            */
  49. /* ----------------------------------------------------------- */
  50.  
  51. /* ----------------------------------------------------------- */
  52. /* Include IBMCLASS headers                                    */
  53. /* ----------------------------------------------------------- */
  54. // include IBMCLASS headers
  55. #include <iframe.hpp>           /* IFrameWindow                */
  56. #include <icanvas.hpp>
  57. #include <icmdhdr.hpp>          /* ICommandHandler             */
  58. #include <ipainhdr.hpp>         /* IPaintHandler               */
  59. #include <ipainevt.hpp>         /* IPaintEvent                 */
  60. #include <isizehdr.hpp>         /* Resize event handler        */
  61. #include <imenubar.hpp>         /* IActionBarMenu              */
  62. #include <ithread.hpp>          /* Thread utilization          */
  63. #include <imchdr.hpp>           /* Mouse commands              */
  64. #include <iframhdr.hpp>         /* frame closed */
  65. /* ----------------------------------------------------------- */
  66. /* Class:   MyClientWindow                                     */
  67. /*                                                             */
  68. /* Purpose: This is the sample application's Client Window.    */
  69. /*          It is a subclass of IFrameWindow. It also contains */
  70. /*          the member function responsible in 'drawing' the   */
  71. /*          lines on the screen. It also provides the functions*/
  72. /*          needed to set window dimensions, window colors and */
  73. /*          to issue events to the parallel thread.            */
  74. /*                                                             */
  75. /* Change History:                                             */
  76. /* Rel Programmer        Stamp Date     Description            */
  77. /* --- ----------------- ----- -------- ---------------------- */
  78. /* 1.0 Noel Sales        njCs  16/12/92 Creation               */
  79. /* 1.1 Bill Sarantakos   bjs   09/05/95 Minor fixes            */
  80. /* ----------------------------------------------------------- */
  81. class MyClientWindow : public ICanvas
  82. {
  83. public:
  84.    /* -------------------------------------------------------- */
  85.    /* declare the constructor                                  */
  86.    /* -------------------------------------------------------- */
  87.    MyClientWindow(unsigned long windowId,
  88.                         IWindow   *parentWindow,
  89.                         IWindow   *ownerWindow);
  90.    /* -------------------------------------------------------- */
  91.    /* DrawLines() is the line drawing function. It runs under  */
  92.    /* a separate thread.                                       */
  93.    /* -------------------------------------------------------- */
  94.    void DrawLines( );
  95.    /* -------------------------------------------------------- */
  96.    /* SetThreadMessage() and GetThreadMessage() are elementary */
  97.    /* 'inter thread' communication routines. In the real world */
  98.    /* they must be guarded by semaphores. The application is   */
  99.    /* quite simple however so the use of semaphores was        */
  100.    /* dispensed with.                                          */
  101.    /* -------------------------------------------------------- */
  102.    void SetThreadMessage(long Tmsg) {threadMsg= Tmsg; }
  103.    long GetThreadMessage()          {return threadMsg; }
  104.  
  105.    /* -------------------------------------------------------- */
  106.    /* the following functions support the Line Drawing         */
  107.    /* Function. SetcxClient and SetcyClient respectively set   */
  108.    /* x and y dimensions of the Client rectangle.              */
  109.    /* -------------------------------------------------------- */
  110.    void SetcxClient(long cx) {cxClient= cx; }
  111.    void SetcyClient(long cy) {cyClient= cy; }
  112.  
  113.    /* -------------------------------------------------------- */
  114.    /* Set the initial begin and end points of a line           */
  115.    /* -------------------------------------------------------- */
  116.    void SetBeginPoint(IPoint Begin) {ptl1= Begin.asPOINTL() ;}
  117.    void SetEndPoint  (IPoint End)   {ptl2= End.asPOINTL() ;}
  118.  
  119.    /* -------------------------------------------------------- */
  120.    /* Increment and obtain the color counter                   */
  121.    /* -------------------------------------------------------- */
  122.    void IncColorCount()                {fcolourcounter++;      }
  123.    long GetColorCount()                {return fcolourcounter; }
  124.    void SetColorCount(long Value)      {fcolourcounter= Value; }
  125.  
  126.    /* -------------------------------------------------------- */
  127.    /* Set and obtain the background color                      */
  128.    /* -------------------------------------------------------- */
  129.    void SetBcolor(long value)          {lBcolour= value; }
  130.    long GetBcolor()                    {return lBcolour; }
  131.  
  132.    /* -------------------------------------------------------- */
  133.    /* Set and obtain the foreground color                      */
  134.    /* -------------------------------------------------------- */
  135.    void SetFcolor(long value)          {lFcolour= value; }
  136.    long GetFcolor()                    {return lFcolour; }
  137.  
  138. protected:
  139.    const IWindow   *MyParent;
  140.    long            cxClient, cyClient;
  141.    long            fcolourcounter, lBcolour, lFcolour;
  142.    long            threadMsg;
  143.    POINTL          ptl1, ptl2;
  144.  
  145.    HAB                habThread2;  /* thread anchor block      */
  146.    IPresSpaceHandle   hps;
  147.  
  148.    RECTL rclClient;                /* rectangle for client     */
  149. // IMsgQueueHandle qmsgThread2;    /* message queue structure  */
  150. };
  151. /* ----------------------------------------------------------- */
  152. /* Class:   MyWindow                                           */
  153. /*                                                             */
  154. /* Purpose: This is the sample application's main window       */
  155. /*          It is a subclass of IFrameWindow. The frame has    */
  156. /*          a command menu and needs to handle the WM_PAINT    */
  157. /*          and MOUSE CLICK events.                            */
  158. /*                                                             */
  159. /* Change History:                                             */
  160. /* Rel Programmer        Stamp Date     Description            */
  161. /* --- ----------------- ----- -------- ---------------------- */
  162. /* 1.0 Noel Sales        njCs  16/12/92 Creation               */
  163. /* 1.1 Bill Sarantakos   bjs   09/05/95 Minor fixes            */
  164. /* ----------------------------------------------------------- */
  165.  
  166. class MyWindow : public IFrameWindow, public ICommandHandler,
  167.                  public IPaintHandler, public IMouseClickHandler,
  168.                  public IFrameHandler
  169. {
  170. public:
  171.    /* -------------------------------------------------------- */
  172.    /* declare the constructor                                  */
  173.    /* -------------------------------------------------------- */
  174.    MyWindow(unsigned long windowId);
  175.  
  176. protected:
  177.    /* -------------------------------------------------------- */
  178.    /* declare the event handlers. These event handlers are all */
  179.    /* pure virtual functions in their respective base classes  */
  180.    /* -------------------------------------------------------- */
  181.    Boolean command(ICommandEvent&);
  182.    Boolean paintWindow(IPaintEvent &);
  183.    Boolean mouseClicked(IMouseClickEvent &);
  184.    Boolean closed( IFrameEvent &);
  185.  
  186. private:
  187.    IMenuBar                     /* create the menu bar         */
  188.       menubar;
  189.    MyClientWindow               /* create the client window    */
  190.       myClient;
  191.    IThread                      /* define an IThread object    */
  192.       thread;
  193. };
  194.  
  195. #endif
  196.