gtk*paned.c cosmetic improvment



i've never much liked either gtkhpaned or gtkvpaned, but i
never liked my "improved" versions much either. this has
prevented me from bothering to send anything in for your
consideration in the past.

one change that came to me while i was on holiday, and
which i implemented this evening, is to at least use mouse
cursors corresponding to the type of paned window that's
being pointed at. that's to say, use an up-and-down cursor
for panes that move up and down, and a left-and-right
cursor for panes that move left and right.

the following patches to gtk+ 1.2.5 pre 2 show the
necessary modifications.

anyway, here are my patches. first gtkhpaned.c:

*** gtkhpaned.c	Tue Jun  8 16:37:04 1999
--- /u/enh/nonlocal/gtk/test/gtk/gtkhpaned.c	Wed Sep 22 18:09:32 1999
***************
*** 43,48 ****
--- 43,51 ----
  					 GdkEventButton *event);
  static gint gtk_hpaned_motion           (GtkWidget *widget,
  					 GdkEventMotion *event);
+ static void gtk_hpaned_realize (GtkWidget * widget);
+ 
+ static GtkPanedClass * parent_class = NULL;
  
  guint
  gtk_hpaned_get_type (void)
***************
*** 75,80 ****
--- 78,84 ----
    GtkWidgetClass *widget_class;
  
    widget_class = (GtkWidgetClass*) class;
+   parent_class = gtk_type_class (gtk_paned_get_type ());
  
    widget_class->size_request = gtk_hpaned_size_request;
    widget_class->size_allocate = gtk_hpaned_size_allocate;
***************
*** 82,92 ****
--- 86,110 ----
    widget_class->button_press_event = gtk_hpaned_button_press;
    widget_class->button_release_event = gtk_hpaned_button_release;
    widget_class->motion_notify_event = gtk_hpaned_motion;
+   widget_class->realize = gtk_hpaned_realize;
  }
  
  static void
  gtk_hpaned_init (GtkHPaned *hpaned)
  {
+ }
+ 
+ static void
+ gtk_hpaned_realize (GtkWidget * widget)
+ {
+   g_return_if_fail (widget != NULL);
+   g_return_if_fail (GTK_IS_HPANED (widget));
+   
+   if (GTK_WIDGET_CLASS (parent_class)->realize)
+     (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+   
+   gdk_window_set_cursor(GTK_PANED(widget)->handle,
+     gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW));
  }
  
  GtkWidget*

and now gtkvpaned.c:

*** gtkvpaned.c	Tue Jun  8 16:37:15 1999
--- /u/enh/nonlocal/gtk/test/gtk/gtkvpaned.c	Wed Sep 22 18:05:13 1999
***************
*** 43,48 ****
--- 43,51 ----
  					 GdkEventButton *event);
  static gint gtk_vpaned_motion           (GtkWidget *widget,
  					 GdkEventMotion *event);
+ static void gtk_vpaned_realize (GtkWidget * widget);
+ 
+ static GtkPanedClass * parent_class = NULL;
  
  guint
  gtk_vpaned_get_type (void)
***************
*** 75,80 ****
--- 78,84 ----
    GtkWidgetClass *widget_class;
  
    widget_class = (GtkWidgetClass*) class;
+   parent_class = gtk_type_class (gtk_paned_get_type ());
  
    widget_class->size_request = gtk_vpaned_size_request;
    widget_class->size_allocate = gtk_vpaned_size_allocate;
***************
*** 82,92 ****
--- 86,110 ----
    widget_class->button_press_event = gtk_vpaned_button_press;
    widget_class->button_release_event = gtk_vpaned_button_release;
    widget_class->motion_notify_event = gtk_vpaned_motion;
+   widget_class->realize = gtk_vpaned_realize;
  }
  
  static void
  gtk_vpaned_init (GtkVPaned *vpaned)
  {
+ }
+ 
+ static void
+ gtk_vpaned_realize (GtkWidget * widget)
+ {
+   g_return_if_fail (widget != NULL);
+   g_return_if_fail (GTK_IS_VPANED (widget));
+   
+   if (GTK_WIDGET_CLASS (parent_class)->realize)
+     (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+   
+   gdk_window_set_cursor (GTK_PANED(widget)->handle,
+     gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW));
  }
  
  GtkWidget*

an alternative way to do the same thing is to use the run-time
type information to decide what kind of mouse cursor to use.
this is a lot less code, but leaves us with an incestuous relationship
between gtkpaned and its subclasses:

*** /u/enh/nonlocal/gtk/virgin/gtk/gtkpaned.c	Wed Jun  9 12:24:53 1999
--- /u/enh/nonlocal/gtk/test/gtk/gtkpaned.c	Wed Sep 22 18:38:53 1999
***************
*** 25,30 ****
--- 25,31 ----
   */
  
  #include "gtkpaned.h"
+ #include "gtkhpaned.h"
  
  enum {
    ARG_0,
***************
*** 218,224 ****
    attributes.y = paned->handle_ypos;
    attributes.width = paned->handle_size;
    attributes.height = paned->handle_size;
!   attributes.cursor = gdk_cursor_new (GDK_CROSS);
    attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
  			    GDK_BUTTON_RELEASE_MASK |
  			    GDK_POINTER_MOTION_MASK |
--- 219,227 ----
    attributes.y = paned->handle_ypos;
    attributes.width = paned->handle_size;
    attributes.height = paned->handle_size;
!   attributes.cursor = gdk_cursor_new (GTK_IS_HPANED (widget) ?
!     GDK_SB_H_DOUBLE_ARROW : GDK_SB_V_DOUBLE_ARROW);
!   
    attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
  			    GDK_BUTTON_RELEASE_MASK |
  			    GDK_POINTER_MOTION_MASK |

comments?

-- 
"Email is for geeks and pedophiles"



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