]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxCheckBox.cxx
9770d6cb11c8eb736fa5514872fccbfe8447883c
[bbtk.git] / packages / wx / src / bbwxCheckBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxCheckBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/07/06 12:30:03 $
6   Version:   $Revision: 1.4 $
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, int reactiveOnKeyStroke
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     int          _reactiveOnKeyStroke;
75     bool         val;
76   };
77   //------------------------------------------------------------------------
78   //------------------------------------------------------------------------
79   //------------------------------------------------------------------------
80
81   
82     
83   //-------------------------------------------------------------------------
84   CheckBoxWidget::CheckBoxWidget(CheckBox* box, wxWindow *parent,
85                              wxString title,
86                              bool value, int reactiveOnKeyStroke)
87     :  
88     wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
89     mBox(box),
90     _reactiveOnKeyStroke(reactiveOnKeyStroke),
91     val(value)
92   {
93     wxPanel * panel = this;
94     int sizeX, sizeY;
95     
96     sizeX = sizeY = -1; // just to see JPR
97     
98     
99
100     //---------------------------------------------------------------------
101     // 1) Creation of the components of the widget
102     // Any top level sub-widget must have the panel returned by panel
103     // for parent
104     mwxCheckBox = new wxCheckBox( panel, 
105                               -1, 
106                               title,
107                               wxDefaultPosition, 
108                               //wxSize(sizeX,sizeY),
109                               wxDefaultSize, 
110                               wxCHK_2STATE | wxALIGN_RIGHT);      
111
112     mwxCheckBox->SetValue(value);
113
114     // Connecting events to callbacks
115     Connect( mwxCheckBox->GetId(), 
116              wxEVT_COMMAND_CHECKBOX_CLICKED, 
117              (wxObjectEventFunction) 
118              (void (wxPanel::*)(wxScrollEvent&))
119              &CheckBoxWidget::OnCheckBoxClick);
120               
121     //---------------------------------------------------------------------
122
123     //---------------------------------------------------------------------
124     // 2) Insertion of the components in the window
125     
126     // We use a FlexGridSizer
127     wxFlexGridSizer *sizer;
128    sizer        = new wxFlexGridSizer(1);
129     // Insert the sizer in the main panel and refresh the layout
130     panel->SetSizer(sizer);
131   }
132   //-------------------------------------------------------------------------
133   
134
135   //-------------------------------------------------------------------------
136   CheckBoxWidget::~CheckBoxWidget()
137   {
138   }
139   //-------------------------------------------------------------------------
140
141
142   //-------------------------------------------------------------------------
143
144
145
146   //-------------------------------------------------------------------------
147   void CheckBoxWidget::OnCheckBoxClick(wxCommandEvent& event)
148   {
149           // When user clicks the box 
150           // we update the output of the box
151           mBox->bbSetOutputOut( mwxCheckBox->GetValue() );
152           mBox->bbSetInputIn( mwxCheckBox->GetValue() );
153           // and signal that the output has changed
154           //if(_reactiveOnKeyStroke==1){
155           mBox->bbSignalOutputModification(std::string("Out"));
156           //}
157   }
158   //-------------------------------------------------------------------------
159
160   //-------------------------------------------------------------------------
161   
162
163   //-------------------------------------------------------------------------
164   void CheckBoxWidget::SetValue(bool value)
165   {
166     this->val = value;
167     mwxCheckBox->SetValue(value);
168   }
169   //-------------------------------------------------------------------------
170
171  
172   //--------------------------------------------------------------------------
173   //-------------------------------------------------------------------------
174   // WxBlackBox implementation
175   //--------------------------------------------------------------------------
176   //--------------------------------------------------------------------------
177
178   //--------------------------------------------------------------------------
179   BBTK_BLACK_BOX_IMPLEMENTATION(CheckBox,bbtk::WxBlackBox);
180   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CheckBox);
181   
182
183         //-----------------------------------------------------------------     
184         void CheckBox::bbUserSetDefaultValues()
185         {
186                 bbSetInputIn(false);
187                 bbSetOutputOut(false);
188                 bbSetInputReactiveOnKeystroke(1);
189         }
190         
191         //-----------------------------------------------------------------     
192         void CheckBox::bbUserInitializeProcessing()
193         {
194         }
195         
196         //-----------------------------------------------------------------     
197         void CheckBox::bbUserFinalizeProcessing()
198         {
199         }       
200         
201         
202   //--------------------------------------------------------------------------
203   void CheckBox::Process() 
204   {
205     bbSetOutputOut( bbGetInputIn() );
206   }
207
208   void CheckBox::CreateWidget(wxWindow* parent)
209   {
210    
211     CheckBoxWidget *w =  new CheckBoxWidget(this, 
212                                         parent, 
213                                         bbtk::std2wx( bbGetInputTitle() ),
214                                         bbGetInputIn(),
215                                         bbGetInputReactiveOnKeystroke()
216                                         );
217     bbSetOutputWidget( w );
218   }
219   
220
221 } //namespace bbwx
222
223 #endif // _USE_WXWIDGETS_ 
224
225