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####
25 // buildoptionsdlg.cpp :
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation file for ecBuildOptionsDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "buildoptionsdlg.h"
57 // Includes other headers for precompiled compilation
65 #include "bitmaps/package_open.xpm"
66 #include "bitmaps/package_version.xpm"
69 #include "wx/cshelp.h"
71 #include "configtool.h"
72 #include "configtooldoc.h"
73 #include "buildoptionsdlg.h"
76 BEGIN_EVENT_TABLE(ecBuildOptionsDialog, ecDialog)
77 EVT_BUTTON(wxID_OK, ecBuildOptionsDialog::OnOK)
78 EVT_BUTTON(wxID_CANCEL, ecBuildOptionsDialog::OnCancel)
79 EVT_CHOICE(ecID_BUILD_OPTIONS_CATEGORY, ecBuildOptionsDialog::OnSelCategory)
80 EVT_TREE_SEL_CHANGED(ecID_BUILD_OPTIONS_PACKAGES_TREE, ecBuildOptionsDialog::OnSelTree)
81 EVT_INIT_DIALOG(ecBuildOptionsDialog::OnInitDialog)
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
89 ecBuildOptionsDialog::ecBuildOptionsDialog(wxWindow* parent):
90 m_imageList(16, 16, 1),
91 m_arEntries(wxGetApp().GetConfigToolDoc()->GetBuildInfo().entries)
94 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
96 ecDialog::Create(parent, ecID_BUILD_OPTIONS_DIALOG, _("Build Options"),
97 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
101 m_imageList.Add(wxICON(package_open));
102 m_imageList.Add(wxICON(package_version));
103 m_treeCtrl->SetImageList(& m_imageList);
106 // Add some dummy items
107 wxTreeItemId rootId = m_treeCtrl->AddRoot(_("Configuration"), 0, -1);
108 m_treeCtrl->AppendItem(rootId, _("eCos HAL"), 0, -1);
109 m_treeCtrl->AppendItem(rootId, _("I/O sub-system"), 0, -1);
110 m_treeCtrl->AppendItem(rootId, _("Serial device drivers"), 0, -1);
111 m_treeCtrl->AppendItem(rootId, _("Infrastructure"), 0, -1);
112 m_treeCtrl->AppendItem(rootId, _("eCos kernel"), 0, -1);
113 m_treeCtrl->AppendItem(rootId, _("C library"), 0, -1);
115 m_treeCtrl->Expand(rootId);
121 ecBuildOptionsDialog::~ecBuildOptionsDialog()
123 m_treeCtrl->SetImageList(NULL);
126 void ecBuildOptionsDialog::OnInitDialog(wxInitDialogEvent& event)
128 m_treeCtrl->DeleteAllItems();
129 //wxTreeItemId rootId = m_treeCtrl->AddRoot(_("Configuration"), 0, -1);
130 CreateItems(wxGetApp().GetConfigToolDoc()->GetFirstItem(), wxTreeItemId());
132 m_treeCtrl->Expand(m_treeCtrl->GetRootItem());
133 ((wxChoice*) FindWindow(ecID_BUILD_OPTIONS_CATEGORY))->SetSelection(0);
136 void ecBuildOptionsDialog::CreateControls(wxWindow* parent)
138 m_treeCtrl = new wxTreeCtrl(parent, ecID_BUILD_OPTIONS_PACKAGES_TREE,
139 wxDefaultPosition, wxSize(280, 220), wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
141 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
143 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
145 wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, _("&Category:"), wxDefaultPosition, wxDefaultSize, 0 );
146 item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
153 wxChoice *item3 = new wxChoice( parent, ecID_BUILD_OPTIONS_CATEGORY, wxDefaultPosition, wxSize(90,-1), 2, strs3, 0 );
154 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
156 item1->Add( 20, 20, 20, wxALIGN_CENTRE|wxALL, 5 );
158 wxButton *item4 = new wxButton( parent, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
160 item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
162 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
164 wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
166 wxSizer *item6 = new wxBoxSizer( wxVERTICAL );
168 wxStaticText *item7 = new wxStaticText( parent, wxID_STATIC, _("&Packages:"), wxDefaultPosition, wxDefaultSize, 0 );
169 item6->Add( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
171 wxWindow *item8 = parent->FindWindow( ecID_BUILD_OPTIONS_PACKAGES_TREE );
173 item6->Add( item8, 10, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
175 item5->Add( item6, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
177 wxSizer *item9 = new wxBoxSizer( wxVERTICAL );
179 wxStaticText *item10 = new wxStaticText( parent, wxID_STATIC, _("&Flags:"), wxDefaultPosition, wxDefaultSize, 0 );
180 item9->Add( item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
182 wxString *strs11 = (wxString*) NULL;
183 wxListBox *item11 = new wxListBox( parent, ecID_BUILD_OPTIONS_FLAGS, wxDefaultPosition, wxSize(170,240), 0, strs11, 0 );
184 item9->Add( item11, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
186 item5->Add( item9, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
188 item0->Add( item5, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
191 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
193 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
195 wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, _("&Category:"), wxDefaultPosition, wxDefaultSize, 0 );
196 item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
203 wxChoice *item3 = new wxChoice( parent, ecID_BUILD_OPTIONS_CATEGORY, wxDefaultPosition, wxSize(90,-1), 2, strs3, 0 );
204 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
206 item1->Add( 20, 20, 20, wxALIGN_CENTRE|wxALL, 5 );
208 wxButton *item4 = new wxButton( parent, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
210 item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
212 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
214 wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
216 wxSizer *item6 = new wxBoxSizer( wxVERTICAL );
218 wxStaticText *item7 = new wxStaticText( parent, wxID_STATIC, _("&Packages:"), wxDefaultPosition, wxDefaultSize, 0 );
219 item6->Add( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
221 wxWindow *item8 = parent->FindWindow( ecID_BUILD_OPTIONS_PACKAGES_TREE );
223 item6->Add( item8, 10, wxALIGN_CENTRE|wxALL, 5 );
225 item5->Add( item6, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
227 wxSizer *item9 = new wxBoxSizer( wxVERTICAL );
229 wxStaticText *item10 = new wxStaticText( parent, wxID_STATIC, _("&Flags:"), wxDefaultPosition, wxDefaultSize, 0 );
230 item9->Add( item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
232 wxString *strs11 = (wxString*) NULL;
233 wxListBox *item11 = new wxListBox( parent, ecID_BUILD_OPTIONS_FLAGS, wxDefaultPosition, wxSize(170,240), 0, strs11, 0 );
234 item9->Add( item11, 0, wxALIGN_CENTRE|wxALL, 5 );
236 item5->Add( item9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
238 item0->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
242 wxButton *contextButton = new wxContextHelpButton( parent );
243 item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
246 parent->SetAutoLayout( TRUE );
247 parent->SetSizer( item0 );
249 item0->Fit( parent );
250 item0->SetSizeHints( parent );
252 // Add context-sensitive help text
253 parent->FindWindow( ecID_BUILD_OPTIONS_CATEGORY )->SetHelpText(_("Selects the categorty of build flags for which options are to be displayed."));
254 parent->FindWindow( ecID_BUILD_OPTIONS_PACKAGES_TREE )->SetHelpText(_("Displays a view of the packages currently included in the configuration."));
255 parent->FindWindow( ecID_BUILD_OPTIONS_FLAGS )->SetHelpText(_("Lists the flags defined for the packages selected in the adjacent Packages window."));
256 parent->FindWindow( wxID_OK )->SetHelpText(_("Closes the dialog and saves any changes you have made."));
257 parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Closes the dialog without saving any changes you have made."));
260 parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
265 void ecBuildOptionsDialog::OnCancel(wxCommandEvent& event)
270 void ecBuildOptionsDialog::OnOK(wxCommandEvent& event)
275 void ecBuildOptionsDialog::CreateItems(ecConfigItem *pti, wxTreeItemId hParent)
277 if (pti->IsPackage() || !hParent.IsOk())
281 if (!hParent.IsOk()) // pti->GetItemNameOrMacro() == _("Configuration"))
282 h = m_treeCtrl->AddRoot(pti->GetItemNameOrMacro(), 0, -1);
284 h = m_treeCtrl->AppendItem(hParent, pti->GetItemNameOrMacro(), 0, -1);
286 m_treeCtrl->SetItemData(h, new ecBuildOptionsData(pti));
287 // m_Tree.SetItemImage(h,18,18);
288 for(ecConfigItem *pChild=pti->FirstChild();pChild;pChild=pChild->NextSibling()){
289 CreateItems(pChild,h);
294 void ecBuildOptionsDialog::Redisplay (wxTreeItemId item)
296 ecConfigItem *pti= ((ecBuildOptionsData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
298 const CdlValuable valuable = pti->GetCdlValuable();
300 const CdlBuildInfo_Loadable *pe=NULL;
302 const char *pszname=valuable->get_name().c_str();
303 for(EntriesArray::size_type j=0;j<m_arEntries.size();j++){
304 if(0==strcmp(m_arEntries[j].name.c_str(),pszname)){
311 wxString strCat = ((wxChoice*) FindWindow(ecID_BUILD_OPTIONS_CATEGORY))->GetStringSelection();
313 const wxString strFlags=get_flags(wxGetApp().GetConfigToolDoc()->GetCdlConfig(), pe, ecUtils::UnicodeToStdStr(strCat)).c_str();
316 ecUtils::Chop(strFlags,ar, wxT(' '), FALSE, FALSE);
318 wxListBox* listBox = (wxListBox*) FindWindow( ecID_BUILD_OPTIONS_FLAGS );
321 bool bRedraw=(listBox->Number() != ar.GetCount());
324 for(int i=0;i<ar.GetCount();i++){
325 wxString strOld = listBox->GetString(i);
336 for(int i=0;i<ar.GetCount();i++){
337 listBox->Append(ar[i]);
342 void ecBuildOptionsDialog::OnSelCategory(wxCommandEvent& event)
344 wxTreeItemId item = m_treeCtrl->GetSelection();
351 void ecBuildOptionsDialog::OnSelTree(wxTreeEvent& event)
353 wxTreeItemId item = m_treeCtrl->GetSelection();