]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxComboBox.cxx
#3465 Spin in combobox Box and FilterString (find strings)
[bbtk.git] / packages / wx / src / bbwxComboBox.cxx
index 06ec5912e0d115e929e31be9711424aab6d10a51..086708b92fa2fa554b0f160fc006ff2418a16960 100644 (file)
@@ -12,6 +12,8 @@
 #include <wx/control.h>
 #include <wx/listbox.h>
 
+#include <wx/spinbutt.h>
+
 namespace bbwx
 {
   //--------------------------------------------------------------------------
@@ -31,10 +33,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;
   };
   
 
@@ -58,6 +64,7 @@ namespace bbwx
     mBox(box),
     mTypeForm(typeForm)
   {
+       mwxspinbutton                   = NULL;
        itemcontainer                   = NULL;
        wxPanel                 *panel  = this;
        int                     i;
@@ -65,7 +72,7 @@ namespace bbwx
     // 2) Insertion of the components in the window
     
     // We use a FlexGridSizer
-    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
+    wxFlexGridSizer *sizer     = new wxFlexGridSizer(2);
     if (title!="")
     {
           sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
@@ -77,7 +84,7 @@ namespace bbwx
                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,13 +92,27 @@ namespace bbwx
                Connect( wxchoice->GetId(), 
                  wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
        }
+       
+       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);
     panel->SetSizer(sizer);
+       FillItems( iSelection,lstIn );
        
-       for (i=0;i<lstIn.size(); i++)
-       {
-               itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
-       } // for i
+//     for (i=0;i<lstIn.size(); i++)
+//     {
+//             itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
+//     } // for i
 //     itemcontainer->SetSelection(iSelection);
   }
 
@@ -119,7 +140,13 @@ namespace bbwx
        {
                mBox->bbSetInputSelection( iSelection );
                mBox->bbSetOutputOut( iSelection );
-               mBox->bbSetOutputOutString(    bbtk::wx2std( itemcontainer->GetString(iSelection) )     );
+
+// Patch to clean the spaces at the begining 
+               std::string tmpStr = bbtk::wx2std( itemcontainer->GetString(iSelection) );
+               if (tmpStr.length()>0) { while(tmpStr[0]==' ') tmpStr.erase(0,1); }
+               mBox->bbSetOutputOutString(   tmpStr   );
+//             mBox->bbSetOutputOutString(   bbtk::wx2std( itemcontainer->GetString(iSelection) )   );
+
                mBox->bbSignalOutputModification();
                VerifyDeselect(iSelection);
                if (mTypeForm==0) 
@@ -137,19 +164,88 @@ 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();
+       printf("EED ComboBoxWidget::OnSpinCtrlClick %d\n", iSelection );
+       itemcontainer->SetSelection(iSelection);
+       OnComboBoxSelection( iSelection );
+
+/*
+       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 ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
 {
-       int i;
+       int i,size=lstIn.size();
+
+
+#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++)
+       {       
+               if ( strLength < (int) lstIn[i].length() ) { strLength=lstIn[i].length();  }
+       }       // for
+       // Adding spaces at the bigining to the others strings in the list to have the same size
+       int ii,len2;
+       for (i=0 ;i<size; i++)
+       {       
+               len2 = strLength - lstIn[i].length();
+               for (ii=0;ii<len2;ii++)
+               {       
+                       lstIn[i]="  "+lstIn[i];  // spaces characters
+               } // for ii
+       } // for i
+#endif // defined(_WIN32)
+       
        itemcontainer->Clear();
-       for (i=0;i<lstIn.size(); i++)
+       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) 
+       { 
+               ((wxChoice*)itemcontainer)->SetAutoLayout( true ); 
+               ((wxChoice*)itemcontainer)->Layout( ); 
+       } // if mTypeForm       
 } 
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
@@ -205,6 +301,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)