]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxComboBox.cxx
#3496 Linux Bug
[bbtk.git] / packages / wx / src / bbwxComboBox.cxx
index 05f3a33f5728a826ebd8829fb76bab92f10581d7..f0c3cc5d23de828a180d3a8ed0fd9fafb7ac11d2 100644 (file)
@@ -4,7 +4,6 @@
 #include "bbwxComboBox.h"
 #include "bbwxPackage.h"
 
-
 #include <vector>
 #include <string>
 
@@ -12,6 +11,8 @@
 #include <wx/control.h>
 #include <wx/listbox.h>
 
+#include <wx/spinbutt.h>
+
 namespace bbwx
 {
   //--------------------------------------------------------------------------
@@ -31,10 +32,14 @@ namespace bbwx
        void FillItems( int iSelection, std::vector< std::string > lstIn);
     void VerifyDeselect(int iSelection);
 
+    void OnSpinCtrlClick(wxCommandEvent& event);
+
+
   private:
     int                        mTypeForm;
     ComboBox           *mBox;
-       wxItemContainer* itemcontainer;
+       wxItemContainer *itemcontainer;
+       wxSpinButton    *mwxspinbutton;
   };
   
 
@@ -52,12 +57,12 @@ namespace bbwx
                        int typeForm,
                        int sizeX, 
                        int sizeY
-               )
-    :
+               ) :
     wxPanel( parent, -1,wxDefaultPosition ) ,
     mBox(box),
     mTypeForm(typeForm)
   {
+       mwxspinbutton                   = NULL;
        itemcontainer                   = NULL;
        wxPanel                 *panel  = this;
        int                     i;
@@ -65,19 +70,25 @@ namespace bbwx
     // 2) Insertion of the components in the window
     
     // We use a FlexGridSizer
-    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
+//    wxFlexGridSizer *sizerV          = new wxFlexGridSizer(1);
+//    wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(0);
+//    wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(2);
+    wxFlexGridSizer *sizer     = new wxFlexGridSizer(2);
+       
     if (title!="")
     {
           sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
+          sizer->Add( new wxStaticText(panel,-1,  _T("") ) ); 
     }
     //---------------------------------------------------------------------
+        
        if (mTypeForm==1)
        {
                wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );       
                itemcontainer=wxlistbox;
                sizer->Add( wxlistbox,1,wxEXPAND ); 
                Connect( wxlistbox->GetId(), 
-                 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
+                 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );                  
        } else if (mTypeForm==0) {
                wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
                itemcontainer=wxchoice;
@@ -85,18 +96,21 @@ namespace bbwx
                Connect( wxchoice->GetId(), 
                  wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
        }
-    sizer->AddGrowableCol(0);
-    panel->SetSizer(sizer);
        
+       if (mBox->bbGetInputWithSpinButton()==true)
+       {
+               mwxspinbutton = new wxSpinButton( panel, -1 );    
+               Connect( mwxspinbutton->GetId(), 
+                        wxEVT_SPIN, 
+                        (wxObjectEventFunction) 
+                        (void (wxPanel::*)(wxScrollEvent&))
+                        &ComboBoxWidget::OnSpinCtrlClick);
+               sizer->Add( mwxspinbutton,1,wxEXPAND ); 
+       }
+    sizer->AddGrowableCol(0);
 
-
-       FillItems( iSelection,lstIn );
-       
-//     for (i=0;i<lstIn.size(); i++)
-//     {
-//             itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
-//     } // for i
-//     itemcontainer->SetSelection(iSelection);
+    panel->SetSizer(sizer);
+       FillItems( iSelection,lstIn );  
   }
 
   //-------------------------------------------------------------------------  
@@ -147,15 +161,35 @@ namespace bbwx
 //--------------------------------------------------------------------------
 void ComboBoxWidget::OnComboBox(wxEvent& event)
 {
-       OnComboBoxSelection( itemcontainer->GetSelection() );
+       int iSelection = itemcontainer->GetSelection();
+       OnComboBoxSelection( iSelection );
+       if (mBox->bbGetInputWithSpinButton()==true)
+       {
+               mwxspinbutton->SetValue( iSelection );
+       }
+
 }
 
+//--------------------------------------------------------------------------
+void ComboBoxWidget::OnSpinCtrlClick(wxCommandEvent& event)
+{
+       int iSelection = mwxspinbutton->GetValue();
+       itemcontainer->SetSelection(iSelection);
+       OnComboBoxSelection( iSelection );
+}
+
+
 //--------------------------------------------------------------------------
 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
 {
-       int i,size=lstIn.size();
+       int i,size = lstIn.size();
 
-// Patch to put spaces at the beginin
+
+#if defined(_WIN32)
+       // Patch to put spaces at the beginin
+#else
+    /*
+       // Patch to put spaces at the beginin
        int strLength=-1;
        // Looking for the longest string
        for (i=0 ;i<size; i++)
@@ -169,16 +203,27 @@ void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn
                len2 = strLength - lstIn[i].length();
                for (ii=0;ii<len2;ii++)
                {       
-                       lstIn[i]="   "+lstIn[i];  // 3 space characters
+                       lstIn[i]="  "+lstIn[i];  // spaces characters
                } // for ii
        } // for i
+     */
+#endif // defined(_WIN32)
        
        itemcontainer->Clear();
        for (i=0;i<size; i++)
        {
                itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
        } // for i
-       if (iSelection>=0) itemcontainer->SetSelection(iSelection);
+       if (iSelection>=0)
+       { 
+               itemcontainer->SetSelection(iSelection); 
+               if (mBox->bbGetInputWithSpinButton()==true)
+               {
+                   mwxspinbutton->SetRange( 0,size-1 );
+                       mwxspinbutton->SetValue( iSelection );
+               }
+
+       } // iSelection
 
        if (mTypeForm==0) 
        { 
@@ -196,18 +241,20 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
 void ComboBox::Process()
 {
        int iSelection = bbGetInputSelection();
-       if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
-//     if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
+//     if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
+       if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
        ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
-       w->FillItems( iSelection, bbGetInputIn() );
-    bbSetInputSelection( iSelection );
-    bbSetOutputOut( iSelection );
-    int size = bbGetInputIn().size();
-    if         (  (iSelection>=0) && ( iSelection<size) ) 
-    { 
-       bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
-    } // if iSelection
-       w->VerifyDeselect(iSelection);
+       if (w!=NULL) {
+               w->FillItems( iSelection, bbGetInputIn() );
+               bbSetInputSelection( iSelection );
+               bbSetOutputOut( iSelection );
+               int size = bbGetInputIn().size();
+               if      (  (iSelection>=0) && ( iSelection<size) ) 
+               {
+                  bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
+               } // if iSelection
+               w->VerifyDeselect(iSelection);
+       } // if w
 }
 //===== 
 // 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)
@@ -228,6 +275,7 @@ void ComboBox::CreateWidget(wxWindow* parent)
           bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
    } // if InputIn size
    bbSetOutputWidget( w );
+   
 }
 //===== 
 // 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)
@@ -240,6 +288,7 @@ void ComboBox::bbUserSetDefaultValues()
        bbSetInputWinWidth(10);
        bbSetInputWinHeight(45);
        bbSetInputDeselect(false);
+       bbSetInputWithSpinButton(false);
 }
 //===== 
 // 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)
@@ -252,9 +301,8 @@ void ComboBox::bbUserInitializeProcessing()
 //===== 
 void ComboBox::bbUserFinalizeProcessing()
 {
-
-}
 }
-// EO namespace bbwx
+
+}// EO namespace bbwx