Re: Custom widget painting with GtkStyle
- From: Artur Galyamov <artur-pub yandex ru>
- To: Sebastian PajÄk <spconv+m gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Custom widget painting with GtkStyle
- Date: Mon, 21 Dec 2009 09:25:38 +0300
Hmm...
I just found theme on my box, that caused problem too (Raleigh). Do
you see any warnings/errors in console while running?
(a.out:51454): Gtk-CRITICAL **: gtk_paint_box: assertion `GTK_IS_STYLE (style)' failed
If yes, following may help...
(works now with all themes i have + proper style refcounting).
==============================================================
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event)
{
GtkStyle *style;
int was_created;
int x = widget->allocation.x;
int y = widget->allocation.y;
int width = widget->allocation.width;
int height = widget->allocation.height;
was_created = TRUE &&
(style = gtk_rc_get_style_by_paths(gtk_widget_get_settings(widget),
NULL, "GtkButton", GTK_TYPE_BUTTON));
printf("was_created %d\n", was_created);
if (was_created)
style = gtk_style_attach(gtk_style_ref(style), widget->window);
else
style = widget->style;
gtk_paint_box(style, widget->window,
GTK_STATE_NORMAL,
GTK_SHADOW_OUT, &event->area,
widget, "button",
x, y, width, height);
if (was_created) {
gtk_style_detach(style);
gtk_style_unref(style);
}
return FALSE;
}
static GtkWidget *
create_widget(void)
{
GtkWidget *vbox = gtk_vbox_new(FALSE, 4);
GtkWidget *btn0 = gtk_vbox_new(FALSE, 0);
GtkWidget *btn1 = gtk_button_new();
GtkWidget *btn2 = gtk_button_new();
GTK_WIDGET_SET_FLAGS(btn0, GTK_APP_PAINTABLE);
g_signal_connect(btn0, "expose-event",
(GCallback) expose_event, NULL);
gtk_box_pack_start(GTK_BOX(vbox), btn0, 1, 1, 0);
gtk_box_pack_start(GTK_BOX(vbox), btn1, 1, 1, 0);
gtk_box_pack_start(GTK_BOX(vbox), btn2, 1, 1, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
gtk_widget_show_all(vbox);
return vbox;
}
int
main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
auto void on_destroy(void);
auto void on_destroy(void) { gtk_main_quit(); }
g_signal_connect(window, "destroy", (GCallback) on_destroy, NULL);
gtk_container_add(GTK_CONTAINER(window), create_widget());
gtk_widget_show(window);
gtk_main();
return 0;
}
==============================================================
ps. just googled: Raleigh is "no-engine" theme, maybe "MS-Windows"
is same for win32??
--
Artur
20.12.09, 23:00, "Sebastian PajÄk" <spconv+m gmail com>:
Thanks. The code compiles, but the painted box doesn't appear also.
But the fault is somewhere else. I found gtk_paint_box doesn't work
with MS-Windows theme only. With any other theme no problem exists
(yes, I use gtk+ on win xp). It's weird because GtkButton also calls
this function and there is no problem drawing it even with MS-Windows
theme. I have no idea why it is so. Need to study gtk+ source more...
Sebastian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]