]> 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/10/17 08:18:32 $
6   Version:   $Revision: 1.6 $
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   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
48   
49   //-------------------------------------------------------------------------
50   RadioButtonWidget::RadioButtonWidget( RadioButton* box,
51                wxWindow *parent,
52                int In,
53                wxString title,
54                std::vector<wxString> lstIn )
55     :
56     wxPanel( parent, -1) ,
57     mBox(box)
58   {
59     wxPanel *panel      = this;
60     MAX_RADIOBUTTON = lstIn.size();
61     int i;
62     long style=wxRB_GROUP;
63     for (i=0;i<MAX_RADIOBUTTON; i++)
64     {
65            if ( lstIn[i]!=_T(""))
66            {
67     //---------------------------------------------------------------------
68     // 1) Creation of the components of the widget
69     // Any top level sub-widget must have the panel returned by panel
70     // for parent
71               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
72               style=0;
73               if (In==i)
74               {
75                       mwxRadioButton[i]->SetValue(true);
76               } 
77               else 
78               {
79                       mwxRadioButton[i]->SetValue(false);
80               }
81                Connect( mwxRadioButton[i]->GetId(),  
82                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
83                   (wxObjectEventFunction) 
84                   (void (wxPanel::*)(wxEvent&))
85                   &RadioButtonWidget::OnRadioButton ); 
86            } 
87            else 
88            {
89                mwxRadioButton[i]=NULL;
90            }
91     }
92     
93     //---------------------------------------------------------------------
94     // 2) Insertion of the components in the window
95     
96     // We use a FlexGridSizer
97     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
98     if (title!=_T(""))
99     {
100            sizer->Add( new wxStaticText(panel,-1, title ) ); 
101     }
102     for (i=0;i<MAX_RADIOBUTTON; i++)
103     {
104        if (mwxRadioButton[i]!=NULL)
105        {
106           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
107        }
108     }
109     sizer->AddGrowableCol(0);
110     panel->SetSizer(sizer);
111
112 //    panel->SetAutoLayout(true);
113 //    panel->Layout();
114
115   }
116   //-------------------------------------------------------------------------
117   
118   RadioButtonWidget::~RadioButtonWidget()
119   {
120   }
121
122   //-------------------------------------------------------------------------
123  
124   int RadioButtonWidget::GetValue()
125   { 
126     int result=-1;
127     int i;
128     for (i=0;i<MAX_RADIOBUTTON; i++)
129       {
130         if ( mwxRadioButton[i]!=NULL)
131           {
132             if (mwxRadioButton[i]->GetValue()==true)
133               {
134                 result=i;
135               }
136           }
137       }
138     return result;
139   }
140
141   //--------------------------------------------------------------------------
142   void RadioButtonWidget::OnRadioButton(wxEvent& event)
143   {
144     mBox->bbSetOutputOut( GetValue() );
145     mBox->bbSetInputIn( GetValue() );
146     mBox->bbSignalOutputModification("Out");
147   }
148
149   //--------------------------------------------------------------------------
150   //-------------------------------------------------------------------------
151   //--------------------------------------------------------------------------
152   //--------------------------------------------------------------------------
153
154
155   BBTK_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
156
157
158   void RadioButton::bbUserConstructor() 
159   { 
160     bbSetInputIn(0);
161     bbSetOutputOut( bbGetInputIn() );
162     bbSetInputIn0("");
163     bbSetInputIn1("");
164     bbSetInputIn2("");
165     bbSetInputIn3("");
166     bbSetInputIn4("");
167     bbSetInputIn5("");
168     bbSetInputIn6("");
169     bbSetInputIn7("");
170     bbSetInputIn8("");
171     bbSetInputIn9("");
172   }
173   
174
175   void RadioButton::Process() 
176   { 
177     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
178     bbtkDebugDecTab("Core",9);
179   }
180
181   /**
182    * \brief  Create wxWidget . 
183    *
184    *
185    */ 
186  void RadioButton::CreateWidget()
187   {
188
189     std::vector<wxString> lstIn;
190     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
191     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
192     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
193     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
194     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
195     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
196     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
197     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
198     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
199     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
200
201     RadioButtonWidget *w = new RadioButtonWidget(
202                          this,
203                          bbGetWxParent(),
204                          bbGetInputIn() ,
205                          bbtk::std2wx(bbGetInputTitle()),
206                          lstIn );
207
208    bbSetOutputOut( bbGetInputIn() );
209    bbSetOutputWidget( w );
210
211   }
212
213
214
215
216 }//namespace bbtk
217
218 #endif // _USE_WXWIDGETS_ 
219