Tizen 2.1 base
[framework/osp/uifw.git] / inc / FUiCtrlSlider.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiCtrlSlider.h
19  * @brief       This is the header file for the %Slider class.
20  *
21  * This header file contains the declarations of the %Slider class and its helper classes.
22  */
23
24 #ifndef _FUI_CTRL_SLIDER_H_
25 #define _FUI_CTRL_SLIDER_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseTypes.h>
29 #include <FBaseColArrayListT.h>
30 #include <FBaseString.h>
31 #include <FGrpBitmap.h>
32 #include <FGrpRectangle.h>
33 #include <FUiControl.h>
34 #include <FUiContainer.h>
35 #include <FUiIAdjustmentEventListener.h>
36 #include <FUiCtrlControlsTypes.h>
37 #include <FUiCtrlGroupTypes.h>
38 #include <FUiCtrlSliderTypes.h>
39 #include <FUiCtrlISliderEventListener.h>
40
41
42 namespace Tizen { namespace Ui { namespace Controls
43 {
44
45 /**
46  * @class       Slider
47  * @brief       This class is an implementation of a %Slider control.
48  *
49  * @since       2.0
50  *
51  * The %Slider class displays a slider that represents changing progress or setting information. The difference between %Slider
52  * and Progress is that the former accepts user input by the touch of the slider icon.
53  *
54  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_slider.htm">Slider</a>.
55  *
56  * The following example demonstrates how to use the %Slider class.
57  *
58  * @code
59 // Sample code for SliderSample.h
60 #include <FUi.h>
61
62 class SliderSample
63         : public Tizen::Ui::Controls::Form
64         , public Tizen::Ui::IAdjustmentEventListener
65 {
66 public:
67         SliderSample(void)
68         : __pSlider(null){}
69
70         bool Initialize(void);
71         virtual result OnInitializing(void);
72         virtual void OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment);
73
74 private:
75         Tizen::Ui::Controls::Slider* __pSlider;
76 };
77  *      @endcode
78  *
79  *      @code
80 // Sample code for SliderSample.cpp
81 #include <FGraphics.h>
82
83 #include "SliderSample.h"
84
85 using namespace Tizen::Graphics;
86 using namespace Tizen::Ui::Controls;
87
88 bool
89 SliderSample::Initialize(void)
90 {
91         Construct(FORM_STYLE_NORMAL);
92         return true;
93 }
94
95 result
96 SliderSample::OnInitializing(void)
97 {
98         result r = E_SUCCESS;
99
100         // Creates an instance of Slider
101         __pSlider = new Slider();
102         __pSlider->Construct(Rectangle(0, 200, GetClientAreaBounds().width, 200), BACKGROUND_STYLE_DEFAULT, false, 0, 100);
103         __pSlider->SetValue(50);
104         __pSlider->AddAdjustmentEventListener(*this);
105
106         // Adds the slider to the form
107         AddControl(*__pSlider);
108
109         return r;
110 }
111
112 // IAdjustmentEventListener implementation
113 void
114 SliderSample::OnAdjustmentValueChanged(const Control& source, int adjustment)
115 {
116         // ....
117 }
118  * @endcode
119  *
120  */
121 class _OSP_EXPORT_ Slider
122         : public Tizen::Ui::Control
123 {
124 // Lifecycle
125 public:
126         /**
127          * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
128          *
129          * @since               2.0
130          */
131         Slider(void);
132
133         /**
134          * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
135          *
136          * @since               2.0
137          */
138         virtual ~Slider(void);
139
140         /**
141          * Initializes this instance of %Slider with the specified parameters.
142          *
143          * @since               2.0
144          *
145          * @return              An error code
146          * @param[in]   rect                            An instance of the Graphics::Rectangle class @n
147          *                                                                      This instance represents the x and y coordinates of the top-left corner of the created window along with
148          *                                                                      the width and height of the control.
149          * @param[in]   backgroundStyle         The background style set of the slider
150          * @param[in]   showTitle                       Set to @c true to enable the show title, @n
151          *                                                                      else @c false
152          * @param[in]   minValue                        The minimum slider value
153          * @param[in]   maxValue                        The maximum slider value
154          * @param[in]   groupStyle                      The table view style of the slider
155          * @exception   E_SUCCESS           The method is successful.
156          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
157          * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation. @n
158          *                                  The background style of BACKGROUND_STYLE_NONE does not work with group styles except GROUP_STYLE_NONE.
159          * @exception   E_OUT_OF_RANGE          The specified values are less than @c -99 or greater than @c 999.
160          * @exception   E_SYSTEM                        A system error has occurred.
161          * @remarks             A control is fully usable only after it has been added to a container. Therefore, some methods may fail if used earlier. @n
162          *                              If the given size is less than the minimum, it returns E_INVALID_ARG.
163          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
164          */
165         result Construct(const Tizen::Graphics::Rectangle& rect, BackgroundStyle backgroundStyle = BACKGROUND_STYLE_DEFAULT, bool showTitle = false, int minValue = 0, int maxValue = 100, GroupStyle groupStyle = GROUP_STYLE_NONE);
166
167         /**
168          * Adds a IAdjustmentEventListener instance. @n
169          * The added listener listens to events on the context of the specified event dispatcher when they are fired.
170          *
171          * @since               2.0
172          *
173          * @param[in]   listener        The event listener to be added
174          */
175         void AddAdjustmentEventListener(Tizen::Ui::IAdjustmentEventListener& listener);
176
177         /**
178          * Removes a IAdjustmentEventListener instance. @n
179          * The removed listener cannot listen to events when they are fired.
180          *
181          * @since               2.0
182          *
183          * @param[in]   listener        The event listener to be removed
184          */
185         void RemoveAdjustmentEventListener(Tizen::Ui::IAdjustmentEventListener& listener);
186
187 // Operation
188 public:
189         /**
190          * Sets the range of the %Slider control.
191          *
192          * @since               2.0
193          *
194          * @return              An error code
195          * @param[in]   minValue                The minimum value of the %Slider control
196          * @param[in]   maxValue                The maximum value of the %Slider control
197          * @exception   E_SUCCESS       The method is successful.
198          * @exception   E_INVALID_ARG   A specified input parameter is invalid.
199          * @exception   E_OUT_OF_RANGE  The specified values are greater than @c -99 or less than @c 999.
200          * @exception   E_SYSTEM                A system error has occurred.
201          */
202         result SetRange(int minValue, int maxValue);
203
204         /**
205          * Gets the minimum value and the maximum value of the slider.
206          *
207          * @since               2.0
208          *
209          * @param[out]  minValue                The minimum value of the slider
210          * @param[out]  maxValue                The maximum value of the slider
211          */
212         void GetRange(int& minValue, int& maxValue) const;
213
214         /**
215          * Sets the value of the current thumb position. @n
216          * If the specified @c value is greater than @c maxValue, the value is set to @c maxValue, and
217          * if the specified @c value is less than @c minValue, the value is set to @c minValue.
218          *
219          * @since               2.0
220          *
221          * @param[in]   value  The value of the position
222          */
223         void SetValue(int value);
224
225         /**
226          * Gets the value of the current thumb position.
227          *
228          * @since               2.0
229          *
230          * @return              The current thumb position
231          */
232         int GetValue(void) const;
233
234         /**
235          * Sets the icon of the slider.
236          *
237          * @since               2.0
238          *
239          * @param[in]   position        The position of the icon (ICON_POSITION_LEFT/ICON_POSITION_RIGHT)
240          * @param[in]   icon        The bitmap image of the icon
241          * @remarks     If the size of the bitmap is greater than the default size, the bitmap image is scaled down.
242          */
243         void SetIcon(IconPosition position, const Tizen::Graphics::Bitmap& icon);
244
245         /**
246          * Sets the title of the slider.
247          *
248          * @since               2.0
249          *
250          * @return              An error code
251          * @param[in]    title                  The title to be set
252          * @exception   E_SUCCESS                       The method is successful.
253          * @exception   E_SYSTEM                A system error has occurred.
254          */
255         result SetTitleText(const Tizen::Base::String& title);
256
257         /**
258          * Gets the title of the slider.
259          *
260          * @since               2.0
261          *
262          * @return              The title text of the entered string, @n
263          *                          else an empty string if the %Slider instance is not constructed
264          */
265         Tizen::Base::String GetTitleText(void) const;
266
267         /**
268          * Sets the title text color of the %Slider control.
269          *
270          * @since                       2.0
271          *
272          * @param[in]   color   The title text color to be set
273          */
274         void SetTitleTextColor(const Tizen::Graphics::Color& color);
275
276         /**
277          * Gets the title text color of the %Slider control.
278          *
279          * @since               2.0
280          *
281          * @return              The title text color
282          */
283         Tizen::Graphics::Color GetTitleTextColor(void) const;
284
285         /**
286          * Initializes this instance of %Slider with the specified parameters.
287          *
288          * @since               2.0
289          *
290          * @return              An error code
291          * @param[in]   rect                            An instance of the Graphics::Rectangle class @n
292          *                                                                  This instance represents the x and y coordinates of the top-left corner of the created window along with
293          *                                  its width and height.
294          * @param[in]   sliderStyle         The style of the slider @n
295          *                                  Multiple link types can be combined using bitwise OR operator. See Tizen::Ui::Controls::SliderStyle.
296          * @param[in]   minValue            The minimum slider value
297          * @param[in]   maxValue            The maximum slider value
298          * @exception   E_SUCCESS           The method is successful.
299          * @exception   E_OUT_OF_RANGE      The specified minimum and maximum values are less than @c -99, or greater than @c 999.
300          * @exception   E_INVALID_ARG       A specified input parameter is invalid, or the specified @c minValue is greater than @c maxVaue.
301          * @exception   E_SYSTEM            A system error has occurred.
302          * @remarks             A control is fully functional only after it has been added to a container. Therefore, some methods may fail if they are used before
303          *                              adding the control to the container. @n
304          *                              If the specified size is less than the minimum size, the %Slider control is constructed with the minimum size.
305          * @remarks             The width and the height of the control must be greater than @c 0.
306          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
307          */
308         result Construct(const Tizen::Graphics::Rectangle& rect, unsigned long sliderStyle, int minValue = 0, int maxValue = 100);
309
310         /**
311          * Adds a ISliderEventListener instance. @n
312          * The added listener can listen to the slider-related events.
313          *
314          * @since     2.0
315          *
316          * @param[in] listener    The event listener to be added
317          */
318         void AddSliderEventListener(ISliderEventListener& listener);
319
320         /**
321          * Removes a ISliderEventListener instance. @n
322          * The removed listener cannot listen to events when they are fired.
323          *
324          * @since     2.0
325          *
326          * @param[in] listener    The event listener to be removed
327          */
328         void RemoveSliderEventListener(ISliderEventListener& listener);
329
330         /**
331          * Sets the color of the bar.
332          *
333          * @since     2.0
334          *
335          * @return    An error code
336          * @param[in] color             The color to be set
337          * @exception E_SUCCESS         The method is successful.
338          * @exception E_SYSTEM          A system error has occurred.
339          * @remarks   The method ignores the alpha value of the @c color parameter and sets the alpha value to @c 255.
340          */
341         result SetBarColor(const Tizen::Graphics::Color& color);
342
343         /**
344          * Gets the color of the bar.
345          *
346          * @since     2.0
347          *
348          * @return    The color of the bar, @n
349          *                        else RGBA(0, 0, 0, 0) if an error occurs
350          * @exception E_SUCCESS         The method is successful.
351          * @remarks   The specific error code can be accessed using the GetLastResult() method.
352          */
353         Tizen::Graphics::Color GetBarColor(void) const;
354
355         /**
356          * Sets the color of the slider.
357          *
358          * @since     2.0
359          *
360          * @return    An error code
361          * @param[in] color                     The color to be set
362          * @exception E_SUCCESS                 The method is successful.
363          * @exception E_INVALID_OPERATION               The current state of the instance prohibits the execution of the specified operation. @n
364          *                                                                              The operation is not supported if the background style of the %Slider control is BACKGROUND_STYLE_NONE.
365          * @exception E_SYSTEM                  A system error has occurred.
366          * @remarks   If a device supports only the 16-bit color space, this method considers the color as opaque by ignoring the alpha value of @c color.
367          */
368         result SetColor(const Tizen::Graphics::Color& color);
369
370         /**
371          * Gets the color of the slider.
372          *
373          * @since               2.0
374          *
375          * @return              The color , @n
376          *                              else RGBA(0, 0, 0, 0) if an instance is invalid or the background style is BACKGROUND_STYLE_NONE
377          * @exception   E_SUCCESS                       The method is successful.
378          * @exception   E_INVALID_OPERATION     The background style is not proper.
379          * @remarks             The specific error code can be accessed using the GetLastResult() method.
380          */
381         Tizen::Graphics::Color GetColor(void) const;
382
383         /**
384          * Sets the bitmap image to the %Slider control Thumb.
385          *
386          * @since 2.0
387          *
388          * @return    An error code
389          * @param[in] status                    The state of the slider thumb
390          * @param[in] bitmap                    The Thumb bitmap image
391          * @exception E_SUCCESS             The method is successful.
392          * @exception E_OUT_OF_MEMORY       The memory is insufficient.
393          */
394         result SetThumbBitmap(SliderThumbStatus status, const Tizen::Graphics::Bitmap& bitmap);
395
396         /**
397          * Sets the text color of the %Slider control Thumb.
398          *
399          * @since 2.0
400          *
401          * @return        An error code
402          * @param[in] status                                    The state of the slider thumb
403          * @param[in] color                                     The color should be set for the thumb text
404          */
405         void SetThumbTextColor(SliderThumbStatus status, const Tizen::Graphics::Color& color);
406
407 private:
408         //
409         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
410         //
411         Slider(const Slider&);
412
413         //
414         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
415         //
416         Slider& operator =(const Slider&);
417
418         friend class _SliderImpl;
419
420 };      // Slider
421
422 }}}     // Tizen::Ui::Controls
423
424 #endif // _FUI_CTRL_SLIDER_H_