button: Port to draw vfunc

Also port togglebutton, they use the same paint function.
This commit is contained in:
Benjamin Otte
2010-09-08 00:23:04 +02:00
parent e0be884297
commit 748d3d612d
3 changed files with 55 additions and 55 deletions

View File

@ -128,7 +128,7 @@ static void gtk_button_unmap (GtkWidget * widget);
static void gtk_button_style_set (GtkWidget * widget, GtkStyle * prev_style); static void gtk_button_style_set (GtkWidget * widget, GtkStyle * prev_style);
static void gtk_button_size_allocate (GtkWidget * widget, static void gtk_button_size_allocate (GtkWidget * widget,
GtkAllocation * allocation); GtkAllocation * allocation);
static gint gtk_button_expose (GtkWidget * widget, GdkEventExpose * event); static gint gtk_button_draw (GtkWidget * widget, cairo_t *cr);
static gint gtk_button_button_press (GtkWidget * widget, static gint gtk_button_button_press (GtkWidget * widget,
GdkEventButton * event); GdkEventButton * event);
static gint gtk_button_button_release (GtkWidget * widget, static gint gtk_button_button_release (GtkWidget * widget,
@ -215,7 +215,7 @@ gtk_button_class_init (GtkButtonClass *klass)
widget_class->unmap = gtk_button_unmap; widget_class->unmap = gtk_button_unmap;
widget_class->style_set = gtk_button_style_set; widget_class->style_set = gtk_button_style_set;
widget_class->size_allocate = gtk_button_size_allocate; widget_class->size_allocate = gtk_button_size_allocate;
widget_class->expose_event = gtk_button_expose; widget_class->draw = gtk_button_draw;
widget_class->button_press_event = gtk_button_button_press; widget_class->button_press_event = gtk_button_button_press;
widget_class->button_release_event = gtk_button_button_release; widget_class->button_release_event = gtk_button_button_release;
widget_class->grab_broken_event = gtk_button_grab_broken; widget_class->grab_broken_event = gtk_button_grab_broken;
@ -1534,14 +1534,15 @@ gtk_button_size_allocate (GtkWidget *widget,
void void
_gtk_button_paint (GtkButton *button, _gtk_button_paint (GtkButton *button,
const GdkRectangle *area, cairo_t *cr,
int width,
int height,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
const gchar *main_detail, const gchar *main_detail,
const gchar *default_detail) const gchar *default_detail)
{ {
GtkWidget *widget; GtkWidget *widget;
gint width, height;
gint x, y; gint x, y;
GtkBorder default_border; GtkBorder default_border;
GtkBorder default_outside_border; GtkBorder default_outside_border;
@ -1564,17 +1565,15 @@ _gtk_button_paint (GtkButton *button,
style = gtk_widget_get_style (widget); style = gtk_widget_get_style (widget);
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
x = allocation.x; x = 0;
y = allocation.y; y = 0;
width = allocation.width;
height = allocation.height;
if (gtk_widget_has_default (widget) && if (gtk_widget_has_default (widget) &&
GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL) GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
{ {
gtk_paint_box (style, window, gtk_cairo_paint_box (style, cr,
GTK_STATE_NORMAL, GTK_SHADOW_IN, GTK_STATE_NORMAL, GTK_SHADOW_IN,
area, widget, "buttondefault", widget, "buttondefault",
x, y, width, height); x, y, width, height);
x += default_border.left; x += default_border.left;
@ -1600,9 +1599,9 @@ _gtk_button_paint (GtkButton *button,
if (button->relief != GTK_RELIEF_NONE || button->depressed || if (button->relief != GTK_RELIEF_NONE || button->depressed ||
gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT)
gtk_paint_box (style, window, gtk_cairo_paint_box (style, cr,
state_type, state_type,
shadow_type, area, widget, "button", shadow_type, widget, "button",
x, y, width, height); x, y, width, height);
if (gtk_widget_has_focus (widget)) if (gtk_widget_has_focus (widget))
@ -1638,28 +1637,27 @@ _gtk_button_paint (GtkButton *button,
y += child_displacement_y; y += child_displacement_y;
} }
gtk_paint_focus (style, window, gtk_cairo_paint_focus (style, cr,
gtk_widget_get_state (widget), gtk_widget_get_state (widget),
area, widget, "button", widget, "button",
x, y, width, height); x, y, width, height);
} }
} }
static gboolean static gboolean
gtk_button_expose (GtkWidget *widget, gtk_button_draw (GtkWidget *widget,
GdkEventExpose *event) cairo_t *cr)
{
if (gtk_widget_is_drawable (widget))
{ {
GtkButton *button = GTK_BUTTON (widget); GtkButton *button = GTK_BUTTON (widget);
_gtk_button_paint (button, &event->area, _gtk_button_paint (button, cr,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget),
gtk_widget_get_state (widget), gtk_widget_get_state (widget),
button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT, button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
"button", "buttondefault"); "button", "buttondefault");
GTK_WIDGET_CLASS (gtk_button_parent_class)->expose_event (widget, event); GTK_WIDGET_CLASS (gtk_button_parent_class)->draw (widget, cr);
}
return FALSE; return FALSE;
} }

View File

@ -136,7 +136,9 @@ GdkWindow* gtk_button_get_event_window (GtkButton *button);
void _gtk_button_set_depressed (GtkButton *button, void _gtk_button_set_depressed (GtkButton *button,
gboolean depressed); gboolean depressed);
void _gtk_button_paint (GtkButton *button, void _gtk_button_paint (GtkButton *button,
const GdkRectangle *area, cairo_t *cr,
int width,
int height,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
const gchar *main_detail, const gchar *main_detail,

View File

@ -52,8 +52,8 @@ enum {
}; };
static gint gtk_toggle_button_expose (GtkWidget *widget, static gint gtk_toggle_button_draw (GtkWidget *widget,
GdkEventExpose *event); cairo_t *cr);
static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget, static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling); gboolean group_cycling);
static void gtk_toggle_button_pressed (GtkButton *button); static void gtk_toggle_button_pressed (GtkButton *button);
@ -98,7 +98,7 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
gobject_class->set_property = gtk_toggle_button_set_property; gobject_class->set_property = gtk_toggle_button_set_property;
gobject_class->get_property = gtk_toggle_button_get_property; gobject_class->get_property = gtk_toggle_button_get_property;
widget_class->expose_event = gtk_toggle_button_expose; widget_class->draw = gtk_toggle_button_draw;
widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate; widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate;
button_class->pressed = gtk_toggle_button_pressed; button_class->pressed = gtk_toggle_button_pressed;
@ -416,10 +416,8 @@ gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button)
} }
static gint static gint
gtk_toggle_button_expose (GtkWidget *widget, gtk_toggle_button_draw (GtkWidget *widget,
GdkEventExpose *event) cairo_t *cr)
{
if (gtk_widget_is_drawable (widget))
{ {
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget)); GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
GtkButton *button = GTK_BUTTON (widget); GtkButton *button = GTK_BUTTON (widget);
@ -437,12 +435,14 @@ gtk_toggle_button_expose (GtkWidget *widget,
else else
shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
_gtk_button_paint (button, &event->area, state_type, shadow_type, _gtk_button_paint (button, cr,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget),
state_type, shadow_type,
"togglebutton", "togglebuttondefault"); "togglebutton", "togglebuttondefault");
if (child) if (child)
gtk_container_propagate_expose (GTK_CONTAINER (widget), child, event); gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
}
return FALSE; return FALSE;
} }