- add NetConfigDialog box, that configures networking settings

- for all modal dialogs that return a boolean result, return either
  wxOK or wxCANCEL instead of 0,-1.
- you can view the NetConfigDialog box if you choose the Edit:Network menu
  item, but it's not connected to the actual parameter values yet.
This commit is contained in:
Bryce Denney 2002-09-01 19:38:08 +00:00
parent 9620d2a423
commit 9e67dcb3e1
4 changed files with 261 additions and 38 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxdialog.cc,v 1.14 2002-09-01 15:27:32 bdenney Exp $
// $Id: wxdialog.cc,v 1.15 2002-09-01 19:38:07 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// misc/wxdialog.cc
@ -337,7 +337,7 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
// probably should validate before allowing ok
if (validate!=NULL && !(*validate)(this))
return; // validation failed, don't leave yet
EndModal (0);
EndModal (wxOK);
break;
case ID_Browse:
{
@ -367,7 +367,7 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
}
break;
case wxID_CANCEL:
EndModal (-1);
EndModal (wxCANCEL);
break;
case wxHELP:
ShowHelp();
@ -548,7 +548,7 @@ void HDConfigDialog::OnEvent(wxCommandEvent& event)
break;
case wxOK:
// probably should validate before allowing ok
EndModal (0);
EndModal (wxOK);
break;
case ID_Browse:
{
@ -559,7 +559,7 @@ void HDConfigDialog::OnEvent(wxCommandEvent& event)
}
break;
case wxID_CANCEL:
EndModal (-1);
EndModal (wxCANCEL);
break;
case wxHELP:
ShowHelp();
@ -753,7 +753,7 @@ void CdromConfigDialog::OnEvent(wxCommandEvent& event)
break;
case wxOK:
// probably should validate before allowing ok
EndModal (0);
EndModal (wxOK);
break;
case ID_Browse:
{
@ -764,7 +764,7 @@ void CdromConfigDialog::OnEvent(wxCommandEvent& event)
}
break;
case wxID_CANCEL:
EndModal (-1);
EndModal (wxCANCEL);
break;
case wxHELP:
ShowHelp();
@ -779,6 +779,175 @@ void CdromConfigDialog::ShowHelp ()
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
// NetConfigDialog implementation
//////////////////////////////////////////////////////////////////////
// Structure:
// mainSizer:
// vertSizer:
// prompt
// gridSizer 2 columns:
// "enable networking"
// enable = checkbox
// "i/o addr"
// io = wxTextCtrl
// "irq"
// irq = wxSpinCtrl
// "mac"
// mac = wxTextCtrl
// "conn"
// conn = wxChoice
// "phys"
// phys = wxTextCtrl
// "script"
// script = wxTextCtrl
// buttonSizer:
// help
// cancel
// ok
// all events go to OnEvent method
BEGIN_EVENT_TABLE(NetConfigDialog, wxDialog)
EVT_BUTTON(-1, NetConfigDialog::OnEvent)
EVT_CHECKBOX(-1, NetConfigDialog::OnEvent)
EVT_TEXT(-1, NetConfigDialog::OnEvent)
END_EVENT_TABLE()
NetConfigDialog::NetConfigDialog(
wxWindow* parent,
wxWindowID id)
: wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
SetTitle (NET_CONFIG_TITLE);
// top level objects
mainSizer = new wxBoxSizer (wxVERTICAL);
wxBoxSizer *vertSizer = new wxBoxSizer (wxVERTICAL);
mainSizer->Add (vertSizer, 1, wxGROW|wxALIGN_LEFT);
wxBoxSizer *buttonSizer = new wxBoxSizer (wxHORIZONTAL);
mainSizer->Add (buttonSizer, 0, wxALIGN_RIGHT);
// vertSizer contents
wxStaticText *text;
text = new wxStaticText (this, -1, NET_CONFIG_PROMPT);
vertSizer->Add (text, 0, wxLEFT|wxRIGHT|wxTOP, 20);
wxFlexGridSizer *gridSizer = new wxFlexGridSizer (2);
vertSizer->Add (gridSizer, 1, wxALL|wxGROW, 30);
// gridSizer contents
gridSizer->AddGrowableCol (1);
#define add(x) gridSizer->Add (x, 0, wxALL, 5)
#define add_grow(x) gridSizer->Add (x, 1, wxALL|wxGROW, 5)
#define label(x) (new wxStaticText (this, -1, x))
add (label (NET_CONFIG_EN));
add (enable = new wxCheckBox (this, ID_Enable, ""));
gridSizer->Add (30, 30);
gridSizer->Add (30, 30);
add (label (NET_CONFIG_IO));
add (io = new wxTextCtrl (this, -1));
add (label (NET_CONFIG_IRQ));
add (irq = new wxSpinCtrl (this, -1));
add (label (NET_CONFIG_MAC));
add (mac = new wxTextCtrl (this, -1));
add (label (NET_CONFIG_CONN));
add (conn = new wxChoice (this, -1));
add (label (NET_CONFIG_PHYS));
add (phys = new wxTextCtrl (this, -1));
add (label (NET_CONFIG_SCRIPT));
add_grow (script = new wxTextCtrl (this, -1));
#undef label()
#undef add()
irq->SetRange (0, 15);
mac->SetSizeHints (200, mac->GetSize ().GetHeight ());
script->SetSizeHints (200, script->GetSize ().GetHeight ());
// buttonSizer contents
wxButton *btn = new wxButton (this, wxHELP, BTNLABEL_HELP);
buttonSizer->Add (btn, 0, wxALL, 5);
// use wxID_CANCEL because pressing ESC produces this same code
btn = new wxButton (this, wxID_CANCEL, BTNLABEL_CANCEL);
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxOK, BTNLABEL_OK);
buttonSizer->Add (btn, 0, wxALL, 5);
}
void NetConfigDialog::Init()
{
EnableChanged ();
// lay it out!
SetAutoLayout(TRUE);
SetSizer(mainSizer);
mainSizer->Fit (this);
wxSize size = mainSizer->GetMinSize ();
printf ("minsize is %d,%d\n", size.GetWidth(), size.GetHeight ());
int margin = 5;
SetSizeHints (size.GetWidth () + margin, size.GetHeight () + margin);
Center ();
}
void NetConfigDialog::EnableChanged ()
{
bool en = enable->GetValue ();
io->Enable (en);
irq->Enable (en);
mac->Enable (en);
conn->Enable (en);
phys->Enable (en);
script->Enable (en);
}
int NetConfigDialog::GetIO () {
char buf[1024];
wxString string(io->GetValue ());
string.Trim ();
strncpy (buf, string, sizeof(buf));
int n = strtol (string, NULL, 0);
if (n<0 || n>0xffff) {
wxMessageBox("I/O address out of range. Try 0x200-0x400.", "Bad I/O address", wxOK | wxICON_ERROR );
return -1;
}
return n;
}
void NetConfigDialog::SetIO (int addr) {
wxString text;
text.Printf ("0x%03x", addr);
io->SetValue (text);
}
void NetConfigDialog::OnEvent(wxCommandEvent& event)
{
int id = event.GetId ();
printf ("you pressed button id=%d\n", id);
switch (id) {
case ID_Enable:
EnableChanged (); // enable/disable fields that depend on this
break;
case wxOK:
// probably should validate before allowing ok
EndModal (wxOK);
break;
case wxID_CANCEL:
EndModal (wxCANCEL);
break;
case wxHELP:
ShowHelp();
break;
default:
event.Skip ();
}
}
void NetConfigDialog::ShowHelp ()
{
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
/////////////////////////////////////////////////////////////////
// utility
/////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////
// $Id: wxdialog.h,v 1.14 2002-09-01 15:27:33 bdenney Exp $
// $Id: wxdialog.h,v 1.15 2002-09-01 19:38:07 bdenney Exp $
////////////////////////////////////////////////////////////////////
//
// wxWindows dialogs for Bochs
@ -95,8 +95,8 @@ DECLARE_EVENT_TABLE()
// To use this dialog:
// After constructor, use AddRadio () to add radio buttons, SetFilename()
// to fill in the disk image filename, SetCapacity() to set the capacity.
// Then call ShowModal() to display it. Return value is 0 for ok or -1
// for cancel. If you set a validation function, then it will be called
// Then call ShowModal() to display it. Return value is wxOK or wxCANCEL.
// If you set a validation function, then it will be called
// when ok is pressed, and will get a chance to veto the "Ok" if it
// returns false. After ShowModal() returns, use GetFilename and
// GetCapacity to see what the user did. If the validation function
@ -273,8 +273,8 @@ DECLARE_EVENT_TABLE()
// After constructor, use SetEnabled(), SetFilename() to fill in the
// disk image filename, AddRadio() to add radio buttons (the disk
// image file radio button will be added automatically). Then call
// ShowModal() to display it. Return value is 0 for ok or -1 for
// cancel. After ShowModal() returns, use GetFilename() and
// ShowModal() to display it. Return value is wxOK or wxCANCEL.
// After ShowModal() returns, use GetFilename() and
// GetEnabled().
class CdromConfigDialog: public wxDialog
@ -316,6 +316,71 @@ public:
DECLARE_EVENT_TABLE()
};
////////////////////////////////////////////////////////////////////////////
// ConfigNetworkDialog allows the user to change the settings for
// the emulated NE2000 network card.
////////////////////////////////////////////////////////////////////////////
// +--- Configure Networking --------------------------------------+
// | |
// | Bochs can emulate an NE2000-compatible network card. Would |
// | you like to enable it? |
// | |
// | Enable networking? [X] |
// | |
// | NE2000 I/O address: [ 0x280 ] |
// | IRQ: [ 9 ] |
// | MAC address: [ b0:c4:00:00:00:00 ] |
// | Connection to the OS: [ Linux Packet Filter ] |
// | Physical NIC to use: [ eth0 ] |
// | Setup script: [_________________] |
// | |
// | [ Help ] [ Cancel ] [ Ok ] |
// +---------------------------------------------------------------+
// To use this dialog:
// After constructor, use AddConn() to add values to the choice box
// called "Connection to the OS". Then use SetEnable, SetIO, SetIrq, SetMac,
// SetConn, SetNic, and SetDebug to fill in the current values. Then call
// ShowModal(), which will return wxOK or wxCANCEL. Then use the Get* methods
// to retrieve the values that were chosen.
class NetConfigDialog: public wxDialog
{
private:
#define NET_CONFIG_TITLE "Configure Networking"
#define NET_CONFIG_PROMPT "Bochs can emulate an NE2000-compatible network card. Would you like to enable it?"
#define NET_CONFIG_EN "Enable networking?"
#define NET_CONFIG_IO "I/O address (hex): "
#define NET_CONFIG_IRQ "IRQ: "
#define NET_CONFIG_MAC "MAC address: "
#define NET_CONFIG_CONN "Connection to OS: "
#define NET_CONFIG_PHYS "Physical NIC to use: "
#define NET_CONFIG_SCRIPT "Setup script: "
void Init (); // called automatically by ShowModal()
void ShowHelp ();
wxBoxSizer *mainSizer, *vertSizer, *buttonSizer;
wxCheckBox *enable;
wxTextCtrl *io, *mac, *phys, *script;
wxSpinCtrl *irq;
wxChoice *conn;
void EnableChanged ();
public:
NetConfigDialog(wxWindow* parent, wxWindowID id);
void OnEvent (wxCommandEvent& event);
int ShowModal() { Init(); return wxDialog::ShowModal(); }
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); }
int GetConn () { return conn->GetSelection (); }
void AddConn (wxString name); // add to list of choices
void SetPhys (wxString s) { phys->SetValue (s); }
wxString GetPhys () { return phys->GetValue (); }
DECLARE_EVENT_TABLE()
};
/**************************************************************************
Everything else in here is a comment!
@ -519,27 +584,6 @@ let you go right to the configure screen for that disk drive.
| [ Help ] [ Cancel ] [ Ok ] |
+---------------------------------------------------------------+
////////////////////////////////////////////////////////////////////////////
// ConfigNetworkDialog
////////////////////////////////////////////////////////////////////////////
Edit network settings
+---------------------------------------------------------------+
| |
| Bochs can emulate an NE2000-compatible network card. Would |
| you like to enable it? |
| |
| Enable networking? [X] |
| |
| NE2000 I/O address: [ 0x280 ] |
| IRQ: [ 9 ] |
| MAC address: [ b0:c4:00:00:00:00 ] |
| Connection to the OS: [ Linux Packet Filter ] |
| Physical NIC to use: [ eth0 ] |
| NE2000 Debug messages: [ ] |
| |
| [ Help ] [ Cancel ] [ Ok ] |
+---------------------------------------------------------------+
////////////////////////////////////////////////////////////////////////////
// ConfigMemoryDialog
////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.cc,v 1.20 2002-09-01 15:27:33 bdenney Exp $
// $Id: wxmain.cc,v 1.21 2002-09-01 19:38:07 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs.
@ -148,6 +148,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Edit_HD_1, MyFrame::OnOtherEvent)
EVT_MENU(ID_Edit_Cdrom, MyFrame::OnOtherEvent)
EVT_MENU(ID_Edit_Boot, MyFrame::OnEditBoot)
EVT_MENU(ID_Edit_Network, MyFrame::OnEditNet)
// toolbar events
EVT_TOOL(ID_Edit_FD_0, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Edit_FD_1, MyFrame::OnToolbarClick)
@ -367,6 +368,14 @@ void MyFrame::OnEditBoot(wxCommandEvent& WXUNUSED(event))
bootdevice->set (which);
}
void MyFrame::OnEditNet(wxCommandEvent& WXUNUSED(event))
{
NetConfigDialog dlg (this, -1);
int n = dlg.ShowModal ();
if (n==wxOK) {
}
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close( TRUE );
@ -732,7 +741,7 @@ void MyFrame::editFloppyConfig (int drive)
}
int n = dlg.ShowModal ();
printf ("floppy config returned %d\n", n);
if (n==0) {
if (n==wxID_OK) {
char filename[1024];
wxString fn (dlg.GetFilename ());
strncpy (filename, fn.c_str (), sizeof(filename));
@ -772,7 +781,7 @@ void MyFrame::editHDConfig (int drive)
dlg.SetEnable (present->get ());
int n = dlg.ShowModal ();
printf ("HD config returned %d\n", n);
if (n==0) {
if (n==wxID_OK) {
char filename[1024];
wxString fn (dlg.GetFilename ());
strncpy (filename, fn.c_str (), sizeof (filename));
@ -817,7 +826,7 @@ void MyFrame::editCdromConfig ()
dlg.SetEjected (status->get () == BX_EJECTED);
int n = dlg.ShowModal ();
printf ("cdrom config returned %d\n", n);
if (n==0) {
if (n==wxID_OK) {
char filename[1024];
wxString fn (dlg.GetFilename ());
strncpy (filename, fn.c_str (), sizeof(filename));

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.h,v 1.13 2002-08-31 04:58:24 bdenney Exp $
// $Id: wxmain.h,v 1.14 2002-09-01 19:38:08 bdenney Exp $
/////////////////////////////////////////////////////////////////
// This file defines variables and classes that the wxWindows .cc files
// share. It should be included only by wx.cc and wxmain.cc.
@ -131,6 +131,7 @@ public:
void OnKillSim(wxCommandEvent& event);
void OnSim2CIEvent(wxCommandEvent& event);
void OnEditBoot(wxCommandEvent& event);
void OnEditNet(wxCommandEvent& event);
void OnOtherEvent(wxCommandEvent& event);
static bool editFloppyValidate (FloppyConfigDialog *dialog);
void editFloppyConfig (int drive);