home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / orbtngrp.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  4KB  |  144 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /*
  7.  *
  8.  *          Copyright (C) 1994, M. A. Sridhar
  9.  *  
  10.  *
  11.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  12.  *     to copy, modify or distribute this software  as you see fit,
  13.  *     and to use  it  for  any  purpose, provided   this copyright
  14.  *     notice and the following   disclaimer are included  with all
  15.  *     copies.
  16.  *
  17.  *                        DISCLAIMER
  18.  *
  19.  *     The author makes no warranties, either expressed or implied,
  20.  *     with respect  to  this  software, its  quality, performance,
  21.  *     merchantability, or fitness for any particular purpose. This
  22.  *     software is distributed  AS IS.  The  user of this  software
  23.  *     assumes all risks  as to its quality  and performance. In no
  24.  *     event shall the author be liable for any direct, indirect or
  25.  *     consequential damages, even if the  author has been  advised
  26.  *     as to the possibility of such damages.
  27.  *
  28.  */
  29.  
  30.  
  31. #if defined(__GNUC__)
  32. #pragma implementation
  33. #endif
  34.  
  35.  
  36. #include "ui/orbtngrp.h"
  37. #include "ui/cntroler.h"
  38. #include "ui/toglbtn.h"
  39. #include "base/integer.h"
  40.  
  41. typedef CL_Binding <UI_OrButtonGroup> Bind;
  42.  
  43. #if defined(__GNUC__) && __GNUC_MINOR__ >= 6
  44. template class CL_Binding<UI_OrButtonGroup>;
  45. #endif
  46.  
  47. UI_OrButtonGroup::UI_OrButtonGroup
  48.     (UI_VObjCollection* parent, const UI_Rectangle& shape,
  49.      UI_ViewID id, UI_ViewDescriptor* vd)
  50. : UI_ButtonGroup (parent, shape, id)
  51. {
  52.     if (vd) {
  53.         char* fmt = "UI_OrButtonGroup constructor: invalid type %d "
  54.             "at index %d";
  55.         for (short i = 0; vd[i].type != View_None; i++) {
  56.             if (vd[i].type != View_ToggleButton) {
  57.                 CL_Error::Warning (fmt, vd[i].type, i);
  58.                 break;
  59.             }
  60.             UI_ToggleButton* p = new UI_ToggleButton
  61.                 (this, vd[i].shape, vd[i].id);
  62.             p->Title() = vd[i].title;
  63.         }
  64.     }
  65.     _Init ();
  66. }
  67.  
  68.  
  69. #if defined(__MS_WINDOWS__)
  70. UI_OrButtonGroup::UI_OrButtonGroup
  71.     (UI_CompositeVObject* parent,  UI_ViewID id, UI_ViewHandle h)
  72. : UI_ButtonGroup (parent, id, h)
  73. {
  74.     _Init ();
  75. }
  76.  
  77. #endif
  78.  
  79.  
  80.  
  81. void UI_OrButtonGroup::_Init ()
  82. {
  83.     Bind bind (this, &UI_OrButtonGroup::_ModelChanged);
  84.     _selection.AddDependent (bind, 1);
  85. }
  86.  
  87.  
  88.  
  89.  
  90. CL_IntegerSet& UI_OrButtonGroup::Selection ()
  91. {
  92.     _UpdateSelection ();
  93.     return _selection;
  94. }
  95.  
  96. void UI_OrButtonGroup::_UpdateSelection ()
  97. {
  98.     // We're going to modify _selection, so we must first remove ourselves
  99.     // from its dependent set
  100.     Bind bind (this, &UI_OrButtonGroup::_ModelChanged);
  101.     _selection.RemoveDependent (bind); // So we don't get notified
  102.  
  103.     // Now fix it up:
  104.     _selection.MakeEmpty ();
  105.     CL_IntPtrMapIterator itr (_objMap);
  106.     while (itr.More()) {
  107.         CL_IntPtrAssoc assoc = itr.Next();
  108.         UI_ViewID id = assoc.key;
  109.         CL_Integer value =  (CL_Integer&) ((*this)[id]->Model());
  110.         if (value)
  111.             _selection.Add (id);
  112.     }
  113.     _selection.AddDependent (bind, 1); // Add us back as dependent
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. bool UI_OrButtonGroup::_ModelChanged (CL_Object&, long)
  121. {
  122.     CL_IntPtrMapIterator itr (_objMap);
  123.     while (itr.More()) {
  124.         CL_IntPtrAssoc assoc = itr.Next();
  125.         UI_ViewID id = assoc.key;
  126.         CL_Integer value = _selection.Includes (id) ? 1 : 0;
  127.         (*this)[id]->Model() = value;
  128.     }
  129.     return TRUE;
  130. }
  131.  
  132.  
  133. bool UI_OrButtonGroup::Select()
  134. {
  135.     _UpdateSelection ();
  136.     _Controller->AddEvent (new UI_Event (Event_Select, this, this));
  137.     return TRUE;
  138. }
  139.  
  140.  
  141.         
  142.  
  143.  
  144.