]> Creatis software - bbtk.git/blobdiff - packages/wx/src/bbwxComboBox.cxx
#2452 BBTK Feature New Normal - ComboBox in wx package
[bbtk.git] / packages / wx / src / bbwxComboBox.cxx
index 4d4ce175e4909edac78f638703e2b3a8822a4ee7..e76d44f4d54443769211b03cf167c709b15d7eae 100644 (file)
@@ -9,6 +9,8 @@
 #include <string>
 
 #include <wx/choice.h>
+#include <wx/control.h>
+#include <wx/listbox.h>
 
 namespace bbwx
 {
@@ -20,14 +22,17 @@ namespace bbwx
        ComboBoxWidget( ComboBox* box, wxWindow *parent, 
                       int iSelection, 
                       std::string title, 
-                      std::vector< std::string > lstIn );
+                      std::vector< std::string > lstIn, 
+                                                        int typeForm );
 
        ~ComboBoxWidget();
 
        void OnComboBox(wxEvent& event);
 
   private:
-    ComboBox      *mBox;
+    int                                mTypeForm;
+    ComboBox           *mBox;
+        wxListBox              *wxlistbox;
         wxChoice               *wxchoice;
   };
   
@@ -42,28 +47,19 @@ namespace bbwx
                wxWindow *parent,
                int iSelection,
                std::string title,
-               std::vector< std::string > lstIn )
+               std::vector< std::string > lstIn,
+                                       int typeForm)
     :
     wxPanel( parent, -1) ,
-    mBox(box)
+    mBox(box),
+    mTypeForm(typeForm)
   {
-    wxPanel *panel     = this;
+   wxPanel     *panel          = this;
+       wxlistbox                               = NULL;
+       wxchoice                                        = NULL;
+   int i;
 
 
-    
-    //---------------------------------------------------------------------
-    // 1) Creation de wxChoise widget
-
-        wxchoice = new wxChoice ( panel , -1 );
-
-        Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
-
-    int i;
-    for (i=0;i<lstIn.size(); i++)
-    {
-          wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
-        } // for i
-    wxchoice->SetSelection(iSelection);
 
     //---------------------------------------------------------------------
     // 2) Insertion of the components in the window
@@ -74,10 +70,38 @@ namespace bbwx
     {
           sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
     }
-    sizer->Add( wxchoice,1,wxGROW ); 
     sizer->AddGrowableCol(0);
     panel->SetSizer(sizer);
 
+   
+    //---------------------------------------------------------------------
+    // 1) Creation de wxChoise widget
+
+               if (mTypeForm==1)
+               {
+
+                       wxlistbox = new wxListBox ( panel , -1 );                       
+                       Connect( wxlistbox->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
+               for (i=0;i<lstIn.size(); i++)
+               {
+                       wxlistbox->Append(  bbtk::std2wx( lstIn[i] )  ); 
+                       } // for i
+               wxlistbox->SetSelection(iSelection);
+                  sizer->Add( wxlistbox,1,wxGROW ); 
+
+               } else {
+
+                       wxchoice = new wxChoice ( panel , -1 );
+                       Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
+               for (i=0;i<lstIn.size(); i++)
+               {
+                       wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
+                       } // for i
+               wxchoice->SetSelection(iSelection);
+                  sizer->Add( wxchoice,1,wxGROW ); 
+               }
+
+
 //    panel->SetAutoLayout(true);
 //    panel->Layout();
 
@@ -91,10 +115,15 @@ namespace bbwx
   //--------------------------------------------------------------------------
   void ComboBoxWidget::OnComboBox(wxEvent& event)
   {
+        int iSelection;
+        if (mTypeForm==1)
+        {
+                iSelection = wxlistbox->GetSelection();
+        } else {
+                iSelection = wxchoice->GetSelection();
+        }
 
-       int iSelection = wxchoice->GetSelection();
     mBox->bbSetInputSelection( iSelection );
-
     mBox->bbSetOutputOut( iSelection );
     mBox->bbSetOutputOutString(    bbtk::wx2std( wxchoice->GetString(iSelection) )     );
     mBox->bbSignalOutputModification("Out");
@@ -125,7 +154,8 @@ void ComboBox::CreateWidget(wxWindow* parent)
                                                                        parent,
                                bbGetInputSelection() ,
                                bbGetInputTitle(),
-                               bbGetInputIn() );
+                               bbGetInputIn(),
+                               bbGetInputForm() );
 
    bbSetOutputOut( bbGetInputSelection() );
    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
@@ -140,6 +170,7 @@ void ComboBox::bbUserSetDefaultValues()
 {
        bbSetInputSelection(0);
        bbSetInputTitle("");
+       bbSetInputForm(0);
 }
 //===== 
 // 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)