diff options
Diffstat (limited to 'docs/release/src/osd/winui/newui.cpp')
-rw-r--r-- | docs/release/src/osd/winui/newui.cpp | 1079 |
1 files changed, 240 insertions, 839 deletions
diff --git a/docs/release/src/osd/winui/newui.cpp b/docs/release/src/osd/winui/newui.cpp index 73dda176311..77695a55603 100644 --- a/docs/release/src/osd/winui/newui.cpp +++ b/docs/release/src/osd/winui/newui.cpp @@ -1,27 +1,27 @@ // For licensing and usage information, read docs/winui_license.txt -//**************************************************************************** +//************************************************************************************************ // MASTER -//============================================================ // // newui.c - This is the NEWUI Windows dropdown menu system // -//============================================================ +// known bugs: +// - Unable to modify keyboard or joystick. Last known to be working in 0.158 . +// Need to use the default UI. +// +// +//************************************************************************************************ -// Needed for better file dialog -//#ifdef _WIN32_WINNT -//#undef _WIN32_WINNT -//#endif // _WIN32_WINNT -//#define _WIN32_WINNT 0x500 +// Set minimum windows version to XP +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif +#define _WIN32_WINNT 0x501 // standard windows headers -#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN // leave out not-needed libraries #include "newui.h" -// stupid hack; not sure why this is needed -//#ifdef const -//#undef const -//#endif // const #include <shellapi.h> @@ -35,17 +35,17 @@ typedef enum _win_file_dialog_type win_file_dialog_type; typedef struct _win_open_file_name win_open_file_name; struct _win_open_file_name { - win_file_dialog_type type; // type of file dialog - HWND owner; // owner of the dialog - HINSTANCE instance; // instance - const char * filter; // pipe char ("|") delimited strings - DWORD filter_index; // index into filter - char filename[MAX_PATH]; // filename buffer - const char * initial_directory; // initial directory for dialog - DWORD flags; // standard flags - LPARAM custom_data; // custom data for dialog hook - LPOFNHOOKPROC hook; // custom dialog hook - LPCTSTR template_name; // custom dialog template + win_file_dialog_type type; // type of file dialog + HWND owner; // owner of the dialog + HINSTANCE instance; // instance + const char * filter; // pipe char ("|") delimited strings + DWORD filter_index; // index into filter + char filename[MAX_PATH]; // filename buffer + const char * initial_directory; // initial directory for dialog + DWORD flags; // standard flags + LPARAM custom_data; // custom data for dialog hook + LPOFNHOOKPROC hook; // custom dialog hook + LPCTSTR template_name; // custom dialog template }; @@ -67,12 +67,8 @@ typedef void (*dialog_notification)(dialog_box *dialog, HWND dlgwnd, NMHDR *noti #define win_dialog_tcsdup win_dialog_strdup #endif -static const TCHAR guide_prop[] = TEXT("opcntrl_guide"); -static const TCHAR spec_prop[] = TEXT("opcntrl_optspec"); -static const TCHAR value_prop[] = TEXT("opcntrl_value"); - -#define SEQWM_SETFOCUS (WM_APP + 0) -#define SEQWM_KILLFOCUS (WM_APP + 1) +#define SEQWM_SETFOCUS (WM_APP + 0) +#define SEQWM_KILLFOCUS (WM_APP + 1) enum { @@ -152,39 +148,39 @@ struct _seqselect_info // PARAMETERS //============================================================ -#define DIM_VERTICAL_SPACING 3 -#define DIM_HORIZONTAL_SPACING 5 -#define DIM_NORMAL_ROW_HEIGHT 10 -#define DIM_COMBO_ROW_HEIGHT 12 -#define DIM_SLIDER_ROW_HEIGHT 18 -#define DIM_BUTTON_ROW_HEIGHT 12 -#define DIM_EDIT_WIDTH 120 -#define DIM_BUTTON_WIDTH 50 -#define DIM_ADJUSTER_SCR_WIDTH 12 -#define DIM_ADJUSTER_HEIGHT 12 -#define DIM_SCROLLBAR_WIDTH 10 -#define DIM_BOX_VERTSKEW -3 +#define DIM_VERTICAL_SPACING 3 +#define DIM_HORIZONTAL_SPACING 5 +#define DIM_NORMAL_ROW_HEIGHT 10 +#define DIM_COMBO_ROW_HEIGHT 12 +#define DIM_SLIDER_ROW_HEIGHT 18 +#define DIM_BUTTON_ROW_HEIGHT 12 +#define DIM_EDIT_WIDTH 120 +#define DIM_BUTTON_WIDTH 50 +#define DIM_ADJUSTER_SCR_WIDTH 12 +#define DIM_ADJUSTER_HEIGHT 12 +#define DIM_SCROLLBAR_WIDTH 10 +#define DIM_BOX_VERTSKEW -3 -#define DLGITEM_BUTTON ((const WCHAR *) dlgitem_button) -#define DLGITEM_EDIT ((const WCHAR *) dlgitem_edit) -#define DLGITEM_STATIC ((const WCHAR *) dlgitem_static) -#define DLGITEM_LISTBOX ((const WCHAR *) dlgitem_listbox) -#define DLGITEM_SCROLLBAR ((const WCHAR *) dlgitem_scrollbar) -#define DLGITEM_COMBOBOX ((const WCHAR *) dlgitem_combobox) +#define DLGITEM_BUTTON ((const WCHAR *) dlgitem_button) +#define DLGITEM_EDIT ((const WCHAR *) dlgitem_edit) +#define DLGITEM_STATIC ((const WCHAR *) dlgitem_static) +#define DLGITEM_LISTBOX ((const WCHAR *) dlgitem_listbox) +#define DLGITEM_SCROLLBAR ((const WCHAR *) dlgitem_scrollbar) +#define DLGITEM_COMBOBOX ((const WCHAR *) dlgitem_combobox) -#define DLGTEXT_OK "OK" -#define DLGTEXT_APPLY "Apply" -#define DLGTEXT_CANCEL "Cancel" +#define DLGTEXT_OK "OK" +#define DLGTEXT_APPLY "Apply" +#define DLGTEXT_CANCEL "Cancel" -#define FONT_SIZE 8 -#define FONT_FACE L"Arial" +#define FONT_SIZE 8 +#define FONT_FACE L"Arial" -#define SCROLL_DELTA_LINE 10 -#define SCROLL_DELTA_PAGE 100 +#define SCROLL_DELTA_LINE 10 +#define SCROLL_DELTA_PAGE 100 -#define LOG_WINMSGS 0 -#define DIALOG_STYLE WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT -#define MAX_DIALOG_HEIGHT 200 +#define LOG_WINMSGS 0 +#define DIALOG_STYLE WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT +#define MAX_DIALOG_HEIGHT 200 @@ -204,6 +200,10 @@ static const WORD dlgitem_static[] = { 0xFFFF, 0x0082 }; static const WORD dlgitem_listbox[] = { 0xFFFF, 0x0083 }; static const WORD dlgitem_scrollbar[] = { 0xFFFF, 0x0084 }; static const WORD dlgitem_combobox[] = { 0xFFFF, 0x0085 }; +static int joystick_menu_setup = 0; +static char state_filename[MAX_PATH]; +static void add_filter_entry(std::string &dest, const char *description, const char *extensions); +static const char* software_dir; //============================================================ @@ -211,8 +211,7 @@ static const WORD dlgitem_combobox[] = { 0xFFFF, 0x0085 }; //============================================================ static void dialog_prime(dialog_box *di); -static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, - short width, short height, const char *str, const WCHAR *class_name, WORD *id); +static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, short width, short height, const char *str, const WCHAR *class_name, WORD *id); @@ -223,7 +222,6 @@ static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, #define ID_FRAMESKIP_0 10000 #define ID_DEVICE_0 11000 #define ID_JOYSTICK_0 12000 -#define ID_INPUT_0 13000 #define ID_VIDEO_VIEW_0 14000 #define MAX_JOYSTICKS (8) @@ -242,38 +240,50 @@ enum }; -//============================================================ -// LOCAL VARIABLES -//============================================================ +//======================================================================== +// LOCAL STRING FUNCTIONS (these require osd_free after being called) +//======================================================================== -static int joystick_menu_setup = 0; -static char state_filename[MAX_PATH]; -static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions); -static const char* software_dir; - -struct file_dialog_params +static WCHAR *ui_wstring_from_utf8(const char *utf8string) { - device_image_interface *dev; - int *create_format; - option_resolution **create_args; -}; + int char_count; + WCHAR *result; + + // convert MAME string (UTF-8) to UTF-16 + char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0); + result = (WCHAR *)osd_malloc_array(char_count * sizeof(*result)); + if (result != nullptr) + MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count); + + return result; +} +static char *ui_utf8_from_wstring(const WCHAR *wstring) +{ + int char_count; + char *result; + // convert UTF-16 to MAME string (UTF-8) + char_count = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, nullptr, 0, nullptr, nullptr); + result = (char *)osd_malloc_array(char_count * sizeof(*result)); + if (result != nullptr) + WideCharToMultiByte(CP_UTF8, 0, wstring, -1, result, char_count, nullptr, nullptr); + return result; +} //============================================================ // win_get_file_name_dialog - sanitize all of the ugliness // in invoking GetOpenFileName() and GetSaveFileName() +// called from win_file_dialog, state_dialog //============================================================ static BOOL win_get_file_name_dialog(win_open_file_name *ofn) { BOOL result = FALSE; BOOL dialog_result; - OSVERSIONINFO vers; OPENFILENAME os_ofn; - DWORD os_ofn_size; LPTSTR t_filter = NULL; LPTSTR t_file = NULL; DWORD t_file_size = 0; @@ -282,25 +292,10 @@ static BOOL win_get_file_name_dialog(win_open_file_name *ofn) char *utf8_file; int i; - // determine the version of Windows - memset(&vers, 0, sizeof(vers)); - vers.dwOSVersionInfoSize = sizeof(vers); - GetVersionEx(&vers); - - // based on the version of Windows, determine the correct struct size - if (vers.dwMajorVersion >= 5) - os_ofn_size = sizeof(os_ofn); - else -#ifdef __GNUC__ - os_ofn_size = 76; // MinGW does not define OPENFILENAME_NT4 -#else - os_ofn_size = sizeof(OPENFILENAME_NT4); -#endif - // do we have to translate the filter? if (ofn->filter) { - buffer = tstring_from_utf8(ofn->filter); + buffer = ui_wstring_from_utf8(ofn->filter); if (!buffer) goto done; @@ -316,7 +311,7 @@ static BOOL win_get_file_name_dialog(win_open_file_name *ofn) // do we need to translate the file parameter? if (ofn->filename) { - buffer = tstring_from_utf8(ofn->filename); + buffer = ui_wstring_from_utf8(ofn->filename); if (!buffer) goto done; @@ -329,14 +324,14 @@ static BOOL win_get_file_name_dialog(win_open_file_name *ofn) // do we need to translate the initial directory? if (ofn->initial_directory) { - t_initial_directory = tstring_from_utf8(ofn->initial_directory); + t_initial_directory = ui_wstring_from_utf8(ofn->initial_directory); if (t_initial_directory == NULL) goto done; } // translate our custom structure to a native Win32 structure memset(&os_ofn, 0, sizeof(os_ofn)); - os_ofn.lStructSize = os_ofn_size; + os_ofn.lStructSize = sizeof(OPENFILENAME); os_ofn.hwndOwner = ofn->owner; os_ofn.hInstance = ofn->instance; os_ofn.lpstrFilter = t_filter; @@ -373,7 +368,7 @@ static BOOL win_get_file_name_dialog(win_open_file_name *ofn) // copy file back out into passed structure if (t_file) { - utf8_file = utf8_from_tstring(t_file); + utf8_file = ui_utf8_from_wstring(t_file); if (!utf8_file) goto done; @@ -394,6 +389,7 @@ done: //============================================================ // win_scroll_window +// called from dialog_proc //============================================================ static void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line) @@ -454,6 +450,7 @@ static void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int sc //============================================================ // win_append_menu_utf8 +// create a menu item //============================================================ static BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char *item) @@ -465,7 +462,7 @@ static BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char // only convert string when it's not a bitmap if (!(flags & MF_BITMAP) && item) { - t_str = tstring_from_utf8(item); + t_str = ui_wstring_from_utf8(item); t_item = t_str; } @@ -478,182 +475,10 @@ static BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char } -static int get_option_count(const option_guide *guide, const char *optspec) -{ - struct OptionRange ranges[128]; - int count = 0, i; - - option_resolution_listranges(optspec, guide->parameter, ranges, ARRAY_LENGTH(ranges)); - - for (i = 0; ranges[i].min >= 0; i++) - count += ranges[i].max - ranges[i].min + 1; - - return count; -} - - - -static BOOL prepare_combobox(HWND control, const option_guide *guide, const char *optspec) -{ - struct OptionRange ranges[128]; - int default_value, default_index, current_index, option_count; - int i, j, k; - BOOL has_option; - TCHAR buf1[256]; - TCHAR buf2[256]; - LPTSTR tempstr; - - SendMessage(control, CB_GETLBTEXT, SendMessage(control, CB_GETCURSEL, 0, 0), (LPARAM) buf1); - SendMessage(control, CB_RESETCONTENT, 0, 0); - has_option = guide && optspec; - - if (has_option) - { - if ((guide->option_type != OPTIONTYPE_INT) && (guide->option_type != OPTIONTYPE_ENUM_BEGIN)) - goto unexpected; - - option_resolution_listranges(optspec, guide->parameter, - ranges, ARRAY_LENGTH(ranges)); - option_resolution_getdefault(optspec, guide->parameter, &default_value); - - option_count = 0; - default_index = -1; - current_index = -1; - - for (i = 0; ranges[i].min >= 0; i++) - { - for (j = ranges[i].min; j <= ranges[i].max; j++) - { - if (guide->option_type == OPTIONTYPE_INT) - { - _sntprintf(buf2, ARRAY_LENGTH(buf2), TEXT("%d"), j); - SendMessage(control, CB_ADDSTRING, 0, (LPARAM) buf2); - } - else - if (guide->option_type == OPTIONTYPE_ENUM_BEGIN) - { - for (k = 1; guide[k].option_type == OPTIONTYPE_ENUM_VALUE; k++) - { - if (guide[k].parameter == j) - break; - } - if (guide[k].option_type != OPTIONTYPE_ENUM_VALUE) - goto unexpected; - - tempstr = tstring_from_utf8(guide[k].display_name); - SendMessage(control, CB_ADDSTRING, 0, (LPARAM) tempstr); - osd_free(tempstr); - } - else - goto unexpected; - - SendMessage(control, CB_SETITEMDATA, option_count, j); - - if (j == default_value) - default_index = option_count; - if (!_tcscmp(buf1, buf2)) - current_index = option_count; - option_count++; - } - } - - // if there is only one option, it is effectively disabled - if (option_count <= 1) - has_option = FALSE; - - if (current_index >= 0) - SendMessage(control, CB_SETCURSEL, current_index, 0); - else if (default_index >= 0) - SendMessage(control, CB_SETCURSEL, default_index, 0); - } - else - { - // this item is non applicable - SendMessage(control, CB_ADDSTRING, 0, (LPARAM) TEXT("N/A")); - SendMessage(control, CB_SETCURSEL, 0, 0); - } - EnableWindow(control, has_option); - return TRUE; - -unexpected: - printf("Unexpected result in prepare_combobox\n"); - assert(FALSE); - return FALSE; -} - - - -static BOOL prepare_editbox(HWND control, const option_guide *guide, const char *optspec) -{ - optreserr_t err = OPTIONRESOLUTION_ERROR_SUCCESS; - char buf[32]; - int val, has_option, option_count; - - has_option = guide && optspec; - buf[0] = '\0'; - - if (has_option) - { - switch(guide->option_type) - { - case OPTIONTYPE_STRING: - break; - - case OPTIONTYPE_INT: - err = option_resolution_getdefault(optspec, guide->parameter, &val); - if (err) - goto done; - _snprintf(buf, ARRAY_LENGTH(buf), "%d", val); - break; - - default: - err = OPTIONRESOLTUION_ERROR_INTERNAL; - goto done; - } - } - - if (has_option) - { - option_count = get_option_count(guide, optspec); - if (option_count <= 1) - has_option = FALSE; - } - -done: - if (err == OPTIONRESOLTUION_ERROR_INTERNAL) - printf("Unexpected result in prepare_editbox\n"); - assert(err != OPTIONRESOLTUION_ERROR_INTERNAL); - win_set_window_text_utf8(control, buf); - EnableWindow(control, !err && has_option); - return err == OPTIONRESOLUTION_ERROR_SUCCESS; -} - - - -static BOOL win_prepare_option_control(HWND control, const option_guide *guide, const char *optspec) -{ - BOOL rc = FALSE; - TCHAR class_name[32]; - - SetProp(control, guide_prop, (HANDLE) guide); - SetProp(control, spec_prop, (HANDLE) optspec); - GetClassName(control, class_name, sizeof(class_name) - / sizeof(class_name[0])); - - if (!_tcsicmp(class_name, TEXT("ComboBox"))) - rc = prepare_combobox(control, guide, optspec); - else - if (!_tcsicmp(class_name, TEXT("Edit"))) - rc = prepare_editbox(control, guide, optspec); - - return rc; -} - - - //============================================================ // call_windowproc +// called from adjuster_sb_wndproc, seqselect_wndproc //============================================================ static LRESULT call_windowproc(WNDPROC wndproc, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) @@ -668,9 +493,10 @@ static LRESULT call_windowproc(WNDPROC wndproc, HWND hwnd, UINT msg, WPARAM wpar -//============================================================ +//========================================================================== // dialog_write -//============================================================ +// called from dialog_write_string, win_dialog_init, dialog_write_item +//========================================================================== static int dialog_write(struct _dialog_box *di, const void *ptr, size_t sz, int align) { @@ -719,6 +545,7 @@ static int dialog_write(struct _dialog_box *di, const void *ptr, size_t sz, int //============================================================ // dialog_write_string +// called from win_dialog_init, dialog_write_item //============================================================ static int dialog_write_string(dialog_box *di, const WCHAR *str) @@ -733,6 +560,7 @@ static int dialog_write_string(dialog_box *di, const WCHAR *str) //============================================================ // win_dialog_exit +// called from win_dialog_init, calc_dlgunits_multiple, change_device, and all customise_input functions //============================================================ static void win_dialog_exit(dialog_box *dialog) @@ -754,15 +582,15 @@ static void win_dialog_exit(dialog_box *dialog) if (dialog->handle) GlobalFree(dialog->handle); - //pool_free_lib(dialog->mempool); free(dialog); } -//============================================================ +//=========================================================================== // win_dialog_init -//============================================================ +// called from calc_dlgunits_multiple, and all customise_input functions +//=========================================================================== dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layout) { @@ -783,7 +611,6 @@ dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layou memset(di, 0, sizeof(*di)); di->layout = layout; - //di->mempool = pool_alloc_lib(NULL); memset(&dlg_template, 0, sizeof(dlg_template)); dlg_template.style = di->style = DIALOG_STYLE; @@ -797,7 +624,7 @@ dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layou if (dialog_write(di, w, sizeof(w), 2)) goto error; - w_title = wstring_from_utf8(title); + w_title = ui_wstring_from_utf8(title); rc = dialog_write_string(di, w_title); osd_free(w_title); if (rc) @@ -824,6 +651,7 @@ error: //============================================================ // compute_dlgunits_multiple +// called from dialog_scrollbar_init //============================================================ static void calc_dlgunits_multiple(void) @@ -844,8 +672,7 @@ static void calc_dlgunits_multiple(void) if (!dialog) goto done; - if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT, - 0, 0, offset_x, offset_y, wnd_title, DLGITEM_STATIC, &id)) + if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT, 0, 0, offset_x, offset_y, wnd_title, DLGITEM_STATIC, &id)) goto done; dialog_prime(dialog); @@ -868,6 +695,7 @@ done: //============================================================ // dialog_trigger +// called from dialog_proc, file_dialog_hook //============================================================ static void dialog_trigger(HWND dlgwnd, WORD trigger_flags) @@ -909,6 +737,7 @@ static void dialog_trigger(HWND dlgwnd, WORD trigger_flags) //============================================================ // dialog_proc +// called from win_dialog_runmodal //============================================================ static INT_PTR CALLBACK dialog_proc(HWND dlgwnd, UINT msg, WPARAM wparam, LPARAM lparam) @@ -917,12 +746,6 @@ static INT_PTR CALLBACK dialog_proc(HWND dlgwnd, UINT msg, WPARAM wparam, LPARAM CHAR buf[32]; WORD command; - //if (LOG_WINMSGS) - //{ - // logerror("dialog_proc(): dlgwnd=%p msg=0x%08x wparam=0x%08x lparam=0x%08x\n", - // dlgwnd, (unsigned int) msg, (unsigned int) wparam, (unsigned int) lparam); - //} - switch(msg) { case WM_INITDIALOG: @@ -985,12 +808,12 @@ static INT_PTR CALLBACK dialog_proc(HWND dlgwnd, UINT msg, WPARAM wparam, LPARAM -//============================================================ +//========================================================================================================================================================================================= // dialog_write_item -//============================================================ +// called from calc_dlgunits_multiple, win_dialog_add_active_combobox, win_dialog_add_adjuster, dialog_add_single_seqselect, win_dialog_add_portselect, win_dialog_add_standard_buttons +//========================================================================================================================================================================================= -static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, - short width, short height, const char *str, const WCHAR *class_name, WORD *id) +static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, short width, short height, const char *str, const WCHAR *class_name, WORD *id) { DLGITEMTEMPLATE item_template; UINT class_name_length; @@ -1016,7 +839,7 @@ static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, if (dialog_write(di, class_name, class_name_length, 2)) return 1; - w_str = str ? wstring_from_utf8(str) : NULL; + w_str = str ? ui_wstring_from_utf8(str) : NULL; rc = dialog_write_string(di, w_str); if (w_str) osd_free(w_str); @@ -1036,12 +859,12 @@ static int dialog_write_item(dialog_box *di, DWORD style, short x, short y, -//============================================================ +//========================================================================================================================================================== // dialog_add_trigger -//============================================================ +// called from dialog_add_scrollbar, win_dialog_add_active_combobox, win_dialog_add_combobox_item, win_dialog_add_adjuster, dialog_add_single_seqselect +//========================================================================================================================================================== -static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item, - WORD trigger_flags, UINT message, trigger_function trigger_proc, +static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item, WORD trigger_flags, UINT message, trigger_function trigger_proc, WPARAM wparam, LPARAM lparam, void (*storeval)(void *param, int val), void *storeval_param) { if (!di) @@ -1052,8 +875,6 @@ static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item, assert(trigger_flags); dialog_info_trigger *trigger = new(dialog_info_trigger); - //dialog_info_trigger *trigger; - //trigger = global_alloc(dialog_info_trigger); trigger->next = NULL; trigger->trigger_flags = trigger_flags; @@ -1077,6 +898,7 @@ static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item, //============================================================ // dialog_scrollbar_init +// called from dialog_add_scrollbar //============================================================ static LRESULT dialog_scrollbar_init(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1100,6 +922,7 @@ static LRESULT dialog_scrollbar_init(dialog_box *dialog, HWND dlgwnd, UINT messa //============================================================ // dialog_add_scrollbar +// called from dialog_prime //============================================================ static int dialog_add_scrollbar(dialog_box *dialog) @@ -1113,9 +936,10 @@ static int dialog_add_scrollbar(dialog_box *dialog) -//============================================================ +//============================================================================== // dialog_prime -//============================================================ +// called from calc_dlgunits_multiple, win_dialog_runmodal, win_file_dialog +//============================================================================== static void dialog_prime(dialog_box *di) { @@ -1139,6 +963,7 @@ static void dialog_prime(dialog_box *di) //============================================================ // dialog_get_combo_value +// called from win_dialog_add_active_combobox //============================================================ static LRESULT dialog_get_combo_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam) @@ -1154,6 +979,7 @@ static LRESULT dialog_get_combo_value(dialog_box *dialog, HWND dialog_item, UINT //============================================================ // dialog_get_adjuster_value +// called from win_dialog_add_adjuster //============================================================ static LRESULT dialog_get_adjuster_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam) @@ -1165,9 +991,10 @@ static LRESULT dialog_get_adjuster_value(dialog_box *dialog, HWND dialog_item, U -//============================================================ +//==================================================================================================== // dialog_new_control -//============================================================ +// called from win_dialog_add_active_combobox, win_dialog_add_adjuster, win_dialog_add_portselect +//==================================================================================================== static void dialog_new_control(struct _dialog_box *di, short *x, short *y) { @@ -1177,9 +1004,10 @@ static void dialog_new_control(struct _dialog_box *di, short *x, short *y) -//============================================================ +//==================================================================================================== // dialog_finish_control -//============================================================ +// called from win_dialog_add_active_combobox, win_dialog_add_adjuster, win_dialog_add_portselect +//==================================================================================================== static void dialog_finish_control(struct _dialog_box *di, short x, short y) { @@ -1200,6 +1028,7 @@ static void dialog_finish_control(struct _dialog_box *di, short x, short y) //============================================================ // dialog_combo_changed +// called from win_dialog_add_active_combobox //============================================================ static LRESULT dialog_combo_changed(dialog_box *dialog, HWND dlgitem, UINT message, WPARAM wparam, LPARAM lparam) @@ -1213,6 +1042,7 @@ static LRESULT dialog_combo_changed(dialog_box *dialog, HWND dlgitem, UINT messa //============================================================ // win_dialog_wcsdup +// called from win_dialog_add_adjuster (via define) //============================================================ static WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s) @@ -1227,6 +1057,7 @@ static WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s) //============================================================ // win_dialog_add_active_combobox +// called from win_dialog_add_combobox //============================================================ static int win_dialog_add_active_combobox(dialog_box *dialog, const char *item_label, int default_value, @@ -1276,19 +1107,19 @@ done: //============================================================ // win_dialog_add_combobox +// called from customise_switches, customise_analogcontrols //============================================================ -static int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value, - void (*storeval)(void *param, int val), void *storeval_param) +static int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value, void (*storeval)(void *param, int val), void *storeval_param) { - return win_dialog_add_active_combobox(dialog, item_label, default_value, - storeval, storeval_param, NULL, NULL); + return win_dialog_add_active_combobox(dialog, item_label, default_value, storeval, storeval_param, NULL, NULL); } //============================================================ // win_dialog_add_combobox_item +// called from customise_switches, customise_analogcontrols //============================================================ static int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_label, int item_data) @@ -1317,6 +1148,7 @@ static int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_lab //============================================================ // adjuster_sb_wndproc +// called from adjuster_sb_setup //============================================================ struct adjuster_sb_stuff @@ -1374,19 +1206,10 @@ static INT_PTR CALLBACK adjuster_sb_wndproc(HWND sbwnd, UINT msg, WPARAM wparam, } -//============================================================ -// win_dialog_malloc -//============================================================ - -//static void *win_dialog_malloc(dialog_box *dialog, size_t size) -//{ -// return pool_malloc_lib(dialog->mempool, size); -//} - - //============================================================ // adjuster_sb_setup +// called from win_dialog_add_adjuster //============================================================ static LRESULT adjuster_sb_setup(dialog_box *dialog, HWND sbwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1412,6 +1235,7 @@ static LRESULT adjuster_sb_setup(dialog_box *dialog, HWND sbwnd, UINT message, W //============================================================ // win_dialog_add_adjuster +// called from customise_analogcontrols //============================================================ static int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, int default_value, @@ -1424,8 +1248,7 @@ static int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, i dialog_new_control(dialog, &x, &y); - if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT, - x, y, dialog->layout->label_width, DIM_ADJUSTER_HEIGHT, item_label, DLGITEM_STATIC, NULL)) + if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT, x, y, dialog->layout->label_width, DIM_ADJUSTER_HEIGHT, item_label, DLGITEM_STATIC, NULL)) goto error; x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING; @@ -1436,28 +1259,23 @@ static int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, i goto error; x += dialog->layout->combo_width - DIM_ADJUSTER_SCR_WIDTH; - _sntprintf(buf, ARRAY_LENGTH(buf), - is_percentage ? TEXT("%d%%") : TEXT("%d"), - default_value); + _sntprintf(buf, ARRAY_LENGTH(buf), is_percentage ? TEXT("%d%%") : TEXT("%d"), default_value); s = win_dialog_tcsdup(dialog, buf); osd_free(buf); if (!s) return 1; - if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, WM_SETTEXT, NULL, - 0, (LPARAM) s, NULL, NULL)) + if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, WM_SETTEXT, NULL, 0, (LPARAM) s, NULL, NULL)) goto error; // add the trigger invoked when the apply button is pressed if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_adjuster_value, 0, 0, storeval, storeval_param)) goto error; - if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT, - x, y, DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_SCROLLBAR, NULL)) + if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT, x, y, DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_SCROLLBAR, NULL)) goto error; x += DIM_ADJUSTER_SCR_WIDTH + DIM_HORIZONTAL_SPACING; - if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, 0, adjuster_sb_setup, - 0, MAKELONG(min_value, max_value), NULL, NULL)) + if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, 0, adjuster_sb_setup, 0, MAKELONG(min_value, max_value), NULL, NULL)) return 1; y += DIM_COMBO_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2; @@ -1485,9 +1303,10 @@ static seqselect_info *get_seqselect_info(HWND editwnd) -//============================================================ +//============================================================================= // seqselect_settext -//============================================================ +// called from seqselect_start_read_from_main_thread, seqselect_setup +//============================================================================= //#pragma GCC diagnostic push #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wunused-value" @@ -1502,7 +1321,7 @@ static void seqselect_settext(HWND editwnd) // the basics stuff = get_seqselect_info(editwnd); if (stuff == NULL) - return; // this should not happen - need to fix this + return; // this should not happen - need to fix this // retrieve the seq name seqstring = Machine->input().seq_name(*stuff->code); @@ -1529,6 +1348,7 @@ static void seqselect_settext(HWND editwnd) //============================================================ // seqselect_start_read_from_main_thread +// called from seqselect_wndproc //============================================================ static void seqselect_start_read_from_main_thread(void *param) @@ -1580,6 +1400,7 @@ static void seqselect_start_read_from_main_thread(void *param) //============================================================ // seqselect_stop_read_from_main_thread +// called from seqselect_wndproc //============================================================ static void seqselect_stop_read_from_main_thread(void *param) @@ -1600,6 +1421,7 @@ static void seqselect_stop_read_from_main_thread(void *param) //============================================================ // seqselect_wndproc +// called from seqselect_setup //============================================================ static INT_PTR CALLBACK seqselect_wndproc(HWND editwnd, UINT msg, WPARAM wparam, LPARAM lparam) @@ -1657,6 +1479,7 @@ static INT_PTR CALLBACK seqselect_wndproc(HWND editwnd, UINT msg, WPARAM wparam, //============================================================ // seqselect_setup +// called from dialog_add_single_seqselect //============================================================ static LRESULT seqselect_setup(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1675,6 +1498,7 @@ static LRESULT seqselect_setup(dialog_box *dialog, HWND editwnd, UINT message, W //============================================================ // seqselect_apply +// called from dialog_add_single_seqselect //============================================================ static LRESULT seqselect_apply(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -1690,14 +1514,13 @@ static LRESULT seqselect_apply(dialog_box *dialog, HWND editwnd, UINT message, W //============================================================ // dialog_add_single_seqselect +// called from win_dialog_add_portselect //============================================================ -static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y, - short cx, short cy, ioport_field *field, int is_analog, int seqtype) +static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y, short cx, short cy, ioport_field *field, int is_analog, int seqtype) { // write the dialog item - if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_ENDELLIPSIS | ES_CENTER | SS_SUNKEN, - x, y, cx, cy, NULL, DLGITEM_EDIT, NULL)) + if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_ENDELLIPSIS | ES_CENTER | SS_SUNKEN, x, y, cx, cy, NULL, DLGITEM_EDIT, NULL)) return 1; // allocate a seqselect_info @@ -1728,6 +1551,7 @@ static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y, //============================================================ // win_dialog_add_seqselect +// called from customise_input, customise_miscinput //============================================================ static int win_dialog_add_portselect(dialog_box *dialog, ioport_field *field) @@ -1780,8 +1604,7 @@ static int win_dialog_add_portselect(dialog_box *dialog, ioport_field *field) // create our local name for this entry; also convert from // MAME strings to wide strings len = strlen(port_name); - s = (char *) alloca((len + (port_suffix[seq] ? strlen(port_suffix[seq]) - : 0) + 1) * sizeof(*s)); + s = (char *) alloca((len + (port_suffix[seq] ? strlen(port_suffix[seq]) : 0) + 1) * sizeof(*s)); strcpy(s, port_name); if (port_suffix[seq]) @@ -1796,8 +1619,7 @@ static int win_dialog_add_portselect(dialog_box *dialog, ioport_field *field) return 1; x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING; - if (dialog_add_single_seqselect(di, x, y, DIM_EDIT_WIDTH, DIM_NORMAL_ROW_HEIGHT, - field, is_analog[seq], seq_types[seq])) + if (dialog_add_single_seqselect(di, x, y, DIM_EDIT_WIDTH, DIM_NORMAL_ROW_HEIGHT, field, is_analog[seq], seq_types[seq])) return 1; y += DIM_VERTICAL_SPACING + DIM_NORMAL_ROW_HEIGHT; x += DIM_EDIT_WIDTH + DIM_HORIZONTAL_SPACING; @@ -1810,24 +1632,6 @@ static int win_dialog_add_portselect(dialog_box *dialog, ioport_field *field) //============================================================ -// win_dialog_add_notification -//============================================================ - -static int win_dialog_add_notification(dialog_box *dialog, UINT notification, dialog_notification callback, void *param) -{ - // hack - if (!dialog->notify_callback) - printf("Unexpected result in win_dialog_add_notification\n"); - assert(!dialog->notify_callback); - dialog->notify_code = notification; - dialog->notify_callback = callback; - dialog->notify_param = param; - return 0; -} - - - -//============================================================ // win_dialog_add_standard_buttons //============================================================ @@ -1848,16 +1652,14 @@ static int win_dialog_add_standard_buttons(dialog_box *dialog) y = di->size_y + DIM_VERTICAL_SPACING; // display cancel button - if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT, - x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_CANCEL, DLGITEM_BUTTON, NULL)) + if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT, x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_CANCEL, DLGITEM_BUTTON, NULL)) return 1; // work out where OK button goes x -= DIM_HORIZONTAL_SPACING + DIM_BUTTON_WIDTH; // display OK button - if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT, - x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_OK, DLGITEM_BUTTON, NULL)) + if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT, x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_OK, DLGITEM_BUTTON, NULL)) return 1; di->size_y += DIM_BUTTON_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2; @@ -1886,13 +1688,13 @@ static void before_display_dialog(running_machine &machine) static void after_display_dialog(running_machine &machine) { winwindow_ui_pause(machine, FALSE); - //Machine = NULL; } //============================================================ // win_dialog_runmodal +// called from the various customise_inputs functions //============================================================ static void win_dialog_runmodal(running_machine &machine, HWND wnd, dialog_box *dialog) @@ -1913,68 +1715,11 @@ static void win_dialog_runmodal(running_machine &machine, HWND wnd, dialog_box * //============================================================ -// file_dialog_hook -//============================================================ - -static UINT_PTR CALLBACK file_dialog_hook(HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam) -{ - OPENFILENAME *ofn; - dialog_box *dialog; - UINT_PTR rc = 0; - LPNMHDR notify; - LONG_PTR l; - - switch(message) - { - case WM_INITDIALOG: - ofn = (OPENFILENAME *) lparam; - dialog = (dialog_box *) ofn->lCustData; - - SetWindowLongPtr(dlgwnd, GWLP_USERDATA, (LONG_PTR) dialog); - dialog_trigger(dlgwnd, TRIGGER_INITDIALOG); - rc = 1; - - // hack - if (dialog->notify_callback && (dialog->notify_code == CDN_TYPECHANGE)) - dialog->notify_callback(dialog, dlgwnd, NULL, dialog->notify_param); - break; - - case WM_NOTIFY: - notify = (LPNMHDR) lparam; - switch(notify->code) - { - case CDN_FILEOK: - dialog_trigger(dlgwnd, TRIGGER_APPLY); - break; - } - - // hack - l = GetWindowLongPtr(dlgwnd, GWLP_USERDATA); - dialog = (dialog_box *) l; - if (dialog->notify_callback && (notify->code == dialog->notify_code)) - dialog->notify_callback(dialog, dlgwnd, notify, dialog->notify_param); - break; - - case WM_COMMAND: - switch(HIWORD(wparam)) - { - case CBN_SELCHANGE: - dialog_trigger(dlgwnd, TRIGGER_CHANGED); - break; - } - break; - } - return rc; -} - - - -//============================================================ // win_file_dialog +// called from change_device //============================================================ -static BOOL win_file_dialog(running_machine &machine, - HWND parent, win_file_dialog_type dlgtype, dialog_box *custom_dialog, const char *filter, +static BOOL win_file_dialog(running_machine &machine, HWND parent, win_file_dialog_type dlgtype, const char *filter, const char *initial_dir, char *filename, size_t filename_len) { win_open_file_name ofn; @@ -1991,17 +1736,6 @@ static BOOL win_file_dialog(running_machine &machine, if (dlgtype == WIN_FILE_DIALOG_OPEN) ofn.flags |= OFN_FILEMUSTEXIST; - if (custom_dialog) - { - custom_dialog->style = WS_CHILD | WS_CLIPSIBLINGS | DS_3DLOOK | DS_CONTROL | DS_SETFONT; - dialog_prime(custom_dialog); - - ofn.flags |= OFN_ENABLETEMPLATEHANDLE | OFN_ENABLEHOOK; - ofn.instance = (HINSTANCE)custom_dialog->handle; - ofn.custom_data = (LPARAM) custom_dialog; - ofn.hook = file_dialog_hook; - } - snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s", filename); before_display_dialog(machine); @@ -2014,45 +1748,6 @@ static BOOL win_file_dialog(running_machine &machine, - -//============================================================ -// input_item_from_serial_number -//============================================================ -#if 0 -static int input_item_from_serial_number(running_machine &machine, int serial_number, - ioport_port **port, ioport_field **field, ioport_setting **setting) -{ - ioport_port *this_port = NULL; - ioport_field *this_field = NULL; - ioport_setting *this_setting = NULL; - - int i = 0; - for (this_port = machine.ioport().ports().first(); (i != serial_number) && (this_port); this_port = this_port->next()) - { - i++; - for (this_field = this_port->fields().first(); (i != serial_number) && (this_field); this_field = this_field->next()) - { - i++; - for (this_setting = this_field->settings().first(); (i != serial_number) && (this_setting); this_setting = this_setting->next()) - i++; - } - } - - if (this_field) - this_port = &this_field->port(); - - if (port) - *port = this_port; - if (field) - *field = this_field; - if (setting) - *setting = this_setting; - - return (i == serial_number); -} -#endif - - //============================================================ // customise_input //============================================================ @@ -2060,14 +1755,7 @@ static int input_item_from_serial_number(running_machine &machine, int serial_nu static void customise_input(running_machine &machine, HWND wnd, const char *title, int player, int inputclass) { dialog_box *dlg; - int this_inputclass = 0; - int this_player = 0, portslot_count = 0, i = 0; - const int max_portslots = 256; - - struct - { - ioport_field *field; - } portslots[max_portslots]; + int this_inputclass, this_player; /* create the dialog */ dlg = win_dialog_init(title, NULL); @@ -2089,35 +1777,12 @@ static void customise_input(running_machine &machine, HWND wnd, const char *titl && (this_player == player) && (this_inputclass == inputclass)) { - /* store this InputPort/RECT combo in our list. we do not - * necessarily want to add it yet because we the INI might - * want to reorder the tab order */ - if (portslot_count < max_portslots) - { - portslots[portslot_count].field = &field; - portslot_count++; - } + if (win_dialog_add_portselect(dlg, &field)) + goto done; } } } - /* finally add the portselects to the dialog */ - if (portslot_count > max_portslots) - portslot_count = max_portslots; - - /* No keyboard? Just exit */ - if (!portslot_count) - goto done; - - for (i = 0; i < portslot_count; i++) - { - if (portslots[i].field) - { - if (win_dialog_add_portselect(dlg, portslots[i].field)) - goto done; - } - } - /* ...and now add OK/Cancel */ if (win_dialog_add_standard_buttons(dlg)) goto done; @@ -2154,13 +1819,11 @@ static void customise_keyboard(running_machine &machine, HWND wnd) -//============================================================ +//=============================================================================================== // check_for_miscinput -// (to decide if "Miscellaneous Inputs" menu item should -// show or not). -// We do this here because the core check has been broken -// for years (always returns false). -//============================================================ +// (to decide if "Miscellaneous Inputs" menu item should show or not). +// We do this here because the core check has been broken for years (always returns false). +//=============================================================================================== static bool check_for_miscinput(running_machine &machine) { @@ -2196,16 +1859,9 @@ static bool check_for_miscinput(running_machine &machine) static void customise_miscinput(running_machine &machine, HWND wnd) { dialog_box *dlg; - int this_inputclass = 0; - int portslot_count = 0, i = 0; - const int max_portslots = 256; + int this_inputclass; const char *title = "Miscellaneous Inputs"; - struct - { - ioport_field *field; - } portslots[max_portslots]; - /* create the dialog */ dlg = win_dialog_init(title, NULL); if (!dlg) @@ -2225,31 +1881,12 @@ static void customise_miscinput(running_machine &machine, HWND wnd) && (this_inputclass != INPUT_CLASS_CONTROLLER) && (this_inputclass != INPUT_CLASS_KEYBOARD)) { - /* store this InputPort/RECT combo in our list. we do not - * necessarily want to add it yet because we the INI might - * want to reorder the tab order */ - if (portslot_count < max_portslots) - { - portslots[portslot_count].field = &field; - portslot_count++; - } + if (win_dialog_add_portselect(dlg, &field)) + goto done; } } } - /* finally add the portselects to the dialog */ - if (portslot_count > max_portslots) - portslot_count = max_portslots; - - for (i = 0; i < portslot_count; i++) - { - if (portslots[i].field) - { - if (win_dialog_add_portselect(dlg, portslots[i].field)) - goto done; - } - } - /* ...and now add OK/Cancel */ if (win_dialog_add_standard_buttons(dlg)) goto done; @@ -2266,6 +1903,7 @@ done: //============================================================ // storeval_inputport +// called from customise_switches //============================================================ static void storeval_inputport(void *param, int val) @@ -2379,10 +2017,18 @@ static void store_analogitem(void *param, int val, int selected_item) switch(selected_item) { - case ANALOG_ITEM_KEYSPEED: settings.delta = val; break; - case ANALOG_ITEM_CENTERSPEED: settings.centerdelta = val; break; - case ANALOG_ITEM_REVERSE: settings.reverse = val; break; - case ANALOG_ITEM_SENSITIVITY: settings.sensitivity = val; break; + case ANALOG_ITEM_KEYSPEED: + settings.delta = val; + break; + case ANALOG_ITEM_CENTERSPEED: + settings.centerdelta = val; + break; + case ANALOG_ITEM_REVERSE: + settings.reverse = val; + break; + case ANALOG_ITEM_SENSITIVITY: + settings.sensitivity = val; + break; } field->set_user_settings(settings); } @@ -2447,18 +2093,15 @@ static void customise_analogcontrols(running_machine &machine, HWND wnd) name = field.name(); afield = &field; - _snprintf(buf, ARRAY_LENGTH(buf), - "%s %s", name, "Digital Speed"); + _snprintf(buf, ARRAY_LENGTH(buf), "%s %s", name, "Digital Speed"); if (win_dialog_add_adjuster(dlg, buf, settings.delta, 1, 255, FALSE, store_delta, (void *) afield)) goto done; - _snprintf(buf, ARRAY_LENGTH(buf), - "%s %s", name, "Autocenter Speed"); - if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 1, 255, FALSE, store_centerdelta, (void *) afield)) + _snprintf(buf, ARRAY_LENGTH(buf), "%s %s", name, "Autocenter Speed"); + if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 0, 255, FALSE, store_centerdelta, (void *) afield)) goto done; - _snprintf(buf, ARRAY_LENGTH(buf), - "%s %s", name, "Reverse"); + _snprintf(buf, ARRAY_LENGTH(buf), "%s %s", name, "Reverse"); if (win_dialog_add_combobox(dlg, buf, settings.reverse ? 1 : 0, store_reverse, (void *) afield)) goto done; if (win_dialog_add_combobox_item(dlg, "Off", 0)) @@ -2466,8 +2109,7 @@ static void customise_analogcontrols(running_machine &machine, HWND wnd) if (win_dialog_add_combobox_item(dlg, "On", 1)) goto done; - _snprintf(buf, ARRAY_LENGTH(buf), - "%s %s", name, "Sensitivity"); + _snprintf(buf, ARRAY_LENGTH(buf), "%s %s", name, "Sensitivity"); if (win_dialog_add_adjuster(dlg, buf, settings.sensitivity, 1, 255, TRUE, store_sensitivity, (void *) afield)) goto done; } @@ -2487,6 +2129,7 @@ done: //============================================================ // win_dirname +// called from state_dialog //============================================================ static char *win_dirname(const char *filename) @@ -2523,11 +2166,10 @@ static char *win_dirname(const char *filename) //============================================================ // state_dialog +// called when loading or saving a state //============================================================ -static void state_dialog(HWND wnd, win_file_dialog_type dlgtype, - DWORD fileproc_flags, bool is_load, - running_machine &machine) +static void state_dialog(HWND wnd, win_file_dialog_type dlgtype, DWORD fileproc_flags, bool is_load, running_machine &machine) { win_open_file_name ofn; char *dir = NULL; @@ -2588,226 +2230,31 @@ static void state_save(running_machine &machine) //============================================================ -// format_combo_changed -//============================================================ - -static void format_combo_changed(dialog_box *dialog, HWND dlgwnd, NMHDR *notification, void *changed_param) -{ - HWND wnd; - int format_combo_val = 0; - device_image_interface *dev; - const option_guide *guide; - const char *optspec; - struct file_dialog_params *params; - int has_option = 0; - TCHAR t_buf1[128]; - char *utf8_buf1; - - params = (struct file_dialog_params *) changed_param; - - // locate the format control - format_combo_val = notification ? (((OFNOTIFY *) notification)->lpOFN->nFilterIndex - 1) : 0; - if (format_combo_val < 0) - format_combo_val = 0; - *(params->create_format) = format_combo_val; - - // compute our parameters - dev = params->dev; - guide = dev->device_get_creation_option_guide(); - optspec =dev->device_get_indexed_creatable_format(format_combo_val)->optspec(); - - // set the default extension - CommDlg_OpenSave_SetDefExt(GetParent(dlgwnd), - (const char*)dev->device_get_indexed_creatable_format(format_combo_val)->extensions()); - - // enumerate through all of the child windows - wnd = NULL; - while((wnd = FindWindowEx(dlgwnd, wnd, NULL, NULL))) - { - // get label text, removing trailing NULL - GetWindowText(wnd, t_buf1, ARRAY_LENGTH(t_buf1)); - utf8_buf1 = utf8_from_tstring(t_buf1); - assert(utf8_buf1[strlen(utf8_buf1)-1] == ':'); - utf8_buf1[strlen(utf8_buf1)-1] = '\0'; - - // find guide entry - while(guide->option_type && strcmp(utf8_buf1, guide->display_name)) - guide++; - - wnd = GetNextWindow(wnd, GW_HWNDNEXT); - if (wnd && guide) - { - // we now have the handle to the window, and the guide entry - has_option = option_resolution_contains(optspec, guide->parameter); - - SendMessage(wnd, CB_GETLBTEXT, SendMessage(wnd, CB_GETCURSEL, 0, 0), (LPARAM) t_buf1); - SendMessage(wnd, CB_RESETCONTENT, 0, 0); - - win_prepare_option_control(wnd, - has_option ? guide : NULL, - has_option ? optspec : NULL); - } - osd_free(utf8_buf1); - } -} - - - -//============================================================ -// storeval_option_resolution -//============================================================ - -struct storeval_optres_params -{ - struct file_dialog_params *fdparams; - const option_guide *guide_entry; -}; - -static void storeval_option_resolution(void *storeval_param, int val) -{ - option_resolution *resolution; - struct storeval_optres_params *params; - device_image_interface *dev; - char buf[16]; - - params = (struct storeval_optres_params *) storeval_param; - dev = params->fdparams->dev; - - // create the resolution, if necessary - resolution = *(params->fdparams->create_args); - if (!resolution) - { - const option_guide *optguide = dev->device_get_creation_option_guide(); - const image_device_format *format = dev->device_get_indexed_creatable_format(*(params->fdparams->create_format)); - - resolution = option_resolution_create(optguide, format->optspec()); - if (!resolution) - return; - *(params->fdparams->create_args) = resolution; - } - - snprintf(buf, ARRAY_LENGTH(buf), "%d", val); - option_resolution_add_param(resolution, params->guide_entry->identifier, buf); -} - - - -//============================================================ -// build_option_dialog -//============================================================ - -static dialog_box *build_option_dialog(device_image_interface *dev, char *filter, size_t filter_len, int *create_format, option_resolution **create_args) -{ - dialog_box *dialog; - const option_guide *guide_entry; - int found = 0, pos = 0; - char buf[256]; - struct file_dialog_params *params; - struct storeval_optres_params *storeval_params; - static const struct dialog_layout filedialog_layout = { 44, 220 }; - - // make the filter - pos = 0; - for (auto &format : dev->formatlist()) - pos += add_filter_entry(filter + pos, filter_len - pos, format->description(), format->extensions()); - - // create the dialog - dialog = win_dialog_init(NULL, &filedialog_layout); - if (!dialog) - goto error; - - // allocate the params - params = global_alloc(file_dialog_params); - if (!params) - goto error; - params->dev = dev; - params->create_format = create_format; - params->create_args = create_args; - - // set the notify handler; so that we get notified when the format dialog changed - if (win_dialog_add_notification(dialog, CDN_TYPECHANGE, format_combo_changed, params)) - goto error; - - // loop through the entries - for (guide_entry = dev->device_get_creation_option_guide(); guide_entry->option_type != OPTIONTYPE_END; guide_entry++) - { - // make sure that this entry is present on at least one option specification - found = FALSE; - for (auto &format : dev->formatlist()) - { - if (option_resolution_contains(format->optspec(), guide_entry->parameter)) - { - found = TRUE; - break; - } - } - - if (found) - { - storeval_params = global_alloc(storeval_optres_params); - if (!storeval_params) - goto error; - storeval_params->fdparams = params; - storeval_params->guide_entry = guide_entry; - - // this option is present on at least one of the specs - switch(guide_entry->option_type) - { - case OPTIONTYPE_INT: - snprintf(buf, ARRAY_LENGTH(buf), "%s:", guide_entry->display_name); - if (win_dialog_add_combobox(dialog, buf, 0, storeval_option_resolution, storeval_params)) - goto error; - break; - - default: - break; - } - } - } - - return dialog; - -error: - if (dialog) - win_dialog_exit(dialog); - return NULL; -} - - - -//============================================================ // copy_extension_list //============================================================ -static int copy_extension_list(char *dest, size_t dest_len, const char *extensions) +static void copy_extension_list(std::string &dest, const char *extensions) { - const char *s; - int pos = 0; - // our extension lists are comma delimited; Win32 expects to see lists // delimited by semicolons - s = extensions; - while(*s) + char const *s = extensions; + while (*s) { // append a semicolon if not at the beginning if (s != extensions) - pos += snprintf(&dest[pos], dest_len - pos, ";"); + dest.push_back(';'); // append ".*" - pos += snprintf(&dest[pos], dest_len - pos, "*."); + dest.append("*."); // append the file extension - while(*s && (*s != ',')) - { - pos += snprintf(&dest[pos], dest_len - pos, "%c", *s); - s++; - } + while (*s && (*s != ',')) + dest.push_back(*s++); // if we found a comma, advance while(*s == ',') s++; } - return pos; } @@ -2816,26 +2263,23 @@ static int copy_extension_list(char *dest, size_t dest_len, const char *extensio // add_filter_entry //============================================================ -static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions) +static void add_filter_entry(std::string &dest, const char *description, const char *extensions) { - int pos = 0; - // add the description - pos += snprintf(&dest[pos], dest_len - pos, "%s (", description); + dest.append(description); + dest.append(" ("); // add the extensions to the description - pos += copy_extension_list(&dest[pos], dest_len - pos, extensions); + copy_extension_list(dest, extensions); // add the trailing rparen and '|' character - pos += snprintf(&dest[pos], dest_len - pos, ")|"); + dest.append(")|"); // now add the extension list itself - pos += copy_extension_list(&dest[pos], dest_len - pos, extensions); + copy_extension_list(dest, extensions); // append a '|' - pos += snprintf(&dest[pos], dest_len - pos, "|"); - - return pos; + dest.append("|"); } @@ -2844,55 +2288,36 @@ static int add_filter_entry(char *dest, size_t dest_len, const char *description // build_generic_filter //============================================================ -static void build_generic_filter(device_image_interface *dev, bool is_save, char *filter, size_t filter_len) +static void build_generic_filter(device_image_interface *img, bool is_save, std::string &filter) { - char *s; + std::string file_extension = img->file_extensions(); - const char *file_extension; - - /* copy the string */ - file_extension = dev->file_extensions(); - const char* s2 = ",zip,7z"; // Add ZIP extension as a default. - char *result = (LPSTR) alloca(strlen(file_extension)+strlen(s2)+1); - strcpy(result, file_extension); if (!is_save) - strcat(result, s2); - - // start writing the filter - s = filter; + file_extension.append(",zip,7z"); - // common image types - s += add_filter_entry(filter, filter_len, "Common image types", result); - //free(result); + add_filter_entry(filter, "Common image types", file_extension.c_str()); - // all files - s += sprintf(s, "All files (*.*)|*.*|"); + filter.append("All files (*.*)|*.*|"); - // compressed if (!is_save) - s += sprintf(s, "Compressed Images (*.zip;*.7z)|*.zip;*.7z|"); - - *(s++) = '\0'; + filter.append("Compressed Images (*.zip;*.7z)|*.zip;*.7z|"); } //============================================================ // change_device +// open a dialog box to open or create a software file //============================================================ static void change_device(HWND wnd, device_image_interface *image, bool is_save) { - dialog_box *dialog = NULL; - char filter[2048]; + std::string filter; char filename[MAX_PATH]; const char *initial_dir; BOOL result = 0; int create_format = 0; - option_resolution *create_args = NULL; - - // sanity check - assert(image); + util::option_resolution *create_args = NULL; // get the file if (image->exists()) @@ -2925,22 +2350,12 @@ static void change_device(HWND wnd, device_image_interface *image, bool is_save) // NOTE: the working directory can come from the .cfg file. If it's wrong delete the cfg. //printf("%s = %s = %s = %s\n",dst,working,initial_dir,software_dir); - // add custom dialog elements, if appropriate - if (is_save - && (image->device_get_creation_option_guide()) - && (image->formatlist().front())) - { - dialog = build_option_dialog(image, filter, ARRAY_LENGTH(filter), &create_format, &create_args); - if (!dialog) - goto done; - } - else - // build a normal filter - build_generic_filter(image, is_save, filter, ARRAY_LENGTH(filter)); + + // build a normal filter + build_generic_filter(image, is_save, filter); // display the dialog - result = win_file_dialog(image->device().machine(), wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN, - dialog, filter, initial_dir, filename, ARRAY_LENGTH(filename)); + result = win_file_dialog(image->device().machine(), wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN, filter.c_str(), initial_dir, filename, ARRAY_LENGTH(filename)); if (result) { // mount the image @@ -2952,12 +2367,6 @@ static void change_device(HWND wnd, device_image_interface *image, bool is_save) // no need to check the returnvalue and show a messagebox anymore. // a UI message will now be generated by the image code } - -done: - if (dialog) - win_dialog_exit(dialog); - if (create_args) - option_resolution_close(create_args); } @@ -3021,7 +2430,7 @@ static HMENU find_sub_menu(HMENU menu, const char *menutext, bool create_sub_men while(*menutext) { - TCHAR *t_menutext = tstring_from_utf8(menutext); + TCHAR *t_menutext = ui_wstring_from_utf8(menutext); int i = -1; do @@ -3199,10 +2608,10 @@ static void prepare_menus(HWND wnd) speed = window->machine().video().throttled() ? window->machine().video().speed_factor() : 0; - has_config = window->machine().ioport().type_class_present(INPUT_CLASS_CONFIG); - has_dipswitch = window->machine().ioport().type_class_present(INPUT_CLASS_DIPSWITCH); - has_keyboard = window->machine().ioport().type_class_present(INPUT_CLASS_KEYBOARD); - has_misc = check_for_miscinput(window->machine()); + has_config = window->machine().ioport().type_class_present(INPUT_CLASS_CONFIG); + has_dipswitch = window->machine().ioport().type_class_present(INPUT_CLASS_DIPSWITCH); + has_keyboard = window->machine().ioport().type_class_present(INPUT_CLASS_KEYBOARD); + has_misc = check_for_miscinput(window->machine()); has_analog = 0; for (auto &port : window->machine().ioport().ports()) @@ -3274,9 +2683,8 @@ static void prepare_menus(HWND wnd) view_index = window->m_target->view(); while((view_name = window->m_target->view_name(i))) { - TCHAR *t_view_name = tstring_from_utf8(view_name); - InsertMenu(video_menu, i, MF_BYPOSITION | (i == view_index ? MF_CHECKED : 0), - ID_VIDEO_VIEW_0 + i, t_view_name); + TCHAR *t_view_name = ui_wstring_from_utf8(view_name); + InsertMenu(video_menu, i, MF_BYPOSITION | (i == view_index ? MF_CHECKED : 0), ID_VIDEO_VIEW_0 + i, t_view_name); osd_free(t_view_name); i++; } @@ -3312,8 +2720,8 @@ static void prepare_menus(HWND wnd) cassette_state state; state = (cassette_state)(img.exists() ? (dynamic_cast<cassette_image_device*>(&img.device())->get_state() & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED); win_append_menu_utf8(sub_menu, MF_SEPARATOR, 0, NULL); - win_append_menu_utf8(sub_menu, flags_for_exists | ((state == CASSETTE_STOPPED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_STOPPAUSE, "Pause/Stop"); - win_append_menu_utf8(sub_menu, flags_for_exists | ((state == CASSETTE_PLAY) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_PLAY, "Play"); + win_append_menu_utf8(sub_menu, flags_for_exists | ((state == CASSETTE_STOPPED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_STOPPAUSE, "Pause/Stop"); + win_append_menu_utf8(sub_menu, flags_for_exists | ((state == CASSETTE_PLAY) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_PLAY, "Play"); win_append_menu_utf8(sub_menu, flags_for_writing | ((state == CASSETTE_RECORD) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_RECORD, "Record"); win_append_menu_utf8(sub_menu, flags_for_exists, new_item + DEVOPTION_CASSETTE_REWIND, "Rewind"); win_append_menu_utf8(sub_menu, flags_for_exists, new_item + DEVOPTION_CASSETTE_FASTFORWARD, "Fast Forward"); @@ -3395,10 +2803,7 @@ static void win_toggle_menubar(void) { RECT window_rect; GetWindowRect(hwnd, &window_rect); - SetWindowPos(hwnd, HWND_TOP, 0, 0, - window_rect.right - window_rect.left + width_diff, - window_rect.bottom - window_rect.top + height_diff, - SWP_NOMOVE | SWP_NOZORDER); + SetWindowPos(hwnd, HWND_TOP, 0, 0, window_rect.right - window_rect.left + width_diff, window_rect.bottom - window_rect.top + height_diff, SWP_NOMOVE | SWP_NOZORDER); } RedrawWindow(hwnd, NULL, NULL, 0); @@ -3409,6 +2814,7 @@ static void win_toggle_menubar(void) //============================================================ // device_command +// This handles all options under the "Media" dropdown //============================================================ static void device_command(HWND wnd, device_image_interface *img, int devoption) @@ -3489,7 +2895,7 @@ static void help_display(HWND wnd, const char *chapter) if (!is_windowed()) winwindow_toggle_full_screen(); - TCHAR *t_chapter = tstring_from_utf8(chapter); + TCHAR *t_chapter = ui_wstring_from_utf8(chapter); // htmlhelp(wnd, t_chapter, 0 /*HH_DISPLAY_TOPIC*/, 0); // TCHAR *szSite = new TCHAR[100]; // _tcscpy(szSite, TEXT("http://messui.the-chronicles.org/onlinehelp/")); @@ -3585,10 +2991,10 @@ static int pause_for_command(UINT command) // invoke_command //============================================================ -static int invoke_command(HWND wnd, UINT command) +static bool invoke_command(HWND wnd, UINT command) { std::string error_string; - int handled = 1; + bool handled = TRUE; int dev_command = 0; device_image_interface *img; LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA); @@ -3772,13 +3178,9 @@ static int invoke_command(HWND wnd, UINT command) window->m_target->set_view(command - ID_VIDEO_VIEW_0); window->update(); // actually change window size } -// else -// if (input_item_from_serial_number(window->machine(), command - ID_INPUT_0, NULL, &field, &setting)) - // should never happen -// handled = 0; else // bogus command - handled = 0; + handled = FALSE; break; } @@ -3802,7 +3204,7 @@ static void set_menu_text(HMENU menu_bar, int command, const char *text) MENUITEMINFO mii; // convert to TCHAR - t_text = tstring_from_utf8(text); + t_text = ui_wstring_from_utf8(text); // invoke SetMenuItemInfo() memset(&mii, 0, sizeof(mii)); @@ -3854,8 +3256,7 @@ static int win_setup_menus(running_machine &machine, HMODULE module, HMENU menu_ char *src; char *dst; - snprintf(state_filename, ARRAY_LENGTH(state_filename), - "%s State", machine.system().description); + snprintf(state_filename, ARRAY_LENGTH(state_filename), "%s State", machine.system().description); src = state_filename; dst = state_filename; |