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