annotate finch/libgnt/gntslider.c @ 29591:41c53be0e8b5

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