- add HDConfigDialog box for wxWindows for editing hard disk params.

Now you can edit floppy and hard disk parameters using dialogs.
This commit is contained in:
Bryce Denney 2002-08-28 15:27:26 +00:00
parent 02bae6a701
commit 17da6fe3c1
4 changed files with 327 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxdialog.cc,v 1.2 2002-08-28 07:54:53 bdenney Exp $
// $Id: wxdialog.cc,v 1.3 2002-08-28 15:27:25 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// misc/wxdialog.cc
@ -14,7 +14,7 @@
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/html/htmlwin.h"
#include "wx/spinctrl.h"
#include "config.h" // definitions based on configure script
#include "osdep.h" // workarounds for missing stuff
@ -239,7 +239,7 @@ void FloppyConfigDialog::AddRadio (char *description, char *filename)
void FloppyConfigDialog::SetDriveName (char *name)
{
wxString text;
text.Printf ("Configure Floppy %s", name);
text.Printf (FLOPPY_CONFIG_TITLE, name);
SetTitle (text);
text.Printf (FLOPPY_CONFIG_INSTRS, name);
ChangeStaticText (vertSizer, instr, text);
@ -305,13 +305,13 @@ void FloppyConfigDialog::SetFilename (char *f) {
filename->SetValue (f);
}
const char *FloppyConfigDialog::GetFilename ()
char *FloppyConfigDialog::GetFilename ()
{
int n = GetRadio ();
if (n < n_rbtns) {
return equivalentFilename[n];
} else {
return filename->GetValue ().c_str ();
return (char *)filename->GetValue ().c_str ();
}
}
@ -336,7 +336,7 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
long style = wxOPEN;
wxFileDialog *fdialog = new wxFileDialog (this, filename->GetValue (), "", "", "*.*", style);
if (fdialog->ShowModal () == wxID_OK)
SetFilename (fdialog->GetPath().c_str ());
SetFilename ((char *)fdialog->GetPath().c_str ());
}
break;
case wxCANCEL:
@ -353,13 +353,203 @@ void FloppyConfigDialog::ShowHelp ()
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
// HDConfigDialog implementation
//////////////////////////////////////////////////////////////////////
// Structure:
// vertSizer:
// enable checkbox
// hsizer[0]:
// "Disk image:"
// disk image text control
// browse button
// hsizer[1]:
// "Geometry: cylinders"
// geom[0] = cyl control
// "heads"
// geom[1] = heads control
// " sectors/track "
// geom[2] = spt control
// hsizer[2]:
// "Size in MB: "
// megs text control
// buttonSizer:
// help
// cancel
// ok
// all events go to OnEvent method
BEGIN_EVENT_TABLE(HDConfigDialog, wxDialog)
EVT_BUTTON(-1, HDConfigDialog::OnEvent)
EVT_CHECKBOX(-1, HDConfigDialog::OnEvent)
EVT_TEXT(-1, HDConfigDialog::OnEvent)
END_EVENT_TABLE()
HDConfigDialog::HDConfigDialog(
wxWindow* parent,
wxWindowID id)
: wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
computeMegs = TRUE;
static char *geomNames[] = HD_CONFIG_GEOM_NAMES;
vertSizer = new wxBoxSizer (wxVERTICAL);
enable = new wxCheckBox (this, ID_Enable, "Enabled");
enable->SetValue (TRUE);
hsizer[0] = new wxBoxSizer (wxHORIZONTAL);
hsizer[1] = new wxBoxSizer (wxHORIZONTAL);
hsizer[2] = new wxBoxSizer (wxHORIZONTAL);
buttonSizer = new wxBoxSizer (wxHORIZONTAL);
// add top level components to vertSizer
vertSizer->Add (enable, 0, wxTOP|wxLEFT, 30);
vertSizer->Add (hsizer[0], 0, wxLEFT, 30);
vertSizer->Add (hsizer[1], 0, wxLEFT, 30);
vertSizer->Add (hsizer[2], 0, wxLEFT, 30);
vertSizer->Add (buttonSizer, 0, wxALIGN_RIGHT|wxTOP, 10);
// contents of hsizer[0]
wxStaticText *text;
text = new wxStaticText (this, -1, HD_CONFIG_DISKIMG);
hsizer[0]->Add (text);
filename = new wxTextCtrl (this, ID_FilenameText);
filename->SetSize (300, filename->GetSize ().GetHeight ());
hsizer[0]->Add (filename, 1);
wxButton *btn = new wxButton (this, ID_Browse, "<--Browse");
hsizer[0]->Add (btn);
// contents of hsizer[1]
for (int i=0; i<3; i++) {
text = new wxStaticText (this, -1, geomNames[i]);
hsizer[1]->Add (text);
geom[i] = new wxSpinCtrl (this, ID_Cylinders+i);
hsizer[1]->Add (geom[i]);
}
// contents of hsizer[2]
text = new wxStaticText (this, ID_Megs, HD_CONTROL_MEGS); // size in megs
hsizer[2]->Add (text);
megs = new wxTextCtrl (this, -1);
hsizer[2]->Add (megs);
// contents of buttonSizer
btn = new wxButton (this, wxHELP, "Help");
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxCANCEL, "Cancel");
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxOK, "Ok");
buttonSizer->Add (btn, 0, wxALL, 5);
// lay it out!
SetAutoLayout(TRUE);
SetSizer(vertSizer);
vertSizer->Fit (this);
wxSize size = vertSizer->GetMinSize ();
printf ("minsize is %d,%d\n", size.GetWidth(), size.GetHeight ());
int margin = 5;
SetSizeHints (size.GetWidth () + margin, size.GetHeight () + margin);
Center ();
}
void HDConfigDialog::SetDriveName (char *name)
{
wxString text;
text.Printf (HD_CONFIG_TITLE, name);
SetTitle (text);
}
void HDConfigDialog::SetGeom (int n, int value) {
printf ("setting geom[%d] to %d\n", n, value);
geom[n]->SetValue (value);
printf ("now geom[%d] has value %d\n", n, geom[n]->GetValue ());
if (computeMegs) ComputeMegs ();
}
void HDConfigDialog::ComputeMegs () {
float meg = 512.0
* geom[0]->GetValue ()
* geom[1]->GetValue ()
* geom[2]->GetValue ()
/ (1024.0*1024.0);
wxString text;
text.Printf ("%.1f", meg);
megs->SetValue (text);
}
void HDConfigDialog::Init()
{
}
void HDConfigDialog::SetFilename (char *f) {
if (!strcmp (f, "none")) {
enable->SetValue (FALSE);
// trick event handler into updating the state
printf ("sending fake ID_Enable event to OnEvent\n");
wxCommandEvent fakeCheckboxEvent;
fakeCheckboxEvent.SetId (ID_Enable);
OnEvent (fakeCheckboxEvent);
}
filename->SetValue (wxString (f));
}
char *HDConfigDialog::GetFilename ()
{
if (enable->GetValue ())
return (char *)filename->GetValue().c_str ();
else
return "none";
}
void HDConfigDialog::OnEvent(wxCommandEvent& event)
{
int id = event.GetId ();
printf ("you pressed button id=%d\n", id);
switch (id) {
case ID_Cylinders:
case ID_Heads:
case ID_SPT:
if (computeMegs) ComputeMegs ();
break;
case ID_Enable:
{
bool en = enable->GetValue ();
filename->Enable (en);
for (int i=0; i<3; i++) geom[i]->Enable (en);
megs->Enable (en);
}
break;
case ID_Megs:
break;
case wxOK:
// probably should validate before allowing ok
EndModal (0);
break;
case ID_Browse:
{
long style = wxOPEN;
wxFileDialog *fdialog = new wxFileDialog (this, filename->GetValue (), "", "", "*.*", style);
if (fdialog->ShowModal () == wxID_OK)
SetFilename ((char *)fdialog->GetPath().c_str ());
}
break;
case wxCANCEL:
EndModal (-1);
break;
case wxHELP:
ShowHelp();
break;
default:
event.Skip ();
}
}
void HDConfigDialog::ShowHelp ()
{
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
}
/////////////////////////////////////////////////////////////////
// utility
/////////////////////////////////////////////////////////////////
// Unfortunately this step is necessary if you change the text.
// Otherwise the sizer that contains the text never realizes that
// the size has changed, and the layout is never updated. The
// Unfortunately this step is necessary if you change the text of
// a wxStaticText. Otherwise the sizer that contains the text never realizes
// that the size has changed, and the layout is never updated. The
// SetItemMinSize trick was reported on comp.soft-sys.wxwindows by
// Dirk Birnhardt.
void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext)

View File

@ -1,9 +1,11 @@
////////////////////////////////////////////////////////////////////
// $Id: wxdialog.h,v 1.2 2002-08-28 07:54:53 bdenney Exp $
// $Id: wxdialog.h,v 1.3 2002-08-28 15:27:25 bdenney Exp $
////////////////////////////////////////////////////////////////////
//
// wxWindows dialogs for Bochs
#include "wx/spinctrl.h"
////////////////////////////////////////////////////////////////////
// LogMsgAskDialog is a modal dialog box that shows the user a
// simulation error message and asks if they want to continue or
@ -92,7 +94,7 @@ DECLARE_EVENT_TABLE()
class FloppyConfigDialog: public wxDialog
{
public:
#define FLOPPY_CONFIG_TITLE "Configure Floppy Drive %s"
#define FLOPPY_CONFIG_TITLE "Configure %s"
#define FLOPPY_CONFIG_INSTRS "Select the device or image to use when simulating %s."
#define FLOPPY_CONFIG_CAP "What is the capacity of this disk?"
#define FLOPPY_CONFIG_HINT "Hint: To create a disk image, choose the name and capacity above, then click Ok."
@ -122,9 +124,64 @@ public:
void SetCapacity (int cap) { capacity->SetSelection (cap); }
int GetRadio ();
int GetCapacity () { return capacity->GetSelection (); }
const char *GetFilename ();
char *GetFilename ();
void SetDriveName (char *name);
void SetValidateFunc (validateFunc_t v) { validate = v; }
void AddRadio (char *description, char *filename);
DECLARE_EVENT_TABLE()
};
////////////////////////////////////////////////////////////////////
// HDConfigDialog is a modal dialog box that asks the user
// what physical device or disk image should be used for emulation.
//
// +-----Configure Hard Disk-------------------------------------------+
// | |
// | [ ] Enable |
// | Disk image: [______________________________] [Browse] |
// | Geometry: cylinders [____] heads [____] sectors/track [____] |
// | Size in Megabytes: _____ |
// | |
// | [ Help ] [ Cancel ] [ Ok ] |
// +-------------------------------------------------------------------+
//
// To use this dialog:
// After constructor, use SetFilename(), SetGeomRange(), SetGeom() to fill in
// the fields. Note that SetGeomRange() should be called before SetGeom()
// or else the text field may not accept the SetGeom() value because of its
// default min/max setting. Call ShowModal to display. Return value is 0=ok
// or -1=cancel. Use GetFilename() and GetGeom() to retrieve values.
//////////////////////////////////////////////////////////////////////
class HDConfigDialog: public wxDialog
{
public:
#define HD_CONFIG_TITLE "Configure %s"
#define HD_CONFIG_DISKIMG "Disk image: "
private:
void Init (); // called automatically by ShowModal()
void ShowHelp ();
wxBoxSizer *vertSizer, *hsizer[3], *buttonSizer;
wxCheckBox *enable;
wxTextCtrl *filename;
wxSpinCtrl *geom[3];
wxTextCtrl *megs;
enum geomfields_t { CYL, HEADS, SPT };
#define HD_CONFIG_GEOM_NAMES \
{ "Geometry: cylinders", " heads ", " sectors/track " }
#define HD_CONTROL_MEGS "Size in Megabytes: "
bool computeMegs;
public:
HDConfigDialog(wxWindow* parent, wxWindowID id);
void OnEvent (wxCommandEvent& event);
int ShowModal() { Init(); return wxDialog::ShowModal(); }
void SetFilename (char *f);
char *GetFilename ();
void SetDriveName (char *name);
void SetGeom (int n, int value);
int GetGeom (int n) { return geom[n]->GetValue (); }
void SetGeomRange (int n, int min, int max) { geom[n]->SetRange (min, max); }
void ComputeMegs ();
void SetEnable (bool val) { enable->SetValue (val); }
DECLARE_EVENT_TABLE()
};

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.cc,v 1.11 2002-08-28 07:54:53 bdenney Exp $
// $Id: wxmain.cc,v 1.12 2002-08-28 15:27:25 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs.
@ -143,6 +143,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Simulate_PauseResume, MyFrame::OnPauseResumeSim)
EVT_MENU(ID_Simulate_Stop, MyFrame::OnKillSim)
EVT_MENU(ID_Sim2Cui_Event, MyFrame::OnSim2CuiEvent)
EVT_MENU(ID_Edit_HD_0, MyFrame::OnOtherEvent)
EVT_MENU(ID_Edit_HD_1, MyFrame::OnOtherEvent)
// toolbar events
EVT_TOOL(ID_Toolbar_FloppyA, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Toolbar_FloppyB, MyFrame::OnToolbarClick)
@ -174,7 +176,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
menuConfiguration->Append (ID_Quit, "&Quit");
menuEdit = new wxMenu;
menuEdit->Append( ID_Edit_Disks, "&Disks..." );
menuEdit->Append( ID_Toolbar_FloppyA, "Floppy Disk &0..." );
menuEdit->Append( ID_Toolbar_FloppyB, "Floppy Disk &1..." );
menuEdit->Append( ID_Edit_HD_0, "Hard Disk 0..." );
menuEdit->Append( ID_Edit_HD_1, "Hard Disk 1..." );
menuEdit->Append( ID_Edit_Boot, "&Boot..." );
menuEdit->Append( ID_Edit_Vga, "&VGA..." );
menuEdit->Append( ID_Edit_Memory, "&Memory..." );
@ -553,6 +558,17 @@ MyFrame::OnSim2CuiEvent (wxCommandEvent& event)
wxASSERT_MSG (0, "switch stmt should have returned");
}
void
MyFrame::OnOtherEvent (wxCommandEvent& event)
{
int id = event.GetId ();
printf ("event id=%d\n", id);
switch (id) {
case ID_Edit_HD_0: editHDConfig (0); break;
case ID_Edit_HD_1: editHDConfig (1); break;
}
}
bool
MyFrame::editFloppyValidate (FloppyConfigDialog *dialog)
{
@ -573,6 +589,7 @@ void MyFrame::editFloppyConfig (int drive)
|| disktype->get_type () != BXT_PARAM_ENUM
|| status->get_type() != BXT_PARAM_ENUM) {
wxLogError ("floppy params have wrong type");
return;
}
dlg.AddRadio ("None/Disabled", "none");
dlg.AddRadio ("Physical floppy drive /dev/fd0", "/dev/fd0");
@ -590,6 +607,42 @@ void MyFrame::editFloppyConfig (int drive)
}
}
void MyFrame::editHDConfig (int drive)
{
HDConfigDialog dlg (this, -1);
dlg.SetDriveName (drive==0? BX_HARD_DISK0_NAME : BX_HARD_DISK1_NAME);
bx_list_c *list = (bx_list_c*) SIM->get_param ((drive==0)? BXP_DISKC : BXP_DISKD);
if (!list) { wxLogError ("HD object param is null"); return; }
bx_param_filename_c *fname = (bx_param_filename_c*) list->get(0);
bx_param_num_c *cyl = (bx_param_num_c *) list->get(1);
bx_param_num_c *heads = (bx_param_num_c *) list->get(2);
bx_param_num_c *spt = (bx_param_num_c *) list->get(3);
if (fname->get_type () != BXT_PARAM_STRING
|| cyl->get_type () != BXT_PARAM_NUM
|| heads->get_type () != BXT_PARAM_NUM
|| spt->get_type() != BXT_PARAM_NUM) {
wxLogError ("HD params have wrong type");
return;
}
dlg.SetFilename (fname->getptr ());
dlg.SetGeomRange (0, cyl->get_min(), cyl->get_max ());
dlg.SetGeomRange (1, heads->get_min(), heads->get_max ());
dlg.SetGeomRange (2, spt->get_min(), spt->get_max ());
dlg.SetGeom (0, cyl->get ());
dlg.SetGeom (1, heads->get ());
dlg.SetGeom (2, spt->get ());
int n = dlg.ShowModal ();
printf ("HD config returned %d\n", n);
if (n==0) {
printf ("filename is '%s'\n", dlg.GetFilename ());
fname->set (dlg.GetFilename ());
cyl->set (dlg.GetGeom (0));
heads->set (dlg.GetGeom (1));
spt->set (dlg.GetGeom (2));
printf ("cyl=%d heads=%d spt=%d\n", cyl->get(), heads->get(), spt->get());
}
}
void MyFrame::OnToolbarClick(wxCommandEvent& event)
{
wxLogDebug ("clicked toolbar thingy");

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.h,v 1.6 2002-08-28 07:54:53 bdenney Exp $
// $Id: wxmain.h,v 1.7 2002-08-28 15:27:26 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.
@ -25,7 +25,10 @@ enum
ID_Config_New,
ID_Config_Read,
ID_Config_Save,
ID_Edit_Disks,
ID_Edit_FD_0,
ID_Edit_FD_1,
ID_Edit_HD_0,
ID_Edit_HD_1,
ID_Edit_Boot,
ID_Edit_Vga,
ID_Edit_Memory,
@ -69,6 +72,12 @@ enum
ID_Filename,
ID_FilenameText,
ID_Browse,
// dialog box: HDConfigDialog
ID_Enable,
ID_Cylinders,
ID_Heads,
ID_SPT,
ID_Megs,
};
@ -117,8 +126,10 @@ public:
void OnPauseResumeSim(wxCommandEvent& event);
void OnKillSim(wxCommandEvent& event);
void OnSim2CuiEvent(wxCommandEvent& event);
void OnOtherEvent(wxCommandEvent& event);
static bool editFloppyValidate (FloppyConfigDialog *dialog);
void editFloppyConfig (int drive);
void editHDConfig (int drive);
void OnToolbarClick(wxCommandEvent& event);
int HandleAskParam (BxEvent *event);
int HandleAskParamString (bx_param_string_c *param);