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