]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxCheckBox.cxx
Add CheckBox
[bbtk.git] / packages / wx / src / bbwxCheckBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxCheckBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/01/13 09:57:13 $
6   Version:   $Revision: 1.1 $
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 Short description in one line
34  *
35  * Long 
36  * description
37  *  
38  */
39
40 #ifdef _USE_WXWIDGETS_
41
42 #include "bbwxCheckBox.h"
43 #include "bbwxPackage.h"
44 #include "bbtkUtilities.h"
45
46 namespace bbwx
47 {
48   //--------------------------------------------------------------------------
49   // The widget created by the box 
50   class CheckBoxWidget : public wxPanel 
51   {
52   public:
53     /// Ctor with the two first params the parent window and the creator box
54     /// which must be passed to the WxBlackBoxWidget constructor.
55     /// The other params initialize the widget 
56     CheckBoxWidget(CheckBox* box, wxWindow *parent,
57                  wxString title,
58                  bool value
59                  );
60     /// Dtor
61     ~CheckBoxWidget();
62     /// Events callbacks
63     /// Called when the box is clicked
64     void OnCheckBoxClick(wxCommandEvent& event);
65
66     // Accessors
67     bool GetValue() { return mwxCheckBox->GetValue(); }
68     void SetValue(bool val);
69     // Update the texts which display the min/max/current values of the slider
70         
71   private:
72     CheckBox*    mBox;
73     wxCheckBox   *mwxCheckBox;
74
75     bool       val;
76   };
77   //------------------------------------------------------------------------
78   //------------------------------------------------------------------------
79   //------------------------------------------------------------------------
80
81   
82     
83   //-------------------------------------------------------------------------
84   CheckBoxWidget::CheckBoxWidget(CheckBox* box, wxWindow *parent,
85                              wxString title,
86                              bool value)
87     :  
88     wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
89     mBox(box),
90     val(value)
91   {
92     wxPanel * panel = this;
93     int sizeX, sizeY;
94     
95     sizeX = sizeY = -1; // just to see JPR
96     
97     
98
99     //---------------------------------------------------------------------
100     // 1) Creation of the components of the widget
101     // Any top level sub-widget must have the panel returned by panel
102     // for parent
103     mwxCheckBox = new wxCheckBox( panel, 
104                               -1, 
105                               title,
106                               wxDefaultPosition, 
107                               //wxSize(sizeX,sizeY),
108                               wxDefaultSize, 
109                               wxCHK_2STATE | wxALIGN_RIGHT);      
110
111     mwxCheckBox->SetValue(value);
112
113     // Connecting events to callbacks
114     Connect( mwxCheckBox->GetId(), 
115              wxEVT_COMMAND_CHECKBOX_CLICKED, 
116              (wxObjectEventFunction) 
117              (void (wxPanel::*)(wxScrollEvent&))
118              &CheckBoxWidget::OnCheckBoxClick);
119               
120     //---------------------------------------------------------------------
121
122     //---------------------------------------------------------------------
123     // 2) Insertion of the components in the window
124     
125     // We use a FlexGridSizer
126     wxFlexGridSizer *sizer;
127    sizer        = new wxFlexGridSizer(1);
128     // Insert the sizer in the main panel and refresh the layout
129     panel->SetSizer(sizer);
130   }
131   //-------------------------------------------------------------------------
132   
133
134   //-------------------------------------------------------------------------
135   CheckBoxWidget::~CheckBoxWidget()
136   {
137   }
138   //-------------------------------------------------------------------------
139
140
141   //-------------------------------------------------------------------------
142
143
144
145   //-------------------------------------------------------------------------
146   void CheckBoxWidget::OnCheckBoxClick(wxCommandEvent& event)
147   {
148     // When user clicks the box 
149     // we update the output of the box
150     mBox->bbSetOutputOut( mwxCheckBox->GetValue() );
151     mBox->bbSetInputIn( mwxCheckBox->GetValue() );
152     // and signal that the output has changed
153     mBox->bbSignalOutputModification(std::string("Out"));
154   }
155   //-------------------------------------------------------------------------
156
157   //-------------------------------------------------------------------------
158   
159
160   //-------------------------------------------------------------------------
161   void CheckBoxWidget::SetValue(bool value)
162   {
163     this->val = value;
164     mwxCheckBox->SetValue(value);
165   }
166   //-------------------------------------------------------------------------
167
168  
169   //--------------------------------------------------------------------------
170   //-------------------------------------------------------------------------
171   // WxBlackBox implementation
172   //--------------------------------------------------------------------------
173   //--------------------------------------------------------------------------
174
175   //--------------------------------------------------------------------------
176   BBTK_BLACK_BOX_IMPLEMENTATION(CheckBox,bbtk::WxBlackBox);
177   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CheckBox);
178   
179   //--------------------------------------------------------------------------
180   void CheckBox::bbUserConstructor() 
181   { 
182     bbSetInputIn(false);
183     bbSetOutputOut(false);
184   }
185   
186   //--------------------------------------------------------------------------
187   void CheckBox::Process() 
188   {
189     bbSetOutputOut( bbGetInputIn() );
190   }
191
192   void CheckBox::CreateWidget(wxWindow* parent)
193   {
194    
195     CheckBoxWidget *w =  new CheckBoxWidget(this, 
196                                         parent, 
197                                         bbtk::std2wx( bbGetInputTitle() ),
198                                         bbGetInputIn() 
199                                         );
200     bbSetOutputWidget( w );
201   }
202   
203
204 } //namespace bbwx
205
206 #endif // _USE_WXWIDGETS_ 
207
208