]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/configtool/standalone/wxwin/buildoptionsdlg.cpp
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / tools / src / tools / configtool / standalone / wxwin / buildoptionsdlg.cpp
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
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)
11 // any later version.
12 //
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
16 // more details.
17 //
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.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 // buildoptionsdlg.cpp :
26 //
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
29 //
30 // Author(s):   julians
31 // Contact(s):  julians
32 // Date:        2000/09/27
33 // Version:     $Id: buildoptionsdlg.cpp,v 1.2 2001/03/23 13:38:04 julians Exp $
34 // Purpose:
35 // Description: Implementation file for ecBuildOptionsDialog
36 // Requires:
37 // Provides:
38 // See also:
39 // Known bugs:
40 // Usage:
41 //
42 //####DESCRIPTIONEND####
43 //
44 //===========================================================================
45
46 // ============================================================================
47 // declarations
48 // ============================================================================
49
50 // ----------------------------------------------------------------------------
51 // headers
52 // ----------------------------------------------------------------------------
53 #ifdef __GNUG__
54 #pragma implementation "buildoptionsdlg.h"
55 #endif
56
57 // Includes other headers for precompiled compilation
58 #include "ecpch.h"
59
60 #ifdef __BORLANDC__
61 #pragma hdrstop
62 #endif
63
64 #ifdef __WXGTK__
65 #include "bitmaps/package_open.xpm"
66 #include "bitmaps/package_version.xpm"
67 #endif
68
69 #include "wx/cshelp.h"
70
71 #include "configtool.h"
72 #include "configtooldoc.h"
73 #include "buildoptionsdlg.h"
74 #include "flags.hxx"
75
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)
82 END_EVENT_TABLE()
83
84 // ----------------------------------------------------------------------------
85 // main frame
86 // ----------------------------------------------------------------------------
87
88 // Frame constructor
89 ecBuildOptionsDialog::ecBuildOptionsDialog(wxWindow* parent):
90     m_imageList(16, 16, 1),
91     m_arEntries(wxGetApp().GetConfigToolDoc()->GetBuildInfo().entries)
92
93 {
94     SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
95
96     ecDialog::Create(parent, ecID_BUILD_OPTIONS_DIALOG, _("Build Options"),
97         wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
98
99     CreateControls(this);
100
101     m_imageList.Add(wxICON(package_open));
102     m_imageList.Add(wxICON(package_version));
103     m_treeCtrl->SetImageList(& m_imageList);
104
105 #if 0
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);
114
115     m_treeCtrl->Expand(rootId);
116 #endif
117
118     Centre(wxBOTH);
119 }
120
121 ecBuildOptionsDialog::~ecBuildOptionsDialog()
122 {
123     m_treeCtrl->SetImageList(NULL);
124 }
125
126 void ecBuildOptionsDialog::OnInitDialog(wxInitDialogEvent& event)
127 {
128     m_treeCtrl->DeleteAllItems();
129     //wxTreeItemId rootId = m_treeCtrl->AddRoot(_("Configuration"), 0, -1);
130     CreateItems(wxGetApp().GetConfigToolDoc()->GetFirstItem(), wxTreeItemId());
131
132     m_treeCtrl->Expand(m_treeCtrl->GetRootItem());
133     ((wxChoice*) FindWindow(ecID_BUILD_OPTIONS_CATEGORY))->SetSelection(0);
134 }
135
136 void ecBuildOptionsDialog::CreateControls(wxWindow* parent)
137 {
138     m_treeCtrl = new wxTreeCtrl(parent, ecID_BUILD_OPTIONS_PACKAGES_TREE,
139         wxDefaultPosition, wxSize(280, 220), wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
140
141     wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
142
143     wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
144
145     wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, _("&Category:"), wxDefaultPosition, wxDefaultSize, 0 );
146     item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
147
148     wxString strs3[] = 
149     {
150         _("CFLAGS"), 
151         _("LDFLAGS")
152     };
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 );
155
156     item1->Add( 20, 20, 20, wxALIGN_CENTRE|wxALL, 5 );
157
158     wxButton *item4 = new wxButton( parent, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
159     item4->SetDefault();
160     item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
161
162     item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
163
164     wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
165
166     wxSizer *item6 = new wxBoxSizer( wxVERTICAL );
167
168     wxStaticText *item7 = new wxStaticText( parent, wxID_STATIC, _("&Packages:"), wxDefaultPosition, wxDefaultSize, 0 );
169     item6->Add( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
170
171     wxWindow *item8 = parent->FindWindow( ecID_BUILD_OPTIONS_PACKAGES_TREE );
172     wxASSERT( item8 );
173     item6->Add( item8, 10, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
174
175     item5->Add( item6, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
176
177     wxSizer *item9 = new wxBoxSizer( wxVERTICAL );
178
179     wxStaticText *item10 = new wxStaticText( parent, wxID_STATIC, _("&Flags:"), wxDefaultPosition, wxDefaultSize, 0 );
180     item9->Add( item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
181
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 );
185
186     item5->Add( item9, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
187
188     item0->Add( item5, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
189
190 #if 0
191     wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
192
193     wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
194
195     wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, _("&Category:"), wxDefaultPosition, wxDefaultSize, 0 );
196     item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
197
198     wxString strs3[] = 
199     {
200         _("CFLAGS"), 
201         _("LDFLAGS")
202     };
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 );
205
206     item1->Add( 20, 20, 20, wxALIGN_CENTRE|wxALL, 5 );
207
208     wxButton *item4 = new wxButton( parent, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
209     item4->SetDefault();
210     item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
211
212     item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
213
214     wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
215
216     wxSizer *item6 = new wxBoxSizer( wxVERTICAL );
217
218     wxStaticText *item7 = new wxStaticText( parent, wxID_STATIC, _("&Packages:"), wxDefaultPosition, wxDefaultSize, 0 );
219     item6->Add( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
220
221     wxWindow *item8 = parent->FindWindow( ecID_BUILD_OPTIONS_PACKAGES_TREE );
222     wxASSERT( item8 );
223     item6->Add( item8, 10, wxALIGN_CENTRE|wxALL, 5 );
224
225     item5->Add( item6, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
226
227     wxSizer *item9 = new wxBoxSizer( wxVERTICAL );
228
229     wxStaticText *item10 = new wxStaticText( parent, wxID_STATIC, _("&Flags:"), wxDefaultPosition, wxDefaultSize, 0 );
230     item9->Add( item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
231
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 );
235
236     item5->Add( item9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
237
238     item0->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
239 #endif
240
241 #ifdef __WXGTK__
242     wxButton *contextButton = new wxContextHelpButton( parent );
243     item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
244 #endif
245
246     parent->SetAutoLayout( TRUE );
247     parent->SetSizer( item0 );
248     parent->Layout();
249     item0->Fit( parent );
250     item0->SetSizeHints( parent );
251
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."));
258
259 #if __WXGTK__
260     parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
261 #endif
262
263 }
264
265 void ecBuildOptionsDialog::OnCancel(wxCommandEvent& event)
266 {
267     event.Skip();
268 }
269
270 void ecBuildOptionsDialog::OnOK(wxCommandEvent& event)
271 {
272     event.Skip();
273 }
274
275 void ecBuildOptionsDialog::CreateItems(ecConfigItem *pti, wxTreeItemId hParent)
276 {
277     if (pti->IsPackage() || !hParent.IsOk())
278     {
279         wxTreeItemId h;
280
281         if (!hParent.IsOk()) // pti->GetItemNameOrMacro() == _("Configuration"))
282             h = m_treeCtrl->AddRoot(pti->GetItemNameOrMacro(), 0, -1);
283         else
284             h = m_treeCtrl->AppendItem(hParent, pti->GetItemNameOrMacro(), 0, -1);
285
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);
290         }
291     }
292 }
293
294 void ecBuildOptionsDialog::Redisplay (wxTreeItemId item)
295 {
296     ecConfigItem *pti= ((ecBuildOptionsData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
297
298     const CdlValuable valuable = pti->GetCdlValuable();
299     std::string name;
300     const CdlBuildInfo_Loadable *pe=NULL;
301     if(valuable){
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)){
305                 pe=&m_arEntries[j];
306                 break;
307             }
308         }
309     }
310
311     wxString strCat = ((wxChoice*) FindWindow(ecID_BUILD_OPTIONS_CATEGORY))->GetStringSelection();
312
313     const wxString strFlags=get_flags(wxGetApp().GetConfigToolDoc()->GetCdlConfig(), pe, ecUtils::UnicodeToStdStr(strCat)).c_str();
314
315     wxArrayString ar;
316     ecUtils::Chop(strFlags,ar, wxT(' '), FALSE, FALSE);
317
318     wxListBox* listBox = (wxListBox*) FindWindow( ecID_BUILD_OPTIONS_FLAGS );
319     
320     wxString strEdit;
321     bool bRedraw=(listBox->Number() != ar.GetCount());
322     if(!bRedraw)
323     {
324         for(int i=0;i<ar.GetCount();i++){
325             wxString strOld = listBox->GetString(i);
326
327             if(strOld!=ar[i])
328             {
329                 bRedraw = TRUE;
330                 break;
331             }
332         }
333     }
334     if(bRedraw){
335         listBox->Clear();
336         for(int i=0;i<ar.GetCount();i++){
337             listBox->Append(ar[i]);
338         }
339     }
340 }
341
342 void ecBuildOptionsDialog::OnSelCategory(wxCommandEvent& event)
343 {
344     wxTreeItemId item = m_treeCtrl->GetSelection();
345     if (item.IsOk())
346     {
347         Redisplay(item);
348     }
349 }
350
351 void ecBuildOptionsDialog::OnSelTree(wxTreeEvent& event)
352 {
353     wxTreeItemId item = m_treeCtrl->GetSelection();
354     if (item.IsOk())
355     {
356         Redisplay(item);
357     }
358 }