summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-19 23:45:38 -0500
committerCaolán McNamara <caolanm@redhat.com>2014-02-21 12:47:31 +0000
commit8e2e2b0d2d585839e2ecf339f26336c8f653b0e6 (patch)
treebc192cb78bc3667f15d92526ec803023f3faa99a
parent165ab67a284efc75d3ed07c4dd2b03a430959481 (diff)
fdo#73565: Populate date members in a locale-safe way.
Change-Id: Id90b2829465fada690b0446d6d823e76e792c77b (cherry picked from commit 2be2786879883badd6d0075e63965bacd312ed23) Reviewed-on: https://gerrit.libreoffice.org/8139 Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Reviewed-on: https://gerrit.libreoffice.org/8140 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/source/ui/cctrl/checklistmenu.cxx106
1 files changed, 64 insertions, 42 deletions
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 2cde8eb453ea..848d84cb62d1 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -32,6 +32,7 @@
#include "svtools/fmtfield.hxx"
#include "document.hxx"
+using namespace com::sun::star;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::accessibility::XAccessible;
using ::com::sun::star::accessibility::XAccessibleContext;
@@ -1279,50 +1280,71 @@ void ScCheckListMenuWindow::setMemberSize(size_t n)
void ScCheckListMenuWindow::addDateMember(const OUString& rsName, double nVal, bool bVisible)
{
ScDocument* pDoc = getDoc();
- if ( pDoc )
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+
+ // Convert the numeric date value to a date object.
+ Date aDate = *(pFormatter->GetNullDate());
+ aDate += static_cast<long>(rtl::math::approxFloor(nVal));
+
+ sal_uInt16 nYear = aDate.GetYear();
+ sal_uInt16 nMonth = aDate.GetMonth();
+ sal_uInt16 nDay = aDate.GetDay();
+
+ // Get the localized month name list.
+ CalendarWrapper* pCalendar = ScGlobal::GetCalendar();
+ uno::Sequence<i18n::CalendarItem2> aMonths = pCalendar->getMonths();
+ if (aMonths.getLength() < nMonth)
+ return;
+
+ OUString aYearName = OUString::number(nYear);
+ OUString aMonthName = aMonths[nMonth-1].FullName;
+ OUString aDayName = OUString::number(nDay);
+
+ maChecks.SetUpdateMode(false);
+
+ SvTreeListEntry* pYearEntry = maChecks.FindEntry(NULL, aYearName);
+ if (!pYearEntry)
{
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
- OUString rsDate;
- if ( pFormatter )
- {
- OUString sFormat("YYYY/MMMM/DD");
- Color* pColor = NULL;
- pFormatter->GetPreviewString(sFormat,
- nVal,
- rsDate,
- &pColor,
- ScGlobal::eLnge );
- }
- maChecks.SetUpdateMode(false);
- sal_Int32 nIndex = 0;
- OUString sParent;
- SvTreeListEntry* pParent = NULL;
- int count = 0;
- do
- {
- OUString sPart = rsDate.getToken( 0, '/', nIndex );
- bool bLeaf = ( ++count == 3 );
- SvTreeListEntry* pChild = maChecks.FindEntry( pParent, sPart );
- if ( !pChild )
- {
- if ( bLeaf )
- pChild = maChecks.SvTreeListBox::InsertEntry( sPart, pParent, sal_False, LISTBOX_APPEND, NULL, SvLBoxButtonKind_enabledCheckbox );
- else
- pChild = maChecks.SvTreeListBox::InsertEntry( sPart, pParent, sal_True, LISTBOX_APPEND, NULL, SvLBoxButtonKind_enabledCheckbox );
- Member aMember;
- aMember.maName = sPart;
- aMember.maRealName = rsName;
- aMember.mbDate = true;
- aMember.mbLeaf = bLeaf;
- aMember.mbVisible = bVisible;
- aMember.mpParent = pParent;
- maMembers.push_back(aMember);
- }
- sParent = sPart;
- pParent = pChild;
- } while ( nIndex >= 0 );
- maChecks.SetUpdateMode(true);
+ pYearEntry = maChecks.InsertEntry(aYearName, NULL, true);
+ Member aMemYear;
+ aMemYear.maName = aYearName;
+ aMemYear.maRealName = rsName;
+ aMemYear.mbDate = true;
+ aMemYear.mbLeaf = false;
+ aMemYear.mbVisible = bVisible;
+ aMemYear.mpParent = NULL;
+ maMembers.push_back(aMemYear);
+ }
+
+ SvTreeListEntry* pMonthEntry = maChecks.FindEntry(pYearEntry, aMonthName);
+ if (!pMonthEntry)
+ {
+ pMonthEntry = maChecks.InsertEntry(aMonthName, pYearEntry, true);
+ Member aMemMonth;
+ aMemMonth.maName = aMonthName;
+ aMemMonth.maRealName = rsName;
+ aMemMonth.mbDate = true;
+ aMemMonth.mbLeaf = false;
+ aMemMonth.mbVisible = bVisible;
+ aMemMonth.mpParent = pYearEntry;
+ maMembers.push_back(aMemMonth);
}
+
+ SvTreeListEntry* pDayEntry = maChecks.FindEntry(pMonthEntry, aDayName);
+ if (!pDayEntry)
+ {
+ pDayEntry = maChecks.InsertEntry(aDayName, pMonthEntry, false);
+ Member aMemDay;
+ aMemDay.maName = aDayName;
+ aMemDay.maRealName = rsName;
+ aMemDay.mbDate = true;
+ aMemDay.mbLeaf = true;
+ aMemDay.mbVisible = bVisible;
+ aMemDay.mpParent = pMonthEntry;
+ maMembers.push_back(aMemDay);
+ }
+
+ maChecks.SetUpdateMode(true);
}
void ScCheckListMenuWindow::addMember(const OUString& rName, bool bVisible)