[metacity] tabpopup.c: split out MetaSelectImage



commit 62ffc362ae3d709dfddc873d0db6f49778520f08
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Oct 4 00:47:37 2014 +0300

    tabpopup.c: split out MetaSelectImage

 src/Makefile.am       |    2 +
 src/ui/select-image.c |  124 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/ui/select-image.h |   48 +++++++++++++++++++
 src/ui/tabpopup.c     |  115 +---------------------------------------------
 4 files changed, 175 insertions(+), 114 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 55e8de9..465d637 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -92,6 +92,8 @@ metacity_SOURCES=                             \
        include/resizepopup.h                   \
        ui/tabpopup.c                           \
        include/tabpopup.h                              \
+       ui/select-image.c \
+       ui/select-image.h \
        ui/tile-preview.c \
        include/tile-preview.h \
        ui/theme-parser.c                       \
diff --git a/src/ui/select-image.c b/src/ui/select-image.c
new file mode 100644
index 0000000..22db457
--- /dev/null
+++ b/src/ui/select-image.c
@@ -0,0 +1,124 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Metacity popup window thing showing windows you can tab to */
+
+/* 
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (C) 2005 Elijah Newren
+ * 
+ * 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 2 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 "select-image.h"
+
+#define OUTSIDE_SELECT_RECT 2
+#define INSIDE_SELECT_RECT 2
+
+static void     meta_select_image_class_init   (MetaSelectImageClass *klass);
+static gboolean meta_select_image_draw         (GtkWidget            *widget,
+                                                cairo_t              *cr);
+
+static GtkImageClass *parent_class;
+
+GType
+meta_select_image_get_type (void)
+{
+  static GType image_type = 0;
+
+  if (!image_type)
+    {
+      static const GTypeInfo image_info =
+      {
+        sizeof (MetaSelectImageClass),
+        NULL,           /* base_init */
+        NULL,           /* base_finalize */
+        (GClassInitFunc) meta_select_image_class_init,
+        NULL,           /* class_finalize */
+        NULL,           /* class_data */
+        sizeof (MetaSelectImage),
+        16,             /* n_preallocs */
+        (GInstanceInitFunc) NULL,
+      };
+
+      image_type = g_type_register_static (GTK_TYPE_IMAGE, "MetaSelectImage", &image_info, 0);
+    }
+
+  return image_type;
+}
+
+static void
+meta_select_image_class_init (MetaSelectImageClass *klass)
+{
+  GtkWidgetClass *widget_class;
+  
+  parent_class = g_type_class_peek (gtk_image_get_type ());
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+  
+  widget_class->draw= meta_select_image_draw;
+}
+
+static gboolean
+meta_select_image_draw (GtkWidget *widget,
+                        cairo_t   *cr)
+{
+  GtkAllocation allocation;
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  if (META_SELECT_IMAGE (widget)->selected)
+    {
+      GtkMisc *misc;
+      GtkRequisition requisition;
+      GtkStyleContext *context;
+      GdkRGBA color;
+      int x, y, w, h;
+      gint xpad, ypad;
+      gfloat xalign, yalign;
+
+      misc = GTK_MISC (widget);
+      
+      gtk_widget_get_preferred_size (widget, &requisition, 0);
+      gtk_misc_get_alignment (misc, &xalign, &yalign);
+      gtk_misc_get_padding (misc, &xpad, &ypad);
+
+      x = (allocation.width - (requisition.width - xpad * 2)) * xalign + 0.5;
+      y = (allocation.height - (requisition.height - ypad * 2)) * yalign + 0.5;
+
+      x -= INSIDE_SELECT_RECT + 1;
+      y -= INSIDE_SELECT_RECT + 1;       
+      
+      w = requisition.width - OUTSIDE_SELECT_RECT * 2 - 1;
+      h = requisition.height - OUTSIDE_SELECT_RECT * 2 - 1;
+
+      context = gtk_widget_get_style_context (widget);
+
+      gtk_style_context_set_state (context,
+                                   gtk_widget_get_state_flags (widget));
+
+      gtk_style_context_lookup_color (context, "color", &color);
+
+      cairo_set_line_width (cr, 2.0);
+      cairo_set_source_rgb (cr, color.red, color.green, color.blue);
+
+      cairo_rectangle (cr, x, y, w + 1, h + 1);
+      cairo_stroke (cr);
+
+      cairo_set_line_width (cr, 1.0);
+    }
+
+  return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
+}
diff --git a/src/ui/select-image.h b/src/ui/select-image.h
new file mode 100644
index 0000000..f42c769
--- /dev/null
+++ b/src/ui/select-image.h
@@ -0,0 +1,48 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Metacity popup window thing showing windows you can tab to */
+
+/* 
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (C) 2005 Elijah Newren
+ * 
+ * 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 2 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 SELECT_IMAGE_H
+#define SELECT_IMAGE_H
+
+#include <gtk/gtk.h>
+
+#define META_TYPE_SELECT_IMAGE            (meta_select_image_get_type ())
+#define META_SELECT_IMAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_IMAGE, 
MetaSelectImage))
+
+typedef struct _MetaSelectImage       MetaSelectImage;
+typedef struct _MetaSelectImageClass  MetaSelectImageClass;
+
+struct _MetaSelectImage
+{
+  GtkImage parent_instance;
+  guint selected : 1;
+};
+
+struct _MetaSelectImageClass
+{
+  GtkImageClass parent_class;
+};
+
+GType meta_select_image_get_type (void) G_GNUC_CONST;
+
+#endif
diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c
index a6ca434..4b88d29 100644
--- a/src/ui/tabpopup.c
+++ b/src/ui/tabpopup.c
@@ -26,6 +26,7 @@
 #include "util.h"
 #include "core.h"
 #include "tabpopup.h"
+#include "select-image.h"
 /* FIXME these two includes are 100% broken ...
  */
 #include "../core/workspace.h"
@@ -587,25 +588,7 @@ meta_ui_tab_popup_select (MetaTabPopup *popup,
     }
 }
 
-#define META_TYPE_SELECT_IMAGE            (meta_select_image_get_type ())
-#define META_SELECT_IMAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_IMAGE, 
MetaSelectImage))
 
-typedef struct _MetaSelectImage       MetaSelectImage;
-typedef struct _MetaSelectImageClass  MetaSelectImageClass;
-
-struct _MetaSelectImage
-{
-  GtkImage parent_instance;
-  guint selected : 1;
-};
-
-struct _MetaSelectImageClass
-{
-  GtkImageClass parent_class;
-};
-
-
-static GType meta_select_image_get_type (void) G_GNUC_CONST;
 
 static GtkWidget*
 selectable_image_new (GdkPixbuf *pixbuf)
@@ -632,102 +615,6 @@ unselect_image (GtkWidget *widget)
   gtk_widget_queue_draw (widget);
 }
 
-static void     meta_select_image_class_init   (MetaSelectImageClass *klass);
-static gboolean meta_select_image_draw         (GtkWidget            *widget,
-                                                cairo_t              *cr);
-
-static GtkImageClass *parent_class;
-
-GType
-meta_select_image_get_type (void)
-{
-  static GType image_type = 0;
-
-  if (!image_type)
-    {
-      static const GTypeInfo image_info =
-      {
-        sizeof (MetaSelectImageClass),
-        NULL,           /* base_init */
-        NULL,           /* base_finalize */
-        (GClassInitFunc) meta_select_image_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (MetaSelectImage),
-        16,             /* n_preallocs */
-        (GInstanceInitFunc) NULL,
-      };
-
-      image_type = g_type_register_static (GTK_TYPE_IMAGE, "MetaSelectImage", &image_info, 0);
-    }
-
-  return image_type;
-}
-
-static void
-meta_select_image_class_init (MetaSelectImageClass *klass)
-{
-  GtkWidgetClass *widget_class;
-  
-  parent_class = g_type_class_peek (gtk_image_get_type ());
-
-  widget_class = GTK_WIDGET_CLASS (klass);
-  
-  widget_class->draw= meta_select_image_draw;
-}
-
-static gboolean
-meta_select_image_draw (GtkWidget *widget,
-                        cairo_t   *cr)
-{
-  GtkAllocation allocation;
-
-  gtk_widget_get_allocation (widget, &allocation);
-
-  if (META_SELECT_IMAGE (widget)->selected)
-    {
-      GtkMisc *misc;
-      GtkRequisition requisition;
-      GtkStyleContext *context;
-      GdkRGBA color;
-      int x, y, w, h;
-      gint xpad, ypad;
-      gfloat xalign, yalign;
-
-      misc = GTK_MISC (widget);
-      
-      gtk_widget_get_preferred_size (widget, &requisition, 0);
-      gtk_misc_get_alignment (misc, &xalign, &yalign);
-      gtk_misc_get_padding (misc, &xpad, &ypad);
-
-      x = (allocation.width - (requisition.width - xpad * 2)) * xalign + 0.5;
-      y = (allocation.height - (requisition.height - ypad * 2)) * yalign + 0.5;
-
-      x -= INSIDE_SELECT_RECT + 1;
-      y -= INSIDE_SELECT_RECT + 1;       
-      
-      w = requisition.width - OUTSIDE_SELECT_RECT * 2 - 1;
-      h = requisition.height - OUTSIDE_SELECT_RECT * 2 - 1;
-
-      context = gtk_widget_get_style_context (widget);
-
-      gtk_style_context_set_state (context,
-                                   gtk_widget_get_state_flags (widget));
-
-      gtk_style_context_lookup_color (context, "color", &color);
-
-      cairo_set_line_width (cr, 2.0);
-      cairo_set_source_rgb (cr, color.red, color.green, color.blue);
-
-      cairo_rectangle (cr, x, y, w + 1, h + 1);
-      cairo_stroke (cr);
-
-      cairo_set_line_width (cr, 1.0);
-    }
-
-  return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
-}
-
 #define META_TYPE_SELECT_WORKSPACE   (meta_select_workspace_get_type ())
 #define META_SELECT_WORKSPACE(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_WORKSPACE, 
MetaSelectWorkspace))
 


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