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_InputPadPresenter.cpp
20 * @brief This is the implementation file for the _InputPadPresenter class.
23 #include <FGrp_CanvasImpl.h>
24 #include <FGrp_TextTextSimple.h>
25 #include <FGrp_BitmapImpl.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiCtrl_InputPad.h"
30 #include "FUiCtrl_InputPadPresenter.h"
31 #include "FUiCtrl_DateTimeUtils.h"
32 #include "FUi_CoordinateSystemUtils.h"
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Graphics::_Text;
37 using namespace Tizen::Base;
39 namespace Tizen { namespace Ui { namespace Controls
42 _InputPadPresenter::_InputPadPresenter(_InputPad* pInputPad)
43 : __pInputPad(pInputPad)
44 , __pInputPadEventListener(null)
46 , __pKeypadBackgroundBitmap(null)
47 , __inputPadStyle(INPUTPAD_STYLE_NORMAL)
49 , __buttonHeight(0.0f)
55 , __isLayoutChanged(false)
57 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
59 __pKeypadButtonNormalBitmap[i] = null;
60 __pKeypadButtonEffectBitmap[i] = null;
64 _InputPadPresenter::~_InputPadPresenter(void)
69 delete __pKeypadBackgroundBitmap;
70 __pKeypadBackgroundBitmap = null;
72 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
74 delete __pKeypadButtonNormalBitmap[i];
75 __pKeypadButtonNormalBitmap[i] = null;
77 delete __pKeypadButtonEffectBitmap[i];
78 __pKeypadButtonEffectBitmap[i] = null;
83 _InputPadPresenter::Construct(const FloatRectangle& bounds)
87 r = LoadProperties(__pInputPad->GetOrientation());
88 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
89 "A system error has occurred. Failed to load the properties for input pad.");
92 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
93 "A system error has occurred. Failed to load the resource for input pad.");
95 r = InitializeTextObjects();
96 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
97 "A system error has occurred. Failed to initialize the text objects for input pad.");
103 _InputPadPresenter::LoadProperties(_ControlOrientation orientation)
105 float marginTop = 0.0f;
107 GET_SHAPE_CONFIG(INPUTPAD::BUTTON_WIDTH, orientation, __buttonWidth);
108 GET_SHAPE_CONFIG(INPUTPAD::BUTTON_HEIGHT, orientation, __buttonHeight);
109 GET_SHAPE_CONFIG(INPUTPAD::BUTTON_HORIZONTAL_MARGIN, orientation, __marginX);
110 GET_SHAPE_CONFIG(INPUTPAD::BUTTON_VERTICAL_MARGIN, orientation, __marginY);
111 GET_SHAPE_CONFIG(INPUTPAD::TOP_MARGIN, orientation, marginTop);
113 __startX = (__pInputPad->GetBounds().width - (__buttonWidth + __marginX) * INPUTPAD_BUTTON_COLUMN_MAX + __marginX) / 2;
114 __startY = marginTop;
120 _InputPadPresenter::LoadResource(void)
122 result r = E_SUCCESS;
124 Color buttonColor[DATETIME_STATUS_MAX];
125 Color replacementColor = Color::GetColor(COLOR_ID_MAGENTA);
127 Bitmap* pButtonBgNormalBitmap[DATETIME_STATUS_MAX];
128 bool isCustomBitmap[DATETIME_STATUS_MAX];
130 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
132 buttonColor[i] = Color();
133 pButtonBgNormalBitmap[i] = null;
134 isCustomBitmap[i] = false;
137 GET_COLOR_CONFIG(INPUTPAD::BUTTON_BG_NORMAL, buttonColor[DATETIME_STATUS_NORMAL]);
138 GET_COLOR_CONFIG(INPUTPAD::BUTTON_BG_PRESSED, buttonColor[DATETIME_STATUS_SELECTED]);
139 GET_COLOR_CONFIG(INPUTPAD::BUTTON_BG_HIGHLIGHTED, buttonColor[DATETIME_STATUS_HIGHLIGHTED]);
140 GET_COLOR_CONFIG(INPUTPAD::BUTTON_BG_DISABLED, buttonColor[DATETIME_STATUS_DISABLED]);
142 r = GET_BITMAP_CONFIG_N(INPUTPAD::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pKeypadBackgroundBitmap);
143 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
145 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormalBitmap[DATETIME_STATUS_NORMAL]);
146 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
148 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormalBitmap[DATETIME_STATUS_SELECTED]);
149 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
151 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormalBitmap[DATETIME_STATUS_HIGHLIGHTED]);
152 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
154 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pButtonBgNormalBitmap[DATETIME_STATUS_DISABLED]);
155 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
157 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_NORMAL);
158 isCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_PRESSED);
159 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_HIGHLIGHTED);
160 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_DISABLED);
162 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
164 if (isCustomBitmap[i])
166 __pKeypadButtonNormalBitmap[i] = pButtonBgNormalBitmap[i];
170 __pKeypadButtonNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBgNormalBitmap[i], replacementColor, buttonColor[i]);
171 SysTryCatch(NID_UI_CTRL, (__pKeypadButtonNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
175 if (!isCustomBitmap[DATETIME_STATUS_NORMAL])
177 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pKeypadButtonEffectBitmap[DATETIME_STATUS_NORMAL]);
178 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
181 if (!isCustomBitmap[DATETIME_STATUS_SELECTED])
183 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pKeypadButtonEffectBitmap[DATETIME_STATUS_SELECTED]);
184 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
187 if (!isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED])
189 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, __pKeypadButtonEffectBitmap[DATETIME_STATUS_HIGHLIGHTED]);
190 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
193 if (!isCustomBitmap[DATETIME_STATUS_DISABLED])
195 r = GET_BITMAP_CONFIG_N(INPUTPAD::BUTTON_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pKeypadButtonEffectBitmap[DATETIME_STATUS_DISABLED]);
196 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
199 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
201 delete pButtonBgNormalBitmap[i];
207 delete __pKeypadBackgroundBitmap;
208 __pKeypadBackgroundBitmap = null;
210 for (int i = 0; i < DATETIME_STATUS_MAX; i++)
212 delete pButtonBgNormalBitmap[i];
214 delete __pKeypadButtonNormalBitmap[i];
215 __pKeypadButtonNormalBitmap[i] = null;
217 delete __pKeypadButtonEffectBitmap[i];
218 __pKeypadButtonEffectBitmap[i] = null;
225 _InputPadPresenter::InitializeTextObjects(void)
227 result r = E_SUCCESS;
230 r = __textObject.Construct();
231 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
233 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
234 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
235 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
237 r = __guideTextObject.Construct();
238 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
240 __guideTextObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_TOP);
241 __guideTextObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
242 __guideTextObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
248 _InputPadPresenter::SetInputPadEventListener(const _IInputPadEventListener& listener)
250 __pInputPadEventListener = const_cast <_IInputPadEventListener*>(&listener);
256 _InputPadPresenter::SetInputPadStyle(const _InputPadStyle style)
258 if (style != __inputPadStyle || __isLayoutChanged == true)
260 __isLayoutChanged = false;
262 __inputPadStyle = style;
270 _InputPadPresenter::GetInputPadStyle(void) const
272 return __inputPadStyle;
276 _InputPadPresenter::GetButtonBounds(int index) const
278 FloatRectangle buttonBounds;
280 buttonBounds.x = __startX + (index % INPUTPAD_BUTTON_COLUMN_MAX) * (__buttonWidth + __marginX);
281 buttonBounds.y = __startY + (index / INPUTPAD_BUTTON_COLUMN_MAX) * (__buttonHeight + __marginY);
282 buttonBounds.width = __buttonWidth;
283 buttonBounds.height = __buttonHeight;
289 _InputPadPresenter::Draw(void)
291 result r = E_SUCCESS;
292 FloatRectangle bgBounds;
294 Canvas* pCanvas = __pInputPad->GetCanvasN();
296 SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), r, "Propagating.");
298 bgBounds = pCanvas->GetBoundsF();
300 if(__pKeypadBackgroundBitmap != null)
302 r = pCanvas->DrawNinePatchedBitmap(bgBounds, *__pKeypadBackgroundBitmap);
303 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
306 r = DrawAllButtons(*pCanvas);
321 _InputPadPresenter::EnableLayoutChangedFlag(void)
323 __isLayoutChanged = true;
329 _InputPadPresenter::SetFont(Font* pFont)
337 __pFont = _FontImpl::CloneN(*pFont);
338 SysTryReturnVoidResult(NID_UI_CTRL, __pFont != null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
344 _InputPadPresenter::DrawAllButtons(Canvas& canvas)
346 result r = E_SUCCESS;
348 for (int i = 0; i < INPUTPAD_BUTTON_MAX; i++)
350 r |= DrawButton(canvas, i);
362 _InputPadPresenter::DrawButton(Canvas& canvas, int index)
364 result r = E_SUCCESS;
366 DateTimePickerStatus status;
367 bool isCustomBitmap[DATETIME_STATUS_MAX];
369 FloatRectangle buttonBounds = GetButtonBounds(index);
370 int returnValue = GetReturnValue(index);
372 // Do not Draw Extra Buttons in case of Numeric Keypad
378 if (__pInputPad->IsEnabled() == false)
380 status = DATETIME_STATUS_DISABLED;
381 GET_COLOR_CONFIG(INPUTPAD::TEXT_DISABLED, textColor);
383 else if (__pressedIndex == index)
385 status = DATETIME_STATUS_SELECTED;
386 GET_COLOR_CONFIG(INPUTPAD::TEXT_PRESSED, textColor);
390 status = DATETIME_STATUS_NORMAL;
391 GET_COLOR_CONFIG(INPUTPAD::TEXT_NORMAL, textColor);
394 isCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_NORMAL);
395 isCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_PRESSED);
396 isCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_HIGHLIGHTED);
397 isCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(INPUTPAD::BUTTON_BG_DISABLED);
399 if (isCustomBitmap[status] == false && __pKeypadButtonEffectBitmap[status] != null)
401 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pKeypadButtonEffectBitmap[status]))
403 r = canvas.DrawNinePatchedBitmap(buttonBounds, *__pKeypadButtonEffectBitmap[status]);
404 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
408 r = canvas.DrawBitmap(buttonBounds, *__pKeypadButtonEffectBitmap[status]);
409 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
413 if (__pKeypadButtonNormalBitmap[status] != null)
415 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pKeypadButtonNormalBitmap[status]))
417 r = canvas.DrawNinePatchedBitmap(buttonBounds, *__pKeypadButtonNormalBitmap[status]);
418 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
422 r = canvas.DrawBitmap(buttonBounds, *__pKeypadButtonNormalBitmap[status]);
423 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
428 if (__inputPadStyle == INPUTPAD_STYLE_ALPHA)
430 // Calculate text bounds
431 int textCorrectionY = 0;
432 GET_SHAPE_CONFIG(INPUTPAD::TEXT_CORRECTION_Y, __pInputPad->GetOrientation(), textCorrectionY);
434 buttonBounds.y += textCorrectionY;
436 _DateTimeUtils dateTimeUtils;
437 String text = dateTimeUtils.GetMonthString(returnValue);
439 r = __textObject.RemoveAll();
440 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
442 TextSimple* pSimpleText = new (std::nothrow)TextSimple((wchar_t*)text.GetPointer(), text.GetLength(),
443 TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
444 SysTryReturnResult(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
446 r = __textObject.AppendElement(*pSimpleText);
447 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
449 r = __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
450 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
453 GET_SHAPE_CONFIG(INPUTPAD::ALPHA_FONT_SIZE, __pInputPad->GetOrientation(), fontSize);
455 r = _FontImpl::GetInstance(*__pFont)->SetStyle(FONT_STYLE_BOLD);
456 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
458 r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
459 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
461 r = __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
462 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
464 r = __textObject.SetBounds(buttonBounds);
465 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
467 r = __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
468 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
471 int guideTextCorrectionX = 0;
472 GET_SHAPE_CONFIG(INPUTPAD::GUIDE_CORRECTION_X, __pInputPad->GetOrientation(), guideTextCorrectionX);
474 buttonBounds.width -= guideTextCorrectionX;
476 Color guideTextColor;
477 GET_COLOR_CONFIG(INPUTPAD::GUIDE_TEXT_NORMAL, guideTextColor);
479 String guideText = Integer::ToString(returnValue);
481 r = __guideTextObject.RemoveAll();
482 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
484 TextSimple* pSimpleTextForGuideText = new (std::nothrow)TextSimple((wchar_t*)guideText.GetPointer(),
485 guideText.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
486 SysTryReturnResult(NID_UI_CTRL, (pSimpleTextForGuideText != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
488 r = __guideTextObject.AppendElement(*pSimpleTextForGuideText);
489 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
491 r = __guideTextObject.SetForegroundColor(guideTextColor, 0, __guideTextObject.GetTextLength());
492 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
494 GET_SHAPE_CONFIG(INPUTPAD::GUIDE_FONT_SIZE, __pInputPad->GetOrientation(), fontSize);
496 r = _FontImpl::GetInstance(*__pFont)->SetStyle(FONT_STYLE_PLAIN);
497 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
499 r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
500 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
502 r = __guideTextObject.SetFont(__pFont, 0, __guideTextObject.GetTextLength());
503 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
505 r = __guideTextObject.SetBounds(buttonBounds);
506 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
508 r = __guideTextObject.Draw(*_CanvasImpl::GetInstance(canvas));
509 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
511 else if (returnValue >= 0)
513 String text = Integer::ToString(returnValue);
515 r = __textObject.RemoveAll();
516 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
518 TextSimple* pSimpleText = new (std::nothrow)TextSimple((wchar_t*)text.GetPointer(),
519 text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
520 SysTryReturnResult(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
522 r = __textObject.AppendElement(*pSimpleText);
523 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
524 result r = E_SUCCESS;
526 r = __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
527 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
531 GET_SHAPE_CONFIG(INPUTPAD::NUMERIC_FONT_SIZE, __pInputPad->GetOrientation(), fontSize);
533 r = _FontImpl::GetInstance(*__pFont)->SetStyle(FONT_STYLE_BOLD);
534 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
536 r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
537 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
539 r = __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
540 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
542 r = __textObject.SetBounds(buttonBounds);
543 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
545 r = __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
546 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
553 _InputPadPresenter::RefreshButton(int index)
555 Canvas* pCanvas = __pInputPad->GetCanvasN();
556 SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), GetLastResult(), "Propagating.");
558 result r = DrawButton(*pCanvas, index);
559 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to draw the keypad button.");
564 if (__pInputPad->GetVisualElement() != null)
566 __pInputPad->GetVisualElement()->SetFlushNeeded();
579 _InputPadPresenter::GetIndexFromTouchedPosition(const FloatPoint& point) const
581 float correctionValue = 0.0f;
583 GET_FIXED_VALUE_CONFIG(INPUTPAD::BUTTON_TOUCH_CORRECTION_Y, __pInputPad->GetOrientation(), correctionValue);
585 if (point.x < (__startX - correctionValue) || point.y < (__startY - correctionValue))
590 int row = _CoordinateSystemUtils::ConvertToInteger((point.y - __startY + __marginY + correctionValue) / (__buttonHeight + __marginY));
591 int col = _CoordinateSystemUtils::ConvertToInteger((point.x - __startX + __marginX) / (__buttonWidth + __marginX));
592 if (row >= INPUTPAD_BUTTON_ROW_MAX || col >= INPUTPAD_BUTTON_COLUMN_MAX)
597 return row * INPUTPAD_BUTTON_COLUMN_MAX + col;
601 _InputPadPresenter::GetReturnValue(int index) const
603 if (__inputPadStyle == INPUTPAD_STYLE_NORMAL)
605 if (index >= INPUTPAD_NUMBER_1 && index <= INPUTPAD_NUMBER_9)
609 else if (index == INPUTPAD_NUMBER_0)
614 else if (__inputPadStyle == INPUTPAD_STYLE_ALPHA)
623 _InputPadPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
625 if (&source != __pInputPad)
630 __pressedIndex = GetIndexFromTouchedPosition(touchinfo.GetCurrentPosition());
631 if (__pressedIndex >= 0)
633 RefreshButton(__pressedIndex);
641 _InputPadPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
643 if (&source != __pInputPad)
648 SysTryReturn(NID_UI_CTRL, __pressedIndex >= 0, true, E_SUCCESS, "Touch pressed Index is invalid, ignoring touch release");
650 int refreshIndex = __pressedIndex;
651 int currentReleasedIndex = GetIndexFromTouchedPosition(touchinfo.GetCurrentPosition());
653 if (currentReleasedIndex >= 0)
655 if (__pInputPadEventListener != null)
657 __pInputPadEventListener->OnInputPadValueChanged(source, GetReturnValue(currentReleasedIndex));
662 if (refreshIndex >= 0)
664 RefreshButton(refreshIndex);
671 _InputPadPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
673 return OnTouchReleased(source, touchinfo);
676 }}} // Tizen::Ui::Controls