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()) );
125 mBox->bbSetOutputOut("");
126 mBox->bbSignalOutputModification(std::string("Out"));
127 mBox->bbSetInputDefaultDir("");
132 void ButtonSelectFilesDirectoryWidget::OnButton( wxEvent& )
134 printf("EED ButtonSelectFilesDirectoryWidget::OnButton Start\n");
135 if (mBox->bbGetInputType()==0)
138 } else if (mBox->bbGetInputType()==1){
142 printf("EED ButtonSelectFilesDirectoryWidget::OnButton End\n");
146 //--------------------------------------------------------------------------
147 void ButtonSelectFilesDirectoryWidget::SetLabel(wxString title)
149 mwxButton->SetLabel(title);
157 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ButtonSelectFilesDirectory)
158 BBTK_BLACK_BOX_IMPLEMENTATION(ButtonSelectFilesDirectory,bbtk::WxBlackBox);
160 // 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)
162 void ButtonSelectFilesDirectory::Process()
165 ButtonSelectFilesDirectoryWidget* w = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget();
173 // 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)
175 void ButtonSelectFilesDirectory::CreateWidget(wxWindow* parent)
179 ( new ButtonSelectFilesDirectoryWidget ( this, //bbGetWxParent(),
181 bbtk::std2wx(bbGetInputLabel()) ) );
186 // 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)
188 void ButtonSelectFilesDirectory::bbUserSetDefaultValues()
191 bbSetInputOpenSave("Open");
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)
196 void ButtonSelectFilesDirectory::bbUserInitializeProcessing()
201 // 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)
203 void ButtonSelectFilesDirectory::bbUserFinalizeProcessing()
208 void ButtonSelectFilesDirectory::UpdateLabel()
210 ButtonSelectFilesDirectoryWidget* wxwidget = (ButtonSelectFilesDirectoryWidget*)bbGetOutputWidget();
211 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
216 }// EO namespace bbwx