summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-background-canvas-group.c
blob: 06cb28b8e9d965d17f1d5fca7e5867934239092d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* -*- 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>
*/

#include <config.h>
#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_CLASS_BOILERPLATE (NautilusBackgroundCanvasGroup, nautilus_background_canvas_group, GNOME_TYPE_CANVAS_GROUP)

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);
	
	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_get_widget_background(GTK_WIDGET (item->canvas));
	if (background != NULL) {
		GdkGC *gc;
		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.
		*/
		gc = gdk_gc_new (drawable);

		/* 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, &rectangle,
					  -drawable_corner_x, -drawable_corner_y);

		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));
}