src/mess/osd/winui/messui.c
| r2257 | r2258 | |
| 62 | 62 | |
| 63 | 63 | static int *mess_icon_index; |
| 64 | 64 | |
| 65 | | static void MessOpenOtherSoftware(int iDevice); |
| 66 | | static void MessCreateDevice(int iDevice); |
| 65 | static void MessOpenOtherSoftware(const device_config *dev); |
| 66 | static void MessCreateDevice(const device_config *dev); |
| 67 | 67 | static void MessRefreshPicker(int drvindex); |
| 68 | 68 | |
| 69 | 69 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem); |
| 70 | 70 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem); |
| 71 | 71 | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem); |
| 72 | 72 | |
| 73 | | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const struct IODevice *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 74 | | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const struct IODevice *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 75 | | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const struct IODevice *dev, int nID, LPCTSTR pszFilename); |
| 76 | | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const struct IODevice *dev, int nID, LPTSTR pszBuffer, UINT nBufferLength); |
| 73 | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 74 | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 75 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const device_config *dev, LPCTSTR pszFilename); |
| 76 | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const device_config *dev, LPTSTR pszBuffer, UINT nBufferLength); |
| 77 | 77 | |
| 78 | 78 | #ifdef MAME_DEBUG |
| 79 | 79 | static void MessTestsBegin(void); |
| r2257 | r2258 | |
| 439 | 439 | |
| 440 | 440 | |
| 441 | 441 | // Places the specified image in the specified slot; nID = -1 means don't matter |
| 442 | | static void MessSpecifyImage(int drvindex, const mess_device_class *devclass, int nID, LPCSTR pszFilename) |
| 442 | static void MessSpecifyImage(int drvindex, const device_config *device, LPCSTR pszFilename) |
| 443 | 443 | { |
| 444 | 444 | machine_config *config; |
| 445 | | const device_config *dev; |
| 446 | | const struct IODevice *iodev = NULL; |
| 447 | 445 | const char *s; |
| 448 | 446 | |
| 447 | if (LOG_SOFTWARE) |
| 448 | dprintf("MessSpecifyImage(): device=%p pszFilename='%s'\n", device, pszFilename); |
| 449 | |
| 449 | 450 | // allocate the machine config |
| 450 | 451 | config = machine_config_alloc_with_mess_devices(drivers[drvindex]); |
| 451 | 452 | |
| 452 | | for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev)) |
| 453 | // if device is NULL, this is a special case; try to find existing image |
| 454 | if (device == NULL) |
| 453 | 455 | { |
| 454 | | iodev = mess_device_from_core_device(dev); |
| 455 | | |
| 456 | | if (iodev->devclass.get_info == devclass->get_info) |
| 457 | | break; |
| 456 | for (device = image_device_first(config); device != NULL; device = image_device_next(device)) |
| 457 | { |
| 458 | s = GetSelectedSoftware(drvindex, device); |
| 459 | if ((s != NULL) && !mame_stricmp(s, pszFilename)) |
| 460 | break; |
| 461 | } |
| 458 | 462 | } |
| 459 | 463 | |
| 460 | | if (LOG_SOFTWARE) |
| 464 | // still not found? find an image using the same file extension |
| 465 | if (device == NULL) |
| 461 | 466 | { |
| 462 | | dprintf("MessSpecifyImage(): nID=%d pszFilename='%s'\n", nID, pszFilename); |
| 463 | | } |
| 467 | const char *file_extension; |
| 464 | 468 | |
| 465 | | if (nID < 0) |
| 466 | | { |
| 467 | | // special case; first try to find existing image |
| 468 | | s = GetSelectedSoftware(drvindex, dev); |
| 469 | | if (s && !mame_stricmp(s, pszFilename)) |
| 469 | // identify the file extension |
| 470 | file_extension = strrchr(pszFilename, '.'); |
| 471 | file_extension = file_extension ? file_extension + 1 : NULL; |
| 472 | |
| 473 | if (file_extension != NULL) |
| 470 | 474 | { |
| 471 | | nID = iodev->index_in_device; |
| 475 | for (device = image_device_first(config); device != NULL; device = image_device_next(device)) |
| 476 | { |
| 477 | const struct IODevice *iodev = mess_device_from_core_device(device); |
| 478 | const char *s = iodev->file_extensions; |
| 479 | if (s != NULL) |
| 480 | { |
| 481 | while(*s != '\0') |
| 482 | { |
| 483 | if (!mame_stricmp(s, file_extension)) |
| 484 | break; |
| 485 | } |
| 486 | |
| 487 | if (*s != '\0') |
| 488 | break; |
| 489 | } |
| 490 | } |
| 472 | 491 | } |
| 473 | 492 | } |
| 474 | 493 | |
| 475 | | if (nID < 0) |
| 494 | if (device != NULL) |
| 476 | 495 | { |
| 477 | | // still not found? locate an empty slot |
| 478 | | s = GetSelectedSoftware(drvindex, dev); |
| 479 | | if (!s || !*s || !mame_stricmp(s, pszFilename)) |
| 480 | | { |
| 481 | | nID = iodev->index_in_device; |
| 482 | | } |
| 496 | // place the image |
| 497 | InternalSetSelectedSoftware(drvindex, device, pszFilename); |
| 483 | 498 | } |
| 499 | else |
| 500 | { |
| 501 | // could not place the image |
| 502 | if (LOG_SOFTWARE) |
| 503 | dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename); |
| 504 | } |
| 484 | 505 | |
| 485 | | if (nID >= 0) |
| 486 | | InternalSetSelectedSoftware(drvindex, dev, pszFilename); |
| 487 | | else if (LOG_SOFTWARE) |
| 488 | | dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename); |
| 489 | | |
| 490 | 506 | machine_config_free(config); |
| 491 | 507 | } |
| 492 | 508 | |
| r2257 | r2258 | |
| 518 | 534 | { |
| 519 | 535 | if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, dev))) |
| 520 | 536 | { |
| 521 | | MessSpecifyImage(drvindex, &devclass, iodev->index_in_device, NULL); |
| 537 | MessSpecifyImage(drvindex, dev, NULL); |
| 522 | 538 | } |
| 523 | 539 | } |
| 524 | 540 | |
| r2257 | r2258 | |
| 738 | 754 | |
| 739 | 755 | |
| 740 | 756 | /* Specify IO_COUNT for type if you want all types */ |
| 741 | | static void SetupImageTypes(const machine_config *config, mess_image_type *types, int count, BOOL bZip, int type) |
| 757 | static void SetupImageTypes(const machine_config *config, mess_image_type *types, int count, BOOL bZip, const device_config *dev) |
| 742 | 758 | { |
| 743 | 759 | int num_extensions = 0; |
| 744 | | const device_config *dev; |
| 745 | | const struct IODevice *iodev; |
| 760 | ; |
| 746 | 761 | |
| 747 | 762 | memset(types, 0, sizeof(*types) * count); |
| 748 | 763 | count--; |
| 749 | 764 | |
| 750 | 765 | if (bZip) |
| 751 | 766 | { |
| 767 | /* add the ZIP extension */ |
| 752 | 768 | types[num_extensions].ext = "zip"; |
| 753 | 769 | types[num_extensions].dev = NULL; |
| 754 | 770 | num_extensions++; |
| 755 | 771 | } |
| 756 | 772 | |
| 757 | | for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev)) |
| 773 | if (dev == NULL) |
| 758 | 774 | { |
| 759 | | iodev = mess_device_from_core_device(dev); |
| 775 | /* special case; all non-printer devices */ |
| 776 | for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev)) |
| 777 | { |
| 778 | const struct IODevice *iodev = mess_device_from_core_device(dev); |
| 760 | 779 | |
| 761 | | if (iodev->type != IO_PRINTER) |
| 780 | if (iodev->type != IO_PRINTER) |
| 781 | SetupImageTypes(config, &types[num_extensions], count - num_extensions, FALSE, dev); |
| 782 | } |
| 783 | |
| 784 | } |
| 785 | else |
| 786 | { |
| 787 | const struct IODevice *iodev = mess_device_from_core_device(dev); |
| 788 | const char *ext = iodev->file_extensions; |
| 789 | |
| 790 | if (ext != NULL) |
| 762 | 791 | { |
| 763 | | const char *ext = iodev->file_extensions; |
| 764 | | if (ext != NULL) |
| 792 | while(*ext != '\0') |
| 765 | 793 | { |
| 766 | | while(*ext != '\0') |
| 794 | if (num_extensions < count) |
| 767 | 795 | { |
| 768 | | if ((type == IO_COUNT) || (type == iodev->type)) |
| 769 | | { |
| 770 | | if (num_extensions < count) |
| 771 | | { |
| 772 | | types[num_extensions].dev = iodev; |
| 773 | | types[num_extensions].ext = ext; |
| 774 | | num_extensions++; |
| 775 | | } |
| 776 | | } |
| 777 | | ext += strlen(ext) + 1; |
| 796 | types[num_extensions].dev = iodev; |
| 797 | types[num_extensions].ext = ext; |
| 798 | num_extensions++; |
| 778 | 799 | } |
| 779 | 800 | } |
| 801 | ext += strlen(ext) + 1; |
| 780 | 802 | } |
| 781 | 803 | } |
| 782 | 804 | } |
| 783 | 805 | |
| 784 | 806 | |
| 785 | 807 | |
| 786 | | static void MessSetupDevice(common_file_dialog_proc cfd, int iDevice) |
| 808 | static void MessSetupDevice(common_file_dialog_proc cfd, const device_config *dev) |
| 787 | 809 | { |
| 788 | 810 | TCHAR filename[MAX_PATH]; |
| 789 | 811 | mess_image_type imagetypes[64]; |
| r2257 | r2258 | |
| 800 | 822 | // allocate the machine config |
| 801 | 823 | config = machine_config_alloc_with_mess_devices(drivers[drvindex]); |
| 802 | 824 | |
| 803 | | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, iDevice); |
| 825 | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev); |
| 804 | 826 | |
| 805 | 827 | if (CommonFileImageDialog(last_directory, cfd, filename, imagetypes)) |
| 806 | 828 | { |
| r2257 | r2258 | |
| 817 | 839 | |
| 818 | 840 | |
| 819 | 841 | |
| 820 | | static void MessOpenOtherSoftware(int iDevice) |
| 842 | static void MessOpenOtherSoftware(const device_config *dev) |
| 821 | 843 | { |
| 822 | | MessSetupDevice(GetOpenFileName, iDevice); |
| 844 | MessSetupDevice(GetOpenFileName, dev); |
| 823 | 845 | } |
| 824 | 846 | |
| 825 | 847 | |
| 826 | 848 | |
| 827 | | static void MessCreateDevice(int iDevice) |
| 849 | static void MessCreateDevice(const device_config *dev) |
| 828 | 850 | { |
| 829 | | MessSetupDevice(GetSaveFileName, iDevice); |
| 851 | MessSetupDevice(GetSaveFileName, dev); |
| 830 | 852 | } |
| 831 | 853 | |
| 832 | 854 | |
| 833 | 855 | |
| 834 | | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const struct IODevice *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 856 | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 835 | 857 | { |
| 836 | 858 | BOOL bResult; |
| 837 | 859 | mess_image_type imagetypes[64]; |
| r2257 | r2258 | |
| 845 | 867 | // allocate the machine config |
| 846 | 868 | config = machine_config_alloc_with_mess_devices(drivers[gamenum]); |
| 847 | 869 | |
| 848 | | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type); |
| 870 | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev); |
| 849 | 871 | bResult = CommonFileImageDialog(last_directory, GetOpenFileName, pszFilename, imagetypes); |
| 850 | 872 | |
| 851 | 873 | machine_config_free(config); |
| r2257 | r2258 | |
| 854 | 876 | |
| 855 | 877 | |
| 856 | 878 | |
| 857 | | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const struct IODevice *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 879 | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength) |
| 858 | 880 | { |
| 859 | 881 | BOOL bResult; |
| 860 | 882 | mess_image_type imagetypes[64]; |
| r2257 | r2258 | |
| 868 | 890 | // allocate the machine config |
| 869 | 891 | config = machine_config_alloc_with_mess_devices(drivers[gamenum]); |
| 870 | 892 | |
| 871 | | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type); |
| 893 | SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev); |
| 872 | 894 | bResult = CommonFileImageDialog(last_directory, GetSaveFileName, pszFilename, imagetypes); |
| 873 | 895 | |
| 874 | 896 | machine_config_free(config); |
| r2257 | r2258 | |
| 878 | 900 | |
| 879 | 901 | |
| 880 | 902 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int drvindex, |
| 881 | | const struct IODevice *dev, int nID, LPCTSTR pszFilename) |
| 903 | const device_config *dev, LPCTSTR pszFilename) |
| 882 | 904 | { |
| 883 | 905 | char* utf8_filename = utf8_from_tstring(pszFilename); |
| 884 | 906 | if( !utf8_filename ) |
| 885 | 907 | return; |
| 886 | | MessSpecifyImage(drvindex, &dev->devclass, nID, utf8_filename); |
| 908 | MessSpecifyImage(drvindex, dev, utf8_filename); |
| 887 | 909 | MessRefreshPicker(drvindex); |
| 888 | 910 | free(utf8_filename); |
| 889 | 911 | } |
| r2257 | r2258 | |
| 891 | 913 | |
| 892 | 914 | |
| 893 | 915 | static LPCTSTR DevView_GetSelectedSoftware(HWND hwndDevView, int nDriverIndex, |
| 894 | | const struct IODevice *dev, int nID, LPTSTR pszBuffer, UINT nBufferLength) |
| 916 | const device_config *dev, LPTSTR pszBuffer, UINT nBufferLength) |
| 895 | 917 | { |
| 896 | 918 | LPCTSTR t_buffer = NULL; |
| 897 | 919 | TCHAR* t_s; |
| 898 | | LPCSTR s = GetSelectedSoftware(nDriverIndex, dev->devconfig); |
| 920 | LPCSTR s = GetSelectedSoftware(nDriverIndex, dev); |
| 899 | 921 | |
| 900 | 922 | t_s = tstring_from_utf8(s); |
| 901 | 923 | if( !t_s ) |
| r2257 | r2258 | |
| 1004 | 1026 | devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 1005 | 1027 | if (!devclass.gamedrv) |
| 1006 | 1028 | return; |
| 1007 | | MessSpecifyImage(drvindex, &devclass, -1, pszFullName); |
| 1029 | MessSpecifyImage(drvindex, NULL, pszFullName); |
| 1008 | 1030 | |
| 1009 | 1031 | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1010 | 1032 | strncpyz(g_szSelectedItem, pszName, sizeof(g_szSelectedItem) / sizeof(g_szSelectedItem[0])); |
| r2257 | r2258 | |
| 1137 | 1159 | |
| 1138 | 1160 | BOOL MessCommand(HWND hwnd,int id, HWND hwndCtl, UINT codeNotify) |
| 1139 | 1161 | { |
| 1140 | | switch (id) { |
| 1141 | | case ID_MESS_OPEN_SOFTWARE: |
| 1142 | | MessOpenOtherSoftware(IO_COUNT); |
| 1143 | | break; |
| 1162 | switch (id) |
| 1163 | { |
| 1164 | case ID_MESS_OPEN_SOFTWARE: |
| 1165 | MessOpenOtherSoftware(NULL); |
| 1166 | break; |
| 1144 | 1167 | |
| 1145 | | case ID_MESS_CREATE_SOFTWARE: |
| 1146 | | MessCreateDevice(IO_COUNT); |
| 1147 | | break; |
| 1168 | case ID_MESS_CREATE_SOFTWARE: |
| 1169 | MessCreateDevice(NULL); |
| 1170 | break; |
| 1148 | 1171 | |
| 1149 | 1172 | #ifdef MAME_DEBUG |
| 1150 | | case ID_MESS_RUN_TESTS: |
| 1151 | | MessTestsBegin(); |
| 1152 | | break; |
| 1173 | case ID_MESS_RUN_TESTS: |
| 1174 | MessTestsBegin(); |
| 1175 | break; |
| 1153 | 1176 | #endif /* MAME_DEBUG */ |
| 1154 | 1177 | } |
| 1155 | 1178 | return FALSE; |