xref: /AOO41X/main/sw/source/ui/docvw/PostItMgr.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "PostItMgr.hxx"
28cdf0e10cSrcweir #include <postithelper.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <SidebarWin.hxx>
31cdf0e10cSrcweir #include <AnnotationWin.hxx>
32cdf0e10cSrcweir #include <frmsidebarwincontainer.hxx>
33cdf0e10cSrcweir #include <accmap.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <SidebarWindowsConsts.hxx>
36cdf0e10cSrcweir #include <AnchorOverlayObject.hxx>
37cdf0e10cSrcweir #include <ShadowOverlayObject.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <vcl/svapp.hxx>
40cdf0e10cSrcweir #include <vcl/scrbar.hxx>
41cdf0e10cSrcweir #include <vcl/outdev.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <viewopt.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <view.hxx>
46cdf0e10cSrcweir #include <docsh.hxx>
47cdf0e10cSrcweir #include <wrtsh.hxx>
48cdf0e10cSrcweir #include <doc.hxx>
49cdf0e10cSrcweir #include <fldbas.hxx>
50cdf0e10cSrcweir #include <fmtfld.hxx>
51cdf0e10cSrcweir #include <docufld.hxx>
52cdf0e10cSrcweir #include <edtwin.hxx>
53cdf0e10cSrcweir #include <txtfld.hxx>
54cdf0e10cSrcweir #include <ndtxt.hxx>
55cdf0e10cSrcweir #include <redline.hxx>
56cdf0e10cSrcweir #include <docary.hxx>
57cdf0e10cSrcweir #include <SwRewriter.hxx>
58cdf0e10cSrcweir #include <tools/color.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include <swmodule.hxx>
61cdf0e10cSrcweir #include <annotation.hrc>
62cdf0e10cSrcweir #include "cmdid.h"
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <sfx2/request.hxx>
65cdf0e10cSrcweir #include <sfx2/event.hxx>
66cdf0e10cSrcweir #include <svl/srchitem.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir #include <svl/languageoptions.hxx>
70cdf0e10cSrcweir #include <svtools/langtab.hxx>
71cdf0e10cSrcweir #include <svl/smplhint.hxx>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include <svx/svdview.hxx>
74cdf0e10cSrcweir #include <editeng/eeitem.hxx>
75cdf0e10cSrcweir #include <editeng/langitem.hxx>
76cdf0e10cSrcweir #include <editeng/outliner.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
79cdf0e10cSrcweir #include <i18npool/lang.h>
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #include "swevent.hxx"
82cdf0e10cSrcweir #include "switerator.hxx"
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // distance between Anchor Y and initial note position
85cdf0e10cSrcweir #define POSTIT_INITIAL_ANCHOR_DISTANCE      20
86cdf0e10cSrcweir //distance between two postits
87cdf0e10cSrcweir #define POSTIT_SPACE_BETWEEN				8
88cdf0e10cSrcweir #define POSTIT_MINIMUMSIZE_WITH_META		60
89cdf0e10cSrcweir #define POSTIT_SCROLL_SIDEBAR_HEIGHT		20
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // if we layout more often we stop, this should never happen
92cdf0e10cSrcweir #define MAX_LOOP_COUNT						50
93cdf0e10cSrcweir 
94cdf0e10cSrcweir using namespace sw::sidebarwindows;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir /*
97cdf0e10cSrcweir bool comp_author( const SwPostItItem* a, const SwPostItItem* b)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	return a->pFmtFld->GetFld()->GetPar1() < b->pFmtFld->GetFld()->GetPar1();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir bool comp_date( const SwPostItItem* a, const SwPostItItem* b)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	return static_cast<SwPostItField*>(a->pFmtFld->GetFld())->GetDate()  < static_cast<SwPostItField*>(b->pFmtFld->GetFld())->GetDate();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir */
107cdf0e10cSrcweir 
108cdf0e10cSrcweir //
109cdf0e10cSrcweir bool comp_pos(const SwSidebarItem* a, const SwSidebarItem* b)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     // --> OD 2010-01-19 #i88070#
112cdf0e10cSrcweir     // sort by anchor position
113cdf0e10cSrcweir //// if position is on the same line, sort by x (Left) position, otherwise by y(Bottom) position
114cdf0e10cSrcweir //// if two notes are at the same position, sort by logical node position
115cdf0e10cSrcweir //    return (a->maLayoutInfo.mPosition.Bottom() == b->maLayoutInfo.mPosition.Bottom())
116cdf0e10cSrcweir //            ? ( ( (a->maLayoutInfo.mPosition.Left() == b->maLayoutInfo.mPosition.Left()) &&
117cdf0e10cSrcweir //                  (a->GetBroadCaster()->ISA(SwFmtFld) && b->GetBroadCaster()->ISA(SwFmtFld)) )
118cdf0e10cSrcweir //                ? *(static_cast<SwFmtFld*>(a->GetBroadCaster())->GetTxtFld()->GetStart()) <
119cdf0e10cSrcweir //                    *(static_cast<SwFmtFld*>(b->GetBroadCaster())->GetTxtFld()->GetStart())
120cdf0e10cSrcweir //                : a->maLayoutInfo.mPosition.Left() < b->maLayoutInfo.mPosition.Left() )
121cdf0e10cSrcweir //            : a->maLayoutInfo.mPosition.Bottom() < b->maLayoutInfo.mPosition.Bottom();
122cdf0e10cSrcweir     return a->GetAnchorPosition() < b->GetAnchorPosition();
123cdf0e10cSrcweir     // <--
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir SwPostItMgr::SwPostItMgr(SwView* pView)
127cdf0e10cSrcweir 	: mpView(pView)
128cdf0e10cSrcweir 	, mpWrtShell(mpView->GetDocShell()->GetWrtShell())
129cdf0e10cSrcweir 	, mpEditWin(&mpView->GetEditWin())
130cdf0e10cSrcweir 	, mnEventId(0)
131cdf0e10cSrcweir 	, mbWaitingForCalcRects(false)
132cdf0e10cSrcweir 	, mpActivePostIt(0)
133cdf0e10cSrcweir 	, mbLayout(false)
134cdf0e10cSrcweir 	, mbLayoutHeight(0)
135cdf0e10cSrcweir 	, mbLayouting(false)
136cdf0e10cSrcweir 	, mbReadOnly(mpView->GetDocShell()->IsReadOnly())
137cdf0e10cSrcweir 	, mbDeleteNote(true)
138cdf0e10cSrcweir 	, mpAnswer(0)
139cdf0e10cSrcweir     , mbIsShowAnchor( false )
140cdf0e10cSrcweir     , mpFrmSidebarWinContainer( 0 )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	if(!mpView->GetDrawView() )
143cdf0e10cSrcweir 		mpView->GetWrtShell().MakeDrawView();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	SwNoteProps aProps;
146cdf0e10cSrcweir     mbIsShowAnchor = aProps.IsShowAnchor();
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	//make sure we get the colour yellow always, even if not the first one of comments or redlining
149cdf0e10cSrcweir 	SW_MOD()->GetRedlineAuthor();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	// collect all PostIts and redline comments that exist after loading the document
152cdf0e10cSrcweir 	// don't check for existance for any of them, don't focus them
153cdf0e10cSrcweir 	AddPostIts(false,false);
154cdf0e10cSrcweir     /*  this code can be used once we want redline comments in the Sidebar
155cdf0e10cSrcweir 	AddRedlineComments(false,false);
156cdf0e10cSrcweir 	*/
157cdf0e10cSrcweir 	// we want to receive stuff like SFX_HINT_DOCCHANGED
158cdf0e10cSrcweir 	StartListening(*mpView->GetDocShell());
159cdf0e10cSrcweir 	if (!mvPostItFlds.empty())
160cdf0e10cSrcweir 	{
161cdf0e10cSrcweir 		mbWaitingForCalcRects = true;
162cdf0e10cSrcweir 		mnEventId = Application::PostUserEvent( LINK( this, SwPostItMgr, CalcHdl), 0 );
163cdf0e10cSrcweir 	}
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir SwPostItMgr::~SwPostItMgr()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	if ( mnEventId )
169cdf0e10cSrcweir 		Application::RemoveUserEvent( mnEventId );
170cdf0e10cSrcweir     // forget about all our Sidebar windows
171cdf0e10cSrcweir     RemoveSidebarWin();
172cdf0e10cSrcweir 	EndListening( *mpView->GetDocShell() );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	for(std::vector<SwPostItPageItem*>::iterator i = mPages.begin(); i!= mPages.end() ; i++)
175cdf0e10cSrcweir 		delete (*i);
176cdf0e10cSrcweir 	mPages.clear();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     delete mpFrmSidebarWinContainer;
179cdf0e10cSrcweir     mpFrmSidebarWinContainer = 0;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir void SwPostItMgr::CheckForRemovedPostIts()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	bool bRemoved = false;
185cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end(); )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir         std::list<SwSidebarItem*>::iterator it = i++;
188cdf0e10cSrcweir 		if ( !(*it)->UseElement() )
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir             SwSidebarItem* p = (*it);
191cdf0e10cSrcweir 			mvPostItFlds.remove(*it);
192cdf0e10cSrcweir             if (GetActiveSidebarWin() == p->pPostIt)
193cdf0e10cSrcweir                 SetActiveSidebarWin(0);
194cdf0e10cSrcweir 			if (p->pPostIt)
195cdf0e10cSrcweir 				delete p->pPostIt;
196cdf0e10cSrcweir 			delete p;
197cdf0e10cSrcweir 			bRemoved = true;
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	if ( bRemoved )
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		// make sure that no deleted items remain in page lists
204cdf0e10cSrcweir 		// todo: only remove deleted ones?!
205cdf0e10cSrcweir 		if ( mvPostItFlds.empty() )
206cdf0e10cSrcweir 		{
207cdf0e10cSrcweir 			PreparePageContainer();
208cdf0e10cSrcweir 			PrepareView();
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 		else
211cdf0e10cSrcweir 			// if postits are their make sure that page lists are not empty
212cdf0e10cSrcweir 			// otherwise sudden paints can cause pain (in BorderOverPageBorder)
213cdf0e10cSrcweir 			CalcRects();
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir void SwPostItMgr::InsertItem(SfxBroadcaster* pItem, bool bCheckExistance, bool bFocus)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	if (bCheckExistance)
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir         for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
222cdf0e10cSrcweir 		{
223cdf0e10cSrcweir 			if ( (*i)->GetBroadCaster() == pItem )
224cdf0e10cSrcweir 				return;
225cdf0e10cSrcweir 		}
226cdf0e10cSrcweir 	}
227cdf0e10cSrcweir 	mbLayout = bFocus;
228cdf0e10cSrcweir 	if (pItem->ISA(SwFmtFld))
229cdf0e10cSrcweir         mvPostItFlds.push_back(new SwAnnotationItem(static_cast<SwFmtFld*>(pItem), true, bFocus) );
230cdf0e10cSrcweir 	/*
231cdf0e10cSrcweir 	else
232cdf0e10cSrcweir 	if (pItem->ISA(SwRedline))
233cdf0e10cSrcweir 		mvPostItFlds.push_back(new SwRedCommentItem( static_cast<SwRedline*>(pItem), true, bFocus)) ;
234cdf0e10cSrcweir 	*/
235cdf0e10cSrcweir 	DBG_ASSERT(pItem->ISA(SwFmtFld) /*|| pItem->ISA(SwRedline)*/,"Mgr::InsertItem: seems like new stuff was added");
236cdf0e10cSrcweir 	StartListening(*pItem);
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir void SwPostItMgr::RemoveItem( SfxBroadcaster* pBroadcast )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	EndListening(*pBroadcast);
242cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir 		if ( (*i)->GetBroadCaster() == pBroadcast )
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir             SwSidebarItem* p = (*i);
247cdf0e10cSrcweir             if (GetActiveSidebarWin() == p->pPostIt)
248cdf0e10cSrcweir                 SetActiveSidebarWin(0);
249cdf0e10cSrcweir 			mvPostItFlds.remove(*i);
250cdf0e10cSrcweir 			delete p->pPostIt;
251cdf0e10cSrcweir 			delete p;
252cdf0e10cSrcweir 			break;
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir 	mbLayout = true;
256cdf0e10cSrcweir 	PrepareView();
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir void SwPostItMgr::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir 	if ( rHint.IsA(TYPE(SfxEventHint) ) )
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		sal_uInt32 nId = ((SfxEventHint&)rHint).GetEventId();
264cdf0e10cSrcweir 		if ( nId == SW_EVENT_LAYOUT_FINISHED )
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			if ( !mbWaitingForCalcRects && !mvPostItFlds.empty())
267cdf0e10cSrcweir 			{
268cdf0e10cSrcweir 				mbWaitingForCalcRects = true;
269cdf0e10cSrcweir 				mnEventId = Application::PostUserEvent( LINK( this, SwPostItMgr, CalcHdl), 0 );
270cdf0e10cSrcweir 			}
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 	else if ( rHint.IsA(TYPE(SfxSimpleHint)	) )
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		sal_uInt32 nId = ((SfxSimpleHint&)rHint).GetId();
276cdf0e10cSrcweir 		switch ( nId )
277cdf0e10cSrcweir 		{
278cdf0e10cSrcweir 			case SFX_HINT_MODECHANGED:
279cdf0e10cSrcweir 			{
280cdf0e10cSrcweir 				if ( mbReadOnly != !!(mpView->GetDocShell()->IsReadOnly()) )
281cdf0e10cSrcweir 				{
282cdf0e10cSrcweir 					mbReadOnly = !mbReadOnly;
283cdf0e10cSrcweir 					SetReadOnlyState();
284cdf0e10cSrcweir 					mbLayout = true;
285cdf0e10cSrcweir 				}
286cdf0e10cSrcweir 				break;
287cdf0e10cSrcweir 			}
288cdf0e10cSrcweir 			case SFX_HINT_DOCCHANGED:
289cdf0e10cSrcweir 			{
290cdf0e10cSrcweir 				if ( mpView->GetDocShell() == &rBC )
291cdf0e10cSrcweir 				{
292cdf0e10cSrcweir 					if ( !mbWaitingForCalcRects && !mvPostItFlds.empty())
293cdf0e10cSrcweir 					{
294cdf0e10cSrcweir 						mbWaitingForCalcRects = true;
295cdf0e10cSrcweir 						mnEventId = Application::PostUserEvent( LINK( this, SwPostItMgr, CalcHdl), 0 );
296cdf0e10cSrcweir 					}
297cdf0e10cSrcweir 				}
298cdf0e10cSrcweir 				break;
299cdf0e10cSrcweir 			}
300cdf0e10cSrcweir 			case SFX_HINT_USER04:
301cdf0e10cSrcweir 			{
302cdf0e10cSrcweir 				// if we are in a SplitNode/Cut operation, do not delete note and then add again, as this will flicker
303cdf0e10cSrcweir 				mbDeleteNote = !mbDeleteNote;
304cdf0e10cSrcweir 				break;
305cdf0e10cSrcweir 			}
306cdf0e10cSrcweir 			case SFX_HINT_DYING:
307cdf0e10cSrcweir 			{
308cdf0e10cSrcweir 				if ( mpView->GetDocShell() != &rBC )
309cdf0e10cSrcweir 				{
310cdf0e10cSrcweir 					// field to be removed is the broadcaster
311cdf0e10cSrcweir 					DBG_ERROR("Notification for removed SwFmtFld was not sent!");
312cdf0e10cSrcweir 					RemoveItem(&rBC);
313cdf0e10cSrcweir 				}
314cdf0e10cSrcweir 				break;
315cdf0e10cSrcweir 			}
316cdf0e10cSrcweir 		}
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 	/*
319cdf0e10cSrcweir 	else if ( rHint.IsA(TYPE(SwRedlineHint) ) )
320cdf0e10cSrcweir 	{
321cdf0e10cSrcweir 		const SwRedlineHint rRedlineHint = static_cast<const SwRedlineHint&>(rHint);
322cdf0e10cSrcweir 	   	SwRedline* pRedline = const_cast<SwRedline*>(rRedlineHint.GetRedline());
323cdf0e10cSrcweir 		switch ( rRedlineHint.Which() )
324cdf0e10cSrcweir 		{
325cdf0e10cSrcweir 			case SWREDLINE_INSERTED :
326cdf0e10cSrcweir 			{
327cdf0e10cSrcweir 				bool bEmpty = !HasNotes();
328cdf0e10cSrcweir 				InsertItem( pRedline, true, false );
329cdf0e10cSrcweir 				if (bEmpty && !mvPostItFlds.empty())
330cdf0e10cSrcweir 					PrepareView(true);
331cdf0e10cSrcweir 				break;
332cdf0e10cSrcweir 			}
333cdf0e10cSrcweir 			case SWREDLINE_REMOVED:
334cdf0e10cSrcweir 			{
335cdf0e10cSrcweir 				RemoveItem(pRedline);
336cdf0e10cSrcweir 				break;
337cdf0e10cSrcweir 			}
338cdf0e10cSrcweir 			case SWREDLINE_FOCUS:
339cdf0e10cSrcweir 			{
340cdf0e10cSrcweir                                 if (rRedlineHint.GetView()== mpView)
341cdf0e10cSrcweir 					Focus(rBC);
342cdf0e10cSrcweir 				break;
343cdf0e10cSrcweir 			}
344cdf0e10cSrcweir 		}
345cdf0e10cSrcweir 	}
346cdf0e10cSrcweir 	*/
347cdf0e10cSrcweir 	else if ( rHint.IsA(TYPE(SwFmtFldHint) ) )
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		const SwFmtFldHint& rFmtHint = static_cast<const SwFmtFldHint&>(rHint);
350cdf0e10cSrcweir 		SwFmtFld* pFld = const_cast <SwFmtFld*>( rFmtHint.GetField() );
351cdf0e10cSrcweir 		switch ( rFmtHint.Which() )
352cdf0e10cSrcweir 		{
353cdf0e10cSrcweir 			case SWFMTFLD_INSERTED :
354cdf0e10cSrcweir 			{
355cdf0e10cSrcweir 				if (!pFld)
356cdf0e10cSrcweir 				{
357cdf0e10cSrcweir 					AddPostIts(true);
358cdf0e10cSrcweir 					break;
359cdf0e10cSrcweir 				}
360cdf0e10cSrcweir 				// get field to be inserted from hint
361cdf0e10cSrcweir 				if ( pFld->IsFldInDoc() )
362cdf0e10cSrcweir 				{
363cdf0e10cSrcweir 					bool bEmpty = !HasNotes();
364cdf0e10cSrcweir 					InsertItem( pFld, true, false );
365cdf0e10cSrcweir 					if (bEmpty && !mvPostItFlds.empty())
366cdf0e10cSrcweir 						PrepareView(true);
367cdf0e10cSrcweir 				}
368cdf0e10cSrcweir 				else
369cdf0e10cSrcweir 				{
370cdf0e10cSrcweir 					DBG_ERROR( "Inserted field not in document!" );
371cdf0e10cSrcweir                 		}
372cdf0e10cSrcweir 				break;
373cdf0e10cSrcweir 			}
374cdf0e10cSrcweir 			case SWFMTFLD_REMOVED:
375cdf0e10cSrcweir 			{
376cdf0e10cSrcweir 				if (mbDeleteNote)
377cdf0e10cSrcweir 				{
378cdf0e10cSrcweir 					if (!pFld)
379cdf0e10cSrcweir 					{
380cdf0e10cSrcweir 						CheckForRemovedPostIts();
381cdf0e10cSrcweir 						break;
382cdf0e10cSrcweir 					}
383cdf0e10cSrcweir 					RemoveItem(pFld);
384cdf0e10cSrcweir 				}
385cdf0e10cSrcweir 				break;
386cdf0e10cSrcweir 			}
387cdf0e10cSrcweir 			case SWFMTFLD_FOCUS:
388cdf0e10cSrcweir 			{
389cdf0e10cSrcweir        				if (rFmtHint.GetView()== mpView)
390cdf0e10cSrcweir 					Focus(rBC);
391cdf0e10cSrcweir 				break;
392cdf0e10cSrcweir 			}
393cdf0e10cSrcweir 			case SWFMTFLD_CHANGED:
394cdf0e10cSrcweir 			{
395cdf0e10cSrcweir 		                SwFmtFld* pFmtFld = dynamic_cast<SwFmtFld*>(&rBC);
396cdf0e10cSrcweir                 for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
397cdf0e10cSrcweir 				{
398cdf0e10cSrcweir                 			if ( pFmtFld == (*i)->GetBroadCaster() )
399cdf0e10cSrcweir 					{
400cdf0e10cSrcweir 						if ((*i)->pPostIt)
401cdf0e10cSrcweir 						{
402cdf0e10cSrcweir 							(*i)->pPostIt->SetPostItText();
403cdf0e10cSrcweir 							mbLayout = true;
404cdf0e10cSrcweir 						}
405cdf0e10cSrcweir 						break;
406cdf0e10cSrcweir 					}
407cdf0e10cSrcweir 				}
408cdf0e10cSrcweir 				break;
409cdf0e10cSrcweir 			}
410cdf0e10cSrcweir 			case SWFMTFLD_LANGUAGE:
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir                 		SwFmtFld* pFmtFld = dynamic_cast<SwFmtFld*>(&rBC);
413cdf0e10cSrcweir                 for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
414cdf0e10cSrcweir 				{
415cdf0e10cSrcweir                     			if ( pFmtFld == (*i)->GetBroadCaster() )
416cdf0e10cSrcweir 					{
417cdf0e10cSrcweir 						if ((*i)->pPostIt)
418cdf0e10cSrcweir 						{
419cdf0e10cSrcweir 							sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( (*i)->GetFmtFld()->GetFld()->GetLanguage() );
420cdf0e10cSrcweir 							sal_uInt16 nLangWhichId = 0;
421cdf0e10cSrcweir 							switch (nScriptType)
422cdf0e10cSrcweir 							{
423cdf0e10cSrcweir 								case SCRIPTTYPE_LATIN :    nLangWhichId = EE_CHAR_LANGUAGE ; break;
424cdf0e10cSrcweir 								case SCRIPTTYPE_ASIAN :    nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
425cdf0e10cSrcweir 								case SCRIPTTYPE_COMPLEX :  nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
426cdf0e10cSrcweir 							}
427cdf0e10cSrcweir                             (*i)->pPostIt->SetLanguage( SvxLanguageItem((*i)->GetFmtFld()->GetFld()->GetLanguage(),
428cdf0e10cSrcweir                                                         nLangWhichId) );
429cdf0e10cSrcweir 						}
430cdf0e10cSrcweir 						break;
431cdf0e10cSrcweir 					}
432cdf0e10cSrcweir 				}
433cdf0e10cSrcweir 				break;
434cdf0e10cSrcweir 			}
435cdf0e10cSrcweir 		}
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir void SwPostItMgr::Focus(SfxBroadcaster& rBC)
440cdf0e10cSrcweir {
441cdf0e10cSrcweir 	if (!mpWrtShell->GetViewOptions()->IsPostIts())
442cdf0e10cSrcweir 	{
443cdf0e10cSrcweir 		SfxRequest aRequest(mpView->GetViewFrame(),FN_VIEW_NOTES);
444cdf0e10cSrcweir 		mpView->ExecViewOptions(aRequest);
445cdf0e10cSrcweir 	}
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
448cdf0e10cSrcweir 	{
449cdf0e10cSrcweir 		// field to get the focus is the broadcaster
450cdf0e10cSrcweir 		if ( &rBC == (*i)->GetBroadCaster() )
451cdf0e10cSrcweir 		{
452cdf0e10cSrcweir 			if ((*i)->pPostIt)
453cdf0e10cSrcweir 			{
454cdf0e10cSrcweir 				(*i)->pPostIt->GrabFocus();
455cdf0e10cSrcweir 				MakeVisible((*i)->pPostIt);
456cdf0e10cSrcweir 			}
457cdf0e10cSrcweir 			else
458cdf0e10cSrcweir 			{
459cdf0e10cSrcweir 				// when the layout algorithm starts, this postit is created and receives focus
460cdf0e10cSrcweir 				(*i)->bFocus = true;
461cdf0e10cSrcweir 			}
462cdf0e10cSrcweir 		}
463cdf0e10cSrcweir 	}
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir bool SwPostItMgr::CalcRects()
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	if ( mnEventId )
469cdf0e10cSrcweir 	{
470cdf0e10cSrcweir 		// if CalcRects() was forced and an event is still pending: remove it
471cdf0e10cSrcweir 		// it is superfluous and also may cause reentrance problems if triggered while layouting
472cdf0e10cSrcweir 		Application::RemoveUserEvent( mnEventId );
473cdf0e10cSrcweir 		mnEventId = 0;
474cdf0e10cSrcweir 	}
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	bool bChange = false;
477cdf0e10cSrcweir 	bool bRepair = false;
478cdf0e10cSrcweir 	PreparePageContainer();
479cdf0e10cSrcweir 	if ( !mvPostItFlds.empty() )
480cdf0e10cSrcweir 	{
481cdf0e10cSrcweir         for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
482cdf0e10cSrcweir 		{
483cdf0e10cSrcweir             SwSidebarItem* pItem = (*i);
484cdf0e10cSrcweir 			if ( !pItem->UseElement() )
485cdf0e10cSrcweir 			{
486cdf0e10cSrcweir 				DBG_ERROR("PostIt is not in doc or other wrong use");
487cdf0e10cSrcweir 				bRepair = true;
488cdf0e10cSrcweir 				continue;
489cdf0e10cSrcweir 			}
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 			//save old rect and visible state
492cdf0e10cSrcweir             SwRect aOldRect(pItem->maLayoutInfo.mPosition);
493cdf0e10cSrcweir 			SwPostItHelper::SwLayoutStatus eOldStatus = pItem->mLayoutStatus;
494cdf0e10cSrcweir 			std::vector< SwLayoutInfo > aInfo;
495cdf0e10cSrcweir             {
496cdf0e10cSrcweir                 SwPosition aPosition = pItem->GetAnchorPosition();
497cdf0e10cSrcweir                 pItem->mLayoutStatus = SwPostItHelper::getLayoutInfos( aInfo, aPosition );
498cdf0e10cSrcweir             }
499cdf0e10cSrcweir             if( aInfo.size() )
500cdf0e10cSrcweir 			{
501cdf0e10cSrcweir                 pItem->maLayoutInfo = aInfo[0];
502cdf0e10cSrcweir             }
503cdf0e10cSrcweir             bChange = bChange ||
504cdf0e10cSrcweir                       ( pItem->maLayoutInfo.mPosition != aOldRect ) ||
505cdf0e10cSrcweir                       ( eOldStatus != pItem->mLayoutStatus );
506cdf0e10cSrcweir 		}
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 		// show notes in right order in navigator
509cdf0e10cSrcweir         //prevent Anchors during layout to overlap, e.g. when moving a frame
510cdf0e10cSrcweir 		Sort(SORT_POS);
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 		// sort the items into the right page vector, so layout can be done by page
513cdf0e10cSrcweir         for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
514cdf0e10cSrcweir 		{
515cdf0e10cSrcweir             SwSidebarItem* pItem = (*i);
516cdf0e10cSrcweir 			if( SwPostItHelper::INVISIBLE == pItem->mLayoutStatus )
517cdf0e10cSrcweir 			{
518cdf0e10cSrcweir 				if (pItem->pPostIt)
519cdf0e10cSrcweir 					pItem->pPostIt->HideNote();
520cdf0e10cSrcweir 				continue;
521cdf0e10cSrcweir 			}
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 			if( SwPostItHelper::HIDDEN == pItem->mLayoutStatus )
524cdf0e10cSrcweir 			{
525cdf0e10cSrcweir 				if (!mpWrtShell->GetViewOptions()->IsShowHiddenChar())
526cdf0e10cSrcweir 				{
527cdf0e10cSrcweir 					if (pItem->pPostIt)
528cdf0e10cSrcweir 						pItem->pPostIt->HideNote();
529cdf0e10cSrcweir 					continue;
530cdf0e10cSrcweir 				}
531cdf0e10cSrcweir 			}
532cdf0e10cSrcweir 
533cdf0e10cSrcweir             const unsigned long aPageNum = pItem->maLayoutInfo.mnPageNumber;
534cdf0e10cSrcweir 			if (aPageNum > mPages.size())
535cdf0e10cSrcweir 			{
536cdf0e10cSrcweir                 const unsigned long nNumberOfPages = mPages.size();
537cdf0e10cSrcweir 				for (unsigned int j=0; j<aPageNum - nNumberOfPages; ++j)
538cdf0e10cSrcweir 					mPages.push_back( new SwPostItPageItem());
539cdf0e10cSrcweir 			}
540cdf0e10cSrcweir 			mPages[aPageNum-1]->mList->push_back(pItem);
541cdf0e10cSrcweir             mPages[aPageNum-1]->mPageRect = pItem->maLayoutInfo.mPageFrame;
542cdf0e10cSrcweir             mPages[aPageNum-1]->eSidebarPosition = pItem->maLayoutInfo.meSidebarPosition;
543cdf0e10cSrcweir 		}
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 		if (!bChange && mpWrtShell->getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE))
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir             long nLayoutHeight = SwPostItHelper::getLayoutHeight( mpWrtShell->GetLayout() );
548cdf0e10cSrcweir 			if( nLayoutHeight > mbLayoutHeight )
549cdf0e10cSrcweir 			{
550cdf0e10cSrcweir 				if (mPages[0]->bScrollbar || HasScrollbars())
551cdf0e10cSrcweir 					bChange = true;
552cdf0e10cSrcweir 			}
553cdf0e10cSrcweir             else if( nLayoutHeight < mbLayoutHeight )
554cdf0e10cSrcweir 			{
555cdf0e10cSrcweir 				if (mPages[0]->bScrollbar || !BorderOverPageBorder(1))
556cdf0e10cSrcweir 					bChange = true;
557cdf0e10cSrcweir 			}
558cdf0e10cSrcweir 		}
559cdf0e10cSrcweir 	}
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	if ( bRepair )
562cdf0e10cSrcweir 		CheckForRemovedPostIts();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	mbLayoutHeight = SwPostItHelper::getLayoutHeight( mpWrtShell->GetLayout() );
565cdf0e10cSrcweir 	mbWaitingForCalcRects = false;
566cdf0e10cSrcweir 	return bChange;
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
569cdf0e10cSrcweir bool SwPostItMgr::HasScrollbars() const
570cdf0e10cSrcweir {
571cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::const_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir         if ((*i)->bShow && (*i)->pPostIt && (*i)->pPostIt->HasScrollbar())
574cdf0e10cSrcweir 			return true;
575cdf0e10cSrcweir 	}
576cdf0e10cSrcweir 	return false;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir void SwPostItMgr::PreparePageContainer()
580cdf0e10cSrcweir {
581cdf0e10cSrcweir 	// we do not just delete the SwPostItPageItem, so offset/scrollbar is not lost
582cdf0e10cSrcweir 	long lPageSize = mpWrtShell->GetNumPages();
583cdf0e10cSrcweir 	long lContainerSize = mPages.size();
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	if (lContainerSize < lPageSize)
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir 		for (int i=0; i<lPageSize - lContainerSize;i++)
588cdf0e10cSrcweir 			mPages.push_back( new SwPostItPageItem());
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir 	else
591cdf0e10cSrcweir 	if (lContainerSize > lPageSize)
592cdf0e10cSrcweir 	{
593cdf0e10cSrcweir 		for (int i=mPages.size()-1; i >= lPageSize;--i)
594cdf0e10cSrcweir 		{
595cdf0e10cSrcweir 			delete mPages[i];
596cdf0e10cSrcweir 			mPages.pop_back();
597cdf0e10cSrcweir 		}
598cdf0e10cSrcweir 	}
599cdf0e10cSrcweir 	// only clear the list, DO NOT delete the objects itself
600cdf0e10cSrcweir 	for(std::vector<SwPostItPageItem*>::iterator i = mPages.begin(); i!= mPages.end() ; i++)
601cdf0e10cSrcweir 	{
602cdf0e10cSrcweir 		(*i)->mList->clear();
603cdf0e10cSrcweir 		if (mvPostItFlds.empty())
604cdf0e10cSrcweir 			(*i)->bScrollbar = false;
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 	}
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir void SwPostItMgr::LayoutPostIts()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	if ( !mvPostItFlds.empty() && !mbWaitingForCalcRects )
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir 		mbLayouting = true;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 			//loop over all pages and do the layout
616cdf0e10cSrcweir 			// - create SwPostIt if neccessary
617cdf0e10cSrcweir 			// - place SwPostIts on their initial position
618cdf0e10cSrcweir 			// - calculate neccessary height for all PostIts together
619cdf0e10cSrcweir 			bool bUpdate = false;
620cdf0e10cSrcweir 			for (unsigned long n=0;n<mPages.size();n++)
621cdf0e10cSrcweir 			{
622cdf0e10cSrcweir 				// only layout if there are notes on this page
623cdf0e10cSrcweir 				if (mPages[n]->mList->size()>0)
624cdf0e10cSrcweir 				{
625cdf0e10cSrcweir                     std::list<SwSidebarWin*>    aVisiblePostItList;
626cdf0e10cSrcweir 					unsigned long			lNeededHeight = 0;
627cdf0e10cSrcweir 					long					mlPageBorder = 0;
628cdf0e10cSrcweir 					long					mlPageEnd = 0;
629cdf0e10cSrcweir 
630cdf0e10cSrcweir                     for(SwSidebarItem_iterator i = mPages[n]->mList->begin(); i!= mPages[n]->mList->end(); i++)
631cdf0e10cSrcweir 					{
632cdf0e10cSrcweir                         SwSidebarItem* pItem = (*i);
633cdf0e10cSrcweir                         SwSidebarWin* pPostIt = pItem->pPostIt;
634cdf0e10cSrcweir 
635cdf0e10cSrcweir                         if (mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT )
636cdf0e10cSrcweir 						{
637cdf0e10cSrcweir 							// x value for notes positioning
638cdf0e10cSrcweir 							mlPageBorder = mpEditWin->LogicToPixel( Point( mPages[n]->mPageRect.Left(), 0)).X() - GetSidebarWidth(true);// - GetSidebarBorderWidth(true);
639cdf0e10cSrcweir 							//bending point
640cdf0e10cSrcweir                             mlPageEnd =
641cdf0e10cSrcweir                                 mpWrtShell->getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE)
642cdf0e10cSrcweir                                 ? pItem->maLayoutInfo.mPagePrtArea.Left()
643cdf0e10cSrcweir                                 : mPages[n]->mPageRect.Left() + 350;
644cdf0e10cSrcweir 						}
645cdf0e10cSrcweir                         else if (mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_RIGHT )
646cdf0e10cSrcweir 						{
647cdf0e10cSrcweir 							// x value for notes positioning
648cdf0e10cSrcweir 							mlPageBorder = mpEditWin->LogicToPixel( Point(mPages[n]->mPageRect.Right(), 0)).X() + GetSidebarBorderWidth(true);
649cdf0e10cSrcweir 							//bending point
650cdf0e10cSrcweir                             mlPageEnd =
651cdf0e10cSrcweir                                 mpWrtShell->getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE)
652cdf0e10cSrcweir                                 ? pItem->maLayoutInfo.mPagePrtArea.Right() :
653cdf0e10cSrcweir                                 mPages[n]->mPageRect.Right() - 350;
654cdf0e10cSrcweir 						}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 						if (pItem->bShow)
657cdf0e10cSrcweir 						{
658cdf0e10cSrcweir                             long Y = mpEditWin->LogicToPixel( Point(0,pItem->maLayoutInfo.mPosition.Bottom())).Y();
659cdf0e10cSrcweir 							long aPostItHeight = 0;
660cdf0e10cSrcweir 							if (!pPostIt)
661cdf0e10cSrcweir 							{
662cdf0e10cSrcweir                                 pPostIt = (*i)->GetSidebarWindow( mpView->GetEditWin(),
663cdf0e10cSrcweir                                                                   WB_DIALOGCONTROL,
664cdf0e10cSrcweir                                                                   *this,
665cdf0e10cSrcweir                                                                   0 );
666cdf0e10cSrcweir 								pPostIt->InitControls();
667cdf0e10cSrcweir 								pPostIt->SetReadonly(mbReadOnly);
668cdf0e10cSrcweir 								pItem->pPostIt = pPostIt;
669cdf0e10cSrcweir 								if (mpAnswer)
670cdf0e10cSrcweir 								{
671cdf0e10cSrcweir 									if (pPostIt->CalcFollow()) //do we really have another note in front of this one
672cdf0e10cSrcweir                                         static_cast<sw::annotation::SwAnnotationWin*>(pPostIt)->InitAnswer(mpAnswer);
673cdf0e10cSrcweir 									delete mpAnswer;
674cdf0e10cSrcweir 									mpAnswer = 0;
675cdf0e10cSrcweir 								}
676cdf0e10cSrcweir 							}
677cdf0e10cSrcweir 
678cdf0e10cSrcweir                             pPostIt->SetChangeTracking(
679cdf0e10cSrcweir                                 pItem->mLayoutStatus,
680cdf0e10cSrcweir                                 GetColorAnchor(pItem->maLayoutInfo.mRedlineAuthor));
681cdf0e10cSrcweir                             pPostIt->SetSidebarPosition(mPages[n]->eSidebarPosition);
682cdf0e10cSrcweir                             pPostIt->SetFollow(pPostIt->CalcFollow());
683cdf0e10cSrcweir                             aPostItHeight = ( pPostIt->GetPostItTextHeight() < pPostIt->GetMinimumSizeWithoutMeta()
684cdf0e10cSrcweir                                               ? pPostIt->GetMinimumSizeWithoutMeta()
685cdf0e10cSrcweir                                               : pPostIt->GetPostItTextHeight() )
686cdf0e10cSrcweir                                             + pPostIt->GetMetaHeight();
687cdf0e10cSrcweir                             pPostIt->SetPosSizePixelRect( mlPageBorder ,
688cdf0e10cSrcweir                                                           Y - GetInitialAnchorDistance(),
689cdf0e10cSrcweir                                                           GetNoteWidth() ,
690cdf0e10cSrcweir                                                           aPostItHeight,
691cdf0e10cSrcweir                                                           pItem->maLayoutInfo.mPosition,
692cdf0e10cSrcweir                                                           mlPageEnd );
693cdf0e10cSrcweir                             pPostIt->ChangeSidebarItem( *pItem );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 							if (pItem->bFocus)
696cdf0e10cSrcweir 							{
697cdf0e10cSrcweir 								mbLayout = true;
698cdf0e10cSrcweir                                 pPostIt->GrabFocus();
699cdf0e10cSrcweir 								pItem->bFocus = false;
700cdf0e10cSrcweir 							}
701cdf0e10cSrcweir 							// only the visible postits are used for the final layout
702cdf0e10cSrcweir 							aVisiblePostItList.push_back(pPostIt);
703cdf0e10cSrcweir 							lNeededHeight += pPostIt->IsFollow() ? aPostItHeight : aPostItHeight+GetSpaceBetween();
704cdf0e10cSrcweir 						}
705cdf0e10cSrcweir 						else // we don't want to see it
706cdf0e10cSrcweir 						{
707cdf0e10cSrcweir 							if (pPostIt)
708cdf0e10cSrcweir 								pPostIt->HideNote();
709cdf0e10cSrcweir 						}
710cdf0e10cSrcweir 					}
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 					if ((aVisiblePostItList.size()>0) && ShowNotes())
713cdf0e10cSrcweir 					{
714cdf0e10cSrcweir 						bool bOldScrollbar = mPages[n]->bScrollbar;
715cdf0e10cSrcweir 						if (ShowNotes())
716cdf0e10cSrcweir 							mPages[n]->bScrollbar = LayoutByPage(aVisiblePostItList, mPages[n]->mPageRect.SVRect(), lNeededHeight);
717cdf0e10cSrcweir 						else
718cdf0e10cSrcweir 							mPages[n]->bScrollbar = false;
719cdf0e10cSrcweir 						if (!mPages[n]->bScrollbar)
720cdf0e10cSrcweir 						{
721cdf0e10cSrcweir 							mPages[n]->lOffset = 0;
722cdf0e10cSrcweir 						}
723cdf0e10cSrcweir 						else
724cdf0e10cSrcweir 						{
725cdf0e10cSrcweir 							//when we changed our zoom level, the offset value can be to big, so lets check for the largest possible zoom value
726cdf0e10cSrcweir 							long aAvailableHeight = mpEditWin->LogicToPixel(Size(0,mPages[n]->mPageRect.Height())).Height() - 2 * GetSidebarScrollerHeight();
727cdf0e10cSrcweir 							long lOffset = -1 * GetScrollSize() * (aVisiblePostItList.size() - aAvailableHeight / GetScrollSize());
728cdf0e10cSrcweir 							if (mPages[n]->lOffset < lOffset)
729cdf0e10cSrcweir 								mPages[n]->lOffset = lOffset;
730cdf0e10cSrcweir 						}
731cdf0e10cSrcweir 						bUpdate = (bOldScrollbar != mPages[n]->bScrollbar) || bUpdate;
732cdf0e10cSrcweir 						const long aSidebarheight = mPages[n]->bScrollbar ? mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height() : 0;
733cdf0e10cSrcweir 						/*
734cdf0e10cSrcweir                        					TODO
735cdf0e10cSrcweir                        					- enlarge all notes till GetNextBorder(), as we resized to average value before
736cdf0e10cSrcweir                        					*/
737cdf0e10cSrcweir 						//lets hide the ones which overlap the page
738cdf0e10cSrcweir                         for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
739cdf0e10cSrcweir 						{
740cdf0e10cSrcweir 							if (mPages[n]->lOffset != 0)
741cdf0e10cSrcweir 								(*i)->TranslateTopPosition(mPages[n]->lOffset);
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 							bool bBottom  = mpEditWin->PixelToLogic(Point(0,(*i)->VirtualPos().Y()+(*i)->VirtualSize().Height())).Y() <= (mPages[n]->mPageRect.Bottom()-aSidebarheight);
744cdf0e10cSrcweir 							bool bTop = mpEditWin->PixelToLogic(Point(0,(*i)->VirtualPos().Y())).Y() >= (mPages[n]->mPageRect.Top()+aSidebarheight);
745cdf0e10cSrcweir 							if ( bBottom && bTop )
746cdf0e10cSrcweir 							{
747cdf0e10cSrcweir 								(*i)->ShowNote();
748cdf0e10cSrcweir 							}
749cdf0e10cSrcweir 							else
750cdf0e10cSrcweir 							{
751cdf0e10cSrcweir 								if (mpEditWin->PixelToLogic(Point(0,(*i)->VirtualPos().Y())).Y() < (mPages[n]->mPageRect.Top()+aSidebarheight))
752cdf0e10cSrcweir 								{
753cdf0e10cSrcweir                                     if ( mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT )
754cdf0e10cSrcweir                                         (*i)->ShowAnchorOnly(Point( mPages[n]->mPageRect.Left(),
755cdf0e10cSrcweir                                                                     mPages[n]->mPageRect.Top()));
756cdf0e10cSrcweir                                     else if ( mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_RIGHT )
757cdf0e10cSrcweir                                         (*i)->ShowAnchorOnly(Point( mPages[n]->mPageRect.Right(),
758cdf0e10cSrcweir                                                                     mPages[n]->mPageRect.Top()));
759cdf0e10cSrcweir 								}
760cdf0e10cSrcweir 								else
761cdf0e10cSrcweir 								{
762cdf0e10cSrcweir                                     if ( mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT )
763cdf0e10cSrcweir                                         (*i)->ShowAnchorOnly(Point(mPages[n]->mPageRect.Left(),
764cdf0e10cSrcweir                                                                    mPages[n]->mPageRect.Bottom()));
765cdf0e10cSrcweir                                     else if ( mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_RIGHT )
766cdf0e10cSrcweir                                         (*i)->ShowAnchorOnly(Point(mPages[n]->mPageRect.Right(),
767cdf0e10cSrcweir                                                                    mPages[n]->mPageRect.Bottom()));
768cdf0e10cSrcweir 								}
769cdf0e10cSrcweir 								DBG_ASSERT(mPages[n]->bScrollbar,"SwPostItMgr::LayoutByPage(): note overlaps, but bScrollbar is not true");
770cdf0e10cSrcweir 							}
771cdf0e10cSrcweir 						}
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 						// do some magic so we really see the focused note
774cdf0e10cSrcweir                         for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
775cdf0e10cSrcweir 						{
776cdf0e10cSrcweir                             				if ((*i)->HasChildPathFocus())
777cdf0e10cSrcweir 							{
778cdf0e10cSrcweir 								MakeVisible((*i),n+1);
779cdf0e10cSrcweir 								break;
780cdf0e10cSrcweir 							}
781cdf0e10cSrcweir 						}
782cdf0e10cSrcweir 					}
783cdf0e10cSrcweir 					else
784cdf0e10cSrcweir 					{
785cdf0e10cSrcweir                         for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
786cdf0e10cSrcweir                                                                 (*i)->SetPosAndSize();
787cdf0e10cSrcweir 
788cdf0e10cSrcweir                                                         bool bOldScrollbar = mPages[n]->bScrollbar;
789cdf0e10cSrcweir                                                         mPages[n]->bScrollbar = false;
790cdf0e10cSrcweir                                                         bUpdate = (bOldScrollbar != mPages[n]->bScrollbar) || bUpdate;
791cdf0e10cSrcweir 					}
792cdf0e10cSrcweir 					aVisiblePostItList.clear();
793cdf0e10cSrcweir 				}
794cdf0e10cSrcweir 				else
795cdf0e10cSrcweir 				{
796cdf0e10cSrcweir 					bUpdate = true;
797cdf0e10cSrcweir 					mPages[n]->bScrollbar = false;
798cdf0e10cSrcweir 				}
799cdf0e10cSrcweir 			}
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 			if (!ShowNotes())
802cdf0e10cSrcweir 			{       // we do not want to see the notes anymore -> Options-Writer-View-Notes
803cdf0e10cSrcweir 				bool bRepair = false;
804cdf0e10cSrcweir                 for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
805cdf0e10cSrcweir 				{
806cdf0e10cSrcweir                     SwSidebarItem* pItem = (*i);
807cdf0e10cSrcweir 					if ( !pItem->UseElement() )
808cdf0e10cSrcweir 					{
809cdf0e10cSrcweir 						DBG_ERROR("PostIt is not in doc!");
810cdf0e10cSrcweir 						bRepair = true;
811cdf0e10cSrcweir 						continue;
812cdf0e10cSrcweir 					}
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 					if ((*i)->pPostIt)
815cdf0e10cSrcweir 					{
816cdf0e10cSrcweir 						(*i)->pPostIt->HideNote();
817cdf0e10cSrcweir 						if ((*i)->pPostIt->HasChildPathFocus())
818cdf0e10cSrcweir 						{
819cdf0e10cSrcweir                             SetActiveSidebarWin(0);
820cdf0e10cSrcweir 							(*i)->pPostIt->GrabFocusToDocument();
821cdf0e10cSrcweir 						}
822cdf0e10cSrcweir 					}
823cdf0e10cSrcweir 				}
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 				if ( bRepair )
826cdf0e10cSrcweir 					CheckForRemovedPostIts();
827cdf0e10cSrcweir 			}
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 			// notes scrollbar is otherwise not drawn correctly for some cases
831cdf0e10cSrcweir 			// scrollbar area is enough
832cdf0e10cSrcweir 			if (bUpdate)
833cdf0e10cSrcweir 				mpEditWin->Invalidate();
834cdf0e10cSrcweir 		mbLayouting = false;
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir bool SwPostItMgr::BorderOverPageBorder(unsigned long aPage) const
839cdf0e10cSrcweir {
840cdf0e10cSrcweir 	if ( mPages[aPage-1]->mList->empty() )
841cdf0e10cSrcweir 	{
842cdf0e10cSrcweir 		DBG_ERROR("Notes SidePane painted but no rects and page lists calculated!");
843cdf0e10cSrcweir 		return false;
844cdf0e10cSrcweir 	}
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     SwSidebarItem_iterator aItem = mPages[aPage-1]->mList->end();
847cdf0e10cSrcweir 	--aItem;
848cdf0e10cSrcweir 	DBG_ASSERT ((*aItem)->pPostIt,"BorderOverPageBorder: NULL postIt, should never happen");
849cdf0e10cSrcweir 	if ((*aItem)->pPostIt)
850cdf0e10cSrcweir 	{
851cdf0e10cSrcweir 		const long aSidebarheight = mPages[aPage-1]->bScrollbar ? mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height() : 0;
852cdf0e10cSrcweir 		const long aEndValue = mpEditWin->PixelToLogic(Point(0,(*aItem)->pPostIt->GetPosPixel().Y()+(*aItem)->pPostIt->GetSizePixel().Height())).Y();
853cdf0e10cSrcweir 		return aEndValue <= mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight;
854cdf0e10cSrcweir 	}
855cdf0e10cSrcweir 	else
856cdf0e10cSrcweir 		return false;
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir void SwPostItMgr::Scroll(const long lScroll,const unsigned long aPage)
860cdf0e10cSrcweir {
861cdf0e10cSrcweir 	DBG_ASSERT((lScroll % GetScrollSize() )==0,"SwPostItMgr::Scroll: scrolling by wrong value");
862cdf0e10cSrcweir 	// do not scroll more than neccessary up or down
863cdf0e10cSrcweir 	if ( ((mPages[aPage-1]->lOffset == 0) && (lScroll>0)) || ( BorderOverPageBorder(aPage) && (lScroll<0)) )
864cdf0e10cSrcweir 		return;
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 	const bool bOldUp = ArrowEnabled(KEY_PAGEUP,aPage);
867cdf0e10cSrcweir 	const bool bOldDown = ArrowEnabled(KEY_PAGEDOWN,aPage);
868cdf0e10cSrcweir 	const long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
869cdf0e10cSrcweir     for(SwSidebarItem_iterator i = mPages[aPage-1]->mList->begin(); i!= mPages[aPage-1]->mList->end(); i++)
870cdf0e10cSrcweir 	{
871cdf0e10cSrcweir         SwSidebarWin* pPostIt = (*i)->pPostIt;
872cdf0e10cSrcweir 		// if this is an answer, we should take the normal position and not the real, slightly moved position
873cdf0e10cSrcweir 		pPostIt->SetVirtualPosSize(pPostIt->GetPosPixel(),pPostIt->GetSizePixel());
874cdf0e10cSrcweir 		pPostIt->TranslateTopPosition(lScroll);
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 		if ((*i)->bShow)
877cdf0e10cSrcweir 		{
878cdf0e10cSrcweir 			bool bBottom  = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y()+pPostIt->VirtualSize().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
879cdf0e10cSrcweir 			bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() >=	 (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
880cdf0e10cSrcweir 			if ( bBottom && bTop)
881cdf0e10cSrcweir 			{
882cdf0e10cSrcweir 					pPostIt->ShowNote();
883cdf0e10cSrcweir 			}
884cdf0e10cSrcweir 			else
885cdf0e10cSrcweir 			{
886cdf0e10cSrcweir 				if ( mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() < (mPages[aPage-1]->mPageRect.Top()+aSidebarheight))
887cdf0e10cSrcweir 				{
888cdf0e10cSrcweir                     if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT)
889cdf0e10cSrcweir                         pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Top()));
890cdf0e10cSrcweir                     else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_RIGHT)
891cdf0e10cSrcweir                         pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Top()));
892cdf0e10cSrcweir 				}
893cdf0e10cSrcweir 				else
894cdf0e10cSrcweir 				{
895cdf0e10cSrcweir                     if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT)
896cdf0e10cSrcweir                         pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Bottom()));
897cdf0e10cSrcweir                     else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_RIGHT)
898cdf0e10cSrcweir                         pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Bottom()));
899cdf0e10cSrcweir 				}
900cdf0e10cSrcweir 			}
901cdf0e10cSrcweir 		}
902cdf0e10cSrcweir 	}
903cdf0e10cSrcweir 	mPages[aPage-1]->lOffset += lScroll;
904cdf0e10cSrcweir 	if ( (bOldUp != ArrowEnabled(KEY_PAGEUP,aPage)) ||(bOldDown != ArrowEnabled(KEY_PAGEDOWN,aPage)) )
905cdf0e10cSrcweir 	{
906cdf0e10cSrcweir 		mpEditWin->Invalidate(GetBottomScrollRect(aPage));
907cdf0e10cSrcweir 		mpEditWin->Invalidate(GetTopScrollRect(aPage));
908cdf0e10cSrcweir 	}
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir void SwPostItMgr::AutoScroll(const SwSidebarWin* pPostIt,const unsigned long aPage )
912cdf0e10cSrcweir {
913cdf0e10cSrcweir 	// otherwise all notes are visible
914cdf0e10cSrcweir 	if (mPages[aPage-1]->bScrollbar)
915cdf0e10cSrcweir 	{
916cdf0e10cSrcweir 		const long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
917cdf0e10cSrcweir 		const bool bBottom  = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
918cdf0e10cSrcweir 		const bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y())).Y() >= (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
919cdf0e10cSrcweir 		if ( !(bBottom && bTop))
920cdf0e10cSrcweir 		{
921cdf0e10cSrcweir 			const long aDiff = bBottom ? mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Top() + aSidebarheight)).Y() - pPostIt->GetPosPixel().Y() :
922cdf0e10cSrcweir 											mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Bottom() - aSidebarheight)).Y() - (pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height());
923cdf0e10cSrcweir 			// this just adds the missing value to get the next a* GetScrollSize() after aDiff
924cdf0e10cSrcweir 			// e.g aDiff= 61 POSTIT_SCOLL=50 --> lScroll = 100
925cdf0e10cSrcweir 			const long lScroll = bBottom ? (aDiff + ( GetScrollSize() - (aDiff % GetScrollSize()))) : (aDiff - (GetScrollSize() + (aDiff % GetScrollSize())));
926cdf0e10cSrcweir 			Scroll(lScroll, aPage);
927cdf0e10cSrcweir 		}
928cdf0e10cSrcweir 	}
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
931cdf0e10cSrcweir void SwPostItMgr::MakeVisible(const SwSidebarWin* pPostIt,long aPage )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir 	if (aPage == -1)
934cdf0e10cSrcweir 	{
935cdf0e10cSrcweir 		// we dont know the page yet, lets find it ourselves
936cdf0e10cSrcweir 		for (unsigned long n=0;n<mPages.size();n++)
937cdf0e10cSrcweir 		{
938cdf0e10cSrcweir 			if (mPages[n]->mList->size()>0)
939cdf0e10cSrcweir 			{
940cdf0e10cSrcweir                 for(SwSidebarItem_iterator i = mPages[n]->mList->begin(); i!= mPages[n]->mList->end(); i++)
941cdf0e10cSrcweir 				{
942cdf0e10cSrcweir 					if ((*i)->pPostIt==pPostIt)
943cdf0e10cSrcweir 					{
944cdf0e10cSrcweir 						aPage = n+1;
945cdf0e10cSrcweir 						break;
946cdf0e10cSrcweir 					}
947cdf0e10cSrcweir 				}
948cdf0e10cSrcweir 			}
949cdf0e10cSrcweir 		}
950cdf0e10cSrcweir 	}
951cdf0e10cSrcweir 	if (aPage!=-1)
952cdf0e10cSrcweir 		AutoScroll(pPostIt,aPage);
953cdf0e10cSrcweir 	Rectangle aNoteRect (Point(pPostIt->GetPosPixel().X(),pPostIt->GetPosPixel().Y()-5),pPostIt->GetSizePixel());
954cdf0e10cSrcweir 	if (!aNoteRect.IsEmpty())
955cdf0e10cSrcweir 		mpWrtShell->MakeVisible(SwRect(mpEditWin->PixelToLogic(aNoteRect)));
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir bool SwPostItMgr::ArrowEnabled(sal_uInt16 aDirection,unsigned long aPage) const
959cdf0e10cSrcweir {
960cdf0e10cSrcweir 	switch (aDirection)
961cdf0e10cSrcweir 	{
962cdf0e10cSrcweir 		case KEY_PAGEUP:
963cdf0e10cSrcweir 			{
964cdf0e10cSrcweir 				return (mPages[aPage-1]->lOffset != 0);
965cdf0e10cSrcweir 			}
966cdf0e10cSrcweir 		case KEY_PAGEDOWN:
967cdf0e10cSrcweir 			{
968cdf0e10cSrcweir 				return (!BorderOverPageBorder(aPage));
969cdf0e10cSrcweir 			}
970cdf0e10cSrcweir 		default: return false;
971cdf0e10cSrcweir 	}
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
974cdf0e10cSrcweir Color SwPostItMgr::GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const
975cdf0e10cSrcweir {
976cdf0e10cSrcweir 	if (ArrowEnabled(aDirection,aPage))
977cdf0e10cSrcweir 	{
978cdf0e10cSrcweir 		if (Application::GetSettings().GetStyleSettings().GetHighContrastMode())
979cdf0e10cSrcweir 			return Color(COL_WHITE);
980cdf0e10cSrcweir 		else
981cdf0e10cSrcweir 			return COL_NOTES_SIDEPANE_ARROW_ENABLED;
982cdf0e10cSrcweir 	}
983cdf0e10cSrcweir 	else
984cdf0e10cSrcweir 	{
985cdf0e10cSrcweir 		return COL_NOTES_SIDEPANE_ARROW_DISABLED;
986cdf0e10cSrcweir 	}
987cdf0e10cSrcweir }
988cdf0e10cSrcweir 
989cdf0e10cSrcweir bool SwPostItMgr::LayoutByPage(std::list<SwSidebarWin*> &aVisiblePostItList,const Rectangle aBorder, long lNeededHeight)
990cdf0e10cSrcweir {
991cdf0e10cSrcweir 	/*** General layout idea:***/
992cdf0e10cSrcweir 	//  - if we have space left, we always move the current one up,
993cdf0e10cSrcweir 	//    otherwise the next one down
994cdf0e10cSrcweir 	//  - first all notes are resized
995cdf0e10cSrcweir 	//	- then the real layout starts
996cdf0e10cSrcweir 	/*************************************************************/
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 	//rBorder is the page rect
999cdf0e10cSrcweir     const Rectangle	rBorder			= mpEditWin->LogicToPixel( aBorder);
1000cdf0e10cSrcweir 	long			lTopBorder		= rBorder.Top() + 5;
1001cdf0e10cSrcweir 	long			lBottomBorder	= rBorder.Bottom() - 5;
1002cdf0e10cSrcweir 	const long		lVisibleHeight	= lBottomBorder - lTopBorder; //rBorder.GetHeight() ;
1003cdf0e10cSrcweir 	long			lSpaceUsed		= 0;
1004cdf0e10cSrcweir 	long			lTranslatePos	= 0;
1005cdf0e10cSrcweir 	int				loop			= 0;
1006cdf0e10cSrcweir 	bool			bDone			= false;
1007cdf0e10cSrcweir 	bool			bScrollbars		= false;
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 	// do all neccessary resizings
1010cdf0e10cSrcweir 	if (lVisibleHeight < lNeededHeight)
1011cdf0e10cSrcweir 	{
1012cdf0e10cSrcweir 		// ok, now we have to really resize and adding scrollbars
1013cdf0e10cSrcweir 		const long lAverageHeight = (lVisibleHeight - aVisiblePostItList.size()*GetSpaceBetween()) / aVisiblePostItList.size();
1014cdf0e10cSrcweir 		if (lAverageHeight<GetMinimumSizeWithMeta())
1015cdf0e10cSrcweir 		{
1016cdf0e10cSrcweir 			bScrollbars = true;
1017cdf0e10cSrcweir 			lTopBorder += GetSidebarScrollerHeight() + 10;
1018cdf0e10cSrcweir 			lBottomBorder -= (GetSidebarScrollerHeight() + 10);
1019cdf0e10cSrcweir                 for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
1020cdf0e10cSrcweir 					(*i)->SetSize(Size((*i)->VirtualSize().getWidth(),(*i)->GetMinimumSizeWithMeta()));
1021cdf0e10cSrcweir 		}
1022cdf0e10cSrcweir 		else
1023cdf0e10cSrcweir 		{
1024cdf0e10cSrcweir             for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
1025cdf0e10cSrcweir 			{
1026cdf0e10cSrcweir 				if ( (*i)->VirtualSize().getHeight() > lAverageHeight)
1027cdf0e10cSrcweir 					(*i)->SetSize(Size((*i)->VirtualSize().getWidth(),lAverageHeight));
1028cdf0e10cSrcweir 			}
1029cdf0e10cSrcweir 		}
1030cdf0e10cSrcweir 	}
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 	//start the real layout so nothing overlaps anymore
1033cdf0e10cSrcweir 	if (aVisiblePostItList.size()>1)
1034cdf0e10cSrcweir 	{
1035cdf0e10cSrcweir 		// if no window is moved anymore we are finished
1036cdf0e10cSrcweir 		while (!bDone)
1037cdf0e10cSrcweir 		{
1038cdf0e10cSrcweir 			loop++;
1039cdf0e10cSrcweir   			bDone = true;
1040cdf0e10cSrcweir 			lSpaceUsed = lTopBorder + GetSpaceBetween();
1041cdf0e10cSrcweir             for(SwSidebarWin_iterator i = aVisiblePostItList.begin(); i!= aVisiblePostItList.end() ; i++)
1042cdf0e10cSrcweir 			{
1043cdf0e10cSrcweir                 SwSidebarWin_iterator aNextPostIt = i;
1044cdf0e10cSrcweir 				++aNextPostIt;
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 				if (aNextPostIt !=aVisiblePostItList.end())
1047cdf0e10cSrcweir 				{
1048cdf0e10cSrcweir 					lTranslatePos = ( (*i)->VirtualPos().Y() + (*i)->VirtualSize().Height()) - (*aNextPostIt)->VirtualPos().Y();
1049cdf0e10cSrcweir 					if (lTranslatePos > 0) // note windows overlaps the next one
1050cdf0e10cSrcweir 					{
1051cdf0e10cSrcweir 						// we are not done yet, loop at least once more
1052cdf0e10cSrcweir 						bDone = false;
1053cdf0e10cSrcweir 						// if there is space left, move the current note up
1054cdf0e10cSrcweir 						// it could also happen that there is no space left for the first note due to a scrollbar
1055cdf0e10cSrcweir 						// then we also jump into, so we move the current one up and the next one down
1056cdf0e10cSrcweir 						if ( (lSpaceUsed <= (*i)->VirtualPos().Y()) || (i==aVisiblePostItList.begin()))
1057cdf0e10cSrcweir 						{
1058cdf0e10cSrcweir 							// we have space left, so let's move the current one up
1059cdf0e10cSrcweir 							if ( ((*i)->VirtualPos().Y()- lTranslatePos - GetSpaceBetween()) > lTopBorder)
1060cdf0e10cSrcweir 							{
1061cdf0e10cSrcweir 								if ((*aNextPostIt)->IsFollow())
1062cdf0e10cSrcweir                                     (*i)->TranslateTopPosition(-1*(lTranslatePos+ANCHORLINE_WIDTH));
1063cdf0e10cSrcweir 								else
1064cdf0e10cSrcweir 									(*i)->TranslateTopPosition(-1*(lTranslatePos+GetSpaceBetween()));
1065cdf0e10cSrcweir 							}
1066cdf0e10cSrcweir 							else
1067cdf0e10cSrcweir 							{
1068cdf0e10cSrcweir 								long lMoveUp = (*i)->VirtualPos().Y() - lTopBorder;
1069cdf0e10cSrcweir 								(*i)->TranslateTopPosition(-1* lMoveUp);
1070cdf0e10cSrcweir 								if ((*aNextPostIt)->IsFollow())
1071cdf0e10cSrcweir                                     (*aNextPostIt)->TranslateTopPosition( (lTranslatePos+ANCHORLINE_WIDTH) - lMoveUp);
1072cdf0e10cSrcweir 								else
1073cdf0e10cSrcweir 									(*aNextPostIt)->TranslateTopPosition( (lTranslatePos+GetSpaceBetween()) - lMoveUp);
1074cdf0e10cSrcweir 							}
1075cdf0e10cSrcweir 						}
1076cdf0e10cSrcweir 						else
1077cdf0e10cSrcweir 						{
1078cdf0e10cSrcweir 							// no space left, left move the next one down
1079cdf0e10cSrcweir 							if ((*aNextPostIt)->IsFollow())
1080cdf0e10cSrcweir                                 (*aNextPostIt)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1081cdf0e10cSrcweir 							else
1082cdf0e10cSrcweir 								(*aNextPostIt)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1083cdf0e10cSrcweir 						}
1084cdf0e10cSrcweir 					}
1085cdf0e10cSrcweir 					else
1086cdf0e10cSrcweir 					{
1087cdf0e10cSrcweir 						// the first one could overlap the topborder instead of a second note
1088cdf0e10cSrcweir 						if (i==aVisiblePostItList.begin())
1089cdf0e10cSrcweir 						{
1090cdf0e10cSrcweir 							long lMoveDown = lTopBorder - (*i)->VirtualPos().Y();
1091cdf0e10cSrcweir 							if (lMoveDown>0)
1092cdf0e10cSrcweir 							{
1093cdf0e10cSrcweir 								bDone = false;
1094cdf0e10cSrcweir 								(*i)->TranslateTopPosition( lMoveDown);
1095cdf0e10cSrcweir 							}
1096cdf0e10cSrcweir 						}
1097cdf0e10cSrcweir 					}
1098cdf0e10cSrcweir 					if (aNextPostIt !=aVisiblePostItList.end() && (*aNextPostIt)->IsFollow())
1099cdf0e10cSrcweir                         lSpaceUsed += (*i)->VirtualSize().Height() + ANCHORLINE_WIDTH;
1100cdf0e10cSrcweir 					else
1101cdf0e10cSrcweir 						lSpaceUsed += (*i)->VirtualSize().Height() + GetSpaceBetween();
1102cdf0e10cSrcweir 				}
1103cdf0e10cSrcweir 				else
1104cdf0e10cSrcweir 				{
1105cdf0e10cSrcweir 					//(*i) is the last visible item
1106cdf0e10cSrcweir                     SwSidebarWin_iterator aPrevPostIt = i;
1107cdf0e10cSrcweir 					--aPrevPostIt;
1108cdf0e10cSrcweir 					//lTranslatePos = ( (*aPrevPostIt)->VirtualPos().Y() + (*aPrevPostIt)->VirtualSize().Height() + GetSpaceBetween() ) - (*i)->VirtualPos().Y();
1109cdf0e10cSrcweir 					lTranslatePos = ( (*aPrevPostIt)->VirtualPos().Y() + (*aPrevPostIt)->VirtualSize().Height() ) - (*i)->VirtualPos().Y();
1110cdf0e10cSrcweir 					if (lTranslatePos > 0)
1111cdf0e10cSrcweir 					{
1112cdf0e10cSrcweir 						bDone = false;
1113cdf0e10cSrcweir 						if ( ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()+lTranslatePos) < lBottomBorder)
1114cdf0e10cSrcweir 						{
1115cdf0e10cSrcweir 							if ( (*i)->IsFollow() )
1116cdf0e10cSrcweir                                 (*i)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1117cdf0e10cSrcweir 							else
1118cdf0e10cSrcweir 								(*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1119cdf0e10cSrcweir 						}
1120cdf0e10cSrcweir 						else
1121cdf0e10cSrcweir 						{
1122cdf0e10cSrcweir 							(*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()) );
1123cdf0e10cSrcweir 						}
1124cdf0e10cSrcweir 					}
1125cdf0e10cSrcweir 					else
1126cdf0e10cSrcweir 					{
1127cdf0e10cSrcweir 						// note does not overlap, but we might be over the lower border
1128cdf0e10cSrcweir                         // only do this if there are no scrollbars, otherwise notes are supposed to overlap the border
1129cdf0e10cSrcweir 						if (!bScrollbars && ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height() > lBottomBorder) )
1130cdf0e10cSrcweir 						{
1131cdf0e10cSrcweir 							bDone = false;
1132cdf0e10cSrcweir 							(*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()));
1133cdf0e10cSrcweir 						}
1134cdf0e10cSrcweir 					}
1135cdf0e10cSrcweir 				}
1136cdf0e10cSrcweir 			}
1137cdf0e10cSrcweir 			// security check so we don't loop forever
1138cdf0e10cSrcweir 			if (loop>MAX_LOOP_COUNT)
1139cdf0e10cSrcweir 			{
1140cdf0e10cSrcweir 				DBG_ERROR("PostItMgr::Layout(): We are looping forever");
1141cdf0e10cSrcweir 				break;
1142cdf0e10cSrcweir 			}
1143cdf0e10cSrcweir 		}
1144cdf0e10cSrcweir 	}
1145cdf0e10cSrcweir 	else
1146cdf0e10cSrcweir 	{
1147cdf0e10cSrcweir 		// only one left, make sure it is not hidden at the top or bottom
1148cdf0e10cSrcweir         SwSidebarWin_iterator i = aVisiblePostItList.begin();
1149cdf0e10cSrcweir 		lTranslatePos = lTopBorder - (*i)->VirtualPos().Y();
1150cdf0e10cSrcweir 		if (lTranslatePos>0)
1151cdf0e10cSrcweir 		{
1152cdf0e10cSrcweir 			(*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1153cdf0e10cSrcweir 		}
1154cdf0e10cSrcweir 		lTranslatePos =	lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height());
1155cdf0e10cSrcweir 		if (lTranslatePos<0)
1156cdf0e10cSrcweir 		{
1157cdf0e10cSrcweir 			(*i)->TranslateTopPosition(lTranslatePos);
1158cdf0e10cSrcweir 		}
1159cdf0e10cSrcweir 	}
1160cdf0e10cSrcweir 	return bScrollbars;
1161cdf0e10cSrcweir  }
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir /*
1164cdf0e10cSrcweir void SwPostItMgr::AddRedlineComments(bool bCheckExistance, bool bFocus)
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir 	bool bEmpty = mvPostItFlds.empty();
1167cdf0e10cSrcweir 	const SwRedlineTbl& aTable = mpView->GetDocShell()->GetDoc()->GetRedlineTbl();
1168cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < aTable.Count(); ++i )
1169cdf0e10cSrcweir 	{
1170cdf0e10cSrcweir 		SwRedline* pRedline = const_cast<SwRedline*>((aTable)[i]);
1171cdf0e10cSrcweir 		if ( pRedline->GetComment() != String(rtl::OUString::createFromAscii("")) )
1172cdf0e10cSrcweir 			InsertItem(pRedline, bCheckExistance, bFocus);
1173cdf0e10cSrcweir 	}
1174cdf0e10cSrcweir 	if (bEmpty && !mvPostItFlds.empty())
1175cdf0e10cSrcweir 		PrepareView(true);
1176cdf0e10cSrcweir  }
1177cdf0e10cSrcweir  */
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir void SwPostItMgr::AddPostIts(bool bCheckExistance, bool bFocus)
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir 	bool bEmpty = mvPostItFlds.empty();
1182cdf0e10cSrcweir 	SwFieldType* pType = mpView->GetDocShell()->GetDoc()->GetFldType(RES_POSTITFLD, aEmptyStr,false);
1183cdf0e10cSrcweir 	SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
1184cdf0e10cSrcweir 	SwFmtFld* pSwFmtFld = aIter.First();
1185cdf0e10cSrcweir 	while(pSwFmtFld)
1186cdf0e10cSrcweir 	{
1187cdf0e10cSrcweir 		if ( pSwFmtFld->GetTxtFld())
1188cdf0e10cSrcweir 		{
1189cdf0e10cSrcweir 			if ( pSwFmtFld->IsFldInDoc() )
1190cdf0e10cSrcweir 				InsertItem(pSwFmtFld,bCheckExistance,bFocus);
1191cdf0e10cSrcweir 		}
1192cdf0e10cSrcweir 		pSwFmtFld = aIter.Next();
1193cdf0e10cSrcweir 	}
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 	// if we just added the first one we have to update the view for centering
1196cdf0e10cSrcweir 	if (bEmpty && !mvPostItFlds.empty())
1197cdf0e10cSrcweir 		PrepareView(true);
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir void SwPostItMgr::RemoveSidebarWin()
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir 	if (!mvPostItFlds.empty())
1203cdf0e10cSrcweir 	{
1204cdf0e10cSrcweir         for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1205cdf0e10cSrcweir 		{
1206cdf0e10cSrcweir 			EndListening( *((*i)->GetBroadCaster()) );
1207cdf0e10cSrcweir 			if ((*i)->pPostIt)
1208cdf0e10cSrcweir 				delete (*i)->pPostIt;
1209cdf0e10cSrcweir 			delete (*i);
1210cdf0e10cSrcweir 		}
1211cdf0e10cSrcweir 		mvPostItFlds.clear();
1212cdf0e10cSrcweir 	}
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir 	// all postits removed, no items should be left in pages
1215cdf0e10cSrcweir 	PreparePageContainer();
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir // copy to new vector, otherwise RemoveItem would operate and delete stuff on mvPostItFlds as well
1219cdf0e10cSrcweir // RemoveItem will clean up the core field and visible postit if neccessary
1220cdf0e10cSrcweir // we cannot just delete everything as before, as postits could move into change tracking
1221cdf0e10cSrcweir void SwPostItMgr::Delete(String aAuthor)
1222cdf0e10cSrcweir {
1223cdf0e10cSrcweir 	mpWrtShell->StartAllAction();
1224cdf0e10cSrcweir     if ( HasActiveSidebarWin() && (GetActiveSidebarWin()->GetAuthor()==aAuthor) )
1225cdf0e10cSrcweir     {
1226cdf0e10cSrcweir         SetActiveSidebarWin(0);
1227cdf0e10cSrcweir     }
1228cdf0e10cSrcweir 	SwRewriter aRewriter;
1229cdf0e10cSrcweir 	String aUndoString = SW_RES(STR_DELETE_AUTHOR_NOTES);
1230cdf0e10cSrcweir 	aUndoString += aAuthor;
1231cdf0e10cSrcweir 	aRewriter.AddRule(UNDO_ARG1, aUndoString);
1232cdf0e10cSrcweir 	mpWrtShell->StartUndo( UNDO_DELETE, &aRewriter );
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 	std::vector<SwFmtFld*> aTmp;
1235cdf0e10cSrcweir     aTmp.reserve( mvPostItFlds.size() );
1236cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator pPostIt = mvPostItFlds.begin(); pPostIt!= mvPostItFlds.end() ; pPostIt++)
1237cdf0e10cSrcweir 	{
1238cdf0e10cSrcweir 		if ((*pPostIt)->GetFmtFld() && ((*pPostIt)->pPostIt->GetAuthor() == aAuthor) )
1239cdf0e10cSrcweir 			aTmp.push_back( (*pPostIt)->GetFmtFld() );
1240cdf0e10cSrcweir 	}
1241cdf0e10cSrcweir 	for(std::vector<SwFmtFld*>::iterator i = aTmp.begin(); i!= aTmp.end() ; i++)
1242cdf0e10cSrcweir 	{
1243cdf0e10cSrcweir 		mpWrtShell->GotoField( *(*i) );
1244cdf0e10cSrcweir 		mpWrtShell->DelRight();
1245cdf0e10cSrcweir 	}
1246cdf0e10cSrcweir     mpWrtShell->EndUndo();
1247cdf0e10cSrcweir 	PrepareView();
1248cdf0e10cSrcweir 	mpWrtShell->EndAllAction();
1249cdf0e10cSrcweir 	mbLayout = true;
1250cdf0e10cSrcweir 	CalcRects();
1251cdf0e10cSrcweir 	LayoutPostIts();
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir void SwPostItMgr::Delete()
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir 	mpWrtShell->StartAllAction();
1257cdf0e10cSrcweir     SetActiveSidebarWin(0);
1258cdf0e10cSrcweir 	SwRewriter aRewriter;
1259cdf0e10cSrcweir 	aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_DELETE_ALL_NOTES) );
1260cdf0e10cSrcweir 	mpWrtShell->StartUndo( UNDO_DELETE, &aRewriter );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     std::vector<SwFmtFld*> aTmp;
1263cdf0e10cSrcweir     aTmp.reserve( mvPostItFlds.size() );
1264cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator pPostIt = mvPostItFlds.begin(); pPostIt!= mvPostItFlds.end() ; pPostIt++)
1265cdf0e10cSrcweir 	{
1266cdf0e10cSrcweir 		if ((*pPostIt)->GetFmtFld())
1267cdf0e10cSrcweir 			aTmp.push_back( (*pPostIt)->GetFmtFld() );
1268cdf0e10cSrcweir 	}
1269cdf0e10cSrcweir 	for(std::vector<SwFmtFld*>::iterator i = aTmp.begin(); i!= aTmp.end() ; i++)
1270cdf0e10cSrcweir 	{
1271cdf0e10cSrcweir 		mpWrtShell->GotoField( *(*i) );
1272cdf0e10cSrcweir 		mpWrtShell->DelRight();
1273cdf0e10cSrcweir 	}
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir /*
1276cdf0e10cSrcweir 	for(std::list<SwPostItItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1277cdf0e10cSrcweir 	{
1278cdf0e10cSrcweir 		SwPostItItem* pItem = (*i);
1279cdf0e10cSrcweir 		// stop listening, we delete ourselves
1280cdf0e10cSrcweir 		EndListening( *(pItem->pFmtFld) );
1281cdf0e10cSrcweir 		// delete the actual SwPostItField
1282cdf0e10cSrcweir 		mpWrtShell->GotoField(*pItem->pFmtFld);
1283cdf0e10cSrcweir 		mpWrtShell->DelRight();
1284cdf0e10cSrcweir 		// delete visual representation
1285cdf0e10cSrcweir 		delete pItem->pPostIt;
1286cdf0e10cSrcweir 		// delete struct saving the pointers
1287cdf0e10cSrcweir 		delete pItem;
1288cdf0e10cSrcweir 	}
1289cdf0e10cSrcweir 	mvPostItFlds.clear();
1290cdf0e10cSrcweir */
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir     mpWrtShell->EndUndo();
1293cdf0e10cSrcweir 	PrepareView();
1294cdf0e10cSrcweir 	mpWrtShell->EndAllAction();
1295cdf0e10cSrcweir 	mbLayout = true;
1296cdf0e10cSrcweir 	CalcRects();
1297cdf0e10cSrcweir 	LayoutPostIts();
1298cdf0e10cSrcweir }
1299cdf0e10cSrcweir #if 0
1300cdf0e10cSrcweir void SwPostItMgr::Hide(SwPostItField* pPostItField )
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 		if ((*i)->GetFmtFld())
1305cdf0e10cSrcweir 		{
1306cdf0e10cSrcweir 			SwPostItField* pField = static_cast<SwPostItField*>((*i)->GetFmtFld()->GetFld());
1307cdf0e10cSrcweir 			if (pPostItField==pField)
1308cdf0e10cSrcweir 			{
1309cdf0e10cSrcweir 				(*i)->bShow = false;
1310cdf0e10cSrcweir 				(*i)->pPostIt->HideNote();
1311cdf0e10cSrcweir 				break;
1312cdf0e10cSrcweir 			}
1313cdf0e10cSrcweir 		}
1314cdf0e10cSrcweir 	}
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 	LayoutPostIts();
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir #endif
1319cdf0e10cSrcweir void SwPostItMgr::Hide( const String& rAuthor )
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir     for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1322cdf0e10cSrcweir 	{
1323cdf0e10cSrcweir 		if ( (*i)->pPostIt && ((*i)->pPostIt->GetAuthor() == rAuthor) )
1324cdf0e10cSrcweir 		{
1325cdf0e10cSrcweir 			(*i)->bShow	 = false;
1326cdf0e10cSrcweir 			(*i)->pPostIt->HideNote();
1327cdf0e10cSrcweir 		}
1328cdf0e10cSrcweir 	}
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 	LayoutPostIts();
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir void SwPostItMgr::Hide()
1334cdf0e10cSrcweir {
1335cdf0e10cSrcweir     for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1336cdf0e10cSrcweir 	{
1337cdf0e10cSrcweir 		(*i)->bShow = false;
1338cdf0e10cSrcweir 		(*i)->pPostIt->HideNote();
1339cdf0e10cSrcweir 	}
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir void SwPostItMgr::Show()
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir     for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1346cdf0e10cSrcweir 	{
1347cdf0e10cSrcweir 		(*i)->bShow = true;
1348cdf0e10cSrcweir 	}
1349cdf0e10cSrcweir 	LayoutPostIts();
1350cdf0e10cSrcweir }
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir void SwPostItMgr::Sort(const short aType)
1353cdf0e10cSrcweir {
1354cdf0e10cSrcweir 	if (mvPostItFlds.size()>1 )
1355cdf0e10cSrcweir 	{
1356cdf0e10cSrcweir 		switch (aType)
1357cdf0e10cSrcweir 		{
1358cdf0e10cSrcweir 			case SORT_POS:
1359cdf0e10cSrcweir 				mvPostItFlds.sort(comp_pos);
1360cdf0e10cSrcweir 				break;
1361cdf0e10cSrcweir 			/*
1362cdf0e10cSrcweir 			case SORT_AUTHOR:
1363cdf0e10cSrcweir 				mvPostItFlds.sort(comp_author);
1364cdf0e10cSrcweir 				break;
1365cdf0e10cSrcweir 			case SORT_DATE:
1366cdf0e10cSrcweir 				mvPostItFlds.sort(comp_date);
1367cdf0e10cSrcweir 				break;
1368cdf0e10cSrcweir 			*/
1369cdf0e10cSrcweir 		}
1370cdf0e10cSrcweir 	}
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir SwSidebarWin* SwPostItMgr::GetSidebarWin( const SfxBroadcaster* pBroadcaster) const
1374cdf0e10cSrcweir {
1375cdf0e10cSrcweir 	for(const_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1376cdf0e10cSrcweir 	{
1377cdf0e10cSrcweir 		if ( (*i)->GetBroadCaster() == pBroadcaster)
1378cdf0e10cSrcweir 			return (*i)->pPostIt;
1379cdf0e10cSrcweir 	}
1380cdf0e10cSrcweir 	return NULL;
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir sw::annotation::SwAnnotationWin* SwPostItMgr::GetAnnotationWin(const SwPostItField* pFld) const
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir     for(const_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1386cdf0e10cSrcweir     {
1387cdf0e10cSrcweir         if ( (*i)->GetFmtFld() && ((*i)->GetFmtFld()->GetFld() == pFld))
1388cdf0e10cSrcweir             return dynamic_cast<sw::annotation::SwAnnotationWin*>((*i)->pPostIt);
1389cdf0e10cSrcweir     }
1390cdf0e10cSrcweir     return NULL;
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir SwSidebarWin* SwPostItMgr::GetNextPostIt( sal_uInt16 aDirection,
1394cdf0e10cSrcweir                                           SwSidebarWin* aPostIt )
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir 	if (mvPostItFlds.size()>1)
1397cdf0e10cSrcweir 	{
1398cdf0e10cSrcweir         for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1399cdf0e10cSrcweir 		{
1400cdf0e10cSrcweir 			if ( (*i)->pPostIt ==aPostIt)
1401cdf0e10cSrcweir 			{
1402cdf0e10cSrcweir                 SwSidebarItem_iterator iNextPostIt  = i;
1403cdf0e10cSrcweir 				if (aDirection==KEY_PAGEUP)
1404cdf0e10cSrcweir 				{
1405cdf0e10cSrcweir 					if ( iNextPostIt==mvPostItFlds.begin() )
1406cdf0e10cSrcweir 					{
1407cdf0e10cSrcweir 						return NULL;
1408cdf0e10cSrcweir 					}
1409cdf0e10cSrcweir 					--iNextPostIt;
1410cdf0e10cSrcweir 				}
1411cdf0e10cSrcweir 				else
1412cdf0e10cSrcweir 				{
1413cdf0e10cSrcweir 					iNextPostIt++;
1414cdf0e10cSrcweir 					if ( iNextPostIt==mvPostItFlds.end() )
1415cdf0e10cSrcweir 					{
1416cdf0e10cSrcweir 						return NULL;
1417cdf0e10cSrcweir 					}
1418cdf0e10cSrcweir 				}
1419cdf0e10cSrcweir 				// lets quit, we are back at the beginng
1420cdf0e10cSrcweir 				if ( (*iNextPostIt)->pPostIt==aPostIt)
1421cdf0e10cSrcweir 					return NULL;
1422cdf0e10cSrcweir 				return (*iNextPostIt)->pPostIt;
1423cdf0e10cSrcweir 			}
1424cdf0e10cSrcweir 		}
1425cdf0e10cSrcweir 		return NULL;
1426cdf0e10cSrcweir 	}
1427cdf0e10cSrcweir 	else
1428cdf0e10cSrcweir 		return NULL;
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir long SwPostItMgr::GetNextBorder()
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir 	for (unsigned long n=0;n<mPages.size();n++)
1434cdf0e10cSrcweir 	{
1435cdf0e10cSrcweir         for(SwSidebarItem_iterator b = mPages[n]->mList->begin(); b!= mPages[n]->mList->end(); b++)
1436cdf0e10cSrcweir 		{
1437cdf0e10cSrcweir 			if ((*b)->pPostIt == mpActivePostIt)
1438cdf0e10cSrcweir 			{
1439cdf0e10cSrcweir                 SwSidebarItem_iterator aNext = b;
1440cdf0e10cSrcweir 				aNext++;
1441cdf0e10cSrcweir 				bool bFollow = (aNext == mPages[n]->mList->end()) ? false : (*aNext)->pPostIt->IsFollow();
1442cdf0e10cSrcweir 				if ( mPages[n]->bScrollbar || bFollow )
1443cdf0e10cSrcweir 				{
1444cdf0e10cSrcweir 					return -1;
1445cdf0e10cSrcweir 				}
1446cdf0e10cSrcweir 				else
1447cdf0e10cSrcweir 				{
1448cdf0e10cSrcweir 					//if this is the last item, return the bottom border otherwise the next item
1449cdf0e10cSrcweir 					if (aNext == mPages[n]->mList->end())
1450cdf0e10cSrcweir 						return mpEditWin->LogicToPixel(Point(0,mPages[n]->mPageRect.Bottom())).Y() - GetSpaceBetween();
1451cdf0e10cSrcweir 					else
1452cdf0e10cSrcweir 						return (*aNext)->pPostIt->GetPosPixel().Y() - GetSpaceBetween();
1453cdf0e10cSrcweir 				}
1454cdf0e10cSrcweir 			}
1455cdf0e10cSrcweir 		}
1456cdf0e10cSrcweir 	}
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir 	DBG_ERROR("SwPostItMgr::GetNextBorder(): We have to find a next border here");
1459cdf0e10cSrcweir 	return -1;
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir void SwPostItMgr::SetShadowState(const SwPostItField* pFld,bool bCursor)
1463cdf0e10cSrcweir {
1464cdf0e10cSrcweir 	if (pFld)
1465cdf0e10cSrcweir 	{
1466cdf0e10cSrcweir 		if (pFld !=mShadowState.mpShadowFld)
1467cdf0e10cSrcweir 		{
1468cdf0e10cSrcweir 			if (mShadowState.mpShadowFld)
1469cdf0e10cSrcweir 			{
1470cdf0e10cSrcweir 				// reset old one if still alive
1471cdf0e10cSrcweir 				// TODO: does not work properly if mouse and cursor was set
1472cdf0e10cSrcweir                 sw::annotation::SwAnnotationWin* pOldPostIt =
1473cdf0e10cSrcweir                                     GetAnnotationWin(mShadowState.mpShadowFld);
1474cdf0e10cSrcweir 				if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1475cdf0e10cSrcweir                     pOldPostIt->SetViewState(VS_NORMAL);
1476cdf0e10cSrcweir 			}
1477cdf0e10cSrcweir 			//set new one, if it is not currently edited
1478cdf0e10cSrcweir             sw::annotation::SwAnnotationWin* pNewPostIt = GetAnnotationWin(pFld);
1479cdf0e10cSrcweir 			if (pNewPostIt && pNewPostIt->Shadow() && (pNewPostIt->Shadow()->GetShadowState() != SS_EDIT))
1480cdf0e10cSrcweir 			{
1481cdf0e10cSrcweir                 pNewPostIt->SetViewState(VS_VIEW);
1482cdf0e10cSrcweir 				//remember our new field
1483cdf0e10cSrcweir 				mShadowState.mpShadowFld = pFld;
1484cdf0e10cSrcweir 				mShadowState.bCursor = false;
1485cdf0e10cSrcweir 				mShadowState.bMouse = false;
1486cdf0e10cSrcweir 			}
1487cdf0e10cSrcweir 		}
1488cdf0e10cSrcweir 		if (bCursor)
1489cdf0e10cSrcweir 			mShadowState.bCursor = true;
1490cdf0e10cSrcweir 		else
1491cdf0e10cSrcweir 			mShadowState.bMouse = true;
1492cdf0e10cSrcweir 	}
1493cdf0e10cSrcweir 	else
1494cdf0e10cSrcweir 	{
1495cdf0e10cSrcweir 		if (mShadowState.mpShadowFld)
1496cdf0e10cSrcweir 		{
1497cdf0e10cSrcweir 			if (bCursor)
1498cdf0e10cSrcweir 				mShadowState.bCursor = false;
1499cdf0e10cSrcweir 			else
1500cdf0e10cSrcweir 				mShadowState.bMouse = false;
1501cdf0e10cSrcweir 			if (!mShadowState.bCursor && !mShadowState.bMouse)
1502cdf0e10cSrcweir 			{
1503cdf0e10cSrcweir 				// reset old one if still alive
1504cdf0e10cSrcweir                 sw::annotation::SwAnnotationWin* pOldPostIt = GetAnnotationWin(mShadowState.mpShadowFld);
1505cdf0e10cSrcweir 				if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1506cdf0e10cSrcweir 				{
1507cdf0e10cSrcweir                     pOldPostIt->SetViewState(VS_NORMAL);
1508cdf0e10cSrcweir 					mShadowState.mpShadowFld = 0;
1509cdf0e10cSrcweir 				}
1510cdf0e10cSrcweir 			}
1511cdf0e10cSrcweir 		}
1512cdf0e10cSrcweir 	}
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir void SwPostItMgr::PrepareView(bool bIgnoreCount)
1516cdf0e10cSrcweir {
1517cdf0e10cSrcweir 	if (!HasNotes() || bIgnoreCount)
1518cdf0e10cSrcweir 	{
1519cdf0e10cSrcweir 		mpWrtShell->StartAllAction();
1520cdf0e10cSrcweir 		//mpEditWin->Invalidate(); // really not needed anymore??
1521cdf0e10cSrcweir 		SwRootFrm* pLayout = mpWrtShell->GetLayout();
1522cdf0e10cSrcweir         if ( pLayout )
1523cdf0e10cSrcweir             SwPostItHelper::setSidebarChanged( pLayout,
1524cdf0e10cSrcweir                 mpWrtShell->getIDocumentSettingAccess()->get( IDocumentSettingAccess::BROWSE_MODE ) );
1525cdf0e10cSrcweir 		mpWrtShell->EndAllAction();
1526cdf0e10cSrcweir 	}
1527cdf0e10cSrcweir }
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir bool SwPostItMgr::ShowScrollbar(const unsigned long aPage) const
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir 	if (mPages.size() > aPage-1)
1532cdf0e10cSrcweir 		return (mPages[aPage-1]->bScrollbar && !mbWaitingForCalcRects);
1533cdf0e10cSrcweir 	else
1534cdf0e10cSrcweir 		return false;
1535cdf0e10cSrcweir }
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir bool SwPostItMgr::IsHit(const Point &aPointPixel)
1538cdf0e10cSrcweir {
1539cdf0e10cSrcweir 	if (HasNotes() && ShowNotes())
1540cdf0e10cSrcweir 	{
1541cdf0e10cSrcweir 		const Point aPoint = mpEditWin->PixelToLogic(aPointPixel);
1542cdf0e10cSrcweir         const SwRootFrm* pLayout = mpWrtShell->GetLayout();
1543cdf0e10cSrcweir         SwRect aPageFrm;
1544cdf0e10cSrcweir 		const unsigned long nPageNum = SwPostItHelper::getPageInfo( aPageFrm, pLayout, aPoint );
1545cdf0e10cSrcweir 	    if( nPageNum )
1546cdf0e10cSrcweir 		{
1547cdf0e10cSrcweir 			Rectangle aRect;
1548cdf0e10cSrcweir 			DBG_ASSERT(mPages.size()>nPageNum-1,"SwPostitMgr:: page container size wrong");
1549cdf0e10cSrcweir             aRect = mPages[nPageNum-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1550cdf0e10cSrcweir                     ? Rectangle(Point(aPageFrm.Left()-GetSidebarWidth()-GetSidebarBorderWidth(),aPageFrm.Top()),Size(GetSidebarWidth(),aPageFrm.Height()))
1551cdf0e10cSrcweir                     : Rectangle( Point(aPageFrm.Right()+GetSidebarBorderWidth(),aPageFrm.Top()) , Size(GetSidebarWidth(),aPageFrm.Height()));
1552cdf0e10cSrcweir 			if (aRect.IsInside(aPoint))
1553cdf0e10cSrcweir 			{
1554cdf0e10cSrcweir 				// we hit the note's sidebar
1555cdf0e10cSrcweir 				// lets now test for the arrow area
1556cdf0e10cSrcweir 				if (mPages[nPageNum-1]->bScrollbar)
1557cdf0e10cSrcweir 					return ScrollbarHit(nPageNum,aPoint);
1558cdf0e10cSrcweir 				else
1559cdf0e10cSrcweir 					return false;
1560cdf0e10cSrcweir 			}
1561cdf0e10cSrcweir 		}
1562cdf0e10cSrcweir 	}
1563cdf0e10cSrcweir 	return false;
1564cdf0e10cSrcweir }
1565cdf0e10cSrcweir Rectangle SwPostItMgr::GetBottomScrollRect(const unsigned long aPage) const
1566cdf0e10cSrcweir {
1567cdf0e10cSrcweir 	SwRect aPageRect = mPages[aPage-1]->mPageRect;
1568cdf0e10cSrcweir     Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1569cdf0e10cSrcweir                          ? Point(aPageRect.Left() - GetSidebarWidth() - GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
1570cdf0e10cSrcweir                          : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
1571cdf0e10cSrcweir 	Size aSize(GetSidebarWidth() - mpEditWin->PixelToLogic(Size(4,0)).Width(), mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height()) ;
1572cdf0e10cSrcweir 	return Rectangle(aPointBottom,aSize);
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir }
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir Rectangle SwPostItMgr::GetTopScrollRect(const unsigned long aPage) const
1577cdf0e10cSrcweir {
1578cdf0e10cSrcweir 	SwRect aPageRect = mPages[aPage-1]->mPageRect;
1579cdf0e10cSrcweir     Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1580cdf0e10cSrcweir                       ? Point(aPageRect.Left() - GetSidebarWidth() -GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
1581cdf0e10cSrcweir                       : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
1582cdf0e10cSrcweir 	Size aSize(GetSidebarWidth() - mpEditWin->PixelToLogic(Size(4,0)).Width(), mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height()) ;
1583cdf0e10cSrcweir 	return Rectangle(aPointTop,aSize);
1584cdf0e10cSrcweir }
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir //IMPORTANT: if you change the rects here, also change SwPageFrm::PaintNotesSidebar()
1588cdf0e10cSrcweir bool SwPostItMgr::ScrollbarHit(const unsigned long aPage,const Point &aPoint)
1589cdf0e10cSrcweir {
1590cdf0e10cSrcweir 	SwRect aPageRect = mPages[aPage-1]->mPageRect;
1591cdf0e10cSrcweir     Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1592cdf0e10cSrcweir                          ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
1593cdf0e10cSrcweir                          : Point(aPageRect.Right() + GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
1594cdf0e10cSrcweir 
1595cdf0e10cSrcweir     Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1596cdf0e10cSrcweir                       ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
1597cdf0e10cSrcweir                       : Point(aPageRect.Right()+GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir 	Rectangle aRectBottom(GetBottomScrollRect(aPage));
1600cdf0e10cSrcweir 	Rectangle aRectTop(GetTopScrollRect(aPage));
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 	if (aRectBottom.IsInside(aPoint))
1603cdf0e10cSrcweir 	{
1604cdf0e10cSrcweir 		if (aPoint.X() < long((aPointBottom.X() + GetSidebarWidth()/3)))
1605cdf0e10cSrcweir 			Scroll( GetScrollSize(),aPage);
1606cdf0e10cSrcweir 		else
1607cdf0e10cSrcweir 			Scroll( -1*GetScrollSize(), aPage);
1608cdf0e10cSrcweir 		return true;
1609cdf0e10cSrcweir 	}
1610cdf0e10cSrcweir 	else
1611cdf0e10cSrcweir 	if (aRectTop.IsInside(aPoint))
1612cdf0e10cSrcweir 	{
1613cdf0e10cSrcweir 		if (aPoint.X() < long((aPointTop.X() + GetSidebarWidth()/3*2)))
1614cdf0e10cSrcweir 			Scroll(GetScrollSize(), aPage);
1615cdf0e10cSrcweir 		else
1616cdf0e10cSrcweir 			Scroll(-1*GetScrollSize(), aPage);
1617cdf0e10cSrcweir 		return true;
1618cdf0e10cSrcweir 	}
1619cdf0e10cSrcweir 	return false;
1620cdf0e10cSrcweir }
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir void SwPostItMgr::CorrectPositions()
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir    if ( mbWaitingForCalcRects || mbLayouting || mvPostItFlds.empty() )
1625cdf0e10cSrcweir        return;
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir    // find first valid note
1628cdf0e10cSrcweir    SwSidebarWin *pFirstPostIt = 0;
1629cdf0e10cSrcweir    for(SwSidebarItem_iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1630cdf0e10cSrcweir    {
1631cdf0e10cSrcweir 	   pFirstPostIt = (*i)->pPostIt;
1632cdf0e10cSrcweir 	   if (pFirstPostIt)
1633cdf0e10cSrcweir 			break;
1634cdf0e10cSrcweir    }
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir    //if we have not found a valid note, forget about it and leave
1637cdf0e10cSrcweir    if (!pFirstPostIt)
1638cdf0e10cSrcweir 	   return;
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir     // yeah, I know,    if this is a left page it could be wrong, but finding the page and the note is probably not even faster than just doing it
1641cdf0e10cSrcweir     // --> OD 2010-06-03 #i111964# - check, if anchor overlay object exists.
1642cdf0e10cSrcweir     const long aAnchorX = pFirstPostIt->Anchor()
1643cdf0e10cSrcweir                           ? mpEditWin->LogicToPixel( Point((long)(pFirstPostIt->Anchor()->GetSixthPosition().getX()),0)).X()
1644cdf0e10cSrcweir                           : 0;
1645cdf0e10cSrcweir     const long aAnchorY = pFirstPostIt->Anchor()
1646cdf0e10cSrcweir                           ? mpEditWin->LogicToPixel( Point(0,(long)(pFirstPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1
1647cdf0e10cSrcweir                           : 0;
1648cdf0e10cSrcweir     // <--
1649cdf0e10cSrcweir     if (Point(aAnchorX,aAnchorY) != pFirstPostIt->GetPosPixel())
1650cdf0e10cSrcweir     {
1651cdf0e10cSrcweir         long aAnchorPosX = 0;
1652cdf0e10cSrcweir         long aAnchorPosY = 0;
1653cdf0e10cSrcweir         for (unsigned long n=0;n<mPages.size();n++)
1654cdf0e10cSrcweir         {
1655cdf0e10cSrcweir             for(SwSidebarItem_iterator i = mPages[n]->mList->begin(); i!= mPages[n]->mList->end(); i++)
1656cdf0e10cSrcweir             {
1657cdf0e10cSrcweir                 // --> OD 2010-06-03 #i111964# - check, if anchor overlay object exists.
1658cdf0e10cSrcweir                 if ( (*i)->bShow && (*i)->pPostIt && (*i)->pPostIt->Anchor() )
1659cdf0e10cSrcweir                 // <--
1660cdf0e10cSrcweir                 {
1661cdf0e10cSrcweir                     aAnchorPosX = mPages[n]->eSidebarPosition == sw::sidebarwindows::SIDEBAR_LEFT
1662cdf0e10cSrcweir                         ? mpEditWin->LogicToPixel( Point((long)((*i)->pPostIt->Anchor()->GetSeventhPosition().getX()),0)).X()
1663cdf0e10cSrcweir                         : mpEditWin->LogicToPixel( Point((long)((*i)->pPostIt->Anchor()->GetSixthPosition().getX()),0)).X();
1664cdf0e10cSrcweir                     aAnchorPosY = mpEditWin->LogicToPixel( Point(0,(long)((*i)->pPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1;
1665cdf0e10cSrcweir                     (*i)->pPostIt->SetPosPixel(Point(aAnchorPosX,aAnchorPosY));
1666cdf0e10cSrcweir 			   }
1667cdf0e10cSrcweir             }
1668cdf0e10cSrcweir         }
1669cdf0e10cSrcweir     }
1670cdf0e10cSrcweir }
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir bool SwPostItMgr::ShowNotes() const
1674cdf0e10cSrcweir {
1675cdf0e10cSrcweir 	// we only want to see notes if Options - Writer - View - Notes is ticked
1676cdf0e10cSrcweir 	return mpWrtShell->GetViewOptions()->IsPostIts();
1677cdf0e10cSrcweir }
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir bool SwPostItMgr::HasNotes() const
1680cdf0e10cSrcweir {
1681cdf0e10cSrcweir 	return !mvPostItFlds.empty();
1682cdf0e10cSrcweir }
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir unsigned long SwPostItMgr::GetSidebarWidth(bool bPx) const
1685cdf0e10cSrcweir {
1686cdf0e10cSrcweir 	unsigned long aWidth = (unsigned long)(mpWrtShell->GetViewOptions()->GetZoom() * 1.8);
1687cdf0e10cSrcweir 	if (bPx)
1688cdf0e10cSrcweir 		return aWidth;
1689cdf0e10cSrcweir 	else
1690cdf0e10cSrcweir 		return mpEditWin->PixelToLogic(Size( aWidth ,0)).Width();
1691cdf0e10cSrcweir }
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir unsigned long SwPostItMgr::GetSidebarBorderWidth(bool bPx) const
1694cdf0e10cSrcweir {
1695cdf0e10cSrcweir 	if (bPx)
1696cdf0e10cSrcweir 		return 2;
1697cdf0e10cSrcweir 	else
1698cdf0e10cSrcweir 		return mpEditWin->PixelToLogic(Size(2,0)).Width();
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir unsigned long SwPostItMgr::GetNoteWidth()
1702cdf0e10cSrcweir {
1703cdf0e10cSrcweir 	return GetSidebarWidth(true);
1704cdf0e10cSrcweir }
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir Color SwPostItMgr::GetColorDark(sal_uInt16 aAuthorIndex)
1707cdf0e10cSrcweir {
1708cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1709cdf0e10cSrcweir 	{
1710cdf0e10cSrcweir 		static const Color aArrayNormal[] = {
1711cdf0e10cSrcweir 			COL_AUTHOR1_NORMAL,		COL_AUTHOR2_NORMAL,		COL_AUTHOR3_NORMAL,
1712cdf0e10cSrcweir 			COL_AUTHOR4_NORMAL,		COL_AUTHOR5_NORMAL,		COL_AUTHOR6_NORMAL,
1713cdf0e10cSrcweir 			COL_AUTHOR7_NORMAL,		COL_AUTHOR8_NORMAL,		COL_AUTHOR9_NORMAL };
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir 		return Color( aArrayNormal[ aAuthorIndex % (sizeof( aArrayNormal )/ sizeof( aArrayNormal[0] ))]);
1716cdf0e10cSrcweir 	}
1717cdf0e10cSrcweir 	else
1718cdf0e10cSrcweir 		return Color(COL_WHITE);
1719cdf0e10cSrcweir }
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir Color SwPostItMgr::GetColorLight(sal_uInt16 aAuthorIndex)
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1724cdf0e10cSrcweir 	{
1725cdf0e10cSrcweir 		static const Color aArrayLight[] = {
1726cdf0e10cSrcweir 			COL_AUTHOR1_LIGHT,		COL_AUTHOR2_LIGHT,		COL_AUTHOR3_LIGHT,
1727cdf0e10cSrcweir 			COL_AUTHOR4_LIGHT,		COL_AUTHOR5_LIGHT,		COL_AUTHOR6_LIGHT,
1728cdf0e10cSrcweir 			COL_AUTHOR7_LIGHT,		COL_AUTHOR8_LIGHT,		COL_AUTHOR9_LIGHT };
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir 		return Color( aArrayLight[ aAuthorIndex % (sizeof( aArrayLight )/ sizeof( aArrayLight[0] ))]);
1731cdf0e10cSrcweir 	}
1732cdf0e10cSrcweir 	else
1733cdf0e10cSrcweir 		return Color(COL_WHITE);
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir Color SwPostItMgr::GetColorAnchor(sal_uInt16 aAuthorIndex)
1737cdf0e10cSrcweir {
1738cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1739cdf0e10cSrcweir 	{
1740cdf0e10cSrcweir         static const Color aArrayAnchor[] = {
1741cdf0e10cSrcweir 			COL_AUTHOR1_DARK,		COL_AUTHOR2_DARK,		COL_AUTHOR3_DARK,
1742cdf0e10cSrcweir 			COL_AUTHOR4_DARK,		COL_AUTHOR5_DARK,		COL_AUTHOR6_DARK,
1743cdf0e10cSrcweir 			COL_AUTHOR7_DARK,		COL_AUTHOR8_DARK,		COL_AUTHOR9_DARK };
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir         return Color( aArrayAnchor[  aAuthorIndex % (sizeof( aArrayAnchor )  / sizeof( aArrayAnchor[0] ))]);
1746cdf0e10cSrcweir 	}
1747cdf0e10cSrcweir 	else
1748cdf0e10cSrcweir 		return Color(COL_WHITE);
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir 
1751cdf0e10cSrcweir void SwPostItMgr::SetActiveSidebarWin( SwSidebarWin* p)
1752cdf0e10cSrcweir {
1753cdf0e10cSrcweir 	if ( p != mpActivePostIt )
1754cdf0e10cSrcweir 	{
1755cdf0e10cSrcweir 		// we need the temp variable so we can set mpActivePostIt before we call DeactivatePostIt
1756cdf0e10cSrcweir 		// therefore we get a new layout in DOCCHANGED when switching from postit to document,
1757cdf0e10cSrcweir 		// otherwise, GetActivePostIt() would still hold our old postit
1758cdf0e10cSrcweir         SwSidebarWin* pActive = mpActivePostIt;
1759cdf0e10cSrcweir 		mpActivePostIt = p;
1760cdf0e10cSrcweir 		if (pActive)
1761cdf0e10cSrcweir 		{
1762cdf0e10cSrcweir 			pActive->DeactivatePostIt();
1763cdf0e10cSrcweir 			mShadowState.mpShadowFld = 0;
1764cdf0e10cSrcweir 		}
1765cdf0e10cSrcweir 		if (mpActivePostIt)
1766cdf0e10cSrcweir 		{
1767cdf0e10cSrcweir 			mpActivePostIt->GotoPos();
1768cdf0e10cSrcweir 			mpView->AttrChangedNotify(0);
1769cdf0e10cSrcweir 			mpActivePostIt->ActivatePostIt();
1770cdf0e10cSrcweir 		}
1771cdf0e10cSrcweir 	}
1772cdf0e10cSrcweir }
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir IMPL_LINK( SwPostItMgr, CalcHdl, void*, /* pVoid*/  )
1775cdf0e10cSrcweir {
1776cdf0e10cSrcweir 	mnEventId = 0;
1777cdf0e10cSrcweir 	if ( mbLayouting )
1778cdf0e10cSrcweir 	{
1779cdf0e10cSrcweir 		DBG_ERROR("Reentrance problem in Layout Manager!");
1780cdf0e10cSrcweir 		mbWaitingForCalcRects = false;
1781cdf0e10cSrcweir 		return 0;
1782cdf0e10cSrcweir 	}
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir 	// do not change order, even if it would seem so in the first place, we need the calcrects always
1785cdf0e10cSrcweir 	if (CalcRects() || mbLayout)
1786cdf0e10cSrcweir 	{
1787cdf0e10cSrcweir 		mbLayout = false;
1788cdf0e10cSrcweir 		LayoutPostIts();
1789cdf0e10cSrcweir 	}
1790cdf0e10cSrcweir 	return 0;
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir void SwPostItMgr::Rescale()
1794cdf0e10cSrcweir {
1795cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1796cdf0e10cSrcweir 		if ( (*i)->pPostIt )
1797cdf0e10cSrcweir 			(*i)->pPostIt->Rescale();
1798cdf0e10cSrcweir }
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir sal_Int32 SwPostItMgr::GetInitialAnchorDistance() const
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir 	const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
1803cdf0e10cSrcweir     return POSTIT_INITIAL_ANCHOR_DISTANCE * f.GetNumerator() / f.GetDenominator();
1804cdf0e10cSrcweir }
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir sal_Int32 SwPostItMgr::GetSpaceBetween() const
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir 	const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
1809cdf0e10cSrcweir 	return ( POSTIT_SPACE_BETWEEN ) * f.GetNumerator() / f.GetDenominator();
1810cdf0e10cSrcweir }
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir sal_Int32 SwPostItMgr::GetScrollSize() const
1813cdf0e10cSrcweir {
1814cdf0e10cSrcweir 	const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
1815cdf0e10cSrcweir 	return ( POSTIT_SPACE_BETWEEN + POSTIT_MINIMUMSIZE_WITH_META ) * f.GetNumerator() / f.GetDenominator();
1816cdf0e10cSrcweir }
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir sal_Int32 SwPostItMgr::GetMinimumSizeWithMeta() const
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir 	const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
1821cdf0e10cSrcweir 	return POSTIT_MINIMUMSIZE_WITH_META * f.GetNumerator() / f.GetDenominator();
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir sal_Int32 SwPostItMgr::GetSidebarScrollerHeight() const
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir 	const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
1827cdf0e10cSrcweir 	return POSTIT_SCROLL_SIDEBAR_HEIGHT * f.GetNumerator() / f.GetDenominator();
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir void SwPostItMgr::SetSpellChecking()
1831cdf0e10cSrcweir {
1832cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1833cdf0e10cSrcweir 		if ( (*i)->pPostIt )
1834cdf0e10cSrcweir 			(*i)->pPostIt->SetSpellChecking();
1835cdf0e10cSrcweir }
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir void SwPostItMgr::SetReadOnlyState()
1838cdf0e10cSrcweir {
1839cdf0e10cSrcweir     for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1840cdf0e10cSrcweir 		if ( (*i)->pPostIt )
1841cdf0e10cSrcweir 			(*i)->pPostIt->SetReadonly( mbReadOnly );
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir void SwPostItMgr::CheckMetaText()
1845cdf0e10cSrcweir {
1846cdf0e10cSrcweir         for(std::list<SwSidebarItem*>::iterator i = mvPostItFlds.begin(); i!= mvPostItFlds.end() ; i++)
1847cdf0e10cSrcweir                 if ( (*i)->pPostIt )
1848cdf0e10cSrcweir                        (*i)->pPostIt->CheckMetaText();
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir }
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir sal_uInt16 SwPostItMgr::Replace(SvxSearchItem* pItem)
1853cdf0e10cSrcweir {
1854cdf0e10cSrcweir     SwSidebarWin* pWin = GetActiveSidebarWin();
1855cdf0e10cSrcweir     sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( *pItem );
1856cdf0e10cSrcweir 	if (!aResult)
1857cdf0e10cSrcweir         SetActiveSidebarWin(0);
1858cdf0e10cSrcweir 	return aResult;
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir sal_uInt16 SwPostItMgr::FinishSearchReplace(const ::com::sun::star::util::SearchOptions& rSearchOptions, bool bSrchForward)
1862cdf0e10cSrcweir {
1863cdf0e10cSrcweir     SwSidebarWin* pWin = GetActiveSidebarWin();
1864cdf0e10cSrcweir 	SvxSearchItem aItem(SID_SEARCH_ITEM );
1865cdf0e10cSrcweir 	aItem.SetSearchOptions(rSearchOptions);
1866cdf0e10cSrcweir 	aItem.SetBackward(!bSrchForward);
1867cdf0e10cSrcweir     sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
1868cdf0e10cSrcweir 	if (!aResult)
1869cdf0e10cSrcweir         SetActiveSidebarWin(0);
1870cdf0e10cSrcweir 	return aResult;
1871cdf0e10cSrcweir }
1872cdf0e10cSrcweir 
1873cdf0e10cSrcweir sal_uInt16 SwPostItMgr::SearchReplace(const SwFmtFld &pFld, const ::com::sun::star::util::SearchOptions& rSearchOptions, bool bSrchForward)
1874cdf0e10cSrcweir {
1875cdf0e10cSrcweir 	sal_uInt16 aResult = 0;
1876cdf0e10cSrcweir     SwSidebarWin* pWin = GetSidebarWin(&pFld);
1877cdf0e10cSrcweir 	if (pWin)
1878cdf0e10cSrcweir 	{
1879cdf0e10cSrcweir         ESelection aOldSelection = pWin->GetOutlinerView()->GetSelection();
1880cdf0e10cSrcweir 		if (bSrchForward)
1881cdf0e10cSrcweir             pWin->GetOutlinerView()->SetSelection(ESelection(0,0,0,0));
1882cdf0e10cSrcweir 		else
1883cdf0e10cSrcweir             pWin->GetOutlinerView()->SetSelection(ESelection(0xFFFF,0xFFFF,0xFFFF,0xFFFF));
1884cdf0e10cSrcweir 		SvxSearchItem aItem(SID_SEARCH_ITEM );
1885cdf0e10cSrcweir 		aItem.SetSearchOptions(rSearchOptions);
1886cdf0e10cSrcweir 		aItem.SetBackward(!bSrchForward);
1887cdf0e10cSrcweir         aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
1888cdf0e10cSrcweir 		if (!aResult)
1889cdf0e10cSrcweir             pWin->GetOutlinerView()->SetSelection(aOldSelection);
1890cdf0e10cSrcweir 		else
1891cdf0e10cSrcweir 		{
1892cdf0e10cSrcweir             SetActiveSidebarWin(pWin);
1893cdf0e10cSrcweir 			MakeVisible(pWin);
1894cdf0e10cSrcweir 		}
1895cdf0e10cSrcweir 	}
1896cdf0e10cSrcweir 	return aResult;
1897cdf0e10cSrcweir }
1898cdf0e10cSrcweir 
1899cdf0e10cSrcweir void SwPostItMgr::AssureStdModeAtShell()
1900cdf0e10cSrcweir {
1901cdf0e10cSrcweir 	//#i103373# #i103645#
1902cdf0e10cSrcweir         // deselect any drawing or frame and leave editing mode
1903cdf0e10cSrcweir       	SdrView* pSdrView = mpWrtShell->GetDrawView();
1904cdf0e10cSrcweir         if ( pSdrView && pSdrView->IsTextEdit() )
1905cdf0e10cSrcweir         {
1906cdf0e10cSrcweir         	sal_Bool bLockView = mpWrtShell->IsViewLocked();
1907cdf0e10cSrcweir        		mpWrtShell->LockView( sal_True );
1908cdf0e10cSrcweir         	mpWrtShell->EndTextEdit();
1909cdf0e10cSrcweir                 mpWrtShell->LockView( bLockView );
1910cdf0e10cSrcweir     	}
1911cdf0e10cSrcweir 
1912cdf0e10cSrcweir         if( mpWrtShell->IsSelFrmMode() || mpWrtShell->IsObjSelected())
1913cdf0e10cSrcweir         {
1914cdf0e10cSrcweir                 mpWrtShell->UnSelectFrm();
1915cdf0e10cSrcweir                 mpWrtShell->LeaveSelFrmMode();
1916cdf0e10cSrcweir                 mpWrtShell->GetView().LeaveDrawCreate();
1917cdf0e10cSrcweir                 mpWrtShell->EnterStdMode();
1918cdf0e10cSrcweir 
1919cdf0e10cSrcweir                 mpWrtShell->DrawSelChanged();
1920cdf0e10cSrcweir                 mpView->StopShellTimer();
1921cdf0e10cSrcweir         }
1922cdf0e10cSrcweir }
1923cdf0e10cSrcweir 
1924cdf0e10cSrcweir bool SwPostItMgr::HasActiveSidebarWin() const
1925cdf0e10cSrcweir {
1926cdf0e10cSrcweir     return mpActivePostIt != 0;
1927cdf0e10cSrcweir }
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir bool SwPostItMgr::HasActiveAnnotationWin() const
1930cdf0e10cSrcweir {
1931cdf0e10cSrcweir     return HasActiveSidebarWin() &&
1932cdf0e10cSrcweir            dynamic_cast<sw::annotation::SwAnnotationWin*>(mpActivePostIt) != 0;
1933cdf0e10cSrcweir }
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir void SwPostItMgr::GrabFocusOnActiveSidebarWin()
1936cdf0e10cSrcweir {
1937cdf0e10cSrcweir     if ( HasActiveSidebarWin() )
1938cdf0e10cSrcweir     {
1939cdf0e10cSrcweir         mpActivePostIt->GrabFocus();
1940cdf0e10cSrcweir     }
1941cdf0e10cSrcweir }
1942cdf0e10cSrcweir 
1943cdf0e10cSrcweir void SwPostItMgr::UpdateDataOnActiveSidebarWin()
1944cdf0e10cSrcweir {
1945cdf0e10cSrcweir     if ( HasActiveSidebarWin() )
1946cdf0e10cSrcweir     {
1947cdf0e10cSrcweir         mpActivePostIt->UpdateData();
1948cdf0e10cSrcweir     }
1949cdf0e10cSrcweir }
1950cdf0e10cSrcweir 
1951cdf0e10cSrcweir void SwPostItMgr::DeleteActiveSidebarWin()
1952cdf0e10cSrcweir {
1953cdf0e10cSrcweir     if ( HasActiveSidebarWin() )
1954cdf0e10cSrcweir     {
1955cdf0e10cSrcweir         mpActivePostIt->Delete();
1956cdf0e10cSrcweir     }
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir void SwPostItMgr::HideActiveSidebarWin()
1960cdf0e10cSrcweir {
1961cdf0e10cSrcweir     if ( HasActiveSidebarWin() )
1962cdf0e10cSrcweir     {
1963cdf0e10cSrcweir         mpActivePostIt->Hide();
1964cdf0e10cSrcweir     }
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir void SwPostItMgr::ToggleInsModeOnActiveSidebarWin()
1968cdf0e10cSrcweir {
1969cdf0e10cSrcweir     if ( HasActiveSidebarWin() )
1970cdf0e10cSrcweir     {
1971cdf0e10cSrcweir         mpActivePostIt->ToggleInsMode();
1972cdf0e10cSrcweir     }
1973cdf0e10cSrcweir }
1974cdf0e10cSrcweir 
1975cdf0e10cSrcweir void SwPostItMgr::ConnectSidebarWinToFrm( const SwFrm& rFrm,
1976cdf0e10cSrcweir                                           const SwFmtFld& rFmtFld,
1977cdf0e10cSrcweir                                           SwSidebarWin& rSidebarWin )
1978cdf0e10cSrcweir {
1979cdf0e10cSrcweir     if ( mpFrmSidebarWinContainer == 0 )
1980cdf0e10cSrcweir     {
1981cdf0e10cSrcweir         mpFrmSidebarWinContainer = new SwFrmSidebarWinContainer();
1982cdf0e10cSrcweir     }
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir     const bool bInserted = mpFrmSidebarWinContainer->insert( rFrm, rFmtFld, rSidebarWin );
1985cdf0e10cSrcweir     if ( bInserted &&
1986cdf0e10cSrcweir          mpWrtShell->GetAccessibleMap() )
1987cdf0e10cSrcweir     {
1988cdf0e10cSrcweir         mpWrtShell->GetAccessibleMap()->InvalidatePosOrSize( 0, 0, &rSidebarWin, SwRect() );
1989cdf0e10cSrcweir     }
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir void SwPostItMgr::DisconnectSidebarWinFromFrm( const SwFrm& rFrm,
1993cdf0e10cSrcweir                                                SwSidebarWin& rSidebarWin )
1994cdf0e10cSrcweir {
1995cdf0e10cSrcweir     if ( mpFrmSidebarWinContainer != 0 )
1996cdf0e10cSrcweir     {
1997cdf0e10cSrcweir         const bool bRemoved = mpFrmSidebarWinContainer->remove( rFrm, rSidebarWin );
1998cdf0e10cSrcweir         if ( bRemoved &&
1999cdf0e10cSrcweir              mpWrtShell->GetAccessibleMap() )
2000cdf0e10cSrcweir         {
2001cdf0e10cSrcweir             mpWrtShell->GetAccessibleMap()->Dispose( 0, 0, &rSidebarWin );
2002cdf0e10cSrcweir         }
2003cdf0e10cSrcweir     }
2004cdf0e10cSrcweir }
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir bool SwPostItMgr::HasFrmConnectedSidebarWins( const SwFrm& rFrm )
2007cdf0e10cSrcweir {
2008cdf0e10cSrcweir     bool bRet( false );
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir     if ( mpFrmSidebarWinContainer != 0 )
2011cdf0e10cSrcweir     {
2012cdf0e10cSrcweir         bRet = !mpFrmSidebarWinContainer->empty( rFrm );
2013cdf0e10cSrcweir     }
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir     return bRet;
2016cdf0e10cSrcweir }
2017cdf0e10cSrcweir 
2018cdf0e10cSrcweir Window* SwPostItMgr::GetSidebarWinForFrmByIndex( const SwFrm& rFrm,
2019cdf0e10cSrcweir                                                  const sal_Int32 nIndex )
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir     Window* pSidebarWin( 0 );
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir     if ( mpFrmSidebarWinContainer != 0 )
2024cdf0e10cSrcweir     {
2025cdf0e10cSrcweir         pSidebarWin = mpFrmSidebarWinContainer->get( rFrm, nIndex );
2026cdf0e10cSrcweir     }
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir     return pSidebarWin;
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir void SwPostItMgr::GetAllSidebarWinForFrm( const SwFrm& rFrm,
2032cdf0e10cSrcweir                                           std::vector< Window* >* pChildren )
2033cdf0e10cSrcweir {
2034cdf0e10cSrcweir     if ( mpFrmSidebarWinContainer != 0 )
2035cdf0e10cSrcweir     {
2036cdf0e10cSrcweir         mpFrmSidebarWinContainer->getAll( rFrm, pChildren );
2037cdf0e10cSrcweir     }
2038cdf0e10cSrcweir }
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir void SwNoteProps::Commit() {}
2041cdf0e10cSrcweir void SwNoteProps::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
2042