Replaced floppy dialog by a new implementation based on win32ParamDialog

- DONE: create image feature
- DONE: OK button forces a media change
- TODO: set status and media type after browse button
win32ParamDialog changes:
- changed base IDs for dialog child items
- set enum and bool parameters only if modified
- several changes for the floppy dialog
This commit is contained in:
Volker Ruppert 2013-12-08 21:22:50 +00:00
parent 8836d1aa2d
commit eebeb7a06a
5 changed files with 167 additions and 202 deletions

View File

@ -29,17 +29,6 @@
const char log_choices[5][16] = {"ignore", "log", "ask user", "end simulation", "no change"};
char *backslashes(char *s)
{
if (s != NULL) {
while (*s != 0) {
if (*s == '/') *s = '\\';
s++;
}
}
return s;
}
HWND GetBochsWindow()
{
HWND hwnd;
@ -51,32 +40,6 @@ HWND GetBochsWindow()
return hwnd;
}
BOOL CreateImage(HWND hDlg, int sectors, const char *filename)
{
if (sectors < 1) {
MessageBox(hDlg, "The disk size is invalid.", "Invalid size", MB_ICONERROR);
return FALSE;
}
if (lstrlen(filename) < 1) {
MessageBox(hDlg, "You must type a file name for the new disk image.", "Bad filename", MB_ICONERROR);
return FALSE;
}
int ret = SIM->create_disk_image (filename, sectors, 0);
if (ret == -1) { // already exists
int answer = MessageBox(hDlg, "File exists. Do you want to overwrite it?",
"File exists", MB_YESNO);
if (answer == IDYES)
ret = SIM->create_disk_image (filename, sectors, 1);
else
return FALSE;
}
if (ret == -2) {
MessageBox(hDlg, "I could not create the disk image. Check for permission problems or available disk space.", "Failed", MB_ICONERROR);
return FALSE;
}
return TRUE;
}
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
char path[MAX_PATH];
@ -193,107 +156,6 @@ static BOOL CALLBACK StringParamProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
return FALSE;
}
static BOOL CALLBACK FloppyDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static bx_param_string_c *fpath;
static bx_param_bool_c *readonly;
static bx_param_enum_c *devtype, *status;
static bx_param_enum_c *mediatype;
bx_list_c *list;
char mesg[MAX_PATH];
char path[MAX_PATH];
const char *title;
int i, cap;
switch (msg) {
case WM_INITDIALOG:
list = (bx_list_c *)SIM->get_param((const char*)lParam);
fpath = SIM->get_param_string("path", list);
status = SIM->get_param_enum("status", list);
readonly = SIM->get_param_bool("readonly", list);
devtype = SIM->get_param_enum("devtype", list);
mediatype = SIM->get_param_enum("type", list);
cap = devtype->get() - (int)devtype->get_min();
SetWindowText(GetDlgItem(hDlg, IDDEVTYPE), floppy_devtype_names[cap]);
i = 0;
while (floppy_type_names[i] != NULL) {
SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_ADDSTRING, 0, (LPARAM)floppy_type_names[i]);
SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_SETITEMDATA, i, (LPARAM)(mediatype->get_min() + i));
i++;
}
cap = mediatype->get() - (int)mediatype->get_min();
SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_SETCURSEL, cap, 0);
if (status->get() == BX_INSERTED) {
SendMessage(GetDlgItem(hDlg, IDSTATUS), BM_SETCHECK, BST_CHECKED, 0);
}
if (readonly->get()) {
SendMessage(GetDlgItem(hDlg, IDREADONLY), BM_SETCHECK, BST_CHECKED, 0);
}
lstrcpy(path, fpath->getptr());
title = fpath->get_label();
if (!title) title = fpath->get_name();
SetWindowText(hDlg, title);
if (lstrlen(path) && lstrcmp(path, "none")) {
SetWindowText(GetDlgItem(hDlg, IDPATH), path);
}
return TRUE;
case WM_CLOSE:
EndDialog(hDlg, -1);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDBROWSE:
GetDlgItemText(hDlg, IDPATH, path, MAX_PATH);
if (AskFilename(hDlg, (bx_param_filename_c*)fpath, path) > 0) {
SetWindowText(GetDlgItem(hDlg, IDPATH), path);
SendMessage(GetDlgItem(hDlg, IDSTATUS), BM_SETCHECK, BST_CHECKED, 0);
SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_SELECTSTRING, (WPARAM)-1, (LPARAM)"auto");
EnableWindow(GetDlgItem(hDlg, IDCREATE), FALSE);
}
return TRUE;
case IDOK:
status->set(BX_EJECTED);
if (SendMessage(GetDlgItem(hDlg, IDSTATUS), BM_GETCHECK, 0, 0) == BST_CHECKED) {
GetDlgItemText(hDlg, IDPATH, path, MAX_PATH);
if (lstrlen(path) == 0) {
lstrcpy(path, "none");
}
} else {
lstrcpy(path, "none");
}
readonly->set(SendMessage(GetDlgItem(hDlg, IDREADONLY), BM_GETCHECK, 0, 0) == BST_CHECKED);
fpath->set(path);
i = SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_GETCURSEL, 0, 0);
cap = SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_GETITEMDATA, i, 0);
mediatype->set(cap);
if (lstrcmp(path, "none")) {
status->set(BX_INSERTED);
}
EndDialog(hDlg, 1);
return TRUE;
case IDCANCEL:
EndDialog(hDlg, -1);
return TRUE;
case IDMEDIATYPE:
if (HIWORD(wParam) == CBN_SELCHANGE) {
i = SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_GETCURSEL, 0, 0);
EnableWindow(GetDlgItem(hDlg, IDCREATE), (floppy_type_n_sectors[i] > 0));
}
break;
case IDCREATE:
GetDlgItemText(hDlg, IDPATH, path, MAX_PATH);
backslashes(path);
i = SendMessage(GetDlgItem(hDlg, IDMEDIATYPE), CB_GETCURSEL, 0, 0);
if (CreateImage(hDlg, floppy_type_n_sectors[i], path)) {
wsprintf(mesg, "Created a %s disk image called %s", floppy_type_names[i], path);
MessageBox(hDlg, mesg, "Image created", MB_OK);
}
return TRUE;
}
}
return FALSE;
}
void SetStandardLogOptions(HWND hDlg)
{
int level, idx;
@ -735,12 +597,6 @@ int AskString(bx_param_string_c *param)
(DLGPROC)StringParamProc, (LPARAM)param);
}
int FloppyDialog(HWND window, const char *pname)
{
return (int) DialogBoxParam(NULL, MAKEINTRESOURCE(FLOPPY_DLG), window,
(DLGPROC)FloppyDlgProc, (LPARAM)pname);
}
int MainMenuDialog(HWND hwnd, bx_bool runtime)
{
return (int) DialogBoxParam(NULL, MAKEINTRESOURCE(MAINMENU_DLG), hwnd,
@ -779,7 +635,7 @@ BxEvent* win32_notify_callback(void *unused, BxEvent *event)
} else if (param->get_type() == BXT_LIST) {
param->get_param_path(pname, BX_PATHNAME_LEN);
if (!strncmp(pname, "floppy", 6)) {
event->retcode = FloppyDialog(GetBochsWindow(), pname);
event->retcode = (Bit32s) win32FloppyParamDialog(GetBochsWindow(), pname);
} else {
event->retcode = (Bit32s) win32ParamDialog(GetBochsWindow(), pname);
}

View File

@ -26,10 +26,23 @@
#include "win32res.h"
#include "scrollwin.h"
#define ID_LABEL 100
#define ID_PARAM 1000
#define ID_LABEL 1000
#define ID_PARAM 1500
#define ID_BROWSE 2000
#define ID_UPDOWN 3000
#define ID_UPDOWN 2500
// helper function
char *backslashes(char *s)
{
if (s != NULL) {
while (*s != 0) {
if (*s == '/') *s = '\\';
s++;
}
}
return s;
}
// dialog item list code
@ -458,13 +471,11 @@ HWND CreateTabControl(HWND hDlg, UINT cid, UINT xpos, UINT ypos, SIZE size, BOOL
}
HWND CreateBrowseButton(HWND hDlg, UINT cid, UINT xpos, UINT ypos, BOOL hide)
HWND CreateButton(HWND hDlg, UINT id, UINT xpos, UINT ypos, BOOL hide, const char *text)
{
HWND Button;
RECT r;
int code;
code = ID_BROWSE + cid;
r.left = xpos;
r.top = ypos;
r.right = r.left + 50;
@ -474,12 +485,17 @@ HWND CreateBrowseButton(HWND hDlg, UINT cid, UINT xpos, UINT ypos, BOOL hide)
} else {
MapDialogRect(hDlg, &r);
}
Button = CreateWindow("BUTTON", "Browse...", WS_CHILD, r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, hDlg, (HMENU)code, NULL, NULL);
Button = CreateWindow("BUTTON", text, WS_CHILD, r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, hDlg, (HMENU)id, NULL, NULL);
SendMessage(Button, WM_SETFONT, (WPARAM)DlgFont, TRUE);
ShowWindow(Button, hide ? SW_HIDE : SW_SHOW);
return Button;
}
HWND CreateBrowseButton(HWND hDlg, UINT cid, UINT xpos, UINT ypos, BOOL hide)
{
return CreateButton(hDlg, ID_BROWSE + cid, xpos, ypos, hide, "Browse...");
}
HWND CreateCheckbox(HWND hDlg, UINT cid, UINT xpos, UINT ypos, BOOL hide, bx_param_bool_c *bparam)
{
HWND Checkbox;
@ -794,6 +810,7 @@ void SetParamList(HWND hDlg, bx_list_c *list)
bx_param_c *param;
bx_param_num_c *nparam;
bx_param_enum_c *eparam;
bx_param_bool_c *bparam;
bx_param_string_c *sparam;
int j;
LRESULT val;
@ -813,12 +830,17 @@ void SetParamList(HWND hDlg, bx_list_c *list)
if (param->get_type() == BXT_LIST) {
SetParamList(hDlg, (bx_list_c*)param);
} else if (param->get_type() == BXT_PARAM_BOOL) {
val = SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), BM_GETCHECK, 0, 0);
((bx_param_bool_c*)param)->set(val == BST_CHECKED);
val = (SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), BM_GETCHECK, 0, 0) == BST_CHECKED);
bparam = (bx_param_bool_c*)param;
if (val != bparam->get()) {
bparam->set(val);
}
} else if (param->get_type() == BXT_PARAM_ENUM) {
val = SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), CB_GETCURSEL, 0, 0);
eparam = (bx_param_enum_c*)param;
eparam->set(val + eparam->get_min());
val = (LRESULT)(SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), CB_GETCURSEL, 0, 0) + eparam->get_min());
if (val != eparam->get()) {
eparam->set(val);
}
} else {
if (SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), EM_GETMODIFY, 0, 0)) {
if (param->get_type() == BXT_PARAM_NUM) {
@ -952,6 +974,24 @@ void ProcessDependentList(HWND hDlg, bx_param_c *param, BOOL enabled)
}
}
void SetDefaultButtons(HWND Window, UINT xpos, UINT ypos)
{
RECT r;
r.left = xpos;
r.top = ypos;
r.right = r.left + 50;
r.bottom = r.top + 14;
MapDialogRect(Window, &r);
MoveWindow(GetDlgItem(Window, IDOK), r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, FALSE);
r.left = xpos + 60;
r.top = ypos;
r.right = r.left + 50;
r.bottom = r.top + 14;
MapDialogRect(Window, &r);
MoveWindow(GetDlgItem(Window, IDCANCEL), r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, FALSE);
}
static INT_PTR CALLBACK ParamDlgProc(HWND Window, UINT AMessage, WPARAM wParam, LPARAM lParam)
{
static bx_list_c *list = NULL;
@ -977,18 +1017,7 @@ static INT_PTR CALLBACK ParamDlgProc(HWND Window, UINT AMessage, WPARAM wParam,
SetWindowText(Window, list->get_title());
nextDlgID = 1;
size = CreateParamList(Window, 0, 6, 6, FALSE, list);
r.left = size.cx / 2 - 50;
r.top = size.cy + 12;
r.right = r.left + 50;
r.bottom = r.top + 14;
MapDialogRect(Window, &r);
MoveWindow(GetDlgItem(Window, IDOK), r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, FALSE);
r.left = size.cx / 2 + 10;
r.top = size.cy + 12;
r.right = r.left + 50;
r.bottom = r.top + 14;
MapDialogRect(Window, &r);
MoveWindow(GetDlgItem(Window, IDCANCEL), r.left, r.top, r.right-r.left+1, r.bottom-r.top+1, FALSE);
SetDefaultButtons(Window, size.cx / 2 - 50, size.cy + 12);
GetWindowRect(Window, &r2);
r.left = 0;
r.top = 0;
@ -1066,6 +1095,108 @@ static INT_PTR CALLBACK ParamDlgProc(HWND Window, UINT AMessage, WPARAM wParam,
return 0;
}
BOOL CreateImage(HWND hDlg, int sectors, const char *filename)
{
if (sectors < 1) {
MessageBox(hDlg, "The disk size is invalid.", "Invalid size", MB_ICONERROR);
return FALSE;
}
if (lstrlen(filename) < 1) {
MessageBox(hDlg, "You must type a file name for the new disk image.", "Bad filename", MB_ICONERROR);
return FALSE;
}
int ret = SIM->create_disk_image (filename, sectors, 0);
if (ret == -1) { // already exists
int answer = MessageBox(hDlg, "File exists. Do you want to overwrite it?",
"File exists", MB_YESNO);
if (answer == IDYES)
ret = SIM->create_disk_image (filename, sectors, 1);
else
return FALSE;
}
if (ret == -2) {
MessageBox(hDlg, "I could not create the disk image. Check for permission problems or available disk space.", "Failed", MB_ICONERROR);
return FALSE;
}
return TRUE;
}
static INT_PTR CALLBACK FloppyParamDlgProc(HWND Window, UINT AMessage, WPARAM wParam, LPARAM lParam)
{
static bx_list_c *list = NULL;
static UINT path_id, type_id;
bx_param_enum_c *status;
UINT_PTR code;
INT_PTR ret;
int i;
RECT r, r2;
SIZE size;
char mesg[MAX_PATH];
char path[MAX_PATH];
switch (AMessage) {
case WM_INITDIALOG:
list = (bx_list_c*)SIM->get_param((const char*)lParam);
SetWindowText(Window, list->get_title());
nextDlgID = 1;
size = CreateParamList(Window, 0, 6, 6, FALSE, list);
CreateLabel(Window, 99, 60, size.cy + 12, 160, FALSE,
"Clicking OK signals a media change for this drive.");
CreateButton(Window, IDCREATE, size.cx / 2 - 85, size.cy + 30, FALSE, "Create Image");
SetDefaultButtons(Window, size.cx / 2 - 25, size.cy + 30);
GetWindowRect(Window, &r2);
r.left = 0;
r.top = 0;
r.right = size.cx + 18;
r.bottom = size.cy + 70;
MapDialogRect(Window, &r);
MoveWindow(Window, r2.left, r2.top, r.right, r.bottom, TRUE);
CreateParamDlgTooltip(Window);
path_id = findDlgIDFromParam(list->get_by_name("path")) + ID_PARAM;
type_id = findDlgIDFromParam(list->get_by_name("type")) + ID_PARAM;
return TRUE;
case WM_COMMAND:
code = LOWORD(wParam);
switch (code) {
case IDOK:
// force a media change
status = (bx_param_enum_c*)list->get_by_name("status");
status->set(BX_EJECTED);
SetParamList(Window, list);
cleanupDlgLists();
DestroyWindow(hwndTT);
EndDialog(Window, 1);
break;
case IDCREATE:
GetDlgItemText(Window, path_id, path, MAX_PATH);
backslashes(path);
i = SendMessage(GetDlgItem(Window, type_id), CB_GETCURSEL, 0, 0);
if (CreateImage(Window, floppy_type_n_sectors[i], path)) {
wsprintf(mesg, "Created a %s disk image called %s", floppy_type_names[i], path);
MessageBox(Window, mesg, "Image created", MB_OK);
}
return TRUE;
break;
default:
ret = ParamDlgProc(Window, AMessage, wParam, lParam);
if (code == path_id) {
EnableWindow(GetDlgItem(Window, IDCREATE), IsWindowEnabled(GetDlgItem(Window, type_id)));
} else if (code == type_id) {
i = SendMessage(GetDlgItem(Window, type_id), CB_GETCURSEL, 0, 0);
EnableWindow(GetDlgItem(Window, IDCREATE), (i != 0));
}
return ret;
}
break;
case WM_CLOSE:
case WM_NOTIFY:
case WM_CTLCOLOREDIT:
return ParamDlgProc(Window, AMessage, wParam, lParam);
break;
}
return 0;
}
INT_PTR win32ParamDialog(HWND parent, const char *menu)
{
InitDlgFont();
@ -1075,4 +1206,13 @@ INT_PTR win32ParamDialog(HWND parent, const char *menu)
return ret;
}
INT_PTR win32FloppyParamDialog(HWND parent, const char *menu)
{
InitDlgFont();
RegisterScrollWindow(NULL);
INT_PTR ret = DialogBoxParam(NULL, MAKEINTRESOURCE(PARAM_DLG), parent, (DLGPROC)FloppyParamDlgProc, (LPARAM)menu);
DeleteObject(DlgFont);
return ret;
}
#endif // BX_USE_TEXTCONFIG && defined(WIN32)

View File

@ -27,6 +27,7 @@
int AskFilename(HWND hwnd, bx_param_filename_c *param, char *buffer);
INT_PTR win32ParamDialog(HWND parent, const char *menu);
INT_PTR win32FloppyParamDialog(HWND parent, const char *menu);
#endif

View File

@ -39,16 +39,5 @@
#define IDASKLIST 2050
#define STRING_DLG 2100
#define IDSTRING 2110
#define FLOPPY_DLG 2200
#define IDDEVTX 2205
#define IDDEVTYPE 2210
#define IDPATHTX 2215
#define IDPATH 2220
#define IDBROWSE 2230
#define IDMEDIATX 2235
#define IDMEDIATYPE 2240
#define IDSTATUS 2250
#define IDREADONLY 2255
#define IDCREATE 2260
#define IDCHANGETX 2265
#define PARAM_DLG 2800
#define PARAM_DLG 3000
#define IDCREATE 3010

View File

@ -32,27 +32,6 @@ BEGIN
PUSHBUTTON "Cancel", IDCANCEL, 70, 40, 50, 14
END
FLOPPY_DLG DIALOG 30, 30, 240, 130
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Param"
FONT 8, "Helv"
BEGIN
LTEXT "Device Type", IDDEVTX, 5, 12, 45, 14
EDITTEXT IDDEVTYPE, 50, 10, 40, 14, ES_READONLY | NOT WS_TABSTOP
LTEXT "Path", IDPATHTX, 5, 32, 40, 14
EDITTEXT IDPATH, 50, 30, 120, 14, ES_AUTOHSCROLL
PUSHBUTTON "Browse...", IDBROWSE, 180, 30, 50, 14
LTEXT "Media Type", IDMEDIATX, 5, 52, 45, 14
COMBOBOX IDMEDIATYPE, 50, 50, 40, 14, CBS_DROPDOWNLIST | WS_TABSTOP
AUTOCHECKBOX "Inserted", IDSTATUS, 50, 70, 50, 14
AUTOCHECKBOX "Write Protection", IDREADONLY, 116, 70, 70, 14
LTEXT "Clicking OK signals a media change for this drive.",
IDCHANGETX, 35, 90, 185, 8
PUSHBUTTON "Create Image", IDCREATE, 35, 105, 50, 14
DEFPUSHBUTTON "OK", IDOK, 95, 105, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 155, 105, 50, 14
END
MAINMENU_DLG DIALOG 30, 30, 275, 130
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Bochs Start Menu"