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