Made the index panel use NautilusBackground.

This commit is contained in:
Darin Adler 2000-01-12 00:08:20 +00:00
parent 8c92ececd0
commit 32f075751e
22 changed files with 699 additions and 267 deletions

View file

@ -1,3 +1,54 @@
2000-01-11 Darin Adler <darin@eazel.com>
NautilusBackground is now used for the index panel background.
* libnautilus/nautilus-background.c:
(nautilus_background_attach_to_canvas):
(nautilus_get_widget_background):
(nautilus_gtk_style_get_default_class):
(nautilus_gdk_window_update_sizes):
(nautilus_background_draw_flat_box):
(nautilus_background_get_gtk_style_class):
(nautilus_background_set_widget_style):
(nautilus_background_set_up_canvas):
(nautilus_widget_background_changed):
(nautilus_get_widget_background):
Added new code that changes the background of a widget by
modifying the GtkStyle. For solid colors and tiled images we
can just modify the GtkStyle. For gradients we need to make
a GtkStyle subclass.
* libnautilus/nautilus-background.h:
(nautilus_background_attach_to_canvas):
(nautilus_get_widget_background):
Changed the old interface that was canvas-specific, to a new one
that allows attacking a background to any widget.
* src/ntl-index-panel.h:
Now that the background is attached to the widget, we don't need
a background field in NautilusIndexPanel.
* src/ntl-index-panel.c:
(nautilus_index_panel_set_up_background)
(nautilus_index_panel_finalize):
(nautilus_index_panel_drag_data_received):
(nautilus_index_panel_set_up_info):
Changed the index panel to use NautilusBackground.
* libnautilus/nautilus-background-canvas-group.h:
libnautilus/nautilus-background-canvas-group.c:
(nautilus_background_canvas_group_get_background):
(nautilus_background_canvas_group_set_background):
Moved the code that manages the background object out of the
canvas group code, since we can now attach a background to
any widget.
* libnautilus/gdk-extensions.c:
(nautilus_gdk_color_parse_with_white_default): Changed this helper
to accept NULLs and return the default instead of prohibiting
NULL. This is consistent with the gradient's use of NULL to
represent the default color.
2000-01-11 John Sullivan <sullivan@eazel.com>
* libnautilus/nautilus-gtk-extensions.h:

View file

@ -391,7 +391,7 @@ void
nautilus_gdk_color_parse_with_white_default (const char *color_spec,
GdkColor *color)
{
if (!gdk_color_parse (color_spec, color)) {
if (color_spec == NULL || !gdk_color_parse (color_spec, color)) {
color->red = 0xFFFF;
color->green = 0xFFFF;
color->blue = 0xFFFF;

View file

@ -84,8 +84,7 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
NautilusBackground *background;
/* Draw the background. */
background = nautilus_background_canvas_group_get_background
(NAUTILUS_BACKGROUND_CANVAS_GROUP (item));
background = nautilus_get_widget_background(GTK_WIDGET (item->canvas));
if (background != NULL) {
GdkGC *gc;
GdkColormap *colormap;
@ -124,31 +123,3 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
drawable_corner_x, drawable_corner_y,
drawable_width, drawable_height));
}
NautilusBackground *
nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *canvas_group)
{
gpointer data;
data = gtk_object_get_data (GTK_OBJECT (canvas_group), "nautilus_background");
g_assert (data == NULL || NAUTILUS_IS_BACKGROUND (data));
return data;
}
void
nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *canvas_group,
NautilusBackground *background)
{
NautilusBackground *old_background;
g_return_if_fail (NAUTILUS_IS_BACKGROUND_CANVAS_GROUP (canvas_group));
g_return_if_fail (background == NULL || NAUTILUS_IS_BACKGROUND (background));
old_background = nautilus_background_canvas_group_get_background (canvas_group);
gtk_object_set_data (GTK_OBJECT (canvas_group), "nautilus_background", background);
if (background != NULL)
gtk_object_ref (GTK_OBJECT (background));
if (old_background != NULL)
gtk_object_unref (GTK_OBJECT (old_background));
}

View file

@ -27,6 +27,7 @@
#define NAUTILUS_BACKGROUND_CANVAS_GROUP_H
#include "nautilus-background.h"
#include <libgnomeui/gnome-canvas.h>
/* A NautilusBackgroundCanvasGroup is used internally by NautilusBackground to change
the color of a canvas. The reason we have to change the class of a canvas group is
@ -55,8 +56,5 @@ typedef GnomeCanvasGroupClass NautilusBackgroundCanvasGroupClass;
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP))
GtkType nautilus_background_canvas_group_get_type (void);
NautilusBackground *nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *root);
void nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *root,
NautilusBackground *background);
#endif /* NAUTILUS_BACKGROUND_CANVAS_GROUP_H */

View file

@ -33,11 +33,25 @@
#include "nautilus-background-canvas-group.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object, gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object,
gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height);
NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusBackground, nautilus_background, GTK_TYPE_OBJECT)
@ -155,11 +169,124 @@ nautilus_background_set_color (NautilusBackground *background,
gtk_signal_emit (GTK_OBJECT (background), signals[CHANGED]);
}
void
nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas)
static GtkStyleClass *
nautilus_gtk_style_get_default_class (void)
{
/* Since there's no signal to override in GnomeCanvas to control
static GtkStyleClass *default_class;
if (default_class == NULL) {
GtkStyle *style;
style = gtk_style_new ();
default_class = style->klass;
gtk_style_unref (style);
}
return default_class;
}
static void nautilus_gdk_window_update_sizes (GdkWindow *window, int *width, int *height)
{
g_return_if_fail (window != NULL);
g_return_if_fail (width != NULL);
g_return_if_fail (height != NULL);
if (*width == -1 && *height == -1)
gdk_window_get_size (window, width, height);
else if (*width == -1)
gdk_window_get_size (window, width, NULL);
else if (*height == -1)
gdk_window_get_size (window, NULL, height);
}
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height)
{
gboolean call_parent;
NautilusBackground *background;
call_parent = TRUE;
background = nautilus_get_widget_background (widget);
if (background != NULL) {
if (nautilus_gradient_is_gradient (background->details->color))
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
}
static GtkStyleClass *
nautilus_background_get_gtk_style_class (void)
{
static GtkStyleClass *klass;
if (klass == NULL) {
static GtkStyleClass klass_storage;
klass = &klass_storage;
*klass = *nautilus_gtk_style_get_default_class ();
klass->draw_flat_box = nautilus_background_draw_flat_box;
}
return klass;
}
static void
nautilus_background_set_widget_style (NautilusBackground *background,
GtkWidget *widget)
{
GtkStyle *style;
char *start_color_spec;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
style = gtk_widget_get_style (widget);
g_return_if_fail(style->klass == nautilus_gtk_style_get_default_class ()
|| style->klass == nautilus_background_get_gtk_style_class ());
/* Make a copy of the style. */
style = gtk_style_copy (style);
/* Give it the special class that allows it to draw gradients. */
style->klass = nautilus_background_get_gtk_style_class ();
/* Set up the colors in the style. */
start_color_spec = nautilus_gradient_get_start_color_spec (background->details->color);
nautilus_gdk_color_parse_with_white_default
(start_color_spec, &style->bg[GTK_STATE_NORMAL]);
g_free (start_color_spec);
/* Put the style in the widget. */
gtk_widget_set_style (widget, style);
gtk_style_unref (style);
}
static void
nautilus_background_set_up_canvas (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
/* Attach ourselves to a canvas in a way that will work.
Changing the style is not sufficient.
Since there's no signal to override in GnomeCanvas to control
drawing the background, we change the class of the canvas root.
This gives us a chance to draw the background before any of the
objects draw themselves, and has no effect on the bounds or
@ -169,16 +296,57 @@ nautilus_background_attach_to_canvas (NautilusBackground *background,
canvas item as the background. The canvas item contributed to
the bounds of the canvas and had to constantly be resized.
*/
if (GNOME_IS_CANVAS (widget)) {
g_assert (GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GNOME_IS_CANVAS (canvas));
GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass =
gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
}
}
g_assert (GTK_OBJECT (canvas->root)->klass == gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (canvas->root)->klass == gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
static void
nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *background)
{
nautilus_background_set_widget_style (background, widget);
nautilus_background_set_up_canvas (widget);
GTK_OBJECT (canvas->root)->klass = gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
gtk_widget_queue_clear (widget);
}
nautilus_background_canvas_group_set_background (NAUTILUS_BACKGROUND_CANVAS_GROUP (canvas->root), background);
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
gpointer data;
NautilusBackground *background;
GtkStyle *old_style;
GtkStyle *new_style;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
/* Check for an existing background. */
data = gtk_object_get_data (GTK_OBJECT (widget), "nautilus_background");
if (data != NULL) {
g_assert (NAUTILUS_IS_BACKGROUND (data));
return data;
}
/* Store the background in the widget's data. */
background = nautilus_background_new ();
gtk_object_set_data_full (GTK_OBJECT (widget), "nautilus_background",
background, (GtkDestroyNotify) gtk_object_unref);
gtk_object_ref (GTK_OBJECT (background));
gtk_object_sink (GTK_OBJECT (background));
/* Arrange to get the signal whenever the background changes. */
gtk_signal_connect_object_while_alive (GTK_OBJECT (background), "changed",
nautilus_widget_background_changed,
GTK_OBJECT (widget));
nautilus_widget_background_changed (widget, background);
return background;
}
/* self check code */
@ -197,6 +365,8 @@ nautilus_self_check_background (void)
nautilus_background_set_color (background, "red");
nautilus_background_set_color (background, "red-blue");
nautilus_background_set_color (background, "red-blue:h");
gtk_object_unref (GTK_OBJECT (background));
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */

View file

@ -33,10 +33,15 @@
The color or gradient is always present, even if there's a tiled image
on top of it. This is used when the tiled image can't be loaded for
some reason (or just has not been loaded yet).
The NautilusBackground object is easier to modify than a GtkStyle.
You can just call nautilus_get_window_background and modify the
returned background directly, unlike a style, which must be copied,
modified and then set.
*/
#include <gdk/gdktypes.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtkwidget.h>
typedef struct _NautilusBackground NautilusBackground;
typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
@ -69,9 +74,17 @@ void nautilus_background_draw (NautilusBackground *
GdkColormap *colormap,
const GdkRectangle *rectangle);
void nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;

View file

@ -391,7 +391,7 @@ void
nautilus_gdk_color_parse_with_white_default (const char *color_spec,
GdkColor *color)
{
if (!gdk_color_parse (color_spec, color)) {
if (color_spec == NULL || !gdk_color_parse (color_spec, color)) {
color->red = 0xFFFF;
color->green = 0xFFFF;
color->blue = 0xFFFF;

View file

@ -84,8 +84,7 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
NautilusBackground *background;
/* Draw the background. */
background = nautilus_background_canvas_group_get_background
(NAUTILUS_BACKGROUND_CANVAS_GROUP (item));
background = nautilus_get_widget_background(GTK_WIDGET (item->canvas));
if (background != NULL) {
GdkGC *gc;
GdkColormap *colormap;
@ -124,31 +123,3 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
drawable_corner_x, drawable_corner_y,
drawable_width, drawable_height));
}
NautilusBackground *
nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *canvas_group)
{
gpointer data;
data = gtk_object_get_data (GTK_OBJECT (canvas_group), "nautilus_background");
g_assert (data == NULL || NAUTILUS_IS_BACKGROUND (data));
return data;
}
void
nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *canvas_group,
NautilusBackground *background)
{
NautilusBackground *old_background;
g_return_if_fail (NAUTILUS_IS_BACKGROUND_CANVAS_GROUP (canvas_group));
g_return_if_fail (background == NULL || NAUTILUS_IS_BACKGROUND (background));
old_background = nautilus_background_canvas_group_get_background (canvas_group);
gtk_object_set_data (GTK_OBJECT (canvas_group), "nautilus_background", background);
if (background != NULL)
gtk_object_ref (GTK_OBJECT (background));
if (old_background != NULL)
gtk_object_unref (GTK_OBJECT (old_background));
}

View file

@ -27,6 +27,7 @@
#define NAUTILUS_BACKGROUND_CANVAS_GROUP_H
#include "nautilus-background.h"
#include <libgnomeui/gnome-canvas.h>
/* A NautilusBackgroundCanvasGroup is used internally by NautilusBackground to change
the color of a canvas. The reason we have to change the class of a canvas group is
@ -55,8 +56,5 @@ typedef GnomeCanvasGroupClass NautilusBackgroundCanvasGroupClass;
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP))
GtkType nautilus_background_canvas_group_get_type (void);
NautilusBackground *nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *root);
void nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *root,
NautilusBackground *background);
#endif /* NAUTILUS_BACKGROUND_CANVAS_GROUP_H */

View file

@ -33,11 +33,25 @@
#include "nautilus-background-canvas-group.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object, gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object,
gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height);
NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusBackground, nautilus_background, GTK_TYPE_OBJECT)
@ -155,11 +169,124 @@ nautilus_background_set_color (NautilusBackground *background,
gtk_signal_emit (GTK_OBJECT (background), signals[CHANGED]);
}
void
nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas)
static GtkStyleClass *
nautilus_gtk_style_get_default_class (void)
{
/* Since there's no signal to override in GnomeCanvas to control
static GtkStyleClass *default_class;
if (default_class == NULL) {
GtkStyle *style;
style = gtk_style_new ();
default_class = style->klass;
gtk_style_unref (style);
}
return default_class;
}
static void nautilus_gdk_window_update_sizes (GdkWindow *window, int *width, int *height)
{
g_return_if_fail (window != NULL);
g_return_if_fail (width != NULL);
g_return_if_fail (height != NULL);
if (*width == -1 && *height == -1)
gdk_window_get_size (window, width, height);
else if (*width == -1)
gdk_window_get_size (window, width, NULL);
else if (*height == -1)
gdk_window_get_size (window, NULL, height);
}
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height)
{
gboolean call_parent;
NautilusBackground *background;
call_parent = TRUE;
background = nautilus_get_widget_background (widget);
if (background != NULL) {
if (nautilus_gradient_is_gradient (background->details->color))
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
}
static GtkStyleClass *
nautilus_background_get_gtk_style_class (void)
{
static GtkStyleClass *klass;
if (klass == NULL) {
static GtkStyleClass klass_storage;
klass = &klass_storage;
*klass = *nautilus_gtk_style_get_default_class ();
klass->draw_flat_box = nautilus_background_draw_flat_box;
}
return klass;
}
static void
nautilus_background_set_widget_style (NautilusBackground *background,
GtkWidget *widget)
{
GtkStyle *style;
char *start_color_spec;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
style = gtk_widget_get_style (widget);
g_return_if_fail(style->klass == nautilus_gtk_style_get_default_class ()
|| style->klass == nautilus_background_get_gtk_style_class ());
/* Make a copy of the style. */
style = gtk_style_copy (style);
/* Give it the special class that allows it to draw gradients. */
style->klass = nautilus_background_get_gtk_style_class ();
/* Set up the colors in the style. */
start_color_spec = nautilus_gradient_get_start_color_spec (background->details->color);
nautilus_gdk_color_parse_with_white_default
(start_color_spec, &style->bg[GTK_STATE_NORMAL]);
g_free (start_color_spec);
/* Put the style in the widget. */
gtk_widget_set_style (widget, style);
gtk_style_unref (style);
}
static void
nautilus_background_set_up_canvas (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
/* Attach ourselves to a canvas in a way that will work.
Changing the style is not sufficient.
Since there's no signal to override in GnomeCanvas to control
drawing the background, we change the class of the canvas root.
This gives us a chance to draw the background before any of the
objects draw themselves, and has no effect on the bounds or
@ -169,16 +296,57 @@ nautilus_background_attach_to_canvas (NautilusBackground *background,
canvas item as the background. The canvas item contributed to
the bounds of the canvas and had to constantly be resized.
*/
if (GNOME_IS_CANVAS (widget)) {
g_assert (GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GNOME_IS_CANVAS (canvas));
GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass =
gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
}
}
g_assert (GTK_OBJECT (canvas->root)->klass == gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (canvas->root)->klass == gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
static void
nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *background)
{
nautilus_background_set_widget_style (background, widget);
nautilus_background_set_up_canvas (widget);
GTK_OBJECT (canvas->root)->klass = gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
gtk_widget_queue_clear (widget);
}
nautilus_background_canvas_group_set_background (NAUTILUS_BACKGROUND_CANVAS_GROUP (canvas->root), background);
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
gpointer data;
NautilusBackground *background;
GtkStyle *old_style;
GtkStyle *new_style;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
/* Check for an existing background. */
data = gtk_object_get_data (GTK_OBJECT (widget), "nautilus_background");
if (data != NULL) {
g_assert (NAUTILUS_IS_BACKGROUND (data));
return data;
}
/* Store the background in the widget's data. */
background = nautilus_background_new ();
gtk_object_set_data_full (GTK_OBJECT (widget), "nautilus_background",
background, (GtkDestroyNotify) gtk_object_unref);
gtk_object_ref (GTK_OBJECT (background));
gtk_object_sink (GTK_OBJECT (background));
/* Arrange to get the signal whenever the background changes. */
gtk_signal_connect_object_while_alive (GTK_OBJECT (background), "changed",
nautilus_widget_background_changed,
GTK_OBJECT (widget));
nautilus_widget_background_changed (widget, background);
return background;
}
/* self check code */
@ -197,6 +365,8 @@ nautilus_self_check_background (void)
nautilus_background_set_color (background, "red");
nautilus_background_set_color (background, "red-blue");
nautilus_background_set_color (background, "red-blue:h");
gtk_object_unref (GTK_OBJECT (background));
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */

View file

@ -33,10 +33,15 @@
The color or gradient is always present, even if there's a tiled image
on top of it. This is used when the tiled image can't be loaded for
some reason (or just has not been loaded yet).
The NautilusBackground object is easier to modify than a GtkStyle.
You can just call nautilus_get_window_background and modify the
returned background directly, unlike a style, which must be copied,
modified and then set.
*/
#include <gdk/gdktypes.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtkwidget.h>
typedef struct _NautilusBackground NautilusBackground;
typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
@ -69,9 +74,17 @@ void nautilus_background_draw (NautilusBackground *
GdkColormap *colormap,
const GdkRectangle *rectangle);
void nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;

View file

@ -391,7 +391,7 @@ void
nautilus_gdk_color_parse_with_white_default (const char *color_spec,
GdkColor *color)
{
if (!gdk_color_parse (color_spec, color)) {
if (color_spec == NULL || !gdk_color_parse (color_spec, color)) {
color->red = 0xFFFF;
color->green = 0xFFFF;
color->blue = 0xFFFF;

View file

@ -84,8 +84,7 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
NautilusBackground *background;
/* Draw the background. */
background = nautilus_background_canvas_group_get_background
(NAUTILUS_BACKGROUND_CANVAS_GROUP (item));
background = nautilus_get_widget_background(GTK_WIDGET (item->canvas));
if (background != NULL) {
GdkGC *gc;
GdkColormap *colormap;
@ -124,31 +123,3 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
drawable_corner_x, drawable_corner_y,
drawable_width, drawable_height));
}
NautilusBackground *
nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *canvas_group)
{
gpointer data;
data = gtk_object_get_data (GTK_OBJECT (canvas_group), "nautilus_background");
g_assert (data == NULL || NAUTILUS_IS_BACKGROUND (data));
return data;
}
void
nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *canvas_group,
NautilusBackground *background)
{
NautilusBackground *old_background;
g_return_if_fail (NAUTILUS_IS_BACKGROUND_CANVAS_GROUP (canvas_group));
g_return_if_fail (background == NULL || NAUTILUS_IS_BACKGROUND (background));
old_background = nautilus_background_canvas_group_get_background (canvas_group);
gtk_object_set_data (GTK_OBJECT (canvas_group), "nautilus_background", background);
if (background != NULL)
gtk_object_ref (GTK_OBJECT (background));
if (old_background != NULL)
gtk_object_unref (GTK_OBJECT (old_background));
}

View file

@ -27,6 +27,7 @@
#define NAUTILUS_BACKGROUND_CANVAS_GROUP_H
#include "nautilus-background.h"
#include <libgnomeui/gnome-canvas.h>
/* A NautilusBackgroundCanvasGroup is used internally by NautilusBackground to change
the color of a canvas. The reason we have to change the class of a canvas group is
@ -55,8 +56,5 @@ typedef GnomeCanvasGroupClass NautilusBackgroundCanvasGroupClass;
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP))
GtkType nautilus_background_canvas_group_get_type (void);
NautilusBackground *nautilus_background_canvas_group_get_background (NautilusBackgroundCanvasGroup *root);
void nautilus_background_canvas_group_set_background (NautilusBackgroundCanvasGroup *root,
NautilusBackground *background);
#endif /* NAUTILUS_BACKGROUND_CANVAS_GROUP_H */

View file

@ -33,11 +33,25 @@
#include "nautilus-background-canvas-group.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object, gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object,
gpointer klass);
static void nautilus_background_destroy (GtkObject *object);
static void nautilus_background_finalize (GtkObject *object);
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height);
NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusBackground, nautilus_background, GTK_TYPE_OBJECT)
@ -155,11 +169,124 @@ nautilus_background_set_color (NautilusBackground *background,
gtk_signal_emit (GTK_OBJECT (background), signals[CHANGED]);
}
void
nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas)
static GtkStyleClass *
nautilus_gtk_style_get_default_class (void)
{
/* Since there's no signal to override in GnomeCanvas to control
static GtkStyleClass *default_class;
if (default_class == NULL) {
GtkStyle *style;
style = gtk_style_new ();
default_class = style->klass;
gtk_style_unref (style);
}
return default_class;
}
static void nautilus_gdk_window_update_sizes (GdkWindow *window, int *width, int *height)
{
g_return_if_fail (window != NULL);
g_return_if_fail (width != NULL);
g_return_if_fail (height != NULL);
if (*width == -1 && *height == -1)
gdk_window_get_size (window, width, height);
else if (*width == -1)
gdk_window_get_size (window, width, NULL);
else if (*height == -1)
gdk_window_get_size (window, NULL, height);
}
static void nautilus_background_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
gchar *detail,
gint x,
gint y,
gint width,
gint height)
{
gboolean call_parent;
NautilusBackground *background;
call_parent = TRUE;
background = nautilus_get_widget_background (widget);
if (background != NULL) {
if (nautilus_gradient_is_gradient (background->details->color))
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
}
static GtkStyleClass *
nautilus_background_get_gtk_style_class (void)
{
static GtkStyleClass *klass;
if (klass == NULL) {
static GtkStyleClass klass_storage;
klass = &klass_storage;
*klass = *nautilus_gtk_style_get_default_class ();
klass->draw_flat_box = nautilus_background_draw_flat_box;
}
return klass;
}
static void
nautilus_background_set_widget_style (NautilusBackground *background,
GtkWidget *widget)
{
GtkStyle *style;
char *start_color_spec;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
style = gtk_widget_get_style (widget);
g_return_if_fail(style->klass == nautilus_gtk_style_get_default_class ()
|| style->klass == nautilus_background_get_gtk_style_class ());
/* Make a copy of the style. */
style = gtk_style_copy (style);
/* Give it the special class that allows it to draw gradients. */
style->klass = nautilus_background_get_gtk_style_class ();
/* Set up the colors in the style. */
start_color_spec = nautilus_gradient_get_start_color_spec (background->details->color);
nautilus_gdk_color_parse_with_white_default
(start_color_spec, &style->bg[GTK_STATE_NORMAL]);
g_free (start_color_spec);
/* Put the style in the widget. */
gtk_widget_set_style (widget, style);
gtk_style_unref (style);
}
static void
nautilus_background_set_up_canvas (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
/* Attach ourselves to a canvas in a way that will work.
Changing the style is not sufficient.
Since there's no signal to override in GnomeCanvas to control
drawing the background, we change the class of the canvas root.
This gives us a chance to draw the background before any of the
objects draw themselves, and has no effect on the bounds or
@ -169,16 +296,57 @@ nautilus_background_attach_to_canvas (NautilusBackground *background,
canvas item as the background. The canvas item contributed to
the bounds of the canvas and had to constantly be resized.
*/
if (GNOME_IS_CANVAS (widget)) {
g_assert (GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass
== gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GNOME_IS_CANVAS (canvas));
GTK_OBJECT (GNOME_CANVAS (widget)->root)->klass =
gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
}
}
g_assert (GTK_OBJECT (canvas->root)->klass == gtk_type_class (GNOME_TYPE_CANVAS_GROUP)
|| GTK_OBJECT (canvas->root)->klass == gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP));
static void
nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *background)
{
nautilus_background_set_widget_style (background, widget);
nautilus_background_set_up_canvas (widget);
GTK_OBJECT (canvas->root)->klass = gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
gtk_widget_queue_clear (widget);
}
nautilus_background_canvas_group_set_background (NAUTILUS_BACKGROUND_CANVAS_GROUP (canvas->root), background);
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
gpointer data;
NautilusBackground *background;
GtkStyle *old_style;
GtkStyle *new_style;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
/* Check for an existing background. */
data = gtk_object_get_data (GTK_OBJECT (widget), "nautilus_background");
if (data != NULL) {
g_assert (NAUTILUS_IS_BACKGROUND (data));
return data;
}
/* Store the background in the widget's data. */
background = nautilus_background_new ();
gtk_object_set_data_full (GTK_OBJECT (widget), "nautilus_background",
background, (GtkDestroyNotify) gtk_object_unref);
gtk_object_ref (GTK_OBJECT (background));
gtk_object_sink (GTK_OBJECT (background));
/* Arrange to get the signal whenever the background changes. */
gtk_signal_connect_object_while_alive (GTK_OBJECT (background), "changed",
nautilus_widget_background_changed,
GTK_OBJECT (widget));
nautilus_widget_background_changed (widget, background);
return background;
}
/* self check code */
@ -197,6 +365,8 @@ nautilus_self_check_background (void)
nautilus_background_set_color (background, "red");
nautilus_background_set_color (background, "red-blue");
nautilus_background_set_color (background, "red-blue:h");
gtk_object_unref (GTK_OBJECT (background));
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */

View file

@ -33,10 +33,15 @@
The color or gradient is always present, even if there's a tiled image
on top of it. This is used when the tiled image can't be loaded for
some reason (or just has not been loaded yet).
The NautilusBackground object is easier to modify than a GtkStyle.
You can just call nautilus_get_window_background and modify the
returned background directly, unlike a style, which must be copied,
modified and then set.
*/
#include <gdk/gdktypes.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtkwidget.h>
typedef struct _NautilusBackground NautilusBackground;
typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
@ -69,9 +74,17 @@ void nautilus_background_draw (NautilusBackground *
GdkColormap *colormap,
const GdkRectangle *rectangle);
void nautilus_background_attach_to_canvas (NautilusBackground *background,
GnomeCanvas *canvas);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;

View file

@ -24,15 +24,11 @@
*
*/
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <gnome.h>
#include "nautilus.h"
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-string.h>
@ -49,7 +45,6 @@ static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragC
GtkSelectionData *selection_data,
guint info, guint time);
static void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data);
static void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri);
static void nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar *uri);
static void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path);
@ -132,8 +127,6 @@ nautilus_index_panel_initialize (gpointer object, gpointer klass)
gtk_drag_dest_set (GTK_WIDGET (index_panel),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
index_dnd_target_table, ARRAY_LENGTH (index_dnd_target_table), GDK_ACTION_COPY);
index_panel->background = nautilus_background_new ();
}
static void
@ -154,8 +147,6 @@ nautilus_index_panel_finalize (GtkObject *object)
index_panel = NAUTILUS_INDEX_PANEL (object);
g_free (index_panel->uri);
if (index_panel->background != NULL)
gtk_object_unref (GTK_OBJECT (index_panel->background));
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
}
@ -176,13 +167,14 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
{
char *color_spec;
guint16 *data;
NautilusBackground *background;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (widget));
switch (info)
{
case TARGET_URI_LIST:
printf("dropped data on index panel: %s", selection_data->data);
g_message("dropped data on index panel: %s", selection_data->data);
/* handle background images and keywords soon */
@ -198,7 +190,8 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
case TARGET_COLOR:
data = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", data[0], data[1], data[2]);
nautilus_index_panel_set_up_background (NAUTILUS_INDEX_PANEL (widget), color_spec);
background = nautilus_get_widget_background (widget);
nautilus_background_set_color (background, color_spec);
g_free (color_spec);
break;
@ -245,24 +238,6 @@ void nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nau
gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->meta_tabs), page_num);
}
/* set up the index panel's background. Darin's background stuff will soon replace this,
but for now just set up the color */
void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data)
{
GdkColor temp_color;
GtkStyle *temp_style;
gdk_color_parse (background_data, &temp_color);
gdk_color_alloc (gtk_widget_get_colormap (GTK_WIDGET (index_panel)), &temp_color);
temp_style = gtk_style_new();
temp_style->bg[GTK_STATE_NORMAL] = temp_color;
gtk_widget_set_style (GTK_WIDGET (index_panel),
gtk_style_attach (temp_style, GTK_WIDGET (index_panel)->window));
nautilus_background_set_color (index_panel->background, background_data);
}
/* set up the logo image */
void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path)
{
@ -373,8 +348,11 @@ nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar
void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri)
{
NautilusBackground *background;
/* set up the background from the metadata. At first, just use hardwired backgrounds */
nautilus_index_panel_set_up_background (index_panel, "rgb:DDDD/DDDD/FFFF");
background = nautilus_get_widget_background (GTK_WIDGET (index_panel));
nautilus_background_set_color (background, "rgb:DDDD/DDDD/FFFF");
/* next, install the logo image. */
/* For now, just use a fixed folder image */

View file

@ -26,10 +26,8 @@
#ifndef NTL_INDEX_PANEL_H
#define NTL_INDEX_PANEL_H
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
#include "nautilus.h"
#include <libnautilus/nautilus-background.h>
#include <gtk/gtkeventbox.h>
#include "ntl-view.h"
typedef struct _NautilusIndexPanel NautilusIndexPanel;
typedef struct _NautilusIndexPanelClass NautilusIndexPanelClass;
@ -52,7 +50,6 @@ struct _NautilusIndexPanel
GtkWidget *per_uri_container;
GtkWidget *meta_tabs;
gchar *uri;
NautilusBackground *background;
};
struct _NautilusIndexPanelClass

View file

@ -24,15 +24,11 @@
*
*/
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <gnome.h>
#include "nautilus.h"
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-string.h>
@ -49,7 +45,6 @@ static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragC
GtkSelectionData *selection_data,
guint info, guint time);
static void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data);
static void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri);
static void nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar *uri);
static void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path);
@ -132,8 +127,6 @@ nautilus_index_panel_initialize (gpointer object, gpointer klass)
gtk_drag_dest_set (GTK_WIDGET (index_panel),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
index_dnd_target_table, ARRAY_LENGTH (index_dnd_target_table), GDK_ACTION_COPY);
index_panel->background = nautilus_background_new ();
}
static void
@ -154,8 +147,6 @@ nautilus_index_panel_finalize (GtkObject *object)
index_panel = NAUTILUS_INDEX_PANEL (object);
g_free (index_panel->uri);
if (index_panel->background != NULL)
gtk_object_unref (GTK_OBJECT (index_panel->background));
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
}
@ -176,13 +167,14 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
{
char *color_spec;
guint16 *data;
NautilusBackground *background;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (widget));
switch (info)
{
case TARGET_URI_LIST:
printf("dropped data on index panel: %s", selection_data->data);
g_message("dropped data on index panel: %s", selection_data->data);
/* handle background images and keywords soon */
@ -198,7 +190,8 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
case TARGET_COLOR:
data = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", data[0], data[1], data[2]);
nautilus_index_panel_set_up_background (NAUTILUS_INDEX_PANEL (widget), color_spec);
background = nautilus_get_widget_background (widget);
nautilus_background_set_color (background, color_spec);
g_free (color_spec);
break;
@ -245,24 +238,6 @@ void nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nau
gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->meta_tabs), page_num);
}
/* set up the index panel's background. Darin's background stuff will soon replace this,
but for now just set up the color */
void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data)
{
GdkColor temp_color;
GtkStyle *temp_style;
gdk_color_parse (background_data, &temp_color);
gdk_color_alloc (gtk_widget_get_colormap (GTK_WIDGET (index_panel)), &temp_color);
temp_style = gtk_style_new();
temp_style->bg[GTK_STATE_NORMAL] = temp_color;
gtk_widget_set_style (GTK_WIDGET (index_panel),
gtk_style_attach (temp_style, GTK_WIDGET (index_panel)->window));
nautilus_background_set_color (index_panel->background, background_data);
}
/* set up the logo image */
void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path)
{
@ -373,8 +348,11 @@ nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar
void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri)
{
NautilusBackground *background;
/* set up the background from the metadata. At first, just use hardwired backgrounds */
nautilus_index_panel_set_up_background (index_panel, "rgb:DDDD/DDDD/FFFF");
background = nautilus_get_widget_background (GTK_WIDGET (index_panel));
nautilus_background_set_color (background, "rgb:DDDD/DDDD/FFFF");
/* next, install the logo image. */
/* For now, just use a fixed folder image */

View file

@ -26,10 +26,8 @@
#ifndef NTL_INDEX_PANEL_H
#define NTL_INDEX_PANEL_H
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
#include "nautilus.h"
#include <libnautilus/nautilus-background.h>
#include <gtk/gtkeventbox.h>
#include "ntl-view.h"
typedef struct _NautilusIndexPanel NautilusIndexPanel;
typedef struct _NautilusIndexPanelClass NautilusIndexPanelClass;
@ -52,7 +50,6 @@ struct _NautilusIndexPanel
GtkWidget *per_uri_container;
GtkWidget *meta_tabs;
gchar *uri;
NautilusBackground *background;
};
struct _NautilusIndexPanelClass

View file

@ -24,15 +24,11 @@
*
*/
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <gnome.h>
#include "nautilus.h"
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-string.h>
@ -49,7 +45,6 @@ static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragC
GtkSelectionData *selection_data,
guint info, guint time);
static void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data);
static void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri);
static void nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar *uri);
static void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path);
@ -132,8 +127,6 @@ nautilus_index_panel_initialize (gpointer object, gpointer klass)
gtk_drag_dest_set (GTK_WIDGET (index_panel),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
index_dnd_target_table, ARRAY_LENGTH (index_dnd_target_table), GDK_ACTION_COPY);
index_panel->background = nautilus_background_new ();
}
static void
@ -154,8 +147,6 @@ nautilus_index_panel_finalize (GtkObject *object)
index_panel = NAUTILUS_INDEX_PANEL (object);
g_free (index_panel->uri);
if (index_panel->background != NULL)
gtk_object_unref (GTK_OBJECT (index_panel->background));
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
}
@ -176,13 +167,14 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
{
char *color_spec;
guint16 *data;
NautilusBackground *background;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (widget));
switch (info)
{
case TARGET_URI_LIST:
printf("dropped data on index panel: %s", selection_data->data);
g_message("dropped data on index panel: %s", selection_data->data);
/* handle background images and keywords soon */
@ -198,7 +190,8 @@ nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *cont
case TARGET_COLOR:
data = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", data[0], data[1], data[2]);
nautilus_index_panel_set_up_background (NAUTILUS_INDEX_PANEL (widget), color_spec);
background = nautilus_get_widget_background (widget);
nautilus_background_set_color (background, color_spec);
g_free (color_spec);
break;
@ -245,24 +238,6 @@ void nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nau
gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->meta_tabs), page_num);
}
/* set up the index panel's background. Darin's background stuff will soon replace this,
but for now just set up the color */
void nautilus_index_panel_set_up_background (NautilusIndexPanel *index_panel, const gchar *background_data)
{
GdkColor temp_color;
GtkStyle *temp_style;
gdk_color_parse (background_data, &temp_color);
gdk_color_alloc (gtk_widget_get_colormap (GTK_WIDGET (index_panel)), &temp_color);
temp_style = gtk_style_new();
temp_style->bg[GTK_STATE_NORMAL] = temp_color;
gtk_widget_set_style (GTK_WIDGET (index_panel),
gtk_style_attach (temp_style, GTK_WIDGET (index_panel)->window));
nautilus_background_set_color (index_panel->background, background_data);
}
/* set up the logo image */
void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path)
{
@ -373,8 +348,11 @@ nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar
void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri)
{
NautilusBackground *background;
/* set up the background from the metadata. At first, just use hardwired backgrounds */
nautilus_index_panel_set_up_background (index_panel, "rgb:DDDD/DDDD/FFFF");
background = nautilus_get_widget_background (GTK_WIDGET (index_panel));
nautilus_background_set_color (background, "rgb:DDDD/DDDD/FFFF");
/* next, install the logo image. */
/* For now, just use a fixed folder image */

View file

@ -26,10 +26,8 @@
#ifndef NTL_INDEX_PANEL_H
#define NTL_INDEX_PANEL_H
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
#include "nautilus.h"
#include <libnautilus/nautilus-background.h>
#include <gtk/gtkeventbox.h>
#include "ntl-view.h"
typedef struct _NautilusIndexPanel NautilusIndexPanel;
typedef struct _NautilusIndexPanelClass NautilusIndexPanelClass;
@ -52,7 +50,6 @@ struct _NautilusIndexPanel
GtkWidget *per_uri_container;
GtkWidget *meta_tabs;
gchar *uri;
NautilusBackground *background;
};
struct _NautilusIndexPanelClass