Hello, I am a newbie to gtk based app. development.I am a teacher and have to migrate an educational program from gtk1.2 to gtk2.
The main window of this program contains a background image with several buttons for triggering miscellaneous actions. These buttons must reside at fixed locations. So, everything displayed in the main window is contained in a GtkFixed widget, which one belongs to the main window.
I am faced to the following issue: - with gtk1.2, everything works fine. - with gtk2, buttons are hidden "behind" the background image: they are not visible but if one click at the location where a button resides, the corresponding action is triggered.My question is thus: how to force buttons to be painted after the background image has been painted ?
I join a small program which behaves as explained above.When compiled with options CFLAGS=-Wall -Werror `gtk-config --cflags` and LDFLAGS=`gtk-config --libs` the button is displayed upon the background image. When compiled with options CFLAGS=-Wall -Werror `pkg-config --cflags gtk+-2.0` and LDFLAGS=`pkg-config --libs gtk+-2.0` the button is hidden (though it reacts if one click to the right place).
Thanks a lot in advance for any help. Pierre -- Pierre HABRAKEN - mailto:Pierre Habraken imag fr Tél: 04 76 63 59 94 - Fax: 04 76 51 47 93
#include <gtk/gtk.h>
#include <stdio.h>
#include "image.xpm"
GtkWindow *mainwin;
GtkButton *button;
GtkDrawingArea *drawing_area;
GtkFixed *fixed;
GdkPixmap *image;
gboolean realize_event(GtkWidget *widget, gpointer user_data) {
GdkBitmap *mask;
GtkStyle *style;
style = gtk_widget_get_style(GTK_WIDGET(drawing_area));
image = gdk_pixmap_create_from_xpm_d(
GTK_WIDGET(drawing_area)->window,
&mask,
&style->bg[GTK_STATE_NORMAL],
(gchar **)image_xpm);
gdk_window_set_back_pixmap(GTK_WIDGET(drawing_area)->window,
image, FALSE);
printf("realize_event\n");
return TRUE;
}
void cb_button(GtkWidget *w, gpointer func_data) {
printf("button\n");
}
int main(int argc, char **argv) {
gtk_init (&argc, &argv);
mainwin=GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
fixed=GTK_FIXED(gtk_fixed_new());
gtk_widget_show(GTK_WIDGET(fixed));
drawing_area=GTK_DRAWING_AREA(gtk_drawing_area_new());
gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area), 910, 600);
gtk_signal_connect(GTK_OBJECT(drawing_area), "realize",
GTK_SIGNAL_FUNC(realize_event), NULL);
gtk_fixed_put(fixed,GTK_WIDGET(drawing_area),0,0);
button=GTK_BUTTON(gtk_button_new_with_label("Button"));
gtk_widget_show(GTK_WIDGET(button));
gtk_signal_connect(GTK_OBJECT(button), "released",
GTK_SIGNAL_FUNC(cb_button), NULL);
gtk_fixed_put(fixed,GTK_WIDGET(button),680, 264);
gtk_container_add(GTK_CONTAINER(mainwin),GTK_WIDGET(fixed));
gtk_widget_show_all(GTK_WIDGET(mainwin));
gtk_widget_realize(GTK_WIDGET(mainwin));
gtk_main();
return 0;
}
Attachment:
image.xpm.gz
Description: GNU Zip compressed data