]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputTextMultiLine.cxx
#3234 BBTK Feature New Normal - InputText with password option
[bbtk.git] / packages / wx / src / bbwxInputTextMultiLine.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 "bbwxInputTextMultiLine.h"
5 #include "bbwxPackage.h"
6 namespace bbwx
7 {
8
9
10   //--------------------------------------------------------------------------
11   class InputTextMultiLineWidget : wxPanel
12   {
13   public:
14     InputTextMultiLineWidget(InputTextMultiLine* box, wxWindow *parent,
15                     wxString In, wxString title );
16     ~InputTextMultiLineWidget();
17
18     std::string GetValue();
19         void SetValue(std::string value);
20
21     void OnTextEnter(wxCommandEvent& event);
22     void OnTextUpdate(wxCommandEvent& event);
23
24     void SetTitle(wxString);
25
26   private:
27     InputTextMultiLine  *mBox;
28     wxTextCtrl                  *mwxTextCtrl;
29     wxStaticText                *mwxTitle;
30   };
31   
32   //------------------------------------------------------------------------
33   //------------------------------------------------------------------------
34   //------------------------------------------------------------------------
35
36   InputTextMultiLineWidget::InputTextMultiLineWidget(InputTextMultiLine* box,
37                                    wxWindow *parent, 
38                                    wxString In, 
39                                    wxString title )
40     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
41       mBox(box)
42   {
43     wxPanel                     *panel  = this;
44
45 //wxTE_PROCESS_ENTER
46 //wxTE_MULTILINE    
47 //wxTE_PASSWORD
48     mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,40) , wxTE_MULTILINE);
49     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_ENTER, 
50              (wxObjectEventFunction) 
51              (wxEventFunction)
52              (wxCommandEventFunction) 
53              (void (wxPanel::*)(wxCommandEvent&))
54              &InputTextMultiLineWidget::OnTextEnter ); 
55
56     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
57              (wxObjectEventFunction) 
58              (wxEventFunction)
59              (wxCommandEventFunction) 
60              (void (wxPanel::*)(wxCommandEvent&))
61              &InputTextMultiLineWidget::OnTextUpdate ); 
62
63
64     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
65     mwxTitle                            = new wxStaticText(panel, -1, title ); 
66     sizer->Add( mwxTitle ); 
67     sizer->Add( mwxTextCtrl, 1, wxEXPAND ); 
68     sizer->AddGrowableCol(0);
69     sizer->AddGrowableRow(1);
70     
71     panel-> SetSizer(sizer);
72     panel-> SetAutoLayout(true);
73     panel-> Layout();
74
75   }
76   //-------------------------------------------------------------------------
77   
78   InputTextMultiLineWidget::~InputTextMultiLineWidget()
79   {
80   }
81
82   //-------------------------------------------------------------------------
83   
84  
85    void InputTextMultiLineWidget::SetTitle(wxString s)
86   { 
87     mwxTitle->SetLabel(s);
88   }
89
90   //-------------------------------------------------------------------------
91   std::string InputTextMultiLineWidget::GetValue()
92   { 
93     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
94   }
95         
96   void InputTextMultiLineWidget::SetValue(std::string value)
97   { 
98         mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
99   }
100         
101   //--------------------------------------------------------------------------
102   void InputTextMultiLineWidget::OnTextUpdate(wxCommandEvent& event)
103   {
104         if (mBox->bbGetInputReactiveOnKeystroke()==2){
105             mBox->bbSetOutputOut( GetValue() );
106             mBox->bbSetInputIn( GetValue() );
107             mBox->bbSignalOutputModification("Out");
108         }
109   }
110
111   //--------------------------------------------------------------------------
112   void InputTextMultiLineWidget::OnTextEnter(wxCommandEvent& event)
113   {
114         if (mBox->bbGetInputReactiveOnKeystroke()==1){
115             mBox->bbSetOutputOut( GetValue() );
116                 mBox->bbSetInputIn( GetValue() );
117                 mBox->bbSignalOutputModification("Out");
118         }
119   }
120
121   //--------------------------------------------------------------------------
122   //-------------------------------------------------------------------------
123   //--------------------------------------------------------------------------
124   //--------------------------------------------------------------------------
125
126 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputTextMultiLine)
127 BBTK_BLACK_BOX_IMPLEMENTATION(InputTextMultiLine,bbtk::WxBlackBox);
128 //===== 
129 // 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)
130 //===== 
131 void InputTextMultiLine::Process()
132 {
133     InputTextMultiLineWidget *w=(InputTextMultiLineWidget *)bbGetOutputWidget();
134         if (w) 
135         {
136                 if (firsttime==true)
137                 {
138                         firsttime=false;
139                         w->SetValue(  bbGetInputIn().c_str() );
140                 }
141                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
142                 bbSetOutputOut( w->GetValue() );
143         } else {
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 InputTextMultiLine::CreateWidget(wxWindow* parent)
151 {
152     bbSetOutputWidget
153      ( (wxWindow*) new InputTextMultiLineWidget(        this, //bbGetWxParent(),
154                                                                                 parent,
155                                                                                 bbtk::std2wx ( bbGetInputIn() ) , 
156                                                                                 bbtk::std2wx ( bbGetInputTitle() ) 
157                                                                           ) 
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 InputTextMultiLine::bbUserSetDefaultValues()
164 {
165                 firsttime=true;
166                 bbSetInputTitle("");
167                 bbSetInputIn("");
168                 bbSetOutputWidget(NULL);
169                 bbSetInputReactiveOnKeystroke(2);
170 }
171 //===== 
172 // 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)
173 //===== 
174 void InputTextMultiLine::bbUserInitializeProcessing()
175 {
176
177 }
178 //===== 
179 // 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)
180 //===== 
181 void InputTextMultiLine::bbUserFinalizeProcessing()
182 {
183
184 }
185 }
186 // EO namespace bbwx
187
188