1 /*****************************************************************
2     ViewKlass - C++ framework library for Motif
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 
18     Copyright (C) 2001 John Lemcke
19     jostle@users.sourceforge.net
20 *****************************************************************/
21 
22 #ifndef SLIDER_H
23 #define SLIDER_H
24 
25 #include <Vk/VkComponent.h>
26 #include <Vk/VkRepeatButton.h>
27 #include <Vk/VkAction.h>
28 #include <Xm/Scale.h>
29 #include <Xm/TextF.h>
30 #include <Xm/Label.h>
31 #include <Xm/Form.h>
32 
33 #include <iostream>
34 
35 class SliderAction;
36 
37 class Slider : public VkComponent {
38 public:
39 	Slider(const char *name, Widget parent);
40 
41 	virtual ~Slider();
42 
43 	void setValue(int value, bool undoable = true);
44 
45 	int getValue();
46 
47 	void setLabel(const char*);
48 
49 	void setRange(int min, int max);
50 
className()51 	virtual const char* className() { return "Slider";}
52 
53 	friend std::ostream& operator<<(std::ostream& os, Slider& me);
54 
55 private:
56 	static const char* const _defaultResources[];
57 
58 	Widget _scale;
59 	Widget _textf;
60 	Widget _label;
61 
62 	int _min;
63 	int _max;
64 public:
65 	int _value;
66 
67 	VkRepeatButton* _inc;
68 	VkRepeatButton* _dec;
69 	virtual void increment(VkCallbackObject* obj,
70 						   void* clientData,
71 						   void* callData);
72 	virtual void decrement(VkCallbackObject* obj,
73 						   void* clientData,
74 						   void* callData);
75 
76 	static void scaleChangedCb(Widget w, XtPointer client_data,
77 							   XtPointer call_data);
78 	void scaleChanged(int value, bool undoable);
79 
80 	static void textChangedCb(Widget w, XtPointer client_data,
81 							  XtPointer call_data);
82 	void textChanged(int value);
83 
84 	SliderAction* mAction;
85 };
86 
87 
88 class SliderAction : public VkAction
89 {
90 public:
SliderAction(const char * name,Slider * slider)91 	SliderAction(const char* name, Slider* slider)
92 		: VkAction(name),
93 		  mSlider(slider)
94 		{}
95 
doit()96 	void doit() {
97 		mUndoValues.push_back(mSlider->_value);
98 	}
99 
undoit()100 	void undoit() {
101 		mUndoValues.pop_back();
102 		mSlider->setValue(mUndoValues.back(), false);
103 	}
104 
105 	Slider* mSlider;
106 	std::vector<int> mUndoValues;
107 };
108 
109 #endif // SLIDER_H
110