Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / PostItMgr.hxx
blob38f2bbff3ff3823e36f0e362eb11bb6cfbb7e8a6
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 <list>
28 #include <vector>
29 #include <editeng/outlobj.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/log.hxx>
32 #include <tools/link.hxx>
33 #include <swrect.hxx>
34 #include <unotools/configitem.hxx>
35 #include <unotools/options.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <SidebarWindowsTypes.hxx>
38 #include <svl/lstner.hxx>
39 #include <vcl/vclptr.hxx>
40 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
42 class OutputDevice;
43 class SwWrtShell;
44 class SwDoc;
45 class SwView;
46 class SwPostItField;
47 class SwFormatField;
48 class SwField;
49 class SfxBroadcaster;
50 class SfxHint;
51 class SwEditWin;
52 class Color;
53 class SfxItemPool;
54 class SfxItemSet;
55 class SvxSearchItem;
56 class SvxLanguageItem;
57 namespace sw { namespace annotation {
58 class SwAnnotationWin;
60 namespace sw { namespace sidebarwindows {
61 class SwFrameSidebarWinContainer;
63 class SwSidebarItem;
64 class SwFrame;
65 namespace vcl { class Window; }
66 struct ImplSVEvent;
67 class OutlinerSearchable;
68 namespace i18nutil { struct SearchOptions2; }
70 #define COL_NOTES_SIDEPANE_ARROW_ENABLED RGB_COLORDATA(0,0,0)
71 #define COL_NOTES_SIDEPANE_ARROW_DISABLED RGB_COLORDATA(172,168,153)
73 typedef std::list<SwSidebarItem*> SwSidebarItem_list;
74 typedef std::list<SwSidebarItem*>::iterator SwSidebarItem_iterator;
76 struct SwPostItPageItem
78 bool bScrollbar;
79 sw::sidebarwindows::SidebarPosition eSidebarPosition;
80 long lOffset;
81 SwRect mPageRect;
82 SwSidebarItem_list* mList;
83 SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT ), lOffset(0)
85 mList = new SwSidebarItem_list;
87 ~SwPostItPageItem()
89 mList->clear();
90 delete mList;
95 struct FieldShadowState
97 const SwPostItField* mpShadowField;
98 bool bCursor;
99 bool bMouse;
100 FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
105 class SwNoteProps: public utl::ConfigItem
107 private:
108 bool bIsShowAnchor;
110 virtual void ImplCommit() override;
112 public:
113 SwNoteProps()
114 : ConfigItem("Office.Writer/Notes")
115 , bIsShowAnchor(false)
117 const css::uno::Sequence< OUString >& rNames = GetPropertyNames();
118 css::uno::Sequence< css::uno::Any > aValues = GetProperties(rNames);
119 const css::uno::Any* pValues = aValues.getConstArray();
120 SAL_WARN_IF(aValues.getLength() != rNames.getLength(), "sw", "GetProperties failed");
121 if (aValues.getLength())
122 pValues[0]>>=bIsShowAnchor;
125 bool IsShowAnchor()
127 return bIsShowAnchor;
129 static css::uno::Sequence< OUString >& GetPropertyNames()
131 static css::uno::Sequence< OUString > aNames;
132 if(!aNames.getLength())
134 aNames.realloc(1);
135 OUString* pNames = aNames.getArray();
136 pNames[0] = "ShowAnkor";
138 return aNames;
141 virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
144 class SwPostItMgr: public SfxListener
146 private:
147 SwView* mpView;
148 SwWrtShell* mpWrtShell;
149 VclPtr<SwEditWin> mpEditWin;
150 std::list< SwSidebarItem*> mvPostItFields;
151 std::vector<SwPostItPageItem*> mPages;
152 ImplSVEvent * mnEventId;
153 bool mbWaitingForCalcRects;
154 VclPtr<sw::annotation::SwAnnotationWin> mpActivePostIt;
155 bool mbLayout;
156 long mbLayoutHeight;
157 bool mbLayouting;
158 bool mbReadOnly;
159 bool mbDeleteNote;
160 FieldShadowState mShadowState;
161 OutlinerParaObject* mpAnswer;
162 OUString maAnswerText;
163 bool mbIsShowAnchor;
165 // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
166 sw::sidebarwindows::SwFrameSidebarWinContainer* mpFrameSidebarWinContainer;
168 typedef std::list<sw::annotation::SwAnnotationWin*>::iterator SwAnnotationWin_iterator;
170 void AddPostIts(bool bCheckExistance = true,bool bFocus = true);
171 void RemoveSidebarWin();
172 void PreparePageContainer();
173 void Scroll(const long lScroll,const unsigned long aPage );
174 void AutoScroll(const sw::annotation::SwAnnotationWin* pPostIt,const unsigned long aPage );
175 bool ScrollbarHit(const unsigned long aPage,const Point &aPoint);
176 bool LayoutByPage( std::list<sw::annotation::SwAnnotationWin*> &aVisiblePostItList,
177 const tools::Rectangle& rBorder,
178 long lNeededHeight);
179 void CheckForRemovedPostIts();
180 bool ArrowEnabled(sal_uInt16 aDirection,unsigned long aPage) const;
181 bool BorderOverPageBorder(unsigned long aPage) const;
182 bool HasScrollbars() const;
183 void Focus(SfxBroadcaster& rBC);
185 sal_Int32 GetInitialAnchorDistance() const;
186 sal_Int32 GetScrollSize() const;
187 sal_Int32 GetSpaceBetween() const;
188 void SetReadOnlyState();
189 DECL_LINK( CalcHdl, void*, void);
191 sw::annotation::SwAnnotationWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const;
193 SwSidebarItem* InsertItem( SfxBroadcaster* pItem, bool bCheckExistance, bool bFocus);
194 void RemoveItem( SfxBroadcaster* pBroadcast );
196 public:
197 SwPostItMgr(SwView* aDoc);
198 virtual ~SwPostItMgr() override;
200 typedef std::list< SwSidebarItem* >::const_iterator const_iterator;
201 const_iterator begin() const { return mvPostItFields.begin(); }
202 const_iterator end() const { return mvPostItFields.end(); }
204 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
206 void LayoutPostIts();
207 bool CalcRects();
209 void MakeVisible( const sw::annotation::SwAnnotationWin* pPostIt);
211 bool ShowScrollbar(const unsigned long aPage) const;
212 bool HasNotes() const ;
213 bool ShowNotes() const;
214 bool IsShowAnchor() { return mbIsShowAnchor;}
215 unsigned long GetSidebarWidth(bool bPx = false) const;
216 unsigned long GetSidebarBorderWidth(bool bPx = false) const;
218 void PrepareView(bool bIgnoreCount = false);
220 void CorrectPositions();
222 void SetLayout() { mbLayout = true; };
223 void Delete(const OUString& aAuthor);
224 void Delete(sal_uInt32 nPostItId);
225 void Delete();
227 void ExecuteFormatAllDialog(SwView& rView);
228 void FormatAll(const SfxItemSet &rNewAttr);
230 void Hide( const OUString& rAuthor );
231 void Hide();
232 void Show();
234 void Rescale();
236 tools::Rectangle GetBottomScrollRect(const unsigned long aPage) const;
237 tools::Rectangle GetTopScrollRect(const unsigned long aPage) const;
239 bool IsHit(const Point &aPointPixel);
240 /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
241 vcl::Window* IsHitSidebarWindow(const Point& rPointLogic);
242 Color GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const;
244 sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const;
245 sw::annotation::SwAnnotationWin* GetAnnotationWin(const sal_uInt32 nPostItId) const;
247 sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection,
248 sw::annotation::SwAnnotationWin* aPostIt);
249 long GetNextBorder();
251 sw::annotation::SwAnnotationWin* GetActiveSidebarWin() { return mpActivePostIt; }
252 void SetActiveSidebarWin( sw::annotation::SwAnnotationWin* p);
253 SW_DLLPUBLIC bool HasActiveSidebarWin() const;
254 bool HasActiveAnnotationWin() const;
255 void GrabFocusOnActiveSidebarWin();
256 SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin();
257 void DeleteActiveSidebarWin();
258 void HideActiveSidebarWin();
259 void ToggleInsModeOnActiveSidebarWin();
261 sal_Int32 GetMinimumSizeWithMeta() const;
262 sal_Int32 GetSidebarScrollerHeight() const;
264 void SetShadowState(const SwPostItField* pField,bool bCursor = true);
266 void SetSpellChecking();
268 static Color GetColorDark(std::size_t aAuthorIndex);
269 static Color GetColorLight(std::size_t aAuthorIndex);
270 static Color GetColorAnchor(std::size_t aAuthorIndex);
272 void RegisterAnswer(OutlinerParaObject* pAnswer) { mpAnswer = pAnswer;}
273 OutlinerParaObject* IsAnswer() {return mpAnswer;}
274 void RegisterAnswerText(const OUString& aAnswerText) { maAnswerText = aAnswerText; }
275 const OUString& GetAnswerText() { return maAnswerText; }
276 void CheckMetaText();
278 sal_uInt16 Replace(SvxSearchItem* pItem);
279 sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
280 sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions,bool bSrchForward);
282 void AssureStdModeAtShell();
284 void ConnectSidebarWinToFrame( const SwFrame& rFrame,
285 const SwFormatField& rFormatField,
286 sw::annotation::SwAnnotationWin& rSidebarWin );
287 void DisconnectSidebarWinFromFrame( const SwFrame& rFrame,
288 sw::annotation::SwAnnotationWin& rSidebarWin );
289 bool HasFrameConnectedSidebarWins( const SwFrame& rFrame );
290 vcl::Window* GetSidebarWinForFrameByIndex( const SwFrame& rFrame,
291 const sal_Int32 nIndex );
292 void GetAllSidebarWinForFrame( const SwFrame& rFrame,
293 std::vector< vcl::Window* >* pChildren );
295 void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
296 void PaintTile(OutputDevice& rRenderContext);
299 #endif
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */