Re: Custom widget painting with GtkStyle
- From: Sebastian PajÄk <spconv+m gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: Custom widget painting with GtkStyle
- Date: Sun, 20 Dec 2009 23:00:54 +0100
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
2009/12/20 Artur Galyamov <artur-pub yandex ru>:
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event)
{
 Âstatic GtkStyle *style = NULL;
 Âint x = widget->allocation.x;
 Âint y = widget->allocation.y;
 Âint width = widget->allocation.width;
 Âint height = widget->allocation.height;
 Âif (!style)
   Âstyle = gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL,
     Â"GtkButton", GTK_TYPE_BUTTON);
 Âstyle = gtk_style_attach(style, widget->window);
 Âgtk_paint_box(style, widget->window,
   ÂGTK_STATE_NORMAL,
   ÂGTK_SHADOW_OUT, &event->area,
   Âwidget, "button",
   Âx, y, width, height);
 Âgtk_style_detach(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;
}
Attaches don't work here..
--
Artur
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]