2000-12-26 19:41:33 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* capplet-dir-view-list.c
|
|
|
|
* Copyright (C) 2000 Helix Code, Inc.
|
|
|
|
*
|
|
|
|
* Authors: Jacob Berkman <jacob@helixcode.com>
|
|
|
|
* Bradford Hovinen <hovinen@helixcode.com>
|
|
|
|
*
|
|
|
|
* 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, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <gdk-pixbuf/gnome-canvas-pixbuf.h>
|
|
|
|
|
|
|
|
#include "capplet-dir-view.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_clear (CappletDirView *view)
|
|
|
|
{
|
2001-01-24 20:26:38 +00:00
|
|
|
g_return_if_fail (GNOME_IS_ICON_LIST (view->view_data));
|
2000-12-26 19:41:33 +00:00
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
gnome_icon_list_clear (GNOME_ICON_LIST (view->view_data));
|
2000-12-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_clean (CappletDirView *view)
|
|
|
|
{
|
2001-01-24 20:26:38 +00:00
|
|
|
/* i think this can be a no-op now */
|
|
|
|
view->view_data = NULL;
|
2000-12-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates a 24-bits RGB value from a GdkColor
|
|
|
|
*/
|
|
|
|
static guint
|
|
|
|
rgb_from_gdk_color (GdkColor *color)
|
|
|
|
{
|
|
|
|
guint a =
|
|
|
|
(((color->red >> 8) << 16) |
|
|
|
|
((color->green >> 8) << 8) |
|
|
|
|
((color->blue >> 8)));
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GnomeCanvasItem *
|
|
|
|
flatten_alpha (GdkPixbuf *image, GnomeCanvas *canvas)
|
|
|
|
{
|
|
|
|
GnomeCanvasItem *item;
|
|
|
|
GtkStyle *style;
|
|
|
|
GdkPixbuf *flat;
|
|
|
|
guint rgb;
|
|
|
|
|
|
|
|
if (!image || !gdk_pixbuf_get_has_alpha (image))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (canvas)))
|
|
|
|
gtk_widget_realize (GTK_WIDGET (canvas));
|
|
|
|
|
|
|
|
style = gtk_widget_get_style (GTK_WIDGET (canvas));
|
|
|
|
rgb = rgb_from_gdk_color (&style->base[GTK_STATE_NORMAL]);
|
|
|
|
|
|
|
|
flat = gdk_pixbuf_composite_color_simple (
|
|
|
|
image,
|
|
|
|
gdk_pixbuf_get_width (image),
|
|
|
|
gdk_pixbuf_get_height (image),
|
|
|
|
GDK_INTERP_NEAREST,
|
|
|
|
255,
|
|
|
|
32,
|
|
|
|
rgb, rgb);
|
|
|
|
|
|
|
|
item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (canvas->root),
|
|
|
|
GNOME_TYPE_CANVAS_PIXBUF,
|
|
|
|
"pixbuf", flat,
|
|
|
|
"height", (double)gdk_pixbuf_get_height (flat),
|
|
|
|
"width", (double)gdk_pixbuf_get_width (flat),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gdk_pixbuf_unref (flat);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_populate (CappletDirView *view)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
int i;
|
|
|
|
GnomeCanvasItem *item;
|
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
g_return_if_fail (GNOME_IS_ICON_LIST (view->view_data));
|
2000-12-26 19:41:33 +00:00
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
gnome_icon_list_freeze (GNOME_ICON_LIST (view->view_data));
|
2000-12-26 19:41:33 +00:00
|
|
|
|
|
|
|
for (i = 0, list = view->capplet_dir->entries; list; list = list->next, i++) {
|
2000-12-27 20:33:41 +00:00
|
|
|
#if 0
|
2000-12-26 19:41:33 +00:00
|
|
|
item = flatten_alpha (CAPPLET_DIR_ENTRY (list->data)->pb,
|
2001-01-24 20:26:38 +00:00
|
|
|
GNOME_CANVAS (view->view_data));
|
|
|
|
gnome_icon_list_insert_item (GNOME_ICON_LIST (view->view_data), i, item,
|
2000-12-26 19:41:33 +00:00
|
|
|
CAPPLET_DIR_ENTRY (list->data)->label);
|
2000-12-27 20:33:41 +00:00
|
|
|
#else
|
2001-01-24 20:26:38 +00:00
|
|
|
gnome_icon_list_insert (GNOME_ICON_LIST (view->view_data), i,
|
2000-12-27 20:33:41 +00:00
|
|
|
CAPPLET_DIR_ENTRY (list->data)->icon,
|
|
|
|
CAPPLET_DIR_ENTRY (list->data)->label);
|
|
|
|
#endif
|
2000-12-26 19:41:33 +00:00
|
|
|
}
|
2001-01-24 20:26:38 +00:00
|
|
|
gnome_icon_list_thaw (GNOME_ICON_LIST (view->view_data));
|
2000-12-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_icon_list_cb (GtkWidget *widget, gint arg1, GdkEvent *event,
|
|
|
|
CappletDirView *view)
|
|
|
|
{
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS &&
|
|
|
|
((GdkEventButton *) event)->button == 1)
|
|
|
|
{
|
|
|
|
capplet_dir_entry_activate
|
|
|
|
(g_slist_nth_data (view->capplet_dir->entries, arg1), view);
|
|
|
|
view->selected = NULL;
|
|
|
|
} else {
|
|
|
|
view->selected = g_slist_nth_data (view->capplet_dir->entries, arg1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
list_create (CappletDirView *view)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adjustment;
|
2001-01-24 20:26:38 +00:00
|
|
|
GtkWidget *w, *sw;
|
2000-12-26 19:41:33 +00:00
|
|
|
GSList *list;
|
|
|
|
int i;
|
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2000-12-26 19:41:33 +00:00
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw));
|
2000-12-26 19:41:33 +00:00
|
|
|
|
2001-01-24 20:26:38 +00:00
|
|
|
view->view_data = w = gnome_icon_list_new (72, adjustment, 0);
|
2000-12-26 19:41:33 +00:00
|
|
|
|
|
|
|
if (view->selected)
|
|
|
|
view->capplet_dir = view->selected->dir;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (view->capplet_dir) populate_icon_list (view);
|
|
|
|
|
|
|
|
if (view->selected) {
|
|
|
|
for (i = 0, list = view->capplet_dir->entries; list; i++, list = list->next) {
|
|
|
|
if (list->data == view->selected) {
|
|
|
|
gnome_icon_list_select_icon (view->u.icon_list, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (w), "select-icon",
|
|
|
|
GTK_SIGNAL_FUNC (select_icon_list_cb),
|
|
|
|
view);
|
2001-01-24 20:26:38 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sw), w);
|
|
|
|
gtk_widget_show_all (sw);
|
|
|
|
|
|
|
|
return sw;
|
2000-12-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CappletDirViewImpl capplet_dir_view_list = {
|
|
|
|
list_clear,
|
|
|
|
list_clean,
|
|
|
|
list_populate,
|
|
|
|
list_create
|
|
|
|
};
|