]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxColourSelectorButton.cxx
Windows compilation
[bbtk.git] / packages / wx / src / bbwxColourSelectorButton.cxx
index 9328d6ae5405c86ce1d40c7fa8261d40448fc882..f61de883dbe95be403088ca616044c4ae026deda 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxColourSelectorButton.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/11/24 15:45:51 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2008/12/12 08:55:23 $
+  Version:   $Revision: 1.9 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 #include "bbwxColourSelectorButton.h"
 #include "bbwxPackage.h"
 
+#include <wx/clrpicker.h>
 
 namespace bbwx
 {
+//-------------------------------------------------------------------------
+class wxColourPickerCtrlWidget :public wxPanel
+{
+
+public:
+   wxColourPickerCtrlWidget( ColourSelectorButton* box,
+                             wxWindow *parent,
+                             unsigned char  cr,
+                             unsigned char  cg,
+                             unsigned char  cb  );
+
+   ~wxColourPickerCtrlWidget();
+   void OnColorChange(wxColourPickerEvent& e);
+   void UpdateBox();
+private:
+   wxColourPickerCtrl *picker;
+   ColourSelectorButton *mBox;
+};
+//-------------------------------------------------------------------------
 
 //-------------------------------------------------------------------------
 wxColourPickerCtrlWidget::wxColourPickerCtrlWidget(    ColourSelectorButton* box,
@@ -118,15 +138,29 @@ void wxColourPickerCtrlWidget::UpdateBox()
   
   void ColourSelectorButton::bbUserConstructor() 
   { 
+  // Default input value
     bbSetInputIn("1 1 1");
+  // Initial output value = the same than input
+    bbSetOutputOut("1 1 1");
+    // IMPORTANT : Initialize output widget to null pointer to test it after 
+    bbSetOutputWidget(0);
   }
 
 
   void ColourSelectorButton::Process() 
   { 
-    bbtkDebugMessageInc("Process",9,"ColourSelectorButton::Process()"<<std::endl);
-      pickerWidget->UpdateBox();
-    bbtkDebugDecTab("Process",9);
+  // The widget may not be created : have to test it before using it
+    wxColourPickerCtrlWidget* w = ( wxColourPickerCtrlWidget* )bbGetOutputWidget();
+    if (w) 
+      {
+       w->UpdateBox();
+      }
+    else 
+      {
+      // If widget does not exist yet you have to update the output value according 
+      // to the input (which may have changed if the user set it)
+       bbSetOutputOut(bbGetInputIn());
+      }
   }
 
 
@@ -137,7 +171,6 @@ void wxColourPickerCtrlWidget::UpdateBox()
    */
   void ColourSelectorButton::CreateWidget(wxWindow* parent)
   {
-    bbtkDebugMessage("Process",9,"=> ColourSelectorButton::CreateWidget()"<<std::endl);
     
     float r,g,b;
     sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
@@ -146,13 +179,11 @@ void wxColourPickerCtrlWidget::UpdateBox()
     cg = (unsigned char)(255.*g);
     cb = (unsigned char)(255.*b);
 
-    pickerWidget = new wxColourPickerCtrlWidget(this, //bbGetWxParent() , 
-                                                                                               parent,
-                                                                                               cr , cg , cb );    
+    wxColourPickerCtrlWidget* w = new wxColourPickerCtrlWidget(this, //bbGetWxParent() , 
+                                                               parent,
+                                                               cr , cg , cb );    
     
-    bbtkDebugMessage("Process",9,"<= ColourSelectorButton::CreateWidget()"<<std::endl);
-
-    bbSetOutputWidget( pickerWidget );
+    bbSetOutputWidget( w );
   }