a11y: Simplify OCommonAccessibleComponent::getAccessibleIndexInParent
[LibreOffice.git] / sw / inc / PostItMgr.hxx
blob8c25f381641be230f2cc7a31cb69b553c2dce5d5
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 .
19 #pragma once
21 #include <sal/config.h>
22 #include "swdllapi.h"
24 #include <cstddef>
25 #include <memory>
26 #include <vector>
27 #include <rtl/ustring.hxx>
28 #include <sal/log.hxx>
29 #include <tools/link.hxx>
30 #include "swrect.hxx"
31 #include <unotools/configitem.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include "SidebarWindowsTypes.hxx"
34 #include <editeng/outlobj.hxx>
35 #include <svl/lstner.hxx>
36 #include <vcl/vclptr.hxx>
38 class OutputDevice;
39 class SwWrtShell;
40 class SwView;
41 class SwPostItField;
42 class SwFormatField;
43 class SfxBroadcaster;
44 class SfxHint;
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 SwSidebarItem;
52 class SwFrame;
53 namespace vcl { class Window; }
54 struct ImplSVEvent;
55 class OutlinerParaObject;
56 namespace i18nutil { struct SearchOptions2; }
58 #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0)
59 #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153)
61 struct SwPostItPageItem
63 bool bScrollbar;
64 sw::sidebarwindows::SidebarPosition eSidebarPosition;
65 tools::Long lOffset;
66 SwRect mPageRect;
67 std::vector<SwSidebarItem*> mvSidebarItems;
68 SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::NONE ), lOffset(0)
73 struct FieldShadowState
75 const SwPostItField* mpShadowField;
76 bool bCursor;
77 bool bMouse;
78 FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
83 class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener,
84 public SfxBroadcaster
86 private:
87 SwView* mpView;
88 SwWrtShell* mpWrtShell;
89 VclPtr<SwEditWin> mpEditWin;
90 std::vector<std::unique_ptr<SwSidebarItem>> mvPostItFields;
91 std::vector<std::unique_ptr<SwPostItPageItem>> mPages;
92 ImplSVEvent * mnEventId;
93 bool mbWaitingForCalcRects;
94 VclPtr<sw::annotation::SwAnnotationWin> mpActivePostIt;
95 bool mbLayout;
96 tools::Long mbLayoutHeight;
97 bool mbLayouting;
98 bool mbReadOnly;
99 bool mbDeleteNote;
100 FieldShadowState mShadowState;
101 std::optional<OutlinerParaObject> mpAnswer;
102 OUString maAnswerText;
104 // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
105 std::unique_ptr<sw::sidebarwindows::SwFrameSidebarWinContainer> mpFrameSidebarWinContainer;
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);
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);
129 sw::annotation::SwAnnotationWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const;
131 SwSidebarItem* InsertItem( SfxBroadcaster* pItem, bool bCheckExistence, bool bFocus);
132 void RemoveItem( SfxBroadcaster* pBroadcast );
134 VclPtr<sw::annotation::SwAnnotationWin> GetOrCreateAnnotationWindow(SwSidebarItem& rItem);
136 public:
137 SwPostItMgr(SwView* aDoc);
138 virtual ~SwPostItMgr() override;
140 typedef std::vector< std::unique_ptr<SwSidebarItem> >::const_iterator const_iterator;
141 const_iterator begin() const { return mvPostItFields.begin(); }
142 const_iterator end() const { return mvPostItFields.end(); }
143 const std::vector<std::unique_ptr<SwSidebarItem>>& GetPostItFields() { return mvPostItFields; }
145 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
147 std::vector<SwFormatField*> UpdatePostItsParentInfo();
148 void LayoutPostIts();
149 bool CalcRects();
151 void MakeVisible( const sw::annotation::SwAnnotationWin* pPostIt);
153 bool ShowScrollbar(const tools::ULong aPage) const;
154 bool HasNotes() const ;
155 bool ShowNotes() const;
156 void SetSidebarWidth(const Point& rPointLogic);
157 tools::Rectangle GetSidebarRect(const Point& rPointLogic);
158 tools::ULong GetSidebarWidth(bool bPx = false) const;
159 tools::ULong GetSidebarBorderWidth(bool bPx = false) const;
161 void PrepareView(bool bIgnoreCount = false);
163 void CorrectPositions();
165 void SetLayout() { mbLayout = true; };
166 void Delete(const OUString& aAuthor);
167 void Delete(sal_uInt32 nPostItId);
168 void Delete();
169 void DeleteCommentThread(sal_uInt32 nPostItId);
170 void ToggleResolved(sal_uInt32 nPostItId);
171 void ToggleResolvedForThread(sal_uInt32 nPostItId);
172 void PromoteToRoot(sal_uInt32 nPostItId);
173 void MoveSubthreadToRoot(const sw::annotation::SwAnnotationWin* pNewRoot);
175 sw::annotation::SwAnnotationWin* GetRemovedAnnotationWin(const SfxBroadcaster* pBroadcast);
177 void ExecuteFormatAllDialog(SwView& rView);
178 void FormatAll(const SfxItemSet &rNewAttr);
180 void Hide( std::u16string_view rAuthor );
181 void Hide();
182 void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin* topNote);
183 void ShowHideResolvedNotes(bool visible);
185 void Rescale();
187 tools::Rectangle GetBottomScrollRect(const tools::ULong aPage) const;
188 tools::Rectangle GetTopScrollRect(const tools::ULong aPage) const;
190 bool IsHit(const Point &aPointPixel);
191 /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
192 vcl::Window* IsHitSidebarWindow(const Point& rPointLogic);
193 bool IsHitSidebarDragArea(const Point& rPointLogic);
194 Color GetArrowColor(sal_uInt16 aDirection, tools::ULong aPage) const;
196 sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const;
197 sw::annotation::SwAnnotationWin* GetAnnotationWin(const sal_uInt32 nPostItId) const;
199 sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection,
200 sw::annotation::SwAnnotationWin* aPostIt);
201 SwPostItField* GetLatestPostItField();
202 sw::annotation::SwAnnotationWin* GetOrCreateAnnotationWindowForLatestPostItField();
204 tools::Long GetNextBorder();
206 sw::annotation::SwAnnotationWin* GetActiveSidebarWin() { return mpActivePostIt; }
207 void SetActiveSidebarWin( sw::annotation::SwAnnotationWin* p);
208 SW_DLLPUBLIC bool HasActiveSidebarWin() const;
209 bool HasActiveAnnotationWin() const;
210 void GrabFocusOnActiveSidebarWin();
211 SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin();
212 void DeleteActiveSidebarWin();
213 void HideActiveSidebarWin();
214 void ToggleInsModeOnActiveSidebarWin();
216 sal_Int32 GetMinimumSizeWithMeta() const;
217 sal_Int32 GetSidebarScrollerHeight() const;
219 void SetShadowState(const SwPostItField* pField,bool bCursor = true);
221 void SetSpellChecking();
223 static Color GetColorDark(std::size_t aAuthorIndex);
224 static Color GetColorLight(std::size_t aAuthorIndex);
225 static Color GetColorAnchor(std::size_t aAuthorIndex);
227 void RegisterAnswer(const OutlinerParaObject& rAnswer) { mpAnswer = rAnswer; }
228 OutlinerParaObject* IsAnswer() { return mpAnswer ? &*mpAnswer : nullptr; }
229 void RegisterAnswerText(const OUString& rAnswerText) { maAnswerText = rAnswerText; }
230 const OUString& GetAnswerText() const { return maAnswerText; }
231 void CheckMetaText();
232 void UpdateColors();
234 sal_uInt16 Replace(SvxSearchItem const * pItem);
235 sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
236 sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
238 void AssureStdModeAtShell();
240 void ConnectSidebarWinToFrame( const SwFrame& rFrame,
241 const SwFormatField& rFormatField,
242 sw::annotation::SwAnnotationWin& rSidebarWin );
243 void DisconnectSidebarWinFromFrame( const SwFrame& rFrame,
244 sw::annotation::SwAnnotationWin& rSidebarWin );
245 bool HasFrameConnectedSidebarWins( const SwFrame& rFrame );
246 vcl::Window* GetSidebarWinForFrameByIndex( const SwFrame& rFrame,
247 const sal_Int32 nIndex );
248 void GetAllSidebarWinForFrame( const SwFrame& rFrame,
249 std::vector< vcl::Window* >* pChildren );
251 void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
252 void PaintTile(OutputDevice& rRenderContext);
254 sw::sidebarwindows::SidebarPosition GetSidebarPos(const Point& rPointLogic);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */