]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxSpinCtrl.cxx
a30be49db914f12ad402ef4704e206a4b70236b6
[bbtk.git] / packages / wx / src / bbwxSpinCtrl.cxx
1 //===== 
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)
3 //===== 
4 #include "bbwxSpinCtrl.h"
5 #include "bbwxPackage.h"
6
7 #include <wx/spinbutt.h>
8 #include <wx/spinctrl.h>
9
10 namespace bbwx
11 {
12
13
14
15   //--------------------------------------------------------------------------
16   // The widget created by the box 
17   class SpinCtrlWidget : public wxPanel 
18   {
19   public:
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 );
25     /// Dtor
26     ~SpinCtrlWidget();
27     /// Events callbacks
28     /// Called when the box is clicked
29     void OnSpinCtrlClick(wxCommandEvent& event);
30
31     // Accessors
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
35         
36   private:
37     SpinCtrl*       mBox;
38     wxSpinCtrl          *mwxSpinCtrl;
39     wxSpinButton        *mwxSpinButton;
40     int                 _reactiveOnKeyStroke;
41     int                 selected;
42   };
43   //------------------------------------------------------------------------
44   //------------------------------------------------------------------------
45   //------------------------------------------------------------------------
46
47   
48     
49   //-------------------------------------------------------------------------
50   SpinCtrlWidget::SpinCtrlWidget(SpinCtrl* box, wxWindow *parent,
51                              wxString title,
52                               int reactiveOnKeyStroke)
53     :  
54     wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
55     mBox(box),
56     _reactiveOnKeyStroke(reactiveOnKeyStroke)
57   {
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
62     // for parent
63
64
65     wxFlexGridSizer *sizer;
66     sizer       = new wxFlexGridSizer(1);
67
68     
69     mwxSpinCtrl         = NULL;
70     mwxSpinButton       = NULL;
71         if (mBox->bbGetInputType()==0)
72         {
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 );
81         } else {
82             mwxSpinButton = new wxSpinButton( panel, -1 );      
83                 // Connecting events to callbacks
84                 Connect( mwxSpinButton->GetId(), 
85                          wxEVT_SPIN, 
86                          (wxObjectEventFunction) 
87                          (void (wxPanel::*)(wxScrollEvent&))
88                          &SpinCtrlWidget::OnSpinCtrlClick);
89                 sizer->Add( mwxSpinButton );
90         }// if Type
91               
92     //---------------------------------------------------------------------
93
94     //---------------------------------------------------------------------
95     // 2) Insertion of the components in the window
96     
97     // We use a FlexGridSizer
98     panel->SetSizer(sizer);
99   }
100   //-------------------------------------------------------------------------
101   
102
103   //-------------------------------------------------------------------------
104   SpinCtrlWidget::~SpinCtrlWidget()
105   {
106   }
107   //-------------------------------------------------------------------------
108
109
110   //-------------------------------------------------------------------------
111
112
113
114   //-------------------------------------------------------------------------
115   void SpinCtrlWidget::OnSpinCtrlClick(wxCommandEvent& event)
116   {
117           // When user clicks the box 
118           // we update the output of the box
119
120         if (mBox->bbGetInputType()==0)
121         {
122           mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() );
123         } else {
124           mBox->bbSetOutputOut( mwxSpinButton->GetValue() );
125         }// if Type
126
127           // and signal that the output has changed
128           //if(_reactiveOnKeyStroke==1){
129           mBox->bbSignalOutputModification(std::string("Out"));
130           //}
131   }
132   //-------------------------------------------------------------------------
133
134   //-------------------------------------------------------------------------
135   
136
137   //-------------------------------------------------------------------------
138   void SpinCtrlWidget::SetValue(int min, int max, int selected)
139   {
140         if (mBox->bbGetInputType()==0)
141         {
142             mwxSpinCtrl->SetRange( min,max );
143             mwxSpinCtrl->SetValue( selected );
144         } else {
145             mwxSpinButton->SetRange( min,max );
146             mwxSpinButton->SetValue( selected );
147         }// if Type
148   }
149   //-------------------------------------------------------------------------
150
151
152 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,SpinCtrl)
153 BBTK_BLACK_BOX_IMPLEMENTATION(SpinCtrl,bbtk::WxBlackBox);
154 //===== 
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)
156 //===== 
157 void SpinCtrl::Process()
158 {
159                 // if with label
160                 ((SpinCtrlWidget*)bbGetOutputWidget())->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );    
161                 bbSetOutputOut( bbGetInputSelected() );
162 }
163 //===== 
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)
165 //===== 
166 void SpinCtrl::CreateWidget(wxWindow* parent)
167 {
168
169                 SpinCtrlWidget *spinctrlwidget=new  SpinCtrlWidget( this , parent, bbGetInputTitle() ,1);
170                 bbSetOutputWidget( spinctrlwidget );
171                 spinctrlwidget->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() );    
172
173 }
174 //===== 
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)
176 //===== 
177 void SpinCtrl::bbUserSetDefaultValues()
178 {
179         bbSetInputMin(0);
180         bbSetInputMax(100);
181         bbSetInputSelected(0);
182         bbSetInputType(0);
183         bbSetInputTitle("");    
184
185 }
186 //===== 
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)
188 //===== 
189 void SpinCtrl::bbUserInitializeProcessing()
190 {
191 }
192 //===== 
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)
194 //===== 
195 void SpinCtrl::bbUserFinalizeProcessing()
196 {
197 }
198
199 } // EO namespace bbwx
200
201