2003-06-29 23:34:20 +00:00
|
|
|
/* gtkseparatortoolitem.c
|
|
|
|
*
|
2003-12-29 10:55:53 +00:00
|
|
|
* Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
|
2003-06-29 23:34:20 +00:00
|
|
|
* Copyright (C) 2002 James Henstridge <james@daa.com.au>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2003-06-29 23:34:20 +00:00
|
|
|
#include "gtkseparatormenuitem.h"
|
|
|
|
#include "gtkseparatortoolitem.h"
|
|
|
|
#include "gtkintl.h"
|
2003-07-07 14:35:31 +00:00
|
|
|
#include "gtktoolbar.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2005-03-20 07:01:23 +00:00
|
|
|
#include "gtkalias.h"
|
2003-07-07 14:35:31 +00:00
|
|
|
|
2010-05-16 00:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkseparatortoolitem
|
|
|
|
* @Short_description: A toolbar item that separates groups of other
|
|
|
|
* toolbar items
|
|
|
|
* @Title: GtkSeparatorToolItem
|
|
|
|
* @See_also: #GtkToolbar, #GtkRadioToolButton
|
|
|
|
*
|
|
|
|
* A #GtkSeparatorItem is a #GtkToolItem that separates groups of other
|
|
|
|
* #GtkToolItems. Depending on the theme, a #GtkSeparatorToolItem will
|
|
|
|
* often look like a vertical line on horizontally docked toolbars.
|
|
|
|
*
|
|
|
|
* If the #GtkToolbar child property "expand" is %TRUE and the property
|
|
|
|
* #GtkSeparatorToolItem:draw is %FALSE, a #GtkSeparatorToolItem will act as
|
|
|
|
* a "spring" that forces other items to the ends of the toolbar.
|
|
|
|
*
|
|
|
|
* Use gtk_separator_tool_item_new() to create a new #GtkSeparatorToolItem.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
#define MENU_ID "gtk-separator-tool-item-menu-id"
|
|
|
|
|
2003-10-25 19:58:51 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_DRAW
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
|
|
|
|
static void gtk_separator_tool_item_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_separator_tool_item_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_separator_tool_item_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
static void gtk_separator_tool_item_add (GtkContainer *container,
|
|
|
|
GtkWidget *child);
|
2004-01-18 14:31:00 +00:00
|
|
|
static gint get_space_size (GtkToolItem *tool_item);
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2003-10-25 19:58:51 +00:00
|
|
|
#define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
|
|
|
|
|
|
|
|
struct _GtkSeparatorToolItemPrivate
|
|
|
|
{
|
|
|
|
guint draw : 1;
|
|
|
|
};
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2006-05-14 04:25:34 +00:00
|
|
|
G_DEFINE_TYPE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2003-07-07 14:35:31 +00:00
|
|
|
static gint
|
|
|
|
get_space_size (GtkToolItem *tool_item)
|
|
|
|
{
|
2004-01-18 14:31:00 +00:00
|
|
|
gint space_size = _gtk_toolbar_get_default_space_size();
|
2003-07-07 14:35:31 +00:00
|
|
|
GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
|
|
|
|
|
|
|
|
if (GTK_IS_TOOLBAR (parent))
|
|
|
|
{
|
|
|
|
gtk_widget_style_get (parent,
|
2005-03-26 05:49:15 +00:00
|
|
|
"space-size", &space_size,
|
2003-07-07 14:35:31 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2003-07-07 14:35:31 +00:00
|
|
|
return space_size;
|
|
|
|
}
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
|
|
|
|
{
|
2003-10-25 19:58:51 +00:00
|
|
|
GObjectClass *object_class;
|
2003-06-29 23:34:20 +00:00
|
|
|
GtkContainerClass *container_class;
|
|
|
|
GtkToolItemClass *toolitem_class;
|
2003-07-07 14:35:31 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
object_class = (GObjectClass *)class;
|
2003-06-29 23:34:20 +00:00
|
|
|
container_class = (GtkContainerClass *)class;
|
|
|
|
toolitem_class = (GtkToolItemClass *)class;
|
2003-07-07 14:35:31 +00:00
|
|
|
widget_class = (GtkWidgetClass *)class;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2003-10-25 19:58:51 +00:00
|
|
|
object_class->set_property = gtk_separator_tool_item_set_property;
|
|
|
|
object_class->get_property = gtk_separator_tool_item_get_property;
|
2003-07-08 18:20:45 +00:00
|
|
|
widget_class->size_request = gtk_separator_tool_item_size_request;
|
2003-07-07 14:35:31 +00:00
|
|
|
widget_class->expose_event = gtk_separator_tool_item_expose;
|
2003-08-04 21:13:55 +00:00
|
|
|
toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
container_class->add = gtk_separator_tool_item_add;
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DRAW,
|
|
|
|
g_param_spec_boolean ("draw",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Draw"),
|
|
|
|
P_("Whether the separator is drawn, or just blank"),
|
2003-10-25 19:58:51 +00:00
|
|
|
TRUE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-02 23:56:43 +00:00
|
|
|
gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
|
2003-10-25 19:58:51 +00:00
|
|
|
{
|
|
|
|
separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
|
|
|
|
separator_item->priv->draw = TRUE;
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_separator_tool_item_add (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2004-01-18 14:31:00 +00:00
|
|
|
g_warning ("attempt to add a child to an GtkSeparatorToolItem");
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *menu_item = NULL;
|
|
|
|
|
|
|
|
menu_item = gtk_separator_menu_item_new();
|
|
|
|
|
|
|
|
gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-10-25 19:58:51 +00:00
|
|
|
static void
|
|
|
|
gtk_separator_tool_item_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAW:
|
|
|
|
gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_separator_tool_item_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAW:
|
|
|
|
g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
static void
|
|
|
|
gtk_separator_tool_item_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
GtkToolItem *item = GTK_TOOL_ITEM (widget);
|
|
|
|
GtkOrientation orientation = gtk_tool_item_get_orientation (item);
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
requisition->width = get_space_size (item);
|
|
|
|
requisition->height = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requisition->height = get_space_size (item);
|
|
|
|
requisition->width = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-07 14:35:31 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_separator_tool_item_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
2004-01-18 14:31:00 +00:00
|
|
|
GtkToolbar *toolbar = NULL;
|
2004-06-05 18:24:53 +00:00
|
|
|
GtkSeparatorToolItemPrivate *priv =
|
|
|
|
GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (widget);
|
2003-07-07 14:35:31 +00:00
|
|
|
|
2004-06-05 18:24:53 +00:00
|
|
|
if (priv->draw)
|
|
|
|
{
|
2008-02-06 09:53:34 +00:00
|
|
|
if (GTK_IS_TOOLBAR (widget->parent))
|
2004-06-05 18:24:53 +00:00
|
|
|
toolbar = GTK_TOOLBAR (widget->parent);
|
2004-01-18 14:31:00 +00:00
|
|
|
|
2004-06-05 18:24:53 +00:00
|
|
|
_gtk_toolbar_paint_space_line (widget, toolbar,
|
|
|
|
&(event->area), &widget->allocation);
|
|
|
|
}
|
2003-07-07 14:35:31 +00:00
|
|
|
|
2003-10-25 19:58:51 +00:00
|
|
|
return FALSE;
|
2003-07-07 14:35:31 +00:00
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
/**
|
|
|
|
* gtk_separator_tool_item_new:
|
|
|
|
*
|
|
|
|
* Create a new #GtkSeparatorToolItem
|
|
|
|
*
|
|
|
|
* Return value: the new #GtkSeparatorToolItem
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2008-12-29 00:07:32 +00:00
|
|
|
*/
|
2003-06-29 23:34:20 +00:00
|
|
|
GtkToolItem *
|
|
|
|
gtk_separator_tool_item_new (void)
|
|
|
|
{
|
|
|
|
GtkToolItem *self;
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_separator_tool_item_get_draw:
|
2004-01-22 23:47:42 +00:00
|
|
|
* @item: a #GtkSeparatorToolItem
|
2003-10-25 19:58:51 +00:00
|
|
|
*
|
2008-12-29 00:07:32 +00:00
|
|
|
* Returns whether @item is drawn as a line, or just blank.
|
|
|
|
* See gtk_separator_tool_item_set_draw().
|
2003-10-25 19:58:51 +00:00
|
|
|
*
|
2008-12-29 00:07:32 +00:00
|
|
|
* Return value: %TRUE if @item is drawn as a line, or just blank.
|
2003-10-25 19:58:51 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2008-12-29 00:07:32 +00:00
|
|
|
*/
|
2003-10-25 19:58:51 +00:00
|
|
|
gboolean
|
2004-01-22 23:47:42 +00:00
|
|
|
gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
|
2003-10-25 19:58:51 +00:00
|
|
|
{
|
2004-01-22 23:47:42 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2004-01-22 23:47:42 +00:00
|
|
|
return item->priv->draw;
|
2003-10-25 19:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_separator_tool_item_set_draw:
|
2004-01-22 23:47:42 +00:00
|
|
|
* @item: a #GtkSeparatorToolItem
|
2008-12-29 00:07:32 +00:00
|
|
|
* @draw: whether @item is drawn as a vertical line
|
2003-10-25 19:58:51 +00:00
|
|
|
*
|
2008-12-29 00:07:32 +00:00
|
|
|
* Whether @item is drawn as a vertical line, or just blank.
|
|
|
|
* Setting this to %FALSE along with gtk_tool_item_set_expand() is useful
|
2003-10-25 19:58:51 +00:00
|
|
|
* to create an item that forces following items to the end of the toolbar.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2008-12-29 00:07:32 +00:00
|
|
|
*/
|
2003-10-25 19:58:51 +00:00
|
|
|
void
|
2004-01-22 23:47:42 +00:00
|
|
|
gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
|
2003-10-25 19:58:51 +00:00
|
|
|
gboolean draw)
|
|
|
|
{
|
2004-01-22 23:47:42 +00:00
|
|
|
g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
|
2003-10-25 19:58:51 +00:00
|
|
|
|
|
|
|
draw = draw != FALSE;
|
|
|
|
|
2004-01-22 23:47:42 +00:00
|
|
|
if (draw != item->priv->draw)
|
2003-10-25 19:58:51 +00:00
|
|
|
{
|
2004-01-22 23:47:42 +00:00
|
|
|
item->priv->draw = draw;
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2004-01-22 23:47:42 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (item));
|
2003-10-25 19:58:51 +00:00
|
|
|
|
2004-01-22 23:47:42 +00:00
|
|
|
g_object_notify (G_OBJECT (item), "draw");
|
2003-10-25 19:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-20 07:01:23 +00:00
|
|
|
#define __GTK_SEPARATOR_TOOL_ITEM_C__
|
|
|
|
#include "gtkaliasdef.c"
|