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 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 *
|
||||
*============================================================================*/
|
||||
|
@ -561,27 +545,22 @@ EAPI void ecore_cocoa_terminate_cb_set(Ecore_Cocoa_Terminate_Cb cb)
|
|||
* Sets the clipboard of Cocoa (NSPasteboard)
|
||||
* @param data The contents to be set in the clipboard
|
||||
* @param size The size in bytes of @c data
|
||||
* @param type
|
||||
* @param mine_type
|
||||
* @return EINA_TRUE on success, EINA_FALSE on failure
|
||||
*/
|
||||
EAPI Eina_Bool ecore_cocoa_clipboard_set(const void *data,
|
||||
int size,
|
||||
Ecore_Cocoa_Cnp_Type type);
|
||||
int size,
|
||||
const char *mime_type);
|
||||
|
||||
/*
|
||||
* Gets the contents of the Cocoa clipboard
|
||||
* @param size Pointer used to retrieve the size of the received contents
|
||||
* @param type The type of object to retrieve from the clipboard
|
||||
* @param retrieved_types The types of objects retrieved from the clipboard
|
||||
* @param mine_type The type of object to retrieve from the clipboard
|
||||
* @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,
|
||||
Ecore_Cocoa_Cnp_Type type,
|
||||
Ecore_Cocoa_Cnp_Type *retrieved_types)
|
||||
const char *mime_type)
|
||||
EINA_WARN_UNUSED_RESULT;
|
||||
|
||||
/*
|
||||
|
@ -589,6 +568,11 @@ EAPI void *ecore_cocoa_clipboard_get(int *size,
|
|||
*/
|
||||
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 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -9,16 +9,17 @@
|
|||
#import "ecore_cocoa_app.h"
|
||||
|
||||
EAPI Eina_Bool
|
||||
ecore_cocoa_clipboard_set(const void *data,
|
||||
int size,
|
||||
Ecore_Cocoa_Cnp_Type type)
|
||||
ecore_cocoa_clipboard_set(const void *data,
|
||||
int size,
|
||||
const char *raw_mime_type)
|
||||
{
|
||||
NSMutableArray *objects;
|
||||
NSString *str = nil;
|
||||
BOOL ok = YES;
|
||||
NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
|
||||
|
||||
objects = [[NSMutableArray alloc] init];
|
||||
if (type & ECORE_COCOA_CNP_TYPE_STRING)
|
||||
if ([mime_type hasPrefix:@"text/"])
|
||||
{
|
||||
str = [[NSString alloc] initWithBytes: data
|
||||
length: size
|
||||
|
@ -26,18 +27,9 @@ ecore_cocoa_clipboard_set(const void *data,
|
|||
if (str)
|
||||
[objects addObject: str];
|
||||
}
|
||||
if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
||||
else
|
||||
{
|
||||
WRN("Markup CNP: NOT IMPLEMENTED");
|
||||
}
|
||||
|
||||
if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
|
||||
{
|
||||
WRN("Image CNP: NOT IMPLEMENTED");
|
||||
}
|
||||
if (type & ECORE_COCOA_CNP_TYPE_HTML)
|
||||
{
|
||||
WRN("HTML CNP: NOT IMPLEMENTED");
|
||||
ERR("Mimetype %s is not handled yet", raw_mime_type);
|
||||
}
|
||||
|
||||
/* Write to pasteboard */
|
||||
|
@ -54,35 +46,45 @@ ecore_cocoa_clipboard_set(const void *data,
|
|||
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 *
|
||||
ecore_cocoa_clipboard_get(int *size,
|
||||
Ecore_Cocoa_Cnp_Type type,
|
||||
Ecore_Cocoa_Cnp_Type *retrieved_types)
|
||||
ecore_cocoa_clipboard_get(int *size,
|
||||
const char *raw_mime_type)
|
||||
{
|
||||
NSMutableArray *classes;
|
||||
void *data;
|
||||
void *data = NULL;
|
||||
NSDictionary *options;
|
||||
NSPasteboard *pb;
|
||||
NSArray *items;
|
||||
unsigned int len;
|
||||
BOOL string_class = NO;
|
||||
Ecore_Cocoa_Cnp_Type types = 0;
|
||||
NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
|
||||
|
||||
classes = [[NSMutableArray alloc] init];
|
||||
|
||||
if (type & ECORE_COCOA_CNP_TYPE_STRING)
|
||||
if ([mime_type hasPrefix:@"text/"])
|
||||
{
|
||||
string_class = YES;
|
||||
[classes addObject: [NSString class]];
|
||||
}
|
||||
if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
|
||||
else
|
||||
{
|
||||
WRN("Image CNP: NOT IMPLEMENTED");
|
||||
}
|
||||
if (type & ECORE_COCOA_CNP_TYPE_HTML)
|
||||
{
|
||||
WRN("HTML CNP: NOT IMPLEMENTED");
|
||||
ERR("Mimetype %s is not handled yet", raw_mime_type);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ([classes count] <= 0)
|
||||
|
@ -120,7 +122,6 @@ ecore_cocoa_clipboard_get(int *size,
|
|||
(const char *)data, len);
|
||||
goto remove_fail;
|
||||
}
|
||||
types |= ECORE_COCOA_CNP_TYPE_STRING;
|
||||
|
||||
#if 0
|
||||
if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
||||
|
@ -139,7 +140,7 @@ ecore_cocoa_clipboard_get(int *size,
|
|||
#endif
|
||||
}
|
||||
|
||||
if (!types)
|
||||
if (!data)
|
||||
{
|
||||
ERR("No types retrieved!");
|
||||
goto remove_fail;
|
||||
|
@ -148,14 +149,12 @@ ecore_cocoa_clipboard_get(int *size,
|
|||
[classes removeAllObjects];
|
||||
|
||||
if (size) *size = len;
|
||||
if (retrieved_types) *retrieved_types = types;
|
||||
return data;
|
||||
|
||||
remove_fail:
|
||||
[classes removeAllObjects];
|
||||
fail:
|
||||
if (size) *size = 0;
|
||||
if (retrieved_types) *retrieved_types = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue