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