1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include <rtl/ustring.hxx>
30 #include <sal/log.hxx>
31 #include <tools/link.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>
50 namespace sw
{ namespace annotation
{
51 class SwAnnotationWin
;
53 namespace sw
{ namespace sidebarwindows
{
54 class SwFrameSidebarWinContainer
;
58 namespace vcl
{ class Window
; }
60 class OutlinerParaObject
;
61 namespace i18nutil
{ struct SearchOptions2
; }
63 #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0)
64 #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153)
66 struct SwPostItPageItem
69 sw::sidebarwindows::SidebarPosition eSidebarPosition
;
72 std::vector
<SwSidebarItem
*> mvSidebarItems
;
73 SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT
), lOffset(0)
78 struct FieldShadowState
80 const SwPostItField
* mpShadowField
;
83 FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
88 class SwNoteProps final
: public utl::ConfigItem
93 virtual void ImplCommit() override
;
97 : ConfigItem("Office.Writer/Notes")
98 , m_bIsShowAnchor(false)
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
;
108 bool IsShowAnchor() const
110 return m_bIsShowAnchor
;
112 static css::uno::Sequence
< OUString
>& GetPropertyNames()
114 static css::uno::Sequence
< OUString
> aNames
;
115 if(!aNames
.hasElements())
118 OUString
* pNames
= aNames
.getArray();
119 pNames
[0] = "ShowAnkor";
124 virtual void Notify( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
127 class SAL_DLLPUBLIC_RTTI SwPostItMgr final
: public SfxListener
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
;
143 FieldShadowState mShadowState
;
144 OutlinerParaObject
* mpAnswer
;
145 OUString maAnswerText
;
148 // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
149 std::unique_ptr
<sw::sidebarwindows::SwFrameSidebarWinContainer
> mpFrameSidebarWinContainer
;
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
,
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
);
166 sal_Int32
GetInitialAnchorDistance() const;
167 sal_Int32
GetScrollSize() const;
168 sal_Int32
GetSpaceBetween() const;
169 void SetReadOnlyState();
170 DECL_LINK( CalcHdl
, void*, void);
172 sw::annotation::SwAnnotationWin
* GetSidebarWin(const SfxBroadcaster
* pBroadcaster
) const;
174 SwSidebarItem
* InsertItem( SfxBroadcaster
* pItem
, bool bCheckExistence
, bool bFocus
);
175 void RemoveItem( SfxBroadcaster
* pBroadcast
);
178 SwPostItMgr(SwView
* aDoc
);
179 virtual ~SwPostItMgr() override
;
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(); }
185 void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
187 void LayoutPostIts();
190 void MakeVisible( const sw::annotation::SwAnnotationWin
* pPostIt
);
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;
199 void PrepareView(bool bIgnoreCount
= false);
201 void CorrectPositions();
203 void SetLayout() { mbLayout
= true; };
204 void Delete(const OUString
& aAuthor
);
205 void Delete(sal_uInt32 nPostItId
);
207 void DeleteCommentThread(sal_uInt32 nPostItId
);
208 void ToggleResolved(sal_uInt32 nPostItId
);
209 void ToggleResolvedForThread(sal_uInt32 nPostItId
);
211 void ExecuteFormatAllDialog(SwView
& rView
);
212 void FormatAll(const SfxItemSet
&rNewAttr
);
214 void Hide( const OUString
& rAuthor
);
217 void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin
* topNote
);
218 void ShowHideResolvedNotes(bool visible
);
222 tools::Rectangle
GetBottomScrollRect(const unsigned long aPage
) const;
223 tools::Rectangle
GetTopScrollRect(const unsigned long aPage
) const;
225 bool IsHit(const Point
&aPointPixel
);
226 /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
227 vcl::Window
* IsHitSidebarWindow(const Point
& rPointLogic
);
228 Color
GetArrowColor(sal_uInt16 aDirection
,unsigned long aPage
) const;
230 sw::annotation::SwAnnotationWin
* GetAnnotationWin(const SwPostItField
* pField
) const;
231 sw::annotation::SwAnnotationWin
* GetAnnotationWin(const sal_uInt32 nPostItId
) const;
233 sw::annotation::SwAnnotationWin
* GetNextPostIt( sal_uInt16 aDirection
,
234 sw::annotation::SwAnnotationWin
* aPostIt
);
235 long GetNextBorder();
237 sw::annotation::SwAnnotationWin
* GetActiveSidebarWin() { return mpActivePostIt
; }
238 void SetActiveSidebarWin( sw::annotation::SwAnnotationWin
* p
);
239 SW_DLLPUBLIC
bool HasActiveSidebarWin() const;
240 bool HasActiveAnnotationWin() const;
241 void GrabFocusOnActiveSidebarWin();
242 SW_DLLPUBLIC
void UpdateDataOnActiveSidebarWin();
243 void DeleteActiveSidebarWin();
244 void HideActiveSidebarWin();
245 void ToggleInsModeOnActiveSidebarWin();
247 sal_Int32
GetMinimumSizeWithMeta() const;
248 sal_Int32
GetSidebarScrollerHeight() const;
250 void SetShadowState(const SwPostItField
* pField
,bool bCursor
= true);
252 void SetSpellChecking();
254 static Color
GetColorDark(std::size_t aAuthorIndex
);
255 static Color
GetColorLight(std::size_t aAuthorIndex
);
256 static Color
GetColorAnchor(std::size_t aAuthorIndex
);
258 void RegisterAnswer(OutlinerParaObject
* pAnswer
) { mpAnswer
= pAnswer
;}
259 OutlinerParaObject
* IsAnswer() {return mpAnswer
;}
260 void RegisterAnswerText(const OUString
& aAnswerText
) { maAnswerText
= aAnswerText
; }
261 const OUString
& GetAnswerText() const { return maAnswerText
; }
262 void CheckMetaText();
264 sal_uInt16
Replace(SvxSearchItem
const * pItem
);
265 sal_uInt16
SearchReplace(const SwFormatField
&pField
, const i18nutil::SearchOptions2
& rSearchOptions
,bool bSrchForward
);
266 sal_uInt16
FinishSearchReplace(const i18nutil::SearchOptions2
& rSearchOptions
,bool bSrchForward
);
268 void AssureStdModeAtShell();
270 void ConnectSidebarWinToFrame( const SwFrame
& rFrame
,
271 const SwFormatField
& rFormatField
,
272 sw::annotation::SwAnnotationWin
& rSidebarWin
);
273 void DisconnectSidebarWinFromFrame( const SwFrame
& rFrame
,
274 sw::annotation::SwAnnotationWin
& rSidebarWin
);
275 bool HasFrameConnectedSidebarWins( const SwFrame
& rFrame
);
276 vcl::Window
* GetSidebarWinForFrameByIndex( const SwFrame
& rFrame
,
277 const sal_Int32 nIndex
);
278 void GetAllSidebarWinForFrame( const SwFrame
& rFrame
,
279 std::vector
< vcl::Window
* >* pChildren
);
281 void DrawNotesForPage(OutputDevice
*pOutDev
, sal_uInt32 nPage
);
282 void PaintTile(OutputDevice
& rRenderContext
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */