forked from AuroraMiddleware/gtk
2c9eb3a572
Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
276 lines
8.1 KiB
C
276 lines
8.1 KiB
C
/* GTK - The GIMP Toolkit
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* 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
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
/*
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
* 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/.
|
|
*/
|
|
|
|
#include "gtkcheckmenuitem.h"
|
|
#include "gtkaccellabel.h"
|
|
#include "gtksignal.h"
|
|
|
|
#define CHECK_TOGGLE_SIZE 12
|
|
|
|
enum {
|
|
TOGGLED,
|
|
LAST_SIGNAL
|
|
};
|
|
|
|
|
|
static void gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass);
|
|
static void gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item);
|
|
static gint gtk_check_menu_item_expose (GtkWidget *widget,
|
|
GdkEventExpose *event);
|
|
static void gtk_check_menu_item_activate (GtkMenuItem *menu_item);
|
|
static void gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item,
|
|
guint16 *requisition);
|
|
static void gtk_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
|
|
GdkRectangle *area);
|
|
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
|
|
GdkRectangle *area);
|
|
|
|
|
|
static GtkMenuItemClass *parent_class = NULL;
|
|
static guint check_menu_item_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
GtkType
|
|
gtk_check_menu_item_get_type (void)
|
|
{
|
|
static GtkType check_menu_item_type = 0;
|
|
|
|
if (!check_menu_item_type)
|
|
{
|
|
static const GtkTypeInfo check_menu_item_info =
|
|
{
|
|
"GtkCheckMenuItem",
|
|
sizeof (GtkCheckMenuItem),
|
|
sizeof (GtkCheckMenuItemClass),
|
|
(GtkClassInitFunc) gtk_check_menu_item_class_init,
|
|
(GtkObjectInitFunc) gtk_check_menu_item_init,
|
|
/* reserved_1 */ NULL,
|
|
/* reserved_2 */ NULL,
|
|
(GtkClassInitFunc) NULL,
|
|
};
|
|
|
|
check_menu_item_type = gtk_type_unique (GTK_TYPE_MENU_ITEM, &check_menu_item_info);
|
|
}
|
|
|
|
return check_menu_item_type;
|
|
}
|
|
|
|
static void
|
|
gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
|
|
{
|
|
GtkObjectClass *object_class;
|
|
GtkWidgetClass *widget_class;
|
|
GtkMenuItemClass *menu_item_class;
|
|
|
|
object_class = (GtkObjectClass*) klass;
|
|
widget_class = (GtkWidgetClass*) klass;
|
|
menu_item_class = (GtkMenuItemClass*) klass;
|
|
|
|
parent_class = gtk_type_class (GTK_TYPE_MENU_ITEM);
|
|
|
|
widget_class->expose_event = gtk_check_menu_item_expose;
|
|
|
|
menu_item_class->activate = gtk_check_menu_item_activate;
|
|
menu_item_class->hide_on_activate = FALSE;
|
|
menu_item_class->toggle_size_request = gtk_check_menu_item_toggle_size_request;
|
|
|
|
klass->toggled = NULL;
|
|
klass->draw_indicator = gtk_real_check_menu_item_draw_indicator;
|
|
|
|
check_menu_item_signals[TOGGLED] =
|
|
gtk_signal_new ("toggled",
|
|
GTK_RUN_FIRST,
|
|
GTK_CLASS_TYPE (object_class),
|
|
GTK_SIGNAL_OFFSET (GtkCheckMenuItemClass, toggled),
|
|
gtk_marshal_VOID__VOID,
|
|
GTK_TYPE_NONE, 0);
|
|
}
|
|
|
|
GtkWidget*
|
|
gtk_check_menu_item_new (void)
|
|
{
|
|
return GTK_WIDGET (gtk_type_new (GTK_TYPE_CHECK_MENU_ITEM));
|
|
}
|
|
|
|
GtkWidget*
|
|
gtk_check_menu_item_new_with_label (const gchar *label)
|
|
{
|
|
GtkWidget *check_menu_item;
|
|
GtkWidget *accel_label;
|
|
|
|
check_menu_item = gtk_check_menu_item_new ();
|
|
accel_label = gtk_accel_label_new (label);
|
|
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
|
|
|
|
gtk_container_add (GTK_CONTAINER (check_menu_item), accel_label);
|
|
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), check_menu_item);
|
|
gtk_widget_show (accel_label);
|
|
|
|
return check_menu_item;
|
|
}
|
|
|
|
void
|
|
gtk_check_menu_item_set_active (GtkCheckMenuItem *check_menu_item,
|
|
gboolean is_active)
|
|
{
|
|
g_return_if_fail (check_menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
|
|
|
|
is_active = is_active != 0;
|
|
|
|
if (check_menu_item->active != is_active)
|
|
gtk_menu_item_activate (GTK_MENU_ITEM (check_menu_item));
|
|
}
|
|
|
|
static void
|
|
gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item,
|
|
guint16 *requisition)
|
|
{
|
|
g_return_if_fail (menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item));
|
|
|
|
*requisition = CHECK_TOGGLE_SIZE;
|
|
}
|
|
|
|
void
|
|
gtk_check_menu_item_set_show_toggle (GtkCheckMenuItem *menu_item,
|
|
gboolean always)
|
|
{
|
|
g_return_if_fail (menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item));
|
|
|
|
#if 0
|
|
menu_item->always_show_toggle = always != FALSE;
|
|
#endif
|
|
}
|
|
|
|
void
|
|
gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item)
|
|
{
|
|
gtk_signal_emit (GTK_OBJECT (check_menu_item), check_menu_item_signals[TOGGLED]);
|
|
}
|
|
|
|
static void
|
|
gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item)
|
|
{
|
|
check_menu_item->active = FALSE;
|
|
check_menu_item->always_show_toggle = TRUE;
|
|
}
|
|
|
|
static gint
|
|
gtk_check_menu_item_expose (GtkWidget *widget,
|
|
GdkEventExpose *event)
|
|
{
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
g_return_val_if_fail (GTK_IS_CHECK_MENU_ITEM (widget), FALSE);
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->expose_event)
|
|
(* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
|
|
|
|
gtk_check_menu_item_draw_indicator (GTK_CHECK_MENU_ITEM (widget), &event->area);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
static void
|
|
gtk_check_menu_item_activate (GtkMenuItem *menu_item)
|
|
{
|
|
GtkCheckMenuItem *check_menu_item;
|
|
|
|
g_return_if_fail (menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item));
|
|
|
|
check_menu_item = GTK_CHECK_MENU_ITEM (menu_item);
|
|
check_menu_item->active = !check_menu_item->active;
|
|
|
|
gtk_check_menu_item_toggled (check_menu_item);
|
|
gtk_widget_queue_draw (GTK_WIDGET (check_menu_item));
|
|
}
|
|
|
|
static void
|
|
gtk_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
|
|
GdkRectangle *area)
|
|
{
|
|
g_return_if_fail (check_menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
|
|
g_return_if_fail (GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item) != NULL);
|
|
|
|
if (GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator)
|
|
(* GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator) (check_menu_item, area);
|
|
}
|
|
|
|
static void
|
|
gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
|
|
GdkRectangle *area)
|
|
{
|
|
GtkWidget *widget;
|
|
GtkStateType state_type;
|
|
GtkShadowType shadow_type;
|
|
gint width, height;
|
|
gint x, y;
|
|
|
|
g_return_if_fail (check_menu_item != NULL);
|
|
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
|
|
|
|
if (GTK_WIDGET_DRAWABLE (check_menu_item))
|
|
{
|
|
widget = GTK_WIDGET (check_menu_item);
|
|
|
|
width = 8;
|
|
height = 8;
|
|
x = (GTK_CONTAINER (check_menu_item)->border_width +
|
|
widget->style->xthickness + 2);
|
|
y = (widget->allocation.height - height) / 2;
|
|
|
|
if (check_menu_item->active ||
|
|
check_menu_item->always_show_toggle ||
|
|
(GTK_WIDGET_STATE (check_menu_item) == GTK_STATE_PRELIGHT))
|
|
{
|
|
state_type = GTK_WIDGET_STATE (widget);
|
|
|
|
if (check_menu_item->always_show_toggle)
|
|
{
|
|
shadow_type = GTK_SHADOW_OUT;
|
|
if (check_menu_item->active)
|
|
shadow_type = GTK_SHADOW_IN;
|
|
}
|
|
else
|
|
{
|
|
shadow_type = GTK_SHADOW_IN;
|
|
if (check_menu_item->active &&
|
|
(state_type == GTK_STATE_PRELIGHT))
|
|
shadow_type = GTK_SHADOW_OUT;
|
|
}
|
|
|
|
gtk_paint_check (widget->style, widget->window,
|
|
state_type, shadow_type,
|
|
area, widget, "check",
|
|
x, y, width, height);
|
|
}
|
|
}
|
|
}
|