tdf#119209: Windows share has inappropriate server suggestion
[LibreOffice.git] / include / svtools / calendar.hxx
blobea2df0f63be02605a618b1869db01067324c5f3d
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_SVTOOLS_CALENDAR_HXX
21 #define INCLUDED_SVTOOLS_CALENDAR_HXX
23 #include <svtools/svtdllapi.h>
24 #include <unotools/calendarwrapper.hxx>
25 #include <com/sun/star/i18n/Weekdays.hpp>
27 #include <vcl/ctrl.hxx>
28 #include <vcl/timer.hxx>
29 #include <vcl/field.hxx>
30 #include <memory>
31 #include <set>
33 class MouseEvent;
34 class TrackingEvent;
35 class KeyEvent;
36 class HelpEvent;
37 class DataChangedEvent;
38 class FloatingWindow;
39 class PushButton;
40 class ImplCFieldFloatWin;
41 class Button;
43 /*************************************************************************
45 Description
46 ============
48 class Calendar
50 This class allows for the selection of a date. The displayed date range is
51 the one specified by the Date class. We display as many months as we have
52 space in the control. The user can switch between months using a ContextMenu
53 (clicking on the month's name) or via two ScrollButtons in-between the months.
55 --------------------------------------------------------------------------
57 WinBits
59 WB_BORDER We draw a border around the window.
60 WB_TABSTOP Keyboard control is possible. We get the focus, when
61 the user clicks in the Control.
63 --------------------------------------------------------------------------
65 We set and get the selected date by SetCurDate()/GetCurDate().
66 If the user selects a date Select() is called. If the user double clicks
67 DoubleClick() is called.
69 --------------------------------------------------------------------------
71 CalcWindowSizePixel() calculates the window size in pixel that is needed
72 to display a certain number of months.
74 --------------------------------------------------------------------------
76 SetSaturdayColor() and SetSundayColor() set a special color for Saturdays
77 and Sundays.
78 AddDateInfo() marks special days. With that we can set e.g. public holidays
79 to another color or encircle them (for e.g. appointments).
80 If we do not supply a year in the date, the day is used in EVERY year.
82 AddDateInfo() can also add text for every date, which is displayed if the
83 BalloonHelp is enabled.
84 In order to not have to supply all years with the relevant data, we call
85 the RequestDateInfo() handler if a new year is displayed. We can then query
86 the year in the handler with GetRequestYear().
88 --------------------------------------------------------------------------
90 In order to display a ContextMenu for a date, we need to override the
91 Command handler. GetDate() can infer the date from the mouse's position.
92 If we use the keyboard, the current date should be use.
94 If a ContextMenu is displayed, the baseclass' handler must not be called.
96 --------------------------------------------------------------------------
98 SetNoSelection() deselects everything.
99 SetCurDate() does not select the current date, but only defines the focus
100 rectangle.
101 GetSelectDateCount()/GetSelectDate() query the selected range.
102 IsDateSelected() queries for the status of a date.
104 The SelectionChanging() handler is being called while a user selects a
105 date. In it, we can change the selected range. E.g. if we want to limit
106 or extend the selected range. The selected range is realised via SelectDate()
107 and SelectDateRange() and queried with GetSelectDateCount()/GetSelectDate().
109 IsSelectLeft() returns the direction of the selection:
110 sal_True is a selection to the left or up
111 sal_False is a selection to the right or down
113 --------------------------------------------------------------------------
115 If the DateRange area changes and we want to take over the selection, we
116 should only do this is if IsScrollDateRangeChanged() returns sal_True.
117 This method returns sal_True if the area change was triggered by using the
118 ScrollButtons and sal_False if it was triggered by Resize(), other method
119 calls or by ending a selection.
121 *************************************************************************/
123 typedef std::set<sal_Int32> IntDateSet;
126 class SVT_DLLPUBLIC Calendar final : public Control
128 std::unique_ptr<IntDateSet> mpSelectTable;
129 std::unique_ptr<IntDateSet> mpOldSelectTable;
130 OUString maDayTexts[31];
131 OUString maDayText;
132 OUString maWeekText;
133 CalendarWrapper maCalendarWrapper;
134 tools::Rectangle maPrevRect;
135 tools::Rectangle maNextRect;
136 OUString maDayOfWeekText;
137 long mnDayOfWeekAry[7];
138 Date maOldFormatFirstDate;
139 Date maOldFormatLastDate;
140 Date maFirstDate;
141 Date maOldFirstDate;
142 Date maCurDate;
143 Date maOldCurDate;
144 Date maAnchorDate;
145 Date const maDropDate;
146 Color maSelColor;
147 Color maOtherColor;
148 sal_Int32 mnDayCount;
149 long mnDaysOffX;
150 long mnWeekDayOffY;
151 long mnDaysOffY;
152 long mnMonthHeight;
153 long mnMonthWidth;
154 long mnMonthPerLine;
155 long mnLines;
156 long mnDayWidth;
157 long mnDayHeight;
158 WinBits mnWinStyle;
159 sal_Int16 mnFirstYear;
160 sal_Int16 mnLastYear;
161 bool mbCalc:1,
162 mbFormat:1,
163 mbDrag:1,
164 mbSelection:1,
165 mbMenuDown:1,
166 mbSpinDown:1,
167 mbPrevIn:1,
168 mbNextIn:1,
169 mbTravelSelect:1,
170 mbAllSel:1,
171 mbDropPos:1;
172 Link<Calendar*,void> maSelectHdl;
173 Timer maDragScrollTimer;
174 sal_uInt16 mnDragScrollHitTest;
176 using Control::ImplInitSettings;
177 using Window::ImplInit;
178 SVT_DLLPRIVATE void ImplInit( WinBits nWinStyle );
179 SVT_DLLPRIVATE void ImplInitSettings();
181 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
183 SVT_DLLPRIVATE void ImplFormat();
184 using Window::ImplHitTest;
185 SVT_DLLPRIVATE sal_uInt16 ImplHitTest( const Point& rPos, Date& rDate ) const;
186 SVT_DLLPRIVATE void ImplDrawSpin(vcl::RenderContext& rRenderContext);
187 SVT_DLLPRIVATE void ImplDrawDate(vcl::RenderContext& rRenderContext, long nX, long nY,
188 sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
189 bool bOther, sal_Int32 nToday);
190 SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
191 SVT_DLLPRIVATE void ImplUpdateDate( const Date& rDate );
192 SVT_DLLPRIVATE void ImplUpdateSelection( IntDateSet* pOld );
193 SVT_DLLPRIVATE void ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
194 bool bMove );
195 SVT_DLLPRIVATE void ImplUpdate( bool bCalcNew = false );
196 using Window::ImplScroll;
197 SVT_DLLPRIVATE void ImplScroll( bool bPrev );
198 SVT_DLLPRIVATE void ImplInvertDropPos();
199 SVT_DLLPRIVATE void ImplShowMenu( const Point& rPos, const Date& rDate );
200 SVT_DLLPRIVATE void ImplTracking( const Point& rPos, bool bRepeat );
201 SVT_DLLPRIVATE void ImplEndTracking( bool bCancel );
202 SVT_DLLPRIVATE DayOfWeek ImplGetWeekStart() const;
204 DECL_LINK( ScrollHdl, Timer *, void );
206 public:
207 Calendar( vcl::Window* pParent, WinBits nWinStyle );
208 virtual ~Calendar() override;
209 virtual void dispose() override;
211 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
212 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
213 virtual void MouseMove( const MouseEvent& rMEvt ) override;
214 virtual void Tracking( const TrackingEvent& rMEvt ) override;
215 virtual void KeyInput( const KeyEvent& rKEvt ) override;
216 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
217 virtual void Resize() override;
218 virtual void GetFocus() override;
219 virtual void LoseFocus() override;
220 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
221 virtual void Command( const CommandEvent& rCEvt ) override;
222 virtual void StateChanged( StateChangedType nStateChange ) override;
223 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
225 void Select();
227 Date GetFirstSelectedDate() const;
228 void EnableCallEverySelect() { mbAllSel = true; }
230 void SetCurDate( const Date& rNewDate );
231 void SetFirstDate( const Date& rNewFirstDate );
232 const Date& GetFirstDate() const { return maFirstDate; }
233 Date GetLastDate() const { return GetFirstDate() + mnDayCount; }
234 Date GetFirstMonth() const;
235 Date GetLastMonth() const;
236 sal_uInt16 GetMonthCount() const;
237 bool GetDate( const Point& rPos, Date& rDate ) const;
238 tools::Rectangle GetDateRect( const Date& rDate ) const;
240 void StartSelection();
241 void EndSelection();
243 bool IsTravelSelect() const { return mbTravelSelect; }
245 Size CalcWindowSizePixel() const;
247 void SetSelectHdl( const Link<Calendar*,void>& rLink ) { maSelectHdl = rLink; }
251 /*************************************************************************
253 Description
254 ============
256 class CalendarField
258 This class is a DateField with which one can select a date via a DropDownButton
259 and the CalendarControl.
261 --------------------------------------------------------------------------
263 WinBits
265 See DateField
267 The preferences for the CalendarControl can be set via SetCalendarStyle().
269 --------------------------------------------------------------------------
271 With EnableToday()/EnableNone() we can enable a TodayButton and a NoneButton.
273 --------------------------------------------------------------------------
275 Because we only take over the start date into the field, we should query
276 with GetCalendar() in the SelectHandler and with GetSelectDateCount()/GetSelectDate()
277 the selected range. We then can e.g. take over that value to another field.
279 --------------------------------------------------------------------------
281 If a derived Calendar should be used, we can override the CreateCalendar()
282 method in CalendarField and create an own calendar there ourselves.
284 *************************************************************************/
287 class SVT_DLLPUBLIC CalendarField : public DateField
289 private:
290 VclPtr<ImplCFieldFloatWin> mpFloatWin;
291 VclPtr<Calendar> mpCalendar;
292 VclPtr<PushButton> mpTodayBtn;
293 VclPtr<PushButton> mpNoneBtn;
294 Date const maDefaultDate;
295 bool mbToday;
296 bool mbNone;
298 DECL_DLLPRIVATE_LINK( ImplSelectHdl, Calendar*, void );
299 DECL_DLLPRIVATE_LINK( ImplClickHdl, Button*, void );
300 DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void );
302 public:
303 CalendarField( vcl::Window* pParent, WinBits nWinStyle );
304 virtual ~CalendarField() override;
305 virtual void dispose() override;
307 virtual bool ShowDropDown( bool bShow ) override;
308 Calendar* GetCalendar();
310 void EnableToday() { mbToday = true; }
311 void EnableNone() { mbNone = true; }
313 protected:
314 virtual void StateChanged( StateChangedType nStateChange ) override;
317 #endif // INCLUDED_SVTOOLS_CALENDAR_HXX
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */