src/emu/softlist.c
| r11093 | r11094 | |
| 13 | 13 | #include "emuopts.h" |
| 14 | 14 | #include "hash.h" |
| 15 | 15 | #include "softlist.h" |
| 16 | #include "ui.h" |
| 16 | 17 | |
| 17 | 18 | #include <ctype.h> |
| 18 | 19 | |
| r11093 | r11094 | |
| 1865 | 1866 | char *list_name; /* currently selected list */ |
| 1866 | 1867 | device_image_interface* image; |
| 1867 | 1868 | software_entry_state *entrylist; |
| 1869 | char filename_buffer[1024]; |
| 1868 | 1870 | }; |
| 1869 | 1871 | |
| 1870 | 1872 | /* state of a software part */ |
| r11093 | r11094 | |
| 2041 | 2043 | { |
| 2042 | 2044 | const ui_menu_event *event; |
| 2043 | 2045 | software_menu_state *sw_state = (software_menu_state *)state; |
| 2044 | | |
| 2046 | const software_entry_state *entry; |
| 2047 | const software_entry_state *selected_entry = NULL; |
| 2048 | int bestmatch = 0; |
| 2049 | |
| 2045 | 2050 | if (!ui_menu_populated(menu)) |
| 2046 | 2051 | { |
| 2047 | 2052 | if (sw_state->list_name) |
| r11093 | r11094 | |
| 2053 | 2058 | /* process the menu */ |
| 2054 | 2059 | event = ui_menu_process(machine, menu, 0); |
| 2055 | 2060 | |
| 2056 | | if (event != NULL && event->iptkey == IPT_UI_SELECT && event->itemref != NULL) |
| 2061 | if (event != NULL && event->itemref != NULL) |
| 2057 | 2062 | { |
| 2058 | | device_image_interface *image = sw_state->image; |
| 2059 | | software_entry_state *entry = (software_entry_state *) event->itemref; |
| 2060 | | software_list *tmp_list = software_list_open(machine.options(), sw_state->list_name, FALSE, NULL); |
| 2061 | | software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL); |
| 2062 | | |
| 2063 | | // if the selected software has multiple parts that can be loaded, open the submenu |
| 2064 | | if (swinfo_has_multiple_parts(tmp_info, image->image_config().image_interface())) |
| 2063 | /* handle selections */ |
| 2064 | if (event->iptkey == IPT_UI_SELECT) |
| 2065 | 2065 | { |
| 2066 | | ui_menu *child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), ui_mess_menu_software_parts, entry); |
| 2067 | | software_entry_state *child_menustate = (software_entry_state *)ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL); |
| 2068 | | child_menustate->short_name = entry->short_name; |
| 2069 | | child_menustate->interface = image->image_config().image_interface(); |
| 2070 | | child_menustate->list_name = sw_state->list_name; |
| 2071 | | child_menustate->image = image; |
| 2072 | | ui_menu_stack_push(child_menu); |
| 2066 | device_image_interface *image = sw_state->image; |
| 2067 | software_entry_state *entry = (software_entry_state *) event->itemref; |
| 2068 | software_list *tmp_list = software_list_open(machine.options(), sw_state->list_name, FALSE, NULL); |
| 2069 | software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL); |
| 2070 | |
| 2071 | // if the selected software has multiple parts that can be loaded, open the submenu |
| 2072 | if (swinfo_has_multiple_parts(tmp_info, image->image_config().image_interface())) |
| 2073 | { |
| 2074 | ui_menu *child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), ui_mess_menu_software_parts, entry); |
| 2075 | software_entry_state *child_menustate = (software_entry_state *)ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL); |
| 2076 | child_menustate->short_name = entry->short_name; |
| 2077 | child_menustate->interface = image->image_config().image_interface(); |
| 2078 | child_menustate->list_name = sw_state->list_name; |
| 2079 | child_menustate->image = image; |
| 2080 | ui_menu_stack_push(child_menu); |
| 2081 | } |
| 2082 | else |
| 2083 | { |
| 2084 | // otherwise, load the file |
| 2085 | if (image != NULL) |
| 2086 | image->load(entry->short_name); |
| 2087 | else |
| 2088 | popmessage("No matching device found for interface '%s'!", entry->interface); |
| 2089 | } |
| 2090 | software_list_close(tmp_list); |
| 2091 | |
| 2092 | // reset the char buffer when pressing IPT_UI_SELECT |
| 2093 | if (sw_state->filename_buffer[0] != '\0') |
| 2094 | memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer)); |
| 2073 | 2095 | } |
| 2074 | | else |
| 2096 | else if (event->iptkey == IPT_SPECIAL) |
| 2075 | 2097 | { |
| 2076 | | // otherwise, load the file |
| 2077 | | if (image != NULL) |
| 2078 | | image->load(entry->short_name); |
| 2079 | | else |
| 2080 | | popmessage("No matching device found for interface '%s'!", entry->interface); |
| 2098 | int buflen = strlen(sw_state->filename_buffer); |
| 2099 | bool update_selected = FALSE; |
| 2100 | |
| 2101 | /* if it's a backspace and we can handle it, do so */ |
| 2102 | if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0) |
| 2103 | { |
| 2104 | *(char *)utf8_previous_char(&sw_state->filename_buffer[buflen]) = 0; |
| 2105 | update_selected = TRUE; |
| 2106 | |
| 2107 | if (ARRAY_LENGTH(sw_state->filename_buffer) > 0) |
| 2108 | ui_popup_time(5, "%s", sw_state->filename_buffer); |
| 2109 | } |
| 2110 | /* if it's any other key and we're not maxed out, update */ |
| 2111 | else if (event->unichar >= ' ' && event->unichar < 0x7f) |
| 2112 | { |
| 2113 | buflen += utf8_from_uchar(&sw_state->filename_buffer[buflen], ARRAY_LENGTH(sw_state->filename_buffer) - buflen, event->unichar); |
| 2114 | sw_state->filename_buffer[buflen] = 0; |
| 2115 | update_selected = TRUE; |
| 2116 | |
| 2117 | if (ARRAY_LENGTH(sw_state->filename_buffer) > 0) |
| 2118 | ui_popup_time(5, "%s", sw_state->filename_buffer); |
| 2119 | } |
| 2120 | |
| 2121 | if (update_selected) |
| 2122 | { |
| 2123 | const software_entry_state *cur_selected = (const software_entry_state *)ui_menu_get_selection(menu); |
| 2124 | |
| 2125 | // check for entries which matches our filename_buffer: |
| 2126 | // from current entry to the end |
| 2127 | for (entry = cur_selected; entry != NULL; entry = entry->next) |
| 2128 | { |
| 2129 | if (entry->short_name != NULL && sw_state->filename_buffer != NULL) |
| 2130 | { |
| 2131 | int match = 0; |
| 2132 | for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++) |
| 2133 | { |
| 2134 | if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0) |
| 2135 | match = i; |
| 2136 | } |
| 2137 | |
| 2138 | if (match > bestmatch) |
| 2139 | { |
| 2140 | bestmatch = match; |
| 2141 | selected_entry = entry; |
| 2142 | } |
| 2143 | } |
| 2144 | } |
| 2145 | // and from the first entry to current one |
| 2146 | for (entry = sw_state->entrylist; entry != cur_selected; entry = entry->next) |
| 2147 | { |
| 2148 | if (entry->short_name != NULL && sw_state->filename_buffer != NULL) |
| 2149 | { |
| 2150 | int match = 0; |
| 2151 | for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++) |
| 2152 | { |
| 2153 | if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0) |
| 2154 | match = i; |
| 2155 | } |
| 2156 | |
| 2157 | if (match > bestmatch) |
| 2158 | { |
| 2159 | bestmatch = match; |
| 2160 | selected_entry = entry; |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | if (selected_entry != NULL && selected_entry != cur_selected) |
| 2166 | ui_menu_set_selection(menu, (void *) selected_entry); |
| 2167 | } |
| 2081 | 2168 | } |
| 2082 | | software_list_close(tmp_list); |
| 2083 | 2169 | } |
| 2084 | 2170 | } |
| 2085 | 2171 | |