src/osd/winui/dialog.c
| r0 | r10259 | |
| 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/osd/winui/messui.c
| r0 | r10259 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // messui.c - MESS extensions to src/osd/winui/winui.c |
| 4 | // |
| 5 | //============================================================ |
| 6 | |
| 7 | // standard windows headers |
| 8 | #define WIN32_LEAN_AND_MEAN |
| 9 | #include <assert.h> |
| 10 | #include <string.h> |
| 11 | #include <windows.h> |
| 12 | #include <shellapi.h> |
| 13 | #include <commctrl.h> |
| 14 | #include <commdlg.h> |
| 15 | #include <wingdi.h> |
| 16 | #include <winuser.h> |
| 17 | #include <tchar.h> |
| 18 | |
| 19 | // MAME/MAMEOS/MAMEUI/MESS headers |
| 20 | #include "screenshot.h" |
| 21 | #include "bitmask.h" |
| 22 | #include "winui.h" |
| 23 | #include "resourcems.h" |
| 24 | #include "mui_opts.h" |
| 25 | #include "picker.h" |
| 26 | #include "tabview.h" |
| 27 | #include "mui_util.h" |
| 28 | #include "columnedit.h" |
| 29 | #include "optionsms.h" |
| 30 | #include "softwarepicker.h" |
| 31 | #include "softwarelist.h" |
| 32 | #include "devview.h" |
| 33 | #include "windows/window.h" |
| 34 | #include "strconv.h" |
| 35 | #include "messui.h" |
| 36 | #include "winutf8.h" |
| 37 | #include "swconfig.h" |
| 38 | #include "zippath.h" |
| 39 | #include "emuopts.h" |
| 40 | |
| 41 | |
| 42 | //============================================================ |
| 43 | // PARAMETERS |
| 44 | //============================================================ |
| 45 | |
| 46 | #define LOG_SOFTWARE 0 |
| 47 | |
| 48 | |
| 49 | //============================================================ |
| 50 | // TYPEDEFS |
| 51 | //============================================================ |
| 52 | |
| 53 | typedef struct _mess_image_type mess_image_type; |
| 54 | struct _mess_image_type |
| 55 | { |
| 56 | const device_config_image_interface *dev; |
| 57 | char *ext; |
| 58 | const char *dlgname; |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | typedef struct _device_entry device_entry; |
| 63 | struct _device_entry |
| 64 | { |
| 65 | iodevice_t dev_type; |
| 66 | const char *icon_name; |
| 67 | const char *dlgname; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | |
| 72 | //============================================================ |
| 73 | // GLOBAL VARIABLES |
| 74 | //============================================================ |
| 75 | |
| 76 | char g_szSelectedItem[MAX_PATH]; |
| 77 | |
| 78 | char g_szSelectedSoftware[MAX_PATH]; |
| 79 | |
| 80 | char g_szSelectedDevice[MAX_PATH]; |
| 81 | |
| 82 | //============================================================ |
| 83 | // LOCAL VARIABLES |
| 84 | //============================================================ |
| 85 | |
| 86 | static software_config *s_config; |
| 87 | static BOOL s_bIgnoreSoftwarePickerNotifies; |
| 88 | |
| 89 | static int *mess_icon_index; |
| 90 | |
| 91 | // TODO - We need to make icons for Cylinders, Punch Cards, and Punch Tape! |
| 92 | static const device_entry s_devices[] = |
| 93 | { |
| 94 | { IO_CARTSLOT, "roms", "Cartridge images" }, |
| 95 | { IO_FLOPPY, "floppy", "Floppy disk images" }, |
| 96 | { IO_HARDDISK, "hard", "Hard disk images" }, |
| 97 | { IO_CYLINDER, NULL, "Cylinders" }, |
| 98 | { IO_CASSETTE, NULL, "Cassette images" }, |
| 99 | { IO_PUNCHCARD, NULL, "Punchcard images" }, |
| 100 | { IO_PUNCHTAPE, NULL, "Punchtape images" }, |
| 101 | { IO_PRINTER, NULL, "Printer Output" }, |
| 102 | { IO_SERIAL, NULL, "Serial Output" }, |
| 103 | { IO_PARALLEL, NULL, "Parallel Output" }, |
| 104 | { IO_SNAPSHOT, "snapshot", "Snapshots" }, |
| 105 | { IO_QUICKLOAD, "snapshot", "Quickloads" }, |
| 106 | { IO_MEMCARD, NULL, "Memory cards" }, |
| 107 | { IO_CDROM, NULL, "CD-ROM images" }, |
| 108 | { IO_MAGTAPE, NULL, "Magnetic tapes" } |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | |
| 113 | static const LPCTSTR mess_column_names[] = |
| 114 | { |
| 115 | TEXT("Software"), |
| 116 | TEXT("Goodname"), |
| 117 | TEXT("Manufacturer"), |
| 118 | TEXT("Year"), |
| 119 | TEXT("Playable"), |
| 120 | TEXT("CRC"), |
| 121 | TEXT("SHA-1"), |
| 122 | TEXT("MD5") |
| 123 | }; |
| 124 | |
| 125 | static const LPCTSTR softlist_column_names[] = |
| 126 | { |
| 127 | TEXT("Name"), |
| 128 | TEXT("List"), |
| 129 | TEXT("Description"), |
| 130 | TEXT("Year"), |
| 131 | TEXT("Publisher"), |
| 132 | TEXT("CRC"), |
| 133 | TEXT("SHA-1"), |
| 134 | TEXT("MD5")}; |
| 135 | |
| 136 | |
| 137 | |
| 138 | //============================================================ |
| 139 | // PROTOTYPES |
| 140 | //============================================================ |
| 141 | |
| 142 | static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn); |
| 143 | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn); |
| 144 | |
| 145 | static LPCSTR SoftwareTabView_GetTabShortName(int tab); |
| 146 | static LPCSTR SoftwareTabView_GetTabLongName(int tab); |
| 147 | static void SoftwareTabView_OnSelectionChanged(void); |
| 148 | static void SoftwareTabView_OnMoveSize(void); |
| 149 | static void SetupSoftwareTabView(void); |
| 150 | |
| 151 | static void MessOpenOtherSoftware(const device_config_image_interface *dev); |
| 152 | static void MessRefreshPicker(void); |
| 153 | |
| 154 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem); |
| 155 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem); |
| 156 | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem); |
| 157 | |
| 158 | static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem); |
| 159 | static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem); |
| 160 | static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem); |
| 161 | |
| 162 | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 163 | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 164 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config_image_interface *dev, LPCTSTR pszFilename); |
| 165 | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszBuffer, UINT nBufferLength); |
| 166 | |
| 167 | #ifdef MAME_DEBUG |
| 168 | static void MessTestsBegin(void); |
| 169 | #endif /* MAME_DEBUG */ |
| 170 | |
| 171 | |
| 172 | |
| 173 | //============================================================ |
| 174 | // PICKER/TABVIEW CALLBACKS |
| 175 | //============================================================ |
| 176 | |
| 177 | static const struct PickerCallbacks s_softwarePickerCallbacks = |
| 178 | { |
| 179 | SetMessSortColumn, // pfnSetSortColumn |
| 180 | GetMessSortColumn, // pfnGetSortColumn |
| 181 | SetMessSortReverse, // pfnSetSortReverse |
| 182 | GetMessSortReverse, // pfnGetSortReverse |
| 183 | NULL, // pfnSetViewMode |
| 184 | GetViewMode, // pfnGetViewMode |
| 185 | SetMessColumnWidths, // pfnSetColumnWidths |
| 186 | GetMessColumnWidths, // pfnGetColumnWidths |
| 187 | SetMessColumnOrder, // pfnSetColumnOrder |
| 188 | GetMessColumnOrder, // pfnGetColumnOrder |
| 189 | SetMessColumnShown, // pfnSetColumnShown |
| 190 | GetMessColumnShown, // pfnGetColumnShown |
| 191 | NULL, // pfnGetOffsetChildren |
| 192 | |
| 193 | NULL, // pfnCompare |
| 194 | MamePlayGame, // pfnDoubleClick |
| 195 | SoftwarePicker_GetItemString, // pfnGetItemString |
| 196 | SoftwarePicker_GetItemImage, // pfnGetItemImage |
| 197 | SoftwarePicker_LeavingItem, // pfnLeavingItem |
| 198 | SoftwarePicker_EnteringItem, // pfnEnteringItem |
| 199 | NULL, // pfnBeginListViewDrag |
| 200 | NULL, // pfnFindItemParent |
| 201 | SoftwarePicker_Idle, // pfnIdle |
| 202 | SoftwarePicker_OnHeaderContextMenu, // pfnOnHeaderContextMenu |
| 203 | NULL // pfnOnBodyContextMenu |
| 204 | }; |
| 205 | |
| 206 | static const struct PickerCallbacks s_softwareListCallbacks = |
| 207 | { |
| 208 | SetMessSortColumn, // pfnSetSortColumn |
| 209 | GetMessSortColumn, // pfnGetSortColumn |
| 210 | SetMessSortReverse, // pfnSetSortReverse |
| 211 | GetMessSortReverse, // pfnGetSortReverse |
| 212 | NULL, // pfnSetViewMode |
| 213 | GetViewMode, // pfnGetViewMode |
| 214 | SetMessColumnWidths, // pfnSetColumnWidths |
| 215 | GetMessColumnWidths, // pfnGetColumnWidths |
| 216 | SetMessColumnOrder, // pfnSetColumnOrder |
| 217 | GetMessColumnOrder, // pfnGetColumnOrder |
| 218 | SetMessColumnShown, // pfnSetColumnShown |
| 219 | GetMessColumnShown, // pfnGetColumnShown |
| 220 | NULL, // pfnGetOffsetChildren |
| 221 | |
| 222 | NULL, // pfnCompare |
| 223 | MamePlayGame, // pfnDoubleClick |
| 224 | SoftwareList_GetItemString, // pfnGetItemString |
| 225 | SoftwareList_GetItemImage, // pfnGetItemImage |
| 226 | SoftwareList_LeavingItem, // pfnLeavingItem |
| 227 | SoftwareList_EnteringItem, // pfnEnteringItem |
| 228 | NULL, // pfnBeginListViewDrag |
| 229 | NULL, // pfnFindItemParent |
| 230 | SoftwareList_Idle, // pfnIdle |
| 231 | SoftwareList_OnHeaderContextMenu, // pfnOnHeaderContextMenu |
| 232 | NULL // pfnOnBodyContextMenu |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | static const struct TabViewCallbacks s_softwareTabViewCallbacks = |
| 237 | { |
| 238 | NULL, // pfnGetShowTabCtrl |
| 239 | SetCurrentSoftwareTab, // pfnSetCurrentTab |
| 240 | GetCurrentSoftwareTab, // pfnGetCurrentTab |
| 241 | NULL, // pfnSetShowTab |
| 242 | NULL, // pfnGetShowTab |
| 243 | |
| 244 | SoftwareTabView_GetTabShortName, // pfnGetTabShortName |
| 245 | SoftwareTabView_GetTabLongName, // pfnGetTabLongName |
| 246 | |
| 247 | SoftwareTabView_OnSelectionChanged, // pfnOnSelectionChanged |
| 248 | SoftwareTabView_OnMoveSize // pfnOnMoveSize |
| 249 | }; |
| 250 | |
| 251 | |
| 252 | |
| 253 | //============================================================ |
| 254 | // IMPLEMENTATION |
| 255 | //============================================================ |
| 256 | static char *strncpyz(char *dest, const char *source, size_t len) |
| 257 | { |
| 258 | char *s; |
| 259 | if (len) { |
| 260 | s = strncpy(dest, source, len - 1); |
| 261 | dest[len-1] = '\0'; |
| 262 | } |
| 263 | else { |
| 264 | s = dest; |
| 265 | } |
| 266 | return s; |
| 267 | } |
| 268 | |
| 269 | static const device_entry *lookupdevice(iodevice_t d) |
| 270 | { |
| 271 | int i; |
| 272 | for (i = 0; i < ARRAY_LENGTH(s_devices); i++) |
| 273 | { |
| 274 | if (s_devices[i].dev_type == d) |
| 275 | return &s_devices[i]; |
| 276 | } |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | |
| 282 | BOOL CreateMessIcons(void) |
| 283 | { |
| 284 | int i; |
| 285 | HWND hwndSoftwareList; |
| 286 | HIMAGELIST hSmall; |
| 287 | HIMAGELIST hLarge; |
| 288 | |
| 289 | // create the icon index, if we havn't already |
| 290 | if (!mess_icon_index) |
| 291 | { |
| 292 | mess_icon_index = (int*)pool_malloc_lib(GetMameUIMemoryPool(), driver_list_get_count(drivers) * IO_COUNT * sizeof(*mess_icon_index)); |
| 293 | } |
| 294 | |
| 295 | for (i = 0; i < (driver_list_get_count(drivers) * IO_COUNT); i++) |
| 296 | mess_icon_index[i] = 0; |
| 297 | |
| 298 | // Associate the image lists with the list view control. |
| 299 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 300 | hSmall = GetSmallImageList(); |
| 301 | hLarge = GetLargeImageList(); |
| 302 | (void)ListView_SetImageList(hwndSoftwareList, hSmall, LVSIL_SMALL); |
| 303 | (void)ListView_SetImageList(hwndSoftwareList, hLarge, LVSIL_NORMAL); |
| 304 | return TRUE; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | |
| 309 | static int GetMessIcon(int drvindex, int nSoftwareType) |
| 310 | { |
| 311 | int the_index; |
| 312 | int nIconPos = 0; |
| 313 | HICON hIcon = 0; |
| 314 | const game_driver *drv; |
| 315 | char buffer[32]; |
| 316 | const char *iconname; |
| 317 | |
| 318 | assert(drvindex >= 0); |
| 319 | assert(drvindex < driver_list_get_count(drivers)); |
| 320 | |
| 321 | if ((nSoftwareType >= 0) && (nSoftwareType < IO_COUNT)) |
| 322 | { |
| 323 | iconname = device_config_image_interface::device_brieftypename((iodevice_t)nSoftwareType); |
| 324 | the_index = (drvindex * IO_COUNT) + nSoftwareType; |
| 325 | |
| 326 | nIconPos = mess_icon_index[the_index]; |
| 327 | if (nIconPos >= 0) |
| 328 | { |
| 329 | for (drv = drivers[drvindex]; drv; drv = driver_get_clone(drv)) |
| 330 | { |
| 331 | _snprintf(buffer, ARRAY_LENGTH(buffer), "%s/%s", drv->name, iconname); |
| 332 | hIcon = LoadIconFromFile(buffer); |
| 333 | if (hIcon) |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | if (hIcon) |
| 338 | { |
| 339 | nIconPos = ImageList_AddIcon(GetSmallImageList(), hIcon); |
| 340 | ImageList_AddIcon(GetLargeImageList(), hIcon); |
| 341 | if (nIconPos != -1) |
| 342 | mess_icon_index[the_index] = nIconPos; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | return nIconPos; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | #ifdef UNUSED_FUNCTION |
| 351 | static void MessHashErrorProc(const char *message) |
| 352 | { |
| 353 | SetStatusBarTextF(0, "Hash file: %s", message); |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | |
| 358 | static BOOL AddSoftwarePickerDirs(HWND hwndPicker, LPCSTR pszDirectories, LPCSTR pszSubDir) |
| 359 | { |
| 360 | LPCSTR s; |
| 361 | LPSTR pszNewString; |
| 362 | char cSeparator = ';'; |
| 363 | int nLength; |
| 364 | |
| 365 | do |
| 366 | { |
| 367 | s = pszDirectories; |
| 368 | while(*s && (*s != cSeparator)) |
| 369 | s++; |
| 370 | |
| 371 | nLength = s - pszDirectories; |
| 372 | if (nLength > 0) |
| 373 | { |
| 374 | pszNewString = (LPSTR) alloca((nLength + 1 + (pszSubDir ? strlen(pszSubDir) + 1 : 0))); |
| 375 | memcpy(pszNewString, pszDirectories, nLength); |
| 376 | pszNewString[nLength] = '\0'; |
| 377 | |
| 378 | if (pszSubDir) |
| 379 | { |
| 380 | pszNewString[nLength++] = '\\'; |
| 381 | strcpy(&pszNewString[nLength], pszSubDir); |
| 382 | } |
| 383 | |
| 384 | if (!SoftwarePicker_AddDirectory(hwndPicker, pszNewString)) |
| 385 | return FALSE; |
| 386 | } |
| 387 | pszDirectories = s + 1; |
| 388 | } |
| 389 | while(*s); |
| 390 | return TRUE; |
| 391 | } |
| 392 | |
| 393 | void MySoftwareListClose(void) |
| 394 | { |
| 395 | // free the machine config, if necessary |
| 396 | if (s_config != NULL) |
| 397 | { |
| 398 | software_config_free(s_config); |
| 399 | s_config = NULL; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void MyFillSoftwareList(int drvindex, BOOL bForce) |
| 404 | { |
| 405 | BOOL is_same; |
| 406 | const game_driver *drv; |
| 407 | HWND hwndSoftwarePicker; |
| 408 | HWND hwndSoftwareList; |
| 409 | HWND hwndSoftwareDevView; |
| 410 | |
| 411 | // do we have to do anything? |
| 412 | if (!bForce) |
| 413 | { |
| 414 | if (s_config != NULL) |
| 415 | is_same = (drvindex == s_config->driver_index); |
| 416 | else |
| 417 | is_same = (drvindex < 0); |
| 418 | if (is_same) |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | // free the machine config, if necessary |
| 423 | MySoftwareListClose(); |
| 424 | |
| 425 | // allocate the machine config, if necessary |
| 426 | if (drvindex >= 0) |
| 427 | { |
| 428 | s_config = software_config_alloc(drvindex, MameUIGlobal(), NULL); |
| 429 | } |
| 430 | |
| 431 | // locate key widgets |
| 432 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 433 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 434 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 435 | |
| 436 | // set up the device view |
| 437 | DevView_SetDriver(hwndSoftwareDevView, s_config); |
| 438 | |
| 439 | // set up the software picker |
| 440 | SoftwarePicker_Clear(hwndSoftwarePicker); |
| 441 | SoftwarePicker_SetDriver(hwndSoftwarePicker, s_config); |
| 442 | |
| 443 | // add the relevant paths |
| 444 | drv = drivers[drvindex]; |
| 445 | while(drv != NULL) |
| 446 | { |
| 447 | AddSoftwarePickerDirs(hwndSoftwarePicker, GetSoftwareDirs(), drv->name); |
| 448 | drv = driver_get_compatible(drv); |
| 449 | } |
| 450 | AddSoftwarePickerDirs(hwndSoftwarePicker, GetExtraSoftwarePaths(drvindex), NULL); |
| 451 | |
| 452 | // set up the software picker |
| 453 | SoftwareList_Clear(hwndSoftwareList); |
| 454 | SoftwareList_SetDriver(hwndSoftwareList, s_config); |
| 455 | |
| 456 | /* allocate the machine config */ |
| 457 | machine_config config(*drivers[drvindex]); |
| 458 | |
| 459 | core_options *options = mame_options_init(NULL); |
| 460 | for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 461 | { |
| 462 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); |
| 463 | |
| 464 | for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) |
| 465 | { |
| 466 | if (swlist->list_name[i]) |
| 467 | { |
| 468 | software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL); |
| 469 | |
| 470 | if (list) |
| 471 | { |
| 472 | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 473 | { |
| 474 | const device_config_image_interface *image = NULL; |
| 475 | software_part *part = software_find_part(swinfo, NULL, NULL); |
| 476 | |
| 477 | // search for a device with the right interface |
| 478 | for (bool gotone = config.m_devicelist.first(image); gotone; gotone = image->next(image)) |
| 479 | { |
| 480 | const char *interface = image->image_interface(); |
| 481 | if (interface != NULL) |
| 482 | { |
| 483 | if (!strcmp(interface, part->interface_)) |
| 484 | { |
| 485 | SoftwareList_AddFile(hwndSoftwareList, swinfo->shortname, swlist->list_name[i], swinfo->longname, swinfo->publisher, swinfo->year, image->brief_instance_name()); |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | software_list_close(list); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | |
| 499 | |
| 500 | void MessUpdateSoftwareList(void) |
| 501 | { |
| 502 | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 503 | MyFillSoftwareList(Picker_GetSelectedItem(hwndList), TRUE); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | |
| 508 | BOOL MessApproveImageList(HWND hParent, int drvindex) |
| 509 | { |
| 510 | const device_config_image_interface *dev; |
| 511 | char szMessage[256]; |
| 512 | LPCSTR pszSoftware; |
| 513 | BOOL bResult = FALSE; |
| 514 | |
| 515 | if (g_szSelectedSoftware[0] && g_szSelectedDevice[0]) { |
| 516 | return TRUE; |
| 517 | } |
| 518 | // allocate the machine config |
| 519 | machine_config config(*drivers[drvindex]); |
| 520 | |
| 521 | for (bool gotone = config.m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 522 | { |
| 523 | // confirm any mandatory devices are loaded |
| 524 | if (dev->must_be_loaded()) |
| 525 | { |
| 526 | pszSoftware = GetSelectedSoftware(drvindex, &config, dev); |
| 527 | if (!pszSoftware || !*pszSoftware) |
| 528 | { |
| 529 | snprintf(szMessage, ARRAY_LENGTH(szMessage), |
| 530 | "System '%s' requires that device %s must have an image to load\n", |
| 531 | drivers[drvindex]->description, |
| 532 | dev->image_type_name()); |
| 533 | goto done; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | bResult = TRUE; |
| 538 | |
| 539 | done: |
| 540 | if (!bResult) |
| 541 | { |
| 542 | win_message_box_utf8(hParent, szMessage, MAMEUINAME, MB_OK); |
| 543 | } |
| 544 | |
| 545 | return bResult; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | |
| 550 | // this is a wrapper call to wrap the idiosycracies of SetSelectedSoftware() |
| 551 | static void InternalSetSelectedSoftware(int drvindex, const machine_config *config, const device_config_image_interface *device, const char *pszSoftware) |
| 552 | { |
| 553 | if (!pszSoftware) |
| 554 | pszSoftware = ""; |
| 555 | |
| 556 | // only call SetSelectedSoftware() if this value is different |
| 557 | if (strcmp(GetSelectedSoftware(drvindex, config, device), pszSoftware)) |
| 558 | { |
| 559 | SetSelectedSoftware(drvindex, config, device, pszSoftware); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | |
| 564 | |
| 565 | static int is_null_or_empty(const char *s) |
| 566 | { |
| 567 | return (s == NULL) || (s[0] == '\0'); |
| 568 | } |
| 569 | |
| 570 | |
| 571 | |
| 572 | // Places the specified image in the specified slot; nID = -1 means don't matter |
| 573 | static void MessSpecifyImage(int drvindex, const device_config_image_interface *device, LPCSTR pszFilename) |
| 574 | { |
| 575 | const char *s; |
| 576 | |
| 577 | if (LOG_SOFTWARE) |
| 578 | dprintf("MessSpecifyImage(): device=%p pszFilename='%s'\n", device, pszFilename); |
| 579 | |
| 580 | // if device is NULL, this is a special case; try to find existing image |
| 581 | if (device == NULL) |
| 582 | { |
| 583 | const device_config_image_interface *dev; |
| 584 | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 585 | { |
| 586 | s = GetSelectedSoftware(drvindex, s_config->mconfig, dev); |
| 587 | if ((s != NULL) && !mame_stricmp(s, pszFilename)) { |
| 588 | device = dev; |
| 589 | break; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // still not found? find an empty slot for which the device uses the |
| 595 | // same file extension |
| 596 | if (device == NULL) |
| 597 | { |
| 598 | const char *file_extension; |
| 599 | |
| 600 | // identify the file extension |
| 601 | file_extension = strrchr(pszFilename, '.'); |
| 602 | file_extension = file_extension ? file_extension + 1 : NULL; |
| 603 | |
| 604 | if (file_extension != NULL) |
| 605 | { |
| 606 | const device_config_image_interface *dev; |
| 607 | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 608 | { |
| 609 | s = GetSelectedSoftware(drvindex, s_config->mconfig, dev); |
| 610 | if (is_null_or_empty(s) && dev->uses_file_extension(file_extension)) { |
| 611 | device = dev; |
| 612 | break; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | if (device != NULL) |
| 619 | { |
| 620 | // place the image |
| 621 | InternalSetSelectedSoftware(drvindex, s_config->mconfig, device, pszFilename); |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | // could not place the image |
| 626 | if (LOG_SOFTWARE) |
| 627 | dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
| 632 | |
| 633 | static void MessRemoveImage(int drvindex, const char *pszFilename) |
| 634 | { |
| 635 | const device_config_image_interface *device; |
| 636 | const char *s; |
| 637 | |
| 638 | for (bool gotone = s_config->mconfig->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 639 | { |
| 640 | s = GetSelectedSoftware(drvindex, s_config->mconfig, device); |
| 641 | if ((s != NULL) && !strcmp(pszFilename, s)) |
| 642 | MessSpecifyImage(drvindex, device, NULL); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | |
| 647 | |
| 648 | void MessReadMountedSoftware(int drvindex) |
| 649 | { |
| 650 | // First read stuff into device view |
| 651 | DevView_Refresh(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW)); |
| 652 | |
| 653 | // Now read stuff into picker |
| 654 | MessRefreshPicker(); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | |
| 659 | static void MessRefreshPicker(void) |
| 660 | { |
| 661 | HWND hwndSoftware; |
| 662 | int i; |
| 663 | LVFINDINFO lvfi; |
| 664 | const device_config_image_interface *dev; |
| 665 | LPCSTR pszSoftware; |
| 666 | |
| 667 | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 668 | |
| 669 | s_bIgnoreSoftwarePickerNotifies = TRUE; |
| 670 | |
| 671 | // Now clear everything out; this may call back into us but it should not |
| 672 | // be problematic |
| 673 | ListView_SetItemState(hwndSoftware, -1, 0, LVIS_SELECTED); |
| 674 | |
| 675 | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 676 | { |
| 677 | pszSoftware = GetSelectedSoftware(s_config->driver_index, s_config->mconfig, dev); |
| 678 | if (pszSoftware && *pszSoftware) |
| 679 | { |
| 680 | i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware); |
| 681 | if (i < 0) |
| 682 | { |
| 683 | SoftwarePicker_AddFile(hwndSoftware, pszSoftware); |
| 684 | i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware); |
| 685 | } |
| 686 | if (i >= 0) |
| 687 | { |
| 688 | memset(&lvfi, 0, sizeof(lvfi)); |
| 689 | lvfi.flags = LVFI_PARAM; |
| 690 | lvfi.lParam = i; |
| 691 | i = ListView_FindItem(hwndSoftware, -1, &lvfi); |
| 692 | ListView_SetItemState(hwndSoftware, i, LVIS_SELECTED, LVIS_SELECTED); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | s_bIgnoreSoftwarePickerNotifies = FALSE; |
| 698 | } |
| 699 | |
| 700 | |
| 701 | |
| 702 | void InitMessPicker(void) |
| 703 | { |
| 704 | struct PickerOptions opts; |
| 705 | HWND hwndSoftware; |
| 706 | |
| 707 | s_config = NULL; |
| 708 | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 709 | |
| 710 | memset(&opts, 0, sizeof(opts)); |
| 711 | opts.pCallbacks = &s_softwarePickerCallbacks; |
| 712 | opts.nColumnCount = MESS_COLUMN_MAX; |
| 713 | opts.ppszColumnNames = mess_column_names; |
| 714 | SetupSoftwarePicker(hwndSoftware, &opts); |
| 715 | |
| 716 | SetWindowLong(hwndSoftware, GWL_STYLE, GetWindowLong(hwndSoftware, GWL_STYLE) |
| 717 | | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED); |
| 718 | |
| 719 | SetupSoftwareTabView(); |
| 720 | |
| 721 | { |
| 722 | static const struct DevViewCallbacks s_devViewCallbacks = |
| 723 | { |
| 724 | DevView_GetOpenFileName, |
| 725 | DevView_GetCreateFileName, |
| 726 | DevView_SetSelectedSoftware, |
| 727 | DevView_GetSelectedSoftware |
| 728 | }; |
| 729 | DevView_SetCallbacks(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW), &s_devViewCallbacks); |
| 730 | } |
| 731 | |
| 732 | HWND hwndSoftwareList; |
| 733 | |
| 734 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 735 | |
| 736 | memset(&opts, 0, sizeof(opts)); |
| 737 | opts.pCallbacks = &s_softwareListCallbacks; |
| 738 | opts.nColumnCount = MESS_COLUMN_MAX; |
| 739 | opts.ppszColumnNames = softlist_column_names; |
| 740 | SetupSoftwareList(hwndSoftwareList, &opts); |
| 741 | |
| 742 | SetWindowLong(hwndSoftwareList, GWL_STYLE, GetWindowLong(hwndSoftwareList, GWL_STYLE) |
| 743 | | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED); |
| 744 | |
| 745 | } |
| 746 | |
| 747 | |
| 748 | |
| 749 | // ------------------------------------------------------------------------ |
| 750 | // Open others dialog |
| 751 | // ------------------------------------------------------------------------ |
| 752 | |
| 753 | static BOOL CommonFileImageDialog(LPTSTR the_last_directory, common_file_dialog_proc cfd, LPTSTR filename, const machine_config *config, mess_image_type *imagetypes) |
| 754 | { |
| 755 | BOOL success; |
| 756 | OPENFILENAME of; |
| 757 | char szFilter[2048]; |
| 758 | LPSTR s; |
| 759 | const char *typname; |
| 760 | int i; |
| 761 | TCHAR* t_filter; |
| 762 | TCHAR* t_buffer; |
| 763 | |
| 764 | s = szFilter; |
| 765 | *filename = 0; |
| 766 | |
| 767 | // Common image types |
| 768 | strcpy(s, "Common image types"); |
| 769 | s += strlen(s); |
| 770 | *(s++) = '|'; |
| 771 | for (i = 0; imagetypes[i].ext; i++) |
| 772 | { |
| 773 | *(s++) = '*'; |
| 774 | *(s++) = '.'; |
| 775 | strcpy(s, imagetypes[i].ext); |
| 776 | s += strlen(s); |
| 777 | *(s++) = ';'; |
| 778 | } |
| 779 | *(s++) = '|'; |
| 780 | |
| 781 | // All files |
| 782 | strcpy(s, "All files (*.*)"); |
| 783 | s += strlen(s); |
| 784 | *(s++) = '|'; |
| 785 | strcpy(s, "*.*"); |
| 786 | s += strlen(s); |
| 787 | *(s++) = '|'; |
| 788 | |
| 789 | // The others |
| 790 | for (i = 0; imagetypes[i].ext; i++) |
| 791 | { |
| 792 | if (!imagetypes[i].dev) |
| 793 | typname = "Compressed images"; |
| 794 | else |
| 795 | typname = imagetypes[i].dlgname; |
| 796 | |
| 797 | strcpy(s, typname); |
| 798 | s += strlen(s); |
| 799 | strcpy(s, " (*."); |
| 800 | s += strlen(s); |
| 801 | strcpy(s, imagetypes[i].ext); |
| 802 | s += strlen(s); |
| 803 | *(s++) = ')'; |
| 804 | *(s++) = '|'; |
| 805 | *(s++) = '*'; |
| 806 | *(s++) = '.'; |
| 807 | strcpy(s, imagetypes[i].ext); |
| 808 | s += strlen(s); |
| 809 | *(s++) = '|'; |
| 810 | } |
| 811 | *(s++) = '|'; |
| 812 | |
| 813 | t_buffer = tstring_from_utf8(szFilter); |
| 814 | if( !t_buffer ) |
| 815 | return FALSE; |
| 816 | |
| 817 | // convert a pipe-char delimited string into a NUL delimited string |
| 818 | t_filter = (LPTSTR) alloca((_tcslen(t_buffer) + 2) * sizeof(*t_filter)); |
| 819 | for (i = 0; t_buffer[i] != '\0'; i++) |
| 820 | t_filter[i] = (t_buffer[i] != '|') ? t_buffer[i] : '\0'; |
| 821 | t_filter[i++] = '\0'; |
| 822 | t_filter[i++] = '\0'; |
| 823 | osd_free(t_buffer); |
| 824 | |
| 825 | of.lStructSize = sizeof(of); |
| 826 | of.hwndOwner = GetMainWindow(); |
| 827 | of.hInstance = NULL; |
| 828 | of.lpstrFilter = t_filter; |
| 829 | of.lpstrCustomFilter = NULL; |
| 830 | of.nMaxCustFilter = 0; |
| 831 | of.nFilterIndex = 1; |
| 832 | of.lpstrFile = filename; |
| 833 | of.nMaxFile = MAX_PATH; |
| 834 | of.lpstrFileTitle = NULL; |
| 835 | of.nMaxFileTitle = 0; |
| 836 | of.lpstrInitialDir = the_last_directory; |
| 837 | of.lpstrTitle = NULL; |
| 838 | of.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; |
| 839 | of.nFileOffset = 0; |
| 840 | of.nFileExtension = 0; |
| 841 | of.lpstrDefExt = TEXT("rom"); |
| 842 | of.lCustData = 0; |
| 843 | of.lpfnHook = NULL; |
| 844 | of.lpTemplateName = NULL; |
| 845 | |
| 846 | success = cfd(&of); |
| 847 | if (success) |
| 848 | { |
| 849 | //GetDirectory(filename,last_directory,sizeof(last_directory)); |
| 850 | } |
| 851 | |
| 852 | return success; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | |
| 857 | /* Specify IO_COUNT for type if you want all types */ |
| 858 | static void SetupImageTypes(const machine_config *config, mess_image_type *types, int count, BOOL bZip, const device_config_image_interface *dev) |
| 859 | { |
| 860 | int num_extensions = 0; |
| 861 | |
| 862 | memset(types, 0, sizeof(*types) * count); |
| 863 | count--; |
| 864 | |
| 865 | if (bZip) |
| 866 | { |
| 867 | /* add the ZIP extension */ |
| 868 | types[num_extensions].ext = mame_strdup("zip"); |
| 869 | types[num_extensions].dev = NULL; |
| 870 | types[num_extensions].dlgname = NULL; |
| 871 | num_extensions++; |
| 872 | } |
| 873 | |
| 874 | if (dev == NULL) |
| 875 | { |
| 876 | const device_config_image_interface *device; |
| 877 | /* special case; all non-printer devices */ |
| 878 | for (bool gotone = config->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 879 | { |
| 880 | if (device->image_type() != IO_PRINTER) |
| 881 | SetupImageTypes(config, &types[num_extensions], count - num_extensions, FALSE, device); |
| 882 | } |
| 883 | |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | astring extensions((char*)dev->file_extensions()); |
| 888 | char *ext = strtok((char*)extensions.cstr(),","); |
| 889 | while (ext != NULL) |
| 890 | { |
| 891 | if (num_extensions < count) |
| 892 | { |
| 893 | types[num_extensions].dev = dev; |
| 894 | types[num_extensions].ext = mame_strdup(ext); |
| 895 | types[num_extensions].dlgname = lookupdevice(dev->image_type())->dlgname; |
| 896 | num_extensions++; |
| 897 | } |
| 898 | ext = strtok (NULL, ","); |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | |
| 904 | static void CleanupImageTypes(mess_image_type *types, int count) |
| 905 | { |
| 906 | int i; |
| 907 | for (i = 0; i < count; ++i) |
| 908 | { |
| 909 | if (types[i].ext) |
| 910 | osd_free(types[i].ext); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | |
| 915 | static void MessSetupDevice(common_file_dialog_proc cfd, const device_config_image_interface *dev) |
| 916 | { |
| 917 | TCHAR filename[MAX_PATH]; |
| 918 | mess_image_type imagetypes[64]; |
| 919 | int drvindex; |
| 920 | HWND hwndList; |
| 921 | char* utf8_filename; |
| 922 | BOOL cfd_res; |
| 923 | |
| 924 | // begin_resource_tracking(); |
| 925 | |
| 926 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 927 | drvindex = Picker_GetSelectedItem(hwndList); |
| 928 | |
| 929 | // allocate the machine config |
| 930 | machine_config config(*drivers[drvindex]); |
| 931 | |
| 932 | SetupImageTypes(&config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 933 | cfd_res = CommonFileImageDialog(last_directory, cfd, filename, &config, imagetypes); |
| 934 | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 935 | |
| 936 | if (cfd_res) |
| 937 | { |
| 938 | utf8_filename = utf8_from_tstring(filename); |
| 939 | if( !utf8_filename ) |
| 940 | return; |
| 941 | // TODO - this should go against InternalSetSelectedSoftware() |
| 942 | SoftwarePicker_AddFile(GetDlgItem(GetMainWindow(), IDC_SWLIST), utf8_filename); |
| 943 | osd_free(utf8_filename); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | |
| 948 | |
| 949 | static void MessOpenOtherSoftware(const device_config_image_interface *dev) |
| 950 | { |
| 951 | MessSetupDevice(GetOpenFileName, dev); |
| 952 | } |
| 953 | |
| 954 | |
| 955 | |
| 956 | /* This is used to Mount an image in the device view of MESSUI. The directory in the dialog box is not |
| 957 | set, and is thus random. |
| 958 | 2009-10-18 Robbbert: |
| 959 | I've attempted to set the directory properly. Since the emulation is not running at this time, |
| 960 | we cannot do the same as the NEWUI does, that is, "initial_dir = image_working_directory(dev);" |
| 961 | because a crash occurs (the image system isn't set up yet). |
| 962 | |
| 963 | Order of priority: |
| 964 | 1. Directory where existing image is already loaded from |
| 965 | 2. First directory specified in game-specific software tab |
| 966 | 3. First directory specified in the system-wide software directories |
| 967 | 4. mess-folder\software |
| 968 | 5. mess-folder */ |
| 969 | |
| 970 | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 971 | { |
| 972 | BOOL bResult; |
| 973 | TCHAR *t_s; |
| 974 | int i; |
| 975 | mess_image_type imagetypes[64]; |
| 976 | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 977 | int drvindex = Picker_GetSelectedItem(hwndList); |
| 978 | astring as; |
| 979 | |
| 980 | /* Get the path to the currently mounted image */ |
| 981 | zippath_parent(&as, GetSelectedSoftware(drvindex, config, dev)); |
| 982 | t_s = tstring_from_utf8(astring_c(&as)); |
| 983 | |
| 984 | /* See if an image was loaded, and that the path still exists */ |
| 985 | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 986 | { |
| 987 | /* Get the path from the software tab */ |
| 988 | astring_cpyc(&as, GetExtraSoftwarePaths(drvindex)); |
| 989 | |
| 990 | /* We only want the first path; throw out the rest */ |
| 991 | i = astring_chr(&as, 0, ';'); |
| 992 | if (i > 0) astring_substr(&as, 0, i); |
| 993 | osd_free(t_s); |
| 994 | t_s = tstring_from_utf8(astring_c(&as)); |
| 995 | |
| 996 | /* Make sure a folder was specified in the tab, and that it exists */ |
| 997 | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 998 | { |
| 999 | /* Get the path from the system-wide software setting in the drop-down directory setup */ |
| 1000 | astring_cpyc(&as, GetSoftwareDirs()); |
| 1001 | |
| 1002 | /* We only want the first path; throw out the rest */ |
| 1003 | i = astring_chr(&as, 0, ';'); |
| 1004 | if (i > 0) astring_substr(&as, 0, i); |
| 1005 | osd_free(t_s); |
| 1006 | t_s = tstring_from_utf8(astring_c(&as)); |
| 1007 | |
| 1008 | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1009 | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1010 | { |
| 1011 | char *dst = NULL; |
| 1012 | |
| 1013 | osd_get_full_path(&dst,"."); |
| 1014 | /* Default to emu directory */ |
| 1015 | osd_free(t_s); |
| 1016 | t_s = tstring_from_utf8(dst); |
| 1017 | |
| 1018 | /* If software folder exists, use it instead */ |
| 1019 | zippath_combine(&as, dst, "software"); |
| 1020 | if (osd_opendir(astring_c(&as))) |
| 1021 | { |
| 1022 | osd_free(t_s); |
| 1023 | t_s = tstring_from_utf8(astring_c(&as)); |
| 1024 | } |
| 1025 | osd_free(dst); |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 1031 | bResult = CommonFileImageDialog(t_s, GetOpenFileName, pszFilename, config, imagetypes); |
| 1032 | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 1033 | |
| 1034 | osd_free(t_s); |
| 1035 | |
| 1036 | return bResult; |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | /* This is used to Create an image in the device view of MESSUI. The directory in the dialog box is not |
| 1041 | set, and is thus random. |
| 1042 | |
| 1043 | Order of priority: |
| 1044 | 1. First directory specified in game-specific software tab |
| 1045 | 2. First directory specified in the system-wide software directories |
| 1046 | 3. mess-folder\software |
| 1047 | 4. mess-folder */ |
| 1048 | |
| 1049 | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 1050 | { |
| 1051 | BOOL bResult; |
| 1052 | TCHAR *t_s; |
| 1053 | int i; |
| 1054 | mess_image_type imagetypes[64]; |
| 1055 | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1056 | int drvindex = Picker_GetSelectedItem(hwndList); |
| 1057 | astring as; |
| 1058 | |
| 1059 | /* Get the path from the software tab */ |
| 1060 | astring_cpyc(&as, GetExtraSoftwarePaths(drvindex)); |
| 1061 | |
| 1062 | /* We only want the first path; throw out the rest */ |
| 1063 | i = astring_chr(&as, 0, ';'); |
| 1064 | if (i > 0) astring_substr(&as, 0, i); |
| 1065 | t_s = tstring_from_utf8(astring_c(&as)); |
| 1066 | |
| 1067 | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1068 | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1069 | { |
| 1070 | /* Get the path from the system-wide software setting in the drop-down directory setup */ |
| 1071 | astring_cpyc(&as, GetSoftwareDirs()); |
| 1072 | |
| 1073 | /* We only want the first path; throw out the rest */ |
| 1074 | i = astring_chr(&as, 0, ';'); |
| 1075 | if (i > 0) astring_substr(&as, 0, i); |
| 1076 | osd_free(t_s); |
| 1077 | t_s = tstring_from_utf8(astring_c(&as)); |
| 1078 | |
| 1079 | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1080 | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1081 | { |
| 1082 | char *dst = NULL; |
| 1083 | |
| 1084 | osd_get_full_path(&dst,"."); |
| 1085 | /* Default to emu directory */ |
| 1086 | osd_free(t_s); |
| 1087 | t_s = tstring_from_utf8(dst); |
| 1088 | |
| 1089 | /* If software folder exists, use it instead */ |
| 1090 | zippath_combine(&as, dst, "software"); |
| 1091 | if (osd_opendir(astring_c(&as))) |
| 1092 | { |
| 1093 | osd_free(t_s); |
| 1094 | t_s = tstring_from_utf8(astring_c(&as)); |
| 1095 | } |
| 1096 | osd_free(dst); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 1101 | bResult = CommonFileImageDialog(t_s, GetSaveFileName, pszFilename, config, imagetypes); |
| 1102 | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 1103 | |
| 1104 | osd_free(t_s); |
| 1105 | |
| 1106 | return bResult; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int drvindex, |
| 1112 | const machine_config *config, const device_config_image_interface *dev, LPCTSTR pszFilename) |
| 1113 | { |
| 1114 | char* utf8_filename = utf8_from_tstring(pszFilename); |
| 1115 | if( !utf8_filename ) |
| 1116 | return; |
| 1117 | MessSpecifyImage(drvindex, dev, utf8_filename); |
| 1118 | MessRefreshPicker(); |
| 1119 | osd_free(utf8_filename); |
| 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, |
| 1125 | const machine_config *config, const device_config_image_interface *dev, LPTSTR pszBuffer, UINT nBufferLength) |
| 1126 | { |
| 1127 | LPCTSTR t_buffer = NULL; |
| 1128 | TCHAR* t_s; |
| 1129 | LPCSTR s = GetSelectedSoftware(nDriverIndex, config, dev); |
| 1130 | |
| 1131 | t_s = tstring_from_utf8(s); |
| 1132 | if( !t_s ) |
| 1133 | return t_buffer; |
| 1134 | |
| 1135 | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_s); |
| 1136 | osd_free(t_s); |
| 1137 | t_buffer = pszBuffer; |
| 1138 | |
| 1139 | return t_buffer; |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | // ------------------------------------------------------------------------ |
| 1145 | // Software Picker Class |
| 1146 | // ------------------------------------------------------------------------ |
| 1147 | |
| 1148 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem) |
| 1149 | { |
| 1150 | iodevice_t nType; |
| 1151 | int nIcon; |
| 1152 | int drvindex; |
| 1153 | const char *icon_name; |
| 1154 | HWND hwndGamePicker; |
| 1155 | HWND hwndSoftwarePicker; |
| 1156 | |
| 1157 | hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1158 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1159 | drvindex = Picker_GetSelectedItem(hwndGamePicker); |
| 1160 | nType = SoftwarePicker_GetImageType(hwndSoftwarePicker, nItem); |
| 1161 | nIcon = GetMessIcon(drvindex, nType); |
| 1162 | if (!nIcon) |
| 1163 | { |
| 1164 | switch(nType) |
| 1165 | { |
| 1166 | case IO_UNKNOWN: |
| 1167 | nIcon = FindIconIndex(IDI_WIN_REDX); |
| 1168 | break; |
| 1169 | |
| 1170 | default: |
| 1171 | icon_name = lookupdevice(nType)->icon_name; |
| 1172 | if (!icon_name) |
| 1173 | icon_name = device_config_image_interface::device_typename(nType); |
| 1174 | nIcon = FindIconIndexByName(icon_name); |
| 1175 | if (nIcon < 0) |
| 1176 | nIcon = FindIconIndex(IDI_WIN_UNKNOWN); |
| 1177 | break; |
| 1178 | } |
| 1179 | } |
| 1180 | return nIcon; |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem) |
| 1186 | { |
| 1187 | int drvindex; |
| 1188 | const char *pszFullName; |
| 1189 | HWND hwndList; |
| 1190 | |
| 1191 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1192 | { |
| 1193 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1194 | drvindex = Picker_GetSelectedItem(hwndList); |
| 1195 | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 1196 | |
| 1197 | MessRemoveImage(drvindex, pszFullName); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem) |
| 1204 | { |
| 1205 | LPCSTR pszFullName; |
| 1206 | LPCSTR pszName; |
| 1207 | const char* tmp; |
| 1208 | LPSTR s; |
| 1209 | int drvindex; |
| 1210 | HWND hwndList; |
| 1211 | |
| 1212 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1213 | |
| 1214 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1215 | { |
| 1216 | drvindex = Picker_GetSelectedItem(hwndList); |
| 1217 | |
| 1218 | // Get the fullname and partialname for this file |
| 1219 | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 1220 | tmp = strchr(pszFullName, '\\'); |
| 1221 | pszName = tmp ? tmp + 1 : pszFullName; |
| 1222 | |
| 1223 | // Do the dirty work |
| 1224 | MessSpecifyImage(drvindex, NULL, pszFullName); |
| 1225 | |
| 1226 | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1227 | strncpyz(g_szSelectedItem, pszName, ARRAY_LENGTH(g_szSelectedItem)); |
| 1228 | s = strrchr(g_szSelectedItem, '.'); |
| 1229 | if (s) |
| 1230 | *s = '\0'; |
| 1231 | |
| 1232 | UpdateScreenShot(); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | // ------------------------------------------------------------------------ |
| 1238 | // Software List Class |
| 1239 | // ------------------------------------------------------------------------ |
| 1240 | |
| 1241 | static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem) |
| 1242 | { |
| 1243 | iodevice_t nType; |
| 1244 | int nIcon; |
| 1245 | int drvindex; |
| 1246 | const char *icon_name; |
| 1247 | HWND hwndGamePicker; |
| 1248 | HWND hwndSoftwareList; |
| 1249 | |
| 1250 | hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1251 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1252 | drvindex = Picker_GetSelectedItem(hwndGamePicker); |
| 1253 | nType = SoftwareList_GetImageType(hwndSoftwareList, nItem); |
| 1254 | nIcon = GetMessIcon(drvindex, nType); |
| 1255 | if (!nIcon) |
| 1256 | { |
| 1257 | switch(nType) |
| 1258 | { |
| 1259 | case IO_UNKNOWN: |
| 1260 | nIcon = FindIconIndex(IDI_WIN_REDX); |
| 1261 | break; |
| 1262 | |
| 1263 | default: |
| 1264 | icon_name = lookupdevice(nType)->icon_name; |
| 1265 | if (!icon_name) |
| 1266 | icon_name = device_config_image_interface::device_typename(nType); |
| 1267 | nIcon = FindIconIndexByName(icon_name); |
| 1268 | if (nIcon < 0) |
| 1269 | nIcon = FindIconIndex(IDI_WIN_UNKNOWN); |
| 1270 | break; |
| 1271 | } |
| 1272 | } |
| 1273 | return nIcon; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem) |
| 1279 | { |
| 1280 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1281 | { |
| 1282 | g_szSelectedSoftware[0] = 0; |
| 1283 | g_szSelectedDevice[0] = 0; |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem) |
| 1290 | { |
| 1291 | LPCSTR pszFullName; |
| 1292 | int drvindex; |
| 1293 | HWND hwndList; |
| 1294 | |
| 1295 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1296 | |
| 1297 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1298 | { |
| 1299 | drvindex = Picker_GetSelectedItem(hwndList); |
| 1300 | |
| 1301 | // Get the fullname and partialname for this file |
| 1302 | pszFullName = SoftwareList_LookupFilename(hwndSoftwareList, nItem); |
| 1303 | |
| 1304 | strncpyz(g_szSelectedSoftware, pszFullName, ARRAY_LENGTH(g_szSelectedSoftware)); |
| 1305 | |
| 1306 | strncpyz(g_szSelectedDevice, SoftwareList_LookupDevice(hwndSoftwareList, nItem), ARRAY_LENGTH(g_szSelectedDevice)); |
| 1307 | |
| 1308 | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1309 | strncpyz(g_szSelectedItem, pszFullName, ARRAY_LENGTH(g_szSelectedItem)); |
| 1310 | |
| 1311 | UpdateScreenShot(); |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | // ------------------------------------------------------------------------ |
| 1317 | // Header context menu stuff |
| 1318 | // ------------------------------------------------------------------------ |
| 1319 | |
| 1320 | static HWND MyColumnDialogProc_hwndPicker; |
| 1321 | static int *MyColumnDialogProc_order; |
| 1322 | static int *MyColumnDialogProc_shown; |
| 1323 | |
| 1324 | static void MyGetRealColumnOrder(int *order) |
| 1325 | { |
| 1326 | int i, nColumnCount; |
| 1327 | nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1328 | for (i = 0; i < nColumnCount; i++) |
| 1329 | order[i] = Picker_GetRealColumnFromViewColumn(MyColumnDialogProc_hwndPicker, i); |
| 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | static void MyGetColumnInfo(int *order, int *shown) |
| 1335 | { |
| 1336 | const struct PickerCallbacks *pCallbacks; |
| 1337 | pCallbacks = Picker_GetCallbacks(MyColumnDialogProc_hwndPicker); |
| 1338 | pCallbacks->pfnGetColumnOrder(order); |
| 1339 | pCallbacks->pfnGetColumnShown(shown); |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | static void MySetColumnInfo(int *order, int *shown) |
| 1345 | { |
| 1346 | const struct PickerCallbacks *pCallbacks; |
| 1347 | pCallbacks = Picker_GetCallbacks(MyColumnDialogProc_hwndPicker); |
| 1348 | pCallbacks->pfnSetColumnOrder(order); |
| 1349 | pCallbacks->pfnSetColumnShown(shown); |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | static INT_PTR CALLBACK MyColumnDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) |
| 1354 | { |
| 1355 | INT_PTR result = 0; |
| 1356 | int nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1357 | const LPCTSTR *ppszColumnNames = Picker_GetColumnNames(MyColumnDialogProc_hwndPicker); |
| 1358 | |
| 1359 | result = InternalColumnDialogProc(hDlg, Msg, wParam, lParam, nColumnCount, |
| 1360 | MyColumnDialogProc_shown, MyColumnDialogProc_order, ppszColumnNames, |
| 1361 | MyGetRealColumnOrder, MyGetColumnInfo, MySetColumnInfo); |
| 1362 | |
| 1363 | return result; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | static BOOL RunColumnDialog(HWND hwndPicker) |
| 1369 | { |
| 1370 | BOOL bResult; |
| 1371 | int nColumnCount; |
| 1372 | |
| 1373 | MyColumnDialogProc_hwndPicker = hwndPicker; |
| 1374 | nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1375 | |
| 1376 | MyColumnDialogProc_order = (int*)alloca(nColumnCount * sizeof(int)); |
| 1377 | MyColumnDialogProc_shown = (int*)alloca(nColumnCount * sizeof(int)); |
| 1378 | bResult = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_COLUMNS), GetMainWindow(), MyColumnDialogProc); |
| 1379 | return bResult; |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn) |
| 1385 | { |
| 1386 | HMENU hMenu; |
| 1387 | HMENU hMenuLoad; |
| 1388 | HWND hwndPicker; |
| 1389 | int nMenuItem; |
| 1390 | |
| 1391 | hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER)); |
| 1392 | hMenu = GetSubMenu(hMenuLoad, 0); |
| 1393 | |
| 1394 | nMenuItem = (int) TrackPopupMenu(hMenu, |
| 1395 | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, |
| 1396 | pt.x, |
| 1397 | pt.y, |
| 1398 | 0, |
| 1399 | GetMainWindow(), |
| 1400 | NULL); |
| 1401 | |
| 1402 | DestroyMenu(hMenuLoad); |
| 1403 | |
| 1404 | hwndPicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1405 | |
| 1406 | switch(nMenuItem) { |
| 1407 | case ID_SORT_ASCENDING: |
| 1408 | SetMessSortReverse(FALSE); |
| 1409 | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1410 | Picker_Sort(hwndPicker); |
| 1411 | break; |
| 1412 | |
| 1413 | case ID_SORT_DESCENDING: |
| 1414 | SetMessSortReverse(TRUE); |
| 1415 | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1416 | Picker_Sort(hwndPicker); |
| 1417 | break; |
| 1418 | |
| 1419 | case ID_CUSTOMIZE_FIELDS: |
| 1420 | if (RunColumnDialog(hwndPicker)) |
| 1421 | Picker_ResetColumnDisplay(hwndPicker); |
| 1422 | break; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn) |
| 1427 | { |
| 1428 | HMENU hMenu; |
| 1429 | HMENU hMenuLoad; |
| 1430 | HWND hwndPicker; |
| 1431 | int nMenuItem; |
| 1432 | |
| 1433 | hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER)); |
| 1434 | hMenu = GetSubMenu(hMenuLoad, 0); |
| 1435 | |
| 1436 | nMenuItem = (int) TrackPopupMenu(hMenu, |
| 1437 | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, |
| 1438 | pt.x, |
| 1439 | pt.y, |
| 1440 | 0, |
| 1441 | GetMainWindow(), |
| 1442 | NULL); |
| 1443 | |
| 1444 | DestroyMenu(hMenuLoad); |
| 1445 | |
| 1446 | hwndPicker = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1447 | |
| 1448 | switch(nMenuItem) { |
| 1449 | case ID_SORT_ASCENDING: |
| 1450 | SetMessSortReverse(FALSE); |
| 1451 | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1452 | Picker_Sort(hwndPicker); |
| 1453 | break; |
| 1454 | |
| 1455 | case ID_SORT_DESCENDING: |
| 1456 | SetMessSortReverse(TRUE); |
| 1457 | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1458 | Picker_Sort(hwndPicker); |
| 1459 | break; |
| 1460 | |
| 1461 | case ID_CUSTOMIZE_FIELDS: |
| 1462 | if (RunColumnDialog(hwndPicker)) |
| 1463 | Picker_ResetColumnDisplay(hwndPicker); |
| 1464 | break; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | |
| 1469 | // ------------------------------------------------------------------------ |
| 1470 | // MessCommand |
| 1471 | // ------------------------------------------------------------------------ |
| 1472 | |
| 1473 | BOOL MessCommand(HWND hwnd,int id, HWND hwndCtl, UINT codeNotify) |
| 1474 | { |
| 1475 | switch (id) |
| 1476 | { |
| 1477 | case ID_MESS_OPEN_SOFTWARE: |
| 1478 | MessOpenOtherSoftware(NULL); |
| 1479 | break; |
| 1480 | |
| 1481 | #ifdef MAME_DEBUG |
| 1482 | case ID_MESS_RUN_TESTS: |
| 1483 | MessTestsBegin(); |
| 1484 | break; |
| 1485 | #endif /* MAME_DEBUG */ |
| 1486 | } |
| 1487 | return FALSE; |
| 1488 | } |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | // ------------------------------------------------------------------------ |
| 1493 | // Software Tab View |
| 1494 | // ------------------------------------------------------------------------ |
| 1495 | |
| 1496 | static LPCSTR s_tabs[] = |
| 1497 | { |
| 1498 | "picker\0Picker", |
| 1499 | "devview\0Device View", |
| 1500 | "softlist\0Software", |
| 1501 | }; |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | static LPCSTR SoftwareTabView_GetTabShortName(int tab) |
| 1506 | { |
| 1507 | return s_tabs[tab]; |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | static LPCSTR SoftwareTabView_GetTabLongName(int tab) |
| 1513 | { |
| 1514 | return s_tabs[tab] + strlen(s_tabs[tab]) + 1; |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | static void SoftwareTabView_OnSelectionChanged(void) |
| 1520 | { |
| 1521 | int nTab; |
| 1522 | HWND hwndSoftwarePicker; |
| 1523 | HWND hwndSoftwareDevView; |
| 1524 | HWND hwndSoftwareList; |
| 1525 | |
| 1526 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1527 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1528 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1529 | |
| 1530 | nTab = TabView_GetCurrentTab(GetDlgItem(GetMainWindow(), IDC_SWTAB)); |
| 1531 | |
| 1532 | switch(nTab) |
| 1533 | { |
| 1534 | case 0: |
| 1535 | ShowWindow(hwndSoftwarePicker, SW_SHOW); |
| 1536 | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1537 | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1538 | break; |
| 1539 | |
| 1540 | case 1: |
| 1541 | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1542 | ShowWindow(hwndSoftwareDevView, SW_SHOW); |
| 1543 | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1544 | break; |
| 1545 | case 2: |
| 1546 | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1547 | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1548 | ShowWindow(hwndSoftwareList, SW_SHOW); |
| 1549 | break; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | static void SoftwareTabView_OnMoveSize(void) |
| 1556 | { |
| 1557 | HWND hwndSoftwareTabView; |
| 1558 | HWND hwndSoftwarePicker; |
| 1559 | HWND hwndSoftwareDevView; |
| 1560 | HWND hwndSoftwareList; |
| 1561 | RECT rMain, rSoftwareTabView, rClient, rTab; |
| 1562 | BOOL res; |
| 1563 | |
| 1564 | hwndSoftwareTabView = GetDlgItem(GetMainWindow(), IDC_SWTAB); |
| 1565 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1566 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1567 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1568 | |
| 1569 | GetWindowRect(hwndSoftwareTabView, &rSoftwareTabView); |
| 1570 | GetClientRect(GetMainWindow(), &rMain); |
| 1571 | ClientToScreen(GetMainWindow(), &((POINT *) &rMain)[0]); |
| 1572 | ClientToScreen(GetMainWindow(), &((POINT *) &rMain)[1]); |
| 1573 | |
| 1574 | // Calculate rClient from rSoftwareTabView in terms of rMain coordinates |
| 1575 | rClient.left = rSoftwareTabView.left - rMain.left; |
| 1576 | rClient.top = rSoftwareTabView.top - rMain.top; |
| 1577 | rClient.right = rSoftwareTabView.right - rMain.left; |
| 1578 | rClient.bottom = rSoftwareTabView.bottom - rMain.top; |
| 1579 | |
| 1580 | // If the tabs are visible, then make sure that the tab view's tabs are |
| 1581 | // not being covered up |
| 1582 | if (GetWindowLong(hwndSoftwareTabView, GWL_STYLE) & WS_VISIBLE) |
| 1583 | { |
| 1584 | res = TabCtrl_GetItemRect(hwndSoftwareTabView, 0, &rTab); |
| 1585 | rClient.top += rTab.bottom - rTab.top + 2; |
| 1586 | } |
| 1587 | |
| 1588 | /* Now actually move the controls */ |
| 1589 | MoveWindow(hwndSoftwarePicker, rClient.left, rClient.top, |
| 1590 | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1591 | TRUE); |
| 1592 | MoveWindow(hwndSoftwareDevView, rClient.left + 3, rClient.top + 2, |
| 1593 | rClient.right - rClient.left - 6, rClient.bottom - rClient.top -4, |
| 1594 | TRUE); |
| 1595 | MoveWindow(hwndSoftwareList, rClient.left, rClient.top, |
| 1596 | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1597 | TRUE); |
| 1598 | } |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | static void SetupSoftwareTabView(void) |
| 1603 | { |
| 1604 | struct TabViewOptions opts; |
| 1605 | |
| 1606 | memset(&opts, 0, sizeof(opts)); |
| 1607 | opts.pCallbacks = &s_softwareTabViewCallbacks; |
| 1608 | opts.nTabCount = ARRAY_LENGTH(s_tabs); |
| 1609 | |
| 1610 | SetupTabView(GetDlgItem(GetMainWindow(), IDC_SWTAB), &opts); |
| 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | // ------------------------------------------------------------------------ |
| 1615 | // MessUI Diagnostics |
| 1616 | // ------------------------------------------------------------------------ |
| 1617 | |
| 1618 | #ifdef MAME_DEBUG |
| 1619 | |
| 1620 | static int s_nOriginalPick; |
| 1621 | static UINT_PTR s_nTestingTimer; |
| 1622 | static BOOL s_bInTimerProc; |
| 1623 | |
| 1624 | static void MessTestsColumns(void) |
| 1625 | { |
| 1626 | int i, j; |
| 1627 | int oldshown[MESS_COLUMN_MAX]; |
| 1628 | int shown[MESS_COLUMN_MAX]; |
| 1629 | |
| 1630 | GetMessColumnShown(oldshown); |
| 1631 | |
| 1632 | shown[0] = 1; |
| 1633 | for (i = 0; i < (1<<(MESS_COLUMN_MAX-1)); i++) |
| 1634 | { |
| 1635 | for (j = 1; j < MESS_COLUMN_MAX; j++) |
| 1636 | shown[j] = (i & (1<<(j-1))) ? 1 : 0; |
| 1637 | |
| 1638 | SetMessColumnShown(shown); |
| 1639 | Picker_ResetColumnDisplay(GetDlgItem(GetMainWindow(), IDC_SWLIST)); |
| 1640 | } |
| 1641 | |
| 1642 | SetMessColumnShown(oldshown); |
| 1643 | Picker_ResetColumnDisplay(GetDlgItem(GetMainWindow(), IDC_SWLIST)); |
| 1644 | } |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | static void CALLBACK MessTestsTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
| 1650 | { |
| 1651 | int nNewGame; |
| 1652 | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1653 | |
| 1654 | // if either of the pickers have further idle work to do, or we are |
| 1655 | // already in this timerproc, do not do anything |
| 1656 | if (s_bInTimerProc || Picker_IsIdling(hwndList) |
| 1657 | || Picker_IsIdling(GetDlgItem(GetMainWindow(), IDC_SWLIST))) |
| 1658 | return; |
| 1659 | s_bInTimerProc = TRUE; |
| 1660 | |
| 1661 | nNewGame = GetSelectedPick() + 1; |
| 1662 | |
| 1663 | if (nNewGame >= driver_list_get_count(drivers)) |
| 1664 | { |
| 1665 | /* We are done */ |
| 1666 | Picker_SetSelectedPick(hwndList, s_nOriginalPick); |
| 1667 | |
| 1668 | KillTimer(NULL, s_nTestingTimer); |
| 1669 | s_nTestingTimer = 0; |
| 1670 | |
| 1671 | win_message_box_utf8(GetMainWindow(), "Tests successfully completed!", MAMEUINAME, MB_OK); |
| 1672 | } |
| 1673 | else |
| 1674 | { |
| 1675 | // MessTestsFlex(GetDlgItem(GetMainWindow(), IDC_SWLIST), drivers[Picker_GetSelectedItem(hwndList)]); |
| 1676 | Picker_SetSelectedPick(hwndList, nNewGame); |
| 1677 | } |
| 1678 | s_bInTimerProc = FALSE; |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | static void MessTestsBegin(void) |
| 1684 | { |
| 1685 | int nOriginalPick; |
| 1686 | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1687 | |
| 1688 | nOriginalPick = GetSelectedPick(); |
| 1689 | |
| 1690 | // If we are not currently running tests, set up the timer and keep track |
| 1691 | // of the original selected pick item |
| 1692 | if (!s_nTestingTimer) |
| 1693 | { |
| 1694 | s_nTestingTimer = SetTimer(NULL, 0, 50, MessTestsTimerProc); |
| 1695 | if (!s_nTestingTimer) |
| 1696 | return; |
| 1697 | s_nOriginalPick = nOriginalPick; |
| 1698 | } |
| 1699 | |
| 1700 | MessTestsColumns(); |
| 1701 | |
| 1702 | if (nOriginalPick == 0) |
| 1703 | Picker_SetSelectedPick(hwndList, 1); |
| 1704 | Picker_SetSelectedPick(hwndList, 0); |
| 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | |
| 1709 | #endif // MAME_DEBUG |
src/osd/winui/devview.c
| r0 | r10259 | |
| 1 | // ------------------------------------------------------------------------ |
| 2 | // Software Device View class |
| 3 | // ------------------------------------------------------------------------ |
| 4 | |
| 5 | #define WIN32_LEAN_AND_MEAN |
| 6 | #include <assert.h> |
| 7 | #include <string.h> |
| 8 | #include <windows.h> |
| 9 | #include <shellapi.h> |
| 10 | #include <commctrl.h> |
| 11 | #include <commdlg.h> |
| 12 | #include <wingdi.h> |
| 13 | #include <winuser.h> |
| 14 | #include <tchar.h> |
| 15 | |
| 16 | #include "emu.h" |
| 17 | #include "devview.h" |
| 18 | #include "optionsms.h" |
| 19 | #include "strconv.h" |
| 20 | #include "winutf8.h" |
| 21 | #include "mui_util.h" |
| 22 | |
| 23 | #define DEVVIEW_PADDING 10 |
| 24 | |
| 25 | |
| 26 | struct DevViewInfo |
| 27 | { |
| 28 | HFONT hFont; |
| 29 | int nWidth; |
| 30 | BOOL bSurpressFilenameChanged; |
| 31 | const software_config *config; |
| 32 | const struct DevViewCallbacks *pCallbacks; |
| 33 | struct DevViewEntry *pEntries; |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | |
| 38 | struct DevViewEntry |
| 39 | { |
| 40 | const device_config_image_interface *dev; |
| 41 | HWND hwndStatic; |
| 42 | HWND hwndEdit; |
| 43 | HWND hwndBrowseButton; |
| 44 | WNDPROC pfnEditWndProc; |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | |
| 49 | static struct DevViewInfo *GetDevViewInfo(HWND hwndDevView) |
| 50 | { |
| 51 | LONG_PTR l; |
| 52 | l = GetWindowLongPtr(hwndDevView, GWLP_USERDATA); |
| 53 | return (struct DevViewInfo *) l; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | static void DevView_Clear(HWND hwndDevView) |
| 59 | { |
| 60 | struct DevViewInfo *pDevViewInfo; |
| 61 | int i; |
| 62 | |
| 63 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 64 | |
| 65 | if (pDevViewInfo->pEntries != NULL) |
| 66 | { |
| 67 | for (i = 0; pDevViewInfo->pEntries[i].dev; i++) |
| 68 | { |
| 69 | DestroyWindow(pDevViewInfo->pEntries[i].hwndStatic); |
| 70 | DestroyWindow(pDevViewInfo->pEntries[i].hwndEdit); |
| 71 | DestroyWindow(pDevViewInfo->pEntries[i].hwndBrowseButton); |
| 72 | } |
| 73 | free(pDevViewInfo->pEntries); |
| 74 | pDevViewInfo->pEntries = NULL; |
| 75 | } |
| 76 | |
| 77 | pDevViewInfo->config = NULL; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | |
| 82 | static void DevView_GetColumns(HWND hwndDevView, int *pnStaticPos, int *pnStaticWidth, |
| 83 | int *pnEditPos, int *pnEditWidth, int *pnButtonPos, int *pnButtonWidth) |
| 84 | { |
| 85 | struct DevViewInfo *pDevViewInfo; |
| 86 | RECT r; |
| 87 | |
| 88 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 89 | |
| 90 | GetClientRect(hwndDevView, &r); |
| 91 | |
| 92 | *pnStaticPos = DEVVIEW_PADDING; |
| 93 | *pnStaticWidth = pDevViewInfo->nWidth; |
| 94 | |
| 95 | *pnButtonWidth = 25; |
| 96 | *pnButtonPos = (r.right - r.left) - *pnButtonWidth - DEVVIEW_PADDING; |
| 97 | |
| 98 | *pnEditPos = *pnStaticPos + *pnStaticWidth + DEVVIEW_PADDING; |
| 99 | *pnEditWidth = *pnButtonPos - *pnEditPos - DEVVIEW_PADDING; |
| 100 | if (*pnEditWidth < 0) |
| 101 | *pnEditWidth = 0; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | void DevView_Refresh(HWND hwndDevView) |
| 107 | { |
| 108 | struct DevViewInfo *pDevViewInfo; |
| 109 | int i; |
| 110 | LPCTSTR pszSelection; |
| 111 | TCHAR szBuffer[MAX_PATH]; |
| 112 | |
| 113 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 114 | |
| 115 | if (pDevViewInfo->pEntries) |
| 116 | { |
| 117 | for (i = 0; pDevViewInfo->pEntries[i].dev; i++) |
| 118 | { |
| 119 | pszSelection = pDevViewInfo->pCallbacks->pfnGetSelectedSoftware( |
| 120 | hwndDevView, |
| 121 | pDevViewInfo->config->driver_index, |
| 122 | pDevViewInfo->config->mconfig, |
| 123 | pDevViewInfo->pEntries[i].dev, |
| 124 | szBuffer, ARRAY_LENGTH(szBuffer)); |
| 125 | |
| 126 | if (!pszSelection) |
| 127 | pszSelection = TEXT(""); |
| 128 | |
| 129 | pDevViewInfo->bSurpressFilenameChanged = TRUE; |
| 130 | SetWindowText(pDevViewInfo->pEntries[i].hwndEdit, pszSelection); |
| 131 | pDevViewInfo->bSurpressFilenameChanged = FALSE; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | static void DevView_TextChanged(HWND hwndDevView, int nChangedEntry, LPCTSTR pszFilename) |
| 139 | { |
| 140 | struct DevViewInfo *pDevViewInfo; |
| 141 | |
| 142 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 143 | if (!pDevViewInfo->bSurpressFilenameChanged && pDevViewInfo->pCallbacks->pfnSetSelectedSoftware) |
| 144 | { |
| 145 | pDevViewInfo->pCallbacks->pfnSetSelectedSoftware(hwndDevView, |
| 146 | pDevViewInfo->config->driver_index, |
| 147 | pDevViewInfo->config->mconfig, |
| 148 | pDevViewInfo->pEntries[nChangedEntry].dev, |
| 149 | pszFilename); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | |
| 155 | static LRESULT CALLBACK DevView_EditWndProc(HWND hwndEdit, UINT nMessage, WPARAM wParam, LPARAM lParam) |
| 156 | { |
| 157 | struct DevViewInfo *pDevViewInfo; |
| 158 | struct DevViewEntry *pEnt; |
| 159 | LRESULT rc; |
| 160 | HWND hwndDevView; |
| 161 | LONG_PTR l; |
| 162 | |
| 163 | l = GetWindowLongPtr(hwndEdit, GWLP_USERDATA); |
| 164 | pEnt = (struct DevViewEntry *) l; |
| 165 | if (IsWindowUnicode(hwndEdit)) |
| 166 | rc = CallWindowProcW(pEnt->pfnEditWndProc, hwndEdit, nMessage, wParam, lParam); |
| 167 | else |
| 168 | rc = CallWindowProcA(pEnt->pfnEditWndProc, hwndEdit, nMessage, wParam, lParam); |
| 169 | |
| 170 | if (nMessage == WM_SETTEXT) |
| 171 | { |
| 172 | hwndDevView = GetParent(hwndEdit); |
| 173 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 174 | DevView_TextChanged(hwndDevView, pEnt - pDevViewInfo->pEntries, (LPCTSTR) lParam); |
| 175 | } |
| 176 | return rc; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | BOOL DevView_SetDriver(HWND hwndDevView, const software_config *config) |
| 182 | { |
| 183 | struct DevViewInfo *pDevViewInfo; |
| 184 | const device_config_image_interface *dev = NULL; |
| 185 | struct DevViewEntry *pEnt; |
| 186 | int i; |
| 187 | int y, nHeight, nDevCount; |
| 188 | int nStaticPos, nStaticWidth, nEditPos, nEditWidth, nButtonPos, nButtonWidth; |
| 189 | HDC hDc; |
| 190 | LPTSTR *ppszDevices; |
| 191 | LPTSTR t_s; |
| 192 | SIZE sz; |
| 193 | LONG_PTR l; |
| 194 | |
| 195 | |
| 196 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 197 | |
| 198 | // clear out |
| 199 | DevView_Clear(hwndDevView); |
| 200 | |
| 201 | // copy the config |
| 202 | pDevViewInfo->config = config; |
| 203 | |
| 204 | // count total amount of devices |
| 205 | nDevCount = 0; |
| 206 | |
| 207 | { |
| 208 | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 209 | { |
| 210 | nDevCount++; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (nDevCount > 0) |
| 215 | { |
| 216 | // get the names of all of the devices |
| 217 | ppszDevices = (LPTSTR *) alloca(nDevCount * sizeof(*ppszDevices)); |
| 218 | i = 0; |
| 219 | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 220 | { |
| 221 | t_s = tstring_from_utf8(dev->devconfig().name()); |
| 222 | ppszDevices[i] = (TCHAR*)alloca((_tcslen(t_s) + 1) * sizeof(TCHAR)); |
| 223 | _tcscpy(ppszDevices[i], t_s); |
| 224 | osd_free(t_s); |
| 225 | i++; |
| 226 | } |
| 227 | |
| 228 | // Calculate the requisite size for the device column |
| 229 | pDevViewInfo->nWidth = 0; |
| 230 | if (nDevCount > 0) |
| 231 | { |
| 232 | hDc = GetDC(hwndDevView); |
| 233 | for (i = 0; i < nDevCount; i++) |
| 234 | { |
| 235 | GetTextExtentPoint32(hDc, ppszDevices[i], _tcslen(ppszDevices[i]), &sz); |
| 236 | if (sz.cx > pDevViewInfo->nWidth) |
| 237 | pDevViewInfo->nWidth = sz.cx; |
| 238 | } |
| 239 | ReleaseDC(hwndDevView, hDc); |
| 240 | } |
| 241 | |
| 242 | pEnt = (struct DevViewEntry *) malloc(sizeof(struct DevViewEntry) * (nDevCount + 1)); |
| 243 | if (!pEnt) |
| 244 | return FALSE; |
| 245 | memset(pEnt, 0, sizeof(struct DevViewEntry) * (nDevCount + 1)); |
| 246 | pDevViewInfo->pEntries = pEnt; |
| 247 | |
| 248 | y = 10; |
| 249 | nHeight = 21; |
| 250 | DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth, |
| 251 | &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth); |
| 252 | |
| 253 | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 254 | { |
| 255 | pEnt->dev = dev; |
| 256 | |
| 257 | pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", dev->devconfig().name(), |
| 258 | WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight, |
| 259 | hwndDevView, NULL, NULL, NULL); |
| 260 | |
| 261 | pEnt->hwndEdit = win_create_window_ex_utf8(0, "EDIT", "", |
| 262 | WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, nEditPos, y, nEditWidth, nHeight, |
| 263 | hwndDevView, NULL, NULL, NULL); |
| 264 | |
| 265 | pEnt->hwndBrowseButton = win_create_window_ex_utf8(0, "BUTTON", "...", |
| 266 | WS_VISIBLE | WS_CHILD, nButtonPos, y, nButtonWidth, nHeight, |
| 267 | hwndDevView, NULL, NULL, NULL); |
| 268 | |
| 269 | if (pEnt->hwndStatic) |
| 270 | { |
| 271 | SendMessage(pEnt->hwndStatic, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE); |
| 272 | } |
| 273 | if (pEnt->hwndEdit) |
| 274 | { |
| 275 | SendMessage(pEnt->hwndEdit, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE); |
| 276 | l = (LONG_PTR) DevView_EditWndProc; |
| 277 | l = SetWindowLongPtr(pEnt->hwndEdit, GWLP_WNDPROC, l); |
| 278 | pEnt->pfnEditWndProc = (WNDPROC) l; |
| 279 | SetWindowLongPtr(pEnt->hwndEdit, GWLP_USERDATA, (LONG_PTR) pEnt); |
| 280 | } |
| 281 | if (pEnt->hwndBrowseButton) |
| 282 | { |
| 283 | SetWindowLongPtr(pEnt->hwndBrowseButton, GWLP_USERDATA, (LONG_PTR) pEnt); |
| 284 | } |
| 285 | |
| 286 | y += nHeight; |
| 287 | pEnt++; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | DevView_Refresh(hwndDevView); |
| 292 | return TRUE; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | |
| 297 | static void DevView_ButtonClick(HWND hwndDevView, struct DevViewEntry *pEnt, HWND hwndButton) |
| 298 | { |
| 299 | struct DevViewInfo *pDevViewInfo; |
| 300 | HMENU hMenu; |
| 301 | RECT r; |
| 302 | int rc; |
| 303 | BOOL b; |
| 304 | TCHAR szPath[MAX_PATH]; |
| 305 | |
| 306 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 307 | |
| 308 | hMenu = CreatePopupMenu(); |
| 309 | |
| 310 | if (pDevViewInfo->pCallbacks->pfnGetOpenFileName) |
| 311 | AppendMenu(hMenu, MF_STRING, 1, TEXT("Mount...")); |
| 312 | |
| 313 | if (pEnt->dev->is_creatable()) |
| 314 | { |
| 315 | if (pDevViewInfo->pCallbacks->pfnGetCreateFileName) |
| 316 | AppendMenu(hMenu, MF_STRING, 2, TEXT("Create...")); |
| 317 | } |
| 318 | |
| 319 | AppendMenu(hMenu, MF_STRING, 3, TEXT("Unmount")); |
| 320 | |
| 321 | GetWindowRect(hwndButton, &r); |
| 322 | rc = TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD, |
| 323 | r.left, r.bottom, 0, hwndDevView, NULL); |
| 324 | |
| 325 | switch(rc) |
| 326 | { |
| 327 | case 1: |
| 328 | b = pDevViewInfo->pCallbacks->pfnGetOpenFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev, |
| 329 | szPath, ARRAY_LENGTH(szPath)); |
| 330 | break; |
| 331 | case 2: |
| 332 | b = pDevViewInfo->pCallbacks->pfnGetCreateFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev, |
| 333 | szPath, ARRAY_LENGTH(szPath)); |
| 334 | break; |
| 335 | case 3: |
| 336 | memset(szPath, 0, sizeof(szPath)); |
| 337 | b = TRUE; |
| 338 | break; |
| 339 | default: |
| 340 | b = FALSE; |
| 341 | break; |
| 342 | } |
| 343 | if (!b) |
| 344 | return; |
| 345 | SetWindowText(pEnt->hwndEdit, szPath); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | static BOOL DevView_Setup(HWND hwndDevView) |
| 351 | { |
| 352 | struct DevViewInfo *pDevViewInfo; |
| 353 | |
| 354 | // allocate the device view info |
| 355 | pDevViewInfo = (DevViewInfo*)malloc(sizeof(struct DevViewInfo)); |
| 356 | if (!pDevViewInfo) |
| 357 | return FALSE; |
| 358 | memset(pDevViewInfo, 0, sizeof(*pDevViewInfo)); |
| 359 | |
| 360 | SetWindowLongPtr(hwndDevView, GWLP_USERDATA, (LONG_PTR) pDevViewInfo); |
| 361 | |
| 362 | // create and specify the font |
| 363 | pDevViewInfo->hFont = CreateFont(10, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, |
| 364 | 0, 0, 0, TEXT("MS Sans Serif")); |
| 365 | SendMessage(hwndDevView, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, FALSE); |
| 366 | return TRUE; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | static void DevView_Free(HWND hwndDevView) |
| 372 | { |
| 373 | struct DevViewInfo *pDevViewInfo; |
| 374 | |
| 375 | DevView_Clear(hwndDevView); |
| 376 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 377 | DeleteObject(pDevViewInfo->hFont); |
| 378 | free(pDevViewInfo); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | |
| 383 | static LRESULT CALLBACK DevView_WndProc(HWND hwndDevView, UINT nMessage, WPARAM wParam, LPARAM lParam) |
| 384 | { |
| 385 | struct DevViewInfo *pDevViewInfo; |
| 386 | struct DevViewEntry *pEnt; |
| 387 | int nStaticPos, nStaticWidth, nEditPos, nEditWidth, nButtonPos, nButtonWidth; |
| 388 | RECT r; |
| 389 | LONG_PTR l; |
| 390 | LRESULT rc = 0; |
| 391 | BOOL bHandled = FALSE; |
| 392 | HWND hwndButton; |
| 393 | |
| 394 | switch(nMessage) |
| 395 | { |
| 396 | case WM_DESTROY: |
| 397 | DevView_Free(hwndDevView); |
| 398 | break; |
| 399 | |
| 400 | case WM_SHOWWINDOW: |
| 401 | if (wParam) |
| 402 | { |
| 403 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 404 | DevView_Refresh(hwndDevView); |
| 405 | } |
| 406 | break; |
| 407 | |
| 408 | case WM_COMMAND: |
| 409 | switch(HIWORD(wParam)) |
| 410 | { |
| 411 | case BN_CLICKED: |
| 412 | hwndButton = (HWND) lParam; |
| 413 | l = GetWindowLongPtr(hwndButton, GWLP_USERDATA); |
| 414 | pEnt = (struct DevViewEntry *) l; |
| 415 | DevView_ButtonClick(hwndDevView, pEnt, hwndButton); |
| 416 | break; |
| 417 | } |
| 418 | break; |
| 419 | } |
| 420 | |
| 421 | if (!bHandled) |
| 422 | rc = DefWindowProc(hwndDevView, nMessage, wParam, lParam); |
| 423 | |
| 424 | switch(nMessage) |
| 425 | { |
| 426 | case WM_CREATE: |
| 427 | if (!DevView_Setup(hwndDevView)) |
| 428 | return -1; |
| 429 | break; |
| 430 | |
| 431 | case WM_MOVE: |
| 432 | case WM_SIZE: |
| 433 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 434 | pEnt = pDevViewInfo->pEntries; |
| 435 | if (pEnt) |
| 436 | { |
| 437 | DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth, |
| 438 | &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth); |
| 439 | while(pEnt->dev) |
| 440 | { |
| 441 | GetClientRect(pEnt->hwndStatic, &r); |
| 442 | MapWindowPoints(pEnt->hwndStatic, hwndDevView, ((POINT *) &r), 2); |
| 443 | MoveWindow(pEnt->hwndStatic, nStaticPos, r.top, nStaticWidth, r.bottom - r.top, FALSE); |
| 444 | MoveWindow(pEnt->hwndEdit, nEditPos, r.top, nEditWidth, r.bottom - r.top, FALSE); |
| 445 | MoveWindow(pEnt->hwndBrowseButton, nButtonPos, r.top, nButtonWidth, r.bottom - r.top, FALSE); |
| 446 | pEnt++; |
| 447 | } |
| 448 | } |
| 449 | break; |
| 450 | } |
| 451 | return rc; |
| 452 | } |
| 453 | |
| 454 | |
| 455 | |
| 456 | void DevView_SetCallbacks(HWND hwndDevView, const struct DevViewCallbacks *pCallbacks) |
| 457 | { |
| 458 | struct DevViewInfo *pDevViewInfo; |
| 459 | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 460 | pDevViewInfo->pCallbacks = pCallbacks; |
| 461 | } |
| 462 | |
| 463 | |
| 464 | |
| 465 | void DevView_RegisterClass(void) |
| 466 | { |
| 467 | WNDCLASS wc; |
| 468 | memset(&wc, 0, sizeof(wc)); |
| 469 | wc.lpszClassName = TEXT("MessSoftwareDevView"); |
| 470 | wc.hInstance = GetModuleHandle(NULL); |
| 471 | wc.lpfnWndProc = DevView_WndProc; |
| 472 | wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); |
| 473 | RegisterClass(&wc); |
| 474 | } |
| 475 | |
| 476 | |
| 477 | |
src/osd/winui/menu.c
| r0 | r10259 | |
| 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 | } |
src/osd/winui/layoutms.c
| r0 | r10259 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | layoutms.c |
| 4 | |
| 5 | MESS specific TreeView definitions (and maybe more in the future) |
| 6 | |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | #define WIN32_LEAN_AND_MEAN |
| 10 | #include <windows.h> |
| 11 | #include <windowsx.h> |
| 12 | #include <shellapi.h> |
| 13 | #include <commctrl.h> |
| 14 | #include <stdio.h> /* for sprintf */ |
| 15 | #include <stdlib.h> /* For malloc and free */ |
| 16 | #include <string.h> |
| 17 | |
| 18 | #include "emu.h" |
| 19 | #include "bitmask.h" |
| 20 | #include "TreeView.h" |
| 21 | #include "mui_util.h" |
| 22 | #include "resource.h" |
| 23 | #include "directories.h" |
| 24 | #include "mui_opts.h" |
| 25 | #include "splitters.h" |
| 26 | #include "help.h" |
| 27 | #include "mui_audit.h" |
| 28 | #include "screenshot.h" |
| 29 | #include "winui.h" |
| 30 | #include "properties.h" |
| 31 | |
| 32 | #include "msuiutil.h" |
| 33 | #include "resourcems.h" |
| 34 | #include "propertiesms.h" |
| 35 | |
| 36 | static BOOL FilterAvailable(int driver_index); |
| 37 | |
| 38 | extern const FOLDERDATA g_folderData[] = |
| 39 | { |
| 40 | {"All Systems", "allgames", FOLDER_ALLGAMES, IDI_FOLDER, 0, 0, NULL, NULL, TRUE }, |
| 41 | {"Available", "available", FOLDER_AVAILABLE, IDI_FOLDER_AVAILABLE, F_AVAILABLE, 0, NULL, FilterAvailable, TRUE }, |
| 42 | #ifdef SHOW_UNAVAILABLE_FOLDER |
| 43 | {"Unavailable", "unavailable", FOLDER_UNAVAILABLE, IDI_FOLDER_UNAVAILABLE, 0, F_AVAILABLE, NULL, FilterAvailable, FALSE }, |
| 44 | #endif |
| 45 | {"Console", "console", FOLDER_CONSOLE, IDI_FOLDER, F_CONSOLE, F_COMPUTER, NULL, DriverIsConsole, TRUE }, |
| 46 | {"Computer", "computer", FOLDER_COMPUTER, IDI_FOLDER, F_COMPUTER, F_CONSOLE, NULL, DriverIsComputer, TRUE }, |
| 47 | {"Modified/Hacked", "modified", FOLDER_MODIFIED, IDI_FOLDER, 0, 0, NULL, DriverIsModified, TRUE }, |
| 48 | {"Manufacturer", "manufacturer", FOLDER_MANUFACTURER, IDI_FOLDER_MANUFACTURER, 0, 0, CreateManufacturerFolders }, |
| 49 | {"Year", "year", FOLDER_YEAR, IDI_FOLDER_YEAR, 0, 0, CreateYearFolders }, |
| 50 | {"Source", "source", FOLDER_SOURCE, IDI_FOLDER_SOURCE, 0, 0, CreateSourceFolders }, |
| 51 | {"CPU", "cpu", FOLDER_CPU, IDI_FOLDER, 0, 0, CreateCPUFolders }, |
| 52 | {"Sound", "sound", FOLDER_SND, IDI_FOLDER, 0, 0, CreateSoundFolders }, |
| 53 | {"Imperfect", "imperfect", FOLDER_DEFICIENCY, IDI_FOLDER, 0, 0, CreateDeficiencyFolders }, |
| 54 | {"Dumping Status", "dumping", FOLDER_DUMPING, IDI_FOLDER, 0, 0, CreateDumpingFolders }, |
| 55 | {"Working", "working", FOLDER_WORKING, IDI_WORKING, F_WORKING, F_NONWORKING, NULL, DriverIsBroken, FALSE }, |
| 56 | {"Not Working", "nonworking", FOLDER_NONWORKING, IDI_NONWORKING, F_NONWORKING, F_WORKING, NULL, DriverIsBroken, TRUE }, |
| 57 | {"Originals", "originals", FOLDER_ORIGINAL, IDI_FOLDER, F_ORIGINALS, F_CLONES, NULL, DriverIsClone, FALSE }, |
| 58 | {"Clones", "clones", FOLDER_CLONES, IDI_FOLDER, F_CLONES, F_ORIGINALS, NULL, DriverIsClone, TRUE }, |
| 59 | {"Raster", "raster", FOLDER_RASTER, IDI_FOLDER, F_RASTER, F_VECTOR, NULL, DriverIsVector, FALSE }, |
| 60 | {"Vector", "vector", FOLDER_VECTOR, IDI_FOLDER, F_VECTOR, F_RASTER, NULL, DriverIsVector, TRUE }, |
| 61 | {"Mouse", "mouse", FOLDER_MOUSE, IDI_FOLDER, 0, 0, NULL, DriverUsesMouse, TRUE }, |
| 62 | {"Trackball", "trackball", FOLDER_TRACKBALL, IDI_FOLDER, 0, 0, NULL, DriverUsesTrackball, TRUE }, |
| 63 | {"Stereo", "stereo", FOLDER_STEREO, IDI_SOUND, 0, 0, NULL, DriverIsStereo, TRUE }, |
| 64 | { NULL } |
| 65 | }; |
| 66 | |
| 67 | /* list of filter/control Id pairs */ |
| 68 | extern const FILTER_ITEM g_filterList[] = |
| 69 | { |
| 70 | { F_COMPUTER, IDC_FILTER_COMPUTER, DriverIsComputer, TRUE }, |
| 71 | { F_CONSOLE, IDC_FILTER_CONSOLE, DriverIsConsole, TRUE }, |
| 72 | { F_MODIFIED, IDC_FILTER_MODIFIED, DriverIsModified, TRUE }, |
| 73 | { F_CLONES, IDC_FILTER_CLONES, DriverIsClone, TRUE }, |
| 74 | { F_NONWORKING, IDC_FILTER_NONWORKING, DriverIsBroken, TRUE }, |
| 75 | { F_UNAVAILABLE, IDC_FILTER_UNAVAILABLE, FilterAvailable, FALSE }, |
| 76 | { F_RASTER, IDC_FILTER_RASTER, DriverIsVector, FALSE }, |
| 77 | { F_VECTOR, IDC_FILTER_VECTOR, DriverIsVector, TRUE }, |
| 78 | { F_ORIGINALS, IDC_FILTER_ORIGINALS, DriverIsClone, FALSE }, |
| 79 | { F_WORKING, IDC_FILTER_WORKING, DriverIsBroken, FALSE }, |
| 80 | { F_AVAILABLE, IDC_FILTER_AVAILABLE, FilterAvailable, TRUE }, |
| 81 | { 0 } |
| 82 | }; |
| 83 | |
| 84 | extern const DIRECTORYINFO g_directoryInfo[] = |
| 85 | { |
| 86 | { "ROMs", GetRomDirs, SetRomDirs, TRUE, DIRDLG_ROMS }, |
| 87 | { "Software", GetSoftwareDirs, SetSoftwareDirs, TRUE, DIRDLG_SOFTWARE }, |
| 88 | { "Artwork", GetArtDir, SetArtDir, FALSE, 0 }, |
| 89 | { "Background Images", GetBgDir, SetBgDir, FALSE, 0 }, |
| 90 | { "Cabinets", GetCabinetDir, SetCabinetDir, FALSE, 0 }, |
| 91 | { "Cheats", GetCheatDir, SetCheatDir, FALSE, DIRDLG_CHEAT }, |
| 92 | { "Comment Files", GetCommentDir, SetCommentDir, FALSE, DIRDLG_COMMENT }, |
| 93 | { "Config", GetCfgDir, SetCfgDir, FALSE, DIRDLG_CFG }, |
| 94 | { "Control Panels", GetControlPanelDir, SetControlPanelDir, FALSE, 0 }, |
| 95 | { "Controller Files", GetCtrlrDir, SetCtrlrDir, FALSE, DIRDLG_CTRLR }, |
| 96 | { "Crosshairs", GetCrosshairDir, SetCrosshairDir, FALSE, 0 }, |
| 97 | { "Fonts", GetFontDir, SetFontDir, FALSE, 0 }, |
| 98 | { "Flyers", GetFlyerDir, SetFlyerDir, FALSE, 0 }, |
| 99 | { "Hash", GetHashDirs, SetHashDirs, FALSE, 0 }, |
| 100 | { "Hard Drive Difference", GetDiffDir, SetDiffDir, FALSE, 0 }, |
| 101 | { "Icons", GetIconsDir, SetIconsDir, FALSE, 0 }, |
| 102 | { "Ini Files", GetIniDir, SetIniDir, FALSE, DIRDLG_INI }, |
| 103 | { "Input files", GetInpDir, SetInpDir, FALSE, DIRDLG_INP }, |
| 104 | { "Marquees", GetMarqueeDir, SetMarqueeDir, FALSE, 0 }, |
| 105 | { "Memory Card", GetMemcardDir, SetMemcardDir, FALSE, 0 }, |
| 106 | { "NVRAM", GetNvramDir, SetNvramDir, FALSE, 0 }, |
| 107 | { "PCBs", GetPcbDir, SetPcbDir, FALSE, 0 }, |
| 108 | { "Snapshots", GetImgDir, SetImgDir, FALSE, DIRDLG_IMG }, |
| 109 | { "State", GetStateDir, SetStateDir, FALSE, 0 }, |
| 110 | { "Titles", GetTitlesDir, SetTitlesDir, FALSE, 0 }, |
| 111 | { NULL } |
| 112 | }; |
| 113 | |
| 114 | extern const SPLITTERINFO g_splitterInfo[] = |
| 115 | { |
| 116 | { 0.2, IDC_SPLITTER, IDC_TREE, IDC_LIST, AdjustSplitter1Rect }, |
| 117 | { 0.4, IDC_SPLITTER2, IDC_LIST, IDC_SWLIST, AdjustSplitter1Rect }, |
| 118 | { 0.6, IDC_SPLITTER3, IDC_SWTAB, IDC_SSFRAME, AdjustSplitter2Rect }, |
| 119 | { -1 } |
| 120 | }; |
| 121 | |
| 122 | extern const MAMEHELPINFO g_helpInfo[] = |
| 123 | { |
| 124 | { ID_HELP_CONTENTS, TRUE, "mess.chm::/windows/main.htm" }, |
| 125 | { ID_HELP_RELEASE, TRUE, "mess.chm" }, |
| 126 | { ID_HELP_WHATS_NEW, TRUE, "mess.chm::/messnew.txt" }, |
| 127 | { -1 } |
| 128 | }; |
| 129 | |
| 130 | extern const PROPERTYSHEETINFO g_propSheets[] = |
| 131 | { |
| 132 | { FALSE, NULL, IDD_PROP_GAME, GamePropertiesDialogProc }, |
| 133 | { FALSE, NULL, IDD_PROP_AUDIT, GameAuditDialogProc }, |
| 134 | { TRUE, NULL, IDD_PROP_DISPLAY, GameOptionsProc }, |
| 135 | { TRUE, NULL, IDD_PROP_ADVANCED, GameOptionsProc }, |
| 136 | { TRUE, NULL, IDD_PROP_SCREEN, GameOptionsProc }, |
| 137 | { TRUE, NULL, IDD_PROP_SOUND, GameOptionsProc }, |
| 138 | { TRUE, NULL, IDD_PROP_INPUT, GameOptionsProc }, |
| 139 | { TRUE, NULL, IDD_PROP_CONTROLLER, GameOptionsProc }, |
| 140 | { TRUE, NULL, IDD_PROP_DEBUG, GameOptionsProc }, |
| 141 | { TRUE, NULL, IDD_PROP_MISC, GameOptionsProc }, |
| 142 | { FALSE, NULL, IDD_PROP_SOFTWARE, GameMessOptionsProc }, |
| 143 | { FALSE, PropSheetFilter_Config, IDD_PROP_CONFIGURATION, GameMessOptionsProc }, |
| 144 | { TRUE, PropSheetFilter_Vector, IDD_PROP_VECTOR, GameOptionsProc }, |
| 145 | { FALSE } |
| 146 | }; |
| 147 | |
| 148 | extern const ICONDATA g_iconData[] = |
| 149 | { |
| 150 | { IDI_WIN_NOROMS, "noroms" }, |
| 151 | { IDI_WIN_ROMS, "roms" }, |
| 152 | { IDI_WIN_UNKNOWN, "unknown" }, |
| 153 | { IDI_WIN_CLONE, "clone" }, |
| 154 | { IDI_WIN_REDX, "warning" }, |
| 155 | { IDI_WIN_NOROMSNEEDED, "noromsneeded" }, |
| 156 | { IDI_WIN_MISSINGOPTROM, "missingoptrom" }, |
| 157 | { IDI_WIN_FLOP, "floppy" }, |
| 158 | { IDI_WIN_CASS, "cassette" }, |
| 159 | { IDI_WIN_SERL, "serial" }, |
| 160 | { IDI_WIN_SNAP, "snapshot" }, |
| 161 | { IDI_WIN_PRIN, "printer" }, |
| 162 | { IDI_WIN_HARD, "hard" }, |
| 163 | { 0 } |
| 164 | }; |
| 165 | |
| 166 | extern const TCHAR g_szPlayGameString[] = TEXT("&Run %s"); |
| 167 | extern const char g_szGameCountString[] = "%d systems"; |
| 168 | static const char g_szHistoryFileName[] = "sysinfo.dat"; |
| 169 | static const char g_szMameInfoFileName[] = "messinfo.dat"; |
| 170 | |
| 171 | static BOOL FilterAvailable(int driver_index) |
| 172 | { |
| 173 | return !DriverUsesRoms(driver_index) || IsAuditResultYes(GetRomAuditResults(driver_index)); |
| 174 | } |
src/osd/winui/propertiesms.c
| r0 | r10259 | |
| 1 | #define WIN32_LEAN_AND_MEAN |
| 2 | |
| 3 | #ifndef _MSC_VER |
| 4 | #define NONAMELESSUNION 1 |
| 5 | #endif |
| 6 | |
| 7 | #include <windows.h> |
| 8 | #include <string.h> |
| 9 | #include <assert.h> |
| 10 | #include <commctrl.h> |
| 11 | #include <commdlg.h> |
| 12 | #include <windowsx.h> |
| 13 | #include <sys/stat.h> |
| 14 | #include <stdio.h> |
| 15 | #include <tchar.h> |
| 16 | |
| 17 | #include "emu.h" |
| 18 | #include "emuopts.h" |
| 19 | #include "image.h" |
| 20 | #include "screenshot.h" |
| 21 | #include "datamap.h" |
| 22 | #include "bitmask.h" |
| 23 | #include "winui.h" |
| 24 | #include "directories.h" |
| 25 | #include "mui_util.h" |
| 26 | #include "mui_opts.h" |
| 27 | #include "resourcems.h" |
| 28 | #include "propertiesms.h" |
| 29 | #include "optionsms.h" |
| 30 | #include "msuiutil.h" |
| 31 | #include "strconv.h" |
| 32 | #include "winutf8.h" |
| 33 | #include "machine/ram.h" |
| 34 | |
| 35 | static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem); |
| 36 | static BOOL SoftwareDirectories_OnDelete(HWND hDlg); |
| 37 | static BOOL SoftwareDirectories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR); |
| 38 | static BOOL SoftwareDirectories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR); |
| 39 | |
| 40 | extern BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult); |
| 41 | BOOL g_bModifiedSoftwarePaths = FALSE; |
| 42 | |
| 43 | |
| 44 | |
| 45 | static void MarkChanged(HWND hDlg) |
| 46 | { |
| 47 | HWND hCtrl; |
| 48 | |
| 49 | /* fake a CBN_SELCHANGE event from IDC_SIZES to force it to be changed */ |
| 50 | hCtrl = GetDlgItem(hDlg, IDC_SIZES); |
| 51 | PostMessage(hDlg, WM_COMMAND, (CBN_SELCHANGE << 16) | IDC_SIZES, (LPARAM) hCtrl); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | |
| 56 | static void AppendList(HWND hList, LPCTSTR lpItem, int nItem) |
| 57 | { |
| 58 | LV_ITEM Item; |
| 59 | HRESULT res; |
| 60 | memset(&Item, 0, sizeof(LV_ITEM)); |
| 61 | Item.mask = LVIF_TEXT; |
| 62 | Item.pszText = (LPTSTR) lpItem; |
| 63 | Item.iItem = nItem; |
| 64 | res = ListView_InsertItem(hList, &Item); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | |
| 69 | static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem) |
| 70 | { |
| 71 | int nItem; |
| 72 | TCHAR inbuf[MAX_PATH]; |
| 73 | TCHAR outbuf[MAX_PATH]; |
| 74 | HWND hList; |
| 75 | LPTSTR lpIn; |
| 76 | BOOL res; |
| 77 | |
| 78 | g_bModifiedSoftwarePaths = TRUE; |
| 79 | |
| 80 | hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 81 | nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); |
| 82 | |
| 83 | if (nItem == -1) |
| 84 | return FALSE; |
| 85 | |
| 86 | /* Last item is placeholder for append */ |
| 87 | if (nItem == ListView_GetItemCount(hList) - 1) |
| 88 | { |
| 89 | bBrowse = FALSE; |
| 90 | } |
| 91 | |
| 92 | if (!lpItem) { |
| 93 | if (bBrowse) { |
| 94 | ListView_GetItemText(hList, nItem, 0, inbuf, ARRAY_LENGTH(inbuf)); |
| 95 | lpIn = inbuf; |
| 96 | } |
| 97 | else { |
| 98 | lpIn = NULL; |
| 99 | } |
| 100 | |
| 101 | if (!BrowseForDirectory(hDlg, lpIn, outbuf)) |
| 102 | return FALSE; |
| 103 | lpItem = outbuf; |
| 104 | } |
| 105 | |
| 106 | AppendList(hList, lpItem, nItem); |
| 107 | if (bBrowse) |
| 108 | res = ListView_DeleteItem(hList, nItem+1); |
| 109 | MarkChanged(hDlg); |
| 110 | return TRUE; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | |
| 115 | static BOOL SoftwareDirectories_OnDelete(HWND hDlg) |
| 116 | { |
| 117 | int nCount; |
| 118 | int nSelect; |
| 119 | int nItem; |
| 120 | HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 121 | BOOL res; |
| 122 | |
| 123 | g_bModifiedSoftwarePaths = TRUE; |
| 124 | |
| 125 | nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL); |
| 126 | |
| 127 | if (nItem == -1) |
| 128 | return FALSE; |
| 129 | |
| 130 | /* Don't delete "Append" placeholder. */ |
| 131 | if (nItem == ListView_GetItemCount(hList) - 1) |
| 132 | return FALSE; |
| 133 | |
| 134 | res = ListView_DeleteItem(hList, nItem); |
| 135 | |
| 136 | nCount = ListView_GetItemCount(hList); |
| 137 | if (nCount <= 1) |
| 138 | return FALSE; |
| 139 | |
| 140 | /* If the last item was removed, select the item above. */ |
| 141 | if (nItem == nCount - 1) |
| 142 | nSelect = nCount - 2; |
| 143 | else |
| 144 | nSelect = nItem; |
| 145 | |
| 146 | ListView_SetItemState(hList, nSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); |
| 147 | MarkChanged(hDlg); |
| 148 | return TRUE; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | |
| 153 | static BOOL SoftwareDirectories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR) |
| 154 | { |
| 155 | BOOL bResult = FALSE; |
| 156 | NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; |
| 157 | LVITEM* pItem = &pDispInfo->item; |
| 158 | HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 159 | |
| 160 | /* Last item is placeholder for append */ |
| 161 | if (pItem->iItem == ListView_GetItemCount(hList) - 1) |
| 162 | { |
| 163 | HWND hEdit = (HWND) (FPTR) SendMessage(hList, LVM_GETEDITCONTROL, 0, 0); |
| 164 | win_set_window_text_utf8(hEdit, ""); |
| 165 | } |
| 166 | |
| 167 | return bResult; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | static BOOL SoftwareDirectories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR) |
| 173 | { |
| 174 | BOOL bResult = FALSE; |
| 175 | NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; |
| 176 | LVITEM* pItem = &pDispInfo->item; |
| 177 | |
| 178 | if (pItem->pszText != NULL) |
| 179 | { |
| 180 | struct _stat file_stat; |
| 181 | |
| 182 | /* Don't allow empty entries. */ |
| 183 | if (!_tcscmp(pItem->pszText, TEXT(""))) |
| 184 | { |
| 185 | return FALSE; |
| 186 | } |
| 187 | |
| 188 | /* Check validity of edited directory. */ |
| 189 | if (_tstat(pItem->pszText, &file_stat) == 0 |
| 190 | && (file_stat.st_mode & S_IFDIR)) |
| 191 | { |
| 192 | bResult = TRUE; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | if (win_message_box_utf8(NULL, "Directory does not exist, continue anyway?", MAMEUINAME, MB_OKCANCEL) == IDOK) |
| 197 | bResult = TRUE; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if (bResult == TRUE) |
| 202 | { |
| 203 | SoftwareDirectories_OnInsertBrowse(hDlg, TRUE, pItem->pszText); |
| 204 | } |
| 205 | |
| 206 | return bResult; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | |
| 211 | BOOL PropSheetFilter_Config(const machine_config *drv, const game_driver *gamedrv) |
| 212 | { |
| 213 | return (drv->m_devicelist.first(RAM)!=NULL) || DriverHasDevice(gamedrv, IO_PRINTER); |
| 214 | } |
| 215 | |
| 216 | |
| 217 | |
| 218 | INT_PTR CALLBACK GameMessOptionsProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) |
| 219 | { |
| 220 | INT_PTR rc = 0; |
| 221 | BOOL bHandled = FALSE; |
| 222 | |
| 223 | switch (Msg) { |
| 224 | case WM_NOTIFY: |
| 225 | switch (((NMHDR *) lParam)->code) { |
| 226 | case LVN_ENDLABELEDIT: |
| 227 | rc = SoftwareDirectories_OnEndLabelEdit(hDlg, (NMHDR *) lParam); |
| 228 | bHandled = TRUE; |
| 229 | break; |
| 230 | |
| 231 | case LVN_BEGINLABELEDIT: |
| 232 | rc = SoftwareDirectories_OnBeginLabelEdit(hDlg, (NMHDR *) lParam); |
| 233 | bHandled = TRUE; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (!bHandled) |
| 239 | rc = GameOptionsProc(hDlg, Msg, wParam, lParam); |
| 240 | return rc; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | |
| 245 | BOOL MessPropertiesCommand(HWND hWnd, WORD wNotifyCode, WORD wID, BOOL *changed) |
| 246 | { |
| 247 | BOOL handled = TRUE; |
| 248 | |
| 249 | switch(wID) |
| 250 | { |
| 251 | case IDC_DIR_BROWSE: |
| 252 | if (wNotifyCode == BN_CLICKED) |
| 253 | *changed = SoftwareDirectories_OnInsertBrowse(hWnd, TRUE, NULL); |
| 254 | break; |
| 255 | |
| 256 | case IDC_DIR_INSERT: |
| 257 | if (wNotifyCode == BN_CLICKED) |
| 258 | *changed = SoftwareDirectories_OnInsertBrowse(hWnd, FALSE, NULL); |
| 259 | break; |
| 260 | |
| 261 | case IDC_DIR_DELETE: |
| 262 | if (wNotifyCode == BN_CLICKED) |
| 263 | *changed = SoftwareDirectories_OnDelete(hWnd); |
| 264 | break; |
| 265 | |
| 266 | default: |
| 267 | handled = FALSE; |
| 268 | break; |
| 269 | } |
| 270 | return handled; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | //============================================================ |
| 276 | // DATAMAP HANDLERS |
| 277 | //============================================================ |
| 278 | |
| 279 | static BOOL DirListReadControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 280 | { |
| 281 | int directory_count; |
| 282 | LV_ITEM lvi; |
| 283 | TCHAR buffer[2048]; |
| 284 | char *utf8_dir_list; |
| 285 | int i, pos, driver_index; |
| 286 | BOOL res; |
| 287 | |
| 288 | // determine the directory count; note that one item is the "< >" entry |
| 289 | directory_count = ListView_GetItemCount(control); |
| 290 | if (directory_count > 0) |
| 291 | directory_count--; |
| 292 | |
| 293 | buffer[0] = '\0'; |
| 294 | pos = 0; |
| 295 | |
| 296 | for (i = 0; i < directory_count; i++) |
| 297 | { |
| 298 | // append a semicolon, if we're past the first entry |
| 299 | if (i > 0) |
| 300 | pos += _sntprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, TEXT(";")); |
| 301 | |
| 302 | // retrieve the next entry |
| 303 | memset(&lvi, '\0', sizeof(lvi)); |
| 304 | lvi.mask = LVIF_TEXT; |
| 305 | lvi.iItem = i; |
| 306 | lvi.pszText = &buffer[pos]; |
| 307 | lvi.cchTextMax = ARRAY_LENGTH(buffer) - pos; |
| 308 | res = ListView_GetItem(control, &lvi); |
| 309 | |
| 310 | // advance the position |
| 311 | pos += _tcslen(&buffer[pos]); |
| 312 | } |
| 313 | |
| 314 | utf8_dir_list = utf8_from_tstring(buffer); |
| 315 | if (utf8_dir_list != NULL) |
| 316 | { |
| 317 | driver_index = PropertiesCurrentGame(dialog); |
| 318 | SetExtraSoftwarePaths(driver_index, utf8_dir_list); |
| 319 | osd_free(utf8_dir_list); |
| 320 | } |
| 321 | return TRUE; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | |
| 326 | static BOOL DirListPopulateControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 327 | { |
| 328 | int driver_index, pos, new_pos, current_item; |
| 329 | const char *dir_list; |
| 330 | TCHAR *t_dir_list; |
| 331 | TCHAR *s; |
| 332 | LV_COLUMN lvc; |
| 333 | RECT r; |
| 334 | HRESULT res; |
| 335 | BOOL b_res; |
| 336 | |
| 337 | // access the directory list, and convert to TCHARs |
| 338 | driver_index = PropertiesCurrentGame(dialog); |
| 339 | dir_list = GetExtraSoftwarePaths(driver_index); |
| 340 | t_dir_list = tstring_from_utf8(dir_list); |
| 341 | if (!t_dir_list) |
| 342 | return FALSE; |
| 343 | |
| 344 | // delete all items in the list control |
| 345 | b_res = ListView_DeleteAllItems(control); |
| 346 | |
| 347 | // add the column |
| 348 | GetClientRect(control, &r); |
| 349 | memset(&lvc, 0, sizeof(LVCOLUMN)); |
| 350 | lvc.mask = LVCF_WIDTH; |
| 351 | lvc.cx = r.right - r.left - GetSystemMetrics(SM_CXHSCROLL); |
| 352 | res = ListView_InsertColumn(control, 0, &lvc); |
| 353 | |
| 354 | // add each of the directories |
| 355 | pos = 0; |
| 356 | current_item = 0; |
| 357 | while(t_dir_list[pos] != '\0') |
| 358 | { |
| 359 | // parse off this item |
| 360 | s = _tcschr(&t_dir_list[pos], ';'); |
| 361 | if (s != NULL) |
| 362 | { |
| 363 | *s = '\0'; |
| 364 | new_pos = s - t_dir_list + 1; |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | new_pos = pos + _tcslen(&t_dir_list[pos]); |
| 369 | } |
| 370 | |
| 371 | // append this item |
| 372 | AppendList(control, &t_dir_list[pos], current_item); |
| 373 | |
| 374 | // advance to next item |
| 375 | pos = new_pos; |
| 376 | current_item++; |
| 377 | } |
| 378 | |
| 379 | // finish up |
| 380 | AppendList(control, TEXT(DIRLIST_NEWENTRYTEXT), current_item); |
| 381 | ListView_SetItemState(control, 0, LVIS_SELECTED, LVIS_SELECTED); |
| 382 | osd_free(t_dir_list); |
| 383 | return TRUE; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | |
| 388 | static BOOL RamPopulateControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 389 | { |
| 390 | int i, current_index, driver_index; |
| 391 | const game_driver *gamedrv; |
| 392 | UINT32 ram, current_ram; |
| 393 | const char *this_ram_string; |
| 394 | TCHAR* t_ramstring; |
| 395 | const device_config *device; |
| 396 | |
| 397 | // identify the driver |
| 398 | driver_index = PropertiesCurrentGame(dialog); |
| 399 | gamedrv = drivers[driver_index]; |
| 400 | |
| 401 | // clear out the combo box |
| 402 | (void)ComboBox_ResetContent(control); |
| 403 | |
| 404 | // allocate the machine config |
| 405 | machine_config cfg(*gamedrv); |
| 406 | |
| 407 | // identify how many options that we have |
| 408 | device = cfg.m_devicelist.first(RAM); |
| 409 | |
| 410 | EnableWindow(control, (device != NULL)); |
| 411 | i = 0; |
| 412 | // we can only do something meaningful if there is more than one option |
| 413 | if (device != NULL) |
| 414 | { |
| 415 | ram_config *config = (ram_config *)downcast<const legacy_device_config_base *>(device)->inline_config(); |
| 416 | |
| 417 | // identify the current amount of RAM |
| 418 | this_ram_string = options_get_string(opts, OPTION_RAMSIZE); |
| 419 | current_ram = (this_ram_string != NULL) ? ram_parse_string(this_ram_string) : 0; |
| 420 | if (current_ram == 0) |
| 421 | current_ram = ram_parse_string(config->default_size); |
| 422 | |
| 423 | // by default, assume index 0 |
| 424 | current_index = 0; |
| 425 | |
| 426 | { |
| 427 | ram = ram_parse_string(config->default_size); |
| 428 | t_ramstring = tstring_from_utf8(config->default_size); |
| 429 | if( !t_ramstring ) |
| 430 | return FALSE; |
| 431 | |
| 432 | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 433 | (void)ComboBox_SetItemData(control, i, ram); |
| 434 | |
| 435 | osd_free(t_ramstring); |
| 436 | } |
| 437 | if (config->extra_options != NULL) |
| 438 | { |
| 439 | int j; |
| 440 | int size = strlen(config->extra_options); |
| 441 | char * const s = mame_strdup(config->extra_options); |
| 442 | char * const e = s + size; |
| 443 | char *p = s; |
| 444 | for (j=0;j<size;j++) { |
| 445 | if (p[j]==',') p[j]=0; |
| 446 | } |
| 447 | |
| 448 | /* try to parse each option */ |
| 449 | while(p <= e) |
| 450 | { |
| 451 | i++; |
| 452 | // identify this option |
| 453 | ram = ram_parse_string(p); |
| 454 | |
| 455 | this_ram_string = p; |
| 456 | |
| 457 | t_ramstring = tstring_from_utf8(this_ram_string); |
| 458 | if( !t_ramstring ) |
| 459 | return FALSE; |
| 460 | |
| 461 | // add this option to the combo box |
| 462 | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 463 | (void)ComboBox_SetItemData(control, i, ram); |
| 464 | |
| 465 | osd_free(t_ramstring); |
| 466 | |
| 467 | // is this the current option? record the index if so |
| 468 | if (ram == current_ram) |
| 469 | current_index = i; |
| 470 | |
| 471 | p+= strlen(p); |
| 472 | if (p == e) |
| 473 | break; |
| 474 | |
| 475 | p += 1; |
| 476 | } |
| 477 | |
| 478 | osd_free(s); |
| 479 | } |
| 480 | |
| 481 | // set the combo box |
| 482 | (void)ComboBox_SetCurSel(control, current_index); |
| 483 | } |
| 484 | return TRUE; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | |
| 489 | //============================================================ |
| 490 | // DATAMAP SETUP |
| 491 | //============================================================ |
| 492 | |
| 493 | void MessBuildDataMap(datamap *properties_datamap) |
| 494 | { |
| 495 | // MESS specific stuff |
| 496 | datamap_add(properties_datamap, IDC_DIR_LIST, DM_STRING, NULL); |
| 497 | datamap_add(properties_datamap, IDC_RAM_COMBOBOX, DM_INT, OPTION_RAMSIZE); |
| 498 | // datamap_add(properties_datamap, IDC_USE_NEW_UI, DM_BOOL, "newui"); |
| 499 | |
| 500 | // set up callbacks |
| 501 | datamap_set_callback(properties_datamap, IDC_DIR_LIST, DCT_READ_CONTROL, DirListReadControl); |
| 502 | datamap_set_callback(properties_datamap, IDC_DIR_LIST, DCT_POPULATE_CONTROL, DirListPopulateControl); |
| 503 | datamap_set_callback(properties_datamap, IDC_RAM_COMBOBOX, DCT_POPULATE_CONTROL, RamPopulateControl); |
| 504 | } |
src/osd/winui/softwarepicker.c
| r0 | r10259 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // softwarepicker.c - MESS's software picker |
| 4 | // |
| 5 | //============================================================ |
| 6 | |
| 7 | #define WIN32_LEAN_AND_MEAN |
| 8 | #include <assert.h> |
| 9 | #include <string.h> |
| 10 | #include <windows.h> |
| 11 | #include <shellapi.h> |
| 12 | #include <commctrl.h> |
| 13 | #include <commdlg.h> |
| 14 | #include <wingdi.h> |
| 15 | #include <winuser.h> |
| 16 | #include <tchar.h> |
| 17 | #include <ctype.h> |
| 18 | |
| 19 | #include "emu.h" |
| 20 | #include "unzip.h" |
| 21 | #include "strconv.h" |
| 22 | #include "hashfile.h" |
| 23 | #include "picker.h" |
| 24 | #include "screenshot.h" |
| 25 | #include "bitmask.h" |
| 26 | #include "winui.h" |
| 27 | #include "optionsms.h" |
| 28 | #include "resourcems.h" |
| 29 | #include "mui_opts.h" |
| 30 | #include "softwarepicker.h" |
| 31 | #include "mui_util.h" |
| 32 | |
| 33 | |
| 34 | |
| 35 | //============================================================ |
| 36 | // TYPE DEFINITIONS |
| 37 | //============================================================ |
| 38 | |
| 39 | typedef struct _file_info file_info; |
| 40 | struct _file_info |
| 41 | { |
| 42 | const device_config_image_interface *device; |
| 43 | |
| 44 | // hash information |
| 45 | char hash_string[HASH_BUF_SIZE]; |
| 46 | BOOL hash_realized; |
| 47 | const hash_info *hashinfo; |
| 48 | |
| 49 | const char *zip_entry_name; |
| 50 | const char *base_name; |
| 51 | char file_name[1]; |
| 52 | }; |
| 53 | |
| 54 | typedef struct _directory_search_info directory_search_info; |
| 55 | struct _directory_search_info |
| 56 | { |
| 57 | directory_search_info *next; |
| 58 | HANDLE find_handle; |
| 59 | WIN32_FIND_DATA fd; |
| 60 | char directory_name[1]; |
| 61 | }; |
| 62 | |
| 63 | typedef struct _software_picker_info software_picker_info; |
| 64 | struct _software_picker_info |
| 65 | { |
| 66 | WNDPROC old_window_proc; |
| 67 | file_info **file_index; |
| 68 | int file_index_length; |
| 69 | int hashes_realized; |
| 70 | int current_position; |
| 71 | directory_search_info *first_search_info; |
| 72 | directory_search_info *last_search_info; |
| 73 | const software_config *config; |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | |
| 78 | //============================================================ |
| 79 | // CONSTANTS |
| 80 | //============================================================ |
| 81 | |
| 82 | static const TCHAR software_picker_property_name[] = TEXT("SWPICKER"); |
| 83 | |
| 84 | |
| 85 | |
| 86 | //============================================================ |
| 87 | |
| 88 | static LPCSTR NormalizePath(LPCSTR pszPath, LPSTR pszBuffer, size_t nBufferSize) |
| 89 | { |
| 90 | BOOL bChanged = FALSE; |
| 91 | LPSTR s; |
| 92 | int i, j; |
| 93 | |
| 94 | if (pszPath[0] == '\\') |
| 95 | { |
| 96 | win_get_current_directory_utf8(nBufferSize, pszBuffer); |
| 97 | pszBuffer[2] = '\0'; |
| 98 | bChanged = TRUE; |
| 99 | } |
| 100 | else if (!isalpha(pszPath[0]) || (pszPath[1] != ':')) |
| 101 | { |
| 102 | win_get_current_directory_utf8(nBufferSize, pszBuffer); |
| 103 | bChanged = TRUE; |
| 104 | } |
| 105 | |
| 106 | if (bChanged) |
| 107 | { |
| 108 | s = (LPSTR) alloca(strlen(pszBuffer) + 1); |
| 109 | strcpy(s, pszBuffer); |
| 110 | snprintf(pszBuffer, nBufferSize, "%s\\%s", s, pszPath); |
| 111 | pszPath = pszBuffer; |
| 112 | |
| 113 | // Remove double path separators |
| 114 | i = 0; |
| 115 | j = 0; |
| 116 | while(pszBuffer[i]) |
| 117 | { |
| 118 | while ((pszBuffer[i] == '\\') && (pszBuffer[i+1] == '\\')) |
| 119 | i++; |
| 120 | pszBuffer[j++] = pszBuffer[i++]; |
| 121 | } |
| 122 | pszBuffer[j] = '\0'; |
| 123 | } |
| 124 | return pszPath; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | static software_picker_info *GetSoftwarePickerInfo(HWND hwndPicker) |
| 130 | { |
| 131 | HANDLE h; |
| 132 | h = GetProp(hwndPicker, software_picker_property_name); |
| 133 | assert(h); |
| 134 | return (software_picker_info *) h; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | LPCSTR SoftwarePicker_LookupFilename(HWND hwndPicker, int nIndex) |
| 140 | { |
| 141 | software_picker_info *pPickerInfo; |
| 142 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 143 | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 144 | return NULL; |
| 145 | return pPickerInfo->file_index[nIndex]->file_name; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | |
| 150 | const device_config_image_interface *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex) |
| 151 | { |
| 152 | software_picker_info *pPickerInfo; |
| 153 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 154 | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 155 | { |
| 156 | return NULL; |
| 157 | } |
| 158 | return pPickerInfo->file_index[nIndex]->device; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | |
| 163 | int SoftwarePicker_LookupIndex(HWND hwndPicker, LPCSTR pszFilename) |
| 164 | { |
| 165 | software_picker_info *pPickerInfo; |
| 166 | int i; |
| 167 | |
| 168 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 169 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 170 | { |
| 171 | if (!mame_stricmp(pPickerInfo->file_index[i]->file_name, pszFilename)) |
| 172 | return i; |
| 173 | } |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | |
| 179 | iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex) |
| 180 | { |
| 181 | iodevice_t type; |
| 182 | const device_config_image_interface *device = SoftwarePicker_LookupDevice(hwndPicker, nIndex); |
| 183 | |
| 184 | if (device != NULL) |
| 185 | { |
| 186 | type = device->image_type(); |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | type = IO_UNKNOWN; |
| 191 | } |
| 192 | return type; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | |
| 197 | void SoftwarePicker_SetDriver(HWND hwndPicker, const software_config *config) |
| 198 | { |
| 199 | int i; |
| 200 | software_picker_info *pPickerInfo; |
| 201 | |
| 202 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 203 | pPickerInfo->config = config; |
| 204 | |
| 205 | // invalidate the hash "realization" |
| 206 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 207 | { |
| 208 | pPickerInfo->file_index[i]->hashinfo = NULL; |
| 209 | pPickerInfo->file_index[i]->hash_realized = FALSE; |
| 210 | } |
| 211 | pPickerInfo->hashes_realized = 0; |
| 212 | } |
| 213 | |
| 214 | |
| 215 | |
| 216 | static void ComputeFileHash(software_picker_info *pPickerInfo, |
| 217 | file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength) |
| 218 | { |
| 219 | unsigned int functions; |
| 220 | |
| 221 | // determine which functions to use |
| 222 | functions = hashfile_functions_used(pPickerInfo->config->hashfile, pFileInfo->device->image_type()); |
| 223 | |
| 224 | // compute the hash |
| 225 | pFileInfo->device->device_compute_hash((char *)pFileInfo->hash_string, (const void *)pBuffer, (size_t)nLength, functions); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | static BOOL SoftwarePicker_CalculateHash(HWND hwndPicker, int nIndex) |
| 231 | { |
| 232 | software_picker_info *pPickerInfo; |
| 233 | file_info *pFileInfo; |
| 234 | LPSTR pszZipName; |
| 235 | BOOL rc = FALSE; |
| 236 | unsigned char *pBuffer; |
| 237 | unsigned int nLength; |
| 238 | HANDLE hFile, hFileMapping; |
| 239 | LVFINDINFO lvfi; |
| 240 | BOOL res; |
| 241 | |
| 242 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 243 | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 244 | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 245 | |
| 246 | if (pFileInfo->zip_entry_name) |
| 247 | { |
| 248 | // this is in a ZIP file |
| 249 | zip_file *zip; |
| 250 | zip_error ziperr; |
| 251 | const zip_file_header *zipent; |
| 252 | |
| 253 | // open the ZIP file |
| 254 | nLength = pFileInfo->zip_entry_name - pFileInfo->file_name; |
| 255 | pszZipName = (LPSTR) alloca(nLength); |
| 256 | memcpy(pszZipName, pFileInfo->file_name, nLength); |
| 257 | pszZipName[nLength - 1] = '\0'; |
| 258 | |
| 259 | // get the entry name |
| 260 | ziperr = zip_file_open(pszZipName, &zip); |
| 261 | if (ziperr == ZIPERR_NONE) |
| 262 | { |
| 263 | zipent = zip_file_first_file(zip); |
| 264 | while(!rc && zipent) |
| 265 | { |
| 266 | if (!mame_stricmp(zipent->filename, pFileInfo->zip_entry_name)) |
| 267 | { |
| 268 | pBuffer = (unsigned char *)malloc(zipent->uncompressed_length); |
| 269 | if (pBuffer) |
| 270 | { |
| 271 | ziperr = zip_file_decompress(zip, pBuffer, zipent->uncompressed_length); |
| 272 | if (ziperr == ZIPERR_NONE) |
| 273 | { |
| 274 | ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, zipent->uncompressed_length); |
| 275 | rc = TRUE; |
| 276 | } |
| 277 | free(pBuffer); |
| 278 | } |
| 279 | } |
| 280 | zipent = zip_file_next_file(zip); |
| 281 | } |
| 282 | zip_file_close(zip); |
| 283 | } |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | // plain open file; map it into memory and calculate the hash |
| 288 | hFile = win_create_file_utf8(pFileInfo->file_name, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 289 | OPEN_EXISTING, 0, NULL); |
| 290 | if (hFile != INVALID_HANDLE_VALUE) |
| 291 | { |
| 292 | nLength = GetFileSize(hFile, NULL); |
| 293 | hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); |
| 294 | if (hFileMapping) |
| 295 | { |
| 296 | pBuffer = (unsigned char *)MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0); |
| 297 | if (pBuffer) |
| 298 | { |
| 299 | ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, nLength); |
| 300 | UnmapViewOfFile(pBuffer); |
| 301 | rc = TRUE; |
| 302 | } |
| 303 | CloseHandle(hFileMapping); |
| 304 | } |
| 305 | CloseHandle(hFile); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (rc) |
| 310 | { |
| 311 | memset(&lvfi, 0, sizeof(lvfi)); |
| 312 | lvfi.flags = LVFI_PARAM; |
| 313 | lvfi.lParam = nIndex; |
| 314 | nIndex = ListView_FindItem(hwndPicker, -1, &lvfi); |
| 315 | if (nIndex > 0) |
| 316 | res = ListView_RedrawItems(hwndPicker, nIndex, nIndex); |
| 317 | } |
| 318 | |
| 319 | return rc; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | |
| 324 | static void SoftwarePicker_RealizeHash(HWND hwndPicker, int nIndex) |
| 325 | { |
| 326 | software_picker_info *pPickerInfo; |
| 327 | file_info *pFileInfo; |
| 328 | unsigned int nHashFunctionsUsed = 0; |
| 329 | unsigned int nCalculatedHashes = 0; |
| 330 | iodevice_t type; |
| 331 | |
| 332 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 333 | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 334 | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 335 | |
| 336 | // Determine which hash functions we need to use for this file, and which hashes |
| 337 | // have already been calculated |
| 338 | if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL)) |
| 339 | { |
| 340 | type = pFileInfo->device->image_type(); |
| 341 | if (type < IO_COUNT) |
| 342 | nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->config->hashfile, type); |
| 343 | nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string); |
| 344 | } |
| 345 | |
| 346 | // Did we fully compute all hashes? |
| 347 | if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0) |
| 348 | { |
| 349 | // We have calculated all hashs for this file; mark it as realized |
| 350 | pPickerInfo->file_index[nIndex]->hash_realized = TRUE; |
| 351 | pPickerInfo->hashes_realized++; |
| 352 | |
| 353 | if (pPickerInfo->config->hashfile) |
| 354 | { |
| 355 | pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->config->hashfile, |
| 356 | pPickerInfo->file_index[nIndex]->hash_string); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | |
| 363 | static BOOL SoftwarePicker_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename, |
| 364 | UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce) |
| 365 | { |
| 366 | software_picker_info *pPickerInfo; |
| 367 | file_info **ppNewIndex; |
| 368 | file_info *pInfo; |
| 369 | int nIndex, nSize; |
| 370 | LPCSTR pszExtension = NULL; |
| 371 | const device_config_image_interface *device = NULL; |
| 372 | |
| 373 | // first check to see if it is already here |
| 374 | if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0) |
| 375 | return TRUE; |
| 376 | |
| 377 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 378 | |
| 379 | // look up the device |
| 380 | if (strrchr(pszFilename, '.')) |
| 381 | pszExtension = strrchr(pszFilename, '.'); |
| 382 | if ((pszExtension != NULL) && (pPickerInfo->config != NULL)) |
| 383 | { |
| 384 | for (bool gotone = pPickerInfo->config->mconfig->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 385 | { |
| 386 | if (device->uses_file_extension(pszExtension)) { |
| 387 | break; |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | // no device? cop out unless bForce is on |
| 393 | if ((device == NULL) && !bForce) |
| 394 | return TRUE; |
| 395 | |
| 396 | // create the FileInfo structure |
| 397 | nSize = sizeof(file_info) + strlen(pszFilename); |
| 398 | pInfo = (file_info *) malloc(nSize); |
| 399 | if (!pInfo) |
| 400 | goto error; |
| 401 | memset(pInfo, 0, nSize); |
| 402 | |
| 403 | // copy the filename |
| 404 | strcpy(pInfo->file_name, pszFilename); |
| 405 | |
| 406 | // set up device and CRC, if specified |
| 407 | pInfo->device = device; |
| 408 | if ((device != NULL) && (device->has_partial_hash() != 0)) |
| 409 | nCrc = 0; |
| 410 | if (nCrc != 0) |
| 411 | snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc); |
| 412 | |
| 413 | // set up zip entry name length, if specified |
| 414 | if (nZipEntryNameLength > 0) |
| 415 | pInfo->zip_entry_name = pInfo->file_name + strlen(pInfo->file_name) - nZipEntryNameLength; |
| 416 | |
| 417 | // calculate the subname |
| 418 | pInfo->base_name = strrchr(pInfo->file_name, '\\'); |
| 419 | if (pInfo->base_name) |
| 420 | pInfo->base_name++; |
| 421 | else |
| 422 | pInfo->base_name = pInfo->file_name; |
| 423 | |
| 424 | ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index)); |
| 425 | memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index)); |
| 426 | if (pPickerInfo->file_index) free(pPickerInfo->file_index); |
| 427 | if (!ppNewIndex) |
| 428 | goto error; |
| 429 | |
| 430 | nIndex = pPickerInfo->file_index_length++; |
| 431 | pPickerInfo->file_index = ppNewIndex; |
| 432 | pPickerInfo->file_index[nIndex] = pInfo; |
| 433 | |
| 434 | // Realize the hash |
| 435 | SoftwarePicker_RealizeHash(hwndPicker, nIndex); |
| 436 | |
| 437 | // Actually insert the item into the picker |
| 438 | Picker_InsertItemSorted(hwndPicker, nIndex); |
| 439 | return TRUE; |
| 440 | |
| 441 | error: |
| 442 | if (pInfo) |
| 443 | free(pInfo); |
| 444 | return FALSE; |
| 445 | } |
| 446 | |
| 447 | |
| 448 | |
| 449 | static BOOL SoftwarePicker_AddZipEntFile(HWND hwndPicker, LPCSTR pszZipPath, |
| 450 | BOOL bForce, zip_file *pZip, const zip_file_header *pZipEnt) |
| 451 | { |
| 452 | LPSTR s; |
| 453 | LPCSTR temp = pZipEnt->filename; |
| 454 | int nLength; |
| 455 | int nZipEntryNameLength; |
| 456 | |
| 457 | // special case; skip first two characters if they are './' |
| 458 | if ((pZipEnt->filename[0] == '.') && (pZipEnt->filename[1] == '/')) |
| 459 | { |
| 460 | while(*(++temp) == '/') |
| 461 | ; |
| 462 | } |
| 463 | |
| 464 | nZipEntryNameLength = strlen(pZipEnt->filename); |
| 465 | nLength = strlen(pszZipPath) + 1 + nZipEntryNameLength + 1; |
| 466 | s = (LPSTR) alloca(nLength); |
| 467 | snprintf(s, nLength, "%s\\%s", pszZipPath, pZipEnt->filename); |
| 468 | |
| 469 | return SoftwarePicker_AddFileEntry(hwndPicker, s, |
| 470 | nZipEntryNameLength, pZipEnt->crc, bForce); |
| 471 | } |
| 472 | |
| 473 | static BOOL SoftwarePicker_InternalAddFile(HWND hwndPicker, LPCSTR pszFilename, |
| 474 | BOOL bForce) |
| 475 | { |
| 476 | LPCSTR s; |
| 477 | BOOL rc = TRUE; |
| 478 | zip_error ziperr; |
| 479 | zip_file *pZip; |
| 480 | const zip_file_header *pZipEnt; |
| 481 | |
| 482 | s = strrchr(pszFilename, '.'); |
| 483 | if (s && !mame_stricmp(s, ".zip")) |
| 484 | { |
| 485 | ziperr = zip_file_open(pszFilename, &pZip); |
| 486 | if (ziperr == ZIPERR_NONE) |
| 487 | { |
| 488 | pZipEnt = zip_file_first_file(pZip); |
| 489 | while(rc && pZipEnt) |
| 490 | { |
| 491 | rc = SoftwarePicker_AddZipEntFile(hwndPicker, pszFilename, |
| 492 | bForce, pZip, pZipEnt); |
| 493 | pZipEnt = zip_file_next_file(pZip); |
| 494 | } |
| 495 | zip_file_close(pZip); |
| 496 | } |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | rc = SoftwarePicker_AddFileEntry(hwndPicker, pszFilename, 0, 0, bForce); |
| 501 | } |
| 502 | return rc; |
| 503 | } |
| 504 | |
| 505 | |
| 506 | |
| 507 | BOOL SoftwarePicker_AddFile(HWND hwndPicker, LPCSTR pszFilename) |
| 508 | { |
| 509 | char szBuffer[MAX_PATH]; |
| 510 | |
| 511 | Picker_ResetIdle(hwndPicker); |
| 512 | pszFilename = NormalizePath(pszFilename, szBuffer, sizeof(szBuffer) |
| 513 | / sizeof(szBuffer[0])); |
| 514 | |
| 515 | return SoftwarePicker_InternalAddFile(hwndPicker, pszFilename, TRUE); |
| 516 | } |
| 517 | |
| 518 | |
| 519 | |
| 520 | BOOL SoftwarePicker_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory) |
| 521 | { |
| 522 | software_picker_info *pPickerInfo; |
| 523 | directory_search_info *pSearchInfo; |
| 524 | directory_search_info **ppLast; |
| 525 | size_t nSearchInfoSize; |
| 526 | char szBuffer[MAX_PATH]; |
| 527 | |
| 528 | pszDirectory = NormalizePath(pszDirectory, szBuffer, sizeof(szBuffer) |
| 529 | / sizeof(szBuffer[0])); |
| 530 | |
| 531 | Picker_ResetIdle(hwndPicker); |
| 532 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 533 | |
| 534 | nSearchInfoSize = sizeof(directory_search_info) + strlen(pszDirectory); |
| 535 | pSearchInfo = (directory_search_info *)malloc(nSearchInfoSize); |
| 536 | if (!pSearchInfo) |
| 537 | return FALSE; |
| 538 | memset(pSearchInfo, 0, nSearchInfoSize); |
| 539 | pSearchInfo->find_handle = INVALID_HANDLE_VALUE; |
| 540 | |
| 541 | strcpy(pSearchInfo->directory_name, pszDirectory); |
| 542 | |
| 543 | // insert into linked list |
| 544 | if (pPickerInfo->last_search_info) |
| 545 | ppLast = &pPickerInfo->last_search_info->next; |
| 546 | else |
| 547 | ppLast = &pPickerInfo->first_search_info; |
| 548 | *ppLast = pSearchInfo; |
| 549 | pPickerInfo->last_search_info = pSearchInfo; |
| 550 | return TRUE; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
| 555 | static void SoftwarePicker_FreeSearchInfo(directory_search_info *pSearchInfo) |
| 556 | { |
| 557 | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 558 | FindClose(pSearchInfo->find_handle); |
| 559 | free(pSearchInfo); |
| 560 | } |
| 561 | |
| 562 | |
| 563 | |
| 564 | static void SoftwarePicker_InternalClear(software_picker_info *pPickerInfo) |
| 565 | { |
| 566 | directory_search_info *p; |
| 567 | int i; |
| 568 | |
| 569 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 570 | free(pPickerInfo->file_index[i]); |
| 571 | |
| 572 | while(pPickerInfo->first_search_info) |
| 573 | { |
| 574 | p = pPickerInfo->first_search_info->next; |
| 575 | SoftwarePicker_FreeSearchInfo(pPickerInfo->first_search_info); |
| 576 | pPickerInfo->first_search_info = p; |
| 577 | } |
| 578 | |
| 579 | pPickerInfo->file_index = NULL; |
| 580 | pPickerInfo->file_index_length = 0; |
| 581 | pPickerInfo->current_position = 0; |
| 582 | pPickerInfo->last_search_info = NULL; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | |
| 587 | void SoftwarePicker_Clear(HWND hwndPicker) |
| 588 | { |
| 589 | software_picker_info *pPickerInfo; |
| 590 | BOOL res; |
| 591 | |
| 592 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 593 | SoftwarePicker_InternalClear(pPickerInfo); |
| 594 | res = ListView_DeleteAllItems(hwndPicker); |
| 595 | } |
| 596 | |
| 597 | |
| 598 | |
| 599 | static BOOL SoftwarePicker_AddEntry(HWND hwndPicker, |
| 600 | directory_search_info *pSearchInfo) |
| 601 | { |
| 602 | //software_picker_info *pPickerInfo; |
| 603 | LPSTR pszFilename; |
| 604 | BOOL rc; |
| 605 | char* utf8_FileName; |
| 606 | |
| 607 | //pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 608 | |
| 609 | utf8_FileName = utf8_from_tstring(pSearchInfo->fd.cFileName); |
| 610 | if( !utf8_FileName ) |
| 611 | return FALSE; |
| 612 | |
| 613 | if (!strcmp(utf8_FileName, ".") || !strcmp(utf8_FileName, "..")) { |
| 614 | osd_free(utf8_FileName); |
| 615 | return TRUE; |
| 616 | } |
| 617 | |
| 618 | pszFilename = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + 1 + strlen(utf8_FileName) + 1); |
| 619 | strcpy(pszFilename, pSearchInfo->directory_name); |
| 620 | strcat(pszFilename, "\\"); |
| 621 | strcat(pszFilename, utf8_FileName); |
| 622 | |
| 623 | if (pSearchInfo->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 624 | rc = SoftwarePicker_AddDirectory(hwndPicker, pszFilename); |
| 625 | else |
| 626 | rc = SoftwarePicker_InternalAddFile(hwndPicker, pszFilename, FALSE); |
| 627 | |
| 628 | osd_free(utf8_FileName); |
| 629 | return rc; |
| 630 | } |
| 631 | |
| 632 | |
| 633 | |
| 634 | BOOL SoftwarePicker_Idle(HWND hwndPicker) |
| 635 | { |
| 636 | software_picker_info *pPickerInfo; |
| 637 | file_info *pFileInfo; |
| 638 | static const char szWildcards[] = "\\*.*"; |
| 639 | directory_search_info *pSearchInfo; |
| 640 | LPSTR pszFilter; |
| 641 | BOOL bSuccess; |
| 642 | int nCount; |
| 643 | BOOL bDone = FALSE; |
| 644 | |
| 645 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 646 | |
| 647 | pSearchInfo = pPickerInfo->first_search_info; |
| 648 | |
| 649 | if (pSearchInfo) |
| 650 | { |
| 651 | // searching through directories |
| 652 | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 653 | { |
| 654 | bSuccess = FindNextFile(pSearchInfo->find_handle, &pSearchInfo->fd); |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | pszFilter = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + strlen(szWildcards) + 1); |
| 659 | strcpy(pszFilter, pSearchInfo->directory_name); |
| 660 | strcat(pszFilter, szWildcards); |
| 661 | pSearchInfo->find_handle = win_find_first_file_utf8(pszFilter, &pSearchInfo->fd); |
| 662 | bSuccess = pSearchInfo->find_handle != INVALID_HANDLE_VALUE; |
| 663 | } |
| 664 | |
| 665 | if (bSuccess) |
| 666 | { |
| 667 | SoftwarePicker_AddEntry(hwndPicker, pSearchInfo); |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | pPickerInfo->first_search_info = pSearchInfo->next; |
| 672 | if (!pPickerInfo->first_search_info) |
| 673 | pPickerInfo->last_search_info = NULL; |
| 674 | SoftwarePicker_FreeSearchInfo(pSearchInfo); |
| 675 | } |
| 676 | } |
| 677 | else if (pPickerInfo->config!=NULL && pPickerInfo->config->hashfile && (pPickerInfo->hashes_realized |
| 678 | < pPickerInfo->file_index_length)) |
| 679 | { |
| 680 | // time to realize some hashes |
| 681 | nCount = 100; |
| 682 | |
| 683 | while((nCount > 0) && pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 684 | { |
| 685 | pPickerInfo->current_position++; |
| 686 | pPickerInfo->current_position %= pPickerInfo->file_index_length; |
| 687 | nCount--; |
| 688 | } |
| 689 | |
| 690 | pFileInfo = pPickerInfo->file_index[pPickerInfo->current_position]; |
| 691 | if (!pFileInfo->hash_realized) |
| 692 | { |
| 693 | if (hashfile_functions_used(pPickerInfo->config->hashfile, pFileInfo->device->image_type())) |
| 694 | { |
| 695 | // only calculate the hash if it is appropriate for this device |
| 696 | if (!SoftwarePicker_CalculateHash(hwndPicker, pPickerInfo->current_position)) |
| 697 | return FALSE; |
| 698 | } |
| 699 | SoftwarePicker_RealizeHash(hwndPicker, pPickerInfo->current_position); |
| 700 | |
| 701 | // under normal circumstances this will be redundant, but in the unlikely |
| 702 | // event of a failure, we do not want to keep running into a brick wall |
| 703 | // by calculating this hash over and over |
| 704 | if (!pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 705 | { |
| 706 | pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized = TRUE; |
| 707 | pPickerInfo->hashes_realized++; |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | // we are done! |
| 714 | bDone = TRUE; |
| 715 | } |
| 716 | |
| 717 | return !bDone; |
| 718 | } |
| 719 | |
| 720 | |
| 721 | |
| 722 | LPCTSTR SoftwarePicker_GetItemString(HWND hwndPicker, int nRow, int nColumn, |
| 723 | TCHAR *pszBuffer, UINT nBufferLength) |
| 724 | { |
| 725 | software_picker_info *pPickerInfo; |
| 726 | const file_info *pFileInfo; |
| 727 | LPCTSTR s = NULL; |
| 728 | const char *pszUtf8 = NULL; |
| 729 | unsigned int nHashFunction = 0; |
| 730 | char szBuffer[256]; |
| 731 | TCHAR* t_buf; |
| 732 | |
| 733 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 734 | if ((nRow < 0) || (nRow >= pPickerInfo->file_index_length)) |
| 735 | return NULL; |
| 736 | |
| 737 | pFileInfo = pPickerInfo->file_index[nRow]; |
| 738 | |
| 739 | switch(nColumn) |
| 740 | { |
| 741 | case MESS_COLUMN_IMAGES: |
| 742 | t_buf = tstring_from_utf8(pFileInfo->base_name); |
| 743 | if( !t_buf ) |
| 744 | return s; |
| 745 | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 746 | s = pszBuffer; |
| 747 | osd_free(t_buf); |
| 748 | break; |
| 749 | |
| 750 | case MESS_COLUMN_GOODNAME: |
| 751 | case MESS_COLUMN_MANUFACTURER: |
| 752 | case MESS_COLUMN_YEAR: |
| 753 | case MESS_COLUMN_PLAYABLE: |
| 754 | if (pFileInfo->hashinfo) |
| 755 | { |
| 756 | switch(nColumn) |
| 757 | { |
| 758 | case MESS_COLUMN_GOODNAME: |
| 759 | pszUtf8 = pFileInfo->hashinfo->longname; |
| 760 | break; |
| 761 | case MESS_COLUMN_MANUFACTURER: |
| 762 | pszUtf8 = pFileInfo->hashinfo->manufacturer; |
| 763 | break; |
| 764 | case MESS_COLUMN_YEAR: |
| 765 | pszUtf8 = pFileInfo->hashinfo->year; |
| 766 | break; |
| 767 | case MESS_COLUMN_PLAYABLE: |
| 768 | pszUtf8 = pFileInfo->hashinfo->playable; |
| 769 | break; |
| 770 | } |
| 771 | if (pszUtf8) |
| 772 | { |
| 773 | t_buf = tstring_from_utf8(pszUtf8); |
| 774 | if( !t_buf ) |
| 775 | return s; |
| 776 | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 777 | s = pszBuffer; |
| 778 | osd_free(t_buf); |
| 779 | } |
| 780 | } |
| 781 | break; |
| 782 | |
| 783 | case MESS_COLUMN_CRC: |
| 784 | case MESS_COLUMN_MD5: |
| 785 | case MESS_COLUMN_SHA1: |
| 786 | switch (nColumn) |
| 787 | { |
| 788 | case MESS_COLUMN_CRC: nHashFunction = HASH_CRC; break; |
| 789 | case MESS_COLUMN_MD5: nHashFunction = HASH_MD5; break; |
| 790 | case MESS_COLUMN_SHA1: nHashFunction = HASH_SHA1; break; |
| 791 | } |
| 792 | if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer)) |
| 793 | { |
| 794 | t_buf = tstring_from_utf8(szBuffer); |
| 795 | if( !t_buf ) |
| 796 | return s; |
| 797 | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 798 | s = pszBuffer; |
| 799 | osd_free(t_buf); |
| 800 | } |
| 801 | break; |
| 802 | } |
| 803 | return s; |
| 804 | } |
| 805 | |
| 806 | |
| 807 | |
| 808 | static LRESULT CALLBACK SoftwarePicker_WndProc(HWND hwndPicker, UINT nMessage, |
| 809 | WPARAM wParam, LPARAM lParam) |
| 810 | { |
| 811 | software_picker_info *pPickerInfo; |
| 812 | LRESULT rc; |
| 813 | |
| 814 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 815 | rc = CallWindowProc(pPickerInfo->old_window_proc, hwndPicker, nMessage, wParam, lParam); |
| 816 | |
| 817 | if (nMessage == WM_DESTROY) |
| 818 | { |
| 819 | SoftwarePicker_InternalClear(pPickerInfo); |
| 820 | SoftwarePicker_SetDriver(hwndPicker, NULL); |
| 821 | free(pPickerInfo); |
| 822 | } |
| 823 | |
| 824 | return rc; |
| 825 | } |
| 826 | |
| 827 | |
| 828 | |
| 829 | BOOL SetupSoftwarePicker(HWND hwndPicker, const struct PickerOptions *pOptions) |
| 830 | { |
| 831 | software_picker_info *pPickerInfo = NULL; |
| 832 | LONG_PTR l; |
| 833 | |
| 834 | if (!SetupPicker(hwndPicker, pOptions)) |
| 835 | goto error; |
| 836 | |
| 837 | pPickerInfo = (software_picker_info *)malloc(sizeof(*pPickerInfo)); |
| 838 | if (!pPickerInfo) |
| 839 | goto error; |
| 840 | |
| 841 | memset(pPickerInfo, 0, sizeof(*pPickerInfo)); |
| 842 | if (!SetProp(hwndPicker, software_picker_property_name, (HANDLE) pPickerInfo)) |
| 843 | goto error; |
| 844 | |
| 845 | l = (LONG_PTR) SoftwarePicker_WndProc; |
| 846 | l = SetWindowLongPtr(hwndPicker, GWLP_WNDPROC, l); |
| 847 | pPickerInfo->old_window_proc = (WNDPROC) l; |
| 848 | return TRUE; |
| 849 | |
| 850 | error: |
| 851 | if (pPickerInfo) |
| 852 | free(pPickerInfo); |
| 853 | return FALSE; |
| 854 | } |
src/mess/osd/winui/dialog.c
| r10258 | r10259 | |
| 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
| r10258 | r10259 | |
| 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 | | } |
src/mess/osd/winui/messui.c
| r10258 | r10259 | |
| 1 | | //============================================================ |
| 2 | | // |
| 3 | | // messui.c - MESS extensions to src/osd/winui/winui.c |
| 4 | | // |
| 5 | | //============================================================ |
| 6 | | |
| 7 | | // standard windows headers |
| 8 | | #define WIN32_LEAN_AND_MEAN |
| 9 | | #include <assert.h> |
| 10 | | #include <string.h> |
| 11 | | #include <windows.h> |
| 12 | | #include <shellapi.h> |
| 13 | | #include <commctrl.h> |
| 14 | | #include <commdlg.h> |
| 15 | | #include <wingdi.h> |
| 16 | | #include <winuser.h> |
| 17 | | #include <tchar.h> |
| 18 | | |
| 19 | | // MAME/MAMEOS/MAMEUI/MESS headers |
| 20 | | #include "screenshot.h" |
| 21 | | #include "bitmask.h" |
| 22 | | #include "winui.h" |
| 23 | | #include "resourcems.h" |
| 24 | | #include "mui_opts.h" |
| 25 | | #include "picker.h" |
| 26 | | #include "tabview.h" |
| 27 | | #include "mui_util.h" |
| 28 | | #include "columnedit.h" |
| 29 | | #include "mess.h" |
| 30 | | #include "softwarepicker.h" |
| 31 | | #include "softwarelist.h" |
| 32 | | #include "devview.h" |
| 33 | | #include "windows/window.h" |
| 34 | | #include "strconv.h" |
| 35 | | #include "messui.h" |
| 36 | | #include "winutf8.h" |
| 37 | | #include "swconfig.h" |
| 38 | | #include "zippath.h" |
| 39 | | #include "emuopts.h" |
| 40 | | |
| 41 | | |
| 42 | | //============================================================ |
| 43 | | // PARAMETERS |
| 44 | | //============================================================ |
| 45 | | |
| 46 | | #define LOG_SOFTWARE 0 |
| 47 | | |
| 48 | | |
| 49 | | //============================================================ |
| 50 | | // TYPEDEFS |
| 51 | | //============================================================ |
| 52 | | |
| 53 | | typedef struct _mess_image_type mess_image_type; |
| 54 | | struct _mess_image_type |
| 55 | | { |
| 56 | | const device_config_image_interface *dev; |
| 57 | | char *ext; |
| 58 | | const char *dlgname; |
| 59 | | }; |
| 60 | | |
| 61 | | |
| 62 | | typedef struct _device_entry device_entry; |
| 63 | | struct _device_entry |
| 64 | | { |
| 65 | | iodevice_t dev_type; |
| 66 | | const char *icon_name; |
| 67 | | const char *dlgname; |
| 68 | | }; |
| 69 | | |
| 70 | | |
| 71 | | |
| 72 | | //============================================================ |
| 73 | | // GLOBAL VARIABLES |
| 74 | | //============================================================ |
| 75 | | |
| 76 | | char g_szSelectedItem[MAX_PATH]; |
| 77 | | |
| 78 | | char g_szSelectedSoftware[MAX_PATH]; |
| 79 | | |
| 80 | | char g_szSelectedDevice[MAX_PATH]; |
| 81 | | |
| 82 | | //============================================================ |
| 83 | | // LOCAL VARIABLES |
| 84 | | //============================================================ |
| 85 | | |
| 86 | | static software_config *s_config; |
| 87 | | static BOOL s_bIgnoreSoftwarePickerNotifies; |
| 88 | | |
| 89 | | static int *mess_icon_index; |
| 90 | | |
| 91 | | // TODO - We need to make icons for Cylinders, Punch Cards, and Punch Tape! |
| 92 | | static const device_entry s_devices[] = |
| 93 | | { |
| 94 | | { IO_CARTSLOT, "roms", "Cartridge images" }, |
| 95 | | { IO_FLOPPY, "floppy", "Floppy disk images" }, |
| 96 | | { IO_HARDDISK, "hard", "Hard disk images" }, |
| 97 | | { IO_CYLINDER, NULL, "Cylinders" }, |
| 98 | | { IO_CASSETTE, NULL, "Cassette images" }, |
| 99 | | { IO_PUNCHCARD, NULL, "Punchcard images" }, |
| 100 | | { IO_PUNCHTAPE, NULL, "Punchtape images" }, |
| 101 | | { IO_PRINTER, NULL, "Printer Output" }, |
| 102 | | { IO_SERIAL, NULL, "Serial Output" }, |
| 103 | | { IO_PARALLEL, NULL, "Parallel Output" }, |
| 104 | | { IO_SNAPSHOT, "snapshot", "Snapshots" }, |
| 105 | | { IO_QUICKLOAD, "snapshot", "Quickloads" }, |
| 106 | | { IO_MEMCARD, NULL, "Memory cards" }, |
| 107 | | { IO_CDROM, NULL, "CD-ROM images" }, |
| 108 | | { IO_MAGTAPE, NULL, "Magnetic tapes" } |
| 109 | | }; |
| 110 | | |
| 111 | | |
| 112 | | |
| 113 | | static const LPCTSTR mess_column_names[] = |
| 114 | | { |
| 115 | | TEXT("Software"), |
| 116 | | TEXT("Goodname"), |
| 117 | | TEXT("Manufacturer"), |
| 118 | | TEXT("Year"), |
| 119 | | TEXT("Playable"), |
| 120 | | TEXT("CRC"), |
| 121 | | TEXT("SHA-1"), |
| 122 | | TEXT("MD5") |
| 123 | | }; |
| 124 | | |
| 125 | | static const LPCTSTR softlist_column_names[] = |
| 126 | | { |
| 127 | | TEXT("Name"), |
| 128 | | TEXT("List"), |
| 129 | | TEXT("Description"), |
| 130 | | TEXT("Year"), |
| 131 | | TEXT("Publisher"), |
| 132 | | TEXT("CRC"), |
| 133 | | TEXT("SHA-1"), |
| 134 | | TEXT("MD5")}; |
| 135 | | |
| 136 | | |
| 137 | | |
| 138 | | //============================================================ |
| 139 | | // PROTOTYPES |
| 140 | | //============================================================ |
| 141 | | |
| 142 | | static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn); |
| 143 | | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn); |
| 144 | | |
| 145 | | static LPCSTR SoftwareTabView_GetTabShortName(int tab); |
| 146 | | static LPCSTR SoftwareTabView_GetTabLongName(int tab); |
| 147 | | static void SoftwareTabView_OnSelectionChanged(void); |
| 148 | | static void SoftwareTabView_OnMoveSize(void); |
| 149 | | static void SetupSoftwareTabView(void); |
| 150 | | |
| 151 | | static void MessOpenOtherSoftware(const device_config_image_interface *dev); |
| 152 | | static void MessRefreshPicker(void); |
| 153 | | |
| 154 | | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem); |
| 155 | | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem); |
| 156 | | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem); |
| 157 | | |
| 158 | | static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem); |
| 159 | | static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem); |
| 160 | | static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem); |
| 161 | | |
| 162 | | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 163 | | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 164 | | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config_image_interface *dev, LPCTSTR pszFilename); |
| 165 | | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszBuffer, UINT nBufferLength); |
| 166 | | |
| 167 | | #ifdef MAME_DEBUG |
| 168 | | static void MessTestsBegin(void); |
| 169 | | #endif /* MAME_DEBUG */ |
| 170 | | |
| 171 | | |
| 172 | | |
| 173 | | //============================================================ |
| 174 | | // PICKER/TABVIEW CALLBACKS |
| 175 | | //============================================================ |
| 176 | | |
| 177 | | static const struct PickerCallbacks s_softwarePickerCallbacks = |
| 178 | | { |
| 179 | | SetMessSortColumn, // pfnSetSortColumn |
| 180 | | GetMessSortColumn, // pfnGetSortColumn |
| 181 | | SetMessSortReverse, // pfnSetSortReverse |
| 182 | | GetMessSortReverse, // pfnGetSortReverse |
| 183 | | NULL, // pfnSetViewMode |
| 184 | | GetViewMode, // pfnGetViewMode |
| 185 | | SetMessColumnWidths, // pfnSetColumnWidths |
| 186 | | GetMessColumnWidths, // pfnGetColumnWidths |
| 187 | | SetMessColumnOrder, // pfnSetColumnOrder |
| 188 | | GetMessColumnOrder, // pfnGetColumnOrder |
| 189 | | SetMessColumnShown, // pfnSetColumnShown |
| 190 | | GetMessColumnShown, // pfnGetColumnShown |
| 191 | | NULL, // pfnGetOffsetChildren |
| 192 | | |
| 193 | | NULL, // pfnCompare |
| 194 | | MamePlayGame, // pfnDoubleClick |
| 195 | | SoftwarePicker_GetItemString, // pfnGetItemString |
| 196 | | SoftwarePicker_GetItemImage, // pfnGetItemImage |
| 197 | | SoftwarePicker_LeavingItem, // pfnLeavingItem |
| 198 | | SoftwarePicker_EnteringItem, // pfnEnteringItem |
| 199 | | NULL, // pfnBeginListViewDrag |
| 200 | | NULL, // pfnFindItemParent |
| 201 | | SoftwarePicker_Idle, // pfnIdle |
| 202 | | SoftwarePicker_OnHeaderContextMenu, // pfnOnHeaderContextMenu |
| 203 | | NULL // pfnOnBodyContextMenu |
| 204 | | }; |
| 205 | | |
| 206 | | static const struct PickerCallbacks s_softwareListCallbacks = |
| 207 | | { |
| 208 | | SetMessSortColumn, // pfnSetSortColumn |
| 209 | | GetMessSortColumn, // pfnGetSortColumn |
| 210 | | SetMessSortReverse, // pfnSetSortReverse |
| 211 | | GetMessSortReverse, // pfnGetSortReverse |
| 212 | | NULL, // pfnSetViewMode |
| 213 | | GetViewMode, // pfnGetViewMode |
| 214 | | SetMessColumnWidths, // pfnSetColumnWidths |
| 215 | | GetMessColumnWidths, // pfnGetColumnWidths |
| 216 | | SetMessColumnOrder, // pfnSetColumnOrder |
| 217 | | GetMessColumnOrder, // pfnGetColumnOrder |
| 218 | | SetMessColumnShown, // pfnSetColumnShown |
| 219 | | GetMessColumnShown, // pfnGetColumnShown |
| 220 | | NULL, // pfnGetOffsetChildren |
| 221 | | |
| 222 | | NULL, // pfnCompare |
| 223 | | MamePlayGame, // pfnDoubleClick |
| 224 | | SoftwareList_GetItemString, // pfnGetItemString |
| 225 | | SoftwareList_GetItemImage, // pfnGetItemImage |
| 226 | | SoftwareList_LeavingItem, // pfnLeavingItem |
| 227 | | SoftwareList_EnteringItem, // pfnEnteringItem |
| 228 | | NULL, // pfnBeginListViewDrag |
| 229 | | NULL, // pfnFindItemParent |
| 230 | | SoftwareList_Idle, // pfnIdle |
| 231 | | SoftwareList_OnHeaderContextMenu, // pfnOnHeaderContextMenu |
| 232 | | NULL // pfnOnBodyContextMenu |
| 233 | | }; |
| 234 | | |
| 235 | | |
| 236 | | static const struct TabViewCallbacks s_softwareTabViewCallbacks = |
| 237 | | { |
| 238 | | NULL, // pfnGetShowTabCtrl |
| 239 | | SetCurrentSoftwareTab, // pfnSetCurrentTab |
| 240 | | GetCurrentSoftwareTab, // pfnGetCurrentTab |
| 241 | | NULL, // pfnSetShowTab |
| 242 | | NULL, // pfnGetShowTab |
| 243 | | |
| 244 | | SoftwareTabView_GetTabShortName, // pfnGetTabShortName |
| 245 | | SoftwareTabView_GetTabLongName, // pfnGetTabLongName |
| 246 | | |
| 247 | | SoftwareTabView_OnSelectionChanged, // pfnOnSelectionChanged |
| 248 | | SoftwareTabView_OnMoveSize // pfnOnMoveSize |
| 249 | | }; |
| 250 | | |
| 251 | | |
| 252 | | |
| 253 | | //============================================================ |
| 254 | | // IMPLEMENTATION |
| 255 | | //============================================================ |
| 256 | | static char *strncpyz(char *dest, const char *source, size_t len) |
| 257 | | { |
| 258 | | char *s; |
| 259 | | if (len) { |
| 260 | | s = strncpy(dest, source, len - 1); |
| 261 | | dest[len-1] = '\0'; |
| 262 | | } |
| 263 | | else { |
| 264 | | s = dest; |
| 265 | | } |
| 266 | | return s; |
| 267 | | } |
| 268 | | |
| 269 | | static const device_entry *lookupdevice(iodevice_t d) |
| 270 | | { |
| 271 | | int i; |
| 272 | | for (i = 0; i < ARRAY_LENGTH(s_devices); i++) |
| 273 | | { |
| 274 | | if (s_devices[i].dev_type == d) |
| 275 | | return &s_devices[i]; |
| 276 | | } |
| 277 | | return NULL; |
| 278 | | } |
| 279 | | |
| 280 | | |
| 281 | | |
| 282 | | BOOL CreateMessIcons(void) |
| 283 | | { |
| 284 | | int i; |
| 285 | | HWND hwndSoftwareList; |
| 286 | | HIMAGELIST hSmall; |
| 287 | | HIMAGELIST hLarge; |
| 288 | | |
| 289 | | // create the icon index, if we havn't already |
| 290 | | if (!mess_icon_index) |
| 291 | | { |
| 292 | | mess_icon_index = (int*)pool_malloc_lib(GetMameUIMemoryPool(), driver_list_get_count(drivers) * IO_COUNT * sizeof(*mess_icon_index)); |
| 293 | | } |
| 294 | | |
| 295 | | for (i = 0; i < (driver_list_get_count(drivers) * IO_COUNT); i++) |
| 296 | | mess_icon_index[i] = 0; |
| 297 | | |
| 298 | | // Associate the image lists with the list view control. |
| 299 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 300 | | hSmall = GetSmallImageList(); |
| 301 | | hLarge = GetLargeImageList(); |
| 302 | | (void)ListView_SetImageList(hwndSoftwareList, hSmall, LVSIL_SMALL); |
| 303 | | (void)ListView_SetImageList(hwndSoftwareList, hLarge, LVSIL_NORMAL); |
| 304 | | return TRUE; |
| 305 | | } |
| 306 | | |
| 307 | | |
| 308 | | |
| 309 | | static int GetMessIcon(int drvindex, int nSoftwareType) |
| 310 | | { |
| 311 | | int the_index; |
| 312 | | int nIconPos = 0; |
| 313 | | HICON hIcon = 0; |
| 314 | | const game_driver *drv; |
| 315 | | char buffer[32]; |
| 316 | | const char *iconname; |
| 317 | | |
| 318 | | assert(drvindex >= 0); |
| 319 | | assert(drvindex < driver_list_get_count(drivers)); |
| 320 | | |
| 321 | | if ((nSoftwareType >= 0) && (nSoftwareType < IO_COUNT)) |
| 322 | | { |
| 323 | | iconname = device_config_image_interface::device_brieftypename((iodevice_t)nSoftwareType); |
| 324 | | the_index = (drvindex * IO_COUNT) + nSoftwareType; |
| 325 | | |
| 326 | | nIconPos = mess_icon_index[the_index]; |
| 327 | | if (nIconPos >= 0) |
| 328 | | { |
| 329 | | for (drv = drivers[drvindex]; drv; drv = driver_get_clone(drv)) |
| 330 | | { |
| 331 | | _snprintf(buffer, ARRAY_LENGTH(buffer), "%s/%s", drv->name, iconname); |
| 332 | | hIcon = LoadIconFromFile(buffer); |
| 333 | | if (hIcon) |
| 334 | | break; |
| 335 | | } |
| 336 | | |
| 337 | | if (hIcon) |
| 338 | | { |
| 339 | | nIconPos = ImageList_AddIcon(GetSmallImageList(), hIcon); |
| 340 | | ImageList_AddIcon(GetLargeImageList(), hIcon); |
| 341 | | if (nIconPos != -1) |
| 342 | | mess_icon_index[the_index] = nIconPos; |
| 343 | | } |
| 344 | | } |
| 345 | | } |
| 346 | | return nIconPos; |
| 347 | | } |
| 348 | | |
| 349 | | |
| 350 | | #ifdef UNUSED_FUNCTION |
| 351 | | static void MessHashErrorProc(const char *message) |
| 352 | | { |
| 353 | | SetStatusBarTextF(0, "Hash file: %s", message); |
| 354 | | } |
| 355 | | #endif |
| 356 | | |
| 357 | | |
| 358 | | static BOOL AddSoftwarePickerDirs(HWND hwndPicker, LPCSTR pszDirectories, LPCSTR pszSubDir) |
| 359 | | { |
| 360 | | LPCSTR s; |
| 361 | | LPSTR pszNewString; |
| 362 | | char cSeparator = ';'; |
| 363 | | int nLength; |
| 364 | | |
| 365 | | do |
| 366 | | { |
| 367 | | s = pszDirectories; |
| 368 | | while(*s && (*s != cSeparator)) |
| 369 | | s++; |
| 370 | | |
| 371 | | nLength = s - pszDirectories; |
| 372 | | if (nLength > 0) |
| 373 | | { |
| 374 | | pszNewString = (LPSTR) alloca((nLength + 1 + (pszSubDir ? strlen(pszSubDir) + 1 : 0))); |
| 375 | | memcpy(pszNewString, pszDirectories, nLength); |
| 376 | | pszNewString[nLength] = '\0'; |
| 377 | | |
| 378 | | if (pszSubDir) |
| 379 | | { |
| 380 | | pszNewString[nLength++] = '\\'; |
| 381 | | strcpy(&pszNewString[nLength], pszSubDir); |
| 382 | | } |
| 383 | | |
| 384 | | if (!SoftwarePicker_AddDirectory(hwndPicker, pszNewString)) |
| 385 | | return FALSE; |
| 386 | | } |
| 387 | | pszDirectories = s + 1; |
| 388 | | } |
| 389 | | while(*s); |
| 390 | | return TRUE; |
| 391 | | } |
| 392 | | |
| 393 | | void MySoftwareListClose(void) |
| 394 | | { |
| 395 | | // free the machine config, if necessary |
| 396 | | if (s_config != NULL) |
| 397 | | { |
| 398 | | software_config_free(s_config); |
| 399 | | s_config = NULL; |
| 400 | | } |
| 401 | | } |
| 402 | | |
| 403 | | void MyFillSoftwareList(int drvindex, BOOL bForce) |
| 404 | | { |
| 405 | | BOOL is_same; |
| 406 | | const game_driver *drv; |
| 407 | | HWND hwndSoftwarePicker; |
| 408 | | HWND hwndSoftwareList; |
| 409 | | HWND hwndSoftwareDevView; |
| 410 | | |
| 411 | | // do we have to do anything? |
| 412 | | if (!bForce) |
| 413 | | { |
| 414 | | if (s_config != NULL) |
| 415 | | is_same = (drvindex == s_config->driver_index); |
| 416 | | else |
| 417 | | is_same = (drvindex < 0); |
| 418 | | if (is_same) |
| 419 | | return; |
| 420 | | } |
| 421 | | |
| 422 | | // free the machine config, if necessary |
| 423 | | MySoftwareListClose(); |
| 424 | | |
| 425 | | // allocate the machine config, if necessary |
| 426 | | if (drvindex >= 0) |
| 427 | | { |
| 428 | | s_config = software_config_alloc(drvindex, MameUIGlobal(), NULL); |
| 429 | | } |
| 430 | | |
| 431 | | // locate key widgets |
| 432 | | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 433 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 434 | | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 435 | | |
| 436 | | // set up the device view |
| 437 | | DevView_SetDriver(hwndSoftwareDevView, s_config); |
| 438 | | |
| 439 | | // set up the software picker |
| 440 | | SoftwarePicker_Clear(hwndSoftwarePicker); |
| 441 | | SoftwarePicker_SetDriver(hwndSoftwarePicker, s_config); |
| 442 | | |
| 443 | | // add the relevant paths |
| 444 | | drv = drivers[drvindex]; |
| 445 | | while(drv != NULL) |
| 446 | | { |
| 447 | | AddSoftwarePickerDirs(hwndSoftwarePicker, GetSoftwareDirs(), drv->name); |
| 448 | | drv = driver_get_compatible(drv); |
| 449 | | } |
| 450 | | AddSoftwarePickerDirs(hwndSoftwarePicker, GetExtraSoftwarePaths(drvindex), NULL); |
| 451 | | |
| 452 | | // set up the software picker |
| 453 | | SoftwareList_Clear(hwndSoftwareList); |
| 454 | | SoftwareList_SetDriver(hwndSoftwareList, s_config); |
| 455 | | |
| 456 | | /* allocate the machine config */ |
| 457 | | machine_config config(*drivers[drvindex]); |
| 458 | | |
| 459 | | core_options *options = mame_options_init(NULL); |
| 460 | | for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 461 | | { |
| 462 | | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); |
| 463 | | |
| 464 | | for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) |
| 465 | | { |
| 466 | | if (swlist->list_name[i]) |
| 467 | | { |
| 468 | | software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL); |
| 469 | | |
| 470 | | if (list) |
| 471 | | { |
| 472 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 473 | | { |
| 474 | | const device_config_image_interface *image = NULL; |
| 475 | | software_part *part = software_find_part(swinfo, NULL, NULL); |
| 476 | | |
| 477 | | // search for a device with the right interface |
| 478 | | for (bool gotone = config.m_devicelist.first(image); gotone; gotone = image->next(image)) |
| 479 | | { |
| 480 | | const char *interface = image->image_interface(); |
| 481 | | if (interface != NULL) |
| 482 | | { |
| 483 | | if (!strcmp(interface, part->interface_)) |
| 484 | | { |
| 485 | | SoftwareList_AddFile(hwndSoftwareList, swinfo->shortname, swlist->list_name[i], swinfo->longname, swinfo->publisher, swinfo->year, image->brief_instance_name()); |
| 486 | | break; |
| 487 | | } |
| 488 | | } |
| 489 | | } |
| 490 | | } |
| 491 | | software_list_close(list); |
| 492 | | } |
| 493 | | } |
| 494 | | } |
| 495 | | } |
| 496 | | } |
| 497 | | |
| 498 | | |
| 499 | | |
| 500 | | void MessUpdateSoftwareList(void) |
| 501 | | { |
| 502 | | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 503 | | MyFillSoftwareList(Picker_GetSelectedItem(hwndList), TRUE); |
| 504 | | } |
| 505 | | |
| 506 | | |
| 507 | | |
| 508 | | BOOL MessApproveImageList(HWND hParent, int drvindex) |
| 509 | | { |
| 510 | | const device_config_image_interface *dev; |
| 511 | | char szMessage[256]; |
| 512 | | LPCSTR pszSoftware; |
| 513 | | BOOL bResult = FALSE; |
| 514 | | |
| 515 | | if (g_szSelectedSoftware[0] && g_szSelectedDevice[0]) { |
| 516 | | return TRUE; |
| 517 | | } |
| 518 | | // allocate the machine config |
| 519 | | machine_config config(*drivers[drvindex]); |
| 520 | | |
| 521 | | for (bool gotone = config.m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 522 | | { |
| 523 | | // confirm any mandatory devices are loaded |
| 524 | | if (dev->must_be_loaded()) |
| 525 | | { |
| 526 | | pszSoftware = GetSelectedSoftware(drvindex, &config, dev); |
| 527 | | if (!pszSoftware || !*pszSoftware) |
| 528 | | { |
| 529 | | snprintf(szMessage, ARRAY_LENGTH(szMessage), |
| 530 | | "System '%s' requires that device %s must have an image to load\n", |
| 531 | | drivers[drvindex]->description, |
| 532 | | dev->image_type_name()); |
| 533 | | goto done; |
| 534 | | } |
| 535 | | } |
| 536 | | } |
| 537 | | bResult = TRUE; |
| 538 | | |
| 539 | | done: |
| 540 | | if (!bResult) |
| 541 | | { |
| 542 | | win_message_box_utf8(hParent, szMessage, MAMEUINAME, MB_OK); |
| 543 | | } |
| 544 | | |
| 545 | | return bResult; |
| 546 | | } |
| 547 | | |
| 548 | | |
| 549 | | |
| 550 | | // this is a wrapper call to wrap the idiosycracies of SetSelectedSoftware() |
| 551 | | static void InternalSetSelectedSoftware(int drvindex, const machine_config *config, const device_config_image_interface *device, const char *pszSoftware) |
| 552 | | { |
| 553 | | if (!pszSoftware) |
| 554 | | pszSoftware = ""; |
| 555 | | |
| 556 | | // only call SetSelectedSoftware() if this value is different |
| 557 | | if (strcmp(GetSelectedSoftware(drvindex, config, device), pszSoftware)) |
| 558 | | { |
| 559 | | SetSelectedSoftware(drvindex, config, device, pszSoftware); |
| 560 | | } |
| 561 | | } |
| 562 | | |
| 563 | | |
| 564 | | |
| 565 | | static int is_null_or_empty(const char *s) |
| 566 | | { |
| 567 | | return (s == NULL) || (s[0] == '\0'); |
| 568 | | } |
| 569 | | |
| 570 | | |
| 571 | | |
| 572 | | // Places the specified image in the specified slot; nID = -1 means don't matter |
| 573 | | static void MessSpecifyImage(int drvindex, const device_config_image_interface *device, LPCSTR pszFilename) |
| 574 | | { |
| 575 | | const char *s; |
| 576 | | |
| 577 | | if (LOG_SOFTWARE) |
| 578 | | dprintf("MessSpecifyImage(): device=%p pszFilename='%s'\n", device, pszFilename); |
| 579 | | |
| 580 | | // if device is NULL, this is a special case; try to find existing image |
| 581 | | if (device == NULL) |
| 582 | | { |
| 583 | | const device_config_image_interface *dev; |
| 584 | | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 585 | | { |
| 586 | | s = GetSelectedSoftware(drvindex, s_config->mconfig, dev); |
| 587 | | if ((s != NULL) && !mame_stricmp(s, pszFilename)) { |
| 588 | | device = dev; |
| 589 | | break; |
| 590 | | } |
| 591 | | } |
| 592 | | } |
| 593 | | |
| 594 | | // still not found? find an empty slot for which the device uses the |
| 595 | | // same file extension |
| 596 | | if (device == NULL) |
| 597 | | { |
| 598 | | const char *file_extension; |
| 599 | | |
| 600 | | // identify the file extension |
| 601 | | file_extension = strrchr(pszFilename, '.'); |
| 602 | | file_extension = file_extension ? file_extension + 1 : NULL; |
| 603 | | |
| 604 | | if (file_extension != NULL) |
| 605 | | { |
| 606 | | const device_config_image_interface *dev; |
| 607 | | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 608 | | { |
| 609 | | s = GetSelectedSoftware(drvindex, s_config->mconfig, dev); |
| 610 | | if (is_null_or_empty(s) && dev->uses_file_extension(file_extension)) { |
| 611 | | device = dev; |
| 612 | | break; |
| 613 | | } |
| 614 | | } |
| 615 | | } |
| 616 | | } |
| 617 | | |
| 618 | | if (device != NULL) |
| 619 | | { |
| 620 | | // place the image |
| 621 | | InternalSetSelectedSoftware(drvindex, s_config->mconfig, device, pszFilename); |
| 622 | | } |
| 623 | | else |
| 624 | | { |
| 625 | | // could not place the image |
| 626 | | if (LOG_SOFTWARE) |
| 627 | | dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename); |
| 628 | | } |
| 629 | | } |
| 630 | | |
| 631 | | |
| 632 | | |
| 633 | | static void MessRemoveImage(int drvindex, const char *pszFilename) |
| 634 | | { |
| 635 | | const device_config_image_interface *device; |
| 636 | | const char *s; |
| 637 | | |
| 638 | | for (bool gotone = s_config->mconfig->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 639 | | { |
| 640 | | s = GetSelectedSoftware(drvindex, s_config->mconfig, device); |
| 641 | | if ((s != NULL) && !strcmp(pszFilename, s)) |
| 642 | | MessSpecifyImage(drvindex, device, NULL); |
| 643 | | } |
| 644 | | } |
| 645 | | |
| 646 | | |
| 647 | | |
| 648 | | void MessReadMountedSoftware(int drvindex) |
| 649 | | { |
| 650 | | // First read stuff into device view |
| 651 | | DevView_Refresh(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW)); |
| 652 | | |
| 653 | | // Now read stuff into picker |
| 654 | | MessRefreshPicker(); |
| 655 | | } |
| 656 | | |
| 657 | | |
| 658 | | |
| 659 | | static void MessRefreshPicker(void) |
| 660 | | { |
| 661 | | HWND hwndSoftware; |
| 662 | | int i; |
| 663 | | LVFINDINFO lvfi; |
| 664 | | const device_config_image_interface *dev; |
| 665 | | LPCSTR pszSoftware; |
| 666 | | |
| 667 | | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 668 | | |
| 669 | | s_bIgnoreSoftwarePickerNotifies = TRUE; |
| 670 | | |
| 671 | | // Now clear everything out; this may call back into us but it should not |
| 672 | | // be problematic |
| 673 | | ListView_SetItemState(hwndSoftware, -1, 0, LVIS_SELECTED); |
| 674 | | |
| 675 | | for (bool gotone = s_config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 676 | | { |
| 677 | | pszSoftware = GetSelectedSoftware(s_config->driver_index, s_config->mconfig, dev); |
| 678 | | if (pszSoftware && *pszSoftware) |
| 679 | | { |
| 680 | | i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware); |
| 681 | | if (i < 0) |
| 682 | | { |
| 683 | | SoftwarePicker_AddFile(hwndSoftware, pszSoftware); |
| 684 | | i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware); |
| 685 | | } |
| 686 | | if (i >= 0) |
| 687 | | { |
| 688 | | memset(&lvfi, 0, sizeof(lvfi)); |
| 689 | | lvfi.flags = LVFI_PARAM; |
| 690 | | lvfi.lParam = i; |
| 691 | | i = ListView_FindItem(hwndSoftware, -1, &lvfi); |
| 692 | | ListView_SetItemState(hwndSoftware, i, LVIS_SELECTED, LVIS_SELECTED); |
| 693 | | } |
| 694 | | } |
| 695 | | } |
| 696 | | |
| 697 | | s_bIgnoreSoftwarePickerNotifies = FALSE; |
| 698 | | } |
| 699 | | |
| 700 | | |
| 701 | | |
| 702 | | void InitMessPicker(void) |
| 703 | | { |
| 704 | | struct PickerOptions opts; |
| 705 | | HWND hwndSoftware; |
| 706 | | |
| 707 | | s_config = NULL; |
| 708 | | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 709 | | |
| 710 | | memset(&opts, 0, sizeof(opts)); |
| 711 | | opts.pCallbacks = &s_softwarePickerCallbacks; |
| 712 | | opts.nColumnCount = MESS_COLUMN_MAX; |
| 713 | | opts.ppszColumnNames = mess_column_names; |
| 714 | | SetupSoftwarePicker(hwndSoftware, &opts); |
| 715 | | |
| 716 | | SetWindowLong(hwndSoftware, GWL_STYLE, GetWindowLong(hwndSoftware, GWL_STYLE) |
| 717 | | | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED); |
| 718 | | |
| 719 | | SetupSoftwareTabView(); |
| 720 | | |
| 721 | | { |
| 722 | | static const struct DevViewCallbacks s_devViewCallbacks = |
| 723 | | { |
| 724 | | DevView_GetOpenFileName, |
| 725 | | DevView_GetCreateFileName, |
| 726 | | DevView_SetSelectedSoftware, |
| 727 | | DevView_GetSelectedSoftware |
| 728 | | }; |
| 729 | | DevView_SetCallbacks(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW), &s_devViewCallbacks); |
| 730 | | } |
| 731 | | |
| 732 | | HWND hwndSoftwareList; |
| 733 | | |
| 734 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 735 | | |
| 736 | | memset(&opts, 0, sizeof(opts)); |
| 737 | | opts.pCallbacks = &s_softwareListCallbacks; |
| 738 | | opts.nColumnCount = MESS_COLUMN_MAX; |
| 739 | | opts.ppszColumnNames = softlist_column_names; |
| 740 | | SetupSoftwareList(hwndSoftwareList, &opts); |
| 741 | | |
| 742 | | SetWindowLong(hwndSoftwareList, GWL_STYLE, GetWindowLong(hwndSoftwareList, GWL_STYLE) |
| 743 | | | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED); |
| 744 | | |
| 745 | | } |
| 746 | | |
| 747 | | |
| 748 | | |
| 749 | | // ------------------------------------------------------------------------ |
| 750 | | // Open others dialog |
| 751 | | // ------------------------------------------------------------------------ |
| 752 | | |
| 753 | | static BOOL CommonFileImageDialog(LPTSTR the_last_directory, common_file_dialog_proc cfd, LPTSTR filename, const machine_config *config, mess_image_type *imagetypes) |
| 754 | | { |
| 755 | | BOOL success; |
| 756 | | OPENFILENAME of; |
| 757 | | char szFilter[2048]; |
| 758 | | LPSTR s; |
| 759 | | const char *typname; |
| 760 | | int i; |
| 761 | | TCHAR* t_filter; |
| 762 | | TCHAR* t_buffer; |
| 763 | | |
| 764 | | s = szFilter; |
| 765 | | *filename = 0; |
| 766 | | |
| 767 | | // Common image types |
| 768 | | strcpy(s, "Common image types"); |
| 769 | | s += strlen(s); |
| 770 | | *(s++) = '|'; |
| 771 | | for (i = 0; imagetypes[i].ext; i++) |
| 772 | | { |
| 773 | | *(s++) = '*'; |
| 774 | | *(s++) = '.'; |
| 775 | | strcpy(s, imagetypes[i].ext); |
| 776 | | s += strlen(s); |
| 777 | | *(s++) = ';'; |
| 778 | | } |
| 779 | | *(s++) = '|'; |
| 780 | | |
| 781 | | // All files |
| 782 | | strcpy(s, "All files (*.*)"); |
| 783 | | s += strlen(s); |
| 784 | | *(s++) = '|'; |
| 785 | | strcpy(s, "*.*"); |
| 786 | | s += strlen(s); |
| 787 | | *(s++) = '|'; |
| 788 | | |
| 789 | | // The others |
| 790 | | for (i = 0; imagetypes[i].ext; i++) |
| 791 | | { |
| 792 | | if (!imagetypes[i].dev) |
| 793 | | typname = "Compressed images"; |
| 794 | | else |
| 795 | | typname = imagetypes[i].dlgname; |
| 796 | | |
| 797 | | strcpy(s, typname); |
| 798 | | s += strlen(s); |
| 799 | | strcpy(s, " (*."); |
| 800 | | s += strlen(s); |
| 801 | | strcpy(s, imagetypes[i].ext); |
| 802 | | s += strlen(s); |
| 803 | | *(s++) = ')'; |
| 804 | | *(s++) = '|'; |
| 805 | | *(s++) = '*'; |
| 806 | | *(s++) = '.'; |
| 807 | | strcpy(s, imagetypes[i].ext); |
| 808 | | s += strlen(s); |
| 809 | | *(s++) = '|'; |
| 810 | | } |
| 811 | | *(s++) = '|'; |
| 812 | | |
| 813 | | t_buffer = tstring_from_utf8(szFilter); |
| 814 | | if( !t_buffer ) |
| 815 | | return FALSE; |
| 816 | | |
| 817 | | // convert a pipe-char delimited string into a NUL delimited string |
| 818 | | t_filter = (LPTSTR) alloca((_tcslen(t_buffer) + 2) * sizeof(*t_filter)); |
| 819 | | for (i = 0; t_buffer[i] != '\0'; i++) |
| 820 | | t_filter[i] = (t_buffer[i] != '|') ? t_buffer[i] : '\0'; |
| 821 | | t_filter[i++] = '\0'; |
| 822 | | t_filter[i++] = '\0'; |
| 823 | | osd_free(t_buffer); |
| 824 | | |
| 825 | | of.lStructSize = sizeof(of); |
| 826 | | of.hwndOwner = GetMainWindow(); |
| 827 | | of.hInstance = NULL; |
| 828 | | of.lpstrFilter = t_filter; |
| 829 | | of.lpstrCustomFilter = NULL; |
| 830 | | of.nMaxCustFilter = 0; |
| 831 | | of.nFilterIndex = 1; |
| 832 | | of.lpstrFile = filename; |
| 833 | | of.nMaxFile = MAX_PATH; |
| 834 | | of.lpstrFileTitle = NULL; |
| 835 | | of.nMaxFileTitle = 0; |
| 836 | | of.lpstrInitialDir = the_last_directory; |
| 837 | | of.lpstrTitle = NULL; |
| 838 | | of.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; |
| 839 | | of.nFileOffset = 0; |
| 840 | | of.nFileExtension = 0; |
| 841 | | of.lpstrDefExt = TEXT("rom"); |
| 842 | | of.lCustData = 0; |
| 843 | | of.lpfnHook = NULL; |
| 844 | | of.lpTemplateName = NULL; |
| 845 | | |
| 846 | | success = cfd(&of); |
| 847 | | if (success) |
| 848 | | { |
| 849 | | //GetDirectory(filename,last_directory,sizeof(last_directory)); |
| 850 | | } |
| 851 | | |
| 852 | | return success; |
| 853 | | } |
| 854 | | |
| 855 | | |
| 856 | | |
| 857 | | /* Specify IO_COUNT for type if you want all types */ |
| 858 | | static void SetupImageTypes(const machine_config *config, mess_image_type *types, int count, BOOL bZip, const device_config_image_interface *dev) |
| 859 | | { |
| 860 | | int num_extensions = 0; |
| 861 | | |
| 862 | | memset(types, 0, sizeof(*types) * count); |
| 863 | | count--; |
| 864 | | |
| 865 | | if (bZip) |
| 866 | | { |
| 867 | | /* add the ZIP extension */ |
| 868 | | types[num_extensions].ext = mame_strdup("zip"); |
| 869 | | types[num_extensions].dev = NULL; |
| 870 | | types[num_extensions].dlgname = NULL; |
| 871 | | num_extensions++; |
| 872 | | } |
| 873 | | |
| 874 | | if (dev == NULL) |
| 875 | | { |
| 876 | | const device_config_image_interface *device; |
| 877 | | /* special case; all non-printer devices */ |
| 878 | | for (bool gotone = config->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 879 | | { |
| 880 | | if (device->image_type() != IO_PRINTER) |
| 881 | | SetupImageTypes(config, &types[num_extensions], count - num_extensions, FALSE, device); |
| 882 | | } |
| 883 | | |
| 884 | | } |
| 885 | | else |
| 886 | | { |
| 887 | | astring extensions((char*)dev->file_extensions()); |
| 888 | | char *ext = strtok((char*)extensions.cstr(),","); |
| 889 | | while (ext != NULL) |
| 890 | | { |
| 891 | | if (num_extensions < count) |
| 892 | | { |
| 893 | | types[num_extensions].dev = dev; |
| 894 | | types[num_extensions].ext = mame_strdup(ext); |
| 895 | | types[num_extensions].dlgname = lookupdevice(dev->image_type())->dlgname; |
| 896 | | num_extensions++; |
| 897 | | } |
| 898 | | ext = strtok (NULL, ","); |
| 899 | | } |
| 900 | | } |
| 901 | | } |
| 902 | | |
| 903 | | |
| 904 | | static void CleanupImageTypes(mess_image_type *types, int count) |
| 905 | | { |
| 906 | | int i; |
| 907 | | for (i = 0; i < count; ++i) |
| 908 | | { |
| 909 | | if (types[i].ext) |
| 910 | | osd_free(types[i].ext); |
| 911 | | } |
| 912 | | } |
| 913 | | |
| 914 | | |
| 915 | | static void MessSetupDevice(common_file_dialog_proc cfd, const device_config_image_interface *dev) |
| 916 | | { |
| 917 | | TCHAR filename[MAX_PATH]; |
| 918 | | mess_image_type imagetypes[64]; |
| 919 | | int drvindex; |
| 920 | | HWND hwndList; |
| 921 | | char* utf8_filename; |
| 922 | | BOOL cfd_res; |
| 923 | | |
| 924 | | // begin_resource_tracking(); |
| 925 | | |
| 926 | | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 927 | | drvindex = Picker_GetSelectedItem(hwndList); |
| 928 | | |
| 929 | | // allocate the machine config |
| 930 | | machine_config config(*drivers[drvindex]); |
| 931 | | |
| 932 | | SetupImageTypes(&config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 933 | | cfd_res = CommonFileImageDialog(last_directory, cfd, filename, &config, imagetypes); |
| 934 | | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 935 | | |
| 936 | | if (cfd_res) |
| 937 | | { |
| 938 | | utf8_filename = utf8_from_tstring(filename); |
| 939 | | if( !utf8_filename ) |
| 940 | | return; |
| 941 | | // TODO - this should go against InternalSetSelectedSoftware() |
| 942 | | SoftwarePicker_AddFile(GetDlgItem(GetMainWindow(), IDC_SWLIST), utf8_filename); |
| 943 | | osd_free(utf8_filename); |
| 944 | | } |
| 945 | | } |
| 946 | | |
| 947 | | |
| 948 | | |
| 949 | | static void MessOpenOtherSoftware(const device_config_image_interface *dev) |
| 950 | | { |
| 951 | | MessSetupDevice(GetOpenFileName, dev); |
| 952 | | } |
| 953 | | |
| 954 | | |
| 955 | | |
| 956 | | /* This is used to Mount an image in the device view of MESSUI. The directory in the dialog box is not |
| 957 | | set, and is thus random. |
| 958 | | 2009-10-18 Robbbert: |
| 959 | | I've attempted to set the directory properly. Since the emulation is not running at this time, |
| 960 | | we cannot do the same as the NEWUI does, that is, "initial_dir = image_working_directory(dev);" |
| 961 | | because a crash occurs (the image system isn't set up yet). |
| 962 | | |
| 963 | | Order of priority: |
| 964 | | 1. Directory where existing image is already loaded from |
| 965 | | 2. First directory specified in game-specific software tab |
| 966 | | 3. First directory specified in the system-wide software directories |
| 967 | | 4. mess-folder\software |
| 968 | | 5. mess-folder */ |
| 969 | | |
| 970 | | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 971 | | { |
| 972 | | BOOL bResult; |
| 973 | | TCHAR *t_s; |
| 974 | | int i; |
| 975 | | mess_image_type imagetypes[64]; |
| 976 | | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 977 | | int drvindex = Picker_GetSelectedItem(hwndList); |
| 978 | | astring as; |
| 979 | | |
| 980 | | /* Get the path to the currently mounted image */ |
| 981 | | zippath_parent(&as, GetSelectedSoftware(drvindex, config, dev)); |
| 982 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 983 | | |
| 984 | | /* See if an image was loaded, and that the path still exists */ |
| 985 | | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 986 | | { |
| 987 | | /* Get the path from the software tab */ |
| 988 | | astring_cpyc(&as, GetExtraSoftwarePaths(drvindex)); |
| 989 | | |
| 990 | | /* We only want the first path; throw out the rest */ |
| 991 | | i = astring_chr(&as, 0, ';'); |
| 992 | | if (i > 0) astring_substr(&as, 0, i); |
| 993 | | osd_free(t_s); |
| 994 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 995 | | |
| 996 | | /* Make sure a folder was specified in the tab, and that it exists */ |
| 997 | | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 998 | | { |
| 999 | | /* Get the path from the system-wide software setting in the drop-down directory setup */ |
| 1000 | | astring_cpyc(&as, GetSoftwareDirs()); |
| 1001 | | |
| 1002 | | /* We only want the first path; throw out the rest */ |
| 1003 | | i = astring_chr(&as, 0, ';'); |
| 1004 | | if (i > 0) astring_substr(&as, 0, i); |
| 1005 | | osd_free(t_s); |
| 1006 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 1007 | | |
| 1008 | | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1009 | | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1010 | | { |
| 1011 | | char *dst = NULL; |
| 1012 | | |
| 1013 | | osd_get_full_path(&dst,"."); |
| 1014 | | /* Default to emu directory */ |
| 1015 | | osd_free(t_s); |
| 1016 | | t_s = tstring_from_utf8(dst); |
| 1017 | | |
| 1018 | | /* If software folder exists, use it instead */ |
| 1019 | | zippath_combine(&as, dst, "software"); |
| 1020 | | if (osd_opendir(astring_c(&as))) |
| 1021 | | { |
| 1022 | | osd_free(t_s); |
| 1023 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 1024 | | } |
| 1025 | | osd_free(dst); |
| 1026 | | } |
| 1027 | | } |
| 1028 | | } |
| 1029 | | |
| 1030 | | SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 1031 | | bResult = CommonFileImageDialog(t_s, GetOpenFileName, pszFilename, config, imagetypes); |
| 1032 | | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 1033 | | |
| 1034 | | osd_free(t_s); |
| 1035 | | |
| 1036 | | return bResult; |
| 1037 | | } |
| 1038 | | |
| 1039 | | |
| 1040 | | /* This is used to Create an image in the device view of MESSUI. The directory in the dialog box is not |
| 1041 | | set, and is thus random. |
| 1042 | | |
| 1043 | | Order of priority: |
| 1044 | | 1. First directory specified in game-specific software tab |
| 1045 | | 2. First directory specified in the system-wide software directories |
| 1046 | | 3. mess-folder\software |
| 1047 | | 4. mess-folder */ |
| 1048 | | |
| 1049 | | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 1050 | | { |
| 1051 | | BOOL bResult; |
| 1052 | | TCHAR *t_s; |
| 1053 | | int i; |
| 1054 | | mess_image_type imagetypes[64]; |
| 1055 | | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1056 | | int drvindex = Picker_GetSelectedItem(hwndList); |
| 1057 | | astring as; |
| 1058 | | |
| 1059 | | /* Get the path from the software tab */ |
| 1060 | | astring_cpyc(&as, GetExtraSoftwarePaths(drvindex)); |
| 1061 | | |
| 1062 | | /* We only want the first path; throw out the rest */ |
| 1063 | | i = astring_chr(&as, 0, ';'); |
| 1064 | | if (i > 0) astring_substr(&as, 0, i); |
| 1065 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 1066 | | |
| 1067 | | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1068 | | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1069 | | { |
| 1070 | | /* Get the path from the system-wide software setting in the drop-down directory setup */ |
| 1071 | | astring_cpyc(&as, GetSoftwareDirs()); |
| 1072 | | |
| 1073 | | /* We only want the first path; throw out the rest */ |
| 1074 | | i = astring_chr(&as, 0, ';'); |
| 1075 | | if (i > 0) astring_substr(&as, 0, i); |
| 1076 | | osd_free(t_s); |
| 1077 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 1078 | | |
| 1079 | | /* Make sure a folder was specified in the tab, and that it exists */ |
| 1080 | | if ((!osd_opendir(astring_c(&as))) || (astring_chr(&as, 0, ':') == -1)) |
| 1081 | | { |
| 1082 | | char *dst = NULL; |
| 1083 | | |
| 1084 | | osd_get_full_path(&dst,"."); |
| 1085 | | /* Default to emu directory */ |
| 1086 | | osd_free(t_s); |
| 1087 | | t_s = tstring_from_utf8(dst); |
| 1088 | | |
| 1089 | | /* If software folder exists, use it instead */ |
| 1090 | | zippath_combine(&as, dst, "software"); |
| 1091 | | if (osd_opendir(astring_c(&as))) |
| 1092 | | { |
| 1093 | | osd_free(t_s); |
| 1094 | | t_s = tstring_from_utf8(astring_c(&as)); |
| 1095 | | } |
| 1096 | | osd_free(dst); |
| 1097 | | } |
| 1098 | | } |
| 1099 | | |
| 1100 | | SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); |
| 1101 | | bResult = CommonFileImageDialog(t_s, GetSaveFileName, pszFilename, config, imagetypes); |
| 1102 | | CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); |
| 1103 | | |
| 1104 | | osd_free(t_s); |
| 1105 | | |
| 1106 | | return bResult; |
| 1107 | | } |
| 1108 | | |
| 1109 | | |
| 1110 | | |
| 1111 | | static void DevView_SetSelectedSoftware(HWND hwndDevView, int drvindex, |
| 1112 | | const machine_config *config, const device_config_image_interface *dev, LPCTSTR pszFilename) |
| 1113 | | { |
| 1114 | | char* utf8_filename = utf8_from_tstring(pszFilename); |
| 1115 | | if( !utf8_filename ) |
| 1116 | | return; |
| 1117 | | MessSpecifyImage(drvindex, dev, utf8_filename); |
| 1118 | | MessRefreshPicker(); |
| 1119 | | osd_free(utf8_filename); |
| 1120 | | } |
| 1121 | | |
| 1122 | | |
| 1123 | | |
| 1124 | | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, |
| 1125 | | const machine_config *config, const device_config_image_interface *dev, LPTSTR pszBuffer, UINT nBufferLength) |
| 1126 | | { |
| 1127 | | LPCTSTR t_buffer = NULL; |
| 1128 | | TCHAR* t_s; |
| 1129 | | LPCSTR s = GetSelectedSoftware(nDriverIndex, config, dev); |
| 1130 | | |
| 1131 | | t_s = tstring_from_utf8(s); |
| 1132 | | if( !t_s ) |
| 1133 | | return t_buffer; |
| 1134 | | |
| 1135 | | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_s); |
| 1136 | | osd_free(t_s); |
| 1137 | | t_buffer = pszBuffer; |
| 1138 | | |
| 1139 | | return t_buffer; |
| 1140 | | } |
| 1141 | | |
| 1142 | | |
| 1143 | | |
| 1144 | | // ------------------------------------------------------------------------ |
| 1145 | | // Software Picker Class |
| 1146 | | // ------------------------------------------------------------------------ |
| 1147 | | |
| 1148 | | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem) |
| 1149 | | { |
| 1150 | | iodevice_t nType; |
| 1151 | | int nIcon; |
| 1152 | | int drvindex; |
| 1153 | | const char *icon_name; |
| 1154 | | HWND hwndGamePicker; |
| 1155 | | HWND hwndSoftwarePicker; |
| 1156 | | |
| 1157 | | hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1158 | | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1159 | | drvindex = Picker_GetSelectedItem(hwndGamePicker); |
| 1160 | | nType = SoftwarePicker_GetImageType(hwndSoftwarePicker, nItem); |
| 1161 | | nIcon = GetMessIcon(drvindex, nType); |
| 1162 | | if (!nIcon) |
| 1163 | | { |
| 1164 | | switch(nType) |
| 1165 | | { |
| 1166 | | case IO_UNKNOWN: |
| 1167 | | nIcon = FindIconIndex(IDI_WIN_REDX); |
| 1168 | | break; |
| 1169 | | |
| 1170 | | default: |
| 1171 | | icon_name = lookupdevice(nType)->icon_name; |
| 1172 | | if (!icon_name) |
| 1173 | | icon_name = device_config_image_interface::device_typename(nType); |
| 1174 | | nIcon = FindIconIndexByName(icon_name); |
| 1175 | | if (nIcon < 0) |
| 1176 | | nIcon = FindIconIndex(IDI_WIN_UNKNOWN); |
| 1177 | | break; |
| 1178 | | } |
| 1179 | | } |
| 1180 | | return nIcon; |
| 1181 | | } |
| 1182 | | |
| 1183 | | |
| 1184 | | |
| 1185 | | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem) |
| 1186 | | { |
| 1187 | | int drvindex; |
| 1188 | | const char *pszFullName; |
| 1189 | | HWND hwndList; |
| 1190 | | |
| 1191 | | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1192 | | { |
| 1193 | | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1194 | | drvindex = Picker_GetSelectedItem(hwndList); |
| 1195 | | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 1196 | | |
| 1197 | | MessRemoveImage(drvindex, pszFullName); |
| 1198 | | } |
| 1199 | | } |
| 1200 | | |
| 1201 | | |
| 1202 | | |
| 1203 | | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem) |
| 1204 | | { |
| 1205 | | LPCSTR pszFullName; |
| 1206 | | LPCSTR pszName; |
| 1207 | | const char* tmp; |
| 1208 | | LPSTR s; |
| 1209 | | int drvindex; |
| 1210 | | HWND hwndList; |
| 1211 | | |
| 1212 | | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1213 | | |
| 1214 | | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1215 | | { |
| 1216 | | drvindex = Picker_GetSelectedItem(hwndList); |
| 1217 | | |
| 1218 | | // Get the fullname and partialname for this file |
| 1219 | | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 1220 | | tmp = strchr(pszFullName, '\\'); |
| 1221 | | pszName = tmp ? tmp + 1 : pszFullName; |
| 1222 | | |
| 1223 | | // Do the dirty work |
| 1224 | | MessSpecifyImage(drvindex, NULL, pszFullName); |
| 1225 | | |
| 1226 | | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1227 | | strncpyz(g_szSelectedItem, pszName, ARRAY_LENGTH(g_szSelectedItem)); |
| 1228 | | s = strrchr(g_szSelectedItem, '.'); |
| 1229 | | if (s) |
| 1230 | | *s = '\0'; |
| 1231 | | |
| 1232 | | UpdateScreenShot(); |
| 1233 | | } |
| 1234 | | } |
| 1235 | | |
| 1236 | | |
| 1237 | | // ------------------------------------------------------------------------ |
| 1238 | | // Software List Class |
| 1239 | | // ------------------------------------------------------------------------ |
| 1240 | | |
| 1241 | | static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem) |
| 1242 | | { |
| 1243 | | iodevice_t nType; |
| 1244 | | int nIcon; |
| 1245 | | int drvindex; |
| 1246 | | const char *icon_name; |
| 1247 | | HWND hwndGamePicker; |
| 1248 | | HWND hwndSoftwareList; |
| 1249 | | |
| 1250 | | hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1251 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1252 | | drvindex = Picker_GetSelectedItem(hwndGamePicker); |
| 1253 | | nType = SoftwareList_GetImageType(hwndSoftwareList, nItem); |
| 1254 | | nIcon = GetMessIcon(drvindex, nType); |
| 1255 | | if (!nIcon) |
| 1256 | | { |
| 1257 | | switch(nType) |
| 1258 | | { |
| 1259 | | case IO_UNKNOWN: |
| 1260 | | nIcon = FindIconIndex(IDI_WIN_REDX); |
| 1261 | | break; |
| 1262 | | |
| 1263 | | default: |
| 1264 | | icon_name = lookupdevice(nType)->icon_name; |
| 1265 | | if (!icon_name) |
| 1266 | | icon_name = device_config_image_interface::device_typename(nType); |
| 1267 | | nIcon = FindIconIndexByName(icon_name); |
| 1268 | | if (nIcon < 0) |
| 1269 | | nIcon = FindIconIndex(IDI_WIN_UNKNOWN); |
| 1270 | | break; |
| 1271 | | } |
| 1272 | | } |
| 1273 | | return nIcon; |
| 1274 | | } |
| 1275 | | |
| 1276 | | |
| 1277 | | |
| 1278 | | static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem) |
| 1279 | | { |
| 1280 | | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1281 | | { |
| 1282 | | g_szSelectedSoftware[0] = 0; |
| 1283 | | g_szSelectedDevice[0] = 0; |
| 1284 | | } |
| 1285 | | } |
| 1286 | | |
| 1287 | | |
| 1288 | | |
| 1289 | | static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem) |
| 1290 | | { |
| 1291 | | LPCSTR pszFullName; |
| 1292 | | int drvindex; |
| 1293 | | HWND hwndList; |
| 1294 | | |
| 1295 | | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1296 | | |
| 1297 | | if (!s_bIgnoreSoftwarePickerNotifies) |
| 1298 | | { |
| 1299 | | drvindex = Picker_GetSelectedItem(hwndList); |
| 1300 | | |
| 1301 | | // Get the fullname and partialname for this file |
| 1302 | | pszFullName = SoftwareList_LookupFilename(hwndSoftwareList, nItem); |
| 1303 | | |
| 1304 | | strncpyz(g_szSelectedSoftware, pszFullName, ARRAY_LENGTH(g_szSelectedSoftware)); |
| 1305 | | |
| 1306 | | strncpyz(g_szSelectedDevice, SoftwareList_LookupDevice(hwndSoftwareList, nItem), ARRAY_LENGTH(g_szSelectedDevice)); |
| 1307 | | |
| 1308 | | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1309 | | strncpyz(g_szSelectedItem, pszFullName, ARRAY_LENGTH(g_szSelectedItem)); |
| 1310 | | |
| 1311 | | UpdateScreenShot(); |
| 1312 | | } |
| 1313 | | } |
| 1314 | | |
| 1315 | | |
| 1316 | | // ------------------------------------------------------------------------ |
| 1317 | | // Header context menu stuff |
| 1318 | | // ------------------------------------------------------------------------ |
| 1319 | | |
| 1320 | | static HWND MyColumnDialogProc_hwndPicker; |
| 1321 | | static int *MyColumnDialogProc_order; |
| 1322 | | static int *MyColumnDialogProc_shown; |
| 1323 | | |
| 1324 | | static void MyGetRealColumnOrder(int *order) |
| 1325 | | { |
| 1326 | | int i, nColumnCount; |
| 1327 | | nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1328 | | for (i = 0; i < nColumnCount; i++) |
| 1329 | | order[i] = Picker_GetRealColumnFromViewColumn(MyColumnDialogProc_hwndPicker, i); |
| 1330 | | } |
| 1331 | | |
| 1332 | | |
| 1333 | | |
| 1334 | | static void MyGetColumnInfo(int *order, int *shown) |
| 1335 | | { |
| 1336 | | const struct PickerCallbacks *pCallbacks; |
| 1337 | | pCallbacks = Picker_GetCallbacks(MyColumnDialogProc_hwndPicker); |
| 1338 | | pCallbacks->pfnGetColumnOrder(order); |
| 1339 | | pCallbacks->pfnGetColumnShown(shown); |
| 1340 | | } |
| 1341 | | |
| 1342 | | |
| 1343 | | |
| 1344 | | static void MySetColumnInfo(int *order, int *shown) |
| 1345 | | { |
| 1346 | | const struct PickerCallbacks *pCallbacks; |
| 1347 | | pCallbacks = Picker_GetCallbacks(MyColumnDialogProc_hwndPicker); |
| 1348 | | pCallbacks->pfnSetColumnOrder(order); |
| 1349 | | pCallbacks->pfnSetColumnShown(shown); |
| 1350 | | } |
| 1351 | | |
| 1352 | | |
| 1353 | | static INT_PTR CALLBACK MyColumnDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) |
| 1354 | | { |
| 1355 | | INT_PTR result = 0; |
| 1356 | | int nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1357 | | const LPCTSTR *ppszColumnNames = Picker_GetColumnNames(MyColumnDialogProc_hwndPicker); |
| 1358 | | |
| 1359 | | result = InternalColumnDialogProc(hDlg, Msg, wParam, lParam, nColumnCount, |
| 1360 | | MyColumnDialogProc_shown, MyColumnDialogProc_order, ppszColumnNames, |
| 1361 | | MyGetRealColumnOrder, MyGetColumnInfo, MySetColumnInfo); |
| 1362 | | |
| 1363 | | return result; |
| 1364 | | } |
| 1365 | | |
| 1366 | | |
| 1367 | | |
| 1368 | | static BOOL RunColumnDialog(HWND hwndPicker) |
| 1369 | | { |
| 1370 | | BOOL bResult; |
| 1371 | | int nColumnCount; |
| 1372 | | |
| 1373 | | MyColumnDialogProc_hwndPicker = hwndPicker; |
| 1374 | | nColumnCount = Picker_GetColumnCount(MyColumnDialogProc_hwndPicker); |
| 1375 | | |
| 1376 | | MyColumnDialogProc_order = (int*)alloca(nColumnCount * sizeof(int)); |
| 1377 | | MyColumnDialogProc_shown = (int*)alloca(nColumnCount * sizeof(int)); |
| 1378 | | bResult = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_COLUMNS), GetMainWindow(), MyColumnDialogProc); |
| 1379 | | return bResult; |
| 1380 | | } |
| 1381 | | |
| 1382 | | |
| 1383 | | |
| 1384 | | static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn) |
| 1385 | | { |
| 1386 | | HMENU hMenu; |
| 1387 | | HMENU hMenuLoad; |
| 1388 | | HWND hwndPicker; |
| 1389 | | int nMenuItem; |
| 1390 | | |
| 1391 | | hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER)); |
| 1392 | | hMenu = GetSubMenu(hMenuLoad, 0); |
| 1393 | | |
| 1394 | | nMenuItem = (int) TrackPopupMenu(hMenu, |
| 1395 | | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, |
| 1396 | | pt.x, |
| 1397 | | pt.y, |
| 1398 | | 0, |
| 1399 | | GetMainWindow(), |
| 1400 | | NULL); |
| 1401 | | |
| 1402 | | DestroyMenu(hMenuLoad); |
| 1403 | | |
| 1404 | | hwndPicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1405 | | |
| 1406 | | switch(nMenuItem) { |
| 1407 | | case ID_SORT_ASCENDING: |
| 1408 | | SetMessSortReverse(FALSE); |
| 1409 | | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1410 | | Picker_Sort(hwndPicker); |
| 1411 | | break; |
| 1412 | | |
| 1413 | | case ID_SORT_DESCENDING: |
| 1414 | | SetMessSortReverse(TRUE); |
| 1415 | | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1416 | | Picker_Sort(hwndPicker); |
| 1417 | | break; |
| 1418 | | |
| 1419 | | case ID_CUSTOMIZE_FIELDS: |
| 1420 | | if (RunColumnDialog(hwndPicker)) |
| 1421 | | Picker_ResetColumnDisplay(hwndPicker); |
| 1422 | | break; |
| 1423 | | } |
| 1424 | | } |
| 1425 | | |
| 1426 | | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn) |
| 1427 | | { |
| 1428 | | HMENU hMenu; |
| 1429 | | HMENU hMenuLoad; |
| 1430 | | HWND hwndPicker; |
| 1431 | | int nMenuItem; |
| 1432 | | |
| 1433 | | hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER)); |
| 1434 | | hMenu = GetSubMenu(hMenuLoad, 0); |
| 1435 | | |
| 1436 | | nMenuItem = (int) TrackPopupMenu(hMenu, |
| 1437 | | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, |
| 1438 | | pt.x, |
| 1439 | | pt.y, |
| 1440 | | 0, |
| 1441 | | GetMainWindow(), |
| 1442 | | NULL); |
| 1443 | | |
| 1444 | | DestroyMenu(hMenuLoad); |
| 1445 | | |
| 1446 | | hwndPicker = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1447 | | |
| 1448 | | switch(nMenuItem) { |
| 1449 | | case ID_SORT_ASCENDING: |
| 1450 | | SetMessSortReverse(FALSE); |
| 1451 | | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1452 | | Picker_Sort(hwndPicker); |
| 1453 | | break; |
| 1454 | | |
| 1455 | | case ID_SORT_DESCENDING: |
| 1456 | | SetMessSortReverse(TRUE); |
| 1457 | | SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn)); |
| 1458 | | Picker_Sort(hwndPicker); |
| 1459 | | break; |
| 1460 | | |
| 1461 | | case ID_CUSTOMIZE_FIELDS: |
| 1462 | | if (RunColumnDialog(hwndPicker)) |
| 1463 | | Picker_ResetColumnDisplay(hwndPicker); |
| 1464 | | break; |
| 1465 | | } |
| 1466 | | } |
| 1467 | | |
| 1468 | | |
| 1469 | | // ------------------------------------------------------------------------ |
| 1470 | | // MessCommand |
| 1471 | | // ------------------------------------------------------------------------ |
| 1472 | | |
| 1473 | | BOOL MessCommand(HWND hwnd,int id, HWND hwndCtl, UINT codeNotify) |
| 1474 | | { |
| 1475 | | switch (id) |
| 1476 | | { |
| 1477 | | case ID_MESS_OPEN_SOFTWARE: |
| 1478 | | MessOpenOtherSoftware(NULL); |
| 1479 | | break; |
| 1480 | | |
| 1481 | | #ifdef MAME_DEBUG |
| 1482 | | case ID_MESS_RUN_TESTS: |
| 1483 | | MessTestsBegin(); |
| 1484 | | break; |
| 1485 | | #endif /* MAME_DEBUG */ |
| 1486 | | } |
| 1487 | | return FALSE; |
| 1488 | | } |
| 1489 | | |
| 1490 | | |
| 1491 | | |
| 1492 | | // ------------------------------------------------------------------------ |
| 1493 | | // Software Tab View |
| 1494 | | // ------------------------------------------------------------------------ |
| 1495 | | |
| 1496 | | static LPCSTR s_tabs[] = |
| 1497 | | { |
| 1498 | | "picker\0Picker", |
| 1499 | | "devview\0Device View", |
| 1500 | | "softlist\0Software", |
| 1501 | | }; |
| 1502 | | |
| 1503 | | |
| 1504 | | |
| 1505 | | static LPCSTR SoftwareTabView_GetTabShortName(int tab) |
| 1506 | | { |
| 1507 | | return s_tabs[tab]; |
| 1508 | | } |
| 1509 | | |
| 1510 | | |
| 1511 | | |
| 1512 | | static LPCSTR SoftwareTabView_GetTabLongName(int tab) |
| 1513 | | { |
| 1514 | | return s_tabs[tab] + strlen(s_tabs[tab]) + 1; |
| 1515 | | } |
| 1516 | | |
| 1517 | | |
| 1518 | | |
| 1519 | | static void SoftwareTabView_OnSelectionChanged(void) |
| 1520 | | { |
| 1521 | | int nTab; |
| 1522 | | HWND hwndSoftwarePicker; |
| 1523 | | HWND hwndSoftwareDevView; |
| 1524 | | HWND hwndSoftwareList; |
| 1525 | | |
| 1526 | | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1527 | | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1528 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1529 | | |
| 1530 | | nTab = TabView_GetCurrentTab(GetDlgItem(GetMainWindow(), IDC_SWTAB)); |
| 1531 | | |
| 1532 | | switch(nTab) |
| 1533 | | { |
| 1534 | | case 0: |
| 1535 | | ShowWindow(hwndSoftwarePicker, SW_SHOW); |
| 1536 | | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1537 | | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1538 | | break; |
| 1539 | | |
| 1540 | | case 1: |
| 1541 | | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1542 | | ShowWindow(hwndSoftwareDevView, SW_SHOW); |
| 1543 | | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1544 | | break; |
| 1545 | | case 2: |
| 1546 | | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1547 | | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1548 | | ShowWindow(hwndSoftwareList, SW_SHOW); |
| 1549 | | break; |
| 1550 | | } |
| 1551 | | } |
| 1552 | | |
| 1553 | | |
| 1554 | | |
| 1555 | | static void SoftwareTabView_OnMoveSize(void) |
| 1556 | | { |
| 1557 | | HWND hwndSoftwareTabView; |
| 1558 | | HWND hwndSoftwarePicker; |
| 1559 | | HWND hwndSoftwareDevView; |
| 1560 | | HWND hwndSoftwareList; |
| 1561 | | RECT rMain, rSoftwareTabView, rClient, rTab; |
| 1562 | | BOOL res; |
| 1563 | | |
| 1564 | | hwndSoftwareTabView = GetDlgItem(GetMainWindow(), IDC_SWTAB); |
| 1565 | | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1566 | | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1567 | | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1568 | | |
| 1569 | | GetWindowRect(hwndSoftwareTabView, &rSoftwareTabView); |
| 1570 | | GetClientRect(GetMainWindow(), &rMain); |
| 1571 | | ClientToScreen(GetMainWindow(), &((POINT *) &rMain)[0]); |
| 1572 | | ClientToScreen(GetMainWindow(), &((POINT *) &rMain)[1]); |
| 1573 | | |
| 1574 | | // Calculate rClient from rSoftwareTabView in terms of rMain coordinates |
| 1575 | | rClient.left = rSoftwareTabView.left - rMain.left; |
| 1576 | | rClient.top = rSoftwareTabView.top - rMain.top; |
| 1577 | | rClient.right = rSoftwareTabView.right - rMain.left; |
| 1578 | | rClient.bottom = rSoftwareTabView.bottom - rMain.top; |
| 1579 | | |
| 1580 | | // If the tabs are visible, then make sure that the tab view's tabs are |
| 1581 | | // not being covered up |
| 1582 | | if (GetWindowLong(hwndSoftwareTabView, GWL_STYLE) & WS_VISIBLE) |
| 1583 | | { |
| 1584 | | res = TabCtrl_GetItemRect(hwndSoftwareTabView, 0, &rTab); |
| 1585 | | rClient.top += rTab.bottom - rTab.top + 2; |
| 1586 | | } |
| 1587 | | |
| 1588 | | /* Now actually move the controls */ |
| 1589 | | MoveWindow(hwndSoftwarePicker, rClient.left, rClient.top, |
| 1590 | | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1591 | | TRUE); |
| 1592 | | MoveWindow(hwndSoftwareDevView, rClient.left + 3, rClient.top + 2, |
| 1593 | | rClient.right - rClient.left - 6, rClient.bottom - rClient.top -4, |
| 1594 | | TRUE); |
| 1595 | | MoveWindow(hwndSoftwareList, rClient.left, rClient.top, |
| 1596 | | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1597 | | TRUE); |
| 1598 | | } |
| 1599 | | |
| 1600 | | |
| 1601 | | |
| 1602 | | static void SetupSoftwareTabView(void) |
| 1603 | | { |
| 1604 | | struct TabViewOptions opts; |
| 1605 | | |
| 1606 | | memset(&opts, 0, sizeof(opts)); |
| 1607 | | opts.pCallbacks = &s_softwareTabViewCallbacks; |
| 1608 | | opts.nTabCount = ARRAY_LENGTH(s_tabs); |
| 1609 | | |
| 1610 | | SetupTabView(GetDlgItem(GetMainWindow(), IDC_SWTAB), &opts); |
| 1611 | | } |
| 1612 | | |
| 1613 | | |
| 1614 | | // ------------------------------------------------------------------------ |
| 1615 | | // MessUI Diagnostics |
| 1616 | | // ------------------------------------------------------------------------ |
| 1617 | | |
| 1618 | | #ifdef MAME_DEBUG |
| 1619 | | |
| 1620 | | static int s_nOriginalPick; |
| 1621 | | static UINT_PTR s_nTestingTimer; |
| 1622 | | static BOOL s_bInTimerProc; |
| 1623 | | |
| 1624 | | static void MessTestsColumns(void) |
| 1625 | | { |
| 1626 | | int i, j; |
| 1627 | | int oldshown[MESS_COLUMN_MAX]; |
| 1628 | | int shown[MESS_COLUMN_MAX]; |
| 1629 | | |
| 1630 | | GetMessColumnShown(oldshown); |
| 1631 | | |
| 1632 | | shown[0] = 1; |
| 1633 | | for (i = 0; i < (1<<(MESS_COLUMN_MAX-1)); i++) |
| 1634 | | { |
| 1635 | | for (j = 1; j < MESS_COLUMN_MAX; j++) |
| 1636 | | shown[j] = (i & (1<<(j-1))) ? 1 : 0; |
| 1637 | | |
| 1638 | | SetMessColumnShown(shown); |
| 1639 | | Picker_ResetColumnDisplay(GetDlgItem(GetMainWindow(), IDC_SWLIST)); |
| 1640 | | } |
| 1641 | | |
| 1642 | | SetMessColumnShown(oldshown); |
| 1643 | | Picker_ResetColumnDisplay(GetDlgItem(GetMainWindow(), IDC_SWLIST)); |
| 1644 | | } |
| 1645 | | |
| 1646 | | |
| 1647 | | |
| 1648 | | |
| 1649 | | static void CALLBACK MessTestsTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
| 1650 | | { |
| 1651 | | int nNewGame; |
| 1652 | | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1653 | | |
| 1654 | | // if either of the pickers have further idle work to do, or we are |
| 1655 | | // already in this timerproc, do not do anything |
| 1656 | | if (s_bInTimerProc || Picker_IsIdling(hwndList) |
| 1657 | | || Picker_IsIdling(GetDlgItem(GetMainWindow(), IDC_SWLIST))) |
| 1658 | | return; |
| 1659 | | s_bInTimerProc = TRUE; |
| 1660 | | |
| 1661 | | nNewGame = GetSelectedPick() + 1; |
| 1662 | | |
| 1663 | | if (nNewGame >= driver_list_get_count(drivers)) |
| 1664 | | { |
| 1665 | | /* We are done */ |
| 1666 | | Picker_SetSelectedPick(hwndList, s_nOriginalPick); |
| 1667 | | |
| 1668 | | KillTimer(NULL, s_nTestingTimer); |
| 1669 | | s_nTestingTimer = 0; |
| 1670 | | |
| 1671 | | win_message_box_utf8(GetMainWindow(), "Tests successfully completed!", MAMEUINAME, MB_OK); |
| 1672 | | } |
| 1673 | | else |
| 1674 | | { |
| 1675 | | // MessTestsFlex(GetDlgItem(GetMainWindow(), IDC_SWLIST), drivers[Picker_GetSelectedItem(hwndList)]); |
| 1676 | | Picker_SetSelectedPick(hwndList, nNewGame); |
| 1677 | | } |
| 1678 | | s_bInTimerProc = FALSE; |
| 1679 | | } |
| 1680 | | |
| 1681 | | |
| 1682 | | |
| 1683 | | static void MessTestsBegin(void) |
| 1684 | | { |
| 1685 | | int nOriginalPick; |
| 1686 | | HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 1687 | | |
| 1688 | | nOriginalPick = GetSelectedPick(); |
| 1689 | | |
| 1690 | | // If we are not currently running tests, set up the timer and keep track |
| 1691 | | // of the original selected pick item |
| 1692 | | if (!s_nTestingTimer) |
| 1693 | | { |
| 1694 | | s_nTestingTimer = SetTimer(NULL, 0, 50, MessTestsTimerProc); |
| 1695 | | if (!s_nTestingTimer) |
| 1696 | | return; |
| 1697 | | s_nOriginalPick = nOriginalPick; |
| 1698 | | } |
| 1699 | | |
| 1700 | | MessTestsColumns(); |
| 1701 | | |
| 1702 | | if (nOriginalPick == 0) |
| 1703 | | Picker_SetSelectedPick(hwndList, 1); |
| 1704 | | Picker_SetSelectedPick(hwndList, 0); |
| 1705 | | } |
| 1706 | | |
| 1707 | | |
| 1708 | | |
| 1709 | | #endif // MAME_DEBUG |
src/mess/osd/winui/devview.c
| r10258 | r10259 | |
| 1 | | // ------------------------------------------------------------------------ |
| 2 | | // Software Device View class |
| 3 | | // ------------------------------------------------------------------------ |
| 4 | | |
| 5 | | #define WIN32_LEAN_AND_MEAN |
| 6 | | #include <assert.h> |
| 7 | | #include <string.h> |
| 8 | | #include <windows.h> |
| 9 | | #include <shellapi.h> |
| 10 | | #include <commctrl.h> |
| 11 | | #include <commdlg.h> |
| 12 | | #include <wingdi.h> |
| 13 | | #include <winuser.h> |
| 14 | | #include <tchar.h> |
| 15 | | |
| 16 | | #include "emu.h" |
| 17 | | #include "devview.h" |
| 18 | | #include "optionsms.h" |
| 19 | | #include "strconv.h" |
| 20 | | #include "winutf8.h" |
| 21 | | #include "mui_util.h" |
| 22 | | |
| 23 | | #define DEVVIEW_PADDING 10 |
| 24 | | |
| 25 | | |
| 26 | | struct DevViewInfo |
| 27 | | { |
| 28 | | HFONT hFont; |
| 29 | | int nWidth; |
| 30 | | BOOL bSurpressFilenameChanged; |
| 31 | | const software_config *config; |
| 32 | | const struct DevViewCallbacks *pCallbacks; |
| 33 | | struct DevViewEntry *pEntries; |
| 34 | | }; |
| 35 | | |
| 36 | | |
| 37 | | |
| 38 | | struct DevViewEntry |
| 39 | | { |
| 40 | | const device_config_image_interface *dev; |
| 41 | | HWND hwndStatic; |
| 42 | | HWND hwndEdit; |
| 43 | | HWND hwndBrowseButton; |
| 44 | | WNDPROC pfnEditWndProc; |
| 45 | | }; |
| 46 | | |
| 47 | | |
| 48 | | |
| 49 | | static struct DevViewInfo *GetDevViewInfo(HWND hwndDevView) |
| 50 | | { |
| 51 | | LONG_PTR l; |
| 52 | | l = GetWindowLongPtr(hwndDevView, GWLP_USERDATA); |
| 53 | | return (struct DevViewInfo *) l; |
| 54 | | } |
| 55 | | |
| 56 | | |
| 57 | | |
| 58 | | static void DevView_Clear(HWND hwndDevView) |
| 59 | | { |
| 60 | | struct DevViewInfo *pDevViewInfo; |
| 61 | | int i; |
| 62 | | |
| 63 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 64 | | |
| 65 | | if (pDevViewInfo->pEntries != NULL) |
| 66 | | { |
| 67 | | for (i = 0; pDevViewInfo->pEntries[i].dev; i++) |
| 68 | | { |
| 69 | | DestroyWindow(pDevViewInfo->pEntries[i].hwndStatic); |
| 70 | | DestroyWindow(pDevViewInfo->pEntries[i].hwndEdit); |
| 71 | | DestroyWindow(pDevViewInfo->pEntries[i].hwndBrowseButton); |
| 72 | | } |
| 73 | | free(pDevViewInfo->pEntries); |
| 74 | | pDevViewInfo->pEntries = NULL; |
| 75 | | } |
| 76 | | |
| 77 | | pDevViewInfo->config = NULL; |
| 78 | | } |
| 79 | | |
| 80 | | |
| 81 | | |
| 82 | | static void DevView_GetColumns(HWND hwndDevView, int *pnStaticPos, int *pnStaticWidth, |
| 83 | | int *pnEditPos, int *pnEditWidth, int *pnButtonPos, int *pnButtonWidth) |
| 84 | | { |
| 85 | | struct DevViewInfo *pDevViewInfo; |
| 86 | | RECT r; |
| 87 | | |
| 88 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 89 | | |
| 90 | | GetClientRect(hwndDevView, &r); |
| 91 | | |
| 92 | | *pnStaticPos = DEVVIEW_PADDING; |
| 93 | | *pnStaticWidth = pDevViewInfo->nWidth; |
| 94 | | |
| 95 | | *pnButtonWidth = 25; |
| 96 | | *pnButtonPos = (r.right - r.left) - *pnButtonWidth - DEVVIEW_PADDING; |
| 97 | | |
| 98 | | *pnEditPos = *pnStaticPos + *pnStaticWidth + DEVVIEW_PADDING; |
| 99 | | *pnEditWidth = *pnButtonPos - *pnEditPos - DEVVIEW_PADDING; |
| 100 | | if (*pnEditWidth < 0) |
| 101 | | *pnEditWidth = 0; |
| 102 | | } |
| 103 | | |
| 104 | | |
| 105 | | |
| 106 | | void DevView_Refresh(HWND hwndDevView) |
| 107 | | { |
| 108 | | struct DevViewInfo *pDevViewInfo; |
| 109 | | int i; |
| 110 | | LPCTSTR pszSelection; |
| 111 | | TCHAR szBuffer[MAX_PATH]; |
| 112 | | |
| 113 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 114 | | |
| 115 | | if (pDevViewInfo->pEntries) |
| 116 | | { |
| 117 | | for (i = 0; pDevViewInfo->pEntries[i].dev; i++) |
| 118 | | { |
| 119 | | pszSelection = pDevViewInfo->pCallbacks->pfnGetSelectedSoftware( |
| 120 | | hwndDevView, |
| 121 | | pDevViewInfo->config->driver_index, |
| 122 | | pDevViewInfo->config->mconfig, |
| 123 | | pDevViewInfo->pEntries[i].dev, |
| 124 | | szBuffer, ARRAY_LENGTH(szBuffer)); |
| 125 | | |
| 126 | | if (!pszSelection) |
| 127 | | pszSelection = TEXT(""); |
| 128 | | |
| 129 | | pDevViewInfo->bSurpressFilenameChanged = TRUE; |
| 130 | | SetWindowText(pDevViewInfo->pEntries[i].hwndEdit, pszSelection); |
| 131 | | pDevViewInfo->bSurpressFilenameChanged = FALSE; |
| 132 | | } |
| 133 | | } |
| 134 | | } |
| 135 | | |
| 136 | | |
| 137 | | |
| 138 | | static void DevView_TextChanged(HWND hwndDevView, int nChangedEntry, LPCTSTR pszFilename) |
| 139 | | { |
| 140 | | struct DevViewInfo *pDevViewInfo; |
| 141 | | |
| 142 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 143 | | if (!pDevViewInfo->bSurpressFilenameChanged && pDevViewInfo->pCallbacks->pfnSetSelectedSoftware) |
| 144 | | { |
| 145 | | pDevViewInfo->pCallbacks->pfnSetSelectedSoftware(hwndDevView, |
| 146 | | pDevViewInfo->config->driver_index, |
| 147 | | pDevViewInfo->config->mconfig, |
| 148 | | pDevViewInfo->pEntries[nChangedEntry].dev, |
| 149 | | pszFilename); |
| 150 | | } |
| 151 | | } |
| 152 | | |
| 153 | | |
| 154 | | |
| 155 | | static LRESULT CALLBACK DevView_EditWndProc(HWND hwndEdit, UINT nMessage, WPARAM wParam, LPARAM lParam) |
| 156 | | { |
| 157 | | struct DevViewInfo *pDevViewInfo; |
| 158 | | struct DevViewEntry *pEnt; |
| 159 | | LRESULT rc; |
| 160 | | HWND hwndDevView; |
| 161 | | LONG_PTR l; |
| 162 | | |
| 163 | | l = GetWindowLongPtr(hwndEdit, GWLP_USERDATA); |
| 164 | | pEnt = (struct DevViewEntry *) l; |
| 165 | | if (IsWindowUnicode(hwndEdit)) |
| 166 | | rc = CallWindowProcW(pEnt->pfnEditWndProc, hwndEdit, nMessage, wParam, lParam); |
| 167 | | else |
| 168 | | rc = CallWindowProcA(pEnt->pfnEditWndProc, hwndEdit, nMessage, wParam, lParam); |
| 169 | | |
| 170 | | if (nMessage == WM_SETTEXT) |
| 171 | | { |
| 172 | | hwndDevView = GetParent(hwndEdit); |
| 173 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 174 | | DevView_TextChanged(hwndDevView, pEnt - pDevViewInfo->pEntries, (LPCTSTR) lParam); |
| 175 | | } |
| 176 | | return rc; |
| 177 | | } |
| 178 | | |
| 179 | | |
| 180 | | |
| 181 | | BOOL DevView_SetDriver(HWND hwndDevView, const software_config *config) |
| 182 | | { |
| 183 | | struct DevViewInfo *pDevViewInfo; |
| 184 | | const device_config_image_interface *dev = NULL; |
| 185 | | struct DevViewEntry *pEnt; |
| 186 | | int i; |
| 187 | | int y, nHeight, nDevCount; |
| 188 | | int nStaticPos, nStaticWidth, nEditPos, nEditWidth, nButtonPos, nButtonWidth; |
| 189 | | HDC hDc; |
| 190 | | LPTSTR *ppszDevices; |
| 191 | | LPTSTR t_s; |
| 192 | | SIZE sz; |
| 193 | | LONG_PTR l; |
| 194 | | |
| 195 | | |
| 196 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 197 | | |
| 198 | | // clear out |
| 199 | | DevView_Clear(hwndDevView); |
| 200 | | |
| 201 | | // copy the config |
| 202 | | pDevViewInfo->config = config; |
| 203 | | |
| 204 | | // count total amount of devices |
| 205 | | nDevCount = 0; |
| 206 | | |
| 207 | | { |
| 208 | | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 209 | | { |
| 210 | | nDevCount++; |
| 211 | | } |
| 212 | | } |
| 213 | | |
| 214 | | if (nDevCount > 0) |
| 215 | | { |
| 216 | | // get the names of all of the devices |
| 217 | | ppszDevices = (LPTSTR *) alloca(nDevCount * sizeof(*ppszDevices)); |
| 218 | | i = 0; |
| 219 | | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 220 | | { |
| 221 | | t_s = tstring_from_utf8(dev->devconfig().name()); |
| 222 | | ppszDevices[i] = (TCHAR*)alloca((_tcslen(t_s) + 1) * sizeof(TCHAR)); |
| 223 | | _tcscpy(ppszDevices[i], t_s); |
| 224 | | osd_free(t_s); |
| 225 | | i++; |
| 226 | | } |
| 227 | | |
| 228 | | // Calculate the requisite size for the device column |
| 229 | | pDevViewInfo->nWidth = 0; |
| 230 | | if (nDevCount > 0) |
| 231 | | { |
| 232 | | hDc = GetDC(hwndDevView); |
| 233 | | for (i = 0; i < nDevCount; i++) |
| 234 | | { |
| 235 | | GetTextExtentPoint32(hDc, ppszDevices[i], _tcslen(ppszDevices[i]), &sz); |
| 236 | | if (sz.cx > pDevViewInfo->nWidth) |
| 237 | | pDevViewInfo->nWidth = sz.cx; |
| 238 | | } |
| 239 | | ReleaseDC(hwndDevView, hDc); |
| 240 | | } |
| 241 | | |
| 242 | | pEnt = (struct DevViewEntry *) malloc(sizeof(struct DevViewEntry) * (nDevCount + 1)); |
| 243 | | if (!pEnt) |
| 244 | | return FALSE; |
| 245 | | memset(pEnt, 0, sizeof(struct DevViewEntry) * (nDevCount + 1)); |
| 246 | | pDevViewInfo->pEntries = pEnt; |
| 247 | | |
| 248 | | y = 10; |
| 249 | | nHeight = 21; |
| 250 | | DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth, |
| 251 | | &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth); |
| 252 | | |
| 253 | | for (bool gotone = pDevViewInfo->config->mconfig->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) |
| 254 | | { |
| 255 | | pEnt->dev = dev; |
| 256 | | |
| 257 | | pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", dev->devconfig().name(), |
| 258 | | WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight, |
| 259 | | hwndDevView, NULL, NULL, NULL); |
| 260 | | |
| 261 | | pEnt->hwndEdit = win_create_window_ex_utf8(0, "EDIT", "", |
| 262 | | WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, nEditPos, y, nEditWidth, nHeight, |
| 263 | | hwndDevView, NULL, NULL, NULL); |
| 264 | | |
| 265 | | pEnt->hwndBrowseButton = win_create_window_ex_utf8(0, "BUTTON", "...", |
| 266 | | WS_VISIBLE | WS_CHILD, nButtonPos, y, nButtonWidth, nHeight, |
| 267 | | hwndDevView, NULL, NULL, NULL); |
| 268 | | |
| 269 | | if (pEnt->hwndStatic) |
| 270 | | { |
| 271 | | SendMessage(pEnt->hwndStatic, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE); |
| 272 | | } |
| 273 | | if (pEnt->hwndEdit) |
| 274 | | { |
| 275 | | SendMessage(pEnt->hwndEdit, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE); |
| 276 | | l = (LONG_PTR) DevView_EditWndProc; |
| 277 | | l = SetWindowLongPtr(pEnt->hwndEdit, GWLP_WNDPROC, l); |
| 278 | | pEnt->pfnEditWndProc = (WNDPROC) l; |
| 279 | | SetWindowLongPtr(pEnt->hwndEdit, GWLP_USERDATA, (LONG_PTR) pEnt); |
| 280 | | } |
| 281 | | if (pEnt->hwndBrowseButton) |
| 282 | | { |
| 283 | | SetWindowLongPtr(pEnt->hwndBrowseButton, GWLP_USERDATA, (LONG_PTR) pEnt); |
| 284 | | } |
| 285 | | |
| 286 | | y += nHeight; |
| 287 | | pEnt++; |
| 288 | | } |
| 289 | | } |
| 290 | | |
| 291 | | DevView_Refresh(hwndDevView); |
| 292 | | return TRUE; |
| 293 | | } |
| 294 | | |
| 295 | | |
| 296 | | |
| 297 | | static void DevView_ButtonClick(HWND hwndDevView, struct DevViewEntry *pEnt, HWND hwndButton) |
| 298 | | { |
| 299 | | struct DevViewInfo *pDevViewInfo; |
| 300 | | HMENU hMenu; |
| 301 | | RECT r; |
| 302 | | int rc; |
| 303 | | BOOL b; |
| 304 | | TCHAR szPath[MAX_PATH]; |
| 305 | | |
| 306 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 307 | | |
| 308 | | hMenu = CreatePopupMenu(); |
| 309 | | |
| 310 | | if (pDevViewInfo->pCallbacks->pfnGetOpenFileName) |
| 311 | | AppendMenu(hMenu, MF_STRING, 1, TEXT("Mount...")); |
| 312 | | |
| 313 | | if (pEnt->dev->is_creatable()) |
| 314 | | { |
| 315 | | if (pDevViewInfo->pCallbacks->pfnGetCreateFileName) |
| 316 | | AppendMenu(hMenu, MF_STRING, 2, TEXT("Create...")); |
| 317 | | } |
| 318 | | |
| 319 | | AppendMenu(hMenu, MF_STRING, 3, TEXT("Unmount")); |
| 320 | | |
| 321 | | GetWindowRect(hwndButton, &r); |
| 322 | | rc = TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD, |
| 323 | | r.left, r.bottom, 0, hwndDevView, NULL); |
| 324 | | |
| 325 | | switch(rc) |
| 326 | | { |
| 327 | | case 1: |
| 328 | | b = pDevViewInfo->pCallbacks->pfnGetOpenFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev, |
| 329 | | szPath, ARRAY_LENGTH(szPath)); |
| 330 | | break; |
| 331 | | case 2: |
| 332 | | b = pDevViewInfo->pCallbacks->pfnGetCreateFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev, |
| 333 | | szPath, ARRAY_LENGTH(szPath)); |
| 334 | | break; |
| 335 | | case 3: |
| 336 | | memset(szPath, 0, sizeof(szPath)); |
| 337 | | b = TRUE; |
| 338 | | break; |
| 339 | | default: |
| 340 | | b = FALSE; |
| 341 | | break; |
| 342 | | } |
| 343 | | if (!b) |
| 344 | | return; |
| 345 | | SetWindowText(pEnt->hwndEdit, szPath); |
| 346 | | } |
| 347 | | |
| 348 | | |
| 349 | | |
| 350 | | static BOOL DevView_Setup(HWND hwndDevView) |
| 351 | | { |
| 352 | | struct DevViewInfo *pDevViewInfo; |
| 353 | | |
| 354 | | // allocate the device view info |
| 355 | | pDevViewInfo = (DevViewInfo*)malloc(sizeof(struct DevViewInfo)); |
| 356 | | if (!pDevViewInfo) |
| 357 | | return FALSE; |
| 358 | | memset(pDevViewInfo, 0, sizeof(*pDevViewInfo)); |
| 359 | | |
| 360 | | SetWindowLongPtr(hwndDevView, GWLP_USERDATA, (LONG_PTR) pDevViewInfo); |
| 361 | | |
| 362 | | // create and specify the font |
| 363 | | pDevViewInfo->hFont = CreateFont(10, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, |
| 364 | | 0, 0, 0, TEXT("MS Sans Serif")); |
| 365 | | SendMessage(hwndDevView, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, FALSE); |
| 366 | | return TRUE; |
| 367 | | } |
| 368 | | |
| 369 | | |
| 370 | | |
| 371 | | static void DevView_Free(HWND hwndDevView) |
| 372 | | { |
| 373 | | struct DevViewInfo *pDevViewInfo; |
| 374 | | |
| 375 | | DevView_Clear(hwndDevView); |
| 376 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 377 | | DeleteObject(pDevViewInfo->hFont); |
| 378 | | free(pDevViewInfo); |
| 379 | | } |
| 380 | | |
| 381 | | |
| 382 | | |
| 383 | | static LRESULT CALLBACK DevView_WndProc(HWND hwndDevView, UINT nMessage, WPARAM wParam, LPARAM lParam) |
| 384 | | { |
| 385 | | struct DevViewInfo *pDevViewInfo; |
| 386 | | struct DevViewEntry *pEnt; |
| 387 | | int nStaticPos, nStaticWidth, nEditPos, nEditWidth, nButtonPos, nButtonWidth; |
| 388 | | RECT r; |
| 389 | | LONG_PTR l; |
| 390 | | LRESULT rc = 0; |
| 391 | | BOOL bHandled = FALSE; |
| 392 | | HWND hwndButton; |
| 393 | | |
| 394 | | switch(nMessage) |
| 395 | | { |
| 396 | | case WM_DESTROY: |
| 397 | | DevView_Free(hwndDevView); |
| 398 | | break; |
| 399 | | |
| 400 | | case WM_SHOWWINDOW: |
| 401 | | if (wParam) |
| 402 | | { |
| 403 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 404 | | DevView_Refresh(hwndDevView); |
| 405 | | } |
| 406 | | break; |
| 407 | | |
| 408 | | case WM_COMMAND: |
| 409 | | switch(HIWORD(wParam)) |
| 410 | | { |
| 411 | | case BN_CLICKED: |
| 412 | | hwndButton = (HWND) lParam; |
| 413 | | l = GetWindowLongPtr(hwndButton, GWLP_USERDATA); |
| 414 | | pEnt = (struct DevViewEntry *) l; |
| 415 | | DevView_ButtonClick(hwndDevView, pEnt, hwndButton); |
| 416 | | break; |
| 417 | | } |
| 418 | | break; |
| 419 | | } |
| 420 | | |
| 421 | | if (!bHandled) |
| 422 | | rc = DefWindowProc(hwndDevView, nMessage, wParam, lParam); |
| 423 | | |
| 424 | | switch(nMessage) |
| 425 | | { |
| 426 | | case WM_CREATE: |
| 427 | | if (!DevView_Setup(hwndDevView)) |
| 428 | | return -1; |
| 429 | | break; |
| 430 | | |
| 431 | | case WM_MOVE: |
| 432 | | case WM_SIZE: |
| 433 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 434 | | pEnt = pDevViewInfo->pEntries; |
| 435 | | if (pEnt) |
| 436 | | { |
| 437 | | DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth, |
| 438 | | &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth); |
| 439 | | while(pEnt->dev) |
| 440 | | { |
| 441 | | GetClientRect(pEnt->hwndStatic, &r); |
| 442 | | MapWindowPoints(pEnt->hwndStatic, hwndDevView, ((POINT *) &r), 2); |
| 443 | | MoveWindow(pEnt->hwndStatic, nStaticPos, r.top, nStaticWidth, r.bottom - r.top, FALSE); |
| 444 | | MoveWindow(pEnt->hwndEdit, nEditPos, r.top, nEditWidth, r.bottom - r.top, FALSE); |
| 445 | | MoveWindow(pEnt->hwndBrowseButton, nButtonPos, r.top, nButtonWidth, r.bottom - r.top, FALSE); |
| 446 | | pEnt++; |
| 447 | | } |
| 448 | | } |
| 449 | | break; |
| 450 | | } |
| 451 | | return rc; |
| 452 | | } |
| 453 | | |
| 454 | | |
| 455 | | |
| 456 | | void DevView_SetCallbacks(HWND hwndDevView, const struct DevViewCallbacks *pCallbacks) |
| 457 | | { |
| 458 | | struct DevViewInfo *pDevViewInfo; |
| 459 | | pDevViewInfo = GetDevViewInfo(hwndDevView); |
| 460 | | pDevViewInfo->pCallbacks = pCallbacks; |
| 461 | | } |
| 462 | | |
| 463 | | |
| 464 | | |
| 465 | | void DevView_RegisterClass(void) |
| 466 | | { |
| 467 | | WNDCLASS wc; |
| 468 | | memset(&wc, 0, sizeof(wc)); |
| 469 | | wc.lpszClassName = TEXT("MessSoftwareDevView"); |
| 470 | | wc.hInstance = GetModuleHandle(NULL); |
| 471 | | wc.lpfnWndProc = DevView_WndProc; |
| 472 | | wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); |
| 473 | | RegisterClass(&wc); |
| 474 | | } |
| 475 | | |
| 476 | | |
| 477 | | |
src/mess/osd/winui/layoutms.c
| r10258 | r10259 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | layoutms.c |
| 4 | | |
| 5 | | MESS specific TreeView definitions (and maybe more in the future) |
| 6 | | |
| 7 | | ***************************************************************************/ |
| 8 | | |
| 9 | | #define WIN32_LEAN_AND_MEAN |
| 10 | | #include <windows.h> |
| 11 | | #include <windowsx.h> |
| 12 | | #include <shellapi.h> |
| 13 | | #include <commctrl.h> |
| 14 | | #include <stdio.h> /* for sprintf */ |
| 15 | | #include <stdlib.h> /* For malloc and free */ |
| 16 | | #include <string.h> |
| 17 | | |
| 18 | | #include "emu.h" |
| 19 | | #include "bitmask.h" |
| 20 | | #include "TreeView.h" |
| 21 | | #include "mui_util.h" |
| 22 | | #include "resource.h" |
| 23 | | #include "directories.h" |
| 24 | | #include "mui_opts.h" |
| 25 | | #include "splitters.h" |
| 26 | | #include "help.h" |
| 27 | | #include "mui_audit.h" |
| 28 | | #include "screenshot.h" |
| 29 | | #include "winui.h" |
| 30 | | #include "properties.h" |
| 31 | | |
| 32 | | #include "msuiutil.h" |
| 33 | | #include "resourcems.h" |
| 34 | | #include "propertiesms.h" |
| 35 | | |
| 36 | | static BOOL FilterAvailable(int driver_index); |
| 37 | | |
| 38 | | extern const FOLDERDATA g_folderData[] = |
| 39 | | { |
| 40 | | {"All Systems", "allgames", FOLDER_ALLGAMES, IDI_FOLDER, 0, 0, NULL, NULL, TRUE }, |
| 41 | | {"Available", "available", FOLDER_AVAILABLE, IDI_FOLDER_AVAILABLE, F_AVAILABLE, 0, NULL, FilterAvailable, TRUE }, |
| 42 | | #ifdef SHOW_UNAVAILABLE_FOLDER |
| 43 | | {"Unavailable", "unavailable", FOLDER_UNAVAILABLE, IDI_FOLDER_UNAVAILABLE, 0, F_AVAILABLE, NULL, FilterAvailable, FALSE }, |
| 44 | | #endif |
| 45 | | {"Console", "console", FOLDER_CONSOLE, IDI_FOLDER, F_CONSOLE, F_COMPUTER, NULL, DriverIsConsole, TRUE }, |
| 46 | | {"Computer", "computer", FOLDER_COMPUTER, IDI_FOLDER, F_COMPUTER, F_CONSOLE, NULL, DriverIsComputer, TRUE }, |
| 47 | | {"Modified/Hacked", "modified", FOLDER_MODIFIED, IDI_FOLDER, 0, 0, NULL, DriverIsModified, TRUE }, |
| 48 | | {"Manufacturer", "manufacturer", FOLDER_MANUFACTURER, IDI_FOLDER_MANUFACTURER, 0, 0, CreateManufacturerFolders }, |
| 49 | | {"Year", "year", FOLDER_YEAR, IDI_FOLDER_YEAR, 0, 0, CreateYearFolders }, |
| 50 | | {"Source", "source", FOLDER_SOURCE, IDI_FOLDER_SOURCE, 0, 0, CreateSourceFolders }, |
| 51 | | {"CPU", "cpu", FOLDER_CPU, IDI_FOLDER, 0, 0, CreateCPUFolders }, |
| 52 | | {"Sound", "sound", FOLDER_SND, IDI_FOLDER, 0, 0, CreateSoundFolders }, |
| 53 | | {"Imperfect", "imperfect", FOLDER_DEFICIENCY, IDI_FOLDER, 0, 0, CreateDeficiencyFolders }, |
| 54 | | {"Dumping Status", "dumping", FOLDER_DUMPING, IDI_FOLDER, 0, 0, CreateDumpingFolders }, |
| 55 | | {"Working", "working", FOLDER_WORKING, IDI_WORKING, F_WORKING, F_NONWORKING, NULL, DriverIsBroken, FALSE }, |
| 56 | | {"Not Working", "nonworking", FOLDER_NONWORKING, IDI_NONWORKING, F_NONWORKING, F_WORKING, NULL, DriverIsBroken, TRUE }, |
| 57 | | {"Originals", "originals", FOLDER_ORIGINAL, IDI_FOLDER, F_ORIGINALS, F_CLONES, NULL, DriverIsClone, FALSE }, |
| 58 | | {"Clones", "clones", FOLDER_CLONES, IDI_FOLDER, F_CLONES, F_ORIGINALS, NULL, DriverIsClone, TRUE }, |
| 59 | | {"Raster", "raster", FOLDER_RASTER, IDI_FOLDER, F_RASTER, F_VECTOR, NULL, DriverIsVector, FALSE }, |
| 60 | | {"Vector", "vector", FOLDER_VECTOR, IDI_FOLDER, F_VECTOR, F_RASTER, NULL, DriverIsVector, TRUE }, |
| 61 | | {"Mouse", "mouse", FOLDER_MOUSE, IDI_FOLDER, 0, 0, NULL, DriverUsesMouse, TRUE }, |
| 62 | | {"Trackball", "trackball", FOLDER_TRACKBALL, IDI_FOLDER, 0, 0, NULL, DriverUsesTrackball, TRUE }, |
| 63 | | {"Stereo", "stereo", FOLDER_STEREO, IDI_SOUND, 0, 0, NULL, DriverIsStereo, TRUE }, |
| 64 | | { NULL } |
| 65 | | }; |
| 66 | | |
| 67 | | /* list of filter/control Id pairs */ |
| 68 | | extern const FILTER_ITEM g_filterList[] = |
| 69 | | { |
| 70 | | { F_COMPUTER, IDC_FILTER_COMPUTER, DriverIsComputer, TRUE }, |
| 71 | | { F_CONSOLE, IDC_FILTER_CONSOLE, DriverIsConsole, TRUE }, |
| 72 | | { F_MODIFIED, IDC_FILTER_MODIFIED, DriverIsModified, TRUE }, |
| 73 | | { F_CLONES, IDC_FILTER_CLONES, DriverIsClone, TRUE }, |
| 74 | | { F_NONWORKING, IDC_FILTER_NONWORKING, DriverIsBroken, TRUE }, |
| 75 | | { F_UNAVAILABLE, IDC_FILTER_UNAVAILABLE, FilterAvailable, FALSE }, |
| 76 | | { F_RASTER, IDC_FILTER_RASTER, DriverIsVector, FALSE }, |
| 77 | | { F_VECTOR, IDC_FILTER_VECTOR, DriverIsVector, TRUE }, |
| 78 | | { F_ORIGINALS, IDC_FILTER_ORIGINALS, DriverIsClone, FALSE }, |
| 79 | | { F_WORKING, IDC_FILTER_WORKING, DriverIsBroken, FALSE }, |
| 80 | | { F_AVAILABLE, IDC_FILTER_AVAILABLE, FilterAvailable, TRUE }, |
| 81 | | { 0 } |
| 82 | | }; |
| 83 | | |
| 84 | | extern const DIRECTORYINFO g_directoryInfo[] = |
| 85 | | { |
| 86 | | { "ROMs", GetRomDirs, SetRomDirs, TRUE, DIRDLG_ROMS }, |
| 87 | | { "Software", GetSoftwareDirs, SetSoftwareDirs, TRUE, DIRDLG_SOFTWARE }, |
| 88 | | { "Artwork", GetArtDir, SetArtDir, FALSE, 0 }, |
| 89 | | { "Background Images", GetBgDir, SetBgDir, FALSE, 0 }, |
| 90 | | { "Cabinets", GetCabinetDir, SetCabinetDir, FALSE, 0 }, |
| 91 | | { "Cheats", GetCheatDir, SetCheatDir, FALSE, DIRDLG_CHEAT }, |
| 92 | | { "Comment Files", GetCommentDir, SetCommentDir, FALSE, DIRDLG_COMMENT }, |
| 93 | | { "Config", GetCfgDir, SetCfgDir, FALSE, DIRDLG_CFG }, |
| 94 | | { "Control Panels", GetControlPanelDir, SetControlPanelDir, FALSE, 0 }, |
| 95 | | { "Controller Files", GetCtrlrDir, SetCtrlrDir, FALSE, DIRDLG_CTRLR }, |
| 96 | | { "Crosshairs", GetCrosshairDir, SetCrosshairDir, FALSE, 0 }, |
| 97 | | { "Fonts", GetFontDir, SetFontDir, FALSE, 0 }, |
| 98 | | { "Flyers", GetFlyerDir, SetFlyerDir, FALSE, 0 }, |
| 99 | | { "Hash", GetHashDirs, SetHashDirs, FALSE, 0 }, |
| 100 | | { "Hard Drive Difference", GetDiffDir, SetDiffDir, FALSE, 0 }, |
| 101 | | { "Icons", GetIconsDir, SetIconsDir, FALSE, 0 }, |
| 102 | | { "Ini Files", GetIniDir, SetIniDir, FALSE, DIRDLG_INI }, |
| 103 | | { "Input files", GetInpDir, SetInpDir, FALSE, DIRDLG_INP }, |
| 104 | | { "Marquees", GetMarqueeDir, SetMarqueeDir, FALSE, 0 }, |
| 105 | | { "Memory Card", GetMemcardDir, SetMemcardDir, FALSE, 0 }, |
| 106 | | { "NVRAM", GetNvramDir, SetNvramDir, FALSE, 0 }, |
| 107 | | { "PCBs", GetPcbDir, SetPcbDir, FALSE, 0 }, |
| 108 | | { "Snapshots", GetImgDir, SetImgDir, FALSE, DIRDLG_IMG }, |
| 109 | | { "State", GetStateDir, SetStateDir, FALSE, 0 }, |
| 110 | | { "Titles", GetTitlesDir, SetTitlesDir, FALSE, 0 }, |
| 111 | | { NULL } |
| 112 | | }; |
| 113 | | |
| 114 | | extern const SPLITTERINFO g_splitterInfo[] = |
| 115 | | { |
| 116 | | { 0.2, IDC_SPLITTER, IDC_TREE, IDC_LIST, AdjustSplitter1Rect }, |
| 117 | | { 0.4, IDC_SPLITTER2, IDC_LIST, IDC_SWLIST, AdjustSplitter1Rect }, |
| 118 | | { 0.6, IDC_SPLITTER3, IDC_SWTAB, IDC_SSFRAME, AdjustSplitter2Rect }, |
| 119 | | { -1 } |
| 120 | | }; |
| 121 | | |
| 122 | | extern const MAMEHELPINFO g_helpInfo[] = |
| 123 | | { |
| 124 | | { ID_HELP_CONTENTS, TRUE, "mess.chm::/windows/main.htm" }, |
| 125 | | { ID_HELP_RELEASE, TRUE, "mess.chm" }, |
| 126 | | { ID_HELP_WHATS_NEW, TRUE, "mess.chm::/messnew.txt" }, |
| 127 | | { -1 } |
| 128 | | }; |
| 129 | | |
| 130 | | extern const PROPERTYSHEETINFO g_propSheets[] = |
| 131 | | { |
| 132 | | { FALSE, NULL, IDD_PROP_GAME, GamePropertiesDialogProc }, |
| 133 | | { FALSE, NULL, IDD_PROP_AUDIT, GameAuditDialogProc }, |
| 134 | | { TRUE, NULL, IDD_PROP_DISPLAY, GameOptionsProc }, |
| 135 | | { TRUE, NULL, IDD_PROP_ADVANCED, GameOptionsProc }, |
| 136 | | { TRUE, NULL, IDD_PROP_SCREEN, GameOptionsProc }, |
| 137 | | { TRUE, NULL, IDD_PROP_SOUND, GameOptionsProc }, |
| 138 | | { TRUE, NULL, IDD_PROP_INPUT, GameOptionsProc }, |
| 139 | | { TRUE, NULL, IDD_PROP_CONTROLLER, GameOptionsProc }, |
| 140 | | { TRUE, NULL, IDD_PROP_DEBUG, GameOptionsProc }, |
| 141 | | { TRUE, NULL, IDD_PROP_MISC, GameOptionsProc }, |
| 142 | | { FALSE, NULL, IDD_PROP_SOFTWARE, GameMessOptionsProc }, |
| 143 | | { FALSE, PropSheetFilter_Config, IDD_PROP_CONFIGURATION, GameMessOptionsProc }, |
| 144 | | { TRUE, PropSheetFilter_Vector, IDD_PROP_VECTOR, GameOptionsProc }, |
| 145 | | { FALSE } |
| 146 | | }; |
| 147 | | |
| 148 | | extern const ICONDATA g_iconData[] = |
| 149 | | { |
| 150 | | { IDI_WIN_NOROMS, "noroms" }, |
| 151 | | { IDI_WIN_ROMS, "roms" }, |
| 152 | | { IDI_WIN_UNKNOWN, "unknown" }, |
| 153 | | { IDI_WIN_CLONE, "clone" }, |
| 154 | | { IDI_WIN_REDX, "warning" }, |
| 155 | | { IDI_WIN_NOROMSNEEDED, "noromsneeded" }, |
| 156 | | { IDI_WIN_MISSINGOPTROM, "missingoptrom" }, |
| 157 | | { IDI_WIN_FLOP, "floppy" }, |
| 158 | | { IDI_WIN_CASS, "cassette" }, |
| 159 | | { IDI_WIN_SERL, "serial" }, |
| 160 | | { IDI_WIN_SNAP, "snapshot" }, |
| 161 | | { IDI_WIN_PRIN, "printer" }, |
| 162 | | { IDI_WIN_HARD, "hard" }, |
| 163 | | { 0 } |
| 164 | | }; |
| 165 | | |
| 166 | | extern const TCHAR g_szPlayGameString[] = TEXT("&Run %s"); |
| 167 | | extern const char g_szGameCountString[] = "%d systems"; |
| 168 | | static const char g_szHistoryFileName[] = "sysinfo.dat"; |
| 169 | | static const char g_szMameInfoFileName[] = "messinfo.dat"; |
| 170 | | |
| 171 | | static BOOL FilterAvailable(int driver_index) |
| 172 | | { |
| 173 | | return !DriverUsesRoms(driver_index) || IsAuditResultYes(GetRomAuditResults(driver_index)); |
| 174 | | } |
src/mess/osd/winui/softwarepicker.c
| r10258 | r10259 | |
| 1 | | //============================================================ |
| 2 | | // |
| 3 | | // softwarepicker.c - MESS's software picker |
| 4 | | // |
| 5 | | //============================================================ |
| 6 | | |
| 7 | | #define WIN32_LEAN_AND_MEAN |
| 8 | | #include <assert.h> |
| 9 | | #include <string.h> |
| 10 | | #include <windows.h> |
| 11 | | #include <shellapi.h> |
| 12 | | #include <commctrl.h> |
| 13 | | #include <commdlg.h> |
| 14 | | #include <wingdi.h> |
| 15 | | #include <winuser.h> |
| 16 | | #include <tchar.h> |
| 17 | | #include <ctype.h> |
| 18 | | |
| 19 | | #include "emu.h" |
| 20 | | #include "unzip.h" |
| 21 | | #include "strconv.h" |
| 22 | | #include "hashfile.h" |
| 23 | | #include "picker.h" |
| 24 | | #include "screenshot.h" |
| 25 | | #include "bitmask.h" |
| 26 | | #include "winui.h" |
| 27 | | #include "resourcems.h" |
| 28 | | #include "mui_opts.h" |
| 29 | | #include "softwarepicker.h" |
| 30 | | #include "mui_util.h" |
| 31 | | |
| 32 | | |
| 33 | | |
| 34 | | //============================================================ |
| 35 | | // TYPE DEFINITIONS |
| 36 | | //============================================================ |
| 37 | | |
| 38 | | typedef struct _file_info file_info; |
| 39 | | struct _file_info |
| 40 | | { |
| 41 | | const device_config_image_interface *device; |
| 42 | | |
| 43 | | // hash information |
| 44 | | char hash_string[HASH_BUF_SIZE]; |
| 45 | | BOOL hash_realized; |
| 46 | | const hash_info *hashinfo; |
| 47 | | |
| 48 | | const char *zip_entry_name; |
| 49 | | const char *base_name; |
| 50 | | char file_name[1]; |
| 51 | | }; |
| 52 | | |
| 53 | | typedef struct _directory_search_info directory_search_info; |
| 54 | | struct _directory_search_info |
| 55 | | { |
| 56 | | directory_search_info *next; |
| 57 | | HANDLE find_handle; |
| 58 | | WIN32_FIND_DATA fd; |
| 59 | | char directory_name[1]; |
| 60 | | }; |
| 61 | | |
| 62 | | typedef struct _software_picker_info software_picker_info; |
| 63 | | struct _software_picker_info |
| 64 | | { |
| 65 | | WNDPROC old_window_proc; |
| 66 | | file_info **file_index; |
| 67 | | int file_index_length; |
| 68 | | int hashes_realized; |
| 69 | | int current_position; |
| 70 | | directory_search_info *first_search_info; |
| 71 | | directory_search_info *last_search_info; |
| 72 | | const software_config *config; |
| 73 | | }; |
| 74 | | |
| 75 | | |
| 76 | | |
| 77 | | //============================================================ |
| 78 | | // CONSTANTS |
| 79 | | //============================================================ |
| 80 | | |
| 81 | | static const TCHAR software_picker_property_name[] = TEXT("SWPICKER"); |
| 82 | | |
| 83 | | |
| 84 | | |
| 85 | | //============================================================ |
| 86 | | |
| 87 | | static LPCSTR NormalizePath(LPCSTR pszPath, LPSTR pszBuffer, size_t nBufferSize) |
| 88 | | { |
| 89 | | BOOL bChanged = FALSE; |
| 90 | | LPSTR s; |
| 91 | | int i, j; |
| 92 | | |
| 93 | | if (pszPath[0] == '\\') |
| 94 | | { |
| 95 | | win_get_current_directory_utf8(nBufferSize, pszBuffer); |
| 96 | | pszBuffer[2] = '\0'; |
| 97 | | bChanged = TRUE; |
| 98 | | } |
| 99 | | else if (!isalpha(pszPath[0]) || (pszPath[1] != ':')) |
| 100 | | { |
| 101 | | win_get_current_directory_utf8(nBufferSize, pszBuffer); |
| 102 | | bChanged = TRUE; |
| 103 | | } |
| 104 | | |
| 105 | | if (bChanged) |
| 106 | | { |
| 107 | | s = (LPSTR) alloca(strlen(pszBuffer) + 1); |
| 108 | | strcpy(s, pszBuffer); |
| 109 | | snprintf(pszBuffer, nBufferSize, "%s\\%s", s, pszPath); |
| 110 | | pszPath = pszBuffer; |
| 111 | | |
| 112 | | // Remove double path separators |
| 113 | | i = 0; |
| 114 | | j = 0; |
| 115 | | while(pszBuffer[i]) |
| 116 | | { |
| 117 | | while ((pszBuffer[i] == '\\') && (pszBuffer[i+1] == '\\')) |
| 118 | | i++; |
| 119 | | pszBuffer[j++] = pszBuffer[i++]; |
| 120 | | } |
| 121 | | pszBuffer[j] = '\0'; |
| 122 | | } |
| 123 | | return pszPath; |
| 124 | | } |
| 125 | | |
| 126 | | |
| 127 | | |
| 128 | | static software_picker_info *GetSoftwarePickerInfo(HWND hwndPicker) |
| 129 | | { |
| 130 | | HANDLE h; |
| 131 | | h = GetProp(hwndPicker, software_picker_property_name); |
| 132 | | assert(h); |
| 133 | | return (software_picker_info *) h; |
| 134 | | } |
| 135 | | |
| 136 | | |
| 137 | | |
| 138 | | LPCSTR SoftwarePicker_LookupFilename(HWND hwndPicker, int nIndex) |
| 139 | | { |
| 140 | | software_picker_info *pPickerInfo; |
| 141 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 142 | | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 143 | | return NULL; |
| 144 | | return pPickerInfo->file_index[nIndex]->file_name; |
| 145 | | } |
| 146 | | |
| 147 | | |
| 148 | | |
| 149 | | const device_config_image_interface *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex) |
| 150 | | { |
| 151 | | software_picker_info *pPickerInfo; |
| 152 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 153 | | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 154 | | { |
| 155 | | return NULL; |
| 156 | | } |
| 157 | | return pPickerInfo->file_index[nIndex]->device; |
| 158 | | } |
| 159 | | |
| 160 | | |
| 161 | | |
| 162 | | int SoftwarePicker_LookupIndex(HWND hwndPicker, LPCSTR pszFilename) |
| 163 | | { |
| 164 | | software_picker_info *pPickerInfo; |
| 165 | | int i; |
| 166 | | |
| 167 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 168 | | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 169 | | { |
| 170 | | if (!mame_stricmp(pPickerInfo->file_index[i]->file_name, pszFilename)) |
| 171 | | return i; |
| 172 | | } |
| 173 | | return -1; |
| 174 | | } |
| 175 | | |
| 176 | | |
| 177 | | |
| 178 | | iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex) |
| 179 | | { |
| 180 | | iodevice_t type; |
| 181 | | const device_config_image_interface *device = SoftwarePicker_LookupDevice(hwndPicker, nIndex); |
| 182 | | |
| 183 | | if (device != NULL) |
| 184 | | { |
| 185 | | type = device->image_type(); |
| 186 | | } |
| 187 | | else |
| 188 | | { |
| 189 | | type = IO_UNKNOWN; |
| 190 | | } |
| 191 | | return type; |
| 192 | | } |
| 193 | | |
| 194 | | |
| 195 | | |
| 196 | | void SoftwarePicker_SetDriver(HWND hwndPicker, const software_config *config) |
| 197 | | { |
| 198 | | int i; |
| 199 | | software_picker_info *pPickerInfo; |
| 200 | | |
| 201 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 202 | | pPickerInfo->config = config; |
| 203 | | |
| 204 | | // invalidate the hash "realization" |
| 205 | | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 206 | | { |
| 207 | | pPickerInfo->file_index[i]->hashinfo = NULL; |
| 208 | | pPickerInfo->file_index[i]->hash_realized = FALSE; |
| 209 | | } |
| 210 | | pPickerInfo->hashes_realized = 0; |
| 211 | | } |
| 212 | | |
| 213 | | |
| 214 | | |
| 215 | | static void ComputeFileHash(software_picker_info *pPickerInfo, |
| 216 | | file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength) |
| 217 | | { |
| 218 | | unsigned int functions; |
| 219 | | |
| 220 | | // determine which functions to use |
| 221 | | functions = hashfile_functions_used(pPickerInfo->config->hashfile, pFileInfo->device->image_type()); |
| 222 | | |
| 223 | | // compute the hash |
| 224 | | pFileInfo->device->device_compute_hash((char *)pFileInfo->hash_string, (const void *)pBuffer, (size_t)nLength, functions); |
| 225 | | } |
| 226 | | |
| 227 | | |
| 228 | | |
| 229 | | static BOOL SoftwarePicker_CalculateHash(HWND hwndPicker, int nIndex) |
| 230 | | { |
| 231 | | software_picker_info *pPickerInfo; |
| 232 | | file_info *pFileInfo; |
| 233 | | LPSTR pszZipName; |
| 234 | | BOOL rc = FALSE; |
| 235 | | unsigned char *pBuffer; |
| 236 | | unsigned int nLength; |
| 237 | | HANDLE hFile, hFileMapping; |
| 238 | | LVFINDINFO lvfi; |
| 239 | | BOOL res; |
| 240 | | |
| 241 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 242 | | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 243 | | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 244 | | |
| 245 | | if (pFileInfo->zip_entry_name) |
| 246 | | { |
| 247 | | // this is in a ZIP file |
| 248 | | zip_file *zip; |
| 249 | | zip_error ziperr; |
| 250 | | const zip_file_header *zipent; |
| 251 | | |
| 252 | | // open the ZIP file |
| 253 | | nLength = pFileInfo->zip_entry_name - pFileInfo->file_name; |
| 254 | | pszZipName = (LPSTR) alloca(nLength); |
| 255 | | memcpy(pszZipName, pFileInfo->file_name, nLength); |
| 256 | | pszZipName[nLength - 1] = '\0'; |
| 257 | | |
| 258 | | // get the entry name |
| 259 | | ziperr = zip_file_open(pszZipName, &zip); |
| 260 | | if (ziperr == ZIPERR_NONE) |
| 261 | | { |
| 262 | | zipent = zip_file_first_file(zip); |
| 263 | | while(!rc && zipent) |
| 264 | | { |
| 265 | | if (!mame_stricmp(zipent->filename, pFileInfo->zip_entry_name)) |
| 266 | | { |
| 267 | | pBuffer = (unsigned char *)malloc(zipent->uncompressed_length); |
| 268 | | if (pBuffer) |
| 269 | | { |
| 270 | | ziperr = zip_file_decompress(zip, pBuffer, zipent->uncompressed_length); |
| 271 | | if (ziperr == ZIPERR_NONE) |
| 272 | | { |
| 273 | | ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, zipent->uncompressed_length); |
| 274 | | rc = TRUE; |
| 275 | | } |
| 276 | | free(pBuffer); |
| 277 | | } |
| 278 | | } |
| 279 | | zipent = zip_file_next_file(zip); |
| 280 | | } |
| 281 | | zip_file_close(zip); |
| 282 | | } |
| 283 | | } |
| 284 | | else |
| 285 | | { |
| 286 | | // plain open file; map it into memory and calculate the hash |
| 287 | | hFile = win_create_file_utf8(pFileInfo->file_name, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 288 | | OPEN_EXISTING, 0, NULL); |
| 289 | | if (hFile != INVALID_HANDLE_VALUE) |
| 290 | | { |
| 291 | | nLength = GetFileSize(hFile, NULL); |
| 292 | | hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); |
| 293 | | if (hFileMapping) |
| 294 | | { |
| 295 | | pBuffer = (unsigned char *)MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0); |
| 296 | | if (pBuffer) |
| 297 | | { |
| 298 | | ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, nLength); |
| 299 | | UnmapViewOfFile(pBuffer); |
| 300 | | rc = TRUE; |
| 301 | | } |
| 302 | | CloseHandle(hFileMapping); |
| 303 | | } |
| 304 | | CloseHandle(hFile); |
| 305 | | } |
| 306 | | } |
| 307 | | |
| 308 | | if (rc) |
| 309 | | { |
| 310 | | memset(&lvfi, 0, sizeof(lvfi)); |
| 311 | | lvfi.flags = LVFI_PARAM; |
| 312 | | lvfi.lParam = nIndex; |
| 313 | | nIndex = ListView_FindItem(hwndPicker, -1, &lvfi); |
| 314 | | if (nIndex > 0) |
| 315 | | res = ListView_RedrawItems(hwndPicker, nIndex, nIndex); |
| 316 | | } |
| 317 | | |
| 318 | | return rc; |
| 319 | | } |
| 320 | | |
| 321 | | |
| 322 | | |
| 323 | | static void SoftwarePicker_RealizeHash(HWND hwndPicker, int nIndex) |
| 324 | | { |
| 325 | | software_picker_info *pPickerInfo; |
| 326 | | file_info *pFileInfo; |
| 327 | | unsigned int nHashFunctionsUsed = 0; |
| 328 | | unsigned int nCalculatedHashes = 0; |
| 329 | | iodevice_t type; |
| 330 | | |
| 331 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 332 | | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 333 | | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 334 | | |
| 335 | | // Determine which hash functions we need to use for this file, and which hashes |
| 336 | | // have already been calculated |
| 337 | | if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL)) |
| 338 | | { |
| 339 | | type = pFileInfo->device->image_type(); |
| 340 | | if (type < IO_COUNT) |
| 341 | | nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->config->hashfile, type); |
| 342 | | nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string); |
| 343 | | } |
| 344 | | |
| 345 | | // Did we fully compute all hashes? |
| 346 | | if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0) |
| 347 | | { |
| 348 | | // We have calculated all hashs for this file; mark it as realized |
| 349 | | pPickerInfo->file_index[nIndex]->hash_realized = TRUE; |
| 350 | | pPickerInfo->hashes_realized++; |
| 351 | | |
| 352 | | if (pPickerInfo->config->hashfile) |
| 353 | | { |
| 354 | | pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->config->hashfile, |
| 355 | | pPickerInfo->file_index[nIndex]->hash_string); |
| 356 | | } |
| 357 | | } |
| 358 | | } |
| 359 | | |
| 360 | | |
| 361 | | |
| 362 | | static BOOL SoftwarePicker_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename, |
| 363 | | UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce) |
| 364 | | { |
| 365 | | software_picker_info *pPickerInfo; |
| 366 | | file_info **ppNewIndex; |
| 367 | | file_info *pInfo; |
| 368 | | int nIndex, nSize; |
| 369 | | LPCSTR pszExtension = NULL; |
| 370 | | const device_config_image_interface *device = NULL; |
| 371 | | |
| 372 | | // first check to see if it is already here |
| 373 | | if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0) |
| 374 | | return TRUE; |
| 375 | | |
| 376 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 377 | | |
| 378 | | // look up the device |
| 379 | | if (strrchr(pszFilename, '.')) |
| 380 | | pszExtension = strrchr(pszFilename, '.'); |
| 381 | | if ((pszExtension != NULL) && (pPickerInfo->config != NULL)) |
| 382 | | { |
| 383 | | for (bool gotone = pPickerInfo->config->mconfig->m_devicelist.first(device); gotone; gotone = device->next(device)) |
| 384 | | { |
| 385 | | if (device->uses_file_extension(pszExtension)) { |
| 386 | | break; |
| 387 | | } |
| 388 | | } |
| 389 | | } |
| 390 | | |
| 391 | | // no device? cop out unless bForce is on |
| 392 | | if ((device == NULL) && !bForce) |
| 393 | | return TRUE; |
| 394 | | |
| 395 | | // create the FileInfo structure |
| 396 | | nSize = sizeof(file_info) + strlen(pszFilename); |
| 397 | | pInfo = (file_info *) malloc(nSize); |
| 398 | | if (!pInfo) |
| 399 | | goto error; |
| 400 | | memset(pInfo, 0, nSize); |
| 401 | | |
| 402 | | // copy the filename |
| 403 | | strcpy(pInfo->file_name, pszFilename); |
| 404 | | |
| 405 | | // set up device and CRC, if specified |
| 406 | | pInfo->device = device; |
| 407 | | if ((device != NULL) && (device->has_partial_hash() != 0)) |
| 408 | | nCrc = 0; |
| 409 | | if (nCrc != 0) |
| 410 | | snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc); |
| 411 | | |
| 412 | | // set up zip entry name length, if specified |
| 413 | | if (nZipEntryNameLength > 0) |
| 414 | | pInfo->zip_entry_name = pInfo->file_name + strlen(pInfo->file_name) - nZipEntryNameLength; |
| 415 | | |
| 416 | | // calculate the subname |
| 417 | | pInfo->base_name = strrchr(pInfo->file_name, '\\'); |
| 418 | | if (pInfo->base_name) |
| 419 | | pInfo->base_name++; |
| 420 | | else |
| 421 | | pInfo->base_name = pInfo->file_name; |
| 422 | | |
| 423 | | ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index)); |
| 424 | | memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index)); |
| 425 | | if (pPickerInfo->file_index) free(pPickerInfo->file_index); |
| 426 | | if (!ppNewIndex) |
| 427 | | goto error; |
| 428 | | |
| 429 | | nIndex = pPickerInfo->file_index_length++; |
| 430 | | pPickerInfo->file_index = ppNewIndex; |
| 431 | | pPickerInfo->file_index[nIndex] = pInfo; |
| 432 | | |
| 433 | | // Realize the hash |
| 434 | | SoftwarePicker_RealizeHash(hwndPicker, nIndex); |
| 435 | | |
| 436 | | // Actually insert the item into the picker |
| 437 | | Picker_InsertItemSorted(hwndPicker, nIndex); |
| 438 | | return TRUE; |
| 439 | | |
| 440 | | error: |
| 441 | | if (pInfo) |
| 442 | | free(pInfo); |
| 443 | | return FALSE; |
| 444 | | } |
| 445 | | |
| 446 | | |
| 447 | | |
| 448 | | static BOOL SoftwarePicker_AddZipEntFile(HWND hwndPicker, LPCSTR pszZipPath, |
| 449 | | BOOL bForce, zip_file *pZip, const zip_file_header *pZipEnt) |
| 450 | | { |
| 451 | | LPSTR s; |
| 452 | | LPCSTR temp = pZipEnt->filename; |
| 453 | | int nLength; |
| 454 | | int nZipEntryNameLength; |
| 455 | | |
| 456 | | // special case; skip first two characters if they are './' |
| 457 | | if ((pZipEnt->filename[0] == '.') && (pZipEnt->filename[1] == '/')) |
| 458 | | { |
| 459 | | while(*(++temp) == '/') |
| 460 | | ; |
| 461 | | } |
| 462 | | |
| 463 | | nZipEntryNameLength = strlen(pZipEnt->filename); |
| 464 | | nLength = strlen(pszZipPath) + 1 + nZipEntryNameLength + 1; |
| 465 | | s = (LPSTR) alloca(nLength); |
| 466 | | snprintf(s, nLength, "%s\\%s", pszZipPath, pZipEnt->filename); |
| 467 | | |
| 468 | | return SoftwarePicker_AddFileEntry(hwndPicker, s, |
| 469 | | nZipEntryNameLength, pZipEnt->crc, bForce); |
| 470 | | } |
| 471 | | |
| 472 | | static BOOL SoftwarePicker_InternalAddFile(HWND hwndPicker, LPCSTR pszFilename, |
| 473 | | BOOL bForce) |
| 474 | | { |
| 475 | | LPCSTR s; |
| 476 | | BOOL rc = TRUE; |
| 477 | | zip_error ziperr; |
| 478 | | zip_file *pZip; |
| 479 | | const zip_file_header *pZipEnt; |
| 480 | | |
| 481 | | s = strrchr(pszFilename, '.'); |
| 482 | | if (s && !mame_stricmp(s, ".zip")) |
| 483 | | { |
| 484 | | ziperr = zip_file_open(pszFilename, &pZip); |
| 485 | | if (ziperr == ZIPERR_NONE) |
| 486 | | { |
| 487 | | pZipEnt = zip_file_first_file(pZip); |
| 488 | | while(rc && pZipEnt) |
| 489 | | { |
| 490 | | rc = SoftwarePicker_AddZipEntFile(hwndPicker, pszFilename, |
| 491 | | bForce, pZip, pZipEnt); |
| 492 | | pZipEnt = zip_file_next_file(pZip); |
| 493 | | } |
| 494 | | zip_file_close(pZip); |
| 495 | | } |
| 496 | | } |
| 497 | | else |
| 498 | | { |
| 499 | | rc = SoftwarePicker_AddFileEntry(hwndPicker, pszFilename, 0, 0, bForce); |
| 500 | | } |
| 501 | | return rc; |
| 502 | | } |
| 503 | | |
| 504 | | |
| 505 | | |
| 506 | | BOOL SoftwarePicker_AddFile(HWND hwndPicker, LPCSTR pszFilename) |
| 507 | | { |
| 508 | | char szBuffer[MAX_PATH]; |
| 509 | | |
| 510 | | Picker_ResetIdle(hwndPicker); |
| 511 | | pszFilename = NormalizePath(pszFilename, szBuffer, sizeof(szBuffer) |
| 512 | | / sizeof(szBuffer[0])); |
| 513 | | |
| 514 | | return SoftwarePicker_InternalAddFile(hwndPicker, pszFilename, TRUE); |
| 515 | | } |
| 516 | | |
| 517 | | |
| 518 | | |
| 519 | | BOOL SoftwarePicker_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory) |
| 520 | | { |
| 521 | | software_picker_info *pPickerInfo; |
| 522 | | directory_search_info *pSearchInfo; |
| 523 | | directory_search_info **ppLast; |
| 524 | | size_t nSearchInfoSize; |
| 525 | | char szBuffer[MAX_PATH]; |
| 526 | | |
| 527 | | pszDirectory = NormalizePath(pszDirectory, szBuffer, sizeof(szBuffer) |
| 528 | | / sizeof(szBuffer[0])); |
| 529 | | |
| 530 | | Picker_ResetIdle(hwndPicker); |
| 531 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 532 | | |
| 533 | | nSearchInfoSize = sizeof(directory_search_info) + strlen(pszDirectory); |
| 534 | | pSearchInfo = (directory_search_info *)malloc(nSearchInfoSize); |
| 535 | | if (!pSearchInfo) |
| 536 | | return FALSE; |
| 537 | | memset(pSearchInfo, 0, nSearchInfoSize); |
| 538 | | pSearchInfo->find_handle = INVALID_HANDLE_VALUE; |
| 539 | | |
| 540 | | strcpy(pSearchInfo->directory_name, pszDirectory); |
| 541 | | |
| 542 | | // insert into linked list |
| 543 | | if (pPickerInfo->last_search_info) |
| 544 | | ppLast = &pPickerInfo->last_search_info->next; |
| 545 | | else |
| 546 | | ppLast = &pPickerInfo->first_search_info; |
| 547 | | *ppLast = pSearchInfo; |
| 548 | | pPickerInfo->last_search_info = pSearchInfo; |
| 549 | | return TRUE; |
| 550 | | } |
| 551 | | |
| 552 | | |
| 553 | | |
| 554 | | static void SoftwarePicker_FreeSearchInfo(directory_search_info *pSearchInfo) |
| 555 | | { |
| 556 | | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 557 | | FindClose(pSearchInfo->find_handle); |
| 558 | | free(pSearchInfo); |
| 559 | | } |
| 560 | | |
| 561 | | |
| 562 | | |
| 563 | | static void SoftwarePicker_InternalClear(software_picker_info *pPickerInfo) |
| 564 | | { |
| 565 | | directory_search_info *p; |
| 566 | | int i; |
| 567 | | |
| 568 | | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 569 | | free(pPickerInfo->file_index[i]); |
| 570 | | |
| 571 | | while(pPickerInfo->first_search_info) |
| 572 | | { |
| 573 | | p = pPickerInfo->first_search_info->next; |
| 574 | | SoftwarePicker_FreeSearchInfo(pPickerInfo->first_search_info); |
| 575 | | pPickerInfo->first_search_info = p; |
| 576 | | } |
| 577 | | |
| 578 | | pPickerInfo->file_index = NULL; |
| 579 | | pPickerInfo->file_index_length = 0; |
| 580 | | pPickerInfo->current_position = 0; |
| 581 | | pPickerInfo->last_search_info = NULL; |
| 582 | | } |
| 583 | | |
| 584 | | |
| 585 | | |
| 586 | | void SoftwarePicker_Clear(HWND hwndPicker) |
| 587 | | { |
| 588 | | software_picker_info *pPickerInfo; |
| 589 | | BOOL res; |
| 590 | | |
| 591 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 592 | | SoftwarePicker_InternalClear(pPickerInfo); |
| 593 | | res = ListView_DeleteAllItems(hwndPicker); |
| 594 | | } |
| 595 | | |
| 596 | | |
| 597 | | |
| 598 | | static BOOL SoftwarePicker_AddEntry(HWND hwndPicker, |
| 599 | | directory_search_info *pSearchInfo) |
| 600 | | { |
| 601 | | //software_picker_info *pPickerInfo; |
| 602 | | LPSTR pszFilename; |
| 603 | | BOOL rc; |
| 604 | | char* utf8_FileName; |
| 605 | | |
| 606 | | //pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 607 | | |
| 608 | | utf8_FileName = utf8_from_tstring(pSearchInfo->fd.cFileName); |
| 609 | | if( !utf8_FileName ) |
| 610 | | return FALSE; |
| 611 | | |
| 612 | | if (!strcmp(utf8_FileName, ".") || !strcmp(utf8_FileName, "..")) { |
| 613 | | osd_free(utf8_FileName); |
| 614 | | return TRUE; |
| 615 | | } |
| 616 | | |
| 617 | | pszFilename = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + 1 + strlen(utf8_FileName) + 1); |
| 618 | | strcpy(pszFilename, pSearchInfo->directory_name); |
| 619 | | strcat(pszFilename, "\\"); |
| 620 | | strcat(pszFilename, utf8_FileName); |
| 621 | | |
| 622 | | if (pSearchInfo->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 623 | | rc = SoftwarePicker_AddDirectory(hwndPicker, pszFilename); |
| 624 | | else |
| 625 | | rc = SoftwarePicker_InternalAddFile(hwndPicker, pszFilename, FALSE); |
| 626 | | |
| 627 | | osd_free(utf8_FileName); |
| 628 | | return rc; |
| 629 | | } |
| 630 | | |
| 631 | | |
| 632 | | |
| 633 | | BOOL SoftwarePicker_Idle(HWND hwndPicker) |
| 634 | | { |
| 635 | | software_picker_info *pPickerInfo; |
| 636 | | file_info *pFileInfo; |
| 637 | | static const char szWildcards[] = "\\*.*"; |
| 638 | | directory_search_info *pSearchInfo; |
| 639 | | LPSTR pszFilter; |
| 640 | | BOOL bSuccess; |
| 641 | | int nCount; |
| 642 | | BOOL bDone = FALSE; |
| 643 | | |
| 644 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 645 | | |
| 646 | | pSearchInfo = pPickerInfo->first_search_info; |
| 647 | | |
| 648 | | if (pSearchInfo) |
| 649 | | { |
| 650 | | // searching through directories |
| 651 | | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 652 | | { |
| 653 | | bSuccess = FindNextFile(pSearchInfo->find_handle, &pSearchInfo->fd); |
| 654 | | } |
| 655 | | else |
| 656 | | { |
| 657 | | pszFilter = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + strlen(szWildcards) + 1); |
| 658 | | strcpy(pszFilter, pSearchInfo->directory_name); |
| 659 | | strcat(pszFilter, szWildcards); |
| 660 | | pSearchInfo->find_handle = win_find_first_file_utf8(pszFilter, &pSearchInfo->fd); |
| 661 | | bSuccess = pSearchInfo->find_handle != INVALID_HANDLE_VALUE; |
| 662 | | } |
| 663 | | |
| 664 | | if (bSuccess) |
| 665 | | { |
| 666 | | SoftwarePicker_AddEntry(hwndPicker, pSearchInfo); |
| 667 | | } |
| 668 | | else |
| 669 | | { |
| 670 | | pPickerInfo->first_search_info = pSearchInfo->next; |
| 671 | | if (!pPickerInfo->first_search_info) |
| 672 | | pPickerInfo->last_search_info = NULL; |
| 673 | | SoftwarePicker_FreeSearchInfo(pSearchInfo); |
| 674 | | } |
| 675 | | } |
| 676 | | else if (pPickerInfo->config!=NULL && pPickerInfo->config->hashfile && (pPickerInfo->hashes_realized |
| 677 | | < pPickerInfo->file_index_length)) |
| 678 | | { |
| 679 | | // time to realize some hashes |
| 680 | | nCount = 100; |
| 681 | | |
| 682 | | while((nCount > 0) && pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 683 | | { |
| 684 | | pPickerInfo->current_position++; |
| 685 | | pPickerInfo->current_position %= pPickerInfo->file_index_length; |
| 686 | | nCount--; |
| 687 | | } |
| 688 | | |
| 689 | | pFileInfo = pPickerInfo->file_index[pPickerInfo->current_position]; |
| 690 | | if (!pFileInfo->hash_realized) |
| 691 | | { |
| 692 | | if (hashfile_functions_used(pPickerInfo->config->hashfile, pFileInfo->device->image_type())) |
| 693 | | { |
| 694 | | // only calculate the hash if it is appropriate for this device |
| 695 | | if (!SoftwarePicker_CalculateHash(hwndPicker, pPickerInfo->current_position)) |
| 696 | | return FALSE; |
| 697 | | } |
| 698 | | SoftwarePicker_RealizeHash(hwndPicker, pPickerInfo->current_position); |
| 699 | | |
| 700 | | // under normal circumstances this will be redundant, but in the unlikely |
| 701 | | // event of a failure, we do not want to keep running into a brick wall |
| 702 | | // by calculating this hash over and over |
| 703 | | if (!pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 704 | | { |
| 705 | | pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized = TRUE; |
| 706 | | pPickerInfo->hashes_realized++; |
| 707 | | } |
| 708 | | } |
| 709 | | } |
| 710 | | else |
| 711 | | { |
| 712 | | // we are done! |
| 713 | | bDone = TRUE; |
| 714 | | } |
| 715 | | |
| 716 | | return !bDone; |
| 717 | | } |
| 718 | | |
| 719 | | |
| 720 | | |
| 721 | | LPCTSTR SoftwarePicker_GetItemString(HWND hwndPicker, int nRow, int nColumn, |
| 722 | | TCHAR *pszBuffer, UINT nBufferLength) |
| 723 | | { |
| 724 | | software_picker_info *pPickerInfo; |
| 725 | | const file_info *pFileInfo; |
| 726 | | LPCTSTR s = NULL; |
| 727 | | const char *pszUtf8 = NULL; |
| 728 | | unsigned int nHashFunction = 0; |
| 729 | | char szBuffer[256]; |
| 730 | | TCHAR* t_buf; |
| 731 | | |
| 732 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 733 | | if ((nRow < 0) || (nRow >= pPickerInfo->file_index_length)) |
| 734 | | return NULL; |
| 735 | | |
| 736 | | pFileInfo = pPickerInfo->file_index[nRow]; |
| 737 | | |
| 738 | | switch(nColumn) |
| 739 | | { |
| 740 | | case MESS_COLUMN_IMAGES: |
| 741 | | t_buf = tstring_from_utf8(pFileInfo->base_name); |
| 742 | | if( !t_buf ) |
| 743 | | return s; |
| 744 | | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 745 | | s = pszBuffer; |
| 746 | | osd_free(t_buf); |
| 747 | | break; |
| 748 | | |
| 749 | | case MESS_COLUMN_GOODNAME: |
| 750 | | case MESS_COLUMN_MANUFACTURER: |
| 751 | | case MESS_COLUMN_YEAR: |
| 752 | | case MESS_COLUMN_PLAYABLE: |
| 753 | | if (pFileInfo->hashinfo) |
| 754 | | { |
| 755 | | switch(nColumn) |
| 756 | | { |
| 757 | | case MESS_COLUMN_GOODNAME: |
| 758 | | pszUtf8 = pFileInfo->hashinfo->longname; |
| 759 | | break; |
| 760 | | case MESS_COLUMN_MANUFACTURER: |
| 761 | | pszUtf8 = pFileInfo->hashinfo->manufacturer; |
| 762 | | break; |
| 763 | | case MESS_COLUMN_YEAR: |
| 764 | | pszUtf8 = pFileInfo->hashinfo->year; |
| 765 | | break; |
| 766 | | case MESS_COLUMN_PLAYABLE: |
| 767 | | pszUtf8 = pFileInfo->hashinfo->playable; |
| 768 | | break; |
| 769 | | } |
| 770 | | if (pszUtf8) |
| 771 | | { |
| 772 | | t_buf = tstring_from_utf8(pszUtf8); |
| 773 | | if( !t_buf ) |
| 774 | | return s; |
| 775 | | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 776 | | s = pszBuffer; |
| 777 | | osd_free(t_buf); |
| 778 | | } |
| 779 | | } |
| 780 | | break; |
| 781 | | |
| 782 | | case MESS_COLUMN_CRC: |
| 783 | | case MESS_COLUMN_MD5: |
| 784 | | case MESS_COLUMN_SHA1: |
| 785 | | switch (nColumn) |
| 786 | | { |
| 787 | | case MESS_COLUMN_CRC: nHashFunction = HASH_CRC; break; |
| 788 | | case MESS_COLUMN_MD5: nHashFunction = HASH_MD5; break; |
| 789 | | case MESS_COLUMN_SHA1: nHashFunction = HASH_SHA1; break; |
| 790 | | } |
| 791 | | if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer)) |
| 792 | | { |
| 793 | | t_buf = tstring_from_utf8(szBuffer); |
| 794 | | if( !t_buf ) |
| 795 | | return s; |
| 796 | | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| 797 | | s = pszBuffer; |
| 798 | | osd_free(t_buf); |
| 799 | | } |
| 800 | | break; |
| 801 | | } |
| 802 | | return s; |
| 803 | | } |
| 804 | | |
| 805 | | |
| 806 | | |
| 807 | | static LRESULT CALLBACK SoftwarePicker_WndProc(HWND hwndPicker, UINT nMessage, |
| 808 | | WPARAM wParam, LPARAM lParam) |
| 809 | | { |
| 810 | | software_picker_info *pPickerInfo; |
| 811 | | LRESULT rc; |
| 812 | | |
| 813 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 814 | | rc = CallWindowProc(pPickerInfo->old_window_proc, hwndPicker, nMessage, wParam, lParam); |
| 815 | | |
| 816 | | if (nMessage == WM_DESTROY) |
| 817 | | { |
| 818 | | SoftwarePicker_InternalClear(pPickerInfo); |
| 819 | | SoftwarePicker_SetDriver(hwndPicker, NULL); |
| 820 | | free(pPickerInfo); |
| 821 | | } |
| 822 | | |
| 823 | | return rc; |
| 824 | | } |
| 825 | | |
| 826 | | |
| 827 | | |
| 828 | | BOOL SetupSoftwarePicker(HWND hwndPicker, const struct PickerOptions *pOptions) |
| 829 | | { |
| 830 | | software_picker_info *pPickerInfo = NULL; |
| 831 | | LONG_PTR l; |
| 832 | | |
| 833 | | if (!SetupPicker(hwndPicker, pOptions)) |
| 834 | | goto error; |
| 835 | | |
| 836 | | pPickerInfo = (software_picker_info *)malloc(sizeof(*pPickerInfo)); |
| 837 | | if (!pPickerInfo) |
| 838 | | goto error; |
| 839 | | |
| 840 | | memset(pPickerInfo, 0, sizeof(*pPickerInfo)); |
| 841 | | if (!SetProp(hwndPicker, software_picker_property_name, (HANDLE) pPickerInfo)) |
| 842 | | goto error; |
| 843 | | |
| 844 | | l = (LONG_PTR) SoftwarePicker_WndProc; |
| 845 | | l = SetWindowLongPtr(hwndPicker, GWLP_WNDPROC, l); |
| 846 | | pPickerInfo->old_window_proc = (WNDPROC) l; |
| 847 | | return TRUE; |
| 848 | | |
| 849 | | error: |
| 850 | | if (pPickerInfo) |
| 851 | | free(pPickerInfo); |
| 852 | | return FALSE; |
| 853 | | } |
src/mess/osd/winui/propertiesms.c
| r10258 | r10259 | |
| 1 | | #define WIN32_LEAN_AND_MEAN |
| 2 | | |
| 3 | | #ifndef _MSC_VER |
| 4 | | #define NONAMELESSUNION 1 |
| 5 | | #endif |
| 6 | | |
| 7 | | #include <windows.h> |
| 8 | | #include <string.h> |
| 9 | | #include <assert.h> |
| 10 | | #include <commctrl.h> |
| 11 | | #include <commdlg.h> |
| 12 | | #include <windowsx.h> |
| 13 | | #include <sys/stat.h> |
| 14 | | #include <stdio.h> |
| 15 | | #include <tchar.h> |
| 16 | | |
| 17 | | #include "emu.h" |
| 18 | | #include "emuopts.h" |
| 19 | | #include "image.h" |
| 20 | | #include "screenshot.h" |
| 21 | | #include "datamap.h" |
| 22 | | #include "bitmask.h" |
| 23 | | #include "winui.h" |
| 24 | | #include "directories.h" |
| 25 | | #include "mui_util.h" |
| 26 | | #include "mui_opts.h" |
| 27 | | #include "resourcems.h" |
| 28 | | #include "propertiesms.h" |
| 29 | | #include "optionsms.h" |
| 30 | | #include "msuiutil.h" |
| 31 | | #include "strconv.h" |
| 32 | | #include "winutf8.h" |
| 33 | | #include "machine/ram.h" |
| 34 | | |
| 35 | | static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem); |
| 36 | | static BOOL SoftwareDirectories_OnDelete(HWND hDlg); |
| 37 | | static BOOL SoftwareDirectories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR); |
| 38 | | static BOOL SoftwareDirectories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR); |
| 39 | | |
| 40 | | extern BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult); |
| 41 | | BOOL g_bModifiedSoftwarePaths = FALSE; |
| 42 | | |
| 43 | | |
| 44 | | |
| 45 | | static void MarkChanged(HWND hDlg) |
| 46 | | { |
| 47 | | HWND hCtrl; |
| 48 | | |
| 49 | | /* fake a CBN_SELCHANGE event from IDC_SIZES to force it to be changed */ |
| 50 | | hCtrl = GetDlgItem(hDlg, IDC_SIZES); |
| 51 | | PostMessage(hDlg, WM_COMMAND, (CBN_SELCHANGE << 16) | IDC_SIZES, (LPARAM) hCtrl); |
| 52 | | } |
| 53 | | |
| 54 | | |
| 55 | | |
| 56 | | static void AppendList(HWND hList, LPCTSTR lpItem, int nItem) |
| 57 | | { |
| 58 | | LV_ITEM Item; |
| 59 | | HRESULT res; |
| 60 | | memset(&Item, 0, sizeof(LV_ITEM)); |
| 61 | | Item.mask = LVIF_TEXT; |
| 62 | | Item.pszText = (LPTSTR) lpItem; |
| 63 | | Item.iItem = nItem; |
| 64 | | res = ListView_InsertItem(hList, &Item); |
| 65 | | } |
| 66 | | |
| 67 | | |
| 68 | | |
| 69 | | static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem) |
| 70 | | { |
| 71 | | int nItem; |
| 72 | | TCHAR inbuf[MAX_PATH]; |
| 73 | | TCHAR outbuf[MAX_PATH]; |
| 74 | | HWND hList; |
| 75 | | LPTSTR lpIn; |
| 76 | | BOOL res; |
| 77 | | |
| 78 | | g_bModifiedSoftwarePaths = TRUE; |
| 79 | | |
| 80 | | hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 81 | | nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); |
| 82 | | |
| 83 | | if (nItem == -1) |
| 84 | | return FALSE; |
| 85 | | |
| 86 | | /* Last item is placeholder for append */ |
| 87 | | if (nItem == ListView_GetItemCount(hList) - 1) |
| 88 | | { |
| 89 | | bBrowse = FALSE; |
| 90 | | } |
| 91 | | |
| 92 | | if (!lpItem) { |
| 93 | | if (bBrowse) { |
| 94 | | ListView_GetItemText(hList, nItem, 0, inbuf, ARRAY_LENGTH(inbuf)); |
| 95 | | lpIn = inbuf; |
| 96 | | } |
| 97 | | else { |
| 98 | | lpIn = NULL; |
| 99 | | } |
| 100 | | |
| 101 | | if (!BrowseForDirectory(hDlg, lpIn, outbuf)) |
| 102 | | return FALSE; |
| 103 | | lpItem = outbuf; |
| 104 | | } |
| 105 | | |
| 106 | | AppendList(hList, lpItem, nItem); |
| 107 | | if (bBrowse) |
| 108 | | res = ListView_DeleteItem(hList, nItem+1); |
| 109 | | MarkChanged(hDlg); |
| 110 | | return TRUE; |
| 111 | | } |
| 112 | | |
| 113 | | |
| 114 | | |
| 115 | | static BOOL SoftwareDirectories_OnDelete(HWND hDlg) |
| 116 | | { |
| 117 | | int nCount; |
| 118 | | int nSelect; |
| 119 | | int nItem; |
| 120 | | HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 121 | | BOOL res; |
| 122 | | |
| 123 | | g_bModifiedSoftwarePaths = TRUE; |
| 124 | | |
| 125 | | nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL); |
| 126 | | |
| 127 | | if (nItem == -1) |
| 128 | | return FALSE; |
| 129 | | |
| 130 | | /* Don't delete "Append" placeholder. */ |
| 131 | | if (nItem == ListView_GetItemCount(hList) - 1) |
| 132 | | return FALSE; |
| 133 | | |
| 134 | | res = ListView_DeleteItem(hList, nItem); |
| 135 | | |
| 136 | | nCount = ListView_GetItemCount(hList); |
| 137 | | if (nCount <= 1) |
| 138 | | return FALSE; |
| 139 | | |
| 140 | | /* If the last item was removed, select the item above. */ |
| 141 | | if (nItem == nCount - 1) |
| 142 | | nSelect = nCount - 2; |
| 143 | | else |
| 144 | | nSelect = nItem; |
| 145 | | |
| 146 | | ListView_SetItemState(hList, nSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); |
| 147 | | MarkChanged(hDlg); |
| 148 | | return TRUE; |
| 149 | | } |
| 150 | | |
| 151 | | |
| 152 | | |
| 153 | | static BOOL SoftwareDirectories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR) |
| 154 | | { |
| 155 | | BOOL bResult = FALSE; |
| 156 | | NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; |
| 157 | | LVITEM* pItem = &pDispInfo->item; |
| 158 | | HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); |
| 159 | | |
| 160 | | /* Last item is placeholder for append */ |
| 161 | | if (pItem->iItem == ListView_GetItemCount(hList) - 1) |
| 162 | | { |
| 163 | | HWND hEdit = (HWND) (FPTR) SendMessage(hList, LVM_GETEDITCONTROL, 0, 0); |
| 164 | | win_set_window_text_utf8(hEdit, ""); |
| 165 | | } |
| 166 | | |
| 167 | | return bResult; |
| 168 | | } |
| 169 | | |
| 170 | | |
| 171 | | |
| 172 | | static BOOL SoftwareDirectories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR) |
| 173 | | { |
| 174 | | BOOL bResult = FALSE; |
| 175 | | NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; |
| 176 | | LVITEM* pItem = &pDispInfo->item; |
| 177 | | |
| 178 | | if (pItem->pszText != NULL) |
| 179 | | { |
| 180 | | struct _stat file_stat; |
| 181 | | |
| 182 | | /* Don't allow empty entries. */ |
| 183 | | if (!_tcscmp(pItem->pszText, TEXT(""))) |
| 184 | | { |
| 185 | | return FALSE; |
| 186 | | } |
| 187 | | |
| 188 | | /* Check validity of edited directory. */ |
| 189 | | if (_tstat(pItem->pszText, &file_stat) == 0 |
| 190 | | && (file_stat.st_mode & S_IFDIR)) |
| 191 | | { |
| 192 | | bResult = TRUE; |
| 193 | | } |
| 194 | | else |
| 195 | | { |
| 196 | | if (win_message_box_utf8(NULL, "Directory does not exist, continue anyway?", MAMEUINAME, MB_OKCANCEL) == IDOK) |
| 197 | | bResult = TRUE; |
| 198 | | } |
| 199 | | } |
| 200 | | |
| 201 | | if (bResult == TRUE) |
| 202 | | { |
| 203 | | SoftwareDirectories_OnInsertBrowse(hDlg, TRUE, pItem->pszText); |
| 204 | | } |
| 205 | | |
| 206 | | return bResult; |
| 207 | | } |
| 208 | | |
| 209 | | |
| 210 | | |
| 211 | | BOOL PropSheetFilter_Config(const machine_config *drv, const game_driver *gamedrv) |
| 212 | | { |
| 213 | | return (drv->m_devicelist.first(RAM)!=NULL) || DriverHasDevice(gamedrv, IO_PRINTER); |
| 214 | | } |
| 215 | | |
| 216 | | |
| 217 | | |
| 218 | | INT_PTR CALLBACK GameMessOptionsProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) |
| 219 | | { |
| 220 | | INT_PTR rc = 0; |
| 221 | | BOOL bHandled = FALSE; |
| 222 | | |
| 223 | | switch (Msg) { |
| 224 | | case WM_NOTIFY: |
| 225 | | switch (((NMHDR *) lParam)->code) { |
| 226 | | case LVN_ENDLABELEDIT: |
| 227 | | rc = SoftwareDirectories_OnEndLabelEdit(hDlg, (NMHDR *) lParam); |
| 228 | | bHandled = TRUE; |
| 229 | | break; |
| 230 | | |
| 231 | | case LVN_BEGINLABELEDIT: |
| 232 | | rc = SoftwareDirectories_OnBeginLabelEdit(hDlg, (NMHDR *) lParam); |
| 233 | | bHandled = TRUE; |
| 234 | | break; |
| 235 | | } |
| 236 | | } |
| 237 | | |
| 238 | | if (!bHandled) |
| 239 | | rc = GameOptionsProc(hDlg, Msg, wParam, lParam); |
| 240 | | return rc; |
| 241 | | } |
| 242 | | |
| 243 | | |
| 244 | | |
| 245 | | BOOL MessPropertiesCommand(HWND hWnd, WORD wNotifyCode, WORD wID, BOOL *changed) |
| 246 | | { |
| 247 | | BOOL handled = TRUE; |
| 248 | | |
| 249 | | switch(wID) |
| 250 | | { |
| 251 | | case IDC_DIR_BROWSE: |
| 252 | | if (wNotifyCode == BN_CLICKED) |
| 253 | | *changed = SoftwareDirectories_OnInsertBrowse(hWnd, TRUE, NULL); |
| 254 | | break; |
| 255 | | |
| 256 | | case IDC_DIR_INSERT: |
| 257 | | if (wNotifyCode == BN_CLICKED) |
| 258 | | *changed = SoftwareDirectories_OnInsertBrowse(hWnd, FALSE, NULL); |
| 259 | | break; |
| 260 | | |
| 261 | | case IDC_DIR_DELETE: |
| 262 | | if (wNotifyCode == BN_CLICKED) |
| 263 | | *changed = SoftwareDirectories_OnDelete(hWnd); |
| 264 | | break; |
| 265 | | |
| 266 | | default: |
| 267 | | handled = FALSE; |
| 268 | | break; |
| 269 | | } |
| 270 | | return handled; |
| 271 | | } |
| 272 | | |
| 273 | | |
| 274 | | |
| 275 | | //============================================================ |
| 276 | | // DATAMAP HANDLERS |
| 277 | | //============================================================ |
| 278 | | |
| 279 | | static BOOL DirListReadControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 280 | | { |
| 281 | | int directory_count; |
| 282 | | LV_ITEM lvi; |
| 283 | | TCHAR buffer[2048]; |
| 284 | | char *utf8_dir_list; |
| 285 | | int i, pos, driver_index; |
| 286 | | BOOL res; |
| 287 | | |
| 288 | | // determine the directory count; note that one item is the "< >" entry |
| 289 | | directory_count = ListView_GetItemCount(control); |
| 290 | | if (directory_count > 0) |
| 291 | | directory_count--; |
| 292 | | |
| 293 | | buffer[0] = '\0'; |
| 294 | | pos = 0; |
| 295 | | |
| 296 | | for (i = 0; i < directory_count; i++) |
| 297 | | { |
| 298 | | // append a semicolon, if we're past the first entry |
| 299 | | if (i > 0) |
| 300 | | pos += _sntprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, TEXT(";")); |
| 301 | | |
| 302 | | // retrieve the next entry |
| 303 | | memset(&lvi, '\0', sizeof(lvi)); |
| 304 | | lvi.mask = LVIF_TEXT; |
| 305 | | lvi.iItem = i; |
| 306 | | lvi.pszText = &buffer[pos]; |
| 307 | | lvi.cchTextMax = ARRAY_LENGTH(buffer) - pos; |
| 308 | | res = ListView_GetItem(control, &lvi); |
| 309 | | |
| 310 | | // advance the position |
| 311 | | pos += _tcslen(&buffer[pos]); |
| 312 | | } |
| 313 | | |
| 314 | | utf8_dir_list = utf8_from_tstring(buffer); |
| 315 | | if (utf8_dir_list != NULL) |
| 316 | | { |
| 317 | | driver_index = PropertiesCurrentGame(dialog); |
| 318 | | SetExtraSoftwarePaths(driver_index, utf8_dir_list); |
| 319 | | osd_free(utf8_dir_list); |
| 320 | | } |
| 321 | | return TRUE; |
| 322 | | } |
| 323 | | |
| 324 | | |
| 325 | | |
| 326 | | static BOOL DirListPopulateControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 327 | | { |
| 328 | | int driver_index, pos, new_pos, current_item; |
| 329 | | const char *dir_list; |
| 330 | | TCHAR *t_dir_list; |
| 331 | | TCHAR *s; |
| 332 | | LV_COLUMN lvc; |
| 333 | | RECT r; |
| 334 | | HRESULT res; |
| 335 | | BOOL b_res; |
| 336 | | |
| 337 | | // access the directory list, and convert to TCHARs |
| 338 | | driver_index = PropertiesCurrentGame(dialog); |
| 339 | | dir_list = GetExtraSoftwarePaths(driver_index); |
| 340 | | t_dir_list = tstring_from_utf8(dir_list); |
| 341 | | if (!t_dir_list) |
| 342 | | return FALSE; |
| 343 | | |
| 344 | | // delete all items in the list control |
| 345 | | b_res = ListView_DeleteAllItems(control); |
| 346 | | |
| 347 | | // add the column |
| 348 | | GetClientRect(control, &r); |
| 349 | | memset(&lvc, 0, sizeof(LVCOLUMN)); |
| 350 | | lvc.mask = LVCF_WIDTH; |
| 351 | | lvc.cx = r.right - r.left - GetSystemMetrics(SM_CXHSCROLL); |
| 352 | | res = ListView_InsertColumn(control, 0, &lvc); |
| 353 | | |
| 354 | | // add each of the directories |
| 355 | | pos = 0; |
| 356 | | current_item = 0; |
| 357 | | while(t_dir_list[pos] != '\0') |
| 358 | | { |
| 359 | | // parse off this item |
| 360 | | s = _tcschr(&t_dir_list[pos], ';'); |
| 361 | | if (s != NULL) |
| 362 | | { |
| 363 | | *s = '\0'; |
| 364 | | new_pos = s - t_dir_list + 1; |
| 365 | | } |
| 366 | | else |
| 367 | | { |
| 368 | | new_pos = pos + _tcslen(&t_dir_list[pos]); |
| 369 | | } |
| 370 | | |
| 371 | | // append this item |
| 372 | | AppendList(control, &t_dir_list[pos], current_item); |
| 373 | | |
| 374 | | // advance to next item |
| 375 | | pos = new_pos; |
| 376 | | current_item++; |
| 377 | | } |
| 378 | | |
| 379 | | // finish up |
| 380 | | AppendList(control, TEXT(DIRLIST_NEWENTRYTEXT), current_item); |
| 381 | | ListView_SetItemState(control, 0, LVIS_SELECTED, LVIS_SELECTED); |
| 382 | | osd_free(t_dir_list); |
| 383 | | return TRUE; |
| 384 | | } |
| 385 | | |
| 386 | | |
| 387 | | |
| 388 | | static BOOL RamPopulateControl(datamap *map, HWND dialog, HWND control, core_options *opts, const char *option_name) |
| 389 | | { |
| 390 | | int i, current_index, driver_index; |
| 391 | | const game_driver *gamedrv; |
| 392 | | UINT32 ram, current_ram; |
| 393 | | const char *this_ram_string; |
| 394 | | TCHAR* t_ramstring; |
| 395 | | const device_config *device; |
| 396 | | |
| 397 | | // identify the driver |
| 398 | | driver_index = PropertiesCurrentGame(dialog); |
| 399 | | gamedrv = drivers[driver_index]; |
| 400 | | |
| 401 | | // clear out the combo box |
| 402 | | (void)ComboBox_ResetContent(control); |
| 403 | | |
| 404 | | // allocate the machine config |
| 405 | | machine_config cfg(*gamedrv); |
| 406 | | |
| 407 | | // identify how many options that we have |
| 408 | | device = cfg.m_devicelist.first(RAM); |
| 409 | | |
| 410 | | EnableWindow(control, (device != NULL)); |
| 411 | | i = 0; |
| 412 | | // we can only do something meaningful if there is more than one option |
| 413 | | if (device != NULL) |
| 414 | | { |
| 415 | | ram_config *config = (ram_config *)downcast<const legacy_device_config_base *>(device)->inline_config(); |
| 416 | | |
| 417 | | // identify the current amount of RAM |
| 418 | | this_ram_string = options_get_string(opts, OPTION_RAMSIZE); |
| 419 | | current_ram = (this_ram_string != NULL) ? ram_parse_string(this_ram_string) : 0; |
| 420 | | if (current_ram == 0) |
| 421 | | current_ram = ram_parse_string(config->default_size); |
| 422 | | |
| 423 | | // by default, assume index 0 |
| 424 | | current_index = 0; |
| 425 | | |
| 426 | | { |
| 427 | | ram = ram_parse_string(config->default_size); |
| 428 | | t_ramstring = tstring_from_utf8(config->default_size); |
| 429 | | if( !t_ramstring ) |
| 430 | | return FALSE; |
| 431 | | |
| 432 | | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 433 | | (void)ComboBox_SetItemData(control, i, ram); |
| 434 | | |
| 435 | | osd_free(t_ramstring); |
| 436 | | } |
| 437 | | if (config->extra_options != NULL) |
| 438 | | { |
| 439 | | int j; |
| 440 | | int size = strlen(config->extra_options); |
| 441 | | char * const s = mame_strdup(config->extra_options); |
| 442 | | char * const e = s + size; |
| 443 | | char *p = s; |
| 444 | | for (j=0;j<size;j++) { |
| 445 | | if (p[j]==',') p[j]=0; |
| 446 | | } |
| 447 | | |
| 448 | | /* try to parse each option */ |
| 449 | | while(p <= e) |
| 450 | | { |
| 451 | | i++; |
| 452 | | // identify this option |
| 453 | | ram = ram_parse_string(p); |
| 454 | | |
| 455 | | this_ram_string = p; |
| 456 | | |
| 457 | | t_ramstring = tstring_from_utf8(this_ram_string); |
| 458 | | if( !t_ramstring ) |
| 459 | | return FALSE; |
| 460 | | |
| 461 | | // add this option to the combo box |
| 462 | | (void)ComboBox_InsertString(control, i, win_tstring_strdup(t_ramstring)); |
| 463 | | (void)ComboBox_SetItemData(control, i, ram); |
| 464 | | |
| 465 | | osd_free(t_ramstring); |
| 466 | | |
| 467 | | // is this the current option? record the index if so |
| 468 | | if (ram == current_ram) |
| 469 | | current_index = i; |
| 470 | | |
| 471 | | p+= strlen(p); |
| 472 | | if (p == e) |
| 473 | | break; |
| 474 | | |
| 475 | | p += 1; |
| 476 | | } |
| 477 | | |
| 478 | | osd_free(s); |
| 479 | | } |
| 480 | | |
| 481 | | // set the combo box |
| 482 | | (void)ComboBox_SetCurSel(control, current_index); |
| 483 | | } |
| 484 | | return TRUE; |
| 485 | | } |
| 486 | | |
| 487 | | |
| 488 | | |
| 489 | | //============================================================ |
| 490 | | // DATAMAP SETUP |
| 491 | | //============================================================ |
| 492 | | |
| 493 | | void MessBuildDataMap(datamap *properties_datamap) |
| 494 | | { |
| 495 | | // MESS specific stuff |
| 496 | | datamap_add(properties_datamap, IDC_DIR_LIST, DM_STRING, NULL); |
| 497 | | datamap_add(properties_datamap, IDC_RAM_COMBOBOX, DM_INT, OPTION_RAMSIZE); |
| 498 | | // datamap_add(properties_datamap, IDC_USE_NEW_UI, DM_BOOL, "newui"); |
| 499 | | |
| 500 | | // set up callbacks |
| 501 | | datamap_set_callback(properties_datamap, IDC_DIR_LIST, DCT_READ_CONTROL, DirListReadControl); |
| 502 | | datamap_set_callback(properties_datamap, IDC_DIR_LIST, DCT_POPULATE_CONTROL, DirListPopulateControl); |
| 503 | | datamap_set_callback(properties_datamap, IDC_RAM_COMBOBOX, DCT_POPULATE_CONTROL, RamPopulateControl); |
| 504 | | } |