]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
*** empty log message ***
[bbtk.git] / packages / wx / src / bbwxRadioButton.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxRadioButton.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/12 08:55:24 $
6   Version:   $Revision: 1.8 $
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   void RadioButton::bbUserConstructor() 
184   { 
185     bbSetInputIn(0);
186     bbSetOutputOut( bbGetInputIn() );
187     bbSetInputIn0("");
188     bbSetInputIn1("");
189     bbSetInputIn2("");
190     bbSetInputIn3("");
191     bbSetInputIn4("");
192     bbSetInputIn5("");
193     bbSetInputIn6("");
194     bbSetInputIn7("");
195     bbSetInputIn8("");
196     bbSetInputIn9("");
197   }
198   
199
200   void RadioButton::Process() 
201   { 
202     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
203     bbtkDebugDecTab("Core",9);
204   }
205
206   /**
207    * \brief  Create wxWidget . 
208    *
209    *
210    */ 
211  void RadioButton::CreateWidget(wxWindow* parent)
212   {
213
214     std::vector<wxString> lstIn;
215     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
216     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
217     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
218     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
219     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
220     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
221     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
222     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
223     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
224     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
225
226     RadioButtonWidget *w = new RadioButtonWidget(
227                          this,
228 //                         bbGetWxParent(),
229                                                         parent, 
230                          bbGetInputIn() ,
231                          bbtk::std2wx(bbGetInputTitle()),
232                          lstIn );
233
234    bbSetOutputOut( bbGetInputIn() );
235    bbSetOutputWidget( w );
236
237   }
238
239
240
241
242 }//namespace bbtk
243
244 #endif // _USE_WXWIDGETS_ 
245