2005-01-04 [colin] 0.9.13cvs25.6
[claws.git] / src / gtk / gtkshruler.c
index 091c1907ed561d9e5115adececf8b087296ad815..d2fff5b2fbe96a824ffd90ca4d6bce53c48c0bdb 100644 (file)
@@ -1,6 +1,6 @@
 /* GtkSHRuler
  *
- *  Copyright (C) 2000 Alfons Hoogervorst
+ *  Copyright (C) 2000-2004 Alfons Hoogervorst & The Sylpheed Claws Team
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -25,7 +25,7 @@
  * last parameter has the distance between two ticks (which is
  * the width of the fixed font character!
  * 
- * -- Alfons (alfons@proteus.demon.nl)
+ * -- Alfons
  */
 
 #include <math.h>
@@ -48,24 +48,28 @@ static void gtk_shruler_draw_ticks  (GtkRuler        *ruler);
 static void gtk_shruler_draw_pos       (GtkRuler        *ruler);
 #endif
 
-guint
+GType
 gtk_shruler_get_type(void)
 {
-       static guint shruler_type = 0;
+       static GType shruler_type = 0;
 
        if ( !shruler_type ) {
-               static const GtkTypeInfo shruler_info = {
-                       "GtkSHRuler",
-                       sizeof (GtkSHRuler),
+               static const GTypeInfo shruler_info = {
                        sizeof (GtkSHRulerClass),
-                       (GtkClassInitFunc) gtk_shruler_class_init,
-                       (GtkObjectInitFunc) gtk_shruler_init,
-                       /* reserved_1 */ NULL,
-               /* reserved_2 */ NULL,
-               (GtkClassInitFunc) NULL,
-        };
+
+                       (GBaseInitFunc) NULL,
+                       (GBaseFinalizeFunc) NULL,
+
+                       (GClassInitFunc) gtk_shruler_class_init,
+                       (GClassFinalizeFunc) NULL,
+                       NULL,   /* class_data */
+
+                       sizeof (GtkSHRuler),
+                       0,      /* n_preallocs */
+                       (GInstanceInitFunc) gtk_shruler_init,
+               };
                /* inherit from GtkHRuler */
-       shruler_type = gtk_type_unique( gtk_hruler_get_type (), &shruler_info );
+               shruler_type = g_type_register_static (GTK_TYPE_HRULER, "GtkSHRuler", &shruler_info, (GTypeFlags)0);
        }
        return shruler_type;
 }
@@ -99,15 +103,15 @@ gtk_shruler_init (GtkSHRuler * shruler)
        GtkWidget * widget;
        
        widget = GTK_WIDGET (shruler);
-       widget->requisition.width = widget->style->klass->xthickness * 2 + 1;
-       widget->requisition.height = widget->style->klass->ythickness * 2 + RULER_HEIGHT;
+       widget->requisition.width = widget->style->xthickness * 2 + 1;
+       widget->requisition.height = widget->style->ythickness * 2 + RULER_HEIGHT;
 }
 
 
 GtkWidget*
 gtk_shruler_new(void)
 {
-       return GTK_WIDGET( gtk_type_new( gtk_shruler_get_type() ) );
+       return GTK_WIDGET( g_object_new( gtk_shruler_get_type(), NULL ) );
 }
 
 static void
@@ -115,7 +119,6 @@ gtk_shruler_draw_ticks(GtkRuler *ruler)
 {
        GtkWidget *widget;
        GdkGC *gc, *bg_gc;
-       GdkFont *font;
        gint i;
        gint width, height;
        gint xthickness;
@@ -132,10 +135,9 @@ gtk_shruler_draw_ticks(GtkRuler *ruler)
        
        gc = widget->style->fg_gc[GTK_STATE_NORMAL];
        bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
-       font = widget->style->font;
 
-       xthickness = widget->style->klass->xthickness;
-       ythickness = widget->style->klass->ythickness;
+       xthickness = widget->style->xthickness;
+       ythickness = widget->style->ythickness;
 
        width = widget->allocation.width;
        height = widget->allocation.height - ythickness * 2;
@@ -155,24 +157,34 @@ gtk_shruler_draw_ticks(GtkRuler *ruler)
 #endif
 
        /* assume ruler->max_size has the char width */    
-       /* i is increment of char_width,  pos is label number */
+       /* i is increment of char_width,  pos is label number
+        * y position is based on height of widget itself
+        */
        for ( i = 0, pos = 0; i < widget->allocation.width - xthickness; i += ruler->max_size, pos++ ) {        
-               int length = ythickness / 2;
+               int length = height / 4;
        
-               if ( pos % 10 == 0 ) length = ( 4 * ythickness );
-               else if (pos % 5 == 0 ) length = ( 2 * ythickness );
+               if ( pos % 10 == 0 ) length = ( 3 * height / 4 );
+               else if (pos % 5 == 0 ) length = ( height / 2 );
                
                gdk_draw_line(ruler->backing_store, gc,
-                             i, height + ythickness
+                             i, height, 
                              i, height - length);                      
                
                if ( pos % 10 == 0 ) {
-                       char buf[8];
+                       gchar buf[8];
+                       PangoLayout *layout;
+
                        /* draw label */
-                       sprintf(buf, "%d", (int) pos);
-                       gdk_draw_string(ruler->backing_store, font, gc,
-                                       i + 2, ythickness + font->ascent - 1,
-                                       buf);
+                       g_snprintf(buf, sizeof buf, "%d", pos);
+                       
+                       layout = gtk_widget_create_pango_layout
+                                       (GTK_WIDGET(ruler), buf);
+                       
+                       gdk_draw_layout(ruler->backing_store, gc, i + 2,
+                                       (height / 12),
+                                       layout);
+                       
+                       g_object_unref(layout);
            }
        }
 }