1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 0.4
5  * October 1998
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  *
26 */
27 
28 
29 #include "vdk/slider.h"
30 #include "vdk/forms.h"
31 
32 /*
33 the signal sender
34 is the adjustment inside scale widget.
35  */
ValueChanged(GtkWidget * wid,gpointer gp)36 void VDKSlider::ValueChanged(GtkWidget *wid, gpointer gp)
37 {
38 	g_return_if_fail(wid != NULL);
39 	g_return_if_fail(gp != NULL);
40 	VDKSlider* obj = reinterpret_cast<VDKSlider*> (gp);
41 	obj->Value((float)(GTK_ADJUSTMENT(wid)->value));
42 	obj->SignalEmit(value_changed_signal);
43 #ifdef USE_SIGCPLUSPLUS
44 	obj->OnSliderValueChanged(obj, obj->Value);
45 #endif /* USE_SIGCPLUSPLUS */
46 }
47 
VDKSlider(VDKForm * owner,float defValue,float lower,float upper,float step,int mode,int w,int h)48 VDKSlider::VDKSlider(VDKForm* owner,
49 		     float defValue,
50 		     float lower,
51 		     float upper,
52 		     float step,
53 		     int mode,
54 		     int w,
55 		     int h):
56   VDKObject(owner),
57   Value("Value",this,defValue,&VDKSlider::SetValue),
58   Digits("Digits",this,1,&VDKSlider::SetDigits),
59   UpdatePolicy("UpdatePolicy",this,update_discontinuos,
60 	       &VDKSlider::SetUpdatePolicy),
61   LowerBound("LowerBound",this,lower,&VDKSlider::SetLowerBound,
62 	     &VDKSlider::GetLowerBound),
63   UpperBound("UpperBound",this,lower,&VDKSlider::SetUpperBound,
64 	     &VDKSlider::GetUpperBound),
65   Step("Step",this,step, &VDKSlider::SetStep, &VDKSlider::GetStep)
66 {
67   adj = gtk_adjustment_new (defValue, lower, upper+step, step, step, step);
68   widget = mode == h_box ?
69     gtk_hscale_new (GTK_ADJUSTMENT (adj)) :
70     gtk_vscale_new (GTK_ADJUSTMENT (adj));
71   gtk_widget_set_size_request (GTK_WIDGET (widget), w, h);
72   gtk_range_set_update_policy (GTK_RANGE (widget),
73 			       (GtkUpdateType) update_discontinuos);
74   gtk_scale_set_digits (GTK_SCALE (widget), 1);
75   gtk_scale_set_draw_value (GTK_SCALE (widget), TRUE);
76   gtk_signal_connect(adj,"value_changed",
77 		     GTK_SIGNAL_FUNC(VDKSlider::ValueChanged),
78 		     (gpointer) this);
79   ConnectDefaultSignals();
80 }
81 
82 
~VDKSlider()83 VDKSlider::~VDKSlider()
84 {
85 }
86 
87 
88 void
SetValue(float f)89 VDKSlider::SetValue(float f)
90 {
91   /*
92 GtkWidget* widget = WrappedWidget();
93 GtkRange* range = &(GTK_SCALE(widget)->range);
94 GtkAdjustment* adj = gtk_range_get_adjustment(range);
95   */
96 // setting value
97 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj),f);
98 Value(f);
99 }
100 
101 float
GetStep(void)102 VDKSlider::GetStep(void)
103 {
104   return (float)GTK_ADJUSTMENT(adj)->step_increment;
105 }
106 
107 void
SetStep(float f)108 VDKSlider::SetStep(float f)
109 {
110   GTK_ADJUSTMENT(adj)->step_increment = f;
111 }
112 
113 float
GetLowerBound(void)114 VDKSlider::GetLowerBound(void)
115 {
116   return (float)GTK_ADJUSTMENT(adj)->lower;
117 }
118 
119 void
SetLowerBound(float f)120 VDKSlider::SetLowerBound(float f)
121 {
122   GTK_ADJUSTMENT(adj)->lower = f;
123 }
124 
125 float
GetUpperBound(void)126 VDKSlider::GetUpperBound(void)
127 {
128   return (float)GTK_ADJUSTMENT(adj)->upper;
129 }
130 
131 void
SetUpperBound(float f)132 VDKSlider::SetUpperBound(float f)
133 {
134   GTK_ADJUSTMENT(adj)->upper = f;
135 }
136