//===== // 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()) ); } // if OK } void ButtonSelectFilesDirectoryWidget::OnButton( wxEvent& ) { if (mBox->bbGetInputType()==0) { SelectFiles(); } else if (mBox->bbGetInputType()==1){ SelectDirectory(); } } //-------------------------------------------------------------------------- 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