aboutsummaryrefslogtreecommitdiff
path: root/libtopmenu-client/topmenu-appmenubar.c
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-01-28 16:50:47 +0100
committerJavier <dev.git@javispedro.com>2014-01-28 16:50:47 +0100
commitc2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7 (patch)
tree7e1e2285437816c06ac884d68284d854413cf41e /libtopmenu-client/topmenu-appmenubar.c
downloadtopmenu-gtk-c2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7.tar.gz
topmenu-gtk-c2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7.zip
initial import
Diffstat (limited to 'libtopmenu-client/topmenu-appmenubar.c')
-rw-r--r--libtopmenu-client/topmenu-appmenubar.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/libtopmenu-client/topmenu-appmenubar.c b/libtopmenu-client/topmenu-appmenubar.c
new file mode 100644
index 0000000..7d94cf5
--- /dev/null
+++ b/libtopmenu-client/topmenu-appmenubar.c
@@ -0,0 +1,86 @@
+#include "topmenu-appmenubar.h"
+
+G_DEFINE_TYPE(TopMenuAppMenuBar, topmenu_app_menu_bar, GTK_TYPE_MENU_BAR)
+
+enum {
+ PROP_0,
+ PROP_APP_MENU,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
+static void topmenu_app_menu_bar_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ TopMenuAppMenuBar *self = TOPMENU_APP_MENU_BAR(obj);
+ switch (property_id) {
+ case PROP_APP_MENU:
+ g_value_set_object(value, topmenu_app_menu_bar_get_app_menu(self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
+ }
+}
+
+static void topmenu_app_menu_bar_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ TopMenuAppMenuBar *self = TOPMENU_APP_MENU_BAR(obj);
+ switch (property_id) {
+ case PROP_APP_MENU:
+ topmenu_app_menu_bar_set_app_menu(self, g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
+ }
+}
+
+static void topmenu_app_menu_bar_class_init(TopMenuAppMenuBarClass *klass)
+{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ obj_class->get_property = topmenu_app_menu_bar_get_property;
+ obj_class->set_property = topmenu_app_menu_bar_set_property;
+
+ properties[PROP_APP_MENU] = g_param_spec_object("app-menu",
+ "Application menu",
+ "The application menu (shown under the application name)",
+ GTK_TYPE_MENU,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
+
+ g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
+
+ gtk_rc_parse_string (
+ "style \"app-menubar-style\"\n"
+ "{\n"
+ " GtkMenuBar::shadow-type = none\n"
+ " GtkMenuBar::internal-padding = 0\n"
+ "}\n"
+ "class \"TopMenuAppMenuBar\" style \"app-menubar-style\"");
+}
+
+static void topmenu_app_menu_bar_init(TopMenuAppMenuBar *self)
+{
+ self->app_menu_item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(g_get_application_name()));
+ GtkLabel *app_label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(self->app_menu_item)));
+ PangoAttrList *app_label_attr = pango_attr_list_new();
+ pango_attr_list_insert(app_label_attr, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+ gtk_label_set_attributes(app_label, app_label_attr);
+ pango_attr_list_unref(app_label_attr);
+ gtk_widget_show(GTK_WIDGET(self->app_menu_item));
+
+ gtk_menu_shell_prepend(GTK_MENU_SHELL(self), GTK_WIDGET(self->app_menu_item));
+}
+
+TopMenuAppMenuBar *topmenu_app_menu_bar_new(void)
+{
+ return TOPMENU_APP_MENU_BAR(g_object_new(TOPMENU_TYPE_APP_MENU_BAR, NULL));
+}
+
+void topmenu_app_menu_bar_set_app_menu(TopMenuAppMenuBar *self, GtkWidget *menu)
+{
+ gtk_menu_item_set_submenu(self->app_menu_item, GTK_WIDGET(menu));
+}
+
+GtkWidget *topmenu_app_menu_bar_get_app_menu(TopMenuAppMenuBar *self)
+{
+ return gtk_menu_item_get_submenu(self->app_menu_item);
+}