pnmixer
Volume mixer for the system tray
support-ui.h
Go to the documentation of this file.
1 /* support-ui.h
2  * PNmixer is written by Nick Lanham, a fork of OBmixer
3  * which was programmed by Lee Ferrett, derived
4  * from the program "AbsVolume" by Paul Sherman
5  * This program is free software; you can redistribute
6  * it and/or modify it under the terms of the GNU General
7  * Public License v3. source code is available at
8  * <http://github.com/nicklan/pnmixer>
9  */
10 
18 #ifndef _SUPPORT_UI_H_
19 #define _SUPPORT_UI_H_
20 
21 #include <gtk/gtk.h>
22 
23 #ifndef WITH_GTK3
24 
25 /*
26  * Simple functions lacking in Gtk2
27  */
28 
29 GtkBuilder *gtk_builder_new_from_file(const gchar *filename);
30 void gtk_combo_box_text_remove_all(GtkComboBoxText *combo_box);
31 
32 #endif
33 
34 #if GTK_CHECK_VERSION(3,22,0)
35 #define GTK_3_22_UNUSED G_GNUC_UNUSED
36 #else
37 #define GTK_3_22_UNUSED
38 #endif
39 
40 
41 /*
42  * Cast a pointer (that may be a function pointer) to a data pointer,
43  * suppressing any warnings from the compilator.
44  * We need that to suppress pedantic warnings when using
45  * g_signal_handlers_block_by_func(). Indeed, we must feed it a
46  * function pointer, but the signature expects a data pointer.
47  * Aparently Glib doesn't respect ISO C here.
48  * For more details, see this discussion:
49  * http://compgroups.net/comp.lang.c/cast-function-pointer-to-void/722812
50  */
51 
52 #define DATA_PTR(ptr) (*((void **)(&ptr)))
53 
54 /*
55  * GtkBuilder helpers
56  */
57 
58 #define gtk_builder_get_widget(builder, name) \
59  GTK_WIDGET(gtk_builder_get_object(builder, name))
60 
61 #define gtk_builder_get_adjustment(builder, name) \
62  GTK_ADJUSTMENT(gtk_builder_get_object(builder, name))
63 
64 /*
65  * 'assign' functions are used to retrieve a widget from a GtkBuilder
66  * and to assign it into a structure. This is used a lot when we build
67  * a window, and need to keep a pointer toward some widgets for later use.
68  * This macro is more clever that it seems:
69  * - it ensures that the name used in the struct is the same as the name used
70  * in the ui file, therefore enforcing a consistent naming across the code.
71  * - it ensures that the widget was found amidst the GtkBuilder objects,
72  * therefore detecting errors that can happen when reworking the ui files.
73  */
74 
75 #define assign_gtk_widget(builder, container, name) \
76  do { \
77  container->name = gtk_builder_get_widget(builder, #name); \
78  g_assert(GTK_IS_WIDGET(container->name)); \
79  } while (0)
80 
81 #define assign_gtk_adjustment(builder, container, name) \
82  do { \
83  container->name = gtk_builder_get_adjustment(builder, #name); \
84  g_assert(GTK_IS_ADJUSTMENT(container->name)); \
85  } while (0)
86 
87 /*
88  * File helpers
89  */
90 
91 gchar *get_ui_file(const char *filename);
92 gchar *get_pixmap_file(const gchar *filename);
93 
94 #endif // _SUPPORT_UI_H_
void gtk_combo_box_text_remove_all(GtkComboBoxText *combo_box)
Definition: support-ui.c:38
GtkBuilder * gtk_builder_new_from_file(const gchar *filename)
Definition: support-ui.c:25
gchar * get_ui_file(const char *filename)
Definition: support-ui.c:58
gchar * get_pixmap_file(const gchar *filename)
Definition: support-ui.c:85