[gimp] app: add GimpPickablePopup which will allow picking any image/layer's



commit 52aa22f6aaaeb60e02e18fb2db6f013394103dc8
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jun 6 01:47:12 2014 +0200

    app: add GimpPickablePopup which will allow picking any image/layer's
    
    For now contains a dysfunctional image list.

 app/widgets/Makefile.am          |    2 +
 app/widgets/gimppickablebutton.c |   34 +++++
 app/widgets/gimppickablepopup.c  |  279 ++++++++++++++++++++++++++++++++++++++
 app/widgets/gimppickablepopup.h  |   59 ++++++++
 app/widgets/widgets-types.h      |    1 +
 5 files changed, 375 insertions(+), 0 deletions(-)
---
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index 73d3641..cc85911 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -266,6 +266,8 @@ libappwidgets_a_sources = \
        gimppdbdialog.h                 \
        gimppickablebutton.c            \
        gimppickablebutton.h            \
+       gimppickablepopup.c             \
+       gimppickablepopup.h             \
        gimppixbuf.c                    \
        gimppixbuf.h                    \
        gimppluginaction.c              \
diff --git a/app/widgets/gimppickablebutton.c b/app/widgets/gimppickablebutton.c
index 2f525db..841808e 100644
--- a/app/widgets/gimppickablebutton.c
+++ b/app/widgets/gimppickablebutton.c
@@ -37,6 +37,7 @@
 #include "gimpview.h"
 #include "gimpviewrenderer.h"
 #include "gimppickablebutton.h"
+#include "gimppickablepopup.h"
 
 
 enum
@@ -72,6 +73,10 @@ static void     gimp_pickable_button_get_property  (GObject            *object,
 
 static void     gimp_pickable_button_clicked       (GtkButton          *button);
 
+static void     gimp_pickable_button_popup_cancel  (GimpPickablePopup  *popup,
+                                                    GimpPickableButton *button);
+static void     gimp_pickable_button_popup_confirm (GimpPickablePopup  *popup,
+                                                    GimpPickableButton *button);
 static void     gimp_pickable_button_drop_pickable (GtkWidget          *widget,
                                                     gint                x,
                                                     gint                y,
@@ -146,6 +151,8 @@ gimp_pickable_button_constructed (GObject *object)
 {
   GimpPickableButton *button = GIMP_PICKABLE_BUTTON (object);
 
+  G_OBJECT_CLASS (parent_class)->constructed (object);
+
   g_assert (GIMP_IS_CONTEXT (button->private->context));
 
   button->private->view =
@@ -234,6 +241,33 @@ gimp_pickable_button_get_property (GObject    *object,
 static void
 gimp_pickable_button_clicked (GtkButton *button)
 {
+  GimpPickableButton *pickable_button = GIMP_PICKABLE_BUTTON (button);
+  GtkWidget          *popup;
+
+  popup = gimp_pickable_popup_new (pickable_button->private->context,
+                                   pickable_button->private->view_size,
+                                   pickable_button->private->view_border_width);
+
+  g_signal_connect (popup, "cancel",
+                    G_CALLBACK (gimp_pickable_button_popup_cancel),
+                    button);
+  g_signal_connect (popup, "confirm",
+                    G_CALLBACK (gimp_pickable_button_popup_confirm),
+                    button);
+
+  gimp_popup_show (GIMP_POPUP (popup), GTK_WIDGET (button));
+}
+
+static void
+gimp_pickable_button_popup_cancel (GimpPickablePopup  *popup,
+                                   GimpPickableButton *button)
+{
+}
+
+static void
+gimp_pickable_button_popup_confirm (GimpPickablePopup  *popup,
+                                    GimpPickableButton *button)
+{
 }
 
 static void
diff --git a/app/widgets/gimppickablepopup.c b/app/widgets/gimppickablepopup.c
new file mode 100644
index 0000000..b7d2795
--- /dev/null
+++ b/app/widgets/gimppickablepopup.c
@@ -0,0 +1,279 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppickablepopup.c
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "widgets-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpcontext.h"
+#include "core/gimppickable.h"
+#include "core/gimpviewable.h"
+
+#include "gimpcontainertreeview.h"
+#include "gimppickablepopup.h"
+#include "gimpviewrenderer.h"
+
+#include "gimp-intl.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_CONTEXT,
+  PROP_PICKABLE,
+  PROP_VIEW_SIZE,
+  PROP_VIEW_BORDER_WIDTH
+};
+
+struct _GimpPickablePopupPrivate
+{
+  GimpPickable *pickable;
+  GimpContext  *context;
+
+  gint          view_size;
+  gint          view_border_width;
+};
+
+
+static void   gimp_pickable_popup_constructed  (GObject      *object);
+static void   gimp_pickable_popup_finalize     (GObject      *object);
+static void   gimp_pickable_popup_set_property (GObject      *object,
+                                                guint         property_id,
+                                                const GValue *value,
+                                                GParamSpec   *pspec);
+static void   gimp_pickable_popup_get_property (GObject      *object,
+                                                guint         property_id,
+                                                GValue       *value,
+                                                GParamSpec   *pspec);
+
+static void   gimp_pickable_popup_confirm      (GimpPopup    *popup);
+
+
+G_DEFINE_TYPE (GimpPickablePopup, gimp_pickable_popup, GIMP_TYPE_POPUP)
+
+#define parent_class gimp_pickable_popup_parent_class
+
+
+static void
+gimp_pickable_popup_class_init (GimpPickablePopupClass *klass)
+{
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+  GimpPopupClass *popup_class  = GIMP_POPUP_CLASS (klass);
+
+  object_class->constructed  = gimp_pickable_popup_constructed;
+  object_class->finalize     = gimp_pickable_popup_finalize;
+  object_class->get_property = gimp_pickable_popup_get_property;
+  object_class->set_property = gimp_pickable_popup_set_property;
+
+  popup_class->confirm       = gimp_pickable_popup_confirm;
+
+  g_object_class_install_property (object_class, PROP_CONTEXT,
+                                   g_param_spec_object ("context",
+                                                        NULL, NULL,
+                                                        GIMP_TYPE_CONTEXT,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
+
+  g_object_class_install_property (object_class, PROP_PICKABLE,
+                                   g_param_spec_object ("pickable",
+                                                        NULL, NULL,
+                                                        GIMP_TYPE_PICKABLE,
+                                                        GIMP_PARAM_READABLE));
+
+  g_object_class_install_property (object_class, PROP_VIEW_SIZE,
+                                   g_param_spec_int ("view-size",
+                                                     NULL, NULL,
+                                                     1, GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
+                                                     GIMP_VIEW_SIZE_MEDIUM,
+                                                     GIMP_PARAM_READWRITE |
+                                                     G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (object_class, PROP_VIEW_BORDER_WIDTH,
+                                   g_param_spec_int ("view-border-width",
+                                                     NULL, NULL,
+                                                     0,
+                                                     GIMP_VIEW_MAX_BORDER_WIDTH,
+                                                     1,
+                                                     GIMP_PARAM_READWRITE |
+                                                     G_PARAM_CONSTRUCT));
+
+  g_type_class_add_private (klass, sizeof (GimpPickablePopupPrivate));
+}
+
+static void
+gimp_pickable_popup_init (GimpPickablePopup *popup)
+{
+  popup->priv = G_TYPE_INSTANCE_GET_PRIVATE (popup,
+                                             GIMP_TYPE_PICKABLE_POPUP,
+                                             GimpPickablePopupPrivate);
+
+  popup->priv->view_size         = GIMP_VIEW_SIZE_SMALL;
+  popup->priv->view_border_width = 1;
+
+  gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
+}
+
+static void
+gimp_pickable_popup_constructed (GObject *object)
+{
+  GimpPickablePopup *popup = GIMP_PICKABLE_POPUP (object);
+  GtkWidget         *frame;
+  GtkWidget         *image_view;
+
+  G_OBJECT_CLASS (parent_class)->constructed (object);
+
+  g_assert (GIMP_IS_CONTEXT (popup->priv->context));
+
+  frame = gtk_frame_new (NULL);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
+  gtk_container_add (GTK_CONTAINER (popup), frame);
+  gtk_widget_show (frame);
+
+  image_view = gimp_container_tree_view_new (popup->priv->context->gimp->images,
+                                             popup->priv->context,
+                                             popup->priv->view_size,
+                                             popup->priv->view_border_width);
+  gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (image_view),
+                                       4 * (popup->priv->view_size +
+                                            2 * popup->priv->view_border_width),
+                                       4 * (popup->priv->view_size +
+                                            2 * popup->priv->view_border_width));
+  gtk_container_set_border_width (GTK_CONTAINER (image_view), 6);
+  gtk_container_add (GTK_CONTAINER (frame), image_view);
+  gtk_widget_show (image_view);
+}
+
+static void
+gimp_pickable_popup_finalize (GObject *object)
+{
+  GimpPickablePopup *popup = GIMP_PICKABLE_POPUP (object);
+
+  if (popup->priv->pickable)
+    {
+      g_object_unref (popup->priv->pickable);
+      popup->priv->pickable = NULL;
+    }
+
+  if (popup->priv->context)
+    {
+      g_object_unref (popup->priv->context);
+      popup->priv->context = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gimp_pickable_popup_set_property (GObject      *object,
+                                  guint         property_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  GimpPickablePopup *popup = GIMP_PICKABLE_POPUP (object);
+
+  switch (property_id)
+    {
+    case PROP_CONTEXT:
+      if (popup->priv->context)
+        g_object_unref (popup->priv->context);
+      popup->priv->context = g_value_dup_object (value);
+      break;
+
+    case PROP_VIEW_SIZE:
+      popup->priv->view_size = g_value_get_int (value);
+      break;
+
+    case PROP_VIEW_BORDER_WIDTH:
+      popup->priv->view_border_width = g_value_get_int (value);
+      break;
+
+    case PROP_PICKABLE:
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_pickable_popup_get_property (GObject    *object,
+                                  guint       property_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  GimpPickablePopup *popup = GIMP_PICKABLE_POPUP (object);
+
+  switch (property_id)
+    {
+    case PROP_CONTEXT:
+      g_value_set_object (value, popup->priv->context);
+      break;
+
+    case PROP_PICKABLE:
+      g_value_set_object (value, popup->priv->pickable);
+      break;
+
+    case PROP_VIEW_SIZE:
+      g_value_set_int (value, popup->priv->view_size);
+      break;
+
+    case PROP_VIEW_BORDER_WIDTH:
+      g_value_set_int (value, popup->priv->view_border_width);
+      break;
+
+   default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_pickable_popup_confirm (GimpPopup *popup)
+{
+  /* GimpPickablePopup *c_popup = GIMP_PICKABLE_POPUP (popup); */
+
+  GIMP_POPUP_CLASS (parent_class)->confirm (popup);
+}
+
+GtkWidget *
+gimp_pickable_popup_new (GimpContext *context,
+                         gint         view_size,
+                         gint         view_border_width)
+{
+  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (view_size >  0 &&
+                        view_size <= GIMP_VIEWABLE_MAX_POPUP_SIZE, NULL);
+  g_return_val_if_fail (view_border_width >= 0 &&
+                        view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
+                        NULL);
+
+  return g_object_new (GIMP_TYPE_PICKABLE_POPUP,
+                       "type",              GTK_WINDOW_POPUP,
+                       "context",           context,
+                       "view-size",         view_size,
+                       "view-border-width", view_border_width,
+                       NULL);
+}
diff --git a/app/widgets/gimppickablepopup.h b/app/widgets/gimppickablepopup.h
new file mode 100644
index 0000000..e2d34d4
--- /dev/null
+++ b/app/widgets/gimppickablepopup.h
@@ -0,0 +1,59 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppickablepopup.h
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PICKABLE_POPUP_H__
+#define __GIMP_PICKABLE_POPUP_H__
+
+
+#include "gimppopup.h"
+
+
+#define GIMP_TYPE_PICKABLE_POPUP            (gimp_pickable_popup_get_type ())
+#define GIMP_PICKABLE_POPUP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PICKABLE_POPUP, 
GimpPickablePopup))
+#define GIMP_PICKABLE_POPUP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PICKABLE_POPUP, 
GimpPickablePopupClass))
+#define GIMP_IS_PICKABLE_POPUP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PICKABLE_POPUP))
+#define GIMP_IS_PICKABLE_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PICKABLE_POPUP))
+#define GIMP_PICKABLE_POPUP_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PICKABLE_POPUP, 
GimpPickablePopupClass))
+
+
+typedef struct _GimpPickablePopupPrivate GimpPickablePopupPrivate;
+typedef struct _GimpPickablePopupClass   GimpPickablePopupClass;
+
+struct _GimpPickablePopup
+{
+  GimpPopup                 parent_instance;
+
+  GimpPickablePopupPrivate *priv;
+};
+
+struct _GimpPickablePopupClass
+{
+  GimpPopupClass  parent_instance;
+};
+
+
+GType       gimp_pickable_popup_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_pickable_popup_new      (GimpContext *context,
+                                          gint         view_size,
+                                          gint         view_border_width);
+
+
+#endif  /*  __GIMP_PICKABLE_POPUP_H__  */
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index 3bb1680..b037638 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -189,6 +189,7 @@ typedef struct _GimpLanguageStore            GimpLanguageStore;
 typedef struct _GimpMessageBox               GimpMessageBox;
 typedef struct _GimpOverlayBox               GimpOverlayBox;
 typedef struct _GimpPickableButton           GimpPickableButton;
+typedef struct _GimpPickablePopup            GimpPickablePopup;
 typedef struct _GimpPolar                    GimpPolar;
 typedef struct _GimpPopup                    GimpPopup;
 typedef struct _GimpPrefsBox                 GimpPrefsBox;


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