- fix up NetConfigDialog and the code that calls it, so that what the

user selects actually changes the settings.
- modiified files: gui/wxdialog.cc gui/wxdialog.h gui/wxmain.cc
This commit is contained in:
Bryce Denney 2002-09-01 21:24:14 +00:00
parent e7515cd933
commit ed82a64ae5
3 changed files with 118 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxdialog.cc,v 1.15 2002-09-01 19:38:07 bdenney Exp $
// $Id: wxdialog.cc,v 1.16 2002-09-01 21:24:14 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// misc/wxdialog.cc
@ -821,6 +821,7 @@ NetConfigDialog::NetConfigDialog(
: wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
n_conn_choices = 0;
SetTitle (NET_CONFIG_TITLE);
// top level objects
mainSizer = new wxBoxSizer (wxVERTICAL);
@ -861,6 +862,7 @@ NetConfigDialog::NetConfigDialog(
#undef add()
irq->SetRange (0, 15);
conn->SetSizeHints (200, conn->GetSize ().GetHeight ());
mac->SetSizeHints (200, mac->GetSize ().GetHeight ());
script->SetSizeHints (200, script->GetSize ().GetHeight ());
@ -899,7 +901,7 @@ void NetConfigDialog::EnableChanged ()
script->Enable (en);
}
// allow (encourage) use of hex addresses started with "0x"
int NetConfigDialog::GetIO () {
char buf[1024];
wxString string(io->GetValue ());
@ -919,6 +921,50 @@ void NetConfigDialog::SetIO (int addr) {
io->SetValue (text);
}
void NetConfigDialog::SetMac (unsigned char addr[6]) {
wxString text;
text.Printf ("%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
mac->SetValue (text);
}
bool
NetConfigDialog::GetMac (unsigned char addr[6]) {
char buf[32];
wxString string(mac->GetValue ());
string.Trim ();
strncpy (buf, string, sizeof(buf));
// expect NN:NN:NN:NN:NN:NN format
int part[6];
if (6 != sscanf (string, "%x:%x:%x:%x:%x:%x", &part[0], &part[1], &part[2],
&part[3], &part[4], &part[5]))
{
wxMessageBox("MAC address must be in the form FF:FF:FF:FF:FF:FF.", "Bad MAC Address", wxOK | wxICON_ERROR );
return false;
}
for (int i=0; i<6; i++)
addr[i] = part[i];
return true;
}
void NetConfigDialog::AddConn (wxString niceName, char *realName) {
conn->Append (niceName);
int index = n_conn_choices++;
conn->SetClientData (index, realName);
}
void NetConfigDialog::SetConn (const char *realname) {
// search through the choices and find the one whose clientData matches
// realname.
for (int i=0; i<n_conn_choices; i++) {
char *choiceRealName = (char *)conn->GetClientData (i);
if (!strcmp (choiceRealName, realname)) {
conn->SetSelection (i);
return;
}
}
wxLogError ("no choice match for '%s'", realname);
}
void NetConfigDialog::OnEvent(wxCommandEvent& event)
{
int id = event.GetId ();
@ -928,8 +974,14 @@ void NetConfigDialog::OnEvent(wxCommandEvent& event)
EnableChanged (); // enable/disable fields that depend on this
break;
case wxOK:
// probably should validate before allowing ok
EndModal (wxOK);
{
// check for valid mac address by calling GetMac()
unsigned char tmp[6];
if (GetMac (tmp)) {
// mac address was legal
EndModal (wxOK);
}
}
break;
case wxID_CANCEL:
EndModal (wxCANCEL);

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////
// $Id: wxdialog.h,v 1.15 2002-09-01 19:38:07 bdenney Exp $
// $Id: wxdialog.h,v 1.16 2002-09-01 21:24:14 bdenney Exp $
////////////////////////////////////////////////////////////////////
//
// wxWindows dialogs for Bochs
@ -361,22 +361,28 @@ private:
wxTextCtrl *io, *mac, *phys, *script;
wxSpinCtrl *irq;
wxChoice *conn;
int n_conn_choices;
void EnableChanged ();
public:
NetConfigDialog(wxWindow* parent, wxWindowID id);
void OnEvent (wxCommandEvent& event);
int ShowModal() { Init(); return wxDialog::ShowModal(); }
void SetEnable (bool en) { enable->SetValue (en); EnableChanged (); }
bool GetEnable () { return enable->GetValue (); }
void SetIO (int addr);
int GetIO ();
void SetIrq (int addr) { irq->SetValue (addr); }
int GetIrq () { return irq->GetValue (); }
void SetMac (unsigned char addr[6]);
void GetMac (unsigned char addr[6]);
void SetConn (int i) { conn->SetSelection (i); }
bool GetMac (unsigned char addr[6]);
void SetConn(const char *realname);
int GetConn () { return conn->GetSelection (); }
void AddConn (wxString name); // add to list of choices
void *GetConnData () { return conn->GetClientData (conn->GetSelection ()); }
void AddConn (wxString niceName, char *realName);
void SetPhys (wxString s) { phys->SetValue (s); }
wxString GetPhys () { return phys->GetValue (); }
void SetScript (wxString s) { script->SetValue (s); }
wxString GetScript () { return script->GetValue (); }
DECLARE_EVENT_TABLE()
};

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.cc,v 1.21 2002-09-01 19:38:07 bdenney Exp $
// $Id: wxmain.cc,v 1.22 2002-09-01 21:24:14 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs.
@ -371,8 +371,59 @@ void MyFrame::OnEditBoot(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnEditNet(wxCommandEvent& WXUNUSED(event))
{
NetConfigDialog dlg (this, -1);
bx_param_bool_c *present = (bx_param_bool_c*)SIM->get_param (BXP_NE2K_VALID);
bx_param_num_c *io = (bx_param_num_c*)SIM->get_param (BXP_NE2K_IOADDR);
bx_param_num_c *irq = (bx_param_num_c*)SIM->get_param (BXP_NE2K_IRQ);
bx_param_string_c *mac = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_MACADDR);
bx_param_string_c *module = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_ETHMOD);
bx_param_string_c *device = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_ETHDEV);
bx_param_string_c *script = (bx_param_string_c*)
SIM->get_param (BXP_NE2K_SCRIPT);
dlg.SetEnable (present->get ());
dlg.SetIO (io->get ());
dlg.SetIrq (irq->get ());
dlg.SetMac ((unsigned char *) mac->getptr ());
dlg.AddConn ("Null Packet Mover", "null");
#if defined(ETH_LINUX)
dlg.AddConn ("Linux Socket Filter", "linux");
#endif
#if HAVE_ETHERTAP
dlg.AddConn ("Ethertap", "tap");
#endif
#if HAVE_TUNTAP
dlg.AddConn ("TUN/TAP", "tuntap");
#endif
#if defined(ETH_WIN32)
dlg.AddConn ("Win32 packet mover", "win32");
#endif
#if defined(ETH_FBSD)
dlg.AddConn ("Berkeley Packet Filter (FreeBSD, OpenBSD)", "fbsd");
#endif
#ifdef ETH_ARPBACK
dlg.AddConn ("ARPback packet mover", "arpback");
#endif
dlg.SetConn (module->getptr ());
dlg.SetPhys (device->getptr ());
dlg.SetScript (script->getptr ());
int n = dlg.ShowModal ();
if (n==wxOK) {
present->set (dlg.GetEnable ());
io->set (dlg.GetIO ());
irq->set (dlg.GetIrq ());
unsigned char tmp[6];
dlg.GetMac (tmp);
mac->set ((char *)tmp);
module->set ((char *)dlg.GetConnData ());
char buf[1024];
wxString deviceString (dlg.GetPhys ());
strncpy (buf, deviceString.c_str (), sizeof(buf));
device->set (buf);
wxString scriptString (dlg.GetScript ());
strncpy (buf, scriptString.c_str (), sizeof(buf));
script->set (buf);
}
}