2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrl_DateTimeDisplayBox.cpp
19 * @brief This is the implementation file for the _DateTimeDisplayBox class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpCanvas.h>
25 #include <FGrp_TextCommon.h>
26 #include <FGrp_TextTextObject.h>
27 #include <FGrp_TextTextSimple.h>
28 #include <FGrp_CanvasImpl.h>
29 #include <FGrp_BitmapImpl.h>
30 #include "FUi_ResourceManager.h"
31 #include "FUiAnim_VisualElement.h"
32 #include "FUiCtrl_DateTimeDisplayBox.h"
33 #include "FUiCtrl_DateTimeDefine.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
39 namespace Tizen { namespace Ui { namespace Controls
42 _DateTimeDisplayBox::_DateTimeDisplayBox(const Rectangle& bounds, int boxId)
43 : __windowBounds(bounds)
49 , __pBackgroundEffectBitmap(null)
50 , __pBackgroundPressedEffectBitmap(null)
51 , __pBackgroundDisabledEffectBitmap(null)
53 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
55 __pBackgroundNormalBitmap[i] = null;
58 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
60 __backgroundColor[i] = Color();
63 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_NORMAL, __textColor[DATETIME_STATUS_NORMAL]);
64 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_HIGHLIGHTED, __textColor[DATETIME_STATUS_FOCUSED]);
65 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_PRESSED, __textColor[DATETIME_STATUS_SELECTED]);
66 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_DISABLED, __textColor[DATETIME_STATUS_DISABLED]);
69 _DateTimeDisplayBox::~_DateTimeDisplayBox(void)
71 if (__pTextObject != null)
73 __pTextObject->RemoveAll();
78 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
80 delete __pBackgroundNormalBitmap[i];
81 __pBackgroundNormalBitmap[i] = null;
86 _DateTimeDisplayBox::GetDisplayBoxBounds(void) const
88 return __windowBounds;
92 _DateTimeDisplayBox::GetDisplayBoxId(void) const
98 _DateTimeDisplayBox::SetText(const String& text)
100 result r = E_SUCCESS;
101 TextSimple* pSimpleText = null;
103 TextObject * pTextObject = new (std::nothrow) TextObject;
104 SysTryReturn(NID_UI_CTRL, (pTextObject != null), false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
108 wchar_t* pString = const_cast <wchar_t*>(__text.GetPointer());
110 r = pTextObject->Construct();
111 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
113 pSimpleText = new (std::nothrow)TextSimple(pString, __text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
114 SysTryCatch(NID_UI_CTRL, (pSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
116 r = pTextObject->AppendElement(*pSimpleText);
117 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
119 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
120 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
122 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
123 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
125 r = pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
126 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
128 r = pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
129 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
131 if (__pTextObject != null)
133 r = __pTextObject->RemoveAll();
134 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
136 delete __pTextObject;
137 __pTextObject = null;
139 __pTextObject = pTextObject;
144 pTextObject->RemoveAll();
153 _DateTimeDisplayBox::GetText(void) const
159 _DateTimeDisplayBox::DrawDisplayBox(Canvas& canvas, DateTimePickerStatus status)
161 if ((__focusable == false) && (status == DATETIME_STATUS_FOCUSED))
163 status = DATETIME_STATUS_NORMAL;
166 DrawBackground(canvas, status);
167 DrawText(canvas, status);
173 _DateTimeDisplayBox::DrawBackground(Canvas& canvas, DateTimePickerStatus status)
175 result r = E_SUCCESS;
177 if (__pBackgroundNormalBitmap[status] == null)
182 if (__pBackgroundNormalBitmap[status]->IsNinePatchedBitmap() == true)
184 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundNormalBitmap[status]);
185 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
189 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundNormalBitmap[status]);
190 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
193 if (status == DATETIME_STATUS_FOCUSED && __pBackgroundPressedEffectBitmap != null )
195 if (__pBackgroundEffectBitmap->IsNinePatchedBitmap() == true)
197 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundPressedEffectBitmap);
198 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
202 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundPressedEffectBitmap);
203 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
206 else if (status == DATETIME_STATUS_DISABLED && __pBackgroundDisabledEffectBitmap != null)
208 if (__pBackgroundDisabledEffectBitmap->IsNinePatchedBitmap() == true)
210 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundDisabledEffectBitmap);
211 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
215 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundDisabledEffectBitmap);
216 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
219 else if (__pBackgroundEffectBitmap != null)
221 if (__pBackgroundEffectBitmap->IsNinePatchedBitmap() == true)
223 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundEffectBitmap);
224 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
228 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundEffectBitmap);
229 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
237 _DateTimeDisplayBox::DrawText(Canvas& canvas, DateTimePickerStatus status)
239 SysTryReturnVoidResult(NID_UI_CTRL, (__pTextObject != null), E_SYSTEM,
240 "[E_SYSTEM] A system error has occurred. The instance of TextObject is null.");
242 result r = E_SUCCESS;
244 r = __pTextObject->SetForegroundColor(__textColor[status], 0, __pTextObject->GetTextLength());
245 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
247 r = __pTextObject->SetBounds(__windowBounds);
248 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
250 r = __pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
251 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
257 _DateTimeDisplayBox::SetFocusable(bool focusable)
259 __focusable = focusable;
265 _DateTimeDisplayBox::SetBackgroundBitmap(Bitmap* pNormalBitmap, Bitmap* pEffectBitmap, Bitmap* pPressedEffectBitmap, Bitmap* pDisabledEffectBitmap)
267 result r = E_SUCCESS;
269 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_NORMAL, __backgroundColor[DATETIME_STATUS_NORMAL]);
270 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_PRESSED, __backgroundColor[DATETIME_STATUS_SELECTED]);
271 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED, __backgroundColor[DATETIME_STATUS_FOCUSED]);
272 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_DISABLED, __backgroundColor[DATETIME_STATUS_DISABLED]);
274 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_NORMAL, __textColor[DATETIME_STATUS_NORMAL]);
275 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_PRESSED, __textColor[DATETIME_STATUS_SELECTED]);
276 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_HIGHLIGHTED, __textColor[DATETIME_STATUS_FOCUSED]);
277 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_DISABLED, __textColor[DATETIME_STATUS_DISABLED]);
279 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
281 __pBackgroundNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), __backgroundColor[i]);
283 SysTryCatch(NID_UI_CTRL, (__pBackgroundNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
286 __pBackgroundEffectBitmap = pEffectBitmap;
287 __pBackgroundPressedEffectBitmap = pPressedEffectBitmap;
288 __pBackgroundDisabledEffectBitmap = pDisabledEffectBitmap;
293 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
295 delete __pBackgroundNormalBitmap[i];
296 __pBackgroundNormalBitmap[i] = null;
303 _DateTimeDisplayBox::UpdateDisplayBoxBounds(Rectangle& bounds)
305 __windowBounds = bounds;
311 _DateTimeDisplayBox::SetFont(Font* pFont)
318 }}} // Tizen::Ui::Controls