Commit c912e1ef authored by Darin Adler's avatar Darin Adler
Browse files

Added NautilusBackground class, string functions that allow NULL, made

gradient functions allow NULL and treat it as an empty string, added
gdk_color_parse variants that have a default color, cleanup of
NautilusIndexPanel, and some other minor stuff.
parent c5864f04
2000-01-10 Darin Adler <darin@eazel.com>
* libnautilus/Makefile.am, libnautilus/nautilus-background.h,
libnautilus/nautilus-background.c,
libnautilus/nautilus-background-canvas-group.h,
libnautilus/nautilus-background-canvas-group.c,
libnautilus/nautilus-lib-self-check-functions.h,
libnautilus/nautilus-lib-self-check-functions.c: Added first cut
at a new class to manage backgrounds that can be colors, color
gradients, or tiled images.
* libnautilus/Makefile.am, libnautilus/nautilus-string.h,
libnautilus/nautilus-string.c: Added functions that manipulate
strings that allow NULLs to reduce NULL checks in code that
treats NULL the same as an empty string.
* libnautilus/gdk_extensions.c: (nautilus_gradient_new):
(nautilus_gradient_is_gradient):
(nautilus_gradient_is_horizontal):
(nautilus_gradient_strip_trailing_direction_if_any):
(nautilus_gradient_get_start_color_spec):
(nautilus_gradient_get_end_color_spec):
(nautilus_gradient_set_edge_color): Changed gradient functions to
allow NULL and treat it the same as an empty string.
* libnautilus/gdk_extensions.h: libnautilus/gdk_extensions.c:
(nautilus_gdk_color_parse_with_default):
(nautilus_gdk_color_parse_with_white_default): Added alternate
version of gdk_color_parse that uses a default color instead of
just returning false. Added self-checks and updated some existing
self checks at the same time.
* src/ntl-index-panel.h, src/ntl-index-panel.c: Wholesale
cleanup and reformatting of NautilusIndexPanel. Fixed a number of
bugs, including storage leaks, and took first step toward using
NautilusBackground class.
* src/ntl-window.c: (nautilus_window_get_requested_uri):
Changed this so it works when window->ni is NULL.
* src/ntl-window.h: Changed index_panel to be a NautilusIndexPanel
now that the index panel interface uses the class instead of using
GtkWidget everywhere.
* src/file-manager/.cvsignore: Added *.la.
* src/file-manager/fm-directory.c: Minor reformatting to match
GNOME code style better.
2000-01-10 John Sullivan <sullivan@eazel.com> 2000-01-10 John Sullivan <sullivan@eazel.com>
* src/ntl-index-panel.c: (nautilus_index_panel_set_up_label): * src/ntl-index-panel.c: (nautilus_index_panel_set_up_label):
......
...@@ -22,10 +22,12 @@ libnautilusinclude_HEADERS= \ ...@@ -22,10 +22,12 @@ libnautilusinclude_HEADERS= \
gtkflist.h \ gtkflist.h \
gtkscrollframe.h \ gtkscrollframe.h \
nautilus.h \ nautilus.h \
nautilus-background.h \
nautilus-file-utilities.h \ nautilus-file-utilities.h \
nautilus-gtk-extensions.h \ nautilus-gtk-extensions.h \
nautilus-lib-self-check-functions.h \ nautilus-lib-self-check-functions.h \
nautilus-self-checks.h \ nautilus-self-checks.h \
nautilus-string.h \
ntl-content-view-client.h \ ntl-content-view-client.h \
ntl-meta-view-client.h \ ntl-meta-view-client.h \
ntl-view-client.h ntl-view-client.h
...@@ -37,10 +39,13 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \ ...@@ -37,10 +39,13 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gnome-icon-container.c \ gnome-icon-container.c \
gtkflist.c \ gtkflist.c \
gtkscrollframe.c \ gtkscrollframe.c \
nautilus-background.c \
nautilus-background-canvas-group.c \
nautilus-file-utilities.c \ nautilus-file-utilities.c \
nautilus-gtk-extensions.c \ nautilus-gtk-extensions.c \
nautilus-lib-self-check-functions.c \ nautilus-lib-self-check-functions.c \
nautilus-self-checks.c \ nautilus-self-checks.c \
nautilus-string.c \
ntl-content-view-client.c \ ntl-content-view-client.c \
ntl-meta-view-client.c \ ntl-meta-view-client.c \
ntl-view-client.c \ ntl-view-client.c \
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
#include "gdk-extensions.h" #include "gdk-extensions.h"
#include "nautilus-lib-self-check-functions.h" #include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#include <string.h>
#define GRADIENT_BAND_SIZE 4 #define GRADIENT_BAND_SIZE 4
...@@ -194,9 +193,9 @@ nautilus_gradient_new (const char *start_color, ...@@ -194,9 +193,9 @@ nautilus_gradient_new (const char *start_color,
const char *end_color, const char *end_color,
gboolean is_horizontal) gboolean is_horizontal)
{ {
g_return_val_if_fail (start_color != NULL, g_strdup ("")); g_return_val_if_fail (start_color != NULL, NULL);
g_return_val_if_fail (end_color != NULL, g_strdup ("")); g_return_val_if_fail (end_color != NULL, NULL);
g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, g_strdup ("")); 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 start and end colors are identical.
Handle the special case where the end color is an empty string. Handle the special case where the end color is an empty string.
...@@ -221,9 +220,22 @@ nautilus_gradient_new (const char *start_color, ...@@ -221,9 +220,22 @@ nautilus_gradient_new (const char *start_color,
gboolean gboolean
nautilus_gradient_is_gradient (const char *gradient_spec) 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 * static char *
...@@ -231,9 +243,7 @@ nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec) ...@@ -231,9 +243,7 @@ nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
{ {
size_t length; size_t length;
g_return_val_if_fail (gradient_spec != NULL, g_strdup ("")); length = nautilus_strlen (gradient_spec);
length = strlen (gradient_spec);
if (length >= 2 && gradient_spec[length - 2] == ':' if (length >= 2 && gradient_spec[length - 2] == ':'
&& (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h')) && (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
length -= 2; length -= 2;
...@@ -253,9 +263,7 @@ nautilus_gradient_get_start_color_spec (const char *gradient_spec) ...@@ -253,9 +263,7 @@ nautilus_gradient_get_start_color_spec (const char *gradient_spec)
{ {
const char *separator; const char *separator;
g_return_val_if_fail (gradient_spec != NULL, g_strdup ("")); separator = nautilus_strchr (gradient_spec, '-');
separator = strchr (gradient_spec, '-');
if (separator == NULL) if (separator == NULL)
return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec); return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec);
...@@ -274,9 +282,7 @@ nautilus_gradient_get_end_color_spec (const char *gradient_spec) ...@@ -274,9 +282,7 @@ nautilus_gradient_get_end_color_spec (const char *gradient_spec)
{ {
const char *separator; const char *separator;
g_return_val_if_fail (gradient_spec != NULL, g_strdup ("")); separator = nautilus_strchr (gradient_spec, '-');
separator = strchr (gradient_spec, '-');
return nautilus_gradient_strip_trailing_direction_if_any return nautilus_gradient_strip_trailing_direction_if_any
(separator != NULL ? separator + 1 : gradient_spec); (separator != NULL ? separator + 1 : gradient_spec);
} }
...@@ -291,7 +297,6 @@ nautilus_gradient_set_edge_color (const char *gradient_spec, ...@@ -291,7 +297,6 @@ nautilus_gradient_set_edge_color (const char *gradient_spec,
char *opposite_color; char *opposite_color;
char *result; char *result;
g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec)); g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec));
/* Get the color from the existing gradient spec. for the opposite /* 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, ...@@ -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); 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) #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, nautilus_self_check_interpolate (gdouble ratio,
gushort r1, gushort g1, gushort b1, gushort r1, gushort g1, gushort b1,
gushort r2, gushort g2, gushort b2) gushort r2, gushort g2, gushort b2)
...@@ -397,25 +426,30 @@ nautilus_self_check_interpolate (gdouble ratio, ...@@ -397,25 +426,30 @@ nautilus_self_check_interpolate (gdouble ratio,
nautilus_interpolate_color (ratio, &start_color, &end_color, &interpolated_color); 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 void
nautilus_self_check_gdk_extensions (void) nautilus_self_check_gdk_extensions (void)
{ {
/* nautilus_interpolate_color */ /* nautilus_interpolate_color */
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).red, 0); NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0),
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).green, 0); "rgb:0000/0000/0000");
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).blue, 0); NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0); "rgb:0000/0000/0000");
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0); NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0); "rgb:7FFF/7FFF/7FFF");
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0x7FFF); NAUTILUS_CHECK_STRING_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF),
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0x7FFF); "rgb:FFFF/FFFF/FFFF");
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_fill_rectangle */ /* nautilus_fill_rectangle */
/* Make a GdkImage and fill it, maybe? */ /* Make a GdkImage and fill it, maybe? */
...@@ -503,6 +537,13 @@ nautilus_self_check_gdk_extensions (void) ...@@ -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", "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-c:v", "c"), "a-c");
NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d"); 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 */ #endif /* ! NAUTILUS_OMIT_SELF_CHECK */
...@@ -32,44 +32,53 @@ ...@@ -32,44 +32,53 @@
The gradient is vertical by default and the spec. can end with ":v" to indicate that. 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. If the gradient ends with ":h", the gradient is horizontal.
*/ */
char * nautilus_gradient_new (const char *start_color, char * nautilus_gradient_new (const char *start_color,
const char *end_color, const char *end_color,
gboolean is_horizontal); gboolean is_horizontal);
gboolean nautilus_gradient_is_gradient (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_start_color_spec (const char *gradient_spec);
char * nautilus_gradient_get_end_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_horizontal (const char *gradient_spec);
char * nautilus_gradient_set_left_color_spec (const char *gradient_spec, char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
const char *left_color); const char *left_color);
char * nautilus_gradient_set_top_color_spec (const char *gradient_spec, char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
const char *top_color); const char *top_color);
char * nautilus_gradient_set_right_color_spec (const char *gradient_spec, char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
const char *right_color); const char *right_color);
char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec, char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
const char *bottom_color); const char *bottom_color);
/* Fill routines that take GdkRectangle parameters instead of four coordinates. */ /* A version of parse_color that substitutes a default color instead of returning
void nautilus_fill_rectangle (GdkDrawable *drawable, a boolean to indicate it cannot be parsed.
GdkGC *gc, */
const GdkRectangle *rectangle); void nautilus_gdk_color_parse_with_default (const char *color_spec,
void nautilus_fill_rectangle_with_color (GdkDrawable *drawable, const GdkColor *default_color,
GdkGC *gc, GdkColor *color);
const GdkRectangle *rectangle, void nautilus_gdk_color_parse_with_white_default (const char *color_spec,
const GdkColor *color); GdkColor *color);
void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
GdkGC *gc, /* Fill routines that take GdkRectangle parameters instead of four integers. */
GdkColormap *colormap, void nautilus_fill_rectangle (GdkDrawable *drawable,
const GdkRectangle *rectangle, GdkGC *gc,
const GdkColor *start_color, const GdkRectangle *rectangle);
const GdkColor *end_color, void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
gboolean horizontal_gradient); 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.*/ /* A basic operation we use for drawing gradients is interpolating two colors.*/
void nautilus_interpolate_color (gdouble ratio, void nautilus_interpolate_color (gdouble ratio,
const GdkColor *start_color, const GdkColor *start_color,
const GdkColor *end_color, const GdkColor *end_color,
GdkColor *interpolated_color); GdkColor *interpolated_color);
#endif /* GDK_EXTENSIONS_H */ #endif /* GDK_EXTENSIONS_H */
/* -*- 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));
}
/* -*- 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>
*/