summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-viewport.c
blob: 898bab8c055407e75cde198ebaf1a6514b74087d (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-viewport.c - A subclass of GtkViewport with non broken drawing.

   Copyright (C) 1999, 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: Ramiro Estrugo <ramiro@eazel.com>
*/

#include <config.h>

#include "nautilus-viewport.h"

#include "nautilus-gtk-macros.h"

/* GtkObjectClass methods */
static void nautilus_viewport_initialize_class (NautilusViewportClass *viewport_class);
static void nautilus_viewport_initialize       (NautilusViewport      *viewport);
static void nautilus_viewport_draw             (GtkWidget             *widget,
						GdkRectangle          *area);

static void nautilus_viewport_paint            (GtkWidget             *widget,
						GdkRectangle          *area);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusViewport, nautilus_viewport, GTK_TYPE_VIEWPORT)

/* Class init methods */
static void
nautilus_viewport_initialize_class (NautilusViewportClass *viewport_class)
{
	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (viewport_class);
	
	/* GtkWidgetClass */
	widget_class->draw = nautilus_viewport_draw;
}

void
nautilus_viewport_initialize (NautilusViewport *viewport)
{
	/* noop */
}

static void
nautilus_viewport_draw (GtkWidget *widget,
			GdkRectangle *area)
{
	GtkViewport *viewport;
	GtkBin *bin;
	GdkRectangle tmp_area;
	GdkRectangle child_area;
	gint border_width;
	
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_VIEWPORT (widget));
	g_return_if_fail (area != NULL);
	
	if (GTK_WIDGET_DRAWABLE (widget)) {
		viewport = GTK_VIEWPORT (widget);
		bin = GTK_BIN (widget);
		
		border_width = GTK_CONTAINER (widget)->border_width;
		
		tmp_area = *area;
		tmp_area.x -= border_width;
		tmp_area.y -= border_width;
		
		nautilus_viewport_paint (widget, &tmp_area);
		
		tmp_area.x += viewport->hadjustment->value - widget->style->klass->xthickness;
		tmp_area.y += viewport->vadjustment->value - widget->style->klass->ythickness;

		/* The gtk_viewport_draw() version does not adjust the width
		 * and height of the tmp_area for the class x/y thickness.  This
		 * causes some drawing to be clipped on the bottom.  This is a bug
		 * in GTK+.
		 */

		/* FIXME bugzilla.eazel.com xxxx: 
		 * Remove this widget once the fix makes it to GTK+.
		 */
		tmp_area.width += 2 * widget->style->klass->xthickness;
		tmp_area.height += 2 * widget->style->klass->ythickness;
		
		gtk_paint_flat_box(widget->style, viewport->bin_window, 
				   GTK_STATE_NORMAL, GTK_SHADOW_NONE,
				   &tmp_area, widget, "viewportbin",
				   0, 0, -1, -1);
		
		if (bin->child) {
			if (gtk_widget_intersect (bin->child, &tmp_area, &child_area)) {
				gtk_widget_draw (bin->child, &child_area);
			}
		}
	}
}

static void
nautilus_viewport_paint (GtkWidget *widget,
			 GdkRectangle *area)
{
  GtkViewport *viewport;

  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_VIEWPORT (widget));
  g_return_if_fail (area != NULL);

  if (GTK_WIDGET_DRAWABLE (widget))
    {
      viewport = GTK_VIEWPORT (widget);

      gtk_draw_shadow (widget->style, widget->window,
		       GTK_STATE_NORMAL, viewport->shadow_type,
		       0, 0, -1, -1);
    }
}

/* Public NautilusViewport methods */
GtkWidget*
nautilus_viewport_new (GtkAdjustment *hadjustment,
		       GtkAdjustment *vadjustment)
{
	NautilusViewport *viewport;

	viewport = NAUTILUS_VIEWPORT (gtk_widget_new (nautilus_viewport_get_type (), NULL));
	
	gtk_viewport_set_hadjustment (GTK_VIEWPORT (viewport), hadjustment);
	gtk_viewport_set_vadjustment (GTK_VIEWPORT (viewport), vadjustment);

	return GTK_WIDGET (viewport);
}