2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbwxSpinCtrl.h"
5 #include "bbwxPackage.h"
7 #include <wx/spinbutt.h>
8 #include <wx/spinctrl.h>
15 //--------------------------------------------------------------------------
16 // The widget created by the box
17 class SpinCtrlWidget : public wxPanel
20 /// Ctor with the two first params the parent window and the creator box
21 /// which must be passed to the WxBlackBoxWidget constructor.
22 /// The other params initialize the widget
23 SpinCtrlWidget(SpinCtrl* box, wxWindow *parent,
24 wxString title, int reactiveOnKeyStroke );
28 /// Called when the box is clicked
29 void OnSpinCtrlClick(wxCommandEvent& event);
32 bool GetValue() { return mwxSpinCtrl->GetValue(); }
33 void SetValue(int min, int max, int selected);
34 // Update the texts which display the min/max/current values of the slider
38 wxSpinCtrl *mwxSpinCtrl;
39 wxSpinButton *mwxSpinButton;
40 int _reactiveOnKeyStroke;
43 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
49 //-------------------------------------------------------------------------
50 SpinCtrlWidget::SpinCtrlWidget(SpinCtrl* box, wxWindow *parent,
52 int reactiveOnKeyStroke)
54 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
56 _reactiveOnKeyStroke(reactiveOnKeyStroke)
58 wxPanel * panel = this;
59 //---------------------------------------------------------------------
60 // 1) Creation of the components of the widget
61 // Any top level sub-widget must have the panel returned by panel
65 wxFlexGridSizer *sizer;
66 sizer = new wxFlexGridSizer(1);
71 if (mBox->bbGetInputType()==0)
73 mwxSpinCtrl = new wxSpinCtrl( panel, -1 );
74 // Connecting events to callbacks
75 Connect( mwxSpinCtrl->GetId(),
76 wxEVT_COMMAND_SPINCTRL_UPDATED,
77 (wxObjectEventFunction)
78 (void (wxPanel::*)(wxScrollEvent&))
79 &SpinCtrlWidget::OnSpinCtrlClick);
80 sizer->Add( mwxSpinCtrl );
82 mwxSpinButton = new wxSpinButton( panel, -1 );
83 // Connecting events to callbacks
84 Connect( mwxSpinButton->GetId(),
86 (wxObjectEventFunction)
87 (void (wxPanel::*)(wxScrollEvent&))
88 &SpinCtrlWidget::OnSpinCtrlClick);
89 sizer->Add( mwxSpinButton );
92 //---------------------------------------------------------------------
94 //---------------------------------------------------------------------
95 // 2) Insertion of the components in the window
97 // We use a FlexGridSizer
98 panel->SetSizer(sizer);
100 //-------------------------------------------------------------------------
103 //-------------------------------------------------------------------------
104 SpinCtrlWidget::~SpinCtrlWidget()
107 //-------------------------------------------------------------------------
110 //-------------------------------------------------------------------------
114 //-------------------------------------------------------------------------
115 void SpinCtrlWidget::OnSpinCtrlClick(wxCommandEvent& event)
117 // When user clicks the box
118 // we update the output of the box
120 if (mBox->bbGetInputType()==0)
122 mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() );
124 mBox->bbSetOutputOut( mwxSpinButton->GetValue() );
127 // and signal that the output has changed
128 //if(_reactiveOnKeyStroke==1){
129 mBox->bbSignalOutputModification(std::string("Out"));
132 //-------------------------------------------------------------------------
134 //-------------------------------------------------------------------------
137 //-------------------------------------------------------------------------
138 void SpinCtrlWidget::SetValue(int min, int max, int selected)
140 if (mBox->bbGetInputType()==0)
142 mwxSpinCtrl->SetRange( min,max );
143 mwxSpinCtrl->SetValue( selected );
145 mwxSpinButton->SetRange( min,max );
146 mwxSpinButton->SetValue( selected );
149 //-------------------------------------------------------------------------
152 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,SpinCtrl)
153 BBTK_BLACK_BOX_IMPLEMENTATION(SpinCtrl,bbtk::WxBlackBox);
155 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
157 void SpinCtrl::Process()
160 ((SpinCtrlWidget*)bbGetOutputWidget())->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );
161 bbSetOutputOut( bbGetInputSelected() );
164 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
166 void SpinCtrl::CreateWidget(wxWindow* parent)
169 SpinCtrlWidget *spinctrlwidget=new SpinCtrlWidget( this , parent, bbGetInputTitle() ,1);
170 bbSetOutputWidget( spinctrlwidget );
171 spinctrlwidget->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );
175 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
177 void SpinCtrl::bbUserSetDefaultValues()
181 bbSetInputSelected(0);
187 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
189 void SpinCtrl::bbUserInitializeProcessing()
193 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
195 void SpinCtrl::bbUserFinalizeProcessing()
199 } // EO namespace bbwx