aboutsummaryrefslogtreecommitdiff
path: root/libtopmenu-client/topmenu-appmenubar.c
blob: 7d94cf53b7a58c424ed7910f593140121dc2d726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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);
}