summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-04-03 17:54:45 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-04-03 17:55:10 +0200
commit5e80a732aa7f8c6db116ec8753343f40a55034bd (patch)
treecfb1453c0a1f6d94e433e0b699bde9650d9a675d /src
parent0730ffc328dd02b0b85660e056d6390518645b26 (diff)
move clipboard handling on proper place (nw)
Diffstat (limited to 'src')
-rw-r--r--src/osd/modules/lib/osdlib.h10
-rw-r--r--src/osd/modules/lib/osdlib_macosx.cpp83
-rw-r--r--src/osd/modules/lib/osdlib_unix.cpp27
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp74
-rw-r--r--src/osd/osdcore.h5
-rw-r--r--src/osd/sdl/sdlos_macosx.cpp101
-rw-r--r--src/osd/sdl/sdlos_unix.cpp50
-rw-r--r--src/osd/sdl/sdlos_win32.cpp87
-rw-r--r--src/osd/windows/winclip.cpp89
9 files changed, 194 insertions, 332 deletions
diff --git a/src/osd/modules/lib/osdlib.h b/src/osd/modules/lib/osdlib.h
index 484633f137b..dcba7a6bc81 100644
--- a/src/osd/modules/lib/osdlib.h
+++ b/src/osd/modules/lib/osdlib.h
@@ -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__ */
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp
index 34837e8aae4..4d1f839cabd 100644
--- a/src/osd/modules/lib/osdlib_macosx.cpp
+++ b/src/osd/modules/lib/osdlib_macosx.cpp
@@ -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;
+}
diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp
index fd60db54ba9..69abad52f7b 100644
--- a/src/osd/modules/lib/osdlib_unix.cpp
+++ b/src/osd/modules/lib/osdlib_unix.cpp
@@ -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
+
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index 572774d6c4c..c5792f0307d 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -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;
+}
diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h
index 899f024d9f4..623c3ee3f11 100644
--- a/src/osd/osdcore.h
+++ b/src/osd/osdcore.h
@@ -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
diff --git a/src/osd/sdl/sdlos_macosx.cpp b/src/osd/sdl/sdlos_macosx.cpp
deleted file mode 100644
index 5afcfdc54eb..00000000000
--- a/src/osd/sdl/sdlos_macosx.cpp
+++ /dev/null
@@ -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;
-}
diff --git a/src/osd/sdl/sdlos_unix.cpp b/src/osd/sdl/sdlos_unix.cpp
deleted file mode 100644
index 29bb10c6bdd..00000000000
--- a/src/osd/sdl/sdlos_unix.cpp
+++ /dev/null
@@ -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
diff --git a/src/osd/sdl/sdlos_win32.cpp b/src/osd/sdl/sdlos_win32.cpp
deleted file mode 100644
index 0c6a63a8ff4..00000000000
--- a/src/osd/sdl/sdlos_win32.cpp
+++ /dev/null
@@ -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;
-}
diff --git a/src/osd/windows/winclip.cpp b/src/osd/windows/winclip.cpp
deleted file mode 100644
index 7717f4e6188..00000000000
--- a/src/osd/windows/winclip.cpp
+++ /dev/null
@@ -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;
-}