r133 - trunk/src/target/OM-2007/libraries/mokoui

mickey at gta01.hmw-consulting.de mickey at gta01.hmw-consulting.de
Sat Oct 28 00:32:46 CEST 2006


Author: mickey
Date: 2006-10-27 22:32:46 +0000 (Fri, 27 Oct 2006)
New Revision: 133

Added:
   trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.c
   trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.h
Modified:
   trunk/src/target/OM-2007/libraries/mokoui/moko-paned-window.c
   trunk/src/target/OM-2007/libraries/mokoui/mokoui.pro
Log:
mokoui: add MokoAlignment, a GtkAlignment variant that shows a background pixmap


Added: trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.c
===================================================================
--- trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.c	2006-10-27 14:49:19 UTC (rev 132)
+++ trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.c	2006-10-27 22:32:46 UTC (rev 133)
@@ -0,0 +1,178 @@
+/*  moko-alignment.c
+ *
+ *  Authored By Michael 'Mickey' Lauer <mlauer at vanille-media.de>
+ *  Based on GtkAlignment which is (C) 1997-2000 GTK+ Team
+ *
+ *  Copyright (C) 2006 Vanille-Media
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Public License as published by
+ *  the Free Software Foundation; version 2.1 of the license.
+ *
+ *  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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date: 2006/10/05 17:38:14 $) [$Author: mickey $]
+ */
+
+#include "moko-alignment.h"
+
+G_DEFINE_TYPE (MokoAlignment, moko_alignment, GTK_TYPE_ALIGNMENT);
+
+#define MOKO_ALIGNMENT_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOKO_TYPE_ALIGNMENT, MokoAlignmentPrivate))
+
+//FIXME this is a bit hackish
+#define GTK_ALIGNMENT_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ALIGNMENT, GtkAlignmentPrivate))
+typedef struct _GtkAlignmentPrivate
+{
+  guint padding_top;
+  guint padding_bottom;
+  guint padding_left;
+  guint padding_right;
+};
+
+typedef struct _MokoAlignmentPrivate
+{
+} MokoAlignmentPrivate;
+
+/* forward declarations */
+static void
+moko_alignment_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+    GtkAlignment *alignment;
+    GtkBin *bin;
+    GtkAllocation child_allocation;
+    GtkRequisition child_requisition;
+    gint width, height;
+    gint border_width;
+    gint padding_horizontal, padding_vertical;
+    GtkAlignmentPrivate *priv;
+
+    padding_horizontal = 0;
+    padding_vertical = 0;
+
+    widget->allocation = *allocation;
+
+    // <sync. with gdk window>
+    if (GTK_WIDGET_REALIZED (widget))
+        gdk_window_move_resize (widget->window,
+                                allocation->x,
+                                allocation->y,
+                                allocation->width,
+                                allocation->height);
+    // <sync with GdkWindow>
+
+    alignment = GTK_ALIGNMENT (widget);
+    bin = GTK_BIN (widget);
+
+    if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+    {
+        gtk_widget_get_child_requisition (bin->child, &child_requisition);
+
+        border_width = GTK_CONTAINER (alignment)->border_width;
+
+        priv = GTK_ALIGNMENT_GET_PRIVATE (widget);
+        padding_horizontal = priv->padding_left + priv->padding_right;
+        padding_vertical = priv->padding_top + priv->padding_bottom;
+
+        width = allocation->width - padding_horizontal - 2 * border_width;
+        height = allocation->height - padding_vertical - 2 * border_width;
+
+        if (width > child_requisition.width)
+            child_allocation.width = (child_requisition.width *
+                    (1.0 - alignment->xscale) +
+                    width * alignment->xscale);
+        else
+            child_allocation.width = width;
+
+        if (height > child_requisition.height)
+            child_allocation.height = (child_requisition.height *
+                    (1.0 - alignment->yscale) +
+                    height * alignment->yscale);
+        else
+            child_allocation.height = height;
+
+        if (GTK_WIDGET_NO_WINDOW (widget))
+        {
+            if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+                child_allocation.x = (1.0 - alignment->xalign) * (width - child_allocation.width) + allocation->x + border_width + priv->padding_right;
+            else
+                child_allocation.x = alignment->xalign * (width - child_allocation.width) + allocation->x + border_width + priv->padding_left;
+
+            child_allocation.y = alignment->yalign * (height - child_allocation.height) + allocation->y + border_width + priv->padding_top;
+        }
+        else
+        {
+            if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+                child_allocation.x = (1.0 - alignment->xalign) * (width - child_allocation.width) + border_width + priv->padding_right;
+            else
+                child_allocation.x = alignment->xalign * (width - child_allocation.width) + border_width + priv->padding_left;
+
+            child_allocation.y = alignment->yalign * (height - child_allocation.height) + border_width + priv->padding_top;
+        }
+        gtk_widget_size_allocate (bin->child, &child_allocation);
+    }
+}
+
+static void
+moko_alignment_realize (GtkWidget* widget)
+{
+    g_debug( "moko_alignment_realize" );
+
+    GdkWindowAttr attributes;
+    gint attributes_mask;
+
+    GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.x = widget->allocation.x;
+    attributes.y = widget->allocation.y;
+    attributes.width = widget->allocation.width;
+    attributes.height = widget->allocation.height;
+    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.visual = gtk_widget_get_visual (widget);
+    attributes.colormap = gtk_widget_get_colormap (widget);
+    attributes.event_mask = gtk_widget_get_events (widget);
+    attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
+
+    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+    widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
+    gdk_window_set_user_data (widget->window, widget);
+
+    widget->style = gtk_style_attach (widget->style, widget->window);
+    gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+}
+
+static void
+moko_alignment_class_init (MokoAlignmentClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+    /* register private data */
+    g_type_class_add_private (klass, sizeof (MokoAlignmentPrivate));
+
+    /* hook virtual methods */
+    widget_class->realize = moko_alignment_realize;
+    widget_class->size_allocate = moko_alignment_size_allocate;
+
+    /* install properties */
+    /* ... */
+}
+
+static void
+moko_alignment_init (MokoAlignment *self)
+{
+    //FIXME do we need this?
+    //gtk_widget_set_redraw_on_allocate( GTK_WIDGET(self), TRUE );
+    GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET(self), GTK_NO_WINDOW );
+}
+
+MokoAlignment*
+moko_alignment_new (void)
+{
+    return g_object_new (MOKO_TYPE_ALIGNMENT, NULL);
+}


Property changes on: trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.h
===================================================================
--- trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.h	2006-10-27 14:49:19 UTC (rev 132)
+++ trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.h	2006-10-27 22:32:46 UTC (rev 133)
@@ -0,0 +1,50 @@
+/*  moko-alignment.h
+ *
+ *  Authored By Michael 'Mickey' Lauer <mlauer at vanille-media.de>
+ *
+ *  Copyright (C) 2006 Vanille-Media
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Public License as published by
+ *  the Free Software Foundation; version 2.1 of the license.
+ *
+ *  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 Public License for more details.
+ *
+ *  Current Version: $Rev$ ($Date: 2006/10/05 17:38:14 $) [$Author: mickey $]
+ */
+
+#ifndef _MOKO_ALIGNMENT_H_
+#define _MOKO_ALIGNMENT_H_
+
+#include <gtk/gtkalignment.h>
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MOKO_TYPE_ALIGNMENT moko_alignment_get_type()
+#define MOKO_ALIGNMENT(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj),     MOKO_TYPE_ALIGNMENT, MokoAlignment))
+#define MOKO_ALIGNMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass),     MOKO_TYPE_ALIGNMENT, MokoAlignmentClass))
+#define MOKO_IS_ALIGNMENT(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj),     MOKO_TYPE_ALIGNMENT))
+#define MOKO_IS_ALIGNMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass),     MOKO_TYPE_ALIGNMENT))
+#define MOKO_ALIGNMENT_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj),     MOKO_TYPE_ALIGNMENT, MokoAlignmentClass))
+
+typedef struct {
+    GtkAlignment parent;
+} MokoAlignment;
+
+typedef struct {
+    GtkAlignmentClass parent_class;
+} MokoAlignmentClass;
+
+GType moko_alignment_get_type (void);
+
+MokoAlignment* moko_alignment_new (void);
+
+G_END_DECLS
+
+#endif // _MOKO_ALIGNMENT_H_
+


Property changes on: trunk/src/target/OM-2007/libraries/mokoui/moko-alignment.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/src/target/OM-2007/libraries/mokoui/moko-paned-window.c
===================================================================
--- trunk/src/target/OM-2007/libraries/mokoui/moko-paned-window.c	2006-10-27 14:49:19 UTC (rev 132)
+++ trunk/src/target/OM-2007/libraries/mokoui/moko-paned-window.c	2006-10-27 22:32:46 UTC (rev 133)
@@ -17,6 +17,8 @@
  *  Current Version: $Rev$ ($Date$) [$Author$]
  */
 #include "moko-paned-window.h"
+
+#include "moko-alignment.h"
 #include "moko-menubox.h"
 #include "moko-toolbox.h"
 
@@ -30,6 +32,7 @@
 {
     GtkVPaned* outerframe;
     GtkVBox* upper;
+    MokoAlignment* upperenclosing;
     GtkVBox* lower;
     MokoMenuBox* menubox;
     MokoToolBox* toolbox;
@@ -143,7 +146,12 @@
     g_debug( "moko_paned_window_set_upper_pane" );
 
     MokoPanedWindowPriv* priv = MOKO_PANED_WINDOW_GET_PRIVATE(self);
-    gtk_box_pack_end( GTK_BOX(priv->upper), child, TRUE, TRUE, 0 );
+
+    priv->upperenclosing = moko_alignment_new();
+    gtk_alignment_set_padding( GTK_ALIGNMENT(priv->upperenclosing), 10, 10, 10, 10 ); //FIXME get from style
+    gtk_box_pack_end( GTK_BOX(priv->upper), GTK_WIDGET(priv->upperenclosing), TRUE, TRUE, 0 );
+    gtk_container_add( GTK_CONTAINER(priv->upperenclosing), child );
+    //gtk_box_pack_end( GTK_BOX(priv->upper), child, TRUE, TRUE, 0 );
 }
 
 void moko_paned_window_set_lower_pane(MokoPanedWindow* self, GtkWidget* child)

Modified: trunk/src/target/OM-2007/libraries/mokoui/mokoui.pro
===================================================================
--- trunk/src/target/OM-2007/libraries/mokoui/mokoui.pro	2006-10-27 14:49:19 UTC (rev 132)
+++ trunk/src/target/OM-2007/libraries/mokoui/mokoui.pro	2006-10-27 22:32:46 UTC (rev 133)
@@ -2,8 +2,10 @@
 VERSION = 0.0.1
 
 HEADERS = \
+	moko-alignment.h \
 	moko-pixmap-container.h \
 	moko-pixmap-button.h \
+	moko-vbox.h \
 	moko-application.h \
 	moko-window.h \
 	moko-finger-window.h \
@@ -12,8 +14,10 @@
 	moko-toolbox.h \
 	moko-search-bar.h
 SOURCES = \
+	moko-alignment.c \
     moko-pixmap-container.c \
 	moko-pixmap-button.c \
+	moko-vbox.c \
 	moko-application.c \
 	moko-window.c \
 	moko-finger-window.c \





More information about the commitlog mailing list