Fix to adjust the position of the partial Frame
[platform/framework/native/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 /**
19  * @file        FUiCtrlSlider.h
20  * @brief       This is the header file for the %Slider class.
21  *
22  * This header file contains the declarations of the %Slider class and its helper classes.
23  */
24
25 #ifndef _FUI_CTRL_SLIDER_H_
26 #define _FUI_CTRL_SLIDER_H_
27
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseColArrayListT.h>
31 #include <FBaseString.h>
32 #include <FGrpBitmap.h>
33 #include <FGrpRectangle.h>
34 #include <FUiControl.h>
35 #include <FUiContainer.h>
36 #include <FUiIAdjustmentEventListener.h>
37 #include <FUiCtrlControlsTypes.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 @c BACKGROUND_STYLE_NONE does not work with group styles except @c 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 @c 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          * Initializes this instance of %Slider with the specified parameters.
169          *
170          * @since               2.1
171          *
172          * @return              An error code
173          * @param[in]   rect                            An instance of the Graphics::FloatRectangle class @n
174          *                                                                      This instance represents the x and y coordinates of the top-left corner of the created window along with
175          *                                                                      the width and height of the control.
176          * @param[in]   backgroundStyle         The background style set of the slider
177          * @param[in]   showTitle                       Set to @c true to enable the show title, @n
178          *                                                                      else @c false
179          * @param[in]   minValue                        The minimum slider value
180          * @param[in]   maxValue                        The maximum slider value
181          * @param[in]   groupStyle                      The table view style of the slider
182          * @exception   E_SUCCESS           The method is successful.
183          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
184          * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation. @n
185          *                                  The background style of @c BACKGROUND_STYLE_NONE does not work with group styles except @c GROUP_STYLE_NONE.
186          * @exception   E_OUT_OF_RANGE          The specified values are less than @c -99 or greater than @c 999.
187          * @exception   E_SYSTEM                        A system error has occurred.
188          * @remarks             A control is fully usable only after it has been added to a container. Therefore, some methods may fail if used earlier. @n
189          *                              If the given size is less than the minimum, it returns @c E_INVALID_ARG.
190          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
191          */
192         result Construct(const Tizen::Graphics::FloatRectangle& rect, BackgroundStyle backgroundStyle = BACKGROUND_STYLE_DEFAULT, bool showTitle = false, int minValue = 0, int maxValue = 100, GroupStyle groupStyle = GROUP_STYLE_NONE);
193
194         /**
195          * Adds a IAdjustmentEventListener instance. @n
196          * The added listener listens to events on the context of the specified event dispatcher when they are fired.
197          *
198          * @since               2.0
199          *
200          * @param[in]   listener        The event listener to add
201          */
202         void AddAdjustmentEventListener(Tizen::Ui::IAdjustmentEventListener& listener);
203
204         /**
205          * Removes a IAdjustmentEventListener instance. @n
206          * The removed listener cannot listen to events when they are fired.
207          *
208          * @since               2.0
209          *
210          * @param[in]   listener        The event listener to remove
211          */
212         void RemoveAdjustmentEventListener(Tizen::Ui::IAdjustmentEventListener& listener);
213
214 // Operation
215 public:
216         /**
217          * Sets the range of the %Slider control.
218          *
219          * @since               2.0
220          *
221          * @return              An error code
222          * @param[in]   minValue                The minimum value of the %Slider control
223          * @param[in]   maxValue                The maximum value of the %Slider control
224          * @exception   E_SUCCESS       The method is successful.
225          * @exception   E_INVALID_ARG   A specified input parameter is invalid.
226          * @exception   E_OUT_OF_RANGE  The specified values are greater than @c -99 or less than @c 999.
227          * @exception   E_SYSTEM                A system error has occurred.
228          */
229         result SetRange(int minValue, int maxValue);
230
231         /**
232          * Gets the minimum value and the maximum value of the slider.
233          *
234          * @since               2.0
235          *
236          * @param[out]  minValue                The minimum value of the slider
237          * @param[out]  maxValue                The maximum value of the slider
238          */
239         void GetRange(int& minValue, int& maxValue) const;
240
241         /**
242          * Sets the value of the current thumb position. @n
243          * If the specified @c value is greater than @c maxValue, the value is set to @c maxValue, and
244          * if the specified @c value is less than @c minValue, the value is set to @c minValue.
245          *
246          * @since               2.0
247          *
248          * @param[in]   value  The value of the position
249          */
250         void SetValue(int value);
251
252         /**
253          * Gets the value of the current thumb position.
254          *
255          * @since               2.0
256          *
257          * @return              The current thumb position
258          */
259         int GetValue(void) const;
260
261         /**
262          * Sets the icon of the slider.
263          *
264          * @since               2.0
265          *
266          * @param[in]   position        The position of the icon (@c ICON_POSITION_LEFT/@c ICON_POSITION_RIGHT)
267          * @param[in]   icon        The bitmap image of the icon
268          * @remarks     If the size of the bitmap is greater than the default size, the bitmap image is scaled down.
269          */
270         void SetIcon(IconPosition position, const Tizen::Graphics::Bitmap& icon);
271
272         /**
273         * Sets the title of the slider.
274         *
275         * @since                2.0
276         *
277         * @return               An error code
278         * @param[in]    title                   The title to set
279         * @exception    E_SUCCESS                       The method is successful.
280         * @exception    E_SYSTEM                A system error has occurred.
281         */
282         result SetTitleText(const Tizen::Base::String& title);
283
284         /**
285          * Gets the title of the slider.
286          *
287          * @since               2.0
288          *
289          * @return              The title text of the entered string
290          *
291          * @remarks             By default returns an empty string.
292          */
293         Tizen::Base::String GetTitleText(void) const;
294
295         /**
296          * Sets the title text color of the %Slider control.
297          *
298          * @since                       2.0
299          *
300          * @param[in]   color   The title text color to set
301          */
302         void SetTitleTextColor(const Tizen::Graphics::Color& color);
303
304         /**
305          * Gets the title text color of the %Slider control.
306          *
307          * @since               2.0
308          *
309          * @return              The title text color
310          */
311         Tizen::Graphics::Color GetTitleTextColor(void) const;
312
313         /**
314          * Initializes this instance of %Slider with the specified parameters.
315          *
316          * @since               2.0
317          *
318          * @return              An error code
319          * @param[in]   rect                            An instance of the Graphics::Rectangle class @n
320          *                                                                  This instance represents the x and y coordinates of the top-left corner of the created window along with
321          *                                  its width and height.
322          * @param[in]   sliderStyle         The style of the slider @n
323          *                                  Multiple link types can be combined using bitwise OR operator. See Tizen::Ui::Controls::SliderStyle.
324          * @param[in]   minValue            The minimum slider value
325          * @param[in]   maxValue            The maximum slider value
326          * @exception   E_SUCCESS           The method is successful.
327          * @exception   E_OUT_OF_RANGE      The specified minimum and maximum values are less than @c -99, or greater than @c 999.
328          * @exception   E_INVALID_ARG       A specified input parameter is invalid, or the specified @c minValue is greater than @c maxVaue.
329          * @exception   E_SYSTEM            A system error has occurred.
330          * @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
331          *                              adding the control to the container. @n
332          *                              If the specified size is less than the minimum size, the %Slider control is constructed with the minimum size.
333          * @remarks             The width and the height of the control must be greater than @c 0.
334          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
335          */
336         result Construct(const Tizen::Graphics::Rectangle& rect, unsigned long sliderStyle, int minValue = 0, int maxValue = 100);
337
338         /**
339          * Initializes this instance of %Slider with the specified parameters.
340          *
341          * @since               2.1
342          *
343          * @return              An error code
344          * @param[in]   rect                            An instance of the Graphics::FloatRectangle class @n
345          *                                                                  This instance represents the x and y coordinates of the top-left corner of the created window along with
346          *                                  its width and height.
347          * @param[in]   sliderStyle         The style of the slider @n
348          *                                  Multiple link types can be combined using bitwise OR operator. See Tizen::Ui::Controls::SliderStyle.
349          * @param[in]   minValue            The minimum slider value
350          * @param[in]   maxValue            The maximum slider value
351          * @exception   E_SUCCESS           The method is successful.
352          * @exception   E_OUT_OF_RANGE      The specified minimum and maximum values are less than @c -99, or greater than @c 999.
353          * @exception   E_INVALID_ARG       A specified input parameter is invalid, or the specified @c minValue is greater than @c maxVaue.
354          * @exception   E_SYSTEM            A system error has occurred.
355          * @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
356          *                              adding the control to the container. @n
357          *                              If the specified size is less than the minimum size, the %Slider control is constructed with the minimum size.
358          * @remarks             The width and the height of the control must be greater than @c 0.
359          * @remarks             The size of the control must be within the range defined by the minimum size and the maximum size.
360          */
361         result Construct(const Tizen::Graphics::FloatRectangle& rect, unsigned long sliderStyle, int minValue = 0, int maxValue = 100);
362
363         /**
364          * Adds a ISliderEventListener instance. @n
365          * The added listener can listen to the slider-related events.
366          *
367          * @since     2.0
368          *
369          * @param[in] listener    The event listener to add
370          */
371         void AddSliderEventListener(ISliderEventListener& listener);
372
373         /**
374          * Removes a ISliderEventListener instance. @n
375          * The removed listener cannot listen to events when they are fired.
376          *
377          * @since     2.0
378          *
379          * @param[in] listener    The event listener to remove
380          */
381         void RemoveSliderEventListener(ISliderEventListener& listener);
382
383         /**
384          * Sets the color of the bar.
385          *
386          * @since     2.0
387          *
388          * @return    An error code
389          * @param[in] color             The color to set
390          * @exception E_SUCCESS         The method is successful.
391          * @exception E_SYSTEM          A system error has occurred.
392          * @remarks   The method ignores the alpha value of the @c color parameter and sets the alpha value to @c 255.
393          */
394         result SetBarColor(const Tizen::Graphics::Color& color);
395
396         /**
397          * Gets the color of the bar.
398          *
399          * @since     2.0
400          *
401          * @return    The color of the bar, @n
402          *                        else RGBA(0, 0, 0, 0) if an error occurs
403          * @exception E_SUCCESS         The method is successful.
404          * @remarks   The specific error code can be accessed using the GetLastResult() method.
405          */
406         Tizen::Graphics::Color GetBarColor(void) const;
407
408         /**
409          * Sets the background color of the bar.
410          *
411          * @since     2.1
412          *
413          * @param[in] barBackgroundColor             The color to be set
414          * @remarks   The method ignores the alpha value of the @c color parameter and sets the alpha value to @c 255.
415          * @see GetBarBackgroundColor()
416          */
417         void SetBarBackgroundColor(const Tizen::Graphics::Color& barBackgroundColor);
418
419         /**
420          * Gets the background color of the bar.
421          *
422          * @since     2.1
423          *
424          * @return    The background color of the bar, @n
425          *                        else RGBA(0, 0, 0, 0) if an error occurs
426          * @remarks   The specific error code can be accessed using the GetLastResult() method.
427          * @see SetBarBackgroundColor()
428          */
429         Tizen::Graphics::Color GetBarBackgroundColor(void) const;
430
431         /**
432          * Sets the color of the slider.
433          *
434          * @since     2.0
435          *
436          * @return    An error code
437          * @param[in] color                     The color to set
438          * @exception E_SUCCESS                 The method is successful.
439          * @exception E_INVALID_OPERATION               The current state of the instance prohibits the execution of the specified operation. @n
440          *                                                                              The operation is not supported if the background style of the %Slider control is @c BACKGROUND_STYLE_NONE.
441          * @exception E_SYSTEM                  A system error has occurred.
442          * @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.
443          */
444         result SetColor(const Tizen::Graphics::Color& color);
445
446         /**
447          * Gets the color of the slider.
448          *
449          * @since               2.0
450          *
451          * @return              The color , @n
452          *                              else RGBA(0, 0, 0, 0) if an instance is invalid or the background style is @c BACKGROUND_STYLE_NONE
453          * @exception   E_SUCCESS                       The method is successful.
454          * @exception   E_INVALID_OPERATION     The background style is not proper.
455          * @remarks             The specific error code can be accessed using the GetLastResult() method.
456          */
457         Tizen::Graphics::Color GetColor(void) const;
458
459         /**
460          * Sets the bitmap image to the %Slider control Thumb.
461          *
462          * @since 2.0
463          *
464          * @return    An error code
465          * @param[in] status                    The state of the slider thumb
466          * @param[in] bitmap                    The Thumb bitmap image
467          * @exception E_SUCCESS             The method is successful.
468          * @exception E_OUT_OF_MEMORY       The memory is insufficient.
469          */
470         result SetThumbBitmap(SliderThumbStatus status, const Tizen::Graphics::Bitmap& bitmap);
471
472         /**
473          * Sets the text color of the %Slider control Thumb.
474          *
475          * @since 2.0
476          *
477          * @return        An error code
478          * @param[in] status                                    The state of the slider thumb
479          * @param[in] color                                     The color should be set for the thumb text
480          */
481         void SetThumbTextColor(SliderThumbStatus status, const Tizen::Graphics::Color& color);
482
483 private:
484         //
485         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
486         //
487         Slider(const Slider&);
488
489         //
490         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
491         //
492         Slider& operator =(const Slider&);
493
494         friend class _SliderImpl;
495
496 };      // Slider
497
498 }}}     // Tizen::Ui::Controls
499
500 #endif // _FUI_CTRL_SLIDER_H_