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