/src/libreoffice/sw/inc/PostItMgr.hxx
Line | Count | Source |
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 | | #pragma once |
20 | | |
21 | | #include <sal/config.h> |
22 | | #include "swdllapi.h" |
23 | | |
24 | | #include <config_collab.h> |
25 | | |
26 | | #include <cstddef> |
27 | | #include <memory> |
28 | | #include <vector> |
29 | | #include <rtl/ustring.hxx> |
30 | | #include <sal/log.hxx> |
31 | | #include <tools/link.hxx> |
32 | | #include "swrect.hxx" |
33 | | #include <unotools/configitem.hxx> |
34 | | #include <com/sun/star/uno/Any.hxx> |
35 | | #include "SidebarWindowsTypes.hxx" |
36 | | #include <editeng/outlobj.hxx> |
37 | | #include <svl/lstner.hxx> |
38 | | #include <vcl/vclptr.hxx> |
39 | | |
40 | | class OutputDevice; |
41 | | class SwWrtShell; |
42 | | class SwView; |
43 | | class SwPostItField; |
44 | | class SwFormatField; |
45 | | class SwEditWin; |
46 | | class Color; |
47 | | class SfxItemSet; |
48 | | class SvxSearchItem; |
49 | | namespace sw::annotation { class SwAnnotationWin; } |
50 | | namespace sw::sidebarwindows { class SwFrameSidebarWinContainer; } |
51 | | class SwAnnotationItem; |
52 | | class SwFrame; |
53 | | namespace vcl { class Window; } |
54 | | struct ImplSVEvent; |
55 | | namespace i18nutil { struct SearchOptions2; } |
56 | | |
57 | 0 | #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0) |
58 | 0 | #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153) |
59 | | |
60 | | struct SwPostItPageItem |
61 | | { |
62 | | bool bScrollbar; |
63 | | sw::sidebarwindows::SidebarPosition eSidebarPosition; |
64 | | tools::Long lOffset; |
65 | | SwRect mPageRect; |
66 | | std::vector<SwAnnotationItem*> mvSidebarItems; |
67 | 63.2k | SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::NONE ), lOffset(0) |
68 | 63.2k | { |
69 | 63.2k | } |
70 | | }; |
71 | | |
72 | | struct FieldShadowState |
73 | | { |
74 | | const SwPostItField* mpShadowField; |
75 | | bool bCursor; |
76 | | bool bMouse; |
77 | 4.14k | FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false) |
78 | 4.14k | { |
79 | 4.14k | } |
80 | | }; |
81 | | |
82 | | class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener, |
83 | | public SfxBroadcaster |
84 | | { |
85 | | private: |
86 | | SwView* mpView; |
87 | | SwWrtShell* mpWrtShell; |
88 | | VclPtr<SwEditWin> mpEditWin; |
89 | | std::vector<std::unique_ptr<SwAnnotationItem>> mvPostItFields; |
90 | | std::vector<std::unique_ptr<SwPostItPageItem>> mPages; |
91 | | ImplSVEvent * mnEventId; |
92 | | bool mbWaitingForCalcRects; |
93 | | VclPtr<sw::annotation::SwAnnotationWin> mpActivePostIt; |
94 | | bool mbLayout; |
95 | | tools::Long mbLayoutHeight; |
96 | | bool mbLayouting; |
97 | | bool mbReadOnly; |
98 | | bool mbDeleteNote; |
99 | | FieldShadowState mShadowState; |
100 | | std::optional<OutlinerParaObject> mpAnswer; |
101 | | OUString maAnswerText; |
102 | | bool mbForceShowForPrintOrPdf = false; |
103 | | |
104 | | // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances. |
105 | | std::unique_ptr<sw::sidebarwindows::SwFrameSidebarWinContainer> mpFrameSidebarWinContainer; |
106 | | |
107 | | void AddPostIts(bool bCheckExistence = true,bool bFocus = true); |
108 | | void RemoveSidebarWin(); |
109 | | void PreparePageContainer(); |
110 | | void Scroll(const tools::Long lScroll,const tools::ULong aPage ); |
111 | | void AutoScroll(const sw::annotation::SwAnnotationWin* pPostIt,const tools::ULong aPage ); |
112 | | bool ScrollbarHit(const tools::ULong aPage,const Point &aPoint); |
113 | | bool LayoutByPage( std::vector<sw::annotation::SwAnnotationWin*> &aVisiblePostItList, |
114 | | const tools::Rectangle& rBorder, |
115 | | tools::Long lNeededHeight); |
116 | | // return true if a postit was found to have been removed |
117 | | bool CheckForRemovedPostIts(); |
118 | | bool ArrowEnabled(sal_uInt16 aDirection,tools::ULong aPage) const; |
119 | | bool BorderOverPageBorder(tools::ULong aPage) const; |
120 | | bool HasScrollbars() const; |
121 | | void Focus(const SfxBroadcaster& rBC); |
122 | | |
123 | | sal_Int32 GetInitialAnchorDistance() const; |
124 | | sal_Int32 GetScrollSize() const; |
125 | | sal_Int32 GetSpaceBetween() const; |
126 | | void SetReadOnlyState(); |
127 | | DECL_DLLPRIVATE_LINK( CalcHdl, void*, void); |
128 | | |
129 | | sw::annotation::SwAnnotationWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const; |
130 | | |
131 | | SwAnnotationItem* InsertItem( SfxBroadcaster* pItem, bool bCheckExistence, bool bFocus); |
132 | | void RemoveItem( SfxBroadcaster* pBroadcast ); |
133 | | |
134 | | #if ENABLE_YRS |
135 | | public: |
136 | | #endif |
137 | | VclPtr<sw::annotation::SwAnnotationWin> GetOrCreateAnnotationWindow(SwAnnotationItem& rItem, bool& rCreated); |
138 | | |
139 | | public: |
140 | | SwPostItMgr(SwView* aDoc); |
141 | | virtual ~SwPostItMgr() override; |
142 | | |
143 | | typedef std::vector< std::unique_ptr<SwAnnotationItem> >::const_iterator const_iterator; |
144 | 25 | const_iterator begin() const { return mvPostItFields.begin(); } |
145 | 50 | const_iterator end() const { return mvPostItFields.end(); } |
146 | 0 | const std::vector<std::unique_ptr<SwAnnotationItem>>& GetPostItFields() { return mvPostItFields; } |
147 | | |
148 | | void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; |
149 | | |
150 | | std::vector<SwFormatField*> UpdatePostItsParentInfo(); |
151 | | void LayoutPostIts(); |
152 | | bool CalcRects(); |
153 | | |
154 | | void MakeVisible( const sw::annotation::SwAnnotationWin* pPostIt); |
155 | | |
156 | | bool ShowScrollbar(const tools::ULong aPage) const; |
157 | | bool HasNotes() const ; |
158 | | bool ShowNotes() const; |
159 | | void SetSidebarWidth(const Point& rPointLogic); |
160 | | tools::Rectangle GetSidebarRect(const Point& rPointLogic); |
161 | | tools::ULong GetSidebarWidth(bool bPx = false) const; |
162 | | tools::ULong GetSidebarBorderWidth(bool bPx = false) const; |
163 | | |
164 | | void PrepareView(bool bIgnoreCount = false); |
165 | | |
166 | | void CorrectPositions(); |
167 | | |
168 | 0 | void SetLayout() { mbLayout = true; }; |
169 | | void Delete(const OUString& aAuthor); |
170 | | void Delete(sal_uInt32 nPostItId); |
171 | | void Delete(); |
172 | | void DeleteCommentThread(sal_uInt32 nPostItId); |
173 | | void ToggleResolved(sal_uInt32 nPostItId); |
174 | | void ToggleResolvedForThread(sal_uInt32 nPostItId); |
175 | | void PromoteToRoot(sal_uInt32 nPostItId); |
176 | | void MoveSubthreadToRoot(const sw::annotation::SwAnnotationWin* pNewRoot); |
177 | | |
178 | | sw::annotation::SwAnnotationWin* GetRemovedAnnotationWin(const SfxBroadcaster* pBroadcast); |
179 | | |
180 | | void ExecuteFormatAllDialog(SwView& rView); |
181 | | void FormatAll(const SfxItemSet &rNewAttr); |
182 | | |
183 | | void Hide( std::u16string_view rAuthor ); |
184 | | void Hide(); |
185 | | void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin* topNote); |
186 | | void ShowHideResolvedNotes(bool visible); |
187 | | |
188 | | void Rescale(); |
189 | | |
190 | | tools::Rectangle GetBottomScrollRect(const tools::ULong aPage) const; |
191 | | tools::Rectangle GetTopScrollRect(const tools::ULong aPage) const; |
192 | | |
193 | | bool IsHit(const Point &aPointPixel); |
194 | | /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any. |
195 | | vcl::Window* IsHitSidebarWindow(const Point& rPointLogic); |
196 | | bool IsHitSidebarDragArea(const Point& rPointLogic); |
197 | | Color GetArrowColor(sal_uInt16 aDirection, tools::ULong aPage) const; |
198 | | |
199 | | sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const; |
200 | | sw::annotation::SwAnnotationWin* GetAnnotationWin(const sal_uInt32 nPostItId) const; |
201 | | |
202 | | sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection, |
203 | | sw::annotation::SwAnnotationWin* aPostIt); |
204 | | SwPostItField* GetLatestPostItField(); |
205 | | sw::annotation::SwAnnotationWin* GetOrCreateAnnotationWindowForLatestPostItField(); |
206 | | |
207 | | tools::Long GetNextBorder(); |
208 | | |
209 | 0 | sw::annotation::SwAnnotationWin* GetActiveSidebarWin() { return mpActivePostIt; } |
210 | | SW_DLLPUBLIC void SetActiveSidebarWin( sw::annotation::SwAnnotationWin* p); |
211 | | SW_DLLPUBLIC bool HasActiveSidebarWin() const; |
212 | | bool HasActiveAnnotationWin() const; |
213 | | void GrabFocusOnActiveSidebarWin(); |
214 | | SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin(); |
215 | | void DeleteActiveSidebarWin(); |
216 | | void HideActiveSidebarWin(); |
217 | | void ToggleInsModeOnActiveSidebarWin(); |
218 | | |
219 | | sal_Int32 GetMinimumSizeWithMeta() const; |
220 | | sal_Int32 GetSidebarScrollerHeight() const; |
221 | | |
222 | | void SetShadowState(const SwPostItField* pField,bool bCursor = true); |
223 | | |
224 | | void SetSpellChecking(); |
225 | | |
226 | | static Color GetColorDark(std::size_t aAuthorIndex); |
227 | | static Color GetColorLight(std::size_t aAuthorIndex); |
228 | | static Color GetColorAnchor(std::size_t aAuthorIndex); |
229 | | |
230 | 0 | void RegisterAnswer(const OutlinerParaObject& rAnswer) { mpAnswer = rAnswer; } |
231 | 0 | OutlinerParaObject* IsAnswer() { return mpAnswer ? &*mpAnswer : nullptr; } |
232 | 0 | void RegisterAnswerText(const OUString& rAnswerText) { maAnswerText = rAnswerText; } |
233 | 0 | const OUString& GetAnswerText() const { return maAnswerText; } |
234 | | void CheckMetaText(); |
235 | | void UpdateColors(); |
236 | | |
237 | | sal_uInt16 Replace(SvxSearchItem const * pItem); |
238 | | sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward); |
239 | | sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward); |
240 | | |
241 | | void AssureStdModeAtShell(); |
242 | | |
243 | | void ConnectSidebarWinToFrame( const SwFrame& rFrame, |
244 | | const SwFormatField& rFormatField, |
245 | | sw::annotation::SwAnnotationWin& rSidebarWin ); |
246 | | void DisconnectSidebarWinFromFrame( const SwFrame& rFrame, |
247 | | sw::annotation::SwAnnotationWin& rSidebarWin ); |
248 | | bool HasFrameConnectedSidebarWins( const SwFrame& rFrame ); |
249 | | vcl::Window* GetSidebarWinForFrameByIndex( const SwFrame& rFrame, |
250 | | const sal_Int32 nIndex ); |
251 | | std::vector<vcl::Window*> GetAllSidebarWinForFrame(const SwFrame& rFrame); |
252 | | |
253 | | void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage); |
254 | | void PaintTile(OutputDevice& rRenderContext); |
255 | | |
256 | | sw::sidebarwindows::SidebarPosition GetSidebarPos(const Point& rPointLogic); |
257 | | |
258 | 0 | void SetForceShowForPrintOrPdf(bool bForce) { mbForceShowForPrintOrPdf = bForce; } |
259 | | |
260 | | // The commands that directly delete comments (as opposed to deletion of the text that the |
261 | | // comments are anchored to) behave differently, depending on the document type, when the |
262 | | // change tracking is on. For ODF, we allow comments to be marked as deleted; for external |
263 | | // document types, we delete them immediately, as if change tracking os off. |
264 | | class CommentDeleteFlagsRestore |
265 | | { |
266 | | public: |
267 | 0 | virtual ~CommentDeleteFlagsRestore() = default; |
268 | | }; |
269 | | // Checks if the respective configuration must be changed for 'delete' operation, makes the |
270 | | // change if needed, and returns a RAII object that will restore the original configuration |
271 | | // in its dtor. |
272 | | [[nodiscard]] std::unique_ptr<CommentDeleteFlagsRestore> ConfigureForCommentDelete(); |
273 | | }; |
274 | | |
275 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |