Previous 15994 Revisions Next

r10019 Thursday 13th January, 2011 at 09:10:22 UTC by Miodrag Milanović
- NEWUI is transfered to be part of WINUI
- WINUI is now build only if OSD=winui is specified in command line
- for now NEWUI is always enabled for WINUI build (will be fixed)
[src/emu]emuopts.c ui.c ui.h
[src/mess/osd/windows]dialog.c dialog.h menu.c menu.h mess.ico* mess.rc messres.h opcntrl.c opcntrl.h windows.mak winutils.c winutils.h
[src/mess/osd/winui]dialog.c* dialog.h* menu.c* menu.h* mess.rc* messres.h* opcntrl.c* opcntrl.h* propertiesms.c resourcems.h winui.mak winutils.c* winutils.h*
[src/osd/windows]debugwin.c drawdd.c eivc.h input.c vconv.c video.c winalloc.c window.c window.h windows.mak
[src/osd/winui]mameui.rc winui.mak

src/osd/windows/windows.mak
r10018r10019
107107
108108ifdef MSVC_BUILD
109109
110VCONV = $(WINOBJ)/vconv$(EXE)
111VCONVPREFIX = $(subst /,\,$(VCONV))
110OSPREBUILD = $(VCONV_TARGET)
112111
113112# append a 'v' prefix if nothing specified
114113ifndef PREFIX
r10018r10019
116115endif
117116
118117# replace the various compilers with vconv.exe prefixes
119CC = @$(VCONVPREFIX) gcc -I.
120LD = @$(VCONVPREFIX) ld /profile
121AR = @$(VCONVPREFIX) ar
122RC = @$(VCONVPREFIX) windres
118CC = @$(VCONV) gcc -I.
119LD = @$(VCONV) ld /profile
120AR = @$(VCONV) ar
121RC = @$(VCONV) windres
123122
124123# make sure we use the multithreaded runtime
125124ifdef DEBUG
r10018r10019
156155# disable better packing warning
157156CPPONLYFLAGS += /wd4371
158157
158# disable macro redefinition warning
159CCOMFLAGS += /wd4005
160
159161# explicitly set the entry point for UNICODE builds
160162LDFLAGS += /ENTRY:wmainCRTStartup
161163
162164# add some VC++-specific defines
163165DEFS += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DXML_STATIC -Dsnprintf=_snprintf
164166
165# make msvcprep into a pre-build step
166OSPREBUILD = $(VCONV)
167
168ifneq ($(CROSS_BUILD),1)
169# add VCONV to the build tools
170BUILD += $(VCONV)
171
172$(VCONV): $(WINOBJ)/vconv.o
173   @echo Linking $@...
174   @link.exe /nologo $^ version.lib /out:$@
175
176$(WINOBJ)/vconv.o: $(WINSRC)/vconv.c
177   @echo Compiling $<...
178   @cl.exe /nologo /O1 -D_CRT_SECURE_NO_DEPRECATE -c $< /Fo$@
179
180167OSDCLEAN = msvcclean
181168
182169msvcclean:
r10018r10019
186173   $(RM) *.exp
187174
188175endif
176
177
178#-------------------------------------------------
179# build VCONV
180#-------------------------------------------------
181
182VCONV_TARGET = $(BUILDOUT)/vconv$(BUILD_EXE)
183VCONV = $(subst /,\,$(VCONV_TARGET))
184
185ifneq ($(CROSS_BUILD),1)
186BUILD += \
187   $(VCONV_TARGET)
189188endif
190189
190$(VCONV_TARGET): $(WINOBJ)/vconv.o
191   @echo Linking $@...
192   @gcc.exe -static-libgcc $^ $(LIBS) -lversion -o $@
191193
194$(WINOBJ)/vconv.o: $(WINSRC)/vconv.c
195   @echo Compiling $<...
196   @gcc.exe -O3 -c $< -o $@
197
198
199
192200#-------------------------------------------------
193201# due to quirks of using /bin/sh, we need to
194202# explicitly specify the current path
src/osd/windows/eivc.h
r10018r10019
4747#if (_MSC_VER >= 1400)
4848#include <intrin.h>
4949#else
50long __cdecl _InterlockedIncrement(long volatile *);
51long __cdecl _InterlockedDecrement(long volatile *);
52long _InterlockedExchange(long volatile *, long);
53long _InterlockedCompareExchange (long volatile *, long, long);
54long _InterlockedExchangeAdd(long volatile *, long);
55unsigned char _BitScanReverse(unsigned long *Index, unsigned long Mask);
50extern "C" long __cdecl _InterlockedIncrement(long volatile *);
51extern "C" long __cdecl _InterlockedDecrement(long volatile *);
52extern "C" long _InterlockedExchange(long volatile *, long);
53extern "C" long _InterlockedCompareExchange (long volatile *, long, long);
54extern "C" long _InterlockedExchangeAdd(long volatile *, long);
55extern "C" unsigned char _BitScanReverse(unsigned long *Index, unsigned long Mask);
5656#endif
5757
5858#pragma intrinsic(_InterlockedIncrement)
src/osd/windows/vconv.c
r10018r10019
288288   else if (!strcmp(argv[1], "ar"))
289289   {
290290      transtable = ar_translate;
291      executable = "lib.exe";
291      executable = "link.exe";
292292      dst += sprintf(dst, "link /lib /nologo ");
293293      outstring = "/out:";
294294      output_is_first = 1;
src/osd/windows/input.c
r10018r10019
773773            typedesc->name = "Toggle Fullscreen";
774774            input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_LALT, KEYCODE_ENTER);
775775            break;
776
777         case IPT_OSD_2:
778            if (ui_use_newui())
779            {
780               typedesc->token = "TOGGLE_MENUBAR";
781               typedesc->name = "Toggle Menu Bar";
782               input_seq_set_1(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_ESC);
783            }
784            break;
785
786#ifdef MESS
787         case IPT_UI_THROTTLE:
788            input_seq_set_1(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F10);
789            break;
790#endif
791776      }
792777}
793778
src/osd/windows/debugwin.c
r10018r10019
13291329      }
13301330
13311331      // keydown: handle debugger keys
1332      case WM_SYSKEYDOWN:
1333         if (wparam != VK_F10)
1334            return DefWindowProc(wnd, message, wparam, lparam);
1335         // (fall through)
13321336      case WM_KEYDOWN:
13331337      {
13341338         if ((*info->owner->handle_key)(info->owner, wparam, lparam))
r10018r10019
14961500   switch (message)
14971501   {
14981502      // key down: handle navigation in the attached view
1503      case WM_SYSKEYDOWN:
1504         if (wparam != VK_F10)
1505            return CallWindowProc(info->original_editproc, wnd, message, wparam, lparam);
1506         // (fall through)
14991507      case WM_KEYDOWN:
15001508         switch (wparam)
15011509         {
src/osd/windows/drawdd.c
r10018r10019
605605   if (dd->membuffer == NULL)
606606      goto error;
607607
608#ifdef MESS
609   // create a clipper for all modes, since MESS has dialogs
610   if (create_clipper(window))
611      goto error;
612#else
613608   // create a clipper for windowed mode
614609   if (!window->fullscreen && create_clipper(window))
615610      goto error;
616#endif
617611
618612   // full screen mode: set the gamma
619613   if (window->fullscreen)
src/osd/windows/video.c
r10018r10019
6767#include "strconv.h"
6868#include "config.h"
6969
70#ifdef MESS
71#include "menu.h"
72#endif
73
74
7570//============================================================
7671//  GLOBAL VARIABLES
7772//============================================================
r10018r10019
371366   // check for toggling fullscreen mode
372367   if (ui_input_pressed(machine, IPT_OSD_1))
373368      winwindow_toggle_full_screen();
374
375#ifdef MESS
376   // check for toggling menu bar (only if ui is active)
377   if (ui_input_pressed(machine, IPT_OSD_2) && machine->ui_active)
378      win_toggle_menubar();
379#endif
380369}
381370
382371
src/osd/windows/window.c
r10018r10019
6969#include "config.h"
7070#include "winutf8.h"
7171
72#ifdef MESS
73#include "menu.h"
74#endif /* MESS */
75
7672extern int drawnone_init(win_draw_callbacks *callbacks);
7773extern int drawgdi_init(win_draw_callbacks *callbacks);
7874extern int drawdd_init(win_draw_callbacks *callbacks);
r10018r10019
834830      // initialize the description of the window class
835831      wc.lpszClassName   = TEXT("MAME");
836832      wc.hInstance      = GetModuleHandle(NULL);
837#ifdef MESS
838      wc.lpfnWndProc      = win_mess_window_proc;
833#ifdef MENU_BAR
834      LRESULT CALLBACK winwindow_video_window_proc_ui(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
835      wc.lpfnWndProc      = winwindow_video_window_proc_ui;
839836#else
840837      wc.lpfnWndProc      = winwindow_video_window_proc;
841838#endif
src/osd/windows/winalloc.c
r10018r10019
582582   InitializeCriticalSection(&memory_lock);
583583
584584   // determine if we enabled by default
585#ifdef MESS
586   {
587      extern BOOL win_is_gui_application(void);
588      use_malloc_tracking = !win_is_gui_application();
589   }
590#elif defined(WINUI)
585#if defined(WINUI)
591586   use_malloc_tracking = FALSE;
592587#else
593588   use_malloc_tracking = TRUE;
src/osd/windows/window.h
r10018r10019
5050//  PARAMETERS
5151//============================================================
5252
53#ifndef MESS
53#ifndef MENU_BAR
5454#define HAS_WINDOW_MENU         FALSE
5555#else
5656#define HAS_WINDOW_MENU         TRUE
r10018r10019
165165void winwindow_ui_exec_on_main_thread(void (*func)(void *), void *param);
166166void winwindow_dispatch_message(running_machine *machine, MSG *message);
167167
168#if HAS_WINDOW_MENU
169int win_create_menu(running_machine *machine, HMENU *menus);
170#endif
168extern int win_create_menu(running_machine *machine, HMENU *menus);
171169
172170
173171
src/osd/winui/mameui.rc
r10018r10019
33#include "resource.h"
44
55#ifdef MESS
6#include "resourcems.h"
6#include "../../mess/osd/winui/resourcems.h "
77#endif
88
99// Generated Help ID header file
r10018r10019
942942    PUSHBUTTON      "Reset",IDC_PROP_RESET,4,222,97,14,0,0,HIDC_PROP_RESET
943943    PUSHBUTTON      "Restore Default Settings",IDC_USE_DEFAULT,118,222,97,14,
944944                    0,0,HIDC_USE_DEFAULT
945#ifdef MESS
946    CONTROL         "Use New UI",IDC_USE_NEW_UI,"Button",
947                    BS_AUTOCHECKBOX | WS_TABSTOP,119,134,86,10,0
948#endif
949945END
950946
951947IDD_PROP_VECTOR DIALOGEX 0, 0, 220, 240
src/osd/winui/winui.mak
r10018r10019
5555# append "ui" to the emulator name
5656#-------------------------------------------------
5757
58ifdef PTR64
59EMULATOR = $(NAME)ui64$(EXE)
60else
61EMULATOR = $(NAME)ui32$(EXE)
62endif
58EMULATOR = $(PREFIX)$(NAME)ui$(SUFFIX)$(SUFFIX64)$(SUFFIXDEBUG)$(EXE)
6359
64
6560#-------------------------------------------------
6661# object and source roots
6762#-------------------------------------------------
r10018r10019
312307   $(UIOBJ)/history.o \
313308   $(UIOBJ)/dialogs.o \
314309   $(UIOBJ)/mui_opts.o \
315   $(UIOBJ)/layout.o \
316310   $(UIOBJ)/datafile.o \
317311   $(UIOBJ)/dirwatch.o \
318312   $(UIOBJ)/winui.o \
319313   $(UIOBJ)/helpids.o \
320314
321315
316ifeq ($(TARGET),mame)
317OSDOBJS += \
318   $(UIOBJ)/layout.o
319endif
320
322321# extra dependencies
323322$(WINOBJ)/drawdd.o :    $(SRC)/emu/rendersw.c
324323$(WINOBJ)/drawgdi.o :   $(SRC)/emu/rendersw.c
r10018r10019
408407#-------------------------------------------------
409408# rules for resource file
410409#-------------------------------------------------
411
410ifeq ($(TARGET),mame)
412411$(UIOBJ)/mamevers.rc: $(OBJ)/build/verinfo$(EXE) $(SRC)/version.c
413412   @echo Emitting $@...
414413   @"$(OBJ)/build/verinfo$(EXE)" -b winui $(SRC)/version.c > $@
414endif
415415
416416
417417
418
419418#####  End windui.mak ##############################################
420419
src/emu/emuopts.c
r10018r10019
160160   { "skip_gameinfo",               "0",         OPTION_BOOLEAN,    "skip displaying the information screen at startup" },
161161   { "uifont",                   "default",   0,                 "specify a font to use" },
162162   { "ramsize;ram",             NULL,           0,             "size of RAM (if supported by driver)" },
163#ifdef MESS   
164   { "newui;nu",                    "0",        OPTION_BOOLEAN,    "use the new MESS UI" },
165#endif
166163
167164   /* image device options */
168165   { OPTION_ADDED_DEVICE_OPTIONS,    "0",        OPTION_BOOLEAN | OPTION_INTERNAL,   "image device-specific options have been added" },
src/emu/ui.c
r10018r10019
11751175   return state;
11761176}
11771177
1178
11791178/*-------------------------------------------------
1180    ui_use_newui - determines if "newui" is in use
1181-------------------------------------------------*/
1182
1183int ui_use_newui( void )
1184{
1185   #ifdef MESS
1186   #if (defined(WIN32) || defined(_MSC_VER)) && !defined(SDLMAME_WIN32)
1187      if (options_get_bool(mame_options(), "newui"))
1188         return TRUE;
1189   #endif
1190   #endif
1191   return FALSE;
1192}
1193
1194/*-------------------------------------------------
11951179    process_natural_keyboard - processes any
11961180    natural keyboard input
11971181-------------------------------------------------*/
r10018r10019
13681352
13691353   if (ui_disabled) return ui_disabled;
13701354
1371   /* if the user pressed ESC, stop the emulation (except in MESS with newui, where ESC toggles the menubar) */
1372   if (ui_input_pressed(machine, IPT_UI_CANCEL) && !ui_use_newui())
1355   if (ui_input_pressed(machine, IPT_UI_CANCEL))
13731356      machine->schedule_exit();
13741357
13751358   /* turn on menus if requested */
1376   if (ui_input_pressed(machine, IPT_UI_CONFIGURE) && !ui_use_newui())
1359   if (ui_input_pressed(machine, IPT_UI_CONFIGURE))
13771360      return ui_set_handler(ui_menu_ui_handler, 0);
13781361
13791362   /* if the on-screen display isn't up and the user has toggled it, turn it on */
src/emu/ui.h
r10018r10019
181181/* paste */
182182void ui_paste(running_machine *machine);
183183
184int ui_use_newui(void);
185
186184/* returns whether the natural keyboard is active */
187185int ui_get_use_natural_keyboard(running_machine *machine);
188186
src/mess/osd/windows/winutils.c
r10018r10019
1//============================================================
2//
3//  winutils.c - Generic Win32 utility code
4//
5//============================================================
6
7// Needed for better file dialog
8#ifdef _WIN32_WINNT
9#undef _WIN32_WINNT
10#endif // _WIN32_WINNT
11#define _WIN32_WINNT 0x500
12
13// standard windows headers
14#define WIN32_LEAN_AND_MEAN
15#include <windows.h>
16#include <commdlg.h>
17#include <tchar.h>
18#include <stdlib.h>
19
20// MESS headers
21#include "winutils.h"
22#include "strconv.h"
23
24// stupid hack; not sure why this is needed
25#ifdef const
26#undef const
27#endif // const
28
29
30
31//============================================================
32//  win_get_file_name_dialog - sanitize all of the ugliness
33//  in invoking GetOpenFileName() and GetSaveFileName()
34//============================================================
35
36BOOL win_get_file_name_dialog(win_open_file_name *ofn)
37{
38   BOOL result = FALSE;
39   BOOL dialog_result;
40   OSVERSIONINFO vers;
41   OPENFILENAME os_ofn;
42   DWORD os_ofn_size;
43   LPTSTR t_filter = NULL;
44   LPTSTR t_file = NULL;
45   DWORD t_file_size = 0;
46   LPTSTR t_initial_directory = NULL;
47   LPTSTR buffer;
48   char *utf8_file;
49   int i;
50
51   // determine the version of Windows
52   memset(&vers, 0, sizeof(vers));
53   vers.dwOSVersionInfoSize = sizeof(vers);
54   GetVersionEx(&vers);
55
56   // based on the version of Windows, determine the correct struct size
57   if (vers.dwMajorVersion >= 5)
58   {
59      os_ofn_size = sizeof(os_ofn);
60   }
61   else
62   {
63#ifdef __GNUC__
64      os_ofn_size = 76;   // MinGW does not define OPENFILENAME_NT4
65#else
66      os_ofn_size = sizeof(OPENFILENAME_NT4);
67#endif
68   }
69
70   // do we have to translate the filter?
71   if (ofn->filter != NULL)
72   {
73      buffer = tstring_from_utf8(ofn->filter);
74      if (!buffer)
75         goto done;
76
77      // convert a pipe-char delimited string into a NUL delimited string
78      t_filter = (LPTSTR) alloca((_tcslen(buffer) + 2) * sizeof(*t_filter));
79      for (i = 0; buffer[i] != '\0'; i++)
80         t_filter[i] = (buffer[i] != '|') ? buffer[i] : '\0';
81      t_filter[i++] = '\0';
82      t_filter[i++] = '\0';
83      osd_free(buffer);
84   }
85
86   // do we need to translate the file parameter?
87   if (ofn->filename != NULL)
88   {
89      buffer = tstring_from_utf8(ofn->filename);
90      if (!buffer)
91         goto done;
92
93      t_file_size = MAX(_tcslen(buffer) + 1, MAX_PATH);
94      t_file = (LPTSTR) alloca(t_file_size * sizeof(*t_file));
95      _tcscpy(t_file, buffer);
96      osd_free(buffer);
97   }
98
99   // do we need to translate the initial directory?
100   if (ofn->initial_directory != NULL)
101   {
102      t_initial_directory = tstring_from_utf8(ofn->initial_directory);
103      if (t_initial_directory == NULL)
104         goto done;
105   }
106
107   // translate our custom structure to a native Win32 structure
108   memset(&os_ofn, 0, sizeof(os_ofn));
109   os_ofn.lStructSize = os_ofn_size;
110   os_ofn.hwndOwner = ofn->owner;
111   os_ofn.hInstance = ofn->instance;
112   os_ofn.lpstrFilter = t_filter;
113   os_ofn.nFilterIndex = ofn->filter_index;
114   os_ofn.lpstrFile = t_file;
115   os_ofn.nMaxFile = t_file_size;
116   os_ofn.lpstrInitialDir = t_initial_directory;
117   os_ofn.Flags = ofn->flags;
118   os_ofn.lCustData = ofn->custom_data;
119   os_ofn.lpfnHook = ofn->hook;
120   os_ofn.lpTemplateName = ofn->template_name;
121
122   // invoke the correct Win32 call
123   switch(ofn->type)
124   {
125      case WIN_FILE_DIALOG_OPEN:
126         dialog_result = GetOpenFileName(&os_ofn);
127         break;
128
129      case WIN_FILE_DIALOG_SAVE:
130         dialog_result = GetSaveFileName(&os_ofn);
131         break;
132
133      default:
134         // should not reach here
135         dialog_result = FALSE;
136         break;
137   }
138
139   // copy data out
140   ofn->filter_index = os_ofn.nFilterIndex;
141   ofn->flags = os_ofn.Flags;
142
143   // copy file back out into passed structure
144   if (t_file != NULL)
145   {
146      utf8_file = utf8_from_tstring(t_file);
147      if (!utf8_file)
148         goto done;
149
150      snprintf(ofn->filename, ARRAY_LENGTH(ofn->filename), "%s", utf8_file);
151      osd_free(utf8_file);
152   }
153
154   // we've completed the process
155   result = dialog_result;
156
157done:
158   if (t_initial_directory != NULL)
159      osd_free(t_initial_directory);
160   return result;
161}
162
163
164
165//============================================================
166//  win_scroll_window
167//============================================================
168
169void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line)
170{
171   SCROLLINFO si;
172   int scroll_pos;
173
174   // retrieve vital info about the scroll bar
175   memset(&si, 0, sizeof(si));
176   si.cbSize = sizeof(si);
177   si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
178   GetScrollInfo(window, scroll_bar, &si);
179
180   scroll_pos = si.nPos;
181
182   // change scroll_pos in accordance with this message
183   switch(LOWORD(wparam))
184   {
185      case SB_BOTTOM:
186         scroll_pos = si.nMax;
187         break;
188      case SB_LINEDOWN:
189         scroll_pos += scroll_delta_line;
190         break;
191      case SB_LINEUP:
192         scroll_pos -= scroll_delta_line;
193         break;
194      case SB_PAGEDOWN:
195         scroll_pos += scroll_delta_line;
196         break;
197      case SB_PAGEUP:
198         scroll_pos -= scroll_delta_line;
199         break;
200      case SB_THUMBPOSITION:
201      case SB_THUMBTRACK:
202         scroll_pos = HIWORD(wparam);
203         break;
204      case SB_TOP:
205         scroll_pos = si.nMin;
206         break;
207   }
208
209   // max out the scroll bar value
210   if (scroll_pos < si.nMin)
211      scroll_pos = si.nMin;
212   else if (scroll_pos > (si.nMax - si.nPage))
213      scroll_pos = (si.nMax - si.nPage);
214
215   // if the value changed, set the scroll position
216   if (scroll_pos != si.nPos)
217   {
218      SetScrollPos(window, scroll_bar, scroll_pos, TRUE);
219      ScrollWindowEx(window, 0, si.nPos - scroll_pos, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE);
220   }
221}
222
223
224
225//============================================================
226//  win_append_menu_utf8
227//============================================================
228
229BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char *item)
230{
231   BOOL result;
232   const TCHAR *t_item = (const TCHAR*)item;
233   TCHAR *t_str = NULL;
234
235   // only convert string when it's no a bitmap
236   if (!(flags & MF_BITMAP) && item) {
237      t_str = tstring_from_utf8(item);
238      t_item = t_str;
239   }
240
241   result = AppendMenu(menu, flags, id, t_item);
242
243   if (t_str)
244      osd_free(t_str);
245
246   return result;
247}
src/mess/osd/windows/dialog.c
r10018r10019
1//============================================================
2//
3//  dialog.c - Win32 MESS dialog handling
4//
5//============================================================
6
7#define WIN32_LEAN_AND_MEAN
8#include <windows.h>
9#include <tchar.h>
10#include <commctrl.h>
11#include <commdlg.h>
12
13#include "dialog.h"
14#include "emu.h"
15#include "strconv.h"
16#include "pool.h"
17#include "winutil.h"
18#include "winutils.h"
19#include "windows/input.h"
20#include "windows/window.h"
21#include "winutf8.h"
22
23//============================================================
24
25#define SEQWM_SETFOCUS   (WM_APP + 0)
26#define SEQWM_KILLFOCUS   (WM_APP + 1)
27
28enum
29{
30   TRIGGER_INITDIALOG   = 1,
31   TRIGGER_APPLY      = 2,
32   TRIGGER_CHANGED      = 4
33};
34
35typedef LRESULT (*trigger_function)(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam);
36
37struct dialog_info_trigger
38{
39   struct dialog_info_trigger *next;
40   WORD dialog_item;
41   WORD trigger_flags;
42   UINT message;
43   WPARAM wparam;
44   LPARAM lparam;
45   void (*storeval)(void *param, int val);
46   void *storeval_param;
47   trigger_function trigger_proc;
48};
49
50struct dialog_object_pool
51{
52   HGDIOBJ objects[16];
53};
54
55struct _dialog_box
56{
57   HGLOBAL handle;
58   size_t handle_size;
59   struct dialog_info_trigger *trigger_first;
60   struct dialog_info_trigger *trigger_last;
61   WORD item_count;
62   WORD size_x, size_y;
63   WORD pos_x, pos_y;
64   WORD cursize_x, cursize_y;
65   WORD home_y;
66   DWORD style;
67   int combo_string_count;
68   int combo_default_value;
69   object_pool *mempool;
70   struct dialog_object_pool *objpool;
71   const struct dialog_layout *layout;
72
73   // singular notification callback; hack
74   UINT notify_code;
75   dialog_notification notify_callback;
76   void *notify_param;
77};
78
79enum _seqselect_state
80{
81   SEQSELECT_STATE_NOT_POLLING,
82   SEQSELECT_STATE_POLLING,
83   SEQSELECT_STATE_POLLING_COMPLETE
84};
85typedef enum _seqselect_state seqselect_state;
86
87// this is the structure that gets associated with each input_seq edit box
88typedef struct _seqselect_info seqselect_info;
89struct _seqselect_info
90{
91   WNDPROC oldwndproc;
92   const input_field_config *field;      // pointer to the field
93   input_field_user_settings settings;      // the new settings
94   input_seq *code;                  // the input_seq within settings
95   WORD pos;
96   BOOL is_analog;
97   seqselect_state poll_state;
98};
99
100
101
102//============================================================
103//  PARAMETERS
104//============================================================
105
106#define DIM_VERTICAL_SPACING   3
107#define DIM_HORIZONTAL_SPACING   5
108#define DIM_NORMAL_ROW_HEIGHT   10
109#define DIM_COMBO_ROW_HEIGHT   12
110#define DIM_SLIDER_ROW_HEIGHT   18
111#define DIM_BUTTON_ROW_HEIGHT   12
112#define DIM_EDIT_WIDTH         120
113#define DIM_BUTTON_WIDTH      50
114#define DIM_ADJUSTER_SCR_WIDTH   12
115#define DIM_ADJUSTER_HEIGHT      12
116#define DIM_SCROLLBAR_WIDTH      10
117#define DIM_BOX_VERTSKEW      -3
118
119#define DLGITEM_BUTTON         ((const WCHAR *) dlgitem_button)
120#define DLGITEM_EDIT         ((const WCHAR *) dlgitem_edit)
121#define DLGITEM_STATIC         ((const WCHAR *) dlgitem_static)
122#define DLGITEM_LISTBOX         ((const WCHAR *) dlgitem_listbox)
123#define DLGITEM_SCROLLBAR      ((const WCHAR *) dlgitem_scrollbar)
124#define DLGITEM_COMBOBOX      ((const WCHAR *) dlgitem_combobox)
125
126#define DLGTEXT_OK            "OK"
127#define DLGTEXT_APPLY         "Apply"
128#define DLGTEXT_CANCEL         "Cancel"
129
130#define FONT_SIZE            8
131#define FONT_FACE            L"Arial"
132
133#define SCROLL_DELTA_LINE      10
134#define SCROLL_DELTA_PAGE      100
135
136#define LOG_WINMSGS            0
137#define DIALOG_STYLE         WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT
138#define MAX_DIALOG_HEIGHT      200
139
140
141
142//============================================================
143//  LOCAL VARIABLES
144//============================================================
145
146static running_machine *Machine;   // HACK - please fix
147
148static double pixels_to_xdlgunits;
149static double pixels_to_ydlgunits;
150
151static const struct dialog_layout default_layout = { 80, 140 };
152static const WORD dlgitem_button[] =   { 0xFFFF, 0x0080 };
153static const WORD dlgitem_edit[] =      { 0xFFFF, 0x0081 };
154static const WORD dlgitem_static[] =   { 0xFFFF, 0x0082 };
155static const WORD dlgitem_listbox[] =   { 0xFFFF, 0x0083 };
156static const WORD dlgitem_scrollbar[] =   { 0xFFFF, 0x0084 };
157static const WORD dlgitem_combobox[] =   { 0xFFFF, 0x0085 };
158
159
160//============================================================
161//  PROTOTYPES
162//============================================================
163
164static void dialog_prime(dialog_box *di);
165static int dialog_write_item(dialog_box *di, DWORD style, short x, short y,
166    short width, short height, const char *str, const WCHAR *class_name, WORD *id);
167
168
169
170//============================================================
171//  call_windowproc
172//============================================================
173
174static LRESULT call_windowproc(WNDPROC wndproc, HWND hwnd, UINT msg,
175   WPARAM wparam, LPARAM lparam)
176{
177   LRESULT rc;
178   if (IsWindowUnicode(hwnd))
179      rc = CallWindowProcW(wndproc, hwnd, msg, wparam, lparam);
180   else
181      rc = CallWindowProcA(wndproc, hwnd, msg, wparam, lparam);
182   return rc;
183}
184
185
186
187//============================================================
188//  compute_dlgunits_multiple
189//============================================================
190
191static void calc_dlgunits_multiple(void)
192{
193   dialog_box *dialog = NULL;
194   short offset_x = 2048;
195   short offset_y = 2048;
196   const char *wnd_title = "Foo";
197   WORD id;
198   HWND dlg_window = NULL;
199   HWND child_window;
200   RECT r;
201
202   if ((pixels_to_xdlgunits == 0) || (pixels_to_ydlgunits == 0))
203   {
204      // create a bogus dialog
205      dialog = win_dialog_init(NULL, NULL);
206      if (!dialog)
207         goto done;
208
209      if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
210            0, 0, offset_x, offset_y, wnd_title, DLGITEM_STATIC, &id))
211         goto done;
212
213      dialog_prime(dialog);
214      dlg_window = CreateDialogIndirectParam(NULL, (const DLGTEMPLATE*)dialog->handle, NULL, NULL, 0);
215      child_window = GetDlgItem(dlg_window, id);
216
217      GetWindowRect(child_window, &r);
218      pixels_to_xdlgunits = (double)(r.right - r.left) / offset_x;
219      pixels_to_ydlgunits = (double)(r.bottom - r.top) / offset_y;
220
221done:
222      if (dialog)
223         win_dialog_exit(dialog);
224      if (dlg_window)
225         DestroyWindow(dlg_window);
226   }
227}
228
229
230
231//============================================================
232//  dialog_trigger
233//============================================================
234
235static void dialog_trigger(HWND dlgwnd, WORD trigger_flags)
236{
237   LRESULT result;
238   HWND dialog_item;
239   struct _dialog_box *di;
240   struct dialog_info_trigger *trigger;
241   LONG_PTR l;
242
243   l = GetWindowLongPtr(dlgwnd, GWLP_USERDATA);
244   di = (struct _dialog_box *) l;
245   assert(di);
246   for (trigger = di->trigger_first; trigger; trigger = trigger->next)
247   {
248      if (trigger->trigger_flags & trigger_flags)
249      {
250         if (trigger->dialog_item)
251            dialog_item = GetDlgItem(dlgwnd, trigger->dialog_item);
252         else
253            dialog_item = dlgwnd;
254         assert(dialog_item);
255         result = 0;
256
257         if (trigger->message)
258            result = SendMessage(dialog_item, trigger->message, trigger->wparam, trigger->lparam);
259         if (trigger->trigger_proc)
260            result = trigger->trigger_proc(di, dialog_item, trigger->message, trigger->wparam, trigger->lparam);
261
262         if (trigger->storeval)
263            trigger->storeval(trigger->storeval_param, result);
264      }
265   }
266}
267
268//============================================================
269//  dialog_proc
270//============================================================
271
272static INT_PTR CALLBACK dialog_proc(HWND dlgwnd, UINT msg, WPARAM wparam, LPARAM lparam)
273{
274   INT_PTR handled = TRUE;
275   CHAR buf[32];
276   WORD command;
277
278   if (LOG_WINMSGS)
279   {
280      logerror("dialog_proc(): dlgwnd=%p msg=0x%08x wparam=0x%08x lparam=0x%08x\n",
281         dlgwnd, (unsigned int) msg, (unsigned int) wparam, (unsigned int) lparam);
282   }
283
284   switch(msg)
285   {
286      case WM_INITDIALOG:
287         SetWindowLongPtr(dlgwnd, GWLP_USERDATA, (LONG_PTR) lparam);
288         dialog_trigger(dlgwnd, TRIGGER_INITDIALOG);
289         break;
290
291      case WM_COMMAND:
292         command = LOWORD(wparam);
293
294         win_get_window_text_utf8((HWND) lparam, buf, ARRAY_LENGTH(buf));
295         if (!strcmp(buf, DLGTEXT_OK))
296            command = IDOK;
297         else if (!strcmp(buf, DLGTEXT_CANCEL))
298            command = IDCANCEL;
299         else
300            command = 0;
301
302         switch(command)
303         {
304            case IDOK:
305               dialog_trigger(dlgwnd, TRIGGER_APPLY);
306               // fall through
307
308            case IDCANCEL:
309               EndDialog(dlgwnd, 0);
310               break;
311
312            default:
313               handled = FALSE;
314               break;
315         }
316         break;
317
318      case WM_SYSCOMMAND:
319         if (wparam == SC_CLOSE)
320         {
321            EndDialog(dlgwnd, 0);
322         }
323         else
324         {
325            handled = FALSE;
326         }
327         break;
328
329      case WM_VSCROLL:
330         if (lparam)
331         {
332            // this scroll message came from an actual scroll bar window;
333            // pass it on
334            SendMessage((HWND) lparam, msg, wparam, lparam);
335         }
336         else
337         {
338            // scroll the dialog
339            win_scroll_window(dlgwnd, wparam, SB_VERT, SCROLL_DELTA_LINE);
340         }
341         break;
342
343      default:
344         handled = FALSE;
345         break;
346   }
347   return handled;
348}
349
350
351
352//============================================================
353//  dialog_write
354//============================================================
355
356static int dialog_write(struct _dialog_box *di, const void *ptr, size_t sz, int align)
357{
358   HGLOBAL newhandle;
359   size_t base;
360   UINT8 *mem;
361   UINT8 *mem2;
362
363   if (!di->handle)
364   {
365      newhandle = GlobalAlloc(GMEM_ZEROINIT, sz);
366      base = 0;
367   }
368   else
369   {
370      base = di->handle_size;
371      base += align - 1;
372      base -= base % align;
373      newhandle = GlobalReAlloc(di->handle, base + sz, GMEM_ZEROINIT);
374      if (!newhandle)
375      {
376         newhandle = GlobalAlloc(GMEM_ZEROINIT, base + sz);
377         if (newhandle)
378         {
379            mem = (UINT8*)GlobalLock(di->handle);
380            mem2 = (UINT8*)GlobalLock(newhandle);
381            memcpy(mem2, mem, base);
382            GlobalUnlock(di->handle);
383            GlobalUnlock(newhandle);
384            GlobalFree(di->handle);
385         }
386      }
387   }
388   if (!newhandle)
389      return 1;
390
391   mem = (UINT8*)GlobalLock(newhandle);
392   memcpy(mem + base, ptr, sz);
393   GlobalUnlock(newhandle);
394   di->handle = newhandle;
395   di->handle_size = base + sz;
396   return 0;
397}
398
399
400//============================================================
401//  dialog_write_string
402//============================================================
403
404static int dialog_write_string(dialog_box *di, const WCHAR *str)
405{
406   if (!str)
407      str = L"";
408   return dialog_write(di, str, (wcslen(str) + 1) * sizeof(WCHAR), 2);
409}
410
411
412
413//============================================================
414//  dialog_write_item
415//============================================================
416
417static int dialog_write_item(dialog_box *di, DWORD style, short x, short y,
418    short width, short height, const char *str, const WCHAR *class_name, WORD *id)
419{
420   DLGITEMTEMPLATE item_template;
421   UINT class_name_length;
422   WORD w;
423   WCHAR *w_str;
424   int rc;
425
426   memset(&item_template, 0, sizeof(item_template));
427   item_template.style = style;
428   item_template.x = x;
429   item_template.y = y;
430   item_template.cx = width;
431   item_template.cy = height;
432   item_template.id = di->item_count + 1;
433
434   if (dialog_write(di, &item_template, sizeof(item_template), 4))
435      return 1;
436
437   if (*class_name == 0xffff)
438      class_name_length = 4;
439   else
440      class_name_length = (wcslen(class_name) + 1) * sizeof(WCHAR);
441   if (dialog_write(di, class_name, class_name_length, 2))
442      return 1;
443
444   w_str = str ? wstring_from_utf8(str) : NULL;
445   rc = dialog_write_string(di, w_str);
446   if (w_str)
447      osd_free(w_str);
448   if (rc)
449      return 1;
450
451   w = 0;
452   if (dialog_write(di, &w, sizeof(w), 2))
453      return 1;
454
455   di->item_count++;
456
457   if (id)
458      *id = di->item_count;
459   return 0;
460}
461
462
463
464//============================================================
465//  dialog_add_trigger
466//============================================================
467
468static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item,
469   WORD trigger_flags, UINT message, trigger_function trigger_proc,
470   WPARAM wparam, LPARAM lparam,
471   void (*storeval)(void *param, int val), void *storeval_param)
472{
473   struct dialog_info_trigger *trigger;
474
475   assert(di);
476   assert(trigger_flags);
477
478   trigger = (struct dialog_info_trigger *) pool_malloc_lib(di->mempool, sizeof(struct dialog_info_trigger));
479   if (!trigger)
480      return 1;
481
482   trigger->next = NULL;
483   trigger->trigger_flags = trigger_flags;
484   trigger->dialog_item = dialog_item;
485   trigger->message = message;
486   trigger->trigger_proc = trigger_proc;
487   trigger->wparam = wparam;
488   trigger->lparam = lparam;
489   trigger->storeval = storeval;
490   trigger->storeval_param = storeval_param;
491
492   if (di->trigger_last)
493      di->trigger_last->next = trigger;
494   else
495      di->trigger_first = trigger;
496   di->trigger_last = trigger;
497   return 0;
498}
499
500//============================================================
501//  dialog_add_object
502//============================================================
503
504static int dialog_add_object(dialog_box *di, HGDIOBJ obj)
505{
506   int i;
507   struct dialog_object_pool *objpool;
508
509   objpool = di->objpool;
510
511   if (!di->objpool)
512   {
513      objpool = (dialog_object_pool*)pool_malloc_lib(di->mempool, sizeof(struct dialog_object_pool));
514      if (!objpool)
515         return 1;
516      memset(objpool, 0, sizeof(struct dialog_object_pool));
517      di->objpool = objpool;
518   }
519
520
521   for (i = 0; i < ARRAY_LENGTH(objpool->objects); i++)
522   {
523      if (!objpool->objects[i])
524         break;
525   }
526   if (i >= ARRAY_LENGTH(objpool->objects))
527      return 1;
528
529   objpool->objects[i] = obj;
530   return 0;
531}
532
533
534
535//============================================================
536//  dialog_scrollbar_init
537//============================================================
538
539static LRESULT dialog_scrollbar_init(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam)
540{
541   SCROLLINFO si;
542
543   calc_dlgunits_multiple();
544
545   memset(&si, 0, sizeof(si));
546   si.cbSize = sizeof(si);
547   si.nMin  = pixels_to_ydlgunits * 0;
548   si.nMax  = pixels_to_ydlgunits * dialog->size_y;
549   si.nPage = pixels_to_ydlgunits * MAX_DIALOG_HEIGHT;
550   si.fMask = SIF_PAGE | SIF_RANGE;
551
552   SetScrollInfo(dlgwnd, SB_VERT, &si, TRUE);
553   return 0;
554}
555
556
557
558//============================================================
559//  dialog_add_scrollbar
560//============================================================
561
562static int dialog_add_scrollbar(dialog_box *dialog)
563{
564   if (dialog_add_trigger(dialog, 0, TRIGGER_INITDIALOG, 0, dialog_scrollbar_init, 0, 0, NULL, NULL))
565      return 1;
566
567   dialog->style |= WS_VSCROLL;
568   return 0;
569}
570
571
572
573//============================================================
574//  dialog_prime
575//============================================================
576
577static void dialog_prime(dialog_box *di)
578{
579   DLGTEMPLATE *dlg_template;
580
581   if (di->size_y > MAX_DIALOG_HEIGHT)
582   {
583      di->size_x += DIM_SCROLLBAR_WIDTH;
584      dialog_add_scrollbar(di);
585   }
586
587   dlg_template = (DLGTEMPLATE *) GlobalLock(di->handle);
588   dlg_template->cdit = di->item_count;
589   dlg_template->cx = di->size_x;
590   dlg_template->cy = (di->size_y > MAX_DIALOG_HEIGHT) ? MAX_DIALOG_HEIGHT : di->size_y;
591   dlg_template->style = di->style;
592   GlobalUnlock(di->handle);
593}
594
595
596
597//============================================================
598//  dialog_get_combo_value
599//============================================================
600
601static LRESULT dialog_get_combo_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
602{
603   int idx;
604   idx = SendMessage(dialog_item, CB_GETCURSEL, 0, 0);
605   if (idx == CB_ERR)
606      return 0;
607   return SendMessage(dialog_item, CB_GETITEMDATA, idx, 0);
608}
609
610
611
612//============================================================
613//  dialog_get_adjuster_value
614//============================================================
615
616static LRESULT dialog_get_adjuster_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
617{
618   TCHAR buf[32];
619   GetWindowText(dialog_item, buf, ARRAY_LENGTH(buf));
620   return _ttoi(buf);
621}
622
623
624
625//============================================================
626//  dialog_get_slider_value
627//============================================================
628
629static LRESULT dialog_get_slider_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
630{
631   return SendMessage(dialog_item, TBM_GETPOS, 0, 0);
632}
633
634
635
636//============================================================
637//  win_dialog_init
638//============================================================
639
640dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layout)
641{
642   struct _dialog_box *di;
643   DLGTEMPLATE dlg_template;
644   WORD w[2];
645   WCHAR *w_title;
646   int rc;
647
648   // use default layout if not specified
649   if (!layout)
650      layout = &default_layout;
651
652   // create the dialog structure
653   di = (_dialog_box *)malloc(sizeof(struct _dialog_box));
654   if (!di)
655      goto error;
656   memset(di, 0, sizeof(*di));
657
658   di->layout = layout;
659   di->mempool = pool_alloc_lib(NULL);
660
661   memset(&dlg_template, 0, sizeof(dlg_template));
662   dlg_template.style = di->style = DIALOG_STYLE;
663   dlg_template.x = 10;
664   dlg_template.y = 10;
665   if (dialog_write(di, &dlg_template, sizeof(dlg_template), 4))
666      goto error;
667
668   w[0] = 0;
669   w[1] = 0;
670   if (dialog_write(di, w, sizeof(w), 2))
671      goto error;
672
673   w_title = wstring_from_utf8(title);
674   rc = dialog_write_string(di, w_title);
675   osd_free(w_title);
676   if (rc)
677      goto error;
678
679   // set the font, if necessary
680   if (di->style & DS_SETFONT)
681   {
682      w[0] = FONT_SIZE;
683      if (dialog_write(di, w, sizeof(w[0]), 2))
684         goto error;
685      if (dialog_write_string(di, FONT_FACE))
686         goto error;
687   }
688
689   return di;
690
691error:
692   if (di)
693      win_dialog_exit(di);
694   return NULL;
695}
696
697
698
699//============================================================
700//  dialog_new_control
701//============================================================
702
703static void dialog_new_control(struct _dialog_box *di, short *x, short *y)
704{
705   *x = di->pos_x + DIM_HORIZONTAL_SPACING;
706   *y = di->pos_y + DIM_VERTICAL_SPACING;
707}
708
709
710
711//============================================================
712//  dialog_finish_control
713//============================================================
714
715static void dialog_finish_control(struct _dialog_box *di, short x, short y)
716{
717   di->pos_y = y;
718
719   // update dialog size
720   if (x > di->size_x)
721      di->size_x = x;
722   if (y > di->size_y)
723      di->size_y = y;
724   if (x > di->cursize_x)
725      di->cursize_x = x;
726   if (y > di->cursize_y)
727      di->cursize_y = y;
728}
729
730
731
732//============================================================
733//  dialog_combo_changed
734//============================================================
735
736static LRESULT dialog_combo_changed(dialog_box *dialog, HWND dlgitem, UINT message, WPARAM wparam, LPARAM lparam)
737{
738   dialog_itemchangedproc changed = (dialog_itemchangedproc) wparam;
739   changed(dialog, dlgitem, (void *) lparam);
740   return 0;
741}
742
743
744
745//============================================================
746//  win_dialog_add_active_combobox
747//============================================================
748
749int win_dialog_add_active_combobox(dialog_box *dialog, const char *item_label, int default_value,
750   dialog_itemstoreval storeval, void *storeval_param,
751   dialog_itemchangedproc changed, void *changed_param)
752{
753   int rc = 1;
754   short x;
755   short y;
756
757   dialog_new_control(dialog, &x, &y);
758
759   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
760         x, y, dialog->layout->label_width, DIM_COMBO_ROW_HEIGHT, item_label, DLGITEM_STATIC, NULL))
761      goto done;
762
763   y += DIM_BOX_VERTSKEW;
764
765   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
766   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | CBS_DROPDOWNLIST,
767         x, y, dialog->layout->combo_width, DIM_COMBO_ROW_HEIGHT * 8, NULL, DLGITEM_COMBOBOX, NULL))
768      goto done;
769   dialog->combo_string_count = 0;
770   dialog->combo_default_value = default_value;
771
772   // add the trigger invoked when the apply button is pressed
773   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_combo_value, 0, 0, storeval, storeval_param))
774      goto done;
775
776   // if appropriate, add the optional changed trigger
777   if (changed)
778   {
779      if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG | TRIGGER_CHANGED, 0, dialog_combo_changed, (WPARAM) changed, (LPARAM) changed_param, NULL, NULL))
780         goto done;
781   }
782
783   x += dialog->layout->combo_width + DIM_HORIZONTAL_SPACING;
784   y += DIM_COMBO_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
785
786   dialog_finish_control(dialog, x, y);
787   rc = 0;
788
789done:
790   return rc;
791}
792
793
794
795//============================================================
796//  win_dialog_add_combobox
797//============================================================
798
799int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value,
800   void (*storeval)(void *param, int val), void *storeval_param)
801{
802   return win_dialog_add_active_combobox(dialog, item_label, default_value,
803      storeval, storeval_param, NULL, NULL);
804}
805
806
807
808//============================================================
809//  win_dialog_add_combobox_item
810//============================================================
811
812int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_label, int item_data)
813{
814   TCHAR* t_item_label = NULL;
815   // create our own copy of the string
816   if (item_label)
817   {
818      TCHAR* t_tmp = tstring_from_utf8(item_label);
819      if( !t_tmp )
820         return 1;
821      t_item_label = win_dialog_tcsdup(dialog, t_tmp);
822      osd_free(t_tmp);
823      if (!t_item_label)
824         return 1;
825   }
826
827   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_ADDSTRING, NULL, 0, (LPARAM) t_item_label, NULL, NULL))
828      return 1;
829   dialog->combo_string_count++;
830   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_SETITEMDATA, NULL, dialog->combo_string_count-1, (LPARAM) item_data, NULL, NULL))
831      return 1;
832   if (item_data == dialog->combo_default_value)
833   {
834      if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_SETCURSEL, NULL, dialog->combo_string_count-1, 0, NULL, NULL))
835         return 1;
836   }
837   return 0;
838}
839
840
841
842//============================================================
843//  adjuster_sb_wndproc
844//============================================================
845
846struct adjuster_sb_stuff
847{
848   WNDPROC oldwndproc;
849   int min_value;
850   int max_value;
851};
852
853static INT_PTR CALLBACK adjuster_sb_wndproc(HWND sbwnd, UINT msg, WPARAM wparam, LPARAM lparam)
854{
855   INT_PTR result;
856   struct adjuster_sb_stuff *stuff;
857   char buf[64];
858   HWND dlgwnd, editwnd;
859   int value, id;
860   LONG_PTR l;
861
862   l = GetWindowLongPtr(sbwnd, GWLP_USERDATA);
863   stuff = (struct adjuster_sb_stuff *) l;
864
865   if (msg == WM_VSCROLL)
866   {
867      id = GetWindowLong(sbwnd, GWL_ID);
868      dlgwnd = GetParent(sbwnd);
869      editwnd = GetDlgItem(dlgwnd, id - 1);
870      win_get_window_text_utf8(editwnd, buf, ARRAY_LENGTH(buf));
871      value = atoi(buf);
872
873      switch(wparam)
874      {
875         case SB_LINEDOWN:
876         case SB_PAGEDOWN:
877            value--;
878            break;
879
880         case SB_LINEUP:
881         case SB_PAGEUP:
882            value++;
883            break;
884      }
885
886      if (value < stuff->min_value)
887         value = stuff->min_value;
888      else if (value > stuff->max_value)
889         value = stuff->max_value;
890      _snprintf(buf, ARRAY_LENGTH(buf), "%d", value);
891      win_set_window_text_utf8(editwnd, buf);
892      result = 0;
893   }
894   else
895   {
896      result = call_windowproc(stuff->oldwndproc, sbwnd, msg, wparam, lparam);
897   }
898   return result;
899}
900
901
902
903//============================================================
904//  adjuster_sb_setup
905//============================================================
906
907static LRESULT adjuster_sb_setup(dialog_box *dialog, HWND sbwnd, UINT message, WPARAM wparam, LPARAM lparam)
908{
909   struct adjuster_sb_stuff *stuff;
910   LONG_PTR l;
911
912   stuff = (struct adjuster_sb_stuff *) win_dialog_malloc(dialog, sizeof(struct adjuster_sb_stuff));
913   if (!stuff)
914      return 1;
915   stuff->min_value = (WORD) (lparam >> 0);
916   stuff->max_value = (WORD) (lparam >> 16);
917
918   l = (LONG_PTR) stuff;
919   SetWindowLongPtr(sbwnd, GWLP_USERDATA, l);
920   l = (LONG_PTR) adjuster_sb_wndproc;
921   l = SetWindowLongPtr(sbwnd, GWLP_WNDPROC, l);
922   stuff->oldwndproc = (WNDPROC) l;
923   return 0;
924}
925
926
927
928//============================================================
929//  win_dialog_add_adjuster
930//============================================================
931
932int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, int default_value,
933   int min_value, int max_value, BOOL is_percentage,
934   dialog_itemstoreval storeval, void *storeval_param)
935{
936   short x;
937   short y;
938   TCHAR buf[32];
939   TCHAR *s;
940
941   dialog_new_control(dialog, &x, &y);
942
943   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
944         x, y, dialog->layout->label_width, DIM_ADJUSTER_HEIGHT, item_label, DLGITEM_STATIC, NULL))
945      goto error;
946   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
947
948   y += DIM_BOX_VERTSKEW;
949
950   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER,
951         x, y, dialog->layout->combo_width - DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_EDIT, NULL))
952      goto error;
953   x += dialog->layout->combo_width - DIM_ADJUSTER_SCR_WIDTH;
954
955   _sntprintf(buf, ARRAY_LENGTH(buf),
956      is_percentage ? TEXT("%d%%") : TEXT("%d"),
957      default_value);
958   s = win_dialog_tcsdup(dialog, buf);
959   if (!s)
960      return 1;
961   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, WM_SETTEXT, NULL,
962         0, (LPARAM) s, NULL, NULL))
963      goto error;
964
965   // add the trigger invoked when the apply button is pressed
966   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_adjuster_value, 0, 0, storeval, storeval_param))
967      goto error;
968
969   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT,
970         x, y, DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_SCROLLBAR, NULL))
971      goto error;
972   x += DIM_ADJUSTER_SCR_WIDTH + DIM_HORIZONTAL_SPACING;
973
974   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, 0, adjuster_sb_setup,
975         0, MAKELONG(min_value, max_value), NULL, NULL))
976      return 1;
977
978   y += DIM_COMBO_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
979
980   dialog_finish_control(dialog, x, y);
981   return 0;
982
983error:
984   return 1;
985}
986
987
988
989//============================================================
990//  win_dialog_add_slider
991//============================================================
992
993int win_dialog_add_slider(dialog_box *dialog, const char *item_label, int default_value,
994   int min_value, int max_value,
995   dialog_itemstoreval storeval, void *storeval_param)
996{
997   short x;
998   short y;
999
1000   dialog_new_control(dialog, &x, &y);
1001
1002   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
1003         x, y, dialog->layout->label_width, DIM_SLIDER_ROW_HEIGHT, item_label, DLGITEM_STATIC, NULL))
1004      goto error;
1005
1006   y += DIM_BOX_VERTSKEW;
1007
1008   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
1009   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_HORZ | TBS_BOTH,
1010         x, y, dialog->layout->combo_width, DIM_SLIDER_ROW_HEIGHT, NULL, TRACKBAR_CLASSW, NULL))
1011      goto error;
1012
1013   x += dialog->layout->combo_width + DIM_HORIZONTAL_SPACING;
1014   y += DIM_SLIDER_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
1015
1016   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, TBM_SETRANGE, NULL, 0,
1017         (LPARAM) MAKELONG(min_value, max_value), NULL, NULL))
1018      goto error;
1019
1020   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, TBM_SETPOS, NULL, 0,
1021         (LPARAM) default_value, NULL, NULL))
1022      goto error;
1023
1024   // add the trigger invoked when the apply button is pressed
1025   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_slider_value, 0, 0, storeval, storeval_param))
1026      goto error;
1027
1028   dialog_finish_control(dialog, x, y);
1029   return 0;
1030
1031error:
1032   return 1;
1033}
1034
1035
1036
1037//============================================================
1038//  get_seqselect_info
1039//============================================================
1040
1041static seqselect_info *get_seqselect_info(HWND editwnd)
1042{
1043   LONG_PTR lp;
1044   lp = GetWindowLongPtr(editwnd, GWLP_USERDATA);
1045   return (seqselect_info *) lp;
1046}
1047
1048
1049
1050//============================================================
1051//  seqselect_settext
1052//============================================================
1053
1054static void seqselect_settext(HWND editwnd)
1055{
1056   seqselect_info *stuff;
1057   astring seqstring;
1058   char buffer[128];
1059
1060   // the basics
1061   stuff = get_seqselect_info(editwnd);
1062   if (stuff == NULL)
1063      return;   // this should not happen - need to fix this
1064
1065   // retrieve the seq name
1066   input_seq_name(Machine, seqstring, stuff->code);
1067
1068   // change the text - avoid calls to SetWindowText() if we can
1069   win_get_window_text_utf8(editwnd, buffer, ARRAY_LENGTH(buffer));
1070   if (strcmp(buffer, seqstring))
1071      win_set_window_text_utf8(editwnd, seqstring);
1072
1073   // reset the selection
1074   if (GetFocus() == editwnd)
1075   {
1076      DWORD start = 0, end = 0;
1077      SendMessage(editwnd, EM_GETSEL, (WPARAM) (LPDWORD) &start, (LPARAM) (LPDWORD) &end);
1078      if ((start != 0) || (end != strlen(buffer)))
1079         SendMessage(editwnd, EM_SETSEL, 0, -1);
1080   }
1081}
1082
1083
1084
1085//============================================================
1086//  seqselect_start_read_from_main_thread
1087//============================================================
1088
1089static void seqselect_start_read_from_main_thread(void *param)
1090{
1091   seqselect_info *stuff;
1092   HWND editwnd;
1093   //int ret;
1094   win_window_info fake_window_info;
1095   win_window_info *old_window_list;
1096   int pause_count;
1097
1098   // get the basics
1099   editwnd = (HWND) param;
1100   stuff = get_seqselect_info(editwnd);
1101
1102   // are we currently polling?  if so bail out
1103   if (stuff->poll_state != SEQSELECT_STATE_NOT_POLLING)
1104      return;
1105
1106   // change the state
1107   stuff->poll_state = SEQSELECT_STATE_POLLING;
1108
1109   // the Win32 OSD code thinks that we are paused, we need to temporarily
1110   // unpause ourselves or else we will block
1111   pause_count = 0;
1112   while(Machine->paused() && !winwindow_ui_is_paused(Machine))
1113   {
1114      winwindow_ui_pause_from_main_thread(Machine, FALSE);
1115      pause_count++;
1116   }
1117
1118   // butt ugly hack so that we accept focus
1119   old_window_list = win_window_list;
1120   memset(&fake_window_info, 0, sizeof(fake_window_info));
1121   fake_window_info.hwnd = GetFocus();
1122   win_window_list = &fake_window_info;
1123
1124   // start the polling
1125   input_seq_poll_start(Machine, stuff->is_analog ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, NULL);
1126
1127   while(stuff->poll_state == SEQSELECT_STATE_POLLING)
1128   {
1129      // poll
1130      /*ret = */input_seq_poll(Machine, stuff->code);
1131      seqselect_settext(editwnd);
1132   }
1133
1134   // clean up after hack
1135   win_window_list = old_window_list;
1136
1137   // we are no longer polling
1138   stuff->poll_state = SEQSELECT_STATE_NOT_POLLING;
1139
1140   // repause the OSD code
1141   while(pause_count--)
1142      winwindow_ui_pause_from_main_thread(Machine, TRUE);
1143}
1144
1145
1146
1147//============================================================
1148//  seqselect_stop_read_from_main_thread
1149//============================================================
1150
1151static void seqselect_stop_read_from_main_thread(void *param)
1152{
1153   HWND editwnd;
1154   seqselect_info *stuff;
1155
1156   // get the basics
1157   editwnd = (HWND) param;
1158   stuff = get_seqselect_info(editwnd);
1159
1160   // stop the read
1161   if (stuff->poll_state == SEQSELECT_STATE_POLLING)
1162      stuff->poll_state = SEQSELECT_STATE_POLLING_COMPLETE;
1163}
1164
1165
1166
1167//============================================================
1168//  seqselect_wndproc
1169//============================================================
1170
1171static INT_PTR CALLBACK seqselect_wndproc(HWND editwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1172{
1173   seqselect_info *stuff;
1174   INT_PTR result = 0;
1175   BOOL call_baseclass = TRUE;
1176
1177   stuff = get_seqselect_info(editwnd);
1178
1179   switch(msg)
1180   {
1181      case WM_KEYDOWN:
1182      case WM_SYSKEYDOWN:
1183      case WM_CHAR:
1184      case WM_KEYUP:
1185      case WM_SYSKEYUP:
1186         result = 1;
1187         call_baseclass = FALSE;
1188         break;
1189
1190      case WM_SETFOCUS:
1191         PostMessage(editwnd, SEQWM_SETFOCUS, 0, 0);
1192         break;
1193
1194      case WM_KILLFOCUS:
1195         PostMessage(editwnd, SEQWM_KILLFOCUS, 0, 0);
1196         break;
1197
1198      case SEQWM_SETFOCUS:
1199         // if we receive the focus, we should start a polling loop
1200         winwindow_ui_exec_on_main_thread(seqselect_start_read_from_main_thread, (void *) editwnd);
1201         break;
1202
1203      case SEQWM_KILLFOCUS:
1204         // when we abort the focus, end any current polling loop
1205         winwindow_ui_exec_on_main_thread(seqselect_stop_read_from_main_thread, (void *) editwnd);
1206         break;
1207
1208      case WM_LBUTTONDOWN:
1209      case WM_RBUTTONDOWN:
1210         SetFocus(editwnd);
1211         SendMessage(editwnd, EM_SETSEL, 0, -1);
1212         call_baseclass = FALSE;
1213         result = 0;
1214         break;
1215   }
1216
1217   if (call_baseclass)
1218      result = call_windowproc(stuff->oldwndproc, editwnd, msg, wparam, lparam);
1219   return result;
1220}
1221
1222
1223
1224//============================================================
1225//  seqselect_setup
1226//============================================================
1227
1228static LRESULT seqselect_setup(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam)
1229{
1230   seqselect_info *stuff = (seqselect_info *) lparam;
1231   LONG_PTR lp;
1232
1233   lp = SetWindowLongPtr(editwnd, GWLP_WNDPROC, (LONG_PTR) seqselect_wndproc);
1234   stuff->oldwndproc = (WNDPROC) lp;
1235   SetWindowLongPtr(editwnd, GWLP_USERDATA, lparam);
1236   seqselect_settext(editwnd);
1237   return 0;
1238}
1239
1240
1241
1242//============================================================
1243//  seqselect_apply
1244//============================================================
1245
1246static LRESULT seqselect_apply(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam)
1247{
1248   seqselect_info *stuff;
1249   stuff = get_seqselect_info(editwnd);
1250
1251   // store the settings
1252   input_field_set_user_settings(stuff->field, &stuff->settings);
1253
1254   return 0;
1255}
1256
1257//============================================================
1258//  dialog_add_single_seqselect
1259//============================================================
1260
1261static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y,
1262   short cx, short cy, const input_field_config *field, int is_analog, int seq)
1263{
1264   seqselect_info *stuff;
1265
1266   // write the dialog item
1267   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_ENDELLIPSIS | ES_CENTER | SS_SUNKEN,
1268         x, y, cx, cy, NULL, DLGITEM_EDIT, NULL))
1269      return 1;
1270
1271   // allocate a seqselect_info
1272   stuff = (seqselect_info *) pool_malloc_lib(di->mempool, sizeof(seqselect_info));
1273   if (!stuff)
1274      return 1;
1275
1276   // initialize the structure
1277   memset(stuff, 0, sizeof(*stuff));
1278   input_field_get_user_settings(field, &stuff->settings);
1279   stuff->field = field;
1280   stuff->pos = di->item_count;
1281   stuff->is_analog = is_analog;
1282   stuff->code = &stuff->settings.seq[seq];
1283
1284   if (dialog_add_trigger(di, di->item_count, TRIGGER_INITDIALOG, 0, seqselect_setup, di->item_count, (LPARAM) stuff, NULL, NULL))
1285      return 1;
1286   if (dialog_add_trigger(di, di->item_count, TRIGGER_APPLY, 0, seqselect_apply, 0, 0, NULL, NULL))
1287      return 1;
1288   return 0;
1289}
1290
1291
1292
1293//============================================================
1294//  win_dialog_add_seqselect
1295//============================================================
1296
1297int win_dialog_add_portselect(dialog_box *dialog, const input_field_config *field)
1298{
1299   dialog_box *di = dialog;
1300   short x;
1301   short y;
1302   const char *port_name;
1303   const char *this_port_name;
1304   char *s;
1305   int seq;
1306   int seq_count = 0;
1307   const char *port_suffix[3];
1308   int seq_types[3];
1309   int is_analog[3];
1310   int len;
1311
1312   port_name = input_field_name(field);
1313   assert(port_name);
1314
1315   if (field->type >= __ipt_analog_start && field->type <= __ipt_analog_end)
1316   {
1317      seq_types[seq_count] = SEQ_TYPE_STANDARD;
1318      port_suffix[seq_count] = " Analog";
1319      is_analog[seq_count] = TRUE;
1320      seq_count++;
1321
1322      seq_types[seq_count] = SEQ_TYPE_DECREMENT;
1323      port_suffix[seq_count] = " Dec";
1324      is_analog[seq_count] = FALSE;
1325      seq_count++;
1326
1327      seq_types[seq_count] = SEQ_TYPE_INCREMENT;
1328      port_suffix[seq_count] = " Inc";
1329      is_analog[seq_count] = FALSE;
1330      seq_count++;
1331   }
1332   else
1333   {
1334      seq_types[seq_count] = SEQ_TYPE_STANDARD;
1335      port_suffix[seq_count] = NULL;
1336      is_analog[seq_count] = FALSE;
1337      seq_count++;
1338   }
1339
1340   for (seq = 0; seq < seq_count; seq++)
1341   {
1342      // create our local name for this entry; also convert from
1343      // MAME strings to wide strings
1344      len = strlen(port_name);
1345      s = (char *) alloca((len + (port_suffix[seq] ? strlen(port_suffix[seq])
1346         : 0) + 1) * sizeof(*s));
1347      strcpy(s, port_name);
1348
1349      if (port_suffix[seq])
1350         strcpy(s + len, port_suffix[seq]);
1351      this_port_name = s;
1352
1353      // no positions specified
1354      dialog_new_control(di, &x, &y);
1355
1356      if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, x, y,
1357            dialog->layout->label_width, DIM_NORMAL_ROW_HEIGHT, this_port_name, DLGITEM_STATIC, NULL))
1358         return 1;
1359      x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
1360
1361      if (dialog_add_single_seqselect(di, x, y, DIM_EDIT_WIDTH, DIM_NORMAL_ROW_HEIGHT,
1362            field, is_analog[seq], seq_types[seq]))
1363         return 1;
1364      y += DIM_VERTICAL_SPACING + DIM_NORMAL_ROW_HEIGHT;
1365      x += DIM_EDIT_WIDTH + DIM_HORIZONTAL_SPACING;
1366
1367      dialog_finish_control(di, x, y);
1368   }
1369   return 0;
1370}
1371
1372
1373
1374//============================================================
1375//  win_dialog_add_notification
1376//============================================================
1377
1378int win_dialog_add_notification(dialog_box *dialog, UINT notification,
1379   dialog_notification callback, void *param)
1380{
1381   // hack
1382   assert(!dialog->notify_callback);
1383   dialog->notify_code = notification;
1384   dialog->notify_callback = callback;
1385   dialog->notify_param = param;
1386   return 0;
1387}
1388
1389
1390
1391//============================================================
1392//  win_dialog_add_standard_buttons
1393//============================================================
1394
1395int win_dialog_add_standard_buttons(dialog_box *dialog)
1396{
1397   dialog_box *di = dialog;
1398   short x;
1399   short y;
1400
1401   x = di->size_x - DIM_HORIZONTAL_SPACING - DIM_BUTTON_WIDTH;
1402   y = di->size_y + DIM_VERTICAL_SPACING;
1403
1404   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT,
1405         x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_CANCEL, DLGITEM_BUTTON, NULL))
1406      return 1;
1407
1408   x -= DIM_HORIZONTAL_SPACING + DIM_BUTTON_WIDTH;
1409   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT,
1410         x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_OK, DLGITEM_BUTTON, NULL))
1411      return 1;
1412   di->size_y += DIM_BUTTON_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
1413   return 0;
1414}
1415
1416
1417
1418//============================================================
1419//  create_png_bitmap
1420//============================================================
1421
1422static HBITMAP create_png_bitmap(const png_info *png)
1423{
1424   HBITMAP bitmap;
1425   BITMAPINFOHEADER bitmap_header;
1426   void *bitmap_data;
1427   UINT8 *src;
1428   UINT8 *dst;
1429   int x, y;
1430   HDC dc;
1431
1432   // grab a device context
1433   dc = GetDC(NULL);
1434
1435   // create the bitmap header
1436   memset(&bitmap_header, 0, sizeof(bitmap_header));
1437   bitmap_header.biSize = sizeof(BITMAPINFOHEADER);
1438   bitmap_header.biWidth = png->width;
1439   bitmap_header.biHeight = -png->height;
1440   bitmap_header.biPlanes = 1;
1441   bitmap_header.biBitCount = 24;
1442   bitmap_header.biCompression = BI_RGB;
1443
1444   // create an HBITMAP
1445   bitmap = CreateDIBSection(dc, (BITMAPINFO *) &bitmap_header, DIB_RGB_COLORS, &bitmap_data, NULL, 0);
1446   if (!bitmap)
1447      goto done;
1448
1449   // copy the data
1450   src = png->image;
1451   dst = (UINT8 *) bitmap_data;
1452   for (y = 0; y < png->height; y++)
1453   {
1454      for (x = 0; x < png->width; x++)
1455      {
1456         switch(png->color_type) {
1457         case 0:      // 8bpp grayscale case
1458            dst[2] = src[0];
1459            dst[1] = src[0];
1460            dst[0] = src[0];
1461            src++;
1462            break;
1463
1464         case 2:      // 32bpp non-alpha case
1465            dst[2] = src[0];
1466            dst[1] = src[1];
1467            dst[0] = src[2];
1468            src += 3;
1469            break;
1470
1471         case 3:      // 8bpp palettized case
1472            assert(png->palette);
1473            dst[2] = png->palette[*src * 3 + 0];
1474            dst[1] = png->palette[*src * 3 + 1];
1475            dst[0] = png->palette[*src * 3 + 2];
1476            src++;
1477            break;
1478         }
1479         dst += 3;
1480      }
1481   }
1482
1483done:
1484   ReleaseDC(NULL, dc);
1485   return bitmap;
1486}
1487
1488//============================================================
1489//  win_dialog_add_image
1490//============================================================
1491
1492int win_dialog_add_image(dialog_box *dialog, const png_info *png)
1493{
1494   WORD id;
1495   HBITMAP bitmap;
1496   short x, y;
1497   short width, height;
1498
1499   calc_dlgunits_multiple();
1500   width = png->width / pixels_to_xdlgunits;
1501   height = png->height / pixels_to_ydlgunits;
1502
1503   bitmap = create_png_bitmap(png);
1504   if (!bitmap)
1505      return 1;
1506
1507   dialog_new_control(dialog, &x, &y);
1508   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_BITMAP,
1509         x, y, width, height, NULL, DLGITEM_STATIC, &id))
1510      return 1;
1511   if (dialog_add_trigger(dialog, id, TRIGGER_INITDIALOG, STM_SETIMAGE, NULL, (WPARAM)IMAGE_BITMAP, (LPARAM) bitmap, NULL, NULL))
1512      return 1;
1513   if (dialog_add_object(dialog, bitmap))
1514      return 1;
1515   x += width;
1516   y += height;
1517   dialog_finish_control(dialog, x, y);
1518   return 0;
1519}
1520
1521//============================================================
1522//  win_dialog_add_separator
1523//============================================================
1524
1525int win_dialog_add_separator(dialog_box *dialog)
1526{
1527   dialog->home_y = dialog->cursize_y;
1528   dialog->cursize_x = 0;
1529   return 0;
1530}
1531
1532//============================================================
1533//  win_dialog_exit
1534//============================================================
1535
1536void win_dialog_exit(dialog_box *dialog)
1537{
1538   int i;
1539   struct dialog_object_pool *objpool;
1540
1541   assert(dialog);
1542
1543   objpool = dialog->objpool;
1544   if (objpool)
1545   {
1546      for (i = 0; i < ARRAY_LENGTH(objpool->objects); i++)
1547         DeleteObject(objpool->objects[i]);
1548   }
1549
1550   if (dialog->handle)
1551      GlobalFree(dialog->handle);
1552   pool_free_lib(dialog->mempool);
1553   free(dialog);
1554}
1555
1556
1557
1558//============================================================
1559//  win_dialog_malloc
1560//============================================================
1561
1562void *win_dialog_malloc(dialog_box *dialog, size_t size)
1563{
1564   return pool_malloc_lib(dialog->mempool, size);
1565}
1566
1567
1568
1569//============================================================
1570//  win_dialog_strdup
1571//============================================================
1572
1573char *win_dialog_strdup(dialog_box *dialog, const char *s)
1574{
1575   return pool_strdup_lib(dialog->mempool, s);
1576}
1577
1578
1579
1580//============================================================
1581//  win_dialog_wcsdup
1582//============================================================
1583
1584WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s)
1585{
1586   WCHAR *result = (WCHAR *) pool_malloc_lib(dialog->mempool, (wcslen(s) + 1) * sizeof(*s));
1587   if (result)
1588      wcscpy(result, s);
1589   return result;
1590}
1591
1592
1593
1594//============================================================
1595//  before_display_dialog
1596//============================================================
1597
1598static void before_display_dialog(running_machine *machine)
1599{
1600   Machine = machine;
1601   winwindow_ui_pause_from_window_thread(machine, TRUE);
1602}
1603
1604
1605
1606//============================================================
1607//  after_display_dialog
1608//============================================================
1609
1610static void after_display_dialog(running_machine *machine)
1611{
1612   winwindow_ui_pause_from_window_thread(machine, FALSE);
1613   Machine = NULL;
1614}
1615
1616
1617
1618//============================================================
1619//  win_dialog_runmodal
1620//============================================================
1621
1622void win_dialog_runmodal(running_machine *machine, HWND wnd, dialog_box *dialog)
1623{
1624   assert(dialog);
1625
1626   // finishing touches on the dialog
1627   dialog_prime(dialog);
1628
1629   // show the dialog
1630   before_display_dialog(machine);
1631   DialogBoxIndirectParamW(NULL, (const DLGTEMPLATE*)dialog->handle, wnd, dialog_proc, (LPARAM) dialog);
1632   after_display_dialog(machine);
1633}
1634
1635
1636
1637//============================================================
1638//  file_dialog_hook
1639//============================================================
1640
1641static UINT_PTR CALLBACK file_dialog_hook(HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam)
1642{
1643   OPENFILENAME *ofn;
1644   dialog_box *dialog;
1645   UINT_PTR rc = 0;
1646   LPNMHDR notify;
1647   LONG_PTR l;
1648
1649   switch(message) {
1650   case WM_INITDIALOG:
1651      ofn = (OPENFILENAME *) lparam;
1652      dialog = (dialog_box *) ofn->lCustData;
1653
1654      SetWindowLongPtr(dlgwnd, GWLP_USERDATA, (LONG_PTR) dialog);
1655      dialog_trigger(dlgwnd, TRIGGER_INITDIALOG);
1656      rc = 1;
1657
1658      // hack
1659      if (dialog->notify_callback && (dialog->notify_code == CDN_TYPECHANGE))
1660         dialog->notify_callback(dialog, dlgwnd, NULL, dialog->notify_param);
1661      break;
1662
1663   case WM_NOTIFY:
1664      notify = (LPNMHDR) lparam;
1665      switch(notify->code) {
1666      case CDN_FILEOK:
1667         dialog_trigger(dlgwnd, TRIGGER_APPLY);
1668         break;
1669      }
1670
1671      // hack
1672      l = GetWindowLongPtr(dlgwnd, GWLP_USERDATA);
1673      dialog = (dialog_box *) l;
1674      if (dialog->notify_callback && (notify->code == dialog->notify_code))
1675         dialog->notify_callback(dialog, dlgwnd, notify, dialog->notify_param);
1676      break;
1677
1678   case WM_COMMAND:
1679      switch(HIWORD(wparam)) {
1680      case CBN_SELCHANGE:
1681         dialog_trigger(dlgwnd, TRIGGER_CHANGED);
1682         break;
1683      }
1684      break;
1685   }
1686   return rc;
1687}
1688
1689
1690
1691//============================================================
1692//  win_file_dialog
1693//============================================================
1694
1695BOOL win_file_dialog(running_machine *machine,
1696   HWND parent, win_file_dialog_type dlgtype, dialog_box *custom_dialog, const char *filter,
1697   const char *initial_dir, char *filename, size_t filename_len)
1698{
1699   win_open_file_name ofn;
1700   BOOL result = FALSE;
1701
1702   // set up the OPENFILENAME data structure
1703   memset(&ofn, 0, sizeof(ofn));
1704   ofn.type = dlgtype;
1705   ofn.owner = parent;
1706   ofn.flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
1707   ofn.filter = filter;
1708   ofn.initial_directory = initial_dir;
1709
1710   if (dlgtype == WIN_FILE_DIALOG_OPEN)
1711   {
1712      ofn.flags |= OFN_FILEMUSTEXIST;
1713   }
1714
1715   if (custom_dialog)
1716   {
1717      custom_dialog->style = WS_CHILD | WS_CLIPSIBLINGS | DS_3DLOOK | DS_CONTROL | DS_SETFONT;
1718      dialog_prime(custom_dialog);
1719
1720      ofn.flags |= OFN_ENABLETEMPLATEHANDLE | OFN_ENABLEHOOK;
1721      ofn.instance = (HINSTANCE)custom_dialog->handle;
1722      ofn.custom_data = (LPARAM) custom_dialog;
1723      ofn.hook = file_dialog_hook;
1724   }
1725
1726   snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s", filename);
1727
1728   before_display_dialog(machine);
1729   result = win_get_file_name_dialog(&ofn);
1730   after_display_dialog(machine);
1731
1732   snprintf(filename, filename_len, "%s", ofn.filename);
1733   return result;
1734}
1735
1736
src/mess/osd/windows/opcntrl.c
r10018r10019
1//============================================================
2//
3//  opcntrl.c - Code for handling option resolutions in
4//  Win32 controls
5//
6//  This code was factored out of menu.c when Windows Imgtool
7//  started to have dynamic controls
8//
9//============================================================
10
11#include <windows.h>
12#include <commctrl.h>
13#include <stdio.h>
14#include <tchar.h>
15#include <assert.h>
16
17#include "opcntrl.h"
18#include "strconv.h"
19#include "winutf8.h"
20
21
22static const TCHAR guide_prop[] = TEXT("opcntrl_guide");
23static const TCHAR spec_prop[] = TEXT("opcntrl_optspec");
24static const TCHAR value_prop[] = TEXT("opcntrl_value");
25
26
27
28static int get_option_count(const option_guide *guide,
29   const char *optspec)
30{
31   struct OptionRange ranges[128];
32   int count = 0, i;
33
34   option_resolution_listranges(optspec, guide->parameter,
35      ranges, ARRAY_LENGTH(ranges));
36
37   for (i = 0; ranges[i].min >= 0; i++)
38      count += ranges[i].max - ranges[i].min + 1;
39   return count;
40}
41
42
43
44static BOOL prepare_combobox(HWND control, const option_guide *guide,
45   const char *optspec)
46{
47   struct OptionRange ranges[128];
48   int default_value, default_index, current_index, option_count;
49   int i, j, k;
50   BOOL has_option;
51   TCHAR buf1[256];
52   TCHAR buf2[256];
53   LPTSTR tempstr;
54
55   SendMessage(control, CB_GETLBTEXT, SendMessage(control, CB_GETCURSEL, 0, 0), (LPARAM) buf1);
56   SendMessage(control, CB_RESETCONTENT, 0, 0);
57   has_option = guide && optspec;
58
59   if (has_option)
60   {
61      if ((guide->option_type != OPTIONTYPE_INT) && (guide->option_type != OPTIONTYPE_ENUM_BEGIN))
62         goto unexpected;
63
64      option_resolution_listranges(optspec, guide->parameter,
65         ranges, ARRAY_LENGTH(ranges));
66      option_resolution_getdefault(optspec, guide->parameter, &default_value);
67
68      option_count = 0;
69      default_index = -1;
70      current_index = -1;
71
72      for (i = 0; ranges[i].min >= 0; i++)
73      {
74         for (j = ranges[i].min; j <= ranges[i].max; j++)
75         {
76            if (guide->option_type == OPTIONTYPE_INT)
77            {
78               _sntprintf(buf2, ARRAY_LENGTH(buf2), TEXT("%d"), j);
79               SendMessage(control, CB_ADDSTRING, 0, (LPARAM) buf2);
80            }
81            else if (guide->option_type == OPTIONTYPE_ENUM_BEGIN)
82            {
83               for (k = 1; guide[k].option_type == OPTIONTYPE_ENUM_VALUE; k++)
84               {
85                  if (guide[k].parameter == j)
86                     break;
87               }
88               if (guide[k].option_type != OPTIONTYPE_ENUM_VALUE)
89                  goto unexpected;
90               tempstr = tstring_from_utf8(guide[k].display_name);
91               SendMessage(control, CB_ADDSTRING, 0, (LPARAM) tempstr);
92               osd_free(tempstr);
93            }
94            else
95               goto unexpected;
96
97            SendMessage(control, CB_SETITEMDATA, option_count, j);
98
99            if (j == default_value)
100               default_index = option_count;
101            if (!_tcscmp(buf1, buf2))
102               current_index = option_count;
103            option_count++;
104         }
105      }
106
107      // if there is only one option, it is effectively disabled
108      if (option_count <= 1)
109         has_option = FALSE;
110
111      if (current_index >= 0)
112         SendMessage(control, CB_SETCURSEL, current_index, 0);
113      else if (default_index >= 0)
114         SendMessage(control, CB_SETCURSEL, default_index, 0);
115   }
116   else
117   {
118      // this item is non applicable
119      SendMessage(control, CB_ADDSTRING, 0, (LPARAM) TEXT("N/A"));
120      SendMessage(control, CB_SETCURSEL, 0, 0);
121   }
122   EnableWindow(control, has_option);
123   return TRUE;
124
125unexpected:
126   assert(FALSE);
127   return FALSE;
128}
129
130
131
132static BOOL check_combobox(HWND control)
133{
134   return TRUE;
135}
136
137
138
139static BOOL prepare_editbox(HWND control, const option_guide *guide,
140   const char *optspec)
141{
142   optreserr_t err = OPTIONRESOLUTION_ERROR_SUCCESS;
143   char buf[32];
144   int val, has_option, option_count;
145
146   has_option = guide && optspec;
147   buf[0] = '\0';
148
149   if (has_option)
150   {
151      switch(guide->option_type)
152      {
153         case OPTIONTYPE_STRING:
154            break;
155
156         case OPTIONTYPE_INT:
157            err = option_resolution_getdefault(optspec, guide->parameter, &val);
158            if (err)
159               goto done;
160            _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
161            break;
162
163         default:
164            err = OPTIONRESOLTUION_ERROR_INTERNAL;
165            goto done;
166      }
167   }
168
169   if (has_option)
170   {
171      option_count = get_option_count(guide, optspec);
172      if (option_count <= 1)
173         has_option = FALSE;
174   }
175
176done:
177   assert(err != OPTIONRESOLTUION_ERROR_INTERNAL);
178   win_set_window_text_utf8(control, buf);
179   EnableWindow(control, !err && has_option);
180   return err == OPTIONRESOLUTION_ERROR_SUCCESS;
181}
182
183
184
185static BOOL check_editbox(HWND control)
186{
187   char buf[256];
188   const option_guide *guide;
189   const char *optspec;
190   optreserr_t err;
191   HANDLE h;
192   void *val;
193   int i_val;
194
195
196   guide = (const option_guide *) GetProp(control, guide_prop);
197   optspec = (const char *) GetProp(control, spec_prop);
198
199   win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf));
200
201   switch(guide->option_type)
202   {
203      case OPTIONTYPE_INT:
204         i_val = atoi(buf);
205         err = option_resolution_isvalidvalue(optspec, guide->parameter, i_val);
206         if (err)
207         {
208            h = GetProp(control, value_prop);
209            val = (void*) h;
210            _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
211            win_set_window_text_utf8(control, buf);
212         }
213         else
214         {
215            SetProp(control, value_prop, (HANDLE) i_val);
216         }
217         break;
218
219      default:
220         err = OPTIONRESOLTUION_ERROR_INTERNAL;
221         goto done;
222   }
223
224done:
225   assert(err != OPTIONRESOLTUION_ERROR_INTERNAL);
226   return (err != OPTIONRESOLUTION_ERROR_SUCCESS);
227}
228
229
230
231BOOL win_prepare_option_control(HWND control, const option_guide *guide,
232   const char *optspec)
233{
234   BOOL rc = FALSE;
235   TCHAR class_name[32];
236
237   SetProp(control, guide_prop, (HANDLE) guide);
238   SetProp(control, spec_prop, (HANDLE) optspec);
239   GetClassName(control, class_name, sizeof(class_name)
240      / sizeof(class_name[0]));
241
242   if (!_tcsicmp(class_name, TEXT("ComboBox")))
243      rc = prepare_combobox(control, guide, optspec);
244   else if (!_tcsicmp(class_name, TEXT("Edit")))
245      rc = prepare_editbox(control, guide, optspec);
246
247   return rc;
248}
249
250
251
252BOOL win_check_option_control(HWND control)
253{
254   BOOL rc = FALSE;
255   TCHAR class_name[32];
256
257   GetClassName(control, class_name, sizeof(class_name)
258      / sizeof(class_name[0]));
259
260   if (!_tcsicmp(class_name, TEXT("ComboBox")))
261      rc = check_combobox(control);
262   else if (!_tcsicmp(class_name, TEXT("Edit")))
263      rc = check_editbox(control);
264
265   return rc;
266}
267
268
269
270BOOL win_adjust_option_control(HWND control, int delta)
271{
272   const option_guide *guide;
273   const char *optspec;
274   struct OptionRange ranges[128];
275   char buf[64];
276   int val, original_val, i;
277   BOOL changed = FALSE;
278
279   guide = (const option_guide *) GetProp(control, guide_prop);
280   optspec = (const char *) GetProp(control, spec_prop);
281
282   assert(guide->option_type == OPTIONTYPE_INT);
283
284   if (delta == 0)
285      return TRUE;
286
287   option_resolution_listranges(optspec, guide->parameter,
288      ranges, ARRAY_LENGTH(ranges));
289
290   win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf));
291   original_val = atoi(buf);
292   val = original_val + delta;
293
294   for (i = 0; ranges[i].min >= 0; i++)
295   {
296      if (ranges[i].min > val)
297      {
298         if ((delta < 0) && (i > 0))
299            val = ranges[i-1].max;
300         else
301            val = ranges[i].min;
302         changed = TRUE;
303         break;
304      }
305   }
306   if (!changed && (i > 0) && (ranges[i-1].max < val))
307      val = ranges[i-1].max;
308
309   if (val != original_val)
310   {
311      _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
312      win_set_window_text_utf8(control, buf);
313   }
314   return TRUE;
315}
316
317
318
319optreserr_t win_add_resolution_parameter(HWND control, option_resolution *resolution)
320{
321   const option_guide *guide;
322   char buf[256];
323   optreserr_t err;
324   const char *text;
325   const char *old_text;
326   int i;
327
328   if (!win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf)))
329   {
330      err = OPTIONRESOLTUION_ERROR_INTERNAL;
331      return err;
332   }
333   text = buf;
334
335   guide = (const option_guide *) GetProp(control, guide_prop);
336   if (!guide)
337   {
338      err = OPTIONRESOLTUION_ERROR_INTERNAL;
339      return err;
340   }
341
342   if (guide->option_type == OPTIONTYPE_ENUM_BEGIN)
343   {
344      /* need to convert display name to identifier */
345      old_text = text;
346      text = NULL;
347
348      for (i = 1; guide[i].option_type == OPTIONTYPE_ENUM_VALUE; i++)
349      {
350         if (!strcmp(guide[i].display_name, old_text))
351         {
352            text = guide[i].identifier;
353            break;
354         }
355      }
356   }
357
358   if (text)
359   {
360      err = option_resolution_add_param(resolution, guide->identifier, text);
361      if (err)
362         return err;
363   }
364
365   err = OPTIONRESOLUTION_ERROR_SUCCESS;
366
367   return err;
368}
369
370
371
src/mess/osd/windows/winutils.h
r10018r10019
1//============================================================
2//
3//  winutils.h - Generic Win32 utility code in MESS
4//
5//============================================================
6
7#ifndef WINUTILS_H
8#define WINUTILS_H
9
10#include <windows.h>
11#include "osdcore.h"
12
13
14//============================================================
15//  FILE DIALOG WRAPPERS
16//============================================================
17
18enum _win_file_dialog_type
19{
20   WIN_FILE_DIALOG_OPEN = 1,
21   WIN_FILE_DIALOG_SAVE
22};
23typedef enum _win_file_dialog_type win_file_dialog_type;
24
25typedef struct _win_open_file_name win_open_file_name;
26struct _win_open_file_name
27{
28   win_file_dialog_type   type;            // type of file dialog
29   HWND               owner;            // owner of the dialog
30   HINSTANCE            instance;         // instance
31   const char *         filter;            // pipe char ("|") delimited strings
32   DWORD               filter_index;      // index into filter
33   char               filename[MAX_PATH];   // filename buffer
34   const char *         initial_directory;   // initial directory for dialog
35   DWORD               flags;            // standard flags
36   LPARAM               custom_data;      // custom data for dialog hook
37   LPOFNHOOKPROC         hook;            // custom dialog hook
38   LPCTSTR               template_name;      // custom dialog template
39};
40
41BOOL win_get_file_name_dialog(win_open_file_name *ofn);
42
43
44
45//============================================================
46//  MISC
47//============================================================
48
49void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line);
50
51BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char *item);
52
53#endif // WINUTILS_H
src/mess/osd/windows/dialog.h
r10018r10019
1//============================================================
2//
3//  dialog.h - Win32 MESS dialog handling
4//
5//============================================================
6
7#ifndef DIALOG_H
8#define DIALOG_H
9
10#include <windows.h>
11#include "emu.h"
12#include "png.h"
13#include "opresolv.h"
14#include "winutils.h"
15
16typedef struct _dialog_box dialog_box;
17
18struct dialog_layout
19{
20   short label_width;
21   short combo_width;
22};
23
24typedef void (*dialog_itemstoreval)(void *param, int val);
25typedef void (*dialog_itemchangedproc)(dialog_box *dialog, HWND dlgitem, void *changed_param);
26typedef void (*dialog_notification)(dialog_box *dialog, HWND dlgwnd, NMHDR *notification, void *param);
27
28/* dialog allocation / termination */
29dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layout);
30void win_dialog_exit(dialog_box *dialog);
31
32/* dialog memory allocation */
33void *win_dialog_malloc(dialog_box *dialog, size_t size);
34char *win_dialog_strdup(dialog_box *dialog, const char *s);
35WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s);
36
37#ifdef UNICODE
38#define win_dialog_tcsdup   win_dialog_wcsdup
39#else
40#define win_dialog_tcsdup   win_dialog_strdup
41#endif
42
43/* dialog operations */
44void win_dialog_runmodal(running_machine *machine, HWND wnd, dialog_box *dialog);
45int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value,
46   dialog_itemstoreval storeval, void *storeval_param);
47int win_dialog_add_active_combobox(dialog_box *dialog, const char *item_label, int default_value,
48   dialog_itemstoreval storeval, void *storeval_param,
49   dialog_itemchangedproc changed, void *changed_param);
50int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_label, int item_data);
51
52int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, int default_value,
53   int min_value, int max_value, BOOL is_percentage,
54   dialog_itemstoreval storeval, void *storeval_param);
55
56int win_dialog_add_slider(dialog_box *dialog, const char *item_label, int default_value,
57   int min_value, int max_value,
58   dialog_itemstoreval storeval, void *storeval_param);
59
60int win_dialog_add_portselect(dialog_box *dialog, const input_field_config *field);
61
62int win_dialog_add_standard_buttons(dialog_box *dialog);
63int win_dialog_add_image(dialog_box *dialog, const png_info *png);
64int win_dialog_add_separator(dialog_box *dialog);
65int win_dialog_add_notification(dialog_box *dialog, UINT notification,
66   dialog_notification callback, void *param);
67
68
69// wrapper for the standard file dialog
70BOOL win_file_dialog(running_machine *machine,
71   HWND parent, win_file_dialog_type dlgtype, dialog_box *custom_dialog, const char *filter,
72   const char *initial_dir, char *filename, size_t filename_len);
73
74#endif /* DIALOG_H */
src/mess/osd/windows/menu.c
r10018r10019
1//============================================================
2//
3//  menu.c - Win32 MESS menus handling
4//
5//============================================================
6
7// standard windows headers
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#include <commdlg.h>
11#include <winuser.h>
12#include <ctype.h>
13#include <tchar.h>
14
15// MAME/MESS headers
16#include "emu.h"
17#include "emuopts.h"
18#include "menu.h"
19#include "ui.h"
20#include "messres.h"
21#include "windows/video.h"
22#include "windows/input.h"
23#include "dialog.h"
24#include "opcntrl.h"
25#include "strconv.h"
26#include "debug/debugcpu.h"
27#include "inptport.h"
28#include "imagedev/cassette.h"
29#include "windows/window.h"
30#include "winutf8.h"
31
32//============================================================
33//  IMPORTS
34//============================================================
35
36// from timer.c
37extern void win_timer_enable(int enabled);
38
39
40//============================================================
41//  PARAMETERS
42//============================================================
43
44#define ID_FRAMESKIP_0            10000
45#define ID_DEVICE_0               11000
46#define ID_JOYSTICK_0            12000
47#define ID_INPUT_0               13000
48#define ID_VIDEO_VIEW_0            14000
49
50#define MAX_JOYSTICKS            (8)
51
52enum
53{
54   DEVOPTION_OPEN,
55   DEVOPTION_CREATE,
56   DEVOPTION_CLOSE,
57   DEVOPTION_CASSETTE_PLAYRECORD,
58   DEVOPTION_CASSETTE_STOPPAUSE,
59   DEVOPTION_CASSETTE_PLAY,
60   DEVOPTION_CASSETTE_RECORD,
61   DEVOPTION_CASSETTE_REWIND,
62   DEVOPTION_CASSETTE_FASTFORWARD,
63   DEVOPTION_MAX
64};
65
66#ifdef MAME_PROFILER
67#define HAS_PROFILER   1
68#else
69#define HAS_PROFILER   0
70#endif
71
72//============================================================
73//  LOCAL VARIABLES
74//============================================================
75
76static int use_input_categories;
77static int joystick_menu_setup;
78static char state_filename[MAX_PATH];
79
80static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions);
81
82
83
84//============================================================
85//  input_item_from_serial_number
86//============================================================
87
88static int input_item_from_serial_number(running_machine *machine, int serial_number,
89   const input_port_config **port, const input_field_config **field, const input_setting_config **setting)
90{
91   int i;
92   const input_port_config *this_port = NULL;
93   const input_field_config *this_field = NULL;
94   const input_setting_config *this_setting = NULL;
95
96   i = 0;
97   for (this_port = machine->m_portlist.first(); (i != serial_number) && (this_port != NULL); this_port = this_port->next())
98   {
99      i++;
100      for (this_field = this_port->fieldlist; (i != serial_number) && (this_field != NULL); this_field = this_field->next)
101      {
102         i++;
103         for (this_setting = this_field->settinglist; (i != serial_number) && (this_setting != NULL); this_setting = this_setting->next)
104         {
105            i++;
106         }
107      }
108   }
109
110   if (this_setting != NULL)
111      this_field = this_setting->field;
112   if (this_field != NULL)
113      this_port = this_field->port;
114
115   if (port != NULL)
116      *port = this_port;
117   if (field != NULL)
118      *field = this_field;
119   if (setting != NULL)
120      *setting = this_setting;
121   return (i == serial_number);
122}
123
124
125
126//============================================================
127//  serial_number_from_input_item
128//============================================================
129
130static int serial_number_from_input_item(running_machine *machine, const input_port_config *port,
131   const input_field_config *field, const input_setting_config *setting)
132{
133   int i;
134   const input_port_config *this_port;
135   const input_field_config *this_field;
136   const input_setting_config *this_setting;
137
138   i = 0;
139   for (this_port = machine->m_portlist.first(); this_port != NULL; this_port = this_port->next())
140   {
141      if ((port == this_port) && (field == NULL) && (setting == NULL))
142         return i;
143
144      i++;
145      for (this_field = this_port->fieldlist; this_field != NULL; this_field = this_field->next)
146      {
147         if ((port == this_port) && (field == this_field) && (setting == NULL))
148            return i;
149
150         i++;
151         for (this_setting = this_field->settinglist; this_setting != NULL; this_setting = this_setting->next)
152         {
153            if ((port == this_port) && (field == this_field) && (setting == this_setting))
154               return i;
155
156            i++;
157         }
158      }
159   }
160   return -1;
161}
162
163
164
165//============================================================
166//  customize_input
167//============================================================
168
169static void customize_input(running_machine *machine, HWND wnd, const char *title, int player, int inputclass)
170{
171   dialog_box *dlg;
172   const input_port_config *port;
173   const input_field_config *field;
174   int this_inputclass, this_player, portslot_count = 0, i;
175
176   struct
177   {
178      const input_field_config *field;
179   } portslots[256];
180
181   /* create the dialog */
182   dlg = win_dialog_init(title, NULL);
183   if (!dlg)
184      goto done;
185
186   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
187   {
188      for (field = port->fieldlist; field != NULL; field = field->next)
189      {
190         this_inputclass = input_classify_port(field);
191         if (input_field_name(field) && (this_inputclass == inputclass))
192         {
193            /* most of the time, the player parameter is the player number
194                 * but in the case of INPUT_CLASS_CATEGORIZED, it is the
195                 * category */
196            if (inputclass == INPUT_CLASS_CATEGORIZED)
197               this_player = field->category;
198            else
199               this_player = input_player_number(field);
200
201            if (this_player == player)
202            {
203               /* store this InputPort/RECT combo in our list.  we do not
204                     * necessarily want to add it yet because we the INI might
205                     * want to reorder the tab order */
206               if (portslot_count < ARRAY_LENGTH(portslots))
207               {
208                  portslots[portslot_count].field = field;
209               }
210               portslot_count++;
211            }
212         }
213      }
214   }
215
216   /* finally add the portselects to the dialog */
217   if (portslot_count > ARRAY_LENGTH(portslots))
218      portslot_count = ARRAY_LENGTH(portslots);
219   for (i = 0; i < portslot_count; i++)
220   {
221      if (portslots[i].field)
222      {
223         if (win_dialog_add_portselect(dlg, portslots[i].field))
224            goto done;
225      }
226   }
227
228   /* ...and now add OK/Cancel */
229   if (win_dialog_add_standard_buttons(dlg))
230      goto done;
231
232   /* ...and finally display the dialog */
233   win_dialog_runmodal(machine, wnd, dlg);
234
235done:
236   if (dlg)
237      win_dialog_exit(dlg);
238}
239
240
241
242//============================================================
243//  customize_joystick
244//============================================================
245
246static void customize_joystick(running_machine *machine, HWND wnd, int joystick_num)
247{
248   customize_input(machine, wnd, "Joysticks/Controllers", joystick_num, INPUT_CLASS_CONTROLLER);
249}
250
251
252
253//============================================================
254//  customize_keyboard
255//============================================================
256
257static void customize_keyboard(running_machine *machine, HWND wnd)
258{
259   customize_input(machine, wnd, "Emulated Keyboard", 0, INPUT_CLASS_KEYBOARD);
260}
261
262
263
264//============================================================
265//  customize_miscinput
266//============================================================
267
268static void customize_miscinput(running_machine *machine, HWND wnd)
269{
270   customize_input(machine, wnd, "Miscellaneous Input", 0, INPUT_CLASS_MISC);
271}
272
273
274
275//============================================================
276//  customize_categorizedinput
277//============================================================
278
279static void customize_categorizedinput(running_machine *machine, HWND wnd, int category)
280{
281   assert(category > 0);
282   customize_input(machine, wnd, "Input", category, INPUT_CLASS_CATEGORIZED);
283}
284
285
286
287//============================================================
288//  storeval_inputport
289//============================================================
290
291static void storeval_inputport(void *param, int val)
292{
293   const input_field_config *field = (input_field_config *) param;
294   input_field_user_settings settings;
295
296   input_field_get_user_settings(field, &settings);
297   settings.value = (UINT16) val;
298   input_field_set_user_settings(field, &settings);
299}
300
301
302
303//============================================================
304//  customize_switches
305//============================================================
306
307static void customize_switches(running_machine *machine, HWND wnd, const char* title_string, UINT32 ipt_name)
308{
309   dialog_box *dlg;
310   const input_port_config *port;
311   const input_field_config *field;
312   const input_setting_config *setting;
313   const char *switch_name = NULL;
314   input_field_user_settings settings;
315
316   UINT32 type;
317
318   dlg = win_dialog_init(title_string, NULL);
319   if (!dlg)
320      goto done;
321
322   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
323   {
324      for (field = port->fieldlist; field != NULL; field = field->next)
325      {
326         type = field->type;
327
328         if (type == ipt_name)
329         {
330            switch_name = input_field_name(field);
331
332            input_field_get_user_settings(field, &settings);
333
334            if (win_dialog_add_combobox(dlg, switch_name, settings.value, storeval_inputport, (void *) field))
335               goto done;
336
337            for (setting = field->settinglist; setting != NULL; setting = setting->next)
338            {
339               if (win_dialog_add_combobox_item(dlg, setting->name, setting->value))
340                  goto done;
341            }
342         }
343      }
344   }
345
346   if (win_dialog_add_standard_buttons(dlg))
347      goto done;
348
349   win_dialog_runmodal(machine, wnd, dlg);
350
351done:
352   if (dlg)
353      win_dialog_exit(dlg);
354}
355
356
357
358//============================================================
359//  customize_dipswitches
360//============================================================
361
362static void customize_dipswitches(running_machine *machine, HWND wnd)
363{
364   customize_switches(machine, wnd, "Dip Switches", IPT_DIPSWITCH);
365}
366
367
368
369//============================================================
370//  customize_configuration
371//============================================================
372
373static void customize_configuration(running_machine *machine, HWND wnd)
374{
375   customize_switches(machine, wnd, "Driver Configuration", IPT_CONFIG);
376}
377
378
379
380//============================================================
381//  customize_analogcontrols
382//============================================================
383
384enum
385{
386   ANALOG_ITEM_KEYSPEED,
387   ANALOG_ITEM_CENTERSPEED,
388   ANALOG_ITEM_REVERSE,
389   ANALOG_ITEM_SENSITIVITY
390};
391
392
393
394static void store_analogitem(void *param, int val, int selected_item)
395{
396   const input_field_config *field = (const input_field_config *) param;
397   input_field_user_settings settings;
398
399   input_field_get_user_settings(field, &settings);
400
401   switch(selected_item)
402   {
403      case ANALOG_ITEM_KEYSPEED:      settings.delta = val;      break;
404      case ANALOG_ITEM_CENTERSPEED:   settings.centerdelta = val;   break;
405      case ANALOG_ITEM_REVERSE:      settings.reverse = val;      break;
406      case ANALOG_ITEM_SENSITIVITY:   settings.sensitivity = val;   break;
407   }
408   input_field_set_user_settings(field, &settings);
409}
410
411
412
413static void store_delta(void *param, int val)
414{
415   store_analogitem(param, val, ANALOG_ITEM_KEYSPEED);
416}
417
418
419
420static void store_centerdelta(void *param, int val)
421{
422   store_analogitem(param, val, ANALOG_ITEM_CENTERSPEED);
423}
424
425
426
427static void store_reverse(void *param, int val)
428{
429   store_analogitem(param, val, ANALOG_ITEM_REVERSE);
430}
431
432
433
434static void store_sensitivity(void *param, int val)
435{
436   store_analogitem(param, val, ANALOG_ITEM_SENSITIVITY);
437}
438
439
440
441static int port_type_is_analog(int type)
442{
443   return (type >= __ipt_analog_start && type <= __ipt_analog_end);
444}
445
446
447
448static void customize_analogcontrols(running_machine *machine, HWND wnd)
449{
450   dialog_box *dlg;
451   const input_port_config *port;
452   const input_field_config *field;
453   input_field_user_settings settings;
454   const char *name;
455   char buf[255];
456   static const struct dialog_layout layout = { 120, 52 };
457
458   dlg = win_dialog_init("Analog Controls", &layout);
459   if (!dlg)
460      goto done;
461
462   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
463   {
464      for (field = port->fieldlist; field != NULL; field = field->next)
465      {
466         if (port_type_is_analog(field->type))
467         {
468            input_field_get_user_settings(field, &settings);
469            name = input_field_name(field);
470
471            _snprintf(buf, ARRAY_LENGTH(buf),
472               "%s %s", name, "Digital Speed");
473            if (win_dialog_add_adjuster(dlg, buf, settings.delta, 1, 255, FALSE, store_delta, (void *) field))
474               goto done;
475
476            _snprintf(buf, ARRAY_LENGTH(buf),
477               "%s %s", name, "Autocenter Speed");
478            if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 1, 255, FALSE, store_centerdelta, (void *) field))
479               goto done;
480
481            _snprintf(buf, ARRAY_LENGTH(buf),
482               "%s %s", name, "Reverse");
483            if (win_dialog_add_combobox(dlg, buf, settings.reverse ? 1 : 0, store_reverse, (void *) field))
484               goto done;
485            if (win_dialog_add_combobox_item(dlg, "Off", 0))
486               goto done;
487            if (win_dialog_add_combobox_item(dlg, "On", 1))
488               goto done;
489
490            _snprintf(buf, ARRAY_LENGTH(buf),
491               "%s %s", name, "Sensitivity");
492            if (win_dialog_add_adjuster(dlg, buf, settings.sensitivity, 1, 255, TRUE, store_sensitivity, (void *) field))
493               goto done;
494         }
495      }
496   }
497
498   if (win_dialog_add_standard_buttons(dlg))
499      goto done;
500
501   win_dialog_runmodal(machine, wnd, dlg);
502
503done:
504   if (dlg)
505      win_dialog_exit(dlg);
506}
507
508
509//============================================================
510//  win_dirname
511//============================================================
512
513static char *win_dirname(const char *filename)
514{
515   char *dirname;
516   char *c;
517
518   // NULL begets NULL
519   if (!filename)
520      return NULL;
521
522   // allocate space for it
523   dirname = (char*)malloc(strlen(filename) + 1);
524   if (!dirname)
525      return NULL;
526
527   // copy in the name
528   strcpy(dirname, filename);
529
530   // search backward for a slash or a colon
531   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
532      if (*c == '\\' || *c == '/' || *c == ':')
533      {
534         // found it: NULL terminate and return
535         *(c + 1) = 0;
536         return dirname;
537      }
538
539   // otherwise, return an empty string
540   dirname[0] = 0;
541   return dirname;
542}
543
544
545//============================================================
546//  state_dialog
547//============================================================
548
549static void state_dialog(HWND wnd, win_file_dialog_type dlgtype,
550   DWORD fileproc_flags, bool is_load,
551   running_machine *machine)
552{
553   win_open_file_name ofn;
554   char *dir = NULL;
555   int result = 0;
556
557   if (state_filename[0])
558   {
559      dir = win_dirname(state_filename);
560   }
561
562   memset(&ofn, 0, sizeof(ofn));
563   ofn.type = dlgtype;
564   ofn.owner = wnd;
565   ofn.flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | fileproc_flags;
566   ofn.filter = "State Files (*.sta)|*.sta|All Files (*.*)|*.*";
567   ofn.initial_directory = dir;
568
569   if (!core_filename_ends_with(ofn.filename, "sta"))
570      snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s.sta", state_filename);
571   else
572      snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s", state_filename);
573
574   result = win_get_file_name_dialog(&ofn);
575   if (result)
576   {
577      // the core doesn't add the extension if it's an absolute path
578      if (osd_is_absolute_path(ofn.filename) && !core_filename_ends_with(ofn.filename, "sta"))
579         snprintf(state_filename, ARRAY_LENGTH(state_filename), "%s.sta", ofn.filename);
580      else
581         snprintf(state_filename, ARRAY_LENGTH(state_filename), "%s", ofn.filename);
582
583      if (is_load) {
584         machine->schedule_load(state_filename);
585      } else {
586         machine->schedule_save(state_filename);
587      }
588   }
589   if (dir)
590      free(dir);
591}
592
593
594
595static void state_load(HWND wnd, running_machine *machine)
596{
597   state_dialog(wnd, WIN_FILE_DIALOG_OPEN, OFN_FILEMUSTEXIST, TRUE, machine);
598}
599
600static void state_save_as(HWND wnd, running_machine *machine)
601{
602   state_dialog(wnd, WIN_FILE_DIALOG_SAVE, OFN_OVERWRITEPROMPT, FALSE, machine);
603}
604
605static void state_save(running_machine *machine)
606{
607   machine->schedule_save(state_filename);
608}
609
610
611
612//============================================================
613//  format_combo_changed
614//============================================================
615
616struct file_dialog_params
617{
618   device_image_interface *dev;
619   int *create_format;
620   option_resolution **create_args;
621};
622
623static void format_combo_changed(dialog_box *dialog, HWND dlgwnd, NMHDR *notification, void *changed_param)
624{
625   HWND wnd;
626   int format_combo_val;
627   device_image_interface *dev;
628   const option_guide *guide;
629   const char *optspec;
630   struct file_dialog_params *params;
631   int has_option;
632   TCHAR t_buf1[128];
633   char *utf8_buf1;
634
635   params = (struct file_dialog_params *) changed_param;
636
637   // locate the format control
638   format_combo_val = notification ? (((OFNOTIFY *) notification)->lpOFN->nFilterIndex - 1) : 0;
639   if (format_combo_val < 0)
640      format_combo_val = 0;
641   *(params->create_format) = format_combo_val;
642
643   // compute our parameters
644   dev = params->dev;
645   guide = dev->device_get_creation_option_guide();
646   optspec =dev->device_get_indexed_creatable_format(format_combo_val)->m_optspec;
647
648   // set the default extension
649   CommDlg_OpenSave_SetDefExt(GetParent(dlgwnd),
650      (const char*)dev->device_get_indexed_creatable_format(format_combo_val)->m_extensions);
651
652   // enumerate through all of the child windows
653   wnd = NULL;
654   while((wnd = FindWindowEx(dlgwnd, wnd, NULL, NULL)) != NULL)
655   {
656      // get label text, removing trailing NULL
657      GetWindowText(wnd, t_buf1, ARRAY_LENGTH(t_buf1));
658      utf8_buf1 = utf8_from_tstring(t_buf1);
659      assert(utf8_buf1[strlen(utf8_buf1)-1] == ':');
660      utf8_buf1[strlen(utf8_buf1)-1] = '\0';
661
662      // find guide entry
663      while(guide->option_type && strcmp(utf8_buf1, guide->display_name))
664         guide++;
665
666      wnd = GetNextWindow(wnd, GW_HWNDNEXT);
667      if (wnd && guide)
668      {
669         // we now have the handle to the window, and the guide entry
670         has_option = option_resolution_contains(optspec, guide->parameter);
671
672         SendMessage(wnd, CB_GETLBTEXT, SendMessage(wnd, CB_GETCURSEL, 0, 0), (LPARAM) t_buf1);
673         SendMessage(wnd, CB_RESETCONTENT, 0, 0);
674
675         win_prepare_option_control(wnd,
676            has_option ? guide : NULL,
677            has_option ? optspec : NULL);
678      }
679      osd_free(utf8_buf1);
680   }
681}
682
683
684
685//============================================================
686//  storeval_option_resolution
687//============================================================
688
689struct storeval_optres_params
690{
691   struct file_dialog_params *fdparams;
692   const option_guide *guide_entry;
693};
694
695static void storeval_option_resolution(void *storeval_param, int val)
696{
697   option_resolution *resolution;
698   struct storeval_optres_params *params;
699   device_image_interface *dev;
700   char buf[16];
701
702   params = (struct storeval_optres_params *) storeval_param;
703   dev = params->fdparams->dev;
704
705   // create the resolution, if necessary
706   resolution = *(params->fdparams->create_args);
707   if (!resolution)
708   {
709      const option_guide *optguide = dev->device_get_creation_option_guide();
710      const image_device_format *format = dev->device_get_indexed_creatable_format(*(params->fdparams->create_format));
711
712      resolution = option_resolution_create(optguide, format->m_optspec);
713      if (!resolution)
714         return;
715      *(params->fdparams->create_args) = resolution;
716   }
717
718   snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
719   option_resolution_add_param(resolution, params->guide_entry->identifier, buf);
720}
721
722
723
724//============================================================
725//  build_option_dialog
726//============================================================
727
728static dialog_box *build_option_dialog(device_image_interface *dev, char *filter, size_t filter_len, int *create_format, option_resolution **create_args)
729{
730   dialog_box *dialog;
731   const option_guide *guide_entry;
732   int found, pos;
733   char buf[256];
734   struct file_dialog_params *params;
735   struct storeval_optres_params *storeval_params;
736   static const struct dialog_layout filedialog_layout = { 44, 220 };
737   const image_device_format *format;
738
739   // make the filter
740   pos = 0;
741   for (format = dev->device_get_creatable_formats(); format != NULL; format = format->m_next)
742   {
743      pos += add_filter_entry(filter + pos, filter_len - pos, format->m_description, format->m_extensions);
744   }
745
746   // create the dialog
747   dialog = win_dialog_init(NULL, &filedialog_layout);
748   if (!dialog)
749      goto error;
750
751   // allocate the params
752   params = (struct file_dialog_params *) win_dialog_malloc(dialog, sizeof(*params));
753   if (!params)
754      goto error;
755   params->dev = dev;
756   params->create_format = create_format;
757   params->create_args = create_args;
758
759   // set the notify handler; so that we get notified when the format dialog changed
760   if (win_dialog_add_notification(dialog, CDN_TYPECHANGE, format_combo_changed, params))
761      goto error;
762
763   // loop through the entries
764   for (guide_entry = dev->device_get_creation_option_guide(); guide_entry->option_type != OPTIONTYPE_END; guide_entry++)
765   {
766      // make sure that this entry is present on at least one option specification
767      found = FALSE;
768      for (format = dev->device_get_creatable_formats(); format != NULL; format = format->m_next)
769      {
770         if (option_resolution_contains(format->m_optspec, guide_entry->parameter))
771         {
772            found = TRUE;
773            break;
774         }
775      }
776
777      if (found)
778      {
779         storeval_params = (struct storeval_optres_params *) win_dialog_malloc(dialog, sizeof(*storeval_params));
780         if (!storeval_params)
781            goto error;
782         storeval_params->fdparams = params;
783         storeval_params->guide_entry = guide_entry;
784
785         // this option is present on at least one of the specs
786         switch(guide_entry->option_type)
787         {
788            case OPTIONTYPE_INT:
789               snprintf(buf, ARRAY_LENGTH(buf), "%s:", guide_entry->display_name);
790               if (win_dialog_add_combobox(dialog, buf, 0, storeval_option_resolution, storeval_params))
791                  goto error;
792               break;
793
794            default:
795               break;
796         }
797      }
798   }
799
800   return dialog;
801
802error:
803   if (dialog)
804      win_dialog_exit(dialog);
805   return NULL;
806}
807
808
809
810//============================================================
811//  copy_extension_list
812//============================================================
813
814static int copy_extension_list(char *dest, size_t dest_len, const char *extensions)
815{
816   const char *s;
817   int pos = 0;
818
819   // our extension lists are comma delimited; Win32 expects to see lists
820   // delimited by semicolons
821   s = extensions;
822   while(*s)
823   {
824      // append a semicolon if not at the beginning
825      if (s != extensions)
826         pos += snprintf(&dest[pos], dest_len - pos, ";");
827
828      // append ".*"
829      pos += snprintf(&dest[pos], dest_len - pos, "*.");
830
831      // append the file extension
832      while(*s && (*s != ','))
833      {
834         pos += snprintf(&dest[pos], dest_len - pos, "%c", *s);
835         s++;
836      }
837
838      // if we found a comma, advance
839      while(*s == ',')
840         s++;
841   }
842   return pos;
843}
844
845
846
847//============================================================
848//  add_filter_entry
849//============================================================
850
851static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions)
852{
853   int pos = 0;
854
855   // add the description
856   pos += snprintf(&dest[pos], dest_len - pos, "%s (", description);
857
858   // add the extensions to the description
859   pos += copy_extension_list(&dest[pos], dest_len - pos, extensions);
860
861   // add the trailing rparen and '|' character
862   pos += snprintf(&dest[pos], dest_len - pos, ")|");
863
864   // now add the extension list itself
865   pos += copy_extension_list(&dest[pos], dest_len - pos, extensions);
866
867   // append a '|'
868   pos += snprintf(&dest[pos], dest_len - pos, "|");
869
870   return pos;
871}
872
873
874
875//============================================================
876//  build_generic_filter
877//============================================================
878
879static void build_generic_filter(device_t *device, int is_save, char *filter, size_t filter_len)
880{
881   char *s;
882
883   const char *file_extension;
884
885   /* copy the string */
886   file_extension = downcast<const legacy_image_device_config_base *>(&device->baseconfig())->file_extensions();
887
888   // start writing the filter
889   s = filter;
890
891   // common image types
892   s += add_filter_entry(filter, filter_len, "Common image types", file_extension);
893
894   // all files
895   s += sprintf(s, "All files (*.*)|*.*|");
896
897   // compressed
898   if (!is_save)
899      s += sprintf(s, "Compressed Images (*.zip)|*.zip|");
900
901   *(s++) = '\0';
902}
903
904
905
906//============================================================
907//  change_device
908//============================================================
909
910static void change_device(HWND wnd, device_image_interface *image, int is_save)
911{
912   dialog_box *dialog = NULL;
913   char filter[2048];
914   char filename[MAX_PATH];
915   const char *initial_dir;
916   BOOL result;
917   int create_format = 0;
918   option_resolution *create_args = NULL;
919
920   // sanity check
921   assert(image != NULL);
922
923   // get the file
924   if (image->exists())
925   {
926      const char *imgname;
927      imgname = image->basename();
928      snprintf(filename, ARRAY_LENGTH(filename), "%s", imgname);
929   }
930   else
931   {
932      filename[0] = '\0';
933   }
934
935   // use image directory, if it is there
936   initial_dir = image->working_directory();
937
938   // add custom dialog elements, if appropriate
939   if (is_save
940      && (image->device_get_creation_option_guide() != NULL)
941      && (image->device_get_creatable_formats() != NULL))
942   {
943      dialog = build_option_dialog(image, filter, ARRAY_LENGTH(filter), &create_format, &create_args);
944      if (!dialog)
945         goto done;
946   }
947   else
948   {
949      // build a normal filter
950      build_generic_filter(&image->device(), is_save, filter, ARRAY_LENGTH(filter));
951   }
952
953   // display the dialog
954   result = win_file_dialog(image->device().machine, wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN,
955      dialog, filter, initial_dir, filename, ARRAY_LENGTH(filename));
956   if (result)
957   {
958      // mount the image
959      if (is_save)
960         (image_error_t)image->create(filename, image->device_get_indexed_creatable_format(create_format), create_args);
961      else
962         (image_error_t)image->load( filename);
963
964      // no need to check the returnvalue and show a messagebox anymore.
965      // a UI message will now be generated by the image code
966   }
967
968done:
969   if (dialog != NULL)
970      win_dialog_exit(dialog);
971   if (create_args != NULL)
972      option_resolution_close(create_args);
973}
974
975
976
977//============================================================
978//  pause
979//============================================================
980
981static void pause(running_machine *machine)
982{
983   if (!winwindow_ui_is_paused(machine)) {
984      machine->pause();
985   } else {
986      machine->resume();
987   }
988}
989
990
991
992//============================================================
993//  get_menu_item_string
994//============================================================
995
996static BOOL get_menu_item_string(HMENU menu, UINT item, BOOL by_position, HMENU *sub_menu, LPTSTR buffer, size_t buffer_len)
997{
998   MENUITEMINFO mii;
999
1000   // clear out results
1001   memset(buffer, '\0', sizeof(*buffer) * buffer_len);
1002   if (sub_menu)
1003      *sub_menu = NULL;
1004
1005   // prepare MENUITEMINFO structure
1006   memset(&mii, 0, sizeof(mii));
1007   mii.cbSize = sizeof(mii);
1008   mii.fMask = MIIM_TYPE | (sub_menu ? MIIM_SUBMENU : 0);
1009   mii.dwTypeData = buffer;
1010   mii.cch = buffer_len;
1011
1012   // call GetMenuItemInfo()
1013   if (!GetMenuItemInfo(menu, item, by_position, &mii))
1014      return FALSE;
1015
1016   // return results
1017   if (sub_menu)
1018      *sub_menu = mii.hSubMenu;
1019   if (mii.fType == MFT_SEPARATOR)
1020      _sntprintf(buffer, buffer_len, TEXT("-"));
1021   return TRUE;
1022}
1023
1024
1025
1026//============================================================
1027//  find_sub_menu
1028//============================================================
1029
1030static HMENU find_sub_menu(HMENU menu, const char *menutext, int create_sub_menu)
1031{
1032   int i;
1033   TCHAR buf[128];
1034   HMENU sub_menu;
1035
1036   while(*menutext)
1037   {
1038      TCHAR *t_menutext = tstring_from_utf8(menutext);
1039
1040      i = -1;
1041      do
1042      {
1043         if (!get_menu_item_string(menu, ++i, TRUE, &sub_menu, buf, ARRAY_LENGTH(buf)))
1044         {
1045            osd_free(t_menutext);
1046            return NULL;
1047         }
1048      }
1049      while(_tcscmp(t_menutext, buf));
1050
1051      osd_free(t_menutext);
1052
1053      if (!sub_menu && create_sub_menu)
1054      {
1055         MENUITEMINFO mii;
1056         memset(&mii, 0, sizeof(mii));
1057         mii.cbSize = sizeof(mii);
1058         mii.fMask = MIIM_SUBMENU;
1059         mii.hSubMenu = CreateMenu();
1060         if (!SetMenuItemInfo(menu, i, TRUE, &mii))
1061         {
1062            i = GetLastError();
1063            return NULL;
1064         }
1065         sub_menu = mii.hSubMenu;
1066      }
1067      menu = sub_menu;
1068      if (!menu)
1069         return NULL;
1070      menutext += strlen(menutext) + 1;
1071   }
1072   return menu;
1073}
1074
1075
1076
1077//============================================================
1078//  set_command_state
1079//============================================================
1080
1081static void set_command_state(HMENU menu_bar, UINT command, UINT state)
1082{
1083   BOOL result;
1084
1085   MENUITEMINFO mii;
1086
1087   memset(&mii, 0, sizeof(mii));
1088   mii.cbSize = sizeof(mii);
1089   mii.fMask = MIIM_STATE;
1090   mii.fState = state;
1091   result = SetMenuItemInfo(menu_bar, command, FALSE, &mii);
1092}
1093
1094
1095
1096
1097//============================================================
1098//  remove_menu_items
1099//============================================================
1100
1101static void remove_menu_items(HMENU menu)
1102{
1103   while(RemoveMenu(menu, 0, MF_BYPOSITION))
1104      ;
1105}
1106
1107
1108
1109//============================================================
1110//  setup_joystick_menu
1111//============================================================
1112
1113static void setup_joystick_menu(running_machine *machine, HMENU menu_bar)
1114{
1115   int joystick_count = 0;
1116   HMENU joystick_menu;
1117   int i;
1118   UINT command;
1119   HMENU submenu = NULL;
1120   const input_port_config *port;
1121   const input_field_config *field;
1122   const input_setting_config *setting;
1123   char buf[256];
1124   int child_count = 0;
1125
1126   use_input_categories = 0;
1127   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
1128   {
1129      for (field = port->fieldlist; field != NULL; field = field->next)
1130      {
1131         if (field->type == IPT_CATEGORY)
1132         {
1133            use_input_categories = 1;
1134            break;
1135         }
1136      }
1137   }
1138
1139   joystick_menu = find_sub_menu(menu_bar, "&Options\0&Joysticks\0", TRUE);
1140   if (!joystick_menu)
1141      return;
1142
1143   if (use_input_categories)
1144   {
1145      // using input categories
1146      for (port = machine->m_portlist.first(); port != NULL; port = port->next())
1147      {
1148         for (field = port->fieldlist; field != NULL; field = field->next)
1149         {
1150            if (field->type == IPT_CATEGORY)
1151            {
1152               submenu = CreateMenu();
1153               if (!submenu)
1154                  return;
1155
1156               // append all of the category settings
1157               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1158               {
1159                  command = ID_INPUT_0 + serial_number_from_input_item(machine, port, field, setting);
1160                  win_append_menu_utf8(submenu, MF_STRING, command, setting->name);
1161               }
1162
1163               // tack on the final items and the menu item
1164               command = ID_INPUT_0 + serial_number_from_input_item(machine, port, field, NULL);
1165               AppendMenu(submenu, MF_SEPARATOR, 0, NULL);
1166               AppendMenu(submenu, MF_STRING, command, TEXT("&Configure..."));
1167               win_append_menu_utf8(joystick_menu, MF_STRING | MF_POPUP, (UINT_PTR) submenu, field->name);
1168               child_count++;
1169            }
1170         }
1171      }
1172   }
1173   else
1174   {
1175      // set up joystick menu
1176      joystick_count = input_count_players(machine);
1177      if (joystick_count > 0)
1178      {
1179         for (i = 0; i < joystick_count; i++)
1180         {
1181            snprintf(buf, ARRAY_LENGTH(buf), "Joystick %i", i + 1);
1182            win_append_menu_utf8(joystick_menu, MF_STRING, ID_JOYSTICK_0 + i, buf);
1183            child_count++;
1184         }
1185      }
1186   }
1187
1188   // last but not least, enable the joystick menu (or not)
1189   set_command_state(menu_bar, ID_OPTIONS_JOYSTICKS, child_count ? MFS_ENABLED : MFS_GRAYED);
1190}
1191
1192
1193
1194//============================================================
1195//  is_windowed
1196//============================================================
1197
1198static int is_windowed(void)
1199{
1200   return video_config.windowed;
1201}
1202
1203
1204
1205//============================================================
1206//  frameskip_level_count
1207//============================================================
1208
1209static int frameskip_level_count(void)
1210{
1211   static int count = -1;
1212
1213   if (count < 0)
1214   {
1215      int frameskip_min = 0;
1216      int frameskip_max = 10;
1217      options_get_range_int(mame_options(), OPTION_FRAMESKIP, &frameskip_min, &frameskip_max);
1218      count = frameskip_max + 1;
1219   }
1220   return count;
1221}
1222
1223
1224
1225//============================================================
1226//  prepare_menus
1227//============================================================
1228
1229static void prepare_menus(HWND wnd)
1230{
1231   int i;
1232   char buf[MAX_PATH];
1233   TCHAR t_buf[MAX_PATH];
1234   const char *s;
1235   HMENU menu_bar;
1236   HMENU video_menu;
1237   HMENU device_menu;
1238   HMENU sub_menu;
1239   UINT_PTR new_item;
1240   UINT flags_for_exists;
1241   UINT flags_for_writing;
1242   device_image_interface *img = NULL;
1243   int has_config, has_dipswitch, has_keyboard, has_analog, has_misc;
1244   const input_port_config *port;
1245   const input_field_config *field;
1246   const input_setting_config *setting;
1247   int frameskip;
1248   int orientation;
1249   int speed;
1250   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
1251   win_window_info *window = (win_window_info *)ptr;
1252   const char *view_name;
1253   int view_index;
1254   UINT command;
1255   input_field_user_settings settings;
1256
1257   menu_bar = GetMenu(wnd);
1258   if (!menu_bar)
1259      return;
1260
1261   if (!joystick_menu_setup)
1262   {
1263      setup_joystick_menu(window->machine, menu_bar);
1264      joystick_menu_setup = 1;
1265   }
1266
1267   frameskip = window->machine->video().frameskip();
1268
1269   orientation = window->target->orientation();
1270
1271   speed = window->machine->video().throttled() ? window->machine->video().speed_factor() : 0;
1272
1273   has_config      = input_has_input_class(window->machine, INPUT_CLASS_CONFIG);
1274   has_dipswitch   = input_has_input_class(window->machine, INPUT_CLASS_DIPSWITCH);
1275   has_keyboard   = input_has_input_class(window->machine, INPUT_CLASS_KEYBOARD);
1276   has_misc      = input_has_input_class(window->machine, INPUT_CLASS_MISC);
1277
1278   has_analog = 0;
1279   for (port = window->machine->m_portlist.first(); port != NULL; port = port->next())
1280   {
1281      for (field = port->fieldlist; field != NULL; field = field->next)
1282      {
1283         if (port_type_is_analog(field->type))
1284         {
1285            has_analog = 1;
1286            break;
1287         }
1288      }
1289   }
1290
1291   set_command_state(menu_bar, ID_FILE_SAVESTATE,         state_filename[0] != '\0'               ? MFS_ENABLED : MFS_GRAYED);
1292
1293   set_command_state(menu_bar, ID_EDIT_PASTE,            inputx_can_post(window->machine)         ? MFS_ENABLED : MFS_GRAYED);
1294
1295   set_command_state(menu_bar, ID_OPTIONS_PAUSE,         winwindow_ui_is_paused(window->machine)      ? MFS_CHECKED : MFS_ENABLED);
1296   set_command_state(menu_bar, ID_OPTIONS_CONFIGURATION,   has_config                           ? MFS_ENABLED : MFS_GRAYED);
1297   set_command_state(menu_bar, ID_OPTIONS_DIPSWITCHES,      has_dipswitch                        ? MFS_ENABLED : MFS_GRAYED);
1298   set_command_state(menu_bar, ID_OPTIONS_MISCINPUT,      has_misc                           ? MFS_ENABLED : MFS_GRAYED);
1299   set_command_state(menu_bar, ID_OPTIONS_ANALOGCONTROLS,   has_analog                           ? MFS_ENABLED : MFS_GRAYED);
1300   set_command_state(menu_bar, ID_OPTIONS_FULLSCREEN,      !is_windowed()                        ? MFS_CHECKED : MFS_ENABLED);
1301   set_command_state(menu_bar, ID_OPTIONS_TOGGLEFPS,      ui_get_show_fps()                     ? MFS_CHECKED : MFS_ENABLED);
1302#if HAS_PROFILER
1303   set_command_state(menu_bar, ID_OPTIONS_PROFILER,      ui_get_show_profiler()                  ? MFS_CHECKED : MFS_ENABLED);
1304#endif
1305
1306   set_command_state(menu_bar, ID_KEYBOARD_EMULATED,      (has_keyboard) ?
1307                                                (!ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1308                                                                                    : MFS_GRAYED);
1309   set_command_state(menu_bar, ID_KEYBOARD_NATURAL,      (has_keyboard && inputx_can_post(window->machine)) ?                                                (ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1310                                                                                    : MFS_GRAYED);
1311   set_command_state(menu_bar, ID_KEYBOARD_CUSTOMIZE,      has_keyboard                        ? MFS_ENABLED : MFS_GRAYED);
1312
1313   set_command_state(menu_bar, ID_VIDEO_ROTATE_0,         (orientation == ROT0)                  ? MFS_CHECKED : MFS_ENABLED);
1314   set_command_state(menu_bar, ID_VIDEO_ROTATE_90,         (orientation == ROT90)                  ? MFS_CHECKED : MFS_ENABLED);
1315   set_command_state(menu_bar, ID_VIDEO_ROTATE_180,      (orientation == ROT180)                  ? MFS_CHECKED : MFS_ENABLED);
1316   set_command_state(menu_bar, ID_VIDEO_ROTATE_270,      (orientation == ROT270)                  ? MFS_CHECKED : MFS_ENABLED);
1317
1318   set_command_state(menu_bar, ID_THROTTLE_50,            (speed == 50)                        ? MFS_CHECKED : MFS_ENABLED);
1319   set_command_state(menu_bar, ID_THROTTLE_100,         (speed == 100)                        ? MFS_CHECKED : MFS_ENABLED);
1320   set_command_state(menu_bar, ID_THROTTLE_200,         (speed == 200)                        ? MFS_CHECKED : MFS_ENABLED);
1321   set_command_state(menu_bar, ID_THROTTLE_500,         (speed == 500)                        ? MFS_CHECKED : MFS_ENABLED);
1322   set_command_state(menu_bar, ID_THROTTLE_1000,         (speed == 1000)                        ? MFS_CHECKED : MFS_ENABLED);
1323   set_command_state(menu_bar, ID_THROTTLE_UNTHROTTLED,   (speed == 0)                        ? MFS_CHECKED : MFS_ENABLED);
1324
1325   set_command_state(menu_bar, ID_FRAMESKIP_AUTO,         (frameskip < 0)                        ? MFS_CHECKED : MFS_ENABLED);
1326   for (i = 0; i < frameskip_level_count(); i++)
1327      set_command_state(menu_bar, ID_FRAMESKIP_0 + i,      (frameskip == i)                     ? MFS_CHECKED : MFS_ENABLED);
1328
1329   // if we are using categorized input, we need to properly checkmark the categories
1330   if (use_input_categories)
1331   {
1332      for (port = window->machine->m_portlist.first(); port != NULL; port = port->next())
1333      {
1334         for (field = port->fieldlist; field != NULL; field = field->next)
1335         {
1336            if (field->type == IPT_CATEGORY)
1337            {
1338               input_field_get_user_settings(field, &settings);
1339               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1340               {
1341                  command = ID_INPUT_0 + serial_number_from_input_item(window->machine, port, field, setting);
1342                  set_command_state(menu_bar, command, (setting->value == settings.value) ? MFS_CHECKED : MFS_ENABLED);
1343               }
1344            }
1345         }
1346      }
1347   }
1348
1349   // set up screens in video menu
1350   video_menu = find_sub_menu(menu_bar, "&Options\0&Video\0", FALSE);
1351   do
1352   {
1353      get_menu_item_string(video_menu, 0, TRUE, NULL, t_buf, ARRAY_LENGTH(t_buf));
1354      if (_tcscmp(t_buf, TEXT("-")))
1355         RemoveMenu(video_menu, 0, MF_BYPOSITION);
1356   }
1357   while(_tcscmp(t_buf, TEXT("-")));
1358   i = 0;
1359   view_index = window->target->view();
1360   while((view_name = window->target->view_name(i)) != NULL)
1361   {
1362      TCHAR *t_view_name = tstring_from_utf8(view_name);
1363      InsertMenu(video_menu, i, MF_BYPOSITION | (i == view_index ? MF_CHECKED : 0),
1364         ID_VIDEO_VIEW_0 + i, t_view_name);
1365      osd_free(t_view_name);
1366      i++;
1367   }
1368
1369   // set up device menu; first remove all existing menu items
1370   device_menu = find_sub_menu(menu_bar, "&Devices\0", FALSE);
1371   remove_menu_items(device_menu);
1372
1373   int cnt = 0;
1374   // then set up the actual devices
1375   for (bool gotone = window->machine->m_devicelist.first(img); gotone; gotone = img->next(img))
1376   {
1377      new_item = ID_DEVICE_0 + (cnt * DEVOPTION_MAX);
1378      flags_for_exists = MF_STRING;
1379
1380      if (!img->exists())
1381         flags_for_exists |= MF_GRAYED;
1382
1383      flags_for_writing = flags_for_exists;
1384      if (!img->is_writable())
1385         flags_for_writing |= MF_GRAYED;
1386
1387      sub_menu = CreateMenu();
1388      win_append_menu_utf8(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      "Mount...");
1389
1390      if (img->image_config().is_creatable())
1391         win_append_menu_utf8(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   "Create...");
1392
1393      win_append_menu_utf8(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   "Unmount");
1394
1395      if (img->device().type() == CASSETTE)
1396      {
1397         cassette_state state;
1398         state = (cassette_state)(img->exists() ? (cassette_get_state(&img->device()) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED);
1399         win_append_menu_utf8(sub_menu, MF_SEPARATOR, 0, NULL);
1400         win_append_menu_utf8(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   "Pause/Stop");
1401         win_append_menu_utf8(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         "Play");
1402         win_append_menu_utf8(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      "Record");
1403         win_append_menu_utf8(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      "Rewind");
1404         win_append_menu_utf8(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   "Fast Forward");
1405      }
1406      s = img->exists() ? img->filename() : "[empty slot]";
1407
1408      snprintf(buf, ARRAY_LENGTH(buf), "%s: %s", img->image_config().devconfig().name(), s);
1409      win_append_menu_utf8(device_menu, MF_POPUP, (UINT_PTR)sub_menu, buf);
1410
1411      cnt++;
1412   }
1413}
1414
1415
1416
1417//============================================================
1418//  set_seped
1419//============================================================
1420
1421static void set_speed(running_machine *machine, int speed)
1422{
1423   if (speed != 0)
1424   {
1425      machine->video().set_speed_factor(speed);
1426      options_set_int(mame_options(), OPTION_SPEED, speed / 100, OPTION_PRIORITY_CMDLINE);
1427   }
1428
1429   machine->video().set_throttled(speed != 0);
1430   options_set_bool(mame_options(), OPTION_THROTTLE, (speed != 0), OPTION_PRIORITY_CMDLINE);
1431}
1432
1433
1434
1435//============================================================
1436//  win_toggle_menubar
1437//============================================================
1438
1439void win_toggle_menubar(void)
1440{
1441   win_window_info *window;
1442   LONG width_diff;
1443   LONG height_diff;
1444   DWORD style, exstyle;
1445   HWND hwnd;
1446   HMENU menu;
1447
1448   for (window = win_window_list; window != NULL; window = window->next)
1449   {
1450      RECT before_rect = { 100, 100, 200, 200 };
1451      RECT after_rect = { 100, 100, 200, 200 };
1452
1453      hwnd = window->hwnd;
1454
1455      // get current menu
1456      menu = GetMenu(hwnd);
1457
1458      // get before rect
1459      style = GetWindowLong(hwnd, GWL_STYLE);
1460      exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
1461      AdjustWindowRectEx(&before_rect, style, menu ? TRUE : FALSE, exstyle);
1462
1463      // toggle the menu
1464      if (menu)
1465      {
1466         SetProp(hwnd, TEXT("menu"), (HANDLE) menu);
1467         menu = NULL;
1468      }
1469      else
1470      {
1471         menu = (HMENU) GetProp(hwnd, TEXT("menu"));
1472      }
1473      SetMenu(hwnd, menu);
1474
1475      // get after rect, and width/height diff
1476      AdjustWindowRectEx(&after_rect, style, menu ? TRUE : FALSE, exstyle);
1477      width_diff = (after_rect.right - after_rect.left) - (before_rect.right - before_rect.left);
1478      height_diff = (after_rect.bottom - after_rect.top) - (before_rect.bottom - before_rect.top);
1479
1480      if (is_windowed())
1481      {
1482         RECT window_rect;
1483         GetWindowRect(hwnd, &window_rect);
1484         SetWindowPos(hwnd, HWND_TOP, 0, 0,
1485            window_rect.right - window_rect.left + width_diff,
1486            window_rect.bottom - window_rect.top + height_diff,
1487            SWP_NOMOVE | SWP_NOZORDER);
1488      }
1489
1490      RedrawWindow(hwnd, NULL, NULL, 0);
1491   }
1492}
1493
1494
1495
1496//============================================================
1497//  device_command
1498//============================================================
1499
1500static void device_command(HWND wnd, device_image_interface *img, int devoption)
1501{
1502   switch(devoption)
1503   {
1504      case DEVOPTION_OPEN:
1505         change_device(wnd, img, FALSE);
1506         break;
1507
1508      case DEVOPTION_CREATE:
1509         change_device(wnd, img, TRUE);
1510         break;
1511
1512      case DEVOPTION_CLOSE:
1513         img->unload();
1514         break;
1515
1516      default:
1517         if (img->device().type() == CASSETTE)
1518         {
1519            switch(devoption)
1520            {
1521               case DEVOPTION_CASSETTE_STOPPAUSE:
1522                  cassette_change_state(&img->device(), CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
1523                  break;
1524
1525               case DEVOPTION_CASSETTE_PLAY:
1526                  cassette_change_state(&img->device(), CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
1527                  break;
1528
1529               case DEVOPTION_CASSETTE_RECORD:
1530                  cassette_change_state(&img->device(), CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
1531                  break;
1532
1533               case DEVOPTION_CASSETTE_REWIND:
1534                  cassette_seek(&img->device(), -60.0, SEEK_CUR);
1535                  break;
1536
1537               case DEVOPTION_CASSETTE_FASTFORWARD:
1538                  cassette_seek(&img->device(), +60.0, SEEK_CUR);
1539                  break;
1540            }
1541         }
1542         break;
1543   }
1544}
1545
1546
1547
1548//============================================================
1549//  help_display
1550//============================================================
1551
1552static void help_display(HWND wnd, const char *chapter)
1553{
1554   typedef HWND (WINAPI *htmlhelpproc)(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD_PTR dwData);
1555   static htmlhelpproc htmlhelp;
1556   static DWORD htmlhelp_cookie;
1557   LPCSTR htmlhelp_funcname;
1558
1559   if (htmlhelp == NULL)
1560   {
1561#ifdef UNICODE
1562      htmlhelp_funcname = "HtmlHelpW";
1563#else
1564      htmlhelp_funcname = "HtmlHelpA";
1565#endif
1566      htmlhelp = (htmlhelpproc) GetProcAddress(LoadLibrary(TEXT("hhctrl.ocx")), htmlhelp_funcname);
1567      if (!htmlhelp)
1568         return;
1569      htmlhelp(NULL, NULL, 28 /*HH_INITIALIZE*/, (DWORD_PTR) &htmlhelp_cookie);
1570   }
1571
1572   // if full screen, turn it off
1573   if (!is_windowed())
1574      winwindow_toggle_full_screen();
1575
1576   {
1577      TCHAR *t_chapter = tstring_from_utf8(chapter);
1578      htmlhelp(wnd, t_chapter, 0 /*HH_DISPLAY_TOPIC*/, 0);
1579      osd_free(t_chapter);
1580   }
1581}
1582
1583
1584
1585//============================================================
1586//  help_about_mess
1587//============================================================
1588
1589static void help_about_mess(HWND wnd)
1590{
1591   help_display(wnd, "mess.chm::/windows/main.htm");
1592}
1593
1594
1595
1596//============================================================
1597//  help_about_thissystem
1598//============================================================
1599
1600static void help_about_thissystem(running_machine *machine, HWND wnd)
1601{
1602   char buf[256];
1603   snprintf(buf, ARRAY_LENGTH(buf), "mess.chm::/sysinfo/%s.htm", machine->gamedrv->name);
1604   help_display(wnd, buf);
1605}
1606
1607
1608
1609//============================================================
1610//  decode_deviceoption
1611//============================================================
1612
1613static device_image_interface *decode_deviceoption(running_machine *machine, int command, int *devoption)
1614{
1615   int absolute_index;
1616
1617   command -= ID_DEVICE_0;
1618   absolute_index = command / DEVOPTION_MAX;
1619
1620   if (devoption)
1621      *devoption = command % DEVOPTION_MAX;
1622
1623   return image_from_absolute_index(machine, absolute_index);
1624}
1625
1626
1627
1628//============================================================
1629//  set_window_orientation
1630//============================================================
1631
1632static void set_window_orientation(win_window_info *window, int orientation)
1633{
1634   window->target->set_orientation(orientation);
1635   if (window->target->is_ui_target())
1636   {
1637      render_container::user_settings settings;
1638      window->machine->render().ui_container().get_user_settings(settings);
1639      settings.m_orientation = orientation;
1640      window->machine->render().ui_container().set_user_settings(settings);
1641   }
1642   winwindow_video_window_update(window);
1643}
1644
1645
1646
1647//============================================================
1648//  pause_for_command
1649//============================================================
1650
1651static int pause_for_command(UINT command)
1652{
1653   // we really should be more conservative and only pause for commands
1654   // that do dialog stuff
1655   return (command != ID_OPTIONS_PAUSE);
1656}
1657
1658
1659
1660//============================================================
1661//  invoke_command
1662//============================================================
1663
1664static int invoke_command(HWND wnd, UINT command)
1665{
1666   int handled = 1;
1667   int dev_command;
1668   device_image_interface *img;
1669   UINT16 category;
1670   const input_field_config *field;
1671   const input_setting_config *setting;
1672   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
1673   win_window_info *window = (win_window_info *)ptr;
1674   input_field_user_settings settings;
1675
1676   // pause while invoking certain commands
1677   if (pause_for_command(command))
1678      winwindow_ui_pause_from_window_thread(window->machine, TRUE);
1679
1680   switch(command)
1681   {
1682      case ID_FILE_LOADSTATE_NEWUI:
1683         state_load(wnd, window->machine);
1684         break;
1685
1686      case ID_FILE_SAVESTATE:
1687         state_save(window->machine);
1688         break;
1689
1690      case ID_FILE_SAVESTATE_AS:
1691         state_save_as(wnd, window->machine);
1692         break;
1693
1694      case ID_FILE_SAVESCREENSHOT:
1695         window->machine->video().save_active_screen_snapshots();
1696         break;
1697
1698      case ID_FILE_EXIT_NEWUI:
1699         window->machine->schedule_exit();
1700         break;
1701
1702      case ID_EDIT_PASTE:
1703         PostMessage(wnd, WM_PASTE, 0, 0);
1704         break;
1705
1706      case ID_KEYBOARD_NATURAL:
1707         ui_set_use_natural_keyboard(window->machine, TRUE);
1708         break;
1709
1710      case ID_KEYBOARD_EMULATED:
1711         ui_set_use_natural_keyboard(window->machine, FALSE);
1712         break;
1713
1714      case ID_KEYBOARD_CUSTOMIZE:
1715         customize_keyboard(window->machine, wnd);
1716         break;
1717
1718      case ID_VIDEO_ROTATE_0:
1719         set_window_orientation(window, ROT0);
1720         break;
1721
1722      case ID_VIDEO_ROTATE_90:
1723         set_window_orientation(window, ROT90);
1724         break;
1725
1726      case ID_VIDEO_ROTATE_180:
1727         set_window_orientation(window, ROT180);
1728         break;
1729
1730      case ID_VIDEO_ROTATE_270:
1731         set_window_orientation(window, ROT270);
1732         break;
1733
1734      case ID_OPTIONS_PAUSE:
1735         pause(window->machine);
1736         break;
1737
1738      case ID_OPTIONS_HARDRESET:
1739         window->machine->schedule_hard_reset();
1740         break;
1741
1742      case ID_OPTIONS_SOFTRESET:
1743         window->machine->schedule_soft_reset();
1744         break;
1745
1746#if HAS_PROFILER
1747      case ID_OPTIONS_PROFILER:
1748         ui_set_show_profiler(!ui_get_show_profiler());
1749         break;
1750#endif // HAS_PROFILER
1751
1752      case ID_OPTIONS_DEBUGGER:
1753         debug_cpu_get_visible_cpu(window->machine)->debug()->halt_on_next_instruction("User-initiated break\n");
1754         break;
1755
1756      case ID_OPTIONS_CONFIGURATION:
1757         customize_configuration(window->machine, wnd);
1758         break;
1759
1760      case ID_OPTIONS_DIPSWITCHES:
1761         customize_dipswitches(window->machine, wnd);
1762         break;
1763
1764      case ID_OPTIONS_MISCINPUT:
1765         customize_miscinput(window->machine, wnd);
1766         break;
1767
1768      case ID_OPTIONS_ANALOGCONTROLS:
1769         customize_analogcontrols(window->machine, wnd);
1770         break;
1771
1772      case ID_OPTIONS_FULLSCREEN:
1773         winwindow_toggle_full_screen();
1774         break;
1775
1776      case ID_OPTIONS_TOGGLEFPS:
1777         ui_set_show_fps(!ui_get_show_fps());
1778         break;
1779
1780      case ID_OPTIONS_USEMOUSE:
1781         {
1782            // FIXME
1783//              extern int win_use_mouse;
1784//              win_use_mouse = !win_use_mouse;
1785         }
1786         break;
1787
1788      case ID_OPTIONS_TOGGLEMENUBAR:
1789         win_toggle_menubar();
1790         break;
1791
1792      case ID_FRAMESKIP_AUTO:
1793         window->machine->video().set_frameskip(-1);
1794         options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 1, OPTION_PRIORITY_CMDLINE);
1795         break;
1796
1797      case ID_HELP_ABOUT_NEWUI:
1798         help_about_mess(wnd);
1799         break;
1800
1801      case ID_HELP_ABOUTSYSTEM:
1802         help_about_thissystem(window->machine, wnd);
1803         break;
1804
1805      case ID_THROTTLE_50:
1806         set_speed(window->machine, 50);
1807         break;
1808
1809      case ID_THROTTLE_100:
1810         set_speed(window->machine, 100);
1811         break;
1812
1813      case ID_THROTTLE_200:
1814         set_speed(window->machine, 200);
1815         break;
1816
1817      case ID_THROTTLE_500:
1818         set_speed(window->machine, 500);
1819         break;
1820
1821      case ID_THROTTLE_1000:
1822         set_speed(window->machine, 1000);
1823         break;
1824
1825      case ID_THROTTLE_UNTHROTTLED:
1826         set_speed(window->machine, 0);
1827         break;
1828
1829      default:
1830         if ((command >= ID_FRAMESKIP_0) && (command < ID_FRAMESKIP_0 + frameskip_level_count()))
1831         {
1832            // change frameskip
1833            window->machine->video().set_frameskip(command - ID_FRAMESKIP_0);
1834            options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 0, OPTION_PRIORITY_CMDLINE);
1835            options_set_int(mame_options(), OPTION_FRAMESKIP, command - ID_FRAMESKIP_0, OPTION_PRIORITY_CMDLINE);
1836         }
1837         else if ((command >= ID_DEVICE_0) && (command < ID_DEVICE_0 + (IO_COUNT*DEVOPTION_MAX)))
1838         {
1839            // change device
1840            img = decode_deviceoption(window->machine, command, &dev_command);
1841            device_command(wnd, img, dev_command);
1842         }
1843         else if ((command >= ID_JOYSTICK_0) && (command < ID_JOYSTICK_0 + MAX_JOYSTICKS))
1844         {
1845            // customize joystick
1846            customize_joystick(window->machine, wnd, command - ID_JOYSTICK_0);
1847         }
1848         else if ((command >= ID_VIDEO_VIEW_0) && (command < ID_VIDEO_VIEW_0 + 1000))
1849         {
1850            // render views
1851            window->target->set_view(command - ID_VIDEO_VIEW_0);
1852         }
1853         else if (input_item_from_serial_number(window->machine, command - ID_INPUT_0, NULL, &field, &setting))
1854         {
1855            if ((field != NULL) && (field->type == IPT_CATEGORY) && (setting != NULL))
1856            {
1857               // change the input type for this category
1858               input_field_get_user_settings(field, &settings);
1859               settings.value = setting->value;
1860               input_field_set_user_settings(field, &settings);
1861            }
1862            else if ((field != NULL) && (field->type == IPT_CATEGORY) && (setting == NULL))
1863            {
1864               // customize the input type
1865               input_field_get_user_settings(field, &settings);
1866               category = 0;
1867
1868               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1869               {
1870                  if (settings.value == setting->value)
1871                  {
1872                     category = setting->category;
1873                  }
1874               }
1875               if (category)
1876                  customize_categorizedinput(window->machine, wnd, category);
1877            }
1878            else
1879            {
1880               // should never happen
1881               handled = 0;
1882            }
1883         }
1884         else
1885         {
1886            // bogus command
1887            handled = 0;
1888         }
1889         break;
1890   }
1891
1892   // resume emulation
1893   if (pause_for_command(command))
1894      winwindow_ui_pause_from_window_thread(window->machine, FALSE);
1895
1896   return handled;
1897}
1898
1899
1900
1901//============================================================
1902//  set_menu_text
1903//============================================================
1904
1905static void set_menu_text(HMENU menu_bar, int command, const char *text)
1906{
1907   TCHAR *t_text;
1908   MENUITEMINFO mii;
1909
1910   // convert to TCHAR
1911   t_text = tstring_from_utf8(text);
1912
1913   // invoke SetMenuItemInfo()
1914   memset(&mii, 0, sizeof(mii));
1915   mii.cbSize = sizeof(mii);
1916   mii.fMask = MIIM_TYPE;
1917   mii.dwTypeData = t_text;
1918   SetMenuItemInfo(menu_bar, command, FALSE, &mii);
1919
1920   // cleanup
1921   osd_free(t_text);
1922}
1923
1924
1925
1926//============================================================
1927//  win_setup_menus
1928//============================================================
1929
1930int win_setup_menus(running_machine *machine, HMODULE module, HMENU menu_bar)
1931{
1932   HMENU frameskip_menu;
1933   char buf[256];
1934   int i;
1935
1936   // verify that our magic numbers work
1937   assert((ID_DEVICE_0 + IO_COUNT * DEVOPTION_MAX) < ID_JOYSTICK_0);
1938
1939   // initialize critical values
1940   joystick_menu_setup = 0;
1941
1942   // remove the profiler menu item if it doesn't exist
1943#if HAS_PROFILER
1944   ui_set_show_profiler(0);
1945#else
1946   DeleteMenu(menu_bar, ID_OPTIONS_PROFILER, MF_BYCOMMAND);
1947#endif
1948
1949   if ((machine->debug_flags & DEBUG_FLAG_ENABLED) == 0)
1950      DeleteMenu(menu_bar, ID_OPTIONS_DEBUGGER, MF_BYCOMMAND);
1951
1952   // set up frameskip menu
1953   frameskip_menu = find_sub_menu(menu_bar, "&Options\0&Frameskip\0", FALSE);
1954   if (!frameskip_menu)
1955      return 1;
1956   for(i = 0; i < frameskip_level_count(); i++)
1957   {
1958      snprintf(buf, ARRAY_LENGTH(buf), "%i", i);
1959      win_append_menu_utf8(frameskip_menu, MF_STRING, ID_FRAMESKIP_0 + i, buf);
1960   }
1961
1962   // set the help menu to refer to this machine
1963   snprintf(buf, ARRAY_LENGTH(buf), "About %s (%s)...", machine->gamedrv->description, machine->gamedrv->name);
1964   set_menu_text(menu_bar, ID_HELP_ABOUTSYSTEM, buf);
1965
1966   // initialize state_filename for each driver, so we don't carry names in-between them
1967   {
1968      char *src;
1969      char *dst;
1970
1971      snprintf(state_filename, ARRAY_LENGTH(state_filename),
1972         "%s State", machine->gamedrv->description);
1973
1974      src = state_filename;
1975      dst = state_filename;
1976      do
1977      {
1978         if ((*src == '\0') || isalnum(*src) || isspace(*src) || strchr("(),.", *src))
1979            *(dst++) = *src;
1980      }
1981      while(*(src++));
1982   }
1983
1984   return 0;
1985}
1986
1987
1988
1989//============================================================
1990//  win_resource_module
1991//============================================================
1992
1993static HMODULE win_resource_module(void)
1994{
1995   static HMODULE module;
1996   if (module == NULL)
1997   {
1998      MEMORY_BASIC_INFORMATION info;
1999      if ((VirtualQuery((const void*)win_resource_module, &info, sizeof(info))) == sizeof(info))
2000         module = (HMODULE)info.AllocationBase;
2001   }
2002   return module;
2003}
2004
2005
2006
2007//============================================================
2008//  win_create_menu
2009//============================================================
2010
2011#ifdef HAS_WINDOW_MENU
2012int win_create_menu(running_machine *machine, HMENU *menus)
2013{
2014   HMENU menu_bar = NULL;
2015   HMODULE module;
2016
2017   if (options_get_bool(mame_options(), "newui"))
2018   {
2019      module = win_resource_module();
2020      menu_bar = LoadMenu(module, MAKEINTRESOURCE(IDR_RUNTIME_MENU));
2021      if (!menu_bar)
2022         goto error;
2023
2024      if (win_setup_menus(machine, module, menu_bar))
2025         goto error;
2026   }
2027
2028   *menus = menu_bar;
2029   return 0;
2030
2031error:
2032   if (menu_bar)
2033      DestroyMenu(menu_bar);
2034   return 1;
2035}
2036#endif /* HAS_WINDOW_MENU */
2037
2038
2039
2040//============================================================
2041//  win_mess_window_proc
2042//============================================================
2043
2044LRESULT CALLBACK win_mess_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam)
2045{
2046   switch(message)
2047   {
2048      case WM_INITMENU:
2049         prepare_menus(wnd);
2050         break;
2051
2052      case WM_PASTE:
2053         {
2054            LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
2055            win_window_info *window = (win_window_info *)ptr;
2056            ui_paste(window->machine);
2057         }
2058         break;
2059
2060      case WM_COMMAND:
2061         if (invoke_command(wnd, wparam))
2062            break;
2063         /* fall through */
2064
2065      default:
2066         return winwindow_video_window_proc(wnd, message, wparam, lparam);
2067   }
2068   return 0;
2069}
src/mess/osd/windows/messres.h
r10018r10019
1//{{NO_DEPENDENCIES}}
2// Microsoft Visual C++ generated include file.
3// Used by mess.rc
4//
5#define ID_FILE_LOADSTATE_NEWUI         3101
6#define ID_FILE_SAVESTATE               3102
7#define ID_FILE_SAVESTATE_AS            3103
8#define ID_FILE_SAVESCREENSHOT          3104
9#define ID_FILE_EXIT_NEWUI              3105
10#define ID_EDIT_PASTE                   3106
11#define ID_OPTIONS_HIDEMENUBAR          3107
12#define ID_OPTIONS_KEYBOARD             3108
13#define ID_OPTIONS_CONFIGURATION        3109
14#define ID_OPTIONS_DIPSWITCHES          3110
15#define ID_OPTIONS_MISCINPUT            3111
16#define ID_OPTIONS_USEMOUSE             3112
17#define ID_OPTIONS_TOGGLEMENUBAR        3113
18#define ID_OPTIONS_SOFTRESET            3114
19#define ID_OPTIONS_HARDRESET            3115
20#define ID_OPTIONS_FRAMESKIP            3116
21#define ID_OPTIONS_PAUSE                3117
22#define ID_OPTIONS_JOYSTICKS            3118
23#define ID_OPTIONS_ANALOGCONTROLS       3119
24#define ID_OPTIONS_FULLSCREEN           3120
25#define ID_OPTIONS_PROFILER             3121
26#define ID_OPTIONS_TOGGLEFPS            3122
27#define ID_OPTIONS_DEBUGGER             3123
28#define ID_KEYBOARD_EMULATED            3124
29#define ID_KEYBOARD_NATURAL             3125
30#define ID_KEYBOARD_CUSTOMIZE           3126
31#define ID_VIDEO_ROTATE_0               3127
32#define ID_VIDEO_ROTATE_90              3128
33#define ID_VIDEO_ROTATE_180             3129
34#define ID_VIDEO_ROTATE_270             3130
35#define ID_THROTTLE_50                  3131
36#define ID_THROTTLE_100                 3132
37#define ID_THROTTLE_200                 3133
38#define ID_THROTTLE_500                 3134
39#define ID_THROTTLE_1000                3135
40#define ID_THROTTLE_UNTHROTTLED         3136
41#define ID_FRAMESKIP_AUTO               3137
42#define ID_DEVICES                      3138
43#define ID_HELP_ABOUT_NEWUI             3139
44#define ID_HELP_ABOUTSYSTEM             3140
45#define IDI_ICON_CART                   3200
46#define IDI_ICON_HARD                   3201
47#define IDI_ICON_CASS                   3202
48#define IDI_ICON_FLOP                   3203
49#define IDI_ICON_PRIN                   3204
50#define IDI_ICON_SERL                   3205
51#define IDI_ICON_SNAP                   3206
52#define IDR_RUNTIME_MENU                3300
53
54// Next default values for new objects
55//
56#ifdef APSTUDIO_INVOKED
57#ifndef APSTUDIO_READONLY_SYMBOLS
58#define _APS_NEXT_RESOURCE_VALUE        3129
59#define _APS_NEXT_COMMAND_VALUE         40008
60#define _APS_NEXT_CONTROL_VALUE         3306
61#define _APS_NEXT_SYMED_VALUE           101
62#endif
63#endif
src/mess/osd/windows/opcntrl.h
r10018r10019
1//============================================================
2//
3//  opcntrl.h - Code for handling option resolutions in
4//  Win32 controls
5//
6//============================================================
7
8#ifndef OPCNTRL_H
9#define OPCNTRL_H
10
11#include <windows.h>
12#include "opresolv.h"
13
14BOOL win_prepare_option_control(HWND control, const option_guide *guide,
15   const char *optspec);
16BOOL win_check_option_control(HWND control);
17BOOL win_adjust_option_control(HWND control, int delta);
18optreserr_t win_add_resolution_parameter(HWND control, option_resolution *resolution);
19
20#endif // OPCNTRL_H
src/mess/osd/windows/menu.h
r10018r10019
1//============================================================
2//
3//  menu.h - Win32 MESS menu handling
4//
5//============================================================
6
7#ifndef MENU_H
8#define MENU_H
9
10#include <windows.h>
11
12
13
14//============================================================
15//  PROTOTYPES
16//============================================================
17
18int win_setup_menus(running_machine *machine, HMODULE module, HMENU menu_bar);
19LRESULT CALLBACK win_mess_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
20void win_toggle_menubar(void);
21#ifdef HAS_WINDOW_MENU
22int win_create_menu(running_machine *machine, HMENU *menus);
23#endif
24
25
26#endif /* MENU_H */
src/mess/osd/windows/mess.rc
r10018r10019
1// Microsoft Visual C++ generated resource script.
2//
3#include "messres.h"
4
5#define APSTUDIO_READONLY_SYMBOLS
6/////////////////////////////////////////////////////////////////////////////
7//
8// Generated from the TEXTINCLUDE 2 resource.
9//
10#include <windows.h>
11/////////////////////////////////////////////////////////////////////////////
12#undef APSTUDIO_READONLY_SYMBOLS
13
14/////////////////////////////////////////////////////////////////////////////
15// English (U.S.) resources
16
17#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
18#ifdef _WIN32
19LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
20#pragma code_page(1252)
21#endif //_WIN32
22
23/////////////////////////////////////////////////////////////////////////////
24//
25// Menu
26//
27
28IDR_RUNTIME_MENU MENU
29BEGIN
30    POPUP "&File"
31    BEGIN
32        MENUITEM "&Load State...",              ID_FILE_LOADSTATE_NEWUI
33        MENUITEM "&Save State",                 ID_FILE_SAVESTATE
34        MENUITEM "S&ave State As...",           ID_FILE_SAVESTATE_AS
35        MENUITEM SEPARATOR
36        MENUITEM "Save Sc&reenshot",            ID_FILE_SAVESCREENSHOT
37        MENUITEM SEPARATOR
38        MENUITEM "&Exit",                       ID_FILE_EXIT_NEWUI
39    END
40    POPUP "&Edit"
41    BEGIN
42        MENUITEM "Paste",                       ID_EDIT_PASTE
43    END
44    POPUP "&Options"
45    BEGIN
46        MENUITEM "&Pause",                      ID_OPTIONS_PAUSE, GRAYED
47        MENUITEM "Soft &Reset",                 ID_OPTIONS_SOFTRESET
48        MENUITEM "Ha&rd Reset",                 ID_OPTIONS_HARDRESET
49        MENUITEM SEPARATOR
50        POPUP "&Keyboard"
51        BEGIN
52            MENUITEM "Emulated",                    ID_KEYBOARD_EMULATED
53            MENUITEM "Natural",                     ID_KEYBOARD_NATURAL
54            MENUITEM SEPARATOR
55            MENUITEM "Customize Emulated Keyboard...",     ID_KEYBOARD_CUSTOMIZE
56        END
57        MENUITEM "&Joysticks",                  ID_OPTIONS_JOYSTICKS, GRAYED
58        POPUP "&Video"
59        BEGIN
60          MENUITEM SEPARATOR
61          MENUITEM "Rotate 0 degrees",        ID_VIDEO_ROTATE_0
62          MENUITEM "Rotate 90 degrees",       ID_VIDEO_ROTATE_90
63          MENUITEM "Rotate 180 degrees",      ID_VIDEO_ROTATE_180
64          MENUITEM "Rotate 270 degrees",      ID_VIDEO_ROTATE_270
65        END
66        MENUITEM "&Configuration...",           ID_OPTIONS_CONFIGURATION
67        MENUITEM "&DIP Switches...",            ID_OPTIONS_DIPSWITCHES
68        MENUITEM "&Miscellaneous Inputs...",    ID_OPTIONS_MISCINPUT
69        MENUITEM "&Analog Controls...",         ID_OPTIONS_ANALOGCONTROLS
70        MENUITEM SEPARATOR
71        POPUP "&Frameskip"
72        BEGIN
73            MENUITEM "Auto",                        ID_FRAMESKIP_AUTO
74        END
75        POPUP "Maximum &Speed"
76        BEGIN
77            MENUITEM "50%",                         ID_THROTTLE_50
78            MENUITEM "100%",                        ID_THROTTLE_100
79            MENUITEM "200%",                        ID_THROTTLE_200
80            MENUITEM "500%",                        ID_THROTTLE_500
81            MENUITEM "1000%",                       ID_THROTTLE_1000
82            MENUITEM "Unlimited",                   ID_THROTTLE_UNTHROTTLED
83        END
84        MENUITEM "Show &FPS",                   ID_OPTIONS_TOGGLEFPS
85        MENUITEM SEPARATOR
86        MENUITEM "&Hide Menubar",             ID_OPTIONS_TOGGLEMENUBAR
87        MENUITEM "&Full Screen",             ID_OPTIONS_FULLSCREEN
88        MENUITEM "Show P&rofiler",              ID_OPTIONS_PROFILER, GRAYED
89        MENUITEM "&Debugger...",                ID_OPTIONS_DEBUGGER
90    END
91    POPUP "&Devices"
92    BEGIN
93        MENUITEM SEPARATOR
94    END
95    POPUP "&Help"
96    BEGIN
97        MENUITEM "About This System...",        ID_HELP_ABOUTSYSTEM
98        MENUITEM "&About MESS...",              ID_HELP_ABOUT_NEWUI
99    END
100END
101
102
103#ifdef APSTUDIO_INVOKED
104/////////////////////////////////////////////////////////////////////////////
105//
106// TEXTINCLUDE
107//
108
1091 TEXTINCLUDE
110BEGIN
111    "messres.h\0"
112END
113
1142 TEXTINCLUDE
115BEGIN
116    "#include <windows.h>\0"
117END
118
1193 TEXTINCLUDE
120BEGIN
121    "\r\n"
122    "\0"
123END
124
125#endif    // APSTUDIO_INVOKED
126
127
128
129/////////////////////////////////////////////////////////////////////////////
130//
131// DESIGNINFO
132//
133
134IDI_ICON_MESS           ICON    DISCARDABLE     "../../osd/winui/res/mess.ico"
135
136
137
138/////////////////////////////////////////////////////////////////////////////
139//
140// DESIGNINFO
141//
142
143#ifdef APSTUDIO_INVOKED
144GUIDELINES DESIGNINFO
145BEGIN
146    IDD_TAPEDIALOG, DIALOG
147    BEGIN
148        LEFTMARGIN, 7
149        RIGHTMARGIN, 165
150        TOPMARGIN, 7
151        BOTTOMMARGIN, 58
152    END
153END
154#endif    // APSTUDIO_INVOKED
155
156#endif    // English (U.S.) resources
157/////////////////////////////////////////////////////////////////////////////
158
159
160
161#ifndef APSTUDIO_INVOKED
162/////////////////////////////////////////////////////////////////////////////
163//
164// Generated from the TEXTINCLUDE 3 resource.
165//
166
167
168/////////////////////////////////////////////////////////////////////////////
169#endif    // not APSTUDIO_INVOKED
170
src/mess/osd/windows/mess.ico
src/mess/osd/windows/windows.mak
r10018r10019
66#
77###########################################################################
88
9ifndef MESSUI
10MESSUI = 1
11endif
9MESS_WINSRC = src/mess/osd/windows
10MESS_WINOBJ = $(OBJ)/mess/osd/windows
1211
13# build the executable names
14RCFLAGS += -DMESS
15
16LIBS += -lcomdlg32
17
1812OBJDIRS += \
1913   $(MESSOBJ)/osd \
2014   $(MESSOBJ)/osd/windows
21
22MESS_WINSRC = src/mess/osd/windows
23MESS_WINOBJ = $(OBJ)/mess/osd/windows
24
15   
2516RESFILE = $(MESS_WINOBJ)/mess.res
2617
27OSDOBJS += \
28   $(MESS_WINOBJ)/dialog.o   \
29   $(MESS_WINOBJ)/menu.o      \
30   $(MESS_WINOBJ)/mess.res   \
31   $(MESS_WINOBJ)/opcntrl.o
32
3318$(LIBOSD): $(OSDOBJS)
3419
35OSDCOREOBJS += \
36   $(OBJ)/mess/osd/windows/winutils.o
37
3820$(LIBOCORE): $(OSDCOREOBJS)
3921
4022$(LIBOCORE_NOMAIN): $(OSDCOREOBJS:$(WINOBJ)/main.o=)
4123
24$(RESFILE): $(MESS_WINSRC)/mess.rc $(WINOBJ)/mamevers.rc
25
4226#-------------------------------------------------
4327# generic rules for the resource compiler
4428#-------------------------------------------------
r10018r10019
4630$(MESS_WINOBJ)/%.res: $(MESS_WINSRC)/%.rc
4731   @echo Compiling resources $<...
4832   $(RC) $(RCDEFS) $(RCFLAGS) --include-dir mess/$(OSD) -o $@ -i $<
49
50#-------------------------------------------------
51# For building UI include ui.mak
52#-------------------------------------------------
53ifneq ($(MESSUI),0)
54include $(SRC)/mess/osd/winui/winui.mak
55endif
No newline at end of file
src/mess/osd/winui/dialog.c
r0r10019
1//============================================================
2//
3//  dialog.c - Win32 MESS dialog handling
4//
5//============================================================
6
7#define WIN32_LEAN_AND_MEAN
8#include <windows.h>
9#include <tchar.h>
10#include <commctrl.h>
11#include <commdlg.h>
12
13#include "dialog.h"
14#include "emu.h"
15#include "strconv.h"
16#include "pool.h"
17#include "winutil.h"
18#include "winutils.h"
19#include "windows/input.h"
20#include "windows/window.h"
21#include "winutf8.h"
22
23//============================================================
24
25#define SEQWM_SETFOCUS   (WM_APP + 0)
26#define SEQWM_KILLFOCUS   (WM_APP + 1)
27
28enum
29{
30   TRIGGER_INITDIALOG   = 1,
31   TRIGGER_APPLY      = 2,
32   TRIGGER_CHANGED      = 4
33};
34
35typedef LRESULT (*trigger_function)(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam);
36
37struct dialog_info_trigger
38{
39   struct dialog_info_trigger *next;
40   WORD dialog_item;
41   WORD trigger_flags;
42   UINT message;
43   WPARAM wparam;
44   LPARAM lparam;
45   void (*storeval)(void *param, int val);
46   void *storeval_param;
47   trigger_function trigger_proc;
48};
49
50struct dialog_object_pool
51{
52   HGDIOBJ objects[16];
53};
54
55struct _dialog_box
56{
57   HGLOBAL handle;
58   size_t handle_size;
59   struct dialog_info_trigger *trigger_first;
60   struct dialog_info_trigger *trigger_last;
61   WORD item_count;
62   WORD size_x, size_y;
63   WORD pos_x, pos_y;
64   WORD cursize_x, cursize_y;
65   WORD home_y;
66   DWORD style;
67   int combo_string_count;
68   int combo_default_value;
69   object_pool *mempool;
70   struct dialog_object_pool *objpool;
71   const struct dialog_layout *layout;
72
73   // singular notification callback; hack
74   UINT notify_code;
75   dialog_notification notify_callback;
76   void *notify_param;
77};
78
79enum _seqselect_state
80{
81   SEQSELECT_STATE_NOT_POLLING,
82   SEQSELECT_STATE_POLLING,
83   SEQSELECT_STATE_POLLING_COMPLETE
84};
85typedef enum _seqselect_state seqselect_state;
86
87// this is the structure that gets associated with each input_seq edit box
88typedef struct _seqselect_info seqselect_info;
89struct _seqselect_info
90{
91   WNDPROC oldwndproc;
92   const input_field_config *field;      // pointer to the field
93   input_field_user_settings settings;      // the new settings
94   input_seq *code;                  // the input_seq within settings
95   WORD pos;
96   BOOL is_analog;
97   seqselect_state poll_state;
98};
99
100
101
102//============================================================
103//  PARAMETERS
104//============================================================
105
106#define DIM_VERTICAL_SPACING   3
107#define DIM_HORIZONTAL_SPACING   5
108#define DIM_NORMAL_ROW_HEIGHT   10
109#define DIM_COMBO_ROW_HEIGHT   12
110#define DIM_SLIDER_ROW_HEIGHT   18
111#define DIM_BUTTON_ROW_HEIGHT   12
112#define DIM_EDIT_WIDTH         120
113#define DIM_BUTTON_WIDTH      50
114#define DIM_ADJUSTER_SCR_WIDTH   12
115#define DIM_ADJUSTER_HEIGHT      12
116#define DIM_SCROLLBAR_WIDTH      10
117#define DIM_BOX_VERTSKEW      -3
118
119#define DLGITEM_BUTTON         ((const WCHAR *) dlgitem_button)
120#define DLGITEM_EDIT         ((const WCHAR *) dlgitem_edit)
121#define DLGITEM_STATIC         ((const WCHAR *) dlgitem_static)
122#define DLGITEM_LISTBOX         ((const WCHAR *) dlgitem_listbox)
123#define DLGITEM_SCROLLBAR      ((const WCHAR *) dlgitem_scrollbar)
124#define DLGITEM_COMBOBOX      ((const WCHAR *) dlgitem_combobox)
125
126#define DLGTEXT_OK            "OK"
127#define DLGTEXT_APPLY         "Apply"
128#define DLGTEXT_CANCEL         "Cancel"
129
130#define FONT_SIZE            8
131#define FONT_FACE            L"Arial"
132
133#define SCROLL_DELTA_LINE      10
134#define SCROLL_DELTA_PAGE      100
135
136#define LOG_WINMSGS            0
137#define DIALOG_STYLE         WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT
138#define MAX_DIALOG_HEIGHT      200
139
140
141
142//============================================================
143//  LOCAL VARIABLES
144//============================================================
145
146static running_machine *Machine;   // HACK - please fix
147
148static double pixels_to_xdlgunits;
149static double pixels_to_ydlgunits;
150
151static const struct dialog_layout default_layout = { 80, 140 };
152static const WORD dlgitem_button[] =   { 0xFFFF, 0x0080 };
153static const WORD dlgitem_edit[] =      { 0xFFFF, 0x0081 };
154static const WORD dlgitem_static[] =   { 0xFFFF, 0x0082 };
155static const WORD dlgitem_listbox[] =   { 0xFFFF, 0x0083 };
156static const WORD dlgitem_scrollbar[] =   { 0xFFFF, 0x0084 };
157static const WORD dlgitem_combobox[] =   { 0xFFFF, 0x0085 };
158
159
160//============================================================
161//  PROTOTYPES
162//============================================================
163
164static void dialog_prime(dialog_box *di);
165static int dialog_write_item(dialog_box *di, DWORD style, short x, short y,
166    short width, short height, const char *str, const WCHAR *class_name, WORD *id);
167
168
169
170//============================================================
171//  call_windowproc
172//============================================================
173
174static LRESULT call_windowproc(WNDPROC wndproc, HWND hwnd, UINT msg,
175   WPARAM wparam, LPARAM lparam)
176{
177   LRESULT rc;
178   if (IsWindowUnicode(hwnd))
179      rc = CallWindowProcW(wndproc, hwnd, msg, wparam, lparam);
180   else
181      rc = CallWindowProcA(wndproc, hwnd, msg, wparam, lparam);
182   return rc;
183}
184
185
186
187//============================================================
188//  compute_dlgunits_multiple
189//============================================================
190
191static void calc_dlgunits_multiple(void)
192{
193   dialog_box *dialog = NULL;
194   short offset_x = 2048;
195   short offset_y = 2048;
196   const char *wnd_title = "Foo";
197   WORD id;
198   HWND dlg_window = NULL;
199   HWND child_window;
200   RECT r;
201
202   if ((pixels_to_xdlgunits == 0) || (pixels_to_ydlgunits == 0))
203   {
204      // create a bogus dialog
205      dialog = win_dialog_init(NULL, NULL);
206      if (!dialog)
207         goto done;
208
209      if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
210            0, 0, offset_x, offset_y, wnd_title, DLGITEM_STATIC, &id))
211         goto done;
212
213      dialog_prime(dialog);
214      dlg_window = CreateDialogIndirectParam(NULL, (const DLGTEMPLATE*)dialog->handle, NULL, NULL, 0);
215      child_window = GetDlgItem(dlg_window, id);
216
217      GetWindowRect(child_window, &r);
218      pixels_to_xdlgunits = (double)(r.right - r.left) / offset_x;
219      pixels_to_ydlgunits = (double)(r.bottom - r.top) / offset_y;
220
221done:
222      if (dialog)
223         win_dialog_exit(dialog);
224      if (dlg_window)
225         DestroyWindow(dlg_window);
226   }
227}
228
229
230
231//============================================================
232//  dialog_trigger
233//============================================================
234
235static void dialog_trigger(HWND dlgwnd, WORD trigger_flags)
236{
237   LRESULT result;
238   HWND dialog_item;
239   struct _dialog_box *di;
240   struct dialog_info_trigger *trigger;
241   LONG_PTR l;
242
243   l = GetWindowLongPtr(dlgwnd, GWLP_USERDATA);
244   di = (struct _dialog_box *) l;
245   assert(di);
246   for (trigger = di->trigger_first; trigger; trigger = trigger->next)
247   {
248      if (trigger->trigger_flags & trigger_flags)
249      {
250         if (trigger->dialog_item)
251            dialog_item = GetDlgItem(dlgwnd, trigger->dialog_item);
252         else
253            dialog_item = dlgwnd;
254         assert(dialog_item);
255         result = 0;
256
257         if (trigger->message)
258            result = SendMessage(dialog_item, trigger->message, trigger->wparam, trigger->lparam);
259         if (trigger->trigger_proc)
260            result = trigger->trigger_proc(di, dialog_item, trigger->message, trigger->wparam, trigger->lparam);
261
262         if (trigger->storeval)
263            trigger->storeval(trigger->storeval_param, result);
264      }
265   }
266}
267
268//============================================================
269//  dialog_proc
270//============================================================
271
272static INT_PTR CALLBACK dialog_proc(HWND dlgwnd, UINT msg, WPARAM wparam, LPARAM lparam)
273{
274   INT_PTR handled = TRUE;
275   CHAR buf[32];
276   WORD command;
277
278   if (LOG_WINMSGS)
279   {
280      logerror("dialog_proc(): dlgwnd=%p msg=0x%08x wparam=0x%08x lparam=0x%08x\n",
281         dlgwnd, (unsigned int) msg, (unsigned int) wparam, (unsigned int) lparam);
282   }
283
284   switch(msg)
285   {
286      case WM_INITDIALOG:
287         SetWindowLongPtr(dlgwnd, GWLP_USERDATA, (LONG_PTR) lparam);
288         dialog_trigger(dlgwnd, TRIGGER_INITDIALOG);
289         break;
290
291      case WM_COMMAND:
292         command = LOWORD(wparam);
293
294         win_get_window_text_utf8((HWND) lparam, buf, ARRAY_LENGTH(buf));
295         if (!strcmp(buf, DLGTEXT_OK))
296            command = IDOK;
297         else if (!strcmp(buf, DLGTEXT_CANCEL))
298            command = IDCANCEL;
299         else
300            command = 0;
301
302         switch(command)
303         {
304            case IDOK:
305               dialog_trigger(dlgwnd, TRIGGER_APPLY);
306               // fall through
307
308            case IDCANCEL:
309               EndDialog(dlgwnd, 0);
310               break;
311
312            default:
313               handled = FALSE;
314               break;
315         }
316         break;
317
318      case WM_SYSCOMMAND:
319         if (wparam == SC_CLOSE)
320         {
321            EndDialog(dlgwnd, 0);
322         }
323         else
324         {
325            handled = FALSE;
326         }
327         break;
328
329      case WM_VSCROLL:
330         if (lparam)
331         {
332            // this scroll message came from an actual scroll bar window;
333            // pass it on
334            SendMessage((HWND) lparam, msg, wparam, lparam);
335         }
336         else
337         {
338            // scroll the dialog
339            win_scroll_window(dlgwnd, wparam, SB_VERT, SCROLL_DELTA_LINE);
340         }
341         break;
342
343      default:
344         handled = FALSE;
345         break;
346   }
347   return handled;
348}
349
350
351
352//============================================================
353//  dialog_write
354//============================================================
355
356static int dialog_write(struct _dialog_box *di, const void *ptr, size_t sz, int align)
357{
358   HGLOBAL newhandle;
359   size_t base;
360   UINT8 *mem;
361   UINT8 *mem2;
362
363   if (!di->handle)
364   {
365      newhandle = GlobalAlloc(GMEM_ZEROINIT, sz);
366      base = 0;
367   }
368   else
369   {
370      base = di->handle_size;
371      base += align - 1;
372      base -= base % align;
373      newhandle = GlobalReAlloc(di->handle, base + sz, GMEM_ZEROINIT);
374      if (!newhandle)
375      {
376         newhandle = GlobalAlloc(GMEM_ZEROINIT, base + sz);
377         if (newhandle)
378         {
379            mem = (UINT8*)GlobalLock(di->handle);
380            mem2 = (UINT8*)GlobalLock(newhandle);
381            memcpy(mem2, mem, base);
382            GlobalUnlock(di->handle);
383            GlobalUnlock(newhandle);
384            GlobalFree(di->handle);
385         }
386      }
387   }
388   if (!newhandle)
389      return 1;
390
391   mem = (UINT8*)GlobalLock(newhandle);
392   memcpy(mem + base, ptr, sz);
393   GlobalUnlock(newhandle);
394   di->handle = newhandle;
395   di->handle_size = base + sz;
396   return 0;
397}
398
399
400//============================================================
401//  dialog_write_string
402//============================================================
403
404static int dialog_write_string(dialog_box *di, const WCHAR *str)
405{
406   if (!str)
407      str = L"";
408   return dialog_write(di, str, (wcslen(str) + 1) * sizeof(WCHAR), 2);
409}
410
411
412
413//============================================================
414//  dialog_write_item
415//============================================================
416
417static int dialog_write_item(dialog_box *di, DWORD style, short x, short y,
418    short width, short height, const char *str, const WCHAR *class_name, WORD *id)
419{
420   DLGITEMTEMPLATE item_template;
421   UINT class_name_length;
422   WORD w;
423   WCHAR *w_str;
424   int rc;
425
426   memset(&item_template, 0, sizeof(item_template));
427   item_template.style = style;
428   item_template.x = x;
429   item_template.y = y;
430   item_template.cx = width;
431   item_template.cy = height;
432   item_template.id = di->item_count + 1;
433
434   if (dialog_write(di, &item_template, sizeof(item_template), 4))
435      return 1;
436
437   if (*class_name == 0xffff)
438      class_name_length = 4;
439   else
440      class_name_length = (wcslen(class_name) + 1) * sizeof(WCHAR);
441   if (dialog_write(di, class_name, class_name_length, 2))
442      return 1;
443
444   w_str = str ? wstring_from_utf8(str) : NULL;
445   rc = dialog_write_string(di, w_str);
446   if (w_str)
447      osd_free(w_str);
448   if (rc)
449      return 1;
450
451   w = 0;
452   if (dialog_write(di, &w, sizeof(w), 2))
453      return 1;
454
455   di->item_count++;
456
457   if (id)
458      *id = di->item_count;
459   return 0;
460}
461
462
463
464//============================================================
465//  dialog_add_trigger
466//============================================================
467
468static int dialog_add_trigger(struct _dialog_box *di, WORD dialog_item,
469   WORD trigger_flags, UINT message, trigger_function trigger_proc,
470   WPARAM wparam, LPARAM lparam,
471   void (*storeval)(void *param, int val), void *storeval_param)
472{
473   struct dialog_info_trigger *trigger;
474
475   assert(di);
476   assert(trigger_flags);
477
478   trigger = (struct dialog_info_trigger *) pool_malloc_lib(di->mempool, sizeof(struct dialog_info_trigger));
479   if (!trigger)
480      return 1;
481
482   trigger->next = NULL;
483   trigger->trigger_flags = trigger_flags;
484   trigger->dialog_item = dialog_item;
485   trigger->message = message;
486   trigger->trigger_proc = trigger_proc;
487   trigger->wparam = wparam;
488   trigger->lparam = lparam;
489   trigger->storeval = storeval;
490   trigger->storeval_param = storeval_param;
491
492   if (di->trigger_last)
493      di->trigger_last->next = trigger;
494   else
495      di->trigger_first = trigger;
496   di->trigger_last = trigger;
497   return 0;
498}
499
500//============================================================
501//  dialog_add_object
502//============================================================
503
504static int dialog_add_object(dialog_box *di, HGDIOBJ obj)
505{
506   int i;
507   struct dialog_object_pool *objpool;
508
509   objpool = di->objpool;
510
511   if (!di->objpool)
512   {
513      objpool = (dialog_object_pool*)pool_malloc_lib(di->mempool, sizeof(struct dialog_object_pool));
514      if (!objpool)
515         return 1;
516      memset(objpool, 0, sizeof(struct dialog_object_pool));
517      di->objpool = objpool;
518   }
519
520
521   for (i = 0; i < ARRAY_LENGTH(objpool->objects); i++)
522   {
523      if (!objpool->objects[i])
524         break;
525   }
526   if (i >= ARRAY_LENGTH(objpool->objects))
527      return 1;
528
529   objpool->objects[i] = obj;
530   return 0;
531}
532
533
534
535//============================================================
536//  dialog_scrollbar_init
537//============================================================
538
539static LRESULT dialog_scrollbar_init(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam)
540{
541   SCROLLINFO si;
542
543   calc_dlgunits_multiple();
544
545   memset(&si, 0, sizeof(si));
546   si.cbSize = sizeof(si);
547   si.nMin  = pixels_to_ydlgunits * 0;
548   si.nMax  = pixels_to_ydlgunits * dialog->size_y;
549   si.nPage = pixels_to_ydlgunits * MAX_DIALOG_HEIGHT;
550   si.fMask = SIF_PAGE | SIF_RANGE;
551
552   SetScrollInfo(dlgwnd, SB_VERT, &si, TRUE);
553   return 0;
554}
555
556
557
558//============================================================
559//  dialog_add_scrollbar
560//============================================================
561
562static int dialog_add_scrollbar(dialog_box *dialog)
563{
564   if (dialog_add_trigger(dialog, 0, TRIGGER_INITDIALOG, 0, dialog_scrollbar_init, 0, 0, NULL, NULL))
565      return 1;
566
567   dialog->style |= WS_VSCROLL;
568   return 0;
569}
570
571
572
573//============================================================
574//  dialog_prime
575//============================================================
576
577static void dialog_prime(dialog_box *di)
578{
579   DLGTEMPLATE *dlg_template;
580
581   if (di->size_y > MAX_DIALOG_HEIGHT)
582   {
583      di->size_x += DIM_SCROLLBAR_WIDTH;
584      dialog_add_scrollbar(di);
585   }
586
587   dlg_template = (DLGTEMPLATE *) GlobalLock(di->handle);
588   dlg_template->cdit = di->item_count;
589   dlg_template->cx = di->size_x;
590   dlg_template->cy = (di->size_y > MAX_DIALOG_HEIGHT) ? MAX_DIALOG_HEIGHT : di->size_y;
591   dlg_template->style = di->style;
592   GlobalUnlock(di->handle);
593}
594
595
596
597//============================================================
598//  dialog_get_combo_value
599//============================================================
600
601static LRESULT dialog_get_combo_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
602{
603   int idx;
604   idx = SendMessage(dialog_item, CB_GETCURSEL, 0, 0);
605   if (idx == CB_ERR)
606      return 0;
607   return SendMessage(dialog_item, CB_GETITEMDATA, idx, 0);
608}
609
610
611
612//============================================================
613//  dialog_get_adjuster_value
614//============================================================
615
616static LRESULT dialog_get_adjuster_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
617{
618   TCHAR buf[32];
619   GetWindowText(dialog_item, buf, ARRAY_LENGTH(buf));
620   return _ttoi(buf);
621}
622
623
624
625//============================================================
626//  dialog_get_slider_value
627//============================================================
628
629static LRESULT dialog_get_slider_value(dialog_box *dialog, HWND dialog_item, UINT message, WPARAM wparam, LPARAM lparam)
630{
631   return SendMessage(dialog_item, TBM_GETPOS, 0, 0);
632}
633
634
635
636//============================================================
637//  win_dialog_init
638//============================================================
639
640dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layout)
641{
642   struct _dialog_box *di;
643   DLGTEMPLATE dlg_template;
644   WORD w[2];
645   WCHAR *w_title;
646   int rc;
647
648   // use default layout if not specified
649   if (!layout)
650      layout = &default_layout;
651
652   // create the dialog structure
653   di = (_dialog_box *)malloc(sizeof(struct _dialog_box));
654   if (!di)
655      goto error;
656   memset(di, 0, sizeof(*di));
657
658   di->layout = layout;
659   di->mempool = pool_alloc_lib(NULL);
660
661   memset(&dlg_template, 0, sizeof(dlg_template));
662   dlg_template.style = di->style = DIALOG_STYLE;
663   dlg_template.x = 10;
664   dlg_template.y = 10;
665   if (dialog_write(di, &dlg_template, sizeof(dlg_template), 4))
666      goto error;
667
668   w[0] = 0;
669   w[1] = 0;
670   if (dialog_write(di, w, sizeof(w), 2))
671      goto error;
672
673   w_title = wstring_from_utf8(title);
674   rc = dialog_write_string(di, w_title);
675   osd_free(w_title);
676   if (rc)
677      goto error;
678
679   // set the font, if necessary
680   if (di->style & DS_SETFONT)
681   {
682      w[0] = FONT_SIZE;
683      if (dialog_write(di, w, sizeof(w[0]), 2))
684         goto error;
685      if (dialog_write_string(di, FONT_FACE))
686         goto error;
687   }
688
689   return di;
690
691error:
692   if (di)
693      win_dialog_exit(di);
694   return NULL;
695}
696
697
698
699//============================================================
700//  dialog_new_control
701//============================================================
702
703static void dialog_new_control(struct _dialog_box *di, short *x, short *y)
704{
705   *x = di->pos_x + DIM_HORIZONTAL_SPACING;
706   *y = di->pos_y + DIM_VERTICAL_SPACING;
707}
708
709
710
711//============================================================
712//  dialog_finish_control
713//============================================================
714
715static void dialog_finish_control(struct _dialog_box *di, short x, short y)
716{
717   di->pos_y = y;
718
719   // update dialog size
720   if (x > di->size_x)
721      di->size_x = x;
722   if (y > di->size_y)
723      di->size_y = y;
724   if (x > di->cursize_x)
725      di->cursize_x = x;
726   if (y > di->cursize_y)
727      di->cursize_y = y;
728}
729
730
731
732//============================================================
733//  dialog_combo_changed
734//============================================================
735
736static LRESULT dialog_combo_changed(dialog_box *dialog, HWND dlgitem, UINT message, WPARAM wparam, LPARAM lparam)
737{
738   dialog_itemchangedproc changed = (dialog_itemchangedproc) wparam;
739   changed(dialog, dlgitem, (void *) lparam);
740   return 0;
741}
742
743
744
745//============================================================
746//  win_dialog_add_active_combobox
747//============================================================
748
749int win_dialog_add_active_combobox(dialog_box *dialog, const char *item_label, int default_value,
750   dialog_itemstoreval storeval, void *storeval_param,
751   dialog_itemchangedproc changed, void *changed_param)
752{
753   int rc = 1;
754   short x;
755   short y;
756
757   dialog_new_control(dialog, &x, &y);
758
759   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
760         x, y, dialog->layout->label_width, DIM_COMBO_ROW_HEIGHT, item_label, DLGITEM_STATIC, NULL))
761      goto done;
762
763   y += DIM_BOX_VERTSKEW;
764
765   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
766   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | CBS_DROPDOWNLIST,
767         x, y, dialog->layout->combo_width, DIM_COMBO_ROW_HEIGHT * 8, NULL, DLGITEM_COMBOBOX, NULL))
768      goto done;
769   dialog->combo_string_count = 0;
770   dialog->combo_default_value = default_value;
771
772   // add the trigger invoked when the apply button is pressed
773   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_combo_value, 0, 0, storeval, storeval_param))
774      goto done;
775
776   // if appropriate, add the optional changed trigger
777   if (changed)
778   {
779      if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG | TRIGGER_CHANGED, 0, dialog_combo_changed, (WPARAM) changed, (LPARAM) changed_param, NULL, NULL))
780         goto done;
781   }
782
783   x += dialog->layout->combo_width + DIM_HORIZONTAL_SPACING;
784   y += DIM_COMBO_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
785
786   dialog_finish_control(dialog, x, y);
787   rc = 0;
788
789done:
790   return rc;
791}
792
793
794
795//============================================================
796//  win_dialog_add_combobox
797//============================================================
798
799int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value,
800   void (*storeval)(void *param, int val), void *storeval_param)
801{
802   return win_dialog_add_active_combobox(dialog, item_label, default_value,
803      storeval, storeval_param, NULL, NULL);
804}
805
806
807
808//============================================================
809//  win_dialog_add_combobox_item
810//============================================================
811
812int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_label, int item_data)
813{
814   TCHAR* t_item_label = NULL;
815   // create our own copy of the string
816   if (item_label)
817   {
818      TCHAR* t_tmp = tstring_from_utf8(item_label);
819      if( !t_tmp )
820         return 1;
821      t_item_label = win_dialog_tcsdup(dialog, t_tmp);
822      osd_free(t_tmp);
823      if (!t_item_label)
824         return 1;
825   }
826
827   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_ADDSTRING, NULL, 0, (LPARAM) t_item_label, NULL, NULL))
828      return 1;
829   dialog->combo_string_count++;
830   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_SETITEMDATA, NULL, dialog->combo_string_count-1, (LPARAM) item_data, NULL, NULL))
831      return 1;
832   if (item_data == dialog->combo_default_value)
833   {
834      if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, CB_SETCURSEL, NULL, dialog->combo_string_count-1, 0, NULL, NULL))
835         return 1;
836   }
837   return 0;
838}
839
840
841
842//============================================================
843//  adjuster_sb_wndproc
844//============================================================
845
846struct adjuster_sb_stuff
847{
848   WNDPROC oldwndproc;
849   int min_value;
850   int max_value;
851};
852
853static INT_PTR CALLBACK adjuster_sb_wndproc(HWND sbwnd, UINT msg, WPARAM wparam, LPARAM lparam)
854{
855   INT_PTR result;
856   struct adjuster_sb_stuff *stuff;
857   char buf[64];
858   HWND dlgwnd, editwnd;
859   int value, id;
860   LONG_PTR l;
861
862   l = GetWindowLongPtr(sbwnd, GWLP_USERDATA);
863   stuff = (struct adjuster_sb_stuff *) l;
864
865   if (msg == WM_VSCROLL)
866   {
867      id = GetWindowLong(sbwnd, GWL_ID);
868      dlgwnd = GetParent(sbwnd);
869      editwnd = GetDlgItem(dlgwnd, id - 1);
870      win_get_window_text_utf8(editwnd, buf, ARRAY_LENGTH(buf));
871      value = atoi(buf);
872
873      switch(wparam)
874      {
875         case SB_LINEDOWN:
876         case SB_PAGEDOWN:
877            value--;
878            break;
879
880         case SB_LINEUP:
881         case SB_PAGEUP:
882            value++;
883            break;
884      }
885
886      if (value < stuff->min_value)
887         value = stuff->min_value;
888      else if (value > stuff->max_value)
889         value = stuff->max_value;
890      _snprintf(buf, ARRAY_LENGTH(buf), "%d", value);
891      win_set_window_text_utf8(editwnd, buf);
892      result = 0;
893   }
894   else
895   {
896      result = call_windowproc(stuff->oldwndproc, sbwnd, msg, wparam, lparam);
897   }
898   return result;
899}
900
901
902
903//============================================================
904//  adjuster_sb_setup
905//============================================================
906
907static LRESULT adjuster_sb_setup(dialog_box *dialog, HWND sbwnd, UINT message, WPARAM wparam, LPARAM lparam)
908{
909   struct adjuster_sb_stuff *stuff;
910   LONG_PTR l;
911
912   stuff = (struct adjuster_sb_stuff *) win_dialog_malloc(dialog, sizeof(struct adjuster_sb_stuff));
913   if (!stuff)
914      return 1;
915   stuff->min_value = (WORD) (lparam >> 0);
916   stuff->max_value = (WORD) (lparam >> 16);
917
918   l = (LONG_PTR) stuff;
919   SetWindowLongPtr(sbwnd, GWLP_USERDATA, l);
920   l = (LONG_PTR) adjuster_sb_wndproc;
921   l = SetWindowLongPtr(sbwnd, GWLP_WNDPROC, l);
922   stuff->oldwndproc = (WNDPROC) l;
923   return 0;
924}
925
926
927
928//============================================================
929//  win_dialog_add_adjuster
930//============================================================
931
932int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, int default_value,
933   int min_value, int max_value, BOOL is_percentage,
934   dialog_itemstoreval storeval, void *storeval_param)
935{
936   short x;
937   short y;
938   TCHAR buf[32];
939   TCHAR *s;
940
941   dialog_new_control(dialog, &x, &y);
942
943   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
944         x, y, dialog->layout->label_width, DIM_ADJUSTER_HEIGHT, item_label, DLGITEM_STATIC, NULL))
945      goto error;
946   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
947
948   y += DIM_BOX_VERTSKEW;
949
950   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NUMBER,
951         x, y, dialog->layout->combo_width - DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_EDIT, NULL))
952      goto error;
953   x += dialog->layout->combo_width - DIM_ADJUSTER_SCR_WIDTH;
954
955   _sntprintf(buf, ARRAY_LENGTH(buf),
956      is_percentage ? TEXT("%d%%") : TEXT("%d"),
957      default_value);
958   s = win_dialog_tcsdup(dialog, buf);
959   if (!s)
960      return 1;
961   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, WM_SETTEXT, NULL,
962         0, (LPARAM) s, NULL, NULL))
963      goto error;
964
965   // add the trigger invoked when the apply button is pressed
966   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_adjuster_value, 0, 0, storeval, storeval_param))
967      goto error;
968
969   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT,
970         x, y, DIM_ADJUSTER_SCR_WIDTH, DIM_ADJUSTER_HEIGHT, NULL, DLGITEM_SCROLLBAR, NULL))
971      goto error;
972   x += DIM_ADJUSTER_SCR_WIDTH + DIM_HORIZONTAL_SPACING;
973
974   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, 0, adjuster_sb_setup,
975         0, MAKELONG(min_value, max_value), NULL, NULL))
976      return 1;
977
978   y += DIM_COMBO_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
979
980   dialog_finish_control(dialog, x, y);
981   return 0;
982
983error:
984   return 1;
985}
986
987
988
989//============================================================
990//  win_dialog_add_slider
991//============================================================
992
993int win_dialog_add_slider(dialog_box *dialog, const char *item_label, int default_value,
994   int min_value, int max_value,
995   dialog_itemstoreval storeval, void *storeval_param)
996{
997   short x;
998   short y;
999
1000   dialog_new_control(dialog, &x, &y);
1001
1002   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT,
1003         x, y, dialog->layout->label_width, DIM_SLIDER_ROW_HEIGHT, item_label, DLGITEM_STATIC, NULL))
1004      goto error;
1005
1006   y += DIM_BOX_VERTSKEW;
1007
1008   x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
1009   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_HORZ | TBS_BOTH,
1010         x, y, dialog->layout->combo_width, DIM_SLIDER_ROW_HEIGHT, NULL, TRACKBAR_CLASSW, NULL))
1011      goto error;
1012
1013   x += dialog->layout->combo_width + DIM_HORIZONTAL_SPACING;
1014   y += DIM_SLIDER_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
1015
1016   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, TBM_SETRANGE, NULL, 0,
1017         (LPARAM) MAKELONG(min_value, max_value), NULL, NULL))
1018      goto error;
1019
1020   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_INITDIALOG, TBM_SETPOS, NULL, 0,
1021         (LPARAM) default_value, NULL, NULL))
1022      goto error;
1023
1024   // add the trigger invoked when the apply button is pressed
1025   if (dialog_add_trigger(dialog, dialog->item_count, TRIGGER_APPLY, 0, dialog_get_slider_value, 0, 0, storeval, storeval_param))
1026      goto error;
1027
1028   dialog_finish_control(dialog, x, y);
1029   return 0;
1030
1031error:
1032   return 1;
1033}
1034
1035
1036
1037//============================================================
1038//  get_seqselect_info
1039//============================================================
1040
1041static seqselect_info *get_seqselect_info(HWND editwnd)
1042{
1043   LONG_PTR lp;
1044   lp = GetWindowLongPtr(editwnd, GWLP_USERDATA);
1045   return (seqselect_info *) lp;
1046}
1047
1048
1049
1050//============================================================
1051//  seqselect_settext
1052//============================================================
1053
1054static void seqselect_settext(HWND editwnd)
1055{
1056   seqselect_info *stuff;
1057   astring seqstring;
1058   char buffer[128];
1059
1060   // the basics
1061   stuff = get_seqselect_info(editwnd);
1062   if (stuff == NULL)
1063      return;   // this should not happen - need to fix this
1064
1065   // retrieve the seq name
1066   input_seq_name(Machine, seqstring, stuff->code);
1067
1068   // change the text - avoid calls to SetWindowText() if we can
1069   win_get_window_text_utf8(editwnd, buffer, ARRAY_LENGTH(buffer));
1070   if (strcmp(buffer, seqstring))
1071      win_set_window_text_utf8(editwnd, seqstring);
1072
1073   // reset the selection
1074   if (GetFocus() == editwnd)
1075   {
1076      DWORD start = 0, end = 0;
1077      SendMessage(editwnd, EM_GETSEL, (WPARAM) (LPDWORD) &start, (LPARAM) (LPDWORD) &end);
1078      if ((start != 0) || (end != strlen(buffer)))
1079         SendMessage(editwnd, EM_SETSEL, 0, -1);
1080   }
1081}
1082
1083
1084
1085//============================================================
1086//  seqselect_start_read_from_main_thread
1087//============================================================
1088
1089static void seqselect_start_read_from_main_thread(void *param)
1090{
1091   seqselect_info *stuff;
1092   HWND editwnd;
1093   //int ret;
1094   win_window_info fake_window_info;
1095   win_window_info *old_window_list;
1096   int pause_count;
1097
1098   // get the basics
1099   editwnd = (HWND) param;
1100   stuff = get_seqselect_info(editwnd);
1101
1102   // are we currently polling?  if so bail out
1103   if (stuff->poll_state != SEQSELECT_STATE_NOT_POLLING)
1104      return;
1105
1106   // change the state
1107   stuff->poll_state = SEQSELECT_STATE_POLLING;
1108
1109   // the Win32 OSD code thinks that we are paused, we need to temporarily
1110   // unpause ourselves or else we will block
1111   pause_count = 0;
1112   while(Machine->paused() && !winwindow_ui_is_paused(Machine))
1113   {
1114      winwindow_ui_pause_from_main_thread(Machine, FALSE);
1115      pause_count++;
1116   }
1117
1118   // butt ugly hack so that we accept focus
1119   old_window_list = win_window_list;
1120   memset(&fake_window_info, 0, sizeof(fake_window_info));
1121   fake_window_info.hwnd = GetFocus();
1122   win_window_list = &fake_window_info;
1123
1124   // start the polling
1125   input_seq_poll_start(Machine, stuff->is_analog ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, NULL);
1126
1127   while(stuff->poll_state == SEQSELECT_STATE_POLLING)
1128   {
1129      // poll
1130      /*ret = */input_seq_poll(Machine, stuff->code);
1131      seqselect_settext(editwnd);
1132   }
1133
1134   // clean up after hack
1135   win_window_list = old_window_list;
1136
1137   // we are no longer polling
1138   stuff->poll_state = SEQSELECT_STATE_NOT_POLLING;
1139
1140   // repause the OSD code
1141   while(pause_count--)
1142      winwindow_ui_pause_from_main_thread(Machine, TRUE);
1143}
1144
1145
1146
1147//============================================================
1148//  seqselect_stop_read_from_main_thread
1149//============================================================
1150
1151static void seqselect_stop_read_from_main_thread(void *param)
1152{
1153   HWND editwnd;
1154   seqselect_info *stuff;
1155
1156   // get the basics
1157   editwnd = (HWND) param;
1158   stuff = get_seqselect_info(editwnd);
1159
1160   // stop the read
1161   if (stuff->poll_state == SEQSELECT_STATE_POLLING)
1162      stuff->poll_state = SEQSELECT_STATE_POLLING_COMPLETE;
1163}
1164
1165
1166
1167//============================================================
1168//  seqselect_wndproc
1169//============================================================
1170
1171static INT_PTR CALLBACK seqselect_wndproc(HWND editwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1172{
1173   seqselect_info *stuff;
1174   INT_PTR result = 0;
1175   BOOL call_baseclass = TRUE;
1176
1177   stuff = get_seqselect_info(editwnd);
1178
1179   switch(msg)
1180   {
1181      case WM_KEYDOWN:
1182      case WM_SYSKEYDOWN:
1183      case WM_CHAR:
1184      case WM_KEYUP:
1185      case WM_SYSKEYUP:
1186         result = 1;
1187         call_baseclass = FALSE;
1188         break;
1189
1190      case WM_SETFOCUS:
1191         PostMessage(editwnd, SEQWM_SETFOCUS, 0, 0);
1192         break;
1193
1194      case WM_KILLFOCUS:
1195         PostMessage(editwnd, SEQWM_KILLFOCUS, 0, 0);
1196         break;
1197
1198      case SEQWM_SETFOCUS:
1199         // if we receive the focus, we should start a polling loop
1200         winwindow_ui_exec_on_main_thread(seqselect_start_read_from_main_thread, (void *) editwnd);
1201         break;
1202
1203      case SEQWM_KILLFOCUS:
1204         // when we abort the focus, end any current polling loop
1205         winwindow_ui_exec_on_main_thread(seqselect_stop_read_from_main_thread, (void *) editwnd);
1206         break;
1207
1208      case WM_LBUTTONDOWN:
1209      case WM_RBUTTONDOWN:
1210         SetFocus(editwnd);
1211         SendMessage(editwnd, EM_SETSEL, 0, -1);
1212         call_baseclass = FALSE;
1213         result = 0;
1214         break;
1215   }
1216
1217   if (call_baseclass)
1218      result = call_windowproc(stuff->oldwndproc, editwnd, msg, wparam, lparam);
1219   return result;
1220}
1221
1222
1223
1224//============================================================
1225//  seqselect_setup
1226//============================================================
1227
1228static LRESULT seqselect_setup(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam)
1229{
1230   seqselect_info *stuff = (seqselect_info *) lparam;
1231   LONG_PTR lp;
1232
1233   lp = SetWindowLongPtr(editwnd, GWLP_WNDPROC, (LONG_PTR) seqselect_wndproc);
1234   stuff->oldwndproc = (WNDPROC) lp;
1235   SetWindowLongPtr(editwnd, GWLP_USERDATA, lparam);
1236   seqselect_settext(editwnd);
1237   return 0;
1238}
1239
1240
1241
1242//============================================================
1243//  seqselect_apply
1244//============================================================
1245
1246static LRESULT seqselect_apply(dialog_box *dialog, HWND editwnd, UINT message, WPARAM wparam, LPARAM lparam)
1247{
1248   seqselect_info *stuff;
1249   stuff = get_seqselect_info(editwnd);
1250
1251   // store the settings
1252   input_field_set_user_settings(stuff->field, &stuff->settings);
1253
1254   return 0;
1255}
1256
1257//============================================================
1258//  dialog_add_single_seqselect
1259//============================================================
1260
1261static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y,
1262   short cx, short cy, const input_field_config *field, int is_analog, int seq)
1263{
1264   seqselect_info *stuff;
1265
1266   // write the dialog item
1267   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_ENDELLIPSIS | ES_CENTER | SS_SUNKEN,
1268         x, y, cx, cy, NULL, DLGITEM_EDIT, NULL))
1269      return 1;
1270
1271   // allocate a seqselect_info
1272   stuff = (seqselect_info *) pool_malloc_lib(di->mempool, sizeof(seqselect_info));
1273   if (!stuff)
1274      return 1;
1275
1276   // initialize the structure
1277   memset(stuff, 0, sizeof(*stuff));
1278   input_field_get_user_settings(field, &stuff->settings);
1279   stuff->field = field;
1280   stuff->pos = di->item_count;
1281   stuff->is_analog = is_analog;
1282   stuff->code = &stuff->settings.seq[seq];
1283
1284   if (dialog_add_trigger(di, di->item_count, TRIGGER_INITDIALOG, 0, seqselect_setup, di->item_count, (LPARAM) stuff, NULL, NULL))
1285      return 1;
1286   if (dialog_add_trigger(di, di->item_count, TRIGGER_APPLY, 0, seqselect_apply, 0, 0, NULL, NULL))
1287      return 1;
1288   return 0;
1289}
1290
1291
1292
1293//============================================================
1294//  win_dialog_add_seqselect
1295//============================================================
1296
1297int win_dialog_add_portselect(dialog_box *dialog, const input_field_config *field)
1298{
1299   dialog_box *di = dialog;
1300   short x;
1301   short y;
1302   const char *port_name;
1303   const char *this_port_name;
1304   char *s;
1305   int seq;
1306   int seq_count = 0;
1307   const char *port_suffix[3];
1308   int seq_types[3];
1309   int is_analog[3];
1310   int len;
1311
1312   port_name = input_field_name(field);
1313   assert(port_name);
1314
1315   if (field->type >= __ipt_analog_start && field->type <= __ipt_analog_end)
1316   {
1317      seq_types[seq_count] = SEQ_TYPE_STANDARD;
1318      port_suffix[seq_count] = " Analog";
1319      is_analog[seq_count] = TRUE;
1320      seq_count++;
1321
1322      seq_types[seq_count] = SEQ_TYPE_DECREMENT;
1323      port_suffix[seq_count] = " Dec";
1324      is_analog[seq_count] = FALSE;
1325      seq_count++;
1326
1327      seq_types[seq_count] = SEQ_TYPE_INCREMENT;
1328      port_suffix[seq_count] = " Inc";
1329      is_analog[seq_count] = FALSE;
1330      seq_count++;
1331   }
1332   else
1333   {
1334      seq_types[seq_count] = SEQ_TYPE_STANDARD;
1335      port_suffix[seq_count] = NULL;
1336      is_analog[seq_count] = FALSE;
1337      seq_count++;
1338   }
1339
1340   for (seq = 0; seq < seq_count; seq++)
1341   {
1342      // create our local name for this entry; also convert from
1343      // MAME strings to wide strings
1344      len = strlen(port_name);
1345      s = (char *) alloca((len + (port_suffix[seq] ? strlen(port_suffix[seq])
1346         : 0) + 1) * sizeof(*s));
1347      strcpy(s, port_name);
1348
1349      if (port_suffix[seq])
1350         strcpy(s + len, port_suffix[seq]);
1351      this_port_name = s;
1352
1353      // no positions specified
1354      dialog_new_control(di, &x, &y);
1355
1356      if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, x, y,
1357            dialog->layout->label_width, DIM_NORMAL_ROW_HEIGHT, this_port_name, DLGITEM_STATIC, NULL))
1358         return 1;
1359      x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
1360
1361      if (dialog_add_single_seqselect(di, x, y, DIM_EDIT_WIDTH, DIM_NORMAL_ROW_HEIGHT,
1362            field, is_analog[seq], seq_types[seq]))
1363         return 1;
1364      y += DIM_VERTICAL_SPACING + DIM_NORMAL_ROW_HEIGHT;
1365      x += DIM_EDIT_WIDTH + DIM_HORIZONTAL_SPACING;
1366
1367      dialog_finish_control(di, x, y);
1368   }
1369   return 0;
1370}
1371
1372
1373
1374//============================================================
1375//  win_dialog_add_notification
1376//============================================================
1377
1378int win_dialog_add_notification(dialog_box *dialog, UINT notification,
1379   dialog_notification callback, void *param)
1380{
1381   // hack
1382   assert(!dialog->notify_callback);
1383   dialog->notify_code = notification;
1384   dialog->notify_callback = callback;
1385   dialog->notify_param = param;
1386   return 0;
1387}
1388
1389
1390
1391//============================================================
1392//  win_dialog_add_standard_buttons
1393//============================================================
1394
1395int win_dialog_add_standard_buttons(dialog_box *dialog)
1396{
1397   dialog_box *di = dialog;
1398   short x;
1399   short y;
1400
1401   x = di->size_x - DIM_HORIZONTAL_SPACING - DIM_BUTTON_WIDTH;
1402   y = di->size_y + DIM_VERTICAL_SPACING;
1403
1404   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT,
1405         x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_CANCEL, DLGITEM_BUTTON, NULL))
1406      return 1;
1407
1408   x -= DIM_HORIZONTAL_SPACING + DIM_BUTTON_WIDTH;
1409   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_LEFT,
1410         x, y, DIM_BUTTON_WIDTH, DIM_BUTTON_ROW_HEIGHT, DLGTEXT_OK, DLGITEM_BUTTON, NULL))
1411      return 1;
1412   di->size_y += DIM_BUTTON_ROW_HEIGHT + DIM_VERTICAL_SPACING * 2;
1413   return 0;
1414}
1415
1416
1417
1418//============================================================
1419//  create_png_bitmap
1420//============================================================
1421
1422static HBITMAP create_png_bitmap(const png_info *png)
1423{
1424   HBITMAP bitmap;
1425   BITMAPINFOHEADER bitmap_header;
1426   void *bitmap_data;
1427   UINT8 *src;
1428   UINT8 *dst;
1429   int x, y;
1430   HDC dc;
1431
1432   // grab a device context
1433   dc = GetDC(NULL);
1434
1435   // create the bitmap header
1436   memset(&bitmap_header, 0, sizeof(bitmap_header));
1437   bitmap_header.biSize = sizeof(BITMAPINFOHEADER);
1438   bitmap_header.biWidth = png->width;
1439   bitmap_header.biHeight = -png->height;
1440   bitmap_header.biPlanes = 1;
1441   bitmap_header.biBitCount = 24;
1442   bitmap_header.biCompression = BI_RGB;
1443
1444   // create an HBITMAP
1445   bitmap = CreateDIBSection(dc, (BITMAPINFO *) &bitmap_header, DIB_RGB_COLORS, &bitmap_data, NULL, 0);
1446   if (!bitmap)
1447      goto done;
1448
1449   // copy the data
1450   src = png->image;
1451   dst = (UINT8 *) bitmap_data;
1452   for (y = 0; y < png->height; y++)
1453   {
1454      for (x = 0; x < png->width; x++)
1455      {
1456         switch(png->color_type) {
1457         case 0:      // 8bpp grayscale case
1458            dst[2] = src[0];
1459            dst[1] = src[0];
1460            dst[0] = src[0];
1461            src++;
1462            break;
1463
1464         case 2:      // 32bpp non-alpha case
1465            dst[2] = src[0];
1466            dst[1] = src[1];
1467            dst[0] = src[2];
1468            src += 3;
1469            break;
1470
1471         case 3:      // 8bpp palettized case
1472            assert(png->palette);
1473            dst[2] = png->palette[*src * 3 + 0];
1474            dst[1] = png->palette[*src * 3 + 1];
1475            dst[0] = png->palette[*src * 3 + 2];
1476            src++;
1477            break;
1478         }
1479         dst += 3;
1480      }
1481   }
1482
1483done:
1484   ReleaseDC(NULL, dc);
1485   return bitmap;
1486}
1487
1488//============================================================
1489//  win_dialog_add_image
1490//============================================================
1491
1492int win_dialog_add_image(dialog_box *dialog, const png_info *png)
1493{
1494   WORD id;
1495   HBITMAP bitmap;
1496   short x, y;
1497   short width, height;
1498
1499   calc_dlgunits_multiple();
1500   width = png->width / pixels_to_xdlgunits;
1501   height = png->height / pixels_to_ydlgunits;
1502
1503   bitmap = create_png_bitmap(png);
1504   if (!bitmap)
1505      return 1;
1506
1507   dialog_new_control(dialog, &x, &y);
1508   if (dialog_write_item(dialog, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_BITMAP,
1509         x, y, width, height, NULL, DLGITEM_STATIC, &id))
1510      return 1;
1511   if (dialog_add_trigger(dialog, id, TRIGGER_INITDIALOG, STM_SETIMAGE, NULL, (WPARAM)IMAGE_BITMAP, (LPARAM) bitmap, NULL, NULL))
1512      return 1;
1513   if (dialog_add_object(dialog, bitmap))
1514      return 1;
1515   x += width;
1516   y += height;
1517   dialog_finish_control(dialog, x, y);
1518   return 0;
1519}
1520
1521//============================================================
1522//  win_dialog_add_separator
1523//============================================================
1524
1525int win_dialog_add_separator(dialog_box *dialog)
1526{
1527   dialog->home_y = dialog->cursize_y;
1528   dialog->cursize_x = 0;
1529   return 0;
1530}
1531
1532//============================================================
1533//  win_dialog_exit
1534//============================================================
1535
1536void win_dialog_exit(dialog_box *dialog)
1537{
1538   int i;
1539   struct dialog_object_pool *objpool;
1540
1541   assert(dialog);
1542
1543   objpool = dialog->objpool;
1544   if (objpool)
1545   {
1546      for (i = 0; i < ARRAY_LENGTH(objpool->objects); i++)
1547         DeleteObject(objpool->objects[i]);
1548   }
1549
1550   if (dialog->handle)
1551      GlobalFree(dialog->handle);
1552   pool_free_lib(dialog->mempool);
1553   free(dialog);
1554}
1555
1556
1557
1558//============================================================
1559//  win_dialog_malloc
1560//============================================================
1561
1562void *win_dialog_malloc(dialog_box *dialog, size_t size)
1563{
1564   return pool_malloc_lib(dialog->mempool, size);
1565}
1566
1567
1568
1569//============================================================
1570//  win_dialog_strdup
1571//============================================================
1572
1573char *win_dialog_strdup(dialog_box *dialog, const char *s)
1574{
1575   return pool_strdup_lib(dialog->mempool, s);
1576}
1577
1578
1579
1580//============================================================
1581//  win_dialog_wcsdup
1582//============================================================
1583
1584WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s)
1585{
1586   WCHAR *result = (WCHAR *) pool_malloc_lib(dialog->mempool, (wcslen(s) + 1) * sizeof(*s));
1587   if (result)
1588      wcscpy(result, s);
1589   return result;
1590}
1591
1592
1593
1594//============================================================
1595//  before_display_dialog
1596//============================================================
1597
1598static void before_display_dialog(running_machine *machine)
1599{
1600   Machine = machine;
1601   winwindow_ui_pause_from_window_thread(machine, TRUE);
1602}
1603
1604
1605
1606//============================================================
1607//  after_display_dialog
1608//============================================================
1609
1610static void after_display_dialog(running_machine *machine)
1611{
1612   winwindow_ui_pause_from_window_thread(machine, FALSE);
1613   Machine = NULL;
1614}
1615
1616
1617
1618//============================================================
1619//  win_dialog_runmodal
1620//============================================================
1621
1622void win_dialog_runmodal(running_machine *machine, HWND wnd, dialog_box *dialog)
1623{
1624   assert(dialog);
1625
1626   // finishing touches on the dialog
1627   dialog_prime(dialog);
1628
1629   // show the dialog
1630   before_display_dialog(machine);
1631   DialogBoxIndirectParamW(NULL, (const DLGTEMPLATE*)dialog->handle, wnd, dialog_proc, (LPARAM) dialog);
1632   after_display_dialog(machine);
1633}
1634
1635
1636
1637//============================================================
1638//  file_dialog_hook
1639//============================================================
1640
1641static UINT_PTR CALLBACK file_dialog_hook(HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam)
1642{
1643   OPENFILENAME *ofn;
1644   dialog_box *dialog;
1645   UINT_PTR rc = 0;
1646   LPNMHDR notify;
1647   LONG_PTR l;
1648
1649   switch(message) {
1650   case WM_INITDIALOG:
1651      ofn = (OPENFILENAME *) lparam;
1652      dialog = (dialog_box *) ofn->lCustData;
1653
1654      SetWindowLongPtr(dlgwnd, GWLP_USERDATA, (LONG_PTR) dialog);
1655      dialog_trigger(dlgwnd, TRIGGER_INITDIALOG);
1656      rc = 1;
1657
1658      // hack
1659      if (dialog->notify_callback && (dialog->notify_code == CDN_TYPECHANGE))
1660         dialog->notify_callback(dialog, dlgwnd, NULL, dialog->notify_param);
1661      break;
1662
1663   case WM_NOTIFY:
1664      notify = (LPNMHDR) lparam;
1665      switch(notify->code) {
1666      case CDN_FILEOK:
1667         dialog_trigger(dlgwnd, TRIGGER_APPLY);
1668         break;
1669      }
1670
1671      // hack
1672      l = GetWindowLongPtr(dlgwnd, GWLP_USERDATA);
1673      dialog = (dialog_box *) l;
1674      if (dialog->notify_callback && (notify->code == dialog->notify_code))
1675         dialog->notify_callback(dialog, dlgwnd, notify, dialog->notify_param);
1676      break;
1677
1678   case WM_COMMAND:
1679      switch(HIWORD(wparam)) {
1680      case CBN_SELCHANGE:
1681         dialog_trigger(dlgwnd, TRIGGER_CHANGED);
1682         break;
1683      }
1684      break;
1685   }
1686   return rc;
1687}
1688
1689
1690
1691//============================================================
1692//  win_file_dialog
1693//============================================================
1694
1695BOOL win_file_dialog(running_machine *machine,
1696   HWND parent, win_file_dialog_type dlgtype, dialog_box *custom_dialog, const char *filter,
1697   const char *initial_dir, char *filename, size_t filename_len)
1698{
1699   win_open_file_name ofn;
1700   BOOL result = FALSE;
1701
1702   // set up the OPENFILENAME data structure
1703   memset(&ofn, 0, sizeof(ofn));
1704   ofn.type = dlgtype;
1705   ofn.owner = parent;
1706   ofn.flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
1707   ofn.filter = filter;
1708   ofn.initial_directory = initial_dir;
1709
1710   if (dlgtype == WIN_FILE_DIALOG_OPEN)
1711   {
1712      ofn.flags |= OFN_FILEMUSTEXIST;
1713   }
1714
1715   if (custom_dialog)
1716   {
1717      custom_dialog->style = WS_CHILD | WS_CLIPSIBLINGS | DS_3DLOOK | DS_CONTROL | DS_SETFONT;
1718      dialog_prime(custom_dialog);
1719
1720      ofn.flags |= OFN_ENABLETEMPLATEHANDLE | OFN_ENABLEHOOK;
1721      ofn.instance = (HINSTANCE)custom_dialog->handle;
1722      ofn.custom_data = (LPARAM) custom_dialog;
1723      ofn.hook = file_dialog_hook;
1724   }
1725
1726   snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s", filename);
1727
1728   before_display_dialog(machine);
1729   result = win_get_file_name_dialog(&ofn);
1730   after_display_dialog(machine);
1731
1732   snprintf(filename, filename_len, "%s", ofn.filename);
1733   return result;
1734}
1735
1736
src/mess/osd/winui/dialog.h
r0r10019
1//============================================================
2//
3//  dialog.h - Win32 MESS dialog handling
4//
5//============================================================
6
7#ifndef DIALOG_H
8#define DIALOG_H
9
10#include <windows.h>
11#include "emu.h"
12#include "png.h"
13#include "opresolv.h"
14#include "winutils.h"
15
16typedef struct _dialog_box dialog_box;
17
18struct dialog_layout
19{
20   short label_width;
21   short combo_width;
22};
23
24typedef void (*dialog_itemstoreval)(void *param, int val);
25typedef void (*dialog_itemchangedproc)(dialog_box *dialog, HWND dlgitem, void *changed_param);
26typedef void (*dialog_notification)(dialog_box *dialog, HWND dlgwnd, NMHDR *notification, void *param);
27
28/* dialog allocation / termination */
29dialog_box *win_dialog_init(const char *title, const struct dialog_layout *layout);
30void win_dialog_exit(dialog_box *dialog);
31
32/* dialog memory allocation */
33void *win_dialog_malloc(dialog_box *dialog, size_t size);
34char *win_dialog_strdup(dialog_box *dialog, const char *s);
35WCHAR *win_dialog_wcsdup(dialog_box *dialog, const WCHAR *s);
36
37#ifdef UNICODE
38#define win_dialog_tcsdup   win_dialog_wcsdup
39#else
40#define win_dialog_tcsdup   win_dialog_strdup
41#endif
42
43/* dialog operations */
44void win_dialog_runmodal(running_machine *machine, HWND wnd, dialog_box *dialog);
45int win_dialog_add_combobox(dialog_box *dialog, const char *item_label, int default_value,
46   dialog_itemstoreval storeval, void *storeval_param);
47int win_dialog_add_active_combobox(dialog_box *dialog, const char *item_label, int default_value,
48   dialog_itemstoreval storeval, void *storeval_param,
49   dialog_itemchangedproc changed, void *changed_param);
50int win_dialog_add_combobox_item(dialog_box *dialog, const char *item_label, int item_data);
51
52int win_dialog_add_adjuster(dialog_box *dialog, const char *item_label, int default_value,
53   int min_value, int max_value, BOOL is_percentage,
54   dialog_itemstoreval storeval, void *storeval_param);
55
56int win_dialog_add_slider(dialog_box *dialog, const char *item_label, int default_value,
57   int min_value, int max_value,
58   dialog_itemstoreval storeval, void *storeval_param);
59
60int win_dialog_add_portselect(dialog_box *dialog, const input_field_config *field);
61
62int win_dialog_add_standard_buttons(dialog_box *dialog);
63int win_dialog_add_image(dialog_box *dialog, const png_info *png);
64int win_dialog_add_separator(dialog_box *dialog);
65int win_dialog_add_notification(dialog_box *dialog, UINT notification,
66   dialog_notification callback, void *param);
67
68
69// wrapper for the standard file dialog
70BOOL win_file_dialog(running_machine *machine,
71   HWND parent, win_file_dialog_type dlgtype, dialog_box *custom_dialog, const char *filter,
72   const char *initial_dir, char *filename, size_t filename_len);
73
74#endif /* DIALOG_H */
src/mess/osd/winui/menu.c
r0r10019
1//============================================================
2//
3//  menu.c - Win32 MESS menus handling
4//
5//============================================================
6
7// standard windows headers
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#include <commdlg.h>
11#include <winuser.h>
12#include <ctype.h>
13#include <tchar.h>
14
15// MAME/MESS headers
16#include "emu.h"
17#include "emuopts.h"
18#include "menu.h"
19#include "ui.h"
20#include "messres.h"
21#include "windows/video.h"
22#include "windows/input.h"
23#include "dialog.h"
24#include "opcntrl.h"
25#include "strconv.h"
26#include "debug/debugcpu.h"
27#include "inptport.h"
28#include "imagedev/cassette.h"
29#include "windows/window.h"
30#include "winutf8.h"
31
32//============================================================
33//  IMPORTS
34//============================================================
35
36// from timer.c
37extern void win_timer_enable(int enabled);
38
39
40//============================================================
41//  PARAMETERS
42//============================================================
43
44#define ID_FRAMESKIP_0            10000
45#define ID_DEVICE_0               11000
46#define ID_JOYSTICK_0            12000
47#define ID_INPUT_0               13000
48#define ID_VIDEO_VIEW_0            14000
49
50#define MAX_JOYSTICKS            (8)
51
52enum
53{
54   DEVOPTION_OPEN,
55   DEVOPTION_CREATE,
56   DEVOPTION_CLOSE,
57   DEVOPTION_CASSETTE_PLAYRECORD,
58   DEVOPTION_CASSETTE_STOPPAUSE,
59   DEVOPTION_CASSETTE_PLAY,
60   DEVOPTION_CASSETTE_RECORD,
61   DEVOPTION_CASSETTE_REWIND,
62   DEVOPTION_CASSETTE_FASTFORWARD,
63   DEVOPTION_MAX
64};
65
66#ifdef MAME_PROFILER
67#define HAS_PROFILER   1
68#else
69#define HAS_PROFILER   0
70#endif
71
72//============================================================
73//  LOCAL VARIABLES
74//============================================================
75
76static int use_input_categories;
77static int joystick_menu_setup;
78static char state_filename[MAX_PATH];
79
80static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions);
81
82
83
84//============================================================
85//  input_item_from_serial_number
86//============================================================
87
88static int input_item_from_serial_number(running_machine *machine, int serial_number,
89   const input_port_config **port, const input_field_config **field, const input_setting_config **setting)
90{
91   int i;
92   const input_port_config *this_port = NULL;
93   const input_field_config *this_field = NULL;
94   const input_setting_config *this_setting = NULL;
95
96   i = 0;
97   for (this_port = machine->m_portlist.first(); (i != serial_number) && (this_port != NULL); this_port = this_port->next())
98   {
99      i++;
100      for (this_field = this_port->fieldlist; (i != serial_number) && (this_field != NULL); this_field = this_field->next)
101      {
102         i++;
103         for (this_setting = this_field->settinglist; (i != serial_number) && (this_setting != NULL); this_setting = this_setting->next)
104         {
105            i++;
106         }
107      }
108   }
109
110   if (this_setting != NULL)
111      this_field = this_setting->field;
112   if (this_field != NULL)
113      this_port = this_field->port;
114
115   if (port != NULL)
116      *port = this_port;
117   if (field != NULL)
118      *field = this_field;
119   if (setting != NULL)
120      *setting = this_setting;
121   return (i == serial_number);
122}
123
124
125
126//============================================================
127//  serial_number_from_input_item
128//============================================================
129
130static int serial_number_from_input_item(running_machine *machine, const input_port_config *port,
131   const input_field_config *field, const input_setting_config *setting)
132{
133   int i;
134   const input_port_config *this_port;
135   const input_field_config *this_field;
136   const input_setting_config *this_setting;
137
138   i = 0;
139   for (this_port = machine->m_portlist.first(); this_port != NULL; this_port = this_port->next())
140   {
141      if ((port == this_port) && (field == NULL) && (setting == NULL))
142         return i;
143
144      i++;
145      for (this_field = this_port->fieldlist; this_field != NULL; this_field = this_field->next)
146      {
147         if ((port == this_port) && (field == this_field) && (setting == NULL))
148            return i;
149
150         i++;
151         for (this_setting = this_field->settinglist; this_setting != NULL; this_setting = this_setting->next)
152         {
153            if ((port == this_port) && (field == this_field) && (setting == this_setting))
154               return i;
155
156            i++;
157         }
158      }
159   }
160   return -1;
161}
162
163
164
165//============================================================
166//  customize_input
167//============================================================
168
169static void customize_input(running_machine *machine, HWND wnd, const char *title, int player, int inputclass)
170{
171   dialog_box *dlg;
172   const input_port_config *port;
173   const input_field_config *field;
174   int this_inputclass, this_player, portslot_count = 0, i;
175
176   struct
177   {
178      const input_field_config *field;
179   } portslots[256];
180
181   /* create the dialog */
182   dlg = win_dialog_init(title, NULL);
183   if (!dlg)
184      goto done;
185
186   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
187   {
188      for (field = port->fieldlist; field != NULL; field = field->next)
189      {
190         this_inputclass = input_classify_port(field);
191         if (input_field_name(field) && (this_inputclass == inputclass))
192         {
193            /* most of the time, the player parameter is the player number
194                 * but in the case of INPUT_CLASS_CATEGORIZED, it is the
195                 * category */
196            if (inputclass == INPUT_CLASS_CATEGORIZED)
197               this_player = field->category;
198            else
199               this_player = input_player_number(field);
200
201            if (this_player == player)
202            {
203               /* store this InputPort/RECT combo in our list.  we do not
204                     * necessarily want to add it yet because we the INI might
205                     * want to reorder the tab order */
206               if (portslot_count < ARRAY_LENGTH(portslots))
207               {
208                  portslots[portslot_count].field = field;
209               }
210               portslot_count++;
211            }
212         }
213      }
214   }
215
216   /* finally add the portselects to the dialog */
217   if (portslot_count > ARRAY_LENGTH(portslots))
218      portslot_count = ARRAY_LENGTH(portslots);
219   for (i = 0; i < portslot_count; i++)
220   {
221      if (portslots[i].field)
222      {
223         if (win_dialog_add_portselect(dlg, portslots[i].field))
224            goto done;
225      }
226   }
227
228   /* ...and now add OK/Cancel */
229   if (win_dialog_add_standard_buttons(dlg))
230      goto done;
231
232   /* ...and finally display the dialog */
233   win_dialog_runmodal(machine, wnd, dlg);
234
235done:
236   if (dlg)
237      win_dialog_exit(dlg);
238}
239
240
241
242//============================================================
243//  customize_joystick
244//============================================================
245
246static void customize_joystick(running_machine *machine, HWND wnd, int joystick_num)
247{
248   customize_input(machine, wnd, "Joysticks/Controllers", joystick_num, INPUT_CLASS_CONTROLLER);
249}
250
251
252
253//============================================================
254//  customize_keyboard
255//============================================================
256
257static void customize_keyboard(running_machine *machine, HWND wnd)
258{
259   customize_input(machine, wnd, "Emulated Keyboard", 0, INPUT_CLASS_KEYBOARD);
260}
261
262
263
264//============================================================
265//  customize_miscinput
266//============================================================
267
268static void customize_miscinput(running_machine *machine, HWND wnd)
269{
270   customize_input(machine, wnd, "Miscellaneous Input", 0, INPUT_CLASS_MISC);
271}
272
273
274
275//============================================================
276//  customize_categorizedinput
277//============================================================
278
279static void customize_categorizedinput(running_machine *machine, HWND wnd, int category)
280{
281   assert(category > 0);
282   customize_input(machine, wnd, "Input", category, INPUT_CLASS_CATEGORIZED);
283}
284
285
286
287//============================================================
288//  storeval_inputport
289//============================================================
290
291static void storeval_inputport(void *param, int val)
292{
293   const input_field_config *field = (input_field_config *) param;
294   input_field_user_settings settings;
295
296   input_field_get_user_settings(field, &settings);
297   settings.value = (UINT16) val;
298   input_field_set_user_settings(field, &settings);
299}
300
301
302
303//============================================================
304//  customize_switches
305//============================================================
306
307static void customize_switches(running_machine *machine, HWND wnd, const char* title_string, UINT32 ipt_name)
308{
309   dialog_box *dlg;
310   const input_port_config *port;
311   const input_field_config *field;
312   const input_setting_config *setting;
313   const char *switch_name = NULL;
314   input_field_user_settings settings;
315
316   UINT32 type;
317
318   dlg = win_dialog_init(title_string, NULL);
319   if (!dlg)
320      goto done;
321
322   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
323   {
324      for (field = port->fieldlist; field != NULL; field = field->next)
325      {
326         type = field->type;
327
328         if (type == ipt_name)
329         {
330            switch_name = input_field_name(field);
331
332            input_field_get_user_settings(field, &settings);
333
334            if (win_dialog_add_combobox(dlg, switch_name, settings.value, storeval_inputport, (void *) field))
335               goto done;
336
337            for (setting = field->settinglist; setting != NULL; setting = setting->next)
338            {
339               if (win_dialog_add_combobox_item(dlg, setting->name, setting->value))
340                  goto done;
341            }
342         }
343      }
344   }
345
346   if (win_dialog_add_standard_buttons(dlg))
347      goto done;
348
349   win_dialog_runmodal(machine, wnd, dlg);
350
351done:
352   if (dlg)
353      win_dialog_exit(dlg);
354}
355
356
357
358//============================================================
359//  customize_dipswitches
360//============================================================
361
362static void customize_dipswitches(running_machine *machine, HWND wnd)
363{
364   customize_switches(machine, wnd, "Dip Switches", IPT_DIPSWITCH);
365}
366
367
368
369//============================================================
370//  customize_configuration
371//============================================================
372
373static void customize_configuration(running_machine *machine, HWND wnd)
374{
375   customize_switches(machine, wnd, "Driver Configuration", IPT_CONFIG);
376}
377
378
379
380//============================================================
381//  customize_analogcontrols
382//============================================================
383
384enum
385{
386   ANALOG_ITEM_KEYSPEED,
387   ANALOG_ITEM_CENTERSPEED,
388   ANALOG_ITEM_REVERSE,
389   ANALOG_ITEM_SENSITIVITY
390};
391
392
393
394static void store_analogitem(void *param, int val, int selected_item)
395{
396   const input_field_config *field = (const input_field_config *) param;
397   input_field_user_settings settings;
398
399   input_field_get_user_settings(field, &settings);
400
401   switch(selected_item)
402   {
403      case ANALOG_ITEM_KEYSPEED:      settings.delta = val;      break;
404      case ANALOG_ITEM_CENTERSPEED:   settings.centerdelta = val;   break;
405      case ANALOG_ITEM_REVERSE:      settings.reverse = val;      break;
406      case ANALOG_ITEM_SENSITIVITY:   settings.sensitivity = val;   break;
407   }
408   input_field_set_user_settings(field, &settings);
409}
410
411
412
413static void store_delta(void *param, int val)
414{
415   store_analogitem(param, val, ANALOG_ITEM_KEYSPEED);
416}
417
418
419
420static void store_centerdelta(void *param, int val)
421{
422   store_analogitem(param, val, ANALOG_ITEM_CENTERSPEED);
423}
424
425
426
427static void store_reverse(void *param, int val)
428{
429   store_analogitem(param, val, ANALOG_ITEM_REVERSE);
430}
431
432
433
434static void store_sensitivity(void *param, int val)
435{
436   store_analogitem(param, val, ANALOG_ITEM_SENSITIVITY);
437}
438
439
440
441static int port_type_is_analog(int type)
442{
443   return (type >= __ipt_analog_start && type <= __ipt_analog_end);
444}
445
446
447
448static void customize_analogcontrols(running_machine *machine, HWND wnd)
449{
450   dialog_box *dlg;
451   const input_port_config *port;
452   const input_field_config *field;
453   input_field_user_settings settings;
454   const char *name;
455   char buf[255];
456   static const struct dialog_layout layout = { 120, 52 };
457
458   dlg = win_dialog_init("Analog Controls", &layout);
459   if (!dlg)
460      goto done;
461
462   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
463   {
464      for (field = port->fieldlist; field != NULL; field = field->next)
465      {
466         if (port_type_is_analog(field->type))
467         {
468            input_field_get_user_settings(field, &settings);
469            name = input_field_name(field);
470
471            _snprintf(buf, ARRAY_LENGTH(buf),
472               "%s %s", name, "Digital Speed");
473            if (win_dialog_add_adjuster(dlg, buf, settings.delta, 1, 255, FALSE, store_delta, (void *) field))
474               goto done;
475
476            _snprintf(buf, ARRAY_LENGTH(buf),
477               "%s %s", name, "Autocenter Speed");
478            if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 1, 255, FALSE, store_centerdelta, (void *) field))
479               goto done;
480
481            _snprintf(buf, ARRAY_LENGTH(buf),
482               "%s %s", name, "Reverse");
483            if (win_dialog_add_combobox(dlg, buf, settings.reverse ? 1 : 0, store_reverse, (void *) field))
484               goto done;
485            if (win_dialog_add_combobox_item(dlg, "Off", 0))
486               goto done;
487            if (win_dialog_add_combobox_item(dlg, "On", 1))
488               goto done;
489
490            _snprintf(buf, ARRAY_LENGTH(buf),
491               "%s %s", name, "Sensitivity");
492            if (win_dialog_add_adjuster(dlg, buf, settings.sensitivity, 1, 255, TRUE, store_sensitivity, (void *) field))
493               goto done;
494         }
495      }
496   }
497
498   if (win_dialog_add_standard_buttons(dlg))
499      goto done;
500
501   win_dialog_runmodal(machine, wnd, dlg);
502
503done:
504   if (dlg)
505      win_dialog_exit(dlg);
506}
507
508
509//============================================================
510//  win_dirname
511//============================================================
512
513static char *win_dirname(const char *filename)
514{
515   char *dirname;
516   char *c;
517
518   // NULL begets NULL
519   if (!filename)
520      return NULL;
521
522   // allocate space for it
523   dirname = (char*)malloc(strlen(filename) + 1);
524   if (!dirname)
525      return NULL;
526
527   // copy in the name
528   strcpy(dirname, filename);
529
530   // search backward for a slash or a colon
531   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
532      if (*c == '\\' || *c == '/' || *c == ':')
533      {
534         // found it: NULL terminate and return
535         *(c + 1) = 0;
536         return dirname;
537      }
538
539   // otherwise, return an empty string
540   dirname[0] = 0;
541   return dirname;
542}
543
544
545//============================================================
546//  state_dialog
547//============================================================
548
549static void state_dialog(HWND wnd, win_file_dialog_type dlgtype,
550   DWORD fileproc_flags, bool is_load,
551   running_machine *machine)
552{
553   win_open_file_name ofn;
554   char *dir = NULL;
555   int result = 0;
556
557   if (state_filename[0])
558   {
559      dir = win_dirname(state_filename);
560   }
561
562   memset(&ofn, 0, sizeof(ofn));
563   ofn.type = dlgtype;
564   ofn.owner = wnd;
565   ofn.flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | fileproc_flags;
566   ofn.filter = "State Files (*.sta)|*.sta|All Files (*.*)|*.*";
567   ofn.initial_directory = dir;
568
569   if (!core_filename_ends_with(ofn.filename, "sta"))
570      snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s.sta", state_filename);
571   else
572      snprintf(ofn.filename, ARRAY_LENGTH(ofn.filename), "%s", state_filename);
573
574   result = win_get_file_name_dialog(&ofn);
575   if (result)
576   {
577      // the core doesn't add the extension if it's an absolute path
578      if (osd_is_absolute_path(ofn.filename) && !core_filename_ends_with(ofn.filename, "sta"))
579         snprintf(state_filename, ARRAY_LENGTH(state_filename), "%s.sta", ofn.filename);
580      else
581         snprintf(state_filename, ARRAY_LENGTH(state_filename), "%s", ofn.filename);
582
583      if (is_load) {
584         machine->schedule_load(state_filename);
585      } else {
586         machine->schedule_save(state_filename);
587      }
588   }
589   if (dir)
590      free(dir);
591}
592
593
594
595static void state_load(HWND wnd, running_machine *machine)
596{
597   state_dialog(wnd, WIN_FILE_DIALOG_OPEN, OFN_FILEMUSTEXIST, TRUE, machine);
598}
599
600static void state_save_as(HWND wnd, running_machine *machine)
601{
602   state_dialog(wnd, WIN_FILE_DIALOG_SAVE, OFN_OVERWRITEPROMPT, FALSE, machine);
603}
604
605static void state_save(running_machine *machine)
606{
607   machine->schedule_save(state_filename);
608}
609
610
611
612//============================================================
613//  format_combo_changed
614//============================================================
615
616struct file_dialog_params
617{
618   device_image_interface *dev;
619   int *create_format;
620   option_resolution **create_args;
621};
622
623static void format_combo_changed(dialog_box *dialog, HWND dlgwnd, NMHDR *notification, void *changed_param)
624{
625   HWND wnd;
626   int format_combo_val;
627   device_image_interface *dev;
628   const option_guide *guide;
629   const char *optspec;
630   struct file_dialog_params *params;
631   int has_option;
632   TCHAR t_buf1[128];
633   char *utf8_buf1;
634
635   params = (struct file_dialog_params *) changed_param;
636
637   // locate the format control
638   format_combo_val = notification ? (((OFNOTIFY *) notification)->lpOFN->nFilterIndex - 1) : 0;
639   if (format_combo_val < 0)
640      format_combo_val = 0;
641   *(params->create_format) = format_combo_val;
642
643   // compute our parameters
644   dev = params->dev;
645   guide = dev->device_get_creation_option_guide();
646   optspec =dev->device_get_indexed_creatable_format(format_combo_val)->m_optspec;
647
648   // set the default extension
649   CommDlg_OpenSave_SetDefExt(GetParent(dlgwnd),
650      (const char*)dev->device_get_indexed_creatable_format(format_combo_val)->m_extensions);
651
652   // enumerate through all of the child windows
653   wnd = NULL;
654   while((wnd = FindWindowEx(dlgwnd, wnd, NULL, NULL)) != NULL)
655   {
656      // get label text, removing trailing NULL
657      GetWindowText(wnd, t_buf1, ARRAY_LENGTH(t_buf1));
658      utf8_buf1 = utf8_from_tstring(t_buf1);
659      assert(utf8_buf1[strlen(utf8_buf1)-1] == ':');
660      utf8_buf1[strlen(utf8_buf1)-1] = '\0';
661
662      // find guide entry
663      while(guide->option_type && strcmp(utf8_buf1, guide->display_name))
664         guide++;
665
666      wnd = GetNextWindow(wnd, GW_HWNDNEXT);
667      if (wnd && guide)
668      {
669         // we now have the handle to the window, and the guide entry
670         has_option = option_resolution_contains(optspec, guide->parameter);
671
672         SendMessage(wnd, CB_GETLBTEXT, SendMessage(wnd, CB_GETCURSEL, 0, 0), (LPARAM) t_buf1);
673         SendMessage(wnd, CB_RESETCONTENT, 0, 0);
674
675         win_prepare_option_control(wnd,
676            has_option ? guide : NULL,
677            has_option ? optspec : NULL);
678      }
679      osd_free(utf8_buf1);
680   }
681}
682
683
684
685//============================================================
686//  storeval_option_resolution
687//============================================================
688
689struct storeval_optres_params
690{
691   struct file_dialog_params *fdparams;
692   const option_guide *guide_entry;
693};
694
695static void storeval_option_resolution(void *storeval_param, int val)
696{
697   option_resolution *resolution;
698   struct storeval_optres_params *params;
699   device_image_interface *dev;
700   char buf[16];
701
702   params = (struct storeval_optres_params *) storeval_param;
703   dev = params->fdparams->dev;
704
705   // create the resolution, if necessary
706   resolution = *(params->fdparams->create_args);
707   if (!resolution)
708   {
709      const option_guide *optguide = dev->device_get_creation_option_guide();
710      const image_device_format *format = dev->device_get_indexed_creatable_format(*(params->fdparams->create_format));
711
712      resolution = option_resolution_create(optguide, format->m_optspec);
713      if (!resolution)
714         return;
715      *(params->fdparams->create_args) = resolution;
716   }
717
718   snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
719   option_resolution_add_param(resolution, params->guide_entry->identifier, buf);
720}
721
722
723
724//============================================================
725//  build_option_dialog
726//============================================================
727
728static dialog_box *build_option_dialog(device_image_interface *dev, char *filter, size_t filter_len, int *create_format, option_resolution **create_args)
729{
730   dialog_box *dialog;
731   const option_guide *guide_entry;
732   int found, pos;
733   char buf[256];
734   struct file_dialog_params *params;
735   struct storeval_optres_params *storeval_params;
736   static const struct dialog_layout filedialog_layout = { 44, 220 };
737   const image_device_format *format;
738
739   // make the filter
740   pos = 0;
741   for (format = dev->device_get_creatable_formats(); format != NULL; format = format->m_next)
742   {
743      pos += add_filter_entry(filter + pos, filter_len - pos, format->m_description, format->m_extensions);
744   }
745
746   // create the dialog
747   dialog = win_dialog_init(NULL, &filedialog_layout);
748   if (!dialog)
749      goto error;
750
751   // allocate the params
752   params = (struct file_dialog_params *) win_dialog_malloc(dialog, sizeof(*params));
753   if (!params)
754      goto error;
755   params->dev = dev;
756   params->create_format = create_format;
757   params->create_args = create_args;
758
759   // set the notify handler; so that we get notified when the format dialog changed
760   if (win_dialog_add_notification(dialog, CDN_TYPECHANGE, format_combo_changed, params))
761      goto error;
762
763   // loop through the entries
764   for (guide_entry = dev->device_get_creation_option_guide(); guide_entry->option_type != OPTIONTYPE_END; guide_entry++)
765   {
766      // make sure that this entry is present on at least one option specification
767      found = FALSE;
768      for (format = dev->device_get_creatable_formats(); format != NULL; format = format->m_next)
769      {
770         if (option_resolution_contains(format->m_optspec, guide_entry->parameter))
771         {
772            found = TRUE;
773            break;
774         }
775      }
776
777      if (found)
778      {
779         storeval_params = (struct storeval_optres_params *) win_dialog_malloc(dialog, sizeof(*storeval_params));
780         if (!storeval_params)
781            goto error;
782         storeval_params->fdparams = params;
783         storeval_params->guide_entry = guide_entry;
784
785         // this option is present on at least one of the specs
786         switch(guide_entry->option_type)
787         {
788            case OPTIONTYPE_INT:
789               snprintf(buf, ARRAY_LENGTH(buf), "%s:", guide_entry->display_name);
790               if (win_dialog_add_combobox(dialog, buf, 0, storeval_option_resolution, storeval_params))
791                  goto error;
792               break;
793
794            default:
795               break;
796         }
797      }
798   }
799
800   return dialog;
801
802error:
803   if (dialog)
804      win_dialog_exit(dialog);
805   return NULL;
806}
807
808
809
810//============================================================
811//  copy_extension_list
812//============================================================
813
814static int copy_extension_list(char *dest, size_t dest_len, const char *extensions)
815{
816   const char *s;
817   int pos = 0;
818
819   // our extension lists are comma delimited; Win32 expects to see lists
820   // delimited by semicolons
821   s = extensions;
822   while(*s)
823   {
824      // append a semicolon if not at the beginning
825      if (s != extensions)
826         pos += snprintf(&dest[pos], dest_len - pos, ";");
827
828      // append ".*"
829      pos += snprintf(&dest[pos], dest_len - pos, "*.");
830
831      // append the file extension
832      while(*s && (*s != ','))
833      {
834         pos += snprintf(&dest[pos], dest_len - pos, "%c", *s);
835         s++;
836      }
837
838      // if we found a comma, advance
839      while(*s == ',')
840         s++;
841   }
842   return pos;
843}
844
845
846
847//============================================================
848//  add_filter_entry
849//============================================================
850
851static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions)
852{
853   int pos = 0;
854
855   // add the description
856   pos += snprintf(&dest[pos], dest_len - pos, "%s (", description);
857
858   // add the extensions to the description
859   pos += copy_extension_list(&dest[pos], dest_len - pos, extensions);
860
861   // add the trailing rparen and '|' character
862   pos += snprintf(&dest[pos], dest_len - pos, ")|");
863
864   // now add the extension list itself
865   pos += copy_extension_list(&dest[pos], dest_len - pos, extensions);
866
867   // append a '|'
868   pos += snprintf(&dest[pos], dest_len - pos, "|");
869
870   return pos;
871}
872
873
874
875//============================================================
876//  build_generic_filter
877//============================================================
878
879static void build_generic_filter(device_t *device, int is_save, char *filter, size_t filter_len)
880{
881   char *s;
882
883   const char *file_extension;
884
885   /* copy the string */
886   file_extension = downcast<const legacy_image_device_config_base *>(&device->baseconfig())->file_extensions();
887
888   // start writing the filter
889   s = filter;
890
891   // common image types
892   s += add_filter_entry(filter, filter_len, "Common image types", file_extension);
893
894   // all files
895   s += sprintf(s, "All files (*.*)|*.*|");
896
897   // compressed
898   if (!is_save)
899      s += sprintf(s, "Compressed Images (*.zip)|*.zip|");
900
901   *(s++) = '\0';
902}
903
904
905
906//============================================================
907//  change_device
908//============================================================
909
910static void change_device(HWND wnd, device_image_interface *image, int is_save)
911{
912   dialog_box *dialog = NULL;
913   char filter[2048];
914   char filename[MAX_PATH];
915   const char *initial_dir;
916   BOOL result;
917   int create_format = 0;
918   option_resolution *create_args = NULL;
919
920   // sanity check
921   assert(image != NULL);
922
923   // get the file
924   if (image->exists())
925   {
926      const char *imgname;
927      imgname = image->basename();
928      snprintf(filename, ARRAY_LENGTH(filename), "%s", imgname);
929   }
930   else
931   {
932      filename[0] = '\0';
933   }
934
935   // use image directory, if it is there
936   initial_dir = image->working_directory();
937
938   // add custom dialog elements, if appropriate
939   if (is_save
940      && (image->device_get_creation_option_guide() != NULL)
941      && (image->device_get_creatable_formats() != NULL))
942   {
943      dialog = build_option_dialog(image, filter, ARRAY_LENGTH(filter), &create_format, &create_args);
944      if (!dialog)
945         goto done;
946   }
947   else
948   {
949      // build a normal filter
950      build_generic_filter(&image->device(), is_save, filter, ARRAY_LENGTH(filter));
951   }
952
953   // display the dialog
954   result = win_file_dialog(image->device().machine, wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN,
955      dialog, filter, initial_dir, filename, ARRAY_LENGTH(filename));
956   if (result)
957   {
958      // mount the image
959      if (is_save)
960         (image_error_t)image->create(filename, image->device_get_indexed_creatable_format(create_format), create_args);
961      else
962         (image_error_t)image->load( filename);
963
964      // no need to check the returnvalue and show a messagebox anymore.
965      // a UI message will now be generated by the image code
966   }
967
968done:
969   if (dialog != NULL)
970      win_dialog_exit(dialog);
971   if (create_args != NULL)
972      option_resolution_close(create_args);
973}
974
975
976
977//============================================================
978//  pause
979//============================================================
980
981static void pause(running_machine *machine)
982{
983   if (!winwindow_ui_is_paused(machine)) {
984      machine->pause();
985   } else {
986      machine->resume();
987   }
988}
989
990
991
992//============================================================
993//  get_menu_item_string
994//============================================================
995
996static BOOL get_menu_item_string(HMENU menu, UINT item, BOOL by_position, HMENU *sub_menu, LPTSTR buffer, size_t buffer_len)
997{
998   MENUITEMINFO mii;
999
1000   // clear out results
1001   memset(buffer, '\0', sizeof(*buffer) * buffer_len);
1002   if (sub_menu)
1003      *sub_menu = NULL;
1004
1005   // prepare MENUITEMINFO structure
1006   memset(&mii, 0, sizeof(mii));
1007   mii.cbSize = sizeof(mii);
1008   mii.fMask = MIIM_TYPE | (sub_menu ? MIIM_SUBMENU : 0);
1009   mii.dwTypeData = buffer;
1010   mii.cch = buffer_len;
1011
1012   // call GetMenuItemInfo()
1013   if (!GetMenuItemInfo(menu, item, by_position, &mii))
1014      return FALSE;
1015
1016   // return results
1017   if (sub_menu)
1018      *sub_menu = mii.hSubMenu;
1019   if (mii.fType == MFT_SEPARATOR)
1020      _sntprintf(buffer, buffer_len, TEXT("-"));
1021   return TRUE;
1022}
1023
1024
1025
1026//============================================================
1027//  find_sub_menu
1028//============================================================
1029
1030static HMENU find_sub_menu(HMENU menu, const char *menutext, int create_sub_menu)
1031{
1032   int i;
1033   TCHAR buf[128];
1034   HMENU sub_menu;
1035
1036   while(*menutext)
1037   {
1038      TCHAR *t_menutext = tstring_from_utf8(menutext);
1039
1040      i = -1;
1041      do
1042      {
1043         if (!get_menu_item_string(menu, ++i, TRUE, &sub_menu, buf, ARRAY_LENGTH(buf)))
1044         {
1045            osd_free(t_menutext);
1046            return NULL;
1047         }
1048      }
1049      while(_tcscmp(t_menutext, buf));
1050
1051      osd_free(t_menutext);
1052
1053      if (!sub_menu && create_sub_menu)
1054      {
1055         MENUITEMINFO mii;
1056         memset(&mii, 0, sizeof(mii));
1057         mii.cbSize = sizeof(mii);
1058         mii.fMask = MIIM_SUBMENU;
1059         mii.hSubMenu = CreateMenu();
1060         if (!SetMenuItemInfo(menu, i, TRUE, &mii))
1061         {
1062            i = GetLastError();
1063            return NULL;
1064         }
1065         sub_menu = mii.hSubMenu;
1066      }
1067      menu = sub_menu;
1068      if (!menu)
1069         return NULL;
1070      menutext += strlen(menutext) + 1;
1071   }
1072   return menu;
1073}
1074
1075
1076
1077//============================================================
1078//  set_command_state
1079//============================================================
1080
1081static void set_command_state(HMENU menu_bar, UINT command, UINT state)
1082{
1083   BOOL result;
1084
1085   MENUITEMINFO mii;
1086
1087   memset(&mii, 0, sizeof(mii));
1088   mii.cbSize = sizeof(mii);
1089   mii.fMask = MIIM_STATE;
1090   mii.fState = state;
1091   result = SetMenuItemInfo(menu_bar, command, FALSE, &mii);
1092}
1093
1094
1095
1096
1097//============================================================
1098//  remove_menu_items
1099//============================================================
1100
1101static void remove_menu_items(HMENU menu)
1102{
1103   while(RemoveMenu(menu, 0, MF_BYPOSITION))
1104      ;
1105}
1106
1107
1108
1109//============================================================
1110//  setup_joystick_menu
1111//============================================================
1112
1113static void setup_joystick_menu(running_machine *machine, HMENU menu_bar)
1114{
1115   int joystick_count = 0;
1116   HMENU joystick_menu;
1117   int i;
1118   UINT command;
1119   HMENU submenu = NULL;
1120   const input_port_config *port;
1121   const input_field_config *field;
1122   const input_setting_config *setting;
1123   char buf[256];
1124   int child_count = 0;
1125
1126   use_input_categories = 0;
1127   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
1128   {
1129      for (field = port->fieldlist; field != NULL; field = field->next)
1130      {
1131         if (field->type == IPT_CATEGORY)
1132         {
1133            use_input_categories = 1;
1134            break;
1135         }
1136      }
1137   }
1138
1139   joystick_menu = find_sub_menu(menu_bar, "&Options\0&Joysticks\0", TRUE);
1140   if (!joystick_menu)
1141      return;
1142
1143   if (use_input_categories)
1144   {
1145      // using input categories
1146      for (port = machine->m_portlist.first(); port != NULL; port = port->next())
1147      {
1148         for (field = port->fieldlist; field != NULL; field = field->next)
1149         {
1150            if (field->type == IPT_CATEGORY)
1151            {
1152               submenu = CreateMenu();
1153               if (!submenu)
1154                  return;
1155
1156               // append all of the category settings
1157               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1158               {
1159                  command = ID_INPUT_0 + serial_number_from_input_item(machine, port, field, setting);
1160                  win_append_menu_utf8(submenu, MF_STRING, command, setting->name);
1161               }
1162
1163               // tack on the final items and the menu item
1164               command = ID_INPUT_0 + serial_number_from_input_item(machine, port, field, NULL);
1165               AppendMenu(submenu, MF_SEPARATOR, 0, NULL);
1166               AppendMenu(submenu, MF_STRING, command, TEXT("&Configure..."));
1167               win_append_menu_utf8(joystick_menu, MF_STRING | MF_POPUP, (UINT_PTR) submenu, field->name);
1168               child_count++;
1169            }
1170         }
1171      }
1172   }
1173   else
1174   {
1175      // set up joystick menu
1176      joystick_count = input_count_players(machine);
1177      if (joystick_count > 0)
1178      {
1179         for (i = 0; i < joystick_count; i++)
1180         {
1181            snprintf(buf, ARRAY_LENGTH(buf), "Joystick %i", i + 1);
1182            win_append_menu_utf8(joystick_menu, MF_STRING, ID_JOYSTICK_0 + i, buf);
1183            child_count++;
1184         }
1185      }
1186   }
1187
1188   // last but not least, enable the joystick menu (or not)
1189   set_command_state(menu_bar, ID_OPTIONS_JOYSTICKS, child_count ? MFS_ENABLED : MFS_GRAYED);
1190}
1191
1192
1193
1194//============================================================
1195//  is_windowed
1196//============================================================
1197
1198static int is_windowed(void)
1199{
1200   return video_config.windowed;
1201}
1202
1203
1204
1205//============================================================
1206//  frameskip_level_count
1207//============================================================
1208
1209static int frameskip_level_count(void)
1210{
1211   static int count = -1;
1212
1213   if (count < 0)
1214   {
1215      int frameskip_min = 0;
1216      int frameskip_max = 10;
1217      options_get_range_int(mame_options(), OPTION_FRAMESKIP, &frameskip_min, &frameskip_max);
1218      count = frameskip_max + 1;
1219   }
1220   return count;
1221}
1222
1223
1224
1225//============================================================
1226//  prepare_menus
1227//============================================================
1228
1229static void prepare_menus(HWND wnd)
1230{
1231   int i;
1232   char buf[MAX_PATH];
1233   TCHAR t_buf[MAX_PATH];
1234   const char *s;
1235   HMENU menu_bar;
1236   HMENU video_menu;
1237   HMENU device_menu;
1238   HMENU sub_menu;
1239   UINT_PTR new_item;
1240   UINT flags_for_exists;
1241   UINT flags_for_writing;
1242   device_image_interface *img = NULL;
1243   int has_config, has_dipswitch, has_keyboard, has_analog, has_misc;
1244   const input_port_config *port;
1245   const input_field_config *field;
1246   const input_setting_config *setting;
1247   int frameskip;
1248   int orientation;
1249   int speed;
1250   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
1251   win_window_info *window = (win_window_info *)ptr;
1252   const char *view_name;
1253   int view_index;
1254   UINT command;
1255   input_field_user_settings settings;
1256
1257   menu_bar = GetMenu(wnd);
1258   if (!menu_bar)
1259      return;
1260
1261   if (!joystick_menu_setup)
1262   {
1263      setup_joystick_menu(window->machine, menu_bar);
1264      joystick_menu_setup = 1;
1265   }
1266
1267   frameskip = window->machine->video().frameskip();
1268
1269   orientation = window->target->orientation();
1270
1271   speed = window->machine->video().throttled() ? window->machine->video().speed_factor() : 0;
1272
1273   has_config      = input_has_input_class(window->machine, INPUT_CLASS_CONFIG);
1274   has_dipswitch   = input_has_input_class(window->machine, INPUT_CLASS_DIPSWITCH);
1275   has_keyboard   = input_has_input_class(window->machine, INPUT_CLASS_KEYBOARD);
1276   has_misc      = input_has_input_class(window->machine, INPUT_CLASS_MISC);
1277
1278   has_analog = 0;
1279   for (port = window->machine->m_portlist.first(); port != NULL; port = port->next())
1280   {
1281      for (field = port->fieldlist; field != NULL; field = field->next)
1282      {
1283         if (port_type_is_analog(field->type))
1284         {
1285            has_analog = 1;
1286            break;
1287         }
1288      }
1289   }
1290
1291   set_command_state(menu_bar, ID_FILE_SAVESTATE,         state_filename[0] != '\0'               ? MFS_ENABLED : MFS_GRAYED);
1292
1293   set_command_state(menu_bar, ID_EDIT_PASTE,            inputx_can_post(window->machine)         ? MFS_ENABLED : MFS_GRAYED);
1294
1295   set_command_state(menu_bar, ID_OPTIONS_PAUSE,         winwindow_ui_is_paused(window->machine)      ? MFS_CHECKED : MFS_ENABLED);
1296   set_command_state(menu_bar, ID_OPTIONS_CONFIGURATION,   has_config                           ? MFS_ENABLED : MFS_GRAYED);
1297   set_command_state(menu_bar, ID_OPTIONS_DIPSWITCHES,      has_dipswitch                        ? MFS_ENABLED : MFS_GRAYED);
1298   set_command_state(menu_bar, ID_OPTIONS_MISCINPUT,      has_misc                           ? MFS_ENABLED : MFS_GRAYED);
1299   set_command_state(menu_bar, ID_OPTIONS_ANALOGCONTROLS,   has_analog                           ? MFS_ENABLED : MFS_GRAYED);
1300   set_command_state(menu_bar, ID_OPTIONS_FULLSCREEN,      !is_windowed()                        ? MFS_CHECKED : MFS_ENABLED);
1301   set_command_state(menu_bar, ID_OPTIONS_TOGGLEFPS,      ui_get_show_fps()                     ? MFS_CHECKED : MFS_ENABLED);
1302#if HAS_PROFILER
1303   set_command_state(menu_bar, ID_OPTIONS_PROFILER,      ui_get_show_profiler()                  ? MFS_CHECKED : MFS_ENABLED);
1304#endif
1305
1306   set_command_state(menu_bar, ID_KEYBOARD_EMULATED,      (has_keyboard) ?
1307                                                (!ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1308                                                                                    : MFS_GRAYED);
1309   set_command_state(menu_bar, ID_KEYBOARD_NATURAL,      (has_keyboard && inputx_can_post(window->machine)) ?                                                (ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1310                                                                                    : MFS_GRAYED);
1311   set_command_state(menu_bar, ID_KEYBOARD_CUSTOMIZE,      has_keyboard                        ? MFS_ENABLED : MFS_GRAYED);
1312
1313   set_command_state(menu_bar, ID_VIDEO_ROTATE_0,         (orientation == ROT0)                  ? MFS_CHECKED : MFS_ENABLED);
1314   set_command_state(menu_bar, ID_VIDEO_ROTATE_90,         (orientation == ROT90)                  ? MFS_CHECKED : MFS_ENABLED);
1315   set_command_state(menu_bar, ID_VIDEO_ROTATE_180,      (orientation == ROT180)                  ? MFS_CHECKED : MFS_ENABLED);
1316   set_command_state(menu_bar, ID_VIDEO_ROTATE_270,      (orientation == ROT270)                  ? MFS_CHECKED : MFS_ENABLED);
1317
1318   set_command_state(menu_bar, ID_THROTTLE_50,            (speed == 50)                        ? MFS_CHECKED : MFS_ENABLED);
1319   set_command_state(menu_bar, ID_THROTTLE_100,         (speed == 100)                        ? MFS_CHECKED : MFS_ENABLED);
1320   set_command_state(menu_bar, ID_THROTTLE_200,         (speed == 200)                        ? MFS_CHECKED : MFS_ENABLED);
1321   set_command_state(menu_bar, ID_THROTTLE_500,         (speed == 500)                        ? MFS_CHECKED : MFS_ENABLED);
1322   set_command_state(menu_bar, ID_THROTTLE_1000,         (speed == 1000)                        ? MFS_CHECKED : MFS_ENABLED);
1323   set_command_state(menu_bar, ID_THROTTLE_UNTHROTTLED,   (speed == 0)                        ? MFS_CHECKED : MFS_ENABLED);
1324
1325   set_command_state(menu_bar, ID_FRAMESKIP_AUTO,         (frameskip < 0)                        ? MFS_CHECKED : MFS_ENABLED);
1326   for (i = 0; i < frameskip_level_count(); i++)
1327      set_command_state(menu_bar, ID_FRAMESKIP_0 + i,      (frameskip == i)                     ? MFS_CHECKED : MFS_ENABLED);
1328
1329   // if we are using categorized input, we need to properly checkmark the categories
1330   if (use_input_categories)
1331   {
1332      for (port = window->machine->m_portlist.first(); port != NULL; port = port->next())
1333      {
1334         for (field = port->fieldlist; field != NULL; field = field->next)
1335         {
1336            if (field->type == IPT_CATEGORY)
1337            {
1338               input_field_get_user_settings(field, &settings);
1339               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1340               {
1341                  command = ID_INPUT_0 + serial_number_from_input_item(window->machine, port, field, setting);
1342                  set_command_state(menu_bar, command, (setting->value == settings.value) ? MFS_CHECKED : MFS_ENABLED);
1343               }
1344            }
1345         }
1346      }
1347   }
1348
1349   // set up screens in video menu
1350   video_menu = find_sub_menu(menu_bar, "&Options\0&Video\0", FALSE);
1351   do
1352   {
1353      get_menu_item_string(video_menu, 0, TRUE, NULL, t_buf, ARRAY_LENGTH(t_buf));
1354      if (_tcscmp(t_buf, TEXT("-")))
1355         RemoveMenu(video_menu, 0, MF_BYPOSITION);
1356   }
1357   while(_tcscmp(t_buf, TEXT("-")));
1358   i = 0;
1359   view_index = window->target->view();
1360   while((view_name = window->target->view_name(i)) != NULL)
1361   {
1362      TCHAR *t_view_name = tstring_from_utf8(view_name);
1363      InsertMenu(video_menu, i, MF_BYPOSITION | (i == view_index ? MF_CHECKED : 0),
1364         ID_VIDEO_VIEW_0 + i, t_view_name);
1365      osd_free(t_view_name);
1366      i++;
1367   }
1368
1369   // set up device menu; first remove all existing menu items
1370   device_menu = find_sub_menu(menu_bar, "&Devices\0", FALSE);
1371   remove_menu_items(device_menu);
1372
1373   int cnt = 0;
1374   // then set up the actual devices
1375   for (bool gotone = window->machine->m_devicelist.first(img); gotone; gotone = img->next(img))
1376   {
1377      new_item = ID_DEVICE_0 + (cnt * DEVOPTION_MAX);
1378      flags_for_exists = MF_STRING;
1379
1380      if (!img->exists())
1381         flags_for_exists |= MF_GRAYED;
1382
1383      flags_for_writing = flags_for_exists;
1384      if (!img->is_writable())
1385         flags_for_writing |= MF_GRAYED;
1386
1387      sub_menu = CreateMenu();
1388      win_append_menu_utf8(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      "Mount...");
1389
1390      if (img->image_config().is_creatable())
1391         win_append_menu_utf8(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   "Create...");
1392
1393      win_append_menu_utf8(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   "Unmount");
1394
1395      if (img->device().type() == CASSETTE)
1396      {
1397         cassette_state state;
1398         state = (cassette_state)(img->exists() ? (cassette_get_state(&img->device()) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED);
1399         win_append_menu_utf8(sub_menu, MF_SEPARATOR, 0, NULL);
1400         win_append_menu_utf8(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   "Pause/Stop");
1401         win_append_menu_utf8(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         "Play");
1402         win_append_menu_utf8(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      "Record");
1403         win_append_menu_utf8(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      "Rewind");
1404         win_append_menu_utf8(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   "Fast Forward");
1405      }
1406      s = img->exists() ? img->filename() : "[empty slot]";
1407
1408      snprintf(buf, ARRAY_LENGTH(buf), "%s: %s", img->image_config().devconfig().name(), s);
1409      win_append_menu_utf8(device_menu, MF_POPUP, (UINT_PTR)sub_menu, buf);
1410
1411      cnt++;
1412   }
1413}
1414
1415
1416
1417//============================================================
1418//  set_seped
1419//============================================================
1420
1421static void set_speed(running_machine *machine, int speed)
1422{
1423   if (speed != 0)
1424   {
1425      machine->video().set_speed_factor(speed);
1426      options_set_int(mame_options(), OPTION_SPEED, speed / 100, OPTION_PRIORITY_CMDLINE);
1427   }
1428
1429   machine->video().set_throttled(speed != 0);
1430   options_set_bool(mame_options(), OPTION_THROTTLE, (speed != 0), OPTION_PRIORITY_CMDLINE);
1431}
1432
1433
1434
1435//============================================================
1436//  win_toggle_menubar
1437//============================================================
1438
1439void win_toggle_menubar(void)
1440{
1441   win_window_info *window;
1442   LONG width_diff;
1443   LONG height_diff;
1444   DWORD style, exstyle;
1445   HWND hwnd;
1446   HMENU menu;
1447
1448   for (window = win_window_list; window != NULL; window = window->next)
1449   {
1450      RECT before_rect = { 100, 100, 200, 200 };
1451      RECT after_rect = { 100, 100, 200, 200 };
1452
1453      hwnd = window->hwnd;
1454
1455      // get current menu
1456      menu = GetMenu(hwnd);
1457
1458      // get before rect
1459      style = GetWindowLong(hwnd, GWL_STYLE);
1460      exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
1461      AdjustWindowRectEx(&before_rect, style, menu ? TRUE : FALSE, exstyle);
1462
1463      // toggle the menu
1464      if (menu)
1465      {
1466         SetProp(hwnd, TEXT("menu"), (HANDLE) menu);
1467         menu = NULL;
1468      }
1469      else
1470      {
1471         menu = (HMENU) GetProp(hwnd, TEXT("menu"));
1472      }
1473      SetMenu(hwnd, menu);
1474
1475      // get after rect, and width/height diff
1476      AdjustWindowRectEx(&after_rect, style, menu ? TRUE : FALSE, exstyle);
1477      width_diff = (after_rect.right - after_rect.left) - (before_rect.right - before_rect.left);
1478      height_diff = (after_rect.bottom - after_rect.top) - (before_rect.bottom - before_rect.top);
1479
1480      if (is_windowed())
1481      {
1482         RECT window_rect;
1483         GetWindowRect(hwnd, &window_rect);
1484         SetWindowPos(hwnd, HWND_TOP, 0, 0,
1485            window_rect.right - window_rect.left + width_diff,
1486            window_rect.bottom - window_rect.top + height_diff,
1487            SWP_NOMOVE | SWP_NOZORDER);
1488      }
1489
1490      RedrawWindow(hwnd, NULL, NULL, 0);
1491   }
1492}
1493
1494
1495
1496//============================================================
1497//  device_command
1498//============================================================
1499
1500static void device_command(HWND wnd, device_image_interface *img, int devoption)
1501{
1502   switch(devoption)
1503   {
1504      case DEVOPTION_OPEN:
1505         change_device(wnd, img, FALSE);
1506         break;
1507
1508      case DEVOPTION_CREATE:
1509         change_device(wnd, img, TRUE);
1510         break;
1511
1512      case DEVOPTION_CLOSE:
1513         img->unload();
1514         break;
1515
1516      default:
1517         if (img->device().type() == CASSETTE)
1518         {
1519            switch(devoption)
1520            {
1521               case DEVOPTION_CASSETTE_STOPPAUSE:
1522                  cassette_change_state(&img->device(), CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
1523                  break;
1524
1525               case DEVOPTION_CASSETTE_PLAY:
1526                  cassette_change_state(&img->device(), CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
1527                  break;
1528
1529               case DEVOPTION_CASSETTE_RECORD:
1530                  cassette_change_state(&img->device(), CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
1531                  break;
1532
1533               case DEVOPTION_CASSETTE_REWIND:
1534                  cassette_seek(&img->device(), -60.0, SEEK_CUR);
1535                  break;
1536
1537               case DEVOPTION_CASSETTE_FASTFORWARD:
1538                  cassette_seek(&img->device(), +60.0, SEEK_CUR);
1539                  break;
1540            }
1541         }
1542         break;
1543   }
1544}
1545
1546
1547
1548//============================================================
1549//  help_display
1550//============================================================
1551
1552static void help_display(HWND wnd, const char *chapter)
1553{
1554   typedef HWND (WINAPI *htmlhelpproc)(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD_PTR dwData);
1555   static htmlhelpproc htmlhelp;
1556   static DWORD htmlhelp_cookie;
1557   LPCSTR htmlhelp_funcname;
1558
1559   if (htmlhelp == NULL)
1560   {
1561#ifdef UNICODE
1562      htmlhelp_funcname = "HtmlHelpW";
1563#else
1564      htmlhelp_funcname = "HtmlHelpA";
1565#endif
1566      htmlhelp = (htmlhelpproc) GetProcAddress(LoadLibrary(TEXT("hhctrl.ocx")), htmlhelp_funcname);
1567      if (!htmlhelp)
1568         return;
1569      htmlhelp(NULL, NULL, 28 /*HH_INITIALIZE*/, (DWORD_PTR) &htmlhelp_cookie);
1570   }
1571
1572   // if full screen, turn it off
1573   if (!is_windowed())
1574      winwindow_toggle_full_screen();
1575
1576   {
1577      TCHAR *t_chapter = tstring_from_utf8(chapter);
1578      htmlhelp(wnd, t_chapter, 0 /*HH_DISPLAY_TOPIC*/, 0);
1579      osd_free(t_chapter);
1580   }
1581}
1582
1583
1584
1585//============================================================
1586//  help_about_mess
1587//============================================================
1588
1589static void help_about_mess(HWND wnd)
1590{
1591   help_display(wnd, "mess.chm::/windows/main.htm");
1592}
1593
1594
1595
1596//============================================================
1597//  help_about_thissystem
1598//============================================================
1599
1600static void help_about_thissystem(running_machine *machine, HWND wnd)
1601{
1602   char buf[256];
1603   snprintf(buf, ARRAY_LENGTH(buf), "mess.chm::/sysinfo/%s.htm", machine->gamedrv->name);
1604   help_display(wnd, buf);
1605}
1606
1607
1608
1609//============================================================
1610//  decode_deviceoption
1611//============================================================
1612
1613static device_image_interface *decode_deviceoption(running_machine *machine, int command, int *devoption)
1614{
1615   int absolute_index;
1616
1617   command -= ID_DEVICE_0;
1618   absolute_index = command / DEVOPTION_MAX;
1619
1620   if (devoption)
1621      *devoption = command % DEVOPTION_MAX;
1622
1623   return image_from_absolute_index(machine, absolute_index);
1624}
1625
1626
1627
1628//============================================================
1629//  set_window_orientation
1630//============================================================
1631
1632static void set_window_orientation(win_window_info *window, int orientation)
1633{
1634   window->target->set_orientation(orientation);
1635   if (window->target->is_ui_target())
1636   {
1637      render_container::user_settings settings;
1638      window->machine->render().ui_container().get_user_settings(settings);
1639      settings.m_orientation = orientation;
1640      window->machine->render().ui_container().set_user_settings(settings);
1641   }
1642   winwindow_video_window_update(window);
1643}
1644
1645
1646
1647//============================================================
1648//  pause_for_command
1649//============================================================
1650
1651static int pause_for_command(UINT command)
1652{
1653   // we really should be more conservative and only pause for commands
1654   // that do dialog stuff
1655   return (command != ID_OPTIONS_PAUSE);
1656}
1657
1658
1659
1660//============================================================
1661//  invoke_command
1662//============================================================
1663
1664static int invoke_command(HWND wnd, UINT command)
1665{
1666   int handled = 1;
1667   int dev_command;
1668   device_image_interface *img;
1669   UINT16 category;
1670   const input_field_config *field;
1671   const input_setting_config *setting;
1672   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
1673   win_window_info *window = (win_window_info *)ptr;
1674   input_field_user_settings settings;
1675
1676   // pause while invoking certain commands
1677   if (pause_for_command(command))
1678      winwindow_ui_pause_from_window_thread(window->machine, TRUE);
1679
1680   switch(command)
1681   {
1682      case ID_FILE_LOADSTATE_NEWUI:
1683         state_load(wnd, window->machine);
1684         break;
1685
1686      case ID_FILE_SAVESTATE:
1687         state_save(window->machine);
1688         break;
1689
1690      case ID_FILE_SAVESTATE_AS:
1691         state_save_as(wnd, window->machine);
1692         break;
1693
1694      case ID_FILE_SAVESCREENSHOT:
1695         window->machine->video().save_active_screen_snapshots();
1696         break;
1697
1698      case ID_FILE_EXIT_NEWUI:
1699         window->machine->schedule_exit();
1700         break;
1701
1702      case ID_EDIT_PASTE:
1703         PostMessage(wnd, WM_PASTE, 0, 0);
1704         break;
1705
1706      case ID_KEYBOARD_NATURAL:
1707         ui_set_use_natural_keyboard(window->machine, TRUE);
1708         break;
1709
1710      case ID_KEYBOARD_EMULATED:
1711         ui_set_use_natural_keyboard(window->machine, FALSE);
1712         break;
1713
1714      case ID_KEYBOARD_CUSTOMIZE:
1715         customize_keyboard(window->machine, wnd);
1716         break;
1717
1718      case ID_VIDEO_ROTATE_0:
1719         set_window_orientation(window, ROT0);
1720         break;
1721
1722      case ID_VIDEO_ROTATE_90:
1723         set_window_orientation(window, ROT90);
1724         break;
1725
1726      case ID_VIDEO_ROTATE_180:
1727         set_window_orientation(window, ROT180);
1728         break;
1729
1730      case ID_VIDEO_ROTATE_270:
1731         set_window_orientation(window, ROT270);
1732         break;
1733
1734      case ID_OPTIONS_PAUSE:
1735         pause(window->machine);
1736         break;
1737
1738      case ID_OPTIONS_HARDRESET:
1739         window->machine->schedule_hard_reset();
1740         break;
1741
1742      case ID_OPTIONS_SOFTRESET:
1743         window->machine->schedule_soft_reset();
1744         break;
1745
1746#if HAS_PROFILER
1747      case ID_OPTIONS_PROFILER:
1748         ui_set_show_profiler(!ui_get_show_profiler());
1749         break;
1750#endif // HAS_PROFILER
1751
1752      case ID_OPTIONS_DEBUGGER:
1753         debug_cpu_get_visible_cpu(window->machine)->debug()->halt_on_next_instruction("User-initiated break\n");
1754         break;
1755
1756      case ID_OPTIONS_CONFIGURATION:
1757         customize_configuration(window->machine, wnd);
1758         break;
1759
1760      case ID_OPTIONS_DIPSWITCHES:
1761         customize_dipswitches(window->machine, wnd);
1762         break;
1763
1764      case ID_OPTIONS_MISCINPUT:
1765         customize_miscinput(window->machine, wnd);
1766         break;
1767
1768      case ID_OPTIONS_ANALOGCONTROLS:
1769         customize_analogcontrols(window->machine, wnd);
1770         break;
1771
1772      case ID_OPTIONS_FULLSCREEN:
1773         winwindow_toggle_full_screen();
1774         break;
1775
1776      case ID_OPTIONS_TOGGLEFPS:
1777         ui_set_show_fps(!ui_get_show_fps());
1778         break;
1779
1780      case ID_OPTIONS_USEMOUSE:
1781         {
1782            // FIXME
1783//              extern int win_use_mouse;
1784//              win_use_mouse = !win_use_mouse;
1785         }
1786         break;
1787
1788      case ID_OPTIONS_TOGGLEMENUBAR:
1789         win_toggle_menubar();
1790         break;
1791
1792      case ID_FRAMESKIP_AUTO:
1793         window->machine->video().set_frameskip(-1);
1794         options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 1, OPTION_PRIORITY_CMDLINE);
1795         break;
1796
1797      case ID_HELP_ABOUT_NEWUI:
1798         help_about_mess(wnd);
1799         break;
1800
1801      case ID_HELP_ABOUTSYSTEM:
1802         help_about_thissystem(window->machine, wnd);
1803         break;
1804
1805      case ID_THROTTLE_50:
1806         set_speed(window->machine, 50);
1807         break;
1808
1809      case ID_THROTTLE_100:
1810         set_speed(window->machine, 100);
1811         break;
1812
1813      case ID_THROTTLE_200:
1814         set_speed(window->machine, 200);
1815         break;
1816
1817      case ID_THROTTLE_500:
1818         set_speed(window->machine, 500);
1819         break;
1820
1821      case ID_THROTTLE_1000:
1822         set_speed(window->machine, 1000);
1823         break;
1824
1825      case ID_THROTTLE_UNTHROTTLED:
1826         set_speed(window->machine, 0);
1827         break;
1828
1829      default:
1830         if ((command >= ID_FRAMESKIP_0) && (command < ID_FRAMESKIP_0 + frameskip_level_count()))
1831         {
1832            // change frameskip
1833            window->machine->video().set_frameskip(command - ID_FRAMESKIP_0);
1834            options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 0, OPTION_PRIORITY_CMDLINE);
1835            options_set_int(mame_options(), OPTION_FRAMESKIP, command - ID_FRAMESKIP_0, OPTION_PRIORITY_CMDLINE);
1836         }
1837         else if ((command >= ID_DEVICE_0) && (command < ID_DEVICE_0 + (IO_COUNT*DEVOPTION_MAX)))
1838         {
1839            // change device
1840            img = decode_deviceoption(window->machine, command, &dev_command);
1841            device_command(wnd, img, dev_command);
1842         }
1843         else if ((command >= ID_JOYSTICK_0) && (command < ID_JOYSTICK_0 + MAX_JOYSTICKS))
1844         {
1845            // customize joystick
1846            customize_joystick(window->machine, wnd, command - ID_JOYSTICK_0);
1847         }
1848         else if ((command >= ID_VIDEO_VIEW_0) && (command < ID_VIDEO_VIEW_0 + 1000))
1849         {
1850            // render views
1851            window->target->set_view(command - ID_VIDEO_VIEW_0);
1852         }
1853         else if (input_item_from_serial_number(window->machine, command - ID_INPUT_0, NULL, &field, &setting))
1854         {
1855            if ((field != NULL) && (field->type == IPT_CATEGORY) && (setting != NULL))
1856            {
1857               // change the input type for this category
1858               input_field_get_user_settings(field, &settings);
1859               settings.value = setting->value;
1860               input_field_set_user_settings(field, &settings);
1861            }
1862            else if ((field != NULL) && (field->type == IPT_CATEGORY) && (setting == NULL))
1863            {
1864               // customize the input type
1865               input_field_get_user_settings(field, &settings);
1866               category = 0;
1867
1868               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1869               {
1870                  if (settings.value == setting->value)
1871                  {
1872                     category = setting->category;
1873                  }
1874               }
1875               if (category)
1876                  customize_categorizedinput(window->machine, wnd, category);
1877            }
1878            else
1879            {
1880               // should never happen
1881               handled = 0;
1882            }
1883         }
1884         else
1885         {
1886            // bogus command
1887            handled = 0;
1888         }
1889         break;
1890   }
1891
1892   // resume emulation
1893   if (pause_for_command(command))
1894      winwindow_ui_pause_from_window_thread(window->machine, FALSE);
1895
1896   return handled;
1897}
1898
1899
1900
1901//============================================================
1902//  set_menu_text
1903//============================================================
1904
1905static void set_menu_text(HMENU menu_bar, int command, const char *text)
1906{
1907   TCHAR *t_text;
1908   MENUITEMINFO mii;
1909
1910   // convert to TCHAR
1911   t_text = tstring_from_utf8(text);
1912
1913   // invoke SetMenuItemInfo()
1914   memset(&mii, 0, sizeof(mii));
1915   mii.cbSize = sizeof(mii);
1916   mii.fMask = MIIM_TYPE;
1917   mii.dwTypeData = t_text;
1918   SetMenuItemInfo(menu_bar, command, FALSE, &mii);
1919
1920   // cleanup
1921   osd_free(t_text);
1922}
1923
1924
1925
1926//============================================================
1927//  win_setup_menus
1928//============================================================
1929
1930int win_setup_menus(running_machine *machine, HMODULE module, HMENU menu_bar)
1931{
1932   HMENU frameskip_menu;
1933   char buf[256];
1934   int i;
1935
1936   // verify that our magic numbers work
1937   assert((ID_DEVICE_0 + IO_COUNT * DEVOPTION_MAX) < ID_JOYSTICK_0);
1938
1939   // initialize critical values
1940   joystick_menu_setup = 0;
1941
1942   // remove the profiler menu item if it doesn't exist
1943#if HAS_PROFILER
1944   ui_set_show_profiler(0);
1945#else
1946   DeleteMenu(menu_bar, ID_OPTIONS_PROFILER, MF_BYCOMMAND);
1947#endif
1948
1949   if ((machine->debug_flags & DEBUG_FLAG_ENABLED) == 0)
1950      DeleteMenu(menu_bar, ID_OPTIONS_DEBUGGER, MF_BYCOMMAND);
1951
1952   // set up frameskip menu
1953   frameskip_menu = find_sub_menu(menu_bar, "&Options\0&Frameskip\0", FALSE);
1954   if (!frameskip_menu)
1955      return 1;
1956   for(i = 0; i < frameskip_level_count(); i++)
1957   {
1958      snprintf(buf, ARRAY_LENGTH(buf), "%i", i);
1959      win_append_menu_utf8(frameskip_menu, MF_STRING, ID_FRAMESKIP_0 + i, buf);
1960   }
1961
1962   // set the help menu to refer to this machine
1963   snprintf(buf, ARRAY_LENGTH(buf), "About %s (%s)...", machine->gamedrv->description, machine->gamedrv->name);
1964   set_menu_text(menu_bar, ID_HELP_ABOUTSYSTEM, buf);
1965
1966   // initialize state_filename for each driver, so we don't carry names in-between them
1967   {
1968      char *src;
1969      char *dst;
1970
1971      snprintf(state_filename, ARRAY_LENGTH(state_filename),
1972         "%s State", machine->gamedrv->description);
1973
1974      src = state_filename;
1975      dst = state_filename;
1976      do
1977      {
1978         if ((*src == '\0') || isalnum(*src) || isspace(*src) || strchr("(),.", *src))
1979            *(dst++) = *src;
1980      }
1981      while(*(src++));
1982   }
1983
1984   return 0;
1985}
1986
1987
1988
1989//============================================================
1990//  win_resource_module
1991//============================================================
1992
1993static HMODULE win_resource_module(void)
1994{
1995   static HMODULE module;
1996   if (module == NULL)
1997   {
1998      MEMORY_BASIC_INFORMATION info;
1999      if ((VirtualQuery((const void*)win_resource_module, &info, sizeof(info))) == sizeof(info))
2000         module = (HMODULE)info.AllocationBase;
2001   }
2002   return module;
2003}
2004
2005
2006
2007//============================================================
2008//  win_create_menu
2009//============================================================
2010
2011int win_create_menu(running_machine *machine, HMENU *menus)
2012{
2013   HMENU menu_bar = NULL;
2014   HMODULE module;
2015
2016//   if (options_get_bool(mame_options(), "newui"))
2017//   {
2018      module = win_resource_module();
2019      menu_bar = LoadMenu(module, MAKEINTRESOURCE(IDR_RUNTIME_MENU));
2020      if (!menu_bar)
2021         goto error;
2022
2023      if (win_setup_menus(machine, module, menu_bar))
2024         goto error;
2025//   }
2026
2027   *menus = menu_bar;
2028   return 0;
2029
2030error:
2031   if (menu_bar)
2032      DestroyMenu(menu_bar);
2033   return 1;
2034}
2035
2036
2037
2038//============================================================
2039//  winwindow_video_window_proc_ui
2040//============================================================
2041
2042LRESULT CALLBACK winwindow_video_window_proc_ui(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam)
2043{
2044   switch(message)
2045   {
2046      case WM_INITMENU:
2047         prepare_menus(wnd);
2048         break;
2049
2050      case WM_PASTE:
2051         {
2052            LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
2053            win_window_info *window = (win_window_info *)ptr;
2054            ui_paste(window->machine);
2055         }
2056         break;
2057
2058      case WM_COMMAND:
2059         if (invoke_command(wnd, wparam))
2060            break;
2061         /* fall through */
2062
2063      default:
2064         return winwindow_video_window_proc(wnd, message, wparam, lparam);
2065   }
2066   return 0;
2067}
src/mess/osd/winui/menu.h
r0r10019
1//============================================================
2//
3//  menu.h - Win32 MESS menu handling
4//
5//============================================================
6
7#ifndef MENU_H
8#define MENU_H
9
10#include <windows.h>
11
12
13
14//============================================================
15//  PROTOTYPES
16//============================================================
17
18int win_setup_menus(running_machine *machine, HMODULE module, HMENU menu_bar);
19LRESULT CALLBACK winwindow_video_window_proc_ui(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
20void win_toggle_menubar(void);
21int win_create_menu(running_machine *machine, HMENU *menus);
22
23
24#endif /* MENU_H */
src/mess/osd/winui/winutils.c
r0r10019
1//============================================================
2//
3//  winutils.c - Generic Win32 utility code
4//
5//============================================================
6
7// Needed for better file dialog
8#ifdef _WIN32_WINNT
9#undef _WIN32_WINNT
10#endif // _WIN32_WINNT
11#define _WIN32_WINNT 0x500
12
13// standard windows headers
14#define WIN32_LEAN_AND_MEAN
15#include <windows.h>
16#include <commdlg.h>
17#include <tchar.h>
18#include <stdlib.h>
19
20// MESS headers
21#include "winutils.h"
22#include "strconv.h"
23
24// stupid hack; not sure why this is needed
25#ifdef const
26#undef const
27#endif // const
28
29
30
31//============================================================
32//  win_get_file_name_dialog - sanitize all of the ugliness
33//  in invoking GetOpenFileName() and GetSaveFileName()
34//============================================================
35
36BOOL win_get_file_name_dialog(win_open_file_name *ofn)
37{
38   BOOL result = FALSE;
39   BOOL dialog_result;
40   OSVERSIONINFO vers;
41   OPENFILENAME os_ofn;
42   DWORD os_ofn_size;
43   LPTSTR t_filter = NULL;
44   LPTSTR t_file = NULL;
45   DWORD t_file_size = 0;
46   LPTSTR t_initial_directory = NULL;
47   LPTSTR buffer;
48   char *utf8_file;
49   int i;
50
51   // determine the version of Windows
52   memset(&vers, 0, sizeof(vers));
53   vers.dwOSVersionInfoSize = sizeof(vers);
54   GetVersionEx(&vers);
55
56   // based on the version of Windows, determine the correct struct size
57   if (vers.dwMajorVersion >= 5)
58   {
59      os_ofn_size = sizeof(os_ofn);
60   }
61   else
62   {
63#ifdef __GNUC__
64      os_ofn_size = 76;   // MinGW does not define OPENFILENAME_NT4
65#else
66      os_ofn_size = sizeof(OPENFILENAME_NT4);
67#endif
68   }
69
70   // do we have to translate the filter?
71   if (ofn->filter != NULL)
72   {
73      buffer = tstring_from_utf8(ofn->filter);
74      if (!buffer)
75         goto done;
76
77      // convert a pipe-char delimited string into a NUL delimited string
78      t_filter = (LPTSTR) alloca((_tcslen(buffer) + 2) * sizeof(*t_filter));
79      for (i = 0; buffer[i] != '\0'; i++)
80         t_filter[i] = (buffer[i] != '|') ? buffer[i] : '\0';
81      t_filter[i++] = '\0';
82      t_filter[i++] = '\0';
83      osd_free(buffer);
84   }
85
86   // do we need to translate the file parameter?
87   if (ofn->filename != NULL)
88   {
89      buffer = tstring_from_utf8(ofn->filename);
90      if (!buffer)
91         goto done;
92
93      t_file_size = MAX(_tcslen(buffer) + 1, MAX_PATH);
94      t_file = (LPTSTR) alloca(t_file_size * sizeof(*t_file));
95      _tcscpy(t_file, buffer);
96      osd_free(buffer);
97   }
98
99   // do we need to translate the initial directory?
100   if (ofn->initial_directory != NULL)
101   {
102      t_initial_directory = tstring_from_utf8(ofn->initial_directory);
103      if (t_initial_directory == NULL)
104         goto done;
105   }
106
107   // translate our custom structure to a native Win32 structure
108   memset(&os_ofn, 0, sizeof(os_ofn));
109   os_ofn.lStructSize = os_ofn_size;
110   os_ofn.hwndOwner = ofn->owner;
111   os_ofn.hInstance = ofn->instance;
112   os_ofn.lpstrFilter = t_filter;
113   os_ofn.nFilterIndex = ofn->filter_index;
114   os_ofn.lpstrFile = t_file;
115   os_ofn.nMaxFile = t_file_size;
116   os_ofn.lpstrInitialDir = t_initial_directory;
117   os_ofn.Flags = ofn->flags;
118   os_ofn.lCustData = ofn->custom_data;
119   os_ofn.lpfnHook = ofn->hook;
120   os_ofn.lpTemplateName = ofn->template_name;
121
122   // invoke the correct Win32 call
123   switch(ofn->type)
124   {
125      case WIN_FILE_DIALOG_OPEN:
126         dialog_result = GetOpenFileName(&os_ofn);
127         break;
128
129      case WIN_FILE_DIALOG_SAVE:
130         dialog_result = GetSaveFileName(&os_ofn);
131         break;
132
133      default:
134         // should not reach here
135         dialog_result = FALSE;
136         break;
137   }
138
139   // copy data out
140   ofn->filter_index = os_ofn.nFilterIndex;
141   ofn->flags = os_ofn.Flags;
142
143   // copy file back out into passed structure
144   if (t_file != NULL)
145   {
146      utf8_file = utf8_from_tstring(t_file);
147      if (!utf8_file)
148         goto done;
149
150      snprintf(ofn->filename, ARRAY_LENGTH(ofn->filename), "%s", utf8_file);
151      osd_free(utf8_file);
152   }
153
154   // we've completed the process
155   result = dialog_result;
156
157done:
158   if (t_initial_directory != NULL)
159      osd_free(t_initial_directory);
160   return result;
161}
162
163
164
165//============================================================
166//  win_scroll_window
167//============================================================
168
169void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line)
170{
171   SCROLLINFO si;
172   int scroll_pos;
173
174   // retrieve vital info about the scroll bar
175   memset(&si, 0, sizeof(si));
176   si.cbSize = sizeof(si);
177   si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
178   GetScrollInfo(window, scroll_bar, &si);
179
180   scroll_pos = si.nPos;
181
182   // change scroll_pos in accordance with this message
183   switch(LOWORD(wparam))
184   {
185      case SB_BOTTOM:
186         scroll_pos = si.nMax;
187         break;
188      case SB_LINEDOWN:
189         scroll_pos += scroll_delta_line;
190         break;
191      case SB_LINEUP:
192         scroll_pos -= scroll_delta_line;
193         break;
194      case SB_PAGEDOWN:
195         scroll_pos += scroll_delta_line;
196         break;
197      case SB_PAGEUP:
198         scroll_pos -= scroll_delta_line;
199         break;
200      case SB_THUMBPOSITION:
201      case SB_THUMBTRACK:
202         scroll_pos = HIWORD(wparam);
203         break;
204      case SB_TOP:
205         scroll_pos = si.nMin;
206         break;
207   }
208
209   // max out the scroll bar value
210   if (scroll_pos < si.nMin)
211      scroll_pos = si.nMin;
212   else if (scroll_pos > (si.nMax - si.nPage))
213      scroll_pos = (si.nMax - si.nPage);
214
215   // if the value changed, set the scroll position
216   if (scroll_pos != si.nPos)
217   {
218      SetScrollPos(window, scroll_bar, scroll_pos, TRUE);
219      ScrollWindowEx(window, 0, si.nPos - scroll_pos, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE);
220   }
221}
222
223
224
225//============================================================
226//  win_append_menu_utf8
227//============================================================
228
229BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char *item)
230{
231   BOOL result;
232   const TCHAR *t_item = (const TCHAR*)item;
233   TCHAR *t_str = NULL;
234
235   // only convert string when it's no a bitmap
236   if (!(flags & MF_BITMAP) && item) {
237      t_str = tstring_from_utf8(item);
238      t_item = t_str;
239   }
240
241   result = AppendMenu(menu, flags, id, t_item);
242
243   if (t_str)
244      osd_free(t_str);
245
246   return result;
247}
src/mess/osd/winui/opcntrl.c
r0r10019
1//============================================================
2//
3//  opcntrl.c - Code for handling option resolutions in
4//  Win32 controls
5//
6//  This code was factored out of menu.c when Windows Imgtool
7//  started to have dynamic controls
8//
9//============================================================
10
11#include <windows.h>
12#include <commctrl.h>
13#include <stdio.h>
14#include <tchar.h>
15#include <assert.h>
16
17#include "opcntrl.h"
18#include "strconv.h"
19#include "winutf8.h"
20
21
22static const TCHAR guide_prop[] = TEXT("opcntrl_guide");
23static const TCHAR spec_prop[] = TEXT("opcntrl_optspec");
24static const TCHAR value_prop[] = TEXT("opcntrl_value");
25
26
27
28static int get_option_count(const option_guide *guide,
29   const char *optspec)
30{
31   struct OptionRange ranges[128];
32   int count = 0, i;
33
34   option_resolution_listranges(optspec, guide->parameter,
35      ranges, ARRAY_LENGTH(ranges));
36
37   for (i = 0; ranges[i].min >= 0; i++)
38      count += ranges[i].max - ranges[i].min + 1;
39   return count;
40}
41
42
43
44static BOOL prepare_combobox(HWND control, const option_guide *guide,
45   const char *optspec)
46{
47   struct OptionRange ranges[128];
48   int default_value, default_index, current_index, option_count;
49   int i, j, k;
50   BOOL has_option;
51   TCHAR buf1[256];
52   TCHAR buf2[256];
53   LPTSTR tempstr;
54
55   SendMessage(control, CB_GETLBTEXT, SendMessage(control, CB_GETCURSEL, 0, 0), (LPARAM) buf1);
56   SendMessage(control, CB_RESETCONTENT, 0, 0);
57   has_option = guide && optspec;
58
59   if (has_option)
60   {
61      if ((guide->option_type != OPTIONTYPE_INT) && (guide->option_type != OPTIONTYPE_ENUM_BEGIN))
62         goto unexpected;
63
64      option_resolution_listranges(optspec, guide->parameter,
65         ranges, ARRAY_LENGTH(ranges));
66      option_resolution_getdefault(optspec, guide->parameter, &default_value);
67
68      option_count = 0;
69      default_index = -1;
70      current_index = -1;
71
72      for (i = 0; ranges[i].min >= 0; i++)
73      {
74         for (j = ranges[i].min; j <= ranges[i].max; j++)
75         {
76            if (guide->option_type == OPTIONTYPE_INT)
77            {
78               _sntprintf(buf2, ARRAY_LENGTH(buf2), TEXT("%d"), j);
79               SendMessage(control, CB_ADDSTRING, 0, (LPARAM) buf2);
80            }
81            else if (guide->option_type == OPTIONTYPE_ENUM_BEGIN)
82            {
83               for (k = 1; guide[k].option_type == OPTIONTYPE_ENUM_VALUE; k++)
84               {
85                  if (guide[k].parameter == j)
86                     break;
87               }
88               if (guide[k].option_type != OPTIONTYPE_ENUM_VALUE)
89                  goto unexpected;
90               tempstr = tstring_from_utf8(guide[k].display_name);
91               SendMessage(control, CB_ADDSTRING, 0, (LPARAM) tempstr);
92               osd_free(tempstr);
93            }
94            else
95               goto unexpected;
96
97            SendMessage(control, CB_SETITEMDATA, option_count, j);
98
99            if (j == default_value)
100               default_index = option_count;
101            if (!_tcscmp(buf1, buf2))
102               current_index = option_count;
103            option_count++;
104         }
105      }
106
107      // if there is only one option, it is effectively disabled
108      if (option_count <= 1)
109         has_option = FALSE;
110
111      if (current_index >= 0)
112         SendMessage(control, CB_SETCURSEL, current_index, 0);
113      else if (default_index >= 0)
114         SendMessage(control, CB_SETCURSEL, default_index, 0);
115   }
116   else
117   {
118      // this item is non applicable
119      SendMessage(control, CB_ADDSTRING, 0, (LPARAM) TEXT("N/A"));
120      SendMessage(control, CB_SETCURSEL, 0, 0);
121   }
122   EnableWindow(control, has_option);
123   return TRUE;
124
125unexpected:
126   assert(FALSE);
127   return FALSE;
128}
129
130
131
132static BOOL check_combobox(HWND control)
133{
134   return TRUE;
135}
136
137
138
139static BOOL prepare_editbox(HWND control, const option_guide *guide,
140   const char *optspec)
141{
142   optreserr_t err = OPTIONRESOLUTION_ERROR_SUCCESS;
143   char buf[32];
144   int val, has_option, option_count;
145
146   has_option = guide && optspec;
147   buf[0] = '\0';
148
149   if (has_option)
150   {
151      switch(guide->option_type)
152      {
153         case OPTIONTYPE_STRING:
154            break;
155
156         case OPTIONTYPE_INT:
157            err = option_resolution_getdefault(optspec, guide->parameter, &val);
158            if (err)
159               goto done;
160            _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
161            break;
162
163         default:
164            err = OPTIONRESOLTUION_ERROR_INTERNAL;
165            goto done;
166      }
167   }
168
169   if (has_option)
170   {
171      option_count = get_option_count(guide, optspec);
172      if (option_count <= 1)
173         has_option = FALSE;
174   }
175
176done:
177   assert(err != OPTIONRESOLTUION_ERROR_INTERNAL);
178   win_set_window_text_utf8(control, buf);
179   EnableWindow(control, !err && has_option);
180   return err == OPTIONRESOLUTION_ERROR_SUCCESS;
181}
182
183
184
185static BOOL check_editbox(HWND control)
186{
187   char buf[256];
188   const option_guide *guide;
189   const char *optspec;
190   optreserr_t err;
191   HANDLE h;
192   void *val;
193   int i_val;
194
195
196   guide = (const option_guide *) GetProp(control, guide_prop);
197   optspec = (const char *) GetProp(control, spec_prop);
198
199   win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf));
200
201   switch(guide->option_type)
202   {
203      case OPTIONTYPE_INT:
204         i_val = atoi(buf);
205         err = option_resolution_isvalidvalue(optspec, guide->parameter, i_val);
206         if (err)
207         {
208            h = GetProp(control, value_prop);
209            val = (void*) h;
210            _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
211            win_set_window_text_utf8(control, buf);
212         }
213         else
214         {
215            SetProp(control, value_prop, (HANDLE) i_val);
216         }
217         break;
218
219      default:
220         err = OPTIONRESOLTUION_ERROR_INTERNAL;
221         goto done;
222   }
223
224done:
225   assert(err != OPTIONRESOLTUION_ERROR_INTERNAL);
226   return (err != OPTIONRESOLUTION_ERROR_SUCCESS);
227}
228
229
230
231BOOL win_prepare_option_control(HWND control, const option_guide *guide,
232   const char *optspec)
233{
234   BOOL rc = FALSE;
235   TCHAR class_name[32];
236
237   SetProp(control, guide_prop, (HANDLE) guide);
238   SetProp(control, spec_prop, (HANDLE) optspec);
239   GetClassName(control, class_name, sizeof(class_name)
240      / sizeof(class_name[0]));
241
242   if (!_tcsicmp(class_name, TEXT("ComboBox")))
243      rc = prepare_combobox(control, guide, optspec);
244   else if (!_tcsicmp(class_name, TEXT("Edit")))
245      rc = prepare_editbox(control, guide, optspec);
246
247   return rc;
248}
249
250
251
252BOOL win_check_option_control(HWND control)
253{
254   BOOL rc = FALSE;
255   TCHAR class_name[32];
256
257   GetClassName(control, class_name, sizeof(class_name)
258      / sizeof(class_name[0]));
259
260   if (!_tcsicmp(class_name, TEXT("ComboBox")))
261      rc = check_combobox(control);
262   else if (!_tcsicmp(class_name, TEXT("Edit")))
263      rc = check_editbox(control);
264
265   return rc;
266}
267
268
269
270BOOL win_adjust_option_control(HWND control, int delta)
271{
272   const option_guide *guide;
273   const char *optspec;
274   struct OptionRange ranges[128];
275   char buf[64];
276   int val, original_val, i;
277   BOOL changed = FALSE;
278
279   guide = (const option_guide *) GetProp(control, guide_prop);
280   optspec = (const char *) GetProp(control, spec_prop);
281
282   assert(guide->option_type == OPTIONTYPE_INT);
283
284   if (delta == 0)
285      return TRUE;
286
287   option_resolution_listranges(optspec, guide->parameter,
288      ranges, ARRAY_LENGTH(ranges));
289
290   win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf));
291   original_val = atoi(buf);
292   val = original_val + delta;
293
294   for (i = 0; ranges[i].min >= 0; i++)
295   {
296      if (ranges[i].min > val)
297      {
298         if ((delta < 0) && (i > 0))
299            val = ranges[i-1].max;
300         else
301            val = ranges[i].min;
302         changed = TRUE;
303         break;
304      }
305   }
306   if (!changed && (i > 0) && (ranges[i-1].max < val))
307      val = ranges[i-1].max;
308
309   if (val != original_val)
310   {
311      _snprintf(buf, ARRAY_LENGTH(buf), "%d", val);
312      win_set_window_text_utf8(control, buf);
313   }
314   return TRUE;
315}
316
317
318
319optreserr_t win_add_resolution_parameter(HWND control, option_resolution *resolution)
320{
321   const option_guide *guide;
322   char buf[256];
323   optreserr_t err;
324   const char *text;
325   const char *old_text;
326   int i;
327
328   if (!win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf)))
329   {
330      err = OPTIONRESOLTUION_ERROR_INTERNAL;
331      return err;
332   }
333   text = buf;
334
335   guide = (const option_guide *) GetProp(control, guide_prop);
336   if (!guide)
337   {
338      err = OPTIONRESOLTUION_ERROR_INTERNAL;
339      return err;
340   }
341
342   if (guide->option_type == OPTIONTYPE_ENUM_BEGIN)
343   {
344      /* need to convert display name to identifier */
345      old_text = text;
346      text = NULL;
347
348      for (i = 1; guide[i].option_type == OPTIONTYPE_ENUM_VALUE; i++)
349      {
350         if (!strcmp(guide[i].display_name, old_text))
351         {
352            text = guide[i].identifier;
353            break;
354         }
355      }
356   }
357
358   if (text)
359   {
360      err = option_resolution_add_param(resolution, guide->identifier, text);
361      if (err)
362         return err;
363   }
364
365   err = OPTIONRESOLUTION_ERROR_SUCCESS;
366
367   return err;
368}
369
370
371
src/mess/osd/winui/winui.mak
r10018r10019
1#####################################################################
2# winui.mak
3#####################################################################
1###########################################################################
2#
3#   winui.mak
4#
5#   MESS Windows-specific makefile
6#
7###########################################################################
48
5#-------------------------------------------------
6# object and source roots
7#-------------------------------------------------
8# messui executable name
9MESSUINAME = messui
10MESSUIEXE = $(PREFIX)$(PREFIXSDL)$(MESSUINAME)$(SUFFIX)$(SUFFIX64)$(SUFFIXDEBUG)$(EXE)
11BUILD += $(MESSUIEXE)
12WINUISRC = $(SRC)/osd/winui
13WINUIOBJ = $(OBJ)/osd/winui
9# build the executable names
10RCFLAGS += -DMESS
11DEFS += -DMENU_BAR=1
1412
15OBJDIRS += $(WINUIOBJ)
16
1713MESS_WINUISRC = $(SRC)/mess/osd/winui
1814MESS_WINUIOBJ = $(OBJ)/mess/osd/winui
19OBJDIRS += $(MESS_WINUIOBJ)
20CFLAGS += -I$(WINUISRC) -I$(MESS_WINUISRC)
21RCFLAGS += -DMESS
15WINUISRC = $(SRC)/osd/winui
16WINUIOBJ = $(OBJ)/osd/winui
2217
23#-------------------------------------------------
24# Windows UI object files
25#-------------------------------------------------
18RESFILE = $(MESS_WINUIOBJ)/messui.res
2619
27WINUIOBJS += \
28   $(WINUIOBJ)/mui_util.o \
29   $(WINUIOBJ)/directinput.o \
30   $(WINUIOBJ)/dijoystick.o \
31   $(WINUIOBJ)/directdraw.o \
32   $(WINUIOBJ)/directories.o \
33   $(WINUIOBJ)/mui_audit.o \
34   $(WINUIOBJ)/columnedit.o \
35   $(WINUIOBJ)/screenshot.o \
36   $(WINUIOBJ)/treeview.o \
37   $(WINUIOBJ)/splitters.o \
38   $(WINUIOBJ)/bitmask.o \
39   $(WINUIOBJ)/datamap.o \
40   $(WINUIOBJ)/dxdecode.o \
41   $(WINUIOBJ)/picker.o \
42   $(WINUIOBJ)/properties.o \
43   $(WINUIOBJ)/tabview.o \
44   $(WINUIOBJ)/help.o \
45   $(WINUIOBJ)/history.o \
46   $(WINUIOBJ)/dialogs.o \
47   $(WINUIOBJ)/dirwatch.o   \
48   $(WINUIOBJ)/datafile.o   \
49   $(WINUIOBJ)/mui_opts.o \
50   $(WINUIOBJ)/winui.o \
51   $(WINUIOBJ)/helpids.o \
52   $(WINUIOBJ)/mui_main.o \
20CFLAGS += \
21   -I$(MESSSRC)/osd/winui
22   
23OBJDIRS += \
24   $(MESSOBJ)/osd \
25   $(MESSOBJ)/osd/winui
26
27OSDOBJS += \
5328   $(MESS_WINUIOBJ)/messui.o \
5429   $(MESS_WINUIOBJ)/optionsms.o \
5530   $(MESS_WINUIOBJ)/layoutms.o \
r10018r10019
5833   $(MESS_WINUIOBJ)/swconfig.o \
5934   $(MESS_WINUIOBJ)/softwarepicker.o \
6035   $(MESS_WINUIOBJ)/softwarelist.o \
61   $(MESS_WINUIOBJ)/devview.o
36   $(MESS_WINUIOBJ)/devview.o   \
37   $(MESS_WINUIOBJ)/dialog.o   \
38   $(MESS_WINUIOBJ)/menu.o   \
39   $(MESS_WINUIOBJ)/opcntrl.o   \
40   $(MESS_WINUIOBJ)/winutils.o
6241
63
64# add resource file
65RESFILEUI = $(MESS_WINUIOBJ)/messui.res
66
67#-------------------------------------------------
68# rules for creating helpids.c
69#-------------------------------------------------
70
71$(WINUIOBJ)/helpids.o : $(WINUIOBJ)/helpids.c
72   @echo Compiling $<...
73   $(CC) $(CDEFS) $(CFLAGS) -c $< -o $@
74
75$(WINUIOBJ)/helpids.c : $(WINUIOBJ)/mkhelp$(EXE) $(WINUISRC)/resource.h $(WINUISRC)/resource.hm $(WINUISRC)/mameui.rc
76   @"$(WINUIOBJ)/mkhelp$(EXE)" $(WINUISRC)/mameui.rc >$@
77
78# rule to build the generator
79$(WINUIOBJ)/mkhelp$(EXE): $(WINUIOBJ)/mkhelp.o $(LIBOCORE)
80   @echo Linking $@...
81   $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
82
83
84#####################################################################
85# compiler
86
87#
88# Preprocessor Definitions
89#
90
91ifdef MSVC_BUILD
92DEFS += -DWINVER=0x0500 -D_CRT_NON_CONFORMING_SWPRINTFS
93else
94DEFS += -DWINVER=0x0400
95endif
96
97DEFS += \
98   -D_WIN32_IE=0x0501 \
99   -DDECL_SPEC= \
100   -DZEXTERN=extern \
101
102#   -DSHOW_UNAVAILABLE_FOLDER
103
104
105
106#####################################################################
107# Linker
108
109ifndef MSVC_BUILD
110LDFLAGS_UI = $(LDFLAGS)
111else
112
113LIBS += -lkernel32 \
114        -lshell32 \
115        -lcomctl32 \
116        -lcomdlg32 \
117        -ladvapi32\
118
119# workaround to allow linking with MSVC
120LDFLAGS_UI = $(subst /ENTRY:wmainCRTStartup,,$(LDFLAGS))
121endif
122
123
124
125#####################################################################
126# Resources
127
128
12942$(MESS_WINUIOBJ)/messui.res:   $(WINUISRC)/mameui.rc $(MESS_WINUISRC)/messui.rc $(WINUISRC)/resource.h $(MESS_WINUISRC)/resourcems.h $(WINUIOBJ)/mamevers.rc
13043   @echo Compiling resources $<...
13144   $(RC) $(RCDEFS) $(RCFLAGS) --include-dir $(WINUISRC) --include-dir $(MESS_WINUISRC) --include-dir $(WINUIOBJ) -o $@ -i $(MESS_WINUISRC)/messui.rc
r10018r10019
13346$(WINUIOBJ)/mamevers.rc: $(OBJ)/build/verinfo$(EXE) $(SRC)/version.c
13447   @echo Emitting $@...
13548   @"$(VERINFO)" -b mess $(SRC)/version.c  > $@
49   
50$(LIBOSD): $(OSDOBJS)
13651
137$(MESSUIEXE): $(WINUIOBJS) $(VERSIONOBJ) $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBDASM) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(SOFTFLOAT) $(LIBOCORE_NOMAIN) $(RESFILEUI)
138   @echo Linking $@...
139   $(LD) $(LDFLAGS_UI) -mwindows $^ $(LIBS) $(EXPAT) -o $@
52$(LIBOCORE): $(OSDCOREOBJS)
53
54$(LIBOCORE_NOMAIN): $(OSDCOREOBJS:$(WINOBJ)/main.o=)
src/mess/osd/winui/winutils.h
r0r10019
1//============================================================
2//
3//  winutils.h - Generic Win32 utility code in MESS
4//
5//============================================================
6
7#ifndef WINUTILS_H
8#define WINUTILS_H
9
10#include <windows.h>
11#include "osdcore.h"
12
13
14//============================================================
15//  FILE DIALOG WRAPPERS
16//============================================================
17
18enum _win_file_dialog_type
19{
20   WIN_FILE_DIALOG_OPEN = 1,
21   WIN_FILE_DIALOG_SAVE
22};
23typedef enum _win_file_dialog_type win_file_dialog_type;
24
25typedef struct _win_open_file_name win_open_file_name;
26struct _win_open_file_name
27{
28   win_file_dialog_type   type;            // type of file dialog
29   HWND               owner;            // owner of the dialog
30   HINSTANCE            instance;         // instance
31   const char *         filter;            // pipe char ("|") delimited strings
32   DWORD               filter_index;      // index into filter
33   char               filename[MAX_PATH];   // filename buffer
34   const char *         initial_directory;   // initial directory for dialog
35   DWORD               flags;            // standard flags
36   LPARAM               custom_data;      // custom data for dialog hook
37   LPOFNHOOKPROC         hook;            // custom dialog hook
38   LPCTSTR               template_name;      // custom dialog template
39};
40
41BOOL win_get_file_name_dialog(win_open_file_name *ofn);
42
43
44
45//============================================================
46//  MISC
47//============================================================
48
49void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line);
50
51BOOL win_append_menu_utf8(HMENU menu, UINT flags, UINT_PTR id, const char *item);
52
53#endif // WINUTILS_H
src/mess/osd/winui/opcntrl.h
r0r10019
1//============================================================
2//
3//  opcntrl.h - Code for handling option resolutions in
4//  Win32 controls
5//
6//============================================================
7
8#ifndef OPCNTRL_H
9#define OPCNTRL_H
10
11#include <windows.h>
12#include "opresolv.h"
13
14BOOL win_prepare_option_control(HWND control, const option_guide *guide,
15   const char *optspec);
16BOOL win_check_option_control(HWND control);
17BOOL win_adjust_option_control(HWND control, int delta);
18optreserr_t win_add_resolution_parameter(HWND control, option_resolution *resolution);
19
20#endif // OPCNTRL_H
src/mess/osd/winui/messres.h
r0r10019
1//{{NO_DEPENDENCIES}}
2// Microsoft Visual C++ generated include file.
3// Used by mess.rc
4//
5#define ID_FILE_LOADSTATE_NEWUI         3101
6#define ID_FILE_SAVESTATE               3102
7#define ID_FILE_SAVESTATE_AS            3103
8#define ID_FILE_SAVESCREENSHOT          3104
9#define ID_FILE_EXIT_NEWUI              3105
10#define ID_EDIT_PASTE                   3106
11#define ID_OPTIONS_HIDEMENUBAR          3107
12#define ID_OPTIONS_KEYBOARD             3108
13#define ID_OPTIONS_CONFIGURATION        3109
14#define ID_OPTIONS_DIPSWITCHES          3110
15#define ID_OPTIONS_MISCINPUT            3111
16#define ID_OPTIONS_USEMOUSE             3112
17#define ID_OPTIONS_TOGGLEMENUBAR        3113
18#define ID_OPTIONS_SOFTRESET            3114
19#define ID_OPTIONS_HARDRESET            3115
20#define ID_OPTIONS_FRAMESKIP            3116
21#define ID_OPTIONS_PAUSE                3117
22#define ID_OPTIONS_JOYSTICKS            3118
23#define ID_OPTIONS_ANALOGCONTROLS       3119
24#define ID_OPTIONS_FULLSCREEN           3120
25#define ID_OPTIONS_PROFILER             3121
26#define ID_OPTIONS_TOGGLEFPS            3122
27#define ID_OPTIONS_DEBUGGER             3123
28#define ID_KEYBOARD_EMULATED            3124
29#define ID_KEYBOARD_NATURAL             3125
30#define ID_KEYBOARD_CUSTOMIZE           3126
31#define ID_VIDEO_ROTATE_0               3127
32#define ID_VIDEO_ROTATE_90              3128
33#define ID_VIDEO_ROTATE_180             3129
34#define ID_VIDEO_ROTATE_270             3130
35#define ID_THROTTLE_50                  3131
36#define ID_THROTTLE_100                 3132
37#define ID_THROTTLE_200                 3133
38#define ID_THROTTLE_500                 3134
39#define ID_THROTTLE_1000                3135
40#define ID_THROTTLE_UNTHROTTLED         3136
41#define ID_FRAMESKIP_AUTO               3137
42#define ID_DEVICES                      3138
43#define ID_HELP_ABOUT_NEWUI             3139
44#define ID_HELP_ABOUTSYSTEM             3140
45#define IDI_ICON_CART                   3200
46#define IDI_ICON_HARD                   3201
47#define IDI_ICON_CASS                   3202
48#define IDI_ICON_FLOP                   3203
49#define IDI_ICON_PRIN                   3204
50#define IDI_ICON_SERL                   3205
51#define IDI_ICON_SNAP                   3206
52#define IDR_RUNTIME_MENU                3300
53
54// Next default values for new objects
55//
56#ifdef APSTUDIO_INVOKED
57#ifndef APSTUDIO_READONLY_SYMBOLS
58#define _APS_NEXT_RESOURCE_VALUE        3129
59#define _APS_NEXT_COMMAND_VALUE         40008
60#define _APS_NEXT_CONTROL_VALUE         3306
61#define _APS_NEXT_SYMED_VALUE           101
62#endif
63#endif
src/mess/osd/winui/mess.rc
r0r10019
1// Microsoft Visual C++ generated resource script.
2//
3#include "messres.h"
4 
5#define APSTUDIO_READONLY_SYMBOLS
6/////////////////////////////////////////////////////////////////////////////
7//
8// Generated from the TEXTINCLUDE 2 resource.
9//
10#include <windows.h>
11/////////////////////////////////////////////////////////////////////////////
12#undef APSTUDIO_READONLY_SYMBOLS
13 
14/////////////////////////////////////////////////////////////////////////////
15// English (U.S.) resources
16 
17#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
18#ifdef _WIN32
19LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
20#pragma code_page(1252)
21#endif //_WIN32
22 
23/////////////////////////////////////////////////////////////////////////////
24//
25// Menu
26//
27 
28IDR_RUNTIME_MENU MENU
29BEGIN
30    POPUP "&File"
31    BEGIN
32        MENUITEM "&Load State...",              ID_FILE_LOADSTATE_NEWUI
33        MENUITEM "&Save State",                 ID_FILE_SAVESTATE
34        MENUITEM "S&ave State As...",           ID_FILE_SAVESTATE_AS
35        MENUITEM SEPARATOR
36        MENUITEM "Save Sc&reenshot",            ID_FILE_SAVESCREENSHOT
37        MENUITEM SEPARATOR
38        MENUITEM "&Exit",                       ID_FILE_EXIT_NEWUI
39    END
40    POPUP "&Edit"
41    BEGIN
42        MENUITEM "Paste",                       ID_EDIT_PASTE
43    END
44    POPUP "&Options"
45    BEGIN
46        MENUITEM "&Pause",                      ID_OPTIONS_PAUSE, GRAYED
47        MENUITEM "Soft &Reset",                 ID_OPTIONS_SOFTRESET
48        MENUITEM "Ha&rd Reset",                 ID_OPTIONS_HARDRESET
49        MENUITEM SEPARATOR
50        POPUP "&Keyboard"
51        BEGIN
52            MENUITEM "Emulated",                    ID_KEYBOARD_EMULATED
53            MENUITEM "Natural",                     ID_KEYBOARD_NATURAL
54            MENUITEM SEPARATOR
55            MENUITEM "Customize Emulated Keyboard...",     ID_KEYBOARD_CUSTOMIZE
56        END
57        MENUITEM "&Joysticks",                  ID_OPTIONS_JOYSTICKS, GRAYED
58        POPUP "&Video"
59        BEGIN
60          MENUITEM SEPARATOR
61          MENUITEM "Rotate 0 degrees",        ID_VIDEO_ROTATE_0
62          MENUITEM "Rotate 90 degrees",       ID_VIDEO_ROTATE_90
63          MENUITEM "Rotate 180 degrees",      ID_VIDEO_ROTATE_180
64          MENUITEM "Rotate 270 degrees",      ID_VIDEO_ROTATE_270
65        END
66        MENUITEM "&Configuration...",           ID_OPTIONS_CONFIGURATION
67        MENUITEM "&DIP Switches...",            ID_OPTIONS_DIPSWITCHES
68        MENUITEM "&Miscellaneous Inputs...",    ID_OPTIONS_MISCINPUT
69        MENUITEM "&Analog Controls...",         ID_OPTIONS_ANALOGCONTROLS
70        MENUITEM SEPARATOR
71        POPUP "&Frameskip"
72        BEGIN
73            MENUITEM "Auto",                        ID_FRAMESKIP_AUTO
74        END
75        POPUP "Maximum &Speed"
76        BEGIN
77            MENUITEM "50%",                         ID_THROTTLE_50
78            MENUITEM "100%",                        ID_THROTTLE_100
79            MENUITEM "200%",                        ID_THROTTLE_200
80            MENUITEM "500%",                        ID_THROTTLE_500
81            MENUITEM "1000%",                       ID_THROTTLE_1000
82            MENUITEM "Unlimited",                   ID_THROTTLE_UNTHROTTLED
83        END
84        MENUITEM "Show &FPS",                   ID_OPTIONS_TOGGLEFPS
85        MENUITEM SEPARATOR
86        MENUITEM "&Hide Menubar",             ID_OPTIONS_TOGGLEMENUBAR
87        MENUITEM "&Full Screen",             ID_OPTIONS_FULLSCREEN
88        MENUITEM "Show P&rofiler",              ID_OPTIONS_PROFILER, GRAYED
89        MENUITEM "&Debugger...",                ID_OPTIONS_DEBUGGER
90    END
91    POPUP "&Devices"
92    BEGIN
93        MENUITEM SEPARATOR
94    END
95    POPUP "&Help"
96    BEGIN
97        MENUITEM "About This System...",        ID_HELP_ABOUTSYSTEM
98        MENUITEM "&About MESS...",              ID_HELP_ABOUT_NEWUI
99    END
100END
101 
102 
103#ifdef APSTUDIO_INVOKED
104/////////////////////////////////////////////////////////////////////////////
105//
106// TEXTINCLUDE
107//
108 
1091 TEXTINCLUDE
110BEGIN
111    "messres.h\0"
112END
113 
1142 TEXTINCLUDE
115BEGIN
116    "#include <windows.h>\0"
117END
118 
1193 TEXTINCLUDE
120BEGIN
121    "\r\n"
122    "\0"
123END
124 
125#endif    // APSTUDIO_INVOKED
126 
127 
128 
129/////////////////////////////////////////////////////////////////////////////
130//
131// DESIGNINFO
132//
133 
134IDI_ICON_MESS           ICON    DISCARDABLE     "../../osd/winui/res/mess.ico"
135 
136 
137 
138/////////////////////////////////////////////////////////////////////////////
139//
140// DESIGNINFO
141//
142 
143#ifdef APSTUDIO_INVOKED
144GUIDELINES DESIGNINFO
145BEGIN
146    IDD_TAPEDIALOG, DIALOG
147    BEGIN
148        LEFTMARGIN, 7
149        RIGHTMARGIN, 165
150        TOPMARGIN, 7
151        BOTTOMMARGIN, 58
152    END
153END
154#endif    // APSTUDIO_INVOKED
155 
156#endif    // English (U.S.) resources
157/////////////////////////////////////////////////////////////////////////////
158 
159 
160 
161#ifndef APSTUDIO_INVOKED
162/////////////////////////////////////////////////////////////////////////////
163//
164// Generated from the TEXTINCLUDE 3 resource.
165//
166 
167 
168/////////////////////////////////////////////////////////////////////////////
169#endif    // not APSTUDIO_INVOKED
170 
src/mess/osd/winui/propertiesms.c
r10018r10019
495495   // MESS specific stuff
496496   datamap_add(properties_datamap, IDC_DIR_LIST,            DM_STRING,   NULL);
497497   datamap_add(properties_datamap, IDC_RAM_COMBOBOX,         DM_INT,      OPTION_RAMSIZE);
498   datamap_add(properties_datamap, IDC_USE_NEW_UI,            DM_BOOL,   "newui");
498//   datamap_add(properties_datamap, IDC_USE_NEW_UI,            DM_BOOL,   "newui");
499499
500500   // set up callbacks
501501   datamap_set_callback(properties_datamap, IDC_DIR_LIST,      DCT_READ_CONTROL,      DirListReadControl);
src/mess/osd/winui/resourcems.h
r10018r10019
33
44#include "resource.h"
55
6#include "..\windows\messres.h"
6#include "messres.h"
77
88#define IDC_SPLITTER3                2000
99#define IDC_SWTAB                       2001

Previous 15994 Revisions Next


© 1998-2018 The MESS Team