crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / vcl / inc / calendar.hxx
blobb727039ceeb1b6e57d1bba27f03b17b56fc24a4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_CALENDAR_HXX
21 #define INCLUDED_VCL_CALENDAR_HXX
23 #include <unotools/calendarwrapper.hxx>
25 #include <vcl/ctrl.hxx>
26 #include <memory>
27 #include <set>
29 class MouseEvent;
30 class TrackingEvent;
31 class KeyEvent;
32 class HelpEvent;
33 class DataChangedEvent;
35 /*************************************************************************
37 Description
38 ============
40 class Calendar
42 This class allows for the selection of a date. The displayed date range is
43 the one specified by the Date class. We display as many months as we have
44 space in the control. The user can switch between months using a ContextMenu
45 (clicking on the month's name) or via two ScrollButtons in-between the months.
47 --------------------------------------------------------------------------
49 WinBits
51 WB_BORDER We draw a border around the window.
52 WB_TABSTOP Keyboard control is possible. We get the focus, when
53 the user clicks in the Control.
55 --------------------------------------------------------------------------
57 We set and get the selected date by SetCurDate()/GetCurDate().
58 If the user selects a date Select() is called. If the user double clicks
59 DoubleClick() is called.
61 --------------------------------------------------------------------------
63 CalcWindowSizePixel() calculates the window size in pixel that is needed
64 to display a certain number of months.
66 --------------------------------------------------------------------------
68 SetSaturdayColor() and SetSundayColor() set a special color for Saturdays
69 and Sundays.
70 AddDateInfo() marks special days. With that we can set e.g. public holidays
71 to another color or encircle them (for e.g. appointments).
72 If we do not supply a year in the date, the day is used in EVERY year.
74 AddDateInfo() can also add text for every date, which is displayed if the
75 BalloonHelp is enabled.
76 In order to not have to supply all years with the relevant data, we call
77 the RequestDateInfo() handler if a new year is displayed. We can then query
78 the year in the handler with GetRequestYear().
80 --------------------------------------------------------------------------
82 In order to display a ContextMenu for a date, we need to override the
83 Command handler. GetDate() can infer the date from the mouse's position.
84 If we use the keyboard, the current date should be use.
86 If a ContextMenu is displayed, the baseclass' handler must not be called.
88 --------------------------------------------------------------------------
90 SetNoSelection() deselects everything.
91 SetCurDate() does not select the current date, but only defines the focus
92 rectangle.
93 GetSelectDateCount()/GetSelectDate() query the selected range.
94 IsDateSelected() queries for the status of a date.
96 The SelectionChanging() handler is being called while a user selects a
97 date. In it, we can change the selected range. E.g. if we want to limit
98 or extend the selected range. The selected range is realised via SelectDate()
99 and SelectDateRange() and queried with GetSelectDateCount()/GetSelectDate().
101 IsSelectLeft() returns the direction of the selection:
102 sal_True is a selection to the left or up
103 sal_False is a selection to the right or down
105 --------------------------------------------------------------------------
107 If the DateRange area changes and we want to take over the selection, we
108 should only do this is if IsScrollDateRangeChanged() returns sal_True.
109 This method returns sal_True if the area change was triggered by using the
110 ScrollButtons and sal_False if it was triggered by Resize(), other method
111 calls or by ending a selection.
113 *************************************************************************/
115 typedef std::set<sal_Int32> IntDateSet;
117 class Calendar final : public Control
119 std::unique_ptr<IntDateSet> mpSelectTable;
120 std::unique_ptr<IntDateSet> mpOldSelectTable;
121 OUString maDayTexts[31];
122 OUString maDayText;
123 OUString maWeekText;
124 CalendarWrapper maCalendarWrapper;
125 tools::Rectangle maPrevRect;
126 tools::Rectangle maNextRect;
127 OUString maDayOfWeekText;
128 sal_Int32 mnDayOfWeekAry[8];
129 Date maOldFormatFirstDate;
130 Date maOldFormatLastDate;
131 Date maFirstDate;
132 Date maOldFirstDate;
133 Date maCurDate;
134 Date maOldCurDate;
135 Color maSelColor;
136 Color maOtherColor;
137 sal_Int32 mnDayCount;
138 tools::Long mnDaysOffX;
139 tools::Long mnWeekDayOffY;
140 tools::Long mnDaysOffY;
141 tools::Long mnMonthHeight;
142 tools::Long mnMonthWidth;
143 tools::Long mnMonthPerLine;
144 tools::Long mnLines;
145 tools::Long mnDayWidth;
146 tools::Long mnDayHeight;
147 WinBits mnWinStyle;
148 sal_Int16 mnFirstYear;
149 sal_Int16 mnLastYear;
150 bool mbCalc:1,
151 mbFormat:1,
152 mbDrag:1,
153 mbMenuDown:1,
154 mbSpinDown:1,
155 mbPrevIn:1,
156 mbNextIn:1;
157 Link<Calendar*,void> maSelectHdl;
158 Link<Calendar*,void> maActivateHdl;
160 using Control::ImplInitSettings;
161 using Window::ImplInit;
162 void ImplInit( WinBits nWinStyle );
163 void ImplInitSettings();
165 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
167 void ImplFormat();
168 sal_uInt16 ImplDoHitTest( const Point& rPos, Date& rDate ) const;
169 void ImplDrawSpin(vcl::RenderContext& rRenderContext);
170 void ImplDrawDate(vcl::RenderContext& rRenderContext, tools::Long nX, tools::Long nY,
171 sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
172 bool bOther, sal_Int32 nToday);
173 void ImplDraw(vcl::RenderContext& rRenderContext);
174 void ImplUpdateDate( const Date& rDate );
175 void ImplUpdateSelection( IntDateSet* pOld );
176 void ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest );
177 void ImplUpdate( bool bCalcNew = false );
178 void ImplScrollCalendar( bool bPrev );
179 void ImplShowMenu( const Point& rPos, const Date& rDate );
180 void ImplTracking( const Point& rPos, bool bRepeat );
181 void ImplEndTracking( bool bCancel );
182 DayOfWeek ImplGetWeekStart() const;
184 virtual Size GetOptimalSize() const override;
185 public:
186 Calendar( vcl::Window* pParent, WinBits nWinStyle );
187 virtual ~Calendar() override;
188 virtual void dispose() override;
190 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
191 virtual void Tracking( const TrackingEvent& rMEvt ) override;
192 virtual void KeyInput( const KeyEvent& rKEvt ) override;
193 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
194 virtual void Resize() override;
195 virtual void GetFocus() override;
196 virtual void LoseFocus() override;
197 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
198 virtual void Command( const CommandEvent& rCEvt ) override;
199 virtual void StateChanged( StateChangedType nStateChange ) override;
200 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
202 void Select();
204 Date GetFirstSelectedDate() const;
206 void SetCurDate( const Date& rNewDate );
207 void SetFirstDate( const Date& rNewFirstDate );
208 const Date& GetFirstDate() const { return maFirstDate; }
209 Date GetLastDate() const { return GetFirstDate() + mnDayCount; }
210 Date GetFirstMonth() const;
211 Date GetLastMonth() const;
212 sal_uInt16 GetMonthCount() const;
213 bool GetDate( const Point& rPos, Date& rDate ) const;
214 tools::Rectangle GetDateRect( const Date& rDate ) const;
216 void EndSelection();
218 Size CalcWindowSizePixel() const;
220 void SetSelectHdl( const Link<Calendar*,void>& rLink ) { maSelectHdl = rLink; }
221 void SetActivateHdl( const Link<Calendar*,void>& rLink ) { maActivateHdl = rLink; }
223 virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
226 #endif // INCLUDED_VCL_CALENDAR_HXX
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */