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);
72 if (mBox->bbGetInputTitle()!="")
74 sizer->Add( new wxStaticText(panel , -1, bbtk::std2wx(mBox->bbGetInputTitle()) ) );
77 if (mBox->bbGetInputType()==0)
79 mwxSpinCtrl = new wxSpinCtrl( panel, -1 );
80 // Connecting events to callbacks
81 Connect( mwxSpinCtrl->GetId(),
82 wxEVT_COMMAND_SPINCTRL_UPDATED,
83 (wxObjectEventFunction)
84 (void (wxPanel::*)(wxScrollEvent&))
85 &SpinCtrlWidget::OnSpinCtrlClick);
86 sizer->Add( mwxSpinCtrl );
88 mwxSpinButton = new wxSpinButton( panel, -1 );
89 // Connecting events to callbacks
90 Connect( mwxSpinButton->GetId(),
92 (wxObjectEventFunction)
93 (void (wxPanel::*)(wxScrollEvent&))
94 &SpinCtrlWidget::OnSpinCtrlClick);
95 sizer->Add( mwxSpinButton );
98 //---------------------------------------------------------------------
100 //---------------------------------------------------------------------
101 // 2) Insertion of the components in the window
103 // We use a FlexGridSizer
104 panel->SetSizer(sizer);
106 //-------------------------------------------------------------------------
109 //-------------------------------------------------------------------------
110 SpinCtrlWidget::~SpinCtrlWidget()
113 //-------------------------------------------------------------------------
116 //-------------------------------------------------------------------------
120 //-------------------------------------------------------------------------
121 void SpinCtrlWidget::OnSpinCtrlClick(wxCommandEvent& event)
123 // When user clicks the box
124 // we update the output of the box
126 if (mBox->bbGetInputType()==0)
128 mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() );
130 mBox->bbSetOutputOut( mwxSpinButton->GetValue() );
133 // and signal that the output has changed
134 //if(_reactiveOnKeyStroke==1){
135 mBox->bbSignalOutputModification(std::string("Out"));
138 //-------------------------------------------------------------------------
140 //-------------------------------------------------------------------------
143 //-------------------------------------------------------------------------
144 void SpinCtrlWidget::SetValue(int min, int max, int selected)
146 if (mBox->bbGetInputType()==0)
148 mwxSpinCtrl->SetRange( min,max );
149 mwxSpinCtrl->SetValue( selected );
151 mwxSpinButton->SetRange( min,max );
152 mwxSpinButton->SetValue( selected );
155 //-------------------------------------------------------------------------
158 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,SpinCtrl)
159 BBTK_BLACK_BOX_IMPLEMENTATION(SpinCtrl,bbtk::WxBlackBox);
161 // 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)
163 void SpinCtrl::Process()
166 ((SpinCtrlWidget*)bbGetOutputWidget())->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );
167 bbSetOutputOut( bbGetInputSelected() );
170 // 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)
172 void SpinCtrl::CreateWidget(wxWindow* parent)
175 SpinCtrlWidget *spinctrlwidget=new SpinCtrlWidget( this , parent, bbGetInputTitle() ,1);
176 bbSetOutputWidget( spinctrlwidget );
177 spinctrlwidget->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );
181 // 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)
183 void SpinCtrl::bbUserSetDefaultValues()
187 bbSetInputSelected(0);
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::bbUserInitializeProcessing()
199 // 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)
201 void SpinCtrl::bbUserFinalizeProcessing()
205 } // EO namespace bbwx