00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00093 #ifndef __vtkWidgetSet_h
00094 #define __vtkWidgetSet_h
00095 
00096 #include "vtkObject.h"
00097 #include <vtkstd/vector> 
00098 
00099 class vtkAbstractWidget;
00100 
00101 
00102 
00103 
00104 
00105 template< class TWidget > struct ActionFunction
00106 {
00107   typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
00108 };
00109 
00110 
00111 class VTK_WIDGETS_EXPORT vtkWidgetSet : public vtkObject
00112 {
00113 public:
00115   static vtkWidgetSet *New();
00116 
00118 
00119   vtkTypeMacro(vtkWidgetSet,vtkObject);
00120   void PrintSelf(ostream& os, vtkIndent indent);
00122 
00124 
00125   virtual void SetEnabled(int);
00126   vtkBooleanMacro(Enabled, int);
00128 
00130   void AddWidget(vtkAbstractWidget *);
00131 
00133   void RemoveWidget(vtkAbstractWidget *);
00134 
00136   unsigned int GetNumberOfWidgets();
00137 
00139   vtkAbstractWidget *GetNthWidget( unsigned int );
00140 
00141   
00142   
00143   
00144   typedef vtkstd::vector< vtkAbstractWidget * >   WidgetContainerType;
00145   typedef WidgetContainerType::iterator           WidgetIteratorType;
00146   typedef WidgetContainerType::const_iterator     WidgetConstIteratorType;
00147   WidgetContainerType                             Widget;
00148  
00150 
00152   template < class TWidget >
00153   void DispatchAction(TWidget *caller, 
00154                       typename ActionFunction< TWidget >::TActionFunctionPointer action)
00155     {
00156     
00157     for (WidgetIteratorType it  = this->Widget.begin(); 
00158                             it != this->Widget.end()  ; ++it)
00159       {
00160       TWidget *w = static_cast<TWidget *>(*it);
00161       if (caller == w)
00162         {
00163         ((*w).*(action))(caller); 
00164         break;
00165         }
00166       }
00168     
00169     
00170     for (WidgetIteratorType it  = this->Widget.begin(); 
00171                             it != this->Widget.end()  ; ++it)
00172       {
00173       TWidget *w = static_cast<TWidget *>(*it);
00174       if (caller != w) ((*w).*(action))(caller);
00175       }
00176     }
00177   
00178 
00179 protected:
00180   vtkWidgetSet();
00181   ~vtkWidgetSet();
00182 
00183 private:
00184   vtkWidgetSet(const vtkWidgetSet&);  
00185   void operator=(const vtkWidgetSet&);  
00186 };
00187 
00188 #endif
00189