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 VCL_DLLPUBLIC 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;
129  long mnDayOfWeekAry[7];
138  sal_Int32 mnDayCount;
145  long mnLines;
149  sal_Int16 mnFirstYear;
150  sal_Int16 mnLastYear;
151  bool mbCalc:1,
152  mbFormat:1,
153  mbDrag:1,
154  mbSelection:1,
155  mbMenuDown:1,
156  mbSpinDown:1,
157  mbPrevIn:1,
158  mbNextIn:1,
159  mbTravelSelect:1,
160  mbAllSel:1;
165  using Window::ImplInit;
166  VCL_DLLPRIVATE void ImplInit( WinBits nWinStyle );
169  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
171  VCL_DLLPRIVATE void ImplFormat();
172  using Window::ImplHitTest;
173  VCL_DLLPRIVATE sal_uInt16 ImplHitTest( const Point& rPos, Date& rDate ) const;
174  VCL_DLLPRIVATE void ImplDrawSpin(vcl::RenderContext& rRenderContext);
175  VCL_DLLPRIVATE void ImplDrawDate(vcl::RenderContext& rRenderContext, long nX, long nY,
176  sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
177  bool bOther, sal_Int32 nToday);
178  VCL_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
179  VCL_DLLPRIVATE void ImplUpdateDate( const Date& rDate );
180  VCL_DLLPRIVATE void ImplUpdateSelection( IntDateSet* pOld );
181  VCL_DLLPRIVATE void ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest );
182  VCL_DLLPRIVATE void ImplUpdate( bool bCalcNew = false );
183  using Window::ImplScroll;
184  VCL_DLLPRIVATE void ImplScroll( bool bPrev );
185  VCL_DLLPRIVATE void ImplShowMenu( const Point& rPos, const Date& rDate );
186  VCL_DLLPRIVATE void ImplTracking( const Point& rPos, bool bRepeat );
187  VCL_DLLPRIVATE void ImplEndTracking( bool bCancel );
188  VCL_DLLPRIVATE DayOfWeek ImplGetWeekStart() const;
190  virtual Size GetOptimalSize() const override;
191 public:
192  Calendar( vcl::Window* pParent, WinBits nWinStyle );
193  virtual ~Calendar() override;
194  virtual void dispose() override;
196  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
197  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
198  virtual void MouseMove( const MouseEvent& rMEvt ) override;
199  virtual void Tracking( const TrackingEvent& rMEvt ) override;
200  virtual void KeyInput( const KeyEvent& rKEvt ) override;
201  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
202  virtual void Resize() override;
203  virtual void GetFocus() override;
204  virtual void LoseFocus() override;
205  virtual void RequestHelp( const HelpEvent& rHEvt ) override;
206  virtual void Command( const CommandEvent& rCEvt ) override;
207  virtual void StateChanged( StateChangedType nStateChange ) override;
208  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
210  void Select();
212  Date GetFirstSelectedDate() const;
213  void EnableCallEverySelect() { mbAllSel = true; }
215  void SetCurDate( const Date& rNewDate );
216  void SetFirstDate( const Date& rNewFirstDate );
217  const Date& GetFirstDate() const { return maFirstDate; }
218  Date GetLastDate() const { return GetFirstDate() + mnDayCount; }
219  Date GetFirstMonth() const;
220  Date GetLastMonth() const;
221  sal_uInt16 GetMonthCount() const;
222  bool GetDate( const Point& rPos, Date& rDate ) const;
223  tools::Rectangle GetDateRect( const Date& rDate ) const;
225  void StartSelection();
226  void EndSelection();
228  bool IsTravelSelect() const { return mbTravelSelect; }
230  Size CalcWindowSizePixel() const;
232  void SetSelectHdl( const Link<Calendar*,void>& rLink ) { maSelectHdl = rLink; }
233  void SetActivateHdl( const Link<Calendar*,void>& rLink ) { maActivateHdl = rLink; }
234 };
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Rectangle maNextRect
Definition: calendar.hxx:127
Date maOldCurDate
Definition: calendar.hxx:135
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:413
const Date & GetFirstDate() const
Definition: calendar.hxx:217
Link< Calendar *, void > maActivateHdl
Definition: calendar.hxx:162
long mnWeekDayOffY
Definition: calendar.hxx:140
sal_Int16 mnFirstYear
Definition: calendar.hxx:149
virtual WindowHitTest ImplHitTest(const Point &rFramePos)
Definition: mouse.cxx:56
Definition: dllapi.h:29
std::unique_ptr< IntDateSet > mpOldSelectTable
Definition: calendar.hxx:121
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:418
virtual void MouseButtonUp(const MouseEvent &rMEvt)
Definition: mouse.cxx:420
CalendarWrapper maCalendarWrapper
Definition: calendar.hxx:125
Definition: window.hxx:311
OUString maWeekText
Definition: calendar.hxx:124
sal_Int64 WinBits
Color maSelColor
Definition: calendar.hxx:136
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1896
long mnLines
Definition: calendar.hxx:145
sal_Int32 mnDayCount
Definition: calendar.hxx:138
void SetActivateHdl(const Link< Calendar *, void > &rLink)
Definition: calendar.hxx:233
long mnMonthPerLine
Definition: calendar.hxx:144
long mnDayHeight
Definition: calendar.hxx:147
Date maOldFirstDate
Definition: calendar.hxx:133
std::unique_ptr< IntDateSet > mpSelectTable
Definition: calendar.hxx:120
tools::Rectangle maPrevRect
Definition: calendar.hxx:126
OUString maDayText
Definition: calendar.hxx:123
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
void SetSelectHdl(const Link< Calendar *, void > &rLink)
Definition: calendar.hxx:232
long mnDaysOffY
Definition: calendar.hxx:141
virtual void LoseFocus()
Definition: window.cxx:1819
Date maFirstDate
Definition: calendar.hxx:132
Date maOldFormatLastDate
Definition: calendar.hxx:131
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1769
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:932
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
void EnableCallEverySelect()
Definition: calendar.hxx:213
WinBits mnWinStyle
Definition: calendar.hxx:148
long mnDaysOffX
Definition: calendar.hxx:139
long mnMonthWidth
Definition: calendar.hxx:143
long mnMonthHeight
Definition: calendar.hxx:142
virtual void Resize() override
Definition: ctrl.cxx:74
Definition: ctrl.hxx:33
OUString maDayOfWeekText
Definition: calendar.hxx:128
virtual void GetFocus()
Definition: window.cxx:1805
SAL_DLLPRIVATE void ImplScroll(const tools::Rectangle &rRect, long nHorzScroll, long nVertScroll, ScrollFlags nFlags)
Definition: paint.cxx:1663
Date maOldFormatFirstDate
Definition: calendar.hxx:130
Color maOtherColor
Definition: calendar.hxx:137
bool IsTravelSelect() const
Definition: calendar.hxx:228
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1017
Date maCurDate
Definition: calendar.hxx:134
long mnDayWidth
Definition: calendar.hxx:146
Date GetLastDate() const
Definition: calendar.hxx:218
Link< Calendar *, void > maSelectHdl
Definition: calendar.hxx:161
Definition: dllapi.h:31
void ImplInitSettings()
Definition: ctrl.cxx:428
virtual void MouseMove(const MouseEvent &rMEvt)
Definition: mouse.cxx:407
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1887
sal_Int16 mnLastYear
Definition: calendar.hxx:150
virtual void RequestHelp(const HelpEvent &rHEvt)
Definition: window.cxx:1833
std::set< sal_Int32 > IntDateSet
Definition: calendar.hxx:34
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35