[almanah] Finished main window re-design.



commit fec6ff0932c79d6e142cd1dfb263ce38f425f70a
Author: Ãlvaro PeÃa <alvaropg gmail com>
Date:   Mon Nov 26 23:17:26 2012 +0100

    Finished main window re-design.
    
    Removed the main toolbar from the UI file and created in execution time. Moved all the CSS
    style to just one file. Now the code is more clean and the main window looks more like the
    proposed design[1]
    
    [1] https://live.gnome.org/Almanah_Diary/Design#New_Design

 data/Makefile.am                     |    3 +-
 data/almanah.css                     |   29 +++++
 data/almanah.ui                      |   44 ++------
 data/calendar-button.css             |   17 ---
 data/calendar-window.css             |    4 -
 src/Makefile.am                      |    2 -
 src/application.c                    |   14 +++
 src/main-window.c                    |  214 ++++++++++++----------------------
 src/widgets/calendar-button.c        |   18 ---
 src/widgets/calendar-window.c        |   20 ---
 src/widgets/font-style-menu-action.c |   58 ---------
 src/widgets/font-style-menu-action.h |   47 --------
 12 files changed, 127 insertions(+), 343 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 96cff84..e6d3399 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -25,8 +25,7 @@ uidir = $(datadir)/almanah
 ui_DATA = \
 	almanah.ui		\
 	almanah-app-menu.ui	\
-	calendar-button.css	\
-	calendar-window.css
+	almanah.css
 
 ###############################################################################
 # Desktop file
diff --git a/data/almanah.css b/data/almanah.css
new file mode 100644
index 0000000..c0c3f42
--- /dev/null
+++ b/data/almanah.css
@@ -0,0 +1,29 @@
+AlmanahCalendarButton:active {
+    background-image: none;
+    background-color: @menu_bg_color;
+
+    border-image: none;
+    border-color: @menu_bg_color;
+    border-radius: 4px 4px 0 0;
+}
+
+AlmanahCalendarButton GtkLabel:active {
+    color: @theme_text_color;
+    text-shadow: none;
+}
+
+AlmanahCalendarButton GtkArrow:active {
+    color: @theme_text_color;
+}
+
+AlmanahCalendarWindow {
+    background-color: @menu_bg_color;
+}
+
+AlmanahMainWindow GtkScrolledWindow {
+    border-style: solid;
+    border-radius: 0px;
+    border-width: 0px;
+    border-top-width: 1px;
+    border-bottom-width: 1px;
+}
diff --git a/data/almanah.ui b/data/almanah.ui
index 5be21ff..0ef4441 100644
--- a/data/almanah.ui
+++ b/data/almanah.ui
@@ -77,7 +77,7 @@
 						<property name="name">format-hyperlink</property>
 						<property name="label" translatable="yes">Add/Remove _Hyperlink</property>
 						<property name="tooltip" translatable="yes">Add or remove a hyperlink from the currently selected text to a specified URI.</property>
-						<property name="icon-name">insert-link</property>
+						<property name="icon-name">insert-link-symbolic</property>
 					</object>
 					<accelerator key="H" modifiers="GDK_CONTROL_MASK"/>
 				</child>
@@ -94,8 +94,7 @@
 						<property name="name">format-important</property>
 						<property name="label" translatable="yes">I_mportant</property>
 						<property name="tooltip" translatable="yes">Toggle whether the current entry is marked as important.</property>
-						<property name="icon-name">emblem-important</property>
-						<property name="is-important">True</property>
+						<property name="icon-name">starred-symbolic</property>
 						<signal name="activate" handler="mw_important_activate_cb"/>
 					</object>
 					<accelerator key="M" modifiers="GDK_CONTROL_MASK"/>
@@ -116,21 +115,6 @@
 						<signal name="activate" handler="mw_jump_to_today_activate_cb"/>
 					</object>
 				</child>
-				<child>
-					<object class="AlmanahFontStyleMenuAction" id="almanah_ui_font_style">
-						<property name="stock-id">gtk-select-font</property>
-						<property name="name">format-font-style</property>
-						<property name="label" translatable="yes">Font Style</property>
-						<property name="tooltip" translatable="yes">Change font style for selected text.</property>
-						<signal name="activate" handler="mw_font_style_activate_cb"/>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="almanah_ui_font_style_menu">
-						<property name="name">font-style</property>
-						<property name="label" translatable="yes">_Font Style</property>
-					</object>
-				</child>
 			</object>
 		</child>
 		<ui>
@@ -141,18 +125,13 @@
 				<menuitem action="almanah_ui_delete"/>
 				<separator/>
 				<menuitem action="almanah_ui_insert_time"/>
+				<menuitem action="almanah_ui_hyperlink"/>
 			</popup>
-			<toolbar name="almanah_mw_toolbar">
-				<toolitem action="almanah_ui_font_style">
-					<menu action="almanah_ui_font_style_menu">
-						<menuitem action="almanah_ui_bold"/>
-						<menuitem action="almanah_ui_italic"/>
-						<menuitem action="almanah_ui_underline"/>
-					</menu>
-				</toolitem>
-				<toolitem action="almanah_ui_hyperlink"/>
-				<toolitem action="almanah_ui_important"/>
-			</toolbar>
+                        <popup name="almanah_mw_font_menu">
+                                <menuitem action="almanah_ui_bold"/>
+                                <menuitem action="almanah_ui_italic"/>
+                                <menuitem action="almanah_ui_underline"/>
+                        </popup>
 		</ui>
 	</object>
 
@@ -225,10 +204,7 @@
 		<child>
 			<object class="GtkVBox" id="vbox1">
 				<child>
-					<object class="GtkToolbar" constructor="almanah_ui_manager" id="almanah_mw_toolbar">
-						<style>
-							<class name="primary-toolbar"/>
-						</style>
+					<object class="GtkToolbar" id="almanah_mw_toolbar">
 					</object>
 					<packing>
 						<property name="expand">False</property>
@@ -244,7 +220,7 @@
 										<property name="can-focus">True</property>
 										<property name="hscrollbar-policy">GTK_POLICY_AUTOMATIC</property>
 										<property name="vscrollbar-policy">GTK_POLICY_AUTOMATIC</property>
-										<property name="shadow-type">GTK_SHADOW_NONE</property>
+										<property name="shadow-type">GTK_SHADOW_IN</property>
 										<child>
 											<object class="GtkTextView" id="almanah_mw_entry_view">
 												<property name="width-request">300</property>
diff --git a/src/Makefile.am b/src/Makefile.am
index 3951d63..0de37e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,8 +40,6 @@ almanah_SOURCES = \
 	widgets/calendar-button.c		\
 	widgets/calendar-window.h		\
 	widgets/calendar-window.c		\
-	widgets/font-style-menu-action.h	\
-	widgets/font-style-menu-action.c	\
 	widgets/hyperlink-tag.c			\
 	widgets/hyperlink-tag.h
 
diff --git a/src/application.c b/src/application.c
index b1f4dab..5b61563 100644
--- a/src/application.c
+++ b/src/application.c
@@ -213,6 +213,8 @@ startup (GApplication *application)
 	AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
 	gchar *db_filename;
 	GError *error = NULL;
+	GtkCssProvider *style_provider;
+	gchar *css_path;
 
 	/* Chain up. */
 	G_APPLICATION_CLASS (almanah_application_parent_class)->startup (application);
@@ -262,6 +264,18 @@ startup (GApplication *application)
 
 	/* Load GMenu application actions */
 	almanah_application_init_actions (ALMANAH_APPLICATION (application));
+
+	css_path = g_build_filename (almanah_get_css_path (), "almanah.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'. The interface might not be styled correctly"), css_path);
+		g_error_free (error);
+	} else {
+		gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+	}
+	g_free (css_path);
+	g_object_unref (style_provider);
 }
 
 /* Nullify our pointer to the main window when it gets destroyed (e.g. when we quit) so that we don't then try
diff --git a/src/main-window.c b/src/main-window.c
index e5433c9..cd73cb2 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -19,6 +19,7 @@
 
 #include <config.h>
 #include <time.h>
+#include <math.h>
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
@@ -37,7 +38,6 @@
 #include "uri-entry-dialog.h"
 #include "widgets/calendar.h"
 #include "widgets/calendar-button.h"
-#include "widgets/font-style-menu-action.h"
 #include "widgets/hyperlink-tag.h"
 
 /* Interval for automatically saving the current entry. Currently an arbitrary 10 minutes. */
@@ -62,10 +62,9 @@ static void mw_italic_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *ma
 static void mw_underline_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *main_window);
 static void mw_hyperlink_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *main_window);
 static void mw_events_updated_cb (AlmanahEventManager *event_manager, AlmanahEventFactoryType type_id, AlmanahMainWindow *main_window);
-static void mw_font_style_menu_position_func (GtkMenu *menu, int *x, int *y, gboolean *push_in, GtkMenuToolButton *button);
-static GtkMenuToolButton *mw_get_font_style_tool_button_from_action (GtkAction *action);
 static gboolean save_entry_timeout_cb (AlmanahMainWindow *self);
-static void mw_setup_toolbar (AlmanahMainWindow *main_window, AlmanahApplication *application, GtkToolbar *toolbar, GtkAction *today_action, GtkAction *select_date_action, GtkWidget *menu_popup);
+static gint get_icon_margin (void);
+static void mw_setup_toolbar (AlmanahMainWindow *main_window, AlmanahApplication *application, GtkBuilder *builder);
 
 /* GtkBuilder callbacks */
 void mw_cut_activate_cb (GtkAction *action, AlmanahMainWindow *main_window);
@@ -78,7 +77,6 @@ void mw_select_date_activate_cb (GtkAction *action, AlmanahMainWindow *main_wind
 void mw_jump_to_today_activate_cb (GtkAction *action, AlmanahMainWindow *main_window);
 void mw_old_entries_activate_cb (GtkAction *action, AlmanahMainWindow *main_window);
 void mw_events_tree_view_row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, AlmanahMainWindow *main_window);
-void mw_font_style_activate_cb (AlmanahFontStyleMenuAction *action, AlmanahMainWindow *main_window);
 
 /* Other callbacks */
 void mw_calendar_day_selected_cb (AlmanahCalendarButton *calendar, AlmanahMainWindow *main_window);
@@ -100,7 +98,6 @@ struct _AlmanahMainWindowPrivate {
 	GtkAction *copy_action;
 	GtkAction *delete_action;
 	GtkAction *important_action;
-	GtkMenuToolButton *font_style_tool_button;
 
 	gboolean updating_formatting;
 	gboolean pending_bold_active;
@@ -172,10 +169,6 @@ almanah_main_window_new (AlmanahApplication *application)
 	AlmanahEventManager *event_manager;
 	AlmanahMainWindow *main_window;
 	AlmanahMainWindowPrivate *priv;
-	GtkToolbar *toolbar;
-	GtkAction *today_action, *select_date_action;
-	GtkUIManager *manager;
-	GtkWidget *menu_popup;
 	GError *error = NULL;
 	const gchar *interface_filename = almanah_get_interface_filename ();
 	const gchar *object_names[] = {
@@ -235,7 +228,6 @@ almanah_main_window_new (AlmanahApplication *application)
 	priv->copy_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_copy"));
 	priv->delete_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_delete"));
 	priv->important_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_important"));
-	priv->font_style_tool_button = mw_get_font_style_tool_button_from_action (GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_font_style")));
 
 #ifdef ENABLE_SPELL_CHECKING
 	/* Set up spell checking, if it's enabled */
@@ -276,13 +268,8 @@ almanah_main_window_new (AlmanahApplication *application)
 	g_signal_connect (event_manager, "events-updated", G_CALLBACK (mw_events_updated_cb), main_window);
 	g_object_unref (event_manager);
 
-	/* Set up the toolbar */
-	toolbar = GTK_TOOLBAR (gtk_builder_get_object (builder, "almanah_mw_toolbar"));
-	today_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_jump_to_today"));
-	select_date_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_select_date"));
-	manager = GTK_UI_MANAGER (gtk_builder_get_object (builder, "almanah_ui_manager"));
-	menu_popup = gtk_ui_manager_get_widget (manager, "/almanah_mw_menu_button");
-	mw_setup_toolbar (main_window, application, toolbar, today_action, select_date_action, menu_popup);
+	/* Set up the main toolbar */
+	mw_setup_toolbar (main_window, application, builder);
 
 	/* Select the current day and month */
 	mw_jump_to_today_activate_cb (NULL, main_window);
@@ -1024,99 +1011,6 @@ mw_old_entries_activate_cb (GtkAction *action, AlmanahMainWindow *main_window)
 	g_debug ("Old entries clicked, but nothing implemented yet...");
 }
 
-/**
- * Just copied from GtkMenuToolButton (menu_position_func),
- * but using the button widget (not the arrow widget) for
- * menu position calc, and removing the code for a vertical
- * toolbar situation.
- *
- * Copyright (C) 2003 Ricardo Fernandez Pascual
- * Copyright (C) 2004 Paolo Borelli
- * Licensed under the GPL v2
- */
-static void
-mw_font_style_menu_position_func (GtkMenu *menu, int *x, int *y, gboolean *push_in, GtkMenuToolButton *button)
-{
-	GtkAllocation arrow_allocation;
-	GtkWidget *widget = GTK_WIDGET (button);
-	GtkRequisition menu_req;
-	GtkTextDirection direction;
-	GdkRectangle monitor;
-	gint monitor_num;
-	GdkScreen *screen;
-	GdkWindow *window;
-	GtkAllocation allocation;
-
-	gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
-	direction = gtk_widget_get_direction (widget);
-	window = gtk_widget_get_window (widget);
-
-	screen = gtk_widget_get_screen (GTK_WIDGET (menu));
-	monitor_num = gdk_screen_get_monitor_at_window (screen, window);
-	if (monitor_num < 0)
-		monitor_num = 0;
-	gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
-
-	gtk_widget_get_allocation (widget, &allocation);
-
-	gdk_window_get_origin (window, x, y);
-	*x += allocation.x;
-	*y += allocation.y;
-
-	if (direction == GTK_TEXT_DIR_LTR)
-		*x += MAX (allocation.width - menu_req.width, 0);
-	else if (menu_req.width > allocation.width)
-		*x -= menu_req.width - allocation.width;
-
-	if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
-		*y += allocation.height;
-	else if ((*y - menu_req.height) >= monitor.y)
-		*y -= menu_req.height;
-	else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
-		*y += allocation.height;
-	else
-		*y -= menu_req.height;
-
-	*push_in = FALSE;
-}
-
-void
-mw_font_style_activate_cb (AlmanahFontStyleMenuAction *action, AlmanahMainWindow *main_window)
-{
-	AlmanahMainWindowPrivate *priv = ALMANAH_MAIN_WINDOW_GET_PRIVATE(main_window);
-	GtkMenu *menu = NULL;
-
-	if (GTK_IS_MENU_TOOL_BUTTON (priv->font_style_tool_button)) {
-		menu = GTK_MENU (gtk_menu_tool_button_get_menu (priv->font_style_tool_button));
-	}
-
-	if (GTK_IS_MENU (menu)) {
-		gtk_menu_popup (menu, NULL, NULL,
-				(GtkMenuPositionFunc) mw_font_style_menu_position_func,
-				priv->font_style_tool_button,
-				0,
-				gtk_get_current_event_time());
-	}
-}
-
-static GtkMenuToolButton *
-mw_get_font_style_tool_button_from_action (GtkAction *action)
-{
-	GSList *proxies;
-	GtkMenuToolButton *tool_button = NULL;
-
-	proxies = gtk_action_get_proxies (GTK_ACTION (action));
-	while (proxies != NULL) {
-		if (GTK_IS_MENU_TOOL_BUTTON (proxies->data)) {
-			tool_button = GTK_MENU_TOOL_BUTTON (proxies->data);
-		}
-
-		proxies = proxies->next;
-	}
-
-	return tool_button;
-}
-
 static void
 clear_factory_events (AlmanahMainWindow *self, AlmanahEventFactoryType type_id)
 {
@@ -1313,22 +1207,51 @@ mw_menu_button_popup_visible_cb (GtkWidget *menu, GParamSpec *pspec, GtkWidget *
 		gtk_style_context_remove_class (gtk_widget_get_style_context (button), "active-menu");
 }
 
+static gint
+get_icon_margin (void)
+{
+  gint toolbar_size, menu_size;
+
+  gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &menu_size, NULL);
+  gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &toolbar_size, NULL);
+  return (gint) floor ((toolbar_size - menu_size) / 2.0);
+}
+
 static void
-mw_setup_toolbar (AlmanahMainWindow *main_window, AlmanahApplication *application, GtkToolbar *toolbar, GtkAction *today_action, GtkAction *select_date_action, GtkWidget *menu_popup)
+mw_setup_toolbar (AlmanahMainWindow *main_window, AlmanahApplication *application, GtkBuilder *builder)
 {
-	GtkToolItem *calendar_button_item, *separator, *menu_button_item;
-	GtkWidget *menu_button, *menu_button_image;
+	GtkToolbar *toolbar;
+	GtkToolItem *tool_item;
+	GtkWidget *button, *button_image, *popup;
+	GtkUIManager *manager;
 	AlmanahStorageManager *storage_manager;
 
-	gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (toolbar)), GTK_STYLE_CLASS_MENUBAR);
+	toolbar = GTK_TOOLBAR (gtk_builder_get_object (builder, "almanah_mw_toolbar"));
+	manager = GTK_UI_MANAGER (gtk_builder_get_object (builder, "almanah_ui_manager"));
 
-	/* Insert a dynamic space between the text style and calendar & important.
-	 * This can't be done using the <separator/> in the UI file at the moment
+	/* Allow drag the window using the toolbar */
+	gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (toolbar)), GTK_STYLE_CLASS_MENUBAR);
+	gtk_toolbar_set_icon_size (toolbar, GTK_ICON_SIZE_MENU);
+
+	/* The text style button */
+	tool_item = gtk_tool_item_new ();
+	button = gtk_menu_button_new ();
+	popup = gtk_ui_manager_get_widget (manager, "/almanah_mw_font_menu");
+	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), popup);
+	button_image = gtk_image_new_from_icon_name ("gtk-select-font", GTK_ICON_SIZE_MENU);
+	g_object_set (button_image, "margin", get_icon_margin (), NULL);
+	gtk_button_set_image (GTK_BUTTON (button), button_image);
+	gtk_container_add (GTK_CONTAINER (tool_item), button);
+	g_signal_connect (popup, "notify::visible", G_CALLBACK (mw_menu_button_popup_visible_cb), button);
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
+
+	/* Insert a dynamic space between the insert link and calendar & important.
+	 * This can't be done using the <tool_item/> in the UI file at the moment
 	 */
-	separator = gtk_separator_tool_item_new ();
-	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (separator), FALSE);
-	gtk_tool_item_set_expand (separator, TRUE);
-	gtk_toolbar_insert (toolbar, separator, 2);
+	tool_item = gtk_separator_tool_item_new ();
+	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item), FALSE);
+	gtk_tool_item_set_expand (tool_item, TRUE);
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
 
 	/* Setup the calendar button */
 	storage_manager = almanah_application_dup_storage_manager (application);
@@ -1336,29 +1259,38 @@ mw_setup_toolbar (AlmanahMainWindow *main_window, AlmanahApplication *applicatio
 	g_object_unref (storage_manager);
 	g_signal_connect (main_window->priv->calendar_button, "day-selected", G_CALLBACK (mw_calendar_day_selected_cb), main_window);
 	/* Use the same action for the today button in the dropdown window */
-	almanah_calendar_button_set_today_action (main_window->priv->calendar_button, today_action);
-	almanah_calendar_button_set_select_date_action (main_window->priv->calendar_button, select_date_action);
-
+	almanah_calendar_button_set_today_action (main_window->priv->calendar_button, GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_jump_to_today")));
+	almanah_calendar_button_set_select_date_action (main_window->priv->calendar_button, GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_select_date")));
 	/* Insert the calendar button into the toolbar through a GtkToolItem but button style */
-	calendar_button_item = gtk_tool_item_new ();
-	gtk_container_add (GTK_CONTAINER (calendar_button_item), GTK_WIDGET (main_window->priv->calendar_button));
-	gtk_toolbar_insert (toolbar, calendar_button_item, 3);
-
-	/* Another dynamic separator */
-	separator = gtk_separator_tool_item_new ();
-	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (separator), FALSE);
-	gtk_tool_item_set_expand (separator, TRUE);
-	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (separator));
+	tool_item = gtk_tool_item_new ();
+	gtk_container_add (GTK_CONTAINER (tool_item), GTK_WIDGET (main_window->priv->calendar_button));
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
+
+	/* Important entry */
+	tool_item = gtk_separator_tool_item_new ();
+	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item), FALSE);
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
+	tool_item = gtk_toggle_tool_button_new ();
+	gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_item), GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_important")));
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
+
+	/* Another dynamic tool_item */
+	tool_item = gtk_separator_tool_item_new ();
+	gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item), FALSE);
+	gtk_tool_item_set_expand (tool_item, TRUE);
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
 
 	/* Menu button with the common GNOME applications style (Nautilus, Epiphany, ...) */
-	menu_button_item = gtk_tool_item_new ();
-	menu_button = gtk_menu_button_new ();
-	gtk_menu_button_set_popup (GTK_MENU_BUTTON (menu_button), menu_popup);
-	menu_button_image = gtk_image_new_from_icon_name ("emblem-system-symbolic", gtk_toolbar_get_icon_size (toolbar));
-	gtk_button_set_image (GTK_BUTTON (menu_button), menu_button_image);
-	gtk_container_add (GTK_CONTAINER (menu_button_item), menu_button);
-	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (menu_button_item));
-	g_signal_connect (menu_popup, "notify::visible", G_CALLBACK (mw_menu_button_popup_visible_cb), menu_button);
+	tool_item = gtk_tool_item_new ();
+	button = gtk_menu_button_new ();
+	popup = gtk_ui_manager_get_widget (manager, "/almanah_mw_menu_button");
+	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), popup);
+	button_image = gtk_image_new_from_icon_name ("emblem-system-symbolic", GTK_ICON_SIZE_MENU);
+	g_object_set (button_image, "margin", get_icon_margin (), NULL);
+	gtk_button_set_image (GTK_BUTTON (button), button_image);
+	gtk_container_add (GTK_CONTAINER (tool_item), button);
+	gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_item));
+	g_signal_connect (popup, "notify::visible", G_CALLBACK (mw_menu_button_popup_visible_cb), button);
 }
 
 #ifdef ENABLE_SPELL_CHECKING
diff --git a/src/widgets/calendar-button.c b/src/widgets/calendar-button.c
index d2a112e..3d0efba 100644
--- a/src/widgets/calendar-button.c
+++ b/src/widgets/calendar-button.c
@@ -113,8 +113,6 @@ almanah_calendar_button_init (AlmanahCalendarButton *self)
 	GtkBox *main_box;
 	GtkBuilder *builder;
 	GError *error = NULL;
-	GtkCssProvider *style_provider;
-	gchar *css_path;
 	const gchar *interface_filename = almanah_get_interface_filename ();
 	const gchar *object_names[] = {
 		"almanah_calendar_window",
@@ -126,32 +124,16 @@ almanah_calendar_button_init (AlmanahCalendarButton *self)
 
 	gtk_button_set_focus_on_click (GTK_BUTTON (self), TRUE);
 
-	/* The style for the widgets */
-	css_path = g_build_filename (almanah_get_css_path (), "calendar-button.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'. The interface might not be styled correctly"), css_path);
-		g_error_free (error);
-	} else {
-		gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (self)), GTK_STYLE_PROVIDER (style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-	}
-	g_free (css_path);
-
 	/* The button elements */
 	self->priv->label = gtk_label_new (NULL);
-	gtk_style_context_add_provider (gtk_widget_get_style_context (self->priv->label), GTK_STYLE_PROVIDER (style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
 	arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
-	gtk_style_context_add_provider (gtk_widget_get_style_context (arrow), GTK_STYLE_PROVIDER (style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
 	main_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
 	gtk_box_pack_start (main_box, self->priv->label, TRUE, TRUE, 0);
 	gtk_box_pack_start (main_box, arrow, FALSE, TRUE, 0);
 	gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (main_box));
 
-	g_object_unref (style_provider);
-
 	/* Calendar dock window from the UI file */
 	builder = gtk_builder_new ();
 	if (gtk_builder_add_objects_from_file (builder, interface_filename, (gchar **) object_names, &error) == FALSE) {
diff --git a/src/widgets/calendar-window.c b/src/widgets/calendar-window.c
index 6e7381b..74a77bd 100644
--- a/src/widgets/calendar-window.c
+++ b/src/widgets/calendar-window.c
@@ -50,27 +50,7 @@ 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'. 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]