summaryrefslogtreecommitdiff
path: root/libnautilus
diff options
context:
space:
mode:
Diffstat (limited to 'libnautilus')
-rw-r--r--libnautilus/Makefile.am5
-rw-r--r--libnautilus/gdk-extensions.c105
-rw-r--r--libnautilus/gdk-extensions.h79
-rw-r--r--libnautilus/nautilus-background-canvas-group.c154
-rw-r--r--libnautilus/nautilus-background-canvas-group.h62
-rw-r--r--libnautilus/nautilus-background.c202
-rw-r--r--libnautilus/nautilus-background.h95
-rw-r--r--libnautilus/nautilus-lib-self-check-functions.c1
-rw-r--r--libnautilus/nautilus-lib-self-check-functions.h1
-rw-r--r--libnautilus/nautilus-string.c48
-rw-r--r--libnautilus/nautilus-string.h37
11 files changed, 722 insertions, 67 deletions
diff --git a/libnautilus/Makefile.am b/libnautilus/Makefile.am
index 81e6a6b09..47c90e02d 100644
--- a/libnautilus/Makefile.am
+++ b/libnautilus/Makefile.am
@@ -22,10 +22,12 @@ libnautilusinclude_HEADERS= \
gtkflist.h \
gtkscrollframe.h \
nautilus.h \
+ nautilus-background.h \
nautilus-file-utilities.h \
nautilus-gtk-extensions.h \
nautilus-lib-self-check-functions.h \
nautilus-self-checks.h \
+ nautilus-string.h \
ntl-content-view-client.h \
ntl-meta-view-client.h \
ntl-view-client.h
@@ -37,10 +39,13 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gnome-icon-container.c \
gtkflist.c \
gtkscrollframe.c \
+ nautilus-background.c \
+ nautilus-background-canvas-group.c \
nautilus-file-utilities.c \
nautilus-gtk-extensions.c \
nautilus-lib-self-check-functions.c \
nautilus-self-checks.c \
+ nautilus-string.c \
ntl-content-view-client.c \
ntl-meta-view-client.c \
ntl-view-client.c \
diff --git a/libnautilus/gdk-extensions.c b/libnautilus/gdk-extensions.c
index 8f145b5b6..e7f18e36e 100644
--- a/libnautilus/gdk-extensions.c
+++ b/libnautilus/gdk-extensions.c
@@ -29,8 +29,7 @@
#include "gdk-extensions.h"
#include "nautilus-lib-self-check-functions.h"
-
-#include <string.h>
+#include "nautilus-string.h"
#define GRADIENT_BAND_SIZE 4
@@ -194,9 +193,9 @@ nautilus_gradient_new (const char *start_color,
const char *end_color,
gboolean is_horizontal)
{
- g_return_val_if_fail (start_color != NULL, g_strdup (""));
- g_return_val_if_fail (end_color != NULL, g_strdup (""));
- g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, g_strdup (""));
+ g_return_val_if_fail (start_color != NULL, NULL);
+ g_return_val_if_fail (end_color != NULL, NULL);
+ g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, NULL);
/* Handle the special case where the start and end colors are identical.
Handle the special case where the end color is an empty string.
@@ -221,9 +220,22 @@ nautilus_gradient_new (const char *start_color,
gboolean
nautilus_gradient_is_gradient (const char *gradient_spec)
{
- g_return_val_if_fail (gradient_spec != NULL, FALSE);
+ return nautilus_strchr (gradient_spec, '-') != NULL;
+}
+
+/**
+ * nautilus_gradient_is_horizontal
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return true if the spec. specifies a horizontal gradient.
+ */
+gboolean
+nautilus_gradient_is_horizontal (const char *gradient_spec)
+{
+ size_t length;
- return strchr (gradient_spec, '-') != NULL;
+ length = nautilus_strlen (gradient_spec);
+ return length >= 2 && gradient_spec[length - 2] == ':' && gradient_spec[length - 1] == 'h';
}
static char *
@@ -231,9 +243,7 @@ nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
{
size_t length;
- g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
-
- length = strlen (gradient_spec);
+ length = nautilus_strlen (gradient_spec);
if (length >= 2 && gradient_spec[length - 2] == ':'
&& (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
length -= 2;
@@ -253,9 +263,7 @@ nautilus_gradient_get_start_color_spec (const char *gradient_spec)
{
const char *separator;
- g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
-
- separator = strchr (gradient_spec, '-');
+ separator = nautilus_strchr (gradient_spec, '-');
if (separator == NULL)
return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec);
@@ -274,9 +282,7 @@ nautilus_gradient_get_end_color_spec (const char *gradient_spec)
{
const char *separator;
- g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
-
- separator = strchr (gradient_spec, '-');
+ separator = nautilus_strchr (gradient_spec, '-');
return nautilus_gradient_strip_trailing_direction_if_any
(separator != NULL ? separator + 1 : gradient_spec);
}
@@ -291,7 +297,6 @@ nautilus_gradient_set_edge_color (const char *gradient_spec,
char *opposite_color;
char *result;
- g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec));
/* Get the color from the existing gradient spec. for the opposite
@@ -374,11 +379,35 @@ nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
return nautilus_gradient_set_edge_color (gradient_spec, bottom_color, FALSE, TRUE);
}
+/**
+ * nautilus_gdk_color_parse_with_white_default
+ * @color_spec: A color spec.
+ * @color: Pointer to place to put resulting color.
+ *
+ * The same as gdk_color_parse, except sets the color to white if
+ * the spec. can't be parsed instead of returning a boolean flag.
+ */
+void
+nautilus_gdk_color_parse_with_white_default (const char *color_spec,
+ GdkColor *color)
+{
+ if (!gdk_color_parse (color_spec, color)) {
+ color->red = 0xFFFF;
+ color->green = 0xFFFF;
+ color->blue = 0xFFFF;
+ }
+}
+
#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-#include <stdio.h>
+static char *
+nautilus_gdk_color_as_hex_string (GdkColor color)
+{
+ return g_strdup_printf("rgb:%04hX/%04hX/%04hX",
+ color.red, color.green, color.blue);
+}
-static GdkColor
+static char *
nautilus_self_check_interpolate (gdouble ratio,
gushort r1, gushort g1, gushort b1,
gushort r2, gushort g2, gushort b2)
@@ -397,25 +426,30 @@ nautilus_self_check_interpolate (gdouble ratio,
nautilus_interpolate_color (ratio, &start_color, &end_color, &interpolated_color);
- return interpolated_color;
+ return nautilus_gdk_color_as_hex_string (interpolated_color);
+}
+
+static char *
+nautilus_self_check_parse (const char *color_spec)
+{
+ GdkColor color;
+
+ nautilus_gdk_color_parse_with_white_default (color_spec, &color);
+ return nautilus_gdk_color_as_hex_string (color);
}
void
nautilus_self_check_gdk_extensions (void)
{
/* nautilus_interpolate_color */
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).red, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).green, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).blue, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0x7FFF);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0x7FFF);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0x7FFF);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0xFFFF);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0xFFFF);
- NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0xFFFF);
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0),
+ "rgb:0000/0000/0000");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
+ "rgb:0000/0000/0000");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
+ "rgb:7FFF/7FFF/7FFF");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
+ "rgb:FFFF/FFFF/FFFF");
/* nautilus_fill_rectangle */
/* Make a GdkImage and fill it, maybe? */
@@ -503,6 +537,13 @@ nautilus_self_check_gdk_extensions (void)
NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "b"), "a-b");
NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "c"), "a-c");
NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d");
+
+ /* nautilus_gdk_color_parse_with_white_default */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_parse (""), "rgb:FFFF/FFFF/FFFF");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_parse ("a"), "rgb:FFFF/FFFF/FFFF");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_parse ("white"), "rgb:FFFF/FFFF/FFFF");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_parse ("black"), "rgb:0000/0000/0000");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_parse ("rgb:0123/4567/89AB"), "rgb:0123/4567/89AB");
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus/gdk-extensions.h b/libnautilus/gdk-extensions.h
index 8ecadf853..f5dd0c27b 100644
--- a/libnautilus/gdk-extensions.h
+++ b/libnautilus/gdk-extensions.h
@@ -32,44 +32,53 @@
The gradient is vertical by default and the spec. can end with ":v" to indicate that.
If the gradient ends with ":h", the gradient is horizontal.
*/
-char * nautilus_gradient_new (const char *start_color,
- const char *end_color,
- gboolean is_horizontal);
+char * nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal);
-gboolean nautilus_gradient_is_gradient (const char *gradient_spec);
-char * nautilus_gradient_get_start_color_spec (const char *gradient_spec);
-char * nautilus_gradient_get_end_color_spec (const char *gradient_spec);
-gboolean nautilus_gradient_is_horizontal (const char *gradient_spec);
+gboolean nautilus_gradient_is_gradient (const char *gradient_spec);
+char * nautilus_gradient_get_start_color_spec (const char *gradient_spec);
+char * nautilus_gradient_get_end_color_spec (const char *gradient_spec);
+gboolean nautilus_gradient_is_horizontal (const char *gradient_spec);
-char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
- const char *left_color);
-char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
- const char *top_color);
-char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
- const char *right_color);
-char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
- const char *bottom_color);
+char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color);
+char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color);
+char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color);
+char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color);
-/* Fill routines that take GdkRectangle parameters instead of four coordinates. */
-void nautilus_fill_rectangle (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle);
-void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle,
- const GdkColor *color);
-void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
- GdkGC *gc,
- GdkColormap *colormap,
- const GdkRectangle *rectangle,
- const GdkColor *start_color,
- const GdkColor *end_color,
- gboolean horizontal_gradient);
+/* A version of parse_color that substitutes a default color instead of returning
+ a boolean to indicate it cannot be parsed.
+*/
+void nautilus_gdk_color_parse_with_default (const char *color_spec,
+ const GdkColor *default_color,
+ GdkColor *color);
+void nautilus_gdk_color_parse_with_white_default (const char *color_spec,
+ GdkColor *color);
+
+/* Fill routines that take GdkRectangle parameters instead of four integers. */
+void nautilus_fill_rectangle (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle);
+void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle,
+ const GdkColor *color);
+void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ gboolean horizontal_gradient);
-/* A basic operation needed for drawing gradients is interpolating two colors.*/
-void nautilus_interpolate_color (gdouble ratio,
- const GdkColor *start_color,
- const GdkColor *end_color,
- GdkColor *interpolated_color);
+/* A basic operation we use for drawing gradients is interpolating two colors.*/
+void nautilus_interpolate_color (gdouble ratio,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ GdkColor *interpolated_color);
#endif /* GDK_EXTENSIONS_H */
diff --git a/libnautilus/nautilus-background-canvas-group.c b/libnautilus/nautilus-background-canvas-group.c
new file mode 100644
index 000000000..d3cef3e2c
--- /dev/null
+++ b/libnautilus/nautilus-background-canvas-group.c
@@ -0,0 +1,154 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-background.c: Object for the background of a widget.
+
+ Copyright (C) 2000 Eazel, 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.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "nautilus-background-canvas-group.h"
+
+#include <libgnomeui/gnome-canvas.h>
+#include "nautilus-background.h"
+#include "nautilus-gtk-macros.h"
+
+static void nautilus_background_canvas_group_initialize_class (gpointer klass);
+static void nautilus_background_canvas_group_initialize (gpointer object, gpointer klass);
+static void nautilus_background_canvas_group_destroy (GtkObject *object);
+static void nautilus_background_canvas_group_finalize (GtkObject *object);
+static void nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+ int x, int y, int width, int height);
+
+NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusBackgroundCanvasGroup, nautilus_background_canvas_group, GNOME_TYPE_CANVAS_GROUP)
+
+static GtkObjectClass *parent_class;
+
+static void
+nautilus_background_canvas_group_initialize_class (gpointer klass)
+{
+ GtkObjectClass *object_class;
+ GnomeCanvasItemClass *canvas_item_class;
+
+ object_class = GTK_OBJECT_CLASS (klass);
+ canvas_item_class = GNOME_CANVAS_ITEM_CLASS (klass);
+ parent_class = gtk_type_class (GNOME_TYPE_CANVAS_GROUP);
+
+ object_class->destroy = nautilus_background_canvas_group_destroy;
+ object_class->finalize = nautilus_background_canvas_group_finalize;
+
+ canvas_item_class->draw = nautilus_background_canvas_group_draw;
+}
+
+static void
+nautilus_background_canvas_group_initialize (gpointer object, gpointer klass)
+{
+}
+
+static void
+nautilus_background_canvas_group_destroy (GtkObject *object)
+{
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_background_canvas_group_finalize (GtkObject *object)
+{
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
+}
+
+static void
+nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+ int drawable_corner_x, int drawable_corner_y,
+ int drawable_width, int drawable_height)
+{
+ NautilusBackground *background;
+
+ /* Draw the background. */
+ background = nautilus_background_canvas_group_get_background
+ (NAUTILUS_BACKGROUND_CANVAS_GROUP (item));
+ if (background != NULL) {
+ GdkGC *gc;
+ GdkColormap *colormap;
+ GdkRectangle rectangle;
+
+ /* Create a new gc each time.
+ If this is a speed problem, we can create one and keep it around,
+ but it's a bit more complicated to ensure that it's always compatible
+ with whatever drawable is passed in to use.
+ */
+ gc = gdk_gc_new (drawable);
+
+ colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas));
+
+ /* The rectangle is the size of the entire viewed area of the canvas.
+ The corner is determined by the current scroll position of the
+ GtkLayout, and the size is determined by the current size of the widget.
+ Since 0,0 is the corner of the drawable, we need to offset the rectangle
+ so it's relative to the drawable's coordinates.
+ */
+ rectangle.x = GTK_LAYOUT (item->canvas)->xoffset - drawable_corner_x;
+ rectangle.y = GTK_LAYOUT (item->canvas)->yoffset - drawable_corner_y;
+ rectangle.width = GTK_WIDGET (item->canvas)->allocation.width;
+ rectangle.height = GTK_WIDGET (item->canvas)->allocation.height;
+
+ nautilus_background_draw (background, drawable, gc, colormap, &rectangle);
+
+ gdk_gc_unref (gc);
+ }
+
+ /* Call through to the GnomeCanvasGroup implementation, which will draw all
+ the canvas items.
+ */
+ NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, draw,
+ (item, drawable,
+ 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));
+}
diff --git a/libnautilus/nautilus-background-canvas-group.h b/libnautilus/nautilus-background-canvas-group.h
new file mode 100644
index 000000000..b0449f786
--- /dev/null
+++ b/libnautilus/nautilus-background-canvas-group.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-background-canvas-group.h: Class used internally by
+ NautilusBackground to add a background to a canvas.
+
+ Copyright (C) 2000 Eazel, 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.
+
+ Authors: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_BACKGROUND_CANVAS_GROUP_H
+#define NAUTILUS_BACKGROUND_CANVAS_GROUP_H
+
+#include "nautilus-background.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
+ that the cleanest way to hook into the code that erases the canvas is to be the
+ root canvas group. But the canvas class creates the root object and doesn't allow
+ it to be destroyed, so we change the class of the root object in place.
+
+ A future version of GnomeCanvas may allow a nicer way of hooking in to the code
+ that draws the background, and then we can get rid of this class.
+
+ This class is private to NautilusBackground.
+*/
+
+typedef GnomeCanvasGroup NautilusBackgroundCanvasGroup;
+typedef GnomeCanvasGroupClass NautilusBackgroundCanvasGroupClass;
+
+#define NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP \
+ (nautilus_background_canvas_group_get_type ())
+#define NAUTILUS_BACKGROUND_CANVAS_GROUP(obj) \
+ (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP, NautilusBackgroundCanvasGroup))
+#define NAUTILUS_BACKGROUND_CANVAS_GROUP_CLASS(klass) \
+ (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP, NautilusBackgroundCanvasGroupClass))
+#define NAUTILUS_IS_BACKGROUND_CANVAS_GROUP(obj) \
+ (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP))
+#define NAUTILUS_IS_BACKGROUND_CANVAS_GROUP_CLASS(klass) \
+ (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 */
diff --git a/libnautilus/nautilus-background.c b/libnautilus/nautilus-background.c
new file mode 100644
index 000000000..35afd8bc1
--- /dev/null
+++ b/libnautilus/nautilus-background.c
@@ -0,0 +1,202 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-background.c: Object for the background of a widget.
+
+ Copyright (C) 2000 Eazel, 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.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "nautilus-background.h"
+
+#include <gtk/gtksignal.h>
+#include "gdk-extensions.h"
+#include "nautilus-background-canvas-group.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-gtk-macros.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);
+
+NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusBackground, nautilus_background, GTK_TYPE_OBJECT)
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+static GtkObjectClass *parent_class;
+static guint signals[LAST_SIGNAL];
+
+struct _NautilusBackgroundDetails
+{
+ char *color;
+ char *tile_image_uri;
+};
+
+static void
+nautilus_background_initialize_class (gpointer klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = GTK_OBJECT_CLASS (klass);
+
+ parent_class = gtk_type_class (GTK_TYPE_OBJECT);
+
+ signals[CHANGED] =
+ gtk_signal_new ("changed",
+ GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (NautilusBackgroundClass, changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE,
+ 0);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+
+ object_class->destroy = nautilus_background_destroy;
+ object_class->finalize = nautilus_background_finalize;
+}
+
+static void
+nautilus_background_initialize (gpointer object, gpointer klass)
+{
+ NautilusBackground *background;
+
+ background = NAUTILUS_BACKGROUND(object);
+
+ background->details = g_new0 (NautilusBackgroundDetails, 1);
+}
+
+static void
+nautilus_background_destroy (GtkObject *object)
+{
+ NautilusBackground *background;
+
+ background = NAUTILUS_BACKGROUND (object);
+
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_background_finalize (GtkObject *object)
+{
+ NautilusBackground *background;
+
+ background = NAUTILUS_BACKGROUND (object);
+ g_free (background->details);
+
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
+}
+
+NautilusBackground *
+nautilus_background_new (void)
+{
+ return NAUTILUS_BACKGROUND (gtk_type_new (NAUTILUS_TYPE_BACKGROUND));
+}
+
+void
+nautilus_background_draw (NautilusBackground *background,
+ GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle)
+{
+ char *start_color_spec;
+ char *end_color_spec;
+ GdkColor start_color;
+ GdkColor end_color;
+ gboolean horizontal_gradient;
+
+ start_color_spec = nautilus_gradient_get_start_color_spec (background->details->color);
+ end_color_spec = nautilus_gradient_get_end_color_spec (background->details->color);
+ horizontal_gradient = nautilus_gradient_is_horizontal (background->details->color);
+
+ nautilus_gdk_color_parse_with_white_default (start_color_spec, &start_color);
+ nautilus_gdk_color_parse_with_white_default (end_color_spec, &end_color);
+
+ g_free (start_color_spec);
+ g_free (end_color_spec);
+
+ nautilus_fill_rectangle_with_gradient (drawable, gc, colormap, rectangle,
+ &start_color, &end_color, horizontal_gradient);
+}
+
+void
+nautilus_background_set_color (NautilusBackground *background,
+ const char *color)
+{
+ g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
+
+ g_free (background->details->color);
+ background->details->color = g_strdup (color);
+
+ gtk_signal_emit (GTK_OBJECT (background), signals[CHANGED]);
+}
+
+void
+nautilus_background_attach_to_canvas (NautilusBackground *background,
+ GnomeCanvas *canvas)
+{
+ /* 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
+ anything related to scrolling.
+
+ We settled on this after less-than-thrilling results using a
+ canvas item as the background. The canvas item contributed to
+ the bounds of the canvas and had to constantly be resized.
+ */
+
+ g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
+ g_return_if_fail (GNOME_IS_CANVAS (canvas));
+
+ 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));
+
+ GTK_OBJECT (canvas->root)->klass = gtk_type_class (NAUTILUS_TYPE_BACKGROUND_CANVAS_GROUP);
+
+ nautilus_background_canvas_group_set_background (NAUTILUS_BACKGROUND_CANVAS_GROUP (canvas->root), background);
+}
+
+/* self check code */
+
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+void
+nautilus_self_check_background (void)
+{
+ NautilusBackground *background;
+
+ background = nautilus_background_new ();
+
+ nautilus_background_set_color (background, NULL);
+ nautilus_background_set_color (background, "");
+ nautilus_background_set_color (background, "red");
+ nautilus_background_set_color (background, "red-blue");
+ nautilus_background_set_color (background, "red-blue:h");
+}
+
+#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus/nautilus-background.h b/libnautilus/nautilus-background.h
new file mode 100644
index 000000000..e95a359b1
--- /dev/null
+++ b/libnautilus/nautilus-background.h
@@ -0,0 +1,95 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-background.h: Object for the background of a widget.
+
+ Copyright (C) 2000 Eazel, 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.
+
+ Authors: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_BACKGROUND_H
+#define NAUTILUS_BACKGROUND_H
+
+/* Windows for Nautilus can contain backgrounds that are either tiled
+ with an image, a solid color, or a color gradient. This class manages
+ the process of loading the image if necessary and parsing the string
+ that specifies either a color or color gradient.
+
+ 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).
+*/
+
+#include <gdk/gdktypes.h>
+#include <libgnomeui/gnome-canvas.h>
+
+typedef struct _NautilusBackground NautilusBackground;
+typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
+
+#define NAUTILUS_TYPE_BACKGROUND \
+ (nautilus_background_get_type ())
+#define NAUTILUS_BACKGROUND(obj) \
+ (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_BACKGROUND, NautilusBackground))
+#define NAUTILUS_BACKGROUND_CLASS(klass) \
+ (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_BACKGROUND, NautilusBackgroundClass))
+#define NAUTILUS_IS_BACKGROUND(obj) \
+ (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_BACKGROUND))
+#define NAUTILUS_IS_BACKGROUND_CLASS(klass) \
+ (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND))
+
+GtkType nautilus_background_get_type (void);
+NautilusBackground *nautilus_background_new (void);
+
+void nautilus_background_set_color (NautilusBackground *background,
+ const char *color_or_gradient);
+void nautilus_background_set_tile_image_uri (NautilusBackground *background,
+ const char *image_uri);
+
+char * nautilus_background_get_color (NautilusBackground *background);
+char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
+
+void nautilus_background_draw (NautilusBackground *background,
+ GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle);
+
+void nautilus_background_attach_to_canvas (NautilusBackground *background,
+ GnomeCanvas *canvas);
+
+
+typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;
+
+struct _NautilusBackground
+{
+ GtkObject object;
+ NautilusBackgroundDetails *details;
+};
+
+struct _NautilusBackgroundClass
+{
+ GtkObjectClass parent_class;
+
+ /* This signal is emitted when the background image is
+ finished loading. This allows a window to draw with a
+ color background if the image takes a lot time to load.
+ */
+ void (* changed) (NautilusBackground *);
+};
+
+#endif /* NAUTILUS_BACKGROUND_H */
diff --git a/libnautilus/nautilus-lib-self-check-functions.c b/libnautilus/nautilus-lib-self-check-functions.c
index 3e8d2e21e..8fd904042 100644
--- a/libnautilus/nautilus-lib-self-check-functions.c
+++ b/libnautilus/nautilus-lib-self-check-functions.c
@@ -33,6 +33,7 @@
void nautilus_run_lib_self_checks ()
{
+ nautilus_self_check_background ();
nautilus_self_check_gdk_extensions ();
}
diff --git a/libnautilus/nautilus-lib-self-check-functions.h b/libnautilus/nautilus-lib-self-check-functions.h
index dc9ada13a..2b68bd8d6 100644
--- a/libnautilus/nautilus-lib-self-check-functions.h
+++ b/libnautilus/nautilus-lib-self-check-functions.h
@@ -36,3 +36,4 @@ void nautilus_run_lib_self_checks (void);
*/
void nautilus_self_check_gdk_extensions (void);
+void nautilus_self_check_background (void);
diff --git a/libnautilus/nautilus-string.c b/libnautilus/nautilus-string.c
new file mode 100644
index 000000000..02834386b
--- /dev/null
+++ b/libnautilus/nautilus-string.c
@@ -0,0 +1,48 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string.c: String routines to augment <string.h>.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "nautilus-string.h"
+
+size_t
+nautilus_strlen (const char *string_null_allowed)
+{
+ return string_null_allowed == NULL ? 0 : strlen (string_null_allowed);
+}
+
+char *
+nautilus_strchr (const char *haystack_null_allowed, char needle)
+{
+ return haystack_null_allowed == NULL ? NULL : strchr (haystack_null_allowed, needle);
+}
+
+int
+nautilus_strcmp (const char *string_a_null_allowed, const char *string_b_null_allowed)
+{
+ return strcmp (string_a_null_allowed == NULL ? "" : string_a_null_allowed,
+ string_b_null_allowed == NULL ? "" : string_b_null_allowed);
+}
diff --git a/libnautilus/nautilus-string.h b/libnautilus/nautilus-string.h
new file mode 100644
index 000000000..fc0dbe36c
--- /dev/null
+++ b/libnautilus/nautilus-string.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string.h: String routines to augment <string.h>.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_STRING_H
+#define NAUTILUS_STRING_H
+
+#include <string.h>
+
+/* Versions of basic string functions that allow NULL. */
+size_t nautilus_strlen (const char *string_null_allowed);
+char * nautilus_strchr (const char *haystack_null_allowed,
+ char needle);
+int nautilus_strcmp (const char *string_a_null_allowed,
+ const char *string_b_null_allowed);
+
+#endif /* NAUTILUS_STRING_H */