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 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <vcl/svapp.hxx> 32*cdf0e10cSrcweir #include <tools/table.hxx> 33*cdf0e10cSrcweir #include <vcl/help.hxx> 34*cdf0e10cSrcweir #include <vcl/menu.hxx> 35*cdf0e10cSrcweir #include <vcl/decoview.hxx> 36*cdf0e10cSrcweir #include <vcl/floatwin.hxx> 37*cdf0e10cSrcweir #include <vcl/button.hxx> 38*cdf0e10cSrcweir #include <vcl/fixed.hxx> 39*cdf0e10cSrcweir #include <unotools/calendarwrapper.hxx> 40*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 41*cdf0e10cSrcweir #include <com/sun/star/i18n/Weekdays.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/i18n/CalendarDisplayIndex.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/i18n/CalendarFieldIndex.hpp> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #define _SV_CALENDAR_CXX 46*cdf0e10cSrcweir #include <svtools/svtools.hrc> 47*cdf0e10cSrcweir #include <svtools/svtdata.hxx> 48*cdf0e10cSrcweir #include <svtools/calendar.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ======================================================================= 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #define DAY_OFFX 4 53*cdf0e10cSrcweir #define DAY_OFFY 2 54*cdf0e10cSrcweir #define MONTH_BORDERX 4 55*cdf0e10cSrcweir #define MONTH_OFFY 3 56*cdf0e10cSrcweir #define WEEKNUMBER_OFFX 4 57*cdf0e10cSrcweir #define WEEKDAY_OFFY 3 58*cdf0e10cSrcweir #define TITLE_OFFY 3 59*cdf0e10cSrcweir #define TITLE_BORDERY 2 60*cdf0e10cSrcweir #define SPIN_OFFX 4 61*cdf0e10cSrcweir #define SPIN_OFFY TITLE_BORDERY 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #define WEEKNUMBER_HEIGHT 85 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #define CALENDAR_HITTEST_DAY ((sal_uInt16)0x0001) 66*cdf0e10cSrcweir #define CALENDAR_HITTEST_WEEK ((sal_uInt16)0x0002) 67*cdf0e10cSrcweir #define CALENDAR_HITTEST_MONTHTITLE ((sal_uInt16)0x0004) 68*cdf0e10cSrcweir #define CALENDAR_HITTEST_PREV ((sal_uInt16)0x0008) 69*cdf0e10cSrcweir #define CALENDAR_HITTEST_NEXT ((sal_uInt16)0x0010) 70*cdf0e10cSrcweir #define CALENDAR_HITTEST_OUTSIDE ((sal_uInt16)0x1000) 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #define MENU_YEAR_COUNT 3 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #define TABLE_DATE_SELECTED ((void*)0x00000001) 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir using namespace ::com::sun::star; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // ======================================================================= 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir struct ImplDateInfo 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir XubString maText; 83*cdf0e10cSrcweir Color* mpTextColor; 84*cdf0e10cSrcweir Color* mpFrameColor; 85*cdf0e10cSrcweir sal_uInt16 mnFlags; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir ImplDateInfo( const XubString& rText ) : 88*cdf0e10cSrcweir maText( rText ) 89*cdf0e10cSrcweir { mpTextColor = mpFrameColor = NULL; mnFlags = 0; } 90*cdf0e10cSrcweir ~ImplDateInfo() { delete mpTextColor; delete mpFrameColor; } 91*cdf0e10cSrcweir }; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir DECLARE_TABLE( ImplDateTable, ImplDateInfo* ) 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // ======================================================================= 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir static void ImplCalendarSelectDate( Table* pTable, const Date& rDate, sal_Bool bSelect ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir if ( bSelect ) 100*cdf0e10cSrcweir pTable->Insert( rDate.GetDate(), TABLE_DATE_SELECTED ); 101*cdf0e10cSrcweir else 102*cdf0e10cSrcweir pTable->Remove( rDate.GetDate() ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // ----------------------------------------------------------------------- 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir static void ImplCalendarSelectDateRange( Table* pTable, 108*cdf0e10cSrcweir const Date& rStartDate, 109*cdf0e10cSrcweir const Date& rEndDate, 110*cdf0e10cSrcweir sal_Bool bSelect ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir Date aStartDate = rStartDate; 113*cdf0e10cSrcweir Date aEndDate = rEndDate; 114*cdf0e10cSrcweir if ( aStartDate > aEndDate ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir Date aTempDate = aStartDate; 117*cdf0e10cSrcweir aStartDate = aEndDate; 118*cdf0e10cSrcweir aEndDate = aTempDate; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir if ( bSelect ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir while ( aStartDate <= aEndDate ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir pTable->Insert( aStartDate.GetDate(), TABLE_DATE_SELECTED ); 126*cdf0e10cSrcweir aStartDate++; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir else 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir void* p = pTable->First(); 132*cdf0e10cSrcweir while ( p ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir Date aDate( pTable->GetCurKey() ); 135*cdf0e10cSrcweir if ( aDate > aEndDate ) 136*cdf0e10cSrcweir break; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if ( aDate >= aStartDate ) 139*cdf0e10cSrcweir pTable->Remove( aDate.GetDate() ); 140*cdf0e10cSrcweir else 141*cdf0e10cSrcweir p = pTable->Next(); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // ----------------------------------------------------------------------- 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir static void ImplCalendarUnSelectDateRange( Table* pTable, 149*cdf0e10cSrcweir Table* pOldTable, 150*cdf0e10cSrcweir const Date& rStartDate, 151*cdf0e10cSrcweir const Date& rEndDate ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir Date aStartDate = rStartDate; 154*cdf0e10cSrcweir Date aEndDate = rEndDate; 155*cdf0e10cSrcweir if ( aStartDate > aEndDate ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir Date aTempDate = aStartDate; 158*cdf0e10cSrcweir aStartDate = aEndDate; 159*cdf0e10cSrcweir aEndDate = aTempDate; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir void* p = pTable->First(); 163*cdf0e10cSrcweir while ( p ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir Date aDate( pTable->GetCurKey() ); 166*cdf0e10cSrcweir if ( aDate > aEndDate ) 167*cdf0e10cSrcweir break; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if ( aDate >= aStartDate ) 170*cdf0e10cSrcweir pTable->Remove( aDate.GetDate() ); 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir p = pTable->Next(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir p = pOldTable->First(); 176*cdf0e10cSrcweir while ( p ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir Date aDate( pOldTable->GetCurKey() ); 179*cdf0e10cSrcweir if ( aDate > aEndDate ) 180*cdf0e10cSrcweir break; 181*cdf0e10cSrcweir if ( aDate >= aStartDate ) 182*cdf0e10cSrcweir pTable->Insert( aDate.GetDate(), TABLE_DATE_SELECTED ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir p = pOldTable->Next(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // ----------------------------------------------------------------------- 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir inline void ImplCalendarClearSelectDate( Table* pTable ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir pTable->Clear(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // ======================================================================= 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir void Calendar::ImplInit( WinBits nWinStyle ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir mpDateTable = NULL; 200*cdf0e10cSrcweir mpSelectTable = new Table; 201*cdf0e10cSrcweir mpOldSelectTable = NULL; 202*cdf0e10cSrcweir mpRestoreSelectTable = NULL; 203*cdf0e10cSrcweir mpStandardColor = NULL; 204*cdf0e10cSrcweir mpSaturdayColor = NULL; 205*cdf0e10cSrcweir mpSundayColor = NULL; 206*cdf0e10cSrcweir mnDayCount = 0; 207*cdf0e10cSrcweir mnWinStyle = nWinStyle; 208*cdf0e10cSrcweir mnFirstYear = 0; 209*cdf0e10cSrcweir mnLastYear = 0; 210*cdf0e10cSrcweir mnRequestYear = 0; 211*cdf0e10cSrcweir mbCalc = sal_True; 212*cdf0e10cSrcweir mbFormat = sal_True; 213*cdf0e10cSrcweir mbDrag = sal_False; 214*cdf0e10cSrcweir mbSelection = sal_False; 215*cdf0e10cSrcweir mbMultiSelection = sal_False; 216*cdf0e10cSrcweir mbWeekSel = sal_False; 217*cdf0e10cSrcweir mbUnSel = sal_False; 218*cdf0e10cSrcweir mbMenuDown = sal_False; 219*cdf0e10cSrcweir mbSpinDown = sal_False; 220*cdf0e10cSrcweir mbPrevIn = sal_False; 221*cdf0e10cSrcweir mbNextIn = sal_False; 222*cdf0e10cSrcweir mbDirect = sal_False; 223*cdf0e10cSrcweir mbInSelChange = sal_False; 224*cdf0e10cSrcweir mbTravelSelect = sal_False; 225*cdf0e10cSrcweir mbScrollDateRange = sal_False; 226*cdf0e10cSrcweir mbSelLeft = sal_False; 227*cdf0e10cSrcweir mbAllSel = sal_False; 228*cdf0e10cSrcweir mbDropPos = sal_False; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir ::rtl::OUString aGregorian( RTL_CONSTASCII_USTRINGPARAM( "gregorian")); 231*cdf0e10cSrcweir maCalendarWrapper.loadCalendar( aGregorian, 232*cdf0e10cSrcweir Application::GetAppLocaleDataWrapper().getLocale()); 233*cdf0e10cSrcweir if (maCalendarWrapper.getUniqueID() != aGregorian) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir #ifdef DBG_UTIL 236*cdf0e10cSrcweir ByteString aMsg( "Calendar::ImplInit: No ``gregorian'' calendar available for locale ``"); 237*cdf0e10cSrcweir lang::Locale aLoc( Application::GetAppLocaleDataWrapper().getLocale()); 238*cdf0e10cSrcweir aMsg += ByteString( String( aLoc.Language), RTL_TEXTENCODING_UTF8); 239*cdf0e10cSrcweir aMsg += '-'; 240*cdf0e10cSrcweir aMsg += ByteString( String( aLoc.Country), RTL_TEXTENCODING_UTF8); 241*cdf0e10cSrcweir aMsg += "'' and other calendars aren't supported. Using en-US fallback."; 242*cdf0e10cSrcweir DBG_ERRORFILE( aMsg.GetBuffer()); 243*cdf0e10cSrcweir #endif 244*cdf0e10cSrcweir /* If we ever wanted to support other calendars than Gregorian a lot of 245*cdf0e10cSrcweir * rewrite would be necessary to internally replace use of class Date 246*cdf0e10cSrcweir * with proper class CalendarWrapper methods, get rid of fixed 12 247*cdf0e10cSrcweir * months, fixed 7 days, ... */ 248*cdf0e10cSrcweir maCalendarWrapper.loadCalendar( aGregorian, lang::Locale( 249*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en")), 250*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US")), 251*cdf0e10cSrcweir ::rtl::OUString())); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir SetFirstDate( maCurDate ); 255*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, maCurDate, sal_True ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // Sonstige Strings erzeugen 258*cdf0e10cSrcweir maDayText = XubString( SvtResId( STR_SVT_CALENDAR_DAY ) ); 259*cdf0e10cSrcweir maWeekText = XubString( SvtResId( STR_SVT_CALENDAR_WEEK ) ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // Tagestexte anlegen 262*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < 31; i++ ) 263*cdf0e10cSrcweir mpDayText[i] = new UniString( UniString::CreateFromInt32( i+1 ) ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir maDragScrollTimer.SetTimeoutHdl( STATIC_LINK( this, Calendar, ScrollHdl ) ); 266*cdf0e10cSrcweir maDragScrollTimer.SetTimeout( GetSettings().GetMouseSettings().GetScrollRepeat() ); 267*cdf0e10cSrcweir mnDragScrollHitTest = 0; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir ImplInitSettings(); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // ----------------------------------------------------------------------- 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir void Calendar::ImplInitSettings() 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 277*cdf0e10cSrcweir maSelColor = rStyleSettings.GetHighlightTextColor(); 278*cdf0e10cSrcweir SetPointFont( rStyleSettings.GetToolFont() ); 279*cdf0e10cSrcweir SetTextColor( rStyleSettings.GetFieldTextColor() ); 280*cdf0e10cSrcweir SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // ----------------------------------------------------------------------- 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir Calendar::Calendar( Window* pParent, WinBits nWinStyle ) : 286*cdf0e10cSrcweir Control( pParent, nWinStyle & (WB_TABSTOP | WB_GROUP | WB_BORDER | WB_3DLOOK | WB_RANGESELECT | WB_MULTISELECT) ), 287*cdf0e10cSrcweir maCalendarWrapper( Application::GetAppLocaleDataWrapper().getServiceFactory() ), 288*cdf0e10cSrcweir maOldFormatFirstDate( 0, 0, 1900 ), 289*cdf0e10cSrcweir maOldFormatLastDate( 0, 0, 1900 ), 290*cdf0e10cSrcweir maFirstDate( 0, 0, 1900 ), 291*cdf0e10cSrcweir maOldFirstDate( 0, 0, 1900 ), 292*cdf0e10cSrcweir maOldCurDate( 0, 0, 1900 ), 293*cdf0e10cSrcweir maAnchorDate( maCurDate ), 294*cdf0e10cSrcweir maDropDate( 0, 0, 1900 ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir ImplInit( nWinStyle ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // ----------------------------------------------------------------------- 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir Calendar::Calendar( Window* pParent, const ResId& rResId ) : 302*cdf0e10cSrcweir Control( pParent, rResId ), 303*cdf0e10cSrcweir maCalendarWrapper( Application::GetAppLocaleDataWrapper().getServiceFactory() ), 304*cdf0e10cSrcweir maOldFormatFirstDate( 0, 0, 1900 ), 305*cdf0e10cSrcweir maOldFormatLastDate( 0, 0, 1900 ), 306*cdf0e10cSrcweir maFirstDate( 0, 0, 1900 ), 307*cdf0e10cSrcweir maOldFirstDate( 0, 0, 1900 ), 308*cdf0e10cSrcweir maOldCurDate( 0, 0, 1900 ), 309*cdf0e10cSrcweir maAnchorDate( maCurDate ), 310*cdf0e10cSrcweir maDropDate( 0, 0, 1900 ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir ImplInit( rResId.GetWinBits() ); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // ----------------------------------------------------------------------- 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir Calendar::~Calendar() 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir delete mpStandardColor; 320*cdf0e10cSrcweir delete mpSaturdayColor; 321*cdf0e10cSrcweir delete mpSundayColor; 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir if ( mpDateTable ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir ImplDateInfo* pDateInfo = mpDateTable->First(); 326*cdf0e10cSrcweir while ( pDateInfo ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir delete pDateInfo; 329*cdf0e10cSrcweir pDateInfo = mpDateTable->Next(); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir delete mpDateTable; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir delete mpSelectTable; 336*cdf0e10cSrcweir if ( mpOldSelectTable ) 337*cdf0e10cSrcweir delete mpOldSelectTable; 338*cdf0e10cSrcweir if ( mpRestoreSelectTable ) 339*cdf0e10cSrcweir delete mpRestoreSelectTable; 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < 31; i++ ) 342*cdf0e10cSrcweir delete mpDayText[i]; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir // ----------------------------------------------------------------------- 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir void Calendar::SetMinimumNumberOfDaysInWeek( sal_Int16 nDays ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir ImplUpdate( sal_True ); 350*cdf0e10cSrcweir maCalendarWrapper.setMinimumNumberOfDaysForFirstWeek( nDays); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir // ----------------------------------------------------------------------- 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir void Calendar::SetWeekStart( sal_Int16 nDay ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir ImplUpdate( sal_True ); 358*cdf0e10cSrcweir switch (nDay) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir case i18n::Weekdays::SUNDAY : 361*cdf0e10cSrcweir case i18n::Weekdays::MONDAY : 362*cdf0e10cSrcweir case i18n::Weekdays::TUESDAY : 363*cdf0e10cSrcweir case i18n::Weekdays::WEDNESDAY : 364*cdf0e10cSrcweir case i18n::Weekdays::THURSDAY : 365*cdf0e10cSrcweir case i18n::Weekdays::FRIDAY : 366*cdf0e10cSrcweir case i18n::Weekdays::SATURDAY : 367*cdf0e10cSrcweir ; // nothing 368*cdf0e10cSrcweir default: 369*cdf0e10cSrcweir DBG_ERRORFILE("Calendar::SetWeekStart: unknown value for setFirstDayOfWeek() of a Gregorian calendar"); 370*cdf0e10cSrcweir nDay = i18n::Weekdays::SUNDAY; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir maCalendarWrapper.setFirstDayOfWeek( nDay); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir // ----------------------------------------------------------------------- 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir DayOfWeek Calendar::ImplGetWeekStart() const 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir // Map i18n::Weekdays to Date DayOfWeek 380*cdf0e10cSrcweir DayOfWeek eDay; 381*cdf0e10cSrcweir sal_Int16 nDay = maCalendarWrapper.getFirstDayOfWeek(); 382*cdf0e10cSrcweir switch (nDay) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir case i18n::Weekdays::SUNDAY : 385*cdf0e10cSrcweir eDay = SUNDAY; 386*cdf0e10cSrcweir break; 387*cdf0e10cSrcweir case i18n::Weekdays::MONDAY : 388*cdf0e10cSrcweir eDay = MONDAY; 389*cdf0e10cSrcweir break; 390*cdf0e10cSrcweir case i18n::Weekdays::TUESDAY : 391*cdf0e10cSrcweir eDay = TUESDAY; 392*cdf0e10cSrcweir break; 393*cdf0e10cSrcweir case i18n::Weekdays::WEDNESDAY : 394*cdf0e10cSrcweir eDay = WEDNESDAY; 395*cdf0e10cSrcweir break; 396*cdf0e10cSrcweir case i18n::Weekdays::THURSDAY : 397*cdf0e10cSrcweir eDay = THURSDAY; 398*cdf0e10cSrcweir break; 399*cdf0e10cSrcweir case i18n::Weekdays::FRIDAY : 400*cdf0e10cSrcweir eDay = FRIDAY; 401*cdf0e10cSrcweir break; 402*cdf0e10cSrcweir case i18n::Weekdays::SATURDAY : 403*cdf0e10cSrcweir eDay = SATURDAY; 404*cdf0e10cSrcweir break; 405*cdf0e10cSrcweir default: 406*cdf0e10cSrcweir DBG_ERRORFILE("Calendar::ImplGetWeekStart: broken i18n Gregorian calendar (getFirstDayOfWeek())"); 407*cdf0e10cSrcweir eDay = SUNDAY; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir return eDay; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir // ----------------------------------------------------------------------- 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir void Calendar::ImplGetWeekFont( Font& rFont ) const 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir // Wochennummer geben wir in WEEKNUMBER_HEIGHT%-Fonthoehe aus 417*cdf0e10cSrcweir Size aFontSize = rFont.GetSize(); 418*cdf0e10cSrcweir aFontSize.Height() *= WEEKNUMBER_HEIGHT; 419*cdf0e10cSrcweir aFontSize.Height() /= 100; 420*cdf0e10cSrcweir rFont.SetSize( aFontSize ); 421*cdf0e10cSrcweir rFont.SetWeight( WEIGHT_NORMAL ); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir // ----------------------------------------------------------------------- 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir void Calendar::ImplFormat() 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir if ( !mbFormat ) 429*cdf0e10cSrcweir return; 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir if ( mbCalc ) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir Size aOutSize = GetOutputSizePixel(); 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir if ( (aOutSize.Width() <= 1) || (aOutSize.Height() <= 1) ) 436*cdf0e10cSrcweir return; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir XubString a99Text( XubString( RTL_CONSTASCII_USTRINGPARAM( "99" ) ) ); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir Font aOldFont = GetFont(); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // Wochenanzeige beruecksichtigen 443*cdf0e10cSrcweir if ( mnWinStyle & WB_WEEKNUMBER ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir Font aTempFont = aOldFont; 446*cdf0e10cSrcweir ImplGetWeekFont( aTempFont ); 447*cdf0e10cSrcweir SetFont( aTempFont ); 448*cdf0e10cSrcweir mnWeekWidth = GetTextWidth( a99Text )+WEEKNUMBER_OFFX; 449*cdf0e10cSrcweir SetFont( aOldFont ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir mnWeekWidth = 0; 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir if ( mnWinStyle & WB_BOLDTEXT ) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir Font aFont = aOldFont; 457*cdf0e10cSrcweir if ( aFont.GetWeight() < WEIGHT_BOLD ) 458*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD ); 459*cdf0e10cSrcweir else 460*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_NORMAL ); 461*cdf0e10cSrcweir SetFont( aFont ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir long n99TextWidth = GetTextWidth( a99Text ); 465*cdf0e10cSrcweir long nTextHeight = GetTextHeight(); 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir // Breiten und X-Positionen berechnen 468*cdf0e10cSrcweir mnDayWidth = n99TextWidth+DAY_OFFX; 469*cdf0e10cSrcweir mnMonthWidth = mnDayWidth*7; 470*cdf0e10cSrcweir mnMonthWidth += mnWeekWidth; 471*cdf0e10cSrcweir mnMonthWidth += MONTH_BORDERX*2; 472*cdf0e10cSrcweir mnMonthPerLine = aOutSize.Width() / mnMonthWidth; 473*cdf0e10cSrcweir if ( !mnMonthPerLine ) 474*cdf0e10cSrcweir mnMonthPerLine = 1; 475*cdf0e10cSrcweir long nOver = ((aOutSize.Width()-(mnMonthPerLine*mnMonthWidth)) / mnMonthPerLine); 476*cdf0e10cSrcweir mnMonthWidth += nOver; 477*cdf0e10cSrcweir mnDaysOffX = MONTH_BORDERX; 478*cdf0e10cSrcweir mnDaysOffX += nOver/2; 479*cdf0e10cSrcweir mnDaysOffX += mnWeekWidth; 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir // Hoehen und Y-Positionen berechnen 482*cdf0e10cSrcweir mnDayHeight = nTextHeight + DAY_OFFY; 483*cdf0e10cSrcweir mnWeekDayOffY = nTextHeight + TITLE_OFFY + (TITLE_BORDERY*2); 484*cdf0e10cSrcweir mnDaysOffY = mnWeekDayOffY + nTextHeight + WEEKDAY_OFFY; 485*cdf0e10cSrcweir mnMonthHeight = (mnDayHeight*6) + mnDaysOffY; 486*cdf0e10cSrcweir mnMonthHeight += MONTH_OFFY; 487*cdf0e10cSrcweir mnLines = aOutSize.Height() / mnMonthHeight; 488*cdf0e10cSrcweir if ( !mnLines ) 489*cdf0e10cSrcweir mnLines = 1; 490*cdf0e10cSrcweir mnMonthHeight += (aOutSize.Height()-(mnLines*mnMonthHeight)) / mnLines; 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir // Spinfelder berechnen 493*cdf0e10cSrcweir long nSpinSize = nTextHeight+TITLE_BORDERY-SPIN_OFFY; 494*cdf0e10cSrcweir maPrevRect.Left() = SPIN_OFFX; 495*cdf0e10cSrcweir maPrevRect.Top() = SPIN_OFFY; 496*cdf0e10cSrcweir maPrevRect.Right() = maPrevRect.Left()+nSpinSize; 497*cdf0e10cSrcweir maPrevRect.Bottom() = maPrevRect.Top()+nSpinSize; 498*cdf0e10cSrcweir maNextRect.Left() = aOutSize.Width()-SPIN_OFFX-nSpinSize-1; 499*cdf0e10cSrcweir maNextRect.Top() = SPIN_OFFY; 500*cdf0e10cSrcweir maNextRect.Right() = maNextRect.Left()+nSpinSize; 501*cdf0e10cSrcweir maNextRect.Bottom() = maNextRect.Top()+nSpinSize; 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir if ( mnWinStyle & WB_BOLDTEXT ) 504*cdf0e10cSrcweir SetFont( aOldFont ); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir // Calculate DayOfWeekText (gets displayed in a narrow font) 507*cdf0e10cSrcweir maDayOfWeekText.Erase(); 508*cdf0e10cSrcweir long nStartOffX = 0; 509*cdf0e10cSrcweir sal_Int16 nDay = maCalendarWrapper.getFirstDayOfWeek(); 510*cdf0e10cSrcweir for ( sal_Int16 nDayOfWeek = 0; nDayOfWeek < 7; nDayOfWeek++ ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir // Use first character of full name, since the abbreviated name may 513*cdf0e10cSrcweir // be roman digits or similar in some locales. Proper 514*cdf0e10cSrcweir // implementation would need narrow one letter month names defined 515*cdf0e10cSrcweir // in locale data. 516*cdf0e10cSrcweir String aDayOfWeek( maCalendarWrapper.getDisplayName( 517*cdf0e10cSrcweir i18n::CalendarDisplayIndex::DAY, nDay, 1).GetChar(0)); 518*cdf0e10cSrcweir long nOffX = (mnDayWidth-GetTextWidth( aDayOfWeek ))/2; 519*cdf0e10cSrcweir if ( mnWinStyle & WB_BOLDTEXT ) 520*cdf0e10cSrcweir nOffX++; 521*cdf0e10cSrcweir if ( !nDayOfWeek ) 522*cdf0e10cSrcweir nStartOffX = nOffX; 523*cdf0e10cSrcweir else 524*cdf0e10cSrcweir nOffX -= nStartOffX; 525*cdf0e10cSrcweir nOffX += nDayOfWeek * mnDayWidth; 526*cdf0e10cSrcweir mnDayOfWeekAry[nDayOfWeek] = nOffX; 527*cdf0e10cSrcweir maDayOfWeekText += aDayOfWeek; 528*cdf0e10cSrcweir nDay++; 529*cdf0e10cSrcweir nDay %= 7; 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir mbCalc = sal_False; 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir // Anzahl Tage berechnen 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir DayOfWeek eStartDay = ImplGetWeekStart(); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir sal_uInt16 nWeekDay; 540*cdf0e10cSrcweir Date aTempDate = GetFirstMonth(); 541*cdf0e10cSrcweir maFirstDate = aTempDate; 542*cdf0e10cSrcweir nWeekDay = (sal_uInt16)aTempDate.GetDayOfWeek(); 543*cdf0e10cSrcweir nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; 544*cdf0e10cSrcweir maFirstDate -= (sal_uLong)nWeekDay; 545*cdf0e10cSrcweir mnDayCount = nWeekDay; 546*cdf0e10cSrcweir sal_uInt16 nDaysInMonth; 547*cdf0e10cSrcweir sal_uInt16 nMonthCount = (sal_uInt16)(mnMonthPerLine*mnLines); 548*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nMonthCount; i++ ) 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir nDaysInMonth = aTempDate.GetDaysInMonth(); 551*cdf0e10cSrcweir mnDayCount += nDaysInMonth; 552*cdf0e10cSrcweir aTempDate += nDaysInMonth; 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir Date aTempDate2 = aTempDate; 555*cdf0e10cSrcweir aTempDate2--; 556*cdf0e10cSrcweir nDaysInMonth = aTempDate2.GetDaysInMonth(); 557*cdf0e10cSrcweir aTempDate2 -= nDaysInMonth-1; 558*cdf0e10cSrcweir nWeekDay = (sal_uInt16)aTempDate2.GetDayOfWeek(); 559*cdf0e10cSrcweir nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; 560*cdf0e10cSrcweir mnDayCount += 42-nDaysInMonth-nWeekDay; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir // Farben festlegen 563*cdf0e10cSrcweir maOtherColor = Color( COL_LIGHTGRAY ); 564*cdf0e10cSrcweir if ( maOtherColor.IsRGBEqual( GetBackground().GetColor() ) ) 565*cdf0e10cSrcweir maOtherColor.SetColor( COL_GRAY ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir Date aLastDate = GetLastDate(); 568*cdf0e10cSrcweir if ( (maOldFormatLastDate != aLastDate) || 569*cdf0e10cSrcweir (maOldFormatFirstDate != maFirstDate) ) 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir maOldFormatFirstDate = maFirstDate; 572*cdf0e10cSrcweir maOldFormatLastDate = aLastDate; 573*cdf0e10cSrcweir DateRangeChanged(); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir // DateInfo besorgen 577*cdf0e10cSrcweir sal_uInt16 nNewFirstYear = maFirstDate.GetYear(); 578*cdf0e10cSrcweir sal_uInt16 nNewLastYear = GetLastDate().GetYear(); 579*cdf0e10cSrcweir if ( mnFirstYear ) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir if ( nNewFirstYear < mnFirstYear ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir for ( mnRequestYear = nNewFirstYear; mnRequestYear < mnFirstYear; mnRequestYear++ ) 584*cdf0e10cSrcweir RequestDateInfo(); 585*cdf0e10cSrcweir mnFirstYear = nNewFirstYear; 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir if ( nNewLastYear > mnLastYear ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir for ( mnRequestYear = mnLastYear; mnRequestYear < nNewLastYear; mnRequestYear++ ) 590*cdf0e10cSrcweir RequestDateInfo(); 591*cdf0e10cSrcweir mnLastYear = nNewLastYear; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir else 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir for ( mnRequestYear = nNewFirstYear; mnRequestYear < nNewLastYear; mnRequestYear++ ) 597*cdf0e10cSrcweir RequestDateInfo(); 598*cdf0e10cSrcweir mnFirstYear = nNewFirstYear; 599*cdf0e10cSrcweir mnLastYear = nNewLastYear; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir mnRequestYear = 0; 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir mbFormat = sal_False; 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir // ----------------------------------------------------------------------- 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir if ( mbFormat ) 611*cdf0e10cSrcweir return 0; 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir if ( maPrevRect.IsInside( rPos ) ) 614*cdf0e10cSrcweir return CALENDAR_HITTEST_PREV; 615*cdf0e10cSrcweir else if ( maNextRect.IsInside( rPos ) ) 616*cdf0e10cSrcweir return CALENDAR_HITTEST_NEXT; 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir long nX; 619*cdf0e10cSrcweir long nY; 620*cdf0e10cSrcweir long nOffX; 621*cdf0e10cSrcweir long nYMonth; 622*cdf0e10cSrcweir sal_uInt16 nDay; 623*cdf0e10cSrcweir DayOfWeek eStartDay = ImplGetWeekStart(); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir rDate = GetFirstMonth(); 626*cdf0e10cSrcweir nY = 0; 627*cdf0e10cSrcweir for ( long i = 0; i < mnLines; i++ ) 628*cdf0e10cSrcweir { 629*cdf0e10cSrcweir if ( rPos.Y() < nY ) 630*cdf0e10cSrcweir return 0; 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir nX = 0; 633*cdf0e10cSrcweir nYMonth = nY+mnMonthHeight; 634*cdf0e10cSrcweir for ( long j = 0; j < mnMonthPerLine; j++ ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir if ( (rPos.X() < nX) && (rPos.Y() < nYMonth) ) 637*cdf0e10cSrcweir return 0; 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir sal_uInt16 nDaysInMonth = rDate.GetDaysInMonth(); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir // Entsprechender Monat gefunden 642*cdf0e10cSrcweir if ( (rPos.X() > nX) && (rPos.Y() < nYMonth) && 643*cdf0e10cSrcweir (rPos.X() < nX+mnMonthWidth) ) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir if ( rPos.Y() < (nY+(TITLE_BORDERY*2)+mnDayHeight)) 646*cdf0e10cSrcweir return CALENDAR_HITTEST_MONTHTITLE; 647*cdf0e10cSrcweir else 648*cdf0e10cSrcweir { 649*cdf0e10cSrcweir long nDayX = nX+mnDaysOffX; 650*cdf0e10cSrcweir long nDayY = nY+mnDaysOffY; 651*cdf0e10cSrcweir if ( rPos.Y() < nDayY ) 652*cdf0e10cSrcweir return 0; 653*cdf0e10cSrcweir sal_uInt16 nDayIndex = (sal_uInt16)rDate.GetDayOfWeek(); 654*cdf0e10cSrcweir nDayIndex = (nDayIndex+(7-(sal_uInt16)eStartDay)) % 7; 655*cdf0e10cSrcweir if ( (i == 0) && (j == 0) ) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir Date aTempDate = rDate; 658*cdf0e10cSrcweir aTempDate -= nDayIndex; 659*cdf0e10cSrcweir for ( nDay = 0; nDay < nDayIndex; nDay++ ) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir nOffX = nDayX + (nDay*mnDayWidth); 662*cdf0e10cSrcweir if ( (rPos.Y() >= nDayY) && (rPos.Y() < nDayY+mnDayHeight) && 663*cdf0e10cSrcweir (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir rDate = aTempDate; 666*cdf0e10cSrcweir rDate += nDay; 667*cdf0e10cSrcweir return CALENDAR_HITTEST_DAY; 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir for ( nDay = 1; nDay <= nDaysInMonth; nDay++ ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir if ( rPos.Y() < nDayY ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir rDate += nDayIndex; 676*cdf0e10cSrcweir return 0; 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir nOffX = nDayX + (nDayIndex*mnDayWidth); 679*cdf0e10cSrcweir if ( (rPos.Y() >= nDayY) && (rPos.Y() < nDayY+mnDayHeight) && 680*cdf0e10cSrcweir (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir rDate += nDay-1; 683*cdf0e10cSrcweir return CALENDAR_HITTEST_DAY; 684*cdf0e10cSrcweir } 685*cdf0e10cSrcweir if ( nDayIndex == 6 ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir nDayIndex = 0; 688*cdf0e10cSrcweir nDayY += mnDayHeight; 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir else 691*cdf0e10cSrcweir nDayIndex++; 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir if ( (i == mnLines-1) && (j == mnMonthPerLine-1) ) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir sal_uInt16 nWeekDay = (sal_uInt16)rDate.GetDayOfWeek(); 696*cdf0e10cSrcweir nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; 697*cdf0e10cSrcweir sal_uInt16 nDayCount = 42-nDaysInMonth-nWeekDay; 698*cdf0e10cSrcweir Date aTempDate = rDate; 699*cdf0e10cSrcweir aTempDate += nDaysInMonth; 700*cdf0e10cSrcweir for ( nDay = 1; nDay <= nDayCount; nDay++ ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir if ( rPos.Y() < nDayY ) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir rDate += nDayIndex; 705*cdf0e10cSrcweir return 0; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir nOffX = nDayX + (nDayIndex*mnDayWidth); 708*cdf0e10cSrcweir if ( (rPos.Y() >= nDayY) && (rPos.Y() < nDayY+mnDayHeight) && 709*cdf0e10cSrcweir (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir rDate = aTempDate; 712*cdf0e10cSrcweir rDate += nDay-1; 713*cdf0e10cSrcweir return CALENDAR_HITTEST_DAY; 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir if ( nDayIndex == 6 ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir nDayIndex = 0; 718*cdf0e10cSrcweir nDayY += mnDayHeight; 719*cdf0e10cSrcweir } 720*cdf0e10cSrcweir else 721*cdf0e10cSrcweir nDayIndex++; 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir rDate += nDaysInMonth; 728*cdf0e10cSrcweir nX += mnMonthWidth; 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir nY += mnMonthHeight; 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir return 0; 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir // ----------------------------------------------------------------------- 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir static void ImplDrawSpinArrow( OutputDevice* pDev, const Rectangle& rRect, 740*cdf0e10cSrcweir sal_Bool bPrev ) 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir long i; 743*cdf0e10cSrcweir long n; 744*cdf0e10cSrcweir long nLines; 745*cdf0e10cSrcweir long nHeight = rRect.GetHeight(); 746*cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 747*cdf0e10cSrcweir if ( nWidth < nHeight ) 748*cdf0e10cSrcweir n = nWidth; 749*cdf0e10cSrcweir else 750*cdf0e10cSrcweir n = nHeight; 751*cdf0e10cSrcweir if ( !(n & 0x01) ) 752*cdf0e10cSrcweir n--; 753*cdf0e10cSrcweir nLines = n/2; 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir Rectangle aRect( Point( rRect.Left()+(nWidth/2)-(nLines/2), 756*cdf0e10cSrcweir rRect.Top()+(nHeight/2) ), 757*cdf0e10cSrcweir Size( 1, 1 ) ); 758*cdf0e10cSrcweir if ( !bPrev ) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir aRect.Left() += nLines; 761*cdf0e10cSrcweir aRect.Right() += nLines; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir pDev->DrawRect( aRect ); 765*cdf0e10cSrcweir for ( i = 0; i < nLines; i++ ) 766*cdf0e10cSrcweir { 767*cdf0e10cSrcweir if ( bPrev ) 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir aRect.Left()++; 770*cdf0e10cSrcweir aRect.Right()++; 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir else 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir aRect.Left()--; 775*cdf0e10cSrcweir aRect.Right()--; 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir aRect.Top()--; 778*cdf0e10cSrcweir aRect.Bottom()++; 779*cdf0e10cSrcweir pDev->DrawRect( aRect ); 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir // ----------------------------------------------------------------------- 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir void Calendar::ImplDrawSpin( sal_Bool bDrawPrev, sal_Bool bDrawNext ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir if ( !bDrawPrev && !bDrawNext ) 788*cdf0e10cSrcweir return; 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir SetLineColor(); 791*cdf0e10cSrcweir SetFillColor( GetSettings().GetStyleSettings().GetButtonTextColor() ); 792*cdf0e10cSrcweir if ( bDrawPrev ) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir Rectangle aOutRect = maPrevRect; 795*cdf0e10cSrcweir aOutRect.Left() += 3; 796*cdf0e10cSrcweir aOutRect.Top() += 3; 797*cdf0e10cSrcweir aOutRect.Right() -= 3; 798*cdf0e10cSrcweir aOutRect.Bottom() -= 3; 799*cdf0e10cSrcweir ImplDrawSpinArrow( this, aOutRect, sal_True ); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir if ( bDrawNext ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir Rectangle aOutRect = maNextRect; 804*cdf0e10cSrcweir aOutRect.Left() += 3; 805*cdf0e10cSrcweir aOutRect.Top() += 3; 806*cdf0e10cSrcweir aOutRect.Right() -= 3; 807*cdf0e10cSrcweir aOutRect.Bottom() -= 3; 808*cdf0e10cSrcweir ImplDrawSpinArrow( this, aOutRect, sal_False ); 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir // ----------------------------------------------------------------------- 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir void Calendar::ImplDrawDate( long nX, long nY, 815*cdf0e10cSrcweir sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear, 816*cdf0e10cSrcweir DayOfWeek eDayOfWeek, 817*cdf0e10cSrcweir sal_Bool bBack, sal_Bool bOther, sal_uLong nToday ) 818*cdf0e10cSrcweir { 819*cdf0e10cSrcweir ImplDateInfo* pDateInfo; 820*cdf0e10cSrcweir Color* pTextColor = NULL; 821*cdf0e10cSrcweir const String& rDay = *(mpDayText[nDay-1]); 822*cdf0e10cSrcweir Rectangle aDateRect( nX, nY, nX+mnDayWidth-1, nY+mnDayHeight-1 ); 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir sal_Bool bSel = sal_False; 825*cdf0e10cSrcweir sal_Bool bFocus = sal_False; 826*cdf0e10cSrcweir // Aktueller Tag 827*cdf0e10cSrcweir if ( (nDay == maCurDate.GetDay()) && 828*cdf0e10cSrcweir (nMonth == maCurDate.GetMonth()) && 829*cdf0e10cSrcweir (nYear == maCurDate.GetYear()) ) 830*cdf0e10cSrcweir bFocus = sal_True; 831*cdf0e10cSrcweir if ( mpSelectTable ) 832*cdf0e10cSrcweir { 833*cdf0e10cSrcweir if ( mpSelectTable->IsKeyValid( Date( nDay, nMonth, nYear ).GetDate() ) ) 834*cdf0e10cSrcweir bSel = sal_True; 835*cdf0e10cSrcweir } 836*cdf0e10cSrcweir 837*cdf0e10cSrcweir // Dateinfo ermitteln 838*cdf0e10cSrcweir if ( mpDateTable ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir pDateInfo = mpDateTable->Get( Date( nDay, nMonth, nYear ).GetDate() ); 841*cdf0e10cSrcweir if ( !pDateInfo ) 842*cdf0e10cSrcweir pDateInfo = mpDateTable->Get( Date( nDay, nMonth, 0 ).GetDate() ); 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir else 845*cdf0e10cSrcweir pDateInfo = NULL; 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir // Textfarbe ermitteln 848*cdf0e10cSrcweir if ( bSel ) 849*cdf0e10cSrcweir pTextColor = &maSelColor; 850*cdf0e10cSrcweir else if ( bOther ) 851*cdf0e10cSrcweir pTextColor = &maOtherColor; 852*cdf0e10cSrcweir else 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir if ( pDateInfo && pDateInfo->mpTextColor ) 855*cdf0e10cSrcweir pTextColor = pDateInfo->mpTextColor; 856*cdf0e10cSrcweir else 857*cdf0e10cSrcweir { 858*cdf0e10cSrcweir if ( eDayOfWeek == SATURDAY ) 859*cdf0e10cSrcweir pTextColor = mpSaturdayColor; 860*cdf0e10cSrcweir else if ( eDayOfWeek == SUNDAY ) 861*cdf0e10cSrcweir pTextColor = mpSundayColor; 862*cdf0e10cSrcweir if ( !pTextColor ) 863*cdf0e10cSrcweir pTextColor = mpStandardColor; 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir if ( bFocus ) 868*cdf0e10cSrcweir HideFocus(); 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir // Font ermitteln 871*cdf0e10cSrcweir Font aOldFont = GetFont(); 872*cdf0e10cSrcweir sal_Bool bBoldFont = sal_False; 873*cdf0e10cSrcweir if ( (mnWinStyle & WB_BOLDTEXT) && 874*cdf0e10cSrcweir pDateInfo && (pDateInfo->mnFlags & DIB_BOLD) ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir bBoldFont = sal_True; 877*cdf0e10cSrcweir Font aFont = aOldFont; 878*cdf0e10cSrcweir if ( aFont.GetWeight() < WEIGHT_BOLD ) 879*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD ); 880*cdf0e10cSrcweir else 881*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_NORMAL ); 882*cdf0e10cSrcweir SetFont( aFont ); 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir // Hintergrund ausgeben 886*cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 887*cdf0e10cSrcweir if ( bSel || bBack ) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir if ( bSel ) 890*cdf0e10cSrcweir { 891*cdf0e10cSrcweir SetLineColor(); 892*cdf0e10cSrcweir SetFillColor( rStyleSettings.GetHighlightColor() ); 893*cdf0e10cSrcweir DrawRect( aDateRect ); 894*cdf0e10cSrcweir } 895*cdf0e10cSrcweir else 896*cdf0e10cSrcweir Erase( aDateRect ); 897*cdf0e10cSrcweir } 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir // Text ausgeben 900*cdf0e10cSrcweir long nTextX = nX+(mnDayWidth-GetTextWidth( rDay ))-(DAY_OFFX/2); 901*cdf0e10cSrcweir long nTextY = nY+(mnDayHeight-GetTextHeight())/2; 902*cdf0e10cSrcweir if ( pTextColor ) 903*cdf0e10cSrcweir { 904*cdf0e10cSrcweir Color aOldColor = GetTextColor(); 905*cdf0e10cSrcweir SetTextColor( *pTextColor ); 906*cdf0e10cSrcweir DrawText( Point( nTextX, nTextY ), rDay ); 907*cdf0e10cSrcweir SetTextColor( aOldColor ); 908*cdf0e10cSrcweir } 909*cdf0e10cSrcweir else 910*cdf0e10cSrcweir DrawText( Point( nTextX, nTextY ), rDay ); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir // Heute 913*cdf0e10cSrcweir Date aTodayDate( maCurDate ); 914*cdf0e10cSrcweir if ( nToday ) 915*cdf0e10cSrcweir aTodayDate.SetDate( nToday ); 916*cdf0e10cSrcweir else 917*cdf0e10cSrcweir aTodayDate = Date(); 918*cdf0e10cSrcweir if ( (nDay == aTodayDate.GetDay()) && 919*cdf0e10cSrcweir (nMonth == aTodayDate.GetMonth()) && 920*cdf0e10cSrcweir (nYear == aTodayDate.GetYear()) ) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetWindowTextColor() ); 923*cdf0e10cSrcweir SetFillColor(); 924*cdf0e10cSrcweir DrawRect( aDateRect ); 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir // Evt. DateInfo ausgeben 928*cdf0e10cSrcweir if ( (mnWinStyle & WB_FRAMEINFO) && pDateInfo && pDateInfo->mpFrameColor ) 929*cdf0e10cSrcweir { 930*cdf0e10cSrcweir SetLineColor( *(pDateInfo->mpFrameColor) ); 931*cdf0e10cSrcweir SetFillColor(); 932*cdf0e10cSrcweir Rectangle aFrameRect( aDateRect ); 933*cdf0e10cSrcweir aFrameRect.Left()++; 934*cdf0e10cSrcweir aFrameRect.Top()++; 935*cdf0e10cSrcweir long nFrameWidth = aFrameRect.GetWidth(); 936*cdf0e10cSrcweir long nFrameHeight = aFrameRect.GetHeight(); 937*cdf0e10cSrcweir long nFrameOff; 938*cdf0e10cSrcweir if ( nFrameWidth < nFrameHeight ) 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir nFrameOff = nFrameHeight-nFrameWidth; 941*cdf0e10cSrcweir aFrameRect.Top() += nFrameOff/2; 942*cdf0e10cSrcweir nFrameOff %= 2; 943*cdf0e10cSrcweir aFrameRect.Bottom() -= nFrameOff; 944*cdf0e10cSrcweir } 945*cdf0e10cSrcweir else if ( nFrameWidth > nFrameHeight ) 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir nFrameOff = nFrameWidth-nFrameHeight; 948*cdf0e10cSrcweir aFrameRect.Left() += nFrameOff/2; 949*cdf0e10cSrcweir nFrameOff %= 2; 950*cdf0e10cSrcweir aFrameRect.Right() -= nFrameOff; 951*cdf0e10cSrcweir } 952*cdf0e10cSrcweir DrawEllipse( aFrameRect ); 953*cdf0e10cSrcweir } 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir // Evt. noch FocusRect 956*cdf0e10cSrcweir if ( bFocus && HasFocus() ) 957*cdf0e10cSrcweir ShowFocus( aDateRect ); 958*cdf0e10cSrcweir 959*cdf0e10cSrcweir if( mbDropPos && maDropDate == Date( nDay, nMonth, nYear ) ) 960*cdf0e10cSrcweir ImplInvertDropPos(); 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir if ( bBoldFont ) 963*cdf0e10cSrcweir SetFont( aOldFont ); 964*cdf0e10cSrcweir } 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir // ----------------------------------------------------------------------- 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir void Calendar::ImplDraw( sal_Bool bPaint ) 969*cdf0e10cSrcweir { 970*cdf0e10cSrcweir ImplFormat(); 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 973*cdf0e10cSrcweir Size aOutSize = GetOutputSizePixel(); 974*cdf0e10cSrcweir long i; 975*cdf0e10cSrcweir long j; 976*cdf0e10cSrcweir long nX; 977*cdf0e10cSrcweir long nY; 978*cdf0e10cSrcweir long nDeltaX; 979*cdf0e10cSrcweir long nDeltaY; 980*cdf0e10cSrcweir long nDayX; 981*cdf0e10cSrcweir long nDayY; 982*cdf0e10cSrcweir sal_uLong nToday = Date().GetDate(); 983*cdf0e10cSrcweir sal_uInt16 nDay; 984*cdf0e10cSrcweir sal_uInt16 nMonth; 985*cdf0e10cSrcweir sal_uInt16 nYear; 986*cdf0e10cSrcweir Date aDate = GetFirstMonth(); 987*cdf0e10cSrcweir DayOfWeek eStartDay = ImplGetWeekStart(); 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir HideFocus(); 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir nY = 0; 992*cdf0e10cSrcweir for ( i = 0; i < mnLines; i++ ) 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir // Titleleiste ausgeben 995*cdf0e10cSrcweir SetLineColor(); 996*cdf0e10cSrcweir SetFillColor( rStyleSettings.GetFaceColor() ); 997*cdf0e10cSrcweir Rectangle aTitleRect( 0, nY, aOutSize.Width()-1, nY+mnDayHeight-DAY_OFFY+TITLE_BORDERY*2 ); 998*cdf0e10cSrcweir if ( !bPaint ) 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir Rectangle aTempRect( 1, aTitleRect.Top()+TITLE_BORDERY, 1001*cdf0e10cSrcweir aOutSize.Width()-2, 1002*cdf0e10cSrcweir aTitleRect.Bottom()-TITLE_BORDERY ); 1003*cdf0e10cSrcweir if ( !i ) 1004*cdf0e10cSrcweir { 1005*cdf0e10cSrcweir aTempRect.Left() = maPrevRect.Right()+1; 1006*cdf0e10cSrcweir aTempRect.Right() = maNextRect.Left()-1; 1007*cdf0e10cSrcweir } 1008*cdf0e10cSrcweir DrawRect( aTempRect ); 1009*cdf0e10cSrcweir } 1010*cdf0e10cSrcweir else 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir DrawRect( aTitleRect ); 1013*cdf0e10cSrcweir Point aTopLeft1( aTitleRect.Left(), aTitleRect.Top() ); 1014*cdf0e10cSrcweir Point aTopLeft2( aTitleRect.Left(), aTitleRect.Top()+1 ); 1015*cdf0e10cSrcweir Point aBottomRight1( aTitleRect.Right(), aTitleRect.Bottom() ); 1016*cdf0e10cSrcweir Point aBottomRight2( aTitleRect.Right(), aTitleRect.Bottom()-1 ); 1017*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetDarkShadowColor() ); 1018*cdf0e10cSrcweir DrawLine( aTopLeft1, Point( aBottomRight1.X(), aTopLeft1.Y() ) ); 1019*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetLightColor() ); 1020*cdf0e10cSrcweir DrawLine( aTopLeft2, Point( aBottomRight2.X(), aTopLeft2.Y() ) ); 1021*cdf0e10cSrcweir DrawLine( aTopLeft2, Point( aTopLeft2.X(), aBottomRight2.Y() ) ); 1022*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetShadowColor() ); 1023*cdf0e10cSrcweir DrawLine( Point( aTopLeft2.X(), aBottomRight2.Y() ), aBottomRight2 ); 1024*cdf0e10cSrcweir DrawLine( Point( aBottomRight2.X(), aTopLeft2.Y() ), aBottomRight2 ); 1025*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetDarkShadowColor() ); 1026*cdf0e10cSrcweir DrawLine( Point( aTopLeft1.X(), aBottomRight1.Y() ), aBottomRight1 ); 1027*cdf0e10cSrcweir } 1028*cdf0e10cSrcweir Point aSepPos1( 0, aTitleRect.Top()+TITLE_BORDERY ); 1029*cdf0e10cSrcweir Point aSepPos2( 0, aTitleRect.Bottom()-TITLE_BORDERY ); 1030*cdf0e10cSrcweir for ( j = 0; j < mnMonthPerLine-1; j++ ) 1031*cdf0e10cSrcweir { 1032*cdf0e10cSrcweir aSepPos1.X() += mnMonthWidth-1; 1033*cdf0e10cSrcweir aSepPos2.X() = aSepPos1.X(); 1034*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetShadowColor() ); 1035*cdf0e10cSrcweir DrawLine( aSepPos1, aSepPos2 ); 1036*cdf0e10cSrcweir aSepPos1.X()++; 1037*cdf0e10cSrcweir aSepPos2.X() = aSepPos1.X(); 1038*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetLightColor() ); 1039*cdf0e10cSrcweir DrawLine( aSepPos1, aSepPos2 ); 1040*cdf0e10cSrcweir } 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir nX = 0; 1043*cdf0e10cSrcweir for ( j = 0; j < mnMonthPerLine; j++ ) 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir nMonth = aDate.GetMonth(); 1046*cdf0e10cSrcweir nYear = aDate.GetYear(); 1047*cdf0e10cSrcweir 1048*cdf0e10cSrcweir // Monat in der Titleleiste ausgeben 1049*cdf0e10cSrcweir nDeltaX = nX; 1050*cdf0e10cSrcweir nDeltaY = nY+TITLE_BORDERY; 1051*cdf0e10cSrcweir String aMonthText( maCalendarWrapper.getDisplayName( 1052*cdf0e10cSrcweir i18n::CalendarDisplayIndex::MONTH, nMonth-1, 1)); 1053*cdf0e10cSrcweir aMonthText += ' '; 1054*cdf0e10cSrcweir aMonthText += String::CreateFromInt64( nYear ); 1055*cdf0e10cSrcweir long nMonthTextWidth = GetTextWidth( aMonthText ); 1056*cdf0e10cSrcweir long nMonthOffX1 = 0; 1057*cdf0e10cSrcweir long nMonthOffX2 = 0; 1058*cdf0e10cSrcweir if ( i == 0 ) 1059*cdf0e10cSrcweir { 1060*cdf0e10cSrcweir if ( j == 0 ) 1061*cdf0e10cSrcweir nMonthOffX1 = maPrevRect.Right()+1; 1062*cdf0e10cSrcweir if ( j == mnMonthPerLine-1 ) 1063*cdf0e10cSrcweir nMonthOffX2 = aOutSize.Width()-maNextRect.Left()+1; 1064*cdf0e10cSrcweir } 1065*cdf0e10cSrcweir long nMaxMonthWidth = mnMonthWidth-nMonthOffX1-nMonthOffX2-4; 1066*cdf0e10cSrcweir if ( nMonthTextWidth > nMaxMonthWidth ) 1067*cdf0e10cSrcweir { 1068*cdf0e10cSrcweir // Abbreviated month name. 1069*cdf0e10cSrcweir aMonthText = maCalendarWrapper.getDisplayName( 1070*cdf0e10cSrcweir i18n::CalendarDisplayIndex::MONTH, nMonth-1, 0); 1071*cdf0e10cSrcweir aMonthText += ' '; 1072*cdf0e10cSrcweir aMonthText += String::CreateFromInt64( nYear ); 1073*cdf0e10cSrcweir nMonthTextWidth = GetTextWidth( aMonthText ); 1074*cdf0e10cSrcweir } 1075*cdf0e10cSrcweir long nTempOff = (mnMonthWidth-nMonthTextWidth+1)/2; 1076*cdf0e10cSrcweir if ( nTempOff < nMonthOffX1 ) 1077*cdf0e10cSrcweir nDeltaX += nMonthOffX1+1; 1078*cdf0e10cSrcweir else 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir if ( nTempOff+nMonthTextWidth > mnMonthWidth-nMonthOffX2 ) 1081*cdf0e10cSrcweir nDeltaX += mnMonthWidth-nMonthOffX2-nMonthTextWidth; 1082*cdf0e10cSrcweir else 1083*cdf0e10cSrcweir nDeltaX += nTempOff; 1084*cdf0e10cSrcweir } 1085*cdf0e10cSrcweir SetTextColor( rStyleSettings.GetButtonTextColor() ); 1086*cdf0e10cSrcweir DrawText( Point( nDeltaX, nDeltaY ), aMonthText ); 1087*cdf0e10cSrcweir SetTextColor( rStyleSettings.GetWindowTextColor() ); 1088*cdf0e10cSrcweir 1089*cdf0e10cSrcweir // Weekleiste ausgeben 1090*cdf0e10cSrcweir if ( bPaint ) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir nDayX = nX+mnDaysOffX; 1093*cdf0e10cSrcweir nDayY = nY+mnWeekDayOffY; 1094*cdf0e10cSrcweir nDeltaY = nDayY + mnDayHeight; 1095*cdf0e10cSrcweir SetLineColor( rStyleSettings.GetWindowTextColor() ); 1096*cdf0e10cSrcweir Point aStartPos( nDayX, nDeltaY ); 1097*cdf0e10cSrcweir if ( mnWinStyle & WB_WEEKNUMBER ) 1098*cdf0e10cSrcweir aStartPos.X() -= WEEKNUMBER_OFFX-2; 1099*cdf0e10cSrcweir DrawLine( aStartPos, Point( nDayX+(7*mnDayWidth), nDeltaY ) ); 1100*cdf0e10cSrcweir DrawTextArray( Point( nDayX+mnDayOfWeekAry[0], nDayY ), maDayOfWeekText, &(mnDayOfWeekAry[1]) ); 1101*cdf0e10cSrcweir } 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir // Week-Numbers ausgeben 1104*cdf0e10cSrcweir if ( mnWinStyle & WB_WEEKNUMBER ) 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir nDayX = nX+mnDaysOffX; 1107*cdf0e10cSrcweir nDayY = nY+mnWeekDayOffY; 1108*cdf0e10cSrcweir nDeltaY = nDayY + mnDayHeight; 1109*cdf0e10cSrcweir long nMonthHeight = mnDayHeight*6; 1110*cdf0e10cSrcweir if ( bPaint ) 1111*cdf0e10cSrcweir DrawLine( Point( nDayX-WEEKNUMBER_OFFX+2, nDeltaY ), Point( nDayX-WEEKNUMBER_OFFX+2, nDeltaY+nMonthHeight ) ); 1112*cdf0e10cSrcweir else 1113*cdf0e10cSrcweir Erase( Rectangle( nDayX-mnWeekWidth-WEEKNUMBER_OFFX, nDeltaY, nDayX-WEEKNUMBER_OFFX-1, nDeltaY+nMonthHeight ) ); 1114*cdf0e10cSrcweir 1115*cdf0e10cSrcweir Font aOldFont = GetFont(); 1116*cdf0e10cSrcweir Font aTempFont = aOldFont; 1117*cdf0e10cSrcweir ImplGetWeekFont( aTempFont ); 1118*cdf0e10cSrcweir SetFont( aTempFont ); 1119*cdf0e10cSrcweir nDayX -= mnWeekWidth; 1120*cdf0e10cSrcweir nDayY = nY+mnDaysOffY; 1121*cdf0e10cSrcweir maCalendarWrapper.setGregorianDateTime( aDate); 1122*cdf0e10cSrcweir for ( sal_uInt16 nWeekCount = 0; nWeekCount < 6; nWeekCount++ ) 1123*cdf0e10cSrcweir { 1124*cdf0e10cSrcweir sal_Int16 nWeek = maCalendarWrapper.getValue( i18n::CalendarFieldIndex::WEEK_OF_YEAR); 1125*cdf0e10cSrcweir String aWeekText( String::CreateFromInt32( nWeek)); 1126*cdf0e10cSrcweir long nOffX = (mnWeekWidth-WEEKNUMBER_OFFX)-GetTextWidth( aWeekText ); 1127*cdf0e10cSrcweir long nOffY = (mnDayHeight-GetTextHeight())/2; 1128*cdf0e10cSrcweir DrawText( Point( nDayX+nOffX, nDayY+nOffY ), aWeekText ); 1129*cdf0e10cSrcweir nDayY += mnDayHeight; 1130*cdf0e10cSrcweir maCalendarWrapper.addValue( i18n::CalendarFieldIndex::DAY_OF_MONTH, 7); 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir SetFont( aOldFont ); 1133*cdf0e10cSrcweir } 1134*cdf0e10cSrcweir 1135*cdf0e10cSrcweir // Tage ausgeben 1136*cdf0e10cSrcweir sal_uInt16 nDaysInMonth = aDate.GetDaysInMonth(); 1137*cdf0e10cSrcweir nDayX = nX+mnDaysOffX; 1138*cdf0e10cSrcweir nDayY = nY+mnDaysOffY; 1139*cdf0e10cSrcweir if ( !bPaint ) 1140*cdf0e10cSrcweir { 1141*cdf0e10cSrcweir Rectangle aClearRect( nDayX, nDayY, 1142*cdf0e10cSrcweir nDayX+(7*mnDayWidth)-1, nDayY+(6*mnDayHeight)-1 ); 1143*cdf0e10cSrcweir Erase( aClearRect ); 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir sal_uInt16 nDayIndex = (sal_uInt16)aDate.GetDayOfWeek(); 1146*cdf0e10cSrcweir nDayIndex = (nDayIndex+(7-(sal_uInt16)eStartDay)) % 7; 1147*cdf0e10cSrcweir if ( (i == 0) && (j == 0) ) 1148*cdf0e10cSrcweir { 1149*cdf0e10cSrcweir Date aTempDate = aDate; 1150*cdf0e10cSrcweir aTempDate -= nDayIndex; 1151*cdf0e10cSrcweir for ( nDay = 0; nDay < nDayIndex; nDay++ ) 1152*cdf0e10cSrcweir { 1153*cdf0e10cSrcweir nDeltaX = nDayX + (nDay*mnDayWidth); 1154*cdf0e10cSrcweir ImplDrawDate( nDeltaX, nDayY, nDay+aTempDate.GetDay(), 1155*cdf0e10cSrcweir aTempDate.GetMonth(), aTempDate.GetYear(), 1156*cdf0e10cSrcweir (DayOfWeek)((nDay+(sal_uInt16)eStartDay)%7), sal_False, sal_True, nToday ); 1157*cdf0e10cSrcweir } 1158*cdf0e10cSrcweir } 1159*cdf0e10cSrcweir for ( nDay = 1; nDay <= nDaysInMonth; nDay++ ) 1160*cdf0e10cSrcweir { 1161*cdf0e10cSrcweir nDeltaX = nDayX + (nDayIndex*mnDayWidth); 1162*cdf0e10cSrcweir ImplDrawDate( nDeltaX, nDayY, nDay, nMonth, nYear, 1163*cdf0e10cSrcweir (DayOfWeek)((nDayIndex+(sal_uInt16)eStartDay)%7), 1164*cdf0e10cSrcweir sal_False, sal_False, nToday ); 1165*cdf0e10cSrcweir if ( nDayIndex == 6 ) 1166*cdf0e10cSrcweir { 1167*cdf0e10cSrcweir nDayIndex = 0; 1168*cdf0e10cSrcweir nDayY += mnDayHeight; 1169*cdf0e10cSrcweir } 1170*cdf0e10cSrcweir else 1171*cdf0e10cSrcweir nDayIndex++; 1172*cdf0e10cSrcweir } 1173*cdf0e10cSrcweir if ( (i == mnLines-1) && (j == mnMonthPerLine-1) ) 1174*cdf0e10cSrcweir { 1175*cdf0e10cSrcweir sal_uInt16 nWeekDay = (sal_uInt16)aDate.GetDayOfWeek(); 1176*cdf0e10cSrcweir nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; 1177*cdf0e10cSrcweir sal_uInt16 nDayCount = 42-nDaysInMonth-nWeekDay; 1178*cdf0e10cSrcweir Date aTempDate = aDate; 1179*cdf0e10cSrcweir aTempDate += nDaysInMonth; 1180*cdf0e10cSrcweir for ( nDay = 1; nDay <= nDayCount; nDay++ ) 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir nDeltaX = nDayX + (nDayIndex*mnDayWidth); 1183*cdf0e10cSrcweir ImplDrawDate( nDeltaX, nDayY, nDay, 1184*cdf0e10cSrcweir aTempDate.GetMonth(), aTempDate.GetYear(), 1185*cdf0e10cSrcweir (DayOfWeek)((nDayIndex+(sal_uInt16)eStartDay)%7), 1186*cdf0e10cSrcweir sal_False, sal_True, nToday ); 1187*cdf0e10cSrcweir if ( nDayIndex == 6 ) 1188*cdf0e10cSrcweir { 1189*cdf0e10cSrcweir nDayIndex = 0; 1190*cdf0e10cSrcweir nDayY += mnDayHeight; 1191*cdf0e10cSrcweir } 1192*cdf0e10cSrcweir else 1193*cdf0e10cSrcweir nDayIndex++; 1194*cdf0e10cSrcweir } 1195*cdf0e10cSrcweir } 1196*cdf0e10cSrcweir 1197*cdf0e10cSrcweir aDate += nDaysInMonth; 1198*cdf0e10cSrcweir nX += mnMonthWidth; 1199*cdf0e10cSrcweir } 1200*cdf0e10cSrcweir 1201*cdf0e10cSrcweir nY += mnMonthHeight; 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir // Spin-Buttons zeichnen 1205*cdf0e10cSrcweir if ( bPaint ) 1206*cdf0e10cSrcweir ImplDrawSpin(); 1207*cdf0e10cSrcweir } 1208*cdf0e10cSrcweir 1209*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir void Calendar::ImplUpdateDate( const Date& rDate ) 1212*cdf0e10cSrcweir { 1213*cdf0e10cSrcweir if ( IsReallyVisible() && IsUpdateMode() ) 1214*cdf0e10cSrcweir { 1215*cdf0e10cSrcweir Rectangle aDateRect( GetDateRect( rDate ) ); 1216*cdf0e10cSrcweir if ( !aDateRect.IsEmpty() ) 1217*cdf0e10cSrcweir { 1218*cdf0e10cSrcweir sal_Bool bOther = (rDate < GetFirstMonth()) || (rDate > GetLastMonth()); 1219*cdf0e10cSrcweir ImplDrawDate( aDateRect.Left(), aDateRect.Top(), 1220*cdf0e10cSrcweir rDate.GetDay(), rDate.GetMonth(), rDate.GetYear(), 1221*cdf0e10cSrcweir rDate.GetDayOfWeek(), sal_True, bOther ); 1222*cdf0e10cSrcweir } 1223*cdf0e10cSrcweir } 1224*cdf0e10cSrcweir } 1225*cdf0e10cSrcweir 1226*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1227*cdf0e10cSrcweir 1228*cdf0e10cSrcweir void Calendar::ImplUpdateSelection( Table* pOld ) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir Table* pNew = mpSelectTable; 1231*cdf0e10cSrcweir void* p; 1232*cdf0e10cSrcweir sal_uLong nKey; 1233*cdf0e10cSrcweir 1234*cdf0e10cSrcweir p = pOld->First(); 1235*cdf0e10cSrcweir while ( p ) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir nKey = pOld->GetCurKey(); 1238*cdf0e10cSrcweir if ( !pNew->Get( nKey ) ) 1239*cdf0e10cSrcweir { 1240*cdf0e10cSrcweir Date aTempDate( nKey ); 1241*cdf0e10cSrcweir ImplUpdateDate( aTempDate ); 1242*cdf0e10cSrcweir } 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir p = pOld->Next(); 1245*cdf0e10cSrcweir } 1246*cdf0e10cSrcweir 1247*cdf0e10cSrcweir p = pNew->First(); 1248*cdf0e10cSrcweir while ( p ) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir nKey = pNew->GetCurKey(); 1251*cdf0e10cSrcweir if ( !pOld->Get( nKey ) ) 1252*cdf0e10cSrcweir { 1253*cdf0e10cSrcweir Date aTempDate( nKey ); 1254*cdf0e10cSrcweir ImplUpdateDate( aTempDate ); 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir p = pNew->Next(); 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir } 1260*cdf0e10cSrcweir 1261*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest, 1264*cdf0e10cSrcweir sal_Bool bMove, sal_Bool bExpand, sal_Bool bExtended ) 1265*cdf0e10cSrcweir { 1266*cdf0e10cSrcweir Table* pOldSel = new Table( *mpSelectTable ); 1267*cdf0e10cSrcweir Date aOldDate = maCurDate; 1268*cdf0e10cSrcweir Date aTempDate = rDate; 1269*cdf0e10cSrcweir 1270*cdf0e10cSrcweir if ( !(nHitTest & CALENDAR_HITTEST_DAY) ) 1271*cdf0e10cSrcweir aTempDate--; 1272*cdf0e10cSrcweir 1273*cdf0e10cSrcweir if ( mbMultiSelection ) 1274*cdf0e10cSrcweir { 1275*cdf0e10cSrcweir maCurDate = aTempDate; 1276*cdf0e10cSrcweir mbSelLeft = aTempDate < maAnchorDate; 1277*cdf0e10cSrcweir 1278*cdf0e10cSrcweir if ( bMove ) 1279*cdf0e10cSrcweir { 1280*cdf0e10cSrcweir if ( mbSelLeft ) 1281*cdf0e10cSrcweir { 1282*cdf0e10cSrcweir ImplCalendarUnSelectDateRange( mpSelectTable, mpRestoreSelectTable, Date( 1, 1, 0 ), aTempDate ); 1283*cdf0e10cSrcweir ImplCalendarUnSelectDateRange( mpSelectTable, mpRestoreSelectTable, maAnchorDate, Date( 31, 12, 9999 ) ); 1284*cdf0e10cSrcweir } 1285*cdf0e10cSrcweir else 1286*cdf0e10cSrcweir { 1287*cdf0e10cSrcweir ImplCalendarUnSelectDateRange( mpSelectTable, mpRestoreSelectTable, Date( 1, 1, 0 ), maAnchorDate ); 1288*cdf0e10cSrcweir ImplCalendarUnSelectDateRange( mpSelectTable, mpRestoreSelectTable, aTempDate, Date( 31, 12, 9999 ) ); 1289*cdf0e10cSrcweir } 1290*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, aTempDate, maAnchorDate, !mbUnSel ); 1291*cdf0e10cSrcweir } 1292*cdf0e10cSrcweir else 1293*cdf0e10cSrcweir { 1294*cdf0e10cSrcweir if ( bExpand ) 1295*cdf0e10cSrcweir { 1296*cdf0e10cSrcweir if ( !bExtended ) 1297*cdf0e10cSrcweir { 1298*cdf0e10cSrcweir if ( mbSelLeft ) 1299*cdf0e10cSrcweir { 1300*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, Date( 1, 1, 0 ), aTempDate, sal_False ); 1301*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, maAnchorDate, Date( 31, 12, 9999 ), sal_False ); 1302*cdf0e10cSrcweir } 1303*cdf0e10cSrcweir else 1304*cdf0e10cSrcweir { 1305*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, Date( 1, 1, 0 ), maAnchorDate, sal_False ); 1306*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, aTempDate, Date( 31, 12, 9999 ), sal_False ); 1307*cdf0e10cSrcweir } 1308*cdf0e10cSrcweir } 1309*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, aTempDate, maAnchorDate, sal_True ); 1310*cdf0e10cSrcweir } 1311*cdf0e10cSrcweir else if ( bExtended && !(mnWinStyle & WB_RANGESELECT) ) 1312*cdf0e10cSrcweir { 1313*cdf0e10cSrcweir maAnchorDate = aTempDate; 1314*cdf0e10cSrcweir if ( IsDateSelected( aTempDate ) ) 1315*cdf0e10cSrcweir { 1316*cdf0e10cSrcweir mbUnSel = sal_True; 1317*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, aTempDate, sal_False ); 1318*cdf0e10cSrcweir } 1319*cdf0e10cSrcweir else 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, aTempDate, sal_True ); 1322*cdf0e10cSrcweir } 1323*cdf0e10cSrcweir } 1324*cdf0e10cSrcweir else 1325*cdf0e10cSrcweir { 1326*cdf0e10cSrcweir maAnchorDate = aTempDate; 1327*cdf0e10cSrcweir ImplCalendarClearSelectDate( mpSelectTable ); 1328*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, aTempDate, sal_True ); 1329*cdf0e10cSrcweir } 1330*cdf0e10cSrcweir 1331*cdf0e10cSrcweir mpRestoreSelectTable = new Table( *mpSelectTable ); 1332*cdf0e10cSrcweir } 1333*cdf0e10cSrcweir } 1334*cdf0e10cSrcweir else 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir if ( aTempDate < maCurDate ) 1337*cdf0e10cSrcweir mbSelLeft = sal_True; 1338*cdf0e10cSrcweir else 1339*cdf0e10cSrcweir mbSelLeft = sal_False; 1340*cdf0e10cSrcweir if ( !(nHitTest & CALENDAR_HITTEST_DAY) ) 1341*cdf0e10cSrcweir aTempDate = maOldCurDate; 1342*cdf0e10cSrcweir if ( !bMove ) 1343*cdf0e10cSrcweir maAnchorDate = aTempDate; 1344*cdf0e10cSrcweir if ( aTempDate != maCurDate ) 1345*cdf0e10cSrcweir { 1346*cdf0e10cSrcweir maCurDate = aTempDate; 1347*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, aOldDate, sal_False ); 1348*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, maCurDate, sal_True ); 1349*cdf0e10cSrcweir } 1350*cdf0e10cSrcweir } 1351*cdf0e10cSrcweir 1352*cdf0e10cSrcweir sal_Bool bNewSel = *pOldSel != *mpSelectTable; 1353*cdf0e10cSrcweir if ( (maCurDate != aOldDate) || bNewSel ) 1354*cdf0e10cSrcweir { 1355*cdf0e10cSrcweir if ( bNewSel ) 1356*cdf0e10cSrcweir { 1357*cdf0e10cSrcweir mbInSelChange = sal_True; 1358*cdf0e10cSrcweir SelectionChanging(); 1359*cdf0e10cSrcweir mbInSelChange = sal_False; 1360*cdf0e10cSrcweir } 1361*cdf0e10cSrcweir HideFocus(); 1362*cdf0e10cSrcweir if ( bNewSel ) 1363*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 1364*cdf0e10cSrcweir if ( !bNewSel || !pOldSel->Get( aOldDate.GetDate() ) ) 1365*cdf0e10cSrcweir ImplUpdateDate( aOldDate ); 1366*cdf0e10cSrcweir // Damit Focus-Rechteck auch wieder neu ausgegeben wird 1367*cdf0e10cSrcweir if ( HasFocus() || !bNewSel || !mpSelectTable->Get( maCurDate.GetDate() ) ) 1368*cdf0e10cSrcweir ImplUpdateDate( maCurDate ); 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir delete pOldSel; 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir void Calendar::ImplUpdate( sal_Bool bCalcNew ) 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir if ( IsReallyVisible() && IsUpdateMode() ) 1378*cdf0e10cSrcweir { 1379*cdf0e10cSrcweir if ( bCalcNew && !mbCalc ) 1380*cdf0e10cSrcweir Invalidate(); 1381*cdf0e10cSrcweir else if ( !mbFormat && !mbCalc ) 1382*cdf0e10cSrcweir { 1383*cdf0e10cSrcweir if ( mbDirect ) 1384*cdf0e10cSrcweir { 1385*cdf0e10cSrcweir mbFormat = sal_True; 1386*cdf0e10cSrcweir ImplDraw( sal_False ); 1387*cdf0e10cSrcweir return; 1388*cdf0e10cSrcweir } 1389*cdf0e10cSrcweir else 1390*cdf0e10cSrcweir Invalidate(); 1391*cdf0e10cSrcweir } 1392*cdf0e10cSrcweir } 1393*cdf0e10cSrcweir 1394*cdf0e10cSrcweir if ( bCalcNew ) 1395*cdf0e10cSrcweir mbCalc = sal_True; 1396*cdf0e10cSrcweir mbFormat = sal_True; 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir 1399*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1400*cdf0e10cSrcweir 1401*cdf0e10cSrcweir void Calendar::ImplInvertDropPos() 1402*cdf0e10cSrcweir { 1403*cdf0e10cSrcweir Rectangle aRect = GetDateRect( maDropDate );//this is one Pixel to width and one to heigh 1404*cdf0e10cSrcweir aRect.Bottom() = aRect.Top()+mnDayHeight-1; 1405*cdf0e10cSrcweir aRect.Right() = aRect.Left()+mnDayWidth-1; 1406*cdf0e10cSrcweir Invert( aRect ); 1407*cdf0e10cSrcweir } 1408*cdf0e10cSrcweir 1409*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweir void Calendar::ImplScroll( sal_Bool bPrev ) 1412*cdf0e10cSrcweir { 1413*cdf0e10cSrcweir Date aNewFirstMonth = GetFirstMonth(); 1414*cdf0e10cSrcweir if ( bPrev ) 1415*cdf0e10cSrcweir { 1416*cdf0e10cSrcweir aNewFirstMonth--; 1417*cdf0e10cSrcweir aNewFirstMonth -= aNewFirstMonth.GetDaysInMonth()-1; 1418*cdf0e10cSrcweir } 1419*cdf0e10cSrcweir else 1420*cdf0e10cSrcweir aNewFirstMonth += aNewFirstMonth.GetDaysInMonth(); 1421*cdf0e10cSrcweir mbDirect = sal_True; 1422*cdf0e10cSrcweir SetFirstDate( aNewFirstMonth ); 1423*cdf0e10cSrcweir mbDirect = sal_False; 1424*cdf0e10cSrcweir } 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1427*cdf0e10cSrcweir 1428*cdf0e10cSrcweir void Calendar::ImplShowMenu( const Point& rPos, const Date& rDate ) 1429*cdf0e10cSrcweir { 1430*cdf0e10cSrcweir EndSelection(); 1431*cdf0e10cSrcweir 1432*cdf0e10cSrcweir Date aOldFirstDate = GetFirstMonth(); 1433*cdf0e10cSrcweir PopupMenu aPopupMenu; 1434*cdf0e10cSrcweir PopupMenu* pYearPopupMenus[MENU_YEAR_COUNT]; 1435*cdf0e10cSrcweir sal_uInt16 nMonthOff; 1436*cdf0e10cSrcweir sal_uInt16 nCurItemId; 1437*cdf0e10cSrcweir sal_uInt16 nYear = rDate.GetYear()-1; 1438*cdf0e10cSrcweir sal_uInt16 i; 1439*cdf0e10cSrcweir sal_uInt16 j; 1440*cdf0e10cSrcweir sal_uInt16 nYearIdCount = 1000; 1441*cdf0e10cSrcweir 1442*cdf0e10cSrcweir nMonthOff = (rDate.GetYear()-aOldFirstDate.GetYear())*12; 1443*cdf0e10cSrcweir if ( aOldFirstDate.GetMonth() < rDate.GetMonth() ) 1444*cdf0e10cSrcweir nMonthOff += rDate.GetMonth()-aOldFirstDate.GetMonth(); 1445*cdf0e10cSrcweir else 1446*cdf0e10cSrcweir nMonthOff -= aOldFirstDate.GetMonth()-rDate.GetMonth(); 1447*cdf0e10cSrcweir 1448*cdf0e10cSrcweir // Menu aufbauen (Jahre mit verschiedenen Monaten aufnehmen) 1449*cdf0e10cSrcweir for ( i = 0; i < MENU_YEAR_COUNT; i++ ) 1450*cdf0e10cSrcweir { 1451*cdf0e10cSrcweir pYearPopupMenus[i] = new PopupMenu; 1452*cdf0e10cSrcweir for ( j = 1; j <= 12; j++ ) 1453*cdf0e10cSrcweir pYearPopupMenus[i]->InsertItem( nYearIdCount+j, 1454*cdf0e10cSrcweir maCalendarWrapper.getDisplayName( 1455*cdf0e10cSrcweir i18n::CalendarDisplayIndex::MONTH, j-1, 1)); 1456*cdf0e10cSrcweir aPopupMenu.InsertItem( 10+i, UniString::CreateFromInt32( nYear+i ) ); 1457*cdf0e10cSrcweir aPopupMenu.SetPopupMenu( 10+i, pYearPopupMenus[i] ); 1458*cdf0e10cSrcweir nYearIdCount += 1000; 1459*cdf0e10cSrcweir } 1460*cdf0e10cSrcweir 1461*cdf0e10cSrcweir mbMenuDown = sal_True; 1462*cdf0e10cSrcweir nCurItemId = aPopupMenu.Execute( this, rPos ); 1463*cdf0e10cSrcweir mbMenuDown = sal_False; 1464*cdf0e10cSrcweir 1465*cdf0e10cSrcweir // Menu zerstoeren 1466*cdf0e10cSrcweir aPopupMenu.SetPopupMenu( 2, NULL ); 1467*cdf0e10cSrcweir for ( i = 0; i < MENU_YEAR_COUNT; i++ ) 1468*cdf0e10cSrcweir { 1469*cdf0e10cSrcweir aPopupMenu.SetPopupMenu( 10+i, NULL ); 1470*cdf0e10cSrcweir delete pYearPopupMenus[i]; 1471*cdf0e10cSrcweir } 1472*cdf0e10cSrcweir 1473*cdf0e10cSrcweir if ( nCurItemId ) 1474*cdf0e10cSrcweir { 1475*cdf0e10cSrcweir sal_uInt16 nTempMonthOff = nMonthOff % 12; 1476*cdf0e10cSrcweir sal_uInt16 nTempYearOff = nMonthOff / 12; 1477*cdf0e10cSrcweir sal_uInt16 nNewMonth = nCurItemId % 1000; 1478*cdf0e10cSrcweir sal_uInt16 nNewYear = nYear+((nCurItemId-1000)/1000); 1479*cdf0e10cSrcweir if ( nTempMonthOff < nNewMonth ) 1480*cdf0e10cSrcweir nNewMonth = nNewMonth - nTempMonthOff; 1481*cdf0e10cSrcweir else 1482*cdf0e10cSrcweir { 1483*cdf0e10cSrcweir nNewYear--; 1484*cdf0e10cSrcweir nNewMonth = 12-(nTempMonthOff-nNewMonth); 1485*cdf0e10cSrcweir } 1486*cdf0e10cSrcweir nNewYear = nNewYear - nTempYearOff; 1487*cdf0e10cSrcweir SetFirstDate( Date( 1, nNewMonth, nNewYear ) ); 1488*cdf0e10cSrcweir } 1489*cdf0e10cSrcweir } 1490*cdf0e10cSrcweir 1491*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1492*cdf0e10cSrcweir 1493*cdf0e10cSrcweir void Calendar::ImplTracking( const Point& rPos, sal_Bool bRepeat ) 1494*cdf0e10cSrcweir { 1495*cdf0e10cSrcweir Date aTempDate = maCurDate; 1496*cdf0e10cSrcweir sal_uInt16 nHitTest = ImplHitTest( rPos, aTempDate ); 1497*cdf0e10cSrcweir 1498*cdf0e10cSrcweir if ( mbSpinDown ) 1499*cdf0e10cSrcweir { 1500*cdf0e10cSrcweir mbPrevIn = (nHitTest & CALENDAR_HITTEST_PREV) != 0; 1501*cdf0e10cSrcweir mbNextIn = (nHitTest & CALENDAR_HITTEST_NEXT) != 0; 1502*cdf0e10cSrcweir 1503*cdf0e10cSrcweir if ( bRepeat && (mbPrevIn || mbNextIn) ) 1504*cdf0e10cSrcweir { 1505*cdf0e10cSrcweir mbScrollDateRange = sal_True; 1506*cdf0e10cSrcweir ImplScroll( mbPrevIn ); 1507*cdf0e10cSrcweir mbScrollDateRange = sal_False; 1508*cdf0e10cSrcweir } 1509*cdf0e10cSrcweir } 1510*cdf0e10cSrcweir else 1511*cdf0e10cSrcweir ImplMouseSelect( aTempDate, nHitTest, sal_True, sal_False, sal_False ); 1512*cdf0e10cSrcweir } 1513*cdf0e10cSrcweir 1514*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1515*cdf0e10cSrcweir 1516*cdf0e10cSrcweir void Calendar::ImplEndTracking( sal_Bool bCancel ) 1517*cdf0e10cSrcweir { 1518*cdf0e10cSrcweir sal_Bool bSelection = mbSelection; 1519*cdf0e10cSrcweir sal_Bool bSpinDown = mbSpinDown; 1520*cdf0e10cSrcweir 1521*cdf0e10cSrcweir mbDrag = sal_False; 1522*cdf0e10cSrcweir mbSelection = sal_False; 1523*cdf0e10cSrcweir mbMultiSelection = sal_False; 1524*cdf0e10cSrcweir mbUnSel = sal_False; 1525*cdf0e10cSrcweir mbSpinDown = sal_False; 1526*cdf0e10cSrcweir mbPrevIn = sal_False; 1527*cdf0e10cSrcweir mbNextIn = sal_False; 1528*cdf0e10cSrcweir 1529*cdf0e10cSrcweir if ( bCancel ) 1530*cdf0e10cSrcweir { 1531*cdf0e10cSrcweir if ( maOldFirstDate != maFirstDate ) 1532*cdf0e10cSrcweir SetFirstDate( maOldFirstDate ); 1533*cdf0e10cSrcweir 1534*cdf0e10cSrcweir if ( !bSpinDown ) 1535*cdf0e10cSrcweir { 1536*cdf0e10cSrcweir Table* pOldSel = new Table( *mpSelectTable ); 1537*cdf0e10cSrcweir Date aOldDate = maCurDate; 1538*cdf0e10cSrcweir maCurDate = maOldCurDate; 1539*cdf0e10cSrcweir *mpSelectTable = *mpOldSelectTable; 1540*cdf0e10cSrcweir HideFocus(); 1541*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 1542*cdf0e10cSrcweir if ( !pOldSel->Get( aOldDate.GetDate() ) ) 1543*cdf0e10cSrcweir ImplUpdateDate( aOldDate ); 1544*cdf0e10cSrcweir // Damit Focus-Rechteck auch wieder neu ausgegeben wird 1545*cdf0e10cSrcweir if ( HasFocus() || !mpSelectTable->Get( maCurDate.GetDate() ) ) 1546*cdf0e10cSrcweir ImplUpdateDate( maCurDate ); 1547*cdf0e10cSrcweir delete pOldSel; 1548*cdf0e10cSrcweir } 1549*cdf0e10cSrcweir } 1550*cdf0e10cSrcweir 1551*cdf0e10cSrcweir if ( !bSpinDown ) 1552*cdf0e10cSrcweir { 1553*cdf0e10cSrcweir if ( !bCancel ) 1554*cdf0e10cSrcweir { 1555*cdf0e10cSrcweir // Feststellen, ob wir sichtbaren Bereich scrollen sollen 1556*cdf0e10cSrcweir sal_uLong nSelCount = mpSelectTable->Count(); 1557*cdf0e10cSrcweir if ( nSelCount ) 1558*cdf0e10cSrcweir { 1559*cdf0e10cSrcweir Date aFirstSelDate( mpSelectTable->GetObjectKey( 0 ) ); 1560*cdf0e10cSrcweir Date aLastSelDate( mpSelectTable->GetObjectKey( nSelCount-1 ) ); 1561*cdf0e10cSrcweir if ( aLastSelDate < GetFirstMonth() ) 1562*cdf0e10cSrcweir ImplScroll( sal_True ); 1563*cdf0e10cSrcweir else if ( GetLastMonth() < aFirstSelDate ) 1564*cdf0e10cSrcweir ImplScroll( sal_False ); 1565*cdf0e10cSrcweir } 1566*cdf0e10cSrcweir } 1567*cdf0e10cSrcweir 1568*cdf0e10cSrcweir if ( mbAllSel || 1569*cdf0e10cSrcweir (!bCancel && ((maCurDate != maOldCurDate) || (*mpOldSelectTable != *mpSelectTable))) ) 1570*cdf0e10cSrcweir Select(); 1571*cdf0e10cSrcweir 1572*cdf0e10cSrcweir if ( !bSelection && (mnWinStyle & WB_TABSTOP) && !bCancel ) 1573*cdf0e10cSrcweir GrabFocus(); 1574*cdf0e10cSrcweir 1575*cdf0e10cSrcweir delete mpOldSelectTable; 1576*cdf0e10cSrcweir mpOldSelectTable = NULL; 1577*cdf0e10cSrcweir delete mpRestoreSelectTable; 1578*cdf0e10cSrcweir mpRestoreSelectTable = NULL; 1579*cdf0e10cSrcweir } 1580*cdf0e10cSrcweir } 1581*cdf0e10cSrcweir 1582*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1583*cdf0e10cSrcweir 1584*cdf0e10cSrcweir IMPL_STATIC_LINK( Calendar, ScrollHdl, Timer*, EMPTYARG ) 1585*cdf0e10cSrcweir { 1586*cdf0e10cSrcweir sal_Bool bPrevIn = (pThis->mnDragScrollHitTest & CALENDAR_HITTEST_PREV) != 0; 1587*cdf0e10cSrcweir sal_Bool bNextIn = (pThis->mnDragScrollHitTest & CALENDAR_HITTEST_NEXT) != 0; 1588*cdf0e10cSrcweir if( bNextIn || bPrevIn ) 1589*cdf0e10cSrcweir { 1590*cdf0e10cSrcweir pThis->mbScrollDateRange = sal_True; 1591*cdf0e10cSrcweir pThis->ImplScroll( bPrevIn ); 1592*cdf0e10cSrcweir pThis->mbScrollDateRange = sal_False; 1593*cdf0e10cSrcweir } 1594*cdf0e10cSrcweir return 0; 1595*cdf0e10cSrcweir } 1596*cdf0e10cSrcweir 1597*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1598*cdf0e10cSrcweir 1599*cdf0e10cSrcweir void Calendar::MouseButtonDown( const MouseEvent& rMEvt ) 1600*cdf0e10cSrcweir { 1601*cdf0e10cSrcweir if ( rMEvt.IsLeft() && !mbMenuDown ) 1602*cdf0e10cSrcweir { 1603*cdf0e10cSrcweir Date aTempDate = maCurDate; 1604*cdf0e10cSrcweir sal_uInt16 nHitTest = ImplHitTest( rMEvt.GetPosPixel(), aTempDate ); 1605*cdf0e10cSrcweir if ( nHitTest ) 1606*cdf0e10cSrcweir { 1607*cdf0e10cSrcweir if ( nHitTest & CALENDAR_HITTEST_MONTHTITLE ) 1608*cdf0e10cSrcweir ImplShowMenu( rMEvt.GetPosPixel(), aTempDate ); 1609*cdf0e10cSrcweir else 1610*cdf0e10cSrcweir { 1611*cdf0e10cSrcweir maOldFirstDate = maFirstDate; 1612*cdf0e10cSrcweir 1613*cdf0e10cSrcweir mbPrevIn = (nHitTest & CALENDAR_HITTEST_PREV) != 0; 1614*cdf0e10cSrcweir mbNextIn = (nHitTest & CALENDAR_HITTEST_NEXT) != 0; 1615*cdf0e10cSrcweir if ( mbPrevIn || mbNextIn ) 1616*cdf0e10cSrcweir { 1617*cdf0e10cSrcweir mbSpinDown = sal_True; 1618*cdf0e10cSrcweir mbScrollDateRange = sal_True; 1619*cdf0e10cSrcweir ImplScroll( mbPrevIn ); 1620*cdf0e10cSrcweir mbScrollDateRange = sal_False; 1621*cdf0e10cSrcweir // Hier muss BUTTONREPEAT stehen, also nicht wieder 1622*cdf0e10cSrcweir // auf SCROLLREPEAT aendern, sondern mit TH abklaeren, 1623*cdf0e10cSrcweir // warum es evtl. anders sein sollte (71775) 1624*cdf0e10cSrcweir StartTracking( STARTTRACK_BUTTONREPEAT ); 1625*cdf0e10cSrcweir } 1626*cdf0e10cSrcweir else 1627*cdf0e10cSrcweir { 1628*cdf0e10cSrcweir if ( (rMEvt.GetClicks() == 2) && (nHitTest & CALENDAR_HITTEST_DAY) ) 1629*cdf0e10cSrcweir DoubleClick(); 1630*cdf0e10cSrcweir else 1631*cdf0e10cSrcweir { 1632*cdf0e10cSrcweir if ( mpOldSelectTable ) 1633*cdf0e10cSrcweir delete mpOldSelectTable; 1634*cdf0e10cSrcweir maOldCurDate = maCurDate; 1635*cdf0e10cSrcweir mpOldSelectTable = new Table( *mpSelectTable ); 1636*cdf0e10cSrcweir 1637*cdf0e10cSrcweir if ( !mbSelection ) 1638*cdf0e10cSrcweir { 1639*cdf0e10cSrcweir mbDrag = sal_True; 1640*cdf0e10cSrcweir StartTracking(); 1641*cdf0e10cSrcweir } 1642*cdf0e10cSrcweir 1643*cdf0e10cSrcweir mbMultiSelection = (mnWinStyle & (WB_MULTISELECT | WB_RANGESELECT)) != 0; 1644*cdf0e10cSrcweir if ( (nHitTest & CALENDAR_HITTEST_DAY) && mbMultiSelection ) 1645*cdf0e10cSrcweir mbWeekSel = sal_True; 1646*cdf0e10cSrcweir else 1647*cdf0e10cSrcweir mbWeekSel = sal_False; 1648*cdf0e10cSrcweir ImplMouseSelect( aTempDate, nHitTest, sal_False, rMEvt.IsShift(), rMEvt.IsMod1() ); 1649*cdf0e10cSrcweir } 1650*cdf0e10cSrcweir } 1651*cdf0e10cSrcweir } 1652*cdf0e10cSrcweir } 1653*cdf0e10cSrcweir 1654*cdf0e10cSrcweir return; 1655*cdf0e10cSrcweir } 1656*cdf0e10cSrcweir 1657*cdf0e10cSrcweir Control::MouseButtonDown( rMEvt ); 1658*cdf0e10cSrcweir } 1659*cdf0e10cSrcweir 1660*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1661*cdf0e10cSrcweir 1662*cdf0e10cSrcweir void Calendar::MouseButtonUp( const MouseEvent& rMEvt ) 1663*cdf0e10cSrcweir { 1664*cdf0e10cSrcweir if ( rMEvt.IsLeft() && mbSelection ) 1665*cdf0e10cSrcweir ImplEndTracking( sal_False ); 1666*cdf0e10cSrcweir else 1667*cdf0e10cSrcweir Control::MouseButtonUp( rMEvt ); 1668*cdf0e10cSrcweir } 1669*cdf0e10cSrcweir 1670*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1671*cdf0e10cSrcweir 1672*cdf0e10cSrcweir void Calendar::MouseMove( const MouseEvent& rMEvt ) 1673*cdf0e10cSrcweir { 1674*cdf0e10cSrcweir if ( mbSelection && rMEvt.GetButtons() ) 1675*cdf0e10cSrcweir ImplTracking( rMEvt.GetPosPixel(), sal_False ); 1676*cdf0e10cSrcweir else 1677*cdf0e10cSrcweir Control::MouseMove( rMEvt ); 1678*cdf0e10cSrcweir } 1679*cdf0e10cSrcweir 1680*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1681*cdf0e10cSrcweir 1682*cdf0e10cSrcweir void Calendar::Tracking( const TrackingEvent& rTEvt ) 1683*cdf0e10cSrcweir { 1684*cdf0e10cSrcweir Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel(); 1685*cdf0e10cSrcweir 1686*cdf0e10cSrcweir if ( rTEvt.IsTrackingEnded() ) 1687*cdf0e10cSrcweir ImplEndTracking( rTEvt.IsTrackingCanceled() ); 1688*cdf0e10cSrcweir else 1689*cdf0e10cSrcweir ImplTracking( aMousePos, rTEvt.IsTrackingRepeat() ); 1690*cdf0e10cSrcweir } 1691*cdf0e10cSrcweir 1692*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1693*cdf0e10cSrcweir 1694*cdf0e10cSrcweir void Calendar::KeyInput( const KeyEvent& rKEvt ) 1695*cdf0e10cSrcweir { 1696*cdf0e10cSrcweir Date aNewDate = maCurDate; 1697*cdf0e10cSrcweir sal_Bool bMultiSel = (mnWinStyle & (WB_RANGESELECT | WB_MULTISELECT)) != 0; 1698*cdf0e10cSrcweir sal_Bool bExpand = rKEvt.GetKeyCode().IsShift(); 1699*cdf0e10cSrcweir sal_Bool bExtended = rKEvt.GetKeyCode().IsMod1(); 1700*cdf0e10cSrcweir 1701*cdf0e10cSrcweir switch ( rKEvt.GetKeyCode().GetCode() ) 1702*cdf0e10cSrcweir { 1703*cdf0e10cSrcweir case KEY_HOME: 1704*cdf0e10cSrcweir aNewDate.SetDay( 1 ); 1705*cdf0e10cSrcweir break; 1706*cdf0e10cSrcweir 1707*cdf0e10cSrcweir case KEY_END: 1708*cdf0e10cSrcweir aNewDate.SetDay( aNewDate.GetDaysInMonth() ); 1709*cdf0e10cSrcweir break; 1710*cdf0e10cSrcweir 1711*cdf0e10cSrcweir case KEY_LEFT: 1712*cdf0e10cSrcweir aNewDate--; 1713*cdf0e10cSrcweir break; 1714*cdf0e10cSrcweir 1715*cdf0e10cSrcweir case KEY_RIGHT: 1716*cdf0e10cSrcweir aNewDate++; 1717*cdf0e10cSrcweir break; 1718*cdf0e10cSrcweir 1719*cdf0e10cSrcweir case KEY_UP: 1720*cdf0e10cSrcweir aNewDate -= 7; 1721*cdf0e10cSrcweir break; 1722*cdf0e10cSrcweir 1723*cdf0e10cSrcweir case KEY_DOWN: 1724*cdf0e10cSrcweir aNewDate += 7; 1725*cdf0e10cSrcweir break; 1726*cdf0e10cSrcweir 1727*cdf0e10cSrcweir case KEY_PAGEUP: 1728*cdf0e10cSrcweir { 1729*cdf0e10cSrcweir Date aTempDate = aNewDate; 1730*cdf0e10cSrcweir aTempDate -= aNewDate.GetDay()+1; 1731*cdf0e10cSrcweir aNewDate -= aTempDate.GetDaysInMonth(); 1732*cdf0e10cSrcweir } 1733*cdf0e10cSrcweir break; 1734*cdf0e10cSrcweir 1735*cdf0e10cSrcweir case KEY_PAGEDOWN: 1736*cdf0e10cSrcweir aNewDate += aNewDate.GetDaysInMonth(); 1737*cdf0e10cSrcweir break; 1738*cdf0e10cSrcweir 1739*cdf0e10cSrcweir case KEY_SPACE: 1740*cdf0e10cSrcweir if ( bMultiSel && !(mnWinStyle & WB_RANGESELECT) ) 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir if ( !bExpand ) 1743*cdf0e10cSrcweir { 1744*cdf0e10cSrcweir sal_Bool bDateSel = IsDateSelected( maCurDate ); 1745*cdf0e10cSrcweir SelectDate( maCurDate, !bDateSel ); 1746*cdf0e10cSrcweir mbSelLeft = sal_False; 1747*cdf0e10cSrcweir SelectionChanging(); 1748*cdf0e10cSrcweir mbTravelSelect = sal_True; 1749*cdf0e10cSrcweir Select(); 1750*cdf0e10cSrcweir mbTravelSelect = sal_False; 1751*cdf0e10cSrcweir } 1752*cdf0e10cSrcweir } 1753*cdf0e10cSrcweir else 1754*cdf0e10cSrcweir Control::KeyInput( rKEvt ); 1755*cdf0e10cSrcweir break; 1756*cdf0e10cSrcweir 1757*cdf0e10cSrcweir default: 1758*cdf0e10cSrcweir Control::KeyInput( rKEvt ); 1759*cdf0e10cSrcweir break; 1760*cdf0e10cSrcweir } 1761*cdf0e10cSrcweir 1762*cdf0e10cSrcweir if ( aNewDate != maCurDate ) 1763*cdf0e10cSrcweir { 1764*cdf0e10cSrcweir if ( bMultiSel && bExpand ) 1765*cdf0e10cSrcweir { 1766*cdf0e10cSrcweir Table* pOldSel = new Table( *mpSelectTable ); 1767*cdf0e10cSrcweir Date aOldAnchorDate = maAnchorDate; 1768*cdf0e10cSrcweir mbSelLeft = aNewDate < maAnchorDate; 1769*cdf0e10cSrcweir if ( !bExtended ) 1770*cdf0e10cSrcweir { 1771*cdf0e10cSrcweir if ( mbSelLeft ) 1772*cdf0e10cSrcweir { 1773*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, Date( 1, 1, 0 ), aNewDate, sal_False ); 1774*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, maAnchorDate, Date( 31, 12, 9999 ), sal_False ); 1775*cdf0e10cSrcweir } 1776*cdf0e10cSrcweir else 1777*cdf0e10cSrcweir { 1778*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, Date( 1, 1, 0 ), maAnchorDate, sal_False ); 1779*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, aNewDate, Date( 31, 12, 9999 ), sal_False ); 1780*cdf0e10cSrcweir } 1781*cdf0e10cSrcweir } 1782*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, aNewDate, maAnchorDate, sal_True ); 1783*cdf0e10cSrcweir mbDirect = sal_True; 1784*cdf0e10cSrcweir SetCurDate( aNewDate ); 1785*cdf0e10cSrcweir mbDirect = sal_False; 1786*cdf0e10cSrcweir maAnchorDate = aOldAnchorDate; 1787*cdf0e10cSrcweir mbInSelChange = sal_True; 1788*cdf0e10cSrcweir SelectionChanging(); 1789*cdf0e10cSrcweir mbInSelChange = sal_False; 1790*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 1791*cdf0e10cSrcweir delete pOldSel; 1792*cdf0e10cSrcweir } 1793*cdf0e10cSrcweir else 1794*cdf0e10cSrcweir { 1795*cdf0e10cSrcweir if ( mnWinStyle & WB_RANGESELECT ) 1796*cdf0e10cSrcweir { 1797*cdf0e10cSrcweir SetNoSelection(); 1798*cdf0e10cSrcweir SelectDate( aNewDate, sal_True ); 1799*cdf0e10cSrcweir } 1800*cdf0e10cSrcweir mbDirect = sal_True; 1801*cdf0e10cSrcweir SetCurDate( aNewDate ); 1802*cdf0e10cSrcweir mbDirect = sal_False; 1803*cdf0e10cSrcweir } 1804*cdf0e10cSrcweir mbTravelSelect = sal_True; 1805*cdf0e10cSrcweir Select(); 1806*cdf0e10cSrcweir mbTravelSelect = sal_False; 1807*cdf0e10cSrcweir } 1808*cdf0e10cSrcweir } 1809*cdf0e10cSrcweir 1810*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1811*cdf0e10cSrcweir 1812*cdf0e10cSrcweir void Calendar::Paint( const Rectangle& ) 1813*cdf0e10cSrcweir { 1814*cdf0e10cSrcweir ImplDraw( sal_True ); 1815*cdf0e10cSrcweir } 1816*cdf0e10cSrcweir 1817*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1818*cdf0e10cSrcweir 1819*cdf0e10cSrcweir void Calendar::GetFocus() 1820*cdf0e10cSrcweir { 1821*cdf0e10cSrcweir ImplUpdateDate( maCurDate ); 1822*cdf0e10cSrcweir Control::GetFocus(); 1823*cdf0e10cSrcweir } 1824*cdf0e10cSrcweir 1825*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1826*cdf0e10cSrcweir 1827*cdf0e10cSrcweir void Calendar::LoseFocus() 1828*cdf0e10cSrcweir { 1829*cdf0e10cSrcweir HideFocus(); 1830*cdf0e10cSrcweir Control::LoseFocus(); 1831*cdf0e10cSrcweir } 1832*cdf0e10cSrcweir 1833*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1834*cdf0e10cSrcweir 1835*cdf0e10cSrcweir void Calendar::Resize() 1836*cdf0e10cSrcweir { 1837*cdf0e10cSrcweir ImplUpdate( sal_True ); 1838*cdf0e10cSrcweir Control::Resize(); 1839*cdf0e10cSrcweir } 1840*cdf0e10cSrcweir 1841*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1842*cdf0e10cSrcweir 1843*cdf0e10cSrcweir void Calendar::RequestHelp( const HelpEvent& rHEvt ) 1844*cdf0e10cSrcweir { 1845*cdf0e10cSrcweir if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) ) 1846*cdf0e10cSrcweir { 1847*cdf0e10cSrcweir Date aDate = maCurDate; 1848*cdf0e10cSrcweir if ( GetDate( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ), aDate ) ) 1849*cdf0e10cSrcweir { 1850*cdf0e10cSrcweir Rectangle aDateRect = GetDateRect( aDate ); 1851*cdf0e10cSrcweir Point aPt = OutputToScreenPixel( aDateRect.TopLeft() ); 1852*cdf0e10cSrcweir aDateRect.Left() = aPt.X(); 1853*cdf0e10cSrcweir aDateRect.Top() = aPt.Y(); 1854*cdf0e10cSrcweir aPt = OutputToScreenPixel( aDateRect.BottomRight() ); 1855*cdf0e10cSrcweir aDateRect.Right() = aPt.X(); 1856*cdf0e10cSrcweir aDateRect.Bottom() = aPt.Y(); 1857*cdf0e10cSrcweir 1858*cdf0e10cSrcweir if ( (rHEvt.GetMode() & HELPMODE_BALLOON) || (mnWinStyle & WB_QUICKHELPSHOWSDATEINFO) ) 1859*cdf0e10cSrcweir { 1860*cdf0e10cSrcweir ImplDateInfo* pInfo; 1861*cdf0e10cSrcweir if ( mpDateTable ) 1862*cdf0e10cSrcweir { 1863*cdf0e10cSrcweir pInfo = mpDateTable->Get( aDate.GetDate() ); 1864*cdf0e10cSrcweir if ( !pInfo ) 1865*cdf0e10cSrcweir pInfo = mpDateTable->Get( Date( aDate.GetDay(), aDate.GetMonth(), 0 ).GetDate() ); 1866*cdf0e10cSrcweir } 1867*cdf0e10cSrcweir else 1868*cdf0e10cSrcweir pInfo = NULL; 1869*cdf0e10cSrcweir if ( pInfo ) 1870*cdf0e10cSrcweir { 1871*cdf0e10cSrcweir XubString aStr = pInfo->maText; 1872*cdf0e10cSrcweir if ( aStr.Len() ) 1873*cdf0e10cSrcweir { 1874*cdf0e10cSrcweir Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aDateRect, aStr ); 1875*cdf0e10cSrcweir return; 1876*cdf0e10cSrcweir } 1877*cdf0e10cSrcweir } 1878*cdf0e10cSrcweir } 1879*cdf0e10cSrcweir 1880*cdf0e10cSrcweir if ( rHEvt.GetMode() & HELPMODE_QUICK ) 1881*cdf0e10cSrcweir { 1882*cdf0e10cSrcweir maCalendarWrapper.setGregorianDateTime( aDate); 1883*cdf0e10cSrcweir sal_uInt16 nWeek = (sal_uInt16) maCalendarWrapper.getValue( i18n::CalendarFieldIndex::WEEK_OF_YEAR); 1884*cdf0e10cSrcweir sal_uInt16 nMonth = aDate.GetMonth(); 1885*cdf0e10cSrcweir XubString aStr( maDayText ); 1886*cdf0e10cSrcweir aStr.AppendAscii( ": " ); 1887*cdf0e10cSrcweir aStr.Append( XubString::CreateFromInt32( aDate.GetDayOfYear() ) ); 1888*cdf0e10cSrcweir aStr.AppendAscii( " / " ); 1889*cdf0e10cSrcweir aStr.Append( maWeekText ); 1890*cdf0e10cSrcweir aStr.AppendAscii( ": " ); 1891*cdf0e10cSrcweir aStr.Append( XubString::CreateFromInt32( nWeek ) ); 1892*cdf0e10cSrcweir // Evt. noch Jahr hinzufuegen, wenn es nicht das gleiche ist 1893*cdf0e10cSrcweir if ( (nMonth == 12) && (nWeek == 1) ) 1894*cdf0e10cSrcweir { 1895*cdf0e10cSrcweir aStr.AppendAscii( ", " ); 1896*cdf0e10cSrcweir aStr.Append( XubString::CreateFromInt32( aDate.GetYear()+1 ) ); 1897*cdf0e10cSrcweir } 1898*cdf0e10cSrcweir else if ( (nMonth == 1) && (nWeek > 50) ) 1899*cdf0e10cSrcweir { 1900*cdf0e10cSrcweir aStr.AppendAscii( ", " ); 1901*cdf0e10cSrcweir aStr.Append( XubString::CreateFromInt32( aDate.GetYear()-1 ) ); 1902*cdf0e10cSrcweir } 1903*cdf0e10cSrcweir Help::ShowQuickHelp( this, aDateRect, aStr ); 1904*cdf0e10cSrcweir return; 1905*cdf0e10cSrcweir } 1906*cdf0e10cSrcweir } 1907*cdf0e10cSrcweir } 1908*cdf0e10cSrcweir 1909*cdf0e10cSrcweir Control::RequestHelp( rHEvt ); 1910*cdf0e10cSrcweir } 1911*cdf0e10cSrcweir 1912*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1913*cdf0e10cSrcweir 1914*cdf0e10cSrcweir void Calendar::Command( const CommandEvent& rCEvt ) 1915*cdf0e10cSrcweir { 1916*cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 1917*cdf0e10cSrcweir { 1918*cdf0e10cSrcweir if ( !mbSelection && rCEvt.IsMouseEvent() ) 1919*cdf0e10cSrcweir { 1920*cdf0e10cSrcweir Date aTempDate = maCurDate; 1921*cdf0e10cSrcweir sal_uInt16 nHitTest = ImplHitTest( rCEvt.GetMousePosPixel(), aTempDate ); 1922*cdf0e10cSrcweir if ( nHitTest & CALENDAR_HITTEST_MONTHTITLE ) 1923*cdf0e10cSrcweir { 1924*cdf0e10cSrcweir ImplShowMenu( rCEvt.GetMousePosPixel(), aTempDate ); 1925*cdf0e10cSrcweir return; 1926*cdf0e10cSrcweir } 1927*cdf0e10cSrcweir } 1928*cdf0e10cSrcweir } 1929*cdf0e10cSrcweir else if ( rCEvt.GetCommand() == COMMAND_WHEEL ) 1930*cdf0e10cSrcweir { 1931*cdf0e10cSrcweir const CommandWheelData* pData = rCEvt.GetWheelData(); 1932*cdf0e10cSrcweir if ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) 1933*cdf0e10cSrcweir { 1934*cdf0e10cSrcweir long nNotchDelta = pData->GetNotchDelta(); 1935*cdf0e10cSrcweir if ( nNotchDelta < 0 ) 1936*cdf0e10cSrcweir { 1937*cdf0e10cSrcweir while ( nNotchDelta < 0 ) 1938*cdf0e10cSrcweir { 1939*cdf0e10cSrcweir ImplScroll( sal_True ); 1940*cdf0e10cSrcweir nNotchDelta++; 1941*cdf0e10cSrcweir } 1942*cdf0e10cSrcweir } 1943*cdf0e10cSrcweir else 1944*cdf0e10cSrcweir { 1945*cdf0e10cSrcweir while ( nNotchDelta > 0 ) 1946*cdf0e10cSrcweir { 1947*cdf0e10cSrcweir ImplScroll( sal_False ); 1948*cdf0e10cSrcweir nNotchDelta--; 1949*cdf0e10cSrcweir } 1950*cdf0e10cSrcweir } 1951*cdf0e10cSrcweir 1952*cdf0e10cSrcweir return; 1953*cdf0e10cSrcweir } 1954*cdf0e10cSrcweir } 1955*cdf0e10cSrcweir 1956*cdf0e10cSrcweir Control::Command( rCEvt ); 1957*cdf0e10cSrcweir } 1958*cdf0e10cSrcweir 1959*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1960*cdf0e10cSrcweir 1961*cdf0e10cSrcweir void Calendar::StateChanged( StateChangedType nType ) 1962*cdf0e10cSrcweir { 1963*cdf0e10cSrcweir Control::StateChanged( nType ); 1964*cdf0e10cSrcweir 1965*cdf0e10cSrcweir if ( nType == STATE_CHANGE_INITSHOW ) 1966*cdf0e10cSrcweir ImplFormat(); 1967*cdf0e10cSrcweir } 1968*cdf0e10cSrcweir 1969*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1970*cdf0e10cSrcweir 1971*cdf0e10cSrcweir void Calendar::DataChanged( const DataChangedEvent& rDCEvt ) 1972*cdf0e10cSrcweir { 1973*cdf0e10cSrcweir Control::DataChanged( rDCEvt ); 1974*cdf0e10cSrcweir 1975*cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 1976*cdf0e10cSrcweir (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 1977*cdf0e10cSrcweir ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 1978*cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 1979*cdf0e10cSrcweir { 1980*cdf0e10cSrcweir ImplInitSettings(); 1981*cdf0e10cSrcweir Invalidate(); 1982*cdf0e10cSrcweir } 1983*cdf0e10cSrcweir } 1984*cdf0e10cSrcweir 1985*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1986*cdf0e10cSrcweir 1987*cdf0e10cSrcweir void Calendar::SelectionChanging() 1988*cdf0e10cSrcweir { 1989*cdf0e10cSrcweir maSelectionChangingHdl.Call( this ); 1990*cdf0e10cSrcweir } 1991*cdf0e10cSrcweir 1992*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1993*cdf0e10cSrcweir 1994*cdf0e10cSrcweir void Calendar::DateRangeChanged() 1995*cdf0e10cSrcweir { 1996*cdf0e10cSrcweir maDateRangeChangedHdl.Call( this ); 1997*cdf0e10cSrcweir } 1998*cdf0e10cSrcweir 1999*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2000*cdf0e10cSrcweir 2001*cdf0e10cSrcweir void Calendar::RequestDateInfo() 2002*cdf0e10cSrcweir { 2003*cdf0e10cSrcweir maRequestDateInfoHdl.Call( this ); 2004*cdf0e10cSrcweir } 2005*cdf0e10cSrcweir 2006*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2007*cdf0e10cSrcweir 2008*cdf0e10cSrcweir void Calendar::DoubleClick() 2009*cdf0e10cSrcweir { 2010*cdf0e10cSrcweir maDoubleClickHdl.Call( this ); 2011*cdf0e10cSrcweir } 2012*cdf0e10cSrcweir 2013*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2014*cdf0e10cSrcweir 2015*cdf0e10cSrcweir void Calendar::Select() 2016*cdf0e10cSrcweir { 2017*cdf0e10cSrcweir maSelectHdl.Call( this ); 2018*cdf0e10cSrcweir } 2019*cdf0e10cSrcweir 2020*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2021*cdf0e10cSrcweir 2022*cdf0e10cSrcweir void Calendar::SelectDate( const Date& rDate, sal_Bool bSelect ) 2023*cdf0e10cSrcweir { 2024*cdf0e10cSrcweir if ( !rDate.IsValid() ) 2025*cdf0e10cSrcweir return; 2026*cdf0e10cSrcweir 2027*cdf0e10cSrcweir Table* pOldSel; 2028*cdf0e10cSrcweir 2029*cdf0e10cSrcweir if ( !mbInSelChange ) 2030*cdf0e10cSrcweir pOldSel = new Table( *mpSelectTable ); 2031*cdf0e10cSrcweir else 2032*cdf0e10cSrcweir pOldSel = NULL; 2033*cdf0e10cSrcweir 2034*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, rDate, bSelect ); 2035*cdf0e10cSrcweir 2036*cdf0e10cSrcweir if ( pOldSel ) 2037*cdf0e10cSrcweir { 2038*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 2039*cdf0e10cSrcweir delete pOldSel; 2040*cdf0e10cSrcweir } 2041*cdf0e10cSrcweir } 2042*cdf0e10cSrcweir 2043*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2044*cdf0e10cSrcweir 2045*cdf0e10cSrcweir void Calendar::SelectDateRange( const Date& rStartDate, const Date& rEndDate, 2046*cdf0e10cSrcweir sal_Bool bSelect ) 2047*cdf0e10cSrcweir { 2048*cdf0e10cSrcweir if ( !rStartDate.IsValid() || !rEndDate.IsValid() ) 2049*cdf0e10cSrcweir return; 2050*cdf0e10cSrcweir 2051*cdf0e10cSrcweir Table* pOldSel; 2052*cdf0e10cSrcweir 2053*cdf0e10cSrcweir if ( !mbInSelChange ) 2054*cdf0e10cSrcweir pOldSel = new Table( *mpSelectTable ); 2055*cdf0e10cSrcweir else 2056*cdf0e10cSrcweir pOldSel = NULL; 2057*cdf0e10cSrcweir 2058*cdf0e10cSrcweir ImplCalendarSelectDateRange( mpSelectTable, rStartDate, rEndDate, bSelect ); 2059*cdf0e10cSrcweir 2060*cdf0e10cSrcweir if ( pOldSel ) 2061*cdf0e10cSrcweir { 2062*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 2063*cdf0e10cSrcweir delete pOldSel; 2064*cdf0e10cSrcweir } 2065*cdf0e10cSrcweir } 2066*cdf0e10cSrcweir 2067*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2068*cdf0e10cSrcweir 2069*cdf0e10cSrcweir void Calendar::SetNoSelection() 2070*cdf0e10cSrcweir { 2071*cdf0e10cSrcweir Table* pOldSel; 2072*cdf0e10cSrcweir 2073*cdf0e10cSrcweir if ( !mbInSelChange ) 2074*cdf0e10cSrcweir pOldSel = new Table( *mpSelectTable ); 2075*cdf0e10cSrcweir else 2076*cdf0e10cSrcweir pOldSel = NULL; 2077*cdf0e10cSrcweir 2078*cdf0e10cSrcweir ImplCalendarClearSelectDate( mpSelectTable ); 2079*cdf0e10cSrcweir 2080*cdf0e10cSrcweir if ( pOldSel ) 2081*cdf0e10cSrcweir { 2082*cdf0e10cSrcweir ImplUpdateSelection( pOldSel ); 2083*cdf0e10cSrcweir delete pOldSel; 2084*cdf0e10cSrcweir } 2085*cdf0e10cSrcweir } 2086*cdf0e10cSrcweir 2087*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2088*cdf0e10cSrcweir 2089*cdf0e10cSrcweir sal_Bool Calendar::IsDateSelected( const Date& rDate ) const 2090*cdf0e10cSrcweir { 2091*cdf0e10cSrcweir return mpSelectTable->IsKeyValid( rDate.GetDate() ); 2092*cdf0e10cSrcweir } 2093*cdf0e10cSrcweir 2094*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2095*cdf0e10cSrcweir 2096*cdf0e10cSrcweir sal_uLong Calendar::GetSelectDateCount() const 2097*cdf0e10cSrcweir { 2098*cdf0e10cSrcweir return mpSelectTable->Count(); 2099*cdf0e10cSrcweir } 2100*cdf0e10cSrcweir 2101*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2102*cdf0e10cSrcweir 2103*cdf0e10cSrcweir Date Calendar::GetSelectDate( sal_uLong nIndex ) const 2104*cdf0e10cSrcweir { 2105*cdf0e10cSrcweir if ( nIndex < mpSelectTable->Count() ) 2106*cdf0e10cSrcweir return Date( mpSelectTable->GetObjectKey( nIndex ) ); 2107*cdf0e10cSrcweir else 2108*cdf0e10cSrcweir { 2109*cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 2110*cdf0e10cSrcweir return aDate; 2111*cdf0e10cSrcweir } 2112*cdf0e10cSrcweir } 2113*cdf0e10cSrcweir 2114*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2115*cdf0e10cSrcweir 2116*cdf0e10cSrcweir void Calendar::SetCurDate( const Date& rNewDate ) 2117*cdf0e10cSrcweir { 2118*cdf0e10cSrcweir if ( !rNewDate.IsValid() ) 2119*cdf0e10cSrcweir return; 2120*cdf0e10cSrcweir 2121*cdf0e10cSrcweir if ( maCurDate != rNewDate ) 2122*cdf0e10cSrcweir { 2123*cdf0e10cSrcweir sal_Bool bUpdate = IsVisible() && IsUpdateMode(); 2124*cdf0e10cSrcweir Date aOldDate = maCurDate; 2125*cdf0e10cSrcweir maCurDate = rNewDate; 2126*cdf0e10cSrcweir maAnchorDate = maCurDate; 2127*cdf0e10cSrcweir 2128*cdf0e10cSrcweir if ( !(mnWinStyle & (WB_RANGESELECT | WB_MULTISELECT)) ) 2129*cdf0e10cSrcweir { 2130*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, aOldDate, sal_False ); 2131*cdf0e10cSrcweir ImplCalendarSelectDate( mpSelectTable, maCurDate, sal_True ); 2132*cdf0e10cSrcweir } 2133*cdf0e10cSrcweir else if ( !HasFocus() ) 2134*cdf0e10cSrcweir bUpdate = sal_False; 2135*cdf0e10cSrcweir 2136*cdf0e10cSrcweir // Aktuelles Datum noch in den sichtbaren Bereich verschieben 2137*cdf0e10cSrcweir if ( mbFormat || (maCurDate < GetFirstMonth()) ) 2138*cdf0e10cSrcweir SetFirstDate( maCurDate ); 2139*cdf0e10cSrcweir else if ( maCurDate > GetLastMonth() ) 2140*cdf0e10cSrcweir { 2141*cdf0e10cSrcweir Date aTempDate = GetLastMonth(); 2142*cdf0e10cSrcweir long nDateOff = maCurDate-aTempDate; 2143*cdf0e10cSrcweir if ( nDateOff < 365 ) 2144*cdf0e10cSrcweir { 2145*cdf0e10cSrcweir Date aFirstDate = GetFirstMonth(); 2146*cdf0e10cSrcweir aFirstDate += aFirstDate.GetDaysInMonth(); 2147*cdf0e10cSrcweir aTempDate++; 2148*cdf0e10cSrcweir while ( nDateOff > aTempDate.GetDaysInMonth() ) 2149*cdf0e10cSrcweir { 2150*cdf0e10cSrcweir aFirstDate += aFirstDate.GetDaysInMonth(); 2151*cdf0e10cSrcweir long nDaysInMonth = aTempDate.GetDaysInMonth(); 2152*cdf0e10cSrcweir aTempDate += nDaysInMonth; 2153*cdf0e10cSrcweir nDateOff -= nDaysInMonth; 2154*cdf0e10cSrcweir } 2155*cdf0e10cSrcweir SetFirstDate( aFirstDate ); 2156*cdf0e10cSrcweir } 2157*cdf0e10cSrcweir else 2158*cdf0e10cSrcweir SetFirstDate( maCurDate ); 2159*cdf0e10cSrcweir } 2160*cdf0e10cSrcweir else 2161*cdf0e10cSrcweir { 2162*cdf0e10cSrcweir if ( bUpdate ) 2163*cdf0e10cSrcweir { 2164*cdf0e10cSrcweir HideFocus(); 2165*cdf0e10cSrcweir ImplUpdateDate( aOldDate ); 2166*cdf0e10cSrcweir ImplUpdateDate( maCurDate ); 2167*cdf0e10cSrcweir } 2168*cdf0e10cSrcweir } 2169*cdf0e10cSrcweir } 2170*cdf0e10cSrcweir } 2171*cdf0e10cSrcweir 2172*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2173*cdf0e10cSrcweir 2174*cdf0e10cSrcweir void Calendar::SetFirstDate( const Date& rNewFirstDate ) 2175*cdf0e10cSrcweir { 2176*cdf0e10cSrcweir if ( maFirstDate != rNewFirstDate ) 2177*cdf0e10cSrcweir { 2178*cdf0e10cSrcweir maFirstDate = Date( 1, rNewFirstDate.GetMonth(), rNewFirstDate.GetYear() ); 2179*cdf0e10cSrcweir mbDropPos = sal_False; 2180*cdf0e10cSrcweir ImplUpdate(); 2181*cdf0e10cSrcweir } 2182*cdf0e10cSrcweir } 2183*cdf0e10cSrcweir 2184*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2185*cdf0e10cSrcweir 2186*cdf0e10cSrcweir Date Calendar::GetFirstMonth() const 2187*cdf0e10cSrcweir { 2188*cdf0e10cSrcweir if ( maFirstDate.GetDay() > 1 ) 2189*cdf0e10cSrcweir { 2190*cdf0e10cSrcweir if ( maFirstDate.GetMonth() == 12 ) 2191*cdf0e10cSrcweir return Date( 1, 1, maFirstDate.GetYear()+1 ); 2192*cdf0e10cSrcweir else 2193*cdf0e10cSrcweir return Date( 1, maFirstDate.GetMonth()+1, maFirstDate.GetYear() ); 2194*cdf0e10cSrcweir } 2195*cdf0e10cSrcweir else 2196*cdf0e10cSrcweir return maFirstDate; 2197*cdf0e10cSrcweir } 2198*cdf0e10cSrcweir 2199*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2200*cdf0e10cSrcweir 2201*cdf0e10cSrcweir Date Calendar::GetLastMonth() const 2202*cdf0e10cSrcweir { 2203*cdf0e10cSrcweir Date aDate = GetFirstMonth(); 2204*cdf0e10cSrcweir sal_uInt16 nMonthCount = GetMonthCount(); 2205*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nMonthCount; i++ ) 2206*cdf0e10cSrcweir aDate += aDate.GetDaysInMonth(); 2207*cdf0e10cSrcweir aDate--; 2208*cdf0e10cSrcweir return aDate; 2209*cdf0e10cSrcweir } 2210*cdf0e10cSrcweir 2211*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2212*cdf0e10cSrcweir 2213*cdf0e10cSrcweir sal_uInt16 Calendar::GetMonthCount() const 2214*cdf0e10cSrcweir { 2215*cdf0e10cSrcweir if ( mbFormat ) 2216*cdf0e10cSrcweir return 1; 2217*cdf0e10cSrcweir else 2218*cdf0e10cSrcweir return (sal_uInt16)(mnMonthPerLine*mnLines); 2219*cdf0e10cSrcweir } 2220*cdf0e10cSrcweir 2221*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2222*cdf0e10cSrcweir 2223*cdf0e10cSrcweir sal_Bool Calendar::GetDropDate( Date& rDate ) const 2224*cdf0e10cSrcweir { 2225*cdf0e10cSrcweir if( mbDropPos ) 2226*cdf0e10cSrcweir { 2227*cdf0e10cSrcweir rDate = maDropDate; 2228*cdf0e10cSrcweir return sal_True; 2229*cdf0e10cSrcweir } 2230*cdf0e10cSrcweir return sal_False; 2231*cdf0e10cSrcweir } 2232*cdf0e10cSrcweir 2233*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2234*cdf0e10cSrcweir 2235*cdf0e10cSrcweir sal_Bool Calendar::GetDate( const Point& rPos, Date& rDate ) const 2236*cdf0e10cSrcweir { 2237*cdf0e10cSrcweir Date aDate = maCurDate; 2238*cdf0e10cSrcweir sal_uInt16 nHitTest = ImplHitTest( rPos, aDate ); 2239*cdf0e10cSrcweir if ( nHitTest & CALENDAR_HITTEST_DAY ) 2240*cdf0e10cSrcweir { 2241*cdf0e10cSrcweir rDate = aDate; 2242*cdf0e10cSrcweir return sal_True; 2243*cdf0e10cSrcweir } 2244*cdf0e10cSrcweir else 2245*cdf0e10cSrcweir return sal_False; 2246*cdf0e10cSrcweir } 2247*cdf0e10cSrcweir 2248*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2249*cdf0e10cSrcweir 2250*cdf0e10cSrcweir Rectangle Calendar::GetDateRect( const Date& rDate ) const 2251*cdf0e10cSrcweir { 2252*cdf0e10cSrcweir Rectangle aRect; 2253*cdf0e10cSrcweir 2254*cdf0e10cSrcweir if ( mbFormat || (rDate < maFirstDate) || (rDate > (maFirstDate+mnDayCount)) ) 2255*cdf0e10cSrcweir return aRect; 2256*cdf0e10cSrcweir 2257*cdf0e10cSrcweir long nX; 2258*cdf0e10cSrcweir long nY; 2259*cdf0e10cSrcweir sal_uLong nDaysOff; 2260*cdf0e10cSrcweir sal_uInt16 nDayIndex; 2261*cdf0e10cSrcweir Date aDate = GetFirstMonth(); 2262*cdf0e10cSrcweir 2263*cdf0e10cSrcweir if ( rDate < aDate ) 2264*cdf0e10cSrcweir { 2265*cdf0e10cSrcweir aRect = GetDateRect( aDate ); 2266*cdf0e10cSrcweir nDaysOff = aDate-rDate; 2267*cdf0e10cSrcweir nX = (long)(nDaysOff*mnDayWidth); 2268*cdf0e10cSrcweir aRect.Left() -= nX; 2269*cdf0e10cSrcweir aRect.Right() -= nX; 2270*cdf0e10cSrcweir return aRect; 2271*cdf0e10cSrcweir } 2272*cdf0e10cSrcweir else 2273*cdf0e10cSrcweir { 2274*cdf0e10cSrcweir Date aLastDate = GetLastMonth(); 2275*cdf0e10cSrcweir if ( rDate > aLastDate ) 2276*cdf0e10cSrcweir { 2277*cdf0e10cSrcweir sal_uInt16 nWeekDay = (sal_uInt16)aLastDate.GetDayOfWeek(); 2278*cdf0e10cSrcweir nWeekDay = (nWeekDay+(7-(sal_uInt16)ImplGetWeekStart())) % 7; 2279*cdf0e10cSrcweir aLastDate -= nWeekDay; 2280*cdf0e10cSrcweir aRect = GetDateRect( aLastDate ); 2281*cdf0e10cSrcweir nDaysOff = rDate-aLastDate; 2282*cdf0e10cSrcweir nDayIndex = 0; 2283*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i <= nDaysOff; i++ ) 2284*cdf0e10cSrcweir { 2285*cdf0e10cSrcweir if ( aLastDate == rDate ) 2286*cdf0e10cSrcweir { 2287*cdf0e10cSrcweir aRect.Left() += nDayIndex*mnDayWidth; 2288*cdf0e10cSrcweir aRect.Right() = aRect.Left()+mnDayWidth; 2289*cdf0e10cSrcweir return aRect; 2290*cdf0e10cSrcweir } 2291*cdf0e10cSrcweir if ( nDayIndex == 6 ) 2292*cdf0e10cSrcweir { 2293*cdf0e10cSrcweir nDayIndex = 0; 2294*cdf0e10cSrcweir aRect.Top() += mnDayHeight; 2295*cdf0e10cSrcweir aRect.Bottom() += mnDayHeight; 2296*cdf0e10cSrcweir } 2297*cdf0e10cSrcweir else 2298*cdf0e10cSrcweir nDayIndex++; 2299*cdf0e10cSrcweir aLastDate++; 2300*cdf0e10cSrcweir } 2301*cdf0e10cSrcweir } 2302*cdf0e10cSrcweir } 2303*cdf0e10cSrcweir 2304*cdf0e10cSrcweir nY = 0; 2305*cdf0e10cSrcweir for ( long i = 0; i < mnLines; i++ ) 2306*cdf0e10cSrcweir { 2307*cdf0e10cSrcweir nX = 0; 2308*cdf0e10cSrcweir for ( long j = 0; j < mnMonthPerLine; j++ ) 2309*cdf0e10cSrcweir { 2310*cdf0e10cSrcweir sal_uInt16 nDaysInMonth = aDate.GetDaysInMonth(); 2311*cdf0e10cSrcweir 2312*cdf0e10cSrcweir // Monat gerufen 2313*cdf0e10cSrcweir if ( (aDate.GetMonth() == rDate.GetMonth()) && 2314*cdf0e10cSrcweir (aDate.GetYear() == rDate.GetYear()) ) 2315*cdf0e10cSrcweir { 2316*cdf0e10cSrcweir long nDayX = nX+mnDaysOffX; 2317*cdf0e10cSrcweir long nDayY = nY+mnDaysOffY; 2318*cdf0e10cSrcweir nDayIndex = (sal_uInt16)aDate.GetDayOfWeek(); 2319*cdf0e10cSrcweir nDayIndex = (nDayIndex+(7-(sal_uInt16)ImplGetWeekStart())) % 7; 2320*cdf0e10cSrcweir for ( sal_uInt16 nDay = 1; nDay <= nDaysInMonth; nDay++ ) 2321*cdf0e10cSrcweir { 2322*cdf0e10cSrcweir if ( nDay == rDate.GetDay() ) 2323*cdf0e10cSrcweir { 2324*cdf0e10cSrcweir aRect.Left() = nDayX + (nDayIndex*mnDayWidth); 2325*cdf0e10cSrcweir aRect.Top() = nDayY; 2326*cdf0e10cSrcweir aRect.Right() = aRect.Left()+mnDayWidth; 2327*cdf0e10cSrcweir aRect.Bottom() = aRect.Top()+mnDayHeight; 2328*cdf0e10cSrcweir break; 2329*cdf0e10cSrcweir } 2330*cdf0e10cSrcweir if ( nDayIndex == 6 ) 2331*cdf0e10cSrcweir { 2332*cdf0e10cSrcweir nDayIndex = 0; 2333*cdf0e10cSrcweir nDayY += mnDayHeight; 2334*cdf0e10cSrcweir } 2335*cdf0e10cSrcweir else 2336*cdf0e10cSrcweir nDayIndex++; 2337*cdf0e10cSrcweir } 2338*cdf0e10cSrcweir } 2339*cdf0e10cSrcweir 2340*cdf0e10cSrcweir aDate += nDaysInMonth; 2341*cdf0e10cSrcweir nX += mnMonthWidth; 2342*cdf0e10cSrcweir } 2343*cdf0e10cSrcweir 2344*cdf0e10cSrcweir nY += mnMonthHeight; 2345*cdf0e10cSrcweir } 2346*cdf0e10cSrcweir 2347*cdf0e10cSrcweir return aRect; 2348*cdf0e10cSrcweir } 2349*cdf0e10cSrcweir 2350*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2351*cdf0e10cSrcweir 2352*cdf0e10cSrcweir void Calendar::SetStandardColor( const Color& rColor ) 2353*cdf0e10cSrcweir { 2354*cdf0e10cSrcweir if ( mpStandardColor ) 2355*cdf0e10cSrcweir *mpStandardColor = rColor; 2356*cdf0e10cSrcweir else 2357*cdf0e10cSrcweir mpStandardColor = new Color( rColor ); 2358*cdf0e10cSrcweir ImplUpdate(); 2359*cdf0e10cSrcweir } 2360*cdf0e10cSrcweir 2361*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2362*cdf0e10cSrcweir 2363*cdf0e10cSrcweir void Calendar::SetSaturdayColor( const Color& rColor ) 2364*cdf0e10cSrcweir { 2365*cdf0e10cSrcweir if ( mpSaturdayColor ) 2366*cdf0e10cSrcweir *mpSaturdayColor = rColor; 2367*cdf0e10cSrcweir else 2368*cdf0e10cSrcweir mpSaturdayColor = new Color( rColor ); 2369*cdf0e10cSrcweir ImplUpdate(); 2370*cdf0e10cSrcweir } 2371*cdf0e10cSrcweir 2372*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2373*cdf0e10cSrcweir 2374*cdf0e10cSrcweir void Calendar::SetSundayColor( const Color& rColor ) 2375*cdf0e10cSrcweir { 2376*cdf0e10cSrcweir if ( mpSundayColor ) 2377*cdf0e10cSrcweir *mpSundayColor = rColor; 2378*cdf0e10cSrcweir else 2379*cdf0e10cSrcweir mpSundayColor = new Color( rColor ); 2380*cdf0e10cSrcweir ImplUpdate(); 2381*cdf0e10cSrcweir } 2382*cdf0e10cSrcweir 2383*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2384*cdf0e10cSrcweir 2385*cdf0e10cSrcweir void Calendar::AddDateInfo( const Date& rDate, const String& rText, 2386*cdf0e10cSrcweir const Color* pTextColor, const Color* pFrameColor, 2387*cdf0e10cSrcweir sal_uInt16 nFlags ) 2388*cdf0e10cSrcweir { 2389*cdf0e10cSrcweir if ( !mpDateTable ) 2390*cdf0e10cSrcweir mpDateTable = new ImplDateTable( 256, 256 ); 2391*cdf0e10cSrcweir 2392*cdf0e10cSrcweir sal_Bool bChanged = sal_False; 2393*cdf0e10cSrcweir sal_uLong nKey = rDate.GetDate(); 2394*cdf0e10cSrcweir ImplDateInfo* pDateInfo = mpDateTable->Get( nKey ); 2395*cdf0e10cSrcweir if ( pDateInfo ) 2396*cdf0e10cSrcweir pDateInfo->maText = rText; 2397*cdf0e10cSrcweir else 2398*cdf0e10cSrcweir { 2399*cdf0e10cSrcweir pDateInfo = new ImplDateInfo( rText ); 2400*cdf0e10cSrcweir mpDateTable->Insert( nKey, pDateInfo ); 2401*cdf0e10cSrcweir } 2402*cdf0e10cSrcweir if ( pTextColor ) 2403*cdf0e10cSrcweir { 2404*cdf0e10cSrcweir if ( pDateInfo->mpTextColor ) 2405*cdf0e10cSrcweir { 2406*cdf0e10cSrcweir if ( *(pDateInfo->mpTextColor) != *pTextColor ) 2407*cdf0e10cSrcweir { 2408*cdf0e10cSrcweir *(pDateInfo->mpTextColor) = *pTextColor; 2409*cdf0e10cSrcweir bChanged = sal_True; 2410*cdf0e10cSrcweir } 2411*cdf0e10cSrcweir } 2412*cdf0e10cSrcweir else 2413*cdf0e10cSrcweir { 2414*cdf0e10cSrcweir pDateInfo->mpTextColor = new Color( *pTextColor ); 2415*cdf0e10cSrcweir bChanged = sal_True; 2416*cdf0e10cSrcweir } 2417*cdf0e10cSrcweir } 2418*cdf0e10cSrcweir else 2419*cdf0e10cSrcweir { 2420*cdf0e10cSrcweir if ( pDateInfo->mpTextColor ) 2421*cdf0e10cSrcweir { 2422*cdf0e10cSrcweir delete pDateInfo->mpTextColor; 2423*cdf0e10cSrcweir pDateInfo->mpTextColor = NULL; 2424*cdf0e10cSrcweir bChanged = sal_True; 2425*cdf0e10cSrcweir } 2426*cdf0e10cSrcweir } 2427*cdf0e10cSrcweir if ( pFrameColor ) 2428*cdf0e10cSrcweir { 2429*cdf0e10cSrcweir if ( pDateInfo->mpFrameColor ) 2430*cdf0e10cSrcweir { 2431*cdf0e10cSrcweir if ( *(pDateInfo->mpFrameColor) != *pFrameColor ) 2432*cdf0e10cSrcweir { 2433*cdf0e10cSrcweir *(pDateInfo->mpFrameColor) = *pFrameColor; 2434*cdf0e10cSrcweir bChanged = sal_True; 2435*cdf0e10cSrcweir } 2436*cdf0e10cSrcweir } 2437*cdf0e10cSrcweir else 2438*cdf0e10cSrcweir { 2439*cdf0e10cSrcweir pDateInfo->mpFrameColor = new Color( *pFrameColor ); 2440*cdf0e10cSrcweir bChanged = sal_True; 2441*cdf0e10cSrcweir } 2442*cdf0e10cSrcweir } 2443*cdf0e10cSrcweir else 2444*cdf0e10cSrcweir { 2445*cdf0e10cSrcweir if ( pDateInfo->mpFrameColor ) 2446*cdf0e10cSrcweir { 2447*cdf0e10cSrcweir delete pDateInfo->mpFrameColor; 2448*cdf0e10cSrcweir pDateInfo->mpFrameColor = NULL; 2449*cdf0e10cSrcweir bChanged = sal_True; 2450*cdf0e10cSrcweir } 2451*cdf0e10cSrcweir } 2452*cdf0e10cSrcweir if ( pDateInfo->mnFlags != nFlags ) 2453*cdf0e10cSrcweir { 2454*cdf0e10cSrcweir pDateInfo->mnFlags = nFlags; 2455*cdf0e10cSrcweir bChanged = sal_True; 2456*cdf0e10cSrcweir } 2457*cdf0e10cSrcweir 2458*cdf0e10cSrcweir if ( bChanged ) 2459*cdf0e10cSrcweir ImplUpdateDate( rDate ); 2460*cdf0e10cSrcweir } 2461*cdf0e10cSrcweir 2462*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2463*cdf0e10cSrcweir 2464*cdf0e10cSrcweir void Calendar::RemoveDateInfo( const Date& rDate ) 2465*cdf0e10cSrcweir { 2466*cdf0e10cSrcweir if ( mpDateTable ) 2467*cdf0e10cSrcweir { 2468*cdf0e10cSrcweir ImplDateInfo* pDateInfo = mpDateTable->Remove( rDate.GetDate() ); 2469*cdf0e10cSrcweir if ( pDateInfo ) 2470*cdf0e10cSrcweir { 2471*cdf0e10cSrcweir delete pDateInfo; 2472*cdf0e10cSrcweir ImplUpdateDate( rDate ); 2473*cdf0e10cSrcweir } 2474*cdf0e10cSrcweir } 2475*cdf0e10cSrcweir } 2476*cdf0e10cSrcweir 2477*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2478*cdf0e10cSrcweir 2479*cdf0e10cSrcweir void Calendar::ClearDateInfo() 2480*cdf0e10cSrcweir { 2481*cdf0e10cSrcweir if ( mpDateTable ) 2482*cdf0e10cSrcweir { 2483*cdf0e10cSrcweir ImplDateInfo* pDateInfo = mpDateTable->First(); 2484*cdf0e10cSrcweir while ( pDateInfo ) 2485*cdf0e10cSrcweir { 2486*cdf0e10cSrcweir sal_uLong nKey = mpDateTable->GetCurKey(); 2487*cdf0e10cSrcweir mpDateTable->Remove( nKey ); 2488*cdf0e10cSrcweir Date aDate( nKey ); 2489*cdf0e10cSrcweir ImplUpdateDate( aDate ); 2490*cdf0e10cSrcweir delete pDateInfo; 2491*cdf0e10cSrcweir pDateInfo = mpDateTable->First(); 2492*cdf0e10cSrcweir } 2493*cdf0e10cSrcweir delete mpDateTable; 2494*cdf0e10cSrcweir mpDateTable = NULL; 2495*cdf0e10cSrcweir } 2496*cdf0e10cSrcweir } 2497*cdf0e10cSrcweir 2498*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2499*cdf0e10cSrcweir 2500*cdf0e10cSrcweir XubString Calendar::GetDateInfoText( const Date& rDate ) 2501*cdf0e10cSrcweir { 2502*cdf0e10cSrcweir XubString aRet; 2503*cdf0e10cSrcweir if ( mpDateTable ) 2504*cdf0e10cSrcweir { 2505*cdf0e10cSrcweir sal_uLong nKey = rDate.GetDate(); 2506*cdf0e10cSrcweir ImplDateInfo* pDateInfo = mpDateTable->Get( nKey ); 2507*cdf0e10cSrcweir if ( pDateInfo ) 2508*cdf0e10cSrcweir aRet = pDateInfo->maText; 2509*cdf0e10cSrcweir } 2510*cdf0e10cSrcweir return aRet; 2511*cdf0e10cSrcweir } 2512*cdf0e10cSrcweir 2513*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2514*cdf0e10cSrcweir 2515*cdf0e10cSrcweir sal_Bool Calendar::ShowDropPos( const Point& rPos, Date& rDate ) 2516*cdf0e10cSrcweir { 2517*cdf0e10cSrcweir Date aTempDate = maCurDate; 2518*cdf0e10cSrcweir mnDragScrollHitTest = ImplHitTest( rPos, aTempDate ); 2519*cdf0e10cSrcweir 2520*cdf0e10cSrcweir if ( mnDragScrollHitTest ) 2521*cdf0e10cSrcweir { 2522*cdf0e10cSrcweir if ( mnDragScrollHitTest & (CALENDAR_HITTEST_PREV | CALENDAR_HITTEST_NEXT) ) 2523*cdf0e10cSrcweir { 2524*cdf0e10cSrcweir if ( !maDragScrollTimer.IsActive() ) 2525*cdf0e10cSrcweir maDragScrollTimer.Start(); 2526*cdf0e10cSrcweir } 2527*cdf0e10cSrcweir else 2528*cdf0e10cSrcweir { 2529*cdf0e10cSrcweir maDragScrollTimer.Stop(); 2530*cdf0e10cSrcweir if ( mnDragScrollHitTest & CALENDAR_HITTEST_DAY ) 2531*cdf0e10cSrcweir { 2532*cdf0e10cSrcweir if ( !mbDropPos || (aTempDate != maDropDate) ) 2533*cdf0e10cSrcweir { 2534*cdf0e10cSrcweir if( mbDropPos ) 2535*cdf0e10cSrcweir ImplInvertDropPos(); 2536*cdf0e10cSrcweir maDropDate = aTempDate; 2537*cdf0e10cSrcweir mbDropPos = sal_True; 2538*cdf0e10cSrcweir ImplInvertDropPos(); 2539*cdf0e10cSrcweir } 2540*cdf0e10cSrcweir 2541*cdf0e10cSrcweir rDate = maDropDate; 2542*cdf0e10cSrcweir return sal_True; 2543*cdf0e10cSrcweir } 2544*cdf0e10cSrcweir } 2545*cdf0e10cSrcweir } 2546*cdf0e10cSrcweir else 2547*cdf0e10cSrcweir maDragScrollTimer.Stop(); 2548*cdf0e10cSrcweir 2549*cdf0e10cSrcweir HideDropPos(); 2550*cdf0e10cSrcweir return sal_False; 2551*cdf0e10cSrcweir } 2552*cdf0e10cSrcweir 2553*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2554*cdf0e10cSrcweir 2555*cdf0e10cSrcweir void Calendar::HideDropPos() 2556*cdf0e10cSrcweir { 2557*cdf0e10cSrcweir if ( mbDropPos ) 2558*cdf0e10cSrcweir { 2559*cdf0e10cSrcweir ImplInvertDropPos(); 2560*cdf0e10cSrcweir mbDropPos = sal_False; 2561*cdf0e10cSrcweir } 2562*cdf0e10cSrcweir } 2563*cdf0e10cSrcweir 2564*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2565*cdf0e10cSrcweir 2566*cdf0e10cSrcweir void Calendar::StartSelection() 2567*cdf0e10cSrcweir { 2568*cdf0e10cSrcweir if ( mpOldSelectTable ) 2569*cdf0e10cSrcweir delete mpOldSelectTable; 2570*cdf0e10cSrcweir maOldCurDate = maCurDate; 2571*cdf0e10cSrcweir mpOldSelectTable = new Table( *mpSelectTable ); 2572*cdf0e10cSrcweir 2573*cdf0e10cSrcweir mbSelection = sal_True; 2574*cdf0e10cSrcweir } 2575*cdf0e10cSrcweir 2576*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2577*cdf0e10cSrcweir 2578*cdf0e10cSrcweir void Calendar::EndSelection() 2579*cdf0e10cSrcweir { 2580*cdf0e10cSrcweir if ( mbDrag || mbSpinDown || mbSelection ) 2581*cdf0e10cSrcweir { 2582*cdf0e10cSrcweir if ( !mbSelection ) 2583*cdf0e10cSrcweir ReleaseMouse(); 2584*cdf0e10cSrcweir 2585*cdf0e10cSrcweir mbDrag = sal_False; 2586*cdf0e10cSrcweir mbSelection = sal_False; 2587*cdf0e10cSrcweir mbMultiSelection = sal_False; 2588*cdf0e10cSrcweir mbSpinDown = sal_False; 2589*cdf0e10cSrcweir mbPrevIn = sal_False; 2590*cdf0e10cSrcweir mbNextIn = sal_False; 2591*cdf0e10cSrcweir } 2592*cdf0e10cSrcweir } 2593*cdf0e10cSrcweir 2594*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2595*cdf0e10cSrcweir 2596*cdf0e10cSrcweir Size Calendar::CalcWindowSizePixel( long nCalcMonthPerLine, 2597*cdf0e10cSrcweir long nCalcLines ) const 2598*cdf0e10cSrcweir { 2599*cdf0e10cSrcweir XubString a99Text( XubString( RTL_CONSTASCII_USTRINGPARAM( "99" ) ) ); 2600*cdf0e10cSrcweir Font aOldFont = GetFont(); 2601*cdf0e10cSrcweir 2602*cdf0e10cSrcweir // Wochenanzeige beruecksichtigen 2603*cdf0e10cSrcweir long nWeekWidth; 2604*cdf0e10cSrcweir if ( mnWinStyle & WB_WEEKNUMBER ) 2605*cdf0e10cSrcweir { 2606*cdf0e10cSrcweir Font aTempFont = aOldFont; 2607*cdf0e10cSrcweir ImplGetWeekFont( aTempFont ); 2608*cdf0e10cSrcweir ((Calendar*)this)->SetFont( aTempFont ); 2609*cdf0e10cSrcweir nWeekWidth = GetTextWidth( a99Text )+WEEKNUMBER_OFFX; 2610*cdf0e10cSrcweir ((Calendar*)this)->SetFont( aOldFont ); 2611*cdf0e10cSrcweir } 2612*cdf0e10cSrcweir else 2613*cdf0e10cSrcweir nWeekWidth = 0; 2614*cdf0e10cSrcweir 2615*cdf0e10cSrcweir if ( mnWinStyle & WB_BOLDTEXT ) 2616*cdf0e10cSrcweir { 2617*cdf0e10cSrcweir Font aFont = aOldFont; 2618*cdf0e10cSrcweir if ( aFont.GetWeight() < WEIGHT_BOLD ) 2619*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD ); 2620*cdf0e10cSrcweir else 2621*cdf0e10cSrcweir aFont.SetWeight( WEIGHT_NORMAL ); 2622*cdf0e10cSrcweir ((Calendar*)this)->SetFont( aFont ); 2623*cdf0e10cSrcweir } 2624*cdf0e10cSrcweir 2625*cdf0e10cSrcweir Size aSize; 2626*cdf0e10cSrcweir long n99TextWidth = GetTextWidth( a99Text ); 2627*cdf0e10cSrcweir long nTextHeight = GetTextHeight(); 2628*cdf0e10cSrcweir 2629*cdf0e10cSrcweir if ( mnWinStyle & WB_BOLDTEXT ) 2630*cdf0e10cSrcweir ((Calendar*)this)->SetFont( aOldFont ); 2631*cdf0e10cSrcweir 2632*cdf0e10cSrcweir aSize.Width() += ((n99TextWidth+DAY_OFFX)*7) + nWeekWidth; 2633*cdf0e10cSrcweir aSize.Width() += MONTH_BORDERX*2; 2634*cdf0e10cSrcweir aSize.Width() *= nCalcMonthPerLine; 2635*cdf0e10cSrcweir 2636*cdf0e10cSrcweir aSize.Height() = nTextHeight + TITLE_OFFY + (TITLE_BORDERY*2); 2637*cdf0e10cSrcweir aSize.Height() += nTextHeight + WEEKDAY_OFFY; 2638*cdf0e10cSrcweir aSize.Height() += ((nTextHeight+DAY_OFFY)*6); 2639*cdf0e10cSrcweir aSize.Height() += MONTH_OFFY; 2640*cdf0e10cSrcweir aSize.Height() *= nCalcLines; 2641*cdf0e10cSrcweir 2642*cdf0e10cSrcweir return aSize; 2643*cdf0e10cSrcweir } 2644*cdf0e10cSrcweir 2645*cdf0e10cSrcweir // ======================================================================= 2646*cdf0e10cSrcweir 2647*cdf0e10cSrcweir #define CALFIELD_EXTRA_BUTTON_WIDTH 14 2648*cdf0e10cSrcweir #define CALFIELD_EXTRA_BUTTON_HEIGHT 8 2649*cdf0e10cSrcweir #define CALFIELD_SEP_X 6 2650*cdf0e10cSrcweir #define CALFIELD_BORDERLINE_X 5 2651*cdf0e10cSrcweir #define CALFIELD_BORDER_YTOP 4 2652*cdf0e10cSrcweir #define CALFIELD_BORDER_Y 5 2653*cdf0e10cSrcweir 2654*cdf0e10cSrcweir // ======================================================================= 2655*cdf0e10cSrcweir 2656*cdf0e10cSrcweir class ImplCFieldFloatWin : public FloatingWindow 2657*cdf0e10cSrcweir { 2658*cdf0e10cSrcweir private: 2659*cdf0e10cSrcweir Calendar* mpCalendar; 2660*cdf0e10cSrcweir PushButton* mpTodayBtn; 2661*cdf0e10cSrcweir PushButton* mpNoneBtn; 2662*cdf0e10cSrcweir FixedLine* mpFixedLine; 2663*cdf0e10cSrcweir 2664*cdf0e10cSrcweir public: 2665*cdf0e10cSrcweir ImplCFieldFloatWin( Window* pParent ); 2666*cdf0e10cSrcweir ~ImplCFieldFloatWin(); 2667*cdf0e10cSrcweir 2668*cdf0e10cSrcweir void SetCalendar( Calendar* pCalendar ) 2669*cdf0e10cSrcweir { mpCalendar = pCalendar; } 2670*cdf0e10cSrcweir 2671*cdf0e10cSrcweir PushButton* EnableTodayBtn( sal_Bool bEnable ); 2672*cdf0e10cSrcweir PushButton* EnableNoneBtn( sal_Bool bEnable ); 2673*cdf0e10cSrcweir void ArrangeButtons(); 2674*cdf0e10cSrcweir 2675*cdf0e10cSrcweir long Notify( NotifyEvent& rNEvt ); 2676*cdf0e10cSrcweir }; 2677*cdf0e10cSrcweir 2678*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2679*cdf0e10cSrcweir 2680*cdf0e10cSrcweir ImplCFieldFloatWin::ImplCFieldFloatWin( Window* pParent ) : 2681*cdf0e10cSrcweir FloatingWindow( pParent, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW ) 2682*cdf0e10cSrcweir { 2683*cdf0e10cSrcweir mpCalendar = NULL; 2684*cdf0e10cSrcweir mpTodayBtn = NULL; 2685*cdf0e10cSrcweir mpNoneBtn = NULL; 2686*cdf0e10cSrcweir mpFixedLine = NULL; 2687*cdf0e10cSrcweir } 2688*cdf0e10cSrcweir 2689*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2690*cdf0e10cSrcweir 2691*cdf0e10cSrcweir ImplCFieldFloatWin::~ImplCFieldFloatWin() 2692*cdf0e10cSrcweir { 2693*cdf0e10cSrcweir delete mpTodayBtn; 2694*cdf0e10cSrcweir delete mpNoneBtn; 2695*cdf0e10cSrcweir delete mpFixedLine; 2696*cdf0e10cSrcweir } 2697*cdf0e10cSrcweir 2698*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2699*cdf0e10cSrcweir 2700*cdf0e10cSrcweir PushButton* ImplCFieldFloatWin::EnableTodayBtn( sal_Bool bEnable ) 2701*cdf0e10cSrcweir { 2702*cdf0e10cSrcweir if ( bEnable ) 2703*cdf0e10cSrcweir { 2704*cdf0e10cSrcweir if ( !mpTodayBtn ) 2705*cdf0e10cSrcweir { 2706*cdf0e10cSrcweir mpTodayBtn = new PushButton( this, WB_NOPOINTERFOCUS ); 2707*cdf0e10cSrcweir XubString aTodayText( SvtResId( STR_SVT_CALENDAR_TODAY ) ); 2708*cdf0e10cSrcweir mpTodayBtn->SetText( aTodayText ); 2709*cdf0e10cSrcweir Size aSize; 2710*cdf0e10cSrcweir aSize.Width() = mpTodayBtn->GetCtrlTextWidth( mpTodayBtn->GetText() ); 2711*cdf0e10cSrcweir aSize.Height() = mpTodayBtn->GetTextHeight(); 2712*cdf0e10cSrcweir aSize.Width() += CALFIELD_EXTRA_BUTTON_WIDTH; 2713*cdf0e10cSrcweir aSize.Height() += CALFIELD_EXTRA_BUTTON_HEIGHT; 2714*cdf0e10cSrcweir mpTodayBtn->SetSizePixel( aSize ); 2715*cdf0e10cSrcweir mpTodayBtn->Show(); 2716*cdf0e10cSrcweir } 2717*cdf0e10cSrcweir } 2718*cdf0e10cSrcweir else 2719*cdf0e10cSrcweir { 2720*cdf0e10cSrcweir if ( mpTodayBtn ) 2721*cdf0e10cSrcweir { 2722*cdf0e10cSrcweir delete mpTodayBtn; 2723*cdf0e10cSrcweir mpTodayBtn = NULL; 2724*cdf0e10cSrcweir } 2725*cdf0e10cSrcweir } 2726*cdf0e10cSrcweir 2727*cdf0e10cSrcweir return mpTodayBtn; 2728*cdf0e10cSrcweir } 2729*cdf0e10cSrcweir 2730*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2731*cdf0e10cSrcweir 2732*cdf0e10cSrcweir PushButton* ImplCFieldFloatWin::EnableNoneBtn( sal_Bool bEnable ) 2733*cdf0e10cSrcweir { 2734*cdf0e10cSrcweir if ( bEnable ) 2735*cdf0e10cSrcweir { 2736*cdf0e10cSrcweir if ( !mpNoneBtn ) 2737*cdf0e10cSrcweir { 2738*cdf0e10cSrcweir mpNoneBtn = new PushButton( this, WB_NOPOINTERFOCUS ); 2739*cdf0e10cSrcweir XubString aNoneText( SvtResId( STR_SVT_CALENDAR_NONE ) ); 2740*cdf0e10cSrcweir mpNoneBtn->SetText( aNoneText ); 2741*cdf0e10cSrcweir Size aSize; 2742*cdf0e10cSrcweir aSize.Width() = mpNoneBtn->GetCtrlTextWidth( mpNoneBtn->GetText() ); 2743*cdf0e10cSrcweir aSize.Height() = mpNoneBtn->GetTextHeight(); 2744*cdf0e10cSrcweir aSize.Width() += CALFIELD_EXTRA_BUTTON_WIDTH; 2745*cdf0e10cSrcweir aSize.Height() += CALFIELD_EXTRA_BUTTON_HEIGHT; 2746*cdf0e10cSrcweir mpNoneBtn->SetSizePixel( aSize ); 2747*cdf0e10cSrcweir mpNoneBtn->Show(); 2748*cdf0e10cSrcweir } 2749*cdf0e10cSrcweir } 2750*cdf0e10cSrcweir else 2751*cdf0e10cSrcweir { 2752*cdf0e10cSrcweir if ( mpNoneBtn ) 2753*cdf0e10cSrcweir { 2754*cdf0e10cSrcweir delete mpNoneBtn; 2755*cdf0e10cSrcweir mpNoneBtn = NULL; 2756*cdf0e10cSrcweir } 2757*cdf0e10cSrcweir } 2758*cdf0e10cSrcweir 2759*cdf0e10cSrcweir return mpNoneBtn; 2760*cdf0e10cSrcweir } 2761*cdf0e10cSrcweir 2762*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2763*cdf0e10cSrcweir 2764*cdf0e10cSrcweir void ImplCFieldFloatWin::ArrangeButtons() 2765*cdf0e10cSrcweir { 2766*cdf0e10cSrcweir long nBtnHeight = 0; 2767*cdf0e10cSrcweir long nBtnWidth = 0; 2768*cdf0e10cSrcweir Size aOutSize = GetOutputSizePixel(); 2769*cdf0e10cSrcweir if ( mpTodayBtn && mpNoneBtn ) 2770*cdf0e10cSrcweir { 2771*cdf0e10cSrcweir Size aTodayBtnSize = mpTodayBtn->GetSizePixel(); 2772*cdf0e10cSrcweir Size aNoneBtnSize = mpNoneBtn->GetSizePixel(); 2773*cdf0e10cSrcweir if ( aTodayBtnSize.Width() < aNoneBtnSize.Width() ) 2774*cdf0e10cSrcweir aTodayBtnSize.Width() = aNoneBtnSize.Width(); 2775*cdf0e10cSrcweir else 2776*cdf0e10cSrcweir aNoneBtnSize.Width() = aTodayBtnSize.Width(); 2777*cdf0e10cSrcweir if ( aTodayBtnSize.Height() < aNoneBtnSize.Height() ) 2778*cdf0e10cSrcweir aTodayBtnSize.Height() = aNoneBtnSize.Height(); 2779*cdf0e10cSrcweir else 2780*cdf0e10cSrcweir aNoneBtnSize.Height() = aTodayBtnSize.Height(); 2781*cdf0e10cSrcweir 2782*cdf0e10cSrcweir nBtnWidth = aTodayBtnSize.Width() + aNoneBtnSize.Width() + CALFIELD_SEP_X; 2783*cdf0e10cSrcweir nBtnHeight = aTodayBtnSize.Height(); 2784*cdf0e10cSrcweir long nX = (aOutSize.Width()-nBtnWidth)/2; 2785*cdf0e10cSrcweir long nY = aOutSize.Height()+CALFIELD_BORDER_Y+CALFIELD_BORDER_YTOP; 2786*cdf0e10cSrcweir mpTodayBtn->SetPosSizePixel( Point( nX, nY ), aTodayBtnSize ); 2787*cdf0e10cSrcweir nX += aTodayBtnSize.Width() + CALFIELD_SEP_X; 2788*cdf0e10cSrcweir mpNoneBtn->SetPosSizePixel( Point( nX, nY ), aNoneBtnSize ); 2789*cdf0e10cSrcweir } 2790*cdf0e10cSrcweir else if ( mpTodayBtn ) 2791*cdf0e10cSrcweir { 2792*cdf0e10cSrcweir Size aTodayBtnSize = mpTodayBtn->GetSizePixel(); 2793*cdf0e10cSrcweir nBtnWidth = aTodayBtnSize.Width(); 2794*cdf0e10cSrcweir nBtnHeight = aTodayBtnSize.Height(); 2795*cdf0e10cSrcweir mpTodayBtn->SetPosPixel( Point( (aOutSize.Width()-nBtnWidth)/2, aOutSize.Height()+CALFIELD_BORDER_Y+CALFIELD_BORDER_YTOP ) ); 2796*cdf0e10cSrcweir } 2797*cdf0e10cSrcweir else if ( mpNoneBtn ) 2798*cdf0e10cSrcweir { 2799*cdf0e10cSrcweir Size aNoneBtnSize = mpNoneBtn->GetSizePixel(); 2800*cdf0e10cSrcweir nBtnWidth = aNoneBtnSize.Width(); 2801*cdf0e10cSrcweir nBtnHeight = aNoneBtnSize.Height(); 2802*cdf0e10cSrcweir mpNoneBtn->SetPosPixel( Point( (aOutSize.Width()-nBtnWidth)/2, aOutSize.Height()+CALFIELD_BORDER_Y+CALFIELD_BORDER_YTOP ) ); 2803*cdf0e10cSrcweir } 2804*cdf0e10cSrcweir 2805*cdf0e10cSrcweir if ( nBtnHeight ) 2806*cdf0e10cSrcweir { 2807*cdf0e10cSrcweir if ( !mpFixedLine ) 2808*cdf0e10cSrcweir { 2809*cdf0e10cSrcweir mpFixedLine = new FixedLine( this ); 2810*cdf0e10cSrcweir mpFixedLine->Show(); 2811*cdf0e10cSrcweir } 2812*cdf0e10cSrcweir long nLineWidth = aOutSize.Width()-(CALFIELD_BORDERLINE_X*2); 2813*cdf0e10cSrcweir mpFixedLine->SetPosSizePixel( (aOutSize.Width()-nLineWidth)/2, aOutSize.Height()+((CALFIELD_BORDER_YTOP-2)/2), 2814*cdf0e10cSrcweir nLineWidth, 2, WINDOW_POSSIZE_POSSIZE ); 2815*cdf0e10cSrcweir aOutSize.Height() += nBtnHeight + (CALFIELD_BORDER_Y*2) + CALFIELD_BORDER_YTOP; 2816*cdf0e10cSrcweir SetOutputSizePixel( aOutSize ); 2817*cdf0e10cSrcweir } 2818*cdf0e10cSrcweir else 2819*cdf0e10cSrcweir { 2820*cdf0e10cSrcweir if ( mpFixedLine ) 2821*cdf0e10cSrcweir { 2822*cdf0e10cSrcweir delete mpFixedLine; 2823*cdf0e10cSrcweir mpFixedLine = NULL; 2824*cdf0e10cSrcweir } 2825*cdf0e10cSrcweir } 2826*cdf0e10cSrcweir } 2827*cdf0e10cSrcweir 2828*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2829*cdf0e10cSrcweir 2830*cdf0e10cSrcweir long ImplCFieldFloatWin::Notify( NotifyEvent& rNEvt ) 2831*cdf0e10cSrcweir { 2832*cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_KEYINPUT ) 2833*cdf0e10cSrcweir { 2834*cdf0e10cSrcweir const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); 2835*cdf0e10cSrcweir if ( pKEvt->GetKeyCode().GetCode() == KEY_RETURN ) 2836*cdf0e10cSrcweir mpCalendar->Select(); 2837*cdf0e10cSrcweir } 2838*cdf0e10cSrcweir 2839*cdf0e10cSrcweir return FloatingWindow::Notify( rNEvt ); 2840*cdf0e10cSrcweir } 2841*cdf0e10cSrcweir 2842*cdf0e10cSrcweir // ======================================================================= 2843*cdf0e10cSrcweir 2844*cdf0e10cSrcweir CalendarField::CalendarField( Window* pParent, WinBits nWinStyle ) : 2845*cdf0e10cSrcweir DateField( pParent, nWinStyle ), 2846*cdf0e10cSrcweir maDefaultDate( 0, 0, 0 ) 2847*cdf0e10cSrcweir { 2848*cdf0e10cSrcweir mpFloatWin = NULL; 2849*cdf0e10cSrcweir mpCalendar = NULL; 2850*cdf0e10cSrcweir mnCalendarStyle = 0; 2851*cdf0e10cSrcweir mbToday = sal_False; 2852*cdf0e10cSrcweir mbNone = sal_False; 2853*cdf0e10cSrcweir } 2854*cdf0e10cSrcweir 2855*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2856*cdf0e10cSrcweir 2857*cdf0e10cSrcweir CalendarField::CalendarField( Window* pParent, const ResId& rResId ) : 2858*cdf0e10cSrcweir DateField( pParent, rResId ), 2859*cdf0e10cSrcweir maDefaultDate( 0, 0, 0 ) 2860*cdf0e10cSrcweir { 2861*cdf0e10cSrcweir mpFloatWin = NULL; 2862*cdf0e10cSrcweir mpCalendar = NULL; 2863*cdf0e10cSrcweir mnCalendarStyle = 0; 2864*cdf0e10cSrcweir mbToday = sal_False; 2865*cdf0e10cSrcweir mbNone = sal_False; 2866*cdf0e10cSrcweir } 2867*cdf0e10cSrcweir 2868*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2869*cdf0e10cSrcweir 2870*cdf0e10cSrcweir CalendarField::~CalendarField() 2871*cdf0e10cSrcweir { 2872*cdf0e10cSrcweir if ( mpFloatWin ) 2873*cdf0e10cSrcweir { 2874*cdf0e10cSrcweir delete mpCalendar; 2875*cdf0e10cSrcweir delete mpFloatWin; 2876*cdf0e10cSrcweir } 2877*cdf0e10cSrcweir } 2878*cdf0e10cSrcweir 2879*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2880*cdf0e10cSrcweir 2881*cdf0e10cSrcweir IMPL_LINK( CalendarField, ImplSelectHdl, Calendar*, pCalendar ) 2882*cdf0e10cSrcweir { 2883*cdf0e10cSrcweir if ( !pCalendar->IsTravelSelect() ) 2884*cdf0e10cSrcweir { 2885*cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 2886*cdf0e10cSrcweir EndDropDown(); 2887*cdf0e10cSrcweir GrabFocus(); 2888*cdf0e10cSrcweir Date aNewDate = mpCalendar->GetSelectDate( 0 ); 2889*cdf0e10cSrcweir if ( IsEmptyDate() || ( aNewDate != GetDate() ) ) 2890*cdf0e10cSrcweir { 2891*cdf0e10cSrcweir SetDate( aNewDate ); 2892*cdf0e10cSrcweir SetModifyFlag(); 2893*cdf0e10cSrcweir Modify(); 2894*cdf0e10cSrcweir } 2895*cdf0e10cSrcweir Select(); 2896*cdf0e10cSrcweir } 2897*cdf0e10cSrcweir return 0; 2898*cdf0e10cSrcweir } 2899*cdf0e10cSrcweir 2900*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2901*cdf0e10cSrcweir 2902*cdf0e10cSrcweir IMPL_LINK( CalendarField, ImplClickHdl, PushButton*, pBtn ) 2903*cdf0e10cSrcweir { 2904*cdf0e10cSrcweir mpFloatWin->EndPopupMode(); 2905*cdf0e10cSrcweir EndDropDown(); 2906*cdf0e10cSrcweir GrabFocus(); 2907*cdf0e10cSrcweir 2908*cdf0e10cSrcweir if ( pBtn == mpTodayBtn ) 2909*cdf0e10cSrcweir { 2910*cdf0e10cSrcweir Date aToday; 2911*cdf0e10cSrcweir if ( (aToday != GetDate()) || IsEmptyDate() ) 2912*cdf0e10cSrcweir { 2913*cdf0e10cSrcweir SetDate( aToday ); 2914*cdf0e10cSrcweir SetModifyFlag(); 2915*cdf0e10cSrcweir Modify(); 2916*cdf0e10cSrcweir } 2917*cdf0e10cSrcweir } 2918*cdf0e10cSrcweir else if ( pBtn == mpNoneBtn ) 2919*cdf0e10cSrcweir { 2920*cdf0e10cSrcweir if ( !IsEmptyDate() ) 2921*cdf0e10cSrcweir { 2922*cdf0e10cSrcweir SetEmptyDate(); 2923*cdf0e10cSrcweir SetModifyFlag(); 2924*cdf0e10cSrcweir Modify(); 2925*cdf0e10cSrcweir } 2926*cdf0e10cSrcweir } 2927*cdf0e10cSrcweir Select(); 2928*cdf0e10cSrcweir 2929*cdf0e10cSrcweir return 0; 2930*cdf0e10cSrcweir } 2931*cdf0e10cSrcweir 2932*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2933*cdf0e10cSrcweir 2934*cdf0e10cSrcweir IMPL_LINK( CalendarField, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG ) 2935*cdf0e10cSrcweir { 2936*cdf0e10cSrcweir EndDropDown(); 2937*cdf0e10cSrcweir GrabFocus(); 2938*cdf0e10cSrcweir mpCalendar->EndSelection(); 2939*cdf0e10cSrcweir return 0; 2940*cdf0e10cSrcweir } 2941*cdf0e10cSrcweir 2942*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2943*cdf0e10cSrcweir 2944*cdf0e10cSrcweir void CalendarField::Select() 2945*cdf0e10cSrcweir { 2946*cdf0e10cSrcweir maSelectHdl.Call( this ); 2947*cdf0e10cSrcweir } 2948*cdf0e10cSrcweir 2949*cdf0e10cSrcweir // ----------------------------------------------------------------------- 2950*cdf0e10cSrcweir 2951*cdf0e10cSrcweir sal_Bool CalendarField::ShowDropDown( sal_Bool bShow ) 2952*cdf0e10cSrcweir { 2953*cdf0e10cSrcweir if ( bShow ) 2954*cdf0e10cSrcweir { 2955*cdf0e10cSrcweir Calendar* pCalendar = GetCalendar(); 2956*cdf0e10cSrcweir 2957*cdf0e10cSrcweir Date aDate = GetDate(); 2958*cdf0e10cSrcweir if ( IsEmptyDate() || !aDate.IsValid() ) 2959*cdf0e10cSrcweir { 2960*cdf0e10cSrcweir if ( maDefaultDate.IsValid() ) 2961*cdf0e10cSrcweir aDate = maDefaultDate; 2962*cdf0e10cSrcweir else 2963*cdf0e10cSrcweir aDate = Date(); 2964*cdf0e10cSrcweir } 2965*cdf0e10cSrcweir if ( pCalendar->GetStyle() & (WB_RANGESELECT | WB_MULTISELECT) ) 2966*cdf0e10cSrcweir { 2967*cdf0e10cSrcweir pCalendar->SetNoSelection(); 2968*cdf0e10cSrcweir pCalendar->SelectDate( aDate ); 2969*cdf0e10cSrcweir } 2970*cdf0e10cSrcweir pCalendar->SetCurDate( aDate ); 2971*cdf0e10cSrcweir Point aPos( GetParent()->OutputToScreenPixel( GetPosPixel() ) ); 2972*cdf0e10cSrcweir Rectangle aRect( aPos, GetSizePixel() ); 2973*cdf0e10cSrcweir aRect.Bottom() -= 1; 2974*cdf0e10cSrcweir mpCalendar->SetOutputSizePixel( mpCalendar->CalcWindowSizePixel() ); 2975*cdf0e10cSrcweir mpFloatWin->SetOutputSizePixel( mpCalendar->GetSizePixel() ); 2976*cdf0e10cSrcweir mpFloatWin->SetCalendar( mpCalendar ); 2977*cdf0e10cSrcweir mpTodayBtn = mpFloatWin->EnableTodayBtn( mbToday ); 2978*cdf0e10cSrcweir mpNoneBtn = mpFloatWin->EnableNoneBtn( mbNone ); 2979*cdf0e10cSrcweir if ( mpTodayBtn ) 2980*cdf0e10cSrcweir mpTodayBtn->SetClickHdl( LINK( this, CalendarField, ImplClickHdl ) ); 2981*cdf0e10cSrcweir if ( mpNoneBtn ) 2982*cdf0e10cSrcweir mpNoneBtn->SetClickHdl( LINK( this, CalendarField, ImplClickHdl ) ); 2983*cdf0e10cSrcweir mpFloatWin->ArrangeButtons(); 2984*cdf0e10cSrcweir mpCalendar->EnableCallEverySelect(); 2985*cdf0e10cSrcweir mpCalendar->StartSelection(); 2986*cdf0e10cSrcweir mpCalendar->GrabFocus(); 2987*cdf0e10cSrcweir mpCalendar->Show(); 2988*cdf0e10cSrcweir mpFloatWin->StartPopupMode( aRect, FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN ); 2989*cdf0e10cSrcweir } 2990*cdf0e10cSrcweir else 2991*cdf0e10cSrcweir { 2992*cdf0e10cSrcweir mpFloatWin->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL ); 2993*cdf0e10cSrcweir mpCalendar->EndSelection(); 2994*cdf0e10cSrcweir EndDropDown(); 2995*cdf0e10cSrcweir } 2996*cdf0e10cSrcweir return sal_True; 2997*cdf0e10cSrcweir } 2998*cdf0e10cSrcweir 2999*cdf0e10cSrcweir // ----------------------------------------------------------------------- 3000*cdf0e10cSrcweir 3001*cdf0e10cSrcweir Calendar* CalendarField::CreateCalendar( Window* pParent ) 3002*cdf0e10cSrcweir { 3003*cdf0e10cSrcweir return new Calendar( pParent, mnCalendarStyle | WB_TABSTOP ); 3004*cdf0e10cSrcweir } 3005*cdf0e10cSrcweir 3006*cdf0e10cSrcweir // ----------------------------------------------------------------------- 3007*cdf0e10cSrcweir 3008*cdf0e10cSrcweir Calendar* CalendarField::GetCalendar() 3009*cdf0e10cSrcweir { 3010*cdf0e10cSrcweir if ( !mpFloatWin ) 3011*cdf0e10cSrcweir { 3012*cdf0e10cSrcweir mpFloatWin = new ImplCFieldFloatWin( this ); 3013*cdf0e10cSrcweir mpFloatWin->SetPopupModeEndHdl( LINK( this, CalendarField, ImplPopupModeEndHdl ) ); 3014*cdf0e10cSrcweir mpCalendar = CreateCalendar( mpFloatWin ); 3015*cdf0e10cSrcweir mpCalendar->SetPosPixel( Point() ); 3016*cdf0e10cSrcweir mpCalendar->SetSelectHdl( LINK( this, CalendarField, ImplSelectHdl ) ); 3017*cdf0e10cSrcweir } 3018*cdf0e10cSrcweir 3019*cdf0e10cSrcweir return mpCalendar; 3020*cdf0e10cSrcweir } 3021*cdf0e10cSrcweir 3022*cdf0e10cSrcweir // ----------------------------------------------------------------------- 3023*cdf0e10cSrcweir 3024*cdf0e10cSrcweir void CalendarField::StateChanged( StateChangedType nStateChange ) 3025*cdf0e10cSrcweir { 3026*cdf0e10cSrcweir DateField::StateChanged( nStateChange ); 3027*cdf0e10cSrcweir 3028*cdf0e10cSrcweir if ( ( nStateChange == STATE_CHANGE_STYLE ) && GetSubEdit() ) 3029*cdf0e10cSrcweir { 3030*cdf0e10cSrcweir WinBits nAllAlignmentBits = ( WB_LEFT | WB_CENTER | WB_RIGHT | WB_TOP | WB_VCENTER | WB_BOTTOM ); 3031*cdf0e10cSrcweir WinBits nMyAlignment = GetStyle() & nAllAlignmentBits; 3032*cdf0e10cSrcweir GetSubEdit()->SetStyle( ( GetSubEdit()->GetStyle() & ~nAllAlignmentBits ) | nMyAlignment ); 3033*cdf0e10cSrcweir } 3034*cdf0e10cSrcweir } 3035*cdf0e10cSrcweir 3036