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