1 /*
2  *      gui.c
3  *
4  *      Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru>
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program; if not, write to the Free Software
18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *      MA 02110-1301, USA.
20  */
21 
22 /*
23  * 		function for creating GUI elements
24  */
25 
26 #include <gtk/gtk.h>
27 
28 #include "gui.h"
29 
30 /*
31  * 	creates a button with an icon from file and a tooltip
32  */
create_button(const gchar * icon,const gchar * tooltip)33 GtkWidget* create_button(const gchar *icon, const gchar *tooltip)
34 {
35 	GtkWidget *btn = gtk_button_new();
36 
37 	gchar *path = g_build_path(G_DIR_SEPARATOR_S, DBGPLUG_DATA_DIR, icon, NULL);
38 	GtkWidget *image =  gtk_image_new_from_file(path);
39 	g_free(path);
40 
41 	gtk_widget_show(image);
42 	gtk_button_set_image(GTK_BUTTON(btn), image);
43 
44 	gtk_widget_set_tooltip_text(btn, tooltip);
45 
46 	return btn;
47 }
48 
49 /*
50  * 	creates a button with a stock icon and a tooltip
51  */
create_stock_button(const gchar * stockid,const gchar * tooltip)52 GtkWidget* create_stock_button(const gchar *stockid, const gchar *tooltip)
53 {
54 	GtkWidget *btn = gtk_button_new();
55 #if GTK_CHECK_VERSION(3, 0, 0)
56 	GtkWidget *image = gtk_image_new_from_icon_name(stockid, GTK_ICON_SIZE_MENU);
57 #else
58 	GtkWidget *image = gtk_image_new_from_stock (stockid, GTK_ICON_SIZE_MENU);
59 #endif
60 	gtk_widget_show(image);
61 	gtk_button_set_image(GTK_BUTTON(btn), image);
62 
63 	gtk_widget_set_tooltip_text(btn, tooltip);
64 
65 	return btn;
66 }
67 
68 /*
69  * 	creates a toggle button with an icon from file and a tooltip
70  */
create_toggle_button(const gchar * icon,const gchar * tooltip)71 GtkWidget* create_toggle_button(const gchar *icon, const gchar *tooltip)
72 {
73 	GtkWidget *btn = gtk_toggle_button_new();
74 
75 	gchar *path = g_build_path(G_DIR_SEPARATOR_S, DBGPLUG_DATA_DIR, icon, NULL);
76 	GtkWidget *image =  gtk_image_new_from_file(path);
77 	g_free(path);
78 
79 	gtk_widget_show(image);
80 	gtk_button_set_image(GTK_BUTTON(btn), image);
81 
82 	gtk_widget_set_tooltip_text(btn, tooltip);
83 
84 	return btn;
85 }
86 
87 /*
88  * 	sets button icon from file
89  */
set_button_image(GtkWidget * btn,const gchar * icon)90 void set_button_image(GtkWidget *btn, const gchar *icon)
91 {
92 	gchar *path = g_build_path(G_DIR_SEPARATOR_S, DBGPLUG_DATA_DIR, icon, NULL);
93 	GtkWidget *image =  gtk_image_new_from_file(path);
94 	g_free(path);
95 
96 	gtk_widget_show(image);
97 	gtk_button_set_image(GTK_BUTTON(btn), image);
98 }
99