Imported Upstream version 0.8.0.4
[psensor-pkg-debian.git] / src / ui_graph.c
1 /*
2  * Copyright (C) 2010-2013 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #include "graph.h"
20 #include "ui_graph.h"
21
22 static int
23 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
24 {
25         if (event->type != GDK_BUTTON_PRESS)
26                 return FALSE;
27
28         gtk_menu_popup(GTK_MENU(((struct ui_psensor *)data)->popup_menu),
29                        NULL, NULL, NULL, NULL,
30                        event->button, event->time);
31
32         return TRUE;
33 }
34
35 static gboolean
36 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
37 {
38         struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
39
40         graph_update(ui_psensor->sensors,
41                      ui_psensor->w_graph,
42                      ui_psensor->config,
43                      ui_psensor->main_window);
44
45         return FALSE;
46 }
47
48 void ui_graph_create(struct ui_psensor *ui)
49 {
50         GtkWidget *w_graph;
51
52         log_debug("ui_graph_create()");
53
54         w_graph = ui->w_graph;
55
56         g_signal_connect(GTK_WIDGET(w_graph),
57                          "draw",
58                          G_CALLBACK(on_expose_event),
59                          ui);
60
61         gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
62
63         g_signal_connect(GTK_WIDGET(w_graph),
64                          "button_press_event",
65                          (GCallback) on_graph_clicked, ui);
66
67         log_debug("ui_graph_create() ends");
68 }