Creating custom widget questions



Folks,

I am creating a xy linegraph widget for the first time, and I am
experiencing a double destroy method call during shutdown.  Plus, I
would like some clarification on which api family to use for
params ;GtkObject or GObject, and a little help with naming a new
widget.  I'm using gtk2-devel-2.8.17-1.fc5.1

Q1: Naming a new widget:  Is it ok to name it gtk_linegraph_new() ?
       - I named mine sk_linegraph_new(), but all the books i've read
did not hesitate to prefix their names with gtk_

Q2: API Families: GtkObjectClass vs GObjectClass for widget properties?
       - I want the codeset to run anywhere GTK+/GDK is supported!
       - I used GObjectClass methods ( get/set_property ) rather than
GtkObjectClass get/set_arg - initially not noticing the difference; does
it matter ?

Q3: Double-Destroy method calls: GtkWidgetClass->destroy get called at
least twice during shutdown and GTK_DESTROYED(widget) didn't seem to
work?
      - With this widget and a few others, I've noticed that the destroy
method is called multiple times at program termination
      - I included my realize/unrealize() methods as they are the only
methods related to this problem that I could find.
      - Is there a GTK2 equivalent of  GTK_DESTROYED(widget), to help
detect the 2nd+ call ?
      - Is this a problem? can I safely ignore it?

[ FILE sklinegraph.h]

typedef struct _SkLineGraph 
{ 
  GtkWidget   widget;
    ...
} SkLineGraph;

typedef struct _SkLineGraphClass    
{
  GtkWidgetClass parent_class;
} SkLineGraphClass;


[ FILE sklinegraph.c]

G_DEFINE_TYPE (SkLineGraph, sk_linegraph, GTK_TYPE_WIDGET)

static void sk_linegraph_class_init (SkLineGraphClass  *class)
{
  GObjectClass    *gobject_class   = G_OBJECT_CLASS (class);    
  GtkObjectClass  *gtkobject_class = GTK_OBJECT_CLASS (class);      
  GtkWidgetClass  *widget_class    = GTK_WIDGET_CLASS (class);

  gobject_class->set_property = sk_linegraph_set_property;
  gobject_class->get_property = sk_linegraph_get_property;
  gtkobject_class->destroy    = sk_linegraph_destroy;

  widget_class->size_allocate = sk_linegraph_size_allocate;  
  widget_class->size_request  = sk_linegraph_size_request;
  widget_class->realize       = sk_linegraph_realize;
  widget_class->unrealize     = sk_linegraph_unrealize;  
  widget_class->expose_event        = sk_linegraph_expose_event;  
  widget_class->motion_notify_event =
sk_linegraph_motion_notify_event;    
  widget_class->button_press_event  = sk_linegraph_button_press_event;
    
  g_object_class_install_property
(gobject_class,PROP_GRAPH_DRAWING_TYPE,
                                   g_param_spec_boolean
("graph-drawing-type",
                                                     "Graph Drawing
Type",
                                                     "some text",
                                                     FALSE,

G_PARAM_READWRITE));
}

static void sk_linegraph_realize (GtkWidget *widget)
{
  SkLineGraph *slg = NULL;
  GdkWindowAttr attributes;
  gint attributes_mask;

  g_return_if_fail ( widget != NULL);    
  g_return_if_fail (IS_SK_LINEGRAPH (widget));

  slg = SK_LINEGRAPH (widget);
  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK | 
                             GDK_BUTTON_PRESS_MASK |
GDK_POINTER_MOTION_MASK | 
                             GDK_POINTER_MOTION_HINT_MASK;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL |
GDK_WA_COLORMAP;

  widget->window = gdk_window_new (gtk_widget_get_parent_window
(widget), &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, widget);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, widget->window,
GTK_STATE_NORMAL);

  if (slg->lgflags & LG_GRAPH_SCALED) {
      sk_linegraph_manage_scaled_config  (slg);
  } else {
      sk_linegraph_manage_regular_config (slg);
  }

}

static void sk_linegraph_unrealize (GtkWidget *widget)
{
  g_return_if_fail (widget != NULL);
  g_return_if_fail (IS_SK_LINEGRAPH (widget));
  
  if (GTK_WIDGET_CLASS (sk_linegraph_parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (sk_linegraph_parent_class)->unrealize)
(widget);
}

James,

________________________________________________________________________
Registered Linux User #270764
FC5 on Dual AMD 2400+ MPs

________________________________________________________________________



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