[gtk+/wip/attachment-parameters: 1/3] gdkattachmentparameters: add GdkAttachmentParameters



commit d4cad3d76ad18498374621cf40ae51a359ff156f
Author: William Hua <william hua canonical com>
Date:   Fri Sep 18 13:40:36 2015 -0400

    gdkattachmentparameters: add GdkAttachmentParameters

 gdk/Makefile.am                      |    3 +
 gdk/gdk.h                            |    1 +
 gdk/gdkattachmentparameters.c        |  171 ++++++++++++++++++++++++++++++++++
 gdk/gdkattachmentparameters.h        |  102 ++++++++++++++++++++
 gdk/gdkattachmentparametersprivate.h |   31 ++++++
 5 files changed, 308 insertions(+), 0 deletions(-)
---
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index dea10d1..c32404b 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -63,6 +63,7 @@ gdk_public_h_sources =                                \
        gdk.h                                   \
        gdk-autocleanup.h                       \
        gdkapplaunchcontext.h                   \
+       gdkattachmentparameters.h               \
        gdkcairo.h                              \
        gdkcursor.h                             \
        gdkdevice.h                             \
@@ -102,6 +103,7 @@ gdk_h_sources =                                     \
 gdk_private_headers =                          \
        gdk-private.h                           \
        gdkapplaunchcontextprivate.h            \
+       gdkattachmentparametersprivate.h        \
        gdkcursorprivate.h                      \
        gdkdevicemanagerprivate.h               \
        gdkdeviceprivate.h                      \
@@ -126,6 +128,7 @@ gdk_c_sources =                             \
        gdk-private.c                           \
        gdk.c                                   \
        gdkapplaunchcontext.c                   \
+       gdkattachmentparameters.c               \
        gdkcairo.c                              \
        gdkcursor.c                             \
        gdkdeprecated.c                         \
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 65246d7..d88bfb9 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -30,6 +30,7 @@
 #include <gdk/gdkconfig.h>
 #include <gdk/gdkversionmacros.h>
 #include <gdk/gdkapplaunchcontext.h>
+#include <gdk/gdkattachmentparameters.h>
 #include <gdk/gdkcairo.h>
 #include <gdk/gdkcursor.h>
 #include <gdk/gdkdevice.h>
diff --git a/gdk/gdkattachmentparameters.c b/gdk/gdkattachmentparameters.c
new file mode 100644
index 0000000..b459665
--- /dev/null
+++ b/gdk/gdkattachmentparameters.c
@@ -0,0 +1,171 @@
+#include "config.h"
+
+#include "gdkattachmentparameters.h"
+#include "gdkattachmentparametersprivate.h"
+
+GdkAttachmentParameters *
+gdk_attachment_parameters_new (void)
+{
+  return g_new0 (GdkAttachmentParameters, 1);
+}
+
+gpointer
+gdk_attachment_parameters_copy (gconstpointer src,
+                                gpointer      data)
+{
+  GdkAttachmentParameters *copy;
+  const GdkAttachmentParameters *parameters;
+
+  if (!src)
+    return NULL;
+
+  parameters = src;
+
+  copy = g_memdup (parameters, sizeof (*parameters));
+
+  copy->primary_options = g_list_copy (parameters->primary_options);
+  copy->secondary_options = g_list_copy (parameters->secondary_options);
+
+  return copy;
+}
+
+void
+gdk_attachment_parameters_free (gpointer data)
+{
+  GdkAttachmentParameters *parameters;
+
+  if (!data)
+    return;
+
+  parameters = data;
+
+  if (parameters->position_callback_user_data && parameters->position_callback_destroy_notify)
+    parameters->position_callback_destroy_notify (parameters->position_callback_user_data);
+
+  g_list_free (parameters->secondary_options);
+  g_list_free (parameters->primary_options);
+
+  g_free (parameters);
+}
+
+void
+gdk_attachment_parameters_set_attachment_origin (GdkAttachmentParameters *parameters,
+                                                 const GdkPoint          *origin)
+{
+  GdkPoint zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->attachment_origin = origin ? *origin : zero;
+}
+
+void
+gdk_attachment_parameters_set_attachment_rectangle (GdkAttachmentParameters *parameters,
+                                                    const GdkRectangle      *rectangle)
+{
+  g_return_if_fail (parameters);
+
+  if (rectangle)
+    {
+      parameters->has_attachment_rectangle = TRUE;
+      parameters->attachment_rectangle = *rectangle;
+    }
+  else
+    parameters->has_attachment_rectangle = FALSE;
+}
+
+void
+gdk_attachment_parameters_set_relative_offset (GdkAttachmentParameters *parameters,
+                                               const GdkPoint          *offset)
+{
+  GdkPoint zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->relative_offset = offset ? *offset : zero;
+}
+
+void
+gdk_attachment_parameters_set_window_padding (GdkAttachmentParameters    *parameters,
+                                              const GdkAttachmentPadding *padding)
+{
+  GdkAttachmentPadding zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->window_padding = padding ? *padding : zero;
+}
+
+void
+gdk_attachment_parameters_set_right_to_left (GdkAttachmentParameters *parameters,
+                                             gboolean                 is_right_to_left)
+{
+  g_return_if_fail (parameters);
+
+  parameters->is_right_to_left = is_right_to_left;
+}
+
+static void
+add_options (GList               **list,
+             GdkAttachmentOption   first_option,
+             va_list               args)
+{
+  GdkAttachmentOption option;
+
+  for (option = first_option; option; option = va_arg (args, GdkAttachmentOption))
+    *list = g_list_append (*list, GINT_TO_POINTER (option));
+}
+
+void
+gdk_attachment_parameters_add_primary_options (GdkAttachmentParameters *parameters,
+                                               GdkAttachmentOption      first_option,
+                                               ...)
+{
+  va_list args;
+
+  g_return_if_fail (parameters);
+
+  va_start (args, first_option);
+
+  add_options (&parameters->primary_options, first_option, args);
+
+  va_end (args);
+}
+
+void
+gdk_attachment_parameters_add_secondary_options (GdkAttachmentParameters *parameters,
+                                                 GdkAttachmentOption      first_option,
+                                                 ...)
+{
+  va_list args;
+
+  g_return_if_fail (parameters);
+
+  va_start (args, first_option);
+
+  add_options (&parameters->secondary_options, first_option, args);
+
+  va_end (args);
+}
+
+void
+gdk_attachment_parameters_set_position_callback (GdkAttachmentParameters       *parameters,
+                                                 GdkAttachmentPositionCallback  callback,
+                                                 gpointer                       user_data,
+                                                 GDestroyNotify                 destroy_notify)
+{
+  g_return_if_fail (parameters);
+
+  parameters->position_callback = callback;
+
+  if (user_data != parameters->position_callback_user_data)
+    {
+      if (parameters->position_callback_user_data && parameters->position_callback_destroy_notify)
+        parameters->position_callback_destroy_notify (parameters->position_callback_user_data);
+
+      parameters->position_callback_user_data = user_data;
+      parameters->position_callback_destroy_notify = destroy_notify;
+    }
+  else if (user_data)
+    g_warning ("gdk_attachment_parameters_set_position_callback (): parameters already own user data");
+}
diff --git a/gdk/gdkattachmentparameters.h b/gdk/gdkattachmentparameters.h
new file mode 100644
index 0000000..f38adf0
--- /dev/null
+++ b/gdk/gdkattachmentparameters.h
@@ -0,0 +1,102 @@
+#ifndef __GDK_ATTACHMENT_PARAMETERS_H__
+#define __GDK_ATTACHMENT_PARAMETERS_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdktypes.h>
+#include <gdk/gdkversionmacros.h>
+
+G_BEGIN_DECLS
+
+enum _GdkAttachmentOption
+{
+  GDK_ATTACHMENT_END_OPTIONS,
+  GDK_ATTACHMENT_FORCE_FIRST_OPTION,
+  GDK_ATTACHMENT_FORCE_LAST_OPTION,
+  GDK_ATTACHMENT_ATTACH_TOP_EDGE,
+  GDK_ATTACHMENT_ATTACH_LEFT_EDGE,
+  GDK_ATTACHMENT_ATTACH_RIGHT_EDGE,
+  GDK_ATTACHMENT_ATTACH_BOTTOM_EDGE,
+  GDK_ATTACHMENT_ATTACH_FORWARD_EDGE,
+  GDK_ATTACHMENT_ATTACH_BACKWARD_EDGE,
+  GDK_ATTACHMENT_ALIGN_TOP_EDGES,
+  GDK_ATTACHMENT_ALIGN_LEFT_EDGES,
+  GDK_ATTACHMENT_ALIGN_RIGHT_EDGES,
+  GDK_ATTACHMENT_ALIGN_BOTTOM_EDGES,
+  GDK_ATTACHMENT_ALIGN_FORWARD_EDGES,
+  GDK_ATTACHMENT_ALIGN_BACKWARD_EDGES,
+  GDK_ATTACHMENT_CENTER_HORIZONTALLY,
+  GDK_ATTACHMENT_CENTER_VERTICALLY,
+  GDK_ATTACHMENT_CENTER_ON_TOP_EDGE,
+  GDK_ATTACHMENT_CENTER_ON_LEFT_EDGE,
+  GDK_ATTACHMENT_CENTER_ON_RIGHT_EDGE,
+  GDK_ATTACHMENT_CENTER_ON_BOTTOM_EDGE,
+  GDK_ATTACHMENT_CENTER_ON_FORWARD_EDGE,
+  GDK_ATTACHMENT_CENTER_ON_BACKWARD_EDGE
+};
+
+struct _GdkAttachmentPadding
+{
+  gint top;
+  gint left;
+  gint right;
+  gint bottom;
+};
+
+typedef enum _GdkAttachmentOption GdkAttachmentOption;
+typedef struct _GdkAttachmentPadding GdkAttachmentPadding;
+typedef struct _GdkAttachmentParameters GdkAttachmentParameters;
+typedef void (*GdkAttachmentPositionCallback) (const GdkPoint *offset,
+                                               gconstpointer   user_data);
+
+GDK_AVAILABLE_IN_3_18
+GdkAttachmentParameters * gdk_attachment_parameters_new                      (void);
+
+GDK_AVAILABLE_IN_3_18
+gpointer                  gdk_attachment_parameters_copy                     (gconstpointer                  
src,
+                                                                              gpointer                       
data);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_free                     (gpointer                       
data);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_attachment_origin    (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkPoint                
*origin);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_attachment_rectangle (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkRectangle            
*rectangle);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_relative_offset      (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkPoint                
*offset);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_window_padding       (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkAttachmentPadding    
*padding);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_right_to_left        (GdkAttachmentParameters       
*parameters,
+                                                                              gboolean                       
is_right_to_left);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_add_primary_options      (GdkAttachmentParameters       
*parameters,
+                                                                              GdkAttachmentOption            
first_option,
+                                                                              ...) G_GNUC_NULL_TERMINATED;
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_add_secondary_options    (GdkAttachmentParameters       
*parameters,
+                                                                              GdkAttachmentOption            
first_option,
+                                                                              ...) G_GNUC_NULL_TERMINATED;
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_position_callback    (GdkAttachmentParameters       
*parameters,
+                                                                              GdkAttachmentPositionCallback  
callback,
+                                                                              gpointer                       
user_data,
+                                                                              GDestroyNotify                 
destroy_notify);
+
+G_END_DECLS
+
+#endif /* __GDK_ATTACHMENT_PARAMETERS_H__ */
diff --git a/gdk/gdkattachmentparametersprivate.h b/gdk/gdkattachmentparametersprivate.h
new file mode 100644
index 0000000..4600c16
--- /dev/null
+++ b/gdk/gdkattachmentparametersprivate.h
@@ -0,0 +1,31 @@
+#ifndef __GDK_ATTACHMENT_PARAMETERS_PRIVATE_H__
+#define __GDK_ATTACHMENT_PARAMETERS_PRIVATE_H__
+
+#include "gdkattachmentparameters.h"
+
+G_BEGIN_DECLS
+
+struct _GdkAttachmentParameters
+{
+  GdkPoint attachment_origin;
+
+  gboolean has_attachment_rectangle;
+  GdkRectangle attachment_rectangle;
+
+  GdkPoint relative_offset;
+
+  GdkAttachmentPadding window_padding;
+
+  gboolean is_right_to_left;
+
+  GList *primary_options;
+  GList *secondary_options;
+
+  GdkAttachmentPositionCallback position_callback;
+  gpointer position_callback_user_data;
+  GDestroyNotify position_callback_destroy_notify;
+};
+
+G_END_DECLS
+
+#endif /* __GDK_ATTACHMENT_PARAMETERS_PRIVATE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]