2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
1997-11-24 22:37:52 +00:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1997-11-24 22:37:52 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-24 22:37:52 +00:00
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
#include "gtkcheckbutton.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2010-10-19 00:01:31 +00:00
|
|
|
#include "gtkbuttonprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
#include "gtklabel.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkintl.h"
|
2013-05-07 11:46:15 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkcheckbutton
|
|
|
|
* @Short_description: Create widgets with a discrete toggle button
|
|
|
|
* @Title: GtkCheckButton
|
|
|
|
* @See_also: #GtkCheckMenuItem, #GtkButton, #GtkToggleButton, #GtkRadioButton
|
|
|
|
*
|
|
|
|
* A #GtkCheckButton places a discrete #GtkToggleButton next to a widget,
|
|
|
|
* (usually a #GtkLabel). See the section on #GtkToggleButton widgets for
|
|
|
|
* more information about toggle/check buttons.
|
|
|
|
*
|
|
|
|
* The important signal ( #GtkToggleButton::toggled ) is also inherited from
|
|
|
|
* #GtkToggleButton.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-03-02 03:31:13 +00:00
|
|
|
#define INDICATOR_SIZE 16
|
1997-11-24 22:37:52 +00:00
|
|
|
#define INDICATOR_SPACING 2
|
|
|
|
|
|
|
|
|
2013-05-07 11:46:15 +00:00
|
|
|
static void gtk_check_button_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
|
|
|
static void gtk_check_button_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
|
|
|
static void gtk_check_button_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
|
|
|
static void gtk_check_button_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
2013-03-22 11:01:26 +00:00
|
|
|
static void gtk_check_button_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline);
|
1997-11-24 22:37:52 +00:00
|
|
|
static void gtk_check_button_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2010-09-08 13:29:24 +00:00
|
|
|
static gboolean gtk_check_button_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
1999-01-15 16:00:39 +00:00
|
|
|
static void gtk_check_button_paint (GtkWidget *widget,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
static void gtk_check_button_draw_indicator (GtkCheckButton *check_button,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
static void gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2006-05-14 04:25:34 +00:00
|
|
|
G_DEFINE_TYPE (GtkCheckButton, gtk_check_button, GTK_TYPE_TOGGLE_BUTTON)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2014-08-17 04:24:41 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_state_flags)
|
|
|
|
{
|
|
|
|
/* FIXME
|
|
|
|
* This is a hack to get around the optimizations done by the CSS engine.
|
|
|
|
*
|
|
|
|
* The CSS engine will notice that no CSS properties changed on the
|
|
|
|
* widget itself when going from one state to another and not queue
|
|
|
|
* a redraw.
|
|
|
|
* And the reason for no properties changing will be that only the
|
|
|
|
* checkmark itself changes, but that is hidden behind a
|
|
|
|
* gtk_style_context_save()/_restore() pair, so it won't be caught.
|
|
|
|
*/
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->state_flags_changed (widget, previous_state_flags);
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_class_init (GtkCheckButtonClass *class)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class;
|
2010-10-27 01:29:58 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
widget_class = (GtkWidgetClass*) class;
|
2010-10-27 01:29:58 +00:00
|
|
|
|
|
|
|
widget_class->get_preferred_width = gtk_check_button_get_preferred_width;
|
2013-05-07 11:46:15 +00:00
|
|
|
widget_class->get_preferred_width_for_height = gtk_check_button_get_preferred_width_for_height;
|
2010-10-27 01:29:58 +00:00
|
|
|
widget_class->get_preferred_height = gtk_check_button_get_preferred_height;
|
2013-05-07 11:46:15 +00:00
|
|
|
widget_class->get_preferred_height_for_width = gtk_check_button_get_preferred_height_for_width;
|
2013-03-22 11:01:26 +00:00
|
|
|
widget_class->get_preferred_height_and_baseline_for_width = gtk_check_button_get_preferred_height_and_baseline_for_width;
|
1997-11-24 22:37:52 +00:00
|
|
|
widget_class->size_allocate = gtk_check_button_size_allocate;
|
2010-09-08 13:29:24 +00:00
|
|
|
widget_class->draw = gtk_check_button_draw;
|
2014-08-17 04:24:41 +00:00
|
|
|
widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
class->draw_indicator = gtk_real_check_button_draw_indicator;
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
|
2011-07-18 16:18:05 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CHECK_BOX);
|
|
|
|
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_int ("indicator-size",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Indicator Size"),
|
|
|
|
P_("Size of check or radio indicator"),
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
INDICATOR_SIZE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READABLE));
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_int ("indicator-spacing",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Indicator Spacing"),
|
|
|
|
P_("Spacing around check or radio indicator"),
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
INDICATOR_SPACING,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READABLE));
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2012-08-10 17:41:48 +00:00
|
|
|
static void
|
|
|
|
draw_indicator_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkButton *button = GTK_BUTTON (object);
|
|
|
|
|
2014-05-14 02:19:30 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2012-08-10 17:41:48 +00:00
|
|
|
if (gtk_toggle_button_get_mode (GTK_TOGGLE_BUTTON (button)))
|
|
|
|
gtk_button_set_alignment (button, 0.0, 0.5);
|
|
|
|
else
|
|
|
|
gtk_button_set_alignment (button, 0.5, 0.5);
|
2014-05-14 02:19:30 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2012-08-10 17:41:48 +00:00
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_init (GtkCheckButton *check_button)
|
|
|
|
{
|
2010-03-01 16:41:37 +00:00
|
|
|
gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
|
2012-08-10 17:41:48 +00:00
|
|
|
g_signal_connect (check_button, "notify::draw-indicator", G_CALLBACK (draw_indicator_changed), NULL);
|
2010-10-19 02:15:37 +00:00
|
|
|
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkCheckButton.
|
|
|
|
*
|
|
|
|
* Returns: a #GtkWidget.
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkWidget*
|
1998-05-03 22:41:32 +00:00
|
|
|
gtk_check_button_new (void)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2002-10-11 22:57:11 +00:00
|
|
|
return g_object_new (GTK_TYPE_CHECK_BUTTON, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new_with_label:
|
|
|
|
* @label: the text for the check button.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkCheckButton with a #GtkLabel to the right of it.
|
|
|
|
*
|
|
|
|
* Returns: a #GtkWidget.
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkWidget*
|
|
|
|
gtk_check_button_new_with_label (const gchar *label)
|
|
|
|
{
|
2001-08-27 01:05:07 +00:00
|
|
|
return g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 18:58:28 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new_with_mnemonic:
|
|
|
|
* @label: The text of the button, with an underscore in front of the
|
2011-04-13 11:25:06 +00:00
|
|
|
* mnemonic character
|
2001-03-21 18:58:28 +00:00
|
|
|
*
|
2001-06-05 18:22:30 +00:00
|
|
|
* Creates a new #GtkCheckButton containing a label. The label
|
|
|
|
* will be created using gtk_label_new_with_mnemonic(), so underscores
|
|
|
|
* in @label indicate the mnemonic for the check button.
|
2011-09-26 00:58:59 +00:00
|
|
|
*
|
|
|
|
* Returns: a new #GtkCheckButton
|
|
|
|
*/
|
2001-03-21 18:58:28 +00:00
|
|
|
GtkWidget*
|
|
|
|
gtk_check_button_new_with_mnemonic (const gchar *label)
|
|
|
|
{
|
2006-07-06 05:14:03 +00:00
|
|
|
return g_object_new (GTK_TYPE_CHECK_BUTTON,
|
|
|
|
"label", label,
|
|
|
|
"use-underline", TRUE,
|
|
|
|
NULL);
|
2001-03-21 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-15 16:00:39 +00:00
|
|
|
/* This should only be called when toggle_button->draw_indicator
|
|
|
|
* is true.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gtk_check_button_paint (GtkWidget *widget,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr)
|
1999-01-15 16:00:39 +00:00
|
|
|
{
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
GtkCheckButton *check_button = GTK_CHECK_BUTTON (widget);
|
2010-09-08 12:55:53 +00:00
|
|
|
|
2010-09-08 13:29:24 +00:00
|
|
|
gtk_check_button_draw_indicator (check_button, cr);
|
2010-09-08 12:55:53 +00:00
|
|
|
|
2011-08-10 14:00:38 +00:00
|
|
|
if (gtk_widget_has_visible_focus (widget))
|
1999-01-15 16:00:39 +00:00
|
|
|
{
|
2010-09-08 12:55:53 +00:00
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
|
2010-11-19 18:19:42 +00:00
|
|
|
GtkStyleContext *context;
|
2010-09-08 13:29:24 +00:00
|
|
|
GtkAllocation allocation;
|
2011-08-10 14:00:38 +00:00
|
|
|
gint border_width;
|
|
|
|
|
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
2010-09-08 13:29:24 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2010-11-19 18:19:42 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
2010-09-08 12:55:53 +00:00
|
|
|
|
2014-05-01 17:34:48 +00:00
|
|
|
if (child && gtk_widget_get_visible (child))
|
2010-09-08 12:55:53 +00:00
|
|
|
{
|
|
|
|
GtkAllocation child_allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (child, &child_allocation);
|
2010-11-19 18:19:42 +00:00
|
|
|
gtk_render_focus (context, cr,
|
2014-05-04 18:08:34 +00:00
|
|
|
child_allocation.x - allocation.x,
|
|
|
|
child_allocation.y - allocation.y,
|
|
|
|
child_allocation.width,
|
|
|
|
child_allocation.height);
|
2010-09-08 12:55:53 +00:00
|
|
|
}
|
|
|
|
else
|
2010-11-19 18:19:42 +00:00
|
|
|
gtk_render_focus (context, cr,
|
|
|
|
border_width, border_width,
|
|
|
|
allocation.width - 2 * border_width,
|
|
|
|
allocation.height - 2 * border_width);
|
1999-01-15 16:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
void
|
|
|
|
_gtk_check_button_get_props (GtkCheckButton *check_button,
|
|
|
|
gint *indicator_size,
|
|
|
|
gint *indicator_spacing)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (check_button);
|
|
|
|
|
|
|
|
if (indicator_size)
|
2005-03-26 05:49:15 +00:00
|
|
|
gtk_widget_style_get (widget, "indicator-size", indicator_size, NULL);
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
|
|
|
|
if (indicator_spacing)
|
2005-03-26 05:49:15 +00:00
|
|
|
gtk_widget_style_get (widget, "indicator-spacing", indicator_spacing, NULL);
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 23:40:26 +00:00
|
|
|
static void
|
|
|
|
get_padding_and_border (GtkWidget *widget,
|
|
|
|
GtkBorder *border)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkStateFlags state;
|
|
|
|
GtkBorder tmp;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
state = gtk_widget_get_state_flags (widget);
|
|
|
|
|
|
|
|
gtk_style_context_get_padding (context, state, border);
|
|
|
|
gtk_style_context_get_border (context, state, &tmp);
|
|
|
|
border->top += tmp.top;
|
|
|
|
border->right += tmp.right;
|
|
|
|
border->bottom += tmp.bottom;
|
|
|
|
border->left += tmp.left;
|
|
|
|
}
|
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_get_full_border (GtkCheckButton *check_button,
|
|
|
|
GtkBorder *border,
|
|
|
|
gint *indicator)
|
|
|
|
{
|
2014-05-04 18:08:34 +00:00
|
|
|
int indicator_size, indicator_spacing, indicator_extra, border_width;
|
2013-05-07 11:18:00 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2014-05-01 23:40:26 +00:00
|
|
|
get_padding_and_border (GTK_WIDGET (check_button), border);
|
2013-05-07 11:18:00 +00:00
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (check_button));
|
|
|
|
gtk_widget_style_get (GTK_WIDGET (check_button),
|
|
|
|
"indicator-size", &indicator_size,
|
|
|
|
"indicator-spacing", &indicator_spacing,
|
|
|
|
NULL);
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (check_button));
|
|
|
|
|
2014-05-04 18:08:34 +00:00
|
|
|
border->left += border_width;
|
|
|
|
border->right += border_width;
|
|
|
|
border->top += border_width;
|
|
|
|
border->bottom += border_width;
|
2013-05-07 11:18:00 +00:00
|
|
|
|
|
|
|
indicator_extra = indicator_size + 2 * indicator_spacing;
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
indicator_extra += indicator_spacing;
|
|
|
|
if (gtk_widget_get_direction (GTK_WIDGET (check_button)) == GTK_TEXT_DIR_RTL)
|
|
|
|
border->right += indicator_extra;
|
|
|
|
else
|
|
|
|
border->left += indicator_extra;
|
|
|
|
|
|
|
|
if (indicator)
|
|
|
|
*indicator = indicator_size + 2 * indicator_spacing;
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
2013-05-07 11:46:15 +00:00
|
|
|
gtk_check_button_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2002-01-30 22:29:03 +00:00
|
|
|
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (widget);
|
1999-01-11 18:49:54 +00:00
|
|
|
|
2010-10-27 01:29:58 +00:00
|
|
|
if (gtk_toggle_button_get_mode (toggle_button))
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
2013-05-07 11:18:00 +00:00
|
|
|
GtkBorder border;
|
2010-10-27 01:29:58 +00:00
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
gtk_check_button_get_full_border (GTK_CHECK_BUTTON (widget), &border, NULL);
|
2010-10-27 01:29:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
{
|
2013-05-07 11:46:15 +00:00
|
|
|
if (height > -1)
|
|
|
|
height -= border.top + border.bottom;
|
|
|
|
|
|
|
|
_gtk_widget_get_preferred_size_for_size (child,
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
height,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
2013-05-07 11:18:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*minimum = 0;
|
|
|
|
*natural = 0;
|
2010-10-27 01:29:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
*minimum += border.left + border.right;
|
|
|
|
*natural += border.left + border.right;
|
2010-10-27 01:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->get_preferred_width (widget, minimum, natural);
|
|
|
|
}
|
|
|
|
|
2013-05-07 11:46:15 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
gtk_check_button_get_preferred_width_for_height (widget, -1, minimum, natural);
|
|
|
|
}
|
|
|
|
|
2010-10-27 01:29:58 +00:00
|
|
|
static void
|
2013-03-22 11:01:26 +00:00
|
|
|
gtk_check_button_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
2010-10-27 01:29:58 +00:00
|
|
|
{
|
|
|
|
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (widget);
|
|
|
|
|
2010-10-19 02:15:37 +00:00
|
|
|
if (gtk_toggle_button_get_mode (toggle_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
GtkWidget *child;
|
2013-05-07 11:18:00 +00:00
|
|
|
GtkBorder border;
|
|
|
|
gint indicator;
|
2010-06-02 04:28:22 +00:00
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
gtk_check_button_get_full_border (GTK_CHECK_BUTTON (widget), &border, &indicator);
|
2010-10-27 01:29:58 +00:00
|
|
|
|
2010-05-24 20:31:36 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
2010-03-01 06:47:38 +00:00
|
|
|
if (child && gtk_widget_get_visible (child))
|
2010-10-27 01:29:58 +00:00
|
|
|
{
|
|
|
|
gint child_min, child_nat;
|
2013-03-22 11:01:26 +00:00
|
|
|
gint child_min_baseline = -1, child_nat_baseline = -1;
|
2010-09-14 01:33:06 +00:00
|
|
|
|
2013-05-07 11:46:15 +00:00
|
|
|
if (width > -1)
|
|
|
|
width -= border.left + border.right;
|
|
|
|
|
|
|
|
gtk_widget_get_preferred_height_and_baseline_for_width (child, width,
|
2013-03-22 11:01:26 +00:00
|
|
|
&child_min, &child_nat,
|
|
|
|
&child_min_baseline, &child_nat_baseline);
|
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
*minimum = MAX (indicator, child_min);
|
|
|
|
*natural = MAX (indicator, child_nat);
|
|
|
|
|
2013-03-22 11:01:26 +00:00
|
|
|
if (minimum_baseline && child_min_baseline >= 0)
|
2013-05-07 11:18:00 +00:00
|
|
|
*minimum_baseline = child_min_baseline + border.top + (*minimum - child_min) / 2;
|
2013-03-22 11:01:26 +00:00
|
|
|
if (natural_baseline && child_nat_baseline >= 0)
|
2013-05-07 11:18:00 +00:00
|
|
|
*natural_baseline = child_nat_baseline + border.top + (*natural - child_nat) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*minimum = indicator;
|
|
|
|
*natural = indicator;
|
2010-10-27 01:29:58 +00:00
|
|
|
}
|
2001-05-07 15:58:47 +00:00
|
|
|
|
2013-05-07 11:18:00 +00:00
|
|
|
*minimum += border.top + border.bottom;
|
|
|
|
*natural += border.top + border.bottom;
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
else
|
2013-03-22 11:01:26 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->get_preferred_height_and_baseline_for_width (widget, width,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
2013-05-07 11:46:15 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
gtk_check_button_get_preferred_height_and_baseline_for_width (widget, width,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-22 11:01:26 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
gtk_check_button_get_preferred_height_and_baseline_for_width (widget, -1,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_check_button_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
2013-03-22 11:01:26 +00:00
|
|
|
PangoContext *pango_context;
|
|
|
|
PangoFontMetrics *metrics;
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkCheckButton *check_button;
|
1998-11-06 22:05:02 +00:00
|
|
|
GtkToggleButton *toggle_button;
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkButton *button;
|
|
|
|
GtkAllocation child_allocation;
|
2013-03-22 11:01:26 +00:00
|
|
|
gint baseline;
|
2001-12-04 03:27:30 +00:00
|
|
|
|
2001-11-15 21:04:51 +00:00
|
|
|
button = GTK_BUTTON (widget);
|
1997-11-24 22:37:52 +00:00
|
|
|
check_button = GTK_CHECK_BUTTON (widget);
|
1998-11-06 22:05:02 +00:00
|
|
|
toggle_button = GTK_TOGGLE_BUTTON (widget);
|
1999-01-11 18:49:54 +00:00
|
|
|
|
2010-10-19 02:15:37 +00:00
|
|
|
if (gtk_toggle_button_get_mode (toggle_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
2010-08-11 21:15:30 +00:00
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
2010-10-19 00:00:10 +00:00
|
|
|
gdk_window_move_resize (gtk_button_get_event_window (button),
|
1997-11-24 22:37:52 +00:00
|
|
|
allocation->x, allocation->y,
|
|
|
|
allocation->width, allocation->height);
|
2010-05-24 20:31:36 +00:00
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (button));
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2013-05-07 11:18:00 +00:00
|
|
|
GtkBorder border;
|
|
|
|
|
|
|
|
gtk_check_button_get_full_border (check_button, &border, NULL);
|
|
|
|
|
|
|
|
child_allocation.x = allocation->x + border.left;
|
|
|
|
child_allocation.y = allocation->y + border.top;
|
|
|
|
child_allocation.width = allocation->width - border.left - border.right;
|
|
|
|
child_allocation.height = allocation->height - border.top - border.bottom;
|
|
|
|
|
2013-03-22 11:01:26 +00:00
|
|
|
baseline = gtk_widget_get_allocated_baseline (widget);
|
|
|
|
if (baseline != -1)
|
2013-05-07 11:18:00 +00:00
|
|
|
baseline -= border.top;
|
2013-03-22 11:01:26 +00:00
|
|
|
gtk_widget_size_allocate_with_baseline (child, &child_allocation, baseline);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
2013-03-22 11:01:26 +00:00
|
|
|
|
|
|
|
pango_context = gtk_widget_get_pango_context (widget);
|
|
|
|
metrics = pango_context_get_metrics (pango_context,
|
|
|
|
pango_context_get_font_description (pango_context),
|
|
|
|
pango_context_get_language (pango_context));
|
|
|
|
button->priv->baseline_align =
|
|
|
|
(double)pango_font_metrics_get_ascent (metrics) /
|
|
|
|
(pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics));
|
|
|
|
pango_font_metrics_unref (metrics);
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
else
|
2008-08-12 09:06:34 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->size_allocate (widget, allocation);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2010-09-08 13:29:24 +00:00
|
|
|
gtk_check_button_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
1999-01-11 18:49:54 +00:00
|
|
|
GtkToggleButton *toggle_button;
|
|
|
|
GtkBin *bin;
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
1999-01-11 18:49:54 +00:00
|
|
|
|
|
|
|
toggle_button = GTK_TOGGLE_BUTTON (widget);
|
|
|
|
bin = GTK_BIN (widget);
|
2010-10-19 02:15:37 +00:00
|
|
|
|
|
|
|
if (gtk_toggle_button_get_mode (toggle_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2010-09-08 13:29:24 +00:00
|
|
|
gtk_check_button_paint (widget, cr);
|
2010-05-24 20:31:36 +00:00
|
|
|
|
2010-09-08 13:29:24 +00:00
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child)
|
|
|
|
gtk_container_propagate_draw (GTK_CONTAINER (widget),
|
|
|
|
child,
|
|
|
|
cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
2010-09-08 13:29:24 +00:00
|
|
|
else if (GTK_WIDGET_CLASS (gtk_check_button_parent_class)->draw)
|
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->draw (widget, cr);
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_check_button_draw_indicator (GtkCheckButton *check_button,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2010-09-08 13:29:24 +00:00
|
|
|
GtkCheckButtonClass *class = GTK_CHECK_BUTTON_GET_CLASS (check_button);
|
2008-08-12 09:06:34 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
if (class->draw_indicator)
|
2010-09-08 13:29:24 +00:00
|
|
|
class->draw_indicator (check_button, cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
|
2010-09-08 13:29:24 +00:00
|
|
|
cairo_t *cr)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2002-02-22 13:34:28 +00:00
|
|
|
GtkButton *button;
|
1997-11-24 22:37:52 +00:00
|
|
|
gint x, y;
|
Fix G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
Mon Apr 2 10:47:57 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): Fix
G_VALUE_NO_COPY_CONTENTS instead of G_SIGNAL_TYPE_STATIC_SCOPE
stupidity.
Mon Apr 2 00:51:11 2001 Owen Taylor <otaylor@redhat.com>
[ First pass at adding style properties. Still needs some definite
fine-tuning. ]
* gtk/gtkbutton.c: Add ::default_spacing style property.
* gtk/gtkcheckbutton.[ch] gtkradiobutton.c: Add ::indicator_size,
::indicator_spacing style properties.
* gtk/gtkoptionmenu.c: Add ::indicator_size, ::indicator_spacing
style properties.
* gtk/gtk{,h,v}paned.[ch]: Make handle_size a style property
rather than a normal property.
* gtk/gtkwidget.c: Add an ::interior_focus style property to
draw focus inside buttons, in the Windows/Java Metal/etc. style.
* gtk/gtkbutton.c gtk/gtkcheckbutton.c gtk/gtktogglenbutton.c:
Honor ::interior_focus.
* gtk/gtkentry.c: Don't draw focus at all when ::interior_focus is
TRUE.
* gtk/gtkrange.[ch] gtk/gtk{h,v}scrollbar.c gtk/gtk{h,v}scale.c:
Add ::slider_width, ::trough_border, ::stepper_size,
::stepper_spacing style properties.
* gtk/gtkscale.[ch] Add ::slider-length style property.
2001-04-02 15:51:28 +00:00
|
|
|
gint indicator_size;
|
|
|
|
gint indicator_spacing;
|
2013-03-22 11:01:26 +00:00
|
|
|
gint baseline;
|
2010-06-02 04:28:22 +00:00
|
|
|
guint border_width;
|
2010-09-08 13:08:59 +00:00
|
|
|
GtkAllocation allocation;
|
2010-11-19 18:19:42 +00:00
|
|
|
GtkStyleContext *context;
|
2010-01-07 15:47:35 +00:00
|
|
|
|
|
|
|
widget = GTK_WIDGET (check_button);
|
2010-09-08 13:08:59 +00:00
|
|
|
button = GTK_BUTTON (check_button);
|
2010-01-07 15:47:35 +00:00
|
|
|
|
2010-09-08 13:08:59 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2013-03-22 11:01:26 +00:00
|
|
|
baseline = gtk_widget_get_allocated_baseline (widget);
|
2010-11-19 18:19:42 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
2010-08-11 21:15:30 +00:00
|
|
|
|
2010-09-08 13:08:59 +00:00
|
|
|
_gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
|
2001-12-04 03:27:30 +00:00
|
|
|
|
2010-09-08 13:08:59 +00:00
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
2002-02-22 13:34:28 +00:00
|
|
|
|
2010-09-08 13:29:24 +00:00
|
|
|
x = indicator_spacing + border_width;
|
2013-03-22 11:01:26 +00:00
|
|
|
if (baseline == -1)
|
|
|
|
y = (allocation.height - indicator_size) / 2;
|
|
|
|
else
|
|
|
|
y = CLAMP (baseline - indicator_size * button->priv->baseline_align,
|
|
|
|
0, allocation.height - indicator_size);
|
2010-06-02 04:28:22 +00:00
|
|
|
|
2010-09-08 13:08:59 +00:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2010-09-08 13:29:24 +00:00
|
|
|
x = allocation.width - (indicator_size + x);
|
2001-12-04 03:27:30 +00:00
|
|
|
|
2011-12-15 02:43:49 +00:00
|
|
|
gtk_style_context_save (context);
|
2002-11-10 20:52:34 +00:00
|
|
|
|
2014-08-16 22:58:04 +00:00
|
|
|
gtk_render_background (context, cr,
|
|
|
|
border_width, border_width,
|
|
|
|
allocation.width - (2 * border_width),
|
|
|
|
allocation.height - (2 * border_width));
|
2010-11-19 18:19:42 +00:00
|
|
|
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
|
|
|
|
|
|
|
|
gtk_render_check (context, cr,
|
|
|
|
x, y, indicator_size, indicator_size);
|
2010-09-08 13:08:59 +00:00
|
|
|
|
2010-11-19 18:19:42 +00:00
|
|
|
gtk_style_context_restore (context);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|