home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / uidemo / window / main.cxx next >
C/C++ Source or Header  |  1995-02-03  |  3KB  |  119 lines

  1.  
  2.  
  3. // A window demo using YACL
  4.  
  5.  
  6. #include "ui/composit.h"
  7. #include "ui/applic.h"
  8. #include "ui/label.h"
  9. #include "ui/pushbtn.h"
  10.  
  11.  
  12.  
  13. // ======================== Class AppWindow ===========================
  14.  
  15.  
  16. #define ID_LABEL1 11
  17. #define ID_LABEL2 12
  18. #define ID_LABEL3 13
  19. #define ID_LABEL4 14
  20. #define ID_BUTTON 15
  21.  
  22.  
  23. UI_ViewDescriptor desc[] = {
  24.     {View_Label,      ID_LABEL1, 15,  15, 320, 20, FALSE,  ""},
  25.     {View_Label,      ID_LABEL2, 15,  40, 320, 20, FALSE,  ""},
  26.     {View_Label,      ID_LABEL3, 15,  65, 320, 20, FALSE,  ""},
  27.     {View_Label,      ID_LABEL4, 15,  90, 320, 20, FALSE,  ""},
  28.     {View_PushButton, ID_BUTTON,125, 140,  80, 40, FALSE,  ""},
  29.     {View_None, 0}
  30. };
  31.  
  32. class AppWindow: public UI_CompositeVObject {
  33.  
  34. public:
  35.     AppWindow ();
  36.  
  37. protected:
  38.  
  39.     void Initialize  ();
  40.     
  41.     bool Reconfigure (const UI_Rectangle& r);
  42.  
  43.     bool HandleChildEvent (const UI_Event& e);
  44.  
  45. private:
  46.     void SetLabels ();
  47.     long _xInc, _yInc;
  48. };
  49.  
  50.     
  51. AppWindow::AppWindow()
  52. : UI_CompositeVObject (NULL, desc, FALSE, UI_Rectangle (200, 200, 350, 200))
  53. {
  54.     _xInc = _yInc = 32;
  55.     _title = "YACL Window Demo";
  56.     (*this)[ID_LABEL1]->Title() = "I am a window.";
  57.     (*this)[ID_BUTTON]->Title() = "Move!";
  58. }
  59.  
  60. void AppWindow::Initialize ()
  61. {
  62.     SetLabels ();
  63. }
  64.  
  65.  
  66.  
  67. bool AppWindow::Reconfigure (const UI_Rectangle& r)
  68. {
  69.     UI_CompositeVObject::Reconfigure (r);
  70.     SetLabels();
  71.     return TRUE;
  72. }
  73.  
  74. void AppWindow::SetLabels ()
  75. {
  76.     (*this)[ID_LABEL2]->Title() =
  77.         "My client area is at position " + CL_String (_shape.Left())
  78.         + " x " + CL_String (_shape.Top()) + ".";
  79.     (*this)[ID_LABEL3]->Title() =
  80.         "My client area size is " + CL_String (_shape.Width ())
  81.         + " x " + CL_String (_shape.Height ()) + ".";
  82.     UI_Rectangle rect = Area ();
  83.     (*this)[ID_LABEL4]->Title() =
  84.         "My window area size is " + CL_String (rect.Width ())
  85.         + " x " + CL_String (rect.Height ()) + ".";
  86. }
  87.  
  88.  
  89.  
  90. bool AppWindow::HandleChildEvent (const UI_Event& e)
  91. {
  92.     if (e.Origin()->ViewID() != ID_BUTTON || e.Type() != Event_Select)
  93.         return FALSE;
  94.  
  95.     UI_Rectangle screen_rect = _Application->ScreenRect();
  96.     UI_Rectangle& client_area = ClientArea();
  97.     long x = client_area.Origin().XCoord();
  98.     long y = client_area.Origin().YCoord();
  99.     if (x >= screen_rect.Width() - client_area.Width() || x < 0)
  100.         _xInc = -_xInc;
  101.     if (y >= screen_rect.Height() - client_area.Height() || y <= 20)
  102.         _yInc = -_yInc;
  103.     client_area += UI_Point (_xInc, _yInc); // Move the window
  104.     return TRUE;
  105. }
  106.  
  107.  
  108. // ======================== Main program ===========================
  109.  
  110.  
  111. int UI_Application::Main (int, char* []) 
  112. {
  113.     MakeTopWindow (new AppWindow);
  114.     Run();
  115.     return 0;
  116. }
  117.  
  118.  
  119.