gnome-panel r11034 - trunk/applets/clock



Author: vuntz
Date: Thu Apr 10 07:07:46 2008
New Revision: 11034
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11034&view=rev

Log:
2008-04-10  Vincent Untz  <vuntz gnome org>

	* clock-map.c: (clock_map_init): init some fields
	(clock_map_refresh): be a bit more clever about what we do. Do nothing
	if we have no space allocated. Only reload the map if the allocation
	changed.
	(clock_map_expose): add a warning for a case that should never happen
	(clock_map_size_allocate): simplify. The stock map will be loaded at
	the beginning because of an allocation anyway.


Modified:
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/clock-map.c

Modified: trunk/applets/clock/clock-map.c
==============================================================================
--- trunk/applets/clock/clock-map.c	(original)
+++ trunk/applets/clock/clock-map.c	Thu Apr 10 07:07:46 2008
@@ -123,6 +123,8 @@
 	GTK_WIDGET_SET_FLAGS (this, GTK_NO_WINDOW);
 
 	priv->last_refresh = 0;
+	priv->width = 0;
+	priv->height = 0;
 	priv->highlight_timeout_id = 0;
         priv->stock_map_pixbuf = NULL;
 
@@ -180,34 +182,28 @@
 {
         ClockMapPrivate *priv = PRIVATE (this);
 	GtkWidget *widget = GTK_WIDGET (this);
-        GtkWidget *parent = gtk_widget_get_parent (widget);
-	GtkRequisition req;
-        gint width;
-        gint height;
-
-	gtk_widget_size_request (widget, &req);
-        width = req.width;
-        height = req.height;
-
-        if (parent) {
-		if (widget->allocation.width != 1) {
-			width = widget->allocation.width;
-			height = widget->allocation.height;
-		}
 
+        /* Only do something if we have some space allocated.
+         * Note that 1x1 is not really some space... */
+        if (widget->allocation.width <= 1 || widget->allocation.height <= 1)
+                return;
+
+        /* Allocation changed => we reload the map */
+	if (priv->width != widget->allocation.width ||
+	    priv->height != widget->allocation.height) {
                 if (priv->stock_map_pixbuf) {
                         gdk_pixbuf_unref (priv->stock_map_pixbuf);
                         priv->stock_map_pixbuf = NULL;
                 }
+
+                priv->width = widget->allocation.width;
+                priv->height = widget->allocation.height;
         }
 
         if (!priv->stock_map_pixbuf) {
                 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale
                         (ICONDIR "/clock-map.png",
-                         width, height, FALSE, NULL);
-
-                priv->width = gdk_pixbuf_get_width (pixbuf);
-                priv->height = gdk_pixbuf_get_height (pixbuf);
+                         priv->width, priv->height, FALSE, NULL);
 
                 priv->stock_map_pixbuf = pixbuf;
         }
@@ -225,8 +221,10 @@
 	GdkRectangle region;
         cairo_t *cr;
 
-	if (!priv->shadow_map_pixbuf)
+	if (!priv->shadow_map_pixbuf) {
+                g_warning ("Needed to refresh the map in expose event.");
 		clock_map_refresh (CLOCK_MAP (this));
+        }
 
         cr = gdk_cairo_create (this->window);
 
@@ -284,9 +282,8 @@
 	if (GTK_WIDGET_CLASS (clock_map_parent_class)->size_allocate)
 		GTK_WIDGET_CLASS (clock_map_parent_class)->size_allocate (this, allocation);
 
-	if (!priv->stock_map_pixbuf
-	    || priv->width != this->allocation.width
-	    || priv->height != this->allocation.height)
+	if (priv->width != this->allocation.width ||
+	    priv->height != this->allocation.height)
                 clock_map_refresh (CLOCK_MAP (this));
 }
 



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