2015-11-19 07:23:41 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2015-2017 - Ali Bouhlel
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2019-08-29 16:36:09 -04:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2015-11-19 07:23:41 +01:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <boolean.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-11-19 07:56:54 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma comment( lib, "comctl32" )
|
|
|
|
#endif
|
|
|
|
|
2015-11-19 07:53:00 +01:00
|
|
|
#define IDI_ICON 1
|
2015-11-19 07:48:56 +01:00
|
|
|
|
2015-11-19 07:37:22 +01:00
|
|
|
#ifndef _WIN32_WINNT
|
2022-10-01 17:56:16 +02:00
|
|
|
#define _WIN32_WINNT 0x0500 /* _WIN32_WINNT_WIN2K */
|
2015-11-19 07:37:22 +01:00
|
|
|
#endif
|
|
|
|
|
2021-03-08 00:20:06 +01:00
|
|
|
#ifndef _WIN32_IE
|
|
|
|
#define _WIN32_IE 0x0300
|
|
|
|
#endif
|
|
|
|
|
2016-11-29 14:26:33 -05:00
|
|
|
#include "../../gfx/common/win32_common.h"
|
2015-11-19 07:37:22 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <commdlg.h>
|
2015-11-19 07:56:54 +01:00
|
|
|
#include <commctrl.h>
|
2015-11-19 07:37:22 +01:00
|
|
|
|
2015-11-19 07:56:54 +01:00
|
|
|
#include <retro_inline.h>
|
2016-12-16 21:11:08 -05:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-11-19 07:23:41 +01:00
|
|
|
#include <file/file_path.h>
|
2019-08-20 23:01:01 +02:00
|
|
|
#include <encodings/utf.h>
|
2017-01-16 23:32:28 +01:00
|
|
|
#include <string/stdstring.h>
|
2016-12-16 22:30:39 -05:00
|
|
|
#include <compat/strl.h>
|
2015-11-19 07:56:54 +01:00
|
|
|
|
2015-11-19 07:23:41 +01:00
|
|
|
#include "../ui_companion_driver.h"
|
2016-06-20 02:46:25 +02:00
|
|
|
#include "../../msg_hash.h"
|
2016-09-30 21:20:50 +02:00
|
|
|
#include "../../paths.h"
|
2021-03-08 00:20:06 +01:00
|
|
|
#include "../../configuration.h"
|
2023-01-08 09:05:46 +01:00
|
|
|
#include "../../retroarch.h"
|
2016-05-16 20:21:53 +02:00
|
|
|
#include "../../tasks/tasks_internal.h"
|
2019-08-29 16:36:09 -04:00
|
|
|
#include "../../frontend/drivers/platform_win32.h"
|
2015-11-19 07:56:54 +01:00
|
|
|
|
2016-06-07 16:33:55 +02:00
|
|
|
#include "ui_win32.h"
|
2015-11-19 07:56:54 +01:00
|
|
|
|
2021-03-08 00:20:06 +01:00
|
|
|
extern ui_window_win32_t main_window;
|
|
|
|
extern HACCEL window_accelerators;
|
|
|
|
|
|
|
|
static void* ui_application_win32_initialize(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_application_win32_process_events(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
bool translated_accelerator = main_window.hwnd == msg.hwnd && TranslateAccelerator(msg.hwnd, window_accelerators, &msg) != 0;
|
|
|
|
|
|
|
|
if (!translated_accelerator)
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ui_application_t ui_application_win32 = {
|
|
|
|
ui_application_win32_initialize,
|
|
|
|
ui_application_win32_process_events,
|
|
|
|
NULL,
|
|
|
|
false,
|
|
|
|
"win32"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void* ui_window_win32_init(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_window_win32_destroy(void *data)
|
|
|
|
{
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
|
|
|
DestroyWindow(window->hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_window_win32_set_focused(void *data)
|
|
|
|
{
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
|
|
|
SetFocus(window->hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_window_win32_set_visible(void *data,
|
|
|
|
bool set_visible)
|
|
|
|
{
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
|
|
|
ShowWindow(window->hwnd, set_visible ? SW_SHOWNORMAL : SW_HIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_window_win32_set_title(void *data, char *buf)
|
|
|
|
{
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
2021-10-12 17:24:58 +08:00
|
|
|
#ifdef LEGACY_WIN32
|
2021-10-12 11:58:22 +02:00
|
|
|
char *title_local = utf8_to_local_string_alloc(buf);
|
2021-10-12 12:41:05 +02:00
|
|
|
SetWindowText(window->hwnd, title_local);
|
2021-10-12 17:24:58 +08:00
|
|
|
#else
|
2021-10-12 11:58:22 +02:00
|
|
|
wchar_t *title_local = utf8_to_utf16_string_alloc(buf);
|
|
|
|
SetWindowTextW(window->hwnd, title_local);
|
2021-10-12 12:41:05 +02:00
|
|
|
#endif
|
2021-10-12 17:24:58 +08:00
|
|
|
free(title_local);
|
2021-03-08 00:20:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_window_win32_set_droppable(void *data, bool droppable)
|
|
|
|
{
|
|
|
|
/* Minimum supported client: Windows XP,
|
|
|
|
* minimum supported server: Windows 2000 Server */
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
|
|
|
if (DragAcceptFiles_func)
|
|
|
|
DragAcceptFiles_func(window->hwnd, droppable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ui_window_win32_focused(void *data)
|
|
|
|
{
|
|
|
|
ui_window_win32_t *window = (ui_window_win32_t*)data;
|
|
|
|
return (GetForegroundWindow() == window->hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ui_window_t ui_window_win32 = {
|
|
|
|
ui_window_win32_init,
|
|
|
|
ui_window_win32_destroy,
|
|
|
|
ui_window_win32_set_focused,
|
|
|
|
ui_window_win32_set_visible,
|
|
|
|
ui_window_win32_set_title,
|
|
|
|
ui_window_win32_set_droppable,
|
|
|
|
ui_window_win32_focused,
|
|
|
|
"win32"
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum ui_msg_window_response ui_msg_window_win32_response(
|
|
|
|
ui_msg_window_state *state, UINT response)
|
|
|
|
{
|
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case IDOK:
|
2022-11-23 05:08:15 +01:00
|
|
|
return UI_MSG_RESPONSE_OK;
|
2021-03-08 00:20:06 +01:00
|
|
|
case IDCANCEL:
|
2022-11-23 05:08:15 +01:00
|
|
|
return UI_MSG_RESPONSE_CANCEL;
|
2021-03-08 00:20:06 +01:00
|
|
|
case IDYES:
|
2022-11-23 05:08:15 +01:00
|
|
|
return UI_MSG_RESPONSE_YES;
|
2021-03-08 00:20:06 +01:00
|
|
|
case IDNO:
|
2022-11-23 05:08:15 +01:00
|
|
|
return UI_MSG_RESPONSE_NO;
|
2021-03-08 00:20:06 +01:00
|
|
|
default:
|
2022-11-23 05:08:15 +01:00
|
|
|
break;
|
2021-03-08 00:20:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (state->buttons)
|
|
|
|
{
|
|
|
|
case UI_MSG_WINDOW_OK:
|
|
|
|
return UI_MSG_RESPONSE_OK;
|
|
|
|
case UI_MSG_WINDOW_OKCANCEL:
|
|
|
|
return UI_MSG_RESPONSE_CANCEL;
|
|
|
|
case UI_MSG_WINDOW_YESNO:
|
|
|
|
return UI_MSG_RESPONSE_NO;
|
|
|
|
case UI_MSG_WINDOW_YESNOCANCEL:
|
|
|
|
return UI_MSG_RESPONSE_CANCEL;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UI_MSG_RESPONSE_NA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT ui_msg_window_win32_buttons(ui_msg_window_state *state)
|
|
|
|
{
|
|
|
|
switch (state->buttons)
|
|
|
|
{
|
|
|
|
case UI_MSG_WINDOW_OK:
|
|
|
|
return MB_OK;
|
|
|
|
case UI_MSG_WINDOW_OKCANCEL:
|
|
|
|
return MB_OKCANCEL;
|
|
|
|
case UI_MSG_WINDOW_YESNO:
|
|
|
|
return MB_YESNO;
|
|
|
|
case UI_MSG_WINDOW_YESNOCANCEL:
|
|
|
|
return MB_YESNOCANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ui_msg_window_response ui_msg_window_win32_error(
|
|
|
|
ui_msg_window_state *state)
|
|
|
|
{
|
|
|
|
UINT flags = MB_ICONERROR | ui_msg_window_win32_buttons(state);
|
|
|
|
return ui_msg_window_win32_response(state,
|
|
|
|
MessageBoxA(NULL, (LPCSTR)state->text, (LPCSTR)state->title, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ui_msg_window_response ui_msg_window_win32_information(
|
|
|
|
ui_msg_window_state *state)
|
|
|
|
{
|
|
|
|
UINT flags = MB_ICONINFORMATION | ui_msg_window_win32_buttons(state);
|
|
|
|
return ui_msg_window_win32_response(state,
|
|
|
|
MessageBoxA(NULL, (LPCSTR)state->text, (LPCSTR)state->title, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ui_msg_window_response ui_msg_window_win32_question(
|
|
|
|
ui_msg_window_state *state)
|
|
|
|
{
|
|
|
|
UINT flags = MB_ICONQUESTION | ui_msg_window_win32_buttons(state);
|
|
|
|
return ui_msg_window_win32_response(state,
|
|
|
|
MessageBoxA(NULL, (LPCSTR)state->text, (LPCSTR)state->title, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ui_msg_window_response ui_msg_window_win32_warning(
|
|
|
|
ui_msg_window_state *state)
|
|
|
|
{
|
|
|
|
UINT flags = MB_ICONWARNING | ui_msg_window_win32_buttons(state);
|
|
|
|
return ui_msg_window_win32_response(state,
|
|
|
|
MessageBoxA(NULL, (LPCSTR)state->text, (LPCSTR)state->title, flags));
|
|
|
|
}
|
|
|
|
|
2021-09-28 01:16:53 +02:00
|
|
|
ui_msg_window_t ui_msg_window_win32 = {
|
2021-03-08 00:20:06 +01:00
|
|
|
ui_msg_window_win32_error,
|
|
|
|
ui_msg_window_win32_information,
|
|
|
|
ui_msg_window_win32_question,
|
|
|
|
ui_msg_window_win32_warning,
|
|
|
|
"win32"
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool ui_browser_window_win32_core(
|
|
|
|
ui_browser_window_state_t *state, bool save)
|
|
|
|
{
|
|
|
|
OPENFILENAME ofn;
|
|
|
|
bool okay = true;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2023-05-29 18:58:23 +02:00
|
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
2021-03-08 00:20:06 +01:00
|
|
|
bool video_fullscreen = settings->bools.video_fullscreen;
|
|
|
|
|
|
|
|
ofn.lStructSize = sizeof(OPENFILENAME);
|
|
|
|
ofn.hwndOwner = (HWND)state->window;
|
|
|
|
ofn.hInstance = NULL;
|
|
|
|
ofn.lpstrFilter = state->filters; /* actually const */
|
|
|
|
ofn.lpstrCustomFilter = NULL;
|
|
|
|
ofn.nMaxCustFilter = 0;
|
|
|
|
ofn.nFilterIndex = 0;
|
|
|
|
ofn.lpstrFile = state->path;
|
|
|
|
ofn.nMaxFile = PATH_MAX;
|
|
|
|
ofn.lpstrFileTitle = NULL;
|
|
|
|
ofn.nMaxFileTitle = 0;
|
|
|
|
ofn.lpstrInitialDir = state->startdir;
|
|
|
|
ofn.lpstrTitle = state->title;
|
|
|
|
ofn.Flags = OFN_FILEMUSTEXIST
|
|
|
|
| OFN_HIDEREADONLY
|
|
|
|
| OFN_NOCHANGEDIR;
|
|
|
|
ofn.nFileOffset = 0;
|
|
|
|
ofn.nFileExtension = 0;
|
|
|
|
ofn.lpstrDefExt = "";
|
|
|
|
ofn.lCustData = 0;
|
|
|
|
ofn.lpfnHook = NULL;
|
|
|
|
ofn.lpTemplateName = NULL;
|
|
|
|
#if (_WIN32_WINNT >= 0x0500)
|
|
|
|
ofn.pvReserved = NULL;
|
|
|
|
ofn.dwReserved = 0;
|
|
|
|
ofn.FlagsEx = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Full Screen: Show mouse for the file dialog */
|
|
|
|
if (video_fullscreen)
|
2023-05-29 18:58:23 +02:00
|
|
|
{
|
|
|
|
if ( video_st->poke
|
|
|
|
&& video_st->poke->show_mouse)
|
|
|
|
video_st->poke->show_mouse(video_st->data, true);
|
|
|
|
}
|
2021-03-08 00:20:06 +01:00
|
|
|
|
|
|
|
if (!save && !GetOpenFileName(&ofn))
|
|
|
|
okay = false;
|
|
|
|
if (save && !GetSaveFileName(&ofn))
|
|
|
|
okay = false;
|
|
|
|
|
|
|
|
/* Full screen: Hide mouse after the file dialog */
|
|
|
|
if (video_fullscreen)
|
2023-05-29 18:58:23 +02:00
|
|
|
{
|
|
|
|
if ( video_st->poke
|
|
|
|
&& video_st->poke->show_mouse)
|
|
|
|
video_st->poke->show_mouse(video_st->data, false);
|
|
|
|
}
|
2021-03-08 00:20:06 +01:00
|
|
|
|
|
|
|
return okay;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ui_browser_window_win32_open(ui_browser_window_state_t *state)
|
|
|
|
{
|
|
|
|
return ui_browser_window_win32_core(state, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ui_browser_window_win32_save(ui_browser_window_state_t *state)
|
|
|
|
{
|
|
|
|
return ui_browser_window_win32_core(state, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ui_browser_window_t ui_browser_window_win32 = {
|
|
|
|
ui_browser_window_win32_open,
|
|
|
|
ui_browser_window_win32_save,
|
|
|
|
"win32"
|
|
|
|
};
|
|
|
|
|
2020-09-16 10:29:50 +02:00
|
|
|
static void ui_companion_win32_deinit(void *data) { }
|
|
|
|
static void *ui_companion_win32_init(void) { return (void*)-1; }
|
2020-02-13 22:39:29 +01:00
|
|
|
static void ui_companion_win32_toggle(void *data, bool force) { }
|
2016-02-26 13:31:34 +01:00
|
|
|
static void ui_companion_win32_event_command(
|
2020-02-13 22:39:29 +01:00
|
|
|
void *data, enum event_command cmd) { }
|
2015-11-19 07:23:41 +01:00
|
|
|
|
2018-04-30 14:33:05 -04:00
|
|
|
ui_companion_driver_t ui_companion_win32 = {
|
2015-11-19 07:23:41 +01:00
|
|
|
ui_companion_win32_init,
|
|
|
|
ui_companion_win32_deinit,
|
|
|
|
ui_companion_win32_toggle,
|
|
|
|
ui_companion_win32_event_command,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2016-06-12 19:29:07 +02:00
|
|
|
NULL,
|
2020-06-26 21:45:09 +02:00
|
|
|
NULL, /* log_msg */
|
|
|
|
NULL, /* is_active */
|
2023-12-24 19:36:49 -05:00
|
|
|
NULL, /* get_app_icons */
|
|
|
|
NULL, /* set_app_icon */
|
2024-05-13 01:52:52 -04:00
|
|
|
NULL, /* get_app_icon_texture */
|
2016-06-08 15:51:43 +02:00
|
|
|
&ui_browser_window_win32,
|
2016-06-08 06:33:15 +02:00
|
|
|
&ui_msg_window_win32,
|
2016-06-04 04:24:54 +02:00
|
|
|
&ui_window_win32,
|
2016-06-07 17:03:34 +02:00
|
|
|
&ui_application_win32,
|
2015-11-19 07:23:41 +01:00
|
|
|
"win32",
|
|
|
|
};
|