]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxRadioButton.cxx
re-add RadioButton
[bbtk.git] / packages / wx / src / bbwxRadioButton.cxx
diff --git a/packages/wx/src/bbwxRadioButton.cxx b/packages/wx/src/bbwxRadioButton.cxx
new file mode 100644 (file)
index 0000000..6527cfa
--- /dev/null
@@ -0,0 +1,205 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbwxRadioButton.cxx,v $
+  Language:  C++
+  Date:      $Date: 2008/02/11 14:47:12 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+/**
+ *  \file 
+ *  \brief 
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+
+#include "bbwxRadioButton.h"
+#include "bbwxPackage.h"
+
+#include <vector>
+
+namespace bbwx
+{
+  BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
+  
+  //-------------------------------------------------------------------------
+  RadioButtonWidget::RadioButtonWidget( RadioButton* box,
+               wxWindow *parent,
+               int In,
+               wxString title,
+               std::vector<wxString> lstIn )
+    :
+    wxPanel( parent, -1)
+  {
+
+    wxPanel *panel     = this;
+    MAX_RADIOBUTTON = lstIn.size();
+    int i;
+    long style=wxRB_GROUP;
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+    {
+          if ( lstIn[i]!=_T(""))
+          {
+    //---------------------------------------------------------------------
+    // 1) Creation of the components of the widget
+    // Any top level sub-widget must have the panel returned by panel
+    // for parent
+             mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
+             style=0;
+             if (In==i)
+             {
+                     mwxRadioButton[i]->SetValue(true);
+             } 
+             else 
+             {
+                     mwxRadioButton[i]->SetValue(false);
+             }
+              Connect( mwxRadioButton[i]->GetId(),  
+                   wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
+                  (wxObjectEventFunction) 
+                  (void (wxPanel::*)(wxEvent&))
+                  &RadioButtonWidget::OnRadioButton ); 
+          } 
+          else 
+          {
+              mwxRadioButton[i]=NULL;
+          }
+    }
+    
+    //---------------------------------------------------------------------
+    // 2) Insertion of the components in the window
+    
+    // We use a FlexGridSizer
+    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
+    if (title!=_T(""))
+    {
+          sizer->Add( new wxStaticText(panel,-1, title ) ); 
+    }
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+    {
+       if (mwxRadioButton[i]!=NULL)
+       {
+          sizer->Add( mwxRadioButton[i],1,wxGROW ); 
+       }
+    }
+    sizer->AddGrowableCol(0);
+
+    panel->SetSizer(sizer);
+    panel->SetAutoLayout(true);
+    panel->Layout();
+
+  }
+  //-------------------------------------------------------------------------
+  
+  RadioButtonWidget::~RadioButtonWidget()
+  {
+  }
+
+  //-------------------------------------------------------------------------
+  int RadioButtonWidget::GetValue()
+  { 
+    int result=-1;
+    int i;
+    for (i=0;i<MAX_RADIOBUTTON; i++)
+      {
+       if ( mwxRadioButton[i]!=NULL)
+         {
+           if (mwxRadioButton[i]->GetValue()==true)
+             {
+               result=i;
+             }
+         }
+      }
+    return result;
+  }
+
+  //--------------------------------------------------------------------------
+  void RadioButtonWidget::OnRadioButton(wxEvent& event)
+  {
+    mBox->bbSetOutputOut( GetValue() );
+    mBox->bbSetInputIn( GetValue() );
+    mBox->bbSignalOutputModification("Out");
+  }
+
+  //--------------------------------------------------------------------------
+  //-------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+
+
+  BBTK_USER_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
+
+
+  void RadioButton::bbUserConstructor() 
+  { 
+    bbSetInputIn(0);
+    bbSetOutputOut( bbGetInputIn() );
+    bbSetInputIn0("");
+    bbSetInputIn1("");
+    bbSetInputIn2("");
+    bbSetInputIn3("");
+    bbSetInputIn4("");
+    bbSetInputIn5("");
+    bbSetInputIn6("");
+    bbSetInputIn7("");
+    bbSetInputIn8("");
+    bbSetInputIn9("");
+  }
+  
+
+  void RadioButton::Process() 
+  { 
+    bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
+    bbtkDebugDecTab("Core",9);
+  }
+
+  /**
+   * \brief  Create wxWidget . 
+   *
+   *
+   */ 
+ void RadioButton::CreateWidget()
+  {
+
+    std::vector<wxString> lstIn;
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
+    lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
+
+    RadioButtonWidget *w = new RadioButtonWidget(
+                         this,
+                         bbGetWxParent(),
+                         bbGetInputIn() ,
+                         bbtk::std2wx(bbGetInputTitle()),
+                         lstIn );
+
+   bbSetOutputWidget( w );
+
+  }
+
+
+
+
+}//namespace bbtk
+
+#endif // _USE_WXWIDGETS_ 
+