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 Tue 21 Oct 2014, 11:19
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 Posts_count_1  
Author Message
goingnuts

Joined: 07 Dec 2008
Posts: 781

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:
Code:
/* 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);
   gtk_widget_show(box1);
      
   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);
   gtk_widget_show(box2);
   
   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 ();
   
    return(0);
}

I really would like to get this working - any suggestions?
UPDATE: If I change the callback function from the eventbox to:
Code:
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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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