forked from enlightenment/efl
ecore_cocoa: change clipboard API
the new API works with mimetypes, so we can remove the cnp types from Ecore_Cocoa.h and just forward the types from ecore_evas directly Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D11350
This commit is contained in:
parent
165f6f0ae2
commit
06b7933512
|
@ -196,22 +196,6 @@ struct _Ecore_Cocoa_Event_Window_Destroy
|
||||||
Ecore_Cocoa_Object *cocoa_window; /**< Handler of the Cocoa window */
|
Ecore_Cocoa_Object *cocoa_window; /**< Handler of the Cocoa window */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef Ecore_Cocoa_Cnp_Type
|
|
||||||
* Type used to interact with the Cocoa pasteboard.
|
|
||||||
* It holds types that can apply to a context.
|
|
||||||
* @since 1.18
|
|
||||||
*/
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ECORE_COCOA_CNP_TYPE_UNKNOWN = 0, /**< Undefined type */
|
|
||||||
ECORE_COCOA_CNP_TYPE_STRING = (1 << 0), /**< String type (pure text) */
|
|
||||||
ECORE_COCOA_CNP_TYPE_MARKUP = (1 << 1), /**< Elementary markup */
|
|
||||||
ECORE_COCOA_CNP_TYPE_IMAGE = (1 << 2), /**< Image (all formats) */
|
|
||||||
ECORE_COCOA_CNP_TYPE_HTML = (1 << 3) /**< HTML */
|
|
||||||
} Ecore_Cocoa_Cnp_Type;
|
|
||||||
|
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Core *
|
* Core *
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
@ -561,27 +545,22 @@ EAPI void ecore_cocoa_terminate_cb_set(Ecore_Cocoa_Terminate_Cb cb)
|
||||||
* Sets the clipboard of Cocoa (NSPasteboard)
|
* Sets the clipboard of Cocoa (NSPasteboard)
|
||||||
* @param data The contents to be set in the clipboard
|
* @param data The contents to be set in the clipboard
|
||||||
* @param size The size in bytes of @c data
|
* @param size The size in bytes of @c data
|
||||||
* @param type
|
* @param mine_type
|
||||||
* @return EINA_TRUE on success, EINA_FALSE on failure
|
* @return EINA_TRUE on success, EINA_FALSE on failure
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool ecore_cocoa_clipboard_set(const void *data,
|
EAPI Eina_Bool ecore_cocoa_clipboard_set(const void *data,
|
||||||
int size,
|
int size,
|
||||||
Ecore_Cocoa_Cnp_Type type);
|
const char *mime_type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the contents of the Cocoa clipboard
|
* Gets the contents of the Cocoa clipboard
|
||||||
* @param size Pointer used to retrieve the size of the received contents
|
* @param size Pointer used to retrieve the size of the received contents
|
||||||
* @param type The type of object to retrieve from the clipboard
|
* @param mine_type The type of object to retrieve from the clipboard
|
||||||
* @param retrieved_types The types of objects retrieved from the clipboard
|
|
||||||
* @return The data retrieved from the clipboard. NULL on failure
|
* @return The data retrieved from the clipboard. NULL on failure
|
||||||
*
|
*
|
||||||
* If @c type was ECORE_COCOA_CNP_TYPE_STRING or ECORE_COCOA_CNP_TYPE_MARKUP,
|
|
||||||
* @c retrieved_types will contain ECORE_COCOA_CNP_TYPE_STRING and the data
|
|
||||||
* will be a C string (char*) that must be freed after use.
|
|
||||||
*/
|
*/
|
||||||
EAPI void *ecore_cocoa_clipboard_get(int *size,
|
EAPI void *ecore_cocoa_clipboard_get(int *size,
|
||||||
Ecore_Cocoa_Cnp_Type type,
|
const char *mime_type)
|
||||||
Ecore_Cocoa_Cnp_Type *retrieved_types)
|
|
||||||
EINA_WARN_UNUSED_RESULT;
|
EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -589,6 +568,11 @@ EAPI void *ecore_cocoa_clipboard_get(int *size,
|
||||||
*/
|
*/
|
||||||
EAPI void ecore_cocoa_clipboard_clear(void);
|
EAPI void ecore_cocoa_clipboard_clear(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true when the clipboard contains data that can be received.
|
||||||
|
*/
|
||||||
|
EAPI Eina_Bool ecore_cocoa_clipboard_exists(void);
|
||||||
|
|
||||||
#endif /* EFL_BETA_API_SUPPORT */
|
#endif /* EFL_BETA_API_SUPPORT */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -9,16 +9,17 @@
|
||||||
#import "ecore_cocoa_app.h"
|
#import "ecore_cocoa_app.h"
|
||||||
|
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
ecore_cocoa_clipboard_set(const void *data,
|
ecore_cocoa_clipboard_set(const void *data,
|
||||||
int size,
|
int size,
|
||||||
Ecore_Cocoa_Cnp_Type type)
|
const char *raw_mime_type)
|
||||||
{
|
{
|
||||||
NSMutableArray *objects;
|
NSMutableArray *objects;
|
||||||
NSString *str = nil;
|
NSString *str = nil;
|
||||||
BOOL ok = YES;
|
BOOL ok = YES;
|
||||||
|
NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
|
||||||
|
|
||||||
objects = [[NSMutableArray alloc] init];
|
objects = [[NSMutableArray alloc] init];
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_STRING)
|
if ([mime_type hasPrefix:@"text/"])
|
||||||
{
|
{
|
||||||
str = [[NSString alloc] initWithBytes: data
|
str = [[NSString alloc] initWithBytes: data
|
||||||
length: size
|
length: size
|
||||||
|
@ -26,18 +27,9 @@ ecore_cocoa_clipboard_set(const void *data,
|
||||||
if (str)
|
if (str)
|
||||||
[objects addObject: str];
|
[objects addObject: str];
|
||||||
}
|
}
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
else
|
||||||
{
|
{
|
||||||
WRN("Markup CNP: NOT IMPLEMENTED");
|
ERR("Mimetype %s is not handled yet", raw_mime_type);
|
||||||
}
|
|
||||||
|
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
|
|
||||||
{
|
|
||||||
WRN("Image CNP: NOT IMPLEMENTED");
|
|
||||||
}
|
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_HTML)
|
|
||||||
{
|
|
||||||
WRN("HTML CNP: NOT IMPLEMENTED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write to pasteboard */
|
/* Write to pasteboard */
|
||||||
|
@ -54,35 +46,45 @@ ecore_cocoa_clipboard_set(const void *data,
|
||||||
return (ok) ? EINA_TRUE : EINA_FALSE;
|
return (ok) ? EINA_TRUE : EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI Eina_Bool
|
||||||
|
ecore_cocoa_clipboard_exists(void)
|
||||||
|
{
|
||||||
|
NSDictionary *options;
|
||||||
|
NSPasteboard *pb;
|
||||||
|
NSArray *items;
|
||||||
|
NSMutableArray *classes;
|
||||||
|
|
||||||
|
classes = [[NSMutableArray alloc] init];
|
||||||
|
[classes addObject: [NSString class]]; // we only support strings for now
|
||||||
|
pb = [NSPasteboard generalPasteboard];
|
||||||
|
options = [NSDictionary dictionary];
|
||||||
|
return [pb canReadItemWithDataConformingToTypes: classes];
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void *
|
EAPI void *
|
||||||
ecore_cocoa_clipboard_get(int *size,
|
ecore_cocoa_clipboard_get(int *size,
|
||||||
Ecore_Cocoa_Cnp_Type type,
|
const char *raw_mime_type)
|
||||||
Ecore_Cocoa_Cnp_Type *retrieved_types)
|
|
||||||
{
|
{
|
||||||
NSMutableArray *classes;
|
NSMutableArray *classes;
|
||||||
void *data;
|
void *data = NULL;
|
||||||
NSDictionary *options;
|
NSDictionary *options;
|
||||||
NSPasteboard *pb;
|
NSPasteboard *pb;
|
||||||
NSArray *items;
|
NSArray *items;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
BOOL string_class = NO;
|
BOOL string_class = NO;
|
||||||
Ecore_Cocoa_Cnp_Type types = 0;
|
NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
|
||||||
|
|
||||||
classes = [[NSMutableArray alloc] init];
|
classes = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_STRING)
|
if ([mime_type hasPrefix:@"text/"])
|
||||||
{
|
{
|
||||||
string_class = YES;
|
string_class = YES;
|
||||||
[classes addObject: [NSString class]];
|
[classes addObject: [NSString class]];
|
||||||
}
|
}
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
|
else
|
||||||
{
|
{
|
||||||
WRN("Image CNP: NOT IMPLEMENTED");
|
ERR("Mimetype %s is not handled yet", raw_mime_type);
|
||||||
}
|
goto fail;
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_HTML)
|
|
||||||
{
|
|
||||||
WRN("HTML CNP: NOT IMPLEMENTED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([classes count] <= 0)
|
if ([classes count] <= 0)
|
||||||
|
@ -120,7 +122,6 @@ ecore_cocoa_clipboard_get(int *size,
|
||||||
(const char *)data, len);
|
(const char *)data, len);
|
||||||
goto remove_fail;
|
goto remove_fail;
|
||||||
}
|
}
|
||||||
types |= ECORE_COCOA_CNP_TYPE_STRING;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
||||||
|
@ -139,7 +140,7 @@ ecore_cocoa_clipboard_get(int *size,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!types)
|
if (!data)
|
||||||
{
|
{
|
||||||
ERR("No types retrieved!");
|
ERR("No types retrieved!");
|
||||||
goto remove_fail;
|
goto remove_fail;
|
||||||
|
@ -148,14 +149,12 @@ ecore_cocoa_clipboard_get(int *size,
|
||||||
[classes removeAllObjects];
|
[classes removeAllObjects];
|
||||||
|
|
||||||
if (size) *size = len;
|
if (size) *size = len;
|
||||||
if (retrieved_types) *retrieved_types = types;
|
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
remove_fail:
|
remove_fail:
|
||||||
[classes removeAllObjects];
|
[classes removeAllObjects];
|
||||||
fail:
|
fail:
|
||||||
if (size) *size = 0;
|
if (size) *size = 0;
|
||||||
if (retrieved_types) *retrieved_types = 0;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue