src/emu/uiswlist.c
| r11100 | r11101 | |
| 48 | 48 | device_image_interface* image; |
| 49 | 49 | software_entry_state *entrylist; |
| 50 | 50 | char filename_buffer[1024]; |
| 51 | int ordered_by_shortname; |
| 52 | int reorder; |
| 51 | 53 | }; |
| 52 | 54 | |
| 53 | 55 | /* state of a software part */ |
| r11100 | r11101 | |
| 128 | 130 | } |
| 129 | 131 | } |
| 130 | 132 | |
| 131 | | static int compare_software_entries(const software_entry_state *e1, const software_entry_state *e2) |
| 133 | static int compare_software_entries(const software_entry_state *e1, const software_entry_state *e2, int shortname) |
| 132 | 134 | { |
| 133 | 135 | int result; |
| 134 | | const char *e1_basename = (e1->short_name != NULL) ? e1->short_name : ""; |
| 135 | | const char *e2_basename = (e2->short_name != NULL) ? e2->short_name : ""; |
| 136 | const char *e1_basename; |
| 137 | const char *e2_basename; |
| 138 | |
| 139 | if (shortname) |
| 140 | { |
| 141 | e1_basename = (e1->short_name != NULL) ? e1->short_name : ""; |
| 142 | e2_basename = (e2->short_name != NULL) ? e2->short_name : ""; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | e1_basename = (e1->long_name != NULL) ? e1->long_name : ""; |
| 147 | e2_basename = (e2->long_name != NULL) ? e2->long_name : ""; |
| 148 | } |
| 136 | 149 | |
| 137 | 150 | result = mame_stricmp(e1_basename, e2_basename); |
| 138 | 151 | if (result == 0) |
| r11100 | r11101 | |
| 179 | 192 | |
| 180 | 193 | // find the end of the list |
| 181 | 194 | entryptr = &menustate->entrylist; |
| 182 | | while ((*entryptr != NULL) && (compare_software_entries(entry, *entryptr) >= 0)) |
| 195 | while ((*entryptr != NULL) && (compare_software_entries(entry, *entryptr, menustate->ordered_by_shortname) >= 0)) |
| 183 | 196 | entryptr = &(*entryptr)->next; |
| 184 | 197 | |
| 185 | 198 | // insert the entry |
| r11100 | r11101 | |
| 203 | 216 | software_list_close(list); |
| 204 | 217 | } |
| 205 | 218 | |
| 219 | // add an entry to change ordering |
| 220 | ui_menu_item_append(menu, "Switch Item Ordering", NULL, 0, (void *)1); |
| 221 | |
| 206 | 222 | // append all of the menu entries |
| 207 | 223 | for (software_entry_state *entry = menustate->entrylist; entry != NULL; entry = entry->next) |
| 208 | 224 | ui_menu_item_append(menu, entry->short_name, entry->long_name, 0, entry); |
| r11100 | r11101 | |
| 228 | 244 | const software_entry_state *selected_entry = NULL; |
| 229 | 245 | int bestmatch = 0; |
| 230 | 246 | |
| 231 | | if (!ui_menu_populated(menu)) |
| 247 | if (!ui_menu_populated(menu) || sw_state->reorder) |
| 232 | 248 | { |
| 249 | sw_state->reorder = 0; |
| 250 | |
| 233 | 251 | if (sw_state->list_name) |
| 234 | 252 | { |
| 235 | 253 | ui_mess_menu_populate_software_entries(machine, menu, sw_state); |
| r11100 | r11101 | |
| 241 | 259 | |
| 242 | 260 | if (event != NULL && event->itemref != NULL) |
| 243 | 261 | { |
| 262 | if ((FPTR)event->itemref == 1 && event->iptkey == IPT_UI_SELECT) |
| 263 | { |
| 264 | sw_state->ordered_by_shortname ^= 1; |
| 265 | sw_state->reorder = 1; |
| 266 | sw_state->entrylist = NULL; |
| 267 | // reset the char buffer if we change ordering criterion |
| 268 | memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer)); |
| 269 | |
| 270 | // reload the menu with the new order |
| 271 | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 272 | popmessage("Switched Order: entries now ordered by %s", sw_state->ordered_by_shortname ? "shortname" : "description"); |
| 273 | } |
| 244 | 274 | /* handle selections */ |
| 245 | | if (event->iptkey == IPT_UI_SELECT) |
| 275 | else if (event->iptkey == IPT_UI_SELECT) |
| 246 | 276 | { |
| 247 | 277 | device_image_interface *image = sw_state->image; |
| 248 | 278 | software_entry_state *entry = (software_entry_state *) event->itemref; |
| r11100 | r11101 | |
| 298 | 328 | if (ARRAY_LENGTH(sw_state->filename_buffer) > 0) |
| 299 | 329 | ui_popup_time(ERROR_MESSAGE_TIME, "%s", sw_state->filename_buffer); |
| 300 | 330 | } |
| 301 | | |
| 331 | |
| 302 | 332 | if (update_selected) |
| 303 | 333 | { |
| 304 | | const software_entry_state *cur_selected = (const software_entry_state *)ui_menu_get_selection(menu); |
| 305 | | |
| 334 | const software_entry_state *cur_selected; |
| 335 | |
| 336 | // if the current selection is a software entry, start search from here |
| 337 | if ((FPTR)event->itemref != 1) |
| 338 | cur_selected= (const software_entry_state *)ui_menu_get_selection(menu); |
| 339 | // else (if we are on the 'Switch Order' entry) start from the beginning |
| 340 | else |
| 341 | cur_selected= sw_state->entrylist; |
| 342 | |
| 306 | 343 | // check for entries which matches our filename_buffer: |
| 307 | 344 | // from current entry to the end |
| 308 | 345 | for (entry = cur_selected; entry != NULL; entry = entry->next) |
| 309 | 346 | { |
| 310 | | if (entry->short_name != NULL && sw_state->filename_buffer != NULL) |
| 347 | const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name; |
| 348 | |
| 349 | if (compare_name != NULL && sw_state->filename_buffer != NULL) |
| 311 | 350 | { |
| 312 | 351 | int match = 0; |
| 313 | 352 | for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++) |
| 314 | 353 | { |
| 315 | | if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0) |
| 354 | if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0) |
| 316 | 355 | match = i; |
| 317 | 356 | } |
| 318 | 357 | |
| r11100 | r11101 | |
| 326 | 365 | // and from the first entry to current one |
| 327 | 366 | for (entry = sw_state->entrylist; entry != cur_selected; entry = entry->next) |
| 328 | 367 | { |
| 329 | | if (entry->short_name != NULL && sw_state->filename_buffer != NULL) |
| 368 | const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name; |
| 369 | |
| 370 | if (compare_name != NULL && sw_state->filename_buffer != NULL) |
| 330 | 371 | { |
| 331 | 372 | int match = 0; |
| 332 | 373 | for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++) |
| 333 | 374 | { |
| 334 | | if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0) |
| 375 | if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0) |
| 335 | 376 | match = i; |
| 336 | 377 | } |
| 337 | 378 | |
| r11100 | r11101 | |
| 447 | 488 | child_menustate->list_name = (char *)event->itemref; |
| 448 | 489 | child_menustate->image = image; |
| 449 | 490 | child_menustate->entrylist = NULL; |
| 491 | child_menustate->ordered_by_shortname = 1; |
| 450 | 492 | ui_menu_stack_push(child_menu); |
| 451 | 493 | } |
| 452 | 494 | } |