1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "precompiled_reportdesign.hxx" 28*cdf0e10cSrcweir #include "DateTime.hxx" 29*cdf0e10cSrcweir #ifndef RPTUI_DATETIME_HRC 30*cdf0e10cSrcweir #include "DateTime.hrc" 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 33*cdf0e10cSrcweir #include <tools/debug.hxx> 34*cdf0e10cSrcweir #ifndef _RPTUI_DLGRESID_HRC 35*cdf0e10cSrcweir #include "RptResId.hrc" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _RPTUI_SLOTID_HRC_ 38*cdf0e10cSrcweir #include "rptui_slotid.hrc" 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef _RPTUI_MODULE_HELPER_DBU_HXX_ 41*cdf0e10cSrcweir #include "ModuleHelper.hxx" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef RTPUI_REPORTDESIGN_HELPID_HRC 44*cdf0e10cSrcweir #include "helpids.hrc" 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 47*cdf0e10cSrcweir #ifndef _GLOBLMN_HRC 48*cdf0e10cSrcweir #include <svx/globlmn.hrc> 49*cdf0e10cSrcweir #endif 50*cdf0e10cSrcweir #ifndef _SBASLTID_HRC 51*cdf0e10cSrcweir #include <svx/svxids.hrc> 52*cdf0e10cSrcweir #endif 53*cdf0e10cSrcweir #include <connectivity/dbconversion.hxx> 54*cdf0e10cSrcweir #include <unotools/syslocale.hxx> 55*cdf0e10cSrcweir #ifndef RPTUI_TOOLS_HXX 56*cdf0e10cSrcweir #include "UITools.hxx" 57*cdf0e10cSrcweir #endif 58*cdf0e10cSrcweir #include "RptDef.hxx" 59*cdf0e10cSrcweir #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC 60*cdf0e10cSrcweir #include "uistrings.hrc" 61*cdf0e10cSrcweir #endif 62*cdf0e10cSrcweir #include "ReportController.hxx" 63*cdf0e10cSrcweir #include <com/sun/star/report/XFormattedField.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatPreviewer.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/i18n/NumberFormatIndex.hpp> 69*cdf0e10cSrcweir #include <comphelper/numbers.hxx> 70*cdf0e10cSrcweir #include <algorithm> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir namespace rptui 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir using namespace ::com::sun::star; 75*cdf0e10cSrcweir using namespace ::comphelper; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir DBG_NAME( rpt_ODateTimeDialog ) 78*cdf0e10cSrcweir //======================================================================== 79*cdf0e10cSrcweir // class ODateTimeDialog 80*cdf0e10cSrcweir //======================================================================== 81*cdf0e10cSrcweir ODateTimeDialog::ODateTimeDialog( Window* _pParent 82*cdf0e10cSrcweir ,const uno::Reference< report::XSection >& _xHoldAlive 83*cdf0e10cSrcweir ,OReportController* _pController) 84*cdf0e10cSrcweir : ModalDialog( _pParent, ModuleRes(RID_DATETIME_DLG) ) 85*cdf0e10cSrcweir ,m_aDate(this, ModuleRes(CB_DATE ) ) 86*cdf0e10cSrcweir ,m_aFTDateFormat(this, ModuleRes(FT_DATE_FORMAT ) ) 87*cdf0e10cSrcweir ,m_aDateListBox(this, ModuleRes(LB_DATE_TYPE ) ) 88*cdf0e10cSrcweir ,m_aFL0(this, ModuleRes(FL_SEPARATOR0 ) ) 89*cdf0e10cSrcweir ,m_aTime(this, ModuleRes(CB_TIME ) ) 90*cdf0e10cSrcweir ,m_aFTTimeFormat(this, ModuleRes(FT_TIME_FORMAT ) ) 91*cdf0e10cSrcweir ,m_aTimeListBox(this, ModuleRes(LB_TIME_TYPE ) ) 92*cdf0e10cSrcweir ,m_aFL1(this, ModuleRes(FL_SEPARATOR1) ) 93*cdf0e10cSrcweir ,m_aPB_OK(this, ModuleRes(PB_OK)) 94*cdf0e10cSrcweir ,m_aPB_CANCEL(this, ModuleRes(PB_CANCEL)) 95*cdf0e10cSrcweir ,m_aPB_Help(this, ModuleRes(PB_HELP)) 96*cdf0e10cSrcweir ,m_aDateControlling() 97*cdf0e10cSrcweir ,m_aTimeControlling() 98*cdf0e10cSrcweir ,m_pController(_pController) 99*cdf0e10cSrcweir ,m_xHoldAlive(_xHoldAlive) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir DBG_CTOR( rpt_ODateTimeDialog,NULL); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir try 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir SvtSysLocale aSysLocale; 106*cdf0e10cSrcweir m_nLocale = aSysLocale.GetLocaleData().getLocale(); 107*cdf0e10cSrcweir // Fill listbox with all well known date types 108*cdf0e10cSrcweir InsertEntry(util::NumberFormat::DATE); 109*cdf0e10cSrcweir InsertEntry(util::NumberFormat::TIME); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir catch(uno::Exception&) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir m_aDateListBox.SetDropDownLineCount(20); 116*cdf0e10cSrcweir m_aDateListBox.SelectEntryPos(0); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir m_aTimeListBox.SetDropDownLineCount(20); 119*cdf0e10cSrcweir m_aTimeListBox.SelectEntryPos(0); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // use nice enhancement, to toggle enable/disable if a checkbox is checked or not 122*cdf0e10cSrcweir m_aDateControlling.enableOnCheckMark( m_aDate, m_aFTDateFormat, m_aDateListBox); 123*cdf0e10cSrcweir m_aTimeControlling.enableOnCheckMark( m_aTime, m_aFTTimeFormat, m_aTimeListBox); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir CheckBox* pCheckBoxes[] = { &m_aDate,&m_aTime}; 126*cdf0e10cSrcweir for ( size_t i = 0 ; i < sizeof(pCheckBoxes)/sizeof(pCheckBoxes[0]); ++i) 127*cdf0e10cSrcweir pCheckBoxes[i]->SetClickHdl(LINK(this,ODateTimeDialog,CBClickHdl)); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir FreeResource(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 132*cdf0e10cSrcweir void ODateTimeDialog::InsertEntry(sal_Int16 _nNumberFormatId) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir const bool bTime = util::NumberFormat::TIME == _nNumberFormatId; 135*cdf0e10cSrcweir ListBox* pListBox = &m_aDateListBox; 136*cdf0e10cSrcweir if ( bTime ) 137*cdf0e10cSrcweir pListBox = &m_aTimeListBox; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir const uno::Reference< util::XNumberFormatter> xNumberFormatter = m_pController->getReportNumberFormatter(); 140*cdf0e10cSrcweir const uno::Reference< util::XNumberFormats> xFormats = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats(); 141*cdf0e10cSrcweir const uno::Sequence<sal_Int32> aFormatKeys = xFormats->queryKeys(_nNumberFormatId,m_nLocale,sal_True); 142*cdf0e10cSrcweir const sal_Int32* pIter = aFormatKeys.getConstArray(); 143*cdf0e10cSrcweir const sal_Int32* pEnd = pIter + aFormatKeys.getLength(); 144*cdf0e10cSrcweir for(;pIter != pEnd;++pIter) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir const sal_Int16 nPos = pListBox->InsertEntry(getFormatStringByKey(*pIter,xFormats,bTime)); 147*cdf0e10cSrcweir pListBox->SetEntryData(nPos, reinterpret_cast<void*>(*pIter)); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir //------------------------------------------------------------------------ 151*cdf0e10cSrcweir ODateTimeDialog::~ODateTimeDialog() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir DBG_DTOR( rpt_ODateTimeDialog,NULL); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 156*cdf0e10cSrcweir short ODateTimeDialog::Execute() 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir DBG_CHKTHIS( rpt_ODateTimeDialog,NULL); 159*cdf0e10cSrcweir short nRet = ModalDialog::Execute(); 160*cdf0e10cSrcweir if ( nRet == RET_OK && (m_aDate.IsChecked() || m_aTime.IsChecked()) ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir try 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir sal_Int32 nLength = 0; 165*cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aValues( 6 ); 166*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_SECTION; 167*cdf0e10cSrcweir aValues[nLength++].Value <<= m_xHoldAlive; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_TIME_STATE; 170*cdf0e10cSrcweir aValues[nLength++].Value <<= m_aTime.IsChecked(); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_DATE_STATE; 173*cdf0e10cSrcweir aValues[nLength++].Value <<= m_aDate.IsChecked(); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_FORMATKEYDATE; 176*cdf0e10cSrcweir aValues[nLength++].Value <<= getFormatKey(sal_True); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_FORMATKEYTIME; 179*cdf0e10cSrcweir aValues[nLength++].Value <<= getFormatKey(sal_False); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir sal_Int32 nWidth = 0; 182*cdf0e10cSrcweir if ( m_aDate.IsChecked() ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir String sDateFormat = m_aDateListBox.GetEntry( m_aDateListBox.GetSelectEntryPos() ); 185*cdf0e10cSrcweir nWidth = LogicToLogic(PixelToLogic(Size(GetCtrlTextWidth(sDateFormat),0)).Width(),GetMapMode().GetMapUnit(),MAP_100TH_MM); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir if ( m_aTime.IsChecked() ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir String sDateFormat = m_aTimeListBox.GetEntry( m_aTimeListBox.GetSelectEntryPos() ); 190*cdf0e10cSrcweir nWidth = ::std::max<sal_Int32>(LogicToLogic(PixelToLogic(Size(GetCtrlTextWidth(sDateFormat),0)).Width(),GetMapMode().GetMapUnit(),MAP_100TH_MM),nWidth); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if ( nWidth > 4000 ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir aValues[nLength].Name = PROPERTY_WIDTH; 196*cdf0e10cSrcweir aValues[nLength++].Value <<= nWidth; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir m_pController->executeChecked(SID_DATETIME,aValues); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir catch(uno::Exception&) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir nRet = RET_NO; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir return nRet; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 209*cdf0e10cSrcweir ::rtl::OUString ODateTimeDialog::getFormatStringByKey(::sal_Int32 _nNumberFormatKey,const uno::Reference< util::XNumberFormats>& _xFormats,bool _bTime) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir uno::Reference< beans::XPropertySet> xFormSet = _xFormats->getByKey(_nNumberFormatKey); 212*cdf0e10cSrcweir OSL_ENSURE(xFormSet.is(),"XPropertySet is null!"); 213*cdf0e10cSrcweir ::rtl::OUString sFormat; 214*cdf0e10cSrcweir xFormSet->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FormatString"))) >>= sFormat; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir double nValue = 0; 217*cdf0e10cSrcweir if ( _bTime ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir Time aCurrentTime; 220*cdf0e10cSrcweir nValue = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(aCurrentTime.GetTime())); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir else 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir Date aCurrentDate; 225*cdf0e10cSrcweir static ::com::sun::star::util::Date STANDARD_DB_DATE(30,12,1899); 226*cdf0e10cSrcweir nValue = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(static_cast<sal_Int32>(aCurrentDate.GetDate())),STANDARD_DB_DATE); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir uno::Reference< util::XNumberFormatPreviewer> xPreViewer(m_pController->getReportNumberFormatter(),uno::UNO_QUERY); 230*cdf0e10cSrcweir OSL_ENSURE(xPreViewer.is(),"XNumberFormatPreviewer is null!"); 231*cdf0e10cSrcweir return xPreViewer->convertNumberToPreviewString(sFormat,nValue,m_nLocale,sal_True); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 234*cdf0e10cSrcweir IMPL_LINK( ODateTimeDialog, CBClickHdl, CheckBox*, _pBox ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir (void)_pBox; 237*cdf0e10cSrcweir DBG_CHKTHIS( rpt_ODateTimeDialog,NULL); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if ( _pBox == &m_aDate || _pBox == &m_aTime) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir sal_Bool bDate = m_aDate.IsChecked(); 242*cdf0e10cSrcweir sal_Bool bTime = m_aTime.IsChecked(); 243*cdf0e10cSrcweir if (!bDate && !bTime) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir m_aPB_OK.Disable(); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir else 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir m_aPB_OK.Enable(); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir return 1L; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 255*cdf0e10cSrcweir sal_Int32 ODateTimeDialog::getFormatKey(sal_Bool _bDate) const 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir DBG_CHKTHIS( rpt_ODateTimeDialog,NULL); 258*cdf0e10cSrcweir sal_Int32 nFormatKey; 259*cdf0e10cSrcweir if ( _bDate ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir // nFormat = m_aDateF1.IsChecked() ? i18n::NumberFormatIndex::DATE_SYSTEM_LONG : (m_aDateF2.IsChecked() ? i18n::NumberFormatIndex::DATE_SYS_DMMMYYYY : i18n::NumberFormatIndex::DATE_SYSTEM_SHORT); 262*cdf0e10cSrcweir nFormatKey = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(m_aDateListBox.GetEntryData( m_aDateListBox.GetSelectEntryPos() ))); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir else 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir // nFormat = m_aTimeF1.IsChecked() ? i18n::NumberFormatIndex::TIME_HHMMSS : (m_aTimeF2.IsChecked() ? i18n::NumberFormatIndex::TIME_HHMMSSAMPM : i18n::NumberFormatIndex::TIME_HHMM); 267*cdf0e10cSrcweir nFormatKey = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(m_aTimeListBox.GetEntryData( m_aTimeListBox.GetSelectEntryPos() ))); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir return nFormatKey; 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir // ============================================================================= 272*cdf0e10cSrcweir } // rptui 273*cdf0e10cSrcweir // ============================================================================= 274