LibreOffice Module vcl (master) 1
vcl/inc/calendar.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_VCL_CALENDAR_HXX
21#define INCLUDED_VCL_CALENDAR_HXX
22
23#include <vcl/dllapi.h>
25
26#include <vcl/ctrl.hxx>
27#include <memory>
28#include <set>
29
30class MouseEvent;
31class TrackingEvent;
32class KeyEvent;
33class HelpEvent;
35
36/*************************************************************************
37
38Description
39============
40
41class Calendar
42
43This class allows for the selection of a date. The displayed date range is
44the one specified by the Date class. We display as many months as we have
45space in the control. The user can switch between months using a ContextMenu
46(clicking on the month's name) or via two ScrollButtons in-between the months.
47
48--------------------------------------------------------------------------
49
50WinBits
51
52WB_BORDER We draw a border around the window.
53WB_TABSTOP Keyboard control is possible. We get the focus, when
54 the user clicks in the Control.
55
56--------------------------------------------------------------------------
57
58We set and get the selected date by SetCurDate()/GetCurDate().
59If the user selects a date Select() is called. If the user double clicks
60DoubleClick() is called.
61
62--------------------------------------------------------------------------
63
64CalcWindowSizePixel() calculates the window size in pixel that is needed
65to display a certain number of months.
66
67--------------------------------------------------------------------------
68
69SetSaturdayColor() and SetSundayColor() set a special color for Saturdays
70and Sundays.
71AddDateInfo() marks special days. With that we can set e.g. public holidays
72to another color or encircle them (for e.g. appointments).
73If we do not supply a year in the date, the day is used in EVERY year.
74
75AddDateInfo() can also add text for every date, which is displayed if the
76BalloonHelp is enabled.
77In order to not have to supply all years with the relevant data, we call
78the RequestDateInfo() handler if a new year is displayed. We can then query
79the year in the handler with GetRequestYear().
80
81--------------------------------------------------------------------------
82
83In order to display a ContextMenu for a date, we need to override the
84Command handler. GetDate() can infer the date from the mouse's position.
85If we use the keyboard, the current date should be use.
86
87If a ContextMenu is displayed, the baseclass' handler must not be called.
88
89--------------------------------------------------------------------------
90
91SetNoSelection() deselects everything.
92SetCurDate() does not select the current date, but only defines the focus
93rectangle.
94GetSelectDateCount()/GetSelectDate() query the selected range.
95IsDateSelected() queries for the status of a date.
96
97The SelectionChanging() handler is being called while a user selects a
98date. In it, we can change the selected range. E.g. if we want to limit
99or extend the selected range. The selected range is realised via SelectDate()
100and SelectDateRange() and queried with GetSelectDateCount()/GetSelectDate().
101
102IsSelectLeft() returns the direction of the selection:
103sal_True is a selection to the left or up
104sal_False is a selection to the right or down
105
106--------------------------------------------------------------------------
107
108If the DateRange area changes and we want to take over the selection, we
109should only do this is if IsScrollDateRangeChanged() returns sal_True.
110This method returns sal_True if the area change was triggered by using the
111ScrollButtons and sal_False if it was triggered by Resize(), other method
112calls or by ending a selection.
113
114*************************************************************************/
115
116typedef std::set<sal_Int32> IntDateSet;
117
118class Calendar final : public Control
119{
120 std::unique_ptr<IntDateSet> mpSelectTable;
121 std::unique_ptr<IntDateSet> mpOldSelectTable;
122 OUString maDayTexts[31];
123 OUString maDayText;
124 OUString maWeekText;
129 sal_Int32 mnDayOfWeekAry[8];
138 sal_Int32 mnDayCount;
149 sal_Int16 mnFirstYear;
150 sal_Int16 mnLastYear;
151 bool mbCalc:1,
160
162 using Window::ImplInit;
163 void ImplInit( WinBits nWinStyle );
164 void ImplInitSettings();
165
166 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
167
168 void ImplFormat();
169 sal_uInt16 ImplDoHitTest( const Point& rPos, Date& rDate ) const;
170 void ImplDrawSpin(vcl::RenderContext& rRenderContext);
171 void ImplDrawDate(vcl::RenderContext& rRenderContext, tools::Long nX, tools::Long nY,
172 sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
173 bool bOther, sal_Int32 nToday);
174 void ImplDraw(vcl::RenderContext& rRenderContext);
175 void ImplUpdateDate( const Date& rDate );
176 void ImplUpdateSelection( IntDateSet* pOld );
177 void ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest );
178 void ImplUpdate( bool bCalcNew = false );
179 void ImplScrollCalendar( bool bPrev );
180 void ImplShowMenu( const Point& rPos, const Date& rDate );
181 void ImplTracking( const Point& rPos, bool bRepeat );
182 void ImplEndTracking( bool bCancel );
184
185 virtual Size GetOptimalSize() const override;
186public:
187 Calendar( vcl::Window* pParent, WinBits nWinStyle );
188 virtual ~Calendar() override;
189 virtual void dispose() override;
190
191 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
192 virtual void Tracking( const TrackingEvent& rMEvt ) override;
193 virtual void KeyInput( const KeyEvent& rKEvt ) override;
194 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
195 virtual void Resize() override;
196 virtual void GetFocus() override;
197 virtual void LoseFocus() override;
198 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
199 virtual void Command( const CommandEvent& rCEvt ) override;
200 virtual void StateChanged( StateChangedType nStateChange ) override;
201 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
202
203 void Select();
204
206
207 void SetCurDate( const Date& rNewDate );
208 void SetFirstDate( const Date& rNewFirstDate );
209 const Date& GetFirstDate() const { return maFirstDate; }
210 Date GetLastDate() const { return GetFirstDate() + mnDayCount; }
211 Date GetFirstMonth() const;
212 Date GetLastMonth() const;
213 sal_uInt16 GetMonthCount() const;
214 bool GetDate( const Point& rPos, Date& rDate ) const;
215 tools::Rectangle GetDateRect( const Date& rDate ) const;
216
217 void EndSelection();
218
220
221 void SetSelectHdl( const Link<Calendar*,void>& rLink ) { maSelectHdl = rLink; }
222 void SetActivateHdl( const Link<Calendar*,void>& rLink ) { maActivateHdl = rLink; }
223
224 virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
225};
226
227#endif // INCLUDED_VCL_CALENDAR_HXX
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void EndSelection()
Definition: calendar.cxx:1490
void ImplDrawSpin(vcl::RenderContext &rRenderContext)
Definition: calendar.cxx:509
sal_Int16 mnLastYear
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: calendar.cxx:1136
tools::Long mnMonthWidth
const Date & GetFirstDate() const
tools::Rectangle maPrevRect
WinBits mnWinStyle
sal_Int16 mnFirstYear
void ImplScrollCalendar(bool bPrev)
Definition: calendar.cxx:869
void SetCurDate(const Date &rNewDate)
Definition: calendar.cxx:1287
void SetSelectHdl(const Link< Calendar *, void > &rLink)
DayOfWeek ImplGetWeekStart() const
Definition: calendar.cxx:160
tools::Long mnDaysOffX
void ImplFormat()
Definition: calendar.cxx:195
sal_Int32 mnDayOfWeekAry[8]
void SetActivateHdl(const Link< Calendar *, void > &rLink)
Calendar(vcl::Window *pParent, WinBits nWinStyle)
Definition: calendar.cxx:135
virtual void LoseFocus() override
Definition: calendar.cxx:1147
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: calendar.cxx:1012
void ImplUpdate(bool bCalcNew=false)
Definition: calendar.cxx:850
Link< Calendar *, void > maActivateHdl
tools::Rectangle GetDateRect(const Date &rDate) const
Definition: calendar.cxx:1390
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: calendar.cxx:1071
sal_uInt16 GetMonthCount() const
Definition: calendar.cxx:1369
void ImplInit(WinBits nWinStyle)
Definition: calendar.cxx:72
virtual void Resize() override
Definition: calendar.cxx:1153
tools::Long mnMonthPerLine
void ImplEndTracking(bool bCancel)
Definition: calendar.cxx:955
tools::Long mnWeekDayOffY
void ImplInitSettings()
Definition: calendar.cxx:126
OUString maDayText
virtual void DumpAsPropertyTree(tools::JsonWriter &) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
Definition: calendar.cxx:1525
Date GetLastMonth() const
Definition: calendar.cxx:1359
void ImplDrawDate(vcl::RenderContext &rRenderContext, tools::Long nX, tools::Long nY, sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear, bool bOther, sal_Int32 nToday)
Definition: calendar.cxx:527
Date GetFirstMonth() const
Definition: calendar.cxx:1346
std::unique_ptr< IntDateSet > mpSelectTable
bool GetDate(const Point &rPos, Date &rDate) const
Definition: calendar.cxx:1377
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: calendar.cxx:1257
sal_uInt16 ImplDoHitTest(const Point &rPos, Date &rDate) const
Definition: calendar.cxx:334
Date GetLastDate() const
virtual void Tracking(const TrackingEvent &rMEvt) override
Definition: calendar.cxx:1061
Date maOldFormatLastDate
void Select()
Definition: calendar.cxx:1271
virtual ~Calendar() override
Definition: calendar.cxx:148
CalendarWrapper maCalendarWrapper
sal_Int32 mnDayCount
void ImplUpdateSelection(IntDateSet *pOld)
Definition: calendar.cxx:794
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: calendar.cxx:153
tools::Long mnMonthHeight
Date GetFirstSelectedDate() const
Definition: calendar.cxx:1276
Size CalcWindowSizePixel() const
Definition: calendar.cxx:1503
OUString maDayOfWeekText
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: calendar.cxx:117
Link< Calendar *, void > maSelectHdl
virtual Size GetOptimalSize() const override
Definition: calendar.cxx:1520
OUString maDayTexts[31]
virtual void GetFocus() override
Definition: calendar.cxx:1141
tools::Long mnDayHeight
std::unique_ptr< IntDateSet > mpOldSelectTable
void ImplTracking(const Point &rPos, bool bRepeat)
Definition: calendar.cxx:936
tools::Long mnDaysOffY
void ImplDraw(vcl::RenderContext &rRenderContext)
Definition: calendar.cxx:602
void ImplUpdateDate(const Date &rDate)
Definition: calendar.cxx:782
tools::Long mnLines
void ImplMouseSelect(const Date &rDate, sal_uInt16 nHitTest)
Definition: calendar.cxx:817
virtual void StateChanged(StateChangedType nStateChange) override
Definition: calendar.cxx:1249
virtual void Command(const CommandEvent &rCEvt) override
Definition: calendar.cxx:1204
tools::Rectangle maNextRect
void ImplShowMenu(const Point &rPos, const Date &rDate)
Definition: calendar.cxx:882
Date maOldFormatFirstDate
void SetFirstDate(const Date &rNewFirstDate)
Definition: calendar.cxx:1337
virtual void RequestHelp(const HelpEvent &rHEvt) override
Definition: calendar.cxx:1159
tools::Long mnDayWidth
OUString maWeekText
Definition: ctrl.hxx:80
void ImplInitSettings()
Definition: ctrl.cxx:423
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
DayOfWeek
long Long
std::set< sal_Int32 > IntDateSet
StateChangedType
Definition: window.hxx:291
sal_Int64 WinBits
Definition: wintypes.hxx:109