home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / xrbtngrp.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  4KB  |  154 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/xrbtngrp.h"
  37. #include "ui/cntroler.h"
  38. #include "ui/xrtglbtn.h"
  39.  
  40. typedef CL_Binding <UI_ExOrButtonGroup> Bind;
  41.  
  42. #if defined(__GNUC__)
  43. template class CL_Binding<UI_ExOrButtonGroup>;
  44. #endif
  45.  
  46.  
  47. UI_ExOrButtonGroup::UI_ExOrButtonGroup
  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_ExOrButtonGroup 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_ExOrToggleButton) {
  57.                 CL_Error::Warning (fmt, vd[i].type, i);
  58.                 break;
  59.             }
  60.             UI_ExOrToggleButton* p = new UI_ExOrToggleButton
  61.                 (this, vd[i].shape, vd[i].id);
  62.             p->Title() = vd[i].title;
  63.             _objMap.Add (id, p);
  64.         }
  65.     }
  66.     _Init ();
  67. }
  68.  
  69.  
  70. #if defined(__MS_WINDOWS__)
  71. UI_ExOrButtonGroup::UI_ExOrButtonGroup
  72.     (UI_CompositeVObject* parent,  UI_ViewID id, UI_ViewHandle h)
  73. : UI_ButtonGroup (parent, id, h)
  74. {
  75.     _Init ();
  76. }
  77.  
  78. #endif
  79.  
  80.  
  81.  
  82. void UI_ExOrButtonGroup::_Init ()
  83. {
  84.     Bind bind (this, &UI_ExOrButtonGroup::_ModelChanged);
  85.     _selection.AddDependent (bind, 1);
  86. }
  87.  
  88.  
  89. bool UI_ExOrButtonGroup::_ModelChanged (CL_Object&, long)
  90. {
  91.     CL_IntPtrMapIterator itr (_objMap);
  92.     while (itr.More()) {
  93.         CL_IntPtrAssoc assoc = itr.Next();
  94.         UI_ViewID id = assoc.key;
  95.         (CL_Integer&) ((*this)[id]->Model()) = 0;
  96.     }
  97.     if (_objMap.IncludesKey (_selection))
  98.         (CL_Integer&) ((*this)[_selection]->Model()) = 1;
  99.     return TRUE;
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. bool UI_ExOrButtonGroup::HandleChildEvent (const UI_Event& e)
  107. {
  108.     if (e.Type() != Event_Select)
  109.         return FALSE;
  110. #if defined(__MS_WINDOWS__) || defined(__OS2__)
  111.     _UpdateSelection ();
  112.     
  113. #elif defined(__X_MOTIF__)
  114.     UI_VisualObject* v = e.Origin();
  115.     UI_ViewID id = v->ViewID();
  116.     Bind bind (this, &UI_ExOrButtonGroup::_ModelChanged);
  117.     _selection.RemoveDependent (bind);
  118.     _selection = id; // The dependent removal is so that this
  119.                      // assignment does not give us notification
  120.     _selection.AddDependent (bind, 1);
  121. #endif
  122.     _Controller->AddEvent (new UI_Event (Event_Select, this, this));
  123.     return TRUE;
  124. }
  125.  
  126.  
  127.  
  128.  
  129. CL_Integer& UI_ExOrButtonGroup::Selection()
  130. {
  131.     _UpdateSelection ();
  132.     return _selection;
  133. }
  134.  
  135.  
  136. void UI_ExOrButtonGroup::_UpdateSelection()
  137. {
  138.     CL_IntPtrMapIterator itr (_objMap);
  139.     while (itr.More()) {
  140.         CL_IntPtrAssoc assoc = itr.Next();
  141.         UI_ViewID id = assoc.key;
  142.         CL_Integer value =  (CL_Integer&) ((*this)[id]->Model());
  143.         if (value) {
  144.             Bind bind (this, &UI_ExOrButtonGroup::_ModelChanged);
  145.             _selection.RemoveDependent (bind);
  146.             _selection = id; // The dependent removal is so that this
  147.                              // assignment does not give us notification
  148.             _selection.AddDependent (bind, 1);
  149.             break;
  150.         }
  151.     }
  152. }
  153.  
  154.