cvs remove all files in shortcut-bar/, this widget is now in gal, will be

2001-01-27  Jason Leach  <jasonleach@usa.net>

	* cvs remove all files in shortcut-bar/, this widget is now in
	gal, will be maintained there.

	* Makefile.am (SUBDIRS): Remove shortcut-bar from here.

svn path=/trunk/; revision=7857
This commit is contained in:
Jason Leach
2001-01-27 15:18:34 +00:00
committed by Jacob Leach
parent 1d01cfbf2e
commit fb5ba5787f
19 changed files with 7 additions and 7532 deletions

View File

@ -1,3 +1,10 @@
2001-01-27 Jason Leach <jasonleach@usa.net>
* cvs remove all files in shortcut-bar/, this widget is now in
gal, will be maintained there.
* Makefile.am (SUBDIRS): Remove shortcut-bar from here.
2001-01-25 Christopher James Lahey <clahey@helixcode.com>
* menus/gal-view-menus.c: Make this actually deploy the titles

View File

@ -2,5 +2,4 @@
SUBDIRS = \
misc \
meeting-time-sel \
shortcut-bar \
menus

View File

@ -1,8 +0,0 @@
*.o
libshortcut-bar.a
Makefile
Makefile.in
.deps
.libs
.pure
test-shortcut-bar

View File

@ -1,328 +0,0 @@
2000-12-25 Miguel de Icaza <miguel@helixcode.com>
* e-icon-bar.c (e_icon_bar_add_item): Pass draw_background = FALSE
2000-09-30 Damon Chaplin <damon@helixcode.com>
* test-shortcut-bar.c: updated to use new EShortcutBar signals for DnD.
* e-group-bar.c (e_group_bar_add_group): show the new windows if the
EGroupBar is realized, handle the position argument properly, and
fixed the window z-order code.
* e-shortcut-bar.c (e_shortcut_bar_add_group): pass group_num to the
e_group_bar_add_group() function.
* e-icon-bar-bg-item.c (e_icon_bar_bg_item_draw): fixed SEGV when
trying to drag into a group with no items.
2000-09-28 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_destroy): Disconnect the model
before freeing the group array.
2000-09-26 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_on_drag_data_delete): Emit the
signal correctly.
2000-09-25 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_destroy): Call
`e_shortcut_bar_disconnect_model()'.
(e_shortcut_bar_on_drag_data_received): Don't add the item to the
model here; the view is only supposed to act as a view. Rather,
emit the "dropped_shortcut" signal appropriately.
(e_shortcut_bar_on_drag_data_delete): Likewise, don't remove the
item from the model and emit "shortcut_dragged".
(e_shortcut_bar_class_init): Install the "shortcut_dropped" and
"shortcut_dragged" signals.
* e-shortcut-bar.h: New signals "shortcut_dropped",
"shortcut_dragged". "selected_item" changed to "item_selected".
2000-09-18 Christopher James Lahey <clahey@helixcode.com>
* Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and
$(EXTRA_GNOME_LIBS). Removed unneeded libraries.
* e-icon-bar.c, e-icon-bar.h, e-shortcut-bar.c,
e-shortcut-model.c, test-shortcut-bar.c: Fixed the #include lines
to deal properly with gal.
2000-08-16 Larry Ewing <lewing@helixcode.com>
* e-icon-bar.c (e_icon_bar_init): remove COLOR_TEXT references.
2000-08-16 Larry Ewing <lewing@helixcode.com>
* e-icon-bar.h (enum): get rid of COLOR_TEXT.
(struct _EIconBarItem): add pixbuf member to hold unmodified
pixbuf.
* e-icon-bar.c (e_icon_bar_style_set): update the image and the
colors based on the new style.
(e_icon_bar_add_item): store the full alpha pixbuf so that we can
update the background color if the style changes. Use the style
colors where appropriate.
(e_icon_bar_on_editing_stopped): revert to style colors.
(e_icon_bar_on_editing_started): use style fg instead of
COLOR_TEXT.
* e-shortcut-bar.c (e_shortcut_bar_add_group): add an #ifndef
E_USE_STYLES around the call to e_shortcut_bar_set_canvas_style to
allow people to test out the style stuff that is in progress.
2000-07-16 Damon Chaplin <damon@helixcode.com>
* e-shortcut-model.[hc]: new files implementing a simple model for
the shortcuts, so we can have multiple views.
* Makefile.am (libshortcut_bar_a_SOURCES): added e-shortcut-model.[hc]
* e-shortcut-bar.h: updated to use the model.
* e-icon-bar.c (e_icon_bar_item_pressed): set mouse_over_item_num as
well as pressed_item_num to fix bug.
2000-07-10 Ettore Perazzoli <ettore@helixcode.com>
* e-group-bar.c (e_group_bar_add): Set `group_bar'.
2000-06-19 Damon Chaplin <damon@helixcode.com>
* e-icon-bar-bg-item.c:
* e-icon-bar.c:
* e-icon-bar.h:
* e-vscrolled-bar.c: added support for scroll-wheels.
2000-06-02 Christopher James Lahey <clahey@helixcode.com>
* e-icon-bar.c: Free all the item data.
2000-06-01 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_get_view_type): New function.
2000-05-25 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_load_image): Leak plug: free
pathname returned from `gnome_pixmap_file()'.
* Makefile.am: Add `-I$(top_srcdir)'.
2000-05-24 Christopher James Lahey <clahey@helixcode.com>
* Makefile.am: Added libepaned.a.
* test-shortcut-bar.c: Switched from GtkPaned to EPaned.
2000-05-18 Damon Chaplin <damon@helixcode.com>
* e-shortcut-bar.[hc]: new signals "added_item", "removed_item",
"added_group", "removed_group". Note that the removed signals are
emitted just before the item/group is actually removed.
* test-shortcut-bar.c: updated to test the new signals, and ref'ed
the pixbufs in the icon callback.
2000-05-16 Ettore Perazzoli <ettore@helixcode.com>
* e-clipped-label.c: Moved to $(top_srcdir)/widgets/misc.
* e-clipped-label.h: Likewise.
* Makefile.am: Updated accordingly.
2000-05-07 Larry Ewing <lewing@helixcode.com>
* e-icon-bar.h (struct _EIconBarItem): remove the no longer needed
flatened_alpha member.
* e-icon-bar.c (flatten_alpha): using ~rgb can cause visual
artifacts.
(e_icon_bar_add_item): fixup refcounting of the flattend pixbuf,
the canvas item should hold the reference not us. Stop using
item.flattened_alpha since it no longer exists.
(e_icon_bar_remove_item): remove the unref since destroying the
item will take care of that for us.
* e-shortcut-bar.c (e_shortcut_bar_add_item): make sure to unref
the image we get back, the icon bar will hold any references it
needs.
(e_shortcut_bar_get_image_from_url): ref the default image each
time we return it so that references are counted correctly.
2000-05-04 Ettore Perazzoli <ettore@helixcode.com>
* e-shortcut-bar.h (E_TYPE_SHORTCUT_BAR): New #define.
2000-05-04 Ettore Perazzoli <ettore@helixcode.com>
* e-icon-bar-bg-item.c (e_icon_bar_bg_item_draw): Initialize
`shadow' to placate compiler.
* e-icon-bar.c (e_icon_bar_add_item): @text made const-safe.
* e-shortcut-bar.c (e_shortcut_bar_add_group): @group_name made
const-safe.
(e_shortcut_bar_add_item): @item_url and @item_name made
const-safe.
(e_shortcut_bar_get_image_from_url): @item_url made const-safe.
(e_shortcut_bar_load_image): @filename made const-safe.
2000-05-04 Ettore Perazzoli <ettore@helixcode.com>
* test-shortcut-bar.c (icon_callback): Adapted to the new
`EShortcutBarIconCallback' typedef: get a @data parameter and get
a const-safe @url.
* e-shortcut-bar.c (e_shortcut_bar_set_icon_callback): New param
@data. Set `icon_callback_data' to it.
(e_shortcut_bar_get_image_from_url): Pass the callback data to the
callback.
* e-shortcut-bar.h: Changed `EShortcutBarIconCallback' to get a
const-safe @url parameter and a new @data parameter as a closure.
New member `data' in `EShortcutBar'.
2000-05-02 Matt Loper <matt@helixcode.com>
* Makefile.am: set G_LOG_DOMAIN.
2000-04-16 Damon Chaplin <damon@helixcode.com>
* test-shortcut-bar.c: added buttons to test moving/reordering groups.
* e-shortcut-bar.c (e_shortcut_bar_on_drag_end): new function to free
the dragged name & URL when the drag is finished.
* e-group-bar.c (e_group_bar_get_increment): fixed bug when distance
was 0. Should just return 0.
(e_group_bar_set_current_group_num): added animate option and finished.
(e_group_bar_unmap): called e_group_bar_stop_all_animation().
(e_group_bar_reorder_group): finished.
* e-icon-bar-text-item.[hc]: removed, since we now use EText.
2000-04-15 Miguel de Icaza <miguel@gnu.org>
* e-group-bar.c (e_group_bar_realize): Do not use the parent
thingie, because it might be like anything. And anything can be
like any visual, and we dont like want any visual here.
* e-shortcut-bar.c
(e_shortcut_bar_add_group): Apply some loving action when it comes
to visuals and colormaps. Yes, we got one of those machines
--again--. Sigh. This is what you get when you have been away
from the Indy. The whole thing is breaking left and right.
Hopefully, Gtk 1.4 fixes all of this, by always running in the
slowest visual it can find.
2000-04-11 Larry Ewing <lewing@helixcode.com>
* e-icon-bar.c (flatten_alpha): update for
new gdk-pixbuf.
2000-03-31 Damon Chaplin <damon@helixcode.com>
* e-shortcut-bar.[hc]: added support for a
callback function to set the icons.
* test-shortcut-bar.c: updated to use the
callback function.
2000-03-30 Dan Winship <danw@helixcode.com>
* e-shortcut-bar.c: Sort of use the new
pixmaps. This code needs to be restructured, but Damon is
rumored to already be doing it.
2000-03-27 Miguel de Icaza <miguel@gnu.org>
* e-icon-bar.c (flatten_alpha): New function,
used to flatten the images we get and composite them with the
background.
(e_icon_bar_add_item): One happy tigert comming.
2000-03-21 Christopher James Lahey <clahey@helixcode.com>
* e-icon-bar.c: Updated to fix a few bugs.
2000-02-28 NotZed <NotZed@HelixCode.com>
* Makefile.am (test_shortcut_bar_LDADD):
Fixed references to eutil.
2000-02-20 Damon Chaplin <damon@helixcode.com>
* Makefile.am: added libetext.a and libeutil.a
to test_shortcut_bar_LDADD, and got rid of e-icon-bar-text-item.[hc].
I'll delete these soon.
* e-icon-bar.c: changed to be a subclass of
ECanvas and to use EText instead of EIconBarTextItem. Also set
"width_set" & "height_set" of the GnomeCanvasPixbuf items so they
work in the "Small Icon" view.
* e-vscrolled-bar.c: use map/unmap instead of
show/hide for the up & down buttons to avoid queueing resizes.
Otherwise the scrolling starts off a bit jerky.
* test-shortcut-bar.c: output a message when the
main label is resized, just for info.
* *.[hc]: updated my email address.
2000-02-07 Damon Chaplin <damon@helixcode.com>
* e-group-bar.c (e_group_bar_draw): finished.
* e-icon-bar.c (e_icon_bar_item_released):
check that an item was pressed.
2000-01-26 bertrand <bertrand@helixcode.com>
* e-icon-bar.c (e_icon_bar_recalc_item_positions):
don't set the x_set and y_set
arguments as don't exist in gdk-pixbuf
anymore.
2000-01-17 Chrsitopher James Lahey <clahey@helixcode.com>
* Makefile.am: Added gnomecanvaspixbuf to the
list of libraries used.
2000-01-09 Miguel de Icaza <miguel@gnu.org>
* e-icon-bar.c (e_icon_bar_init): Turn on anti-aliasing.
2000-01-08 Miguel de Icaza <miguel@gnu.org>
* e-icon-bar.c (e_icon_bar_add_item): Use
GdkPixbuf here.
(e_icon_bar_get_item_image): ditto and initialize image.
* e-shortcut-bar.c (e_shortcut_bar_add_item):
Use gdk-pixbuf.
2000-01-14 Christopher James Lahey <clahey@helixcode.com>
* e-shortcut-bar.c (e_shortcut_bar_add_item):
Use e_bar_set_item_data.
Drop item_url; Require image argument; Require user data
argument.
2000-01-09 Miguel de Icaza <miguel@gnu.org>
* e-icon-bar.c (e_icon_bar_init): Turn on anti-aliasing.
2000-01-08 Miguel de Icaza <miguel@gnu.org>
* e-icon-bar.c (e_icon_bar_add_item): Use
GdkPixbuf here.
(e_icon_bar_get_item_image): ditto and initialize image.
* e-shortcut-bar.c (e_shortcut_bar_add_item):
Use gdk-pixbuf.

View File

@ -1 +0,0 @@
This code is licensed under the terms of the GNU GPL

View File

@ -1,35 +0,0 @@
noinst_LIBRARIES = libshortcut-bar.a
noinst_PROGRAMS = test-shortcut-bar
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/widgets/misc \
-DEVOLUTION_VERSION=\""$(VERSION)"\" \
$(EXTRA_GNOME_CFLAGS) \
-DG_LOG_DOMAIN=\"shortcut-bar\"
libshortcut_bar_a_SOURCES = \
e-group-bar.c \
e-group-bar.h \
e-icon-bar-bg-item.c \
e-icon-bar-bg-item.h \
e-icon-bar.c \
e-icon-bar.h \
e-shortcut-bar.c \
e-shortcut-bar.h \
e-shortcut-model.c \
e-shortcut-model.h \
e-vscrolled-bar.c \
e-vscrolled-bar.h
test_shortcut_bar_SOURCES = \
test-shortcut-bar.c
test_shortcut_bar_LDADD = \
./libshortcut-bar.a \
../misc/libemiscwidgets.a \
$(EXTRA_GNOME_LIBS)
test_shortcut_bar_LDFLAGS = \
`gnome-config --libs gdk_pixbuf gnomecanvaspixbuf`

File diff suppressed because it is too large Load Diff

View File

@ -1,172 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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 _E_GROUP_BAR_H_
#define _E_GROUP_BAR_H_
#include <gtk/gtkcontainer.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* EGroupBar displays a vertical bar with a number of Groups, which are viewed
* one at a time by selecting the Group's button. When a different Group is
* selected, it slides into view, and the old Group slides out.
* It is typically used on the left of the main application window so users
* can easily access particular features.
*
* It is implemented like GtkNotebook, i.e. the main widgets are the children
* of the EGroupBar and the button widgets are treated specially like the
* GtkNotebook tab labels.
*/
/* This contains information on one item. */
typedef struct _EGroupBarChild EGroupBarChild;
struct _EGroupBarChild
{
/* This is the button used to select the group, and the window we use
to move it around easily. */
GtkWidget *button;
GdkWindow *button_window;
gint button_height;
/* This is the child widget, which can be any widget added by the
application, and the window we use to move it around easily. */
GtkWidget *child;
GdkWindow *child_window;
/* These are TRUE if we are currently animating the windows. */
gboolean button_window_in_animation;
gboolean child_window_in_animation;
/* These are the target y positions that the windows should eventually
move to, used for animation. If we get a size_allocate we just
update these and the animation can continue as normal.
When a child window reaches its target position, it is unmapped if
if it is not the current group (i.e. it has slid off screen). */
gint button_window_target_y;
gint child_window_target_y;
};
#define E_GROUP_BAR(obj) GTK_CHECK_CAST (obj, e_group_bar_get_type (), EGroupBar)
#define E_GROUP_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_group_bar_get_type (), EGroupBarClass)
#define E_IS_GROUP_BAR(obj) GTK_CHECK_TYPE (obj, e_group_bar_get_type ())
typedef struct _EGroupBar EGroupBar;
typedef struct _EGroupBarClass EGroupBarClass;
struct _EGroupBar
{
GtkContainer container;
/* This is an array of EGroupBarChild elements. */
GArray *children;
/* This is the group currently shown. */
gint current_group_num;
/* This is TRUE if all the buttons are allocated the same height. */
gboolean buttons_homogeneous;
/* This is the biggest requested height of all the buttons, which we
use for all buttons when buttons_homogeneous is set. */
gint max_button_height;
/* This is the height of all the child windows & widgets. */
gint child_height;
/* The id of the source function for animation timeouts. If this is
not 0 then we are in the middle of an animation. */
guint animation_timeout_id;
/* The id of the source function for automatically showing groups when
the user drags over the group button, and the group to show. */
guint auto_show_timeout_id;
gint auto_show_group_num;
};
struct _EGroupBarClass
{
GtkContainerClass parent_class;
};
GtkType e_group_bar_get_type (void);
GtkWidget* e_group_bar_new (void);
/*
* Insertion, reordering and deletion of items.
*/
/* Adds a new group at the given position. If position is -1 it adds it as
the last group. It returns the group number. */
gint e_group_bar_add_group (EGroupBar *group_bar,
GtkWidget *child,
GtkWidget *button,
gint position);
void e_group_bar_reorder_group (EGroupBar *group_bar,
gint group_num,
gint new_position);
void e_group_bar_remove_group (EGroupBar *group_bar,
gint group_num);
/*
* Getting & setting the current group.
*/
gint e_group_bar_get_current_group_num (EGroupBar *group_bar);
void e_group_bar_set_current_group_num (EGroupBar *group_bar,
gint group_num,
gboolean animate);
/*
* Getting groups and group numbers.
*/
GtkWidget* e_group_bar_get_nth_group (EGroupBar *group_bar,
gint group_num);
gint e_group_bar_get_group_num (EGroupBar *group_bar,
GtkWidget *child);
/*
* Setting the group button label.
*/
void e_group_bar_set_group_button_label (EGroupBar *group_bar,
gint group_num,
GtkWidget *label);
/*
* Getting & setting the EGroupBar options.
*/
gboolean e_group_bar_get_buttons_homogeneous (EGroupBar *group_bar);
void e_group_bar_set_buttons_homogeneous (EGroupBar *group_bar,
gboolean homogeneous);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_GROUP_BAR_H_ */

View File

@ -1,374 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar.
* It paints the rectangles around items when the mouse moves over them, and
* the lines between items when dragging.
*/
#include <config.h>
#include "e-icon-bar-bg-item.h"
#include "e-icon-bar.h"
/* This is the size of the border around the icons, for the shadow. */
#define E_ICON_BAR_LARGE_ICON_SHADOW_BORDER 2
#define E_ICON_BAR_SMALL_ICON_SHADOW_BORDER 2
/* These are for the horzontal bar when dragging. */
#define E_ICON_BAR_BG_ITEM_BAR_HEIGHT 1
#define E_ICON_BAR_BG_ITEM_BAR_OFFSET 2
#define E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT 8
#define E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT 4
static void e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class);
static void e_icon_bar_bg_item_init (EIconBarBgItem *ibitem);
static void e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg,
guint arg_id);
static void e_icon_bar_bg_item_update (GnomeCanvasItem *item,
double *affine,
ArtSVP *clip_path, int flags);
static void e_icon_bar_bg_item_draw (GnomeCanvasItem *item,
GdkDrawable *drawable,
int x, int y,
int width, int height);
static double e_icon_bar_bg_item_point (GnomeCanvasItem *item,
double x, double y,
int cx, int cy,
GnomeCanvasItem **actual_item);
static gint e_icon_bar_bg_item_event (GnomeCanvasItem *item,
GdkEvent *event);
static gint e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem,
GdkEvent *event);
static gint e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem,
GdkEvent *event);
static gint e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem,
GdkEvent *event);
static GnomeCanvasItemClass *parent_class;
/* The arguments we take */
enum {
ARG_0,
ARG_ICON_BAR
};
GtkType
e_icon_bar_bg_item_get_type (void)
{
static GtkType e_icon_bar_bg_item_type = 0;
if (!e_icon_bar_bg_item_type) {
GtkTypeInfo e_icon_bar_bg_item_info = {
"EIconBarBgItem",
sizeof (EIconBarBgItem),
sizeof (EIconBarBgItemClass),
(GtkClassInitFunc) e_icon_bar_bg_item_class_init,
(GtkObjectInitFunc) e_icon_bar_bg_item_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
e_icon_bar_bg_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_icon_bar_bg_item_info);
}
return e_icon_bar_bg_item_type;
}
static void
e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class)
{
GtkObjectClass *object_class;
GnomeCanvasItemClass *item_class;
parent_class = gtk_type_class (gnome_canvas_item_get_type());
object_class = (GtkObjectClass *) class;
item_class = (GnomeCanvasItemClass *) class;
gtk_object_add_arg_type ("EIconBarBgItem::icon_bar",
GTK_TYPE_POINTER, GTK_ARG_WRITABLE,
ARG_ICON_BAR);
object_class->set_arg = e_icon_bar_bg_item_set_arg;
/* GnomeCanvasItem method overrides */
item_class->update = e_icon_bar_bg_item_update;
item_class->draw = e_icon_bar_bg_item_draw;
item_class->point = e_icon_bar_bg_item_point;
item_class->event = e_icon_bar_bg_item_event;
}
static void
e_icon_bar_bg_item_init (EIconBarBgItem *ibitem)
{
GnomeCanvasItem *item = GNOME_CANVAS_ITEM (ibitem);
ibitem->icon_bar = NULL;
item->x1 = 0;
item->y1 = 0;
item->x2 = 0;
item->y2 = 0;
}
static void
e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
EIconBarBgItem *ibitem;
item = GNOME_CANVAS_ITEM (o);
ibitem = E_ICON_BAR_BG_ITEM (o);
switch (arg_id){
case ARG_ICON_BAR:
ibitem->icon_bar = GTK_VALUE_POINTER (*arg);
break;
}
}
static void
e_icon_bar_bg_item_update (GnomeCanvasItem *item,
double *affine,
ArtSVP *clip_path,
int flags)
{
if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update)
(* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags);
/* The grid covers the entire canvas area. */
item->x1 = 0;
item->y1 = 0;
item->x2 = INT_MAX;
item->y2 = INT_MAX;
}
/*
* DRAWING ROUTINES - functions to paint the canvas item.
*/
static void
e_icon_bar_bg_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
EIconBar *icon_bar;
EIconBarItem *item;
EIconBarBgItem *ibitem;
GtkStyle *style;
GdkGC *gc;
GtkShadowType shadow;
gint item_num, border, bar_x, bar_y, bar_w, i, arrow_height;
ibitem = E_ICON_BAR_BG_ITEM (canvas_item);
icon_bar = ibitem->icon_bar;
g_return_if_fail (icon_bar != NULL);
style = GTK_WIDGET (icon_bar)->style;
shadow = GTK_SHADOW_NONE;
/* Draw the highlight around the current highlight item. */
item_num = -1;
if (icon_bar->editing_item_num == -1) {
if (icon_bar->pressed_item_num != -1) {
item_num = icon_bar->pressed_item_num;
if (icon_bar->pressed_item_num == icon_bar->mouse_over_item_num)
shadow = GTK_SHADOW_IN;
else
shadow = GTK_SHADOW_OUT;
} else if (icon_bar->mouse_over_item_num != -1) {
item_num = icon_bar->mouse_over_item_num;
shadow = GTK_SHADOW_OUT;
}
}
if (item_num != -1) {
item = &g_array_index (icon_bar->items, EIconBarItem,
item_num);
if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS)
border = E_ICON_BAR_LARGE_ICON_SHADOW_BORDER;
else
border = E_ICON_BAR_SMALL_ICON_SHADOW_BORDER;
gtk_draw_shadow (style, drawable, GTK_STATE_NORMAL, shadow,
icon_bar->icon_x - border - x,
item->icon_y - border - y,
icon_bar->icon_w + border * 2 - 1,
icon_bar->icon_h + border * 2 - 1);
}
/* Draw the bar between items when dragging, if needed. */
if (icon_bar->in_drag && icon_bar->dragging_before_item_num != -1) {
if (icon_bar->dragging_before_item_num < icon_bar->items->len) {
item = &g_array_index (icon_bar->items, EIconBarItem,
icon_bar->dragging_before_item_num);
bar_y = 0;
} else {
/* We need to draw the bar after the last item. */
if (icon_bar->items->len != 0) {
item = &g_array_index (icon_bar->items,
EIconBarItem,
icon_bar->items->len - 1);
bar_y = item->item_height + icon_bar->spacing;
} else {
item = NULL;
bar_y = icon_bar->spacing;
}
}
if (item) {
if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) {
bar_y += item->icon_y;
} else {
bar_y += MIN (item->icon_y, item->text_y);
}
}
bar_y -= y + icon_bar->spacing / 2;
bar_x = E_ICON_BAR_BG_ITEM_BAR_OFFSET - x;
bar_w = GTK_WIDGET (icon_bar)->allocation.width - 2 * E_ICON_BAR_BG_ITEM_BAR_OFFSET - 1;
gc = GTK_WIDGET (icon_bar)->style->fg_gc[GTK_STATE_NORMAL];
/* Draw the horizontal bar. */
gdk_draw_rectangle (drawable, gc, TRUE,
bar_x, bar_y,
bar_w, E_ICON_BAR_BG_ITEM_BAR_HEIGHT);
if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS)
arrow_height = E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT / 2;
else
arrow_height = E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT / 2;
/* Draw the arrows at the end of the lines. We use
gdk_draw_line() to draw a series of vertical lines, since
gdk_draw_polygon() produces odd results. */
i = 0;
while (arrow_height > 0) {
gdk_draw_line (drawable, gc,
bar_x + i,
bar_y - arrow_height,
bar_x + i,
bar_y + arrow_height);
gdk_draw_line (drawable, gc,
bar_x + bar_w - i - 1,
bar_y - arrow_height,
bar_x + bar_w - i - 1,
bar_y + arrow_height);
arrow_height--;
i++;
}
}
}
/* This is supposed to return the nearest item the the point and the distance.
Since we are the only item we just return ourself and 0 for the distance.
This is needed so that we get button/motion events. */
static double
e_icon_bar_bg_item_point (GnomeCanvasItem *item, double x, double y,
int cx, int cy,
GnomeCanvasItem **actual_item)
{
*actual_item = item;
return 0.0;
}
static gint
e_icon_bar_bg_item_event (GnomeCanvasItem *item, GdkEvent *event)
{
EIconBarBgItem *ibitem;
ibitem = E_ICON_BAR_BG_ITEM (item);
switch (event->type) {
case GDK_BUTTON_PRESS:
return e_icon_bar_bg_item_button_press (ibitem, event);
case GDK_BUTTON_RELEASE:
return e_icon_bar_bg_item_button_release (ibitem, event);
case GDK_MOTION_NOTIFY:
return e_icon_bar_bg_item_motion_notify (ibitem, event);
default:
break;
}
return FALSE;
}
static gint
e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem,
GdkEvent *event)
{
gint item_num;
if (event->button.button == 4 || event->button.button == 5)
return FALSE;
item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar,
event->button.x,
event->button.y,
NULL);
e_icon_bar_item_pressed (ibitem->icon_bar, item_num, event);
return TRUE;
}
static gint
e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem,
GdkEvent *event)
{
gint item_num;
item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar,
event->button.x,
event->button.y,
NULL);
e_icon_bar_item_released (ibitem->icon_bar, item_num, event);
return TRUE;
}
static gint
e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem,
GdkEvent *event)
{
gint item_num;
item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar,
event->motion.x,
event->motion.y,
NULL);
e_icon_bar_item_motion (ibitem->icon_bar, item_num, event);
return TRUE;
}

View File

@ -1,72 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar.
* It paints the rectangles around items when the mouse moves over them, and
* the lines between items when dragging.
*/
#ifndef _E_ICON_BAR_BG_ITEM_H_
#define _E_ICON_BAR_BG_ITEM_H_
#include <libgnomeui/gnome-canvas.h>
#include "e-icon-bar.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define E_ICON_BAR_BG_ITEM(obj) (GTK_CHECK_CAST((obj), e_icon_bar_bg_item_get_type (), EIconBarBgItem))
#define E_ICON_BAR_BG_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_icon_bar_bg_item_get_type (), EIconBarBgItemClass))
#define E_IS_ICON_BAR_BG_ITEM(o) (GTK_CHECK_TYPE((o), e_icon_bar_bg_item_get_type ()))
typedef struct _EIconBarBgItem EIconBarBgItem;
typedef struct _EIconBarBgItemClass EIconBarBgItemClass;
struct _EIconBarBgItem
{
GnomeCanvasItem canvas_item;
/* The parent EIconBar widget. */
EIconBar *icon_bar;
};
struct _EIconBarBgItemClass
{
GnomeCanvasItemClass parent_class;
};
GtkType e_icon_bar_bg_item_get_type (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_ICON_BAR_BG_ITEM_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,246 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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 _E_ICON_BAR_H_
#define _E_ICON_BAR_H_
#include <gdk_imlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gal/widgets/e-canvas.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* EIconBar is a subclass of GnomeCanvas for displaying a vertical column of
* icons and descriptions. It provides 2 views - large icons and small icons.
*/
/* This contains information on one item. */
typedef struct _EIconBarItem EIconBarItem;
struct _EIconBarItem
{
GnomeCanvasItem *text;
GnomeCanvasItem *image;
/* This holds the original pixbuf so that we can blend
to the background if the style changes */
GdkPixbuf *pixbuf;
/* This is user data attached to the item, e.g. a URL. */
gpointer data;
GtkDestroyNotify destroy;
/* This is the height of the item. */
gint item_height;
/* This is the actual x, width and height of the text, rather than
the maximum allowed area. */
gint text_x;
gint text_width;
gint text_height;
gint icon_y, text_y;
};
/* These are the view types. Defaults to LARGE_ICONS. */
typedef enum
{
E_ICON_BAR_LARGE_ICONS,
E_ICON_BAR_SMALL_ICONS
} EIconBarViewType;
/* These index our colors array. */
typedef enum
{
E_ICON_BAR_COLOR_EDITING_TEXT,
E_ICON_BAR_COLOR_EDITING_RECT,
E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE,
E_ICON_BAR_COLOR_LAST
} EIconBarColors;
#define E_ICON_BAR(obj) GTK_CHECK_CAST (obj, e_icon_bar_get_type (), EIconBar)
#define E_ICON_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_icon_bar_get_type (), EIconBarClass)
#define E_IS_ICON_BAR(obj) GTK_CHECK_TYPE (obj, e_icon_bar_get_type ())
typedef struct _EIconBar EIconBar;
typedef struct _EIconBarClass EIconBarClass;
struct _EIconBar
{
ECanvas canvas;
/* This specifies if we are using large icons or small icons. */
EIconBarViewType view_type;
/* This is an array of EIconBarItem elements. */
GArray *items;
/* This is the index of the item which has been pressed, or -1.
It will be shown as pressed in while the mouse is over it. */
gint pressed_item_num;
/* This is the coordinates of where the button was pressed. If the
mouse moves a certain distance with the button still pressed, we
start a drag. */
gint pressed_x;
gint pressed_y;
/* This is the index of the item the mouse is currently over, or -1.
It will be highlighted unless one of the items is pressed. */
gint mouse_over_item_num;
/* This is the item that we are currently editing, or -1. */
gint editing_item_num;
/* This is a GnomeCanvasRect which is placed around the edited item. */
GnomeCanvasItem *edit_rect_item;
/* This is the index of the item which is being dragged, or -1.
If the drag results in a move it will be deleted. */
gint dragged_item_num;
/* This is TRUE if we are dragging over this EIconBar. */
gboolean in_drag;
/* This is used in drag-and-drop to indicate the item which the mouse
is currently before, e.g. if it is 1 then a dropped item would be
inserted between items 0 and 1. It ranges from 0 to the number of
items, or is -1 when the mouse is not dragging between items. */
gint dragging_before_item_num;
/* These are the common positions of all the items in the EIconBar. */
gint icon_x, icon_w, icon_h, text_x, text_w, spacing;
/* This is the source id of our auto-scroll timeout handler, used when
in the middle of drag-and-drop operations. */
gint auto_scroll_timeout_id;
gint auto_scroll_delay;
gboolean scrolling_up;
/* Colors for drawing. */
GdkColor colors[E_ICON_BAR_COLOR_LAST];
/* Signal connection id for "value_changed" signal of vadjustment. */
guint vadjustment_value_changed_id;
};
struct _EIconBarClass
{
ECanvasClass parent_class;
void (*selected_item) (EIconBar *icon_bar,
GdkEvent *event,
gint item_num);
void (*dragged_item) (EIconBar *icon_bar,
GdkEvent *event,
gint item_num);
};
GtkType e_icon_bar_get_type (void);
GtkWidget* e_icon_bar_new (void);
/* Sets the view type. */
void e_icon_bar_set_view_type (EIconBar *icon_bar,
EIconBarViewType view_type);
/* Adds a new item to a group at the given position. If position is -1 it is
added at the end. It returns the index of the item. */
gint e_icon_bar_add_item (EIconBar *icon_bar,
GdkPixbuf *image,
const gchar *text,
gint position);
/* Reorders an item. Note that position refers to the new position to add the
item after removing it from its current position. If position is -1 it is
moved to the end of the bar. */
void e_icon_bar_reorder_item (EIconBar *icon_bar,
gint item_num,
gint new_position);
void e_icon_bar_remove_item (EIconBar *icon_bar,
gint item_num);
GdkPixbuf * e_icon_bar_get_item_image (EIconBar *icon_bar,
gint item_num);
void e_icon_bar_set_item_image (EIconBar *icon_bar,
gint item_num,
GdkPixbuf *image);
gchar* e_icon_bar_get_item_text (EIconBar *icon_bar,
gint item_num);
void e_icon_bar_set_item_text (EIconBar *icon_bar,
gint item_num,
gchar *text);
gpointer e_icon_bar_get_item_data (EIconBar *icon_bar,
gint item_num);
void e_icon_bar_set_item_data (EIconBar *icon_bar,
gint item_num,
gpointer data);
void e_icon_bar_set_item_data_full (EIconBar *icon_bar,
gint item_num,
gpointer data,
GtkDestroyNotify destroy);
void e_icon_bar_start_editing_item (EIconBar *icon_bar,
gint item_num);
void e_icon_bar_stop_editing_item (EIconBar *icon_bar,
gboolean accept);
/*
* INTERNAL FUNCTIONS - for use by EIconBarBgItem.
*/
/* This returns the index of the item at the given position on the EIconBar,
or -1 if no item is found. If before_item is not NULL, it returns the
item which the mouse is before, or -1 (this is used for dragging). */
gint e_icon_bar_find_item_at_position (EIconBar *icon_bar,
gint x,
gint y,
gint *before_item);
void e_icon_bar_item_pressed (EIconBar *icon_bar,
gint item_num,
GdkEvent *event);
void e_icon_bar_item_released (EIconBar *icon_bar,
gint item_num,
GdkEvent *event);
void e_icon_bar_item_motion (EIconBar *icon_bar,
gint item_num,
GdkEvent *event);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_ICON_BAR_H_ */

View File

@ -1,799 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* EShortcutBar displays a vertical bar with a number of Groups, each of which
* contains any number of icons. It is used on the left of the main application
* window so users can easily access items such as folders and files.
*
* The architecture is a bit complicated. EShortcutBar is a sublass of
* EGroupBar (which supports a number of groups with buttons to slide them
* into view). EShortcutBar places an EIconBar widget in each group page,
* which displays an icon and name for each shortcut.
*/
#include <config.h>
#include <string.h>
#include <gal/util/e-util.h>
#include "e-shortcut-bar.h"
#include "e-clipped-label.h"
#include "e-vscrolled-bar.h"
/* Drag and Drop stuff. */
enum {
TARGET_SHORTCUT
};
static GtkTargetEntry target_table[] = {
{ "E-SHORTCUT", 0, TARGET_SHORTCUT }
};
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
gboolean e_shortcut_bar_default_icon_loaded = FALSE;
GdkPixbuf *e_shortcut_bar_default_icon = NULL;
gchar *e_shortcut_bar_default_icon_filename = "gnome-folder.png";
static void e_shortcut_bar_class_init (EShortcutBarClass *class);
static void e_shortcut_bar_init (EShortcutBar *shortcut_bar);
static void e_shortcut_bar_destroy (GtkObject *object);
static void e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_model_destroyed (EShortcutModel *model,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_group_added (EShortcutModel *model,
gint group_num,
gchar *group_name,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_group_removed (EShortcutModel *model,
gint group_num,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_item_added (EShortcutModel *model,
gint group_num,
gint item_num,
gchar *item_url,
gchar *item_name,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_item_removed (EShortcutModel *model,
gint group_num,
gint item_num,
EShortcutBar *shortcut_bar);
static gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar,
gint position,
const gchar *group_name);
static void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
gint group_num);
static gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar,
gint group_num,
gint position,
const gchar *item_url,
const gchar *item_name);
static void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
static void e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar,
GtkWidget *canvas);
static void e_shortcut_bar_item_selected (EIconBar *icon_bar,
GdkEvent *event,
gint item_num,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_item_dragged (EIconBar *icon_bar,
GdkEvent *event,
gint item_num,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_drag_data_received(GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint time,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_drag_data_delete (GtkWidget *widget,
GdkDragContext *context,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_on_drag_end (GtkWidget *widget,
GdkDragContext *context,
EShortcutBar *shortcut_bar);
static void e_shortcut_bar_stop_editing (GtkWidget *button,
EShortcutBar *shortcut_bar);
static GdkPixbuf* e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
const gchar *item_url);
static GdkPixbuf* e_shortcut_bar_load_image (const gchar *filename);
enum
{
ITEM_SELECTED,
SHORTCUT_DROPPED,
SHORTCUT_DRAGGED,
LAST_SIGNAL
};
static guint e_shortcut_bar_signals[LAST_SIGNAL] = {0};
static EGroupBarClass *parent_class;
static void
e_shortcut_bar_marshal_NONE__INT_INT_STRING_STRING (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args)
{
void (*rfunc) (GtkObject *, gint, gint, gchar *, gchar *, gpointer) = func;
(*rfunc) (object,
GTK_VALUE_INT (args[0]),
GTK_VALUE_INT (args[1]),
GTK_VALUE_STRING (args[2]),
GTK_VALUE_STRING (args[3]),
func_data);
}
E_MAKE_TYPE(e_shortcut_bar, "EShortcutBar", EShortcutBar,
e_shortcut_bar_class_init, e_shortcut_bar_init,
e_group_bar_get_type())
static void
e_shortcut_bar_class_init (EShortcutBarClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
parent_class = gtk_type_class (e_group_bar_get_type ());
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
e_shortcut_bar_signals[ITEM_SELECTED] =
gtk_signal_new ("item_selected",
GTK_RUN_LAST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutBarClass,
item_selected),
gtk_marshal_NONE__POINTER_INT_INT,
GTK_TYPE_NONE, 3, GTK_TYPE_GDK_EVENT,
GTK_TYPE_INT, GTK_TYPE_INT);
e_shortcut_bar_signals[SHORTCUT_DROPPED] =
gtk_signal_new ("shortcut_dropped",
GTK_RUN_LAST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutBarClass, shortcut_dropped),
e_shortcut_bar_marshal_NONE__INT_INT_STRING_STRING,
GTK_TYPE_NONE, 4,
GTK_TYPE_INT,
GTK_TYPE_INT,
GTK_TYPE_STRING,
GTK_TYPE_STRING);
e_shortcut_bar_signals[SHORTCUT_DRAGGED] =
gtk_signal_new ("shortcut_dragged",
GTK_RUN_LAST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutBarClass, shortcut_dragged),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT,
GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, e_shortcut_bar_signals,
LAST_SIGNAL);
/* Method override */
object_class->destroy = e_shortcut_bar_destroy;
}
static void
e_shortcut_bar_init (EShortcutBar *shortcut_bar)
{
shortcut_bar->groups = g_array_new (FALSE, FALSE,
sizeof (EShortcutBarGroup));
shortcut_bar->dragged_url = NULL;
shortcut_bar->dragged_name = NULL;
}
GtkWidget *
e_shortcut_bar_new (void)
{
GtkWidget *shortcut_bar;
shortcut_bar = GTK_WIDGET (gtk_type_new (e_shortcut_bar_get_type ()));
return shortcut_bar;
}
static void
e_shortcut_bar_destroy (GtkObject *object)
{
EShortcutBar *shortcut_bar;
shortcut_bar = E_SHORTCUT_BAR (object);
e_shortcut_bar_disconnect_model (shortcut_bar);
g_array_free (shortcut_bar->groups, TRUE);
g_free (shortcut_bar->dragged_url);
g_free (shortcut_bar->dragged_name);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
e_shortcut_bar_set_model (EShortcutBar *shortcut_bar,
EShortcutModel *model)
{
gint num_groups, group_num, num_items, item_num;
gchar *group_name, *item_url, *item_name;
/* Disconnect any existing model. */
e_shortcut_bar_disconnect_model (shortcut_bar);
shortcut_bar->model = model;
if (!model)
return;
gtk_signal_connect (GTK_OBJECT (model), "destroy",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_model_destroyed),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (model), "group_added",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_added),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (model), "group_removed",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_removed),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (model), "item_added",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_added),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (model), "item_removed",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_removed),
shortcut_bar);
/* Add any items already in the model. */
num_groups = e_shortcut_model_get_num_groups (model);
for (group_num = 0; group_num < num_groups; group_num++) {
group_name = e_shortcut_model_get_group_name (model,
group_num);
e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
g_free (group_name);
num_items = e_shortcut_model_get_num_items (model, group_num);
for (item_num = 0; item_num < num_items; item_num++) {
e_shortcut_model_get_item_info (model, group_num,
item_num, &item_url,
&item_name);
e_shortcut_bar_add_item (shortcut_bar, group_num,
item_num, item_url,
item_name);
g_free (item_url);
g_free (item_name);
}
}
}
static void
e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar)
{
/* Remove all the current groups. */
while (shortcut_bar->groups->len)
e_shortcut_bar_remove_group (shortcut_bar, 0);
if (shortcut_bar->model) {
/* Disconnect all the signals in one go. */
gtk_signal_disconnect_by_data (GTK_OBJECT (shortcut_bar->model), shortcut_bar);
shortcut_bar->model = NULL;
}
}
static void
e_shortcut_bar_on_model_destroyed (EShortcutModel *model,
EShortcutBar *shortcut_bar)
{
e_shortcut_bar_disconnect_model (shortcut_bar);
}
static void
e_shortcut_bar_on_group_added (EShortcutModel *model,
gint group_num,
gchar *group_name,
EShortcutBar *shortcut_bar)
{
e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
}
static void
e_shortcut_bar_on_group_removed (EShortcutModel *model,
gint group_num,
EShortcutBar *shortcut_bar)
{
e_shortcut_bar_remove_group (shortcut_bar, group_num);
}
static void
e_shortcut_bar_on_item_added (EShortcutModel *model,
gint group_num,
gint item_num,
gchar *item_url,
gchar *item_name,
EShortcutBar *shortcut_bar)
{
e_shortcut_bar_add_item (shortcut_bar, group_num, item_num,
item_url, item_name);
}
static void
e_shortcut_bar_on_item_removed (EShortcutModel *model,
gint group_num,
gint item_num,
EShortcutBar *shortcut_bar)
{
e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num);
}
static gint
e_shortcut_bar_add_group (EShortcutBar *shortcut_bar,
gint position,
const gchar *group_name)
{
EShortcutBarGroup *group, tmp_group;
gint group_num;
GtkWidget *button, *label;
g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1);
g_return_val_if_fail (group_name != NULL, -1);
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
gtk_widget_push_visual (gdk_rgb_get_visual ());
group_num = position;
g_array_insert_val (shortcut_bar->groups, group_num, tmp_group);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
group->vscrolled_bar = e_vscrolled_bar_new (NULL);
gtk_widget_show (group->vscrolled_bar);
gtk_signal_connect (
GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->up_button),
"pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar);
gtk_signal_connect (
GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->down_button),
"pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar);
group->icon_bar = e_icon_bar_new ();
gtk_widget_show (group->icon_bar);
gtk_container_add (GTK_CONTAINER (group->vscrolled_bar),
group->icon_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_selected",
GTK_SIGNAL_FUNC (e_shortcut_bar_item_selected),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_dragged",
GTK_SIGNAL_FUNC (e_shortcut_bar_item_dragged),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_get",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_get),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_received",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_received),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_delete",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_delete),
shortcut_bar);
gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_end",
GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_end),
shortcut_bar);
#ifndef E_USE_STYLES
e_shortcut_bar_set_canvas_style (shortcut_bar, group->icon_bar);
#endif
button = gtk_button_new ();
label = e_clipped_label_new (group_name);
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (button), label);
gtk_widget_show (button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing),
shortcut_bar);
gtk_drag_dest_set (GTK_WIDGET (group->icon_bar),
GTK_DEST_DEFAULT_ALL,
target_table, n_targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
gtk_drag_dest_set (GTK_WIDGET (button),
GTK_DEST_DEFAULT_ALL,
target_table, n_targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
e_group_bar_add_group (E_GROUP_BAR (shortcut_bar),
group->vscrolled_bar, button, group_num);
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
return group_num;
}
static void
e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar,
gint group_num)
{
e_group_bar_remove_group (E_GROUP_BAR (shortcut_bar), group_num);
g_array_remove_index (shortcut_bar->groups, group_num);
}
static gint
e_shortcut_bar_add_item (EShortcutBar *shortcut_bar,
gint group_num,
gint position,
const gchar *item_url,
const gchar *item_name)
{
EShortcutBarGroup *group;
GdkPixbuf *image;
gint item_num;
g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1);
g_return_val_if_fail (group_num >= 0, -1);
g_return_val_if_fail (group_num < shortcut_bar->groups->len, -1);
g_return_val_if_fail (item_url != NULL, -1);
g_return_val_if_fail (item_name != NULL, -1);
image = e_shortcut_bar_get_image_from_url (shortcut_bar, item_url);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar),
image, item_name, position);
gdk_pixbuf_unref (image);
e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), item_num,
g_strdup (item_url), g_free);
return item_num;
}
static void
e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num)
{
EShortcutBarGroup *group;
g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_bar->groups->len);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
e_icon_bar_remove_item (E_ICON_BAR (group->icon_bar), item_num);
}
static void
e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar,
GtkWidget *canvas)
{
GtkRcStyle *rc_style;
rc_style = gtk_rc_style_new ();
rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG;
rc_style->fg[GTK_STATE_NORMAL].red = 65535;
rc_style->fg[GTK_STATE_NORMAL].green = 65535;
rc_style->fg[GTK_STATE_NORMAL].blue = 65535;
rc_style->bg[GTK_STATE_NORMAL].red = 32512;
rc_style->bg[GTK_STATE_NORMAL].green = 32512;
rc_style->bg[GTK_STATE_NORMAL].blue = 32512;
gtk_widget_modify_style (GTK_WIDGET (canvas), rc_style);
gtk_rc_style_unref (rc_style);
}
void
e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar,
gint group_num,
EIconBarViewType view_type)
{
EShortcutBarGroup *group;
g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_bar->groups->len);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
e_icon_bar_set_view_type (E_ICON_BAR (group->icon_bar), view_type);
}
EIconBarViewType
e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar,
gint group_num)
{
EShortcutBarGroup *group;
g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), E_ICON_BAR_SMALL_ICONS);
g_return_val_if_fail (group_num >= 0, E_ICON_BAR_SMALL_ICONS);
g_return_val_if_fail (group_num < shortcut_bar->groups->len, E_ICON_BAR_SMALL_ICONS);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
return E_ICON_BAR (group->icon_bar)->view_type;
}
static void
e_shortcut_bar_item_selected (EIconBar *icon_bar,
GdkEvent *event,
gint item_num,
EShortcutBar *shortcut_bar)
{
gint group_num;
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
GTK_WIDGET (icon_bar)->parent);
gtk_signal_emit (GTK_OBJECT (shortcut_bar),
e_shortcut_bar_signals[ITEM_SELECTED],
event, group_num, item_num);
}
static void
e_shortcut_bar_item_dragged (EIconBar *icon_bar,
GdkEvent *event,
gint item_num,
EShortcutBar *shortcut_bar)
{
GtkTargetList *target_list;
gint group_num;
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
GTK_WIDGET (icon_bar)->parent);
shortcut_bar->dragged_url = g_strdup (e_icon_bar_get_item_data (icon_bar, item_num));
shortcut_bar->dragged_name = e_icon_bar_get_item_text (icon_bar, item_num);
target_list = gtk_target_list_new (target_table, n_targets);
gtk_drag_begin (GTK_WIDGET (icon_bar), target_list,
GDK_ACTION_COPY | GDK_ACTION_MOVE,
1, event);
gtk_target_list_unref (target_list);
}
static void
e_shortcut_bar_on_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time,
EShortcutBar *shortcut_bar)
{
gchar *data;
if (info == TARGET_SHORTCUT) {
data = g_strdup_printf ("%s%c%s", shortcut_bar->dragged_name,
'\0', shortcut_bar->dragged_url);
gtk_selection_data_set (selection_data, selection_data->target,
8, data,
strlen (shortcut_bar->dragged_name)
+ strlen (shortcut_bar->dragged_url)
+ 2);
g_free (data);
}
}
static void
e_shortcut_bar_on_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint time,
EShortcutBar *shortcut_bar)
{
gchar *item_name, *item_url;
EIconBar *icon_bar;
gint position, group_num;
icon_bar = E_ICON_BAR (widget);
position = icon_bar->dragging_before_item_num;
if ((data->length >= 0) && (data->format == 8)
&& position != -1) {
item_name = data->data;
item_url = item_name + strlen (item_name) + 1;
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
GTK_WIDGET (icon_bar)->parent);
gtk_signal_emit (GTK_OBJECT (shortcut_bar),
e_shortcut_bar_signals[SHORTCUT_DROPPED],
group_num, position, item_url, item_name);
gtk_drag_finish (context, TRUE, TRUE, time);
return;
}
gtk_drag_finish (context, FALSE, FALSE, time);
}
static void
e_shortcut_bar_on_drag_data_delete (GtkWidget *widget,
GdkDragContext *context,
EShortcutBar *shortcut_bar)
{
EIconBar *icon_bar;
gint group_num;
icon_bar = E_ICON_BAR (widget);
group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
widget->parent);
gtk_signal_emit (GTK_OBJECT (shortcut_bar), e_shortcut_bar_signals[SHORTCUT_DRAGGED],
group_num, icon_bar->dragged_item_num);
}
static void
e_shortcut_bar_on_drag_end (GtkWidget *widget,
GdkDragContext *context,
EShortcutBar *shortcut_bar)
{
g_free (shortcut_bar->dragged_name);
shortcut_bar->dragged_name = NULL;
g_free (shortcut_bar->dragged_url);
shortcut_bar->dragged_url = NULL;
}
void
e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num)
{
EShortcutBarGroup *group;
g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_bar->groups->len);
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
e_icon_bar_start_editing_item (E_ICON_BAR (group->icon_bar), item_num);
}
/* We stop editing any item when a scroll button is pressed. */
static void
e_shortcut_bar_stop_editing (GtkWidget *button,
EShortcutBar *shortcut_bar)
{
EShortcutBarGroup *group;
gint group_num;
for (group_num = 0;
group_num < shortcut_bar->groups->len;
group_num++) {
group = &g_array_index (shortcut_bar->groups,
EShortcutBarGroup, group_num);
e_icon_bar_stop_editing_item (E_ICON_BAR (group->icon_bar),
TRUE);
}
}
/* Sets the callback which is called to return the icon to use for a particular
URL. */
void
e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar,
EShortcutBarIconCallback cb,
gpointer data)
{
shortcut_bar->icon_callback = cb;
shortcut_bar->icon_callback_data = data;
}
static GdkPixbuf *
e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
const gchar *item_url)
{
GdkPixbuf *icon = NULL;
if (shortcut_bar->icon_callback)
icon = (*shortcut_bar->icon_callback) (shortcut_bar,
item_url,
shortcut_bar->icon_callback_data);
if (!icon) {
if (!e_shortcut_bar_default_icon_loaded) {
e_shortcut_bar_default_icon_loaded = TRUE;
e_shortcut_bar_default_icon = e_shortcut_bar_load_image (e_shortcut_bar_default_icon_filename);
}
icon = e_shortcut_bar_default_icon;
/* ref the default icon each time we return it */
gdk_pixbuf_ref (icon);
}
return icon;
}
static GdkPixbuf *
e_shortcut_bar_load_image (const gchar *filename)
{
gchar *pathname;
GdkPixbuf *image = NULL;
pathname = gnome_pixmap_file (filename);
if (pathname)
image = gdk_pixbuf_new_from_file (pathname);
else
g_warning ("Couldn't find pixmap: %s", filename);
g_free (pathname);
return image;
}

View File

@ -1,138 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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 _E_SHORTCUT_BAR_H_
#define _E_SHORTCUT_BAR_H_
#include "e-group-bar.h"
#include "e-icon-bar.h"
#include "e-shortcut-model.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* EShortcutBar displays a vertical bar with a number of Groups, each of which
* contains any number of icons. It is used on the left of the main application
* window so users can easily access items such as folders and files.
*/
typedef struct _EShortcutBar EShortcutBar;
typedef struct _EShortcutBarClass EShortcutBarClass;
typedef GdkPixbuf* (*EShortcutBarIconCallback) (EShortcutBar *shortcut_bar,
const gchar *url,
gpointer data);
/* This contains information on one group. */
typedef struct _EShortcutBarGroup EShortcutBarGroup;
struct _EShortcutBarGroup
{
/* This is the EVScrolledBar which scrolls the group. */
GtkWidget *vscrolled_bar;
/* This is the icon bar containing the child items. */
GtkWidget *icon_bar;
};
#define E_TYPE_SHORTCUT_BAR (e_shortcut_bar_get_type ())
#define E_SHORTCUT_BAR(obj) GTK_CHECK_CAST (obj, e_shortcut_bar_get_type (), EShortcutBar)
#define E_SHORTCUT_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_bar_get_type (), EShortcutBarClass)
#define E_IS_SHORTCUT_BAR(obj) GTK_CHECK_TYPE (obj, e_shortcut_bar_get_type ())
struct _EShortcutBar
{
EGroupBar group_bar;
/* This is the underlying model. */
EShortcutModel *model;
/* This is an array of EShortcutBarGroup elements. */
GArray *groups;
/* The callback which the application sets to return the icon to use
for a given URL. */
EShortcutBarIconCallback icon_callback;
/* Closure for the callback. */
gpointer icon_callback_data;
gchar *dragged_url;
gchar *dragged_name;
};
struct _EShortcutBarClass
{
EGroupBarClass parent_class;
void (*item_selected) (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num,
gint item_num);
void (*shortcut_dropped) (EShortcutBar *shortcut_bar,
gint group_num,
gint position,
const gchar *item_url,
const char *item_name);
void (*shortcut_dragged) (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
};
GtkType e_shortcut_bar_get_type (void);
GtkWidget* e_shortcut_bar_new (void);
/* Sets the underlying model. */
void e_shortcut_bar_set_model (EShortcutBar *shortcut_bar,
EShortcutModel *shortcut_model);
/* Sets/gets the view type for the group. */
void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar,
gint group_num,
EIconBarViewType view_type);
EIconBarViewType e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar,
gint group_num);
void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
/* Sets the callback which is called to return the icon to use for a particular
URL. This callback must be set before any items are added. If the callback
returns NULL the default icon is used. */
void e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar,
EShortcutBarIconCallback cb,
gpointer data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_SHORTCUT_BAR_H_ */

View File

@ -1,556 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* EShortcutModel keeps track of a number of groups of shortcuts.
* Each shortcut has a URL and a short textual name.
* It is used as the model of the EShortcutBar.
*/
#include <config.h>
#include <gtk/gtksignal.h>
#include <gal/util/e-util.h>
#include "e-shortcut-model.h"
/* This contains information on one item. */
typedef struct _EShortcutModelItem EShortcutModelItem;
struct _EShortcutModelItem
{
gchar *name;
gchar *url;
};
/* This contains information on one group. */
typedef struct _EShortcutModelGroup EShortcutModelGroup;
struct _EShortcutModelGroup
{
gchar *name;
/* An array of EShortcutModelItem. */
GArray *items;
};
#define ESM_CLASS(e) ((EShortcutModelClass *)((GtkObject *)e)->klass)
static void e_shortcut_model_class_init (EShortcutModelClass *class);
static void e_shortcut_model_init (EShortcutModel *shortcut_model);
static void e_shortcut_model_destroy (GtkObject *object);
static void e_shortcut_model_free_group (EShortcutModel *shortcut_model,
gint group_num);
static void e_shortcut_model_real_add_group (EShortcutModel *shortcut_model,
gint position,
const gchar *group_name);
static void e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model,
gint group_num);
static void e_shortcut_model_real_add_item (EShortcutModel *shortcut_model,
gint group_num,
gint position,
const gchar *item_url,
const gchar *item_name);
static void e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
static void e_shortcut_model_marshal1 (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
static void e_shortcut_model_marshal2 (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
static gint e_shortcut_model_real_get_num_groups(EShortcutModel *shortcut_model);
static gint e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model,
gint group_num);
static gchar* e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model,
gint group_num);
static void e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
gchar **item_url,
gchar **item_name);
enum
{
GROUP_ADDED,
GROUP_REMOVED,
ITEM_ADDED,
ITEM_REMOVED,
LAST_SIGNAL
};
static guint e_shortcut_model_signals[LAST_SIGNAL] = {0};
static GtkObjectClass *parent_class;
E_MAKE_TYPE(e_shortcut_model, "EShortcutModel", EShortcutModel,
e_shortcut_model_class_init, e_shortcut_model_init,
GTK_TYPE_OBJECT)
static void
e_shortcut_model_class_init (EShortcutModelClass *class)
{
GtkObjectClass *object_class;
parent_class = gtk_type_class (GTK_TYPE_OBJECT);
object_class = (GtkObjectClass *) class;
e_shortcut_model_signals[GROUP_ADDED] =
gtk_signal_new ("group_added",
GTK_RUN_FIRST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutModelClass,
group_added),
e_shortcut_model_marshal1,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT, GTK_TYPE_STRING);
e_shortcut_model_signals[GROUP_REMOVED] =
gtk_signal_new ("group_removed",
GTK_RUN_FIRST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutModelClass,
group_removed),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
e_shortcut_model_signals[ITEM_ADDED] =
gtk_signal_new ("item_added",
GTK_RUN_FIRST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutModelClass,
item_added),
e_shortcut_model_marshal2,
GTK_TYPE_NONE, 4,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_STRING, GTK_TYPE_STRING);
e_shortcut_model_signals[ITEM_REMOVED] =
gtk_signal_new ("item_removed",
GTK_RUN_FIRST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (EShortcutModelClass,
item_removed),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT, GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, e_shortcut_model_signals,
LAST_SIGNAL);
/* Method override */
object_class->destroy = e_shortcut_model_destroy;
class->group_added = e_shortcut_model_real_add_group;
class->group_removed = e_shortcut_model_real_remove_group;
class->item_added = e_shortcut_model_real_add_item;
class->item_removed = e_shortcut_model_real_remove_item;
class->get_num_groups = e_shortcut_model_real_get_num_groups;
class->get_num_items = e_shortcut_model_real_get_num_items;
class->get_group_name = e_shortcut_model_real_get_group_name;
class->get_item_info = e_shortcut_model_real_get_item_info;
}
static void
e_shortcut_model_init (EShortcutModel *shortcut_model)
{
shortcut_model->groups = g_array_new (FALSE, FALSE,
sizeof (EShortcutModelGroup));
}
EShortcutModel *
e_shortcut_model_new (void)
{
EShortcutModel *shortcut_model;
shortcut_model = E_SHORTCUT_MODEL (gtk_type_new (e_shortcut_model_get_type ()));
return shortcut_model;
}
static void
e_shortcut_model_destroy (GtkObject *object)
{
EShortcutModel *shortcut_model;
gint num_groups, group_num;
shortcut_model = E_SHORTCUT_MODEL (object);
num_groups = shortcut_model->groups->len;
for (group_num = 0; group_num < num_groups; group_num++)
e_shortcut_model_free_group (shortcut_model, group_num);
g_array_free (shortcut_model->groups, TRUE);
shortcut_model->groups = NULL;
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
e_shortcut_model_free_group (EShortcutModel *shortcut_model,
gint group_num)
{
EShortcutModelGroup *group;
EShortcutModelItem *item;
gint item_num;
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
g_free (group->name);
for (item_num = 0; item_num < group->items->len; item_num++) {
item = &g_array_index (group->items,
EShortcutModelItem, item_num);
g_free (item->name);
g_free (item->url);
}
}
gint
e_shortcut_model_add_group (EShortcutModel *shortcut_model,
gint position,
const gchar *group_name)
{
g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1);
g_return_val_if_fail (group_name != NULL, -1);
if (position == -1 || position > shortcut_model->groups->len)
position = shortcut_model->groups->len;
gtk_signal_emit (GTK_OBJECT (shortcut_model),
e_shortcut_model_signals[GROUP_ADDED],
position, group_name);
return position;
}
static void
e_shortcut_model_real_add_group (EShortcutModel *shortcut_model,
gint group_num,
const gchar *group_name)
{
EShortcutModelGroup *group, tmp_group;
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num <= shortcut_model->groups->len);
g_return_if_fail (group_name != NULL);
g_array_insert_val (shortcut_model->groups, group_num, tmp_group);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
group->name = g_strdup (group_name);
group->items = g_array_new (FALSE, FALSE,
sizeof (EShortcutModelItem));
}
void
e_shortcut_model_remove_group (EShortcutModel *shortcut_model,
gint group_num)
{
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_model->groups->len);
gtk_signal_emit (GTK_OBJECT (shortcut_model),
e_shortcut_model_signals[GROUP_REMOVED],
group_num);
}
static void
e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model,
gint group_num)
{
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_model->groups->len);
e_shortcut_model_free_group (shortcut_model, group_num);
g_array_remove_index (shortcut_model->groups, group_num);
}
gint
e_shortcut_model_add_item (EShortcutModel *shortcut_model,
gint group_num,
gint position,
const gchar *item_url,
const gchar *item_name)
{
EShortcutModelGroup *group;
g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1);
g_return_val_if_fail (group_num >= 0, -1);
g_return_val_if_fail (group_num < shortcut_model->groups->len, -1);
g_return_val_if_fail (item_url != NULL, -1);
g_return_val_if_fail (item_name != NULL, -1);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
if (position == -1 || position > group->items->len)
position = group->items->len;
gtk_signal_emit (GTK_OBJECT (shortcut_model),
e_shortcut_model_signals[ITEM_ADDED],
group_num, position, item_url, item_name);
return position;
}
static void
e_shortcut_model_real_add_item (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
const gchar *item_url,
const gchar *item_name)
{
EShortcutModelGroup *group;
EShortcutModelItem *item, tmp_item;
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_model->groups->len);
g_return_if_fail (item_url != NULL);
g_return_if_fail (item_name != NULL);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
g_return_if_fail (item_num >= 0);
g_return_if_fail (item_num <= group->items->len);
g_array_insert_val (group->items, item_num, tmp_item);
item = &g_array_index (group->items,
EShortcutModelItem, item_num);
item->name = g_strdup (item_name);
item->url = g_strdup (item_url);
}
void
e_shortcut_model_remove_item (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
gtk_signal_emit (GTK_OBJECT (shortcut_model),
e_shortcut_model_signals[ITEM_REMOVED],
group_num, item_num);
}
static void
e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
EShortcutModelGroup *group;
EShortcutModelItem *item;
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_model->groups->len);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
g_return_if_fail (item_num >= 0);
g_return_if_fail (item_num < group->items->len);
item = &g_array_index (group->items,
EShortcutModelItem, item_num);
g_free (item->name);
g_free (item->url);
g_array_remove_index (group->items, item_num);
}
static void
e_shortcut_model_marshal1 (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args)
{
void (*rfunc) (GtkObject*, gint, gpointer, gpointer);
rfunc = (void (*) (GtkObject*, gint, gpointer, gpointer)) func;
(*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_STRING (args[1]),
func_data);
}
static void
e_shortcut_model_marshal2 (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args)
{
void (*rfunc) (GtkObject*, gint, gint, gpointer, gpointer, gpointer);
rfunc = (void (*) (GtkObject*, gint, gint, gpointer, gpointer,
gpointer)) func;
(*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]),
GTK_VALUE_STRING (args[2]), GTK_VALUE_STRING (args[3]),
func_data);
}
gint
e_shortcut_model_get_num_groups (EShortcutModel *shortcut_model)
{
g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0);
return ESM_CLASS (shortcut_model)->get_num_groups (shortcut_model);
}
static gint
e_shortcut_model_real_get_num_groups (EShortcutModel *shortcut_model)
{
return shortcut_model->groups->len;
}
gint
e_shortcut_model_get_num_items (EShortcutModel *shortcut_model,
gint group_num)
{
g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0);
return ESM_CLASS (shortcut_model)->get_num_items (shortcut_model,
group_num);
}
static gint
e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model,
gint group_num)
{
EShortcutModelGroup *group;
g_return_val_if_fail (group_num >= 0, 0);
g_return_val_if_fail (group_num < shortcut_model->groups->len, 0);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
return group->items->len;
}
gchar*
e_shortcut_model_get_group_name (EShortcutModel *shortcut_model,
gint group_num)
{
g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), NULL);
return ESM_CLASS (shortcut_model)->get_group_name (shortcut_model,
group_num);
}
static gchar*
e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model,
gint group_num)
{
EShortcutModelGroup *group;
g_return_val_if_fail (group_num >= 0, NULL);
g_return_val_if_fail (group_num < shortcut_model->groups->len, NULL);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
return g_strdup (group->name);
}
void
e_shortcut_model_get_item_info (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
gchar **item_url,
gchar **item_name)
{
g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model));
ESM_CLASS (shortcut_model)->get_item_info (shortcut_model,
group_num, item_num,
item_url, item_name);
}
static void
e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
gchar **item_url,
gchar **item_name)
{
EShortcutModelGroup *group;
EShortcutModelItem *item;
g_return_if_fail (group_num >= 0);
g_return_if_fail (group_num < shortcut_model->groups->len);
group = &g_array_index (shortcut_model->groups,
EShortcutModelGroup, group_num);
g_return_if_fail (item_num >= 0);
g_return_if_fail (item_num < group->items->len);
item = &g_array_index (group->items,
EShortcutModelItem, item_num);
if (item_url)
*item_url = g_strdup (item->url);
if (item_name)
*item_name = g_strdup (item->name);
}

View File

@ -1,139 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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 _E_SHORTCUT_MODEL_H_
#define _E_SHORTCUT_MODEL_H_
#include <gtk/gtkobject.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* EShortcutModel keeps track of a number of groups of shortcuts.
* Each shortcut has a URL and a short textual name.
* It is used as the model of the EShortcutBar.
*/
typedef struct _EShortcutModel EShortcutModel;
typedef struct _EShortcutModelClass EShortcutModelClass;
#define E_TYPE_SHORTCUT_MODEL (e_shortcut_model_get_type ())
#define E_SHORTCUT_MODEL(obj) GTK_CHECK_CAST (obj, e_shortcut_model_get_type (), EShortcutModel)
#define E_SHORTCUT_MODEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_model_get_type (), EShortcutModelClass)
#define E_IS_SHORTCUT_MODEL(obj) GTK_CHECK_TYPE (obj, e_shortcut_model_get_type ())
struct _EShortcutModel
{
GtkObject object;
/* This is a private array of EShortcutModelGroup elements. */
GArray *groups;
};
struct _EShortcutModelClass
{
GtkObjectClass parent_class;
/*
* Signals - These act like virtual functions as well as notification
* signals. The class function is run first and does the actual action.
*/
void (*group_added) (EShortcutModel *shortcut_model,
gint group_num,
const gchar *group_name);
void (*group_removed) (EShortcutModel *shortcut_model,
gint group_num);
void (*item_added) (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
const gchar *item_url,
const gchar *item_name);
void (*item_removed) (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
/*
* Virtual methods.
*/
gint (*get_num_groups) (EShortcutModel *shortcut_model);
gint (*get_num_items) (EShortcutModel *shortcut_model,
gint group_num);
/* This returns a copy of the group name. */
gchar* (*get_group_name) (EShortcutModel *shortcut_model,
gint group_num);
/* This returns a copy of the item url and name. */
void (*get_item_info) (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
gchar **item_url,
gchar **item_name);
};
GtkType e_shortcut_model_get_type (void);
EShortcutModel* e_shortcut_model_new (void);
/* Adds a new group at the given position, or last if position is -1.
It returns the index of the new group. */
gint e_shortcut_model_add_group (EShortcutModel *shortcut_model,
gint position,
const gchar *group_name);
void e_shortcut_model_remove_group (EShortcutModel *shortcut_model,
gint group_num);
/* Adds a new item to a group at the given position, or last if position is -1.
It returns the index of the new item within the group. */
gint e_shortcut_model_add_item (EShortcutModel *shortcut_model,
gint group_num,
gint position,
const gchar *item_url,
const gchar *item_name);
void e_shortcut_model_remove_item (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
gint e_shortcut_model_get_num_groups(EShortcutModel *shortcut_model);
gint e_shortcut_model_get_num_items (EShortcutModel *shortcut_model,
gint group_num);
/* The group_name should be freed after use. */
gchar* e_shortcut_model_get_group_name(EShortcutModel *shortcut_model,
gint group_num);
/* The item_url and item_name should be freed after use. */
void e_shortcut_model_get_item_info (EShortcutModel *shortcut_model,
gint group_num,
gint item_num,
gchar **item_url,
gchar **item_name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_SHORTCUT_MODEL_H_ */

View File

@ -1,708 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget
* vertically. It is intended for scrolling narrow vertical bars.
*/
#include <config.h>
#include <gtk/gtkarrow.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtksignal.h>
#include "e-vscrolled-bar.h"
/* These are the offsets of the up & down buttons from the right and top/bottom
of the widget. */
#define E_VSCROLLED_BAR_BUTTON_X_OFFSET 2
#define E_VSCROLLED_BAR_BUTTON_Y_OFFSET 2
/* This is the time between scrolls. */
#define E_VSCROLLED_BAR_SCROLL_TIMEOUT 20
static void e_vscrolled_bar_class_init (EVScrolledBarClass *class);
static void e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar);
static void e_vscrolled_bar_destroy (GtkObject *object);
static void e_vscrolled_bar_finalize (GtkObject *object);
static void e_vscrolled_bar_map (GtkWidget *widget);
static void e_vscrolled_bar_unmap (GtkWidget *widget);
static void e_vscrolled_bar_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void e_vscrolled_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void e_vscrolled_bar_draw (GtkWidget *widget,
GdkRectangle *area);
static gint e_vscrolled_bar_button_press (GtkWidget *widget,
GdkEventButton *event);
static void e_vscrolled_bar_add (GtkContainer *container,
GtkWidget *child);
static void e_vscrolled_bar_remove (GtkContainer *container,
GtkWidget *child);
static void e_vscrolled_bar_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static void e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment,
gpointer data);
static void e_vscrolled_bar_button_pressed (GtkWidget *button,
EVScrolledBar *vscrolled_bar);
static void e_vscrolled_bar_button_released (GtkWidget *button,
EVScrolledBar *vscrolled_bar);
static void e_vscrolled_bar_button_clicked (GtkWidget *button,
EVScrolledBar *vscrolled_bar);
static gboolean e_vscrolled_bar_timeout_handler (gpointer data);
static GtkBinClass *parent_class;
GtkType
e_vscrolled_bar_get_type (void)
{
static GtkType e_vscrolled_bar_type = 0;
if (!e_vscrolled_bar_type) {
GtkTypeInfo e_vscrolled_bar_info = {
"EVScrolledBar",
sizeof (EVScrolledBar),
sizeof (EVScrolledBarClass),
(GtkClassInitFunc) e_vscrolled_bar_class_init,
(GtkObjectInitFunc) e_vscrolled_bar_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
parent_class = gtk_type_class (GTK_TYPE_BIN);
e_vscrolled_bar_type = gtk_type_unique (GTK_TYPE_BIN,
&e_vscrolled_bar_info);
}
return e_vscrolled_bar_type;
}
static void
e_vscrolled_bar_class_init (EVScrolledBarClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
container_class = (GtkContainerClass *) class;
/* Method override */
object_class->destroy = e_vscrolled_bar_destroy;
object_class->finalize = e_vscrolled_bar_finalize;
widget_class->map = e_vscrolled_bar_map;
widget_class->unmap = e_vscrolled_bar_unmap;
widget_class->size_request = e_vscrolled_bar_size_request;
widget_class->size_allocate = e_vscrolled_bar_size_allocate;
widget_class->draw = e_vscrolled_bar_draw;
widget_class->button_press_event = e_vscrolled_bar_button_press;
container_class->add = e_vscrolled_bar_add;
container_class->remove = e_vscrolled_bar_remove;
container_class->forall = e_vscrolled_bar_forall;
}
static void
e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar)
{
GtkWidget *arrow;
GTK_WIDGET_SET_FLAGS (vscrolled_bar, GTK_NO_WINDOW);
gtk_container_set_resize_mode (GTK_CONTAINER (vscrolled_bar),
GTK_RESIZE_QUEUE);
gtk_widget_push_composite_child ();
vscrolled_bar->up_button = gtk_button_new ();
gtk_widget_set_composite_name (vscrolled_bar->up_button,
"up_button");
gtk_widget_set_parent (vscrolled_bar->up_button,
GTK_WIDGET (vscrolled_bar));
arrow = gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_OUT);
gtk_misc_set_padding (GTK_MISC (arrow), 1, 1);
gtk_widget_show (arrow);
gtk_container_add (GTK_CONTAINER (vscrolled_bar->up_button), arrow);
gtk_widget_show (vscrolled_bar->up_button);
gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar);
gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar);
gtk_signal_connect (GTK_OBJECT (vscrolled_bar->up_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar);
vscrolled_bar->down_button = gtk_button_new ();
gtk_widget_set_composite_name (vscrolled_bar->up_button,
"down_button");
gtk_widget_set_parent (vscrolled_bar->down_button,
GTK_WIDGET (vscrolled_bar));
arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
gtk_misc_set_padding (GTK_MISC (arrow), 1, 1);
gtk_widget_show (arrow);
gtk_container_add (GTK_CONTAINER (vscrolled_bar->down_button), arrow);
gtk_widget_show (vscrolled_bar->down_button);
gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar);
gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar);
gtk_signal_connect (GTK_OBJECT (vscrolled_bar->down_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar);
gtk_widget_pop_composite_child ();
vscrolled_bar->adjustment = NULL;
vscrolled_bar->timeout_id = 0;
vscrolled_bar->scrolling_up = FALSE;
vscrolled_bar->min_distance = -1.0;
vscrolled_bar->button_pressed = FALSE;
}
/**
* e_vscrolled_bar_new:
*
* @adjustment: The #GtkAdjustment to use for scrolling, or NULL.
* @Return: A new #EVScrolledBar.
*
* Creates a new #EVScrolledBar with the given adjustment.
**/
GtkWidget *
e_vscrolled_bar_new (GtkAdjustment *adjustment)
{
GtkWidget *vscrolled_bar;
vscrolled_bar = GTK_WIDGET (gtk_type_new (e_vscrolled_bar_get_type ()));
e_vscrolled_bar_set_adjustment (E_VSCROLLED_BAR (vscrolled_bar),
adjustment);
return vscrolled_bar;
}
static void
e_vscrolled_bar_destroy (GtkObject *object)
{
EVScrolledBar *vscrolled_bar;
vscrolled_bar = E_VSCROLLED_BAR (object);
if (vscrolled_bar->timeout_id) {
g_source_remove (vscrolled_bar->timeout_id);
vscrolled_bar->timeout_id = 0;
}
gtk_widget_unparent (vscrolled_bar->up_button);
gtk_widget_unparent (vscrolled_bar->down_button);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
e_vscrolled_bar_finalize (GtkObject *object)
{
EVScrolledBar *vscrolled_bar;
vscrolled_bar = E_VSCROLLED_BAR (object);
gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment));
GTK_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
e_vscrolled_bar_map (GtkWidget *widget)
{
EVScrolledBar *vscrolled_bar;
GtkAdjustment *adjustment;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (widget));
vscrolled_bar = E_VSCROLLED_BAR (widget);
/* chain parent class handler to map self and child */
GTK_WIDGET_CLASS (parent_class)->map (widget);
adjustment = vscrolled_bar->adjustment;
if (GTK_WIDGET_VISIBLE (vscrolled_bar->up_button)
&& adjustment->value != adjustment->lower
&& !GTK_WIDGET_MAPPED (vscrolled_bar->up_button))
gtk_widget_map (vscrolled_bar->up_button);
if (GTK_WIDGET_VISIBLE (vscrolled_bar->down_button)
&& adjustment->value < adjustment->upper - adjustment->page_size
&& !GTK_WIDGET_MAPPED (vscrolled_bar->down_button))
gtk_widget_map (vscrolled_bar->down_button);
}
static void
e_vscrolled_bar_unmap (GtkWidget *widget)
{
EVScrolledBar *vscrolled_bar;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (widget));
vscrolled_bar = E_VSCROLLED_BAR (widget);
/* chain parent class handler to unmap self and child */
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
if (GTK_WIDGET_MAPPED (vscrolled_bar->up_button))
gtk_widget_unmap (vscrolled_bar->up_button);
if (GTK_WIDGET_MAPPED (vscrolled_bar->down_button))
gtk_widget_unmap (vscrolled_bar->down_button);
}
static void
e_vscrolled_bar_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
EVScrolledBar *vscrolled_bar;
GtkBin *bin;
GtkRequisition child_requisition;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (widget));
g_return_if_fail (requisition != NULL);
vscrolled_bar = E_VSCROLLED_BAR (widget);
bin = GTK_BIN (widget);
requisition->width = 0;
requisition->height = 0;
/* We just return the requisition of the child widget, plus the
border width. */
if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) {
gtk_widget_size_request (bin->child, &child_requisition);
*requisition = child_requisition;
}
/* We remember the requested heights of the up & down buttons. */
gtk_widget_size_request (vscrolled_bar->up_button,
&child_requisition);
vscrolled_bar->up_button_width = child_requisition.width;
vscrolled_bar->up_button_height = child_requisition.height;
gtk_widget_size_request (vscrolled_bar->down_button,
&child_requisition);
vscrolled_bar->down_button_width = child_requisition.width;
vscrolled_bar->down_button_height = child_requisition.height;
/* Add on the standard container border widths. */
requisition->width += GTK_CONTAINER (widget)->border_width * 2;
requisition->height += GTK_CONTAINER (widget)->border_width * 2;
}
static void
e_vscrolled_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
EVScrolledBar *vscrolled_bar;
GtkBin *bin;
GtkAllocation button_allocation, child_allocation;
gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (widget));
g_return_if_fail (allocation != NULL);
vscrolled_bar = E_VSCROLLED_BAR (widget);
bin = GTK_BIN (widget);
widget->allocation = *allocation;
border_width = GTK_CONTAINER (widget)->border_width;
child_allocation.x = border_width;
child_allocation.y = border_width;
child_allocation.width = allocation->width - 2 * border_width;
child_allocation.height = allocation->height - 2 * border_width;
gtk_widget_size_allocate (bin->child, &child_allocation);
button_allocation.x = allocation->width - border_width
- vscrolled_bar->up_button_width
- E_VSCROLLED_BAR_BUTTON_X_OFFSET;
button_allocation.y = border_width + E_VSCROLLED_BAR_BUTTON_Y_OFFSET;
button_allocation.width = vscrolled_bar->up_button_width;
button_allocation.height = vscrolled_bar->up_button_height;
gtk_widget_size_allocate (vscrolled_bar->up_button,
&button_allocation);
button_allocation.x = allocation->width - border_width
- vscrolled_bar->down_button_width
- E_VSCROLLED_BAR_BUTTON_X_OFFSET;
button_allocation.y = allocation->height - border_width
- vscrolled_bar->down_button_height
- E_VSCROLLED_BAR_BUTTON_Y_OFFSET;
button_allocation.width = vscrolled_bar->down_button_width;
button_allocation.height = vscrolled_bar->down_button_height;
gtk_widget_size_allocate (vscrolled_bar->down_button,
&button_allocation);
}
static void
e_vscrolled_bar_draw (GtkWidget *widget,
GdkRectangle *area)
{
EVScrolledBar *vscrolled_bar;
GtkBin *bin;
GdkRectangle child_area;
g_return_if_fail (widget != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (widget));
g_return_if_fail (area != NULL);
vscrolled_bar = E_VSCROLLED_BAR (widget);
bin = GTK_BIN (widget);
if (bin->child && GTK_WIDGET_VISIBLE (bin->child) &&
gtk_widget_intersect (bin->child, area, &child_area))
gtk_widget_draw (bin->child, &child_area);
if (GTK_WIDGET_DRAWABLE (vscrolled_bar->up_button) &&
gtk_widget_intersect (vscrolled_bar->up_button, area, &child_area))
gtk_widget_draw (vscrolled_bar->up_button, &child_area);
if (GTK_WIDGET_DRAWABLE (vscrolled_bar->down_button) &&
gtk_widget_intersect (vscrolled_bar->down_button, area, &child_area))
gtk_widget_draw (vscrolled_bar->down_button, &child_area);
}
static gint
e_vscrolled_bar_button_press (GtkWidget *widget,
GdkEventButton *event)
{
EVScrolledBar *vscrolled_bar;
GtkAdjustment *adjustment;
gfloat new_value, step;
vscrolled_bar = E_VSCROLLED_BAR (widget);
adjustment = vscrolled_bar->adjustment;
step = adjustment->page_size;
if (event->button == 4) {
new_value = adjustment->value - step;
if (new_value <= adjustment->lower) {
new_value = adjustment->lower;
}
} else if (event->button == 5) {
new_value = adjustment->value + step;
if (new_value >= adjustment->upper - adjustment->page_size) {
new_value = adjustment->upper - adjustment->page_size;
}
} else
return FALSE;
if (adjustment->value != new_value) {
adjustment->value = new_value;
gtk_signal_emit_by_name (GTK_OBJECT (adjustment),
"value_changed");
return TRUE;
}
return FALSE;
}
static void
e_vscrolled_bar_add (GtkContainer *container,
GtkWidget *child)
{
EVScrolledBar *vscrolled_bar;
GtkBin *bin;
g_return_if_fail (container != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (container));
vscrolled_bar = E_VSCROLLED_BAR (container);
bin = GTK_BIN (container);
g_return_if_fail (bin->child == NULL);
bin->child = child;
gtk_widget_set_parent (child, GTK_WIDGET (bin));
gtk_widget_set_scroll_adjustments (child, NULL,
vscrolled_bar->adjustment);
if (GTK_WIDGET_REALIZED (child->parent))
gtk_widget_realize (child);
if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) {
if (GTK_WIDGET_MAPPED (child->parent))
gtk_widget_map (child);
gtk_widget_queue_resize (child);
}
}
static void
e_vscrolled_bar_remove (GtkContainer *container,
GtkWidget *child)
{
g_return_if_fail (container != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (container));
g_return_if_fail (child != NULL);
g_return_if_fail (GTK_BIN (container)->child == child);
gtk_widget_set_scroll_adjustments (child, NULL, NULL);
/* chain parent class handler to remove child */
GTK_CONTAINER_CLASS (parent_class)->remove (container, child);
}
static void
e_vscrolled_bar_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
g_return_if_fail (container != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (container));
g_return_if_fail (callback != NULL);
GTK_CONTAINER_CLASS (parent_class)->forall (container,
include_internals,
callback,
callback_data);
if (include_internals) {
EVScrolledBar *vscrolled_bar;
vscrolled_bar = E_VSCROLLED_BAR (container);
if (vscrolled_bar->up_button)
callback (vscrolled_bar->up_button, callback_data);
if (vscrolled_bar->down_button)
callback (vscrolled_bar->down_button, callback_data);
}
}
/**
* e_vscrolled_bar_get_adjustment:
*
* @vscrolled_bar: An #EVScrolledBar.
* @Return: The #GtkAdjustment used for scrolling @vscrolled_bar.
*
* Returns the #GtkAdjustment used for scrolling the #EVscrolledBar.
**/
GtkAdjustment*
e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar)
{
g_return_val_if_fail (vscrolled_bar != NULL, NULL);
g_return_val_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar), NULL);
return vscrolled_bar->adjustment;
}
/**
* e_vscrolled_bar_set_adjustment:
*
* @vscrolled_bar: An #EVScrolledBar.
* @adjustment: The #GtkAdjustment to use for scrolling @vscrolled_bar.
*
* Sets the #GtkAdjustment to use for scrolling the #EVscrolledBar.
**/
void
e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar,
GtkAdjustment *adjustment)
{
g_return_if_fail (vscrolled_bar != NULL);
g_return_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar));
if (adjustment)
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
else
adjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL);
if (vscrolled_bar->adjustment == adjustment)
return;
if (vscrolled_bar->adjustment) {
gtk_signal_disconnect_by_func (GTK_OBJECT (vscrolled_bar->adjustment),
GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed),
vscrolled_bar);
gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment));
}
vscrolled_bar->adjustment = adjustment;
gtk_object_ref (GTK_OBJECT (vscrolled_bar->adjustment));
gtk_object_sink (GTK_OBJECT (vscrolled_bar->adjustment));
/* I've used connect_after here to avoid a problem when using a
GnomeCanvas as the child widget. When just using connect it would
leave a blank space when one of the buttons is hidden. We want
the GtkLayout to handle the scrolling before we hide any buttons. */
gtk_signal_connect_after (GTK_OBJECT (adjustment), "changed",
GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed),
vscrolled_bar);
gtk_signal_connect_after (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed),
vscrolled_bar);
e_vscrolled_bar_adjustment_changed (adjustment, vscrolled_bar);
if (GTK_BIN (vscrolled_bar)->child)
gtk_widget_set_scroll_adjustments (GTK_BIN (vscrolled_bar)->child, NULL, adjustment);
}
static void
e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment,
gpointer data)
{
EVScrolledBar *vscrolled_bar;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (data != NULL);
#if 0
g_print ("Adjustment changed to: %g\n", adjustment->value);
#endif
vscrolled_bar = E_VSCROLLED_BAR (data);
if (!GTK_WIDGET_MAPPED (vscrolled_bar))
return;
/* If the adjustment value is not 0, show the up button. */
if (adjustment->value != adjustment->lower) {
gtk_widget_map (vscrolled_bar->up_button);
gdk_window_raise (vscrolled_bar->up_button->window);
} else {
gtk_widget_unmap (vscrolled_bar->up_button);
}
/* If the adjustment value is less than the maximum value, show the
down button. */
if (adjustment->value < adjustment->upper - adjustment->page_size) {
gtk_widget_map (vscrolled_bar->down_button);
gdk_window_raise (vscrolled_bar->down_button->window);
} else {
gtk_widget_unmap (vscrolled_bar->down_button);
}
}
static void
e_vscrolled_bar_button_pressed (GtkWidget *button,
EVScrolledBar *vscrolled_bar)
{
if (vscrolled_bar->timeout_id != 0)
g_source_remove (vscrolled_bar->timeout_id);
vscrolled_bar->timeout_id = g_timeout_add (E_VSCROLLED_BAR_SCROLL_TIMEOUT, e_vscrolled_bar_timeout_handler, vscrolled_bar);
vscrolled_bar->scrolling_up = (button == vscrolled_bar->up_button) ? TRUE : FALSE;
vscrolled_bar->min_distance = vscrolled_bar->adjustment->page_size / 4;
vscrolled_bar->button_pressed = TRUE;
e_vscrolled_bar_timeout_handler (vscrolled_bar);
}
static void
e_vscrolled_bar_button_released (GtkWidget *button,
EVScrolledBar *vscrolled_bar)
{
vscrolled_bar->button_pressed = FALSE;
}
/* This will be called when the user hits the space key to activate the button.
It will also be called just before button_released() is called, but since
we already handle that we simply return if the button is pressed. */
static void
e_vscrolled_bar_button_clicked (GtkWidget *button,
EVScrolledBar *vscrolled_bar)
{
if (vscrolled_bar->button_pressed)
return;
/* We act as if the button is pressed and released immediately. */
e_vscrolled_bar_button_pressed (button, vscrolled_bar);
vscrolled_bar->button_pressed = FALSE;
}
static gboolean
e_vscrolled_bar_timeout_handler (gpointer data)
{
EVScrolledBar *vscrolled_bar;
GtkAdjustment *adjustment;
gfloat new_value;
gboolean retval = TRUE;
vscrolled_bar = E_VSCROLLED_BAR (data);
adjustment = vscrolled_bar->adjustment;
GDK_THREADS_ENTER ();
/* Check if the user has released the button and we have already
scrolled the minimum distance. */
if (vscrolled_bar->button_pressed == FALSE
&& vscrolled_bar->min_distance <= 0) {
GDK_THREADS_LEAVE ();
return FALSE;
}
vscrolled_bar->min_distance -= adjustment->step_increment;
if (vscrolled_bar->scrolling_up) {
new_value = adjustment->value - adjustment->step_increment;
if (new_value <= adjustment->lower) {
new_value = adjustment->lower;
retval = FALSE;
}
} else {
new_value = adjustment->value + adjustment->step_increment;
if (new_value >= adjustment->upper - adjustment->page_size) {
new_value = adjustment->upper - adjustment->page_size;
retval = FALSE;
}
}
if (adjustment->value != new_value) {
adjustment->value = new_value;
gtk_signal_emit_by_name (GTK_OBJECT (adjustment),
"value_changed");
}
GDK_THREADS_LEAVE ();
return retval;
}

View File

@ -1,97 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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 _E_VSCROLLED_BAR_H_
#define _E_VSCROLLED_BAR_H_
#include <gtk/gtkbin.h>
#include <gtk/gtkadjustment.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget
* vertically. It is intended for scrolling narrow vertical bars.
*/
#define E_VSCROLLED_BAR(obj) GTK_CHECK_CAST (obj, e_vscrolled_bar_get_type (), EVScrolledBar)
#define E_VSCROLLED_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_vscrolled_bar_get_type (), EVScrolledBarClass)
#define E_IS_VSCROLLED_BAR(obj) GTK_CHECK_TYPE (obj, e_vscrolled_bar_get_type ())
typedef struct _EVScrolledBar EVScrolledBar;
typedef struct _EVScrolledBarClass EVScrolledBarClass;
struct _EVScrolledBar
{
GtkBin bin;
GtkWidget *up_button;
GtkWidget *down_button;
GtkAdjustment *adjustment;
gint up_button_width;
gint up_button_height;
gint down_button_width;
gint down_button_height;
/* The GTK+ event source ID of our timeout handler. */
gint timeout_id;
/* TRUE if we are scrolling up, FALSE if scrolling down. */
gboolean scrolling_up;
/* The minimum distance left to scroll. If the user just clicks a
button we scroll a minimum amount. This is reduced after each
scroll. */
gfloat min_distance;
/* TRUE if the button is still pressed. When the up/down button is
released, this gets set to FALSE, and we scroll until the minimum
distance falls below 0. */
gboolean button_pressed;
};
struct _EVScrolledBarClass
{
GtkBinClass parent_class;
};
GtkType e_vscrolled_bar_get_type (void);
GtkWidget* e_vscrolled_bar_new (GtkAdjustment *adjustment);
GtkAdjustment* e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar);
void e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar,
GtkAdjustment *adjustment);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_VSCROLLED_BAR_H_ */

View File

@ -1,658 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Author :
* Damon Chaplin <damon@helixcode.com>
*
* Copyright 1999, Helix Code, Inc.
*
* 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 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
*/
/*
* This tests the ShortcutBar widget.
*/
#include <gnome.h>
#include "e-shortcut-bar.h"
#include <gal/e-paned/e-hpaned.h>
#define NUM_SHORTCUT_TYPES 5
gchar *shortcut_types[NUM_SHORTCUT_TYPES] = {
"folder:", "file:", "calendar:", "todo:", "contacts:"
};
gchar *icon_filenames[NUM_SHORTCUT_TYPES] = {
"gnome-balsa2.png", "gnome-folder.png", "gnome-calendar.png",
"gnome-cromagnon.png", "gnome-ccthemes.png"
};
GdkPixbuf *icon_pixbufs[NUM_SHORTCUT_TYPES];
GtkWidget *main_label;
static GdkPixbuf *icon_callback (EShortcutBar *shortcut_bar,
const gchar *url,
gpointer data);
static void on_main_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data);
static void quit (GtkWidget *window, GdkEvent *event, gpointer data);
static void add_test_groups (EShortcutBar *shortcut_bar);
static void add_test_group (EShortcutBar *shortcut_bar, gint i,
gchar *group_name);
static gint get_random_int (gint max);
static void on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num,
gint item_num);
static void show_standard_popup (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num);
static void show_context_popup (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num,
gint item_num);
static void set_large_icons (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void set_small_icons (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void add_group (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void remove_group (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void rename_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void remove_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar);
static void on_set_group_button_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar);
static void on_set_group_button_no_animation_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar);
static void on_item_added (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
static void on_item_removed (EShortcutModel *shortcut_model,
gint group_num,
gint item_num);
static void on_group_added (EShortcutModel *shortcut_model,
gint group_num);
static void on_group_removed (EShortcutModel *shortcut_model,
gint group_num);
static void on_shortcut_dragged (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
static void on_shortcut_dropped (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num,
gchar *url,
gchar *name);
int
main (int argc, char *argv[])
{
GtkWidget *window, *hpaned, *shortcut_bar, *vbox, *button;
EShortcutModel *shortcut_model;
gchar *pathname;
gint i;
gnome_init ("test-shortcut-bar", "0.1", argc, argv);
gtk_widget_push_visual (gdk_rgb_get_visual ());
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
window = gnome_app_new ("TestShortcutBar", "TestShortCutBar");
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
gtk_signal_connect (GTK_OBJECT (window), "delete-event",
GTK_SIGNAL_FUNC (quit), NULL);
hpaned = e_hpaned_new ();
gnome_app_set_contents (GNOME_APP (window), hpaned);
gtk_widget_show (hpaned);
shortcut_model = e_shortcut_model_new ();
shortcut_bar = e_shortcut_bar_new ();
e_shortcut_bar_set_model (E_SHORTCUT_BAR (shortcut_bar),
shortcut_model);
e_paned_pack1 (E_PANED (hpaned), shortcut_bar, FALSE, TRUE);
gtk_widget_show (shortcut_bar);
e_shortcut_bar_set_icon_callback (E_SHORTCUT_BAR (shortcut_bar),
icon_callback,
NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_added",
GTK_SIGNAL_FUNC (on_item_added), NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_removed",
GTK_SIGNAL_FUNC (on_item_removed), NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_added",
GTK_SIGNAL_FUNC (on_group_added), NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_removed",
GTK_SIGNAL_FUNC (on_group_removed), NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_bar), "shortcut_dragged",
GTK_SIGNAL_FUNC (on_shortcut_dragged), NULL);
gtk_signal_connect (GTK_OBJECT (shortcut_bar), "shortcut_dropped",
GTK_SIGNAL_FUNC (on_shortcut_dropped), NULL);
#if 0
gtk_container_set_border_width (GTK_CONTAINER (shortcut_bar), 4);
#endif
e_paned_set_position (E_PANED (hpaned), 100);
/*e_paned_set_gutter_size (E_PANED (hpaned), 12);*/
vbox = gtk_vbox_new (FALSE, 0);
e_paned_pack2 (E_PANED (hpaned), vbox, TRUE, TRUE);
gtk_widget_show (vbox);
main_label = gtk_label_new ("Main Application Window Goes Here");
gtk_box_pack_start (GTK_BOX (vbox), main_label, TRUE, TRUE, 0);
gtk_widget_show (main_label);
gtk_signal_connect (GTK_OBJECT (main_label), "size_allocate",
GTK_SIGNAL_FUNC (on_main_label_size_allocate),
NULL);
button = gtk_button_new_with_label ("Set current group to 3rd");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (on_set_group_button_clicked),
shortcut_bar);
button = gtk_button_new_with_label ("Set current group to 5th (no animation)");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (on_set_group_button_no_animation_clicked),
shortcut_bar);
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
/* Load our default icons. */
for (i = 0; i < NUM_SHORTCUT_TYPES; i++) {
pathname = gnome_pixmap_file (icon_filenames[i]);
if (pathname)
icon_pixbufs[i] = gdk_pixbuf_new_from_file (pathname);
else
icon_pixbufs[i] = NULL;
}
add_test_groups (E_SHORTCUT_BAR (shortcut_bar));
gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_selected",
GTK_SIGNAL_FUNC (on_shortcut_bar_item_selected),
NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
static GdkPixbuf*
icon_callback (EShortcutBar *shortcut_bar,
const gchar *url,
gpointer data)
{
gint i;
for (i = 0; i < NUM_SHORTCUT_TYPES; i++) {
if (!strncmp (url, shortcut_types[i],
strlen (shortcut_types[i]))) {
gdk_pixbuf_ref (icon_pixbufs[i]);
return icon_pixbufs[i];
}
}
return NULL;
}
static void
on_main_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data)
{
g_print ("In on_main_label_size_allocate\n");
}
static void
quit (GtkWidget *window, GdkEvent *event, gpointer data)
{
gtk_widget_destroy (window);
gtk_exit (0);
}
static void
add_test_groups (EShortcutBar *shortcut_bar)
{
add_test_group (shortcut_bar, 1, "Shortcuts");
add_test_group (shortcut_bar, 2, "My Shortcuts");
add_test_group (shortcut_bar, 3, "Longer Shortcuts");
add_test_group (shortcut_bar, 4, "Very Long Shortcuts");
add_test_group (shortcut_bar, 5, "Incredibly Long Shortcuts");
}
static void
add_test_group (EShortcutBar *shortcut_bar, gint i, gchar *group_name)
{
gint group_num, item_num, num_items;
gchar buffer[128];
gint shortcut_type, j;
group_num = e_shortcut_model_add_group (shortcut_bar->model, -1,
group_name);
if (group_num % 2)
e_shortcut_bar_set_view_type (shortcut_bar, group_num,
E_ICON_BAR_SMALL_ICONS);
num_items = get_random_int (5) + 3;
for (j = 1; j <= num_items; j++) {
if (j == 1)
sprintf (buffer, "A very long shortcut with proper words so I can test the wrapping and ellipsis behaviour");
else if (j == 2)
sprintf (buffer, "A very long shortcut with averylongworkinthemiddlesoIcantestthewrappingandellipsisbehaviour");
else
sprintf (buffer, "Item %i:%i\n", i, j);
shortcut_type = get_random_int (NUM_SHORTCUT_TYPES);
item_num = e_shortcut_model_add_item (shortcut_bar->model,
group_num, -1,
shortcut_types[shortcut_type],
buffer);
}
}
/* Returns a random integer between 0 and max - 1. */
static gint
get_random_int (gint max)
{
gint random_num;
random_num = (int) (max * (rand () / (RAND_MAX + 1.0)));
#if 0
g_print ("Random num (%i): %i\n", max, random_num);
#endif
return random_num;
}
static void
on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar,
GdkEvent *event, gint group_num, gint item_num)
{
gchar buffer[256];
if (event->button.button == 1) {
sprintf (buffer, "Item Selected - %i:%i",
group_num + 1, item_num + 1);
gtk_label_set_text (GTK_LABEL (main_label), buffer);
} else if (event->button.button == 3) {
if (item_num == -1)
show_standard_popup (shortcut_bar, event, group_num);
else
show_context_popup (shortcut_bar, event, group_num,
item_num);
}
}
static void
show_standard_popup (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num)
{
GtkWidget *menu, *menuitem;
/* We don't have any commands if there aren't any groups yet. */
if (group_num == -1)
return;
menu = gtk_menu_new ();
menuitem = gtk_menu_item_new_with_label ("Large Icons");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_large_icons), shortcut_bar);
menuitem = gtk_menu_item_new_with_label ("Small Icons");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_small_icons), shortcut_bar);
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Add New Group");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (add_group), shortcut_bar);
menuitem = gtk_menu_item_new_with_label ("Remove Group");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (remove_group), shortcut_bar);
menuitem = gtk_menu_item_new_with_label ("Rename Group");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Add Shortcut...");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Hide Shortcut Bar");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
/* Save the group num so we can get it in the callbacks. */
gtk_object_set_data (GTK_OBJECT (menu), "group_num",
GINT_TO_POINTER (group_num));
/* FIXME: Destroy menu when finished with it somehow? */
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button.button, event->button.time);
}
static void
set_large_icons (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
GtkWidget *menu;
gint group_num;
menu = menuitem->parent;
g_return_if_fail (GTK_IS_MENU (menu));
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
e_shortcut_bar_set_view_type (shortcut_bar, group_num,
E_ICON_BAR_LARGE_ICONS);
}
static void
set_small_icons (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
GtkWidget *menu;
gint group_num;
menu = menuitem->parent;
g_return_if_fail (GTK_IS_MENU (menu));
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
e_shortcut_bar_set_view_type (shortcut_bar, group_num,
E_ICON_BAR_SMALL_ICONS);
}
static void
add_group (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
e_shortcut_model_add_group (shortcut_bar->model, 3, "New Group");
}
static void
remove_group (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
GtkWidget *menu;
gint group_num;
menu = menuitem->parent;
g_return_if_fail (GTK_IS_MENU (menu));
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
e_shortcut_model_remove_group (shortcut_bar->model, group_num);
}
static void
show_context_popup (EShortcutBar *shortcut_bar,
GdkEvent *event,
gint group_num,
gint item_num)
{
GtkWidget *menu, *menuitem, *label, *pixmap;
menu = gtk_menu_new ();
menuitem = gtk_pixmap_menu_item_new ();
label = gtk_label_new ("Open Folder");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (menuitem), label);
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
pixmap = gnome_stock_pixmap_widget (menu, GNOME_STOCK_MENU_OPEN);
if (pixmap) {
gtk_widget_show(pixmap);
gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menuitem), pixmap);
}
menuitem = gtk_menu_item_new_with_label ("Open in New Window");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Advanced Find");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Remove from Shortcut Bar");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (remove_item), shortcut_bar);
menuitem = gtk_menu_item_new_with_label ("Rename Shortcut");
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (rename_item), shortcut_bar);
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("Properties");
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
/* Save the group & item nums so we can get them in the callbacks. */
gtk_object_set_data (GTK_OBJECT (menu), "group_num",
GINT_TO_POINTER (group_num));
gtk_object_set_data (GTK_OBJECT (menu), "item_num",
GINT_TO_POINTER (item_num));
/* FIXME: Destroy menu when finished with it somehow? */
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button.button, event->button.time);
}
static void
rename_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
GtkWidget *menu;
gint group_num, item_num;
menu = menuitem->parent;
g_return_if_fail (GTK_IS_MENU (menu));
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"item_num"));
e_shortcut_bar_start_editing_item (shortcut_bar, group_num, item_num);
}
static void
remove_item (GtkWidget *menuitem,
EShortcutBar *shortcut_bar)
{
GtkWidget *menu;
gint group_num, item_num;
menu = menuitem->parent;
g_return_if_fail (GTK_IS_MENU (menu));
group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"group_num"));
item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu),
"item_num"));
e_shortcut_model_remove_item (shortcut_bar->model, group_num,
item_num);
}
static void
on_set_group_button_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar)
{
g_print ("In on_set_group_button_clicked\n");
e_group_bar_set_current_group_num (E_GROUP_BAR (shortcut_bar),
2, TRUE);
}
static void
on_set_group_button_no_animation_clicked (GtkWidget *button,
EShortcutBar *shortcut_bar)
{
g_print ("In on_set_group_button_no_animation_clicked\n");
e_group_bar_set_current_group_num (E_GROUP_BAR (shortcut_bar),
4, FALSE);
}
static void
on_item_added (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
g_print ("In on_item_added Group:%i Item:%i\n", group_num, item_num);
}
static void
on_item_removed (EShortcutModel *shortcut_model,
gint group_num,
gint item_num)
{
g_print ("In on_item_removed Group:%i Item:%i\n", group_num, item_num);
}
static void
on_group_added (EShortcutModel *shortcut_model,
gint group_num)
{
g_print ("In on_group_added Group:%i\n", group_num);
}
static void
on_group_removed (EShortcutModel *shortcut_model,
gint group_num)
{
g_print ("In on_group_removed Group:%i\n", group_num);
}
static void
on_shortcut_dragged (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num)
{
g_print ("In on_shortcut_dragged Group:%i Item:%i\n", group_num,
item_num);
e_shortcut_model_remove_item (shortcut_bar->model, group_num,
item_num);
}
static void
on_shortcut_dropped (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num,
gchar *url,
gchar *name)
{
g_print ("In on_shortcut_dropped Group:%i Item:%i\n", group_num,
item_num);
e_shortcut_model_add_item (shortcut_bar->model,
group_num, item_num, url, name);
}