Author: nick
Date: 2008-08-10 11:43:06 +0000 (Sun, 10 Aug 2008)
New Revision: 27440

Modified:
   xfce4-panel/trunk/plugins/clock/clock-analog.c
   xfce4-panel/trunk/plugins/clock/clock-binary.c
   xfce4-panel/trunk/plugins/clock/clock-dialog.c
   xfce4-panel/trunk/plugins/clock/clock-digital.c
   xfce4-panel/trunk/plugins/clock/clock-lcd.c
   xfce4-panel/trunk/plugins/clock/clock.c
Log:
* Fix problems with the lcd clock (Bug #3960). Also
  use new tooltip api when available.


Modified: xfce4-panel/trunk/plugins/clock/clock-analog.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock-analog.c      2008-08-10 11:22:05 UTC 
(rev 27439)
+++ xfce4-panel/trunk/plugins/clock/clock-analog.c      2008-08-10 11:43:06 UTC 
(rev 27440)
@@ -95,39 +95,16 @@
 
 
 
-static GObjectClass *xfce_clock_analog_parent_class;
+G_DEFINE_TYPE (XfceClockAnalog, xfce_clock_analog, GTK_TYPE_IMAGE);
 
 
 
-GType
-xfce_clock_analog_get_type (void)
-{
-    static GType type = G_TYPE_INVALID;
-
-    if (G_UNLIKELY (type == G_TYPE_INVALID))
-    {
-        type = g_type_register_static_simple (GTK_TYPE_IMAGE,
-                                              I_("XfceClockAnalog"),
-                                              sizeof (XfceClockAnalogClass),
-                                              (GClassInitFunc) 
xfce_clock_analog_class_init,
-                                              sizeof (XfceClockAnalog),
-                                              (GInstanceInitFunc) 
xfce_clock_analog_init,
-                                              0);
-    }
-
-    return type;
-}
-
-
-
 static void
 xfce_clock_analog_class_init (XfceClockAnalogClass *klass)
 {
     GObjectClass   *gobject_class;
     GtkWidgetClass *gtkwidget_class;
 
-    xfce_clock_analog_parent_class = g_type_class_peek_parent (klass);
-
     gobject_class = G_OBJECT_CLASS (klass);
     gobject_class->finalize = xfce_clock_analog_finalize;
     gobject_class->set_property = xfce_clock_analog_set_property;

Modified: xfce4-panel/trunk/plugins/clock/clock-binary.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock-binary.c      2008-08-10 11:22:05 UTC 
(rev 27439)
+++ xfce4-panel/trunk/plugins/clock/clock-binary.c      2008-08-10 11:43:06 UTC 
(rev 27440)
@@ -83,39 +83,16 @@
 
 
 
-static GObjectClass *xfce_clock_binary_parent_class;
+G_DEFINE_TYPE (XfceClockBinary, xfce_clock_binary, GTK_TYPE_IMAGE);
 
 
 
-GType
-xfce_clock_binary_get_type (void)
-{
-    static GType type = G_TYPE_INVALID;
-
-    if (G_UNLIKELY (type == G_TYPE_INVALID))
-    {
-        type = g_type_register_static_simple (GTK_TYPE_IMAGE,
-                                              I_("XfceClockBinary"),
-                                              sizeof (XfceClockBinaryClass),
-                                              (GClassInitFunc) 
xfce_clock_binary_class_init,
-                                              sizeof (XfceClockBinary),
-                                              (GInstanceInitFunc) 
xfce_clock_binary_init,
-                                              0);
-    }
-
-    return type;
-}
-
-
-
 static void
 xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
 {
     GObjectClass   *gobject_class;
     GtkWidgetClass *gtkwidget_class;
 
-    xfce_clock_binary_parent_class = g_type_class_peek_parent (klass);
-
     gobject_class = G_OBJECT_CLASS (klass);
     gobject_class->finalize = xfce_clock_binary_finalize;
     gobject_class->set_property = xfce_clock_binary_set_property;

Modified: xfce4-panel/trunk/plugins/clock/clock-dialog.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock-dialog.c      2008-08-10 11:22:05 UTC 
(rev 27439)
+++ xfce4-panel/trunk/plugins/clock/clock-dialog.c      2008-08-10 11:43:06 UTC 
(rev 27440)
@@ -454,7 +454,8 @@
         g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK 
(xfce_clock_dialog_digital_format_changed), clock);
         gtk_widget_show (combo);
 
-        entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1);
+        entry = gtk_entry_new ();
+        gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
         gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
         g_object_set_data (G_OBJECT (combo), I_("entry"), entry);
         if (!has_active)
@@ -538,7 +539,8 @@
     g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK 
(xfce_clock_dialog_tooltip_format_changed), clock);
     gtk_widget_show (combo);
 
-    entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1);
+    entry = gtk_entry_new ();
+    gtk_entry_set_max_length (GTK_ENTRY (entry), BUFFER_SIZE - 1);
     gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
     g_object_set_data (G_OBJECT (combo), I_("entry"), entry);
     if (!has_active)

Modified: xfce4-panel/trunk/plugins/clock/clock-digital.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock-digital.c     2008-08-10 11:22:05 UTC 
(rev 27439)
+++ xfce4-panel/trunk/plugins/clock/clock-digital.c     2008-08-10 11:43:06 UTC 
(rev 27440)
@@ -68,38 +68,15 @@
 
 
 
-static GObjectClass *xfce_clock_digital_parent_class;
+G_DEFINE_TYPE (XfceClockDigital, xfce_clock_digital, GTK_TYPE_LABEL);
 
 
 
-GType
-xfce_clock_digital_get_type (void)
-{
-    static GType type = G_TYPE_INVALID;
-
-    if (G_UNLIKELY (type == G_TYPE_INVALID))
-    {
-        type = g_type_register_static_simple (GTK_TYPE_LABEL,
-                                              I_("XfceClockDigital"),
-                                              sizeof (XfceClockDigitalClass),
-                                              (GClassInitFunc) 
xfce_clock_digital_class_init,
-                                              sizeof (XfceClockDigital),
-                                              (GInstanceInitFunc) 
xfce_clock_digital_init,
-                                              0);
-    }
-
-    return type;
-}
-
-
-
 static void
 xfce_clock_digital_class_init (XfceClockDigitalClass *klass)
 {
     GObjectClass *gobject_class;
 
-    xfce_clock_digital_parent_class = g_type_class_peek_parent (klass);
-
     gobject_class = G_OBJECT_CLASS (klass);
     gobject_class->finalize = xfce_clock_digital_finalize;
     gobject_class->set_property = xfce_clock_digital_set_property;

Modified: xfce4-panel/trunk/plugins/clock/clock-lcd.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock-lcd.c 2008-08-10 11:22:05 UTC (rev 
27439)
+++ xfce4-panel/trunk/plugins/clock/clock-lcd.c 2008-08-10 11:43:06 UTC (rev 
27440)
@@ -21,8 +21,10 @@
 #include <config.h>
 #endif
 
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
 
-
 #include <gtk/gtk.h>
 #include <cairo/cairo.h>
 
@@ -95,39 +97,16 @@
 
 
 
-static GObjectClass *xfce_clock_lcd_parent_class;
+G_DEFINE_TYPE (XfceClockLcd, xfce_clock_lcd, GTK_TYPE_IMAGE);
 
 
 
-GType
-xfce_clock_lcd_get_type (void)
-{
-    static GType type = G_TYPE_INVALID;
-
-    if (G_UNLIKELY (type == G_TYPE_INVALID))
-    {
-        type = g_type_register_static_simple (GTK_TYPE_IMAGE,
-                                              I_("XfceClockLcd"),
-                                              sizeof (XfceClockLcdClass),
-                                              (GClassInitFunc) 
xfce_clock_lcd_class_init,
-                                              sizeof (XfceClockLcd),
-                                              (GInstanceInitFunc) 
xfce_clock_lcd_init,
-                                              0);
-    }
-
-    return type;
-}
-
-
-
 static void
 xfce_clock_lcd_class_init (XfceClockLcdClass *klass)
 {
     GObjectClass   *gobject_class;
     GtkWidgetClass *gtkwidget_class;
 
-    xfce_clock_lcd_parent_class = g_type_class_peek_parent (klass);
-
     gobject_class = G_OBJECT_CLASS (klass);
     gobject_class->finalize = xfce_clock_lcd_finalize;
     gobject_class->set_property = xfce_clock_lcd_set_property;
@@ -291,9 +270,6 @@
         requisition->height = height;
         requisition->width = height * ratio;
     }
-    
-    /* increase the width with 1 px for rounding errors */
-    requisition->width++;
 }
 
 
@@ -312,16 +288,23 @@
 
     g_return_val_if_fail (XFCE_CLOCK_IS_LCD (clock), FALSE);
 
+    /* get the width:height ratio */
+    ratio = xfce_clock_lcd_get_ratio (XFCE_CLOCK_LCD (widget));
+
     /* size of a digit should be a fraction of 10 */
     size = widget->allocation.height - widget->allocation.height % 10;
 
-    /* get the width:height ratio */
-    ratio = xfce_clock_lcd_get_ratio (XFCE_CLOCK_LCD (widget));
+    /* make sure we also fit on small vertical panels */
+    size = MIN (floor ((gdouble) widget->allocation.width / ratio), size);
 
     /* begin offsets */
-    offset_x = widget->allocation.x + (widget->allocation.width - (size * 
ratio)) / 2;
-    offset_y = widget->allocation.y + (widget->allocation.height - size) / 2;
+    offset_x = rint ((widget->allocation.width - (size * ratio)) / 2.00);
+    offset_y = rint ((widget->allocation.height - size) / 2.00);
 
+    /* only allow positive values from the base point */
+    offset_x = widget->allocation.x + MAX (0.00, offset_x);
+    offset_y = widget->allocation.y + MAX (0.00, offset_y);
+
     /* get the cairo context */
     cr = gdk_cairo_create (widget->window);
 
@@ -511,11 +494,18 @@
             x = segments_x[segment][j] * size + offset_x;
             y = segments_y[segment][j] * size + offset_y;
 
+            /* when 0.01 * size is larger then 1, round the numbers */
+            if (size >= 10)
+            {
+              x = floor (x);
+              y = floor (y);
+            }
+
             /* leave when there are no valid coordinates */
-            if (x < 0 || y < 0)
+            if (x < offset_x || y < offset_y)
                 break;
 
-            if (j == 0)
+            if (G_UNLIKELY (j == 0))
                 cairo_move_to (cr, x, y);
             else
                 cairo_line_to (cr, x, y);

Modified: xfce4-panel/trunk/plugins/clock/clock.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock.c     2008-08-10 11:22:05 UTC (rev 
27439)
+++ xfce4-panel/trunk/plugins/clock/clock.c     2008-08-10 11:43:06 UTC (rev 
27440)
@@ -228,16 +228,18 @@
 {
     ClockPlugin        *clock = (ClockPlugin *) user_data;
     gchar              *string;
+    struct tm           tm;
+#if !GTK_CHECK_VERSION (2,12,0)
     static GtkTooltips *tooltips = NULL;
-    struct tm           tm;
 
-    if (G_UNLIKELY (clock->tooltip_format == NULL))
-        return TRUE;
-
     /* allocate the tooltip on-demand */
     if (G_UNLIKELY (tooltips == NULL))
         tooltips = gtk_tooltips_new ();
+#endif
 
+    if (G_UNLIKELY (clock->tooltip_format == NULL))
+        return TRUE;
+
     /* get the local time */
     xfce_clock_util_get_localtime (&tm);
 
@@ -245,7 +247,11 @@
     string = xfce_clock_util_strdup_strftime (clock->tooltip_format, &tm);
 
     /* set the tooltip */
+#if GTK_CHECK_VERSION (2,12,0)
+    gtk_widget_set_tooltip_text (clock->ebox, string);
+#else
     gtk_tooltips_set_tip (tooltips, clock->ebox, string, NULL);
+#endif
 
     /* cleanup */
     g_free (string);
@@ -537,6 +543,15 @@
 
 
 static void
+xfce_clock_plugin_set_orientation (ClockPlugin *clock)
+{
+    /* do a size request */
+    xfce_clock_plugin_set_size (clock, xfce_panel_plugin_get_size 
(clock->plugin));
+}
+
+
+
+static void
 xfce_clock_plugin_read (ClockPlugin *clock)
 {
     gchar       *filename;
@@ -663,5 +678,6 @@
     g_signal_connect_swapped (G_OBJECT (plugin), "save", G_CALLBACK 
(xfce_clock_plugin_write), clock);
     g_signal_connect_swapped (G_OBJECT (plugin), "free-data", G_CALLBACK 
(xfce_clock_plugin_free), clock);
     g_signal_connect_swapped (G_OBJECT (plugin), "configure-plugin", 
G_CALLBACK (xfce_clock_dialog_show), clock);
+    g_signal_connect_swapped (G_OBJECT (plugin), "orientation-changed", 
G_CALLBACK (xfce_clock_plugin_set_orientation), clock);
 }
 

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to