mirror of
https://github.com/holub/mame
synced 2025-07-04 09:28:51 +03:00
move clipboard handling on proper place (nw)
This commit is contained in:
parent
0730ffc328
commit
5e80a732aa
@ -461,7 +461,6 @@ project ("ocore_" .. _OPTIONS["osd"])
|
||||
MAME_DIR .. "src/osd/strconv.cpp",
|
||||
MAME_DIR .. "src/osd/strconv.h",
|
||||
MAME_DIR .. "src/osd/sdl/sdldir.cpp",
|
||||
MAME_DIR .. "src/osd/sdl/sdlos_" .. SDLOS_TARGETOS .. ".cpp",
|
||||
MAME_DIR .. "src/osd/modules/osdmodule.cpp",
|
||||
MAME_DIR .. "src/osd/modules/osdmodule.h",
|
||||
MAME_DIR .. "src/osd/modules/lib/osdlib_" .. SDLOS_TARGETOS .. ".cpp",
|
||||
|
@ -253,7 +253,6 @@ project ("ocore_" .. _OPTIONS["osd"])
|
||||
MAME_DIR .. "src/osd/windows/winutf8.h",
|
||||
MAME_DIR .. "src/osd/windows/winutil.cpp",
|
||||
MAME_DIR .. "src/osd/windows/winutil.h",
|
||||
MAME_DIR .. "src/osd/windows/winclip.cpp",
|
||||
MAME_DIR .. "src/osd/modules/osdmodule.cpp",
|
||||
MAME_DIR .. "src/osd/modules/osdmodule.h",
|
||||
MAME_DIR .. "src/osd/modules/file/winfile.cpp",
|
||||
|
@ -61,4 +61,14 @@ void osd_process_kill(void);
|
||||
|
||||
int osd_setenv(const char *name, const char *value, int overwrite);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_get_clipboard_text: retrieves text from the clipboard
|
||||
|
||||
Return value:
|
||||
|
||||
the returned string needs to be osd_free()-ed!
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
char *osd_get_clipboard_text(void);
|
||||
|
||||
#endif /* __OSDLIB__ */
|
||||
|
@ -14,6 +14,10 @@
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
// MAME headers
|
||||
#include "osdcore.h"
|
||||
#include "osdlib.h"
|
||||
@ -136,3 +140,82 @@ void osd_break_into_debugger(const char *message)
|
||||
printf("Ignoring MAME exception: %s\n", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
OSStatus err;
|
||||
|
||||
PasteboardRef pasteboard_ref;
|
||||
err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref);
|
||||
if (err)
|
||||
return NULL;
|
||||
|
||||
PasteboardSynchronize(pasteboard_ref);
|
||||
|
||||
ItemCount item_count;
|
||||
err = PasteboardGetItemCount(pasteboard_ref, &item_count);
|
||||
|
||||
char *result = NULL; // core expects a malloced C string of uft8 data
|
||||
for (UInt32 item_index = 1; (item_index <= item_count) && !result; item_index++)
|
||||
{
|
||||
PasteboardItemID item_id;
|
||||
err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
CFArrayRef flavor_type_array;
|
||||
err = PasteboardCopyItemFlavors(pasteboard_ref, item_id, &flavor_type_array);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
CFIndex const flavor_count = CFArrayGetCount(flavor_type_array);
|
||||
for (CFIndex flavor_index = 0; (flavor_index < flavor_count) && !result; flavor_index++)
|
||||
{
|
||||
CFStringRef const flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index);
|
||||
|
||||
CFStringEncoding encoding;
|
||||
if (UTTypeConformsTo(flavor_type, kUTTypeUTF16PlainText))
|
||||
encoding = kCFStringEncodingUTF16;
|
||||
else if (UTTypeConformsTo (flavor_type, kUTTypeUTF8PlainText))
|
||||
encoding = kCFStringEncodingUTF8;
|
||||
else if (UTTypeConformsTo (flavor_type, kUTTypePlainText))
|
||||
encoding = kCFStringEncodingMacRoman;
|
||||
else
|
||||
continue;
|
||||
|
||||
CFDataRef flavor_data;
|
||||
err = PasteboardCopyItemFlavorData(pasteboard_ref, item_id, flavor_type, &flavor_data);
|
||||
|
||||
if (!err)
|
||||
{
|
||||
CFStringRef string_ref = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, flavor_data, encoding);
|
||||
CFDataRef data_ref = CFStringCreateExternalRepresentation (kCFAllocatorDefault, string_ref, kCFStringEncodingUTF8, '?');
|
||||
CFRelease(string_ref);
|
||||
CFRelease(flavor_data);
|
||||
|
||||
CFIndex const length = CFDataGetLength(data_ref);
|
||||
CFRange const range = CFRangeMake(0, length);
|
||||
|
||||
result = reinterpret_cast<char *>(osd_malloc_array(length + 1));
|
||||
if (result)
|
||||
{
|
||||
CFDataGetBytes(data_ref, range, reinterpret_cast<unsigned char *>(result));
|
||||
result[length] = 0;
|
||||
}
|
||||
|
||||
CFRelease(data_ref);
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(flavor_type_array);
|
||||
}
|
||||
|
||||
CFRelease(pasteboard_ref);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -132,3 +132,30 @@ void osd_break_into_debugger(const char *message)
|
||||
printf("Ignoring MAME exception: %s\n", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SDLMAME_ANDROID
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
if (SDL_HasClipboardText())
|
||||
{
|
||||
char *temp = SDL_GetClipboardText();
|
||||
result = (char *) osd_malloc_array(strlen(temp) + 1);
|
||||
strcpy(result, temp);
|
||||
SDL_free(temp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "osdlib.h"
|
||||
#include "osdcomm.h"
|
||||
#include "osdcore.h"
|
||||
#include "strconv.h"
|
||||
|
||||
#ifdef OSD_WINDOWS
|
||||
#include "winutf8.h"
|
||||
@ -240,3 +241,76 @@ void osd_break_into_debugger(const char *message)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// get_clipboard_text_by_format
|
||||
//============================================================
|
||||
|
||||
static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
|
||||
{
|
||||
char *result = NULL;
|
||||
HANDLE data_handle;
|
||||
LPVOID data;
|
||||
|
||||
// check to see if this format is available
|
||||
if (IsClipboardFormatAvailable(format))
|
||||
{
|
||||
// open the clipboard
|
||||
if (OpenClipboard(NULL))
|
||||
{
|
||||
// try to access clipboard data
|
||||
data_handle = GetClipboardData(format);
|
||||
if (data_handle != NULL)
|
||||
{
|
||||
// lock the data
|
||||
data = GlobalLock(data_handle);
|
||||
if (data != NULL)
|
||||
{
|
||||
// invoke the convert
|
||||
result = (*convert)(data);
|
||||
|
||||
// unlock the data
|
||||
GlobalUnlock(data_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// close out the clipboard
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_wide
|
||||
//============================================================
|
||||
|
||||
static char *convert_wide(LPCVOID data)
|
||||
{
|
||||
return utf8_from_wstring((LPCWSTR) data);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_ansi
|
||||
//============================================================
|
||||
|
||||
static char *convert_ansi(LPCVOID data)
|
||||
{
|
||||
return utf8_from_astring((LPCSTR) data);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
// try to access unicode text
|
||||
char *result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
|
||||
|
||||
// try to access ANSI text
|
||||
if (result == nullptr)
|
||||
result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -774,11 +774,6 @@ void osd_free_executable(void *ptr, size_t size);
|
||||
-----------------------------------------------------------------------------*/
|
||||
void osd_break_into_debugger(const char *message);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
MESS specific code below
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
osd_get_clipboard_text: retrieves text from the clipboard
|
||||
|
||||
|
@ -1,101 +0,0 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Olivier Galibert, R. Belmont
|
||||
//============================================================
|
||||
//
|
||||
// sdlos_*.c - OS specific low level code
|
||||
//
|
||||
// SDLMAME by Olivier Galibert and R. Belmont
|
||||
//
|
||||
//============================================================
|
||||
|
||||
// standard sdl header
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#include "sdlinc.h"
|
||||
|
||||
// MAME headers
|
||||
#include "osdcore.h"
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
OSStatus err;
|
||||
|
||||
PasteboardRef pasteboard_ref;
|
||||
err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref);
|
||||
if (err)
|
||||
return NULL;
|
||||
|
||||
PasteboardSynchronize(pasteboard_ref);
|
||||
|
||||
ItemCount item_count;
|
||||
err = PasteboardGetItemCount(pasteboard_ref, &item_count);
|
||||
|
||||
char *result = NULL; // core expects a malloced C string of uft8 data
|
||||
for (UInt32 item_index = 1; (item_index <= item_count) && !result; item_index++)
|
||||
{
|
||||
PasteboardItemID item_id;
|
||||
err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
CFArrayRef flavor_type_array;
|
||||
err = PasteboardCopyItemFlavors(pasteboard_ref, item_id, &flavor_type_array);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
CFIndex const flavor_count = CFArrayGetCount(flavor_type_array);
|
||||
for (CFIndex flavor_index = 0; (flavor_index < flavor_count) && !result; flavor_index++)
|
||||
{
|
||||
CFStringRef const flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index);
|
||||
|
||||
CFStringEncoding encoding;
|
||||
if (UTTypeConformsTo(flavor_type, kUTTypeUTF16PlainText))
|
||||
encoding = kCFStringEncodingUTF16;
|
||||
else if (UTTypeConformsTo (flavor_type, kUTTypeUTF8PlainText))
|
||||
encoding = kCFStringEncodingUTF8;
|
||||
else if (UTTypeConformsTo (flavor_type, kUTTypePlainText))
|
||||
encoding = kCFStringEncodingMacRoman;
|
||||
else
|
||||
continue;
|
||||
|
||||
CFDataRef flavor_data;
|
||||
err = PasteboardCopyItemFlavorData(pasteboard_ref, item_id, flavor_type, &flavor_data);
|
||||
|
||||
if (!err)
|
||||
{
|
||||
CFStringRef string_ref = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, flavor_data, encoding);
|
||||
CFDataRef data_ref = CFStringCreateExternalRepresentation (kCFAllocatorDefault, string_ref, kCFStringEncodingUTF8, '?');
|
||||
CFRelease(string_ref);
|
||||
CFRelease(flavor_data);
|
||||
|
||||
CFIndex const length = CFDataGetLength(data_ref);
|
||||
CFRange const range = CFRangeMake(0, length);
|
||||
|
||||
result = reinterpret_cast<char *>(osd_malloc_array(length + 1));
|
||||
if (result)
|
||||
{
|
||||
CFDataGetBytes(data_ref, range, reinterpret_cast<unsigned char *>(result));
|
||||
result[length] = 0;
|
||||
}
|
||||
|
||||
CFRelease(data_ref);
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(flavor_type_array);
|
||||
}
|
||||
|
||||
CFRelease(pasteboard_ref);
|
||||
|
||||
return result;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Olivier Galibert, R. Belmont
|
||||
//============================================================
|
||||
//
|
||||
// sdlos_*.c - OS specific low level code
|
||||
//
|
||||
// SDLMAME by Olivier Galibert and R. Belmont
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef SDLMAME_EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "sdlinc.h"
|
||||
|
||||
// MAME headers
|
||||
#include "osdcore.h"
|
||||
|
||||
#ifdef SDLMAME_ANDROID
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
if (SDL_HasClipboardText())
|
||||
{
|
||||
char *temp = SDL_GetClipboardText();
|
||||
result = (char *) osd_malloc_array(strlen(temp) + 1);
|
||||
strcpy(result, temp);
|
||||
SDL_free(temp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,87 +0,0 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Aaron Giles
|
||||
//============================================================
|
||||
//
|
||||
// sdlos_win32.c - Win32 OSD core clipboard access functions
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "strconv.h"
|
||||
|
||||
//============================================================
|
||||
// get_clipboard_text_by_format
|
||||
//============================================================
|
||||
|
||||
static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
|
||||
{
|
||||
char *result = NULL;
|
||||
HANDLE data_handle;
|
||||
LPVOID data;
|
||||
|
||||
// check to see if this format is available
|
||||
if (IsClipboardFormatAvailable(format))
|
||||
{
|
||||
// open the clipboard
|
||||
if (OpenClipboard(NULL))
|
||||
{
|
||||
// try to access clipboard data
|
||||
data_handle = GetClipboardData(format);
|
||||
if (data_handle != NULL)
|
||||
{
|
||||
// lock the data
|
||||
data = GlobalLock(data_handle);
|
||||
if (data != NULL)
|
||||
{
|
||||
// invoke the convert
|
||||
result = (*convert)(data);
|
||||
|
||||
// unlock the data
|
||||
GlobalUnlock(data_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// close out the clipboard
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_wide
|
||||
//============================================================
|
||||
|
||||
static char *convert_wide(LPCVOID data)
|
||||
{
|
||||
return utf8_from_wstring((LPCWSTR) data);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_ansi
|
||||
//============================================================
|
||||
|
||||
static char *convert_ansi(LPCVOID data)
|
||||
{
|
||||
return utf8_from_astring((LPCSTR) data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
// try to access unicode text
|
||||
char *result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
|
||||
|
||||
// try to access ANSI text
|
||||
if (result == nullptr)
|
||||
result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
|
||||
|
||||
return result;
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Aaron Giles
|
||||
//============================================================
|
||||
//
|
||||
// winclip.c - Win32 OSD core clipboard access functions
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "strconv.h"
|
||||
|
||||
//============================================================
|
||||
// get_clipboard_text_by_format
|
||||
//============================================================
|
||||
|
||||
static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
|
||||
{
|
||||
char *result = NULL;
|
||||
HANDLE data_handle;
|
||||
LPVOID data;
|
||||
|
||||
// check to see if this format is available
|
||||
if (IsClipboardFormatAvailable(format))
|
||||
{
|
||||
// open the clipboard
|
||||
if (OpenClipboard(NULL))
|
||||
{
|
||||
// try to access clipboard data
|
||||
data_handle = GetClipboardData(format);
|
||||
if (data_handle != NULL)
|
||||
{
|
||||
// lock the data
|
||||
data = GlobalLock(data_handle);
|
||||
if (data != NULL)
|
||||
{
|
||||
// invoke the convert
|
||||
result = (*convert)(data);
|
||||
|
||||
// unlock the data
|
||||
GlobalUnlock(data_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// close out the clipboard
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_wide
|
||||
//============================================================
|
||||
|
||||
static char *convert_wide(LPCVOID data)
|
||||
{
|
||||
return utf8_from_wstring((LPCWSTR) data);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// convert_ansi
|
||||
//============================================================
|
||||
|
||||
static char *convert_ansi(LPCVOID data)
|
||||
{
|
||||
return utf8_from_astring((LPCSTR) data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_get_clipboard_text
|
||||
//============================================================
|
||||
|
||||
char *osd_get_clipboard_text(void)
|
||||
{
|
||||
char *result;
|
||||
|
||||
// try to access unicode text
|
||||
result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
|
||||
|
||||
// try to access ANSI text
|
||||
if (result == NULL)
|
||||
result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user