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