summaryrefslogtreecommitdiff
path: root/src/widgets/panel/panel-item-icon.c
blob: 327f027e9d0a4ef522e2331b5ee4031f7c8534fa (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
87
88
89
90
91
92
#include "widgets/panel/panel-item-icon.h"

//
// FoobarPanelItemIcon:
//
// Simple item implementation displaying an icon.
//

struct _FoobarPanelItemIcon
{
	FoobarPanelItem       parent_instance;
	GtkWidget*            button;
	FoobarPanelItemAction action;
};

static void foobar_panel_item_icon_class_init    ( FoobarPanelItemIconClass* klass );
static void foobar_panel_item_icon_init          ( FoobarPanelItemIcon*      self );
static void foobar_panel_item_icon_handle_clicked( GtkButton*                button,
                                                   gpointer                  userdata );

G_DEFINE_FINAL_TYPE( FoobarPanelItemIcon, foobar_panel_item_icon, FOOBAR_TYPE_PANEL_ITEM )

// ---------------------------------------------------------------------------------------------------------------------
// Panel Item Implementation
// ---------------------------------------------------------------------------------------------------------------------

//
// Static initialization for icon panel items.
//
void foobar_panel_item_icon_class_init( FoobarPanelItemIconClass* klass )
{
	(void)klass;
}

//
// Instance initialization for icon panel items.
//
void foobar_panel_item_icon_init( FoobarPanelItemIcon* self )
{
	self->button = gtk_button_new( );
	gtk_button_set_has_frame( GTK_BUTTON( self->button ), FALSE );
	gtk_widget_set_halign( self->button, GTK_ALIGN_CENTER );
	gtk_widget_set_valign( self->button, GTK_ALIGN_CENTER );
	g_signal_connect(
		self->button,
		"clicked",
		G_CALLBACK( foobar_panel_item_icon_handle_clicked ),
		self );

	gtk_widget_add_css_class( GTK_WIDGET( self ), "icon" );
	foobar_panel_item_set_child( FOOBAR_PANEL_ITEM( self ), self->button );
}

// ---------------------------------------------------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------------------------------------------------

//
// Create a new icon panel item with the given configuration.
//
FoobarPanelItem* foobar_panel_item_icon_new( FoobarPanelItemConfiguration const* config )
{
	g_return_val_if_fail( config != NULL, NULL );
	g_return_val_if_fail( foobar_panel_item_configuration_get_kind( config ) == FOOBAR_PANEL_ITEM_KIND_ICON, NULL );

	FoobarPanelItemIcon* self = g_object_new( FOOBAR_TYPE_PANEL_ITEM_ICON, NULL );
	self->action = foobar_panel_item_configuration_get_action( config );

	gtk_widget_set_sensitive( self->button, self->action != FOOBAR_PANEL_ITEM_ACTION_NONE );
	gtk_button_set_icon_name(
		GTK_BUTTON( self->button ),
		foobar_panel_item_icon_configuration_get_icon_name( config ) );

	return FOOBAR_PANEL_ITEM( self );
}

// ---------------------------------------------------------------------------------------------------------------------
// Signal Handlers
// ---------------------------------------------------------------------------------------------------------------------

//
// Called when the button was clicked.
//
void foobar_panel_item_icon_handle_clicked(
	GtkButton* button,
	gpointer   userdata )
{
	(void)button;
	FoobarPanelItemIcon* self = (FoobarPanelItemIcon*)userdata;

	foobar_panel_item_invoke_action( FOOBAR_PANEL_ITEM( self ), self->action );
}