GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 02, 2014 4:33 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Widgets appearance order
PostPosted: Mon Jan 21, 2013 2:44 pm 
Offline
Familiar Face

Joined: Tue Feb 28, 2012 1:16 pm
Posts: 11
Location: Russia
Hello.

My question is about the order in which widgets get exposure event.

I have the following widgets packing:

1. main_window->hbox1->hbox12->frame1->vbox121
Output:
Code:
expose_event: I'm [ window ]
expose_event: I'm [ hbox1 ]
expose_event: I'm [ hbox12 ]
expose_event: I'm [ frame1 ]
expose_event: I'm [ vbox121 ]

Everything's fine

2. Add a scrolled window:
main_window->hbox1->scroll1->hbox12->frame1->vbox121
Output:
Code:
expose_event: I'm [ hbox12 ]
expose_event: I'm [ frame1 ]
expose_event: I'm [ vbox121 ]
expose_event: I'm [ window ]
expose_event: I'm [ hbox1 ]


Why the order have changed?
I always thought that "window" is the first who gets an exposure event, and then as the packaging goes.
Thanx.




Here is the code:
Code:
#include <gtk/gtk.h>
#include <glib/gprintf.h>

GtkWidget *window;
GtkWidget *hbox1, *hbox12, *hbox13, *vbox1, *vbox12, *vbox13;
GtkWidget *vbox121;
GtkWidget *scroll1, *frame1, *frame2;

#define register_expose_callback(widget) do \
{   \
   g_signal_connect(GTK_OBJECT(widget), "expose_event", (GtkSignalFunc)expose_event, #widget); \
} while (0)


static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
   g_printf("%s: I'm [ %s ]\n", __func__, (gchar *)user_data);

   return FALSE;
}

int
main(int argc, char *argv[])
{
   gtk_init(&argc, &argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request(GTK_WIDGET(window), 800, 400);
   gtk_window_set_title(GTK_WINDOW(window), "g3");
   g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
register_expose_callback(window);

   hbox1 = gtk_hbox_new(FALSE, 0);
register_expose_callback(hbox1);

   gtk_widget_show(hbox1);
   gtk_container_add(GTK_CONTAINER(window), hbox1);

   hbox12 = gtk_hbox_new(FALSE, 0);
register_expose_callback(hbox12);
   gtk_widget_show(hbox12);

#if 1
   scroll1 = gtk_scrolled_window_new(NULL, NULL);
register_expose_callback(scroll1);
   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll1), hbox12);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   gtk_box_pack_start(GTK_BOX(hbox1), scroll1, TRUE, TRUE, 2);
   gtk_widget_show(scroll1);
#else
   gtk_box_pack_start(GTK_BOX(hbox1), hbox12, TRUE, TRUE, 2);
#endif

////
   vbox121 = gtk_vbox_new(FALSE, 0);
register_expose_callback(vbox121);

   frame1 = gtk_frame_new(" BlahBlah ");
register_expose_callback(frame1);

   gtk_container_add(GTK_CONTAINER(frame1), vbox121);

   gtk_box_pack_start(GTK_BOX(hbox12), frame1, FALSE, TRUE, 2);

   gtk_widget_show(hbox12);
   gtk_widget_show(frame1);
   gtk_widget_show(vbox121);
   gtk_widget_show(window);

   gtk_main();

   return 0;
}


Top
 Profile  
 
 Post subject: Re: Widgets appearance order
PostPosted: Wed Jan 23, 2013 9:23 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Hi,

The order the widgets get re-drawn depend on if the widget has it's own GDK window. So in this case scroll1 the GtkScrolledWindow has its own GDK window and the drawing order is different. Do not depend on the order of the expose events as these can happen in any order and at any time.

for more information on the expose-event and drawing order take a look at the manual page at http://developer.gnome.org/gtk2/stable/chap-drawing-model.html

_________________
E.


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