Commit 4e1175d7 authored by Andy Hertzfeld's avatar Andy Hertzfeld

made the keyboard selection rectangle work again, not as a separate canvas


       made the keyboard selection rectangle work again, not as a separate
       canvas item like it used to be, but as an attribute drawn by the
       icon item.
parent de79345d
2000-01-31 Andy Hertzfeld <andy@eazel.com>
made the keyboard selection rectangle work again. It's no longer a
separate canvas object, but rather a state reflected by the icon_item
like regular selection
*libnautilus/gnome-icon-container-private.h:
removed the kdb_navigation_item field
*libnautilus/gnome-icon-container.c:
removed code that manipulated the kbd_navigation_item, replaced
with setting and clearing the "alt_selection" item attribute
*libnautilus/nautilus-icons-view-icon-item.c:
if the alt_selected attribute is set, frame the item's text with
a gray-stippled rectangle
2000-01-31 John Sullivan <sullivan@eazel.com>
Now saves/restores zoom level in icon & list views, and
......
......@@ -121,9 +121,6 @@ struct _GnomeIconContainerDetails {
icon items. */
GHashTable *canvas_item_to_icon;
/* Rectangle that shows that a certain icon is selected. */
GnomeCanvasItem *kbd_navigation_rectangle;
/* Current icon for keyboard navigation. */
GnomeIconContainerIcon *kbd_current;
......
......@@ -866,6 +866,11 @@ set_kbd_current (GnomeIconContainer *container,
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = icon;
if (details->kbd_current == NULL)
......@@ -873,16 +878,11 @@ set_kbd_current (GnomeIconContainer *container,
icon_get_text_bounding_box (icon, &x1, &y1, &x2, &y2);
gnome_canvas_item_set (details->kbd_navigation_rectangle,
"x1", (gdouble) x1 - 1,
"y1", (gdouble) y1 - 1,
"x2", (gdouble) x2,
"y2", (gdouble) y2,
gnome_canvas_item_set (icon->item,
"alt_selected", 1,
NULL);
gnome_canvas_item_show (details->kbd_navigation_rectangle);
icon_raise (icon);
gnome_canvas_item_raise_to_top (details->kbd_navigation_rectangle);
if (schedule_visibility)
schedule_kbd_icon_visibility (container);
......@@ -896,10 +896,12 @@ unset_kbd_current (GnomeIconContainer *container)
GnomeIconContainerDetails *details;
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = NULL;
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
unschedule_kbd_icon_visibility (container);
}
......@@ -2018,15 +2020,6 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->canvas_item_to_icon = g_hash_table_new (g_direct_hash,
g_direct_equal);
details->kbd_navigation_rectangle
= gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (container)),
gnome_canvas_rect_get_type (),
"outline_color", "black",
"outline_stipple", stipple,
"width_pixels", 1,
NULL);
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
......
......@@ -94,6 +94,12 @@ enum {
#define MAX_LABEL_WIDTH 80
/* Bitmap for stippled selection rectangles. */
static GdkBitmap *stipple;
static char stipple_bits[] = { 0x02, 0x01 };
/* headers */
static void nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *class);
static void nautilus_icons_view_icon_item_initialize (NautilusIconsViewIconItem *cpb);
static void nautilus_icons_view_icon_item_destroy (GtkObject *object);
......@@ -107,7 +113,7 @@ static double nautilus_icons_view_icon_item_point (GnomeCanvasItem *item, double
static void nautilus_icons_view_icon_item_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
static void nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw);
gint icon_left, gint icon_bottom, gboolean real_draw);
static GdkFont* get_font_for_item(GnomeCanvasItem *item);
......@@ -152,6 +158,8 @@ nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *
item_class->render = nautilus_icons_view_icon_item_render;
item_class->point = nautilus_icons_view_icon_item_point;
item_class->bounds = nautilus_icons_view_icon_item_bounds;
stipple = gdk_bitmap_create_from_data (NULL, stipple_bits, 2, 2);
}
/* Object initialization function for the icon item */
......@@ -498,7 +506,7 @@ nautilus_icons_view_icon_item_update (GnomeCanvasItem *item, double *affine, Art
title_font = get_font_for_item(item);
/* make sure the text box measurements are set up before recalculating the bounding box */
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, details->is_selected, FALSE);
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, FALSE);
recompute_bounding_box(icon_view_item);
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, update, (item, affine, clip_path, flags));
......@@ -582,7 +590,7 @@ transform_pixbuf (guchar *dest, int x, int y, int width, int height, int rowstri
/* utility routine to draw the label in a box, using gnomelib routines */
static void
nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw)
gint icon_left, gint icon_bottom, gboolean real_draw)
{
GnomeIconTextInfo *icon_text_info;
gint box_left;
......@@ -620,13 +628,22 @@ nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable,
}
/* invert to indicate selection if necessary */
if (is_selected && real_draw)
if (details->is_selected && real_draw)
{
gdk_gc_set_function (temp_gc, GDK_INVERT);
gdk_draw_rectangle (drawable, temp_gc, TRUE, box_left, icon_bottom - 2, line_width, line_height);
gdk_gc_set_function (temp_gc, GDK_COPY);
}
/* indicate alt-selection by framing the text with a gray-stippled rectangle */
if (details->is_alt_selected && real_draw)
{
gdk_gc_set_stipple(temp_gc, stipple);
gdk_gc_set_fill(temp_gc, GDK_STIPPLED);
gdk_draw_rectangle (drawable, temp_gc, FALSE, box_left, icon_bottom - 2, line_width, line_height);
}
if (real_draw)
gdk_gc_unref (temp_gc);
......@@ -709,7 +726,7 @@ nautilus_icons_view_icon_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable
if (container->details->zoom_level != NAUTILUS_ZOOM_LEVEL_SMALLEST) {
icon_height = details->pixbuf->art_pixbuf->height * item->canvas->pixels_per_unit;
nautilus_icons_view_draw_text_box(item, drawable, title_font, details->label, item->x1 - x,
item->y1 - y + icon_height, details->is_selected, TRUE);
item->y1 - y + icon_height, TRUE);
}
}
......
......@@ -121,9 +121,6 @@ struct _GnomeIconContainerDetails {
icon items. */
GHashTable *canvas_item_to_icon;
/* Rectangle that shows that a certain icon is selected. */
GnomeCanvasItem *kbd_navigation_rectangle;
/* Current icon for keyboard navigation. */
GnomeIconContainerIcon *kbd_current;
......
......@@ -866,6 +866,11 @@ set_kbd_current (GnomeIconContainer *container,
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = icon;
if (details->kbd_current == NULL)
......@@ -873,16 +878,11 @@ set_kbd_current (GnomeIconContainer *container,
icon_get_text_bounding_box (icon, &x1, &y1, &x2, &y2);
gnome_canvas_item_set (details->kbd_navigation_rectangle,
"x1", (gdouble) x1 - 1,
"y1", (gdouble) y1 - 1,
"x2", (gdouble) x2,
"y2", (gdouble) y2,
gnome_canvas_item_set (icon->item,
"alt_selected", 1,
NULL);
gnome_canvas_item_show (details->kbd_navigation_rectangle);
icon_raise (icon);
gnome_canvas_item_raise_to_top (details->kbd_navigation_rectangle);
if (schedule_visibility)
schedule_kbd_icon_visibility (container);
......@@ -896,10 +896,12 @@ unset_kbd_current (GnomeIconContainer *container)
GnomeIconContainerDetails *details;
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = NULL;
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
unschedule_kbd_icon_visibility (container);
}
......@@ -2018,15 +2020,6 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->canvas_item_to_icon = g_hash_table_new (g_direct_hash,
g_direct_equal);
details->kbd_navigation_rectangle
= gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (container)),
gnome_canvas_rect_get_type (),
"outline_color", "black",
"outline_stipple", stipple,
"width_pixels", 1,
NULL);
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
......
......@@ -94,6 +94,12 @@ enum {
#define MAX_LABEL_WIDTH 80
/* Bitmap for stippled selection rectangles. */
static GdkBitmap *stipple;
static char stipple_bits[] = { 0x02, 0x01 };
/* headers */
static void nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *class);
static void nautilus_icons_view_icon_item_initialize (NautilusIconsViewIconItem *cpb);
static void nautilus_icons_view_icon_item_destroy (GtkObject *object);
......@@ -107,7 +113,7 @@ static double nautilus_icons_view_icon_item_point (GnomeCanvasItem *item, double
static void nautilus_icons_view_icon_item_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
static void nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw);
gint icon_left, gint icon_bottom, gboolean real_draw);
static GdkFont* get_font_for_item(GnomeCanvasItem *item);
......@@ -152,6 +158,8 @@ nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *
item_class->render = nautilus_icons_view_icon_item_render;
item_class->point = nautilus_icons_view_icon_item_point;
item_class->bounds = nautilus_icons_view_icon_item_bounds;
stipple = gdk_bitmap_create_from_data (NULL, stipple_bits, 2, 2);
}
/* Object initialization function for the icon item */
......@@ -498,7 +506,7 @@ nautilus_icons_view_icon_item_update (GnomeCanvasItem *item, double *affine, Art
title_font = get_font_for_item(item);
/* make sure the text box measurements are set up before recalculating the bounding box */
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, details->is_selected, FALSE);
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, FALSE);
recompute_bounding_box(icon_view_item);
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, update, (item, affine, clip_path, flags));
......@@ -582,7 +590,7 @@ transform_pixbuf (guchar *dest, int x, int y, int width, int height, int rowstri
/* utility routine to draw the label in a box, using gnomelib routines */
static void
nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw)
gint icon_left, gint icon_bottom, gboolean real_draw)
{
GnomeIconTextInfo *icon_text_info;
gint box_left;
......@@ -620,13 +628,22 @@ nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable,
}
/* invert to indicate selection if necessary */
if (is_selected && real_draw)
if (details->is_selected && real_draw)
{
gdk_gc_set_function (temp_gc, GDK_INVERT);
gdk_draw_rectangle (drawable, temp_gc, TRUE, box_left, icon_bottom - 2, line_width, line_height);
gdk_gc_set_function (temp_gc, GDK_COPY);
}
/* indicate alt-selection by framing the text with a gray-stippled rectangle */
if (details->is_alt_selected && real_draw)
{
gdk_gc_set_stipple(temp_gc, stipple);
gdk_gc_set_fill(temp_gc, GDK_STIPPLED);
gdk_draw_rectangle (drawable, temp_gc, FALSE, box_left, icon_bottom - 2, line_width, line_height);
}
if (real_draw)
gdk_gc_unref (temp_gc);
......@@ -709,7 +726,7 @@ nautilus_icons_view_icon_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable
if (container->details->zoom_level != NAUTILUS_ZOOM_LEVEL_SMALLEST) {
icon_height = details->pixbuf->art_pixbuf->height * item->canvas->pixels_per_unit;
nautilus_icons_view_draw_text_box(item, drawable, title_font, details->label, item->x1 - x,
item->y1 - y + icon_height, details->is_selected, TRUE);
item->y1 - y + icon_height, TRUE);
}
}
......
......@@ -121,9 +121,6 @@ struct _GnomeIconContainerDetails {
icon items. */
GHashTable *canvas_item_to_icon;
/* Rectangle that shows that a certain icon is selected. */
GnomeCanvasItem *kbd_navigation_rectangle;
/* Current icon for keyboard navigation. */
GnomeIconContainerIcon *kbd_current;
......
......@@ -866,6 +866,11 @@ set_kbd_current (GnomeIconContainer *container,
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = icon;
if (details->kbd_current == NULL)
......@@ -873,16 +878,11 @@ set_kbd_current (GnomeIconContainer *container,
icon_get_text_bounding_box (icon, &x1, &y1, &x2, &y2);
gnome_canvas_item_set (details->kbd_navigation_rectangle,
"x1", (gdouble) x1 - 1,
"y1", (gdouble) y1 - 1,
"x2", (gdouble) x2,
"y2", (gdouble) y2,
gnome_canvas_item_set (icon->item,
"alt_selected", 1,
NULL);
gnome_canvas_item_show (details->kbd_navigation_rectangle);
icon_raise (icon);
gnome_canvas_item_raise_to_top (details->kbd_navigation_rectangle);
if (schedule_visibility)
schedule_kbd_icon_visibility (container);
......@@ -896,10 +896,12 @@ unset_kbd_current (GnomeIconContainer *container)
GnomeIconContainerDetails *details;
details = container->details;
if (details->kbd_current)
gnome_canvas_item_set (details->kbd_current->item,
"alt_selected", 0,
NULL);
details->kbd_current = NULL;
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
unschedule_kbd_icon_visibility (container);
}
......@@ -2018,15 +2020,6 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->canvas_item_to_icon = g_hash_table_new (g_direct_hash,
g_direct_equal);
details->kbd_navigation_rectangle
= gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (container)),
gnome_canvas_rect_get_type (),
"outline_color", "black",
"outline_stipple", stipple,
"width_pixels", 1,
NULL);
gnome_canvas_item_hide (details->kbd_navigation_rectangle);
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
......
......@@ -94,6 +94,12 @@ enum {
#define MAX_LABEL_WIDTH 80
/* Bitmap for stippled selection rectangles. */
static GdkBitmap *stipple;
static char stipple_bits[] = { 0x02, 0x01 };
/* headers */
static void nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *class);
static void nautilus_icons_view_icon_item_initialize (NautilusIconsViewIconItem *cpb);
static void nautilus_icons_view_icon_item_destroy (GtkObject *object);
......@@ -107,7 +113,7 @@ static double nautilus_icons_view_icon_item_point (GnomeCanvasItem *item, double
static void nautilus_icons_view_icon_item_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
static void nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw);
gint icon_left, gint icon_bottom, gboolean real_draw);
static GdkFont* get_font_for_item(GnomeCanvasItem *item);
......@@ -152,6 +158,8 @@ nautilus_icons_view_icon_item_initialize_class (NautilusIconsViewIconItemClass *
item_class->render = nautilus_icons_view_icon_item_render;
item_class->point = nautilus_icons_view_icon_item_point;
item_class->bounds = nautilus_icons_view_icon_item_bounds;
stipple = gdk_bitmap_create_from_data (NULL, stipple_bits, 2, 2);
}
/* Object initialization function for the icon item */
......@@ -498,7 +506,7 @@ nautilus_icons_view_icon_item_update (GnomeCanvasItem *item, double *affine, Art
title_font = get_font_for_item(item);
/* make sure the text box measurements are set up before recalculating the bounding box */
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, details->is_selected, FALSE);
nautilus_icons_view_draw_text_box(item, NULL, title_font, details->label, 0, 0, FALSE);
recompute_bounding_box(icon_view_item);
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, update, (item, affine, clip_path, flags));
......@@ -582,7 +590,7 @@ transform_pixbuf (guchar *dest, int x, int y, int width, int height, int rowstri
/* utility routine to draw the label in a box, using gnomelib routines */
static void
nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable, GdkFont *title_font, gchar* label,
gint icon_left, gint icon_bottom, gboolean is_selected, gboolean real_draw)
gint icon_left, gint icon_bottom, gboolean real_draw)
{
GnomeIconTextInfo *icon_text_info;
gint box_left;
......@@ -620,13 +628,22 @@ nautilus_icons_view_draw_text_box (GnomeCanvasItem* item, GdkDrawable *drawable,
}
/* invert to indicate selection if necessary */
if (is_selected && real_draw)
if (details->is_selected && real_draw)
{
gdk_gc_set_function (temp_gc, GDK_INVERT);
gdk_draw_rectangle (drawable, temp_gc, TRUE, box_left, icon_bottom - 2, line_width, line_height);
gdk_gc_set_function (temp_gc, GDK_COPY);
}
/* indicate alt-selection by framing the text with a gray-stippled rectangle */
if (details->is_alt_selected && real_draw)
{
gdk_gc_set_stipple(temp_gc, stipple);
gdk_gc_set_fill(temp_gc, GDK_STIPPLED);
gdk_draw_rectangle (drawable, temp_gc, FALSE, box_left, icon_bottom - 2, line_width, line_height);
}
if (real_draw)
gdk_gc_unref (temp_gc);
......@@ -709,7 +726,7 @@ nautilus_icons_view_icon_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable
if (container->details->zoom_level != NAUTILUS_ZOOM_LEVEL_SMALLEST) {
icon_height = details->pixbuf->art_pixbuf->height * item->canvas->pixels_per_unit;
nautilus_icons_view_draw_text_box(item, drawable, title_font, details->label, item->x1 - x,
item->y1 - y + icon_height, details->is_selected, TRUE);
item->y1 - y + icon_height, TRUE);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment