1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <cairo/cairo.h>
20 #include <libhildondesktop/libhildondesktop.h>
21 #include "applet-wrapper.h"
23 #include "simple-launcher.h"
25 struct _SLAWrapperPrivate {
27 GdkPixmap *background_pixmap;
30 static void sla_wrapper_init(SLAWrapper *self);
31 static void sla_wrapper_class_init(SLAWrapperClass *klass);
32 static void sla_wrapper_finalize(GObject *object);
33 static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event);
34 static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc);
35 static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition);
37 HD_DEFINE_PLUGIN(SLAWrapper, sla_wrapper, HILDON_DESKTOP_TYPE_HOME_ITEM)
39 static void sla_wrapper_init(SLAWrapper *self) {
40 GdkColormap *colormap = NULL;
42 self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SLA_TYPE_WRAPPER);
43 self->priv->background_pixmap = NULL;
45 if ((colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default())) != NULL) {
46 gtk_widget_set_colormap(GTK_WIDGET(self), colormap);
50 static void sla_wrapper_class_init(SLAWrapperClass *klass) {
51 GtkWidgetClass *widget_class;
52 GObjectClass *object_class;
54 widget_class = GTK_WIDGET_CLASS(klass);
55 object_class = G_OBJECT_CLASS(klass);
57 object_class->finalize = sla_wrapper_finalize;
59 widget_class->expose_event = sla_wrapper_expose;
60 widget_class->size_allocate = sla_wrapper_size_allocate;
61 widget_class->size_request = sla_wrapper_size_request;
63 g_type_class_add_private(klass, sizeof(SLAWrapperPrivate)); // Do I need this?
66 static void sla_wrapper_finalize(GObject *self) {
67 SLAWrapperPrivate *priv = SLA_WRAPPER(self)->priv;
69 if (priv->background_pixmap != NULL) {
70 g_object_unref(priv->background_pixmap);
71 priv->background_pixmap = NULL;
78 static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event) {
79 if (GTK_WIDGET_DRAWABLE(widget)) {
82 SLAWrapperPrivate *priv = SLA_WRAPPER(widget)->priv;
84 if (priv->background_pixmap == NULL) {
85 priv->background_pixmap = gdk_pixmap_new(widget->window, SOME_WIDTH, SOME_HEIGHT, 32);
87 cr = gdk_cairo_create(priv->background_pixmap);
89 cairo_set_source_rgba(cr, OUR_R, OUR_G, OUR_B, OUR_A);
90 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
95 cr = gdk_cairo_create(widget->window);
96 gdk_cairo_set_source_pixmap(cr, priv->background_pixmap, 0, 0);
98 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
102 return GTK_WIDGET_CLASS(sla_wrapper_parent_class)->expose_event(widget, event);
108 static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc) {
109 GTK_WIDGET_CLASS(sla_wrapper_parent_class)->size_allocate(widget, alloc);
112 static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition) {
114 requisition->width = our_desired_width;
115 requisition->height = our_desired_height;