Commit 291fb2d6 authored by Darin Adler's avatar Darin Adler

Redid the icon factory to fix a few things:

	* libnautilus/nautilus-icon-factory.c:
	Redid the icon factory to fix a few things:

	- Replaced the existing non-working count-based LRU algorithm with
	  one that works (uses a linked list).
	- Keep resized icons in the cache.
	- Hand out a single NautilusScalableIcon when multiple callers ask
	  for the same icon instead of a new one each time.
	- Fixed one bug where pixbuf's would get an extra ref and never get
	  freed once they are no longer used.

	* libnautilus/nautilus-metadata.h:
	* src/nautilus-index-title.c (nautilus_index_title_set_up_info):
	* libnautilus/nautilus-icon-factory.c
	(nautilus_icon_factory_get_icon_for_file):
	Added keys for the two pieces of metadata Andy just added.

	* libnautilus/gnome-icon-container-private.h:
	* libnautilus/gnome-icon-container.c: (scroll),
	(make_icon_visible), (set_scroll_region): Fixed the code that
	resizes the canvas as items are added and removed to properly
	handle the case where the canvas extends into negative-coordinate
	territory. This included removing the width and height that were
	stored in the private structure.

	* libnautilus/nautilus-directory.c: (nautilus_directory_get): Tiny
	formatting tweak.
parent 6db4c052
2000-02-14 Darin Adler <darin@eazel.com>
* libnautilus/nautilus-icon-factory.c:
Redid the icon factory to fix a few things:
- Replaced the existing non-working count-based LRU algorithm with
one that works (uses a linked list).
- Keep resized icons in the cache.
- Hand out a single NautilusScalableIcon when multiple callers ask
for the same icon instead of a new one each time.
- Fixed one bug where pixbuf's would get an extra ref and never get
freed once they are no longer used.
* libnautilus/nautilus-metadata.h:
* src/nautilus-index-title.c (nautilus_index_title_set_up_info):
* libnautilus/nautilus-icon-factory.c
(nautilus_icon_factory_get_icon_for_file):
Added keys for the two pieces of metadata Andy just added.
* libnautilus/gnome-icon-container-private.h:
* libnautilus/gnome-icon-container.c: (scroll),
(make_icon_visible), (set_scroll_region): Fixed the code that
resizes the canvas as items are added and removed to properly
handle the case where the canvas extends into negative-coordinate
territory. This included removing the width and height that were
stored in the private structure.
* libnautilus/nautilus-directory.c: (nautilus_directory_get): Tiny
formatting tweak.
2000-02-14 John Sullivan <sullivan@eazel.com>
Fixed index title bugs that showed up when visiting http:// url.
......@@ -42,7 +72,6 @@
(fm_directory_view_list_set_zoom_level): Pass default_zoom_level
to metadata call, also reset default_zoom_level to new level.
2000-02-14 Elliot Lee <sopwith@redhat.com>
* components/html/ntl-web-browser.c: Send status strings for now,
......@@ -50,27 +79,30 @@
2000-02-14 Andy Hertzfeld <andy@eazel.com>
*src/nautilus-index-tabs.c:
* src/nautilus-index-tabs.c:
Fixed warning about measuring NULL string that Elliot pointed out
2000-02-14 Elliot Lee <sopwith@redhat.com>
* src/ntl-window-msgs.c: Revert.
* components/help/hyperbola-nav-index.c: More work.
2000-02-13 Andy Hertzfeld <andy@eazel.com>
* libnautilus/nautilus-icon-factory.c:
made it use custom image specified in meta-data, if present.
also, upped the size used for displaying images as themselves without thumbnails,
from 10K to 16K.
Made it use custom image specified in meta-data, if present.
also, upped the size used for displaying images as themselves
without thumbnails, from 10K to 16K.
* src/nautilus-index-title.c:
display "notes" from metadata in index panel if present
Display "notes" from metadata in index panel if present.
* src/ntl-index-panel.c:
fiddled with drag and drop code trying to get it to accept image files, not yet working
Fiddled with drag and drop code trying to get it to accept
image files, not yet working
2000-02-13 Andy Hertzfeld <andy@eazel.com>
made nautilus-index-title widget to hold the title information for the index panel
Made nautilus-index-title widget to hold the title information
for the index panel.
* src/ntl-index-panel.c:
allocated index-title to display info, removed old code that did it
......@@ -85,11 +117,11 @@
* src/nautilus-index-tabs.c:
made the tabs layout be more dynamic, laying out as many
tabs as fit in a row instead of a maximum of two. Tightened
tabs as fit in a row instead of a maximum of two. Tightened
up the layout and improved the drawing, too.
* src/ntl-index-panel.c:
right clicking on the tabs adds extra ones for testing purposes
Right clicking on the tabs adds extra ones for testing purposes.
2000-02-11 Andy Hertzfeld <andy@eazel.com>
* libnautilus/gnome-icon-container-dnd.c:
......@@ -257,13 +289,12 @@
2000-02-10 Elliot Lee <sopwith@redhat.com>
* src/ntl-window.c: Set hpaned position for Darin's sanity.
* src/ntl-window-state.c: Handle view loading failure properly.
2000-02-10 Darin Adler <darin@eazel.com>
* ntl-window-msgs.c: (nautilus_window_has_really_changed):
Check GTK_OBJECT_DESTROYTED to handle the case of a view
Check GTK_OBJECT_DESTROYED to handle the case of a view
that self-destructs.
2000-02-10 Darin Adler <darin@eazel.com>
......
......@@ -30,17 +30,17 @@
#include "nautilus-icon-factory.h"
#include "nautilus-icons-view-icon-item.h"
/* An Icon. */
/* An Icon. */
typedef struct {
/* Canvas item for the icon. */
NautilusIconsViewIconItem *item;
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
*/
double x, y;
/* Whether this item is selected for operation. */
gboolean is_selected : 1;
......@@ -62,29 +62,29 @@ typedef struct {
#define INITIAL_GRID_HEIGHT 64
typedef struct {
/* Size of the grid. */
/* Size of the grid. */
guint width, height;
/* This is the width that we can actually use for finding an empty
* position.
* position.
*/
guint visible_width;
/* Array of grid elements. */
/* Array of grid elements. */
GList **elems;
/* Size of the allocated array. */
/* Size of the allocated array. */
guint alloc_width, alloc_height;
/* Position of the first free cell (used to speed up progressive
* updates). If negative, there is no free cell.
* updates). If negative, there is no free cell.
*/
int first_free_x, first_free_y;
} GnomeIconContainerIconGrid;
/* Private GnomeIconContainer members. */
/* Private GnomeIconContainer members. */
typedef struct {
gboolean active;
......@@ -108,65 +108,62 @@ struct _GnomeIconContainerDetails {
/* single-click mode setting */
gboolean single_click_mode;
/* Size of the container. */
guint width, height;
/* List of icons. */
/* List of icons. */
GList *icons;
guint num_icons;
/* The grid. */
/* The grid. */
GnomeIconContainerIconGrid *grid;
/* FIXME: This is *ugly*, but more efficient (both memory- and
speed-wise) than using gtk_object_{set,get}_data() for all the
icon items. */
speed-wise) than using gtk_object_{set,get}_data() for all the
icon items. */
GHashTable *canvas_item_to_icon;
/* Current icon for keyboard navigation. */
/* Current icon for keyboard navigation. */
GnomeIconContainerIcon *kbd_current;
/* Rubberbanding status. */
GnomeIconContainerRubberbandInfo rubberband_info;
/* Timeout used to make a selected icon fully visible after a short
* period of time. (The timeout is needed to make sure
* double-clicking still works.)
* period of time. (The timeout is needed to make sure
* double-clicking still works.)
*/
guint kbd_icon_visibility_timer_id;
/* the time the mouse button went down in milliseconds */
guint32 button_down_time;
/* Position of the pointer during the last click. */
/* the time the mouse button went down in milliseconds */
guint32 button_down_time;
/* Position of the pointer during the last click. */
int drag_x, drag_y;
/* Button currently pressed, possibly for dragging. */
/* Button currently pressed, possibly for dragging. */
guint drag_button;
/* Icon on which the click happened. */
/* Icon on which the click happened. */
GnomeIconContainerIcon *drag_icon;
/* Whether we are actually performing a dragging action. */
/* Whether we are actually performing a dragging action. */
gboolean doing_drag;
/* Idle ID. */
/* Idle ID. */
guint idle_id;
/* Timeout for selection in browser mode. */
guint linger_selection_mode_timer_id;
/* Icon to be selected at timeout in browser mode. */
/* Icon to be selected at timeout in browser mode. */
GnomeIconContainerIcon *linger_selection_mode_icon;
/* DnD info. */
/* DnD info. */
GnomeIconContainerDndInfo *dnd_info;
/* zoom level */
int zoom_level;
/* default fonts used to draw labels */
GdkFont *label_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
/* zoom level */
int zoom_level;
/* default fonts used to draw labels */
GdkFont *label_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
};
/* Layout and icon size constants.
......
......@@ -598,40 +598,13 @@ static void
scroll (GnomeIconContainer *container,
int delta_x, int delta_y)
{
GnomeIconContainerDetails *details;
GtkAdjustment *hadj, *vadj;
GtkAllocation *allocation;
gfloat vnew, hnew;
gfloat hmax, vmax;
details = container->details;
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
allocation = &GTK_WIDGET (container)->allocation;
if (container->details->width > allocation->width)
hmax = (gfloat) (container->details->width - allocation->width);
else
hmax = 0.0;
if (container->details->height > allocation->height)
vmax = (gfloat) (container->details->height - allocation->height);
else
vmax = 0.0;
hnew = CLAMP (hadj->value + (gfloat) delta_x, 0.0, hmax);
vnew = CLAMP (vadj->value + (gfloat) delta_y, 0.0, vmax);
if (hnew != hadj->value) {
hadj->value = hnew;
gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed");
}
if (vnew != vadj->value) {
vadj->value = vnew;
gtk_signal_emit_by_name (GTK_OBJECT (vadj), "value_changed");
}
gtk_adjustment_set_value (hadj, hadj->value + delta_x);
gtk_adjustment_set_value (vadj, vadj->value + delta_y);
}
static void
......@@ -646,10 +619,6 @@ make_icon_visible (GnomeIconContainer *container,
details = container->details;
allocation = &GTK_WIDGET (container)->allocation;
if (details->height < allocation->height
&& details->width < allocation->width)
return;
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
......@@ -845,41 +814,36 @@ set_kbd_current (GnomeIconContainer *container,
static void
set_scroll_region (GnomeIconContainer *container)
{
GnomeIconContainerDetails *details;
GnomeIconContainerIconGrid *grid;
double x1, y1, x2, y2;
double content_width, content_height;
double scroll_width, scroll_height;
GtkAllocation *allocation;
GtkAdjustment *vadj, *hadj;
double x1, y1, x2, y2;
guint scroll_width, scroll_height;
details = container->details;
grid = details->grid;
allocation = &(GTK_WIDGET (container)->allocation);
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
/* FIXME: We can do this more efficiently. */
gnome_canvas_item_get_bounds (GNOME_CANVAS (container)->root,
&x1, &y1, &x2, &y2);
details->width = x2 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
details->height = y2 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
content_width = x2 - x1 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
content_height = y2 - y1 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
scroll_width = MAX (details->width, allocation->width);
scroll_height = MAX (details->height, allocation->height);
allocation = &GTK_WIDGET (container)->allocation;
scroll_width--;
scroll_height--;
scroll_width = MAX (content_width, allocation->width);
scroll_height = MAX (content_height, allocation->height);
/* FIXME: Why are we subtracting one from each dimension? */
gnome_canvas_set_scroll_region (GNOME_CANVAS (container),
0.0, 0.0,
(double) scroll_width,
(double) scroll_height);
if (details->width <= allocation->width)
gtk_adjustment_set_value (hadj, 0.0);
if (details->height <= allocation->height)
gtk_adjustment_set_value (vadj, 0.0);
x1, y1,
x1 + scroll_width - 1,
y1 + scroll_height - 1);
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
if (content_width <= allocation->width)
gtk_adjustment_set_value (hadj, x1);
if (content_height <= allocation->height)
gtk_adjustment_set_value (vadj, y1);
}
static gboolean
......
......@@ -249,7 +249,7 @@ nautilus_directory_get (const char *uri)
} else {
/* Create a new directory object instead. */
directory = NAUTILUS_DIRECTORY (nautilus_directory_new (uri));
if(!directory)
if (directory == NULL)
return NULL;
g_assert (strcmp (directory->details->uri_text, uri) == 0);
......
......@@ -29,6 +29,9 @@
* should define its key here, so we can keep track of the whole set easily.
*/
#define NAUTILUS_CUSTOM_ICON_METADATA_KEY "CUSTOM_ICON"
#define NAUTILUS_NOTES_METADATA_KEY "NOTES"
#define ICON_VIEW_BACKGROUND_COLOR_METADATA_KEY "ICON_VIEW_BACKGROUND_COLOR"
#define ICON_VIEW_ZOOM_LEVEL_METADATA_KEY "ICON_VIEW_ZOOM_LEVEL"
#define ICON_VIEW_ICON_POSITION_METADATA_KEY "ICON_POSITION"
......@@ -40,5 +43,4 @@
#define INDEX_PANEL_BACKGROUND_COLOR_METADATA_KEY "INDEX_PANEL_BACKGROUND_COLOR"
#endif /* NAUTILUS_METADATA_H */
......@@ -30,17 +30,17 @@
#include "nautilus-icon-factory.h"
#include "nautilus-icons-view-icon-item.h"
/* An Icon. */
/* An Icon. */
typedef struct {
/* Canvas item for the icon. */
NautilusIconsViewIconItem *item;
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
*/
double x, y;
/* Whether this item is selected for operation. */
gboolean is_selected : 1;
......@@ -62,29 +62,29 @@ typedef struct {
#define INITIAL_GRID_HEIGHT 64
typedef struct {
/* Size of the grid. */
/* Size of the grid. */
guint width, height;
/* This is the width that we can actually use for finding an empty
* position.
* position.
*/
guint visible_width;
/* Array of grid elements. */
/* Array of grid elements. */
GList **elems;
/* Size of the allocated array. */
/* Size of the allocated array. */
guint alloc_width, alloc_height;
/* Position of the first free cell (used to speed up progressive
* updates). If negative, there is no free cell.
* updates). If negative, there is no free cell.
*/
int first_free_x, first_free_y;
} GnomeIconContainerIconGrid;
/* Private GnomeIconContainer members. */
/* Private GnomeIconContainer members. */
typedef struct {
gboolean active;
......@@ -108,65 +108,62 @@ struct _GnomeIconContainerDetails {
/* single-click mode setting */
gboolean single_click_mode;
/* Size of the container. */
guint width, height;
/* List of icons. */
/* List of icons. */
GList *icons;
guint num_icons;
/* The grid. */
/* The grid. */
GnomeIconContainerIconGrid *grid;
/* FIXME: This is *ugly*, but more efficient (both memory- and
speed-wise) than using gtk_object_{set,get}_data() for all the
icon items. */
speed-wise) than using gtk_object_{set,get}_data() for all the
icon items. */
GHashTable *canvas_item_to_icon;
/* Current icon for keyboard navigation. */
/* Current icon for keyboard navigation. */
GnomeIconContainerIcon *kbd_current;
/* Rubberbanding status. */
GnomeIconContainerRubberbandInfo rubberband_info;
/* Timeout used to make a selected icon fully visible after a short
* period of time. (The timeout is needed to make sure
* double-clicking still works.)
* period of time. (The timeout is needed to make sure
* double-clicking still works.)
*/
guint kbd_icon_visibility_timer_id;
/* the time the mouse button went down in milliseconds */
guint32 button_down_time;
/* Position of the pointer during the last click. */
/* the time the mouse button went down in milliseconds */
guint32 button_down_time;
/* Position of the pointer during the last click. */
int drag_x, drag_y;
/* Button currently pressed, possibly for dragging. */
/* Button currently pressed, possibly for dragging. */
guint drag_button;
/* Icon on which the click happened. */
/* Icon on which the click happened. */
GnomeIconContainerIcon *drag_icon;
/* Whether we are actually performing a dragging action. */
/* Whether we are actually performing a dragging action. */
gboolean doing_drag;
/* Idle ID. */
/* Idle ID. */
guint idle_id;
/* Timeout for selection in browser mode. */
guint linger_selection_mode_timer_id;
/* Icon to be selected at timeout in browser mode. */
/* Icon to be selected at timeout in browser mode. */
GnomeIconContainerIcon *linger_selection_mode_icon;
/* DnD info. */
/* DnD info. */
GnomeIconContainerDndInfo *dnd_info;
/* zoom level */
int zoom_level;
/* default fonts used to draw labels */
GdkFont *label_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
/* zoom level */
int zoom_level;
/* default fonts used to draw labels */
GdkFont *label_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
};
/* Layout and icon size constants.
......
......@@ -598,40 +598,13 @@ static void
scroll (GnomeIconContainer *container,
int delta_x, int delta_y)
{
GnomeIconContainerDetails *details;
GtkAdjustment *hadj, *vadj;
GtkAllocation *allocation;
gfloat vnew, hnew;
gfloat hmax, vmax;
details = container->details;
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
allocation = &GTK_WIDGET (container)->allocation;
if (container->details->width > allocation->width)
hmax = (gfloat) (container->details->width - allocation->width);
else
hmax = 0.0;
if (container->details->height > allocation->height)
vmax = (gfloat) (container->details->height - allocation->height);
else
vmax = 0.0;
hnew = CLAMP (hadj->value + (gfloat) delta_x, 0.0, hmax);
vnew = CLAMP (vadj->value + (gfloat) delta_y, 0.0, vmax);
if (hnew != hadj->value) {
hadj->value = hnew;
gtk_signal_emit_by_name (GTK_OBJECT (hadj), "value_changed");
}
if (vnew != vadj->value) {
vadj->value = vnew;
gtk_signal_emit_by_name (GTK_OBJECT (vadj), "value_changed");
}
gtk_adjustment_set_value (hadj, hadj->value + delta_x);
gtk_adjustment_set_value (vadj, vadj->value + delta_y);
}
static void
......@@ -646,10 +619,6 @@ make_icon_visible (GnomeIconContainer *container,
details = container->details;
allocation = &GTK_WIDGET (container)->allocation;
if (details->height < allocation->height
&& details->width < allocation->width)
return;
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
......@@ -845,41 +814,36 @@ set_kbd_current (GnomeIconContainer *container,
static void
set_scroll_region (GnomeIconContainer *container)
{
GnomeIconContainerDetails *details;
GnomeIconContainerIconGrid *grid;
double x1, y1, x2, y2;
double content_width, content_height;
double scroll_width, scroll_height;
GtkAllocation *allocation;
GtkAdjustment *vadj, *hadj;
double x1, y1, x2, y2;
guint scroll_width, scroll_height;
details = container->details;
grid = details->grid;
allocation = &(GTK_WIDGET (container)->allocation);
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
/* FIXME: We can do this more efficiently. */
gnome_canvas_item_get_bounds (GNOME_CANVAS (container)->root,
&x1, &y1, &x2, &y2);
details->width = x2 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
details->height = y2 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
content_width = x2 - x1 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
content_height = y2 - y1 + GNOME_ICON_CONTAINER_CELL_SPACING (container);
scroll_width = MAX (details->width, allocation->width);
scroll_height = MAX (details->height, allocation->height);
allocation = &GTK_WIDGET (container)->allocation;
scroll_width--;
scroll_height--;
scroll_width = MAX (content_width, allocation->width);
scroll_height = MAX (content_height, allocation->height);
/* FIXME: Why are we subtracting one from each dimension? */
gnome_canvas_set_scroll_region (GNOME_CANVAS (container),
0.0, 0.0,
(double) scroll_width,
(double) scroll_height);
if (details->width <= allocation->width)
gtk_adjustment_set_value (hadj, 0.0);
if (details->height <= allocation->height)
gtk_adjustment_set_value (vadj, 0.0);
x1, y1,
x1 + scroll_width - 1,
y1 + scroll_height - 1);
hadj = GTK_LAYOUT (container)->hadjustment;
vadj = GTK_LAYOUT (container)->vadjustment;
if (content_width <= allocation->width)
gtk_adjustment_set_value (hadj, x1);
if (content_height <= allocation->height)
gtk_adjustment_set_value (vadj, y1);
}
static gboolean
......
......@@ -249,7 +249,7 @@ nautilus_directory_get (const char *uri)
} else {
/* Create a new directory object instead. */
directory = NAUTILUS_DIRECTORY (nautilus_directory_new (uri));
if(!directory)
if (directory == NULL)
return NULL;
g_assert (strcmp (directory->details->uri_text, uri) == 0);
......
This diff is collapsed.
......@@ -29,6 +29,9 @@
* should define its key here, so we can keep track of the whole set easily.
*/
#define NAUTILUS_CUSTOM_ICON_METADATA_KEY "CUSTOM_ICON"
#define NAUTILUS_NOTES_METADATA_KEY "NOTES"
#define ICON_VIEW_BACKGROUND_COLOR_METADATA_KEY "ICON_VIEW_BACKGROUND_COLOR"
#define ICON_VIEW_ZOOM_LEVEL_METADATA_KEY "ICON_VIEW_ZOOM_LEVEL"
#define ICON_VIEW_ICON_POSITION_METADATA_KEY "ICON_POSITION"
......@@ -40,5 +43,4 @@
#define INDEX_PANEL_BACKGROUND_COLOR_METADATA_KEY "INDEX_PANEL_BACKGROUND_COLOR"
#endif /* NAUTILUS_METADATA_H */
......@@ -30,17 +30,17 @@
#include "nautilus-icon-factory.h"
#include "nautilus-icons-view-icon-item.h"
/* An Icon. */
/* An Icon. */
typedef struct {
/* Canvas item for the icon. */
NautilusIconsViewIconItem *item;
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
/* X/Y coordinates and size. We could use the GnomeCanvasItem
* functions, but this is a lot faster
*/
double x, y;
/* Whether this item is selected for operation. */
gboolean is_selected : 1;
......@@ -62,29 +62,29 @@ typedef struct {
#define INITIAL_GRID_HEIGHT 64
typedef struct {
/* Size of the grid. */
/* Size of the grid. */
guint width, height;
/* This is the width that we can actually use for finding an empty
* position.
* position.
*/
guint visible_width;
/* Array of grid elements. */
/* Array of grid elements. */
GList **elems;
/* Size of the allocated array. */
/* Size of the allocated array. */
guint alloc_width, alloc_height;
/* Position of the first free cell (used to speed up progressive
* updates). If negative, there is no free cell.