xref: /AOO41X/main/sw/inc/PostItMgr.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _POSTITMGR_HXX
29 #define _POSTITMGR_HXX
30 
31 #include <list>
32 #include <vector>
33 #include <editeng/outlobj.hxx>
34 #include <tools/string.hxx>
35 #include <tools/link.hxx>
36 #include <tools/debug.hxx>
37 #include <swrect.hxx>
38 #include <unotools/configitem.hxx>
39 #include <unotools/options.hxx>
40 #include <com/sun/star/util/SearchOptions.hpp>
41 #include <com/sun/star/uno/Any.hxx>
42 #include <SidebarWindowsTypes.hxx>
43 #include <svl/lstner.hxx>
44 
45 class SwWrtShell;
46 class SwDoc;
47 class SwView;
48 class SwPostItField;
49 class SwFmtFld;
50 class SwField;
51 class SfxBroadcaster;
52 class SfxHint;
53 class SwEditWin;
54 class Color;
55 class SvxSearchItem;
56 class SvxLanguageItem;
57 namespace sw { namespace annotation {
58     class SwAnnotationWin;
59 }}
60 namespace sw { namespace sidebarwindows {
61     class SwSidebarWin;
62     class SwFrmSidebarWinContainer;
63 }}
64 class SwSidebarItem;
65 class SwFrm;
66 class Window;
67 
68 #define SORT_POS	1
69 #define SORT_AUTHOR	2
70 #define SORT_DATE	3
71 
72 #define COL_NOTES_SIDEPANE_ARROW_ENABLED	RGB_COLORDATA(0,0,0)
73 #define COL_NOTES_SIDEPANE_ARROW_DISABLED	RGB_COLORDATA(172,168,153)
74 
75 typedef std::list<SwSidebarItem*> SwSidebarItem_list;
76 typedef std::list<SwSidebarItem*>::iterator SwSidebarItem_iterator;
77 
78 
79 struct SwPostItPageItem
80 {
81 	bool bScrollbar;
82     sw::sidebarwindows::SidebarPosition eSidebarPosition;
83 	long lOffset;
84 	SwRect mPageRect;
85     SwSidebarItem_list* mList;
86 	SwPostItPageItem(): bScrollbar(false),lOffset(0)
87 	{
88         mList = new SwSidebarItem_list;
89 	}
90 	~SwPostItPageItem()
91 	{
92 		mList->clear();
93 		delete mList;
94 	}
95 
96 };
97 
98 struct FieldShadowState
99 {
100 	const SwPostItField* mpShadowFld;
101 	bool bCursor;
102 	bool bMouse;
103 	FieldShadowState(): mpShadowFld(0),bCursor(false),bMouse(false)
104 	{
105 	}
106 };
107 
108 class SwNoteProps: public utl::ConfigItem
109 {
110 	private:
111         bool bIsShowAnchor;
112 	public:
113         SwNoteProps()
114             : ConfigItem(::rtl::OUString::createFromAscii("Office.Writer/Notes"))
115             , bIsShowAnchor(false)
116 		{
117             const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames = GetPropertyNames();
118                 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aValues = GetProperties(rNames);
119                 const ::com::sun::star::uno::Any* pValues = aValues.getConstArray();
120    			DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
121         		if (aValues.getLength())
122                 pValues[0]>>=bIsShowAnchor;
123 		}
124 
125         bool IsShowAnchor()
126 		{
127             return bIsShowAnchor;
128 		}
129             ::com::sun::star::uno::Sequence< ::rtl::OUString >& GetPropertyNames()
130         	{
131             static ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames;
132      			if(!aNames.getLength())
133      			{
134              			static const char* aPropNames[] =
135              			{
136                 			"ShowAnkor"
137                    		};
138              			const int nCount = sizeof(aPropNames)/sizeof(const char*);
139              			aNames.realloc(nCount);
140                         ::rtl::OUString* pNames = aNames.getArray();
141          			for(int i = 0; i < nCount; i++)
142                             pNames[i] = ::rtl::OUString::createFromAscii(aPropNames[i]);
143      			}
144      			return aNames;
145         	}
146 
147 	virtual void Commit();
148 	virtual void Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
149 };
150 
151 class SwPostItMgr: public SfxListener
152 {
153 	private:
154 		SwView*							mpView;
155 		SwWrtShell*						mpWrtShell;
156 		SwEditWin*						mpEditWin;
157         std::list< SwSidebarItem*>      mvPostItFlds;
158 		std::vector<SwPostItPageItem*>	mPages;
159 		sal_uLong							mnEventId;
160 		bool							mbWaitingForCalcRects;
161         sw::sidebarwindows::SwSidebarWin* mpActivePostIt;
162 		bool							mbLayout;
163 		long							mbLayoutHeight;
164 		long							mbLayouting;
165 		bool							mbReadOnly;
166 		bool							mbDeleteNote;
167 		FieldShadowState				mShadowState;
168 		OutlinerParaObject*				mpAnswer;
169         bool                            mbIsShowAnchor;
170 
171         // data structure to collect the <SwSidebarWin> instances for certain <SwFrm> instances.
172         sw::sidebarwindows::SwFrmSidebarWinContainer* mpFrmSidebarWinContainer;
173 
174         typedef std::list<sw::sidebarwindows::SwSidebarWin*>::iterator  SwSidebarWin_iterator;
175 
176 		void			AddPostIts(bool bCheckExistance = true,bool bFocus = true);
177 		//void			AddRedlineComments(bool bCheckExistance, bool bFocus);
178         void            RemoveSidebarWin();
179 		void			PreparePageContainer();
180 		void			Scroll(const long lScroll,const unsigned long aPage );
181         void            AutoScroll(const sw::sidebarwindows::SwSidebarWin* pPostIt,const unsigned long aPage );
182 		bool			ScrollbarHit(const unsigned long aPage,const Point &aPoint);
183         bool            LayoutByPage( std::list<sw::sidebarwindows::SwSidebarWin*> &aVisiblePostItList,
184                                       const Rectangle aBorder,
185                                       long lNeededHeight);
186 		void			CheckForRemovedPostIts();
187         	bool            	ArrowEnabled(sal_uInt16 aDirection,unsigned long aPage) const;
188         	bool            	BorderOverPageBorder(unsigned long aPage) const;
189         	bool 		       	HasScrollbars() const;
190 		void			Focus(SfxBroadcaster& rBC);
191 
192 	        sal_Int32       	GetInitialAnchorDistance() const;
193         	sal_Int32       	GetScrollSize() const;
194         	sal_Int32       	GetSpaceBetween() const;
195 		void			SetReadOnlyState();
196 					DECL_LINK( CalcHdl, void*);
197 
198         sw::sidebarwindows::SwSidebarWin* GetSidebarWin(const SfxBroadcaster* pBroadcaster) const;
199 
200         void InsertItem( SfxBroadcaster* pItem, bool bCheckExistance, bool bFocus);
201         void RemoveItem( SfxBroadcaster* pBroadcast );
202 
203         void Sort(const short aType);
204 
205 	public:
206 			SwPostItMgr(SwView* aDoc);
207 			~SwPostItMgr();
208 
209             typedef std::list< SwSidebarItem* >::const_iterator const_iterator;
210 			const_iterator begin()	const { return mvPostItFlds.begin(); }
211 			const_iterator end()	const { return mvPostItFlds.end();	}
212 
213 			void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
214 
215 			void LayoutPostIts();
216 			bool CalcRects();
217 
218             void MakeVisible( const sw::sidebarwindows::SwSidebarWin* pPostIt,
219                               long aPage = -1);
220 
221             bool ShowScrollbar(const unsigned long aPage) const;
222             bool HasNotes() const ;
223             bool ShowNotes() const;
224             bool IsShowAnchor() { return mbIsShowAnchor;}
225             unsigned long GetSidebarWidth(bool bPx = false) const;
226             unsigned long GetSidebarBorderWidth(bool bPx = false) const;
227 			unsigned long GetNoteWidth();
228 
229 			void PrepareView(bool bIgnoreCount = false);
230 
231 			void CorrectPositions();
232 
233 			void SetLayout() { mbLayout = true; };
234 			void Delete(String aAuthor);
235 			void Delete();
236 
237 #if 0
238             void Hide( SwPostItField* pPostItField );
239 #endif
240 			void Hide( const String& rAuthor );
241 			void Hide();
242 			void Show();
243 
244 			void Rescale();
245 
246             Rectangle GetBottomScrollRect(const unsigned long aPage) const;
247             Rectangle GetTopScrollRect(const unsigned long aPage) const;
248 
249             bool IsHit(const Point &aPointPixel);
250             Color GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const;
251 
252             sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pFld) const;
253 
254             sw::sidebarwindows::SwSidebarWin* GetNextPostIt( sal_uInt16 aDirection,
255                                                              sw::sidebarwindows::SwSidebarWin* aPostIt);
256 			long GetNextBorder();
257 
258             sw::sidebarwindows::SwSidebarWin* GetActiveSidebarWin() { return mpActivePostIt; }
259             void SetActiveSidebarWin( sw::sidebarwindows::SwSidebarWin* p);
260             bool HasActiveSidebarWin() const;
261             bool HasActiveAnnotationWin() const;
262             void GrabFocusOnActiveSidebarWin();
263             void UpdateDataOnActiveSidebarWin();
264             void DeleteActiveSidebarWin();
265             void HideActiveSidebarWin();
266             void ToggleInsModeOnActiveSidebarWin();
267 
268             sal_Int32 GetMinimumSizeWithMeta() const;
269             sal_Int32 GetSidebarScrollerHeight() const;
270 
271 			void SetShadowState(const SwPostItField* pFld,bool bCursor = true);
272 
273 			void SetSpellChecking();
274 
275 			Color			GetColorDark(sal_uInt16 aAuthorIndex);
276 			Color			GetColorLight(sal_uInt16 aAuthorIndex);
277             Color           GetColorAnchor(sal_uInt16 aAuthorIndex);
278 
279 
280 			void				RegisterAnswer(OutlinerParaObject* pAnswer) { mpAnswer = pAnswer;}
281 			OutlinerParaObject* IsAnswer() {return mpAnswer;}
282 			void CheckMetaText();
283 			void StartSpelling();
284 
285 			sal_uInt16 Replace(SvxSearchItem* pItem);
286 			sal_uInt16 SearchReplace(const SwFmtFld &pFld, const ::com::sun::star::util::SearchOptions& rSearchOptions,bool bSrchForward);
287 			sal_uInt16 FinishSearchReplace(const ::com::sun::star::util::SearchOptions& rSearchOptions,bool bSrchForward);
288 
289             void AssureStdModeAtShell();
290 
291             void ConnectSidebarWinToFrm( const SwFrm& rFrm,
292                                          const SwFmtFld& rFmtFld,
293                                          sw::sidebarwindows::SwSidebarWin& rSidebarWin );
294             void DisconnectSidebarWinFromFrm( const SwFrm& rFrm,
295                                               sw::sidebarwindows::SwSidebarWin& rSidebarWin );
296             bool HasFrmConnectedSidebarWins( const SwFrm& rFrm );
297             Window* GetSidebarWinForFrmByIndex( const SwFrm& rFrm,
298                                                 const sal_Int32 nIndex );
299             void GetAllSidebarWinForFrm( const SwFrm& rFrm,
300                                          std::vector< Window* >* pChildren );
301 };
302 
303 #endif
304 
305 
306 
307 
308