gtk_object_set_data



Currently working on a project and using GTK+ and am aware of the 
limitation in callbacks where gtk_sgnal_connect can only pass a single data 
value.
In my application I am using an array of records called TASK.  I need a way 
to send more than just my GtkWidget to my callback when the user pushes a 
pushbutton.

Below is the gtk_signal_connect I need to be used once a user pushes a 
button, it will call the start tasks routine.  The display_tasks is a CList 
widget and contains items
in a list.  However, I need to perform actual operations on the items 
selected and their values are stored in the TASK structure.

One possible solution that I could not get to work was using 
gtk_object_set_data and gtk_object_get_data.   Can you use these functions 
by passing an array of records like 'task_list' below.  I tried but when I 
tried to print the value of a field in callback routine I would get garbage 
in my print statement.  Please understand that pointers is not my strong 
suit so maybe I did something wrong.  Below is some partial gtk stuff that 
should show what i am trying to do.  Thanks ahead of time for your help.

typedef struct
{
.... ...
.......
} TASK

in main()
{
  TASK task_list[MAXIMUM_TASKS];
  GtkWidget *display_tasks = NULL:


  gtk_signal_connect(GTK_OBJECT(start_task),"clicked",
                               start_tasks,GTK_CLIST(display_tasks));

  gtk_object_set_data(GTK_OBJECT(display_tasks),"task_list",&task_list);
.....
....
............

}

void start_tasks(GtkWidget *widget, gpointer display_tasks)
{
  TASK *selected_tasks[MAXIMUM_TASKS];

  selected_tasks[MAXIMUM_TASKS] = 
gtk_object_get_data(GTK_OBJECT(display_tasks),"task_list");
  printf(" %s \n",selected_tasks[1]->task_name);

}






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