src/mess/osd/windows/dialog.c
| r10018 | r10019 | |
| 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 | | |
| 28 | | enum |
| 29 | | { |
| 30 | | TRIGGER_INITDIALOG = 1, |
| 31 | | TRIGGER_APPLY = 2, |
| 32 | | TRIGGER_CHANGED = 4 |
| 33 | | }; |
| 34 | | |
| 35 | | typedef LRESULT (*trigger_function)(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 36 | | |
| 37 | | struct 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 | | |
| 50 | | struct dialog_object_pool |
| 51 | | { |
| 52 | | HGDIOBJ objects[16]; |
| 53 | | }; |
| 54 | | |
| 55 | | struct _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 | | |
| 79 | | enum _seqselect_state |
| 80 | | { |
| 81 | | SEQSELECT_STATE_NOT_POLLING, |
| 82 | | SEQSELECT_STATE_POLLING, |
| 83 | | SEQSELECT_STATE_POLLING_COMPLETE |
| 84 | | }; |
| 85 | | typedef enum _seqselect_state seqselect_state; |
| 86 | | |
| 87 | | // this is the structure that gets associated with each input_seq edit box |
| 88 | | typedef struct _seqselect_info seqselect_info; |
| 89 | | struct _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 | | |
| 146 | | static running_machine *Machine; // HACK - please fix |
| 147 | | |
| 148 | | static double pixels_to_xdlgunits; |
| 149 | | static double pixels_to_ydlgunits; |
| 150 | | |
| 151 | | static const struct dialog_layout default_layout = { 80, 140 }; |
| 152 | | static const WORD dlgitem_button[] = { 0xFFFF, 0x0080 }; |
| 153 | | static const WORD dlgitem_edit[] = { 0xFFFF, 0x0081 }; |
| 154 | | static const WORD dlgitem_static[] = { 0xFFFF, 0x0082 }; |
| 155 | | static const WORD dlgitem_listbox[] = { 0xFFFF, 0x0083 }; |
| 156 | | static const WORD dlgitem_scrollbar[] = { 0xFFFF, 0x0084 }; |
| 157 | | static const WORD dlgitem_combobox[] = { 0xFFFF, 0x0085 }; |
| 158 | | |
| 159 | | |
| 160 | | //============================================================ |
| 161 | | // PROTOTYPES |
| 162 | | //============================================================ |
| 163 | | |
| 164 | | static void dialog_prime(dialog_box *di); |
| 165 | | static 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 | | |
| 174 | | static 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 | | |
| 191 | | static 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 | | |
| 221 | | done: |
| 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 | | |
| 235 | | static 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 | | |
| 272 | | static 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 | | |
| 356 | | static 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 | | |
| 404 | | static 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 | | |
| 417 | | static 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 | | |
| 468 | | static 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 | | |
| 504 | | static 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 | | |
| 539 | | static 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 | | |
| 562 | | static 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 | | |
| 577 | | static 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 | | |
| 601 | | static 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 | | |
| 616 | | static 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 | | |
| 629 | | static 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 | | |
| 640 | | dialog_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 | | |
| 691 | | error: |
| 692 | | if (di) |
| 693 | | win_dialog_exit(di); |
| 694 | | return NULL; |
| 695 | | } |
| 696 | | |
| 697 | | |
| 698 | | |
| 699 | | //============================================================ |
| 700 | | // dialog_new_control |
| 701 | | //============================================================ |
| 702 | | |
| 703 | | static 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 | | |
| 715 | | static 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 | | |
| 736 | | static 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 | | |
| 749 | | int 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 | | |
| 789 | | done: |
| 790 | | return rc; |
| 791 | | } |
| 792 | | |
| 793 | | |
| 794 | | |
| 795 | | //============================================================ |
| 796 | | // win_dialog_add_combobox |
| 797 | | //============================================================ |
| 798 | | |
| 799 | | int 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 | | |
| 812 | | int 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 | | |
| 846 | | struct adjuster_sb_stuff |
| 847 | | { |
| 848 | | WNDPROC oldwndproc; |
| 849 | | int min_value; |
| 850 | | int max_value; |
| 851 | | }; |
| 852 | | |
| 853 | | static 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 | | |
| 907 | | static 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 | | |
| 932 | | int 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 | | |
| 983 | | error: |
| 984 | | return 1; |
| 985 | | } |
| 986 | | |
| 987 | | |
| 988 | | |
| 989 | | //============================================================ |
| 990 | | // win_dialog_add_slider |
| 991 | | //============================================================ |
| 992 | | |
| 993 | | int 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 | | |
| 1031 | | error: |
| 1032 | | return 1; |
| 1033 | | } |
| 1034 | | |
| 1035 | | |
| 1036 | | |
| 1037 | | //============================================================ |
| 1038 | | // get_seqselect_info |
| 1039 | | //============================================================ |
| 1040 | | |
| 1041 | | static 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 | | |
| 1054 | | static 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 | | |
| 1089 | | static 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 | | |
| 1151 | | static 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 | | |
| 1171 | | static 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 | | |
| 1228 | | static 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 | | |
| 1246 | | static 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 | | |
| 1261 | | static 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 | | |
| 1297 | | int 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 | | |
| 1378 | | int 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 | | |
| 1395 | | int 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 | | |
| 1422 | | static 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 | | |
| 1483 | | done: |
| 1484 | | ReleaseDC(NULL, dc); |
| 1485 | | return bitmap; |
| 1486 | | } |
| 1487 | | |
| 1488 | | //============================================================ |
| 1489 | | // win_dialog_add_image |
| 1490 | | //============================================================ |
| 1491 | | |
| 1492 | | int 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 | | |
| 1525 | | int 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 | | |
| 1536 | | void 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 | | |
| 1562 | | void *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 | | |
| 1573 | | char *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 | | |
| 1584 | | WCHAR *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 | | |
| 1598 | | static 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 | | |
| 1610 | | static 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 | | |
| 1622 | | void 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 | | |
| 1641 | | static 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 | | |
| 1695 | | BOOL 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/menu.c
| r10018 | r10019 | |
| 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 |
| 37 | | extern 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 | | |
| 52 | | enum |
| 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 | | |
| 76 | | static int use_input_categories; |
| 77 | | static int joystick_menu_setup; |
| 78 | | static char state_filename[MAX_PATH]; |
| 79 | | |
| 80 | | static 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 | | |
| 88 | | static 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 | | |
| 130 | | static 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 | | |
| 169 | | static 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 | | |
| 235 | | done: |
| 236 | | if (dlg) |
| 237 | | win_dialog_exit(dlg); |
| 238 | | } |
| 239 | | |
| 240 | | |
| 241 | | |
| 242 | | //============================================================ |
| 243 | | // customize_joystick |
| 244 | | //============================================================ |
| 245 | | |
| 246 | | static 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 | | |
| 257 | | static 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 | | |
| 268 | | static 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 | | |
| 279 | | static 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 | | |
| 291 | | static 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 | | |
| 307 | | static 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 | | |
| 351 | | done: |
| 352 | | if (dlg) |
| 353 | | win_dialog_exit(dlg); |
| 354 | | } |
| 355 | | |
| 356 | | |
| 357 | | |
| 358 | | //============================================================ |
| 359 | | // customize_dipswitches |
| 360 | | //============================================================ |
| 361 | | |
| 362 | | static 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 | | |
| 373 | | static 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 | | |
| 384 | | enum |
| 385 | | { |
| 386 | | ANALOG_ITEM_KEYSPEED, |
| 387 | | ANALOG_ITEM_CENTERSPEED, |
| 388 | | ANALOG_ITEM_REVERSE, |
| 389 | | ANALOG_ITEM_SENSITIVITY |
| 390 | | }; |
| 391 | | |
| 392 | | |
| 393 | | |
| 394 | | static 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 | | |
| 413 | | static void store_delta(void *param, int val) |
| 414 | | { |
| 415 | | store_analogitem(param, val, ANALOG_ITEM_KEYSPEED); |
| 416 | | } |
| 417 | | |
| 418 | | |
| 419 | | |
| 420 | | static void store_centerdelta(void *param, int val) |
| 421 | | { |
| 422 | | store_analogitem(param, val, ANALOG_ITEM_CENTERSPEED); |
| 423 | | } |
| 424 | | |
| 425 | | |
| 426 | | |
| 427 | | static void store_reverse(void *param, int val) |
| 428 | | { |
| 429 | | store_analogitem(param, val, ANALOG_ITEM_REVERSE); |
| 430 | | } |
| 431 | | |
| 432 | | |
| 433 | | |
| 434 | | static void store_sensitivity(void *param, int val) |
| 435 | | { |
| 436 | | store_analogitem(param, val, ANALOG_ITEM_SENSITIVITY); |
| 437 | | } |
| 438 | | |
| 439 | | |
| 440 | | |
| 441 | | static int port_type_is_analog(int type) |
| 442 | | { |
| 443 | | return (type >= __ipt_analog_start && type <= __ipt_analog_end); |
| 444 | | } |
| 445 | | |
| 446 | | |
| 447 | | |
| 448 | | static 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 | | |
| 503 | | done: |
| 504 | | if (dlg) |
| 505 | | win_dialog_exit(dlg); |
| 506 | | } |
| 507 | | |
| 508 | | |
| 509 | | //============================================================ |
| 510 | | // win_dirname |
| 511 | | //============================================================ |
| 512 | | |
| 513 | | static 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 | | |
| 549 | | static 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 | | |
| 595 | | static void state_load(HWND wnd, running_machine *machine) |
| 596 | | { |
| 597 | | state_dialog(wnd, WIN_FILE_DIALOG_OPEN, OFN_FILEMUSTEXIST, TRUE, machine); |
| 598 | | } |
| 599 | | |
| 600 | | static void state_save_as(HWND wnd, running_machine *machine) |
| 601 | | { |
| 602 | | state_dialog(wnd, WIN_FILE_DIALOG_SAVE, OFN_OVERWRITEPROMPT, FALSE, machine); |
| 603 | | } |
| 604 | | |
| 605 | | static void state_save(running_machine *machine) |
| 606 | | { |
| 607 | | machine->schedule_save(state_filename); |
| 608 | | } |
| 609 | | |
| 610 | | |
| 611 | | |
| 612 | | //============================================================ |
| 613 | | // format_combo_changed |
| 614 | | //============================================================ |
| 615 | | |
| 616 | | struct file_dialog_params |
| 617 | | { |
| 618 | | device_image_interface *dev; |
| 619 | | int *create_format; |
| 620 | | option_resolution **create_args; |
| 621 | | }; |
| 622 | | |
| 623 | | static 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 | | |
| 689 | | struct storeval_optres_params |
| 690 | | { |
| 691 | | struct file_dialog_params *fdparams; |
| 692 | | const option_guide *guide_entry; |
| 693 | | }; |
| 694 | | |
| 695 | | static 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 | | |
| 728 | | static 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 | | |
| 802 | | error: |
| 803 | | if (dialog) |
| 804 | | win_dialog_exit(dialog); |
| 805 | | return NULL; |
| 806 | | } |
| 807 | | |
| 808 | | |
| 809 | | |
| 810 | | //============================================================ |
| 811 | | // copy_extension_list |
| 812 | | //============================================================ |
| 813 | | |
| 814 | | static 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 | | |
| 851 | | static 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 | | |
| 879 | | static 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 | | |
| 910 | | static 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 | | |
| 968 | | done: |
| 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 | | |
| 981 | | static 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 | | |
| 996 | | static 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 | | |
| 1030 | | static 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 | | |
| 1081 | | static 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 | | |
| 1101 | | static 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 | | |
| 1113 | | static 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 | | |
| 1198 | | static int is_windowed(void) |
| 1199 | | { |
| 1200 | | return video_config.windowed; |
| 1201 | | } |
| 1202 | | |
| 1203 | | |
| 1204 | | |
| 1205 | | //============================================================ |
| 1206 | | // frameskip_level_count |
| 1207 | | //============================================================ |
| 1208 | | |
| 1209 | | static 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 | | |
| 1229 | | static 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 | | |
| 1421 | | static 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 | | |
| 1439 | | void 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 | | |
| 1500 | | static 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 | | |
| 1552 | | static 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 | | |
| 1589 | | static 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 | | |
| 1600 | | static 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 | | |
| 1613 | | static 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 | | |
| 1632 | | static 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 | | |
| 1651 | | static 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 | | |
| 1664 | | static 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 | | |
| 1905 | | static 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 | | |
| 1930 | | int 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 | | |
| 1993 | | static 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 |
| 2012 | | int 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 | | |
| 2031 | | error: |
| 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 | | |
| 2044 | | LRESULT 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/winui/dialog.c
| r0 | r10019 | |
| 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 | |
| 28 | enum |
| 29 | { |
| 30 | TRIGGER_INITDIALOG = 1, |
| 31 | TRIGGER_APPLY = 2, |
| 32 | TRIGGER_CHANGED = 4 |
| 33 | }; |
| 34 | |
| 35 | typedef LRESULT (*trigger_function)(dialog_box *dialog, HWND dlgwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 36 | |
| 37 | struct 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 | |
| 50 | struct dialog_object_pool |
| 51 | { |
| 52 | HGDIOBJ objects[16]; |
| 53 | }; |
| 54 | |
| 55 | struct _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 | |
| 79 | enum _seqselect_state |
| 80 | { |
| 81 | SEQSELECT_STATE_NOT_POLLING, |
| 82 | SEQSELECT_STATE_POLLING, |
| 83 | SEQSELECT_STATE_POLLING_COMPLETE |
| 84 | }; |
| 85 | typedef enum _seqselect_state seqselect_state; |
| 86 | |
| 87 | // this is the structure that gets associated with each input_seq edit box |
| 88 | typedef struct _seqselect_info seqselect_info; |
| 89 | struct _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 | |
| 146 | static running_machine *Machine; // HACK - please fix |
| 147 | |
| 148 | static double pixels_to_xdlgunits; |
| 149 | static double pixels_to_ydlgunits; |
| 150 | |
| 151 | static const struct dialog_layout default_layout = { 80, 140 }; |
| 152 | static const WORD dlgitem_button[] = { 0xFFFF, 0x0080 }; |
| 153 | static const WORD dlgitem_edit[] = { 0xFFFF, 0x0081 }; |
| 154 | static const WORD dlgitem_static[] = { 0xFFFF, 0x0082 }; |
| 155 | static const WORD dlgitem_listbox[] = { 0xFFFF, 0x0083 }; |
| 156 | static const WORD dlgitem_scrollbar[] = { 0xFFFF, 0x0084 }; |
| 157 | static const WORD dlgitem_combobox[] = { 0xFFFF, 0x0085 }; |
| 158 | |
| 159 | |
| 160 | //============================================================ |
| 161 | // PROTOTYPES |
| 162 | //============================================================ |
| 163 | |
| 164 | static void dialog_prime(dialog_box *di); |
| 165 | static 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 | |
| 174 | static 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 | |
| 191 | static 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 | |
| 221 | done: |
| 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 | |
| 235 | static 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 | |
| 272 | static 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 | |
| 356 | static 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 | |
| 404 | static 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 | |
| 417 | static 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 | |
| 468 | static 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 | |
| 504 | static 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 | |
| 539 | static 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 | |
| 562 | static 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 | |
| 577 | static 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 | |
| 601 | static 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 | |
| 616 | static 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 | |
| 629 | static 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 | |
| 640 | dialog_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 | |
| 691 | error: |
| 692 | if (di) |
| 693 | win_dialog_exit(di); |
| 694 | return NULL; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | |
| 699 | //============================================================ |
| 700 | // dialog_new_control |
| 701 | //============================================================ |
| 702 | |
| 703 | static 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 | |
| 715 | static 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 | |
| 736 | static 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 | |
| 749 | int 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 | |
| 789 | done: |
| 790 | return rc; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | |
| 795 | //============================================================ |
| 796 | // win_dialog_add_combobox |
| 797 | //============================================================ |
| 798 | |
| 799 | int 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 | |
| 812 | int 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 | |
| 846 | struct adjuster_sb_stuff |
| 847 | { |
| 848 | WNDPROC oldwndproc; |
| 849 | int min_value; |
| 850 | int max_value; |
| 851 | }; |
| 852 | |
| 853 | static 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 | |
| 907 | static 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 | |
| 932 | int 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 | |
| 983 | error: |
| 984 | return 1; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | |
| 989 | //============================================================ |
| 990 | // win_dialog_add_slider |
| 991 | //============================================================ |
| 992 | |
| 993 | int 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 | |
| 1031 | error: |
| 1032 | return 1; |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | //============================================================ |
| 1038 | // get_seqselect_info |
| 1039 | //============================================================ |
| 1040 | |
| 1041 | static 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 | |
| 1054 | static 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 | |
| 1089 | static 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 | |
| 1151 | static 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 | |
| 1171 | static 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 | |
| 1228 | static 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 | |
| 1246 | static 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 | |
| 1261 | static 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 | |
| 1297 | int 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 | |
| 1378 | int 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 | |
| 1395 | int 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 | |
| 1422 | static 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 | |
| 1483 | done: |
| 1484 | ReleaseDC(NULL, dc); |
| 1485 | return bitmap; |
| 1486 | } |
| 1487 | |
| 1488 | //============================================================ |
| 1489 | // win_dialog_add_image |
| 1490 | //============================================================ |
| 1491 | |
| 1492 | int 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 | |
| 1525 | int 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 | |
| 1536 | void 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 | |
| 1562 | void *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 | |
| 1573 | char *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 | |
| 1584 | WCHAR *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 | |
| 1598 | static 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 | |
| 1610 | static 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 | |
| 1622 | void 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 | |
| 1641 | static 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 | |
| 1695 | BOOL 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/menu.c
| r0 | r10019 | |
| 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 |
| 37 | extern 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 | |
| 52 | enum |
| 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 | |
| 76 | static int use_input_categories; |
| 77 | static int joystick_menu_setup; |
| 78 | static char state_filename[MAX_PATH]; |
| 79 | |
| 80 | static 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 | |
| 88 | static 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 | |
| 130 | static 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 | |
| 169 | static 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 | |
| 235 | done: |
| 236 | if (dlg) |
| 237 | win_dialog_exit(dlg); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | //============================================================ |
| 243 | // customize_joystick |
| 244 | //============================================================ |
| 245 | |
| 246 | static 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 | |
| 257 | static 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 | |
| 268 | static 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 | |
| 279 | static 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 | |
| 291 | static 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 | |
| 307 | static 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 | |
| 351 | done: |
| 352 | if (dlg) |
| 353 | win_dialog_exit(dlg); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | |
| 358 | //============================================================ |
| 359 | // customize_dipswitches |
| 360 | //============================================================ |
| 361 | |
| 362 | static 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 | |
| 373 | static 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 | |
| 384 | enum |
| 385 | { |
| 386 | ANALOG_ITEM_KEYSPEED, |
| 387 | ANALOG_ITEM_CENTERSPEED, |
| 388 | ANALOG_ITEM_REVERSE, |
| 389 | ANALOG_ITEM_SENSITIVITY |
| 390 | }; |
| 391 | |
| 392 | |
| 393 | |
| 394 | static 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 | |
| 413 | static void store_delta(void *param, int val) |
| 414 | { |
| 415 | store_analogitem(param, val, ANALOG_ITEM_KEYSPEED); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | |
| 420 | static void store_centerdelta(void *param, int val) |
| 421 | { |
| 422 | store_analogitem(param, val, ANALOG_ITEM_CENTERSPEED); |
| 423 | } |
| 424 | |
| 425 | |
| 426 | |
| 427 | static void store_reverse(void *param, int val) |
| 428 | { |
| 429 | store_analogitem(param, val, ANALOG_ITEM_REVERSE); |
| 430 | } |
| 431 | |
| 432 | |
| 433 | |
| 434 | static void store_sensitivity(void *param, int val) |
| 435 | { |
| 436 | store_analogitem(param, val, ANALOG_ITEM_SENSITIVITY); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | |
| 441 | static int port_type_is_analog(int type) |
| 442 | { |
| 443 | return (type >= __ipt_analog_start && type <= __ipt_analog_end); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | |
| 448 | static 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 | |
| 503 | done: |
| 504 | if (dlg) |
| 505 | win_dialog_exit(dlg); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | //============================================================ |
| 510 | // win_dirname |
| 511 | //============================================================ |
| 512 | |
| 513 | static 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 | |
| 549 | static 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 | |
| 595 | static void state_load(HWND wnd, running_machine *machine) |
| 596 | { |
| 597 | state_dialog(wnd, WIN_FILE_DIALOG_OPEN, OFN_FILEMUSTEXIST, TRUE, machine); |
| 598 | } |
| 599 | |
| 600 | static void state_save_as(HWND wnd, running_machine *machine) |
| 601 | { |
| 602 | state_dialog(wnd, WIN_FILE_DIALOG_SAVE, OFN_OVERWRITEPROMPT, FALSE, machine); |
| 603 | } |
| 604 | |
| 605 | static void state_save(running_machine *machine) |
| 606 | { |
| 607 | machine->schedule_save(state_filename); |
| 608 | } |
| 609 | |
| 610 | |
| 611 | |
| 612 | //============================================================ |
| 613 | // format_combo_changed |
| 614 | //============================================================ |
| 615 | |
| 616 | struct file_dialog_params |
| 617 | { |
| 618 | device_image_interface *dev; |
| 619 | int *create_format; |
| 620 | option_resolution **create_args; |
| 621 | }; |
| 622 | |
| 623 | static 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 | |
| 689 | struct storeval_optres_params |
| 690 | { |
| 691 | struct file_dialog_params *fdparams; |
| 692 | const option_guide *guide_entry; |
| 693 | }; |
| 694 | |
| 695 | static 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 | |
| 728 | static 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 | |
| 802 | error: |
| 803 | if (dialog) |
| 804 | win_dialog_exit(dialog); |
| 805 | return NULL; |
| 806 | } |
| 807 | |
| 808 | |
| 809 | |
| 810 | //============================================================ |
| 811 | // copy_extension_list |
| 812 | //============================================================ |
| 813 | |
| 814 | static 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 | |
| 851 | static 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 | |
| 879 | static 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 | |
| 910 | static 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 | |
| 968 | done: |
| 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 | |
| 981 | static 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 | |
| 996 | static 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 | |
| 1030 | static 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 | |
| 1081 | static 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 | |
| 1101 | static 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 | |
| 1113 | static 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 | |
| 1198 | static int is_windowed(void) |
| 1199 | { |
| 1200 | return video_config.windowed; |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | //============================================================ |
| 1206 | // frameskip_level_count |
| 1207 | //============================================================ |
| 1208 | |
| 1209 | static 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 | |
| 1229 | static 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 | |
| 1421 | static 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 | |
| 1439 | void 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 | |
| 1500 | static 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 | |
| 1552 | static 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 | |
| 1589 | static 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 | |
| 1600 | static 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 | |
| 1613 | static 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 | |
| 1632 | static 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 | |
| 1651 | static 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 | |
| 1664 | static 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 | |
| 1905 | static 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 | |
| 1930 | int 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 | |
| 1993 | static 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 | int 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 | |
| 2030 | error: |
| 2031 | if (menu_bar) |
| 2032 | DestroyMenu(menu_bar); |
| 2033 | return 1; |
| 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | |
| 2038 | //============================================================ |
| 2039 | // winwindow_video_window_proc_ui |
| 2040 | //============================================================ |
| 2041 | |
| 2042 | LRESULT 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 | } |