* src/haiku_select.cc (get_clipboard_object): New function.
(BClipboard_find_data, BClipboard_get_targets, BClipboard_set_data)
(BClipboard_find_system_data)
(BClipboard_find_primary_selection_data)
(BClipboard_find_secondary_selection_data)
(BClipboard_set_system_data, BClipboard_set_primary_selection_data)
(BClipboard_set_secondary_selection_data, BClipboard_free_data)
(BClipboard_system_targets, BClipboard_primary_targets)
(BClipboard_secondary_targets): Delete functions.
(be_find_clipboard_data_1, be_set_clipboard_data_1)
(be_get_clipboard_targets_1, be_find_clipboard_data)
(be_set_clipboard_data, be_get_clipboard_targets): New
functions.
(be_lock_clipboard_message, be_unlock_clipboard): Use
`get_clipboard_object' to get clipboard from ID.
* src/haikuselect.c (haiku_get_clipboard_name): New function.
(Fhaiku_selection_data, Fhaiku_selection_put)
(Fhaiku_selection_owner_p): Adjust to use new simplified
functions.
* src/haikuselect.h: Update prototypes.
static int64 count_primary = -1;
static int64 count_secondary = -1;
+static BClipboard *
+get_clipboard_object (enum haiku_clipboard clipboard)
+{
+ switch (clipboard)
+ {
+ case CLIPBOARD_PRIMARY:
+ return primary;
+
+ case CLIPBOARD_SECONDARY:
+ return secondary;
+
+ case CLIPBOARD_CLIPBOARD:
+ return system_clipboard;
+ }
+
+ abort ();
+}
+
static char *
-BClipboard_find_data (BClipboard *cb, const char *type, ssize_t *len)
+be_find_clipboard_data_1 (BClipboard *cb, const char *type, ssize_t *len)
{
+ BMessage *data;
+ const char *ptr;
+ ssize_t nbytes;
+ void *value;
+
if (!cb->Lock ())
- return 0;
+ return NULL;
- BMessage *dat = cb->Data ();
- if (!dat)
+ data = cb->Data ();
+
+ if (!data)
{
cb->Unlock ();
- return 0;
+ return NULL;
}
- const char *ptr;
- ssize_t bt;
- dat->FindData (type, B_MIME_TYPE, (const void **) &ptr, &bt);
+ data->FindData (type, B_MIME_TYPE, (const void **) &ptr,
+ &nbytes);
if (!ptr)
{
}
if (len)
- *len = bt;
+ *len = nbytes;
- void *data = malloc (bt);
+ value = malloc (nbytes);
if (!data)
{
return NULL;
}
- memcpy (data, ptr, bt);
+ memcpy (value, ptr, nbytes);
cb->Unlock ();
- return (char *) data;
+
+ return (char *) value;
}
static void
-BClipboard_get_targets (BClipboard *cb, char **buf, int buf_size)
+be_get_clipboard_targets_1 (BClipboard *cb, char **buf, int buf_size)
{
BMessage *data;
char *name;
}
static void
-BClipboard_set_data (BClipboard *cb, const char *type, const char *dat,
- ssize_t len, bool clear)
+be_set_clipboard_data_1 (BClipboard *cb, const char *type, const char *data,
+ ssize_t len, bool clear)
{
+ BMessage *message_data;
+
if (!cb->Lock ())
return;
if (clear)
cb->Clear ();
- BMessage *mdat = cb->Data ();
- if (!mdat)
+ message_data = cb->Data ();
+
+ if (!message_data)
{
cb->Unlock ();
return;
}
- if (dat)
+ if (data)
{
- if (mdat->ReplaceData (type, B_MIME_TYPE, dat, len)
+ if (message_data->ReplaceData (type, B_MIME_TYPE, data, len)
== B_NAME_NOT_FOUND)
- mdat->AddData (type, B_MIME_TYPE, dat, len);
+ message_data->AddData (type, B_MIME_TYPE, data, len);
}
else
- mdat->RemoveName (type);
+ message_data->RemoveName (type);
+
cb->Commit ();
cb->Unlock ();
}
char *
-BClipboard_find_system_data (const char *type, ssize_t *len)
-{
- if (!system_clipboard)
- return 0;
-
- return BClipboard_find_data (system_clipboard, type, len);
-}
-
-char *
-BClipboard_find_primary_selection_data (const char *type, ssize_t *len)
-{
- if (!primary)
- return 0;
-
- return BClipboard_find_data (primary, type, len);
-}
-
-char *
-BClipboard_find_secondary_selection_data (const char *type, ssize_t *len)
-{
- if (!secondary)
- return 0;
-
- return BClipboard_find_data (secondary, type, len);
-}
-
-void
-BClipboard_set_system_data (const char *type, const char *data,
- ssize_t len, bool clear)
-{
- if (!system_clipboard)
- return;
-
- count_clipboard = system_clipboard->SystemCount ();
- BClipboard_set_data (system_clipboard, type, data, len, clear);
-}
-
-void
-BClipboard_set_primary_selection_data (const char *type, const char *data,
- ssize_t len, bool clear)
-{
- if (!primary)
- return;
-
- count_primary = primary->SystemCount ();
- BClipboard_set_data (primary, type, data, len, clear);
-}
-
-void
-BClipboard_set_secondary_selection_data (const char *type, const char *data,
- ssize_t len, bool clear)
+be_find_clipboard_data (enum haiku_clipboard id, const char *type,
+ ssize_t *len)
{
- if (!secondary)
- return;
-
- count_secondary = secondary->SystemCount ();
- BClipboard_set_data (secondary, type, data, len, clear);
+ return be_find_clipboard_data_1 (get_clipboard_object (id),
+ type, len);
}
void
-BClipboard_free_data (void *ptr)
+be_set_clipboard_data (enum haiku_clipboard id, const char *type,
+ const char *data, ssize_t len, bool clear)
{
- std::free (ptr);
+ be_set_clipboard_data_1 (get_clipboard_object (id), type,
+ data, len, clear);
}
void
-BClipboard_system_targets (char **buf, int len)
+be_get_clipboard_targets (enum haiku_clipboard id, char **targets,
+ int len)
{
- BClipboard_get_targets (system_clipboard, buf, len);
-}
-
-void
-BClipboard_primary_targets (char **buf, int len)
-{
- BClipboard_get_targets (primary, buf, len);
-}
-
-void
-BClipboard_secondary_targets (char **buf, int len)
-{
- BClipboard_get_targets (secondary, buf, len);
+ be_get_clipboard_targets_1 (get_clipboard_object (id), targets,
+ len);
}
bool
{
BClipboard *board;
- if (clipboard == CLIPBOARD_PRIMARY)
- board = primary;
- else if (clipboard == CLIPBOARD_SECONDARY)
- board = secondary;
- else
- board = system_clipboard;
+ board = get_clipboard_object (clipboard);
if (!board->Lock ())
return 1;
{
BClipboard *board;
- if (clipboard == CLIPBOARD_PRIMARY)
- board = primary;
- else if (clipboard == CLIPBOARD_SECONDARY)
- board = secondary;
- else
- board = system_clipboard;
+ board = get_clipboard_object (clipboard);
if (discard)
board->Revert ();
static void haiku_lisp_to_message (Lisp_Object, void *);
+static enum haiku_clipboard
+haiku_get_clipboard_name (Lisp_Object clipboard)
+{
+ if (EQ (clipboard, QPRIMARY))
+ return CLIPBOARD_PRIMARY;
+
+ if (EQ (clipboard, QSECONDARY))
+ return CLIPBOARD_SECONDARY;
+
+ if (EQ (clipboard, QCLIPBOARD))
+ return CLIPBOARD_CLIPBOARD;
+
+ signal_error ("Invalid clipboard", clipboard);
+}
+
DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data,
2, 2, 0,
doc: /* Retrieve content typed as NAME from the clipboard
int rc;
CHECK_SYMBOL (clipboard);
-
- if (!EQ (clipboard, QPRIMARY) && !EQ (clipboard, QSECONDARY)
- && !EQ (clipboard, QCLIPBOARD))
- signal_error ("Invalid clipboard", clipboard);
+ clipboard_name = haiku_get_clipboard_name (clipboard);
if (!NILP (name))
{
CHECK_STRING (name);
block_input ();
- if (EQ (clipboard, QPRIMARY))
- dat = BClipboard_find_primary_selection_data (SSDATA (name), &len);
- else if (EQ (clipboard, QSECONDARY))
- dat = BClipboard_find_secondary_selection_data (SSDATA (name), &len);
- else
- dat = BClipboard_find_system_data (SSDATA (name), &len);
+ dat = be_find_clipboard_data (clipboard_name,
+ SSDATA (name), &len);
unblock_input ();
if (!dat)
Qforeign_selection, Qt, str);
block_input ();
- BClipboard_free_data (dat);
+ free (dat);
unblock_input ();
}
else
{
- if (EQ (clipboard, QPRIMARY))
- clipboard_name = CLIPBOARD_PRIMARY;
- else if (EQ (clipboard, QSECONDARY))
- clipboard_name = CLIPBOARD_SECONDARY;
- else
- clipboard_name = CLIPBOARD_CLIPBOARD;
-
block_input ();
rc = be_lock_clipboard_message (clipboard_name, &message, false);
unblock_input ();
int rc;
void *message;
+ CHECK_SYMBOL (clipboard);
+ clipboard_name = haiku_get_clipboard_name (clipboard);
+
if (CONSP (name) || NILP (name))
{
- if (EQ (clipboard, QPRIMARY))
- clipboard_name = CLIPBOARD_PRIMARY;
- else if (EQ (clipboard, QSECONDARY))
- clipboard_name = CLIPBOARD_SECONDARY;
- else if (EQ (clipboard, QCLIPBOARD))
- clipboard_name = CLIPBOARD_CLIPBOARD;
- else
- signal_error ("Invalid clipboard", clipboard);
-
rc = be_lock_clipboard_message (clipboard_name,
&message, true);
return unbind_to (ref, Qnil);
}
- CHECK_SYMBOL (clipboard);
CHECK_STRING (name);
if (!NILP (data))
CHECK_STRING (data);
dat = !NILP (data) ? SSDATA (data) : NULL;
len = !NILP (data) ? SBYTES (data) : 0;
- if (EQ (clipboard, QPRIMARY))
- BClipboard_set_primary_selection_data (SSDATA (name), dat, len,
- !NILP (clear));
- else if (EQ (clipboard, QSECONDARY))
- BClipboard_set_secondary_selection_data (SSDATA (name), dat, len,
- !NILP (clear));
- else if (EQ (clipboard, QCLIPBOARD))
- BClipboard_set_system_data (SSDATA (name), dat, len, !NILP (clear));
- else
- {
- unblock_input ();
- signal_error ("Bad clipboard", clipboard);
- }
-
+ be_set_clipboard_data (clipboard_name, SSDATA (name), dat, len,
+ !NILP (clear));
return Qnil;
}
0, 1, 0,
doc: /* Whether the current Emacs process owns the given SELECTION.
The arg should be the name of the selection in question, typically one
-of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. For
-convenience, the symbol nil is the same as `PRIMARY', and t is the
-same as `SECONDARY'. */)
+of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
(Lisp_Object selection)
{
bool value;
- if (NILP (selection))
- selection = QPRIMARY;
- else if (EQ (selection, Qt))
- selection = QSECONDARY;
-
block_input ();
if (EQ (selection, QPRIMARY))
value = BClipboard_owns_primary ();
#endif
/* Whether or not the selection was recently changed. */
-/* Find a string with the MIME type TYPE in the system clipboard. */
-extern char *BClipboard_find_system_data (const char *, ssize_t *);
-extern char *BClipboard_find_primary_selection_data (const char *, ssize_t *);
-extern char *BClipboard_find_secondary_selection_data (const char *, ssize_t *);
-
-extern void BClipboard_set_system_data (const char *, const char *, ssize_t, bool);
-extern void BClipboard_set_primary_selection_data (const char *, const char *,
- ssize_t, bool);
-extern void BClipboard_set_secondary_selection_data (const char *, const char *,
- ssize_t, bool);
-
-extern void BClipboard_system_targets (char **, int);
-extern void BClipboard_primary_targets (char **, int);
-extern void BClipboard_secondary_targets (char **, int);
+extern char *be_find_clipboard_data (enum haiku_clipboard, const char *, ssize_t *);
+extern void be_set_clipboard_data (enum haiku_clipboard, const char *, const char *,
+ ssize_t, bool);
+extern void be_get_clipboard_targets (enum haiku_clipboard, char **, int);
extern bool BClipboard_owns_clipboard (void);
extern bool BClipboard_owns_primary (void);
extern bool BClipboard_owns_secondary (void);
-/* Free the returned data. */
-extern void BClipboard_free_data (void *);
-
extern int be_enum_message (void *, int32 *, int32, int32 *, const char **);
extern int be_get_message_data (void *, const char *, int32, int32,
const void **, ssize_t *);