1 /* $Id$ */
2 /* Copyright (c) 2012-2015 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Rotate Panel */
4 /* This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16
17
18 #include <libintl.h>
19 #include <System.h>
20 #include "Panel/applet.h"
21 #define _(string) gettext(string)
22
23
24 /* Rotate */
25 /* private */
26 /* types */
27 typedef struct _PanelApplet
28 {
29 PanelAppletHelper * helper;
30 GtkWidget * widget;
31 } Rotate;
32
33
34 /* prototypes */
35 static Rotate * _rotate_init(PanelAppletHelper * helper, GtkWidget ** widget);
36 static void _rotate_destroy(Rotate * rotate);
37
38 /* callbacks */
39 static void _rotate_on_clicked(gpointer data);
40
41
42 /* public */
43 /* variables */
44 PanelAppletDefinition applet =
45 {
46 "Rotate",
47 GTK_STOCK_REFRESH, /* XXX use a more adequate image */
48 NULL,
49 _rotate_init,
50 _rotate_destroy,
51 NULL,
52 FALSE,
53 TRUE
54 };
55
56
57 /* private */
58 /* functions */
59 /* rotate_init */
_rotate_init(PanelAppletHelper * helper,GtkWidget ** widget)60 static Rotate * _rotate_init(PanelAppletHelper * helper, GtkWidget ** widget)
61 {
62 Rotate * rotate;
63 GtkWidget * image;
64
65 if((rotate = object_new(sizeof(*rotate))) == NULL)
66 return NULL;
67 rotate->helper = helper;
68 rotate->widget = gtk_button_new();
69 #if GTK_CHECK_VERSION(3, 10, 0)
70 image = gtk_image_new_from_icon_name(applet.icon,
71 #else
72 image = gtk_image_new_from_stock(applet.icon,
73 #endif
74 panel_window_get_icon_size(helper->window));
75 gtk_button_set_image(GTK_BUTTON(rotate->widget), image);
76 gtk_button_set_relief(GTK_BUTTON(rotate->widget), GTK_RELIEF_NONE);
77 #if GTK_CHECK_VERSION(2, 12, 0)
78 gtk_widget_set_tooltip_text(rotate->widget, _("Rotate the screen"));
79 #endif
80 g_signal_connect_swapped(rotate->widget, "clicked", G_CALLBACK(
81 _rotate_on_clicked), rotate);
82 gtk_widget_show_all(rotate->widget);
83 *widget = rotate->widget;
84 return rotate;
85 }
86
87
88 /* rotate_destroy */
_rotate_destroy(Rotate * rotate)89 static void _rotate_destroy(Rotate * rotate)
90 {
91 gtk_widget_destroy(rotate->widget);
92 object_delete(rotate);
93 }
94
95
96 /* callbacks */
97 /* rotate_on_clicked */
_rotate_on_clicked(gpointer data)98 static void _rotate_on_clicked(gpointer data)
99 {
100 Rotate * rotate = data;
101
102 rotate->helper->rotate_screen(rotate->helper->panel);
103 }
104