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::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; }
58 
59 #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0)
60 #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153)
61 
63 {
64  bool bScrollbar;
68  std::vector<SwSidebarItem*> mvSidebarItems;
69  SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT ), lOffset(0)
70  {
71  }
72 };
73 
75 {
77  bool bCursor;
78  bool bMouse;
79  FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
80  {
81  }
82 };
83 
84 class SwNoteProps final : public utl::ConfigItem
85 {
86  private:
88 
89  virtual void ImplCommit() override;
90 
91  public:
93  : ConfigItem("Office.Writer/Notes")
94  , m_bIsShowAnchor(false)
95  {
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;
102  }
103 
104  bool IsShowAnchor() const
105  {
106  return m_bIsShowAnchor;
107  }
108  static css::uno::Sequence< OUString >& GetPropertyNames()
109  {
110  static css::uno::Sequence< OUString > aNames;
111  if(!aNames.hasElements())
112  {
113  aNames.realloc(1);
114  OUString* pNames = aNames.getArray();
115  pNames[0] = "ShowAnkor";
116  }
117  return aNames;
118  }
119 
120  virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
121 };
122 
123 class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener
124 {
125  private:
129  std::vector<std::unique_ptr<SwSidebarItem>> mvPostItFields;
130  std::vector<std::unique_ptr<SwPostItPageItem>> mPages;
134  bool mbLayout;
141  OUString maAnswerText;
143 
144  // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
145  std::unique_ptr<sw::sidebarwindows::SwFrameSidebarWinContainer> mpFrameSidebarWinContainer;
146 
147  void AddPostIts(bool bCheckExistence = true,bool bFocus = true);
148  void RemoveSidebarWin();
149  void PreparePageContainer();
150  void Scroll(const tools::Long lScroll,const unsigned long aPage );
151  void AutoScroll(const sw::annotation::SwAnnotationWin* pPostIt,const unsigned long aPage );
152  bool ScrollbarHit(const unsigned long 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,unsigned long aPage) const;
158  bool BorderOverPageBorder(unsigned long aPage) const;
159  bool HasScrollbars() const;
160  void Focus(SfxBroadcaster& rBC);
161 
162  sal_Int32 GetInitialAnchorDistance() const;
163  sal_Int32 GetScrollSize() const;
164  sal_Int32 GetSpaceBetween() const;
165  void SetReadOnlyState();
166  DECL_LINK( CalcHdl, void*, void);
167 
168  sw::annotation::SwAnnotationWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const;
169 
170  SwSidebarItem* InsertItem( SfxBroadcaster* pItem, bool bCheckExistence, bool bFocus);
171  void RemoveItem( SfxBroadcaster* pBroadcast );
172 
173  public:
174  SwPostItMgr(SwView* aDoc);
175  virtual ~SwPostItMgr() override;
176 
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(); }
180 
181  void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
182 
183  void LayoutPostIts();
184  bool CalcRects();
185 
186  void MakeVisible( const sw::annotation::SwAnnotationWin* pPostIt);
187 
188  bool ShowScrollbar(const unsigned long aPage) const;
189  bool HasNotes() const ;
190  bool ShowNotes() const;
191  bool IsShowAnchor() const { return mbIsShowAnchor;}
192  unsigned long GetSidebarWidth(bool bPx = false) const;
193  unsigned long GetSidebarBorderWidth(bool bPx = false) const;
194 
195  void PrepareView(bool bIgnoreCount = false);
196 
197  void CorrectPositions();
198 
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);
206 
207  void ExecuteFormatAllDialog(SwView& rView);
208  void FormatAll(const SfxItemSet &rNewAttr);
209 
210  void Hide( const OUString& rAuthor );
211  void Hide();
212  void Show();
213  void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin* topNote);
214  void ShowHideResolvedNotes(bool visible);
215 
216  void Rescale();
217 
218  tools::Rectangle GetBottomScrollRect(const unsigned long aPage) const;
219  tools::Rectangle GetTopScrollRect(const unsigned long aPage) const;
220 
221  bool IsHit(const Point &aPointPixel);
223  vcl::Window* IsHitSidebarWindow(const Point& rPointLogic);
224  Color GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const;
225 
226  sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const;
227  sw::annotation::SwAnnotationWin* GetAnnotationWin(const sal_uInt32 nPostItId) const;
228 
229  sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection,
231  tools::Long GetNextBorder();
232 
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();
242 
243  sal_Int32 GetMinimumSizeWithMeta() const;
244  sal_Int32 GetSidebarScrollerHeight() const;
245 
246  void SetShadowState(const SwPostItField* pField,bool bCursor = true);
247 
248  void SetSpellChecking();
249 
250  static Color GetColorDark(std::size_t aAuthorIndex);
251  static Color GetColorLight(std::size_t aAuthorIndex);
252  static Color GetColorAnchor(std::size_t aAuthorIndex);
253 
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();
259 
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);
263 
264  void AssureStdModeAtShell();
265 
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 );
276 
277  void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
278  void PaintTile(OutputDevice& rRenderContext);
279 };
280 
281 #endif
282 
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:297
bool mbWaitingForCalcRects
Definition: PostItMgr.hxx:132
std::vector< SwSidebarItem * > mvSidebarItems
Definition: PostItMgr.hxx:68
OutlinerParaObject * IsAnswer()
Definition: PostItMgr.hxx:255
bool m_bIsShowAnchor
Definition: PostItMgr.hxx:87
const_iterator begin() const
Definition: PostItMgr.hxx:178
long Long
sw::sidebarwindows::SidebarPosition eSidebarPosition
Definition: PostItMgr.hxx:65
static css::uno::Sequence< OUString > & GetPropertyNames()
Definition: PostItMgr.hxx:108
VclPtr< sw::annotation::SwAnnotationWin > mpActivePostIt
Definition: PostItMgr.hxx:133
Dialog to specify the properties of date form field.
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
bool mbDeleteNote
Definition: PostItMgr.hxx:138
std::unique_ptr< sw::sidebarwindows::SwFrameSidebarWinContainer > mpFrameSidebarWinContainer
Definition: PostItMgr.hxx:145
SwView * mpView
Definition: PostItMgr.hxx:126
ConfigItem(ConfigItem const &)=default
OutlinerParaObject * mpAnswer
Definition: PostItMgr.hxx:140
ImplSVEvent * mnEventId
Definition: PostItMgr.hxx:131
const_iterator end() const
Definition: PostItMgr.hxx:179
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:139
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
tools::Long lOffset
Definition: PostItMgr.hxx:66
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
VclPtr< SwEditWin > mpEditWin
Definition: PostItMgr.hxx:128
const SwPostItField * mpShadowField
Definition: PostItMgr.hxx:76
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
const sal_uInt32 LEFT
const PropertyValue * pValues
virtual void ImplCommit() override
Definition: PostItMgr.cxx:2502
#define SAL_WARN_IF(condition, area, stream)
bool IsShowAnchor() const
Definition: PostItMgr.hxx:191
void SetLayout()
Definition: PostItMgr.hxx:199
bool mbLayouting
Definition: PostItMgr.hxx:136
std::vector< std::unique_ptr< SwSidebarItem > >::const_iterator const_iterator
Definition: PostItMgr.hxx:177
bool mbIsShowAnchor
Definition: PostItMgr.hxx:142
OUString maAnswerText
Definition: PostItMgr.hxx:141
void RegisterAnswer(OutlinerParaObject *pAnswer)
Definition: PostItMgr.hxx:254
sw::annotation::SwAnnotationWin * GetActiveSidebarWin()
Definition: PostItMgr.hxx:233
std::vector< std::unique_ptr< SwPostItPageItem > > mPages
Definition: PostItMgr.hxx:130
tools::Long mbLayoutHeight
Definition: PostItMgr.hxx:135
bool mbReadOnly
Definition: PostItMgr.hxx:137
bool IsShowAnchor() const
Definition: PostItMgr.hxx:104
void RegisterAnswerText(const OUString &aAnswerText)
Definition: PostItMgr.hxx:256
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: PostItMgr.cxx:2503
const OUString & GetAnswerText() const
Definition: PostItMgr.hxx:257
std::vector< std::unique_ptr< SwSidebarItem > > mvPostItFields
Definition: PostItMgr.hxx:129
Definition: view.hxx:144
SwWrtShell * mpWrtShell
Definition: PostItMgr.hxx:127