]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtInputText.cxx~
19b5d2cec6b2c2e997489dc580ccd89552029474
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtInputText.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 "bbwtInputText.h"
5 #include "bbwtPackage.h"
6 namespace bbwt
7 {
8  //--------------------------------------------------------------------------
9   class InputTextWidget : public Wt::WContainerWidget
10   {
11   public:
12     InputTextWidget(InputText* box, 
13                                                                                 Wt::WContainerWidget *parent,
14                                                                 Wt::WString In,
15                                                                                 Wt::WString title
16                                                                                 );
17     ~InputTextWidget();
18
19     std::string GetValue();
20                 void SetValue(std::string value);
21
22     void OnTextEnter();
23     void OnTextUpdate(const Wt::WKeyEvent e);
24
25     void SetTitle(Wt::WString);
26
27   private:
28     InputText    *mBox;
29     Wt::WLineEdit        *mwtLineEdit;
30     Wt::WText *mwtTitle;
31   };
32   
33   //------------------------------------------------------------------------
34   //------------------------------------------------------------------------
35   //------------------------------------------------------------------------
36
37   InputTextWidget::InputTextWidget(InputText* box,
38                                    Wt::WContainerWidget *parent, 
39                                    Wt::WString In, 
40                                    Wt::WString title)
41     : 
42                 Wt::WContainerWidget(parent),
43       mBox(box)
44   {
45                 Wt::WContainerWidget *panel     = this;
46                 Wt::WBorderLayout *layout = new Wt::WBorderLayout();
47
48         
49     mwtLineEdit = new Wt::WLineEdit();
50
51                 mwtLineEdit->changed().connect(this,&InputTextWidget::OnTextEnter);
52                 mwtLineEdit->keyWentUp().connect(this, &InputTextWidget::OnTextUpdate);
53                 
54
55     mwtTitle = new Wt::WText(title); 
56                 
57                 layout->addWidget(mwtTitle,Wt::WBorderLayout::North);
58                 layout->addWidget(mwtLineEdit,Wt::WBorderLayout::Center);
59                 
60                 panel->setLayout(layout);
61
62   }
63   //-------------------------------------------------------------------------
64   
65   InputTextWidget::~InputTextWidget()
66   {
67   }
68
69   //-------------------------------------------------------------------------
70   
71  
72    void InputTextWidget::SetTitle(Wt::WString s)
73   { 
74     mwtTitle->setText(s);
75   }
76
77   //-------------------------------------------------------------------------
78   std::string InputTextWidget::GetValue()
79   { 
80     return bbtk::wt2std ( mwtLineEdit->text() );
81   }
82         
83   void InputTextWidget::SetValue(std::string value)
84   { 
85                 mwtLineEdit->setText( bbtk::std2wt(value) ) ;
86   }
87         
88   //--------------------------------------------------------------------------
89   void InputTextWidget::OnTextEnter()
90   {
91                 std::cout<<"bbwtInputText.cxx   ->    OnTextEnter pre if"<<std::endl;
92                 if (mBox->bbGetInputReactiveOnKeystroke()==1)
93                 {
94                                 std::cout<<"bbwtInputText.cxx   ->    OnTextEnter if"<<std::endl;
95                           mBox->bbSetOutputOut( GetValue() );
96                           mBox->bbSetInputIn( GetValue() );
97                     mBox->bbSignalOutputModification("Out");
98                 }
99   }
100
101   //--------------------------------------------------------------------------
102   void InputTextWidget::OnTextUpdate(const Wt::WKeyEvent e)
103   {
104                 std::cout<<"bbwtInputText.cxx   ->   pre If ...OnTextUpdate  VALUE :  "<<GetValue()<<std::endl;
105                 std::cout<<"bbwtInputText.cxx   ->   pre If ...OnTextUpdate  presionado :  "<<e.key()<<std::endl;
106                 std::cout<<"bbwtInputText.cxx   ->    OnTextUpdate pre if"<<std::endl;
107                         if ((mBox->bbGetInputReactiveOnKeystroke()==2 && e.key() != Wt::Key_Enter)||((mBox->bbGetInputReactiveOnKeystroke()==1 && e.key() == Wt::Key_Enter) )) 
108                         {
109                                 std::cout<<"bbwtInputText.cxx   ->    OnTextUpdate  if"<<std::endl;
110                                 std::cout<<"bbwtInputText.cxx   ->    OnTextUpdate  VALUE :  "<<GetValue()<<std::endl;  
111                                 mBox->bbSetOutputOut( GetValue() + bbtk::wt2std(e.text()) );
112                                 mBox->bbSetInputIn( GetValue() );
113                                 mBox->bbSignalOutputModification("Out");
114                         }
115                 
116   }
117
118
119   //--------------------------------------------------------------------------
120   //-------------------------------------------------------------------------
121   //--------------------------------------------------------------------------
122   //--------------------------------------------------------------------------
123 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,InputText)
124 BBTK_BLACK_BOX_IMPLEMENTATION(InputText,bbtk::WtBlackBox);
125 //===== 
126 // 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)
127 //===== 
128 void InputText::Process()
129 {
130
131   InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
132         if (w) 
133         {
134                 if (firsttime==true)
135                 {
136                         firsttime=false;
137                         w->SetValue(  bbGetInputIn().c_str() );
138                 }
139                         w->SetTitle( bbtk::std2wt ( bbGetInputTitle() ) );
140                         bbSetOutputOut( w->GetValue() );
141         }
142   else 
143         {
144           bbSetOutputOut( "<VOID>" );
145         }
146 }
147 //===== 
148 // 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)
149 //===== 
150 void InputText::CreateWidget(Wt::WContainerWidget* parent)
151 {
152
153     bbSetOutputWidget
154       (  new InputTextWidget(this, //bbGetWxParent(),
155                                         parent,
156                                         bbtk::std2wt ( bbGetInputIn() ) , 
157                                         bbtk::std2wt ( bbGetInputTitle() ) ) ); 
158   
159 }
160 //===== 
161 // 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)
162 //===== 
163 void InputText::bbUserSetDefaultValues()
164 {
165         firsttime=true;
166         bbSetInputTitle("");
167         bbSetInputIn("");
168         bbSetOutputWidget(0);
169         bbSetInputReactiveOnKeystroke(2);
170
171 }
172 //===== 
173 // 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)
174 //===== 
175 void InputText::bbUserInitializeProcessing()
176 {
177
178 }
179 //===== 
180 // 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)
181 //===== 
182 void InputText::bbUserFinalizeProcessing()
183 {
184
185 }
186 }
187 // EO namespace bbwt
188
189