Tizen 2.1 base
[framework/osp/uifw.git] / inc / FUiCtrlTimePicker.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                        FUiCtrlTimePicker.h
19  * @brief       This is the header file for the %TimePicker class.
20  *
21  * This header file contains the declarations of the %TimePicker class.
22  */
23 #ifndef _FUI_CTRL_TIME_PICKER_H_
24 #define _FUI_CTRL_TIME_PICKER_H_
25
26 #include <FUiWindow.h>
27 #include <FUiITimeChangeEventListener.h>
28
29 namespace Tizen { namespace Ui { namespace  Controls
30 {
31
32 /**
33  * @class       TimePicker
34  * @brief       This class displays a %TimePicker control on top of the screen.
35  *
36  * @since       2.0
37  *
38  * The %TimePicker class displays a full screen window-based selector that allows the user to select a certain time.
39  *
40  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_datepicker.htm">DatePicker, TimePicker, and DateTimeimePicker</a>.
41  *
42  * The following example demonstrates how to use the %TimePicker class.
43  *
44  * @code
45 // Sample Code for TimePickerSample.h
46 #include <FUi.h>
47
48 class TimePickerSample
49         : public Tizen::Ui::Controls::Form
50         , public Tizen::Ui::ITimeChangeEventListener
51         , public Tizen::Ui::IActionEventListener
52 {
53 public:
54         TimePickerSample(void)
55         : __pTimePicker(null){}
56
57         bool Initialize(void);
58         void ShowTimePicker(bool show);
59         virtual result OnInitializing(void);
60         virtual result OnTerminating(void);
61
62         // IActionEventListener
63         virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
64
65         // ITimeChangeEventListener
66         virtual void OnTimeChanged(const Tizen::Ui::Control& source, int hour, int minute);
67         virtual void OnTimeChangeCanceled(const Tizen::Ui::Control& source);
68
69 private:
70         static const int ID_BUTTON  = 101;
71
72         Tizen::Ui::Controls::TimePicker* __pTimePicker;
73 };
74  *      @endcode
75  *
76  *      @code
77 // Sample Code for TimePickerSample.cpp
78 #include <FGraphics.h>
79
80 #include "TimePickerSample.h"
81
82 using namespace Tizen::Graphics;
83 using namespace Tizen::Ui::Controls;
84
85 bool
86 TimePickerSample::Initialize(void)
87 {
88         Construct(FORM_STYLE_NORMAL);
89         return true;
90 }
91
92 result
93 TimePickerSample::OnInitializing(void)
94 {
95         result r = E_SUCCESS;
96
97         // Createa an instance of Button
98         Button* pButton = new Button();
99         pButton->Construct(Rectangle(50, 50, 300, 200), L"Show TimePicker");
100         pButton->SetActionId(ID_BUTTON);
101         pButton->AddActionEventListener(*this);
102
103         // Adda a Button to the Form
104         AddControl(*pButton);
105
106         // Creates an instanceo of TimePicker
107         __pTimePicker = new TimePicker();
108         __pTimePicker->Construct();
109
110         // Adds an instanceo of ITimeChangeEventListener
111         __pTimePicker->AddTimeChangeEventListener(*this);
112
113         // Show TimePicker after it's owner Form is shown.
114
115         return r;
116 }
117
118 void
119 TimePickerSample::ShowTimePicker(bool show)
120 {
121         // Change to desired show state
122         __pTimePicker->SetShowState(show);
123
124         //Call Show() of the control
125         if (show)
126         {
127                 __pTimePicker->Show();
128         }
129         // Call Invalidate() of the container
130         else
131         {
132                 Invalidate(true);
133         }
134 }
135
136 result
137 TimePickerSample::OnTerminating(void)
138 {
139         result r = E_SUCCESS;
140
141         // Deallocates the time picker
142         delete __pTimePicker;
143
144         return r;
145 }
146
147 // IActionEventListener implementation
148 void
149 TimePickerSample::OnActionPerformed(const Control& source, int actionId)
150 {
151         switch (actionId)
152         {
153         case ID_BUTTON:
154                 ShowTimePicker(true);
155                 break;
156
157         default:
158                 break;
159         }
160 }
161
162
163 // ITimeChangeEventListener implementation
164 void
165 TimePickerSample::OnTimeChanged(const Control& source, int hour, int minute)
166 {
167         // Todo:
168 }
169
170 void
171 TimePickerSample::OnTimeChangeCanceled(const Control& source)
172 {
173         // Todo:
174 }
175  * @endcode
176  */
177 class _OSP_EXPORT_ TimePicker
178         : public Tizen::Ui::Window
179 {
180 public:
181         /**
182          * 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.
183          *
184          * @since       2.0
185          */
186         TimePicker(void);
187
188         /**
189          *      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.
190          *
191          * @since       2.0
192          */
193         virtual ~TimePicker(void);
194
195         /**
196          * Adds a time changed event listener instance.
197          *
198          * @since               2.0
199          *
200          * @param[in]   listener        The listener to be added
201          * @see                 ITimeChangeEventListener::OnTimeChanged()
202          * @see                 ITimeChangeEventListener::OnTimeChangeCanceled()
203          * @see                 RemoveTimeChangeEventListener()
204          */
205         void AddTimeChangeEventListener(Tizen::Ui::ITimeChangeEventListener& listener);
206
207         /**
208          * Removes a listener instance. @n
209          * The removed listener cannot listen to events when they are fired.
210          *
211          * @since               2.0
212          *
213          * @param[in]   listener    The listener to be removed
214          * @see                 AddTimeChangeEventListener()
215          */
216         void RemoveTimeChangeEventListener(Tizen::Ui::ITimeChangeEventListener& listener);
217
218         /**
219          * Initializes this instance of %TimePicker to the current date and time in wall time mode.
220          *
221          * @since               2.0
222          *
223          * @return              An error code
224          * @param[in]   title               The title
225          * @exception   E_SUCCESS           The method is successful.
226          * @exception   E_SYSTEM                    A system error has occurred.
227          */
228         result Construct(const Tizen::Base::String& title = L"");
229
230         /**
231          * Gets the current hour value of the %TimePicker control. @n
232          * The hour value is between @c 0 to @c 23.
233          *
234          * @since               2.0
235          *
236          * @return              The current hour value, @n
237          *                              else @c -1 if an error occurs
238          */
239         int GetHour(void) const;
240
241         /**
242          * Gets the current minute value of the %TimePicker control. @n
243          * The minute value is between @c 0 to @c 59.
244          *
245          * @since               2.0
246          *
247          * @return              The current minute value, @n
248          *                              else @c -1 if an error occurs
249          */
250         int GetMinute(void) const;
251
252         /**
253          * Gets the current time value of the %TimePicker control.
254          *
255          * @since               2.0
256          *
257          * @return              The time value
258          */
259         Tizen::Base::DateTime GetTime(void) const;
260
261         /**
262          * Sets the 12H or 24H hour display type of the %TimePicker control.
263          *
264          * @since               2.0
265          *
266          * @param[in]   enable          Set to @c true to enable the 24 hour notation, @n
267          *                                                      else @c false
268          */
269         void Set24HourNotationEnabled(bool enable);
270
271         /**
272          * Sets the hour value. @n
273          * The hour value should be between @c 0 and @c  23.
274          *
275          * @since               2.0
276          *
277          * @param[in]   hour            The hour value
278          * @exception   E_SUCCESS       The method is successful.
279          * @exception   E_INVALID_ARG   The specified @c hour value is invalid.
280          * @exception   E_SYSTEM                A system error has occurred.
281          */
282         result SetHour(int hour);
283
284         /**
285          * Sets the minute value. @n
286          * The minute value should be between @c 0 and @c 59.
287          *
288          * @since               2.0
289          *
290          * @param[in]   minute          The minute value
291          * @exception   E_SUCCESS       The method is successful.
292          * @exception   E_INVALID_ARG   The specified @c minute value is invalid.
293          * @exception   E_SYSTEM                A system error has occurred.
294          */
295         result SetMinute(int minute);
296
297         /**
298          * Sets the current time value of the %TimePicker control.
299          *
300          * @since               2.0
301          *
302          * @param[in]   time    The time to be set
303          */
304         void SetTime(const Tizen::Base::DateTime& time);
305
306         /**
307          * Sets the time value of the %TimePicker control with the current system time in the Coordinated Universal Time (UTC) mode.
308          *
309          * @since               2.0
310          */
311         void SetCurrentTime(void);
312
313 protected:
314         friend class _TimePickerImpl;
315
316 private:
317         //
318         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
319         //
320         TimePicker(const TimePicker& rhs);
321
322         //
323         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
324         //
325         TimePicker& operator =(const TimePicker& rhs);
326
327 }; // TimePicker
328
329 }}} // Tizen::Ui::Controls
330
331 #endif // _FUI_CTRL_TIME_PICKER_H_