annotate finch/libgnt/gntprogressbar.c @ 26555:35430bc421c2

Add a simple progress-bar in libgnt. Closes #7797. committer: Sadrul Habib Chowdhury <imadil@gmail.com>
author Saleem Abdulrasool <compnerd@compnerd.org>
date Sun, 12 Apr 2009 18:10:03 +0000
parents
children cd7fa6306f85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26555
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
1 /**
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
2 * GNT - The GLib Ncurses Toolkit
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
3 *
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
6 * source distribution.
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
7 *
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
8 * This library is free software; you can redistribute it and/or modify
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
11 * (at your option) any later version.
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
12 *
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
16 * GNU General Public License for more details.
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
17 *
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
21 **/
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
22
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
23 #include "gntprogressbar.h"
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
24 #include "gntutils.h"
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
25
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
26 #include <string.h>
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
27
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
28 typedef struct _GntProgressBarPrivate
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
29 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
30 gdouble fraction;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
31 gboolean show_value;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
32 GntProgressBarOrientation orientation;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
33 } GntProgressBarPrivate;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
34
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
35 #define GNT_PROGRESS_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNT_TYPE_PROGRESS_BAR, GntProgressBarPrivate))
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
36
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
37
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
38 static GntWidgetClass *parent_class = NULL;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
39
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
40
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
41 static void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
42 gnt_progress_bar_draw (GntWidget *widget)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
43 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
44 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (GNT_PROGRESS_BAR (widget));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
45 gchar progress[6]; /* strlen("100 %") == 5 */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
46 gint start, end, i, pos;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
47
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
48 g_snprintf (progress, sizeof (progress), "%.0f %%", priv->fraction * 100);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
49
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
50 switch (priv->orientation)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
51 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
52 case GNT_PROGRESS_LEFT_TO_RIGHT:
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
53 case GNT_PROGRESS_RIGHT_TO_LEFT:
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
54 start = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? 0 : (1.0 - priv->fraction) * widget->priv.width);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
55 end = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? widget->priv.width * priv->fraction : widget->priv.width);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
56
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
57 /* background */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
58 for (i = 0; i < widget->priv.height; i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
59 mvwhline (widget->window, i, 0, ' ' | gnt_color_pair (GNT_COLOR_HIGHLIGHT) | A_REVERSE, widget->priv.width);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
60
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
61 /* foreground */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
62 for (i = 0; i < widget->priv.height; i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
63 mvwhline (widget->window, i, start, ' ' | gnt_color_pair (GNT_COLOR_HIGHLIGHT), end);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
64
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
65 /* text */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
66 if (priv->show_value)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
67 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
68 for (i = 0; i < strlen(progress); i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
69 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
70 pos = widget->priv.width / 2 - strlen (progress) / 2 + i;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
71 wattrset (widget->window, gnt_color_pair (GNT_COLOR_HIGHLIGHT) | ((pos >= start && pos <= end) ? A_NORMAL : A_REVERSE));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
72 mvwprintw (widget->window, widget->priv.height / 2, pos, "%c", progress[i]);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
73 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
74 wattrset (widget->window, gnt_color_pair (GNT_COLOR_HIGHLIGHT));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
75 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
76
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
77 break;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
78 case GNT_PROGRESS_TOP_TO_BOTTOM:
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
79 case GNT_PROGRESS_BOTTOM_TO_TOP:
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
80 start = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? 0 : (1.0 - priv->fraction) * widget->priv.height);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
81 end = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? widget->priv.height * priv->fraction : widget->priv.height);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
82
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
83 /* background */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
84 for (i = 0; i < widget->priv.width; i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
85 mvwvline (widget->window, 0, i, ' ' | gnt_color_pair (GNT_COLOR_HIGHLIGHT) | A_REVERSE, widget->priv.height);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
86
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
87 /* foreground */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
88 for (i = 0; i < widget->priv.width; i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
89 mvwvline (widget->window, start, i, ' ' | gnt_color_pair (GNT_COLOR_HIGHLIGHT), end);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
90
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
91 /* text */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
92 if (priv->show_value)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
93 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
94 for (i = 0; i < strlen(progress); i++)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
95 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
96 pos = widget->priv.height / 2 - strlen (progress) / 2 + i;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
97 wattrset (widget->window, gnt_color_pair (GNT_COLOR_HIGHLIGHT) | ((pos >= start && pos <= end) ? A_NORMAL : A_REVERSE));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
98 mvwprintw (widget->window, pos, widget->priv.width / 2, "%c\n", progress[i]);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
99 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
100 wattrset (widget->window, gnt_color_pair (GNT_COLOR_HIGHLIGHT));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
101 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
102
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
103 break;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
104 default:
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
105 g_assert_not_reached ();
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
106 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
107 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
108
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
109 static void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
110 gnt_progress_bar_size_request (GntWidget *widget)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
111 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
112 gnt_widget_set_size (widget, widget->priv.minw, widget->priv.minh);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
113 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
114
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
115 static void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
116 gnt_progress_bar_class_init (gpointer klass, gpointer class_data)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
117 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
118 GObjectClass *g_class = G_OBJECT_CLASS (klass);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
119
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
120 parent_class = GNT_WIDGET_CLASS (klass);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
121
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
122 g_type_class_add_private (g_class, sizeof (GntProgressBarPrivate));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
123
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
124 parent_class->draw = gnt_progress_bar_draw;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
125 parent_class->size_request = gnt_progress_bar_size_request;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
126 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
127
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
128 static void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
129 gnt_progress_bar_init (GTypeInstance *instance, gpointer g_class)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
130 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
131 GntWidget *widget = GNT_WIDGET (instance);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
132 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (GNT_PROGRESS_BAR (widget));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
133
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
134 gnt_widget_set_take_focus (widget, FALSE);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
135 GNT_WIDGET_SET_FLAGS (widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
136
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
137 widget->priv.minw = 1;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
138 widget->priv.minh = 1;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
139
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
140 priv->show_value = FALSE;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
141 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
142
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
143 GType
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
144 gnt_progress_bar_get_type (void)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
145 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
146 static GType type = 0;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
147
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
148 if (type == 0)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
149 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
150 static const GTypeInfo info =
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
151 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
152 sizeof (GntProgressBarClass),
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
153 NULL, /* base_init */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
154 NULL, /* base_finalize */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
155 gnt_progress_bar_class_init, /* class_init */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
156 NULL, /* class_finalize */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
157 NULL, /* class_data */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
158 sizeof (GntProgressBar),
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
159 0, /* n_preallocs */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
160 gnt_progress_bar_init, /* instance_init */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
161 NULL /* value_table */
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
162 };
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
163
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
164 type = g_type_register_static (GNT_TYPE_WIDGET, "GntProgressBar", &info, 0);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
165 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
166
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
167 return type;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
168 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
169
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
170 GntWidget *
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
171 gnt_progress_bar_new (void)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
172 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
173 GntWidget *widget = g_object_new (GNT_TYPE_PROGRESS_BAR, NULL);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
174 return widget;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
175 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
176
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
177 void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
178 gnt_progress_bar_set_fraction (GntProgressBar *pbar, gdouble fraction)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
179 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
180 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
181
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
182 if (fraction > 1.0)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
183 priv->fraction = 1.0;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
184 else if (fraction < 0.0)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
185 priv->fraction = 0.0;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
186 else
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
187 priv->fraction = fraction;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
188
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
189 gnt_progress_bar_draw (GNT_WIDGET (pbar));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
190 gnt_widget_queue_update (GNT_WIDGET (pbar));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
191 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
192
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
193 void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
194 gnt_progress_bar_set_orientation (GntProgressBar *pbar,
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
195 GntProgressBarOrientation orientation)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
196 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
197 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
198 priv->orientation = orientation;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
199
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
200 gnt_progress_bar_draw (GNT_WIDGET (pbar));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
201 gnt_widget_queue_update (GNT_WIDGET (pbar));
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
202 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
203
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
204 void
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
205 gnt_progress_bar_set_show_progress (GntProgressBar *pbar, gboolean show)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
206 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
207 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
208 priv->show_value = show;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
209 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
210
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
211 gdouble
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
212 gnt_progress_bar_get_fraction (GntProgressBar *pbar)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
213 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
214 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
215 return priv->fraction;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
216 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
217
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
218 GntProgressBarOrientation
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
219 gnt_progress_bar_get_orientation (GntProgressBar *pbar)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
220 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
221 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
222 return priv->orientation;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
223 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
224
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
225 gboolean
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
226 gnt_progress_bar_get_show_progress (GntProgressBar *pbar)
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
227 {
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
228 GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar);
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
229 return priv->show_value;
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
230 }
35430bc421c2 Add a simple progress-bar in libgnt.
Saleem Abdulrasool <compnerd@compnerd.org>
parents:
diff changeset
231