1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation of ecFolderDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
47 #pragma implementation "folderdlg.cpp"
56 #include "configtool.h"
57 #include "folderdlg.h"
59 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
63 BEGIN_EVENT_TABLE(ecFolderDialog, ecDialog)
64 EVT_BUTTON( wxID_OK, ecFolderDialog::OnOK )
65 EVT_BUTTON( wxID_CANCEL, ecFolderDialog::OnCancel )
66 EVT_BUTTON( ecID_FOLDER_DIALOG_BROWSE, ecFolderDialog::OnBrowse )
67 EVT_INIT_DIALOG(ecFolderDialog::OnInitDialog)
70 ecFolderDialog::ecFolderDialog( const wxString& defaultPath, const wxArrayString& paths,
71 const wxString& msg, wxWindow *parent, wxWindowID id, const wxString &title,
72 const wxPoint &position, const wxSize& size, long style )
74 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
76 m_defaultPath = defaultPath;
80 wxDialog::Create( parent, id, title, position, size, style );
87 void ecFolderDialog::OnInitDialog(wxInitDialogEvent& event)
89 wxComboBox* comboBox = (wxComboBox*) FindWindow(ecID_FOLDER_DIALOG_PATHS);
91 wxASSERT (comboBox != NULL) ;
94 for (i = (size_t) 0; i < m_paths.GetCount(); i++)
96 comboBox->Append(m_paths[i]);
97 if (m_paths[i] == m_defaultPath)
98 comboBox->SetSelection(i);
100 if (comboBox->FindString(m_defaultPath) == -1)
101 comboBox->Append(m_defaultPath);
103 if (comboBox->GetSelection() == -1 && comboBox->Number() > 0)
104 comboBox->SetSelection(0);
106 comboBox->SetFocus();
108 wxStaticText* staticText = (wxStaticText*) FindWindow(ecID_FOLDER_DIALOG_MSG);
110 wxASSERT ( staticText != NULL );
112 staticText->SetLabel(m_message);
115 void ecFolderDialog::OnOK(wxCommandEvent &event)
117 wxComboBox* comboBox = (wxComboBox*) FindWindow(ecID_FOLDER_DIALOG_PATHS);
118 m_defaultPath = comboBox->GetValue();
123 void ecFolderDialog::OnCancel(wxCommandEvent &event)
128 void ecFolderDialog::OnBrowse(wxCommandEvent &event)
130 wxComboBox* comboBox = (wxComboBox*) FindWindow(ecID_FOLDER_DIALOG_PATHS);
132 wxString value = comboBox->GetValue();
134 wxDirDialog dirDialog(this, wxT("Choose a directory"), value);
135 if (dirDialog.ShowModal() == wxID_OK)
137 comboBox->SetValue(dirDialog.GetPath());
141 void ecFolderDialog::CreateControls()
143 wxWindow* parent = this;
145 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
147 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
149 wxStaticText *item2 = new wxStaticText( parent, ecID_FOLDER_DIALOG_MSG, _("text"), wxDefaultPosition, wxSize(-1,70), wxST_NO_AUTORESIZE );
150 item1->Add( item2, 10, wxALIGN_CENTER_HORIZONTAL|wxALL, 10 );
152 wxSizer *item3 = new wxBoxSizer( wxVERTICAL );
154 wxButton *item4 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
156 item3->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
158 wxButton *item5 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
159 item3->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
161 wxButton *item6 = new wxButton( parent, ecID_FOLDER_DIALOG_BROWSE, _("&Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
162 item3->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
164 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
166 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
168 wxString *strs7 = (wxString*) NULL;
169 wxComboBox *item7 = new wxComboBox( parent, ecID_FOLDER_DIALOG_PATHS, "", wxDefaultPosition, wxSize(470,-1), 0, strs7, wxCB_DROPDOWN );
170 item0->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
172 parent->SetAutoLayout( TRUE );
173 parent->SetSizer( item0 );
175 item0->Fit( parent );
176 item0->SetSizeHints( parent );
179 //parent->FindWindow( ecID_LICENSE_TEXT )->SetValidator(wxGenericValidator(& m_licenseText));
181 // Add context-sensitive help text
182 parent->FindWindow( wxID_OK )->SetHelpText(_("Confirms your folder selection."));
183 parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Cancels the operation."));
186 //parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));