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