//===== // 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) //===== #include "bbwxSpinCtrl.h" #include "bbwxPackage.h" #include #include namespace bbwx { //-------------------------------------------------------------------------- // The widget created by the box class SpinCtrlWidget : public wxPanel { public: /// Ctor with the two first params the parent window and the creator box /// which must be passed to the WxBlackBoxWidget constructor. /// The other params initialize the widget SpinCtrlWidget(SpinCtrl* box, wxWindow *parent, wxString title, int reactiveOnKeyStroke ); /// Dtor ~SpinCtrlWidget(); /// Events callbacks /// Called when the box is clicked void OnSpinCtrlClick(wxCommandEvent& event); // Accessors bool GetValue() { return mwxSpinCtrl->GetValue(); } void SetValue(int min, int max, int selected); // Update the texts which display the min/max/current values of the slider private: SpinCtrl* mBox; wxSpinCtrl *mwxSpinCtrl; wxSpinButton *mwxSpinButton; int _reactiveOnKeyStroke; int selected; }; //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------- SpinCtrlWidget::SpinCtrlWidget(SpinCtrl* box, wxWindow *parent, wxString title, int reactiveOnKeyStroke) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), mBox(box), _reactiveOnKeyStroke(reactiveOnKeyStroke) { wxPanel * panel = this; //--------------------------------------------------------------------- // 1) Creation of the components of the widget // Any top level sub-widget must have the panel returned by panel // for parent wxFlexGridSizer *sizer; sizer = new wxFlexGridSizer(1); mwxSpinCtrl = NULL; mwxSpinButton = NULL; if (mBox->bbGetInputTitle()!="") { sizer->Add( new wxStaticText(parent , -1, bbtk::std2wx(mBox->bbGetInputTitle()) ) ); } if (mBox->bbGetInputType()==0) { mwxSpinCtrl = new wxSpinCtrl( panel, -1 ); // Connecting events to callbacks Connect( mwxSpinCtrl->GetId(), wxEVT_COMMAND_SPINCTRL_UPDATED, (wxObjectEventFunction) (void (wxPanel::*)(wxScrollEvent&)) &SpinCtrlWidget::OnSpinCtrlClick); sizer->Add( mwxSpinCtrl ); } else { mwxSpinButton = new wxSpinButton( panel, -1 ); // Connecting events to callbacks Connect( mwxSpinButton->GetId(), wxEVT_SPIN, (wxObjectEventFunction) (void (wxPanel::*)(wxScrollEvent&)) &SpinCtrlWidget::OnSpinCtrlClick); sizer->Add( mwxSpinButton ); }// if Type //--------------------------------------------------------------------- //--------------------------------------------------------------------- // 2) Insertion of the components in the window // We use a FlexGridSizer panel->SetSizer(sizer); } //------------------------------------------------------------------------- //------------------------------------------------------------------------- SpinCtrlWidget::~SpinCtrlWidget() { } //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- void SpinCtrlWidget::OnSpinCtrlClick(wxCommandEvent& event) { // When user clicks the box // we update the output of the box if (mBox->bbGetInputType()==0) { mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() ); } else { mBox->bbSetOutputOut( mwxSpinButton->GetValue() ); }// if Type // and signal that the output has changed //if(_reactiveOnKeyStroke==1){ mBox->bbSignalOutputModification(std::string("Out")); //} } //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- void SpinCtrlWidget::SetValue(int min, int max, int selected) { if (mBox->bbGetInputType()==0) { mwxSpinCtrl->SetRange( min,max ); mwxSpinCtrl->SetValue( selected ); } else { mwxSpinButton->SetRange( min,max ); mwxSpinButton->SetValue( selected ); }// if Type } //------------------------------------------------------------------------- BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,SpinCtrl) BBTK_BLACK_BOX_IMPLEMENTATION(SpinCtrl,bbtk::WxBlackBox); //===== // 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) //===== void SpinCtrl::Process() { // if with label ((SpinCtrlWidget*)bbGetOutputWidget())->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() ); bbSetOutputOut( bbGetInputSelected() ); } //===== // 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) //===== void SpinCtrl::CreateWidget(wxWindow* parent) { SpinCtrlWidget *spinctrlwidget=new SpinCtrlWidget( this , parent, bbGetInputTitle() ,1); bbSetOutputWidget( spinctrlwidget ); spinctrlwidget->SetValue( bbGetInputMin() , bbGetInputMax(), bbGetInputSelected() ); } //===== // 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) //===== void SpinCtrl::bbUserSetDefaultValues() { bbSetInputMin(0); bbSetInputMax(100); bbSetInputSelected(0); bbSetInputType(0); bbSetInputTitle(""); } //===== // 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) //===== void SpinCtrl::bbUserInitializeProcessing() { } //===== // 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) //===== void SpinCtrl::bbUserFinalizeProcessing() { } } // EO namespace bbwx