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

  1.  
  2.  
  3. // A simple digital clock program using YACL
  4.  
  5. #include "ui/dialog.h"
  6. #include "ui/timer.h"
  7. #include "ui/cntroler.h"
  8. #include "ui/label.h"
  9. #include "base/date.h"
  10. #include "base/timeofda.h"
  11.  
  12.  
  13. // The main window:
  14.  
  15. class ClockWindow: public UI_Dialog {
  16. public:
  17.     ClockWindow ();
  18.  
  19.     bool Update (CL_Object&, long);
  20.  
  21. protected:
  22.     void Initialize ();
  23.  
  24.     UI_Label*               _date;
  25.     UI_Label*               _time;
  26.     CL_Binding<ClockWindow> _bind;
  27.     UI_Timer                _timer;
  28. };
  29.  
  30.  
  31.  
  32. typedef CL_Binding <ClockWindow> Bind;
  33.  
  34. #if defined(__GNUC__)
  35. template class CL_Binding <ClockWindow>; // Instantiate the template
  36. #endif
  37.  
  38.  
  39. ClockWindow::ClockWindow ()
  40. : UI_Dialog (NULL, NULL, UI_Rectangle (300, 300, 140, 80)),
  41.   _bind  (this, &ClockWindow::Update),
  42.   _timer (_bind)
  43. {
  44.     _date = new UI_Label (this, UI_Rectangle (20,  5, 100, 30));
  45.     _time = new UI_Label (this, UI_Rectangle (20, 40, 100, 30));
  46. }
  47.  
  48. void ClockWindow::Initialize()
  49. {
  50.     _date->Title() = CL_Date::Today().AsString();
  51.     _time->Title() = CL_TimeOfDay::Now().AsString();
  52.     _timer.Start (1000); // Call Update every 1000 millseconds
  53. }
  54.  
  55. bool ClockWindow::Update (CL_Object&, long)
  56. {
  57.     CL_TimeOfDay now = CL_TimeOfDay::Now();
  58.     if (now == CL_TimeOfDay (0, 0, 1))
  59.         _date->Title() = CL_Date::Today().AsString();
  60.     _time->Title() = now.AsString();
  61.     _Controller->DispatchPendingEvents (); // Flush the event queue so that
  62.                                            // the update shows on the screen
  63.     return TRUE;
  64. }
  65.  
  66.  
  67.  
  68. // The main program:
  69.  
  70. int UI_Application::Main (int, char* [])
  71. {
  72.     UI_CompositeVObject* root = new ClockWindow;
  73.     MakeTopWindow (root);
  74.     root->Title()  = "YACL clock";
  75.     Run();
  76.     return 0;
  77. }
  78.  
  79.