LibreOffice Module vcl (master)  1
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
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 .
18  */
23 #include <vcl/dllapi.h>
26 #include <vcl/ctrl.hxx>
27 #include <memory>
28 #include <set>
30 class MouseEvent;
31 class TrackingEvent;
32 class KeyEvent;
33 class HelpEvent;
36 /*************************************************************************
38 Description
39 ============
41 class Calendar
43 This class allows for the selection of a date. The displayed date range is
44 the one specified by the Date class. We display as many months as we have
45 space 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.
48 --------------------------------------------------------------------------
50 WinBits
52 WB_BORDER We draw a border around the window.
53 WB_TABSTOP Keyboard control is possible. We get the focus, when
54  the user clicks in the Control.
56 --------------------------------------------------------------------------
58 We set and get the selected date by SetCurDate()/GetCurDate().
59 If the user selects a date Select() is called. If the user double clicks
60 DoubleClick() is called.
62 --------------------------------------------------------------------------
64 CalcWindowSizePixel() calculates the window size in pixel that is needed
65 to display a certain number of months.
67 --------------------------------------------------------------------------
69 SetSaturdayColor() and SetSundayColor() set a special color for Saturdays
70 and Sundays.
71 AddDateInfo() marks special days. With that we can set e.g. public holidays
72 to another color or encircle them (for e.g. appointments).
73 If we do not supply a year in the date, the day is used in EVERY year.
75 AddDateInfo() can also add text for every date, which is displayed if the
76 BalloonHelp is enabled.
77 In order to not have to supply all years with the relevant data, we call
78 the RequestDateInfo() handler if a new year is displayed. We can then query
79 the year in the handler with GetRequestYear().
81 --------------------------------------------------------------------------
83 In order to display a ContextMenu for a date, we need to override the
84 Command handler. GetDate() can infer the date from the mouse's position.
85 If we use the keyboard, the current date should be use.
87 If a ContextMenu is displayed, the baseclass' handler must not be called.
89 --------------------------------------------------------------------------
91 SetNoSelection() deselects everything.
92 SetCurDate() does not select the current date, but only defines the focus
93 rectangle.
94 GetSelectDateCount()/GetSelectDate() query the selected range.
95 IsDateSelected() queries for the status of a date.
97 The SelectionChanging() handler is being called while a user selects a
98 date. In it, we can change the selected range. E.g. if we want to limit
99 or extend the selected range. The selected range is realised via SelectDate()
100 and SelectDateRange() and queried with GetSelectDateCount()/GetSelectDate().
102 IsSelectLeft() returns the direction of the selection:
103 sal_True is a selection to the left or up
104 sal_False is a selection to the right or down
106 --------------------------------------------------------------------------
108 If the DateRange area changes and we want to take over the selection, we
109 should only do this is if IsScrollDateRangeChanged() returns sal_True.
110 This method returns sal_True if the area change was triggered by using the
111 ScrollButtons and sal_False if it was triggered by Resize(), other method
112 calls or by ending a selection.
114 *************************************************************************/
116 typedef std::set<sal_Int32> IntDateSet;
118 class 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;
128  OUString maDayOfWeekText;
138  sal_Int32 mnDayCount;
149  sal_Int16 mnFirstYear;
150  sal_Int16 mnLastYear;
151  bool mbCalc:1,
152  mbFormat:1,
153  mbDrag:1,
154  mbMenuDown:1,
155  mbSpinDown:1,
156  mbPrevIn:1,
157  mbNextIn:1;
162  using Window::ImplInit;
163  void ImplInit( WinBits nWinStyle );
164  void ImplInitSettings();
166  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
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  using Window::ImplScroll;
180  void ImplScroll( bool bPrev );
181  void ImplShowMenu( const Point& rPos, const Date& rDate );
182  void ImplTracking( const Point& rPos, bool bRepeat );
183  void ImplEndTracking( bool bCancel );
184  DayOfWeek ImplGetWeekStart() const;
186  virtual Size GetOptimalSize() const override;
187 public:
188  Calendar( vcl::Window* pParent, WinBits nWinStyle );
189  virtual ~Calendar() override;
190  virtual void dispose() override;
192  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
193  virtual void Tracking( const TrackingEvent& rMEvt ) override;
194  virtual void KeyInput( const KeyEvent& rKEvt ) override;
195  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
196  virtual void Resize() override;
197  virtual void GetFocus() override;
198  virtual void LoseFocus() override;
199  virtual void RequestHelp( const HelpEvent& rHEvt ) override;
200  virtual void Command( const CommandEvent& rCEvt ) override;
201  virtual void StateChanged( StateChangedType nStateChange ) override;
202  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
204  void Select();
206  Date GetFirstSelectedDate() const;
208  void SetCurDate( const Date& rNewDate );
209  void SetFirstDate( const Date& rNewFirstDate );
210  const Date& GetFirstDate() const { return maFirstDate; }
211  Date GetLastDate() const { return GetFirstDate() + mnDayCount; }
212  Date GetFirstMonth() const;
213  Date GetLastMonth() const;
214  sal_uInt16 GetMonthCount() const;
215  bool GetDate( const Point& rPos, Date& rDate ) const;
216  tools::Rectangle GetDateRect( const Date& rDate ) const;
218  void EndSelection();
220  Size CalcWindowSizePixel() const;
222  void SetSelectHdl( const Link<Calendar*,void>& rLink ) { maSelectHdl = rLink; }
223  void SetActivateHdl( const Link<Calendar*,void>& rLink ) { maActivateHdl = rLink; }
224 };
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long mnLines
virtual void LoseFocus() override
Definition: calendar.cxx:1139
tools::Rectangle maNextRect
void ImplDraw(vcl::RenderContext &rRenderContext)
Definition: calendar.cxx:597
const Date & GetFirstDate() const
Link< Calendar *, void > maActivateHdl
sal_Int16 mnFirstYear
long Long
tools::Long mnDayWidth
virtual ~Calendar() override
Definition: calendar.cxx:146
void ImplUpdate(bool bCalcNew=false)
Definition: calendar.cxx:842
std::unique_ptr< IntDateSet > mpOldSelectTable
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: calendar.cxx:115
void ImplUpdateDate(const Date &rDate)
Definition: calendar.cxx:774
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: calendar.cxx:1249
Size CalcWindowSizePixel() const
Definition: calendar.cxx:1495
tools::Long mnWeekDayOffY
void ImplUpdateSelection(IntDateSet *pOld)
Definition: calendar.cxx:786
CalendarWrapper maCalendarWrapper
void ImplInitSettings()
Definition: calendar.cxx:124
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: calendar.cxx:1128
Definition: window.hxx:289
tools::Long mnMonthHeight
tools::Long mnMonthWidth
OUString maWeekText
sal_Int64 WinBits
bool GetDate(const Point &rPos, Date &rDate) const
Definition: calendar.cxx:1369
void ImplShowMenu(const Point &rPos, const Date &rDate)
Definition: calendar.cxx:874
tools::Rectangle GetDateRect(const Date &rDate) const
Definition: calendar.cxx:1382
virtual void GetFocus() override
Definition: calendar.cxx:1133
sal_Int32 mnDayCount
virtual Size GetOptimalSize() const override
Definition: calendar.cxx:1512
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: calendar.cxx:1004
OUString maDayTexts[31]
Date GetFirstMonth() const
Definition: calendar.cxx:1338
std::set< sal_Int32 > IntDateSet
void SetActivateHdl(const Link< Calendar *, void > &rLink)
virtual void Tracking(const TrackingEvent &rMEvt) override
Definition: calendar.cxx:1053
tools::Long mnDayHeight
void ImplMouseSelect(const Date &rDate, sal_uInt16 nHitTest)
Definition: calendar.cxx:809
void ImplScroll(bool bPrev)
Definition: calendar.cxx:861
std::unique_ptr< IntDateSet > mpSelectTable
tools::Rectangle maPrevRect
Calendar(vcl::Window *pParent, WinBits nWinStyle)
Definition: calendar.cxx:133
sal_uInt16 GetMonthCount() const
Definition: calendar.cxx:1361
OUString maDayText
void ImplFormat()
Definition: calendar.cxx:193
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:303
sal_uInt16 ImplDoHitTest(const Point &rPos, Date &rDate) const
Definition: calendar.cxx:329
virtual void Resize() override
Definition: calendar.cxx:1145
tools::Long mnMonthPerLine
void SetSelectHdl(const Link< Calendar *, void > &rLink)
void ImplDrawSpin(vcl::RenderContext &rRenderContext)
Definition: calendar.cxx:504
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: calendar.cxx:1063
DayOfWeek ImplGetWeekStart() const
Definition: calendar.cxx:158
Date maOldFormatLastDate
void SetCurDate(const Date &rNewDate)
Definition: calendar.cxx:1279
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:522
void ImplInit(WinBits nWinStyle)
Definition: calendar.cxx:70
WinBits mnWinStyle
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: calendar.cxx:151
Definition: ctrl.hxx:33
OUString maDayOfWeekText
Date GetLastMonth() const
Definition: calendar.cxx:1351
void ImplTracking(const Point &rPos, bool bRepeat)
Definition: calendar.cxx:928
Date maOldFormatFirstDate
void ImplEndTracking(bool bCancel)
Definition: calendar.cxx:947
void SetFirstDate(const Date &rNewFirstDate)
Definition: calendar.cxx:1329
virtual void RequestHelp(const HelpEvent &rHEvt) override
Definition: calendar.cxx:1151
tools::Long mnDaysOffX
Date GetFirstSelectedDate() const
Definition: calendar.cxx:1268
Date GetLastDate() const
Link< Calendar *, void > maSelectHdl
void ImplInitSettings()
Definition: ctrl.cxx:428
tools::Long mnDayOfWeekAry[7]
sal_Int16 mnLastYear
tools::Long mnDaysOffY
void EndSelection()
Definition: calendar.cxx:1482
void Select()
Definition: calendar.cxx:1263
virtual void StateChanged(StateChangedType nStateChange) override
Definition: calendar.cxx:1241
virtual void Command(const CommandEvent &rCEvt) override
Definition: calendar.cxx:1196