1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/*
* This file is a part of hildon examples
*
* Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved.
*
* Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <hildon/hildon.h>
#include <cairo.h>
static gboolean
area_expose (GtkWidget *widget,
GdkEventExpose *expose,
gpointer data)
{
cairo_t *cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
gint width, height, x, y;
GError *error = NULL;
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"statusarea_volumelevel2",
HILDON_ICON_PIXEL_SIZE_STYLUS,
0, &error);
gint v_margins = 15;
gint h_margins = 100;
gdouble fill_level = 0.4;
width = widget->allocation.width;
height = widget->allocation.height;
x = widget->allocation.x;
y = widget->allocation.y;
cairo_rectangle (cr, x + h_margins, y + v_margins,
(width - 2 * h_margins)*fill_level,
height - 2 * v_margins);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_fill (cr);
cairo_rectangle (cr, x + h_margins, y + v_margins,
width - 2 * h_margins,
height - 2 * v_margins);
cairo_set_line_width (cr, 2);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_stroke (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, x,
y + (height - gdk_pixbuf_get_height (pixbuf))/2);
cairo_paint (cr);
cairo_destroy (cr);
g_object_unref (pixbuf);
return FALSE;
}
static GtkWidget *
custom_widget_new (void)
{
GtkWidget *area = gtk_event_box_new ();
GTK_WIDGET_SET_FLAGS (area, GTK_NO_WINDOW);
gtk_widget_set_size_request (area, 600, 50);
g_signal_connect (area, "expose-event",
G_CALLBACK (area_expose),
NULL);
return area;
}
static void
on_information_clicked (GtkWidget *widget)
{
GtkWidget* banner = hildon_banner_show_information (widget, NULL, "Information banner");
hildon_banner_set_timeout (HILDON_BANNER (banner), 9000);
}
static void
on_custom_clicked (GtkWidget *widget)
{
GtkWidget *custom_widget = custom_widget_new ();
hildon_banner_show_custom_widget (widget, custom_widget);
}
int
main (int argc,
char **argv)
{
HildonProgram *program;
GtkWidget *window, *vbox, *button1;
GtkWidget *button4;
hildon_gtk_init (&argc, &argv);
window = hildon_window_new ();
program = hildon_program_get_instance ();
hildon_program_add_window (program, HILDON_WINDOW (window));
button1 = gtk_button_new_with_label ("Information");
g_signal_connect (button1, "clicked", G_CALLBACK (on_information_clicked), NULL);
button4 = gtk_button_new_with_label ("Custom");
g_signal_connect (button4, "clicked", G_CALLBACK (on_custom_clicked), NULL);
vbox = gtk_vbox_new (6, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), button1, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), button4, TRUE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show_all (window);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_main ();
return 0;
}
|