18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 /**
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 *
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 * source distribution.
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 *
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
11 * (at your option) any later version.
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
12 *
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
16 * GNU General Public License for more details.
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
17 *
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
19 * along with this program; if not, write to the Free Software
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
22
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
23 #include "gntcolors.h"
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
24 #include "gntkeys.h"
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
25 #include "gntslider.h"
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 #include "gntstyle.h"
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
27
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
28 enum
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 SIG_VALUE_CHANGED,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
31 SIGS,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
32 };
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
33
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
34 static guint signals[SIGS] = { 0 };
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
35
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
36 static GntWidgetClass *parent_class = NULL;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
37
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
38 /* returns TRUE if the value was changed */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
39 static gboolean
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
40 sanitize_value(GntSlider *slider)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
41 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
42 if (slider->current < slider->min)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
43 slider->current = slider->min;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
44 else if (slider->current > slider->max)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
45 slider->current = slider->max;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
46 else
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
47 return FALSE;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
48 return TRUE;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
49 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
50
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
51 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
52 redraw_slider(GntSlider *slider)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
53 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
54 GntWidget *widget = GNT_WIDGET(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
55 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED))
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
56 gnt_widget_draw(widget);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
57 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
58
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
59 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
60 slider_value_changed(GntSlider *slider)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
61 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
62 g_signal_emit(slider, signals[SIG_VALUE_CHANGED], 0, slider->current);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
63 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
64
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
65 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
66 gnt_slider_draw(GntWidget *widget)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
67 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
68 GntSlider *slider = GNT_SLIDER(widget);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
69 int attr = 0;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
70 int position, size = 0;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
71
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
72 if (slider->vertical)
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
73 size = widget->priv.height;
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
74 else
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
75 size = widget->priv.width;
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
76
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
77 if (gnt_widget_has_focus(widget))
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
78 attr |= GNT_COLOR_HIGHLIGHT;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
79 else
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
80 attr |= GNT_COLOR_HIGHLIGHT_D;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
81
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
82 if (slider->max != slider->min)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
83 position = ((size - 1) * (slider->current - slider->min)) / (slider->max - slider->min);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
84 else
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
85 position = 0;
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
86 if (slider->vertical) {
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
87 mvwvline(widget->window, size-position, 0, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL) | A_BOLD,
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
88 position);
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
89 mvwvline(widget->window, 0, 0, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
90 size-position);
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
91 } else {
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
92 mvwhline(widget->window, 0, 0, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL) | A_BOLD,
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
93 position);
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
94 mvwhline(widget->window, 0, position, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
95 size - position);
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
96 }
|
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
97
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
98 mvwaddch(widget->window,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
99 slider->vertical ? (size - position - 1) : 0,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
100 slider->vertical ? 0 : position,
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
101 ACS_CKBOARD | COLOR_PAIR(attr));
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
102 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
103
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
104 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
105 gnt_slider_size_request(GntWidget *widget)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
106 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
107 if (GNT_SLIDER(widget)->vertical) {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 widget->priv.width = 1;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 widget->priv.height = 5;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
110 } else {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
111 widget->priv.width = 5;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
112 widget->priv.height = 1;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
113 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
115
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
116 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
117 gnt_slider_map(GntWidget *widget)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
118 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
119 if (widget->priv.width == 0 || widget->priv.height == 0)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
120 gnt_widget_size_request(widget);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
121 GNTDEBUG;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
122 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
123
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
124 static gboolean
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
125 step_back(GntBindable *bindable, GList *null)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
126 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
127 GntSlider *slider = GNT_SLIDER(bindable);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
128 if (slider->current <= slider->min)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
129 return FALSE;
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
130 gnt_slider_advance_step(slider, -1);
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
131 return TRUE;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
132 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
133
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
134 static gboolean
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
135 step_forward(GntBindable *bindable, GList *list)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
136 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 GntSlider *slider = GNT_SLIDER(bindable);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
138 if (slider->current >= slider->max)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
139 return FALSE;
|
18354
d5d1c12a5ad4
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
140 gnt_slider_advance_step(slider, 1);
|
18352
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
141 return TRUE;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
142 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
143
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
144 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
145 gnt_slider_class_init(GntSliderClass *klass)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
146 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
147 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
148 parent_class = GNT_WIDGET_CLASS(klass);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
149 parent_class->draw = gnt_slider_draw;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
150 parent_class->map = gnt_slider_map;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
151 parent_class->size_request = gnt_slider_size_request;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
152
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
153 klass->changed = NULL;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
154
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
155 signals[SIG_VALUE_CHANGED] =
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
156 g_signal_new("changed",
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
157 G_TYPE_FROM_CLASS(klass),
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 G_SIGNAL_RUN_LAST,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
159 G_STRUCT_OFFSET(GntSliderClass, changed),
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 NULL, NULL,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
161 g_cclosure_marshal_VOID__INT,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 G_TYPE_NONE, 1, G_TYPE_INT);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
163
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
164 gnt_bindable_class_register_action(bindable, "step-backward", step_back, GNT_KEY_LEFT, NULL);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
165 gnt_bindable_register_binding(bindable, "step-backward", GNT_KEY_DOWN, NULL);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
166 gnt_bindable_class_register_action(bindable, "step-forward", step_forward, GNT_KEY_RIGHT, NULL);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
167 gnt_bindable_register_binding(bindable, "step-forward", GNT_KEY_UP, NULL);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
168
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
169 /* XXX: how would home/end work? */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
170
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
171 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
172 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
173
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
174 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
175 gnt_slider_init(GTypeInstance *instance, gpointer class)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
176 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
177 GntWidget *widget = GNT_WIDGET(instance);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
178 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_CAN_TAKE_FOCUS);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
179 widget->priv.minw = 1;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
180 widget->priv.minh = 1;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
181 GNTDEBUG;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
182 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
183
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
184 /******************************************************************************
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
185 * GntSlider API
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
186 *****************************************************************************/
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
187 GType
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
188 gnt_slider_get_gtype(void)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
189 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
190 static GType type = 0;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
191
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
192 if(type == 0)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
193 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
194 static const GTypeInfo info = {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
195 sizeof(GntSliderClass),
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
196 NULL, /* base_init */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
197 NULL, /* base_finalize */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
198 (GClassInitFunc)gnt_slider_class_init,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
199 NULL, /* class_finalize */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
200 NULL, /* class_data */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
201 sizeof(GntSlider),
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
202 0, /* n_preallocs */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
203 gnt_slider_init, /* instance_init */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
204 NULL /* value_table */
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
205 };
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
206
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
207 type = g_type_register_static(GNT_TYPE_WIDGET,
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
208 "GntSlider",
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
209 &info, 0);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
210 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
211
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
212 return type;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
213 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
214
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
215 GntWidget *gnt_slider_new(gboolean vertical, int max, int min)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
216 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
217 GntWidget *widget = g_object_new(GNT_TYPE_SLIDER, NULL);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
218 GntSlider *slider = GNT_SLIDER(widget);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
219
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
220 slider->vertical = vertical;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
221
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
222 if (vertical) {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
223 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_Y);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
224 } else {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
225 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
226 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
227
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 gnt_slider_set_range(slider, max, min);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
229 slider->step = 1;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
230
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
231 return widget;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
232 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
233
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
234 void gnt_slider_set_value(GntSlider *slider, int value)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
235 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
236 if (slider->current == value)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
237 return;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
238 slider->current = value;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
239 sanitize_value(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
240 redraw_slider(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
241 slider_value_changed(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
242 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
243
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
244 int gnt_slider_advance_step(GntSlider *slider, int steps)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
245 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
246 slider->current += steps * slider->step;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
247 sanitize_value(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
248 redraw_slider(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
249 slider_value_changed(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
250 return slider->current;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
251 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
252
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
253 void gnt_slider_set_step(GntSlider *slider, int step)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
254 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 slider->step = step;
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
256 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
257
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
258 void gnt_slider_set_range(GntSlider *slider, int max, int min)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
259 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
260 slider->max = MAX(max, min);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
261 slider->min = MIN(max, min);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
262 sanitize_value(slider);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
263 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
264
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
265 static void
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
266 update_label(GntSlider *slider, int current_value, GntLabel *label)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
267 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
268 char value[256];
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
269 g_snprintf(value, sizeof(value), "%d/%d", current_value, slider->max);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
270 gnt_label_set_text(label, value);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
271 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
272
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
273 void gnt_slider_reflect_label(GntSlider *slider, GntLabel *label)
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
274 {
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
275 g_signal_connect(G_OBJECT(slider), "changed", G_CALLBACK(update_label), label);
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
276 }
|
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
277
|