bbtkWxBlackBox.h

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxBlackBox.h,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:15 $
00006   Version:   $Revision: 1.18 $
00007 ========================================================================*/
00008 
00009 
00010 /* ---------------------------------------------------------------------
00011 
00012 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00013 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00014 *
00015 *  This software is governed by the CeCILL-B license under French law and 
00016 *  abiding by the rules of distribution of free software. You can  use, 
00017 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00018 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00019 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00020 *  or in the file LICENSE.txt.
00021 *
00022 *  As a counterpart to the access to the source code and  rights to copy,
00023 *  modify and redistribute granted by the license, users are provided only
00024 *  with a limited warranty  and the software's author,  the holder of the
00025 *  economic rights,  and the successive licensors  have only  limited
00026 *  liability. 
00027 *
00028 *  The fact that you are presently reading this means that you have had
00029 *  knowledge of the CeCILL-B license and that you accept its terms.
00030 * ------------------------------------------------------------------------ */                                                                         
00047 #ifdef _USE_WXWIDGETS_
00048 
00049 
00050 #ifndef __bbtkWxBlackBox_h__
00051 #define __bbtkWxBlackBox_h__
00052 
00053 
00054 #include "bbtkWx.h"
00055 #include "bbtkAtomicBlackBox.h"
00056 
00057 
00058 namespace bbtk
00059 {
00060 
00061 
00062 
00063 
00064   //==================================================================
00065   // Forward declaration of the class of window associated to a WxBlackBox
00066   class WxBlackBoxWindow;
00067   //==================================================================
00068 
00069   //==================================================================
00070   // Forward declaration of the widget event handler class
00071   class WxBlackBoxWidgetEventHandler;
00072   //==================================================================
00073 
00074 
00075   //==================================================================
00077   class BBTK_EXPORT WxBlackBox : public bbtk::AtomicBlackBox  
00078   { 
00079     BBTK_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::AtomicBlackBox);
00080     //   BBTK_DECLARE_INPUT(WinParent,WxParentToChildData*);
00081     BBTK_DECLARE_INPUT(WinTitle,std::string);
00082     BBTK_DECLARE_INPUT(WinWidth,int);
00083     BBTK_DECLARE_INPUT(WinHeight,int);
00084     BBTK_DECLARE_INPUT(WinDialog,bool);
00085     BBTK_DECLARE_INPUT(WinHide,Void);
00086     BBTK_DECLARE_INPUT(WinClose,Void);
00087     BBTK_DECLARE_OUTPUT(Widget, wxWindow*);//WxBlackBoxWidget*);
00088 
00089   public:
00091     virtual void bbExecute(bool force = false);
00092 
00093 
00094     typedef WxBlackBoxWindow Window;
00095     
00098     Window* bbGetWindow() { return bbmWindow; }
00099 
00108     Window* bbGetContainingWindow();
00109 
00111     wxWindow* bbGetWxParent();
00112 
00115     bool bbIsShown();
00116 
00117     //==================================================================    
00119     virtual void bbUserOnShow() {}
00120     //==================================================================    
00121  
00122     //==================================================================    
00124     virtual void bbUserOnHide() {}
00125     //==================================================================    
00126 
00127   protected:
00128     
00129   
00130     //==================================================================
00132     virtual void bbUserConstructor();
00134     virtual void bbUserCopyConstructor();
00136     virtual void bbUserDestructor();
00137     //==================================================================    
00138 
00139     //==================================================================    
00142     virtual void bbUserCreateWidget() 
00143     {
00144       bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
00145     }
00146     //==================================================================    
00147 
00148 
00149     
00150 
00151     //==================================================================
00153     virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
00154     //==================================================================
00155 
00156 
00157 
00158     //==================================================================
00164     virtual void bbProcess();
00165     //==================================================================
00166 
00167     //==================================================================
00173     void bbShowWindow();
00175     void bbHideWindow();
00177     void bbCloseWindow();
00178     //==================================================================
00179 
00180   private:
00182     friend class WxBlackBoxWindow;
00183     friend class WxBlackBoxWidgetEventHandler;
00184 
00186     inline void bbSetWindow(Window* w) { bbmWindow=w; }
00187 
00189     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
00190     { bbmWidgetEventHandler = w; }
00192     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
00193     { return bbmWidgetEventHandler; }
00194 
00195 
00197     Window* bbmWindow;
00199     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
00200 
00201 
00202     void bbInitAttributes();
00203 
00204   protected :
00205 
00206 
00211     bool bbmUpdateTransferedToParent;
00212 
00213     bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
00214     void bbSetUpdateTransferedToParent(bool b) 
00215     { bbmUpdateTransferedToParent = b; }
00216 
00217   };
00218   //=================================================================
00219  
00220 
00221   //======================================================================
00223 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
00224   public:                                                               \
00225   inline void bbUserCreateWidget()                                      \
00226   {                                                                     \
00227     bbtkDebugMessageInc("process",1,"**> Creating widget for ["         \
00228                         <<bbGetFullName()<<"]"<<std::endl);             \
00229     CALLBACK();                                                         \
00230     bbtkDebugMessageInc("process",2,"<** Creating widget for ["         \
00231                         <<bbGetFullName()<<"]"<<std::endl);             \
00232   }
00233   
00234   //======================================================================
00235 
00236   //=================================================================
00237   // WxBlackBoxDescriptor declaration
00238   BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
00239   BBTK_NAME("WxBlackBox");
00240   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
00241   BBTK_CATEGORY("widget");
00242   BBTK_INPUT(WxBlackBox,WinTitle,
00243              "Title of the window (*)",
00244              std::string,"");
00245   BBTK_INPUT(WxBlackBox,WinWidth,
00246              "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
00247   BBTK_INPUT(WxBlackBox,WinHeight,
00248              "Height of the window (*)",int,"");
00249   BBTK_INPUT(WxBlackBox,WinDialog,
00250              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
00251   BBTK_INPUT(WxBlackBox,WinHide,
00252              "Any signal received hides the window (*)",Void,"signal");
00253   BBTK_INPUT(WxBlackBox,WinClose,
00254              "Any signal received closes the window (*)",Void,"signal");
00255   BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
00256   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
00257   //=================================================================
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267   //==================================================================
00268   // The base of the hierarchy of windows associated to a WxBlackBox
00269   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
00270   {
00271   public:
00272     WxBlackBoxWindow(WxBlackBox::Pointer box);
00273     virtual ~WxBlackBoxWindow();
00274     virtual void bbShow();
00275     virtual void bbHide();
00276     virtual void bbClose();
00277     bool bbIsShown() { return mShown; }
00278     virtual WxBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
00279     virtual wxDialog* bbGetDialog() { return 0; } 
00280     virtual wxFrame* bbGetFrame() { return 0; } 
00281   private:
00282     WxBlackBox::WeakPointer mBox;
00283     bool mShown;
00284   };
00285   //==================================================================
00286 
00287   //==================================================================
00288   // Dialog window which is modal
00289   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
00290   {
00291   public:
00292     WxBlackBoxDialog(WxBlackBox::Pointer box, 
00293                      wxWindow *parent, wxString title, wxSize size);
00294     ~WxBlackBoxDialog();
00295     void bbShow();  
00296     void bbHide();
00297     void bbClose();
00298     wxDialog* bbGetDialog() { return this; } 
00299   };
00300   //==================================================================
00301 
00302   //==================================================================
00303   // Frame window which is not modal
00304   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
00305   {
00306   public:
00307     WxBlackBoxFrame(WxBlackBox::Pointer box,
00308                     wxWindow *parent, wxString title, wxSize size);
00309     ~WxBlackBoxFrame();
00310     void bbShow();
00311     void bbHide();
00312     void bbClose();
00313     wxFrame* bbGetFrame() { return this; } 
00314   };
00315   //==================================================================
00316 
00317 
00318 
00319   //=================================================================
00320   // Handles the destroy events of a widget associated to a WxBlackBox 
00321   // in order to signal the widget death to its associated box
00322   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
00323   {
00324   public:
00326     WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
00328     ~WxBlackBoxWidgetEventHandler();
00330     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
00331     // wxWindow* GetWxWindow() { return mWindow; }
00333     void OnWindowDestroy(wxWindowDestroyEvent&);
00334     //
00335     //bool IsDead() { return mDead; }
00336 
00337   private:
00338     WxBlackBox::WeakPointer mBox;
00339     wxWindow* mWindow;
00340     //bool mDead;
00341   };  
00342   //=================================================================
00343 
00344 
00345 
00346 } //namespace bbtk
00347 
00348 #endif  //__bbtkWxBlackBox_h__
00349 
00350 #endif  //_USE_WXWIDGETS_

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6