Debian Codegraph @

src/style.c

raw
1 /*
2 * ConnMan GTK GUI
3 *
4 * Copyright (C) 2015 Intel Corporation. All rights reserved.
5 * Author: Jaakko Hannikainen <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <gtk/gtk.h>
22
23 #include "config.h"
24 #include "style.h"
25
26 GtkCssProvider *css_provider;
27
28 void style_init()
29 {
30 static const char *stylesheet;
31 GError *error = NULL;
32
33 stylesheet = "" \
34 ".cm-header-title {" \
35 " font-weight: bold;" \
36 "}" \
37 ".cm-wireless-hidden {" \
38 " font-style: italic;" \
39 "}" \
40 ".cm-log {" \
41 " background-color: white;" \
42 " padding: 5px;" \
43 "}" \
44 "";
45
46 css_provider = gtk_css_provider_new();
47 gtk_css_provider_load_from_data(css_provider, stylesheet, -1, &error);
48 if(error != NULL) {
49 g_warning("couldn't load stylesheet: %s", error->message);
50 g_error_free(error);
51 }
52 }
53
54 void label_align_text(GtkLabel *label, gfloat xalign, gfloat yalign)
55 {
56 gtk_label_set_line_wrap(label, TRUE);
57 gtk_label_set_justify(label, GTK_JUSTIFY_LEFT);
58 #if (GTK_MAJOR_VERSION > 3) || (GTK_MINOR_VERSION >= 16)
59 if(xalign >= 0)
60 gtk_label_set_xalign(label, xalign);
61 if(yalign >= 0)
62 gtk_label_set_xalign(label, yalign);
63 #else
64 /* deprecated at 3.14, but above only implemented at 3.16 */
65 if(xalign < 0)
66 gtk_misc_get_alignment(GTK_MISC(label), &xalign, NULL);
67 if(yalign < 0)
68 gtk_misc_get_alignment(GTK_MISC(label), NULL, &yalign);
69 gtk_misc_set_alignment(GTK_MISC(label), xalign, yalign);
70 #endif
71 }
72
73 void style_add_context(GtkWidget *widget)
74 {
75 gtk_style_context_add_provider(gtk_widget_get_style_context(widget),
76 GTK_STYLE_PROVIDER(css_provider),
77 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
78 }
79
80 void style_set_margin(GtkWidget *widget, gint margin)
81 {
82 style_set_margin_start(widget, margin);
83 style_set_margin_end(widget, margin);
84 gtk_widget_set_margin_top(widget, margin);
85 gtk_widget_set_margin_bottom(widget, margin);
86 }
87
88 void style_set_margin_start(GtkWidget *widget, gint margin)
89 {
90 #if (GTK_MAJOR_VERSION > 3) || (GTK_MINOR_VERSION >= 12)
91 gtk_widget_set_margin_start(widget, margin);
92 #else
93 if(gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
94 gtk_widget_set_margin_right(widget, margin);
95 else
96 gtk_widget_set_margin_left(widget, margin);
97 #endif
98 }
99
100 void style_set_margin_end(GtkWidget *widget, gint margin)
101 {
102 #if (GTK_MAJOR_VERSION > 3) || (GTK_MINOR_VERSION >= 12)
103 gtk_widget_set_margin_end(widget, margin);
104 #else
105 if(gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
106 gtk_widget_set_margin_left(widget, margin);
107 else
108 gtk_widget_set_margin_right(widget, margin);
109 #endif
110 }