From 638df47ee07a8f5b3ad4cea9639ac05713ab328f Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Wed, 14 Nov 2012 07:20:41 +0200 Subject: [sidebar-title] try to use GtkStyle in _select_text_color() Hopefully this will play better with themes, when a custom (EelBackground) background is not set in the widget. --- src/caja-sidebar-title.c | 126 ++++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 44 deletions(-) (limited to 'src/caja-sidebar-title.c') diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index 15a761be..466d9873 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -51,12 +51,14 @@ #define MAX_TITLE_SIZE 256 #define MINIMUM_INFO_WIDTH 32 #define SIDEBAR_INFO_MARGIN 4 -#define SHADOW_OFFSET 1 #define MORE_INFO_FONT_SIZE 12 #define MIN_TITLE_FONT_SIZE 12 #define TITLE_PADDING 4 +#define DEFAULT_LIGHT_INFO_COLOR 0xFFFFFF +#define DEFAULT_DARK_INFO_COLOR 0x2A2A2A + static void caja_sidebar_title_class_init (CajaSidebarTitleClass *klass); static void caja_sidebar_title_destroy (GtkObject *object); static void caja_sidebar_title_init (CajaSidebarTitle *pixmap); @@ -72,20 +74,32 @@ static void style_set (GtkWidget GtkStyle *previous_style); static guint get_best_icon_size (CajaSidebarTitle *sidebar_title); +enum +{ + LABEL_COLOR, + LABEL_COLOR_HIGHLIGHT, + LABEL_COLOR_ACTIVE, + LABEL_COLOR_PRELIGHT, + LABEL_INFO_COLOR, + LABEL_INFO_COLOR_HIGHLIGHT, + LABEL_INFO_COLOR_ACTIVE, + LAST_LABEL_COLOR +}; + struct CajaSidebarTitleDetails { CajaFile *file; - guint file_changed_connection; - gboolean monitoring_count; + guint file_changed_connection; + gboolean monitoring_count; - char *title_text; + char *title_text; GtkWidget *icon; GtkWidget *title_label; GtkWidget *more_info_label; GtkWidget *emblem_box; - guint best_icon_size; - + GdkColor label_colors [LAST_LABEL_COLOR]; + guint best_icon_size; gboolean determined_icon; }; @@ -219,58 +233,82 @@ caja_sidebar_title_new (void) return gtk_widget_new (caja_sidebar_title_get_type (), NULL); } +static void +setup_gc_with_fg (CajaSidebarTitle *sidebar_title, int idx, guint32 color) +{ + sidebar_title->details->label_colors [idx] = eel_gdk_rgb_to_color (color); +} + void caja_sidebar_title_select_text_color (CajaSidebarTitle *sidebar_title, - EelBackground *background, - gboolean is_default) + EelBackground *background) { - char *sidebar_title_color; - char *sidebar_info_title_color; - char *sidebar_title_shadow_color; + GdkColor *light_info_color, *dark_info_color; + guint light_info_value, dark_info_value; + GtkStyle *style; - g_return_if_fail (background != NULL); + g_assert (CAJA_IS_SIDEBAR_TITLE (sidebar_title)); + g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (sidebar_title))); - /* if the background is set to the default, the theme can explicitly - * define the title colors. Check if the background has been customized - * and if the theme specified any colors - */ - sidebar_title_color = NULL; - sidebar_info_title_color = NULL; - sidebar_title_shadow_color = NULL; + /* read the info colors from the current theme; use a reasonable default if undefined */ + gtk_widget_style_get (GTK_WIDGET (sidebar_title), + "light_info_color", &light_info_color, + "dark_info_color", &dark_info_color, + NULL); + style = gtk_widget_get_style (GTK_WIDGET (sidebar_title)); - /* FIXME bugzilla.gnome.org 42496: for now, both the title and info - * colors are the same - and hard coded */ - if (eel_background_is_dark (background)) + if (light_info_color) { - sidebar_title_color = g_strdup ("#FFFFFF"); - sidebar_info_title_color = g_strdup ("#FFFFFF"); - sidebar_title_shadow_color = g_strdup ("#000000"); + light_info_value = eel_gdk_color_to_rgb (light_info_color); + gdk_color_free (light_info_color); } else { - sidebar_title_color = g_strdup ("#000000"); - sidebar_info_title_color = g_strdup ("#000000"); - sidebar_title_shadow_color = g_strdup ("#FFFFFF"); + light_info_value = DEFAULT_LIGHT_INFO_COLOR; } - eel_gtk_widget_set_foreground_color (sidebar_title->details->title_label, - sidebar_title_color); - eel_gtk_widget_set_foreground_color (sidebar_title->details->more_info_label, - sidebar_info_title_color); - - eel_gtk_label_set_drop_shadow_color (GTK_LABEL (sidebar_title->details->title_label), - eel_parse_rgb_with_white_default (sidebar_title_shadow_color)); - eel_gtk_label_set_drop_shadow_color (GTK_LABEL (sidebar_title->details->more_info_label), - eel_parse_rgb_with_white_default (sidebar_title_shadow_color)); + if (dark_info_color) + { + dark_info_value = eel_gdk_color_to_rgb (dark_info_color); + gdk_color_free (dark_info_color); + } + else + { + dark_info_value = DEFAULT_DARK_INFO_COLOR; + } - eel_gtk_label_set_drop_shadow_offset (GTK_LABEL (sidebar_title->details->title_label), - SHADOW_OFFSET); - eel_gtk_label_set_drop_shadow_offset (GTK_LABEL (sidebar_title->details->more_info_label), - SHADOW_OFFSET); - g_free (sidebar_title_color); - g_free (sidebar_info_title_color); - g_free (sidebar_title_shadow_color); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_HIGHLIGHT, + eel_gdk_color_to_rgb (&style->text[GTK_STATE_SELECTED])); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_ACTIVE, + eel_gdk_color_to_rgb (&style->text[GTK_STATE_ACTIVE])); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_PRELIGHT, + eel_gdk_color_to_rgb (&style->text[GTK_STATE_PRELIGHT])); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR_HIGHLIGHT, + eel_gdk_color_is_dark (&style->base[GTK_STATE_SELECTED]) ? light_info_value : dark_info_value); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR_ACTIVE, + eel_gdk_color_is_dark (&style->base[GTK_STATE_ACTIVE]) ? light_info_value : dark_info_value); + + /* If EelBackground is not set in the widget, we can safely + * use the foreground color from the theme, because it will + * always be displayed against the gtk background */ + if (!eel_background_is_set(background)) + { + setup_gc_with_fg (sidebar_title, LABEL_COLOR, + eel_gdk_color_to_rgb (&style->text[GTK_STATE_NORMAL])); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, + eel_gdk_color_is_dark (&style->base[GTK_STATE_NORMAL]) ? light_info_value : dark_info_value); + } + else if (eel_background_is_dark (background)) + { + setup_gc_with_fg (sidebar_title, LABEL_COLOR, 0xEFEFEF); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, light_info_value); + } + else /* converse */ + { + setup_gc_with_fg (sidebar_title, LABEL_COLOR, 0x000000); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, dark_info_value); + } } static char* -- cgit v1.2.1 From e96bb83cdc1ed0753d2547463a4e6ec61f41de12 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Wed, 14 Nov 2012 07:29:08 +0200 Subject: [sidebar-title] use gtk_label_set_attributes, obsolete eel_gtk_label_set_scale --- src/caja-sidebar-title.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/caja-sidebar-title.c') diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index 466d9873..beb30359 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -762,9 +762,16 @@ static GtkWidget * sidebar_title_create_more_info_label (void) { GtkWidget *more_info_label; + PangoAttrList *attrs; + + attrs = pango_attr_list_new (); + pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_SMALL)); more_info_label = gtk_label_new (""); - eel_gtk_label_set_scale (GTK_LABEL (more_info_label), PANGO_SCALE_SMALL); + + gtk_label_set_attributes (GTK_LABEL (more_info_label), attrs); + pango_attr_list_unref (attrs); + gtk_label_set_justify (GTK_LABEL (more_info_label), GTK_JUSTIFY_CENTER); gtk_label_set_selectable (GTK_LABEL (more_info_label), TRUE); gtk_label_set_ellipsize (GTK_LABEL (more_info_label), PANGO_ELLIPSIZE_END); -- cgit v1.2.1 From f9c3a1bd9499c47db2b32a0487ad3c91dbafeea9 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Wed, 14 Nov 2012 07:30:55 +0200 Subject: [information-panel] don't use eel_point_in_widget() nor in sidebar-title. the eel function is deprecated. --- src/caja-sidebar-title.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/caja-sidebar-title.c') diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index beb30359..e02eaa9d 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -738,9 +738,21 @@ caja_sidebar_title_size_allocate (GtkWidget *widget, gboolean caja_sidebar_title_hit_test_icon (CajaSidebarTitle *sidebar_title, int x, int y) { + GtkAllocation *allocation; + gboolean icon_hit; + g_return_val_if_fail (CAJA_IS_SIDEBAR_TITLE (sidebar_title), FALSE); - return eel_point_in_widget (sidebar_title->details->icon, x, y); + allocation = g_new0 (GtkAllocation, 1); + gtk_widget_get_allocation (GTK_WIDGET (sidebar_title->details->icon), allocation); + g_return_val_if_fail (allocation != NULL, FALSE); + + icon_hit = x >= allocation->x && y >= allocation->y + && x < allocation->x + allocation->width + && y < allocation->y + allocation->height; + g_free (allocation); + + return icon_hit; } static GtkWidget * -- cgit v1.2.1 From 74206714b6a34f49d5fa8f0b7b50f845f3836924 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Tue, 13 Nov 2012 15:52:16 +0200 Subject: [sidebar-title] Use pango directly to set largest-fitting font size and don't include eel-pango-extensions, which is to be dropped. --- src/caja-sidebar-title.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'src/caja-sidebar-title.c') diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index e02eaa9d..86dd4e41 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -36,9 +36,8 @@ #include #include #include -#include -#include #include +#include #include #include #include @@ -399,15 +398,16 @@ update_icon (CajaSidebarTitle *sidebar_title) static void update_title_font (CajaSidebarTitle *sidebar_title) { - int available_width; - PangoFontDescription *title_font; - int largest_fitting_font_size; - int max_style_font_size; + int available_width, width; + int max_fit_font_size, max_style_font_size; GtkStyle *style; GtkAllocation allocation; + PangoFontDescription *title_font, *tmp_font; + PangoLayout *layout; /* Make sure theres work to do */ - if (eel_strlen (sidebar_title->details->title_text) < 1) + if (sidebar_title->details->title_text == NULL + || strlen (sidebar_title->details->title_text) < 1) { return; } @@ -430,19 +430,29 @@ update_title_font (CajaSidebarTitle *sidebar_title) max_style_font_size = MIN_TITLE_FONT_SIZE + 1; } - largest_fitting_font_size = eel_pango_font_description_get_largest_fitting_font_size ( - title_font, - gtk_widget_get_pango_context (sidebar_title->details->title_label), - sidebar_title->details->title_text, - available_width, - MIN_TITLE_FONT_SIZE, - max_style_font_size); - pango_font_description_set_size (title_font, largest_fitting_font_size * PANGO_SCALE); + /* Calculate largest-fitting font size */ + layout = pango_layout_new (gtk_widget_get_pango_context (sidebar_title->details->title_label)); + pango_layout_set_text (layout, sidebar_title->details->title_text, -1); + pango_layout_set_font_description (layout, title_font); + tmp_font = pango_font_description_new (); - pango_font_description_set_weight (title_font, PANGO_WEIGHT_BOLD); + max_fit_font_size = max_style_font_size; + for (; max_fit_font_size >= MIN_TITLE_FONT_SIZE; max_fit_font_size--) + { + pango_font_description_set_size (tmp_font, max_fit_font_size * PANGO_SCALE); + pango_layout_set_font_description (layout, tmp_font); + pango_layout_get_pixel_size (layout, &width, NULL); - gtk_widget_modify_font (sidebar_title->details->title_label, - title_font); + if (width <= available_width) + break; + } + + pango_font_description_free (tmp_font); + g_object_unref (layout); + + pango_font_description_set_size (title_font, max_fit_font_size * PANGO_SCALE); + pango_font_description_set_weight (title_font, PANGO_WEIGHT_BOLD); + gtk_widget_modify_font (sidebar_title->details->title_label, title_font); pango_font_description_free (title_font); } @@ -455,7 +465,7 @@ update_title (CajaSidebarTitle *sidebar_title) label = GTK_LABEL (sidebar_title->details->title_label); text = sidebar_title->details->title_text; - if (eel_strcmp (text, gtk_label_get_text (label)) == 0) + if (g_strcmp0 (text, gtk_label_get_text (label)) == 0) { return; } -- cgit v1.2.1 From dc5517f0b74d260129753417f7f36b06ef9f4121 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Tue, 13 Nov 2012 07:25:36 +0200 Subject: [sidebar-title] Don't use GtkObject nor eel-gtk-macros --- src/caja-sidebar-title.c | 65 +++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'src/caja-sidebar-title.c') diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index 86dd4e41..c7bda988 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -58,20 +57,17 @@ #define DEFAULT_LIGHT_INFO_COLOR 0xFFFFFF #define DEFAULT_DARK_INFO_COLOR 0x2A2A2A -static void caja_sidebar_title_class_init (CajaSidebarTitleClass *klass); -static void caja_sidebar_title_destroy (GtkObject *object); -static void caja_sidebar_title_init (CajaSidebarTitle *pixmap); -static void caja_sidebar_title_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void update_icon (CajaSidebarTitle *sidebar_title); -static GtkWidget * sidebar_title_create_title_label (void); -static GtkWidget * sidebar_title_create_more_info_label (void); -static void update_all (CajaSidebarTitle *sidebar_title); -static void update_more_info (CajaSidebarTitle *sidebar_title); -static void update_title_font (CajaSidebarTitle *sidebar_title); -static void style_set (GtkWidget *widget, - GtkStyle *previous_style); -static guint get_best_icon_size (CajaSidebarTitle *sidebar_title); +static void caja_sidebar_title_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void update_icon (CajaSidebarTitle *sidebar_title); +static GtkWidget * sidebar_title_create_title_label (void); +static GtkWidget * sidebar_title_create_more_info_label (void); +static void update_all (CajaSidebarTitle *sidebar_title); +static void update_more_info (CajaSidebarTitle *sidebar_title); +static void update_title_font (CajaSidebarTitle *sidebar_title); +static void style_set (GtkWidget *widget, + GtkStyle *previous_style); +static guint get_best_icon_size (CajaSidebarTitle *sidebar_title); enum { @@ -102,22 +98,8 @@ struct CajaSidebarTitleDetails gboolean determined_icon; }; -EEL_CLASS_BOILERPLATE (CajaSidebarTitle, caja_sidebar_title, gtk_vbox_get_type ()) +G_DEFINE_TYPE (CajaSidebarTitle, caja_sidebar_title, GTK_TYPE_VBOX) -static void -caja_sidebar_title_class_init (CajaSidebarTitleClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass*) class; - widget_class = (GtkWidgetClass*) class; - - object_class->destroy = caja_sidebar_title_destroy; - widget_class->size_allocate = caja_sidebar_title_size_allocate; - widget_class->style_set = style_set; - -} static void style_set (GtkWidget *widget, @@ -150,7 +132,9 @@ style_set (GtkWidget *widget, static void caja_sidebar_title_init (CajaSidebarTitle *sidebar_title) { - sidebar_title->details = g_new0 (CajaSidebarTitleDetails, 1); + sidebar_title->details = G_TYPE_INSTANCE_GET_PRIVATE (sidebar_title, + CAJA_TYPE_SIDEBAR_TITLE, + CajaSidebarTitleDetails); /* Create the icon */ sidebar_title->details->icon = gtk_image_new (); @@ -204,7 +188,7 @@ release_file (CajaSidebarTitle *sidebar_title) } static void -caja_sidebar_title_destroy (GtkObject *object) +caja_sidebar_title_finalize (GObject *object) { CajaSidebarTitle *sidebar_title; @@ -215,14 +199,23 @@ caja_sidebar_title_destroy (GtkObject *object) release_file (sidebar_title); g_free (sidebar_title->details->title_text); - g_free (sidebar_title->details); - sidebar_title->details = NULL; } g_signal_handlers_disconnect_by_func (caja_preferences, update_more_info, sidebar_title); - EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object)); + G_OBJECT_CLASS (caja_sidebar_title_parent_class)->finalize (object); +} + +static void +caja_sidebar_title_class_init (CajaSidebarTitleClass *klass) +{ + g_type_class_add_private (klass, sizeof (CajaSidebarTitleDetails)); + + G_OBJECT_CLASS (klass)->finalize = caja_sidebar_title_finalize; + + GTK_WIDGET_CLASS (klass)->size_allocate = caja_sidebar_title_size_allocate; + GTK_WIDGET_CLASS (klass)->style_set = style_set; } /* return a new index title object */ @@ -726,7 +719,7 @@ caja_sidebar_title_size_allocate (GtkWidget *widget, gtk_widget_get_allocation (widget, &old_allocation); old_width = old_allocation.width; - EEL_CALL_PARENT (GTK_WIDGET_CLASS, size_allocate, (widget, allocation)); + GTK_WIDGET_CLASS (caja_sidebar_title_parent_class)->size_allocate (widget, allocation); gtk_widget_get_allocation (widget, &new_allocation); -- cgit v1.2.1