Add attempt to implement a GtkZoom widget, but does not work as expected
authorJoachim Breitner <mail@joachim-breitner.de>
Sun, 25 Nov 2012 15:52:04 +0000 (15:52 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sun, 25 Nov 2012 15:52:04 +0000 (15:52 +0000)
Makefile.am
gtkzoom.c [new file with mode: 0644]
gtkzoom.h [new file with mode: 0644]

index 021a0fb..e26ce4b 100644 (file)
@@ -29,7 +29,7 @@ update-icon-cache:
        fi
 
 dist_man_MANS = sm.6
-EXTRA_DIST = sm.py sm.desktop.in sm.html sm.webapp webapp.html README.Win32 sm.ico sm.rc sm-128.png sm.svg
+EXTRA_DIST = sm.py sm.desktop.in sm.html sm.webapp webapp.html README.Win32 sm.ico sm.rc sm-128.png sm.svg gtkzoom.h gtkzoom.c
 CLEANFILES = sm.desktop 
 
 if WIN32
diff --git a/gtkzoom.c b/gtkzoom.c
new file mode 100644 (file)
index 0000000..9fed867
--- /dev/null
+++ b/gtkzoom.c
@@ -0,0 +1,127 @@
+#include "gtkzoom.h"
+
+struct _GtkZoomPrivate
+{
+       int dummy;
+//  GtkWidget *child;
+};
+
+static gboolean
+gtk_zoom_draw      (GtkWidget      *widget,
+                                     cairo_t        *cr);
+static void
+gtk_zoom_size_allocate (GtkWidget     *widget, GtkAllocation *allocation);
+static void
+gtk_zoom_get_preferred_width (GtkWidget *widget,
+                                 gint      *minimum,
+                                 gint      *natural);
+static void
+gtk_zoom_get_preferred_height (GtkWidget *widget,
+                                 gint      *minimum,
+                                 gint      *natural);
+
+G_DEFINE_TYPE (GtkZoom, gtk_zoom, GTK_TYPE_BIN)
+
+static void
+gtk_zoom_class_init (GtkZoomClass *class)
+{
+  GtkWidgetClass *widget_class = (GtkWidgetClass*) class;
+
+  widget_class->draw          = gtk_zoom_draw;
+  widget_class->size_allocate = gtk_zoom_size_allocate;
+  widget_class->get_preferred_width = gtk_zoom_get_preferred_width;
+  widget_class->get_preferred_height = gtk_zoom_get_preferred_height;
+
+
+  g_type_class_add_private (class, sizeof (GtkZoomPrivate));
+}
+
+static void
+gtk_zoom_init (GtkZoom *zoom)
+{
+  GtkZoomPrivate *priv;
+
+  zoom->priv = G_TYPE_INSTANCE_GET_PRIVATE (zoom,
+                                           GTK_TYPE_ZOOM,
+                                           GtkZoomPrivate);
+  priv = zoom->priv;
+}
+
+GtkWidget*
+gtk_zoom_new (void)
+{
+  return g_object_new (GTK_TYPE_ZOOM, NULL);
+}
+
+
+static void
+gtk_zoom_size_allocate (GtkWidget     *widget, GtkAllocation *allocation)
+{
+  GtkWidget *main_widget;
+
+  GTK_WIDGET_CLASS (gtk_zoom_parent_class)->size_allocate (widget, allocation);
+
+  main_widget = gtk_bin_get_child (GTK_BIN (widget));
+  if (!main_widget || !gtk_widget_get_visible (main_widget))
+    return;
+
+  gtk_widget_size_allocate (main_widget, allocation);
+}
+
+static void
+gtk_zoom_get_preferred_width (GtkWidget *widget,
+                                 gint      *minimum,
+                                 gint      *natural)
+{
+  GtkBin *bin = GTK_BIN (widget);
+  GtkWidget *child;
+
+  if (minimum)
+    *minimum = 0;
+
+  if (natural)
+    *natural = 0;
+
+  child = gtk_bin_get_child (bin);
+  if (child && gtk_widget_get_visible (child))
+    gtk_widget_get_preferred_width (child, minimum, natural);
+}
+
+static void
+gtk_zoom_get_preferred_height (GtkWidget *widget,
+                                  gint      *minimum,
+                                  gint      *natural)
+{
+  GtkBin *bin = GTK_BIN (widget);
+  GtkWidget *child;
+
+  if (minimum)
+    *minimum = 0;
+
+  if (natural)
+    *natural = 0;
+
+  child = gtk_bin_get_child (bin);
+  if (child && gtk_widget_get_visible (child))
+    gtk_widget_get_preferred_height (child, minimum, natural);
+}
+
+
+
+static gboolean
+gtk_zoom_draw (GtkWidget *widget, cairo_t   *cr)
+{
+       GtkWidget *child;
+       child = gtk_bin_get_child (GTK_BIN(widget));
+       if (child) {
+               cairo_save(cr);
+               cairo_scale(cr, 2, 2);
+               gtk_widget_draw(child, cr);
+               cairo_restore(cr);
+       }
+
+       //GTK_WIDGET_CLASS (gtk_zoom_parent_class)->draw (widget, cr);
+
+       return FALSE;
+}
+
diff --git a/gtkzoom.h b/gtkzoom.h
new file mode 100644 (file)
index 0000000..654339b
--- /dev/null
+++ b/gtkzoom.h
@@ -0,0 +1,48 @@
+#ifndef __GTK_ZOOM_H__
+#define __GTK_ZOOM_H__
+
+
+#include <gtk/gtk.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_ZOOM                  (gtk_zoom_get_type ())
+#define GTK_ZOOM(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ZOOM, GtkZoom))
+#define GTK_ZOOM_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ZOOM, GtkZoomClass))
+#define GTK_IS_ZOOM(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ZOOM))
+#define GTK_IS_ZOOM_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ZOOM))
+#define GTK_ZOOM_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ZOOM, GtkZoomClass))
+
+
+typedef struct _GtkZoom              GtkZoom;
+typedef struct _GtkZoomPrivate       GtkZoomPrivate;
+typedef struct _GtkZoomClass         GtkZoomClass;
+
+struct _GtkZoom
+{
+  GtkBin container;
+
+  /*< private >*/
+  GtkZoomPrivate *priv;
+};
+
+struct _GtkZoomClass
+{
+  GtkBinClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+GType      gtk_zoom_get_type  (void) G_GNUC_CONST;
+GtkWidget* gtk_zoom_new       (void);
+
+
+G_END_DECLS
+
+#endif /* __GTK_ZOOM_H__ */