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 FUiCtrl_DateTimeDisplayBox.cpp
20 * @brief This is the implementation file for the _DateTimeDisplayBox class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrpCanvas.h>
26 #include <FGrp_TextCommon.h>
27 #include <FGrp_TextTextObject.h>
28 #include <FGrp_TextTextSimple.h>
29 #include <FGrp_CanvasImpl.h>
30 #include <FGrp_BitmapImpl.h>
31 #include "FUi_ResourceManager.h"
32 #include "FUiAnim_VisualElement.h"
33 #include "FUiCtrl_DateTimeDisplayBox.h"
34 #include "FUiCtrl_DateTimeDefine.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Graphics::_Text;
40 namespace Tizen { namespace Ui { namespace Controls
43 _DateTimeDisplayBox::_DateTimeDisplayBox(const FloatRectangle& bounds, int boxId)
44 : __windowBounds(bounds)
51 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
53 __pBackgroundNormalBitmap[i] = null;
54 __pBackgroundEffectBitmap[i] = null;
57 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_NORMAL, __textColor[DATETIME_STATUS_NORMAL]);
58 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_HIGHLIGHTED, __textColor[DATETIME_STATUS_HIGHLIGHTED]);
59 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_PRESSED, __textColor[DATETIME_STATUS_SELECTED]);
60 GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_DISABLED, __textColor[DATETIME_STATUS_DISABLED]);
63 _DateTimeDisplayBox::~_DateTimeDisplayBox(void)
65 if (__pTextObject != null)
67 __pTextObject->RemoveAll();
74 _DateTimeDisplayBox::GetDisplayBoxBounds(void) const
76 return __windowBounds;
80 _DateTimeDisplayBox::GetDisplayBoxId(void) const
86 _DateTimeDisplayBox::SetText(const String& text)
89 TextSimple* pSimpleText = null;
91 TextObject* pTextObject = new (std::nothrow) TextObject;
92 SysTryReturn(NID_UI_CTRL, (pTextObject != null), false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
96 wchar_t* pString = const_cast <wchar_t*>(__text.GetPointer());
98 r = pTextObject->Construct();
99 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
101 pSimpleText = new (std::nothrow)TextSimple(pString, __text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
102 SysTryCatch(NID_UI_CTRL, (pSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
104 pSimpleText->SetTextShadowEnabled(true);
105 pSimpleText->SetTextShadowOffset(FloatPoint(0.0f, -1.0f));
107 r = pTextObject->AppendElement(*pSimpleText);
108 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
110 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
111 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
113 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
114 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
116 r = pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
117 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
119 r = pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
120 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
122 if (__pTextObject != null)
124 r = __pTextObject->RemoveAll();
125 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
127 delete __pTextObject;
128 __pTextObject = null;
130 __pTextObject = pTextObject;
135 pTextObject->RemoveAll();
144 _DateTimeDisplayBox::GetText(void) const
150 _DateTimeDisplayBox::DrawDisplayBox(Canvas& canvas, DateTimePickerStatus status)
152 if ((!__focusable) && (status == DATETIME_STATUS_HIGHLIGHTED))
154 status = DATETIME_STATUS_NORMAL;
157 DrawBackground(canvas, status);
158 DrawText(canvas, status);
164 _DateTimeDisplayBox::DrawBackground(Canvas& canvas, DateTimePickerStatus status)
166 result r = E_SUCCESS;
167 bool isCustomBitmap[DATETIME_STATUS_MAX];
169 if (__pBackgroundNormalBitmap[status] == null)
174 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
176 isCustomBitmap[i] = false;
179 if (__pBackgroundNormalBitmap[status] != null)
181 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBackgroundNormalBitmap[status]))
183 r = canvas.DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, __windowBounds.width, __windowBounds.height), *__pBackgroundNormalBitmap[status]);
184 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
188 FloatPoint position(0.0f, 0.0f);
189 position.x = (__windowBounds.width - __pBackgroundNormalBitmap[status]->GetWidthF()) / 2;
190 position.y = (__windowBounds.height - __pBackgroundNormalBitmap[status]->GetHeightF()) / 2;
191 r = canvas.DrawBitmap(position, *__pBackgroundNormalBitmap[status]);
192 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
196 if (__boxId == DATETIME_ID_AMPM)
198 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_NORMAL);
199 isCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_PRESSED);
200 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED);
201 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_DISABLED);
205 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_NORMAL);
206 isCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_PRESSED);
207 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED);
208 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_DISABLED);
211 if (!isCustomBitmap[status] && __pBackgroundEffectBitmap[status] != null)
213 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBackgroundEffectBitmap[status]))
215 r = canvas.DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, __windowBounds.width, __windowBounds.height), *__pBackgroundEffectBitmap[status]);
216 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
220 r = canvas.DrawBitmap(FloatPoint(0.0f, 0.0f), *__pBackgroundEffectBitmap[status]);
221 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
229 _DateTimeDisplayBox::DrawText(Canvas& canvas, DateTimePickerStatus status)
231 SysTryReturnVoidResult(NID_UI_CTRL, (__pTextObject != null), E_SYSTEM,
232 "[E_SYSTEM] A system error has occurred. The instance of TextObject is null.");
234 result r = E_SUCCESS;
236 r = __pTextObject->SetForegroundColor(__textColor[status], 0, __pTextObject->GetTextLength());
237 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
239 r = __pTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, __windowBounds.width, __windowBounds.height));
240 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
242 r = __pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
243 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
249 _DateTimeDisplayBox::SetFocusable(bool focusable)
251 __focusable = focusable;
257 _DateTimeDisplayBox::SetBackgroundBitmap(Bitmap **pBackgroundNormalBitmap, Bitmap **pBackgroundEffectBitmap)
259 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_NORMAL, __textColor[DATETIME_STATUS_NORMAL]);
260 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_PRESSED, __textColor[DATETIME_STATUS_SELECTED]);
261 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_HIGHLIGHTED, __textColor[DATETIME_STATUS_HIGHLIGHTED]);
262 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_DISABLED, __textColor[DATETIME_STATUS_DISABLED]);
264 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
266 __pBackgroundNormalBitmap[i] = pBackgroundNormalBitmap[i];
267 __pBackgroundEffectBitmap[i] = pBackgroundEffectBitmap[i];
274 _DateTimeDisplayBox::UpdateDisplayBoxBounds(FloatRectangle& bounds)
276 __windowBounds = bounds;
282 _DateTimeDisplayBox::SetFont(Font* pFont)
289 }}} // Tizen::Ui::Controls