GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Jul 28, 2014 4:27 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Onload event
PostPosted: Sun Jun 10, 2007 8:55 am 
Offline
Familiar Face

Joined: Sun Mar 04, 2007 8:25 pm
Posts: 19
Hello,

A simple question it seems but I don't know the answer : (

In VBasic there is the "Onload" event for a window...that is a sub or module that handles task(s) to be done when the window is called up or loaded for the first time. I would like to know what is the corresponding signal in gtk+.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 7:15 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You probably have a lot more "signals" in GTK than you had "events" in VB. When the program first starts--assuming you're using C or C++, your main() function could be compared to using a "Sub Main" in VB. As for when the window or "Form" is loaded in GTK+, it depends.

If you want code to execute every time you show your window to the user, you could connect a callback to the "show" signal. Perhaps you just want to execute some code when the window is initially "realized" or when it's been "mapped" but not necessarily shown. Each of these states have a corresponding signal which you can attach to a callback singnal. You should read more about widget lifecycles to understand the concepts of realized, mapped, reference counting, etc.

Here's a quick snippet which you can build from and experiment with:



Code:
/* compile using:
cc -Wall -g `pkg-config --cflags --libs gtk+-2.0`  -o example main.c 
*/

#include <gtk/gtk.h>

void on_window_map (GtkWidget*, gpointer);
void on_window_realize (GtkWidget*, gpointer);
void on_window_show (GtkWidget*, gpointer);
               
int
main (int argc, char *argv[])
{
       
        GtkWidget *window;
       
        /* initialize the GTK+ library */
        gtk_init (&argc, &argv);

        /* create main window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title (GTK_WINDOW (window), "Example");
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
        gtk_widget_set_size_request (window, 200, 100);
       
        /* connect signals */
        g_signal_connect (G_OBJECT(window), "destroy",
                        G_CALLBACK (gtk_main_quit), NULL);
        g_signal_connect (G_OBJECT(window), "realize",
                        G_CALLBACK (on_window_realize), NULL);
        g_signal_connect (G_OBJECT(window), "map",
                        G_CALLBACK (on_window_map), NULL); 
        g_signal_connect (G_OBJECT(window), "show",
                        G_CALLBACK (on_window_show), NULL);       
               
        /* show the main window, hide it, then show it again */
        gtk_widget_show (window);
        gtk_widget_hide (window);
        gtk_widget_show (window);
       
        gtk_main ();
       
        return 0;     
}

void
on_window_map (GtkWidget *w,gpointer user_data)
{
        g_print("Window was mapped.\n");
}

void
on_window_realize (GtkWidget *w,gpointer user_data)
{
        g_print("Window was realized.\n");
}

void
on_window_show (GtkWidget *w,gpointer user_data)
{
        g_print("Window was shown.\n");
}


_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group