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



commit b26183c79b14f5f30f6ad7b5b203574ef4fd0075
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        |  199 ++++++++++++++++++++++++++++++++++
 gdk/gdkattachmentparameters.h        |  125 +++++++++++++++++++++
 gdk/gdkattachmentparametersprivate.h |   33 ++++++
 5 files changed, 361 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..c551e5a
--- /dev/null
+++ b/gdk/gdkattachmentparameters.c
@@ -0,0 +1,199 @@
+#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_attachment_margin (GdkAttachmentParameters   *parameters,
+                                                 const GdkAttachmentBorder *margin)
+{
+  GdkAttachmentBorder zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->attachment_margin = margin ? *margin : zero;
+}
+
+void
+gdk_attachment_parameters_set_window_margin (GdkAttachmentParameters   *parameters,
+                                             const GdkAttachmentBorder *margin)
+{
+  GdkAttachmentBorder zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->window_margin = margin ? *margin : zero;
+}
+
+void
+gdk_attachment_parameters_set_window_padding (GdkAttachmentParameters   *parameters,
+                                              const GdkAttachmentBorder *padding)
+{
+  GdkAttachmentBorder zero = { 0 };
+
+  g_return_if_fail (parameters);
+
+  parameters->window_padding = padding ? *padding : zero;
+}
+
+GdkWindowTypeHint
+gdk_attachment_parameters_get_window_type_hint (GdkAttachmentParameters *parameters)
+{
+  g_return_val_if_fail (parameters, GDK_WINDOW_TYPE_HINT_NORMAL);
+
+  return parameters->window_type_hint;
+}
+
+void
+gdk_attachment_parameters_set_window_type_hint (GdkAttachmentParameters *parameters,
+                                                GdkWindowTypeHint        window_type_hint)
+{
+  g_return_if_fail (parameters);
+
+  parameters->window_type_hint = window_type_hint;
+}
+
+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 ("%s (): parameters already owns user data", G_STRFUNC);
+}
diff --git a/gdk/gdkattachmentparameters.h b/gdk/gdkattachmentparameters.h
new file mode 100644
index 0000000..cf7cdc8
--- /dev/null
+++ b/gdk/gdkattachmentparameters.h
@@ -0,0 +1,125 @@
+#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_FIRST_OPTION_IF_PRIMARY_FORCED,
+  GDK_ATTACHMENT_FORCE_LAST_OPTION,
+  GDK_ATTACHMENT_FORCE_LAST_OPTION_IF_PRIMARY_FORCED,
+  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,
+  GDK_ATTACHMENT_ATTACH_ABOVE_CENTER,
+  GDK_ATTACHMENT_ATTACH_BELOW_CENTER,
+  GDK_ATTACHMENT_ATTACH_LEFT_OF_CENTER,
+  GDK_ATTACHMENT_ATTACH_RIGHT_OF_CENTER,
+  GDK_ATTACHMENT_ATTACH_FORWARD_OF_CENTER,
+  GDK_ATTACHMENT_ATTACH_BACKWARD_OF_CENTER
+};
+
+struct _GdkAttachmentBorder
+{
+  gint top;
+  gint left;
+  gint right;
+  gint bottom;
+};
+
+typedef enum _GdkAttachmentOption GdkAttachmentOption;
+typedef struct _GdkAttachmentBorder GdkAttachmentBorder;
+typedef struct _GdkAttachmentParameters GdkAttachmentParameters;
+typedef void (*GdkAttachmentPositionCallback) (GdkWindow           *window,
+                                               GdkAttachmentOption  primary_option,
+                                               GdkAttachmentOption  secondary_option,
+                                               const GdkPoint      *position,
+                                               const GdkPoint      *offset,
+                                               gpointer             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_attachment_margin    (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkAttachmentBorder     
*margin);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_window_margin        (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkAttachmentBorder     
*margin);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_window_padding       (GdkAttachmentParameters       
*parameters,
+                                                                              const GdkAttachmentBorder     
*padding);
+
+GDK_AVAILABLE_IN_3_18
+GdkWindowTypeHint         gdk_attachment_parameters_get_window_type_hint     (GdkAttachmentParameters       
*parameters);
+
+GDK_AVAILABLE_IN_3_18
+void                      gdk_attachment_parameters_set_window_type_hint     (GdkAttachmentParameters       
*parameters,
+                                                                              GdkWindowTypeHint              
window_type_hint);
+
+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..7d04f7e
--- /dev/null
+++ b/gdk/gdkattachmentparametersprivate.h
@@ -0,0 +1,33 @@
+#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;
+
+  GdkAttachmentBorder attachment_margin;
+  GdkAttachmentBorder window_margin;
+  GdkAttachmentBorder window_padding;
+
+  GdkWindowTypeHint window_type_hint;
+
+  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]