]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWidgetBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.h
diff --git a/kernel/src/bbtkWidgetBlackBox.h b/kernel/src/bbtkWidgetBlackBox.h
new file mode 100644 (file)
index 0000000..deed3f7
--- /dev/null
@@ -0,0 +1,292 @@
+/*=========================================================================                                                                               
+  Program:   bbtk
+  Module:    $RCSfile: bbtkWidgetBlackBox.h,v $
+  Language:  C++
+  Date:      $Date: 2009/04/08 07:56:11 $
+  Version:   $Revision: 1.1 $
+========================================================================*/
+
+
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+*  This software is governed by the CeCILL-B license under French law and 
+*  abiding by the rules of distribution of free software. You can  use, 
+*  modify and/ or redistribute the software under the terms of the CeCILL-B 
+*  license as circulated by CEA, CNRS and INRIA at the following URL 
+*  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+*  or in the file LICENSE.txt.
+*
+*  As a counterpart to the access to the source code and  rights to copy,
+*  modify and redistribute granted by the license, users are provided only
+*  with a limited warranty  and the software's author,  the holder of the
+*  economic rights,  and the successive licensors  have only  limited
+*  liability. 
+*
+*  The fact that you are presently reading this means that you have had
+*  knowledge of the CeCILL-B license and that you accept its terms.
+* ------------------------------------------------------------------------ */                                                                         
+/**
+ * \brief Short description in one line
+ * 
+ * Long description which 
+ * can span multiple lines
+ */
+/**
+ * \file 
+ * \brief 
+ */
+/**
+ * \class bbtk::
+ * \brief 
+ */
+#ifndef __bbtkWidgetBlackBox_h_INCLUDED__
+#define __bbtkWidgetBlackBox_h_INCLUDED__
+
+#include "bbtkAtomicBlackBox.h"
+
+namespace bbtk
+{
+
+
+  template <class T> class WidgetBlackBoxWindow;
+
+
+  //==================================================================
+  /// Generic (template) Widget black box from which all 
+  /// widget black boxes for a specific GUI toolkit inherit with 
+  /// apropriate traits.
+  /// Declares the common inputs / outputs and interface to all widget boxes
+  template <class W>
+  class BBTK_EXPORT WidgetBlackBox : public bbtk::AtomicBlackBox  
+  { 
+  public:
+    //    typedef WidgetTraits Traits;
+    typedef W Widget;
+    typedef Widget* WidgetPointer;
+    typedef WidgetBlackBoxWindow<W> Window;
+    
+    
+    BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
+    BBTK_DECLARE_INPUT(WinTitle,std::string);
+    BBTK_DECLARE_INPUT(WinWidth,int);
+    BBTK_DECLARE_INPUT(WinHeight,int);
+    BBTK_DECLARE_INPUT(WinDialog,bool);
+    BBTK_DECLARE_INPUT(WinHide,Void);
+    BBTK_DECLARE_INPUT(WinClose,Void);
+    BBTK_DECLARE_OUTPUT(Widget,Widget*);
+
+    //==================================================================
+    /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles 
+    /// the window creation if needed
+    virtual void bbCreateWindow();
+    //==================================================================
+    
+    //==================================================================
+    /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles 
+    /// the window creation if needed
+    virtual void bbShowWindow();
+    //==================================================================    
+
+    //==================================================================
+    /// Returns the **OWN** window associated to the box
+    /// If 0 returned = no window
+    Window* bbGetWindow() { return bbmWindow; }
+    /// Returns the window containing the widget associated to the box
+    /// Which can be the own window of **ANOTHER** box in case of 
+    /// a hierarchy of widgets (layouts)
+    /// More precisely :
+    /// If bbGetWindow() != 0 then returns bbGetWindow()
+    /// Else if the output 'Widget' is connected 
+    ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
+    /// Else returns 0;
+    Window* bbGetContainingWindow();
+
+
+    /// Returns true iff the 'containing window' exists and is shown 
+    /// (see bbGetContainingWindow).
+    bool bbIsShown();
+
+    /// Convenient method which returns true iff the output Widget is connected
+    bool bbIsOutputWidgetConnected();
+
+    //==================================================================    
+    /// User callback invoked when the containing window is shown
+    virtual void bbUserOnShow() {}
+    //==================================================================    
+    //==================================================================    
+    /// User callback invoked when the containing window is hidden
+    virtual void bbUserOnHide() {}
+    //==================================================================    
+
+    /// Sets the window
+    inline void bbSetWindow(Window* w) { bbmWindow=w; }
+
+    //==================================================================    
+    /// User callback for creating the widget associated to the box
+    /// ** Must be defined ** in user classes
+    virtual void bbUserCreateWidget(Widget* parent) 
+    {
+      bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
+    }
+    //==================================================================    
+
+         
+  protected:
+    
+  
+    //==================================================================
+    /// User callback called in the box contructor
+    virtual void bbUserConstructor();
+    /// User callback called in the box copy constructor
+    virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
+    /// User callback called in the box destructor
+    virtual void bbUserDestructor();
+    //==================================================================    
+
+
+
+    //==================================================================
+    /// Convenient method for layout widgets which creates and returns
+    /// (calls bbUserCreateWidget) 
+    /// the widget of the box connected to the input in.
+    /// Returns NULL if the input is not connected
+    Widget* bbCreateWidgetOfInput(const std::string& in, 
+                                 Widget* parent);
+    //==================================================================
+
+   //==================================================================    
+    /// Callback for creating a Dialog window (modal)
+    /// ** Must be defined ** in toolkit specific descendants 
+    virtual void bbCreateDialogWindow()
+    {
+      bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
+    }
+    //==================================================================    
+
+ //==================================================================    
+    /// Callback for creating a Frame window 
+    /// ** Must be defined ** in toolkit specific descendants 
+    virtual void bbCreateFrameWindow()
+    {
+      bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
+    }
+    //==================================================================    
+    //==================================================================
+    /// Overloaded processing method for WidgetBlackBoxes
+    virtual void bbProcess();
+    //==================================================================
+
+    //==================================================================
+    /// Hides the WidgetBlackBoxWindow associated to the box (if exists)
+    void bbHideWindow();
+    /// Closes (destroys) the WidgetBlackBoxWindow associated to the box 
+    /// (if exists)
+    void bbCloseWindow();
+    //==================================================================
+
+    
+    //==================================================================
+    //   virtual void InitWindowManagerIfNeeded();
+    virtual void IncNbWindowsAlive() {}
+    virtual void DecNbWindowsAlive() {}
+    virtual int  GetNbWindowsAlive() { return 0; }
+    virtual bool IsSomeWindowAlive() { return false; }
+    
+    virtual void IncNbWindowsShown() {}
+    virtual void DecNbWindowsShown() {}
+    virtual int  GetNbWindowsShown() { return 0; }
+    virtual bool IsSomeWindowShown() { return false; }
+    //==================================================================
+
+
+  private:
+    /// friendship
+    friend class WidgetBlackBoxWindow<W>;
+    //    friend class WidgetBlackBoxWidgetEventHandler;
+
+    /// The WidgetBlackBoxWindow associated to the box
+    Window* bbmWindow;
+
+
+    void bbInitAttributes();
+
+  };
+  //=================================================================
+
+  //======================================================================
+  /// Defines the bbUserCreateWidget method
+#define BBTK_CREATE_WIDGET(CALLBACK)                                   \
+  public:                                                              \
+  inline void bbUserCreateWidget(Widget* parent)                       \
+  {                                                                    \
+    bbtkDebugMessageInc("kw",1,"**> Creating widget for ["             \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+    CALLBACK(parent);                                                  \
+    bbtkDebugMessageInc("kw",1,"<** Creating widget for ["             \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+  }
+  
+  //======================================================================
+
+  //======================================================================
+  /// Defines the bbUserOnShow method
+#define BBTK_ON_SHOW_WIDGET(CALLBACK)                                  \
+  public:                                                              \
+  inline void bbUserOnShow()                                   \
+  {                                                                    \
+    bbtkDebugMessageInc("wx",1,"**> Showing ["         \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+    CALLBACK();                                                                \
+    bbtkDebugMessageInc("wx",1,"<** Showing ["         \
+                       <<bbGetFullName()<<"]"<<std::endl);             \
+  }
+  
+  //======================================================================
+
+  //=================================================================
+  // WidgetBlackBoxDescriptor declaration
+  BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
+  BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
+  // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
+  BBTK_CATEGORY("widget");
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
+            "Title of the window (*)",
+            std::string);
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
+            "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
+            "Height of the window (*)",int);
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
+            "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
+            "Any signal received hides the window (*)",Void);
+  BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
+            "Any signal received closes the window (*)",Void);
+  typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
+  BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
+  BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
+  //=================================================================
+
+
+
+
+
+
+
+
+
+} //namespace bbtk
+
+// template code inclusion
+#include "bbtkWidgetBlackBox.txx"
+
+// WidgetBlackBoxWindow interface + code inclusion
+#include "bbtkWidgetBlackBoxWindow.h"
+
+#endif  //__bbtkWidgetBlackBox_h__