X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkWidgetBlackBox.h;fp=kernel%2Fsrc%2FbbtkWidgetBlackBox.h;h=deed3f707b09d000669ed33e50464ae90ef50729;hb=038dbbd7dd8b34107ec932a34170a4625368eb25;hp=0000000000000000000000000000000000000000;hpb=0721fc9ad9e666106a6554d9623ca8328a8bd822;p=bbtk.git diff --git a/kernel/src/bbtkWidgetBlackBox.h b/kernel/src/bbtkWidgetBlackBox.h new file mode 100644 index 0000000..deed3f7 --- /dev/null +++ b/kernel/src/bbtkWidgetBlackBox.h @@ -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 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 BBTK_EXPORT WidgetBlackBox : public bbtk::AtomicBlackBox + { + public: + // typedef WidgetTraits Traits; + typedef W Widget; + typedef Widget* WidgetPointer; + typedef WidgetBlackBoxWindow 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; + // 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 [" \ + < Showing [" \ + <()); + // 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::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__