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