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

  1.  
  2.  
  3. // A second "hello, world" program using YACL
  4.  
  5.  
  6. #include "ui/applic.h"
  7. #include "ui/composit.h"
  8. #include "ui/font.h"
  9. #include "ui/label.h"
  10. #include "ui/stddlg.h"
  11.  
  12.  
  13. // ======================== Class AppWindow ===========================
  14.  
  15. const UI_ViewID ID_BUTTON = 10;
  16. const UI_ViewID ID_LABEL  = 11;
  17.  
  18.  
  19. UI_ViewDescriptor desc[] = {
  20.     {View_PushButton, ID_BUTTON,  75, 80, 225, 50, TRUE, "", 0},
  21.     {View_Label,      ID_LABEL,   40, 50, 295, 20, FALSE, "",  0},
  22.     {View_None, -1, 0, 0, 0, 0, 0, 0}
  23. };
  24.  
  25. class AppWindow: public UI_CompositeVObject {
  26.  
  27. public:
  28.     AppWindow ();
  29.  
  30.     // Override the Composite's virtual method:
  31.     bool HandleChildEvent (const UI_Event& e);
  32.  
  33.     bool WantToQuit();
  34.     
  35. protected:
  36.     short count;
  37. };
  38.  
  39.     
  40. AppWindow::AppWindow()
  41. : UI_CompositeVObject (NULL, desc, FALSE, UI_Rectangle (50, 50, 400, 300)),
  42.   count (5)
  43. {
  44.     (*this)[ID_BUTTON]->Title() =
  45.         "Click here " + CL_String(count) + " times.";
  46. }
  47.  
  48. bool AppWindow::HandleChildEvent (const UI_Event& e)
  49. {
  50.     if (e.Origin()->ViewID() == ID_BUTTON &&
  51.         e.Type() == Event_Select) {
  52.         count--;
  53.         if (count == 0) {
  54.             _Application->Destroy (this);
  55.             // Do an _Application->End() if we want conditional termination
  56.         }
  57.         else {
  58.             (*this)[ID_BUTTON]->Title() =
  59.                 "Click here " + CL_String(count) + " times.";
  60.             switch (count) {
  61.             case 4: {
  62.                 UI_Font& font = Font();
  63.                 font = UI_FontDesc ("Courier", 11, UIFont_Italic);
  64.                 break;
  65.             }
  66.  
  67.             case 2: {
  68.                 UI_Font& font = e.Origin()->Font();
  69.                 font = UI_FontDesc ("Times New Roman", 14, UIFont_StrikeOut
  70.                                     | UIFont_Italic);
  71.                 break;
  72.             }
  73.                 
  74.             case 1: {
  75.                 UI_Font& font = (*this)[ID_LABEL]->Font();
  76.                 font = UI_FontDesc ("Courier", 8, UIFont_Underline);
  77.                 break;
  78.             }
  79.                 
  80.             default:
  81.                 break;
  82.             }
  83.         }
  84.         return TRUE;
  85.     }
  86.     return FALSE;
  87. }
  88.  
  89.  
  90. bool AppWindow::WantToQuit()
  91. {
  92.     return (UI_SimpleDialog ("Do you really want to quit?", "Confirm",
  93.                              this, UIS_YesNo, UIS_Question) == UI_IDYES);
  94. }
  95.  
  96.  
  97.  
  98. // ======================== Main program ===========================
  99.  
  100.  
  101. int UI_Application::Main (int /* argc */, char* [])
  102. {
  103.     UI_CompositeVObject* mainWin = new AppWindow;
  104.     MakeTopWindow (mainWin);
  105.     (*mainWin)[ID_LABEL]->Title() = "Hello, world, this is YACL!";
  106.     Run();
  107.     return 0;
  108. }
  109.  
  110.  
  111.  
  112.