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

  1.  
  2.  
  3. // A small calendar program using YACL
  4. //
  5. // M. A. Sridhar
  6. // Dec 25, 1993
  7.  
  8. #include "ui/monthcal.h"
  9. #include "ui/composit.h"
  10. #include "ui/stddlg.h"
  11. #include "ui/pushbtn.h"
  12. #include "ui/applic.h"
  13.  
  14.  
  15. // ======================== Class AppWindow ===========================
  16.  
  17. #define ID_NEXT 10
  18. #define ID_PREV 11
  19. #define ID_CAL  12
  20.  
  21.  
  22. class CalendarView: public UI_MonthCalendar {
  23. public:
  24.     CalendarView (UI_CompositeVObject* parent, const UI_Rectangle& shape,
  25.                   UI_ViewID id)
  26.     : UI_MonthCalendar (parent, shape, id) {};
  27.  
  28.     void ClickOnDay (short day); // Override inherited method
  29. };
  30.  
  31.  
  32. void CalendarView::ClickOnDay (short day)
  33. {
  34.     CL_String msg;
  35.     msg.AssignWithFormat ("You clicked on %d", day);
  36.     UI_SimpleDialog (msg.AsPtr(), "Calendar");
  37. }
  38.  
  39.  
  40.  
  41. class AppWindow: public UI_CompositeVObject {
  42.  
  43. public:
  44.     AppWindow ();
  45.  
  46.     // Override the Composite's virtual method:
  47.     bool HandleChildEvent (const UI_Event& e);
  48.  
  49. protected:
  50.     CalendarView* cal;
  51.     UI_PushButton* prev, *next;
  52.  
  53. };
  54.  
  55.     
  56. AppWindow::AppWindow()
  57. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (50, 50, 290, 320))
  58. {
  59.     cal  = new CalendarView  (this, UI_Rectangle (0,0, 270, 230), ID_CAL);
  60.     prev = new UI_PushButton (this, UI_Rectangle (50, 250, 40, 30), ID_PREV);
  61.     (prev->Title()) = "<";
  62.     next = new UI_PushButton (this, UI_Rectangle (120, 250, 40, 30), ID_NEXT);
  63.     (next->Title()) = ">";
  64. }
  65.  
  66.  
  67. bool AppWindow::HandleChildEvent (const UI_Event& e)
  68. {
  69.     if (e.Type() == Event_Select) {
  70.         if (e.Origin()->ViewID() == ID_NEXT)
  71.             cal->AdvanceMonth();
  72.         else if (e.Origin()->ViewID() == ID_PREV)
  73.             cal->PreviousMonth();
  74.     return TRUE;
  75.     }
  76.     return FALSE;
  77. }
  78.  
  79.  
  80.  
  81.  
  82. // ========================== Main program ==========================
  83.  
  84.  
  85. int UI_Application::Main (int, char* [])
  86. {
  87.     MakeTopWindow (new AppWindow);
  88.     MainWindow()->Title() = "YACL Calendar Demo";
  89.     Run();
  90.     return 0;
  91. }
  92.