Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 17 Jun 2018, 18:28
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
SOLVED:gtk eventbox - user data parsing
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message

Joined: 07 Dec 2008
Posts: 907

PostPosted: Mon 10 Jun 2013, 14:01    Post subject:  SOLVED:gtk eventbox - user data parsing  

I am trying to trap clicks on gtk labels. I can use an eventbox to do that.
I want to parse some user data as well but cant get that working.
Below code uses the same callback function for the button and the eventbox - the button-callback parses the userdata (act) but the eventbox does not:
/* example-start eventbox event_test.c */
//compile with
//gcc event_test.c $(/usr/local/bin/gtk-config --cflags) -o eventbox $(/usr/local/bin/gtk-config --libs)

#include <gtk/gtk.h>

void callback ( GtkWidget *widget, gpointer str) {   
   g_print ("str is: %s\n", (char *)str);

int main( int argc, char *argv[] ) {
    GtkWidget *window, *event_box, *label, *button, *box1, *box2;
    char *act="This is the content of char act";
    ///the usual window things
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC (gtk_exit), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    gtk_widget_show (window);
    ///the button in box1 - sends value of act without problems.
   box1 = gtk_hbox_new (FALSE, 0);
   button = gtk_button_new_with_label ("click me");
   gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0);
   gtk_widget_show (button);
   gtk_container_add (GTK_CONTAINER (window), box1);
   gtk_signal_connect (GTK_OBJECT (button), "clicked",
                        GTK_SIGNAL_FUNC (callback), (gpointer) act);
   ///the event-thing in box2 - this one wont send the value of act..
   box2 = gtk_hbox_new (FALSE, 0);
   event_box = gtk_event_box_new ();
   gtk_box_pack_start (GTK_BOX (box2), event_box, TRUE, TRUE, 0);
   gtk_widget_show (event_box);
label = gtk_label_new ("Click here to view events from the eventbox...");
    gtk_container_add (GTK_CONTAINER (event_box), label);
    gtk_widget_show (label);
    gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
    gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
                   GTK_SIGNAL_FUNC (callback), (gpointer) act);
    gtk_container_add (GTK_CONTAINER(box1), box2);               
    gtk_widget_realize (event_box);
    gtk_widget_show (window);
    gtk_main ();

I really would like to get this working - any suggestions?
UPDATE: If I change the callback function from the eventbox to:
void callback ( GtkWidget *widget, GdkEvent *event, gpointer str) {   
   g_print ("str is: %s\n", (char *)str);
the user data is passed. This callback does not work for the button so need two different functions.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0265s ][ Queries: 12 (0.0052s) ][ GZIP on ]