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)
4 #include "bbwxButtonSelectFilesDirectory.h"
5 #include "bbwxPackage.h"
7 #include <wx/filedlg.h>
15 //--------------------------------------------------------------------------
16 class ButtonSelectFilesDirectoryWidget : public wxPanel
19 ButtonSelectFilesDirectoryWidget(ButtonSelectFilesDirectory* box, wxWindow *parent,
21 ~ButtonSelectFilesDirectoryWidget();
22 void OnButton( wxEvent& );
23 void SetLabel(wxString title);
24 void SetColour(wxColour color);
27 void SelectDirectory();
30 ButtonSelectFilesDirectory *mBox;
34 //--------------------------------------------------------------------------
35 //--------------------------------------------------------------------------
37 ButtonSelectFilesDirectoryWidget::ButtonSelectFilesDirectoryWidget(ButtonSelectFilesDirectory* box,
40 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
43 wxPanel *panel = this;
44 mwxButton = new wxButton( panel, -1, title);
45 Connect( mwxButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
46 (wxObjectEventFunction)
47 (void (wxPanel::*)(wxEvent&))
48 &ButtonSelectFilesDirectoryWidget::OnButton );
49 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
50 sizer -> Add( mwxButton,1,wxGROW | wxALL,10 );
51 sizer -> AddGrowableCol(0);
52 panel -> SetSizer(sizer);
53 panel -> SetAutoLayout(true);
57 ButtonSelectFilesDirectoryWidget::~ButtonSelectFilesDirectoryWidget()
62 void ButtonSelectFilesDirectoryWidget::SelectFiles( )
66 if (mBox->bbGetInputOpenSave()=="Save")
68 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
69 #if wxMAJOR_VERSION <= 2
70 style = wxSAVE | wxOVERWRITE_PROMPT;
72 style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT;
75 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
76 #if wxMAJOR_VERSION <= 2
77 style = wxOPEN | wxFILE_MUST_EXIST;
79 style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
83 std::string wc(mBox->bbGetInputWildcard());
86 wc = "*"; // Any file must be shown
89 wxFileDialog* FD = new wxFileDialog( 0,
90 bbtk::std2wx(mBox->bbGetInputMessage()),
91 bbtk::std2wx(mBox->bbGetInputDefaultDir()),
92 bbtk::std2wx(mBox->bbGetInputDefaultFile()),
98 int result_FD = FD->ShowModal();
100 // This line is need it by windows //EED
101 FD->SetReturnCode( result_FD );
103 if (FD->GetReturnCode()==wxID_OK)
105 mBox->bbSetOutputOut( bbtk::wx2std (FD->GetPath()) );
106 mBox->bbSignalOutputModification(std::string("Out"));
108 mBox->bbSetOutputOut(" ");
109 mBox->bbSignalOutputModification(std::string("Out"));
113 void ButtonSelectFilesDirectoryWidget:: SelectDirectory()
115 wxDirDialog* FD = new wxDirDialog( 0,
116 bbtk::std2wx(mBox->bbGetInputMessage()),
117 bbtk::std2wx(mBox->bbGetInputDefaultDir()));
119 if (FD->ShowModal()==wxID_OK)
121 mBox->bbSetOutputOut( bbtk::wx2std (FD->GetPath()) );
122 mBox->bbSignalOutputModification(std::string("Out"));
123 mBox->bbSetInputDefaultDir( bbtk::wx2std (FD->GetPath()) );
127 void ButtonSelectFilesDirectoryWidget::OnButton( wxEvent& )
129 if (mBox->bbGetInputType()==0)
132 } else if (mBox->bbGetInputType()==1){
137 //--------------------------------------------------------------------------
138 void ButtonSelectFilesDirectoryWidget::SetLabel(wxString title)
140 mwxButton->SetLabel(title);
148 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ButtonSelectFilesDirectory)
149 BBTK_BLACK_BOX_IMPLEMENTATION(ButtonSelectFilesDirectory,bbtk::WxBlackBox);
151 // 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)
153 void ButtonSelectFilesDirectory::Process()
156 ButtonSelectFilesDirectoryWidget* w = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget();
164 // 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)
166 void ButtonSelectFilesDirectory::CreateWidget(wxWindow* parent)
170 ( new ButtonSelectFilesDirectoryWidget ( this, //bbGetWxParent(),
172 bbtk::std2wx(bbGetInputLabel()) ) );
177 // 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 void ButtonSelectFilesDirectory::bbUserSetDefaultValues()
182 bbSetInputOpenSave("Open");
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)
187 void ButtonSelectFilesDirectory::bbUserInitializeProcessing()
192 // 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)
194 void ButtonSelectFilesDirectory::bbUserFinalizeProcessing()
199 void ButtonSelectFilesDirectory::UpdateLabel()
201 ButtonSelectFilesDirectoryWidget* wxwidget = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget();
202 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
207 }// EO namespace bbwx