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 <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 
67 {
68  bool bScrollbar;
70  long lOffset;
72  std::vector<SwSidebarItem*> mvSidebarItems;
73  SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT ), lOffset(0)
74  {
75  }
76 };
77 
79 {
81  bool bCursor;
82  bool bMouse;
83  FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
84  {
85  }
86 };
87 
89 {
90  private:
92 
93  virtual void ImplCommit() override;
94 
95  public:
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 
108  bool IsShowAnchor() const
109  {
110  return m_bIsShowAnchor;
111  }
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: public SfxListener
128 {
129  private:
133  std::vector<std::unique_ptr<SwSidebarItem>> mvPostItFields;
134  std::vector<std::unique_ptr<SwPostItPageItem>> mPages;
138  bool mbLayout;
145  OUString maAnswerText;
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;
182  const_iterator begin() const { return mvPostItFields.begin(); }
183  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;
195  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 
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);
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,
234  long GetNextBorder();
235 
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 
257  void RegisterAnswer(OutlinerParaObject* pAnswer) { mpAnswer = pAnswer;}
258  OutlinerParaObject* IsAnswer() {return mpAnswer;}
259  void RegisterAnswerText(const OUString& aAnswerText) { maAnswerText = aAnswerText; }
260  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: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
bool mbWaitingForCalcRects
Definition: PostItMgr.hxx:136
std::vector< SwSidebarItem * > mvSidebarItems
Definition: PostItMgr.hxx:72
OutlinerParaObject * IsAnswer()
Definition: PostItMgr.hxx:258
bool m_bIsShowAnchor
Definition: PostItMgr.hxx:91
const_iterator begin() const
Definition: PostItMgr.hxx:182
sw::sidebarwindows::SidebarPosition eSidebarPosition
Definition: PostItMgr.hxx:69
static css::uno::Sequence< OUString > & GetPropertyNames()
Definition: PostItMgr.hxx:112
VclPtr< sw::annotation::SwAnnotationWin > mpActivePostIt
Definition: PostItMgr.hxx:137
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:88
bool mbDeleteNote
Definition: PostItMgr.hxx:142
std::unique_ptr< sw::sidebarwindows::SwFrameSidebarWinContainer > mpFrameSidebarWinContainer
Definition: PostItMgr.hxx:149
SwView * mpView
Definition: PostItMgr.hxx:130
ConfigItem(ConfigItem const &)=default
OutlinerParaObject * mpAnswer
Definition: PostItMgr.hxx:144
ImplSVEvent * mnEventId
Definition: PostItMgr.hxx:135
const_iterator end() const
Definition: PostItMgr.hxx:183
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:143
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
VclPtr< SwEditWin > mpEditWin
Definition: PostItMgr.hxx:132
const SwPostItField * mpShadowField
Definition: PostItMgr.hxx:80
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
virtual void ImplCommit() override
Definition: PostItMgr.cxx:2470
#define SAL_WARN_IF(condition, area, stream)
bool IsShowAnchor() const
Definition: PostItMgr.hxx:195
void SetLayout()
Definition: PostItMgr.hxx:203
bool mbLayouting
Definition: PostItMgr.hxx:140
std::vector< std::unique_ptr< SwSidebarItem > >::const_iterator const_iterator
Definition: PostItMgr.hxx:181
bool mbIsShowAnchor
Definition: PostItMgr.hxx:146
OUString maAnswerText
Definition: PostItMgr.hxx:145
void RegisterAnswer(OutlinerParaObject *pAnswer)
Definition: PostItMgr.hxx:257
sw::annotation::SwAnnotationWin * GetActiveSidebarWin()
Definition: PostItMgr.hxx:236
std::vector< std::unique_ptr< SwPostItPageItem > > mPages
Definition: PostItMgr.hxx:134
long mbLayoutHeight
Definition: PostItMgr.hxx:139
bool mbReadOnly
Definition: PostItMgr.hxx:141
bool IsShowAnchor() const
Definition: PostItMgr.hxx:108
void RegisterAnswerText(const OUString &aAnswerText)
Definition: PostItMgr.hxx:259
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: PostItMgr.cxx:2471
const OUString & GetAnswerText() const
Definition: PostItMgr.hxx:260
std::vector< std::unique_ptr< SwSidebarItem > > mvPostItFields
Definition: PostItMgr.hxx:133
Definition: view.hxx:146
SwWrtShell * mpWrtShell
Definition: PostItMgr.hxx:131