]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWidgetBlackBox.txx
Feature #1774
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.txx
index 2aeb1783de0d188113b47349f13e75b8da9b3da7..6f2e8a6de5998b189b36de9868744d7cfa970af7 100644 (file)
@@ -1,32 +1,40 @@
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  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.
+ # ------------------------------------------------------------------------ */
+
+
 /*=========================================================================                                                                               
   Program:   bbtk
   Module:    $RCSfile: bbtkWidgetBlackBox.txx,v $
   Language:  C++
-  Date:      $Date: 2009/05/19 10:19:23 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2012/11/16 08:49:01 $
+  Version:   $Revision: 1.7 $
 =========================================================================*/
 
-/* ---------------------------------------------------------------------
-
-* 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.
-* ------------------------------------------------------------------------ */                                                                         
+
+
 /**
  *  \file 
  *  \brief 
@@ -34,7 +42,7 @@
 
 
  
-#include "bbtkWidgetBlackBoxWindow.h"
+//#include "bbtkWidgetBlackBoxWindow.h"
 #include "bbtkBlackBoxOutputConnector.h"
 
 
@@ -56,8 +64,8 @@ namespace bbtk
   template <class T>  
   void WidgetBlackBox<T>::bbUserSetDefaultValues()
   {
-    bbtkDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
-    bbmWindow = 0;
+    bbtkBlackBoxDebugMessage("widget",9,"WidgetBlackBox::bbUserSetDefaultValues()"<<std::endl);
+    //    bbmWindow = 0;
     bbSetInputWinTitle(bbGetName());
     bbSetInputWinWidth(800);
     bbSetInputWinHeight(800);
@@ -71,6 +79,7 @@ namespace bbtk
   template <class T>  
   void WidgetBlackBox<T>::bbUserInitializeProcessing()
   {
+    bbmShown = false;
   }
   //=========================================================================
 
@@ -78,18 +87,25 @@ namespace bbtk
   template <class T>  
   void WidgetBlackBox<T>::bbUserFinalizeProcessing()
   {
-    bbtkDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
+    /*
+    std::cout << "****** WidgetBlackBox<T>::bbUserFinalizeProcessing()"<<std::endl;
+    bbtkBlackBoxDebugMessage("widget",9,"==> WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
     if (bbGetWindow()) 
       {
+       bool shown = bbGetWindow()->bbIsShown();
+       bbGetWindow()->bbDestroy();
+       bbSetWindow(0);
+       
        if (GetUseCount()==0)
-         {
-           if (bbGetWindow()->bbIsShown()) DecNbWindowsShown();
+         {    
+           bbtkBlackBoxDebugMessage("widget",9,"**** HERE use count == 0"<<std::endl);
+           if (shown) DecNbWindowsShown();
            DecNbWindowsAlive();
          }
-       bbGetWindow()->bbDestroy();
-       bbSetWindow(0);
+
       }
-    bbtkDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
+    bbtkBlackBoxDebugMessage("widget",9,"<== WidgetBlackBox::bbUserFinalizeProcessing() ["<<bbGetFullName()<<"]"<<std::endl);
+    */
   }
   //=========================================================================
   
@@ -117,16 +133,20 @@ namespace bbtk
     if ( ! bbIsOutputWidgetConnected() )
       {
        // create the Window if does not exist
-       if ( bbGetWindow() == 0)
+       if (!bbWindowIsCreated())
          {
-           bbtkDebugMessage("widget",2,
+           bbtkBlackBoxDebugMessage("widget",2,
                             "-> Creating the window"
                             <<std::endl);
+           // Reinitializing
+           bbSetShown(false);
+           bbmNestedWidgetBoxes.clear();
+           
            //      this->InitWindowManagerIfNeeded();
            // If is a Dialog requested
            if ( bbGetInputWinDialog() )
              {
-               bbtkDebugMessage("process",2,
+               bbtkBlackBoxDebugMessage("widget",2,
                                 "   Input WinDialog set to true : creating a Dialog"
                                 <<std::endl);
                this->bbCreateDialogWindow();
@@ -134,22 +154,28 @@ namespace bbtk
            // Input WinDialog set to false : creating a Frame
            else 
              {
-               bbtkDebugMessage("process",2,
+               bbtkBlackBoxDebugMessage("widget",2,
                                 "   Input WinDialog set to false : creating a Frame"
                                 <<std::endl);
                this->bbCreateFrameWindow();
              }
          }
+       /*
        // Show the window
        if ( !bbGetWindow() )
          {
            bbtkInternalError("Need to show the Window of widget "<<bbGetName()
                              <<" however was not created by apropriate cb");
          }
-       bbtkDebugMessage("widget",2,
+       */
+
+       /*
+       bbtkBlackBoxDebugMessage("widget",2,
                         "-> Showing the window"
                         <<std::endl);
-       bbGetWindow()->bbShow(); 
+       //      bbGetWindow()->bbShow(); 
+       this->bbShowWindow();
+       */
       }                  
     //   
   }
@@ -162,6 +188,9 @@ namespace bbtk
   WidgetBlackBox<T>::bbCreateWidgetOfInput
   (const std::string& in, typename WidgetBlackBox<T>::WidgetPointer parent)
   {
+    bbtkBlackBoxDebugMessage("widget",2,"bbCreateWidgetOfInput("
+                            <<in<<","<<parent<<")"
+                            <<std::endl);
     Widget* w = 0;
     // If input is connected 
     BlackBoxInputConnector* c = bbGetInputConnectorMap().find(in)->second ;
@@ -180,6 +209,8 @@ namespace bbtk
        wfrom->bbUserCreateWidget(parent);
        // Get the widget created
        w = wfrom->bbGetOutputWidget();
+       // Insert the box into the NestedWidgetBoxes list
+       bbmNestedWidgetBoxes.push_back(from);
       }
     return w;
   }
@@ -193,16 +224,52 @@ namespace bbtk
   }
   //==================================================================
 
+  //==================================================================
+  template <class T>  
+  void WidgetBlackBox<T>::bbSetShown(bool b)
+  {
+    if (b==bbmShown) return;
+
+    bbtkBlackBoxDebugMessage("widget",5,"WidgetBlackBox::bbSetShown("
+                            <<b<<")"
+                            <<std::endl);
+    
+    bbmShown = b;
+    if (b)
+      {
+       this->bbUserOnShow();
+     }
+    // Have to propagate to nested widgets
+    std::vector<BlackBox::WeakPointer>::const_iterator i;
+    for (i =bbmNestedWidgetBoxes.begin();
+        i!=bbmNestedWidgetBoxes.end();
+        ++i)
+      {
+       if (!i->expired()) i->lock()->bbSetShown(b);
+      }
+        
+  }
+  //==================================================================
+
+  //==================================================================
+   template <class T>  
+   bool WidgetBlackBox<T>::bbIsShown()
+  {
+    return bbmShown;
+  }
+  //==================================================================
+  /*
  //==================================================================
   template <class T>  
    void WidgetBlackBox<T>::bbShowWindow()
   {
-    bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbShowWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
     if (bbGetWindow()!=0) bbGetWindow()->bbShow();
 
-    bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbShowWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbShowWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
   }
   //==================================================================
@@ -211,12 +278,12 @@ namespace bbtk
   template <class T>  
    void WidgetBlackBox<T>::bbHideWindow()
   {
-    bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbHideWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
     if (bbGetWindow()!=0) bbGetWindow()->bbHide();
 
-    bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbHideWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbHideWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
   }
   //==================================================================
@@ -226,12 +293,12 @@ namespace bbtk
   template <class T>  
   void WidgetBlackBox<T>::bbCloseWindow()
   {
-    bbtkDebugMessageInc("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"=> WidgetBlackBox::bbCloseWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
 
     if (bbGetWindow()!=0) bbGetWindow()->bbDestroy();
 
-    bbtkDebugMessageDec("widget",2,"<= WidgetBlackBox::bbCloseWindow() ["
+    bbtkBlackBoxDebugMessage("widget",1,"<= WidgetBlackBox::bbCloseWindow() ["
                        <<bbGetFullName()<<"]"<<std::endl);
   }
   //==================================================================
@@ -264,7 +331,7 @@ namespace bbtk
     return false;
   }
   //==================================================================
-
+  */
 
 }//namespace bbtk