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_PRESSED]);
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 r = pTextObject->AppendElement(*pSimpleText);
105 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
107 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
108 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
110 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
111 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
113 r = pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
114 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
116 r = pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
117 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
119 if (__pTextObject != null)
121 r = __pTextObject->RemoveAll();
122 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
124 delete __pTextObject;
125 __pTextObject = null;
127 __pTextObject = pTextObject;
132 pTextObject->RemoveAll();
141 _DateTimeDisplayBox::GetText(void) const
147 _DateTimeDisplayBox::DrawDisplayBox(Canvas& canvas, DateTimePickerStatus status)
149 if ((__focusable == false) && (status == DATETIME_STATUS_HIGHLIGHTED))
151 status = DATETIME_STATUS_NORMAL;
154 DrawBackground(canvas, status);
155 DrawText(canvas, status);
161 _DateTimeDisplayBox::DrawBackground(Canvas& canvas, DateTimePickerStatus status)
163 result r = E_SUCCESS;
164 bool isCustomBitmap[DATETIME_STATUS_MAX];
166 if (__pBackgroundNormalBitmap[status] == null)
171 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
173 isCustomBitmap[i] = false;
176 if (__pBackgroundNormalBitmap[status] != null)
178 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBackgroundNormalBitmap[status]))
180 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundNormalBitmap[status]);
181 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
185 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundNormalBitmap[status]);
186 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
190 if (__boxId == DATETIME_ID_AMPM)
192 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_NORMAL);
193 isCustomBitmap[DATETIME_STATUS_PRESSED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_PRESSED);
194 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED);
195 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_DISABLED);
199 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_NORMAL);
200 isCustomBitmap[DATETIME_STATUS_PRESSED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_PRESSED);
201 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED);
202 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_DISABLED);
205 if (isCustomBitmap[status] == false && __pBackgroundEffectBitmap[status] != null)
207 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBackgroundEffectBitmap[status]))
209 r = canvas.DrawNinePatchedBitmap(__windowBounds, *__pBackgroundEffectBitmap[status]);
210 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
214 r = canvas.DrawBitmap(__windowBounds, *__pBackgroundEffectBitmap[status]);
215 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
223 _DateTimeDisplayBox::DrawText(Canvas& canvas, DateTimePickerStatus status)
225 SysTryReturnVoidResult(NID_UI_CTRL, (__pTextObject != null), E_SYSTEM,
226 "[E_SYSTEM] A system error has occurred. The instance of TextObject is null.");
228 result r = E_SUCCESS;
230 r = __pTextObject->SetForegroundColor(__textColor[status], 0, __pTextObject->GetTextLength());
231 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
233 r = __pTextObject->SetBounds(__windowBounds);
234 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
236 r = __pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
237 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
243 _DateTimeDisplayBox::SetFocusable(bool focusable)
245 __focusable = focusable;
251 _DateTimeDisplayBox::SetBackgroundBitmap(Bitmap **pBackgroundNormalBitmap, Bitmap **pBackgroundEffectBitmap)
253 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_NORMAL, __textColor[DATETIME_STATUS_NORMAL]);
254 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_PRESSED, __textColor[DATETIME_STATUS_PRESSED]);
255 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_HIGHLIGHTED, __textColor[DATETIME_STATUS_HIGHLIGHTED]);
256 GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_TEXT_DISABLED, __textColor[DATETIME_STATUS_DISABLED]);
258 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
260 __pBackgroundNormalBitmap[i] = pBackgroundNormalBitmap[i];
261 __pBackgroundEffectBitmap[i] = pBackgroundEffectBitmap[i];
268 _DateTimeDisplayBox::UpdateDisplayBoxBounds(FloatRectangle& bounds)
270 __windowBounds = bounds;
276 _DateTimeDisplayBox::SetFont(Font* pFont)
283 }}} // Tizen::Ui::Controls