]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtComboBox.cxx
#3030 creaWT Bug New Normal - ComboBox update
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtComboBox.cxx
1 //===== 
2 // 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)
3 //===== 
4 #include "bbwtComboBox.h"
5 #include "bbwtPackage.h"
6 namespace bbwt
7 {
8
9   class ComboBoxWidget : public Wt::WContainerWidget
10   {
11     public:
12       ComboBoxWidget(ComboBox* box, Wt::WContainerWidget *parent,
13                       int iSelection,
14                       Wt::WString title,
15                       int typeForm);
16       ~ComboBoxWidget();
17       void OnComboBox();
18           void SetItems( std::vector<std::string> lstIn );      
19
20     private:
21       int                               mTypeForm;
22       ComboBox                  *mBox;
23       Wt::WComboBox     *wtCmbBox;  
24       Wt::WSelectionBox *wtSlctBox;
25       Wt::WComboBox     *selection;
26       //TODO choice
27
28   };
29
30   //------------------------------------------------------------------------
31   //------------------------------------------------------------------------
32   //------------------------------------------------------------------------
33
34
35   ComboBoxWidget::ComboBoxWidget(ComboBox* box, Wt::WContainerWidget *parent,
36                       int iSelection,
37                       Wt::WString title,
38                       int typeForm)
39                  :
40                       Wt::WContainerWidget(parent),
41                       mBox(box),
42                       mTypeForm(typeForm)
43   {
44
45     Wt::WContainerWidget *panel = this;
46     Wt::WBorderLayout *layout = new Wt::WBorderLayout();
47     int i;
48     if(title!="")
49     {
50       layout->addWidget(new Wt::WText(title),Wt::WBorderLayout::North);    
51     }
52     
53     if(mTypeForm == 0)
54     {
55       wtCmbBox  = new Wt::WComboBox();
56       selection = wtCmbBox;
57     } else {
58       wtSlctBox = new Wt::WSelectionBox();
59      // wtSlctBox->setSelectionMode(Wt::ExtendedSelection);
60       selection = wtSlctBox;
61     }
62
63     selection->activated().connect(this,&ComboBoxWidget::OnComboBox);
64
65     layout->addWidget(selection,Wt::WBorderLayout::Center);
66     panel->setLayout(layout);
67   }
68
69 //-------------------------------------------------------------------------  
70   ComboBoxWidget::~ComboBoxWidget()
71   {
72   }
73
74 //--------------------------------------------------------------------------
75   void ComboBoxWidget::OnComboBox()
76   {
77     mBox->bbSetInputSelection( selection->currentIndex() );
78     mBox->bbSetOutputOut( selection->currentIndex() );
79     mBox->bbSetOutputOutString(    bbtk::wt2std( selection->valueText() )     );
80     mBox->bbSignalOutputModification("Out");
81     mBox->bbSignalOutputModification("OutString");
82   }
83
84 //--------------------------------------------------------------------------
85   void ComboBoxWidget::SetItems( std::vector<std::string> lstIn )
86   {
87         int i;
88
89     selection->clear();
90
91     for (i=0;i<lstIn.size(); i++)
92     {
93       selection->addItem(bbtk::std2wt(lstIn[i]));
94     }  // for i
95   }
96
97
98   
99 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,ComboBox)
100 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WtBlackBox);
101 //===== 
102 // 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)
103 //===== 
104 void ComboBox::Process()
105 {
106
107         ComboBoxWidget *widget = (ComboBoxWidget *)bbGetOutputWidget(); 
108         widget->SetItems( bbGetInputIn() );
109
110 }
111 //===== 
112 // 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)
113 //===== 
114 void ComboBox::CreateWidget(Wt::WContainerWidget* parent)
115 {
116
117        ComboBoxWidget *w = new ComboBoxWidget(
118                                 this,
119                                                         parent,
120                                 bbGetInputSelection() ,
121                                 bbGetInputTitle(),
122 //                              bbGetInputIn(),
123                                 bbGetInputForm() );
124
125    bbSetOutputOut( bbGetInputSelection() );
126    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
127    bbSetOutputWidget( w );
128   
129 }
130 //===== 
131 // 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)
132 //===== 
133 void ComboBox::bbUserSetDefaultValues()
134 {
135         bbSetInputSelection(0);
136         bbSetInputTitle("");
137         bbSetInputForm(0);
138 }
139 //===== 
140 // 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)
141 //===== 
142 void ComboBox::bbUserInitializeProcessing()
143 {
144
145 }
146 //===== 
147 // 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)
148 //===== 
149 void ComboBox::bbUserFinalizeProcessing()
150 {
151
152 }
153 }
154 // EO namespace bbwt
155
156