Browse Source

Add itembar and item widgets:

* XfceItembar : container for XfceItem's
* XfceItem : simple container to add to an itembar
* XfceSeparatorItem : special XfceItem that simply shows a separator

* Make panel controls and separator item plugin use the new widgets.
* Make taskbar use new widgets


(Old svn revision: 4337)
tags/xfce4-panel-4.10.0
Jasper Huijsmans 16 years ago
parent
commit
539f02bc2c
15 changed files with 2980 additions and 238 deletions
  1. +2
    -0
      TODO
  2. +20
    -5
      libs/Makefile.am
  3. +973
    -0
      libs/xfce-item.c
  4. +117
    -0
      libs/xfce-item.h
  5. +1225
    -0
      libs/xfce-itembar.c
  6. +119
    -0
      libs/xfce-itembar.h
  7. +308
    -0
      libs/xfce-separator-item.c
  8. +64
    -0
      libs/xfce-separator-item.h
  9. +50
    -3
      panel/controls.c
  10. +25
    -15
      panel/controls.h
  11. +22
    -58
      panel/panel.c
  12. +3
    -29
      panel/xfce_support.c
  13. +0
    -3
      panel/xfce_support.h
  14. +6
    -99
      plugins/separator/separator.c
  15. +46
    -26
      taskbar/xftaskbar.c

+ 2
- 0
TODO View File

@@ -16,6 +16,8 @@ TODO
- [DONE] include move handles (steal code form GtkHandlebox)
- use properties and signals for settings
- perhaps use interfaces or derived widgets for controls
* Change xml parsing to use lang: properties. This allows translations to be
handled through gettext/intltool.

Ideas
-----


+ 20
- 5
libs/Makefile.am View File

@@ -1,17 +1,32 @@
lib_LTLIBRARIES = libxfce4panel.la

libxfce4panel_la_SOURCES = \
xfce-enum-types.h \
xfce-enum-types.c \
xfce-marshal.h \
xfce-marshal.c \
xfce-arrow-button.c \
xfce-arrow-button.h \
xfce-enum-types.c \
xfce-enum-types.h \
xfce-itembar.c \
xfce-itembar.h \
xfce-item.c \
xfce-item.h \
xfce-marshal.c \
xfce-marshal.h \
xfce-paint-private.c \
xfce-paint-private.h \
xfce-panel-window.c \
xfce-panel-window.h
xfce-panel-window.h \
xfce-separator-item.c \
xfce-separator-item.h

xfce4_panelincludedir = $(includedir)/xfce4/panel

xfce4_panelinclude_HEADERS = \
xfce-arrow-button.h \
xfce-itembar.h \
xfce-item.h \
xfce-panel-window.h \
xfce-separator-item.h
libxfce4panel_la_CFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/lib \


+ 973
- 0
libs/xfce-item.c View File

@@ -0,0 +1,973 @@
/* vim: set expandtab ts=8 sw=4: */

/* $Id$
*
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <stdio.h>
#include <string.h>

#include <gtk/gtk.h>

#include "xfce-marshal.h"
#include "xfce-enum-types.h"
#include "xfce-paint-private.h"
#include "xfce-item.h"
#include "xfce-itembar.h"

#define XFCE_ITEM_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFCE_TYPE_ITEM, XfceItemPrivate))

/* keep in sync with itembar */
#define DEFAULT_ORIENTATION GTK_ORIENTATION_HORIZONTAL
#define MIN_ICON_SIZE 12
#define MAX_ICON_SIZE 256
#define DEFAULT_ICON_SIZE 32
#define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS

#define DEFAULT_HOMOGENEOUS FALSE
#define DEFAULT_EXPAND FALSE
#define DEFAULT_HAS_HANDLE FALSE
#define DEFAULT_USE_DRAG_WINDOW FALSE

#define HANDLE_WIDTH XFCE_DEFAULT_HANDLE_WIDTH

enum
{
ORIENTATION_CHANGED,
ICON_SIZE_CHANGED,
TOOLBAR_STYLE_CHANGED,
LAST_SIGNAL
};

enum
{
PROP_0,
PROP_ORIENTATION,
PROP_ICON_SIZE,
PROP_TOOLBAR_STYLE,
PROP_HOMOGENEOUS,
PROP_EXPAND,
PROP_HAS_HANDLE,
PROP_USE_DRAG_WINDOW
};


typedef struct _XfceItemPrivate XfceItemPrivate;

struct _XfceItemPrivate
{
GtkOrientation orientation;
int icon_size;
GtkToolbarStyle toolbar_style;
guint homogeneous:1;
guint expand:1;
guint has_handle:1;
guint use_drag_window:1;

GdkWindow *drag_window;
};


/* init */
static void xfce_item_class_init (XfceItemClass * klass);

static void xfce_item_init (XfceItem * item);

/* GObject */
static void xfce_item_set_property (GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec);

static void xfce_item_get_property (GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec);

/* widget */
static int xfce_item_expose (GtkWidget * widget,
GdkEventExpose * event);

static void xfce_item_size_request (GtkWidget * widget,
GtkRequisition * requisition);

static void xfce_item_size_allocate (GtkWidget * widget,
GtkAllocation * allocation);

static void xfce_item_realize (GtkWidget * widget);

static void xfce_item_unrealize (GtkWidget * widget);

static void xfce_item_map (GtkWidget * widget);

static void xfce_item_unmap (GtkWidget * widget);

static void xfce_item_parent_set (GtkWidget * widget,
GtkWidget * old_parent);

/* internal functions */
static void _create_drag_window (XfceItem * item);

static void _destroy_drag_window (XfceItem * item);

/* global vars */
static GtkBinClass *parent_class = NULL;

static guint item_signals[LAST_SIGNAL] = { 0 };


GType
xfce_item_get_type (void)
{
static GtkType type = 0;

if (!type)
{
static const GTypeInfo type_info = {
sizeof (XfceItemClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) xfce_item_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (XfceItem),
0, /* n_preallocs */
(GInstanceInitFunc) xfce_item_init,
};

type = g_type_register_static (GTK_TYPE_BIN, "XfceItem",
&type_info, 0);
}

return type;
}


static void
xfce_item_class_init (XfceItemClass * klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GParamSpec *pspec;

g_type_class_add_private (klass, sizeof (XfceItemPrivate));

parent_class = g_type_class_peek_parent (klass);

gobject_class = (GObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;

gobject_class->get_property = xfce_item_get_property;
gobject_class->set_property = xfce_item_set_property;

widget_class->expose_event = xfce_item_expose;
widget_class->size_request = xfce_item_size_request;
widget_class->size_allocate = xfce_item_size_allocate;
widget_class->realize = xfce_item_realize;
widget_class->unrealize = xfce_item_unrealize;
widget_class->map = xfce_item_map;
widget_class->unmap = xfce_item_unmap;
widget_class->parent_set = xfce_item_parent_set;
/* properties */

/**
* XfceItem::orientation
*
* The orientation of the #XfceItem.
*/
pspec = g_param_spec_enum ("orientation",
"Orientation",
"The orientation of the item",
GTK_TYPE_ORIENTATION,
DEFAULT_ORIENTATION,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ORIENTATION, pspec);

/**
* XfceItem::icon_size
*
* The orientation of the #XfceItem.
*/
pspec = g_param_spec_int ("icon_size",
"Icon size",
"The icon size of the item",
MIN_ICON_SIZE,
MAX_ICON_SIZE,
DEFAULT_ICON_SIZE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ICON_SIZE, pspec);
/**
* XfceItem::toolbar_style
*
* The toolbar style of the #XfceItem.
*/
pspec = g_param_spec_enum ("toolbar_style",
"Toolbar style",
"The toolbar style of the item",
GTK_TYPE_TOOLBAR_STYLE,
DEFAULT_TOOLBAR_STYLE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TOOLBAR_STYLE, pspec);
/**
* XfceItem::homogeneous
*
* Whether the #XfceItem has the same size as other homogenous items.
*/
pspec = g_param_spec_boolean ("homogeneous",
"Homogenous",
"Whether the item is homogeneous",
DEFAULT_HOMOGENEOUS,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_HOMOGENEOUS, pspec);
/**
* XfceItem::expand
*
* Whether the #XfceItem expands to fill available space.
*/
pspec = g_param_spec_boolean ("expand",
"Expand",
"Whether the item expands",
DEFAULT_EXPAND,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_EXPAND, pspec);
/**
* XfceItem::has_handle
*
* Whether the #XfceItem has a handle attached to it.
*/
pspec = g_param_spec_boolean ("has_handle",
"Has handle",
"Whether the item has a handle",
DEFAULT_HAS_HANDLE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_HAS_HANDLE, pspec);
/**
* XfceItem::use_drag_window
*
* Whether the #XfceItem uses a special window to catch events.
*/
pspec = g_param_spec_boolean ("use_drag_window",
"Use drag window",
"Whether the item uses a drag window",
DEFAULT_USE_DRAG_WINDOW,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_USE_DRAG_WINDOW,
pspec);
/* signals */

/**
* XfceItem::orientation_changed:
* @item: the object which emitted the signal
* @orientation: the new #GtkOrientation of the item
*
* Emitted when the orientation of the item changes.
*/
item_signals[ORIENTATION_CHANGED] =
g_signal_new ("orientation-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (XfceItemClass,
orientation_changed),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, GTK_TYPE_ORIENTATION);

/**
* XfceItem::icon_size_changed:
* @item: the object which emitted the signal
* @size: the new icon size of the item
*
* Emitted when the icon size of the item changes.
*/
item_signals[ICON_SIZE_CHANGED] =
g_signal_new ("icon-size-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (XfceItemClass,
icon_size_changed),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);

/**
* XfceItem::toolbar_style_changed:
* @item: the object which emitted the signal
* @style: the new #GtkToolbarStyle of the item
*
* Emitted when the toolbar style of the item changes.
*/
item_signals[TOOLBAR_STYLE_CHANGED] =
g_signal_new ("toolbar-style-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (XfceItemClass,
toolbar_style_changed),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, GTK_TYPE_TOOLBAR_STYLE);
}

static void
xfce_item_init (XfceItem * item)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (item);
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (item), GTK_NO_WINDOW);

priv->orientation = DEFAULT_ORIENTATION;
priv->icon_size = DEFAULT_ICON_SIZE;
priv->toolbar_style = DEFAULT_TOOLBAR_STYLE;
priv->homogeneous = DEFAULT_HOMOGENEOUS;
priv->expand = DEFAULT_EXPAND;
priv->has_handle = DEFAULT_HAS_HANDLE;
priv->use_drag_window = DEFAULT_USE_DRAG_WINDOW;
priv->drag_window = NULL;
}

static void
xfce_item_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec)
{
XfceItem *item = XFCE_ITEM (object);

switch (prop_id)
{
case PROP_ORIENTATION:
xfce_item_set_orientation (item, g_value_get_enum (value));
break;
case PROP_ICON_SIZE:
xfce_item_set_icon_size (item, g_value_get_int (value));
break;
case PROP_TOOLBAR_STYLE:
xfce_item_set_toolbar_style (item, g_value_get_enum (value));
break;
case PROP_HOMOGENEOUS:
xfce_item_set_homogeneous (item, g_value_get_boolean (value));
break;
case PROP_EXPAND:
xfce_item_set_expand (item, g_value_get_boolean (value));
break;
case PROP_HAS_HANDLE:
xfce_item_set_has_handle (item, g_value_get_boolean (value));
break;
case PROP_USE_DRAG_WINDOW:
xfce_item_set_use_drag_window (item, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
xfce_item_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
XfceItem *item = XFCE_ITEM (object);

switch (prop_id)
{
case PROP_ORIENTATION:
g_value_set_enum (value, xfce_item_get_orientation (item));
break;
case PROP_ICON_SIZE:
g_value_set_int (value, xfce_item_get_icon_size (item));
break;
case PROP_TOOLBAR_STYLE:
g_value_set_enum (value, xfce_item_get_toolbar_style (item));
break;
case PROP_HOMOGENEOUS:
g_value_set_boolean (value, xfce_item_get_homogeneous (item));
break;
case PROP_EXPAND:
g_value_set_boolean (value, xfce_item_get_expand (item));
break;
case PROP_HAS_HANDLE:
g_value_set_boolean (value, xfce_item_get_has_handle (item));
break;
case PROP_USE_DRAG_WINDOW:
g_value_set_boolean (value, xfce_item_get_use_drag_window (item));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static int
xfce_item_expose (GtkWidget * widget, GdkEventExpose *event)
{
if (GTK_WIDGET_DRAWABLE (widget))
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));
GtkAllocation *allocation = &(widget->allocation);

if (priv->has_handle)
{
int x, y, w, h;
GtkOrientation orientation;

x = allocation->x + GTK_CONTAINER (widget)->border_width
+ widget->style->xthickness;
y = allocation->y + GTK_CONTAINER (widget)->border_width
+ widget->style->ythickness;
if (GTK_ORIENTATION_HORIZONTAL == priv->orientation)
{
orientation = GTK_ORIENTATION_VERTICAL;

w = HANDLE_WIDTH;
h = allocation->height
- 2 * GTK_CONTAINER (widget)->border_width
- 2 * widget->style->ythickness;
}
else
{
orientation = GTK_ORIENTATION_HORIZONTAL;

w = allocation->width
- 2 * GTK_CONTAINER (widget)->border_width
- 2 * widget->style->xthickness;
h = HANDLE_WIDTH;
}

xfce_paint_handle (widget, &(event->area), "xfce_item",
orientation, x, y, w, h);
}
if (GTK_BIN (widget)->child)
{
gtk_container_propagate_expose (GTK_CONTAINER (widget),
GTK_BIN (widget)->child, event);
}
}

return TRUE;
}

static void
xfce_item_size_request (GtkWidget * widget, GtkRequisition * requisition)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));
GtkRequisition req = { 0 };

if (GTK_BIN (widget)->child)
gtk_widget_size_request (GTK_BIN (widget)->child, &req);

requisition->width = req.width
+ 2 * GTK_CONTAINER (widget)->border_width;
requisition->height = req.height
+ 2 * GTK_CONTAINER (widget)->border_width;
if (priv->has_handle)
{
if (GTK_ORIENTATION_HORIZONTAL == priv->orientation)
{
requisition->width += HANDLE_WIDTH
+ 2 * widget->style->xthickness;
}
else
{
requisition->height += HANDLE_WIDTH
+ 2 * widget->style->ythickness;
}
}
}

static void
xfce_item_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
GtkAllocation childalloc;
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));
widget->allocation = childalloc = *allocation;
childalloc.x += GTK_CONTAINER (widget)->border_width;
childalloc.y += GTK_CONTAINER (widget)->border_width;
childalloc.width -= 2 * GTK_CONTAINER (widget)->border_width;
childalloc.height -= 2 * GTK_CONTAINER (widget)->border_width;
if (priv->use_drag_window && priv->drag_window != NULL)
{
gdk_window_move_resize (priv->drag_window,
childalloc.x, childalloc.y,
childalloc.width, childalloc.height);
}
if (priv->has_handle)
{
if (!priv->use_drag_window && priv->drag_window != NULL)
{
if (GTK_ORIENTATION_HORIZONTAL == priv->orientation)
{
gdk_window_move_resize (priv->drag_window,
childalloc.x, childalloc.y,
HANDLE_WIDTH
+ widget->style->xthickness,
childalloc.height);
}
else
{
gdk_window_move_resize (priv->drag_window,
childalloc.x, childalloc.y,
childalloc.width,
HANDLE_WIDTH
+ widget->style->ythickness);
}
}
if (GTK_ORIENTATION_HORIZONTAL == priv->orientation)
{
childalloc.x += HANDLE_WIDTH + 2 * widget->style->xthickness;
childalloc.width -= HANDLE_WIDTH
+ 2 * widget->style->xthickness;
}
else
{
childalloc.y += HANDLE_WIDTH + 2 * widget->style->ythickness;
childalloc.height -= HANDLE_WIDTH
+ 2 * widget->style->ythickness;
}
}

if (GTK_BIN (widget)->child)
gtk_widget_size_allocate (GTK_BIN (widget)->child, &childalloc);
}

static void
xfce_item_realize (GtkWidget * widget)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));

GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

widget->window = gtk_widget_get_parent_window (widget);
g_object_ref (widget->window);

if (priv->use_drag_window || priv->has_handle)
_create_drag_window (XFCE_ITEM (widget));

widget->style = gtk_style_attach (widget->style, widget->window);
}

static void
xfce_item_unrealize (GtkWidget * widget)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));

if (priv->use_drag_window)
_destroy_drag_window (XFCE_ITEM (widget));

GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}

static void
xfce_item_map (GtkWidget * widget)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));

if (priv->has_handle && !priv->use_drag_window)
gdk_window_show (priv->drag_window);
GTK_WIDGET_CLASS (parent_class)->map (widget);

if (priv->use_drag_window)
gdk_window_show (priv->drag_window);
}

static void
xfce_item_unmap (GtkWidget * widget)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (XFCE_ITEM (widget));

if (priv->drag_window)
gdk_window_hide (priv->drag_window);

GTK_WIDGET_CLASS (parent_class)->unmap (widget);
}

static void
xfce_item_parent_set (GtkWidget * widget, GtkWidget *old_parent)
{
XfceItembar *bar = XFCE_ITEMBAR (widget->parent);

if (!bar)
return;

g_object_freeze_notify (G_OBJECT (widget));
g_object_set (G_OBJECT (widget),
"orientation", xfce_itembar_get_orientation (bar),
"icon_size", xfce_itembar_get_icon_size (bar),
"toolbar_style", xfce_itembar_get_toolbar_style (bar),
NULL);
g_object_thaw_notify (G_OBJECT (widget));
}

/* internal functions */

static void
_create_drag_window (XfceItem * item)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (item);
GtkWidget *widget;
GdkWindowAttr attributes;
gint attributes_mask, border_width;

widget = GTK_WIDGET (item);
border_width = GTK_CONTAINER (item)->border_width;

attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x + border_width;
attributes.y = widget->allocation.y + border_width;

if (priv->use_drag_window)
{
attributes.width = widget->allocation.width - border_width * 2;
attributes.height = widget->allocation.height - border_width * 2;
}
else /* handle */
{
if (GTK_ORIENTATION_HORIZONTAL == priv->orientation)
{
attributes.width = HANDLE_WIDTH;
attributes.height = widget->allocation.height - border_width * 2;
}
else
{
attributes.width = widget->allocation.width - border_width * 2;
attributes.height = HANDLE_WIDTH;
}
}

attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |=
(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);

attributes_mask = GDK_WA_X | GDK_WA_Y;

priv->drag_window =
gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
attributes_mask);

gdk_window_set_user_data (priv->drag_window, item);
}

static void
_destroy_drag_window (XfceItem * item)
{
XfceItemPrivate *priv = XFCE_ITEM_GET_PRIVATE (item);
if (priv->drag_window)
{
gdk_window_set_user_data (priv->drag_window, NULL);
gdk_window_destroy (priv->drag_window);
priv->drag_window = NULL;
}
}


/* public interface */

GtkWidget *
xfce_item_new (void)
{
XfceItem *item;

item = g_object_new (XFCE_TYPE_ITEM, NULL);

return GTK_WIDGET (item);
}

GtkOrientation
xfce_item_get_orientation (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_ORIENTATION);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->orientation;
}

void
xfce_item_set_orientation (XfceItem * item, GtkOrientation orientation)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (orientation == priv->orientation)
return;

priv->orientation = orientation;

g_signal_emit (item, item_signals[ORIENTATION_CHANGED], 0, orientation);

g_object_notify (G_OBJECT (item), "orientation");

gtk_widget_queue_resize (GTK_WIDGET (item));
}


int
xfce_item_get_icon_size (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_ICON_SIZE);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->icon_size;
}

void
xfce_item_set_icon_size (XfceItem * item, int size)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (size == priv->icon_size)
return;

priv->icon_size = size;

g_signal_emit (item, item_signals[ICON_SIZE_CHANGED], 0, size);

g_object_notify (G_OBJECT (item), "icon_size");

gtk_widget_queue_resize (GTK_WIDGET (item));
}


GtkToolbarStyle
xfce_item_get_toolbar_style (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_TOOLBAR_STYLE);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->toolbar_style;
}

void
xfce_item_set_toolbar_style (XfceItem * item, GtkToolbarStyle style)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (style == priv->toolbar_style)
return;

priv->toolbar_style = style;

g_object_notify (G_OBJECT (item), "toolbar_style");

g_signal_emit (item, item_signals[TOOLBAR_STYLE_CHANGED], 0, style);
}


gboolean
xfce_item_get_homogeneous (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_HOMOGENEOUS);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->homogeneous;
}

void
xfce_item_set_homogeneous (XfceItem * item, gboolean homogeneous)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (homogeneous == priv->homogeneous)
return;

priv->homogeneous = homogeneous;

g_object_notify (G_OBJECT (item), "homogeneous");

gtk_widget_queue_resize (GTK_WIDGET (item));
}


gboolean
xfce_item_get_expand (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_EXPAND);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->expand;
}

void
xfce_item_set_expand (XfceItem * item, gboolean expand)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (expand == priv->expand)
return;

priv->expand = expand;

g_object_notify (G_OBJECT (item), "expand");

gtk_widget_queue_resize (GTK_WIDGET (item));
}


gboolean
xfce_item_get_has_handle (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_HAS_HANDLE);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->has_handle;
}

void
xfce_item_set_has_handle (XfceItem * item, gboolean has_handle)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (has_handle == priv->has_handle)
return;

priv->has_handle = has_handle;

if (has_handle)
{
if (!priv->drag_window && GTK_WIDGET_REALIZED (GTK_WIDGET (item)))
{
_create_drag_window (item);

if (GTK_WIDGET_VISIBLE (GTK_WIDGET (item)))
gdk_window_show (priv->drag_window);
}
}
else if (!priv->use_drag_window)
{
_destroy_drag_window (item);
}
g_object_notify (G_OBJECT (item), "has_handle");

gtk_widget_queue_resize (GTK_WIDGET (item));
}


gboolean
xfce_item_get_use_drag_window (XfceItem * item)
{
XfceItemPrivate *priv;
g_return_val_if_fail (XFCE_IS_ITEM (item), DEFAULT_USE_DRAG_WINDOW);

priv = XFCE_ITEM_GET_PRIVATE (item);

return priv->use_drag_window;
}

void
xfce_item_set_use_drag_window (XfceItem * item, gboolean use_drag_window)
{
XfceItemPrivate *priv;
g_return_if_fail (XFCE_IS_ITEM (item));

priv = XFCE_ITEM_GET_PRIVATE (item);

if (use_drag_window == priv->use_drag_window)
return;

priv->use_drag_window = use_drag_window;

if (use_drag_window)
{
if (!priv->drag_window && GTK_WIDGET_REALIZED (GTK_WIDGET (item)))
{
_create_drag_window (item);

if (GTK_WIDGET_VISIBLE (GTK_WIDGET (item)))
gdk_window_show (priv->drag_window);
}
}
else if (!priv->has_handle)
{
_destroy_drag_window (item);
}
gtk_widget_queue_resize (GTK_WIDGET (item));

g_object_notify (G_OBJECT (item), "use_drag_window");
}



+ 117
- 0
libs/xfce-item.h View File

@@ -0,0 +1,117 @@
/* vim: set expandtab ts=8 sw=4: */

/* $Id$
*
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _XFCE_ITEM_H
#define _XFCE_ITEM_H

#include <gtk/gtkenums.h>
#include <gtk/gtkbin.h>

#define XFCE_TYPE_ITEM (xfce_item_get_type ())
#define XFCE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_ITEM, XfceItem))
#define XFCE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_ITEM, XfceItemClass))
#define XFCE_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_ITEM))
#define XFCE_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_ITEM))
#define XFCE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_ITEM, XfceItemClass))


G_BEGIN_DECLS

typedef struct _XfceItem XfceItem;

typedef struct _XfceItemClass XfceItemClass;

struct _XfceItem
{
GtkBin parent;
};

struct _XfceItemClass
{
GtkBinClass parent_class;

/* signals */
void (*orientation_changed) (XfceItem * item,
GtkOrientation orientation);

void (*icon_size_changed) (XfceItem * item,
int size);

void (*toolbar_style_changed) (XfceItem * item,
GtkToolbarStyle);

/* Padding for future expansion */
void (*_xfce_reserved1) (void);
void (*_xfce_reserved2) (void);
void (*_xfce_reserved3) (void);
};


GType xfce_item_get_type (void) G_GNUC_CONST;

GtkWidget *xfce_item_new (void);


GtkOrientation xfce_item_get_orientation (XfceItem * item);

void xfce_item_set_orientation (XfceItem * item,
GtkOrientation orientation);


int xfce_item_get_icon_size (XfceItem * item);

void xfce_item_set_icon_size (XfceItem * item,
int size);


GtkToolbarStyle xfce_item_get_toolbar_style (XfceItem * item);

void xfce_item_set_toolbar_style (XfceItem * item,
GtkToolbarStyle style);


gboolean xfce_item_get_homogeneous (XfceItem * item);

void xfce_item_set_homogeneous (XfceItem * item,
gboolean homogeneous);


gboolean xfce_item_get_expand (XfceItem * item);

void xfce_item_set_expand (XfceItem * item,
gboolean expand);


gboolean xfce_item_get_has_handle (XfceItem * item);

void xfce_item_set_has_handle (XfceItem * item,
gboolean has_handle);


gboolean xfce_item_get_use_drag_window (XfceItem * item);

void xfce_item_set_use_drag_window (XfceItem * item,
gboolean use_drag_window);


G_END_DECLS

#endif /* _XFCE_ITEM_H */

+ 1225
- 0
libs/xfce-itembar.c
File diff suppressed because it is too large
View File


+ 119
- 0
libs/xfce-itembar.h View File

@@ -0,0 +1,119 @@
/* vim: set expandtab ts=8 sw=4: */

/* $Id$
*
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _XFCE_ITEMBAR_H
#define _XFCE_ITEMBAR_H

#include <gtk/gtkenums.h>
#include <gtk/gtkcontainer.h>
#include "xfce-item.h"

#define XFCE_TYPE_ITEMBAR (xfce_itembar_get_type ())
#define XFCE_ITEMBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_ITEMBAR, XfceItembar))
#define XFCE_ITEMBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_ITEMBAR, XfceItembarClass))
#define XFCE_IS_ITEMBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_ITEMBAR))
#define XFCE_IS_ITEMBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_ITEMBAR))
#define XFCE_ITEMBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_ITEMBAR, XfceItembarClass))


G_BEGIN_DECLS

typedef struct _XfceItembar XfceItembar;

typedef struct _XfceItembarClass XfceItembarClass;

struct _XfceItembar
{
GtkContainer parent;
};

struct _XfceItembarClass
{
GtkContainerClass parent_class;

/* signals */
void (*orientation_changed) (XfceItembar * itembar,
GtkOrientation orientation);

void (*icon_size_changed) (XfceItembar * itembar,
int size);

void (*toolbar_style_changed) (XfceItembar * itembar,
GtkToolbarStyle);

/* Padding for future expansion */
void (*_xfce_reserved1) (void);
void (*_xfce_reserved2) (void);
void (*_xfce_reserved3) (void);
};


GType xfce_itembar_get_type (void) G_GNUC_CONST;

GtkWidget *xfce_itembar_new (GtkOrientation orientation);


GtkOrientation xfce_itembar_get_orientation (XfceItembar * itembar);

void xfce_itembar_set_orientation (XfceItembar * itembar,
GtkOrientation orientation);


int xfce_itembar_get_icon_size (XfceItembar * itembar);

void xfce_itembar_set_icon_size (XfceItembar * itembar,
int size);


GtkToolbarStyle xfce_itembar_get_toolbar_style (XfceItembar * itembar);

void xfce_itembar_set_toolbar_style (XfceItembar * itembar,
GtkToolbarStyle style);

void xfce_itembar_insert (XfceItembar * itembar,
XfceItem * item,
int position);

void xfce_itembar_append (XfceItembar * itembar,
XfceItem * item);

void xfce_itembar_prepend (XfceItembar * itembar,
XfceItem * item);

void xfce_itembar_reorder_child (XfceItembar * itembar,
XfceItem * item,
int position);

int xfce_itembar_get_n_items (XfceItembar * itembar);

int xfce_itembar_get_item_index (XfceItembar * itembar,
XfceItem * item);

XfceItem * xfce_itembar_get_nth_item (XfceItembar * itembar,
gint n);

int xfce_itembar_get_drop_index (XfceItembar * itembar,
gint x,
gint y);

G_END_DECLS

#endif /* _XFCE_ITEMBAR_H */

+ 308
- 0
libs/xfce-separator-item.c View File

@@ -0,0 +1,308 @@
/* vim: set expandtab ts=8 sw=4: */

/* $Id$
*
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <stdio.h>
#include <string.h>
#include <math.h>

#include <gtk/gtk.h>

#include "xfce-separator-item.h"

#define XFCE_SEPARATOR_ITEM_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFCE_TYPE_SEPARATOR_ITEM, \
XfceSeparatorItemPrivate))

#define DEFAULT_SHOW_LINE TRUE
#define DEFAULT_SEP_WIDTH 10
#define SEP_START 0.15
#define SEP_END 0.85

enum
{
PROP_0,
PROP_SHOW_LINE
};


typedef struct _XfceSeparatorItemPrivate XfceSeparatorItemPrivate;

struct _XfceSeparatorItemPrivate
{
guint show_line:1;
};


/* init */
static void xfce_separator_item_class_init (XfceSeparatorItemClass * klass);

static void xfce_separator_item_init (XfceSeparatorItem * item);

/* GObject */
static void xfce_separator_item_set_property (GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec);

static void xfce_separator_item_get_property (GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec);

/* widget */
static int xfce_separator_item_expose (GtkWidget * widget,
GdkEventExpose * event);

static void xfce_separator_item_size_request (GtkWidget * widget,
GtkRequisition * requisition);

/* container */
static GType xfce_separator_item_child_type (GtkContainer * container);

static void xfce_separator_item_add (GtkContainer * container,
GtkWidget * child);

/* global vars */
static XfceItemClass *parent_class = NULL;


GType
xfce_separator_item_get_type (void)
{
static GtkType type = 0;

if (!type)
{
static const GTypeInfo type_info = {
sizeof (XfceSeparatorItemClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) xfce_separator_item_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (XfceSeparatorItem),
0, /* n_preallocs */
(GInstanceInitFunc) xfce_separator_item_init,
};

type = g_type_register_static (XFCE_TYPE_ITEM, "XfceSeparatorItem",
&type_info, 0);
}

return type;
}


static void
xfce_separator_item_class_init (XfceSeparatorItemClass * klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GParamSpec *pspec;

g_type_class_add_private (klass, sizeof (XfceSeparatorItemPrivate));

parent_class = g_type_class_peek_parent (klass);

gobject_class = (GObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
container_class = (GtkContainerClass *) klass;

gobject_class->get_property = xfce_separator_item_get_property;
gobject_class->set_property = xfce_separator_item_set_property;

widget_class->expose_event = xfce_separator_item_expose;
widget_class->size_request = xfce_separator_item_size_request;

container_class->child_type = xfce_separator_item_child_type;
container_class->add = xfce_separator_item_add;

/* properties */
/**
* XfceSeparatorItem::show_line
*
* Whether to show a separator line on the #XfceSeparatorItem.
*/
pspec = g_param_spec_boolean ("show_line",
"Show line",
"Whether to show a separator line",
DEFAULT_SHOW_LINE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_SHOW_LINE, pspec);
}

static void
xfce_separator_item_init (XfceSeparatorItem * item)
{
XfceSeparatorItemPrivate *priv = XFCE_SEPARATOR_ITEM_GET_PRIVATE (item);
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (item), GTK_NO_WINDOW);

priv->show_line = DEFAULT_SHOW_LINE;
}

static void
xfce_separator_item_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
XfceSeparatorItem *item = XFCE_SEPARATOR_ITEM (object);

switch (prop_id)
{
case PROP_SHOW_LINE:
xfce_separator_item_set_show_line (item,
g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
xfce_separator_item_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
XfceSeparatorItem *item = XFCE_SEPARATOR_ITEM (object);

switch (prop_id)
{
case PROP_SHOW_LINE:
g_value_set_boolean (value,
xfce_separator_item_get_show_line (item));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static int
xfce_separator_item_expose (GtkWidget * widget, GdkEventExpose *event)
{
if (GTK_WIDGET_DRAWABLE (widget)
&& xfce_separator_item_get_show_line (XFCE_SEPARATOR_ITEM (widget)))
{
GtkAllocation *allocation = &(widget->allocation);
int start, end, position;

if (GTK_ORIENTATION_HORIZONTAL
== xfce_item_get_orientation (XFCE_ITEM (widget)))
{
start = allocation->y + SEP_START * allocation->height;
end = allocation->y + SEP_END * allocation->height;
position = allocation->x + allocation->width / 2;
gtk_paint_vline (widget->style, widget->window,
GTK_STATE_NORMAL,
&(event->area), widget, "xfce-separator-item",
start, end, position);
}
else
{
start = allocation->x + SEP_START * allocation->width;
end = allocation->x + SEP_END * allocation->width;
position = allocation->y + allocation->height / 2;
gtk_paint_hline (widget->style, widget->window,
GTK_STATE_NORMAL,
&(event->area), widget, "xfce-separator-item",
start, end, position);
}

return TRUE;
}

return FALSE;
}

static void
xfce_separator_item_size_request (GtkWidget * widget,
GtkRequisition * requisition)
{
requisition->width = requisition->height = DEFAULT_SEP_WIDTH;
}

static GType
xfce_separator_item_child_type (GtkContainer * container)
{
return G_TYPE_NONE;
}

static void
xfce_separator_item_add (GtkContainer * container, GtkWidget * child)
{
g_warning ("It is not possible to add a widget to an XfceSeparatorItem.");
}

/* public interface */

GtkWidget *
xfce_separator_item_new (void)
{
XfceSeparatorItem *separator_item;

separator_item = g_object_new (XFCE_TYPE_SEPARATOR_ITEM,
"homogeneous", FALSE,
"use_drag_window", TRUE,
NULL);

return GTK_WIDGET (separator_item);
}

gboolean
xfce_separator_item_get_show_line (XfceSeparatorItem *item)
{
XfceSeparatorItemPrivate *priv;

g_return_val_if_fail (XFCE_IS_SEPARATOR_ITEM (item), DEFAULT_SHOW_LINE);
priv = XFCE_SEPARATOR_ITEM_GET_PRIVATE (item);

return priv->show_line;
}

void
xfce_separator_item_set_show_line (XfceSeparatorItem *item, gboolean show)
{
XfceSeparatorItemPrivate *priv;

g_return_if_fail (XFCE_IS_SEPARATOR_ITEM (item));
priv = XFCE_SEPARATOR_ITEM_GET_PRIVATE (item);

if (priv->show_line != show)
{
priv->show_line = show;

g_object_notify (G_OBJECT (item), "show_line");

gtk_widget_queue_draw (GTK_WIDGET (item));
}
}



+ 64
- 0
libs/xfce-separator-item.h View File

@@ -0,0 +1,64 @@
/* vim: set expandtab ts=8 sw=4: */

/* $Id$
*
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _XFCE_SEPARATOR_ITEM_H
#define _XFCE_SEPARATOR_ITEM_H

#include "xfce-item.h"

#define XFCE_TYPE_SEPARATOR_ITEM (xfce_separator_item_get_type ())
#define XFCE_SEPARATOR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_SEPARATOR_ITEM, XfceSeparatorItem))
#define XFCE_SEPARATOR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_SEPARATOR_ITEM, XfceSeparatorItemClass))
#define XFCE_IS_SEPARATOR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_SEPARATOR_ITEM))
#define XFCE_IS_SEPARATOR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_SEPARATOR_ITEM))
#define XFCE_SEPARATOR_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_SEPARATOR_ITEM, XfceSeparatorItemClass))


G_BEGIN_DECLS

typedef struct _XfceSeparatorItem XfceSeparatorItem;

typedef struct _XfceSeparatorItemClass XfceSeparatorItemClass;

struct _XfceSeparatorItem
{
XfceItem parent;
};

struct _XfceSeparatorItemClass
{
XfceItemClass parent_class;
};


GType xfce_separator_item_get_type (void) G_GNUC_CONST;

GtkWidget *xfce_separator_item_new (void);

gboolean xfce_separator_item_get_show_line (XfceSeparatorItem *item);

void xfce_separator_item_set_show_line (XfceSeparatorItem *item,
gboolean show);


G_END_DECLS

#endif /* _XFCE_SEPARATOR_ITEM_H */

+ 50
- 3
panel/controls.c View File

@@ -46,6 +46,9 @@

#include <libxfce4util/libxfce4util.h>

#include "xfce-item.h"
#include "xfce-itembar.h"

#include "xfce.h"
#include "item.h"
#include "item-control.h"
@@ -865,6 +868,15 @@ create_control (Control * control, int id, const char *filename)
return FALSE;
}

static void
control_orientation_changed (XfceItem *item, GtkOrientation orientation,
Control *control)
{
control_set_orientation (control,
orientation == GTK_ORIENTATION_HORIZONTAL ?
HORIZONTAL : VERTICAL);
}

G_MODULE_EXPORT /* EXPORT:control_new */
Control *
control_new (int index)
@@ -874,16 +886,51 @@ control_new (int index)
control->index = index;
control->with_popup = FALSE;

control->base = gtk_event_box_new ();
control->base = xfce_item_new ();
gtk_widget_show (control->base);
xfce_item_set_homogeneous (XFCE_ITEM (control->base), FALSE);

/* protect against destruction when unpacking */
g_object_ref (control->base);
gtk_object_sink (GTK_OBJECT (control->base));

g_signal_connect (control->base, "orientation-changed",
G_CALLBACK (control_orientation_changed), control);
return control;
}

G_MODULE_EXPORT /* EXPORT: control_swap_base */
void
control_swap_base (Control *control, GtkWidget *newbase)
{
GtkWidget *parent;
int n = 0;

g_return_if_fail (XFCE_IS_ITEM (newbase));
parent = control->base->parent;

if (parent)
{
n = xfce_itembar_get_item_index (XFCE_ITEMBAR (parent),
XFCE_ITEM (control->base));
}

gtk_widget_destroy (control->base);
control->base = newbase;

gtk_widget_show (control->base);
g_object_ref (control->base);
gtk_object_sink (GTK_OBJECT (control->base));

if (parent)
{
xfce_itembar_insert (XFCE_ITEMBAR (parent),
XFCE_ITEM (control->base), n-1);
}
}

G_MODULE_EXPORT /* EXPORT:control_free */
void
control_free (Control * control)
@@ -901,9 +948,9 @@ control_free (Control * control)

G_MODULE_EXPORT /* EXPORT:control_pack */
void
control_pack (Control * control, GtkBox * box)
control_pack (Control * control, GtkWidget * box)
{
gtk_box_pack_start (box, control->base, TRUE, TRUE, 0);
xfce_itembar_append (XFCE_ITEMBAR (box), XFCE_ITEM (control->base));
}

G_MODULE_EXPORT /* EXPORT:control_unpack */


+ 25
- 15
panel/controls.h View File

@@ -30,8 +30,8 @@ typedef gboolean (*CreateControlFunc) (Control * control);
struct _ControlClass
{
int id;
const char *name; /* unique name */
const char *caption; /* translated, human readable */
const char *name; /* unique name */
const char *caption; /* translated, human readable */

/* for plugins */
GModule *gmodule;
@@ -44,10 +44,10 @@ struct _ControlClass
void (*read_config) (Control * control, xmlNodePtr node);
void (*write_config) (Control * control, xmlNodePtr node);
void (*attach_callback) (Control * control, const char *signal,
GCallback callback, gpointer data);
GCallback callback, gpointer data);

void (*create_options) (Control * control, GtkContainer * container,
GtkWidget * done);
GtkWidget * done);

/* global preferences */
void (*set_orientation) (Control * control, int orientation);
@@ -78,13 +78,14 @@ typedef struct
char *name;
char *caption;
GdkPixbuf *icon;
gboolean can_be_added; /* not unique or not already added */
gboolean can_be_added; /* not unique or not already added */
}
ControlInfo;

G_MODULE_IMPORT GSList *get_control_info_list (void);

G_MODULE_IMPORT void insert_control (Panel * panel, const char *name, int position);
G_MODULE_IMPORT void insert_control (Panel * panel, const char *name,
int position);

/* control classes */
G_MODULE_IMPORT void control_class_list_init (void);
@@ -94,37 +95,46 @@ G_MODULE_IMPORT void control_class_list_cleanup (void);
/* NOTE:
* Use next functions only on classes that have at least
* their name field initialized */
G_MODULE_IMPORT void control_class_set_icon (ControlClass * cclass, GdkPixbuf * icon);
G_MODULE_IMPORT void control_class_set_icon (ControlClass * cclass,
GdkPixbuf * icon);

G_MODULE_IMPORT void control_class_set_unique (ControlClass * cclass, gboolean unique);
G_MODULE_IMPORT void control_class_set_unique (ControlClass * cclass,
gboolean unique);

G_MODULE_IMPORT void control_class_set_unloadable (ControlClass * cclass,
gboolean unloadable);
gboolean unloadable);

/* controls */
G_MODULE_IMPORT Control *control_new (int index);

G_MODULE_IMPORT gboolean create_control (Control * control, int id, const char *filename);
G_MODULE_IMPORT void control_swap_base (Control * control,
GtkWidget * newbase);

G_MODULE_IMPORT gboolean create_control (Control * control, int id,
const char *filename);

G_MODULE_IMPORT void control_free (Control * control);

G_MODULE_IMPORT gboolean control_set_from_xml (Control * control, xmlNodePtr node);
G_MODULE_IMPORT gboolean control_set_from_xml (Control * control,
xmlNodePtr node);

G_MODULE_IMPORT void control_write_xml (Control * control, xmlNodePtr parent);

G_MODULE_IMPORT void control_pack (Control * control, GtkBox * box);
G_MODULE_IMPORT void control_pack (Control * control, GtkWidget * box);

G_MODULE_IMPORT void control_unpack (Control * control);

G_MODULE_IMPORT void control_attach_callbacks (Control * control);

G_MODULE_IMPORT void control_create_options (Control * control, GtkContainer * container,
GtkWidget * done);
G_MODULE_IMPORT void control_create_options (Control * control,
GtkContainer * container,
GtkWidget * done);

/* global settings */
G_MODULE_IMPORT void control_set_settings (Control * control);

G_MODULE_IMPORT void control_set_orientation (Control * control, int orientation);
G_MODULE_IMPORT void control_set_orientation (Control * control,
int orientation);

G_MODULE_IMPORT void control_set_size (Control * control, int size);



+ 22
- 58
panel/panel.c View File

@@ -30,6 +30,7 @@
#include <libxfcegui4/libnetk.h>

#include "xfce-panel-window.h"
#include "xfce-itembar.h"

#include "xfce.h"
#include "controls.h"
@@ -1072,51 +1073,20 @@ create_panel_window (Panel * p)
static void
create_panel_framework (Panel * p)
{
gboolean vertical = (settings.orientation == VERTICAL);
GtkOrientation orientation =
(p->priv->settings.orientation == VERTICAL) ?
GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;

/* create all widgets that depend on orientation */
if (vertical)
p->group_box = gtk_vbox_new (FALSE, 0);
else
p->group_box = gtk_hbox_new (FALSE, 0);
xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (p->toplevel),
orientation);

p->group_box = xfce_itembar_new (orientation);
gtk_widget_show (p->group_box);

gtk_container_add (GTK_CONTAINER (p->toplevel), p->group_box);

xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (p->toplevel),
vertical ? GTK_ORIENTATION_VERTICAL :
GTK_ORIENTATION_HORIZONTAL);
}

/* housekeeping for panel controls */

static void
panel_pack_controls (Panel *p)
{
GSList *l;

for (l = p->priv->controls; l != NULL; l = l->next)
{
Control *control = l->data;
control_pack (control, GTK_BOX (p->group_box));
}
}

static void
panel_unpack_controls (Panel *p)
{
GSList *l;

for (l = p->priv->controls; l != NULL; l = l->next)
{
Control *control = l->data;
control_unpack (control);
}
}

G_MODULE_EXPORT /* EXPORT:panel_cleanup */
void
panel_cleanup (void)
@@ -1255,7 +1225,8 @@ panel_move_control (int from, int to)
li = g_slist_nth (panel.priv->controls, from);
control = li->data;

gtk_box_reorder_child (GTK_BOX (panel.group_box), control->base, to);
xfce_itembar_reorder_child (XFCE_ITEMBAR (panel.group_box),
XFCE_ITEM (control->base), to);

panel.priv->controls = g_slist_delete_link (panel.priv->controls, li);
panel.priv->controls = g_slist_insert (panel.priv->controls, control, to);
@@ -1314,7 +1285,7 @@ panel_add_control (Control * control, int index)
index = len;

control->index = index;
control_pack (control, GTK_BOX (panel.group_box));
control_pack (control, panel.group_box);
panel.priv->controls = g_slist_append (panel.priv->controls, control);

if (index >= 0 && index < len)
@@ -1345,7 +1316,6 @@ panel_set_orientation (int orientation)
{
gboolean hidden;
int pos;
GSList *l;

panel.priv->settings.orientation = orientation;

@@ -1367,20 +1337,16 @@ panel_set_orientation (int orientation)

gtk_widget_hide (panel.toplevel);

/* save panel controls */
panel_unpack_controls (&panel);

/* no need to recreate the window */
gtk_widget_destroy (panel.group_box);
create_panel_framework (&panel);

for (l = panel.priv->controls; l != NULL; l = l->next)
{
Control *control = l->data;

control_set_orientation (control, orientation);
}

xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel.toplevel),
orientation == VERTICAL ?
GTK_ORIENTATION_VERTICAL :
GTK_ORIENTATION_HORIZONTAL);
xfce_itembar_set_orientation (XFCE_ITEMBAR (panel.group_box),
orientation == VERTICAL ?
GTK_ORIENTATION_VERTICAL :
GTK_ORIENTATION_HORIZONTAL);
/* change popup position to make it look better
* done here, because it's needed for size calculation
* the setttings dialog will also change, we just
@@ -1404,8 +1370,6 @@ panel_set_orientation (int orientation)
}
panel_set_popup_position (pos);

panel_pack_controls (&panel);

gtk_widget_size_request (panel.toplevel, &panel.priv->req);

/* calls panel_set_position () */
@@ -1823,7 +1787,7 @@ old_groups_set_from_xml (int side, xmlNodePtr node)
else
{
control = control_new (i);
control_pack (control, GTK_BOX (panel.group_box));
control_pack (control, panel.group_box);
panel.priv->controls = g_slist_append (panel.priv->controls,
control);
}
@@ -1881,7 +1845,7 @@ groups_set_from_xml (xmlNodePtr node)
Control *control;

control = control_new (i);
control_pack (control, GTK_BOX (panel.group_box));
control_pack (control, panel.group_box);
panel.priv->controls = g_slist_append (panel.priv->controls, control);

for (child = node->children; child; child = child->next)


+ 3
- 29
panel/xfce_support.c View File

@@ -24,6 +24,8 @@
* --------------
* miscellaneous support functions that can be used by
* all modules (and external plugins).
*
* FIXME should probably be (part of) a library
*/

#ifdef HAVE_CONFIG_H
@@ -224,40 +226,12 @@ G_MODULE_EXPORT /* EXPORT:add_tooltip */
void
add_tooltip (GtkWidget * widget, const char *tip)
{
if (!tooltips)
if (G_UNLIKELY (!tooltips))
tooltips = gtk_tooltips_new ();

gtk_tooltips_set_tip (tooltips, widget, tip, NULL);
}

G_MODULE_EXPORT /* EXPORT:set_window_skip */
void
set_window_skip (GtkWidget * win)
{
#if GTK_CHECK_VERSION(2, 2, 0)
g_object_set (G_OBJECT (win), "skip_taskbar_hint", TRUE, NULL);
g_object_set (G_OBJECT (win), "skip_pager_hint", TRUE, NULL);
#else
Screen *xscreen;
Window xid;
static Atom xa_SKIP_PAGER = 0;
static Atom xa_SKIP_TASKBAR = 0;

if (!xa_SKIP_PAGER)
{
xa_SKIP_PAGER = XInternAtom (GDK_DISPLAY (),
"_NET_WM_STATE_SKIP_PAGER", False);
xa_SKIP_TASKBAR = XInternAtom (GDK_DISPLAY (),
"_NET_WM_STATE_SKIP_TASKBAR", False);
}

xscreen = DefaultScreenOfDisplay (GDK_DISPLAY ());
xid = GDK_WINDOW_XID (win->window);

netk_change_state (xscreen, xid, TRUE, xa_SKIP_PAGER, xa_SKIP_TASKBAR);
#endif
}

/* DND
* ---
*/


+ 0
- 3
panel/xfce_support.h View File

@@ -34,9 +34,6 @@ G_MODULE_IMPORT void write_backup_file (const char *path);
/* tooltips */
G_MODULE_IMPORT void add_tooltip (GtkWidget * widget, const char *tip);

/* x atoms and properties */
G_MODULE_IMPORT void set_window_skip (GtkWidget * win);

/* dnd */
G_MODULE_IMPORT void dnd_set_drag_dest (GtkWidget * widget);



+ 6
- 99
plugins/separator/separator.c View File

@@ -1,9 +1,6 @@
/* $Id$
*
* Copyright 2003 Jasper Huijsmans (jasper)
*
* Adapted from initial implementation by Ejvend Nielsen, copyright 2003
* licensed under GNU GPL.
* Copyright 2003,2005 Jasper Huijsmans (jasper)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,120 +26,33 @@

#include <libxfce4util/libxfce4util.h>

#include "libs/xfce-separator-item.h"
#include "libs/xfce-itembar.h"

#include <panel/plugins.h>
#include <panel/xfce.h>

typedef struct
{
GtkWidget *box;
GtkWidget *align;
GtkWidget *hsep;
GtkWidget *vsep;
}
t_separator;

static void
separator_free (Control * control)
{
t_separator *sep = control->data;

g_object_unref (sep->hsep);
g_object_unref (sep->vsep);

g_free (sep);
}

static void
separator_attach_callback (Control * control, const char *signal,
GCallback callback, gpointer data)
{
t_separator *sep = (t_separator *) control->data;

g_signal_connect (sep->box, signal, callback, data);
g_signal_connect (sep->hsep, signal, callback, data);
g_signal_connect (sep->vsep, signal, callback, data);
/* define explicitly to do nothing */
}

static void
separator_set_size (Control * control, int size)
{
/* define explicitly to do nothing */

#if 0
int s;
t_separator *sep = control->data;

s = icon_size[size] + border_width;

if (settings.orientation == HORIZONTAL)
gtk_widget_set_size_request (control->base, -1, s);
else
gtk_widget_set_size_request (control->base, s, -1);
#endif
}

static void
separator_set_orientation (Control * control, int orientation)
{
t_separator *sep = control->data;
GtkWidget *child;

child = gtk_bin_get_child (GTK_BIN (sep->align));