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
33 // Version: $Id: platformsdlg.cpp,v 1.2 2001/03/23 13:38:04 julians Exp $
35 // Description: Implementation file for the ecPlatformsDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "platformsdlg.h"
57 // Includes other headers for precompiled compilation
64 #include "wx/cshelp.h"
66 #include "configtool.h"
67 #include "platformsdlg.h"
68 #include "platformeditordlg.h"
71 #include "wx/msw/winundef.h"
74 BEGIN_EVENT_TABLE(ecPlatformsDialog, ecDialog)
75 EVT_BUTTON(ecID_PLATFORMS_MODIFY, ecPlatformsDialog::OnModify)
76 EVT_BUTTON(ecID_PLATFORMS_ADD, ecPlatformsDialog::OnAdd)
77 EVT_BUTTON(ecID_PLATFORMS_DELETE, ecPlatformsDialog::OnDelete)
78 EVT_BUTTON(wxID_OK, ecPlatformsDialog::OnOK)
79 EVT_BUTTON(wxID_CANCEL, ecPlatformsDialog::OnCancel)
80 EVT_UPDATE_UI(ecID_PLATFORMS_MODIFY, ecPlatformsDialog::OnUpdateAny)
81 EVT_UPDATE_UI(ecID_PLATFORMS_DELETE, ecPlatformsDialog::OnUpdateAny)
84 const wxChar* ecPlatformsDialog::sm_arpszTypes[]={
85 wxT("Hardware with breakpoint support"),
87 wxT("Synthetic target"),
88 wxT("Hardware without breakpoint support"),
89 wxT("Remote simulator")
94 ecPlatformsDialog::ecPlatformsDialog(wxWindow* parent)
98 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
100 ecDialog::Create(parent, ecID_PLATFORMS_DIALOG, _("Platforms"),
101 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
103 CreateControls(this);
108 for(i=0; i < CeCosTestPlatform::Count(); i++)
110 Add(*CeCosTestPlatform::Get(i));
114 ecPlatformsDialog::~ecPlatformsDialog()
119 void ecPlatformsDialog::Clear()
121 wxNode* node = m_arTargetInfo.First();
124 CeCosTestPlatform* platform = (CeCosTestPlatform*) node->Data();
128 m_arTargetInfo.Clear();
131 void ecPlatformsDialog::CreateControls(wxWindow* parent)
133 // Create custom windows first
134 m_listCtrl = new ecPlatformsListCtrl(parent, ecID_PLATFORMS_LIST, wxDefaultPosition, wxSize(450, 300), wxLC_REPORT|wxCLIP_CHILDREN|wxSUNKEN_BORDER);
135 m_listCtrl->InsertColumn(0, _("Target"), wxLIST_FORMAT_LEFT, 70);
136 m_listCtrl->InsertColumn(1, _("Prefix"), wxLIST_FORMAT_LEFT, 70);
137 m_listCtrl->InsertColumn(2, _("Commands"), wxLIST_FORMAT_LEFT, 70);
138 m_listCtrl->InsertColumn(3, _("Inferior"), wxLIST_FORMAT_LEFT, 70);
139 m_listCtrl->InsertColumn(4, _("Prompt"), wxLIST_FORMAT_LEFT, 70);
140 m_listCtrl->InsertColumn(5, _("ServerSideGdb"), wxLIST_FORMAT_LEFT, 80);
142 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
144 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
146 wxButton *item2 = new wxButton( parent, ecID_PLATFORMS_MODIFY, _("&Modify..."), wxDefaultPosition, wxDefaultSize, 0 );
147 item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
149 wxButton *item3 = new wxButton( parent, ecID_PLATFORMS_ADD, _("&Add..."), wxDefaultPosition, wxDefaultSize, 0 );
150 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
152 wxButton *item4 = new wxButton( parent, ecID_PLATFORMS_DELETE, _("&Delete..."), wxDefaultPosition, wxDefaultSize, 0 );
153 item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
155 wxButton *item5 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
156 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
158 wxButton *item6 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
159 item1->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
162 wxButton *contextButton = new wxContextHelpButton( parent );
163 item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
166 item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 5 );
168 wxWindow *item7 = parent->FindWindow( ecID_PLATFORMS_LIST );
170 item0->Add( item7, 2, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
173 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
175 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
177 wxButton *item2 = new wxButton( parent, ecID_PLATFORMS_MODIFY, "&Modify...", wxDefaultPosition, wxDefaultSize, 0 );
178 item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
180 wxButton *item3 = new wxButton( parent, ecID_PLATFORMS_ADD, "&Add...", wxDefaultPosition, wxDefaultSize, 0 );
181 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
183 wxButton *item4 = new wxButton( parent, ecID_PLATFORMS_DELETE, "&Delete...", wxDefaultPosition, wxDefaultSize, 0 );
184 item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
186 wxButton *item5 = new wxButton( parent, wxID_OK, "&OK", wxDefaultPosition, wxDefaultSize, 0 );
187 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
189 wxButton *item6 = new wxButton( parent, wxID_CANCEL, "&Cancel", wxDefaultPosition, wxDefaultSize, 0 );
190 item1->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
193 wxButton *contextButton = new wxContextHelpButton( parent );
194 item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
197 item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 0 );
199 wxWindow *item7 = parent->FindWindow( ecID_PLATFORMS_LIST );
201 item0->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
204 parent->SetAutoLayout( TRUE );
205 parent->SetSizer( item0 );
207 item0->Fit( parent );
208 item0->SetSizeHints( parent );
210 ((wxButton*) FindWindow(wxID_OK))->SetDefault();
212 // Add context-sensitive help text
213 parent->FindWindow( ecID_PLATFORMS_LIST )->SetHelpText(_("Displays the list of platforms."));
214 parent->FindWindow( ecID_PLATFORMS_MODIFY )->SetHelpText(_("Changes the characteristics of the currently selected platform."));
215 parent->FindWindow( ecID_PLATFORMS_ADD )->SetHelpText(_("Adds a new platform."));
216 parent->FindWindow( ecID_PLATFORMS_DELETE )->SetHelpText(_("Removes the currently selected platform."));
217 parent->FindWindow( wxID_OK )->SetHelpText(_("Closes the dialog and saves any changes you have made."));
218 parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Closes the dialog without saving any changes you have made."));
221 parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
225 void ecPlatformsDialog::OnModify(wxCommandEvent& event)
227 long n = m_listCtrl->GetItemCount();
229 for (i = 0; i < n; i++)
231 if (m_listCtrl->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
233 CeCosTestPlatform *pti=Platform(i);
235 ecPlatformEditorDialog dlg(this);
237 dlg.m_strPlatform = pti->Name();
238 dlg.m_strPrefix = pti->Prefix();
239 dlg.m_strGDB = pti->GdbCmds();
240 dlg.m_strCaption = wxT("Modify Platform");
241 dlg.m_strPrompt = pti->Prompt();
242 dlg.m_bServerSideGdb = pti->ServerSideGdb();
243 dlg.m_strInferior = pti->Inferior();
245 if ( wxID_CANCEL != dlg.ShowModal() )
247 *pti = CeCosTestPlatform(dlg.m_strPlatform,dlg.m_strPrefix,dlg.m_strPrompt,dlg.m_strGDB,dlg.m_bServerSideGdb,dlg.m_strInferior);
248 m_listCtrl->SetItem(i, 1, pti->Prefix());
249 m_listCtrl->SetItem(i, 2, pti->GdbCmds());
250 m_listCtrl->SetItem(i, 3, pti->Inferior());
251 m_listCtrl->SetItem(i, 4, pti->Prompt());
252 m_listCtrl->SetItem(i, 5, pti->ServerSideGdb() ? wxT("Y") : wxT("N"));
258 static long ecFindListCtrlSelection(long& whereFrom, wxListCtrl* listCtrl)
260 long n = listCtrl->GetItemCount();
262 for (i = whereFrom; i < n; i++)
264 if (listCtrl->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
273 void ecPlatformsDialog::OnDelete(wxCommandEvent& event)
279 sel = ecFindListCtrlSelection(whereFrom, m_listCtrl);
282 if (wxYES == wxMessageBox(wxT("Are you sure you wish to delete this platform?"), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxYES_NO, this))
284 delete Platform(sel);
285 m_listCtrl->DeleteItem(sel);
286 delete m_arTargetInfo.Nth(sel);
293 void ecPlatformsDialog::OnAdd(wxCommandEvent& event)
295 ecPlatformEditorDialog dlg(this);
296 dlg.m_strCaption = wxT("New Platform");
297 if (wxID_OK == dlg.ShowModal())
299 if( -1 == m_listCtrl->FindItem(-1, dlg.m_strPlatform) )
301 Add(CeCosTestPlatform(dlg.m_strPlatform,dlg.m_strPrefix,dlg.m_strPrompt,dlg.m_strGDB,dlg.m_bServerSideGdb,dlg.m_strInferior));
303 wxMessageBox(wxT("That platform name is already in use."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
308 void ecPlatformsDialog::OnCancel(wxCommandEvent& event)
313 void ecPlatformsDialog::OnOK(wxCommandEvent& event)
318 void ecPlatformsDialog::Add(const CeCosTestPlatform &ti)
320 wxListCtrl* listCtrl = (wxListCtrl*) FindWindow( ecID_PLATFORMS_LIST );
321 int i = listCtrl->GetItemCount();
323 listCtrl->InsertItem(i,ti.Name());
324 listCtrl->SetItem(i,1,ti.Prefix());
325 listCtrl->SetItem(i,2,ti.GdbCmds());
326 listCtrl->SetItem(i,3,ti.Inferior());
327 listCtrl->SetItem(i,4,ti.Prompt());
328 listCtrl->SetItem(i,5,ti.ServerSideGdb() ? wxT("Y"):wxT("N"));
330 m_arTargetInfo.Append((wxObject*) new CeCosTestPlatform(ti));
333 void ecPlatformsDialog::OnUpdateAny(wxUpdateUIEvent& event)
335 event.Enable( m_listCtrl->GetSelectedItemCount() > 0 );
338 void ecPlatformsDialog::OnDoubleLClick()
340 wxCommandEvent event;
344 void ecPlatformsDialog::OnDeleteKey()
346 wxCommandEvent event;
351 * ecPlatformsListCtrl
354 IMPLEMENT_CLASS(ecPlatformsListCtrl, wxListCtrl)
356 BEGIN_EVENT_TABLE(ecPlatformsListCtrl, wxListCtrl)
357 EVT_LEFT_DCLICK(ecPlatformsListCtrl::OnDoubleLClick)
358 EVT_CHAR(ecPlatformsListCtrl::OnChar)
361 ecPlatformsListCtrl::ecPlatformsListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
362 const wxSize& sz, long style):
363 wxListCtrl(parent, id, pt, sz, style)
367 void ecPlatformsListCtrl::OnDoubleLClick(wxMouseEvent& event)
369 ecPlatformsDialog* parent = (ecPlatformsDialog*) GetParent();
370 parent->OnDoubleLClick();
373 void ecPlatformsListCtrl::OnChar(wxKeyEvent& event)
375 if (event.GetKeyCode() == WXK_DELETE)
377 ecPlatformsDialog* parent = (ecPlatformsDialog*) GetParent();
378 parent->OnDeleteKey();