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: Sun, 20 Dec 2009 20:26:20 +0300
#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]