]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxComboBox.cxx
#3416 BBTK Feature New Normal - Patch combobox to show the end of the string item
[bbtk.git] / packages / wx / src / bbwxComboBox.cxx
index 3c03e1545a20faa251cc6c9724844497a0f2a212..05f3a33f5728a826ebd8829fb76bab92f10581d7 100644 (file)
@@ -58,10 +58,9 @@ namespace bbwx
     mBox(box),
     mTypeForm(typeForm)
   {
-       wxPanel         *panel          = this;
        itemcontainer                   = NULL;
-       int i;
-
+       wxPanel                 *panel  = this;
+       int                     i;
     //---------------------------------------------------------------------
     // 2) Insertion of the components in the window
     
@@ -82,18 +81,21 @@ namespace bbwx
        } else if (mTypeForm==0) {
                wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
                itemcontainer=wxchoice;
-               sizer->Add( wxchoice,1,wxEXPAND ); 
-
+               sizer->Add( wxchoice,1,wxGROW ); 
                Connect( wxchoice->GetId(), 
                  wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
        }
     sizer->AddGrowableCol(0);
     panel->SetSizer(sizer);
        
-       for (i=0;i<lstIn.size(); i++)
-       {
-               itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
-       } // for i
+
+
+       FillItems( iSelection,lstIn );
+       
+//     for (i=0;i<lstIn.size(); i++)
+//     {
+//             itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
+//     } // for i
 //     itemcontainer->SetSelection(iSelection);
   }
 
@@ -121,35 +123,73 @@ namespace bbwx
        {
                mBox->bbSetInputSelection( iSelection );
                mBox->bbSetOutputOut( iSelection );
-               mBox->bbSetOutputOutString(    bbtk::wx2std( itemcontainer->GetString(iSelection) )     );
-               mBox->bbSignalOutputModification();
 
+// 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) 
+               { 
+                       wxChoice *wxchoise=(wxChoice *)itemcontainer;
+                       wxchoise->SetToolTip( itemcontainer->GetString(iSelection)    );
+               } // if mTypeForm
+
 
 //             mBox->bbSignalOutputModification("Out");
 //             mBox->bbSignalOutputModification("OutString");
        } // if iSelection
   }
 
-  //--------------------------------------------------------------------------
-  void ComboBoxWidget::OnComboBox(wxEvent& event)
-  {
+//--------------------------------------------------------------------------
+void ComboBoxWidget::OnComboBox(wxEvent& event)
+{
        OnComboBoxSelection( itemcontainer->GetSelection() );
-  }
+}
+
 //--------------------------------------------------------------------------
-  void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
+void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
+{
+       int i,size=lstIn.size();
+
+// 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];  // 3 space characters
+               } // for ii
+       } // for i
+       
+       itemcontainer->Clear();
+       for (i=0;i<size; i++)
        {
-               int i;
-               itemcontainer->Clear();
-       for (i=0;i<lstIn.size(); i++)
-       {
-                       itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
-               } // for i
-               if (iSelection>=0) itemcontainer->SetSelection(iSelection);
-       } 
+               itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
+       } // for i
+       if (iSelection>=0) itemcontainer->SetSelection(iSelection);
+
+       if (mTypeForm==0) 
+       { 
+               ((wxChoice*)itemcontainer)->SetAutoLayout( true ); 
+               ((wxChoice*)itemcontainer)->Layout( ); 
+       } // if mTypeForm       
+} 
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,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)
 //===== 
@@ -157,16 +197,16 @@ void ComboBox::Process()
 {
        int iSelection = bbGetInputSelection();
        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) && ( (size-1)<=iSelection) ) 
+    if         (  (iSelection>=0) && ( iSelection<size) ) 
     { 
        bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
     } // if iSelection
-
        w->VerifyDeselect(iSelection);
 }
 //===== 
@@ -183,7 +223,10 @@ void ComboBox::CreateWidget(wxWindow* parent)
                                bbGetInputForm(),
                                                        bbGetInputWinWidth(), bbGetInputWinHeight()  );
    bbSetOutputOut( bbGetInputSelection() );
-   bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
+   if (bbGetInputIn().size()> bbGetInputSelection() )
+   {
+          bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
+   } // if InputIn size
    bbSetOutputWidget( w );
 }
 //===== 
@@ -194,8 +237,8 @@ void ComboBox::bbUserSetDefaultValues()
        bbSetInputSelection(0);
        bbSetInputTitle("");
        bbSetInputForm(0);
-       bbSetInputWinWidth(100);
-       bbSetInputWinHeight(200);
+       bbSetInputWinWidth(10);
+       bbSetInputWinHeight(45);
        bbSetInputDeselect(false);
 }
 //=====