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 <editeng/outlobj.hxx>
37 #include <svl/lstner.hxx>
38 #include <vcl/vclptr.hxx>
51 namespace sw::annotation
{ class SwAnnotationWin
; }
52 namespace sw::sidebarwindows
{ class SwFrameSidebarWinContainer
; }
55 namespace vcl
{ class Window
; }
57 class OutlinerParaObject
;
58 namespace i18nutil
{ struct SearchOptions2
; }
60 #define COL_NOTES_SIDEPANE_ARROW_ENABLED Color(0,0,0)
61 #define COL_NOTES_SIDEPANE_ARROW_DISABLED Color(172,168,153)
63 struct SwPostItPageItem
66 sw::sidebarwindows::SidebarPosition eSidebarPosition
;
69 std::vector
<SwSidebarItem
*> mvSidebarItems
;
70 SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT
), lOffset(0)
75 struct FieldShadowState
77 const SwPostItField
* mpShadowField
;
80 FieldShadowState(): mpShadowField(nullptr),bCursor(false),bMouse(false)
85 class SwNoteProps final
: public utl::ConfigItem
90 virtual void ImplCommit() override
;
94 : ConfigItem("Office.Writer/Notes")
95 , m_bIsShowAnchor(false)
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
;
105 bool IsShowAnchor() const
107 return m_bIsShowAnchor
;
109 static css::uno::Sequence
< OUString
>& GetPropertyNames()
111 static css::uno::Sequence
< OUString
> aNames
;
112 if(!aNames
.hasElements())
115 OUString
* pNames
= aNames
.getArray();
116 pNames
[0] = "ShowAnkor";
121 virtual void Notify( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
124 class SAL_DLLPUBLIC_RTTI SwPostItMgr final
: public SfxListener
128 SwWrtShell
* mpWrtShell
;
129 VclPtr
<SwEditWin
> mpEditWin
;
130 std::vector
<std::unique_ptr
<SwSidebarItem
>> mvPostItFields
;
131 std::vector
<std::unique_ptr
<SwPostItPageItem
>> mPages
;
132 ImplSVEvent
* mnEventId
;
133 bool mbWaitingForCalcRects
;
134 VclPtr
<sw::annotation::SwAnnotationWin
> mpActivePostIt
;
136 tools::Long mbLayoutHeight
;
140 FieldShadowState mShadowState
;
141 std::optional
<OutlinerParaObject
> mpAnswer
;
142 OUString maAnswerText
;
145 // data structure to collect the <SwAnnotationWin> instances for certain <SwFrame> instances.
146 std::unique_ptr
<sw::sidebarwindows::SwFrameSidebarWinContainer
> mpFrameSidebarWinContainer
;
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 // return true if a postit was found to have been removed
158 bool CheckForRemovedPostIts();
159 bool ArrowEnabled(sal_uInt16 aDirection
,tools::ULong aPage
) const;
160 bool BorderOverPageBorder(tools::ULong aPage
) const;
161 bool HasScrollbars() const;
162 void Focus(const SfxBroadcaster
& rBC
);
164 sal_Int32
GetInitialAnchorDistance() const;
165 sal_Int32
GetScrollSize() const;
166 sal_Int32
GetSpaceBetween() const;
167 void SetReadOnlyState();
168 DECL_DLLPRIVATE_LINK( CalcHdl
, void*, void);
170 sw::annotation::SwAnnotationWin
* GetSidebarWin(const SfxBroadcaster
* pBroadcaster
) const;
172 SwSidebarItem
* InsertItem( SfxBroadcaster
* pItem
, bool bCheckExistence
, bool bFocus
);
173 void RemoveItem( SfxBroadcaster
* pBroadcast
);
176 SwPostItMgr(SwView
* aDoc
);
177 virtual ~SwPostItMgr() override
;
179 typedef std::vector
< std::unique_ptr
<SwSidebarItem
> >::const_iterator const_iterator
;
180 const_iterator
begin() const { return mvPostItFields
.begin(); }
181 const_iterator
end() const { return mvPostItFields
.end(); }
183 void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
185 void LayoutPostIts();
188 void MakeVisible( const sw::annotation::SwAnnotationWin
* pPostIt
);
190 bool ShowScrollbar(const tools::ULong aPage
) const;
191 bool HasNotes() const ;
192 bool ShowNotes() const;
193 bool IsShowAnchor() const { return mbIsShowAnchor
;}
194 tools::ULong
GetSidebarWidth(bool bPx
= false) const;
195 tools::ULong
GetSidebarBorderWidth(bool bPx
= false) const;
197 void PrepareView(bool bIgnoreCount
= false);
199 void CorrectPositions();
201 void SetLayout() { mbLayout
= true; };
202 void Delete(const OUString
& aAuthor
);
203 void Delete(sal_uInt32 nPostItId
);
205 void DeleteCommentThread(sal_uInt32 nPostItId
);
206 void ToggleResolved(sal_uInt32 nPostItId
);
207 void ToggleResolvedForThread(sal_uInt32 nPostItId
);
209 void ExecuteFormatAllDialog(SwView
& rView
);
210 void FormatAll(const SfxItemSet
&rNewAttr
);
212 void Hide( std::u16string_view rAuthor
);
215 void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin
* topNote
);
216 void ShowHideResolvedNotes(bool visible
);
220 tools::Rectangle
GetBottomScrollRect(const tools::ULong aPage
) const;
221 tools::Rectangle
GetTopScrollRect(const tools::ULong aPage
) const;
223 bool IsHit(const Point
&aPointPixel
);
224 /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
225 vcl::Window
* IsHitSidebarWindow(const Point
& rPointLogic
);
226 Color
GetArrowColor(sal_uInt16 aDirection
, tools::ULong aPage
) const;
228 sw::annotation::SwAnnotationWin
* GetAnnotationWin(const SwPostItField
* pField
) const;
229 sw::annotation::SwAnnotationWin
* GetAnnotationWin(const sal_uInt32 nPostItId
) const;
231 sw::annotation::SwAnnotationWin
* GetNextPostIt( sal_uInt16 aDirection
,
232 sw::annotation::SwAnnotationWin
* aPostIt
);
233 SwPostItField
* GetLatestPostItField();
235 tools::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(const OutlinerParaObject
* pAnswer
) { if (pAnswer
) mpAnswer
=* pAnswer
; else mpAnswer
.reset(); }
259 OutlinerParaObject
* IsAnswer() { return mpAnswer
? &*mpAnswer
: nullptr; }
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: */