[anjal] Anjal self decorates.



commit bff2a195e482c0d5d59aac10f6490422a03611e3
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Wed May 27 02:22:02 2009 +0530

    Anjal self decorates.
---
 src/Makefile.am       |    4 +-
 src/mail-decoration.c |  317 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/mail-decoration.h |   69 +++++++++++
 src/mail-shell.c      |    3 +-
 4 files changed, 391 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 1ca2650..cd5e3c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,7 +57,9 @@ anjal_SOURCES = \
 	mail-settings-view.c \
 	mail-settings-view.h \
 	mail-search.c \
-	mail-search.h
+	mail-search.h \
+	mail-decoration.c \
+	mail-decoration.h
 
 if ENABLE_WEBKIT
 anjal_SOURCES += em-webkit-stream.c \
diff --git a/src/mail-decoration.c b/src/mail-decoration.c
new file mode 100644
index 0000000..00cf4fe
--- /dev/null
+++ b/src/mail-decoration.c
@@ -0,0 +1,317 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>  
+ *
+ *
+ * Authors:
+ *		Srinivasa Ragavan <sragavan novell com>
+ *
+ * Copyright (C) 2009 Novell, Inc. (www.novell.com)
+ *
+ */
+
+/* Many thanks to Aaron Bockover & Cubano. This is just a C version Cubano's self decoration */
+
+#include "mail-decoration.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+#define MAIL_DECORATION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MAIL_DECORATION_TYPE, MailDecorationPrivate))
+
+struct _MailDecorationPrivate
+{
+	GdkCursor *cursors[8];
+	gboolean default_cursor;
+	gboolean resizing;
+	GdkWindowEdge last_edge;
+	int resize_width;
+	int top_height;
+	gboolean check_window;
+	gboolean can_resize;
+};
+
+static GObjectClass *parent_class = NULL;
+
+static void mail_decoration_class_init(MailDecorationClass *klass);
+static void mail_decoration_init(MailDecoration *facet);
+
+GType
+mail_decoration_get_type(void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0))
+	{
+		static const GTypeInfo mail_decoration_info =
+		{
+			sizeof (MailDecorationClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) mail_decoration_class_init,
+			NULL,
+			NULL,
+			sizeof (MailDecoration),
+			0,
+			(GInstanceInitFunc) mail_decoration_init
+		};
+
+		type = g_type_register_static (G_TYPE_OBJECT,
+					       "MailDecoration",
+					       &mail_decoration_info, 0);
+	}
+
+	return type;
+}
+
+static void 
+md_translate_position (GdkWindow *w, double ex, double ey, int *x, int *y, GtkWidget *window)
+{
+	*x = (int)ex;
+	*y = (int)ey;
+            
+	while (w != window->window) {
+		int cx, cy, cw, ch, cd;
+		gdk_window_get_geometry (w, &cx, &cy, &cw, &ch, &cd);
+                x += cx;
+                y += cy;
+                w = (GdkWindow *)((GdkWindowObject *)w)->parent;
+	}
+}
+
+static gboolean
+in_top (MailDecoration *md, double y) 
+{ 
+	return y <= md->priv->resize_width; 
+}
+
+static gboolean
+in_left (MailDecoration *md, double x) 
+{ 
+	return x <= md->priv->resize_width; 
+}
+
+static gboolean 
+in_bottom (MailDecoration *md, double y) 
+{ 
+	return y >= ((GtkWidget *)md->window)->allocation.height - md->priv->resize_width; 
+}
+
+static gboolean 
+in_right (MailDecoration *md, double x) 
+{ 
+	return x >= ((GtkWidget *)md->window)->allocation.width - md->priv->resize_width; 
+}
+
+
+static void
+set_cursor (MailDecoration *md, GdkWindowEdge edge)
+{
+	gdk_window_set_cursor (((GtkWidget *)md->window)->window, md->priv->cursors[edge]);
+	md->priv->default_cursor = FALSE;
+}
+
+static void
+reset_cursor (MailDecoration *md)
+{
+	if (!md->priv->default_cursor) {
+		md->priv->default_cursor = TRUE;
+		gdk_window_set_cursor (((GtkWidget *)md->window)->window, NULL);
+	}
+
+}
+
+static void
+update_cursor (MailDecoration *md, double x, double y, gboolean update)
+{
+	if (update)
+		md->priv->resizing = TRUE;
+
+	if (in_top(md, y) && in_left (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_NORTH_WEST;
+		set_cursor (md, GDK_WINDOW_EDGE_NORTH_WEST);	
+	} else if (in_top (md, y) && in_right (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_NORTH_EAST;
+		set_cursor (md, GDK_WINDOW_EDGE_NORTH_EAST);
+	} else if (in_bottom (md, y) && in_left (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_SOUTH_WEST;
+		set_cursor (md, GDK_WINDOW_EDGE_SOUTH_WEST);
+	} else if (in_bottom (md, y) && in_right (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_SOUTH_EAST;
+		set_cursor (md, GDK_WINDOW_EDGE_SOUTH_EAST);
+	} else if (in_top (md, y)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_NORTH;
+		set_cursor (md, GDK_WINDOW_EDGE_NORTH);
+	} else if (in_bottom (md, y)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_SOUTH;
+		set_cursor (md, GDK_WINDOW_EDGE_SOUTH);
+	} else if (in_left (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_WEST;
+		set_cursor (md, GDK_WINDOW_EDGE_WEST);
+	} else if (in_right (md, x)) {
+		md->priv->last_edge = GDK_WINDOW_EDGE_EAST;
+		set_cursor (md, GDK_WINDOW_EDGE_EAST);
+	} else {
+		if (update)
+			md->priv->resizing = FALSE;
+		reset_cursor (md);
+	}
+}
+
+
+static gboolean            
+md_motion_event (GtkWidget *widget, GdkEventMotion *event, gpointer user_data) 
+{
+	int x, y;
+	MailDecoration *md = (MailDecoration *)user_data;
+
+	md_translate_position (event->window, event->x, event->y, &x, &y, md->window);
+
+	if (md->priv->can_resize) {
+		update_cursor  (md, x, y, FALSE);
+	}
+
+	return FALSE;
+}
+
+static gboolean            
+md_enter_event (GtkWidget *widget , GdkEventCrossing *event, gpointer user_data)   
+{
+	MailDecoration *md = (MailDecoration *)user_data;
+	int x, y;
+
+	md_translate_position (event->window, event->x, event->y, &x, &y, md->window);
+
+	if (md->priv->can_resize) {
+		update_cursor (md, x, y, FALSE);
+	}
+
+	return FALSE;
+}
+
+static gboolean            
+md_leave_event (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
+{
+	MailDecoration *md = (MailDecoration *)user_data;
+
+	if (md->priv->can_resize)
+		reset_cursor (md);
+
+	return FALSE;
+}
+
+static void                
+md_size_allocate_event (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
+{
+	gtk_widget_queue_draw (widget);
+}
+
+static gboolean            
+md_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+{
+	MailDecoration *md = (MailDecoration *)user_data;
+	int x_root = (int) event->x_root;
+	int y_root = (int) event->y_root;
+	int x, y;
+
+        if (!md->priv->can_resize) {
+                return;
+        }
+        
+	md_translate_position (event->window, event->x, event->y, &x, &y, md->window);
+
+        update_cursor (md, x, y, TRUE);
+        if (md->priv->resizing && event->button == 1) {
+		gtk_window_begin_resize_drag (widget, md->priv->last_edge, 1, x_root, y_root, event->time);
+        } else if ((md->priv->resizing && event->button == 2) ||
+                (event->button == 1 && y <= md->priv->top_height)) {
+                gtk_window_begin_move_drag (widget, event->button, x_root, y_root, event->time);
+	} else
+		return FALSE;
+
+	return TRUE;
+}
+
+static gboolean            
+md_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+{
+	int x, y;
+	MailDecoration *md = (MailDecoration *)user_data;
+
+	md_translate_position (event->window, event->x, event->y, &x, &y, md->window);
+ 
+	if (md->priv->resizing) {
+		update_cursor (md, x, y, TRUE);
+	}
+
+	return FALSE;
+}
+
+MailDecoration* mail_decoration_new(GtkWindow *window)
+{
+	MailDecoration *md = g_object_new(mail_decoration_get_type(), NULL);
+
+	md->window = window;
+	gtk_window_set_decorated (window, FALSE);
+	gtk_widget_add_events (window, GDK_BUTTON_PRESS_MASK | 
+					GDK_POINTER_MOTION_MASK |
+					GDK_ENTER_NOTIFY_MASK |
+					GDK_LEAVE_NOTIFY_MASK |
+					GDK_BUTTON_RELEASE_MASK);
+
+	g_signal_connect (window, "motion-notify-event", md_motion_event, md);
+	g_signal_connect (window, "enter-notify-event", md_enter_event, md);
+	g_signal_connect (window, "leave-notify-event", md_leave_event, md);
+	g_signal_connect (window, "button-press-event", md_button_press_event, md);
+	g_signal_connect (window, "button-release-event", md_button_release_event, md);
+	g_signal_connect (window, "size-allocate", md_size_allocate_event, md);
+
+	return md;
+}
+
+
+static void
+mail_decoration_class_init(MailDecorationClass *klass)
+{
+
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (object_class, sizeof(MailDecorationPrivate));
+}
+
+static void
+mail_decoration_init(MailDecoration *md)
+{
+	MailDecorationPrivate *priv;
+
+	priv = MAIL_DECORATION_GET_PRIVATE (md);
+	md->priv = priv;
+
+	priv->cursors[0]= gdk_cursor_new (GDK_TOP_LEFT_CORNER);
+	priv->cursors[1]= gdk_cursor_new (GDK_TOP_SIDE);
+	priv->cursors[2]= gdk_cursor_new (GDK_TOP_RIGHT_CORNER);
+	priv->cursors[3]= gdk_cursor_new (GDK_LEFT_SIDE);
+	priv->cursors[4]= gdk_cursor_new (GDK_RIGHT_SIDE);
+	priv->cursors[5]= gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER);
+	priv->cursors[6]= gdk_cursor_new (GDK_BOTTOM_SIDE);
+	priv->cursors[7]= gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER);
+	
+	priv->default_cursor = TRUE;
+	priv->resizing = FALSE;
+	priv->resize_width = 4;
+	priv->top_height = 80;
+	priv->check_window = TRUE;
+	priv->can_resize = TRUE;
+	
+}
diff --git a/src/mail-decoration.h b/src/mail-decoration.h
new file mode 100644
index 0000000..9010e89
--- /dev/null
+++ b/src/mail-decoration.h
@@ -0,0 +1,69 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>  
+ *
+ *
+ * Authors:
+ *		Srinivasa Ragavan <sragavan novell com>
+ *
+ * Copyright (C) 2009 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef _MAIL_DECORATION_
+#define _MAIL_DECORATION_ 
+
+#include <gtk/gtk.h>
+
+
+#define MAIL_DECORATION_TYPE \
+	(mail_decoration_get_type ())
+#define MAIL_DECORATION(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), MAIL_DECORATION_TYPE, MailDecoration))
+#define MAIL_DECORATION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), MAIL_DECORATION_TYPE, MailDecorationClass))
+#define IS_MAIL_DECORATION(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), MAIL_DECORATION_TYPE))
+#define IS_MAIL_DECORATION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((obj), MAIL_DECORATION_TYPE))
+#define MAIL_DECORATION_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), MAIL_DECORATION_TYPE, MailDecorationClass))
+
+typedef struct _MailDecoration MailDecoration;
+typedef struct _MailDecorationClass MailDecorationClass;
+typedef struct _MailDecorationPrivate MailDecorationPrivate;
+
+struct _MailDecoration {
+        GObject parent; 
+
+	GtkWindow *window;
+	MailDecorationPrivate *priv;
+};
+
+struct _MailDecorationClass {
+	GObjectClass parent_class;
+};
+
+MailDecoration *mail_decoration_new(GtkWindow *);
+
+
+#endif
diff --git a/src/mail-shell.c b/src/mail-shell.c
index 4c6bc82..003514a 100644
--- a/src/mail-shell.c
+++ b/src/mail-shell.c
@@ -279,7 +279,8 @@ mail_shell_construct (MailShell *shell)
 	MailShellPrivate *priv = shell->priv;
 	GtkWidget *tmp, *img, *box, *ar1, *ar2;
 	GtkStyle *style = gtk_widget_get_default_style ();
-
+	
+	mail_decoration_new (shell);
 	ms_init_style (style);
 	g_signal_connect ((GObject *)shell, "delete-event", G_CALLBACK (ms_delete_event), NULL);
 	gtk_window_set_type_hint ((GtkWindow *)shell, GDK_WINDOW_TYPE_HINT_NORMAL);



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