1 /*=========================================================================
3 Module: $RCSfile: bbwxCheckBox.cxx,v $
5 Date: $Date: 2010/05/03 08:06:14 $
6 Version: $Revision: 1.3 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
40 #ifdef _USE_WXWIDGETS_
42 #include "bbwxCheckBox.h"
43 #include "bbwxPackage.h"
44 #include "bbtkUtilities.h"
48 //--------------------------------------------------------------------------
49 // The widget created by the box
50 class CheckBoxWidget : public wxPanel
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,
58 bool value, int reactiveOnKeyStroke
63 /// Called when the box is clicked
64 void OnCheckBoxClick(wxCommandEvent& event);
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
73 wxCheckBox *mwxCheckBox;
74 int _reactiveOnKeyStroke;
77 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 //------------------------------------------------------------------------
83 //-------------------------------------------------------------------------
84 CheckBoxWidget::CheckBoxWidget(CheckBox* box, wxWindow *parent,
86 bool value, int reactiveOnKeyStroke)
88 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
91 _reactiveOnKeyStroke(reactiveOnKeyStroke)
93 wxPanel * panel = this;
96 sizeX = sizeY = -1; // just to see JPR
100 //---------------------------------------------------------------------
101 // 1) Creation of the components of the widget
102 // Any top level sub-widget must have the panel returned by panel
104 mwxCheckBox = new wxCheckBox( panel,
108 //wxSize(sizeX,sizeY),
110 wxCHK_2STATE | wxALIGN_RIGHT);
112 mwxCheckBox->SetValue(value);
114 // Connecting events to callbacks
115 Connect( mwxCheckBox->GetId(),
116 wxEVT_COMMAND_CHECKBOX_CLICKED,
117 (wxObjectEventFunction)
118 (void (wxPanel::*)(wxScrollEvent&))
119 &CheckBoxWidget::OnCheckBoxClick);
121 //---------------------------------------------------------------------
123 //---------------------------------------------------------------------
124 // 2) Insertion of the components in the window
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);
132 //-------------------------------------------------------------------------
135 //-------------------------------------------------------------------------
136 CheckBoxWidget::~CheckBoxWidget()
139 //-------------------------------------------------------------------------
142 //-------------------------------------------------------------------------
146 //-------------------------------------------------------------------------
147 void CheckBoxWidget::OnCheckBoxClick(wxCommandEvent& event)
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"));
158 //-------------------------------------------------------------------------
160 //-------------------------------------------------------------------------
163 //-------------------------------------------------------------------------
164 void CheckBoxWidget::SetValue(bool value)
167 mwxCheckBox->SetValue(value);
169 //-------------------------------------------------------------------------
172 //--------------------------------------------------------------------------
173 //-------------------------------------------------------------------------
174 // WxBlackBox implementation
175 //--------------------------------------------------------------------------
176 //--------------------------------------------------------------------------
178 //--------------------------------------------------------------------------
179 BBTK_BLACK_BOX_IMPLEMENTATION(CheckBox,bbtk::WxBlackBox);
180 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CheckBox);
183 //-----------------------------------------------------------------
184 void CheckBox::bbUserSetDefaultValues()
187 bbSetOutputOut(false);
188 bbSetInputReactiveOnKeystroke(1);
191 //-----------------------------------------------------------------
192 void CheckBox::bbUserInitializeProcessing()
196 //-----------------------------------------------------------------
197 void CheckBox::bbUserFinalizeProcessing()
202 //--------------------------------------------------------------------------
203 void CheckBox::Process()
205 bbSetOutputOut( bbGetInputIn() );
208 void CheckBox::CreateWidget(wxWindow* parent)
211 CheckBoxWidget *w = new CheckBoxWidget(this,
213 bbtk::std2wx( bbGetInputTitle() ),
215 bbGetInputReactiveOnKeystroke()
217 bbSetOutputWidget( w );
223 #endif // _USE_WXWIDGETS_