From: Eduardo DAVILA Date: Thu, 7 Mar 2019 14:21:45 +0000 (+0100) Subject: #3234 BBTK Feature New Normal - InputText with password option X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=714c8039f8498b724c1a22cfcfed3586a22d6235;p=bbtk.git #3234 BBTK Feature New Normal - InputText with password option --- diff --git a/packages/wx/src/bbwxInputText.cxx b/packages/wx/src/bbwxInputText.cxx index d64cfa5..6df004d 100644 --- a/packages/wx/src/bbwxInputText.cxx +++ b/packages/wx/src/bbwxInputText.cxx @@ -58,7 +58,6 @@ namespace bbwx std::string GetValue(); void SetValue(std::string value); - void SetWindowStyle(int style); void OnTextEnter(wxCommandEvent& event); void OnTextUpdate(wxCommandEvent& event); @@ -85,8 +84,8 @@ namespace bbwx wxPanel *panel = this; //wxTE_PROCESS_ENTER -//wxTE_MULTILINE For multiple line you have to create an other box (EED). - +//wxTE_MULTILINE +//wxTE_PASSWORD mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,40) , wxTE_PROCESS_ENTER); Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER, (wxObjectEventFunction) @@ -128,14 +127,6 @@ namespace bbwx mwxTitle->SetLabel(s); } - void InputTextWidget::SetWindowStyle(int style) - { - long wxstyle = wxTE_PROCESS_ENTER; - if (style==1) {wxstyle = wxTE_PASSWORD;} - mwxTextCtrl->SetWindowStyle(wxstyle); - } - - //------------------------------------------------------------------------- std::string InputTextWidget::GetValue() { @@ -183,9 +174,8 @@ namespace bbwx firsttime=true; bbSetInputTitle(""); bbSetInputIn(""); - bbSetOutputWidget(0); + bbSetOutputWidget(NULL); bbSetInputReactiveOnKeystroke(2); - bbSetInputStyle(0); } //----------------------------------------------------------------- @@ -210,7 +200,6 @@ namespace bbwx firsttime=false; w->SetValue( bbGetInputIn().c_str() ); } - w->SetWindowStyle( bbGetInputStyle() ); w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) ); bbSetOutputOut( w->GetValue() ); } else { diff --git a/packages/wx/src/bbwxInputText.h b/packages/wx/src/bbwxInputText.h index 46bc6d5..dbaa017 100644 --- a/packages/wx/src/bbwxInputText.h +++ b/packages/wx/src/bbwxInputText.h @@ -68,7 +68,6 @@ namespace bbwx BBTK_BLACK_BOX_INTERFACE(InputText,bbtk::WxBlackBox); BBTK_DECLARE_INPUT(In,std::string); BBTK_DECLARE_INPUT(Title,std::string); - BBTK_DECLARE_INPUT(Style,int); BBTK_DECLARE_INPUT(ReactiveOnKeystroke,int); BBTK_DECLARE_OUTPUT(Out,std::string); BBTK_PROCESS(Process); @@ -90,11 +89,8 @@ namespace bbwx BBTK_AUTHOR("laurent guigues at creatis.insa-lyon.fr"); BBTK_DESCRIPTION("A zone in which the user can enter a text (wxTextCtrl)"); BBTK_INPUT(InputText,In,"Initial text (default '')",std::string,""); - BBTK_INPUT(InputText,Title,"Title of the input zone (default '') ", std::string,""); - BBTK_INPUT(InputText,Style,"(default 0) 0:OneLine 1:Password ", int,""); BBTK_INPUT(InputText,ReactiveOnKeystroke,"0 not event generated, 1 Enter event genereated, 2 All keys, (default '2') ", int,""); - BBTK_OUTPUT(InputText,Out,"Current text",std::string,""); BBTK_END_DESCRIBE_BLACK_BOX(InputText); diff --git a/packages/wx/src/bbwxInputTextMultiLine.cxx b/packages/wx/src/bbwxInputTextMultiLine.cxx new file mode 100644 index 0000000..82f376c --- /dev/null +++ b/packages/wx/src/bbwxInputTextMultiLine.cxx @@ -0,0 +1,188 @@ +//===== +// 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) +//===== +#include "bbwxInputTextMultiLine.h" +#include "bbwxPackage.h" +namespace bbwx +{ + + + //-------------------------------------------------------------------------- + class InputTextMultiLineWidget : wxPanel + { + public: + InputTextMultiLineWidget(InputTextMultiLine* box, wxWindow *parent, + wxString In, wxString title ); + ~InputTextMultiLineWidget(); + + std::string GetValue(); + void SetValue(std::string value); + + void OnTextEnter(wxCommandEvent& event); + void OnTextUpdate(wxCommandEvent& event); + + void SetTitle(wxString); + + private: + InputTextMultiLine *mBox; + wxTextCtrl *mwxTextCtrl; + wxStaticText *mwxTitle; + }; + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + InputTextMultiLineWidget::InputTextMultiLineWidget(InputTextMultiLine* box, + wxWindow *parent, + wxString In, + wxString title ) + : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(box) + { + wxPanel *panel = this; + +//wxTE_PROCESS_ENTER +//wxTE_MULTILINE +//wxTE_PASSWORD + mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,40) , wxTE_MULTILINE); + Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER, + (wxObjectEventFunction) + (wxEventFunction) + (wxCommandEventFunction) + (void (wxPanel::*)(wxCommandEvent&)) + &InputTextMultiLineWidget::OnTextEnter ); + + Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) + (wxEventFunction) + (wxCommandEventFunction) + (void (wxPanel::*)(wxCommandEvent&)) + &InputTextMultiLineWidget::OnTextUpdate ); + + + wxFlexGridSizer *sizer = new wxFlexGridSizer(1); + mwxTitle = new wxStaticText(panel, -1, title ); + sizer->Add( mwxTitle ); + sizer->Add( mwxTextCtrl, 1, wxEXPAND ); + sizer->AddGrowableCol(0); + sizer->AddGrowableRow(1); + + panel-> SetSizer(sizer); + panel-> SetAutoLayout(true); + panel-> Layout(); + + } + //------------------------------------------------------------------------- + + InputTextMultiLineWidget::~InputTextMultiLineWidget() + { + } + + //------------------------------------------------------------------------- + + + void InputTextMultiLineWidget::SetTitle(wxString s) + { + mwxTitle->SetLabel(s); + } + + //------------------------------------------------------------------------- + std::string InputTextMultiLineWidget::GetValue() + { + return bbtk::wx2std ( mwxTextCtrl->GetValue() ); + } + + void InputTextMultiLineWidget::SetValue(std::string value) + { + mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ; + } + + //-------------------------------------------------------------------------- + void InputTextMultiLineWidget::OnTextUpdate(wxCommandEvent& event) + { + if (mBox->bbGetInputReactiveOnKeystroke()==2){ + mBox->bbSetOutputOut( GetValue() ); + mBox->bbSetInputIn( GetValue() ); + mBox->bbSignalOutputModification("Out"); + } + } + + //-------------------------------------------------------------------------- + void InputTextMultiLineWidget::OnTextEnter(wxCommandEvent& event) + { + if (mBox->bbGetInputReactiveOnKeystroke()==1){ + mBox->bbSetOutputOut( GetValue() ); + mBox->bbSetInputIn( GetValue() ); + mBox->bbSignalOutputModification("Out"); + } + } + + //-------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputTextMultiLine) +BBTK_BLACK_BOX_IMPLEMENTATION(InputTextMultiLine,bbtk::WxBlackBox); +//===== +// 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) +//===== +void InputTextMultiLine::Process() +{ + InputTextMultiLineWidget *w=(InputTextMultiLineWidget *)bbGetOutputWidget(); + if (w) + { + if (firsttime==true) + { + firsttime=false; + w->SetValue( bbGetInputIn().c_str() ); + } + w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) ); + bbSetOutputOut( w->GetValue() ); + } else { + bbSetOutputOut( "" ); + } +} +//===== +// 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) +//===== +void InputTextMultiLine::CreateWidget(wxWindow* parent) +{ + bbSetOutputWidget + ( (wxWindow*) new InputTextMultiLineWidget( this, //bbGetWxParent(), + parent, + bbtk::std2wx ( bbGetInputIn() ) , + bbtk::std2wx ( bbGetInputTitle() ) + ) + ); +} +//===== +// 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) +//===== +void InputTextMultiLine::bbUserSetDefaultValues() +{ + firsttime=true; + bbSetInputTitle(""); + bbSetInputIn(""); + bbSetOutputWidget(NULL); + bbSetInputReactiveOnKeystroke(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) +//===== +void InputTextMultiLine::bbUserInitializeProcessing() +{ + +} +//===== +// 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) +//===== +void InputTextMultiLine::bbUserFinalizeProcessing() +{ + +} +} +// EO namespace bbwx + + diff --git a/packages/wx/src/bbwxInputTextMultiLine.h b/packages/wx/src/bbwxInputTextMultiLine.h new file mode 100644 index 0000000..3bf0897 --- /dev/null +++ b/packages/wx/src/bbwxInputTextMultiLine.h @@ -0,0 +1,61 @@ +//===== +// 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) +//===== +#ifdef _USE_WXWIDGETS_ +#ifndef __bbwxInputTextMultiLine_h_INCLUDED__ +#define __bbwxInputTextMultiLine_h_INCLUDED__ + +#include "bbwx_EXPORT.h" +#include "bbtkWxBlackBox.h" + +namespace bbwx +{ + +class bbwx_EXPORT InputTextMultiLine + : + public bbtk::WxBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(InputTextMultiLine,bbtk::WxBlackBox); +//===== +// 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) +//===== + BBTK_DECLARE_INPUT(In,std::string); + BBTK_DECLARE_INPUT(Title,std::string); + BBTK_DECLARE_INPUT(ReactiveOnKeystroke,int); + BBTK_DECLARE_OUTPUT(Out,std::string); + + BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(wxWindow*); + + private: + bool firsttime; + +//===== +// 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) +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(InputTextMultiLine,bbtk::WxBlackBox); + BBTK_NAME("InputTextMultiLine"); + BBTK_AUTHOR("Info-Dev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("__CategoryBlackBox__"); + + BBTK_INPUT(InputTextMultiLine,In,"Initial text (default '')",std::string,""); + BBTK_INPUT(InputTextMultiLine,Title,"Title of the input zone (default '') ", std::string,""); + BBTK_INPUT(InputTextMultiLine,ReactiveOnKeystroke,"0 not event generated, 1 Enter event genereated, 2 All keys, (default '2') ", int,""); + BBTK_OUTPUT(InputTextMultiLine,Out,"Current text",std::string,""); + + +BBTK_END_DESCRIBE_BLACK_BOX(InputTextMultiLine); +//===== +// 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) +//===== +} +// EO namespace bbwx + +#endif // __bbwxInputTextMultiLine_h_INCLUDED__ +#endif // _USE_WXWIDGETS_ + diff --git a/packages/wx/src/bbwxInputTextPassword.cxx b/packages/wx/src/bbwxInputTextPassword.cxx new file mode 100644 index 0000000..d7fe02e --- /dev/null +++ b/packages/wx/src/bbwxInputTextPassword.cxx @@ -0,0 +1,194 @@ +//===== +// 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) +//===== +#include "bbwxInputTextPassword.h" +#include "bbwxPackage.h" +namespace bbwx +{ + + + //-------------------------------------------------------------------------- + class InputTextPasswordWidget : wxPanel + { + public: + InputTextPasswordWidget(InputTextPassword* box, wxWindow *parent, + wxString In, wxString title ); + ~InputTextPasswordWidget(); + + std::string GetValue(); + void SetValue(std::string value); + + void OnTextEnter(wxCommandEvent& event); + void OnTextUpdate(wxCommandEvent& event); + + void SetTitle(wxString); + + private: + InputTextPassword *mBox; + wxTextCtrl *mwxTextCtrl; + wxStaticText *mwxTitle; + }; + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + InputTextPasswordWidget::InputTextPasswordWidget(InputTextPassword* box, + wxWindow *parent, + wxString In, + wxString title ) + : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(box) + { + wxPanel *panel = this; + +//wxTE_PROCESS_ENTER +//wxTE_MULTILINE +//wxTE_PASSWORD + + mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,40) , wxTE_PASSWORD); + Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER, + (wxObjectEventFunction) + (wxEventFunction) + (wxCommandEventFunction) + (void (wxPanel::*)(wxCommandEvent&)) + &InputTextPasswordWidget::OnTextEnter ); + + Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED, + (wxObjectEventFunction) + (wxEventFunction) + (wxCommandEventFunction) + (void (wxPanel::*)(wxCommandEvent&)) + &InputTextPasswordWidget::OnTextUpdate ); + + wxFlexGridSizer *sizer = new wxFlexGridSizer(1); + mwxTitle = new wxStaticText(panel, -1, title ); + sizer-> Add( mwxTitle ); + sizer-> Add( mwxTextCtrl, 1, wxGROW ); + sizer-> AddGrowableCol(0); + + panel-> SetSizer(sizer); + panel-> SetAutoLayout(true); + panel-> Layout(); + + } + //------------------------------------------------------------------------- + + InputTextPasswordWidget::~InputTextPasswordWidget() + { + } + + //------------------------------------------------------------------------- + + + void InputTextPasswordWidget::SetTitle(wxString s) + { + mwxTitle->SetLabel(s); + } + + //------------------------------------------------------------------------- + std::string InputTextPasswordWidget::GetValue() + { + return bbtk::wx2std ( mwxTextCtrl->GetValue() ); + } + + void InputTextPasswordWidget::SetValue(std::string value) + { + mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ; + } + + //-------------------------------------------------------------------------- + void InputTextPasswordWidget::OnTextUpdate(wxCommandEvent& event) + { + if (mBox->bbGetInputReactiveOnKeystroke()==2){ + mBox->bbSetOutputOut( GetValue() ); + mBox->bbSetInputIn( GetValue() ); + mBox->bbSignalOutputModification("Out"); + } + } + + //-------------------------------------------------------------------------- + void InputTextPasswordWidget::OnTextEnter(wxCommandEvent& event) + { + if (mBox->bbGetInputReactiveOnKeystroke()==1){ + mBox->bbSetOutputOut( GetValue() ); + mBox->bbSetInputIn( GetValue() ); + mBox->bbSignalOutputModification("Out"); + } + } + + + //-------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + + + + + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputTextPassword) +BBTK_BLACK_BOX_IMPLEMENTATION(InputTextPassword,bbtk::WxBlackBox); +//===== +// 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) +//===== +void InputTextPassword::Process() +{ + InputTextPasswordWidget *w=(InputTextPasswordWidget *)bbGetOutputWidget(); + if (w) + { + if (firsttime==true) + { + firsttime=false; + w->SetValue( bbGetInputIn().c_str() ); + } + w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) ); + bbSetOutputOut( w->GetValue() ); + } else { + bbSetOutputOut( "" ); + } + +} +//===== +// 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) +//===== +void InputTextPassword::CreateWidget(wxWindow* parent) +{ + bbSetOutputWidget + ( (wxWindow*) new InputTextPasswordWidget( this, //bbGetWxParent(), + parent, + bbtk::std2wx ( bbGetInputIn() ) , + bbtk::std2wx ( bbGetInputTitle() ) + ) + ); +} +//===== +// 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) +//===== +void InputTextPassword::bbUserSetDefaultValues() +{ + firsttime=true; + bbSetInputTitle(""); + bbSetInputIn(""); + bbSetOutputWidget(NULL); + bbSetInputReactiveOnKeystroke(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) +//===== +void InputTextPassword::bbUserInitializeProcessing() +{ + +} +//===== +// 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) +//===== +void InputTextPassword::bbUserFinalizeProcessing() +{ + +} +} +// EO namespace bbwx + + diff --git a/packages/wx/src/bbwxInputTextPassword.h b/packages/wx/src/bbwxInputTextPassword.h new file mode 100644 index 0000000..ab8bbcd --- /dev/null +++ b/packages/wx/src/bbwxInputTextPassword.h @@ -0,0 +1,61 @@ +//===== +// 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) +//===== +#ifdef _USE_WXWIDGETS_ +#ifndef __bbwxInputTextPassword_h_INCLUDED__ +#define __bbwxInputTextPassword_h_INCLUDED__ + +#include "bbwx_EXPORT.h" +#include "bbtkWxBlackBox.h" + +namespace bbwx +{ + +class bbwx_EXPORT InputTextPassword + : + public bbtk::WxBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(InputTextPassword,bbtk::WxBlackBox); +//===== +// 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) +//===== + BBTK_DECLARE_INPUT(In,std::string); + BBTK_DECLARE_INPUT(Title,std::string); + BBTK_DECLARE_INPUT(ReactiveOnKeystroke,int); + BBTK_DECLARE_OUTPUT(Out,std::string); BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(wxWindow*); + + + private: + bool firsttime; + + + +//===== +// 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) +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(InputTextPassword,bbtk::WxBlackBox); + BBTK_NAME("InputTextPassword"); + BBTK_AUTHOR("Info-Dev"); + BBTK_DESCRIPTION("A zone in which the user can enter a text (wxTextCtrl)"); + BBTK_CATEGORY("__CategoryBlackBox__"); + + BBTK_INPUT(InputTextPassword,In,"Initial text (default '')",std::string,""); + BBTK_INPUT(InputTextPassword,Title,"Title of the input zone (default '') ", std::string,""); + BBTK_INPUT(InputTextPassword,ReactiveOnKeystroke,"0 not event generated, 1 Enter event genereated, 2 All keys, (default '2') ", int,""); + BBTK_OUTPUT(InputTextPassword,Out,"Current text",std::string,""); + +BBTK_END_DESCRIBE_BLACK_BOX(InputTextPassword); +//===== +// 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) +//===== +} +// EO namespace bbwx + +#endif // __bbwxInputTextPassword_h_INCLUDED__ +#endif // _USE_WXWIDGETS_ +