home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / vobjcoll.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  7KB  |  314 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. #if defined(__GNUC__)
  31. #pragma implementation
  32. #endif
  33.  
  34.  
  35. #include "base/binding.h"
  36. #include "base/clntset.h"
  37.  
  38. #include "ui/vobjcoll.h"
  39. #include "ui/applic.h"
  40. #include "ui/cntroler.h"
  41.  
  42.  
  43. #if defined (__MS_WINDOWS__)
  44. #include <windows.h>
  45.  
  46. #elif defined (__X_MOTIF__)
  47. #include <Xm/Xm.h>
  48. #include <Xm/BulletinB.h>
  49.  
  50. #endif
  51.  
  52.  
  53.  
  54. UI_VObjCollection::UI_VObjCollection (UI_VObjCollection* parent,
  55.                                       const UI_Rectangle& shape,
  56.                                       UI_ViewID id)
  57. : UI_VisualObject(parent, shape, id)
  58. {
  59. #if defined(__MS_WINDOWS__)
  60.     _style = WS_CHILD | WS_CLIPCHILDREN;
  61. #elif defined(__OS2__)
  62.     _style = WS_VISIBLE;
  63. #endif
  64. }
  65.  
  66.  
  67. bool UI_VObjCollection::Enable ()
  68. {
  69.     if (!UI_VisualObject::Enable())
  70.         return FALSE;
  71.     UI_VObjCollIterator itr (*this);
  72.     while (itr.More())
  73.         itr.Next()->Enable();
  74.     return TRUE; // ??
  75. }
  76.  
  77.  
  78.  
  79. bool UI_VObjCollection::Disable ()
  80. {
  81.     UI_VisualObject::Disable();
  82.     UI_VObjCollIterator itr (*this);
  83.     while (itr.More())
  84.         itr.Next()->Disable();
  85.     return TRUE; // ??
  86. }
  87.  
  88.  
  89.  
  90. void UI_VObjCollection::MakeInvisible ()
  91. {
  92.     UI_VObjCollIterator itr (*this);
  93.     while (itr.More())
  94.         itr.Next()->MakeInvisible();
  95.     UI_VisualObject::MakeInvisible ();
  96. }
  97.  
  98.  
  99.  
  100. void UI_VObjCollection::MakeVisible ()
  101. {
  102.     UI_VObjCollIterator itr (*this);
  103.     while (itr.More())
  104.         itr.Next()->MakeVisible();
  105.     UI_VisualObject::MakeVisible ();
  106. }
  107.  
  108.  
  109.  
  110. UI_VisualObject* UI_VObjCollection::operator [] (UI_ViewID id)
  111. {
  112.     return (UI_VisualObject*) _objMap[id];
  113. }
  114.  
  115.  
  116.  
  117. long UI_VObjCollection::ChildCount ()
  118. {
  119.     return _objMap.Size();
  120. }
  121.  
  122.  
  123.  
  124.  
  125. bool UI_VObjCollection::Contains (UI_ViewID id)
  126. {
  127.     return _objMap.IncludesKey (id);
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. UI_VObjCollection::~UI_VObjCollection ()
  136. {
  137. }
  138.  
  139.     
  140.  
  141. UI_WindowClass UI_VObjCollection::WindowClass () const
  142. {
  143. #if defined(__MS_WINDOWS__)
  144.     return _YACLWindowClassName;
  145. #elif defined(__OS2__)
  146.     return _YACLWindowClassName;
  147. #elif defined(__X_MOTIF__)
  148.     return xmBulletinBoardWidgetClass;
  149. #endif
  150. }
  151.  
  152.  
  153. bool UI_VObjCollection::MakeVisualElement ()
  154. {
  155. #if defined(__MS_WINDOWS__) 
  156.     return UI_VisualObject::MakeVisualElement ();
  157.  
  158. #elif defined(__OS2__) 
  159.     return UI_VisualObject::MakeVisualElement ();
  160.  
  161. #elif defined(__X_MOTIF__)
  162.  
  163.     // GNU C seems to have a strange bug, so we work around it. Instead of
  164.     // saying
  165.     //    Widget pw = (Widget) (_parent->ViewHandle());
  166.     // we say
  167.     UI_VisualObject* p = _parent;
  168.     Widget pw = (Widget) p->ViewHandle();
  169.  
  170.     CL_String instance_name = InstanceName();
  171.     const char* inst_name = instance_name.AsPtr();
  172.     struct _WidgetClassRec *class_name = WindowClass ();
  173.  
  174.     Arg arg [20];
  175.     short argn = 0;
  176.     _SetupStyle (arg, argn); // Set up the X resources
  177.  
  178.     XmString title = XmStringCreate
  179.         ((char *) _title.AsPtr (), XmSTRING_DEFAULT_CHARSET);    
  180.     XtSetArg (arg [argn], XmNlabelString,  title); argn++;
  181.     XtSetArg (arg [argn], XmNmarginWidth,  0);     argn++;
  182.     XtSetArg (arg [argn], XmNmarginHeight, 0);     argn++;
  183.     _xwidget = XtCreateWidget (inst_name, class_name, pw, arg, argn);
  184.     // XtManageChild (_xwidget);
  185.     // XtSetValues (_xwidget, arg, argn);
  186.  
  187.     XmStringFree (title);
  188.     return TRUE;
  189. #endif
  190. }
  191.  
  192.  
  193.  
  194. bool UI_VObjCollection::_PrivateHandleChildEvent (UI_Event& e)
  195. {
  196.     bool b = HandleChildEvent (e);
  197.     bool p = TRUE;
  198.     if (_eventDependents) {
  199.         CL_ClientSet* set = (CL_ClientSet*) (*_eventDependents)[e.Type()];
  200.         if (set)
  201.             p = set->Permits (e);
  202.     }
  203.     return b || !p;
  204. }
  205.  
  206.  
  207.  
  208.  
  209. bool UI_VObjCollection::DestroyVisualElement ()
  210. {
  211. #if defined(__MS_WINDOWS__)
  212.     if (_handle > 0 && !CreatedViaResource()) {
  213.         DestroyWindow (_handle);
  214.         return TRUE;
  215.     }
  216. #elif defined(__X_MOTIF__)
  217.     if ( _xwidget ) {
  218.         XtUnmanageChild (_xwidget);
  219.         XtDestroyWidget (_xwidget);
  220.         return TRUE;
  221.     }
  222. #endif
  223.     return FALSE;
  224. }
  225.  
  226.  
  227. typedef CL_Binding<UI_VObjCollection> VObjCollBind;
  228.  
  229.  
  230. #if defined(__GNUC__)
  231. template class CL_Binding<UI_VObjCollection>;
  232. #endif
  233.  
  234.  
  235. void UI_VObjCollection::_PrivateInitialize()
  236. {
  237.     UI_VisualObject::_PrivateInitialize();
  238.     if (_model) {
  239.         VObjCollBind b (this, &(UI_VObjCollection::_ModelChanged));
  240.         _model->AddDependent (b, 1);
  241.     }
  242. }
  243.  
  244.  
  245.  
  246. bool UI_VObjCollection::_ModelChanged (CL_Object &o, long val)
  247. {
  248.     return UI_VisualObject::_ModelChanged (o, val);
  249. }
  250.  
  251.  
  252.  
  253. void UI_VObjCollection::AddChild (UI_VisualObject* child)
  254. {
  255.     if (child && child->ViewID() > 0)
  256.         _objMap.Add (child->ViewID(), child);
  257. }
  258.  
  259.  
  260. UI_VisualObject* UI_VObjCollection::RemoveChild (UI_VisualObject* view)
  261. {
  262.     if (!view)
  263.         return NULL;
  264.     UI_ViewID childID = view->ViewID();
  265.     if (childID > 0) {
  266.         CL_IntPtrAssoc assoc = _objMap.Remove (childID);
  267.         return (UI_VisualObject*) assoc.value;
  268.     }
  269.     return NULL;
  270. }
  271.  
  272. bool UI_VObjCollection::SetFont (UI_Font* font)
  273. {
  274.     if (!UI_VisualObject::SetFont (font))
  275.         return FALSE;
  276.     CL_IntPtrMapIterator itr (_objMap);
  277.     while (itr.More()) {
  278.         CL_IntPtrAssoc assoc = itr.Next();
  279.         ((UI_VisualObject*) assoc.value)->SetFont(font);
  280.     }
  281.     return TRUE;
  282. }
  283.  
  284.  
  285.  
  286.  
  287. UI_VObjCollIterator::UI_VObjCollIterator (UI_VObjCollection& v)
  288. : _itr (v._objMap)
  289. {
  290.     _itr.Reset();
  291. }
  292.  
  293.  
  294.  
  295.  
  296. void UI_VObjCollIterator::Reset ()
  297. {
  298.     _itr.Reset();
  299. }
  300.  
  301.  
  302.  
  303. bool UI_VObjCollIterator::More ()
  304. {
  305.     return _itr.More();
  306. }
  307.  
  308.  
  309. UI_VisualObject* UI_VObjCollIterator::Next ()
  310. {
  311.     return (UI_VisualObject*) _itr.Next().value;
  312. }
  313.  
  314.