Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / PostItMgr.hxx
blob760fc7f8abe7c82deee2ad81ca4444f6b8e96ffd
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_SW_INC_POSTITMGR_HXX
21 #define INCLUDED_SW_INC_POSTITMGR_HXX
23 #include <sal/config.h>
24 #include "swdllapi.h"
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 <svl/lstner.hxx>
37 #include <vcl/vclptr.hxx>
39 class OutputDevice;
40 class SwWrtShell;
41 class SwView;
42 class SwPostItField;
43 class SwFormatField;
44 class SfxBroadcaster;
45 class SfxHint;
46 class SwEditWin;
47 class Color;
48 class SfxItemSet;
49 class SvxSearchItem;
50 namespace sw::annotation { class SwAnnotationWin; }
51 namespace sw::sidebarwindows { class SwFrameSidebarWinContainer; }
52 class SwSidebarItem;
53 class SwFrame;
54 namespace vcl { class Window; }
55 struct ImplSVEvent;
56 class OutlinerParaObject;
57 namespace i18nutil { struct SearchOptions2; }
59 #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0)
60 #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153)
62 struct SwPostItPageItem
64 bool bScrollbar;
65 sw::sidebarwindows::SidebarPosition eSidebarPosition;
66 tools::Long lOffset;
67 SwRect mPageRect;
68 std::vector<SwSidebarItem*> mvSidebarItems;
69 SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT ), lOffset(0)
74 struct FieldShadowState
76 const SwPostItField* mpShadowField;
77 bool bCursor;
78 bool bMouse;
79 FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
84 class SwNoteProps final : public utl::ConfigItem
86 private:
87 bool m_bIsShowAnchor;
89 virtual void ImplCommit() override;
91 public:
92 SwNoteProps()
93 : ConfigItem("Office.Writer/Notes")
94 , m_bIsShowAnchor(false)
96 const css::uno::Sequence< OUString >& rNames = GetPropertyNames();
97 css::uno::Sequence< css::uno::Any > aValues = GetProperties(rNames);
98 const css::uno::Any* pValues = aValues.getConstArray();
99 SAL_WARN_IF(aValues.getLength() != rNames.getLength(), "sw", "GetProperties failed");
100 if (aValues.hasElements())
101 pValues[0]>>=m_bIsShowAnchor;
104 bool IsShowAnchor() const
106 return m_bIsShowAnchor;
108 static css::uno::Sequence< OUString >& GetPropertyNames()
110 static css::uno::Sequence< OUString > aNames;
111 if(!aNames.hasElements())
113 aNames.realloc(1);
114 OUString* pNames = aNames.getArray();
115 pNames[0] = "ShowAnkor";
117 return aNames;
120 virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
123 class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener
125 private:
126 SwView* mpView;
127 SwWrtShell* mpWrtShell;
128 VclPtr<SwEditWin> mpEditWin;
129 std::vector<std::unique_ptr<SwSidebarItem>> mvPostItFields;
130 std::vector<std::unique_ptr<SwPostItPageItem>> mPages;
131 ImplSVEvent * mnEventId;
132 bool mbWaitingForCalcRects;
133 VclPtr<sw::annotation::SwAnnotationWin> mpActivePostIt;
134 bool mbLayout;
135 tools::Long mbLayoutHeight;
136 bool mbLayouting;
137 bool mbReadOnly;
138 bool mbDeleteNote;
139 FieldShadowState mShadowState;
140 OutlinerParaObject* mpAnswer;
141 OUString maAnswerText;
142 bool mbIsShowAnchor;
144 // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
145 std::unique_ptr<sw::sidebarwindows::SwFrameSidebarWinContainer> mpFrameSidebarWinContainer;
147 void AddPostIts(bool bCheckExistence = true,bool bFocus = true);
148 void RemoveSidebarWin();
149 void PreparePageContainer();
150 void Scroll(const tools::Long lScroll,const tools::ULong aPage );
151 void AutoScroll(const sw::annotation::SwAnnotationWin* pPostIt,const tools::ULong aPage );
152 bool ScrollbarHit(const tools::ULong aPage,const Point &aPoint);
153 bool LayoutByPage( std::vector<sw::annotation::SwAnnotationWin*> &aVisiblePostItList,
154 const tools::Rectangle& rBorder,
155 tools::Long lNeededHeight);
156 void CheckForRemovedPostIts();
157 bool ArrowEnabled(sal_uInt16 aDirection,tools::ULong aPage) const;
158 bool BorderOverPageBorder(tools::ULong aPage) const;
159 bool HasScrollbars() const;
160 void Focus(SfxBroadcaster& rBC);
162 sal_Int32 GetInitialAnchorDistance() const;
163 sal_Int32 GetScrollSize() const;
164 sal_Int32 GetSpaceBetween() const;
165 void SetReadOnlyState();
166 DECL_LINK( CalcHdl, void*, void);
168 sw::annotation::SwAnnotationWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const;
170 SwSidebarItem* InsertItem( SfxBroadcaster* pItem, bool bCheckExistence, bool bFocus);
171 void RemoveItem( SfxBroadcaster* pBroadcast );
173 public:
174 SwPostItMgr(SwView* aDoc);
175 virtual ~SwPostItMgr() override;
177 typedef std::vector< std::unique_ptr<SwSidebarItem> >::const_iterator const_iterator;
178 const_iterator begin() const { return mvPostItFields.begin(); }
179 const_iterator end() const { return mvPostItFields.end(); }
181 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
183 void LayoutPostIts();
184 bool CalcRects();
186 void MakeVisible( const sw::annotation::SwAnnotationWin* pPostIt);
188 bool ShowScrollbar(const tools::ULong aPage) const;
189 bool HasNotes() const ;
190 bool ShowNotes() const;
191 bool IsShowAnchor() const { return mbIsShowAnchor;}
192 tools::ULong GetSidebarWidth(bool bPx = false) const;
193 tools::ULong GetSidebarBorderWidth(bool bPx = false) const;
195 void PrepareView(bool bIgnoreCount = false);
197 void CorrectPositions();
199 void SetLayout() { mbLayout = true; };
200 void Delete(const OUString& aAuthor);
201 void Delete(sal_uInt32 nPostItId);
202 void Delete();
203 void DeleteCommentThread(sal_uInt32 nPostItId);
204 void ToggleResolved(sal_uInt32 nPostItId);
205 void ToggleResolvedForThread(sal_uInt32 nPostItId);
207 void ExecuteFormatAllDialog(SwView& rView);
208 void FormatAll(const SfxItemSet &rNewAttr);
210 void Hide( std::u16string_view rAuthor );
211 void Hide();
212 void Show();
213 void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin* topNote);
214 void ShowHideResolvedNotes(bool visible);
216 void Rescale();
218 tools::Rectangle GetBottomScrollRect(const tools::ULong aPage) const;
219 tools::Rectangle GetTopScrollRect(const tools::ULong aPage) const;
221 bool IsHit(const Point &aPointPixel);
222 /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
223 vcl::Window* IsHitSidebarWindow(const Point& rPointLogic);
224 Color GetArrowColor(sal_uInt16 aDirection, tools::ULong aPage) const;
226 sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const;
227 sw::annotation::SwAnnotationWin* GetAnnotationWin(const sal_uInt32 nPostItId) const;
229 sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection,
230 sw::annotation::SwAnnotationWin* aPostIt);
231 tools::Long GetNextBorder();
233 sw::annotation::SwAnnotationWin* GetActiveSidebarWin() { return mpActivePostIt; }
234 void SetActiveSidebarWin( sw::annotation::SwAnnotationWin* p);
235 SW_DLLPUBLIC bool HasActiveSidebarWin() const;
236 bool HasActiveAnnotationWin() const;
237 void GrabFocusOnActiveSidebarWin();
238 SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin();
239 void DeleteActiveSidebarWin();
240 void HideActiveSidebarWin();
241 void ToggleInsModeOnActiveSidebarWin();
243 sal_Int32 GetMinimumSizeWithMeta() const;
244 sal_Int32 GetSidebarScrollerHeight() const;
246 void SetShadowState(const SwPostItField* pField,bool bCursor = true);
248 void SetSpellChecking();
250 static Color GetColorDark(std::size_t aAuthorIndex);
251 static Color GetColorLight(std::size_t aAuthorIndex);
252 static Color GetColorAnchor(std::size_t aAuthorIndex);
254 void RegisterAnswer(OutlinerParaObject* pAnswer) { mpAnswer = pAnswer;}
255 OutlinerParaObject* IsAnswer() {return mpAnswer;}
256 void RegisterAnswerText(const OUString& aAnswerText) { maAnswerText = aAnswerText; }
257 const OUString& GetAnswerText() const { return maAnswerText; }
258 void CheckMetaText();
260 sal_uInt16 Replace(SvxSearchItem const * pItem);
261 sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
262 sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
264 void AssureStdModeAtShell();
266 void ConnectSidebarWinToFrame( const SwFrame& rFrame,
267 const SwFormatField& rFormatField,
268 sw::annotation::SwAnnotationWin& rSidebarWin );
269 void DisconnectSidebarWinFromFrame( const SwFrame& rFrame,
270 sw::annotation::SwAnnotationWin& rSidebarWin );
271 bool HasFrameConnectedSidebarWins( const SwFrame& rFrame );
272 vcl::Window* GetSidebarWinForFrameByIndex( const SwFrame& rFrame,
273 const sal_Int32 nIndex );
274 void GetAllSidebarWinForFrame( const SwFrame& rFrame,
275 std::vector< vcl::Window* >* pChildren );
277 void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
278 void PaintTile(OutputDevice& rRenderContext);
281 #endif
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */