]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
ce0f36b5c84c03f1a3c158b202b19b3f44d06c11
[bbtk.git] / packages / wx / src / bbwxRadioButton.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxRadioButton.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.10 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_WXWIDGETS_
43
44
45 #include "bbwxRadioButton.h"
46 #include "bbwxPackage.h"
47
48 #include <vector>
49
50 namespace bbwx
51 {
52     
53   
54   //--------------------------------------------------------------------------
55   // The widget created by the box 
56   class RadioButtonWidget : public wxPanel
57   {
58   public:
59     RadioButtonWidget( RadioButton* box, wxWindow *parent, 
60                       int In, 
61                       wxString title, 
62                       std::vector<wxString> lstIn );
63
64     ~RadioButtonWidget();
65
66     int GetValue();
67     void OnRadioButton(wxEvent& event);
68
69   private:
70     RadioButton      *mBox;
71     int              MAX_RADIOBUTTON;
72     wxRadioButton    *mwxRadioButton[10];
73   };
74   
75   //------------------------------------------------------------------------
76   //------------------------------------------------------------------------
77   //------------------------------------------------------------------------
78
79   //-------------------------------------------------------------------------
80   RadioButtonWidget::RadioButtonWidget( RadioButton* box,
81                wxWindow *parent,
82                int In,
83                wxString title,
84                std::vector<wxString> lstIn )
85     :
86     wxPanel( parent, -1) ,
87     mBox(box)
88   {
89     wxPanel *panel      = this;
90     MAX_RADIOBUTTON = lstIn.size();
91     int i;
92     long style=wxRB_GROUP;
93     for (i=0;i<MAX_RADIOBUTTON; i++)
94     {
95            if ( lstIn[i]!=_T(""))
96            {
97     //---------------------------------------------------------------------
98     // 1) Creation of the components of the widget
99     // Any top level sub-widget must have the panel returned by panel
100     // for parent
101               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
102               style=0;
103               if (In==i)
104               {
105                       mwxRadioButton[i]->SetValue(true);
106               } 
107               else 
108               {
109                       mwxRadioButton[i]->SetValue(false);
110               }
111                Connect( mwxRadioButton[i]->GetId(),  
112                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
113                   (wxObjectEventFunction) 
114                   (void (wxPanel::*)(wxEvent&))
115                   &RadioButtonWidget::OnRadioButton ); 
116            } 
117            else 
118            {
119                mwxRadioButton[i]=NULL;
120            }
121     }
122     
123     //---------------------------------------------------------------------
124     // 2) Insertion of the components in the window
125     
126     // We use a FlexGridSizer
127     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
128     if (title!=_T(""))
129     {
130            sizer->Add( new wxStaticText(panel,-1, title ) ); 
131     }
132     for (i=0;i<MAX_RADIOBUTTON; i++)
133     {
134        if (mwxRadioButton[i]!=NULL)
135        {
136           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
137        }
138     }
139     sizer->AddGrowableCol(0);
140     panel->SetSizer(sizer);
141
142 //    panel->SetAutoLayout(true);
143 //    panel->Layout();
144
145   }
146   //-------------------------------------------------------------------------
147   
148   RadioButtonWidget::~RadioButtonWidget()
149   {
150   }
151
152   //-------------------------------------------------------------------------
153  
154   int RadioButtonWidget::GetValue()
155   { 
156     int result=-1;
157     int i;
158     for (i=0;i<MAX_RADIOBUTTON; i++)
159       {
160         if ( mwxRadioButton[i]!=NULL)
161           {
162             if (mwxRadioButton[i]->GetValue()==true)
163               {
164                 result=i;
165               }
166           }
167       }
168     return result;
169   }
170
171   //--------------------------------------------------------------------------
172   void RadioButtonWidget::OnRadioButton(wxEvent& event)
173   {
174     mBox->bbSetOutputOut( GetValue() );
175     mBox->bbSetInputIn( GetValue() );
176     mBox->bbSignalOutputModification("Out");
177   }
178
179   //--------------------------------------------------------------------------
180   //-------------------------------------------------------------------------
181   //--------------------------------------------------------------------------
182   //--------------------------------------------------------------------------
183
184   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
185   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
186
187   
188         //-----------------------------------------------------------------     
189         void RadioButton::bbUserSetDefaultValues()
190         {
191                 bbSetInputIn(0);
192                 bbSetOutputOut( bbGetInputIn() );
193                 bbSetInputIn0("");
194                 bbSetInputIn1("");
195                 bbSetInputIn2("");
196                 bbSetInputIn3("");
197                 bbSetInputIn4("");
198                 bbSetInputIn5("");
199                 bbSetInputIn6("");
200                 bbSetInputIn7("");
201                 bbSetInputIn8("");
202                 bbSetInputIn9("");              
203         }
204         
205         //-----------------------------------------------------------------     
206         void RadioButton::bbUserInitializeProcessing()
207         {
208         }
209         
210         //-----------------------------------------------------------------     
211         void RadioButton::bbUserFinalizeProcessing()
212         {
213         }
214         
215   void RadioButton::Process() 
216   { 
217     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
218     bbtkDebugDecTab("Core",9);
219   }
220
221   /**
222    * \brief  Create wxWidget . 
223    *
224    *
225    */ 
226  void RadioButton::CreateWidget(wxWindow* parent)
227   {
228
229     std::vector<wxString> lstIn;
230     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
231     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
232     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
233     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
234     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
235     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
236     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
237     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
238     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
239     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
240
241     RadioButtonWidget *w = new RadioButtonWidget(
242                          this,
243 //                         bbGetWxParent(),
244                                                         parent, 
245                          bbGetInputIn() ,
246                          bbtk::std2wx(bbGetInputTitle()),
247                          lstIn );
248
249    bbSetOutputOut( bbGetInputIn() );
250    bbSetOutputWidget( w );
251
252   }
253
254
255
256
257 }//namespace bbtk
258
259 #endif // _USE_WXWIDGETS_ 
260