diff options
author | Carsten Haitzler <raster@src.gnome.org> | 1998-07-03 20:33:16 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@src.gnome.org> | 1998-07-03 20:33:16 +0000 |
commit | 4389781ea1ec28ddcfc7a2c7f543ce7405d34f31 (patch) | |
tree | 924b41dff9752c6dd7f91fdea0e5b4f51135c302 /gtk/gtkcheckbutton.c | |
parent | 0da6bdc3304d7fcd0d37e04a117804b229990d1f (diff) | |
download | gtk+-themes.tar.gz |
Wheee now others can get to play :)themes
Wheee now others can get to play :)
Diffstat (limited to 'gtk/gtkcheckbutton.c')
-rw-r--r-- | gtk/gtkcheckbutton.c | 381 |
1 files changed, 248 insertions, 133 deletions
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c index 834e954e4b..54998e803a 100644 --- a/gtk/gtkcheckbutton.c +++ b/gtk/gtkcheckbutton.c @@ -16,6 +16,8 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gtkcheckbutton.h" +#include "gtkthemes.h" +#include "gtkprivate.h" #include "gtklabel.h" @@ -38,8 +40,9 @@ static gint gtk_check_button_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_check_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area); -static void gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, - GdkRectangle *area); +static void gtk_check_button_realize (GtkWidget *widget); +static void gtk_check_button_unrealize (GtkWidget *widget); +static void gtk_check_button_unmap (GtkWidget *widget); static GtkToggleButtonClass *parent_class = NULL; @@ -72,7 +75,7 @@ gtk_check_button_get_type () static void gtk_check_button_class_init (GtkCheckButtonClass *class) { - GtkWidgetClass *widget_class; + GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; parent_class = gtk_type_class (gtk_toggle_button_get_type ()); @@ -85,7 +88,124 @@ gtk_check_button_class_init (GtkCheckButtonClass *class) class->indicator_size = INDICATOR_SIZE; class->indicator_spacing = INDICATOR_SPACING; - class->draw_indicator = gtk_real_check_button_draw_indicator; + + widget_class->realize = gtk_check_button_realize; + widget_class->unrealize = gtk_check_button_unrealize; +} + +static void +gtk_check_button_unmap (GtkWidget *widget) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); + + GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); +/* gdk_window_hide (widget->window);*/ + gdk_window_clear_area(widget->window,widget->allocation.x, + widget->allocation.y, + widget->allocation.width, + widget->allocation.height); + gtk_widget_draw (widget, NULL); +} + +static void +gtk_check_button_realize (GtkWidget *widget) +{ + GtkCheckButton *check_button; + GdkWindowAttr attributes; + gint attributes_mask; + gint border_width; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); + + check_button = GTK_CHECK_BUTTON (widget); + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + border_width = GTK_CONTAINER (widget)->border_width; + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = widget->allocation.x + border_width; + attributes.y = widget->allocation.y + border_width; + attributes.width = widget->allocation.width - border_width * 2; + attributes.height = widget->allocation.height - border_width * 2; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); + attributes.event_mask |= (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + + widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); + gdk_window_set_user_data (widget->window, check_button); + + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + + if (check_button->init) + check_button->init(GTK_WIDGET(widget)); +} + +static void +gtk_check_button_unrealize (GtkWidget *widget) +{ + GtkButton *check_button; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + check_button=GTK_CHECK_BUTTON(widget); + + if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_MAPPED (widget)) + gtk_check_button_unmap (widget); + + GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED); + + + gtk_style_detach (widget->style); + if (!GTK_WIDGET_NO_WINDOW (widget)) + { + gdk_window_set_user_data (widget->window, NULL); + gdk_window_destroy (widget->window); + } + else + { + gdk_window_unref (widget->window); + } + + if (GTK_IS_CONTAINER (widget)) + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)gtk_widget_unrealize, + NULL); + if (check_button->exit) + check_button->exit(GTK_WIDGET(widget)); + + widget->window = NULL; +} + +void +gtk_check_button_set_theme (GtkCheckButton *check_button, + void (* init) (GtkWidget *check_button), + void (* border) (GtkWidget *check_button), + void (* draw) (GtkWidget *check_button, GdkRectangle *area), + void (* exit) (GtkWidget *check_button)) +{ + if (GTK_WIDGET_REALIZED(GTK_WIDGET(check_button))) + check_button->exit(GTK_WIDGET(check_button)); + check_button->init=init; + check_button->border=border; + check_button->draw=draw; + check_button->exit=exit; + if (GTK_WIDGET_REALIZED(GTK_WIDGET(check_button))) + { + check_button->init(GTK_WIDGET(check_button)); + check_button->draw(GTK_WIDGET(check_button),NULL); + } } static void @@ -97,7 +217,17 @@ gtk_check_button_init (GtkCheckButton *check_button) GtkWidget* gtk_check_button_new () { - return GTK_WIDGET (gtk_type_new (gtk_check_button_get_type ())); + GtkCheckButton *check_button; + + check_button = GTK_CHECK_BUTTON (gtk_type_new (gtk_check_button_get_type ())); + if (check_button) + { + check_button->init=th_dat.functions.check_button.init; + check_button->border=th_dat.functions.check_button.border; + check_button->draw=th_dat.functions.check_button.draw; + check_button->exit=th_dat.functions.check_button.exit; + } + return GTK_WIDGET(check_button); } @@ -124,70 +254,126 @@ gtk_check_button_draw (GtkWidget *widget, GtkButton *button; GtkCheckButton *check_button; GdkRectangle child_area; + GdkRectangle dummy_area; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); - g_return_if_fail (area != NULL); +/* g_return_if_fail (area != NULL);*/ if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { - check_button = GTK_CHECK_BUTTON (widget); - - if (check_button->toggle_button.draw_indicator) - { - button = GTK_BUTTON (widget); - - gtk_check_button_draw_indicator (check_button, area); - - if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && - gtk_widget_intersect (button->child, area, &child_area)) - gtk_widget_draw (button->child, &child_area); - - gtk_widget_draw_focus (widget); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->draw) - (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area); - } + check_button = GTK_CHECK_BUTTON (widget); + button = GTK_BUTTON (widget); + + if (!area) + { +/* dummy_area.x = widget->allocation.x; + dummy_area.y = widget->allocation.y;*/ + dummy_area.x = 0; + dummy_area.y = 0; + dummy_area.width = widget->allocation.width; + dummy_area.height = widget->allocation.height; + area = & dummy_area; + } +/* if (GTK_WIDGET_CLASS (parent_class)->draw) + (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area);*/ + if (check_button->draw) + { + check_button->draw(GTK_WIDGET(widget),area); + if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && + gtk_widget_intersect (button->child, area, &child_area)) + { + gtk_widget_draw (button->child, area); + } + } + else + { + GtkToggleButton *toggle_button; + GtkStateType state_type; + GtkShadowType shadow_type; + GdkRectangle restrict_area; + GdkRectangle new_area; + gint width, height; + gint x, y; + + if (GTK_WIDGET_DRAWABLE (check_button)) + { + widget = GTK_WIDGET (check_button); + toggle_button = GTK_TOGGLE_BUTTON (check_button); + + state_type = GTK_WIDGET_STATE (widget); + if ((state_type != GTK_STATE_NORMAL) && + (state_type != GTK_STATE_PRELIGHT)) + state_type = GTK_STATE_NORMAL; + + restrict_area.x = GTK_CONTAINER (widget)->border_width; + restrict_area.y = restrict_area.x; + restrict_area.width = widget->allocation.width - restrict_area.x * 2; + restrict_area.height = widget->allocation.height - restrict_area.x * 2; + + if (gdk_rectangle_intersect (area, &restrict_area, &new_area)) + { + gtk_style_set_background (widget->style, widget->window, state_type); + gdk_window_clear_area (widget->window, new_area.x, new_area.y, + new_area.width, new_area.height); + } + + x = CHECK_BUTTON_CLASS (widget)->indicator_spacing + GTK_CONTAINER (widget)->border_width; + y = (widget->allocation.height - CHECK_BUTTON_CLASS (widget)->indicator_size) / 2; + width = CHECK_BUTTON_CLASS (widget)->indicator_size; + height = CHECK_BUTTON_CLASS (widget)->indicator_size; + + if (GTK_TOGGLE_BUTTON (widget)->active) + shadow_type = GTK_SHADOW_IN; + else + shadow_type = GTK_SHADOW_OUT; + + gdk_draw_rectangle (widget->window, + widget->style->bg_gc[GTK_WIDGET_STATE (widget)], + TRUE, x + 1, y + 1, width, height); + gtk_draw_shadow (widget->style, widget->window, + GTK_WIDGET_STATE (widget), shadow_type, + x + 1, y + 1, width, height); + } + if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && + gtk_widget_intersect (button->child, area, &child_area)) + gtk_widget_draw (button->child, &child_area); + + if (GTK_WIDGET_DRAWABLE (widget)) + { + check_button = GTK_CHECK_BUTTON (widget); + if (check_button->toggle_button.draw_indicator) + { + gint border_width; + + border_width = GTK_CONTAINER (widget)->border_width; + if (GTK_WIDGET_HAS_FOCUS (widget)) + gdk_draw_rectangle (widget->window, + widget->style->black_gc, FALSE, + border_width, border_width, + widget->allocation.width - 2 * border_width - 1, + widget->allocation.height - 2 * border_width - 1); + else + gdk_draw_rectangle (widget->window, + widget->style->bg_gc[GTK_STATE_NORMAL], FALSE, + border_width, border_width, + widget->allocation.width - 2 * border_width - 1, + widget->allocation.height - 2 * border_width - 1); + } + else + { + if (GTK_WIDGET_CLASS (parent_class)->draw_focus) + (* GTK_WIDGET_CLASS (parent_class)->draw_focus) (widget); + } + } + } } } -static void +void gtk_check_button_draw_focus (GtkWidget *widget) { - GtkCheckButton *check_button; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - check_button = GTK_CHECK_BUTTON (widget); - if (check_button->toggle_button.draw_indicator) - { - gint border_width; - - border_width = GTK_CONTAINER (widget)->border_width; - if (GTK_WIDGET_HAS_FOCUS (widget)) - gdk_draw_rectangle (widget->window, - widget->style->black_gc, FALSE, - border_width, border_width, - widget->allocation.width - 2 * border_width - 1, - widget->allocation.height - 2 * border_width - 1); - else - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_STATE_NORMAL], FALSE, - border_width, border_width, - widget->allocation.width - 2 * border_width - 1, - widget->allocation.height - 2 * border_width - 1); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->draw_focus) - (* GTK_WIDGET_CLASS (parent_class)->draw_focus) (widget); - } - } + gtk_check_button_draw(widget, NULL); } static void @@ -279,24 +465,18 @@ gtk_check_button_expose (GtkWidget *widget, { check_button = GTK_CHECK_BUTTON (widget); - if (check_button->toggle_button.draw_indicator) + gtk_check_button_draw(GTK_WIDGET(check_button), &event->area); +/* if (check_button->toggle_button.draw_indicator) { button = GTK_BUTTON (widget); - gtk_check_button_draw_indicator (check_button, &event->area); child_event = *event; if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && gtk_widget_intersect (button->child, &event->area, &child_event.area)) gtk_widget_event (button->child, (GdkEvent*) &child_event); - - gtk_widget_draw_focus (widget); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); } + */ } return FALSE; @@ -307,71 +487,6 @@ static void gtk_check_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area) { - GtkCheckButtonClass *class; - - g_return_if_fail (check_button != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button)); - g_return_if_fail (CHECK_BUTTON_CLASS (check_button) != NULL); - - class = CHECK_BUTTON_CLASS (check_button); - - if (class->draw_indicator) - (* class->draw_indicator) (check_button, area); + gtk_check_button_draw (GTK_WIDGET(check_button), NULL); } -static void -gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, - GdkRectangle *area) -{ - GtkWidget *widget; - GtkToggleButton *toggle_button; - GtkStateType state_type; - GtkShadowType shadow_type; - GdkRectangle restrict_area; - GdkRectangle new_area; - gint width, height; - gint x, y; - - g_return_if_fail (check_button != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button)); - - if (GTK_WIDGET_DRAWABLE (check_button)) - { - widget = GTK_WIDGET (check_button); - toggle_button = GTK_TOGGLE_BUTTON (check_button); - - state_type = GTK_WIDGET_STATE (widget); - if ((state_type != GTK_STATE_NORMAL) && - (state_type != GTK_STATE_PRELIGHT)) - state_type = GTK_STATE_NORMAL; - - restrict_area.x = GTK_CONTAINER (widget)->border_width; - restrict_area.y = restrict_area.x; - restrict_area.width = widget->allocation.width - restrict_area.x * 2; - restrict_area.height = widget->allocation.height - restrict_area.x * 2; - - if (gdk_rectangle_intersect (area, &restrict_area, &new_area)) - { - gtk_style_set_background (widget->style, widget->window, state_type); - gdk_window_clear_area (widget->window, new_area.x, new_area.y, - new_area.width, new_area.height); - } - - x = CHECK_BUTTON_CLASS (widget)->indicator_spacing + GTK_CONTAINER (widget)->border_width; - y = (widget->allocation.height - CHECK_BUTTON_CLASS (widget)->indicator_size) / 2; - width = CHECK_BUTTON_CLASS (widget)->indicator_size; - height = CHECK_BUTTON_CLASS (widget)->indicator_size; - - if (GTK_TOGGLE_BUTTON (widget)->active) - shadow_type = GTK_SHADOW_IN; - else - shadow_type = GTK_SHADOW_OUT; - - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_WIDGET_STATE (widget)], - TRUE, x + 1, y + 1, width, height); - gtk_draw_shadow (widget->style, widget->window, - GTK_WIDGET_STATE (widget), shadow_type, - x + 1, y + 1, width, height); - } -} |