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

  1.  
  2.  
  3.  
  4.  
  5.  
  6. #include "ui/orbtngrp.h"
  7. #include "ui/strseq.h"
  8. #include "ui/strview.h"
  9. #include "ui/xrbtngrp.h"
  10. #include "ui/pushbtn.h"
  11. #include "ui/label.h"
  12. #include "ui/stred.h"
  13. #include "ui/dialog.h"
  14. #include "ui/applic.h"
  15. #include "ui/interval.h"
  16.  
  17.  
  18. #include "appwin.h"
  19. #include "dlgs.h"
  20.  
  21.  
  22. UI_ViewDescriptor MainGroup [] = {
  23. {View_ExOrToggleButton, 200, 10,  30,  120, 24, TRUE,  "Cars", NULL},
  24. {View_ExOrToggleButton, 201, 10,  60,  120, 24, TRUE,  "Coffee", NULL},
  25. {View_ExOrToggleButton, 202, 10,  90,  120, 24, TRUE,  "Sandwiches", NULL},
  26. {View_None, 0, 0}                                         
  27. };                                                        
  28.                                                           
  29. UI_ViewDescriptor MainDesc [] = {                         
  30. {View_ExOrButtonGroup    ,  ID_CHOICES, 10, 20,  140, 140, FALSE, "Choice",
  31.      MainGroup},
  32. {View_None, 0, 0}
  33. };
  34.  
  35. extern UI_ViewDescriptor DLG_CarOptions_Item[];
  36. extern UI_ViewDescriptor DLG_Sandwich_Item[];
  37. extern UI_ViewDescriptor DLG_Coffee_Item[];
  38.  
  39. UI_ViewDescriptor* AllDialogs[] = {
  40.      DLG_CarOptions_Item,
  41.      DLG_Coffee_Item,
  42.      DLG_Sandwich_Item,
  43.      0
  44. };
  45.  
  46.  
  47. class SubDialog {
  48.  
  49. public:
  50.     SubDialog (UI_CompositeVObject* parent, UI_ViewDescriptor* desc,
  51.                UI_Point topLeft);
  52.  
  53.     void MakeVisible ();
  54.  
  55.     void MakeInvisible ();
  56.  
  57. protected:
  58.     UI_ViewDescriptor*   _desc;
  59.     UI_CompositeVObject* _parent;
  60.     UI_Point             _topLeft;
  61. };
  62.  
  63.  
  64. SubDialog::SubDialog (UI_CompositeVObject* parent, UI_ViewDescriptor desc[],
  65.                       UI_Point topLeft)
  66. : _parent (parent), _desc (desc), _topLeft (topLeft)
  67. {
  68.     for (short i = 0; desc[i].id != 0; i++) {
  69.         UI_ViewDescriptor d = desc[i];
  70.         d.shape.x += _topLeft.XCoord();
  71.         d.shape.y += _topLeft.YCoord();
  72.         parent->CreateChild (d);
  73.     }
  74. }
  75.  
  76. void SubDialog::MakeVisible ()
  77. {
  78.     for (short i = 0; _desc[i].id != 0; i++)
  79.         (*_parent)[_desc[i].id]->MakeVisible();
  80. }
  81.  
  82. void SubDialog::MakeInvisible ()
  83. {
  84.     for (short i = 0; _desc[i].id != 0; i++)
  85.         (*_parent)[_desc[i].id]->MakeInvisible();
  86. }
  87.  
  88.  
  89. static char* fixings[] = {
  90.     "Lettuce",
  91.     "Tomatoes",
  92.     "Onions",
  93.     "Cream cheese",
  94.     "Black olives",
  95.     "Pimentos",
  96.     "Alfalfa sprouts",
  97.     "Cucumber",
  98.     "Mushrooms",
  99.     "Green olives",
  100.     "Jalapenos",
  101.     0
  102. };
  103.  
  104. AppWindow::AppWindow()
  105. : UI_CompositeVObject (NULL, MainDesc, FALSE, UI_Rectangle (50, 50, 650, 300))
  106. {
  107.     _current = NULL;
  108.     for (short i = 0; AllDialogs[i] != 0; i++) {
  109.         _comp[i] = new SubDialog (this, AllDialogs[i], UI_Point (150, 10));
  110.         _comp[i]->MakeInvisible();
  111.     }
  112.     UI_StringView* l = (UI_StringView*) (*this)[ID_FIXINGS_LIST];
  113.     UI_StringSequence& s = (UI_StringSequence&) l->Model();
  114.     for (i = 0; fixings[i] != 0; i++)
  115.         s.Add (fixings[i]);
  116. }
  117.  
  118. void AppWindow::Initialize ()
  119. {
  120.     _title = "Dynamic Dialog Demo";
  121. }
  122.  
  123. void AppWindow::ShowDialog (short index)
  124. {
  125.     if (index < 0 || index > 2)
  126.         return; // Should never happen
  127.     if (_current == _comp[index])
  128.         return; // Same as what's being shown
  129.     if (_current)
  130.         _current->MakeInvisible();
  131.     _current = _comp[index];
  132.     _current->MakeVisible();
  133. }
  134.  
  135. bool AppWindow::HandleChildEvent (const UI_Event& e)
  136. {
  137.     if (e.Type() != Event_Select)
  138.         return FALSE;
  139.     UI_ExOrButtonGroup* grp =  (UI_ExOrButtonGroup*) (*this)[ID_CHOICES];
  140.     if (e.Origin() == grp) 
  141.         ShowDialog (grp->Selection() - 200);
  142.     // Take advantage of the fact that view id's of the buttons are
  143.     // consecutive beginning at 200.
  144.     return TRUE;
  145. }
  146.  
  147.  
  148.  
  149.