* 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
+#include "a11y/gtkcheckmenuitemaccessible.h"
+/**
+ * SECTION:gtkcheckmenuitem
+ * @Short_description: A menu item with a check box
+ * @Title: GtkCheckMenuItem
+ *
+ * A #GtkCheckMenuItem is a menu item that maintains the state of a boolean
+ * value in addition to a #GtkMenuItem usual role in activating application
+ * code.
+ *
+ * A check box indicating the state of the boolean value is displayed
+ * at the left side of the #GtkMenuItem. Activating the #GtkMenuItem
+ * toggles the value.
+ */
+#define INDICATOR_SIZE 16
+
struct _GtkCheckMenuItemPrivate
{
guint active : 1;
P_("Size of check or radio indicator"),
0,
G_MAXINT,
- 13,
+ INDICATOR_SIZE,
GTK_PARAM_READABLE));
widget_class->draw = gtk_check_menu_item_draw;
-
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_CHECK_MENU_ITEM_ACCESSIBLE);
+
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;
+ /**
+ * GtkCheckMenuItem::toggled:
+ * @checkmenuitem: the object which received the signal.
+ *
+ * This signal is emitted when the state of the check box is changed.
+ *
+ * A signal handler can use gtk_check_menu_item_get_active()
+ * to discover the new state.
+ */
check_menu_item_signals[TOGGLED] =
g_signal_new (I_("toggled"),
G_OBJECT_CLASS_TYPE (gobject_class),
gtk_toggle_action_get_draw_as_radio (GTK_TOGGLE_ACTION (action)));
}
+/**
+ * gtk_check_menu_item_new:
+ *
+ * Creates a new #GtkCheckMenuItem.
+ *
+ * Returns: a new #GtkCheckMenuItem.
+ */
GtkWidget*
gtk_check_menu_item_new (void)
{
return g_object_new (GTK_TYPE_CHECK_MENU_ITEM, NULL);
}
+/**
+ * gtk_check_menu_item_new_with_label:
+ * @label: the string to use for the label.
+ *
+ * Creates a new #GtkCheckMenuItem with a label.
+ *
+ * Returns: a new #GtkCheckMenuItem.
+ */
GtkWidget*
gtk_check_menu_item_new_with_label (const gchar *label)
{
/**
* gtk_check_menu_item_new_with_mnemonic:
* @label: The text of the button, with an underscore in front of the
- * mnemonic character
- * @returns: a new #GtkCheckMenuItem
+ * character
*
* Creates a new #GtkCheckMenuItem containing a label. The label
* will be created using gtk_label_new_with_mnemonic(), so underscores
* in @label indicate the mnemonic for the menu item.
- **/
+ *
+ * Returns: a new #GtkCheckMenuItem
+ */
GtkWidget*
gtk_check_menu_item_new_with_mnemonic (const gchar *label)
{
NULL);
}
+/**
+ * gtk_check_menu_item_set_active:
+ * @check_menu_item: a #GtkCheckMenuItem.
+ * @is_active: boolean value indicating whether the check box is active.
+ *
+ * Sets the active state of the menu item's check box.
+ */
void
gtk_check_menu_item_set_active (GtkCheckMenuItem *check_menu_item,
gboolean is_active)
*requisition = indicator_size + toggle_spacing;
}
+/**
+ * gtk_check_menu_item_toggled:
+ * @check_menu_item: a #GtkCheckMenuItem.
+ *
+ * Emits the #GtkCheckMenuItem::toggled signal.
+ */
void
gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item)
{
{
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
GtkWidget *widget;
- GtkStateType state_type;
- GtkShadowType shadow_type;
gint x, y;
widget = GTK_WIDGET (check_menu_item);
if (gtk_widget_is_drawable (widget))
{
GtkAllocation allocation;
- GtkStyle *style;
+ GtkStyleContext *context;
guint border_width;
guint offset;
guint toggle_size;
guint toggle_spacing;
guint horizontal_padding;
guint indicator_size;
+ GtkStateFlags state;
+ GtkBorder padding;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_padding (context, state, &padding);
- style = gtk_widget_get_style (widget);
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_style_get (widget,
toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- offset = border_width + style->xthickness + 2;
+ offset = border_width + padding.left + 2;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
{
x = offset + horizontal_padding +
(toggle_size - toggle_spacing - indicator_size) / 2;
}
- else
+ else
{
x = allocation.width -
offset - horizontal_padding - toggle_size + toggle_spacing +
if (priv->active ||
priv->always_show_toggle ||
- (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT))
+ (state & GTK_STATE_FLAG_PRELIGHT))
{
- GdkWindow *window;
-
- window = gtk_widget_get_window (widget);
- state_type = gtk_widget_get_state (widget);
+ gtk_style_context_save (context);
if (priv->inconsistent)
- shadow_type = GTK_SHADOW_ETCHED_IN;
+ state |= GTK_STATE_FLAG_INCONSISTENT;
else if (priv->active)
- shadow_type = GTK_SHADOW_IN;
- else
- shadow_type = GTK_SHADOW_OUT;
+ state |= GTK_STATE_FLAG_ACTIVE;
- if (!gtk_widget_is_sensitive (widget))
- state_type = GTK_STATE_INSENSITIVE;
+ gtk_style_context_set_state (context, state);
if (priv->draw_as_radio)
{
- gtk_paint_option (style, cr,
- state_type, shadow_type,
- widget, "option",
- x, y, indicator_size, indicator_size);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO);
+ gtk_render_option (context, cr, x, y,
+ indicator_size, indicator_size);
}
else
{
- gtk_paint_check (style, cr,
- state_type, shadow_type,
- widget, "check",
- x, y, indicator_size, indicator_size);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
+ gtk_render_check (context, cr, x, y,
+ indicator_size, indicator_size);
}
+
+ gtk_style_context_restore (context);
}
}
}