From a4a72ff9c3c2c8c42dc101b8a9bb34cc8a5ecc21 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 29 Nov 2021 11:44:05 +0100 Subject: [PATCH] #3475 ButtonSelectFilesDirectory box wx --- .../wx/src/bbwxButtonSelectFilesDirectory.cxx | 218 ++++++++++++++++++ .../wx/src/bbwxButtonSelectFilesDirectory.h | 74 ++++++ packages/wx/src/bbwxFileSelector.h | 3 +- 3 files changed, 293 insertions(+), 2 deletions(-) create mode 100644 packages/wx/src/bbwxButtonSelectFilesDirectory.cxx create mode 100644 packages/wx/src/bbwxButtonSelectFilesDirectory.h diff --git a/packages/wx/src/bbwxButtonSelectFilesDirectory.cxx b/packages/wx/src/bbwxButtonSelectFilesDirectory.cxx new file mode 100644 index 0000000..ad26a75 --- /dev/null +++ b/packages/wx/src/bbwxButtonSelectFilesDirectory.cxx @@ -0,0 +1,218 @@ +//===== +// 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 "bbwxButtonSelectFilesDirectory.h" +#include "bbwxPackage.h" + +#include +#include + + +namespace bbwx +{ + + + //-------------------------------------------------------------------------- + class ButtonSelectFilesDirectoryWidget : public wxPanel + { + public: + ButtonSelectFilesDirectoryWidget(ButtonSelectFilesDirectory* box, wxWindow *parent, + wxString title); + ~ButtonSelectFilesDirectoryWidget(); + void OnButton( wxEvent& ); + void SetLabel(wxString title); + void SetColour(wxColour color); + + private: + void SelectDirectory(); + void SelectFiles(); + + ButtonSelectFilesDirectory *mBox; + wxButton *mwxButton; + }; + + //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + ButtonSelectFilesDirectoryWidget::ButtonSelectFilesDirectoryWidget(ButtonSelectFilesDirectory* box, + wxWindow *parent, + wxString title ) + : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), + mBox(box) + { + wxPanel *panel = this; + mwxButton = new wxButton( panel, -1, title); + Connect( mwxButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , + (wxObjectEventFunction) + (void (wxPanel::*)(wxEvent&)) + &ButtonSelectFilesDirectoryWidget::OnButton ); + wxFlexGridSizer *sizer = new wxFlexGridSizer(1); + sizer -> Add( mwxButton,1,wxGROW | wxALL,10 ); + sizer -> AddGrowableCol(0); + panel -> SetSizer(sizer); + panel -> SetAutoLayout(true); + panel -> Layout(); + } + + ButtonSelectFilesDirectoryWidget::~ButtonSelectFilesDirectoryWidget() + { + } + + + void ButtonSelectFilesDirectoryWidget::SelectFiles( ) + { + + long style; + if (mBox->bbGetInputOpenSave()=="Save") + { +//EED 2017-09-16 Migration wxWidgets 2.8 to 3.0 +#if wxMAJOR_VERSION <= 2 + style = wxSAVE | wxOVERWRITE_PROMPT; +#else + style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT; +#endif + } else { +//EED 2017-09-16 Migration wxWidgets 2.8 to 3.0 +#if wxMAJOR_VERSION <= 2 + style = wxOPEN | wxFILE_MUST_EXIST; +#else + style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; +#endif + } + + std::string wc(mBox->bbGetInputWildcard()); + if (wc=="") + { + wc = "*"; // Any file must be shown + } + + wxFileDialog* FD = new wxFileDialog( 0, + bbtk::std2wx(mBox->bbGetInputMessage()), + bbtk::std2wx(mBox->bbGetInputDefaultDir()), + bbtk::std2wx(mBox->bbGetInputDefaultFile()), + bbtk::std2wx(wc), + style, + wxDefaultPosition); +//EED + + int result_FD = FD->ShowModal(); + + // This line is need it by windows //EED + FD->SetReturnCode( result_FD ); + + if (FD->GetReturnCode()==wxID_OK) + { + mBox->bbSetOutputOut( bbtk::wx2std (FD->GetPath()) ); + mBox->bbSignalOutputModification(std::string("Out")); + } else { + mBox->bbSetOutputOut(" "); + mBox->bbSignalOutputModification(std::string("Out")); + } + } + +void ButtonSelectFilesDirectoryWidget:: SelectDirectory() +{ + wxDirDialog* FD = new wxDirDialog( 0, + bbtk::std2wx(mBox->bbGetInputMessage()), + bbtk::std2wx(mBox->bbGetInputDefaultDir())); + + if (FD->ShowModal()==wxID_OK) + { + mBox->bbSetOutputOut( bbtk::wx2std (FD->GetPath()) ); + mBox->bbSignalOutputModification(std::string("Out")); + mBox->bbSetInputDefaultDir( bbtk::wx2std (FD->GetPath()) ); + } else { + mBox->bbSetOutputOut(""); + mBox->bbSignalOutputModification(std::string("Out")); + mBox->bbSetInputDefaultDir(""); + } + +} + +void ButtonSelectFilesDirectoryWidget::OnButton( wxEvent& ) +{ + printf("EED ButtonSelectFilesDirectoryWidget::OnButton Start\n"); + if (mBox->bbGetInputType()==0) + { + SelectFiles(); + } else if (mBox->bbGetInputType()==1){ + SelectDirectory(); + } + + printf("EED ButtonSelectFilesDirectoryWidget::OnButton End\n"); + +} + + //-------------------------------------------------------------------------- + void ButtonSelectFilesDirectoryWidget::SetLabel(wxString title) + { + mwxButton->SetLabel(title); + } + + + + + + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ButtonSelectFilesDirectory) +BBTK_BLACK_BOX_IMPLEMENTATION(ButtonSelectFilesDirectory,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 ButtonSelectFilesDirectory::Process() +{ + + ButtonSelectFilesDirectoryWidget* w = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget(); + if (w) + { + UpdateLabel(); + } + +} +//===== +// 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 ButtonSelectFilesDirectory::CreateWidget(wxWindow* parent) +{ + + bbSetOutputWidget + ( new ButtonSelectFilesDirectoryWidget ( this, //bbGetWxParent(), + parent, + bbtk::std2wx(bbGetInputLabel()) ) ); + + +} +//===== +// 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 ButtonSelectFilesDirectory::bbUserSetDefaultValues() +{ + bbSetInputType(0); + bbSetInputOpenSave("Open"); +} +//===== +// 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 ButtonSelectFilesDirectory::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 ButtonSelectFilesDirectory::bbUserFinalizeProcessing() +{ + +} + +void ButtonSelectFilesDirectory::UpdateLabel() +{ + ButtonSelectFilesDirectoryWidget* wxwidget = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget(); + wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) ); +} + + + +}// EO namespace bbwx + + diff --git a/packages/wx/src/bbwxButtonSelectFilesDirectory.h b/packages/wx/src/bbwxButtonSelectFilesDirectory.h new file mode 100644 index 0000000..28f55ca --- /dev/null +++ b/packages/wx/src/bbwxButtonSelectFilesDirectory.h @@ -0,0 +1,74 @@ +//===== +// 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 __bbwxButtonSelectFilesDirectory_h_INCLUDED__ +#define __bbwxButtonSelectFilesDirectory_h_INCLUDED__ + +#include "bbwx_EXPORT.h" +#include "bbtkWxBlackBox.h" + +namespace bbwx +{ + +class bbwx_EXPORT ButtonSelectFilesDirectory + : + public bbtk::WxBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ButtonSelectFilesDirectory,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) +//===== + friend class ButtonSelectFilesDirectoryWidget; + + BBTK_DECLARE_INPUT(Type,int); + BBTK_DECLARE_INPUT(Label,std::string); + BBTK_DECLARE_INPUT(Wildcard,std::string); + BBTK_DECLARE_INPUT(OpenSave,std::string); + BBTK_DECLARE_INPUT(Title,std::string); + BBTK_DECLARE_INPUT(Message,std::string); + BBTK_DECLARE_INPUT(DefaultDir,std::string); + BBTK_DECLARE_INPUT(DefaultFile,std::string); + BBTK_DECLARE_OUTPUT(Out,std::string); + BBTK_PROCESS(Process); + void Process(); + BBTK_CREATE_WIDGET(CreateWidget); + void CreateWidget(wxWindow*); + + protected: + + + private: + void UpdateLabel(); + + +//===== +// 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(ButtonSelectFilesDirectory,bbtk::WxBlackBox); + BBTK_NAME("ButtonSelectFilesDirectory"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("__CategoryBlackBox__"); + BBTK_INPUT(ButtonSelectFilesDirectory,Type,"(default 0) 0:Files 1:Directory",int,""); + BBTK_INPUT(ButtonSelectFilesDirectory,Label,"Label",std::string,""); + BBTK_INPUT(ButtonSelectFilesDirectory,Wildcard,"A wildcard, such as \"*.*\" or \"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif\"",std::string,"wildcard"); + BBTK_INPUT(ButtonSelectFilesDirectory,OpenSave,"(Just for Type 0 -Files ) Open for an open dialog (default) / Save for a save dialog",std::string,""); + BBTK_INPUT(ButtonSelectFilesDirectory,Title,"Title of the dialog",std::string,""); + BBTK_INPUT(ButtonSelectFilesDirectory,Message,"Message to show on the dialog",std::string,""); + BBTK_INPUT(ButtonSelectFilesDirectory,DefaultDir,"The default directory",std::string,""); + BBTK_INPUT(ButtonSelectFilesDirectory,DefaultFile,"The default filename",std::string,"file name"); + + BBTK_OUTPUT(ButtonSelectFilesDirectory,Out,"File/Directory string",std::string,""); +BBTK_END_DESCRIBE_BLACK_BOX(ButtonSelectFilesDirectory); +//===== +// 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 // __bbwxButtonSelectFilesDirectory_h_INCLUDED__ +#endif // _USE_WXWIDGETS_ + diff --git a/packages/wx/src/bbwxFileSelector.h b/packages/wx/src/bbwxFileSelector.h index 89e5b8a..b62506b 100644 --- a/packages/wx/src/bbwxFileSelector.h +++ b/packages/wx/src/bbwxFileSelector.h @@ -93,8 +93,7 @@ namespace bbwx BBTK_CATEGORY("widget, Selector"); BBTK_DESCRIPTION("Pops up a file selection dialog for reading or saving (wxFileDialog)"); BBTK_INPUT(FileSelector,Title,"Title of the dialog",std::string,""); - BBTK_INPUT(FileSelector,Message,"Message to show on the dialog", - std::string,""); + BBTK_INPUT(FileSelector,Message,"Message to show on the dialog",std::string,""); BBTK_INPUT(FileSelector,DefaultDir,"The default directory",std::string,""); BBTK_INPUT(FileSelector,DefaultFile,"The default filename",std::string,"file name"); BBTK_INPUT(FileSelector,Wildcard,"A wildcard, such as \"*.*\" or \"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif\"",std::string,"wildcard"); -- 2.45.1