home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / uidemo / menu1 / box.cxx next >
C/C++ Source or Header  |  1995-01-09  |  3KB  |  107 lines

  1.  
  2.  
  3. #include "base/memory.h"
  4.  
  5. #include "ui/ui.h"
  6. #include "box.h"
  7. #include "ids.h"
  8.  
  9.  
  10.  
  11.  
  12. static char* cities[] = {
  13.     "Chicago",
  14.     "New York",
  15.     "Atlanta",
  16.     "Bangalore",
  17.     "Beijing",
  18.     "Bombay",
  19.     "Columbia",
  20.     "Binghamton",
  21.     "Los Angeles",
  22.     "Copenhagen",
  23.     "Amsterdam",
  24.     "Berlin",
  25.     "London",
  26.     0
  27. };
  28.  
  29.  
  30. Box::Box (UI_CompositeVObject* parent, const UI_Rectangle& shape)
  31. : UI_CompositeVObject (parent, NULL, TRUE,
  32.                        UI_Rectangle (100, 100, 480, 400), -1)
  33. {
  34.     ShowBorder ();
  35.     _strseq = new UI_StringSequence;
  36.     for (short i = 0; cities[i] != 0; i++)
  37.         _strseq->Add (cities[i]);
  38.  
  39.     _singl = new UI_StringViewSingleSel
  40.         (this, _strseq, UI_Rectangle (40,  50, 130, 160), ID_SINGLE_VIEW);
  41.     _multi = new UI_StringViewMultiSel
  42.         (this, _strseq, UI_Rectangle (200, 50, 130, 160), ID_MULT_VIEW);
  43.     UI_Label* msg = new UI_Label (this, UI_Rectangle (10, 10, 350, 20));
  44.     UI_Label* sl1 = new UI_Label (this, UI_Rectangle (40, 230, 150, 20),
  45.                                   ID_SSEL_LBL);
  46.     UI_Label* slm = new UI_Label (this, UI_Rectangle (200, 230, 150, 20),
  47.                                   ID_MSEL_LBL);
  48.     sl1->SetTextStyle (UIText_Left);
  49.     slm->SetTextStyle (UIText_Left);
  50.     msg->Model() = CL_String ("Two StringView objects with the same model:");
  51. //    msg->Font().PointSize (9);
  52. // #if defined(__MS_WINDOWS__)
  53. //     char* font_name = "MS Sans Serif";
  54. // #elif defined(__X_MOTIF__)
  55. //     char* font_name = "courier";
  56. // #endif
  57. //     msg->Font().TypeFace (font_name);
  58.     
  59. //     UI_Font& font1 = _singl->Font();
  60. //     font1.TypeFace (font_name);
  61. //     font1.BoldFace (TRUE);
  62. //     font1.PointSize (9);
  63. // 
  64. //     UI_Font& font2 = _multi->Font();
  65. //     font2.TypeFace ("Courier");
  66. //     font2.BoldFace (TRUE);
  67. //     font2.PointSize (10);
  68. }
  69.  
  70.  
  71. Box::~Box()
  72. {
  73.     UI_SimpleDialog (CL_String ("Max mem used: ") +
  74.                      CL_String (CL_MemoryLeakChecker::MaxMemoryUsed()) +
  75.                      CL_String (" Current usage: ") +
  76.                      CL_String (CL_MemoryLeakChecker::CurrentMemoryUsage()));
  77.     delete _strseq;
  78. }
  79.  
  80.  
  81. bool Box::HandleChildEvent (const UI_Event& e)
  82. {
  83.     if (e.Type() != Event_Select)
  84.         return FALSE;
  85.     if(e.Origin()->ViewID() == ID_SINGLE_VIEW) {
  86.         UI_StringViewSingleSel* v = _singl;
  87.         const CL_Integer& indx = v->Selection();
  88.         if (indx == 2)
  89.            _strseq->Remove (2);
  90.         else if (indx >= 0) {
  91.             long l = indx;
  92.             if ((*_strseq)[l] == "Copenhagen")
  93.                 _strseq->Insert ("Click here", l);
  94.             else if ((*_strseq)[l] == "Click here")
  95.                 (*_strseq)[l] = "Don't click";
  96.             else if ((*_strseq)[l] == "Don't click")
  97.                 (*_strseq)[l] = "Click here";
  98.         }
  99.     }
  100.     CL_String s = _singl->Selection().AsString();
  101.     (*this)[ID_SSEL_LBL]->Title() = "Selection: " + s;
  102.     s = _multi->Selection().AsString();
  103.     (*this)[ID_MSEL_LBL]->Title() = "Selection: " + s;
  104.     return TRUE;
  105. }
  106.  
  107.