Fix for N_SE-31349
authorSyed Khaja Moinuddin <moinuddin.s@samsung.com>
Wed, 3 Apr 2013 03:12:56 +0000 (12:12 +0900)
committerSyed Khaja Moinuddin <moinuddin.s@samsung.com>
Wed, 3 Apr 2013 09:11:02 +0000 (18:11 +0900)
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
Change-Id: I306f70b84dbbbc51d717eb8b22b9b86858d4f60a
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
src/ui/controls/FUiCtrl_EditDatePresenter.cpp
src/ui/controls/FUiCtrl_EditTimePresenter.cpp
src/ui/inc/FUiCtrl_EditDatePresenter.h
src/ui/inc/FUiCtrl_EditTimePresenter.h

index 590f05c..5b534d2 100644 (file)
@@ -65,6 +65,7 @@ _EditDatePresenter::_EditDatePresenter(void)
        , __pContentProvider(null)
        , __isAnimating(false)
        , __isEditDateInitialized(false)
+       , __elementWidth(0.0f)
 {
 }
 
@@ -123,6 +124,7 @@ _EditDatePresenter::Initialize(void)
        GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
        GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
        GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
+       GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), __elementWidth);
 
        if (__pEditDate->GetBoundsF().height > editDateHeight)
        {
@@ -160,16 +162,13 @@ _EditDatePresenter::Initialize(void)
                __yearBounds.height = editDateHeight;
        }
 
-       float elementWidth = 0.0f;
-       GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), elementWidth);
-
-       __dayBounds.width = elementWidth;
-       __monthBounds.width = elementWidth;
-       __yearBounds.width = elementWidth;
+       __dayBounds.width = GetTextWidth(DATETIME_ID_DAY);
+       __monthBounds.width = GetTextWidth(DATETIME_ID_MONTH);
+       __yearBounds.width = GetTextWidth(DATETIME_ID_YEAR);
 
-       __dayBounds.x = 0.0f;
-       __monthBounds.x = 0.0f;
-       __yearBounds.x = 0.0f;
+       __dayBounds.x = (__elementWidth - __dayBounds.width) / 2.0f;
+       __monthBounds.x = (__elementWidth - __monthBounds.width) / 2.0f;
+       __yearBounds.x = (__elementWidth - __yearBounds.width) / 2.0f;
 
        __dayBounds.y = bounds.y;
        __monthBounds.y = bounds.y;
@@ -239,6 +238,51 @@ _EditDatePresenter::InitializeTextObject(void)
        return r;
 }
 
+float
+_EditDatePresenter::GetTextWidth(_DateTimeId boxId) const
+{
+       result r = E_SUCCESS;
+       FloatDimension dim;
+       TextObject dateObject;
+
+       String monthString;
+       String yearString;
+       String dayString;
+
+       _DateTimeUtils dateTimeUtils;
+       monthString = dateTimeUtils.GetMonthString(GetMonth());
+       yearString.Format(10, L"%04d", GetYear());
+       dayString.Format(10, L"%02d", GetDay());
+
+       r = dateObject.Construct();
+       SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       TextSimple* pSimpleText = null;
+
+       if (boxId == DATETIME_ID_DAY)
+       {
+               pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(dayString.GetPointer())), dayString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       }
+       else if (boxId == DATETIME_ID_MONTH)
+       {
+               pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(monthString.GetPointer())), monthString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       }
+       else if (boxId == DATETIME_ID_YEAR)
+       {
+               pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(yearString.GetPointer())), yearString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       }
+
+       SysTryReturn(NID_UI_CTRL, (pSimpleText != null), dim.width, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       dateObject.AppendElement(*pSimpleText);
+       dateObject.SetFont(__pFont, 0, dateObject.GetTextLength());
+       dim = dateObject.GetTextExtentF(0, dateObject.GetTextLength());
+
+       dateObject.RemoveAll();
+
+       return dim.width;
+}
+
 int
 _EditDatePresenter::GetLocaleDateFormat(void) const
 {
@@ -434,23 +478,23 @@ _EditDatePresenter::CalculateAreaBounds(void)
 
        if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
        {
-               __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
-               __yearBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
+               __monthBounds.x = __elementWidth + __dividerLineWidth + (__elementWidth - __monthBounds.width) / 2.0f;
+               __yearBounds.x = (2.0f * __elementWidth) + (2.0f * __dividerLineWidth) + (__elementWidth - __yearBounds.width) / 2.0f;
        }
        else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
        {
-               __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
-               __yearBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
+               __dayBounds.x = __elementWidth + __dividerLineWidth + (__elementWidth - __dayBounds.width) / 2.0f;
+               __yearBounds.x = (2.0f * __elementWidth) + (2.0f * __dividerLineWidth) + (__elementWidth - __yearBounds.width) / 2.0f;
        }
        else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
        {
-               __monthBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
-               __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
+               __monthBounds.x = __elementWidth + __dividerLineWidth + (__elementWidth - __monthBounds.width) / 2.0f;
+               __dayBounds.x = (2.0f * __elementWidth) + (2.0f * __dividerLineWidth) + (__elementWidth - __dayBounds.width) / 2.0f;
        }
        else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
        {
-               __dayBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
-               __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
+               __dayBounds.x = __elementWidth + __dividerLineWidth + (__elementWidth - __dayBounds.width) / 2.0f;
+               __monthBounds.x = (2.0f * __elementWidth) + (2.0f * __dividerLineWidth) + (__elementWidth - __monthBounds.width) / 2.0f;
        }
 
        return r;
@@ -747,7 +791,7 @@ _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& to
        _DateTimeId boxId = DATETIME_ID_NONE;
        boxId = GetBoxIdFromPosition(point);
 
-       if (boxId != __selectedId || boxId == DATETIME_ID_NONE)
+       if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
        {
                if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
                {
index 050d247..d4e6689 100755 (executable)
@@ -333,12 +333,13 @@ _EditTimePresenter::GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId)
 
        if (displayBoxId == DATETIME_ID_HOUR)
        {
-               bounds.width = timeElementWidth;
+               bounds.width = GetTextWidth(displayBoxId);
        }
        else if (displayBoxId == DATETIME_ID_MINUTE)
        {
-               bounds.x = bounds.x + timeElementWidth + colonWidth + 2.0f * colonMargin;
-               bounds.width = timeElementWidth;
+               bounds.width = GetTextWidth(displayBoxId);
+               bounds.x = bounds.x + timeElementWidth + colonWidth + 2.0f * colonMargin + (timeElementWidth - bounds.width) / 2.0f;
+
        }
        else if (displayBoxId == DATETIME_ID_AMPM)
        {
@@ -356,6 +357,44 @@ _EditTimePresenter::GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId)
        return bounds;
 }
 
+float
+_EditTimePresenter::GetTextWidth(_DateTimeId boxId) const
+{
+       result r = E_SUCCESS;
+       FloatDimension dim;
+       TextObject dateObject;
+       String hourString;
+       String minuteString;
+
+       hourString.Format(10, L"%02d", GetHour());
+       minuteString.Format(10, L"%02d", GetMinute());
+
+       r = dateObject.Construct();
+       SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       TextSimple* pSimpleText = null;
+
+       if (boxId == DATETIME_ID_HOUR)
+       {
+               pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(hourString.GetPointer())), hourString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       }
+       else if (boxId == DATETIME_ID_MINUTE)
+       {
+               pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(minuteString.GetPointer())), minuteString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       }
+
+       SysTryReturn(NID_UI_CTRL, (pSimpleText != null), dim.width, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
+
+       dateObject.AppendElement(*pSimpleText);
+       dateObject.SetFont(__pFont, 0, dateObject.GetTextLength());
+       dim = dateObject.GetTextExtentF(0, dateObject.GetTextLength());
+
+       dateObject.RemoveAll();
+       return dim.width;
+}
+
 void
 _EditTimePresenter::SetTitleBounds(void)
 {
@@ -562,6 +601,7 @@ _EditTimePresenter::Draw(void)
        FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
 
        float colonMargin = 0.0f;
+       float hourMinuteWidth = 0.0f;
 
        Dimension textArea;
 
@@ -625,8 +665,9 @@ _EditTimePresenter::Draw(void)
        GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonBounds.width);
        GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
        GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), colonBounds.height);
+       GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_WIDTH, __pEditTime->GetOrientation(), hourMinuteWidth);
 
-       colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
+       colonBounds.x = hourBounds.x + hourMinuteWidth + colonMargin;
        colonBounds.y = hourBounds.y + (hourBounds.height - colonBounds.height) / 2.0f;
 
        if (__title.IsEmpty() == false)
@@ -959,7 +1000,7 @@ _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& to
 
        _DateTimeId boxId = GetBoxIdFromPosition(point);
 
-       if (boxId != __selectedId || boxId == DATETIME_ID_NONE)
+       if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
        {
                if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
                {
index 223a272..35fdcf1 100644 (file)
@@ -90,7 +90,7 @@ private:
        void SetTitle(const Tizen::Base::String& title);
        result InitializeTextObject(void);
        result InitializeTitleObject(void);
-
+       float GetTextWidth(_DateTimeId boxId) const;
        result CalculateAreaBounds(void);
        result DrawTitle(Tizen::Graphics::Canvas& canvas);
        result DrawText(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Base::String& text);
@@ -124,6 +124,7 @@ private:
        Tizen::Ui::Animations::VisualElement* __pContentProvider;
        bool __isAnimating;
        bool __isEditDateInitialized;
+       float __elementWidth;
        static const int __dividerCount = 2;
 }; // _EditDatePresenter
 
index 73bf023..7d9e462 100644 (file)
@@ -60,6 +60,7 @@ public:
 
        _DateTimeId GetLastSelectedId(void) const;
        Tizen::Graphics::FloatRectangle GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId) const;
+       float GetTextWidth(_DateTimeId boxId) const;
        void SetTitleBounds(void);
        Tizen::Graphics::FloatRectangle GetTitleBounds(void) const;