]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxRadioButton.cxx
Some indentation
[bbtk.git] / packages / wx / src / bbwxRadioButton.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbwxRadioButton.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/02/14 20:26:54 $
7   Version:   $Revision: 1.3 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22
23
24 #ifdef _USE_WXWIDGETS_
25
26
27 #include "bbwxRadioButton.h"
28 #include "bbwxPackage.h"
29
30 #include <vector>
31
32 namespace bbwx
33 {
34   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,RadioButton);
35   
36   //-------------------------------------------------------------------------
37   RadioButtonWidget::RadioButtonWidget( RadioButton* box,
38                wxWindow *parent,
39                int In,
40                wxString title,
41                std::vector<wxString> lstIn )
42     :
43     wxPanel( parent, -1) ,
44     mBox(box)
45   {
46     wxPanel *panel      = this;
47     MAX_RADIOBUTTON = lstIn.size();
48     int i;
49     long style=wxRB_GROUP;
50     for (i=0;i<MAX_RADIOBUTTON; i++)
51     {
52            if ( lstIn[i]!=_T(""))
53            {
54     //---------------------------------------------------------------------
55     // 1) Creation of the components of the widget
56     // Any top level sub-widget must have the panel returned by panel
57     // for parent
58               mwxRadioButton[i] = new wxRadioButton( panel, -1, lstIn[i],wxDefaultPosition, wxDefaultSize, style);
59               style=0;
60               if (In==i)
61               {
62                       mwxRadioButton[i]->SetValue(true);
63               } 
64               else 
65               {
66                       mwxRadioButton[i]->SetValue(false);
67               }
68                Connect( mwxRadioButton[i]->GetId(),  
69                    wxEVT_COMMAND_RADIOBUTTON_SELECTED, 
70                   (wxObjectEventFunction) 
71                   (void (wxPanel::*)(wxEvent&))
72                   &RadioButtonWidget::OnRadioButton ); 
73            } 
74            else 
75            {
76                mwxRadioButton[i]=NULL;
77            }
78     }
79     
80     //---------------------------------------------------------------------
81     // 2) Insertion of the components in the window
82     
83     // We use a FlexGridSizer
84     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
85     if (title!=_T(""))
86     {
87            sizer->Add( new wxStaticText(panel,-1, title ) ); 
88     }
89     for (i=0;i<MAX_RADIOBUTTON; i++)
90     {
91        if (mwxRadioButton[i]!=NULL)
92        {
93           sizer->Add( mwxRadioButton[i],1,wxGROW ); 
94        }
95     }
96     sizer->AddGrowableCol(0);
97     panel->SetSizer(sizer);
98
99 //    panel->SetAutoLayout(true);
100 //    panel->Layout();
101
102   }
103   //-------------------------------------------------------------------------
104   
105   RadioButtonWidget::~RadioButtonWidget()
106   {
107   }
108
109   //-------------------------------------------------------------------------
110  
111   int RadioButtonWidget::GetValue()
112   { 
113     int result=-1;
114     int i;
115     for (i=0;i<MAX_RADIOBUTTON; i++)
116       {
117         if ( mwxRadioButton[i]!=NULL)
118           {
119             if (mwxRadioButton[i]->GetValue()==true)
120               {
121                 result=i;
122               }
123           }
124       }
125     return result;
126   }
127
128   //--------------------------------------------------------------------------
129   void RadioButtonWidget::OnRadioButton(wxEvent& event)
130   {
131     mBox->bbSetOutputOut( GetValue() );
132     mBox->bbSetInputIn( GetValue() );
133     mBox->bbSignalOutputModification("Out");
134   }
135
136   //--------------------------------------------------------------------------
137   //-------------------------------------------------------------------------
138   //--------------------------------------------------------------------------
139   //--------------------------------------------------------------------------
140
141
142   BBTK_USER_BLACK_BOX_IMPLEMENTATION(RadioButton,bbtk::WxBlackBox);
143
144
145   void RadioButton::bbUserConstructor() 
146   { 
147     bbSetInputIn(0);
148     bbSetOutputOut( bbGetInputIn() );
149     bbSetInputIn0("");
150     bbSetInputIn1("");
151     bbSetInputIn2("");
152     bbSetInputIn3("");
153     bbSetInputIn4("");
154     bbSetInputIn5("");
155     bbSetInputIn6("");
156     bbSetInputIn7("");
157     bbSetInputIn8("");
158     bbSetInputIn9("");
159   }
160   
161
162   void RadioButton::Process() 
163   { 
164     bbtkDebugMessageInc("Core",9,"RadioButton::Process()"<<std::endl);
165     bbtkDebugDecTab("Core",9);
166   }
167
168   /**
169    * \brief  Create wxWidget . 
170    *
171    *
172    */ 
173  void RadioButton::CreateWidget()
174   {
175
176     std::vector<wxString> lstIn;
177     lstIn.push_back( bbtk::std2wx(bbGetInputIn0()) );
178     lstIn.push_back( bbtk::std2wx(bbGetInputIn1()) );
179     lstIn.push_back( bbtk::std2wx(bbGetInputIn2()) );
180     lstIn.push_back( bbtk::std2wx(bbGetInputIn3()) );
181     lstIn.push_back( bbtk::std2wx(bbGetInputIn4()) );
182     lstIn.push_back( bbtk::std2wx(bbGetInputIn5()) );
183     lstIn.push_back( bbtk::std2wx(bbGetInputIn6()) );
184     lstIn.push_back( bbtk::std2wx(bbGetInputIn7()) );
185     lstIn.push_back( bbtk::std2wx(bbGetInputIn8()) );
186     lstIn.push_back( bbtk::std2wx(bbGetInputIn9()) );
187
188     RadioButtonWidget *w = new RadioButtonWidget(
189                          this,
190                          bbGetWxParent(),
191                          bbGetInputIn() ,
192                          bbtk::std2wx(bbGetInputTitle()),
193                          lstIn );
194
195    bbSetOutputWidget( w );
196
197   }
198
199
200
201
202 }//namespace bbtk
203
204 #endif // _USE_WXWIDGETS_ 
205