2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrlDatePicker.h
20 * @brief This is the header file for the %DatePicker class.
22 * This header file contains the declarations of the %DatePicker class.
24 #ifndef _FUI_CTRL_DATE_PICKER_H_
25 #define _FUI_CTRL_DATE_PICKER_H_
27 #include <FUiWindow.h>
28 #include <FUiIDateChangeEventListener.h>
30 namespace Tizen { namespace Ui { namespace Controls
35 * @brief This class displays a full screen %DatePicker on top of the screen.
39 * @remarks One cannot change the size and the position of the %DatePicker.
41 * The %DatePicker class displays a full screen window-based selector that allows the user to select a certain date.
43 * For more information on the class features,
44 * see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_datepicker.htm">DatePicker, TimePicker, and DateTimePicker</a>.
46 * The following example demonstrates how to use the %DatePicker class.
49 // Sample code for DatePickerSample.h
52 class DatePickerSample
53 : public Tizen::Ui::Controls::Form
54 , public Tizen::Ui::IDateChangeEventListener
55 , public Tizen::Ui::IActionEventListener
58 DatePickerSample(void)
59 :__pDatePicker(null){}
61 bool Initialize(void);
62 virtual result OnInitializing(void);
63 virtual result OnTerminating(void);
64 void ShowDatePicker(bool show);
66 // IActionEventListener
67 virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
69 // IDateChangeEventListener
70 virtual void OnDateChanged(const Tizen::Ui::Control& source, int year, int month, int day);
71 virtual void OnDateChangeCanceled(const Tizen::Ui::Control& source);
74 static const int ID_BUTTON = 101;
76 Tizen::Ui::Controls::DatePicker* __pDatePicker;
82 // Sample code for DatePickerSample.cpp
83 #include "DatePickerSample.h"
84 #include <FGraphics.h>
86 using namespace Tizen::Graphics;
87 using namespace Tizen::Ui::Controls;
90 DatePickerSample::Initialize(void)
92 Construct(FORM_STYLE_NORMAL);
97 DatePickerSample::OnInitializing(void)
101 // Creates an instance of Button
102 Button* pButton = new Button();
103 pButton->Construct(Rectangle(50, 50, 300, 200), L"Show DatePicker");
104 pButton->SetActionId(ID_BUTTON);
105 pButton->AddActionEventListener(*this);
107 // Adds the button to the form
110 // Creates an instance of DatePicker
111 __pDatePicker = new DatePicker();
112 __pDatePicker->Construct();
114 // Adds an instance of IDateChangeEventListener
115 __pDatePicker->AddDateChangeEventListener(*this);
117 // Shows the date picker after it's owner form is shown.
123 DatePickerSample::ShowDatePicker(bool show)
125 // Changes to desired show state
126 __pDatePicker->SetShowState(show);
128 // Calls Show() of the control
131 __pDatePicker->Show();
133 // Calls Show() of the container
141 DatePickerSample::OnTerminating(void)
143 result r = E_SUCCESS;
145 // Deallocates the date picker
146 __pDatePicker->Destroy();
151 // IActionEventListener implementation
153 DatePickerSample::OnActionPerformed(const Control& source, int actionId)
159 ShowDatePicker(true);
167 // IDateChangeEventListener implementation
169 DatePickerSample::OnDateChanged(const Control& source, int year, int month, int day)
175 DatePickerSample::OnDateChangeCanceled(const Control& source)
181 class _OSP_EXPORT_ DatePicker
182 : public Tizen::Ui::Window
186 * The object is not fully constructed after this constructor is called. @n
187 * For full construction, the DatePicker::Construct() method must be called right after calling this constructor.
194 * This polymorphic destructor should be overridden if required. @n
195 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
199 virtual ~DatePicker(void);
202 * Adds a data change event listener instance. @n
203 * The added listener is called when the date of the %DatePicker is changed either through user manipulation or by calling one of its setters.
207 * @param[in] listener The listener to add
208 * @see IDateChangeEventListener::OnDateChanged()
209 * @see IDateChangeEventListener::OnDateChangeCanceled()
210 * @see RemoveDateChangeEventListener()
212 void AddDateChangeEventListener(Tizen::Ui::IDateChangeEventListener& listener);
215 * Removes a date changed event listener instance. @n
216 * The removed listener cannot listen to events when they are fired.
220 * @param[in] listener The listener to remove
221 * @see IDateChangeEventListener::OnDateChanged()
222 * @see IDateChangeEventListener::OnDateChangeCanceled()
223 * @see AddDateChangeEventListener()
225 void RemoveDateChangeEventListener(Tizen::Ui::IDateChangeEventListener& listener);
228 * Initializes this instance of %DatePicker with the specified parameter.
232 * @return An error code
233 * @param[in] title The title
234 * @exception E_SUCCESS The method is successful.
235 * @exception E_SYSTEM A system error has occurred.
236 * @remarks The optimal size of the control is defined in
237 * <a href="../org.tizen.native.appprogramming/html/guide/ui/control_optimalsize.htm">Optimal Size of UI Controls</a>.
239 result Construct(const Tizen::Base::String& title = L"");
242 * Gets the current date value of the %DatePicker control.
246 * @return A %DateTime instance
248 Tizen::Base::DateTime GetDate(void) const;
251 * Gets the current day value of the %DatePicker control. @n
252 * The day value is between @c 1 to @c 31.
256 * @return The current day value, @n
257 * else @c -1 if an error occurs
259 int GetDay(void) const;
262 * Gets the current month value of the %DatePicker control. @n
263 * The month value is between @c 1 to @c 12.
267 * @return The current month value, @n
268 * else @c -1 if an error occurs
270 int GetMonth(void) const;
273 * Gets the current year value of the %DatePicker control.
274 * The year value is between @c 1 to @c 9999.
278 * @return The current year value, @n
279 * else @c -1 if an error occurs
282 int GetYear(void) const;
285 * Sets the date value of the %DatePicker control.
289 * @param[in] date The date to set
291 void SetDate(const Tizen::Base::DateTime& date);
294 * Sets the date value of the %DatePicker control with the current date.
298 void SetCurrentDate(void);
301 * Sets the year value. @n
302 * The year value should be between @c 1 and @c 9999.
306 * @return An error code
307 * @param[in] year The year value
308 * @exception E_SUCCESS The method is successful.
309 * @exception E_INVALID_ARG The specified year value is invalid.
311 result SetYear(int year);
314 * Sets the month value. @n
315 * The month value should be between @c 1 and @c 12.
319 * @return An error code
320 * @param[in] month The month value
321 * @exception E_SUCCESS The method is successful.
322 * @exception E_INVALID_ARG The specified month value is invalid.
324 result SetMonth(int month);
327 * Sets the day value. @n
328 * The day value should be between @c 1 and @c 31.
332 * @return An error code
333 * @param[in] day The day value
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_INVALID_ARG The specified @c day is invalid.
337 result SetDay(int day);
340 * Sets the valid year range.
341 * The range should be set in between @c 1 and @c 9999.
345 * @return An error code
346 * @param[in] minYear The minimum year for the valid range
347 * @param[in] maxYear The maximum year for the valid range
348 * @exception E_SUCCESS The method is successful.
349 * @exception E_INVALID_ARG The given year range is invalid.
350 * @exception E_SYSTEM A system error has occurred.
352 result SetYearRange(int minYear, int maxYear);
355 * Gets the valid year range.
359 * @return An error code
360 * @param[out] minYear The minimum year for the valid range
361 * @param[out] maxYear The maximum year for the valid range
362 * @exception E_SUCCESS The method is successful.
363 * @exception E_SYSTEM A system error has occurred.
365 result GetYearRange(int& minYear, int& maxYear) const;
368 friend class _DatePickerImpl;
372 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
374 DatePicker(const DatePicker& rhs);
377 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
379 DatePicker& operator =(const DatePicker& rhs);
383 }}} // Tizen::Ui::Controls
385 #endif // _FUI_CTRL_DATE_PICKER_H_