[almanah] Fix the calendar button/window style
- From: Ãlvaro PeÃa <alvaropg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [almanah] Fix the calendar button/window style
- Date: Thu, 31 May 2012 16:45:38 +0000 (UTC)
commit 2ae868ba36ec71298a3101b25f6afe42698bc109
Author: Ãlvaro PeÃa <alvaropg gmail com>
Date: Thu May 31 18:44:46 2012 +0200
Fix the calendar button/window style
data/Makefile.am | 4 +++-
data/calendar-window.css | 4 ++++
src/interface.c | 9 +++++++++
src/interface.h | 1 +
src/widgets/calendar-button.c | 14 +++++++++++---
src/widgets/calendar-window.c | 20 ++++++++++++++++++++
6 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 69b1db0..1726f23 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -22,7 +22,9 @@ update-icon-cache:
###############################################################################
uidir = $(datadir)/almanah
-ui_DATA = almanah.ui
+ui_DATA = \
+ almanah.ui \
+ calendar-window.css
###############################################################################
# Desktop file
diff --git a/data/calendar-window.css b/data/calendar-window.css
new file mode 100644
index 0000000..60cdc99
--- /dev/null
+++ b/data/calendar-window.css
@@ -0,0 +1,4 @@
+/* Style to make the Calendar window looks like a menu popup */
+AlmanahCalendarWindow {
+ background-color: @menu_bg_color;
+}
diff --git a/src/interface.c b/src/interface.c
index d48b89a..1e4c45e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -34,6 +34,15 @@ almanah_get_interface_filename (void)
return PACKAGE_DATA_DIR"/almanah/almanah.ui";
}
+const gchar *
+almanah_get_css_path (void)
+{
+ if (g_file_test ("./data", G_FILE_TEST_IS_DIR) == TRUE)
+ return "./data";
+ else
+ return PACKAGE_DATA_DIR"/almanah";
+}
+
void
almanah_interface_create_text_tags (GtkTextBuffer *text_buffer, gboolean connect_events)
{
diff --git a/src/interface.h b/src/interface.h
index 0d02179..f3017d7 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -25,6 +25,7 @@
G_BEGIN_DECLS
const gchar *almanah_get_interface_filename (void);
+const gchar *almanah_get_css_path (void);
void almanah_interface_create_text_tags (GtkTextBuffer *text_buffer, gboolean connect_events);
void almanah_calendar_month_changed_cb (GtkCalendar *calendar, gpointer user_data);
gboolean almanah_run_on_screen (GdkScreen *screen, const gchar *command_line, GError **error);
diff --git a/src/widgets/calendar-button.c b/src/widgets/calendar-button.c
index d9635bd..1c36d5c 100644
--- a/src/widgets/calendar-button.c
+++ b/src/widgets/calendar-button.c
@@ -147,6 +147,7 @@ almanah_calendar_button_init (AlmanahCalendarButton *self)
return;
}
+ gtk_window_set_type_hint (GTK_WINDOW (self->priv->dock), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
g_signal_connect (self->priv->dock, "hide", G_CALLBACK (almanah_calendar_button_dock_hiden), self);
@@ -278,11 +279,11 @@ almanah_calendar_button_toggled (GtkToggleButton *togglebutton, gpointer user_da
gint x, y;
AlmanahCalendarButton *self;
GtkStyleContext *style_context;
+ const GtkWidgetPath *path;
self = ALMANAH_CALENDAR_BUTTON (togglebutton);
- style_context = gtk_widget_get_style_context (GTK_WIDGET (togglebutton));
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
if (gtk_toggle_button_get_active (togglebutton)) {
- /* FIXME: Changing the style don't work!?! */
gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
/* Show the dock */
@@ -295,7 +296,14 @@ almanah_calendar_button_toggled (GtkToggleButton *togglebutton, gpointer user_da
/* Isn't necesary to hide the dock */
}
- gtk_widget_reset_style (GTK_WIDGET (togglebutton));
+ gtk_widget_reset_style (GTK_WIDGET (self));
+
+ /* Just for style purposes.
+ * Remove the toolbar style from the path allowing display the CalendarButton as a MenuItem when the user activate it.
+ * It's necesary remove the toolbar style classes every time because the gtk_widget_reset_style reload the path.
+ */
+ path = gtk_style_context_get_path (style_context);
+ gtk_widget_path_iter_clear_classes ((GtkWidgetPath *) path, 2);
}
static void
diff --git a/src/widgets/calendar-window.c b/src/widgets/calendar-window.c
index 74a77bd..109b71c 100644
--- a/src/widgets/calendar-window.c
+++ b/src/widgets/calendar-window.c
@@ -50,7 +50,27 @@ almanah_calendar_window_class_init (AlmanahCalendarWindowClass *klass)
static void
almanah_calendar_window_init (AlmanahCalendarWindow *self)
{
+ gchar *css_path;
+ GtkCssProvider *style_provider;
+ GError *error = NULL;
+
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_CALENDAR_WINDOW, AlmanahCalendarWindowPrivate);
+
+ css_path = g_build_filename (almanah_get_css_path (), "calendar-window.css", NULL);
+ style_provider = gtk_css_provider_new ();
+ if (!gtk_css_provider_load_from_path (style_provider, css_path, NULL)) {
+ /* Error loading the CSS */
+ g_warning (_("Couldn't load the CSS file '%s' for calendar window. The interface might not be styled correctly"), css_path);
+ g_error_free (error);
+ } else {
+ GtkStyleContext *style_context;
+
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+ gtk_style_context_add_provider (style_context, GTK_STYLE_PROVIDER (style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+
+ g_free (css_path);
+ g_object_unref (style_provider);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]