Wed, 13 May 2009 20:29:03 +0000
Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.
| 18406 | 1 | /** |
| 2 | * GNT - The GLib Ncurses Toolkit | |
| 3 | * | |
| 4 | * GNT is the legal property of its developers, whose names are too numerous | |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This library is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19587
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 18406 | 21 | */ |
| 22 | ||
| 23 | #include "gntcolors.h" | |
| 24 | #include "gntkeys.h" | |
| 25 | #include "gntslider.h" | |
| 26 | #include "gntstyle.h" | |
| 27 | ||
| 28 | enum | |
| 29 | { | |
| 30 | SIG_VALUE_CHANGED, | |
| 31 | SIGS, | |
| 32 | }; | |
| 33 | ||
| 34 | static guint signals[SIGS] = { 0 }; | |
| 35 | ||
| 36 | static GntWidgetClass *parent_class = NULL; | |
| 37 | ||
| 38 | /* returns TRUE if the value was changed */ | |
| 39 | static gboolean | |
| 40 | sanitize_value(GntSlider *slider) | |
| 41 | { | |
| 42 | if (slider->current < slider->min) | |
| 43 | slider->current = slider->min; | |
| 44 | else if (slider->current > slider->max) | |
| 45 | slider->current = slider->max; | |
| 46 | else | |
| 47 | return FALSE; | |
| 48 | return TRUE; | |
| 49 | } | |
| 50 | ||
| 51 | static void | |
| 52 | redraw_slider(GntSlider *slider) | |
| 53 | { | |
| 54 | GntWidget *widget = GNT_WIDGET(slider); | |
| 55 | if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
| 56 | gnt_widget_draw(widget); | |
| 57 | } | |
| 58 | ||
| 59 | static void | |
| 60 | slider_value_changed(GntSlider *slider) | |
| 61 | { | |
| 62 | g_signal_emit(slider, signals[SIG_VALUE_CHANGED], 0, slider->current); | |
| 63 | } | |
| 64 | ||
| 65 | static void | |
| 66 | gnt_slider_draw(GntWidget *widget) | |
| 67 | { | |
| 68 | GntSlider *slider = GNT_SLIDER(widget); | |
| 69 | int attr = 0; | |
| 70 | int position, size = 0; | |
| 71 | ||
| 72 | if (slider->vertical) | |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
73 | size = widget->priv.height; |
| 18406 | 74 | else |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
75 | size = widget->priv.width; |
| 18406 | 76 | |
| 77 | if (gnt_widget_has_focus(widget)) | |
| 78 | attr |= GNT_COLOR_HIGHLIGHT; | |
| 79 | else | |
| 80 | attr |= GNT_COLOR_HIGHLIGHT_D; | |
| 81 | ||
| 82 | if (slider->max != slider->min) | |
| 83 | position = ((size - 1) * (slider->current - slider->min)) / (slider->max - slider->min); | |
| 84 | else | |
| 85 | position = 0; | |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
86 | if (slider->vertical) { |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
87 | mvwvline(widget->window, size-position, 0, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL) | A_BOLD, |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
88 | position); |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
89 | mvwvline(widget->window, 0, 0, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
90 | size-position); |
|
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
91 | } else { |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
92 | mvwhline(widget->window, 0, 0, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL) | A_BOLD, |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
93 | position); |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
94 | mvwhline(widget->window, 0, position, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
95 | size - position); |
|
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
96 | } |
|
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
97 | |
| 18406 | 98 | mvwaddch(widget->window, |
| 99 | slider->vertical ? (size - position - 1) : 0, | |
| 100 | slider->vertical ? 0 : position, | |
|
21240
b78eaddaae02
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19859
diff
changeset
|
101 | ACS_CKBOARD | gnt_color_pair(attr)); |
| 18406 | 102 | } |
| 103 | ||
| 104 | static void | |
| 105 | gnt_slider_size_request(GntWidget *widget) | |
| 106 | { | |
| 107 | if (GNT_SLIDER(widget)->vertical) { | |
| 108 | widget->priv.width = 1; | |
| 109 | widget->priv.height = 5; | |
| 110 | } else { | |
| 111 | widget->priv.width = 5; | |
| 112 | widget->priv.height = 1; | |
| 113 | } | |
| 114 | } | |
| 115 | ||
| 116 | static void | |
| 117 | gnt_slider_map(GntWidget *widget) | |
| 118 | { | |
| 119 | if (widget->priv.width == 0 || widget->priv.height == 0) | |
| 120 | gnt_widget_size_request(widget); | |
| 121 | GNTDEBUG; | |
| 122 | } | |
| 123 | ||
| 124 | static gboolean | |
| 125 | step_back(GntBindable *bindable, GList *null) | |
| 126 | { | |
| 127 | GntSlider *slider = GNT_SLIDER(bindable); | |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
128 | gnt_slider_advance_step(slider, -1); |
| 18406 | 129 | return TRUE; |
| 130 | } | |
| 131 | ||
| 132 | static gboolean | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
133 | small_step_back(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
134 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
135 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
136 | gnt_slider_set_value(slider, slider->current - slider->smallstep); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
137 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
138 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
139 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
140 | static gboolean |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
141 | large_step_back(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
142 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
143 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
144 | gnt_slider_set_value(slider, slider->current - slider->largestep); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
145 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
146 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
147 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
148 | static gboolean |
| 18406 | 149 | step_forward(GntBindable *bindable, GList *list) |
| 150 | { | |
| 151 | GntSlider *slider = GNT_SLIDER(bindable); | |
|
18408
44165bc6b9e3
Remove some duplication, and make the slider a little nicer.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18406
diff
changeset
|
152 | gnt_slider_advance_step(slider, 1); |
| 18406 | 153 | return TRUE; |
| 154 | } | |
| 155 | ||
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
156 | static gboolean |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
157 | small_step_forward(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
158 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
159 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
160 | gnt_slider_set_value(slider, slider->current + slider->smallstep); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
161 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
162 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
163 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
164 | static gboolean |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
165 | large_step_forward(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
166 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
167 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
168 | gnt_slider_set_value(slider, slider->current + slider->largestep); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
169 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
170 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
171 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
172 | static gboolean |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
173 | move_min_value(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
174 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
175 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
176 | gnt_slider_set_value(slider, slider->min); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
177 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
178 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
179 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
180 | static gboolean |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
181 | move_max_value(GntBindable *bindable, GList *null) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
182 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
183 | GntSlider *slider = GNT_SLIDER(bindable); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
184 | gnt_slider_set_value(slider, slider->max); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
185 | return TRUE; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
186 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
187 | |
| 18406 | 188 | static void |
| 189 | gnt_slider_class_init(GntSliderClass *klass) | |
| 190 | { | |
| 191 | GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); | |
| 192 | parent_class = GNT_WIDGET_CLASS(klass); | |
| 193 | parent_class->draw = gnt_slider_draw; | |
| 194 | parent_class->map = gnt_slider_map; | |
| 195 | parent_class->size_request = gnt_slider_size_request; | |
| 196 | ||
| 197 | klass->changed = NULL; | |
| 198 | ||
| 199 | signals[SIG_VALUE_CHANGED] = | |
| 200 | g_signal_new("changed", | |
| 201 | G_TYPE_FROM_CLASS(klass), | |
| 202 | G_SIGNAL_RUN_LAST, | |
| 203 | G_STRUCT_OFFSET(GntSliderClass, changed), | |
| 204 | NULL, NULL, | |
| 205 | g_cclosure_marshal_VOID__INT, | |
| 206 | G_TYPE_NONE, 1, G_TYPE_INT); | |
| 207 | ||
| 208 | gnt_bindable_class_register_action(bindable, "step-backward", step_back, GNT_KEY_LEFT, NULL); | |
| 209 | gnt_bindable_register_binding(bindable, "step-backward", GNT_KEY_DOWN, NULL); | |
| 210 | gnt_bindable_class_register_action(bindable, "step-forward", step_forward, GNT_KEY_RIGHT, NULL); | |
| 211 | gnt_bindable_register_binding(bindable, "step-forward", GNT_KEY_UP, NULL); | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
212 | gnt_bindable_class_register_action(bindable, "small-step-backward", small_step_back, GNT_KEY_CTRL_LEFT, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
213 | gnt_bindable_register_binding(bindable, "small-step-backward", GNT_KEY_CTRL_DOWN, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
214 | gnt_bindable_class_register_action(bindable, "small-step-forward", small_step_forward, GNT_KEY_CTRL_RIGHT, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
215 | gnt_bindable_register_binding(bindable, "small-step-forward", GNT_KEY_CTRL_UP, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
216 | gnt_bindable_class_register_action(bindable, "large-step-backward", large_step_back, GNT_KEY_PGDOWN, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
217 | gnt_bindable_class_register_action(bindable, "large-step-forward", large_step_forward, GNT_KEY_PGUP, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
218 | gnt_bindable_class_register_action(bindable, "min-value", move_min_value, GNT_KEY_HOME, NULL); |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
219 | gnt_bindable_class_register_action(bindable, "max-value", move_max_value, GNT_KEY_END, NULL); |
| 18406 | 220 | |
| 221 | gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
| 222 | } | |
| 223 | ||
| 224 | static void | |
| 225 | gnt_slider_init(GTypeInstance *instance, gpointer class) | |
| 226 | { | |
| 227 | GntWidget *widget = GNT_WIDGET(instance); | |
| 228 | GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_CAN_TAKE_FOCUS); | |
| 229 | widget->priv.minw = 1; | |
| 230 | widget->priv.minh = 1; | |
| 231 | GNTDEBUG; | |
| 232 | } | |
| 233 | ||
| 234 | /****************************************************************************** | |
| 235 | * GntSlider API | |
| 236 | *****************************************************************************/ | |
| 237 | GType | |
| 238 | gnt_slider_get_gtype(void) | |
| 239 | { | |
| 240 | static GType type = 0; | |
| 241 | ||
| 242 | if(type == 0) | |
| 243 | { | |
| 244 | static const GTypeInfo info = { | |
| 245 | sizeof(GntSliderClass), | |
| 246 | NULL, /* base_init */ | |
| 247 | NULL, /* base_finalize */ | |
| 248 | (GClassInitFunc)gnt_slider_class_init, | |
| 249 | NULL, /* class_finalize */ | |
| 250 | NULL, /* class_data */ | |
| 251 | sizeof(GntSlider), | |
| 252 | 0, /* n_preallocs */ | |
| 253 | gnt_slider_init, /* instance_init */ | |
| 254 | NULL /* value_table */ | |
| 255 | }; | |
| 256 | ||
| 257 | type = g_type_register_static(GNT_TYPE_WIDGET, | |
| 258 | "GntSlider", | |
| 259 | &info, 0); | |
| 260 | } | |
| 261 | ||
| 262 | return type; | |
| 263 | } | |
| 264 | ||
| 265 | GntWidget *gnt_slider_new(gboolean vertical, int max, int min) | |
| 266 | { | |
| 267 | GntWidget *widget = g_object_new(GNT_TYPE_SLIDER, NULL); | |
| 268 | GntSlider *slider = GNT_SLIDER(widget); | |
| 269 | ||
| 270 | slider->vertical = vertical; | |
| 271 | ||
| 272 | if (vertical) { | |
| 273 | GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_Y); | |
| 274 | } else { | |
| 275 | GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); | |
| 276 | } | |
| 277 | ||
| 278 | gnt_slider_set_range(slider, max, min); | |
| 279 | slider->step = 1; | |
| 280 | ||
| 281 | return widget; | |
| 282 | } | |
| 283 | ||
| 284 | void gnt_slider_set_value(GntSlider *slider, int value) | |
| 285 | { | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
286 | int old; |
| 18406 | 287 | if (slider->current == value) |
| 288 | return; | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
289 | old = slider->current; |
| 18406 | 290 | slider->current = value; |
| 291 | sanitize_value(slider); | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
292 | if (old == slider->current) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
293 | return; |
| 18406 | 294 | redraw_slider(slider); |
| 295 | slider_value_changed(slider); | |
| 296 | } | |
| 297 | ||
| 18433 | 298 | int gnt_slider_get_value(GntSlider *slider) |
| 299 | { | |
| 300 | return slider->current; | |
| 301 | } | |
| 302 | ||
| 18406 | 303 | int gnt_slider_advance_step(GntSlider *slider, int steps) |
| 304 | { | |
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
305 | gnt_slider_set_value(slider, slider->current + steps * slider->step); |
| 18406 | 306 | return slider->current; |
| 307 | } | |
| 308 | ||
| 309 | void gnt_slider_set_step(GntSlider *slider, int step) | |
| 310 | { | |
| 311 | slider->step = step; | |
| 312 | } | |
| 313 | ||
|
19587
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
314 | void gnt_slider_set_small_step(GntSlider *slider, int step) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
315 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
316 | slider->smallstep = step; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
317 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
318 | |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
319 | void gnt_slider_set_large_step(GntSlider *slider, int step) |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
320 | { |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
321 | slider->largestep = step; |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
322 | } |
|
8715e45e1258
Have small and large steps for the slider.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18433
diff
changeset
|
323 | |
| 18406 | 324 | void gnt_slider_set_range(GntSlider *slider, int max, int min) |
| 325 | { | |
| 326 | slider->max = MAX(max, min); | |
| 327 | slider->min = MIN(max, min); | |
| 328 | sanitize_value(slider); | |
| 329 | } | |
| 330 | ||
| 331 | static void | |
| 332 | update_label(GntSlider *slider, int current_value, GntLabel *label) | |
| 333 | { | |
| 334 | char value[256]; | |
| 335 | g_snprintf(value, sizeof(value), "%d/%d", current_value, slider->max); | |
| 336 | gnt_label_set_text(label, value); | |
| 337 | } | |
| 338 | ||
| 339 | void gnt_slider_reflect_label(GntSlider *slider, GntLabel *label) | |
| 340 | { | |
| 341 | g_signal_connect(G_OBJECT(slider), "changed", G_CALLBACK(update_label), label); | |
| 342 | } | |
| 343 |