Hi there, I have two problems with gtk_layout. I create a layout that I add in a scrolled_window. Then I create some buttons that I put in the layout, and I draw rectangles in a callback function connected to the layout's expose event. For the moment, everything's OK. Now come the problems. First problem: When I scroll the scrolled_window, nothing happens. I have to resize my window (with the mouse) to see the scrolling effect, which means to see other buttons. (When I click on scrollbars arrows, the slider doesn't move, I have to click in the trough to move it: is that a clue ??) Second problem: When I resize my window, I no longer see my rectangles. I see them for a very short time in the increased portion of the window, but they disappear quickly. To see them again, I have to mask my window with an other one, or to iconify it and increase it. Do I have to use pixmap to solve this ? Thanks a lot. Here's my code (inspired from a book, but similar to what I need) #include <gtk/gtk.h> #include <windows.h> #include <stdio.h> gint HandleExposeEvent (GtkWidget * widget, GdkEventExpose * event) { GtkLayout *layout; gint i, j, imin, imax, jmin, jmax; layout = GTK_LAYOUT (widget); imin = (layout->xoffset + event->area.x) / 10; imax = (layout->xoffset + event->area.x + event->area.width + 9) / 10; jmin = (layout->yoffset + event->area.y) / 10; jmax = (layout->yoffset + event->area.y + event->area.height + 9) / 10; gdk_window_clear_area (widget->window, event->area.x, event->area.y, event->area.width, event->area.height); for (i=imin; i<imax; i++) { for (j=jmin; j<jmax; j++) { if ((i+j) % 2) gdk_draw_rectangle (layout->bin_window, widget->style->black_gc, TRUE, ((10*i) - layout->xoffset), ((10*j) - layout->yoffset), 1+i%10, 1+j%10); } } return TRUE; } void GtkLayoutDialog () { GtkWidget *layout, *scrolled_window, * label, * dialog_window; int i,j; char buf[128]; dialog_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_position (GTK_WINDOW (dialog_window), GTK_WIN_POS_MOUSE); gtk_widget_set_usize (dialog_window, 200, 200); gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), &dialog_window); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_container_add (GTK_CONTAINER (dialog_window), scrolled_window); layout = gtk_layout_new (NULL, NULL); gtk_layout_set_size (GTK_LAYOUT (layout), 1600, 12800); for (i=0; i<1600; i+=200) { for (j=0; j<12800; j+=200) { sprintf(buf, "%d %ld", i, j); label = gtk_button_new_with_label (buf); gtk_layout_put (GTK_LAYOUT (layout), label, i, j); } } gtk_container_add (GTK_CONTAINER (scrolled_window), layout); gtk_widget_set_events (layout, GDK_EXPOSURE_MASK ); gtk_signal_connect (GTK_OBJECT (layout), "expose_event", GTK_SIGNAL_FUNC (HandleExposeEvent), NULL); gtk_widget_show_all (dialog_window); } int __stdcall WinMain ( struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance, char *lpszCmdLine, int nCmdShow) { gtk_init (&__argc, &__argv); GtkLayoutDialog (); gtk_main (); } -- Salutations, Eric THIERRY
Attachment:
eric.thierry.vcf
Description: Card for Eric THIERRY