summaryrefslogtreecommitdiffstats
path: root/src/frontend/mame/ui/filesel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/ui/filesel.cpp')
-rw-r--r--src/frontend/mame/ui/filesel.cpp350
1 files changed, 30 insertions, 320 deletions
diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp
index b1a2ec6191d..fdefe84715d 100644
--- a/src/frontend/mame/ui/filesel.cpp
+++ b/src/frontend/mame/ui/filesel.cpp
@@ -4,10 +4,9 @@
ui/filesel.cpp
- MESS's clunky built-in file manager
+ MAME's clunky built-in file manager
TODO
- - Support image creation arguments
- Restrict empty slot if image required
***************************************************************************/
@@ -36,255 +35,6 @@ namespace ui {
// time (in seconds) to display errors
#define ERROR_MESSAGE_TIME 5
-// itemrefs for key menu items
-#define ITEMREF_NEW_IMAGE_NAME ((void *) 0x0001)
-#define ITEMREF_CREATE ((void *) 0x0002)
-#define ITEMREF_FORMAT ((void *) 0x0003)
-#define ITEMREF_NO ((void *) 0x0004)
-#define ITEMREF_YES ((void *) 0x0005)
-
-
-/***************************************************************************
- MENU HELPERS
-***************************************************************************/
-
-//-------------------------------------------------
-// input_character - inputs a typed character
-// into a buffer
-//-------------------------------------------------
-
-template <typename F>
-static void input_character(std::string &buffer, unicode_char unichar, F &&filter)
-{
- auto buflen = buffer.size();
-
- if ((unichar == 8) || (unichar == 0x7f))
- {
- // backspace
- if (0 < buflen)
- {
- auto buffer_oldend = buffer.c_str() + buflen;
- auto buffer_newend = utf8_previous_char(buffer_oldend);
- buffer.resize(buffer_newend - buffer.c_str());
- }
- }
- else if ((unichar >= ' ') && (!filter || filter(unichar)))
- {
- // append this character
- buffer += utf8_from_uchar(unichar);
- }
-}
-
-
-/***************************************************************************
- CONFIRM SAVE AS MENU
-***************************************************************************/
-
-//-------------------------------------------------
-// ctor
-//-------------------------------------------------
-
-menu_confirm_save_as::menu_confirm_save_as(mame_ui_manager &mui, render_container *container, bool *yes)
- : menu(mui, container)
-{
- m_yes = yes;
- *m_yes = false;
-}
-
-
-//-------------------------------------------------
-// dtor
-//-------------------------------------------------
-
-menu_confirm_save_as::~menu_confirm_save_as()
-{
-}
-
-
-//-------------------------------------------------
-// populate
-//-------------------------------------------------
-
-void menu_confirm_save_as::populate()
-{
- item_append(_("File Already Exists - Override?"), "", FLAG_DISABLE, nullptr);
- item_append(menu_item_type::SEPARATOR);
- item_append(_("No"), "", 0, ITEMREF_NO);
- item_append(_("Yes"), "", 0, ITEMREF_YES);
-}
-
-//-------------------------------------------------
-// handle - confirm save as menu
-//-------------------------------------------------
-
-void menu_confirm_save_as::handle()
-{
- // process the menu
- const event *event = process(0);
-
- // process the event
- if ((event != nullptr) && (event->iptkey == IPT_UI_SELECT))
- {
- if (event->itemref == ITEMREF_YES)
- *m_yes = true;
-
- // no matter what, pop out
- menu::stack_pop(machine());
- }
-}
-
-
-
-/***************************************************************************
- FILE CREATE MENU
-***************************************************************************/
-
-//-------------------------------------------------
-// is_valid_filename_char - tests to see if a
-// character is valid in a filename
-//-------------------------------------------------
-
-static int is_valid_filename_char(unicode_char unichar)
-{
- // this should really be in the OSD layer, and it shouldn't be 7-bit bullshit
- static const char valid_filename_char[] =
- {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00-0f
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10-1f
- 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, // !"#$%&'()*+,-./
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 0123456789:;<=>?
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // @ABCDEFGHIJKLMNO
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // PQRSTUVWXYZ[\]^_
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // `abcdefghijklmno
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, // pqrstuvwxyz{|}~
- };
- return (unichar < ARRAY_LENGTH(valid_filename_char)) && valid_filename_char[unichar];
-}
-
-
-//-------------------------------------------------
-// ctor
-//-------------------------------------------------
-
-menu_file_create::menu_file_create(mame_ui_manager &mui, render_container *container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool *ok)
- : menu(mui, container)
- , m_current_directory(current_directory)
- , m_current_file(current_file)
- , m_current_format(nullptr)
-{
- m_image = image;
- m_ok = ok;
- *m_ok = true;
- auto const sep = current_file.rfind(PATH_SEPARATOR);
-
- m_filename.reserve(1024);
- m_filename = sep != std::string::npos
- ? current_file.substr(sep + strlen(PATH_SEPARATOR), current_file.size() - sep - strlen(PATH_SEPARATOR))
- : current_file;
-}
-
-
-//-------------------------------------------------
-// dtor
-//-------------------------------------------------
-
-menu_file_create::~menu_file_create()
-{
-}
-
-
-//-------------------------------------------------
-// custom_render - perform our special rendering
-//-------------------------------------------------
-
-void menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
-{
- extra_text_render(top, bottom, origx1, origy1, origx2, origy2,
- m_current_directory.c_str(),
- nullptr);
-}
-
-
-//-------------------------------------------------
-// populate - populates the file creator menu
-//-------------------------------------------------
-
-void menu_file_create::populate()
-{
- std::string buffer;
- const image_device_format *format;
- const std::string *new_image_name;
-
- // append the "New Image Name" item
- if (get_selection() == ITEMREF_NEW_IMAGE_NAME)
- {
- buffer = m_filename + "_";
- new_image_name = &buffer;
- }
- else
- {
- new_image_name = &m_filename;
- }
- item_append(_("New Image Name:"), *new_image_name, 0, ITEMREF_NEW_IMAGE_NAME);
-
- // do we support multiple formats?
- if (ENABLE_FORMATS) format = m_image->formatlist().front().get();
- if (ENABLE_FORMATS && (format != nullptr))
- {
- item_append(_("Image Format:"), m_current_format->description(), 0, ITEMREF_FORMAT);
- m_current_format = format;
- }
-
- // finish up the menu
- item_append(menu_item_type::SEPARATOR);
- item_append(_("Create"), "", 0, ITEMREF_CREATE);
-
- customtop = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
-}
-
-
-//-------------------------------------------------
-// handle - file creator menu
-//-------------------------------------------------
-
-void menu_file_create::handle()
-{
- // process the menu
- const event *event = process(0);
-
- // process the event
- if (event)
- {
- // handle selections
- switch (event->iptkey)
- {
- case IPT_UI_SELECT:
- if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME))
- {
- std::string tmp_file(m_filename);
- if (tmp_file.find(".") != -1 && tmp_file.find(".") < tmp_file.length() - 1)
- {
- m_current_file = m_filename;
- menu::stack_pop(machine());
- }
- else
- ui().popup_time(1, "%s", _("Please enter a file extension too"));
- }
- break;
-
- case IPT_SPECIAL:
- if (get_selection() == ITEMREF_NEW_IMAGE_NAME)
- {
- input_character(m_filename, event->unichar, &is_valid_filename_char);
- reset(reset_options::REMEMBER_POSITION);
- }
- break;
- case IPT_UI_CANCEL:
- *m_ok = false;
- break;
- }
- }
-}
/***************************************************************************
FILE SELECTOR MENU
@@ -294,16 +44,16 @@ void menu_file_create::handle()
// ctor
//-------------------------------------------------
-menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container *container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool has_empty, bool has_softlist, bool has_create, int *result)
+menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container *container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool has_empty, bool has_softlist, bool has_create, menu_file_selector::result &result)
: menu(mui, container)
, m_current_directory(current_directory)
, m_current_file(current_file)
+ , m_result(result)
{
m_image = image;
m_has_empty = has_empty;
m_has_softlist = has_softlist;
m_has_create = has_create;
- m_result = result;
}
@@ -478,7 +228,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry
}
// determine the full path
- util::zippath_combine(buffer, m_current_directory.c_str(), dirent->name);
+ buffer = util::zippath_combine(m_current_directory.c_str(), dirent->name);
// create the file selector entry
entry = &append_entry(
@@ -641,18 +391,18 @@ void menu_file_selector::handle()
{
case SELECTOR_ENTRY_TYPE_EMPTY:
// empty slot - unload
- *m_result = R_EMPTY;
+ m_result = result::EMPTY;
menu::stack_pop(machine());
break;
case SELECTOR_ENTRY_TYPE_CREATE:
// create
- *m_result = R_CREATE;
+ m_result = result::CREATE;
menu::stack_pop(machine());
break;
case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST:
- *m_result = R_SOFTLIST;
+ m_result = result::SOFTLIST;
menu::stack_pop(machine());
break;
@@ -673,7 +423,7 @@ void menu_file_selector::handle()
case SELECTOR_ENTRY_TYPE_FILE:
// file
m_current_file.assign(entry->fullpath);
- *m_result = R_FILE;
+ m_result = result::FILE;
menu::stack_pop(machine());
break;
}
@@ -750,20 +500,19 @@ void menu_file_selector::handle()
/***************************************************************************
- SELECT FORMAT MENU
+ SELECT RW
***************************************************************************/
//-------------------------------------------------
// ctor
//-------------------------------------------------
-menu_select_format::menu_select_format(mame_ui_manager &mui, render_container *container, floppy_image_format_t **formats, int ext_match, int total_usable, int *result)
- : menu(mui, container)
+menu_select_rw::menu_select_rw(mame_ui_manager &mui, render_container *container,
+ bool can_in_place, result &result)
+ : menu(mui, container),
+ m_can_in_place(can_in_place),
+ m_result(result)
{
- m_formats = formats;
- m_ext_match = ext_match;
- m_total_usable = total_usable;
- m_result = result;
}
@@ -771,7 +520,7 @@ menu_select_format::menu_select_format(mame_ui_manager &mui, render_container *c
// dtor
//-------------------------------------------------
-menu_select_format::~menu_select_format()
+menu_select_rw::~menu_select_rw()
{
}
@@ -780,17 +529,14 @@ menu_select_format::~menu_select_format()
// populate
//-------------------------------------------------
-void menu_select_format::populate()
+void menu_select_rw::populate()
{
- item_append(_("Select image format"), "", FLAG_DISABLE, nullptr);
- for (int i = 0; i < m_total_usable; i++)
- {
- const floppy_image_format_t *fmt = m_formats[i];
-
- if (i && i == m_ext_match)
- item_append(menu_item_type::SEPARATOR);
- item_append(fmt->description(), fmt->name(), 0, (void *)(FPTR)i);
- }
+ item_append(_("Select access mode"), "", FLAG_DISABLE, nullptr);
+ item_append(_("Read-only"), "", 0, itemref_from_result(result::READONLY));
+ if (m_can_in_place)
+ item_append(_("Read-write"), "", 0, itemref_from_result(result::READWRITE));
+ item_append(_("Read this image, write to another image"), "", 0, itemref_from_result(result::WRITE_OTHER));
+ item_append(_("Read this image, write to diff"), "", 0, itemref_from_result(result::WRITE_DIFF));
}
@@ -798,72 +544,36 @@ void menu_select_format::populate()
// handle
//-------------------------------------------------
-void menu_select_format::handle()
+void menu_select_rw::handle()
{
// process the menu
const event *event = process(0);
if (event != nullptr && event->iptkey == IPT_UI_SELECT)
{
- *m_result = int(FPTR(event->itemref));
+ m_result = result_from_itemref(event->itemref);
menu::stack_pop(machine());
}
}
-/***************************************************************************
- SELECT RW
-***************************************************************************/
-
//-------------------------------------------------
-// ctor
+// itemref_from_result
//-------------------------------------------------
-menu_select_rw::menu_select_rw(mame_ui_manager &mui, render_container *container,
- bool can_in_place, int *result)
- : menu(mui, container)
+void *menu_select_rw::itemref_from_result(menu_select_rw::result result)
{
- m_can_in_place = can_in_place;
- m_result = result;
+ return (void *)(FPTR)(unsigned int)result;
}
//-------------------------------------------------
-// dtor
+// result_from_itemref
//-------------------------------------------------
-menu_select_rw::~menu_select_rw()
+menu_select_rw::result menu_select_rw::result_from_itemref(void *itemref)
{
+ return (menu_select_rw::result) (unsigned int) (FPTR)itemref;
}
-//-------------------------------------------------
-// populate
-//-------------------------------------------------
-
-void menu_select_rw::populate()
-{
- item_append(_("Select access mode"), "", FLAG_DISABLE, nullptr);
- item_append(_("Read-only"), "", 0, (void *)READONLY);
- if (m_can_in_place)
- item_append(_("Read-write"), "", 0, (void *)READWRITE);
- item_append(_("Read this image, write to another image"), "", 0, (void *)WRITE_OTHER);
- item_append(_("Read this image, write to diff"), "", 0, (void *)WRITE_DIFF);
-}
-
-
-//-------------------------------------------------
-// handle
-//-------------------------------------------------
-
-void menu_select_rw::handle()
-{
- // process the menu
- const event *event = process(0);
- if (event != nullptr && event->iptkey == IPT_UI_SELECT)
- {
- *m_result = int(FPTR(event->itemref));
- menu::stack_pop(machine());
- }
-}
-
} // namespace ui