Commit bddcc07d authored by Darin Adler's avatar Darin Adler

Fixed rubber banding to hit test with all the parts of the icon, not just

	* libnautilus/Makefile.am, libnautilus/gnome-icon-container-dnd.c
	  (set_gnome_icon_list_selection,
	  gnome_icon_container_dnd_begin_drag),
	  libnautilus/gnome-icon-container.c (icon_is_in_region,
	  start_stretching), libnautilus/nautilus-icons-view-icon-item.h,
	  libnautilus/nautilus-icons-view-icon-item.c (hit_stretch_handle,
	  hit_test_pixbuf, hit_test, nautilus_icons_view_icon_item_point,
	  nautilus_icons_view_icon_item_get_icon_world_rectangle,
	  nautilus_icons_view_icon_item_get_icon_rectangle,
	  nautilus_icons_view_icon_item_get_icon_window_rectangle,
	  nautilus_icons_view_icon_item_get_hit_stretch_handle,
	  hit_stretch_handle,
	  nautilus_icons_view_icon_item_hit_test_stretch_handles,
	  nautilus_icons_view_icon_item_hit_test_rectangle):
	Fixed rubber banding to hit test with all the parts of the icon,
	not just the icon pixbuf itself. Did this by changing all the
	internal hit testing to use rects instead of points. At the same
	time changed the external interface to always use world
	coordinates for clarity.

	* libnautilus/nautilus-directory.c (compare_file_with_name),
	libnautilus/nautilus-file.c (nautilus_file_set_keywords): Fixed
	some void * problems that upset newer versions of GCC but not the
	older one that I'm using.

	* libnautilus/nautilus-gtk-extensions.h,
	libnautilus/nautilus-gtk-extensions.c: Formatting and include
	statements fix up.
parent d21681ac
2000-03-10 Darin Adler <darin@eazel.com>
* libnautilus/Makefile.am, libnautilus/gnome-icon-container-dnd.c
(set_gnome_icon_list_selection,
gnome_icon_container_dnd_begin_drag),
libnautilus/gnome-icon-container.c (icon_is_in_region,
start_stretching), libnautilus/nautilus-icons-view-icon-item.h,
libnautilus/nautilus-icons-view-icon-item.c (hit_stretch_handle,
hit_test_pixbuf, hit_test, nautilus_icons_view_icon_item_point,
nautilus_icons_view_icon_item_get_icon_world_rectangle,
nautilus_icons_view_icon_item_get_icon_rectangle,
nautilus_icons_view_icon_item_get_icon_window_rectangle,
nautilus_icons_view_icon_item_get_hit_stretch_handle,
hit_stretch_handle,
nautilus_icons_view_icon_item_hit_test_stretch_handles,
nautilus_icons_view_icon_item_hit_test_rectangle):
Fixed rubber banding to hit test with all the parts of the icon,
not just the icon pixbuf itself. Did this by changing all the
internal hit testing to use rects instead of points. At the same
time changed the external interface to always use world
coordinates for clarity.
* libnautilus/nautilus-directory.c (compare_file_with_name),
libnautilus/nautilus-file.c (nautilus_file_set_keywords): Fixed
some void * problems that upset newer versions of GCC but not the
older one that I'm using.
* libnautilus/nautilus-gtk-extensions.h,
libnautilus/nautilus-gtk-extensions.c: Formatting and include
statements fix up.
2000-03-10 Jonathan Blandford <jrb@redhat.com>
* libnautilus/gnome-icon-container.c (button_press_event): Avoid a
......
......@@ -40,6 +40,7 @@ libnautilusinclude_HEADERS= \
nautilus-file.h \
nautilus-file-utilities.h \
nautilus-glib-extensions.h \
nautilus-gnome-extensions.h \
nautilus-gtk-extensions.h \
nautilus-icon-factory.h \
nautilus-icons-controller.h \
......@@ -70,6 +71,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-file.c \
nautilus-file-utilities.c \
nautilus-glib-extensions.c \
nautilus-gnome-extensions.c \
nautilus-gtk-extensions.c \
nautilus-icon-factory.c \
nautilus-icons-controller.c \
......
......@@ -29,12 +29,13 @@
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "nautilus-glib-extensions.h"
#include <gtk/gtksignal.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-extensions.h"
#include "nautilus-gnome-extensions.h"
#include "nautilus-background.h"
#include "gnome-icon-container-private.h"
#include <libgnomeui/gnome-canvas-rect-ellipse.h>
#include "gnome-icon-container-private.h"
typedef struct {
char *uri;
......@@ -203,7 +204,8 @@ set_gnome_icon_list_selection (GnomeIconContainer *container,
data = g_string_new (NULL);
for (p = details->icons; p != NULL; p = p->next) {
GnomeIconContainerIcon *icon;
ArtIRect rect;
ArtDRect world_rect;
ArtIRect window_rect;
char *uri;
char *s;
......@@ -211,17 +213,19 @@ set_gnome_icon_list_selection (GnomeIconContainer *container,
if (!icon->is_selected)
continue;
nautilus_icons_view_icon_item_get_icon_window_rectangle
(icon->item, &rect);
nautilus_icons_view_icon_item_get_icon_rectangle
(icon->item, &world_rect);
nautilus_gnome_canvas_world_to_window_rectangle
(GNOME_CANVAS (container), &world_rect, &window_rect);
uri = nautilus_icons_controller_get_icon_uri
(details->controller, icon->data);
s = g_strdup_printf ("%s\r%d:%d:%hu:%hu\r\n",
uri,
(int) (rect.x0 - details->dnd_info->start_x),
(int) (rect.y0 - details->dnd_info->start_y),
rect.x1 - rect.x0,
rect.y1 - rect.y0);
(int) (window_rect.x0 - details->dnd_info->start_x),
(int) (window_rect.y0 - details->dnd_info->start_y),
window_rect.x1 - window_rect.x0,
window_rect.y1 - window_rect.y0);
g_free (uri);
......@@ -787,7 +791,8 @@ gnome_icon_container_dnd_begin_drag (GnomeIconContainer *container,
GdkPixmap *pixmap_for_dragged_file;
GdkBitmap *mask_for_dragged_file;
int x_offset, y_offset;
ArtIRect rect;
ArtDRect world_rect;
ArtIRect window_rect;
g_return_if_fail (GNOME_IS_ICON_CONTAINER (container));
g_return_if_fail (event != NULL);
......@@ -820,23 +825,27 @@ gnome_icon_container_dnd_begin_drag (GnomeIconContainer *container,
for relatively small pixbufs. Eventually, we may have to remove this entirely
for UI consistency reasons */
if ((gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf)) < 4096)
transparent_pixbuf = make_semi_transparent(pixbuf);
else
if ((gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf)) < 4096) {
transparent_pixbuf = make_semi_transparent (pixbuf);
} else {
gdk_pixbuf_ref (pixbuf);
transparent_pixbuf = pixbuf;
}
gdk_pixbuf_render_pixmap_and_mask (transparent_pixbuf,
&pixmap_for_dragged_file,
&mask_for_dragged_file,
128);
if (transparent_pixbuf != pixbuf)
gdk_pixbuf_unref(transparent_pixbuf);
gdk_pixbuf_unref (transparent_pixbuf);
/* compute the image's offset */
nautilus_icons_view_icon_item_get_icon_window_rectangle
(container->details->drag_icon->item, &rect);
x_offset = dnd_info->start_x - rect.x0;
y_offset = dnd_info->start_y - rect.y0;
nautilus_icons_view_icon_item_get_icon_rectangle
(container->details->drag_icon->item, &world_rect);
nautilus_gnome_canvas_world_to_window_rectangle
(canvas, &world_rect, &window_rect);
x_offset = dnd_info->start_x - window_rect.x0;
y_offset = dnd_info->start_y - window_rect.y0;
/* set the pixmap and mask for dragging */
gtk_drag_set_icon_pixmap (context, gtk_widget_get_colormap (GTK_WIDGET (container)),
......
......@@ -298,13 +298,12 @@ icon_is_in_region (GnomeIconContainer *container,
int x1, int y1)
{
ArtDRect rect;
if (x0 >= x1 || y0 >= y1)
return FALSE;
nautilus_icons_view_icon_item_get_icon_world_rectangle
rect.x0 = x0;
rect.x1 = x1;
rect.y0 = y0;
rect.y1 = y1;
return nautilus_icons_view_icon_item_hit_test_rectangle
(icon->item, &rect);
return x0 < rect.x1 && x1 >= rect.x0 && y0 < rect.y1 && y1 >= rect.y0;
}
static void
......@@ -1199,12 +1198,13 @@ rubberband_select_in_cell (GnomeIconContainer *container,
prev_x1, prev_y1,
prev_x2, prev_y2);
if (in_curr_region && ! in_prev_region)
if (in_curr_region && ! in_prev_region) {
selection_changed |= icon_set_selected (container, icon,
!icon->was_selected_before_rubberband);
else if (in_prev_region && ! in_curr_region)
} else if (in_prev_region && ! in_curr_region) {
selection_changed |= icon_set_selected (container, icon,
icon->was_selected_before_rubberband);
}
}
return selection_changed;
......@@ -1931,24 +1931,26 @@ start_stretching (GnomeIconContainer *container)
{
GnomeIconContainerDetails *details;
GnomeIconContainerIcon *icon;
int canvas_x, canvas_y;
ArtPoint world_point;
details = container->details;
icon = details->stretch_icon;
gnome_canvas_w2c (GNOME_CANVAS (container),
details->drag_x, details->drag_y,
&canvas_x, &canvas_y);
/* Check if we hit the stretch handles. */
if (!nautilus_icons_view_icon_item_get_hit_stretch_handle
(icon->item, canvas_x, canvas_y))
world_point.x = details->drag_x;
world_point.y = details->drag_y;
if (!nautilus_icons_view_icon_item_hit_test_stretch_handles
(icon->item, &world_point)) {
return FALSE;
}
/* Set up the dragging. */
details->drag_action = DRAG_ACTION_STRETCH;
details->stretch_start.pointer_x = canvas_x;
details->stretch_start.pointer_y = canvas_y;
gnome_canvas_w2c (GNOME_CANVAS (container),
details->drag_x,
details->drag_y,
&details->stretch_start.pointer_x,
&details->stretch_start.pointer_y);
gnome_canvas_w2c (GNOME_CANVAS (container),
icon->x, icon->y,
&details->stretch_start.icon_x,
......
......@@ -1069,7 +1069,8 @@ nautilus_directory_set_file_metadata (NautilusDirectory *directory,
static int
compare_file_with_name (gconstpointer a, gconstpointer b)
{
return strcmp (((const NautilusFile *) a)->info->name, b);
return strcmp (((const NautilusFile *) a)->info->name,
(const char *) b);
}
NautilusFile *
......
......@@ -917,7 +917,7 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
next = child->next;
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL && p != NULL && strcmp (property, p->data) == 0) {
if (property != NULL && p != NULL && strcmp (property, (char *)p->data) == 0) {
p = p->next;
} else {
xmlUnlinkNode (child);
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-gnome-extensions.c - implementation of new functions that operate on
gnome classes. Perhaps some of these should be
rolled into gnome someday.
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: Darin Adler <darin@eazel.com>
*/
#include <config.h>
#include "nautilus-gnome-extensions.h"
void
nautilus_gnome_canvas_world_to_window_rectangle (GnomeCanvas *canvas,
const ArtDRect *world_rect,
ArtIRect *window_rect)
{
double x0, y0, x1, y1;
g_return_if_fail (GNOME_IS_CANVAS (canvas));
g_return_if_fail (world_rect != NULL);
g_return_if_fail (window_rect != NULL);
gnome_canvas_world_to_window (canvas,
world_rect->x0,
world_rect->y0,
&x0, &y0);
gnome_canvas_world_to_window (canvas,
world_rect->x1,
world_rect->y1,
&x1, &y1);
window_rect->x0 = x0;
window_rect->y0 = y0;
window_rect->x1 = x1;
window_rect->y1 = y1;
}
void
nautilus_gnome_canvas_world_to_canvas_rectangle (GnomeCanvas *canvas,
const ArtDRect *world_rect,
ArtIRect *canvas_rect)
{
g_return_if_fail (GNOME_IS_CANVAS (canvas));
g_return_if_fail (world_rect != NULL);
g_return_if_fail (canvas_rect != NULL);
gnome_canvas_w2c (canvas,
world_rect->x0,
world_rect->y0,
&canvas_rect->x0,
&canvas_rect->y0);
gnome_canvas_w2c (canvas,
world_rect->x1,
world_rect->y1,
&canvas_rect->x1,
&canvas_rect->y1);
}
gboolean
nautilus_art_irect_hits_irect (const ArtIRect *rect_a,
const ArtIRect *rect_b)
{
ArtIRect intersection;
g_return_val_if_fail (rect_a != NULL, FALSE);
g_return_val_if_fail (rect_b != NULL, FALSE);
art_irect_intersect (&intersection, rect_a, rect_b);
return !art_irect_empty (&intersection);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-gmp,e-extensions.h - interface for new functions that operate on
gnome classes. Perhaps some of these should be
rolled into gnome someday.
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: Darin Adler <darin@eazel.com>
*/
#ifndef NAUTILUS_GNOME_EXTENSIONS_H
#define NAUTILUS_GNOME_EXTENSIONS_H
#include <libgnomeui/gnome-canvas.h>
void nautilus_gnome_canvas_world_to_canvas_rectangle (GnomeCanvas *canvas,
const ArtDRect *world_rectangle,
ArtIRect *canvas_rectangle);
void nautilus_gnome_canvas_world_to_window_rectangle (GnomeCanvas *canvas,
const ArtDRect *world_rectangle,
ArtIRect *window_rectangle);
gboolean nautilus_art_irect_hits_irect (const ArtIRect *rect_a,
const ArtIRect *rect_b);
#endif /* NAUTILUS_GNOME_EXTENSIONS_H */
......@@ -24,10 +24,13 @@
Authors: John Sullivan <sullivan@eazel.com>
*/
#include <config.h>
#include "nautilus-gtk-extensions.h"
#include <gnome.h>
#include <gtk/gtkselection.h>
#include <gtk/gtksignal.h>
#include <libgnomeui/gnome-geometry.h>
/**
* nautilus_gtk_signal_connect_free_data:
*
......@@ -70,7 +73,7 @@ nautilus_gtk_window_hide_retain_geometry (GtkWindow *window) {
/* Save and restore position to keep it in same position when next shown. */
geometry_string = gnome_geometry_string(GTK_WIDGET (window)->window);
geometry_string = gnome_geometry_string (GTK_WIDGET (window)->window);
gtk_widget_hide (GTK_WIDGET (window));
......
......@@ -36,20 +36,25 @@
#define NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT 2
/* signals */
guint nautilus_gtk_signal_connect_free_data (GtkObject *object,
const gchar *name,
GtkSignalFunc func,
gpointer data);
/* GtkWindow */
void nautilus_gtk_window_present (GtkWindow *window);
/* selection data */
GtkSelectionData *nautilus_gtk_selection_data_copy_deep (const GtkSelectionData *selection_data);
void nautilus_gtk_selection_data_free_deep (GtkSelectionData *selection_data);
/* GtkMenu */
void nautilus_pop_up_context_menu (GtkMenu *menu,
gint16 offset_x,
gint16 offset_y);
/* marshals */
void nautilus_gtk_marshal_NONE__POINTER_INT_INT_DOUBLE (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
......@@ -58,11 +63,10 @@ void nautilus_gtk_marshal_NONE__POINTER_INT_INT_DOUBLE_DOUBLE (GtkO
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
void nautilus_gtk_marshal_NONE__DOUBLE (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
void nautilus_gtk_marshal_NONE__DOUBLE (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args);
#endif /* NAUTILUS_GTK_EXTENSIONS_H */
......@@ -37,6 +37,7 @@
#include "nautilus-glib-extensions.h"
#include "gdk-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-gnome-extensions.h"
#define STRETCH_HANDLE_THICKNESS 5
#define EMBLEM_SPACING 2
......@@ -156,6 +157,8 @@ static void draw_pixbuf (GdkPixb
GdkDrawable *drawable,
int x,
int y);
static gboolean hit_stretch_handle (NautilusIconsViewIconItem *item,
const ArtIRect *canvas_rect);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusIconsViewIconItem, nautilus_icons_view_icon_item, GNOME_TYPE_CANVAS_ITEM)
......@@ -978,9 +981,10 @@ compute_text_rectangle (NautilusIconsViewIconItem *item, const ArtIRect *icon_re
}
static gboolean
hit_test_pixbuf (GdkPixbuf *pixbuf, int pixbuf_x, int pixbuf_y, int probe_x, int probe_y)
hit_test_pixbuf (GdkPixbuf *pixbuf, const ArtIRect *pixbuf_location, const ArtIRect *probe_rect)
{
int relative_x, relative_y;
ArtIRect relative_rect, pixbuf_rect;
int x, y;
guint8 *pixel;
/* You can get here without a pixbuf in some strage cases. */
......@@ -989,11 +993,16 @@ hit_test_pixbuf (GdkPixbuf *pixbuf, int pixbuf_x, int pixbuf_y, int probe_x, int
}
/* Check to see if it's within the rectangle at all. */
relative_x = probe_x - pixbuf_x;
relative_y = probe_y - pixbuf_y;
if (relative_x < 0 || relative_y < 0
|| relative_x > gdk_pixbuf_get_width (pixbuf)
|| relative_y > gdk_pixbuf_get_height (pixbuf)) {
relative_rect.x0 = probe_rect->x0 - pixbuf_location->x0;
relative_rect.y0 = probe_rect->y0 - pixbuf_location->y0;
relative_rect.x1 = probe_rect->x1 - pixbuf_location->x0;
relative_rect.y1 = probe_rect->y1 - pixbuf_location->y0;
pixbuf_rect.x0 = 0;
pixbuf_rect.y0 = 0;
pixbuf_rect.x1 = gdk_pixbuf_get_width (pixbuf);
pixbuf_rect.y1 = gdk_pixbuf_get_height (pixbuf);
art_irect_intersect (&relative_rect, &relative_rect, &pixbuf_rect);
if (art_irect_empty (&relative_rect)) {
return FALSE;
}
......@@ -1004,14 +1013,21 @@ hit_test_pixbuf (GdkPixbuf *pixbuf, int pixbuf_x, int pixbuf_y, int probe_x, int
g_assert (gdk_pixbuf_get_n_channels (pixbuf) == 4);
/* Check the alpha channel of the pixel to see if we have a hit. */
pixel = gdk_pixbuf_get_pixels (pixbuf)
+ relative_y * gdk_pixbuf_get_rowstride (pixbuf)
+ relative_x * 4;
return pixel[3] >= 128;
for (x = pixbuf_rect.x0; x < pixbuf_rect.x1; x++) {
for (y = pixbuf_rect.y0; y < pixbuf_rect.y1; y++) {
pixel = gdk_pixbuf_get_pixels (pixbuf)
+ y * gdk_pixbuf_get_rowstride (pixbuf)
+ x * 4;
if (pixel[3] >= 128) {
return TRUE;
}
}
}
return FALSE;
}
static gboolean
hit_test (NautilusIconsViewIconItem *icon_item, int cx, int cy)
hit_test (NautilusIconsViewIconItem *icon_item, const ArtIRect *canvas_rect)
{
NautilusIconsViewIconItemDetails *details;
ArtIRect icon_rect, text_rect, emblem_rect;
......@@ -1021,27 +1037,27 @@ hit_test (NautilusIconsViewIconItem *icon_item, int cx, int cy)
details = icon_item->details;
/* Check for hits in the stretch handles. */
if (nautilus_icons_view_icon_item_get_hit_stretch_handle (icon_item, cx, cy)) {
if (hit_stretch_handle (icon_item, canvas_rect)) {
return TRUE;
}
/* Check for hit in the icon. */
nautilus_icons_view_icon_item_get_icon_canvas_rectangle (icon_item, &icon_rect);
if (hit_test_pixbuf (details->pixbuf, icon_rect.x0, icon_rect.y0, cx, cy)) {
nautilus_icons_view_icon_item_get_icon_canvas_rectangle
(icon_item, &icon_rect);
if (hit_test_pixbuf (details->pixbuf, &icon_rect, canvas_rect)) {
return TRUE;
}
/* Check for hit in the text. */
compute_text_rectangle (icon_item, &icon_rect, &text_rect);
if (cx >= text_rect.x0 && cx <= text_rect.x1
&& cy >= text_rect.y0 && cy <= text_rect.y1) {
if (nautilus_art_irect_hits_irect (&text_rect, canvas_rect)) {
return TRUE;
}
/* Check for hit in the emblem pixbufs. */
emblem_layout_reset (&emblem_layout, icon_item, &icon_rect);
while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
if (hit_test_pixbuf (emblem_pixbuf, emblem_rect.x0, emblem_rect.y0, cx, cy)) {
if (hit_test_pixbuf (emblem_pixbuf, &emblem_rect, canvas_rect)) {
return TRUE;
}
}
......@@ -1050,17 +1066,23 @@ hit_test (NautilusIconsViewIconItem *icon_item, int cx, int cy)
}
/* Point handler for the icon canvas item. */
/* FIXME: This currently only reports a hit if the pixbuf or stretch handles are hit,
* and ignores hits on the text.
*/
static double
nautilus_icons_view_icon_item_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
GnomeCanvasItem **actual_item)
{
ArtIRect canvas_rect;
*actual_item = item;
if (hit_test (NAUTILUS_ICONS_VIEW_ICON_ITEM (item), cx, cy)) {
canvas_rect.x0 = cx;
canvas_rect.y0 = cy;
canvas_rect.x0 = cx + 1;
canvas_rect.y0 = cy + 1;
if (hit_test (NAUTILUS_ICONS_VIEW_ICON_ITEM (item), &canvas_rect)) {
return 0.0;
} else {
/* This value means not hit.
* It's kind of arbitrary. Can we do better?
*/
return item->canvas->pixels_per_unit * 2 + 10;
}
}
......@@ -1122,8 +1144,8 @@ nautilus_icons_view_icon_item_bounds (GnomeCanvasItem *item, double *x1, double
/* Get the rectangle of the icon only, in world coordinates. */
void
nautilus_icons_view_icon_item_get_icon_world_rectangle (NautilusIconsViewIconItem *item,
ArtDRect *rect)
nautilus_icons_view_icon_item_get_icon_rectangle (NautilusIconsViewIconItem *item,
ArtDRect *rect)
{
double i2w[6];
ArtPoint art_point;
......@@ -1176,36 +1198,6 @@ nautilus_icons_view_icon_item_get_icon_canvas_rectangle (NautilusIconsViewIconIt
rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf));
}
/* Get the rectangle of the icon only, in window coordinates. */
void
nautilus_icons_view_icon_item_get_icon_window_rectangle (NautilusIconsViewIconItem *item,
ArtIRect *rect)
{
double i2w[6];
ArtPoint art_point;
GdkPixbuf *pixbuf;
g_return_if_fail (NAUTILUS_IS_ICONS_VIEW_ICON_ITEM (item));
g_return_if_fail (rect != NULL);
gnome_canvas_item_i2w_affine (GNOME_CANVAS_ITEM (item), i2w);
art_point.x = 0;
art_point.y = 0;
art_affine_point (&art_point, &art_point, i2w);
gnome_canvas_world_to_window (GNOME_CANVAS_ITEM (item)->canvas,
art_point.x, art_point.y,
&art_point.x, &art_point.y);
rect->x0 = floor (art_point.x);
rect->y0 = floor (art_point.y);
pixbuf = item->details->pixbuf;
rect->x1 = rect->x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf));
rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf));
}
void
nautilus_icons_view_icon_item_set_show_stretch_handles (NautilusIconsViewIconItem *item,
gboolean show_stretch_handles)
......@@ -1222,11 +1214,11 @@ nautilus_icons_view_icon_item_set_show_stretch_handles (NautilusIconsViewIconIte
}
/* Check if one of the stretch handles was hit. */
gboolean
nautilus_icons_view_icon_item_get_hit_stretch_handle (NautilusIconsViewIconItem *item,
int canvas_x, int canvas_y)
static gboolean
hit_stretch_handle (NautilusIconsViewIconItem *item,
const ArtIRect *probe_canvas_rect)
{
ArtIRect rect;
ArtIRect icon_rect;
g_return_val_if_fail (NAUTILUS_IS_ICONS_VIEW_ICON_ITEM (item), FALSE);
......@@ -1235,17 +1227,49 @@ nautilus_icons_view_icon_item_get_hit_stretch_handle (NautilusIconsViewIconItem
return FALSE;
}
/* Get both the point and the icon rectangle in canvas coordinates. */
nautilus_icons_view_icon_item_get_icon_canvas_rectangle (item, &rect);
/* Handle the case where it's not in the rectangle at all. */
if (canvas_x < rect.x0 || canvas_x >= rect.x1 || canvas_y < rect.y0 || canvas_y >= rect.y1) {
/* Quick check to see if the rect hits the icon at all. */
nautilus_icons_view_icon_item_get_icon_canvas_rectangle
(item, &icon_rect);
if (!nautilus_art_irect_hits_irect (probe_canvas_rect, &icon_rect)) {
return FALSE;
}
/* Check for hits in the stretch handles. */
return (canvas_x < rect.x0 + STRETCH_HANDLE_THICKNESS
|| canvas_x >= rect.x1 - STRETCH_HANDLE_THICKNESS)
&& (canvas_y < rect.y0 + STRETCH_HANDLE_THICKNESS
|| canvas_y >= rect.y1 - STRETCH_HANDLE_THICKNESS);
return (probe_canvas_rect->x0 < icon_rect.x0 + STRETCH_HANDLE_THICKNESS
|| probe_canvas_rect->x1 >= icon_rect.x1 - STRETCH_HANDLE_THICKNESS)
&& (probe_canvas_rect->y0 < icon_rect.y0 + STRETCH_HANDLE_THICKNESS
|| probe_canvas_rect->y1 >= icon_rect.y1 - STRETCH_HANDLE_THICKNESS);
}
gboolean
nautilus_icons_view_icon_item_hit_test_stretch_handles (NautilusIconsViewIconItem *item,
const ArtPoint *world_point)
{
ArtIRect canvas_rect;
g_return_val_if_fail (NAUTILUS_IS_ICONS_VIEW_ICON_ITEM (item), FALSE);
g_return_val_if_fail (world_point != NULL, FALSE);
gnome_canvas_w2c (GNOME_CANVAS_ITEM (item)->canvas,
world_point->x,
world_point->y,
&canvas_rect.x0,
&canvas_rect.y0);
canvas_rect.x1 = canvas_rect.x0 + 1;
canvas_rect.y1 = canvas_rect.y0 + 1;
return hit_stretch_handle (item, &canvas_rect);
}
gboolean
nautilus_icons_view_icon_item_hit_test_rectangle (NautilusIconsViewIconItem *item,
const ArtDRect *world_rect)
{
ArtIRect canvas_rect;
g_return_val_if_fail (NAUTILUS_IS_ICONS_VIEW_ICON_ITEM (item), FALSE);
g_return_val_if_fail (world_rect != NULL, FALSE);
nautilus_gnome_canvas_world_to_canvas_rectangle