]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxCheckBox.cxx
28c0ec9883aafa2195fe498ef13606d24cd75580
[bbtk.git] / packages / wx / src / bbwxCheckBox.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxCheckBox.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.5 $
34 =========================================================================*/
35
36 /* ---------------------------------------------------------------------
37
38 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
39 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
40 *
41 *  This software is governed by the CeCILL-B license under French law and 
42 *  abiding by the rules of distribution of free software. You can  use, 
43 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
44 *  license as circulated by CEA, CNRS and INRIA at the following URL 
45 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
46 *  or in the file LICENSE.txt.
47 *
48 *  As a counterpart to the access to the source code and  rights to copy,
49 *  modify and redistribute granted by the license, users are provided only
50 *  with a limited warranty  and the software's author,  the holder of the
51 *  economic rights,  and the successive licensors  have only  limited
52 *  liability. 
53 *
54 *  The fact that you are presently reading this means that you have had
55 *  knowledge of the CeCILL-B license and that you accept its terms.
56 * ------------------------------------------------------------------------ */                                                                         
57
58 /**
59  * \file 
60  * \brief Short description in one line
61  *
62  * Long 
63  * description
64  *  
65  */
66
67 #ifdef _USE_WXWIDGETS_
68
69 #include "bbwxCheckBox.h"
70 #include "bbwxPackage.h"
71 #include "bbtkUtilities.h"
72
73 namespace bbwx
74 {
75   //--------------------------------------------------------------------------
76   // The widget created by the box 
77   class CheckBoxWidget : public wxPanel 
78   {
79   public:
80     /// Ctor with the two first params the parent window and the creator box
81     /// which must be passed to the WxBlackBoxWidget constructor.
82     /// The other params initialize the widget 
83     CheckBoxWidget(CheckBox* box, wxWindow *parent,
84                  wxString title,
85                  bool value, int reactiveOnKeyStroke
86                  );
87     /// Dtor
88     ~CheckBoxWidget();
89     /// Events callbacks
90     /// Called when the box is clicked
91     void OnCheckBoxClick(wxCommandEvent& event);
92
93     // Accessors
94     bool GetValue() { return mwxCheckBox->GetValue(); }
95     void SetValue(bool val);
96     // Update the texts which display the min/max/current values of the slider
97         
98   private:
99     CheckBox*    mBox;
100     wxCheckBox   *mwxCheckBox;
101     int          _reactiveOnKeyStroke;
102     bool         val;
103   };
104   //------------------------------------------------------------------------
105   //------------------------------------------------------------------------
106   //------------------------------------------------------------------------
107
108   
109     
110   //-------------------------------------------------------------------------
111   CheckBoxWidget::CheckBoxWidget(CheckBox* box, wxWindow *parent,
112                              wxString title,
113                              bool value, int reactiveOnKeyStroke)
114     :  
115     wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
116     mBox(box),
117     _reactiveOnKeyStroke(reactiveOnKeyStroke),
118     val(value)
119   {
120     wxPanel * panel = this;
121     int sizeX, sizeY;
122     
123     sizeX = sizeY = -1; // just to see JPR
124     
125     
126
127     //---------------------------------------------------------------------
128     // 1) Creation of the components of the widget
129     // Any top level sub-widget must have the panel returned by panel
130     // for parent
131     mwxCheckBox = new wxCheckBox( panel, 
132                               -1, 
133                               title,
134                               wxDefaultPosition, 
135                               //wxSize(sizeX,sizeY),
136                               wxDefaultSize, 
137                               wxCHK_2STATE | wxALIGN_RIGHT);      
138
139     mwxCheckBox->SetValue(value);
140
141     // Connecting events to callbacks
142     Connect( mwxCheckBox->GetId(), 
143              wxEVT_COMMAND_CHECKBOX_CLICKED, 
144              (wxObjectEventFunction) 
145              (void (wxPanel::*)(wxScrollEvent&))
146              &CheckBoxWidget::OnCheckBoxClick);
147               
148     //---------------------------------------------------------------------
149
150     //---------------------------------------------------------------------
151     // 2) Insertion of the components in the window
152     
153     // We use a FlexGridSizer
154     wxFlexGridSizer *sizer;
155    sizer        = new wxFlexGridSizer(1);
156     // Insert the sizer in the main panel and refresh the layout
157     panel->SetSizer(sizer);
158   }
159   //-------------------------------------------------------------------------
160   
161
162   //-------------------------------------------------------------------------
163   CheckBoxWidget::~CheckBoxWidget()
164   {
165   }
166   //-------------------------------------------------------------------------
167
168
169   //-------------------------------------------------------------------------
170
171
172
173   //-------------------------------------------------------------------------
174   void CheckBoxWidget::OnCheckBoxClick(wxCommandEvent& event)
175   {
176           // When user clicks the box 
177           // we update the output of the box
178           mBox->bbSetOutputOut( mwxCheckBox->GetValue() );
179           mBox->bbSetInputIn( mwxCheckBox->GetValue() );
180           // and signal that the output has changed
181           //if(_reactiveOnKeyStroke==1){
182           mBox->bbSignalOutputModification(std::string("Out"));
183           //}
184   }
185   //-------------------------------------------------------------------------
186
187   //-------------------------------------------------------------------------
188   
189
190   //-------------------------------------------------------------------------
191   void CheckBoxWidget::SetValue(bool value)
192   {
193     this->val = value;
194     mwxCheckBox->SetValue(value);
195   }
196   //-------------------------------------------------------------------------
197
198  
199   //--------------------------------------------------------------------------
200   //-------------------------------------------------------------------------
201   // WxBlackBox implementation
202   //--------------------------------------------------------------------------
203   //--------------------------------------------------------------------------
204
205   //--------------------------------------------------------------------------
206   BBTK_BLACK_BOX_IMPLEMENTATION(CheckBox,bbtk::WxBlackBox);
207   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CheckBox);
208   
209
210         //-----------------------------------------------------------------     
211         void CheckBox::bbUserSetDefaultValues()
212         {
213                 bbSetInputIn(false);
214                 bbSetOutputOut(false);
215                 bbSetInputReactiveOnKeystroke(1);
216         }
217         
218         //-----------------------------------------------------------------     
219         void CheckBox::bbUserInitializeProcessing()
220         {
221         }
222         
223         //-----------------------------------------------------------------     
224         void CheckBox::bbUserFinalizeProcessing()
225         {
226         }       
227         
228         
229   //--------------------------------------------------------------------------
230   void CheckBox::Process() 
231   {
232     bbSetOutputOut( bbGetInputIn() );
233   }
234
235   void CheckBox::CreateWidget(wxWindow* parent)
236   {
237    
238     CheckBoxWidget *w =  new CheckBoxWidget(this, 
239                                         parent, 
240                                         bbtk::std2wx( bbGetInputTitle() ),
241                                         bbGetInputIn(),
242                                         bbGetInputReactiveOnKeystroke()
243                                         );
244     bbSetOutputWidget( w );
245 //GetName 
246                 std::cout<<"TESTING.... DELETE ME!!!!! bbwxCheckBox.cxx ---- PARENT  :  "<<bbtk::wx2std(parent->GetName())<<std::endl;
247                 std::cout<<"TESTING.... DELETE ME!!!!! bbwxCheckBox.cxx"<<std::endl;
248   }
249   
250
251 } //namespace bbwx
252
253 #endif // _USE_WXWIDGETS_ 
254
255