]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtComboBox.cxx
2a4bf63943863c8f31a9bf6615e63d55cbf77bd1
[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 AddItems( 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::AddItems( std::vector<std::string> lstIn )
86   {
87         int i;
88     for (i=0;i<lstIn.size(); i++)
89     {
90       selection->addItem(bbtk::std2wt(lstIn[i]));
91     }  // for i
92   }
93
94
95   
96 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,ComboBox)
97 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WtBlackBox);
98 //===== 
99 // 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)
100 //===== 
101 void ComboBox::Process()
102 {
103
104         ComboBoxWidget *widget = (ComboBoxWidget *)bbGetOutputWidget();
105         widget->AddItems( bbGetInputIn() );
106   
107 }
108 //===== 
109 // 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)
110 //===== 
111 void ComboBox::CreateWidget(Wt::WContainerWidget* parent)
112 {
113
114        ComboBoxWidget *w = new ComboBoxWidget(
115                                 this,
116                                                         parent,
117                                 bbGetInputSelection() ,
118                                 bbGetInputTitle(),
119 //                              bbGetInputIn(),
120                                 bbGetInputForm() );
121
122    bbSetOutputOut( bbGetInputSelection() );
123    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
124    bbSetOutputWidget( w );
125   
126 }
127 //===== 
128 // 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)
129 //===== 
130 void ComboBox::bbUserSetDefaultValues()
131 {
132         bbSetInputSelection(0);
133         bbSetInputTitle("");
134         bbSetInputForm(0);
135 }
136 //===== 
137 // 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)
138 //===== 
139 void ComboBox::bbUserInitializeProcessing()
140 {
141
142 }
143 //===== 
144 // 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)
145 //===== 
146 void ComboBox::bbUserFinalizeProcessing()
147 {
148
149 }
150 }
151 // EO namespace bbwt
152
153