#include "haikuselect.h"
+/* The clipboard object representing the primary selection. */
static BClipboard *primary = NULL;
+
+/* The clipboard object representing the secondary selection. */
static BClipboard *secondary = NULL;
+
+/* The clipboard object used by other programs, representing the
+ clipboard. */
static BClipboard *system_clipboard = NULL;
+
+/* The number of times the system clipboard has changed. */
static int64 count_clipboard = -1;
+
+/* The number of times the primary selection has changed. */
static int64 count_primary = -1;
+
+/* The number of times the secondary selection has changed. */
static int64 count_secondary = -1;
static BClipboard *
cb->Unlock ();
}
+void
+be_update_clipboard_count (enum haiku_clipboard id)
+{
+ switch (id)
+ {
+ case CLIPBOARD_CLIPBOARD:
+ count_clipboard = system_clipboard->SystemCount ();
+ break;
+
+ case CLIPBOARD_PRIMARY:
+ count_primary = primary->SystemCount ();
+ break;
+
+ case CLIPBOARD_SECONDARY:
+ count_secondary = secondary->SystemCount ();
+ break;
+ }
+}
+
char *
be_find_clipboard_data (enum haiku_clipboard id, const char *type,
ssize_t *len)
be_set_clipboard_data (enum haiku_clipboard id, const char *type,
const char *data, ssize_t len, bool clear)
{
+ be_update_clipboard_count (id);
+
be_set_clipboard_data_1 (get_clipboard_object (id), type,
data, len, clear);
}
len);
}
-bool
-BClipboard_owns_clipboard (void)
+static bool
+clipboard_owner_p (void)
{
return (count_clipboard >= 0
&& (count_clipboard + 1
== system_clipboard->SystemCount ()));
}
-bool
-BClipboard_owns_primary (void)
+static bool
+primary_owner_p (void)
{
return (count_primary >= 0
&& (count_primary + 1
== primary->SystemCount ()));
}
-bool
-BClipboard_owns_secondary (void)
+static bool
+secondary_owner_p (void)
{
return (count_secondary >= 0
&& (count_secondary + 1
== secondary->SystemCount ()));
}
+bool
+be_clipboard_owner_p (enum haiku_clipboard clipboard)
+{
+ switch (clipboard)
+ {
+ case CLIPBOARD_PRIMARY:
+ return primary_owner_p ();
+
+ case CLIPBOARD_SECONDARY:
+ return secondary_owner_p ();
+
+ case CLIPBOARD_CLIPBOARD:
+ return clipboard_owner_p ();
+ }
+
+ abort ();
+}
+
void
init_haiku_select (void)
{
if (CONSP (name) || NILP (name))
{
+ be_update_clipboard_count (clipboard_name);
+
rc = be_lock_clipboard_message (clipboard_name,
&message, true);
(Lisp_Object selection)
{
bool value;
+ enum haiku_clipboard name;
block_input ();
- if (EQ (selection, QPRIMARY))
- value = BClipboard_owns_primary ();
- else if (EQ (selection, QSECONDARY))
- value = BClipboard_owns_secondary ();
- else if (EQ (selection, QCLIPBOARD))
- value = BClipboard_owns_clipboard ();
- else
- value = false;
+ name = haiku_get_clipboard_name (selection);
+ value = be_clipboard_owner_p (name);
unblock_input ();
return value ? Qt : Qnil;
#ifdef __cplusplus
extern "C"
{
+/* Also declared in haikuterm.h for use in emacs.c. */
extern void init_haiku_select (void);
#endif
/* Whether or not the selection was recently changed. */
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);
+extern bool be_clipboard_owner_p (enum haiku_clipboard);
+extern void be_update_clipboard_count (enum haiku_clipboard);
extern int be_enum_message (void *, int32 *, int32, int32 *, const char **);
extern int be_get_message_data (void *, const char *, int32, int32,