subtle bug possibility



This code doesn't want to run on gtk 0.99.3:

#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gtk/gtkadjustment.h>
#include <gdk/gdk.h>

GtkWidget *window;
GtkWidget *rscroll;
GtkWidget *gscroll;
GtkWidget *bscroll;
GtkWidget *drawbox[16];

void destroy(GtkWidget *widget, gpointer *data)
{
  gtk_main_quit();
}

void set_color(GtkWidget *widget, gpointer *data)
{
  GdkGC *gc;
  int width, height;
  GdkColor *color;
  
  int red = (gtk_range_get_adjustment(GTK_RANGE(rscroll)))->value;
  int green = (gtk_range_get_adjustment(GTK_RANGE(gscroll)))->value;
  int blue = (gtk_range_get_adjustment(GTK_RANGE(bscroll)))->value;

  gc = gdk_gc_new(drawbox[0]->window);
  gdk_window_get_size(drawbox[0]->window, &width, &height);

  color = (GdkColor *)data;
  color->red = red * (65535/255);
  color->green = green * (65535/255);
  color->blue = blue * (65535/255);
  color->pixel = (gulong)(red*65536 + green*256 + blue);

  gdk_color_alloc(gtk_widget_get_colormap(drawbox[0]), color);

  gdk_gc_set_foreground(gc, color);
  gdk_draw_rectangle(drawbox[0]->window, gc, 1, 0, 0, width, height);
}

int
main(int argc, char *argv[])
{
  GtkWidget *scrollbox;
  GtkWidget *column[4];
  GtkWidget *row[16];
  GtkWidget *checkbox[16];
  GtkObject *rset;
  GtkObject *gset;
  GtkObject *bset;
  GdkColor *color;
  int i, j;
  
  void destroy(GtkWidget *, gpointer *);
  void set_color(GtkWidget *, gpointer *);
    
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(destroy), NULL);
  gtk_container_border_width(GTK_CONTAINER(window), 10);
  gtk_widget_set_usize(window, 500, 425);

  color = (GdkColor *)malloc(sizeof(GdkColor));
  
  scrollbox = gtk_vbox_new(TRUE, 10);
  
  rset = gtk_adjustment_new(0.0, 0.0, 263.0, 1.0, 8.0, 8.0);
  gset = gtk_adjustment_new(0.0, 0.0, 263.0, 1.0, 8.0, 8.0);
  bset = gtk_adjustment_new(0.0, 0.0, 263.0, 1.0, 8.0, 8.0);

  rscroll = gtk_hscrollbar_new(GTK_ADJUSTMENT(rset));
  gscroll = gtk_hscrollbar_new(GTK_ADJUSTMENT(gset));
  bscroll = gtk_hscrollbar_new(GTK_ADJUSTMENT(bset));

  gtk_signal_connect(GTK_OBJECT(rset), "value_changed",
GTK_SIGNAL_FUNC(set_color), color);
  gtk_signal_connect(GTK_OBJECT(gset), "value_changed",
GTK_SIGNAL_FUNC(set_color), color);
  gtk_signal_connect(GTK_OBJECT(bset), "value_changed",
GTK_SIGNAL_FUNC(set_color), color);
  
  gtk_box_pack_start(GTK_BOX(scrollbox), rscroll, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(scrollbox), gscroll, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(scrollbox), bscroll, TRUE, TRUE, 0);

  for(i=0;i<4;i++){
    column[i] = gtk_hbox_new(TRUE, 3);
    for(j=0;j<4;j++){
      drawbox[(i+1)*(j+1)+(3-j)*i] = gtk_drawing_area_new();
      checkbox[(i+1)*(j+1)+(3-j)*i] = gtk_check_button_new();
      row[(i+1)*(j+1)+(3-j)*i] = gtk_hbox_new(TRUE, 0);
     
gtk_box_pack_start(GTK_BOX(row[(i+1)*(j+1)+(3-j)*i]),checkbox[(i+1)*(j+1)+(3-j)*i],
TRUE, TRUE, 0);
     
gtk_box_pack_start(GTK_BOX(row[(i+1)*(j+1)+(3-j)*i]),drawbox[(i+1)*(j+1)+(3-j)*i],
TRUE, TRUE, 0);
      gtk_box_pack_start(GTK_BOX(column[i]), row[(i+1)*(j+1)+(3-j)*i],
TRUE, TRUE, 0);
      gtk_widget_show(checkbox[(i+1)*(j+1)+(3-j)*i]);
      gtk_widget_show(drawbox[(i+1)*(j+1)+(3-j)*i]);
      gtk_widget_show(row[(i+1)*(j+1)+(3-j)*i]);
    }
    gtk_box_pack_start(GTK_BOX(scrollbox), column[i], TRUE, TRUE, 0);
    gtk_widget_show(column[i]);
  }
  
  gtk_widget_show(rscroll);
  gtk_widget_show(gscroll);
  gtk_widget_show(bscroll);
  
  gtk_container_add(GTK_CONTAINER(window), scrollbox);
  gtk_widget_show(scrollbox);
  
  gtk_widget_show(window);
  gtk_main();

  free((void *)color);
  
  return 0;
}

It hangs on a SIGINT within gtk_main(). What's wrong?

Nathan



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