Commit c7994562 authored by Michael Meeks's avatar Michael Meeks Committed by Michael Meeks

impl, split, upd. (nautilus_icon_container_get_label_color): don't fetch

2002-07-11  Michael Meeks  <michael@ximian.com>

	* libnautilus-private/nautilus-icon-container.c
	(setup_gc_with_fg, setup_label_gcs, update_label_color):
	impl, split, upd.
	(nautilus_icon_container_get_label_color): don't
	fetch the style for no good reason, get the colored
	gc from an array instead. rename to
	(nautilus_icon_container_get_label_color_and_gc): this
	(realize, unrealize): setup / free the gcs.

	* libnautilus-private/nautilus-icon-canvas-item.c
	(draw_or_measure_label_text): use cached gc(s) from
	the container, instead of thrashing them.
	(antialias_selection_rectangle): upper case, and #define
	since it's always true.
parent 9bb1dff3
2002-07-11 Michael Meeks <michael@ximian.com>
* libnautilus-private/nautilus-icon-container.c
(setup_gc_with_fg, setup_label_gcs, update_label_color):
impl, split, upd.
(nautilus_icon_container_get_label_color): don't
fetch the style for no good reason, get the colored
gc from an array instead. rename to
(nautilus_icon_container_get_label_color_and_gc): this
(realize, unrealize): setup / free the gcs.
* libnautilus-private/nautilus-icon-canvas-item.c
(draw_or_measure_label_text): use cached gc(s) from
the container, instead of thrashing them.
(antialias_selection_rectangle): upper case, and #define
since it's always true.
2002-07-11 Michael Meeks <michael@ximian.com>
* libnautilus-private/nautilus-icon-canvas-item.c
......
......@@ -133,7 +133,7 @@ typedef struct {
GList *emblem;
} EmblemLayout;
static gboolean antialias_selection_rectangle = TRUE;
#define ANTIALIAS_SELECTION_RECTANGLE TRUE
static int click_policy_auto_value;
......@@ -651,7 +651,6 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
canvas_item = GNOME_CANVAS_ITEM (item);
if (drawable != NULL) {
gc = gdk_gc_new (canvas_item->canvas->layout.bin_window);
icon_width = details->pixbuf == NULL ? 0 : gdk_pixbuf_get_width (details->pixbuf);
}
......@@ -665,7 +664,7 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
/* if the icon is highlighted, do some set-up */
if (needs_highlight && drawable != NULL && !details->is_renaming &&
details->text_width > 0 && details->text_height > 0) {
if (antialias_selection_rectangle) {
if (ANTIALIAS_SELECTION_RECTANGLE) {
selection_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
TRUE,
8,
......@@ -680,10 +679,8 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
icon_bottom);
g_object_unref (selection_pixbuf);
} else {
gdk_gc_set_rgb_fg_color (gc, &container->details->highlight_color);
gdk_draw_rectangle
(drawable, GTK_WIDGET (GNOME_CANVAS_ITEM (item)->canvas)->style->black_gc, TRUE,
(drawable, GTK_WIDGET (container)->style->black_gc, TRUE,
icon_left + (icon_width - details->text_width) / 2,
icon_bottom,
details->text_width, details->text_height);
......@@ -695,11 +692,9 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
layout = get_label_layout (&details->editable_text_layout, item, details->editable_text);
if (drawable != NULL) {
label_color = nautilus_icon_container_get_label_color
gc = nautilus_icon_container_get_label_color_and_gc
(NAUTILUS_ICON_CONTAINER (canvas_item->canvas),
TRUE, needs_highlight);
gdk_gc_set_rgb_fg_color (gc, label_color);
&label_color, TRUE, needs_highlight);
draw_label_layout (item, drawable,
layout, needs_highlight,
......@@ -720,12 +715,10 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
layout = get_label_layout (&details->additional_text_layout, item, details->additional_text);
if (drawable != NULL) {
label_color = nautilus_icon_container_get_label_color
gc = nautilus_icon_container_get_label_color_and_gc
(NAUTILUS_ICON_CONTAINER (canvas_item->canvas),
FALSE, needs_highlight);
&label_color, FALSE, needs_highlight);
gdk_gc_set_rgb_fg_color (gc, label_color);
draw_label_layout (item, drawable,
layout, needs_highlight,
label_color,
......@@ -737,10 +730,9 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
width_so_far = MAX (width_so_far, (guint) layout_width);
height_so_far += layout_height + LABEL_LINE_SPACING;
}
if (antialias_selection_rectangle) {
if (ANTIALIAS_SELECTION_RECTANGLE) {
/* add some extra space for highlighting even when we don't highlight so things won't move */
height_so_far += 2; /* extra slop for nicer highlighting */
width_so_far += 8; /* account for emboldening, plus extra to make it look nicer */
......@@ -778,10 +770,6 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
details->text_width = width_so_far;
details->text_height = height_so_far;
}
if (gc != NULL) {
g_object_unref (gc);
}
}
static void
......@@ -1229,7 +1217,7 @@ draw_label_layout (NautilusIconCanvasItem *item,
return;
}
if (!highlight || !antialias_selection_rectangle) {
if (!highlight || !ANTIALIAS_SELECTION_RECTANGLE) {
if (NAUTILUS_ICON_CONTAINER (GNOME_CANVAS_ITEM (item)->canvas)->details->use_drop_shadows) {
/* draw a drop shadow */
eel_gdk_draw_layout_with_drop_shadow (drawable, gc,
......
......@@ -158,6 +158,7 @@ static void icon_get_bounding_box (NautilusIcon
static gboolean is_renaming (NautilusIconContainer *container);
static gboolean is_renaming_pending (NautilusIconContainer *container);
static void process_pending_icon_to_rename (NautilusIconContainer *container);
static void setup_label_gcs (NautilusIconContainer *container);
static int click_policy_auto_value;
......@@ -2403,6 +2404,8 @@ realize (GtkWidget *widget)
(GTK_LAYOUT (widget)->bin_window,
&widget->style->bg[GTK_STATE_NORMAL]);
setup_label_gcs (NAUTILUS_ICON_CONTAINER (widget));
/* make us the focused widget */
g_assert (GTK_IS_WINDOW (gtk_widget_get_toplevel (widget)));
window = GTK_WINDOW (gtk_widget_get_toplevel (widget));
......@@ -2412,11 +2415,23 @@ realize (GtkWidget *widget)
static void
unrealize (GtkWidget *widget)
{
int i;
GtkWindow *window;
NautilusIconContainer *container;
container = NAUTILUS_ICON_CONTAINER (widget);
g_assert (GTK_IS_WINDOW (gtk_widget_get_toplevel (widget)));
window = GTK_WINDOW (gtk_widget_get_toplevel (widget));
gtk_window_set_focus (window, NULL);
for (i = 0; i < LAST_LABEL_COLOR; i++) {
if (container->details->label_gcs [i]) {
g_object_unref (container->details->label_gcs [i]);
container->details->label_gcs [i] = NULL;
}
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
......@@ -5011,42 +5026,68 @@ nautilus_icon_container_set_single_click_mode (NautilusIconContainer *container,
/* update the label color when the background changes */
GdkColor *
nautilus_icon_container_get_label_color (NautilusIconContainer *container,
gboolean is_name,
gboolean is_highlight)
GdkGC *
nautilus_icon_container_get_label_color_and_gc (NautilusIconContainer *container,
GdkColor **color,
gboolean is_name,
gboolean is_highlight)
{
GtkStyle *style;
g_return_val_if_fail (NAUTILUS_IS_ICON_CONTAINER (container), 0);
style = gtk_widget_get_style (GTK_WIDGET (container));
int idx;
if (is_name) {
if (is_highlight) {
return &container->details->label_color_highlight;
idx = LABEL_COLOR_HIGHLIGHT;
} else {
return &container->details->label_color;
idx = LABEL_COLOR;
}
} else {
if (is_highlight) {
return &container->details->label_info_color_highlight;
idx = LABEL_INFO_COLOR_HIGHLIGHT;
} else {
return &container->details->label_info_color;
idx = LABEL_INFO_COLOR;
}
}
if (color) {
*color = &container->details->label_colors [idx];
}
return container->details->label_gcs [idx];
}
static void
update_label_color (EelBackground *background,
NautilusIconContainer *container)
setup_gc_with_fg (NautilusIconContainer *container, int idx, guint32 color)
{
GdkGC *gc;
GdkColor gcolor;
gcolor = eel_gdk_rgb_to_color (color);
container->details->label_colors [idx] = gcolor;
gc = gdk_gc_new (GTK_LAYOUT (container)->bin_window);
gdk_gc_set_rgb_fg_color (gc, &gcolor);
if (container->details->label_gcs [idx]) {
g_object_unref (container->details->label_gcs [idx]);
}
container->details->label_gcs [idx] = gc;
}
static void
setup_label_gcs (NautilusIconContainer *container)
{
EelBackground *background;
char *light_info_color, *dark_info_color;
uint light_info_value, dark_info_value;
g_assert (EEL_IS_BACKGROUND (background));
if (!GTK_WIDGET_REALIZED (container))
return;
g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
background = eel_get_widget_background (GTK_WIDGET (container));
/* FIXME: The code to extract colors from the theme should be in FMDirectoryView, not here.
* The NautilusIconContainer class should simply provide calls to set the colors.
*/
......@@ -5066,19 +5107,28 @@ update_label_color (EelBackground *background,
dark_info_value = strtoul (dark_info_color, NULL, 0);
g_free (dark_info_color);
}
container->details->label_color_highlight = eel_gdk_rgb_to_color (0xFFFFFF);
container->details->label_info_color_highlight = eel_gdk_rgb_to_color (0xCCCCCC);
setup_gc_with_fg (container, LABEL_COLOR_HIGHLIGHT, 0xFFFFFF);
setup_gc_with_fg (container, LABEL_INFO_COLOR_HIGHLIGHT, 0xCCCCCC);
if (container->details->use_drop_shadows || eel_background_is_dark (background)) {
container->details->label_color = eel_gdk_rgb_to_color (0xEFEFEF);
container->details->label_info_color = eel_gdk_rgb_to_color (light_info_value);
setup_gc_with_fg (container, LABEL_COLOR, 0xEFEFEF);
setup_gc_with_fg (container, LABEL_INFO_COLOR, light_info_value);
} else { /* converse */
container->details->label_color = eel_gdk_rgb_to_color (0x000000);
container->details->label_info_color = eel_gdk_rgb_to_color (dark_info_value);
setup_gc_with_fg (container, LABEL_COLOR, 0x000000);
setup_gc_with_fg (container, LABEL_INFO_COLOR, dark_info_value);
}
}
static void
update_label_color (EelBackground *background,
NautilusIconContainer *container)
{
g_assert (EEL_IS_BACKGROUND (background));
setup_label_gcs (container);
}
/* Return if the icon container is a fixed size */
gboolean
......
......@@ -238,4 +238,5 @@ void nautilus_icon_container_set_margins (Nautilu
int bottom_margin);
void nautilus_icon_container_set_use_drop_shadows (NautilusIconContainer *container,
gboolean use_drop_shadows);
#endif /* NAUTILUS_ICON_CONTAINER_H */
......@@ -97,6 +97,14 @@ typedef struct {
guint64 last_typeselect_time;
} TypeSelectState;
enum {
LABEL_COLOR,
LABEL_COLOR_HIGHLIGHT,
LABEL_INFO_COLOR,
LABEL_INFO_COLOR_HIGHLIGHT,
LAST_LABEL_COLOR
};
struct NautilusIconContainerDetails {
/* List of icons. */
GList *icons;
......@@ -177,11 +185,9 @@ struct NautilusIconContainerDetails {
GdkColor highlight_color;
guint32 highlight_color_rgba;
/* color for text labels */
GdkColor label_color;
GdkColor label_color_highlight;
GdkColor label_info_color;
GdkColor label_info_color_highlight;
/* colors for text labels */
GdkGC *label_gcs [LAST_LABEL_COLOR];
GdkColor label_colors [LAST_LABEL_COLOR];
/* State used so arrow keys don't wander if icons aren't lined up.
* Keeps track of last axis arrow key was used on.
......@@ -250,7 +256,8 @@ gboolean nautilus_icon_container_scroll (NautilusIconC
void nautilus_icon_container_update_scroll_region (NautilusIconContainer *container);
/* label color for items */
GdkColor *nautilus_icon_container_get_label_color (NautilusIconContainer *container,
GdkGC *nautilus_icon_container_get_label_color_and_gc (NautilusIconContainer *container,
GdkColor **color,
gboolean first_line,
gboolean needs_highlight);
......
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