1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "sddll.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //#include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertyStates.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
32cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
33cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/geometry/RealPoint2D.hpp>
35cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
36cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp>
37cdf0e10cSrcweir #include <svx/svxids.hrc>
38cdf0e10cSrcweir #include <vcl/menu.hxx>
39cdf0e10cSrcweir #include <vcl/msgbox.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <svl/style.hxx>
42cdf0e10cSrcweir #include <svl/itempool.hxx>
43cdf0e10cSrcweir #include <unotools/useroptions.hxx>
44cdf0e10cSrcweir #include <unotools/syslocale.hxx>
45cdf0e10cSrcweir #include <unotools/saveopt.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <tools/datetime.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <sfx2/imagemgr.hxx>
50cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
51cdf0e10cSrcweir #include <sfx2/bindings.hxx>
52cdf0e10cSrcweir #include <sfx2/app.hxx>
53cdf0e10cSrcweir #include <sfx2/request.hxx>
54cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
55cdf0e10cSrcweir #include <sfx2/objface.hxx>
56cdf0e10cSrcweir #include <sfx2/imagemgr.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <editeng/editeng.hxx>
59cdf0e10cSrcweir #include <editeng/eeitem.hxx>
60cdf0e10cSrcweir #include <editeng/fontitem.hxx>
61cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
62cdf0e10cSrcweir #include <editeng/outlobj.hxx>
63cdf0e10cSrcweir #include <editeng/postitem.hxx>
64cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
65cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
66cdf0e10cSrcweir #include <editeng/crsditem.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <svx/svdetc.hxx>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #include "annotationmanager.hxx"
71cdf0e10cSrcweir #include "annotationmanagerimpl.hxx"
72cdf0e10cSrcweir #include "annotationwindow.hxx"
73cdf0e10cSrcweir #include "annotations.hrc"
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #include "ToolBarManager.hxx"
76cdf0e10cSrcweir #include "DrawDocShell.hxx"
77cdf0e10cSrcweir #include "DrawViewShell.hxx"
78cdf0e10cSrcweir #include "DrawController.hxx"
79cdf0e10cSrcweir #include "glob.hrc"
80cdf0e10cSrcweir #include "sdresid.hxx"
81cdf0e10cSrcweir #include "EventMultiplexer.hxx"
82cdf0e10cSrcweir #include "ViewShellManager.hxx"
83cdf0e10cSrcweir #include "helpids.h"
84cdf0e10cSrcweir #include "sdpage.hxx"
85cdf0e10cSrcweir #include "drawdoc.hxx"
86cdf0e10cSrcweir #include "textapi.hxx"
87cdf0e10cSrcweir #include "optsitem.hxx"
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
90cdf0e10cSrcweir using ::rtl::OUString;
91cdf0e10cSrcweir using namespace ::com::sun::star;
92cdf0e10cSrcweir using namespace ::com::sun::star::uno;
93cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
94cdf0e10cSrcweir using namespace ::com::sun::star::document;
95cdf0e10cSrcweir using namespace ::com::sun::star::geometry;
96cdf0e10cSrcweir using namespace ::com::sun::star::container;
97cdf0e10cSrcweir using namespace ::com::sun::star::beans;
98cdf0e10cSrcweir using namespace ::com::sun::star::text;
99cdf0e10cSrcweir using namespace ::com::sun::star::view;
100cdf0e10cSrcweir using namespace ::com::sun::star::style;
101cdf0e10cSrcweir using namespace ::com::sun::star::frame;
102cdf0e10cSrcweir using namespace ::com::sun::star::lang;
103cdf0e10cSrcweir using namespace ::com::sun::star::ui;
104cdf0e10cSrcweir using namespace ::com::sun::star::task;
105cdf0e10cSrcweir using namespace ::com::sun::star::office;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir namespace sd {
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // --------------------------------------------------------------------
110cdf0e10cSrcweir 
111cdf0e10cSrcweir extern TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // --------------------------------------------------------------------
114cdf0e10cSrcweir 
GetAnnotationPool()115cdf0e10cSrcweir SfxItemPool* GetAnnotationPool()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     static SfxItemPool* mpAnnotationPool = 0;
118cdf0e10cSrcweir 	if( mpAnnotationPool == 0 )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		mpAnnotationPool = EditEngine::CreatePool( sal_False );
121cdf0e10cSrcweir 		mpAnnotationPool->SetPoolDefaultItem(SvxFontHeightItem(423,100,EE_CHAR_FONTHEIGHT));
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		Font aAppFont( Application::GetSettings().GetStyleSettings().GetAppFont() );
124cdf0e10cSrcweir 		String EMPTYSTRING;
125cdf0e10cSrcweir 		mpAnnotationPool->SetPoolDefaultItem(SvxFontItem(aAppFont.GetFamily(),aAppFont.GetName(), EMPTYSTRING,PITCH_DONTKNOW,RTL_TEXTENCODING_DONTKNOW,EE_CHAR_FONTINFO));
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	return mpAnnotationPool;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // --------------------------------------------------------------------
132cdf0e10cSrcweir 
getBindings(ViewShellBase & rBase)133cdf0e10cSrcweir static SfxBindings* getBindings( ViewShellBase& rBase )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
136cdf0e10cSrcweir 		return &rBase.GetMainViewShell()->GetViewFrame()->GetBindings();
137cdf0e10cSrcweir 	else
138cdf0e10cSrcweir 		return 0;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // --------------------------------------------------------------------
142cdf0e10cSrcweir 
getDispatcher(ViewShellBase & rBase)143cdf0e10cSrcweir static SfxDispatcher* getDispatcher( ViewShellBase& rBase )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
146cdf0e10cSrcweir 		return rBase.GetMainViewShell()->GetViewFrame()->GetDispatcher();
147cdf0e10cSrcweir 	else
148cdf0e10cSrcweir 		return 0;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
getCurrentDateTime()151cdf0e10cSrcweir com::sun::star::util::DateTime getCurrentDateTime()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     DateTime aCurrentDate;
154cdf0e10cSrcweir     return com::sun::star::util::DateTime( 0, aCurrentDate.GetSec(), aCurrentDate.GetMin(), aCurrentDate.GetHour(), aCurrentDate.GetDay(), aCurrentDate.GetMonth(), aCurrentDate.GetYear() );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
getAnnotationDateTimeString(const Reference<XAnnotation> & xAnnotation)157cdf0e10cSrcweir OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotation )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     OUString sRet;
160cdf0e10cSrcweir     if( xAnnotation.is() )
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir 	    const LocaleDataWrapper& rLocalData = SvtSysLocale().GetLocaleData();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         com::sun::star::util::DateTime aDateTime( xAnnotation->getDateTime() );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	    Date aDate = Date( aDateTime.Day, aDateTime.Month, aDateTime.Year );
167cdf0e10cSrcweir 	    if (aDate==Date())
168cdf0e10cSrcweir 		    sRet = sRet + String(SdResId(STR_ANNOTATION_TODAY));
169cdf0e10cSrcweir 	    else
170cdf0e10cSrcweir 	    if (aDate == Date(Date()-1))
171cdf0e10cSrcweir 		    sRet = sRet + String(SdResId(STR_ANNOTATION_YESTERDAY));
172cdf0e10cSrcweir 	    else
173cdf0e10cSrcweir 	    if (aDate.IsValid() )
174cdf0e10cSrcweir 		    sRet = sRet + rLocalData.getDate(aDate);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         Time aTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds );
177cdf0e10cSrcweir 	    if(aTime.GetTime() != 0)
178cdf0e10cSrcweir 		    sRet = sRet + rtl::OUString::createFromAscii(" ")  + rLocalData.getTime( aTime,false );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir     return sRet;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // --------------------------------------------------------------------
184cdf0e10cSrcweir 
AnnotationManagerImpl(ViewShellBase & rViewShellBase)185cdf0e10cSrcweir AnnotationManagerImpl::AnnotationManagerImpl( ViewShellBase& rViewShellBase )
186cdf0e10cSrcweir : AnnotationManagerImplBase( m_aMutex )
187cdf0e10cSrcweir , mrBase( rViewShellBase )
188cdf0e10cSrcweir , mpDoc( rViewShellBase.GetDocument() )
189cdf0e10cSrcweir , mbShowAnnotations( true )
190cdf0e10cSrcweir , mnUpdateTagsEvent( 0 )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	SdOptions* pOptions = SD_MOD()->GetSdOptions(mpDoc->GetDocumentType());
193cdf0e10cSrcweir 	if( pOptions )
194cdf0e10cSrcweir 	    mbShowAnnotations = pOptions->IsShowComments() == sal_True;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir // --------------------------------------------------------------------
198cdf0e10cSrcweir 
init()199cdf0e10cSrcweir void AnnotationManagerImpl::init()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	// get current controller and initialize listeners
202cdf0e10cSrcweir 	try
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		addListener();
205cdf0e10cSrcweir 		mxView = Reference< XDrawView >::query(mrBase.GetController());
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 	catch( Exception& e )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		(void)e;
210cdf0e10cSrcweir 		DBG_ERROR( "sd::AnnotationManagerImpl::AnnotationManagerImpl(), Exception caught!" );
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     try
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW );
216cdf0e10cSrcweir         Reference<XEventListener> xListener( this );
217cdf0e10cSrcweir         xModel->addEventListener( xListener );
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir     catch( Exception& )
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir // --------------------------------------------------------------------
225cdf0e10cSrcweir 
226cdf0e10cSrcweir // WeakComponentImplHelper1
disposing()227cdf0e10cSrcweir void SAL_CALL AnnotationManagerImpl::disposing ()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     try
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW );
232cdf0e10cSrcweir         Reference<XEventListener> xListener( this );
233cdf0e10cSrcweir         xModel->removeEventListener( xListener );
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir     catch( Exception& )
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	removeListener();
240cdf0e10cSrcweir 	DisposeTags();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     if( mnUpdateTagsEvent )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         Application::RemoveUserEvent( mnUpdateTagsEvent );
245cdf0e10cSrcweir         mnUpdateTagsEvent = 0;
246cdf0e10cSrcweir     }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     mxView.clear();
249cdf0e10cSrcweir     mxCurrentPage.clear();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir // --------------------------------------------------------------------
253cdf0e10cSrcweir 
254cdf0e10cSrcweir // XEventListener
notifyEvent(const::com::sun::star::document::EventObject & aEvent)255cdf0e10cSrcweir void SAL_CALL AnnotationManagerImpl::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     if( aEvent.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnAnnotationInserted") ) ||
258cdf0e10cSrcweir         aEvent.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnAnnotationRemoved") ) ||
259cdf0e10cSrcweir         aEvent.EventName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OnAnnotationChanged" )) )
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         UpdateTags();
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
disposing(const::com::sun::star::lang::EventObject &)265cdf0e10cSrcweir void SAL_CALL AnnotationManagerImpl::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
ShowAnnotations(bool bShow)269cdf0e10cSrcweir void AnnotationManagerImpl::ShowAnnotations( bool bShow )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     // enforce show annotations if a new annotation is inserted
272cdf0e10cSrcweir     if( mbShowAnnotations != bShow )
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         mbShowAnnotations = bShow;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         SdOptions* pOptions = SD_MOD()->GetSdOptions(mpDoc->GetDocumentType());
277cdf0e10cSrcweir        	if( pOptions )
278cdf0e10cSrcweir 	        pOptions->SetShowComments( mbShowAnnotations ? sal_True : sal_False );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         UpdateTags();
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir // --------------------------------------------------------------------
285cdf0e10cSrcweir 
ExecuteAnnotation(SfxRequest & rReq)286cdf0e10cSrcweir void AnnotationManagerImpl::ExecuteAnnotation(SfxRequest& rReq )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir     switch( rReq.GetSlot() )
289cdf0e10cSrcweir     {
290cdf0e10cSrcweir     case SID_INSERT_POSTIT:
291cdf0e10cSrcweir         ExecuteInsertAnnotation( rReq );
292cdf0e10cSrcweir         break;
293cdf0e10cSrcweir 	case SID_DELETE_POSTIT:
294cdf0e10cSrcweir 	case SID_DELETEALL_POSTIT:
295cdf0e10cSrcweir 	case SID_DELETEALLBYAUTHOR_POSTIT:
296cdf0e10cSrcweir 	    ExecuteDeleteAnnotation( rReq );
297cdf0e10cSrcweir         break;
298cdf0e10cSrcweir 	case SID_PREVIOUS_POSTIT:
299cdf0e10cSrcweir 	case SID_NEXT_POSTIT:
300cdf0e10cSrcweir 	    SelectNextAnnotation( rReq.GetSlot() == SID_NEXT_POSTIT );
301cdf0e10cSrcweir         break;
302cdf0e10cSrcweir     case SID_REPLYTO_POSTIT:
303cdf0e10cSrcweir         ExecuteReplyToAnnotation( rReq );
304cdf0e10cSrcweir         break;
305cdf0e10cSrcweir     case SID_SHOW_POSTIT:
306cdf0e10cSrcweir         ShowAnnotations( !mbShowAnnotations );
307cdf0e10cSrcweir         break;
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir // --------------------------------------------------------------------
312cdf0e10cSrcweir 
ExecuteInsertAnnotation(SfxRequest &)313cdf0e10cSrcweir void AnnotationManagerImpl::ExecuteInsertAnnotation(SfxRequest& /*rReq*/)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir     ShowAnnotations(true);
316cdf0e10cSrcweir     InsertAnnotation();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // --------------------------------------------------------------------
320cdf0e10cSrcweir 
ExecuteDeleteAnnotation(SfxRequest & rReq)321cdf0e10cSrcweir void AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest& rReq)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     ShowAnnotations( true );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     const SfxItemSet* pArgs = rReq.GetArgs();
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     switch( rReq.GetSlot() )
328cdf0e10cSrcweir     {
329cdf0e10cSrcweir     case SID_DELETEALL_POSTIT:
330cdf0e10cSrcweir         DeleteAllAnnotations();
331cdf0e10cSrcweir         break;
332cdf0e10cSrcweir     case SID_DELETEALLBYAUTHOR_POSTIT:
333cdf0e10cSrcweir         if( pArgs )
334cdf0e10cSrcweir         {
335cdf0e10cSrcweir 	        const SfxPoolItem*  pPoolItem = NULL;
336cdf0e10cSrcweir 	        if( SFX_ITEM_SET == pArgs->GetItemState( SID_DELETEALLBYAUTHOR_POSTIT, sal_True, &pPoolItem ) )
337cdf0e10cSrcweir 	        {
338cdf0e10cSrcweir 	            OUString sAuthor( (( const SfxStringItem* ) pPoolItem )->GetValue() );
339cdf0e10cSrcweir 		        DeleteAnnotationsByAuthor( sAuthor );
340cdf0e10cSrcweir 		    }
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir         break;
343cdf0e10cSrcweir     case SID_DELETE_POSTIT:
344cdf0e10cSrcweir         {
345cdf0e10cSrcweir             Reference< XAnnotation > xAnnotation;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             if( rReq.GetSlot() == SID_DELETE_POSTIT )
348cdf0e10cSrcweir             {
349cdf0e10cSrcweir                 if( pArgs )
350cdf0e10cSrcweir                 {
351cdf0e10cSrcweir                     const SfxPoolItem*  pPoolItem = NULL;
352cdf0e10cSrcweir                     if( SFX_ITEM_SET == pArgs->GetItemState( SID_DELETE_POSTIT, sal_True, &pPoolItem ) )
353cdf0e10cSrcweir                         ( ( const SfxUnoAnyItem* ) pPoolItem )->GetValue() >>= xAnnotation;
354cdf0e10cSrcweir                 }
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir             if( !xAnnotation.is() )
358cdf0e10cSrcweir                 GetSelectedAnnotation( xAnnotation );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir             DeleteAnnotation( xAnnotation );
361cdf0e10cSrcweir         }
362cdf0e10cSrcweir         break;
363cdf0e10cSrcweir     }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir     UpdateTags();
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir // --------------------------------------------------------------------
369cdf0e10cSrcweir 
InsertAnnotation()370cdf0e10cSrcweir void AnnotationManagerImpl::InsertAnnotation()
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     SdPage* pPage = GetCurrentPage();
373cdf0e10cSrcweir     if( pPage )
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         if( mpDoc->IsUndoEnabled() )
376cdf0e10cSrcweir             mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_INSERT ) ) );
377cdf0e10cSrcweir 
378cdf0e10cSrcweir         // find free space for new annotation
379cdf0e10cSrcweir         int y = 0, x = 0;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir        	AnnotationVector aAnnotations( pPage->getAnnotations() );
382cdf0e10cSrcweir        	if( !aAnnotations.empty() )
383cdf0e10cSrcweir    	    {
384cdf0e10cSrcweir        	    const int page_width = pPage->GetSize().Width();
385cdf0e10cSrcweir             const int width = 1000;
386cdf0e10cSrcweir             const int height = 800;
387cdf0e10cSrcweir             Rectangle aTagRect;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir        	    while( true )
390cdf0e10cSrcweir        	    {
391cdf0e10cSrcweir                 Rectangle aNewRect( x, y, x + width - 1, y + height - 1 );
392cdf0e10cSrcweir        	        bool bFree = true;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir        	        for( AnnotationVector::iterator iter = aAnnotations.begin(); iter != aAnnotations.end(); iter++ )
395cdf0e10cSrcweir        	        {
396cdf0e10cSrcweir        	            RealPoint2D aPoint( (*iter)->getPosition() );
397cdf0e10cSrcweir        	            aTagRect.nLeft   = sal::static_int_cast< long >( aPoint.X * 100.0 );
398cdf0e10cSrcweir        	            aTagRect.nTop    = sal::static_int_cast< long >( aPoint.Y * 100.0 );
399cdf0e10cSrcweir        	            aTagRect.nRight  = aTagRect.nLeft + width - 1;
400cdf0e10cSrcweir        	            aTagRect.nBottom = aTagRect.nTop + height - 1;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir        	            if( aNewRect.IsOver( aTagRect ) )
403cdf0e10cSrcweir        	            {
404cdf0e10cSrcweir        	                bFree = false;
405cdf0e10cSrcweir        	                break;
406cdf0e10cSrcweir        	            }
407cdf0e10cSrcweir        	        }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir        	        if( bFree == false)
410cdf0e10cSrcweir        	        {
411cdf0e10cSrcweir        	            x += width;
412cdf0e10cSrcweir        	            if( x > page_width )
413cdf0e10cSrcweir        	            {
414cdf0e10cSrcweir        	                x = 0;
415cdf0e10cSrcweir        	                y += height;
416cdf0e10cSrcweir        	            }
417cdf0e10cSrcweir        	        }
418cdf0e10cSrcweir        	        else
419cdf0e10cSrcweir        	        {
420cdf0e10cSrcweir        	            break;
421cdf0e10cSrcweir        	        }
422cdf0e10cSrcweir        	    }
423cdf0e10cSrcweir        	}
424cdf0e10cSrcweir 
425cdf0e10cSrcweir         Reference< XAnnotation > xAnnotation;
426cdf0e10cSrcweir         pPage->createAnnotation( xAnnotation );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         // set current author to new annotation
429cdf0e10cSrcweir         SvtUserOptions aUserOptions;
430cdf0e10cSrcweir         xAnnotation->setAuthor( aUserOptions.GetFullName() );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         // set current time to new annotation
433cdf0e10cSrcweir         xAnnotation->setDateTime( getCurrentDateTime() );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir         // set position
436cdf0e10cSrcweir         RealPoint2D aPos( ((double)x) / 100.0, ((double)y) / 100.0 );
437cdf0e10cSrcweir         xAnnotation->setPosition( aPos );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         if( mpDoc->IsUndoEnabled() )
440cdf0e10cSrcweir             mpDoc->EndUndo();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         UpdateTags(true);
443cdf0e10cSrcweir         SelectAnnotation( xAnnotation, true );
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir // --------------------------------------------------------------------
448cdf0e10cSrcweir 
ExecuteReplyToAnnotation(SfxRequest & rReq)449cdf0e10cSrcweir void AnnotationManagerImpl::ExecuteReplyToAnnotation( SfxRequest& rReq )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir     Reference< XAnnotation > xAnnotation;
452cdf0e10cSrcweir     const SfxItemSet* pArgs = rReq.GetArgs();
453cdf0e10cSrcweir     if( pArgs )
454cdf0e10cSrcweir     {
455cdf0e10cSrcweir         const SfxPoolItem*  pPoolItem = NULL;
456cdf0e10cSrcweir         if( SFX_ITEM_SET == pArgs->GetItemState( rReq.GetSlot(), sal_True, &pPoolItem ) )
457cdf0e10cSrcweir 	        ( ( const SfxUnoAnyItem* ) pPoolItem )->GetValue() >>= xAnnotation;
458cdf0e10cSrcweir     }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     TextApiObject* pTextApi = getTextApiObject( xAnnotation );
462cdf0e10cSrcweir     if( pTextApi )
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir 	    std::auto_ptr< ::Outliner > pOutliner( new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT) );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	    mpDoc->SetCalcFieldValueHdl( pOutliner.get() );
467cdf0e10cSrcweir 	    pOutliner->SetUpdateMode( sal_True );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	    String aStr(SdResId(STR_ANNOTATION_REPLY));
470cdf0e10cSrcweir 	    OUString sAuthor( xAnnotation->getAuthor() );
471cdf0e10cSrcweir 	    if( sAuthor.getLength() == 0 )
472cdf0e10cSrcweir 	        sAuthor = String( SdResId( STR_ANNOTATION_NOAUTHOR ) );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir         aStr.SearchAndReplaceAscii("%1", sAuthor);
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         aStr.Append( String(RTL_CONSTASCII_USTRINGPARAM(" (") ) );
477cdf0e10cSrcweir         aStr.Append( String( getAnnotationDateTimeString( xAnnotation ) ) );
478cdf0e10cSrcweir         aStr.Append( String(RTL_CONSTASCII_USTRINGPARAM("): \"") ) );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir         String sQuote( pTextApi->GetText() );
481cdf0e10cSrcweir 
482cdf0e10cSrcweir         if( sQuote.Len() == 0 )
483cdf0e10cSrcweir             sQuote = String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
484cdf0e10cSrcweir         aStr.Append( sQuote );
485cdf0e10cSrcweir         aStr.Append( String(RTL_CONSTASCII_USTRINGPARAM("\"\n") ) );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         sal_uInt16 nParaCount = aStr.GetTokenCount( '\n' );
488cdf0e10cSrcweir         for( sal_uInt16 nPara = 0; nPara < nParaCount; nPara++ )
489cdf0e10cSrcweir             pOutliner->Insert( aStr.GetToken( nPara, '\n' ), LIST_APPEND, -1 );
490cdf0e10cSrcweir 
491cdf0e10cSrcweir         if( pOutliner->GetParagraphCount() > 1 )
492cdf0e10cSrcweir         {
493cdf0e10cSrcweir 	        SfxItemSet aAnswerSet( pOutliner->GetEmptyItemSet() );
494cdf0e10cSrcweir 	        aAnswerSet.Put(SvxPostureItem(ITALIC_NORMAL,EE_CHAR_ITALIC));
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 	        ESelection aSel;
497cdf0e10cSrcweir 	        aSel.nEndPara = (sal_uInt16)pOutliner->GetParagraphCount()-2;
498cdf0e10cSrcweir 	        aSel.nEndPos = pOutliner->GetText( pOutliner->GetParagraph( aSel.nEndPara ) ).Len();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir             pOutliner->QuickSetAttribs( aAnswerSet, aSel );
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         std::auto_ptr< OutlinerParaObject > pOPO( pOutliner->CreateParaObject() );
504cdf0e10cSrcweir         pTextApi->SetText( *pOPO.get() );
505cdf0e10cSrcweir 
506cdf0e10cSrcweir         SvtUserOptions aUserOptions;
507cdf0e10cSrcweir         xAnnotation->setAuthor( aUserOptions.GetFullName() );
508cdf0e10cSrcweir 
509cdf0e10cSrcweir         // set current time to reply
510cdf0e10cSrcweir         xAnnotation->setDateTime( getCurrentDateTime() );
511cdf0e10cSrcweir 
512cdf0e10cSrcweir         UpdateTags(true);
513cdf0e10cSrcweir         SelectAnnotation( xAnnotation, true );
514cdf0e10cSrcweir 	}
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir // --------------------------------------------------------------------
518cdf0e10cSrcweir 
DeleteAnnotation(Reference<XAnnotation> xAnnotation)519cdf0e10cSrcweir void AnnotationManagerImpl::DeleteAnnotation( Reference< XAnnotation > xAnnotation )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     SdPage* pPage = GetCurrentPage();
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     if( xAnnotation.is() && pPage )
524cdf0e10cSrcweir     {
525cdf0e10cSrcweir         if( mpDoc->IsUndoEnabled() )
526cdf0e10cSrcweir             mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_DELETE ) ) );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         pPage->removeAnnotation( xAnnotation );
529cdf0e10cSrcweir 
530cdf0e10cSrcweir         if( mpDoc->IsUndoEnabled() )
531cdf0e10cSrcweir             mpDoc->EndUndo();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir         UpdateTags();
534cdf0e10cSrcweir     }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
DeleteAnnotationsByAuthor(const rtl::OUString & sAuthor)537cdf0e10cSrcweir void AnnotationManagerImpl::DeleteAnnotationsByAuthor( const rtl::OUString& sAuthor )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir     if( mpDoc->IsUndoEnabled() )
540cdf0e10cSrcweir         mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_DELETE ) ) );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir     SdPage* pPage = 0;
543cdf0e10cSrcweir 	do
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 	    pPage = GetNextPage( pPage, true );
546cdf0e10cSrcweir 
547cdf0e10cSrcweir         if( pPage && !pPage->getAnnotations().empty() )
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             AnnotationVector aAnnotations( pPage->getAnnotations() );
550cdf0e10cSrcweir             for( AnnotationVector::iterator iter = aAnnotations.begin(); iter != aAnnotations.end(); iter++ )
551cdf0e10cSrcweir             {
552cdf0e10cSrcweir                 Reference< XAnnotation > xAnnotation( *iter );
553cdf0e10cSrcweir                 if( xAnnotation->getAuthor() == sAuthor )
554cdf0e10cSrcweir                 {
555cdf0e10cSrcweir                     if( mxSelectedAnnotation == xAnnotation )
556cdf0e10cSrcweir                         mxSelectedAnnotation.clear();
557cdf0e10cSrcweir                     pPage->removeAnnotation( xAnnotation );
558cdf0e10cSrcweir                 }
559cdf0e10cSrcweir             }
560cdf0e10cSrcweir          }
561cdf0e10cSrcweir     } while( pPage );
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     if( mpDoc->IsUndoEnabled() )
564cdf0e10cSrcweir         mpDoc->EndUndo();
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
DeleteAllAnnotations()567cdf0e10cSrcweir void AnnotationManagerImpl::DeleteAllAnnotations()
568cdf0e10cSrcweir {
569cdf0e10cSrcweir     if( mpDoc->IsUndoEnabled() )
570cdf0e10cSrcweir         mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_DELETE ) ) );
571cdf0e10cSrcweir 
572cdf0e10cSrcweir     SdPage* pPage = 0;
573cdf0e10cSrcweir 	do
574cdf0e10cSrcweir 	{
575cdf0e10cSrcweir 	    pPage = GetNextPage( pPage, true );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         if( pPage && !pPage->getAnnotations().empty() )
578cdf0e10cSrcweir         {
579cdf0e10cSrcweir 
580cdf0e10cSrcweir             AnnotationVector aAnnotations( pPage->getAnnotations() );
581cdf0e10cSrcweir             for( AnnotationVector::iterator iter = aAnnotations.begin(); iter != aAnnotations.end(); iter++ )
582cdf0e10cSrcweir             {
583cdf0e10cSrcweir                 pPage->removeAnnotation( (*iter) );
584cdf0e10cSrcweir             }
585cdf0e10cSrcweir          }
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir     while( pPage );
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     mxSelectedAnnotation.clear();
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     if( mpDoc->IsUndoEnabled() )
592cdf0e10cSrcweir         mpDoc->EndUndo();
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir // --------------------------------------------------------------------
596cdf0e10cSrcweir 
GetAnnotationState(SfxItemSet & rSet)597cdf0e10cSrcweir void AnnotationManagerImpl::GetAnnotationState(SfxItemSet& rSet)
598cdf0e10cSrcweir {
599cdf0e10cSrcweir     SdPage* pCurrentPage = GetCurrentPage();
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     const bool bReadOnly = mrBase.GetDocShell()->IsReadOnly();
602cdf0e10cSrcweir     const bool bWrongPageKind = (pCurrentPage == 0) || (pCurrentPage->GetPageKind() != PK_STANDARD);
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
605cdf0e10cSrcweir 
606cdf0e10cSrcweir     if( bReadOnly || bWrongPageKind || (nCurrentODFVersion != SvtSaveOptions::ODFVER_LATEST) )
607cdf0e10cSrcweir         rSet.DisableItem( SID_INSERT_POSTIT );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     rSet.Put(SfxBoolItem(SID_SHOW_POSTIT, mbShowAnnotations));
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     Reference< XAnnotation > xAnnotation;
612cdf0e10cSrcweir     GetSelectedAnnotation( xAnnotation );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir     if( !xAnnotation.is() || bReadOnly )
615cdf0e10cSrcweir         rSet.DisableItem( SID_DELETE_POSTIT );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	SdPage* pPage = 0;
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 	bool bHasAnnotations = false;
620cdf0e10cSrcweir 	do
621cdf0e10cSrcweir 	{
622cdf0e10cSrcweir 	    pPage = GetNextPage( pPage, true );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         if( pPage && !pPage->getAnnotations().empty() )
625cdf0e10cSrcweir             bHasAnnotations = true;
626cdf0e10cSrcweir     }
627cdf0e10cSrcweir     while( pPage && !bHasAnnotations );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     if( !bHasAnnotations || bReadOnly )
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir 	    rSet.DisableItem( SID_DELETEALL_POSTIT );
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     if( bWrongPageKind || !bHasAnnotations )
635cdf0e10cSrcweir     {
636cdf0e10cSrcweir 	    rSet.DisableItem( SID_PREVIOUS_POSTIT );
637cdf0e10cSrcweir 	    rSet.DisableItem( SID_NEXT_POSTIT );
638cdf0e10cSrcweir 	}
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir // --------------------------------------------------------------------
642cdf0e10cSrcweir 
SelectNextAnnotation(bool bForeward)643cdf0e10cSrcweir void AnnotationManagerImpl::SelectNextAnnotation(bool bForeward)
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     ShowAnnotations( true );
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     Reference< XAnnotation > xCurrent;
648cdf0e10cSrcweir     GetSelectedAnnotation( xCurrent );
649cdf0e10cSrcweir     SdPage* pPage = GetCurrentPage();
650cdf0e10cSrcweir     if( !pPage )
651cdf0e10cSrcweir         return;
652cdf0e10cSrcweir 
653cdf0e10cSrcweir    	AnnotationVector aAnnotations( pPage->getAnnotations() );
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     if( bForeward )
656cdf0e10cSrcweir     {
657cdf0e10cSrcweir         if( xCurrent.is() )
658cdf0e10cSrcweir         {
659cdf0e10cSrcweir    	        for( AnnotationVector::iterator iter = aAnnotations.begin(); iter != aAnnotations.end(); iter++ )
660cdf0e10cSrcweir    	        {
661cdf0e10cSrcweir    	            if( (*iter) == xCurrent )
662cdf0e10cSrcweir    	            {
663cdf0e10cSrcweir    	                iter++;
664cdf0e10cSrcweir    	                if( iter != aAnnotations.end() )
665cdf0e10cSrcweir    	                {
666cdf0e10cSrcweir    	                    SelectAnnotation( (*iter) );
667cdf0e10cSrcweir    	                    return;
668cdf0e10cSrcweir    	                }
669cdf0e10cSrcweir    	                break;
670cdf0e10cSrcweir    	            }
671cdf0e10cSrcweir    	        }
672cdf0e10cSrcweir         }
673cdf0e10cSrcweir         else if( !aAnnotations.empty() )
674cdf0e10cSrcweir         {
675cdf0e10cSrcweir             SelectAnnotation( *(aAnnotations.begin()) );
676cdf0e10cSrcweir             return;
677cdf0e10cSrcweir         }
678cdf0e10cSrcweir     }
679cdf0e10cSrcweir     else
680cdf0e10cSrcweir     {
681cdf0e10cSrcweir         if( xCurrent.is() )
682cdf0e10cSrcweir         {
683cdf0e10cSrcweir    	        for( AnnotationVector::iterator iter = aAnnotations.begin(); iter != aAnnotations.end(); iter++ )
684cdf0e10cSrcweir    	        {
685cdf0e10cSrcweir    	            if( (*iter) == xCurrent )
686cdf0e10cSrcweir    	            {
687cdf0e10cSrcweir    	                if( iter != aAnnotations.begin() )
688cdf0e10cSrcweir    	                {
689cdf0e10cSrcweir    	                    iter--;
690cdf0e10cSrcweir                         SelectAnnotation( (*iter) );
691cdf0e10cSrcweir                         return;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir    	                }
694cdf0e10cSrcweir    	                break;
695cdf0e10cSrcweir    	            }
696cdf0e10cSrcweir    	        }
697cdf0e10cSrcweir         }
698cdf0e10cSrcweir         else if( !aAnnotations.empty() )
699cdf0e10cSrcweir         {
700cdf0e10cSrcweir             AnnotationVector::iterator iter( aAnnotations.end() );
701cdf0e10cSrcweir             SelectAnnotation( *(--iter) );
702cdf0e10cSrcweir             return;
703cdf0e10cSrcweir         }
704cdf0e10cSrcweir     }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir     mxSelectedAnnotation.clear();
707cdf0e10cSrcweir     do
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir         do
710cdf0e10cSrcweir         {
711cdf0e10cSrcweir             pPage = GetNextPage( pPage, bForeward );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir             if( pPage && !pPage->getAnnotations().empty() )
714cdf0e10cSrcweir             {
715cdf0e10cSrcweir                 // switch to next/previous slide with annotations
716cdf0e10cSrcweir                 ::boost::shared_ptr<DrawViewShell> pDrawViewShell(::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
717cdf0e10cSrcweir                 if (pDrawViewShell.get() != NULL)
718cdf0e10cSrcweir                 {
719cdf0e10cSrcweir                     pDrawViewShell->ChangeEditMode(pPage->IsMasterPage() ? EM_MASTERPAGE : EM_PAGE, sal_False);
720cdf0e10cSrcweir                     pDrawViewShell->SwitchPage((pPage->GetPageNum() - 1) >> 1);
721cdf0e10cSrcweir 
722cdf0e10cSrcweir                     SfxDispatcher* pDispatcher = getDispatcher( mrBase );
723cdf0e10cSrcweir                     if( pDispatcher )
724cdf0e10cSrcweir                         pDispatcher->Execute( bForeward ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir                     return;
727cdf0e10cSrcweir                 }
728cdf0e10cSrcweir             }
729cdf0e10cSrcweir         }
730cdf0e10cSrcweir         while( pPage );
731cdf0e10cSrcweir 
732cdf0e10cSrcweir         // The question text depends on the search direction.
733cdf0e10cSrcweir         bool bImpress = mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS;
734cdf0e10cSrcweir         sal_uInt16 nStringId;
735cdf0e10cSrcweir         if(bForeward)
736cdf0e10cSrcweir             nStringId = bImpress ? STR_ANNOTATION_WRAP_FORWARD : STR_ANNOTATION_WRAP_FORWARD_DRAW;
737cdf0e10cSrcweir         else
738cdf0e10cSrcweir             nStringId = bImpress ? STR_ANNOTATION_WRAP_BACKWARD : STR_ANNOTATION_WRAP_BACKWARD_DRAW;
739cdf0e10cSrcweir 
740cdf0e10cSrcweir         // Pop up question box that asks the user whether to wrap arround.
741cdf0e10cSrcweir         // The dialog is made modal with respect to the whole application.
742cdf0e10cSrcweir         QueryBox aQuestionBox (
743cdf0e10cSrcweir             NULL,
744cdf0e10cSrcweir             WB_YES_NO | WB_DEF_YES,
745cdf0e10cSrcweir             String(SdResId(nStringId)));
746cdf0e10cSrcweir         aQuestionBox.SetImage (QueryBox::GetStandardImage());
747cdf0e10cSrcweir         sal_uInt16 nBoxResult = aQuestionBox.Execute();
748cdf0e10cSrcweir         if(nBoxResult != BUTTONID_YES)
749cdf0e10cSrcweir             break;
750cdf0e10cSrcweir     }
751cdf0e10cSrcweir     while( true );
752cdf0e10cSrcweir }
753cdf0e10cSrcweir 
754cdf0e10cSrcweir // --------------------------------------------------------------------
755cdf0e10cSrcweir 
onTagSelected(AnnotationTag & rTag)756cdf0e10cSrcweir void AnnotationManagerImpl::onTagSelected(	AnnotationTag& rTag )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir     mxSelectedAnnotation = rTag.GetAnnotation();
759cdf0e10cSrcweir     invalidateSlots();
760cdf0e10cSrcweir }
761cdf0e10cSrcweir 
762cdf0e10cSrcweir // --------------------------------------------------------------------
763cdf0e10cSrcweir 
onTagDeselected(AnnotationTag & rTag)764cdf0e10cSrcweir void AnnotationManagerImpl::onTagDeselected( AnnotationTag& rTag )
765cdf0e10cSrcweir {
766cdf0e10cSrcweir     if( rTag.GetAnnotation() == mxSelectedAnnotation )
767cdf0e10cSrcweir     {
768cdf0e10cSrcweir         mxSelectedAnnotation.clear();
769cdf0e10cSrcweir         invalidateSlots();
770cdf0e10cSrcweir     }
771cdf0e10cSrcweir }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir // --------------------------------------------------------------------
774cdf0e10cSrcweir 
SelectAnnotation(::com::sun::star::uno::Reference<::com::sun::star::office::XAnnotation> xAnnotation,bool bEdit)775cdf0e10cSrcweir void AnnotationManagerImpl::SelectAnnotation( ::com::sun::star::uno::Reference< ::com::sun::star::office::XAnnotation > xAnnotation, bool bEdit /* = sal_False */ )
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     mxSelectedAnnotation = xAnnotation;
778cdf0e10cSrcweir 
779cdf0e10cSrcweir     for( AnnotationTagVector::iterator iter( maTagVector.begin() ); iter != maTagVector.end(); iter++ )
780cdf0e10cSrcweir     {
781cdf0e10cSrcweir         if( (*iter)->GetAnnotation() == xAnnotation )
782cdf0e10cSrcweir         {
783cdf0e10cSrcweir        		SmartTagReference xTag( (*iter).get() );
784cdf0e10cSrcweir             mrBase.GetMainViewShell()->GetView()->getSmartTags().select( xTag );
785cdf0e10cSrcweir             (*iter)->OpenPopup( bEdit );
786cdf0e10cSrcweir             break;
787cdf0e10cSrcweir         }
788cdf0e10cSrcweir     }
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir // --------------------------------------------------------------------
792cdf0e10cSrcweir 
GetSelectedAnnotation(::com::sun::star::uno::Reference<::com::sun::star::office::XAnnotation> & xAnnotation)793cdf0e10cSrcweir void AnnotationManagerImpl::GetSelectedAnnotation( ::com::sun::star::uno::Reference< ::com::sun::star::office::XAnnotation >& xAnnotation )
794cdf0e10cSrcweir {
795cdf0e10cSrcweir     xAnnotation = mxSelectedAnnotation;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
invalidateSlots()798cdf0e10cSrcweir void AnnotationManagerImpl::invalidateSlots()
799cdf0e10cSrcweir {
800cdf0e10cSrcweir     SfxBindings* pBindings = getBindings( mrBase );
801cdf0e10cSrcweir     if( pBindings )
802cdf0e10cSrcweir     {
803cdf0e10cSrcweir         pBindings->Invalidate( SID_INSERT_POSTIT );
804cdf0e10cSrcweir         pBindings->Invalidate( SID_DELETE_POSTIT );
805cdf0e10cSrcweir         pBindings->Invalidate( SID_DELETEALL_POSTIT );
806cdf0e10cSrcweir         pBindings->Invalidate( SID_PREVIOUS_POSTIT );
807cdf0e10cSrcweir         pBindings->Invalidate( SID_NEXT_POSTIT );
808cdf0e10cSrcweir         pBindings->Invalidate( SID_UNDO );
809cdf0e10cSrcweir         pBindings->Invalidate( SID_REDO );
810cdf0e10cSrcweir     }
811cdf0e10cSrcweir }
812cdf0e10cSrcweir 
813cdf0e10cSrcweir // --------------------------------------------------------------------
814cdf0e10cSrcweir 
onSelectionChanged()815cdf0e10cSrcweir void AnnotationManagerImpl::onSelectionChanged()
816cdf0e10cSrcweir {
817cdf0e10cSrcweir 	if( mxView.is() && mrBase.GetDrawView() ) try
818cdf0e10cSrcweir 	{
819cdf0e10cSrcweir 		Reference< XAnnotationAccess > xPage( mxView->getCurrentPage(), UNO_QUERY );
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 		if( xPage != mxCurrentPage )
822cdf0e10cSrcweir 		{
823cdf0e10cSrcweir 			mxCurrentPage = xPage;
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 			UpdateTags(true);
826cdf0e10cSrcweir 	    }
827cdf0e10cSrcweir 	}
828cdf0e10cSrcweir 	catch( Exception& )
829cdf0e10cSrcweir 	{
830cdf0e10cSrcweir 		DBG_ERROR( "sd::AnnotationManagerImpl::onSelectionChanged(), exception caught!" );
831cdf0e10cSrcweir 	}
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
UpdateTags(bool bSynchron)834cdf0e10cSrcweir void AnnotationManagerImpl::UpdateTags( bool bSynchron )
835cdf0e10cSrcweir {
836cdf0e10cSrcweir     if( bSynchron )
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         if( mnUpdateTagsEvent )
839cdf0e10cSrcweir             Application::RemoveUserEvent( mnUpdateTagsEvent );
840cdf0e10cSrcweir 
841cdf0e10cSrcweir             UpdateTagsHdl(0);
842cdf0e10cSrcweir     }
843cdf0e10cSrcweir     else
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         if( !mnUpdateTagsEvent && mxView.is() )
846cdf0e10cSrcweir             mnUpdateTagsEvent = Application::PostUserEvent( LINK( this, AnnotationManagerImpl, UpdateTagsHdl ) );
847cdf0e10cSrcweir     }
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
IMPL_LINK(AnnotationManagerImpl,UpdateTagsHdl,void *,EMPTYARG)850cdf0e10cSrcweir IMPL_LINK(AnnotationManagerImpl,UpdateTagsHdl, void *, EMPTYARG)
851cdf0e10cSrcweir {
852cdf0e10cSrcweir     mnUpdateTagsEvent  = 0;
853cdf0e10cSrcweir     DisposeTags();
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     if( mbShowAnnotations )
856cdf0e10cSrcweir         CreateTags();
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     if(  mrBase.GetDrawView() )
859cdf0e10cSrcweir         static_cast< ::sd::View* >( mrBase.GetDrawView() )->updateHandles();
860cdf0e10cSrcweir 
861cdf0e10cSrcweir     invalidateSlots();
862cdf0e10cSrcweir 
863cdf0e10cSrcweir     return 0;
864cdf0e10cSrcweir }
865cdf0e10cSrcweir 
CreateTags()866cdf0e10cSrcweir void AnnotationManagerImpl::CreateTags()
867cdf0e10cSrcweir {
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     if( mxCurrentPage.is() && mpDoc ) try
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir 	    int nIndex = 1;
872cdf0e10cSrcweir 	    maFont = Application::GetSettings().GetStyleSettings().GetAppFont();
873cdf0e10cSrcweir 
874cdf0e10cSrcweir         rtl::Reference< AnnotationTag > xSelectedTag;
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 	    Reference< XAnnotationEnumeration > xEnum( mxCurrentPage->createAnnotationEnumeration() );
877cdf0e10cSrcweir 	    while( xEnum->hasMoreElements() )
878cdf0e10cSrcweir 	    {
879cdf0e10cSrcweir 	        Reference< XAnnotation > xAnnotation( xEnum->nextElement() );
880cdf0e10cSrcweir 	        Color aColor( GetColorLight( mpDoc->GetAnnotationAuthorIndex( xAnnotation->getAuthor() ) ) );
881cdf0e10cSrcweir 		    rtl::Reference< AnnotationTag > xTag( new AnnotationTag( *this, *mrBase.GetMainViewShell()->GetView(), xAnnotation, aColor, nIndex++, maFont  ) );
882cdf0e10cSrcweir 		    maTagVector.push_back(xTag);
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 		    if( xAnnotation == mxSelectedAnnotation )
885cdf0e10cSrcweir 		    {
886cdf0e10cSrcweir 		        xSelectedTag = xTag;
887cdf0e10cSrcweir 		    }
888cdf0e10cSrcweir 	    }
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	    if( xSelectedTag.is() )
891cdf0e10cSrcweir 	    {
892cdf0e10cSrcweir        		SmartTagReference xTag( xSelectedTag.get() );
893cdf0e10cSrcweir             mrBase.GetMainViewShell()->GetView()->getSmartTags().select( xTag );
894cdf0e10cSrcweir 	    }
895cdf0e10cSrcweir 	    else
896cdf0e10cSrcweir 	    {
897cdf0e10cSrcweir 	        // no tag, no selection!
898cdf0e10cSrcweir 	        mxSelectedAnnotation.clear();
899cdf0e10cSrcweir 	    }
900cdf0e10cSrcweir     }
901cdf0e10cSrcweir     catch( Exception& )
902cdf0e10cSrcweir     {
903cdf0e10cSrcweir         DBG_ERROR( "sd::AnnotationManagerImpl::onSelectionChanged(), exception caught!" );
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir // --------------------------------------------------------------------
908cdf0e10cSrcweir 
DisposeTags()909cdf0e10cSrcweir void AnnotationManagerImpl::DisposeTags()
910cdf0e10cSrcweir {
911cdf0e10cSrcweir 	if( !maTagVector.empty() )
912cdf0e10cSrcweir 	{
913cdf0e10cSrcweir 		AnnotationTagVector::iterator iter = maTagVector.begin();
914cdf0e10cSrcweir 		do
915cdf0e10cSrcweir 		{
916cdf0e10cSrcweir 			(*iter++)->Dispose();
917cdf0e10cSrcweir 		}
918cdf0e10cSrcweir 		while( iter != maTagVector.end() );
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 		maTagVector.clear();
921cdf0e10cSrcweir 	}
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir // --------------------------------------------------------------------
925cdf0e10cSrcweir 
addListener()926cdf0e10cSrcweir void AnnotationManagerImpl::addListener()
927cdf0e10cSrcweir {
928cdf0e10cSrcweir 	Link aLink( LINK(this,AnnotationManagerImpl,EventMultiplexerListener) );
929cdf0e10cSrcweir     mrBase.GetEventMultiplexer()->AddEventListener (
930cdf0e10cSrcweir         aLink,
931cdf0e10cSrcweir         tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
932cdf0e10cSrcweir         | tools::EventMultiplexerEvent::EID_CURRENT_PAGE
933cdf0e10cSrcweir         | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
934cdf0e10cSrcweir         | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED);
935cdf0e10cSrcweir }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir // --------------------------------------------------------------------
938cdf0e10cSrcweir 
removeListener()939cdf0e10cSrcweir void AnnotationManagerImpl::removeListener()
940cdf0e10cSrcweir {
941cdf0e10cSrcweir 	Link aLink( LINK(this,AnnotationManagerImpl,EventMultiplexerListener) );
942cdf0e10cSrcweir     mrBase.GetEventMultiplexer()->RemoveEventListener( aLink );
943cdf0e10cSrcweir }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir // --------------------------------------------------------------------
946cdf0e10cSrcweir 
IMPL_LINK(AnnotationManagerImpl,EventMultiplexerListener,tools::EventMultiplexerEvent *,pEvent)947cdf0e10cSrcweir IMPL_LINK(AnnotationManagerImpl,EventMultiplexerListener,
948cdf0e10cSrcweir     tools::EventMultiplexerEvent*,pEvent)
949cdf0e10cSrcweir {
950cdf0e10cSrcweir     switch (pEvent->meEventId)
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir         case tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
953cdf0e10cSrcweir         case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION:
954cdf0e10cSrcweir             onSelectionChanged();
955cdf0e10cSrcweir             break;
956cdf0e10cSrcweir 
957cdf0e10cSrcweir         case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
958cdf0e10cSrcweir             mxView = Reference<XDrawView>();
959cdf0e10cSrcweir             onSelectionChanged();
960cdf0e10cSrcweir             break;
961cdf0e10cSrcweir 
962cdf0e10cSrcweir         case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
963cdf0e10cSrcweir             mxView = Reference<XDrawView>::query( mrBase.GetController() );
964cdf0e10cSrcweir             onSelectionChanged();
965cdf0e10cSrcweir             break;
966cdf0e10cSrcweir     }
967cdf0e10cSrcweir     return 0;
968cdf0e10cSrcweir }
969cdf0e10cSrcweir #if 0
970cdf0e10cSrcweir OUString AnnotationManagerImpl::GetHelpText( ::com::sun::star::uno::Reference< ::com::sun::star::office::XAnnotation >& xAnnotation )
971cdf0e10cSrcweir {
972cdf0e10cSrcweir     OUString sRet;
973cdf0e10cSrcweir     if( xAnnotation.is() )
974cdf0e10cSrcweir     {
975cdf0e10cSrcweir 	    OUString sAuthor( xAnnotation->getAuthor() );
976cdf0e10cSrcweir 	    if( sAuthor.getLength() != 0 )
977cdf0e10cSrcweir 	    {
978cdf0e10cSrcweir 	        sRet += sAuthor;
979cdf0e10cSrcweir 	    }
980cdf0e10cSrcweir 	    sRet += OUString( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 	    sRet += getAnnotationDateTimeString( xAnnotation );
983cdf0e10cSrcweir 	    sRet += OUString( RTL_CONSTASCII_USTRINGPARAM( "]\n" ) );
984cdf0e10cSrcweir 
985cdf0e10cSrcweir 	    Reference< XText > xText( xAnnotation->getTextRange() );
986cdf0e10cSrcweir 	    if( xText.is() )
987cdf0e10cSrcweir 	        sRet += xText->getString();
988cdf0e10cSrcweir     }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     return sRet;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir #endif
993cdf0e10cSrcweir 
ExecuteAnnotationContextMenu(Reference<XAnnotation> xAnnotation,::Window * pParent,const Rectangle & rContextRect,bool bButtonMenu)994cdf0e10cSrcweir void AnnotationManagerImpl::ExecuteAnnotationContextMenu( Reference< XAnnotation > xAnnotation, ::Window* pParent, const Rectangle& rContextRect, bool bButtonMenu /* = false */ )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir     SfxDispatcher* pDispatcher( getDispatcher( mrBase ) );
997cdf0e10cSrcweir     if( !pDispatcher )
998cdf0e10cSrcweir         return;
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir     const bool bReadOnly = mrBase.GetDocShell()->IsReadOnly();
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir     AnnotationWindow* pAnnotationWindow = bButtonMenu ? 0 : dynamic_cast< AnnotationWindow* >( pParent );
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir     if( bReadOnly && !pAnnotationWindow )
1005cdf0e10cSrcweir         return;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	std::auto_ptr< PopupMenu > pMenu( new PopupMenu( SdResId( pAnnotationWindow ? RID_ANNOTATION_CONTEXTMENU : RID_ANNOTATION_TAG_CONTEXTMENU ) ) );
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir     SvtUserOptions aUserOptions;
1010cdf0e10cSrcweir     OUString sCurrentAuthor( aUserOptions.GetFullName() );
1011cdf0e10cSrcweir     OUString sAuthor( xAnnotation->getAuthor() );
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir     String aStr( pMenu->GetItemText( SID_DELETEALLBYAUTHOR_POSTIT ) ), aReplace( sAuthor );
1014cdf0e10cSrcweir     if( aReplace.Len() == 0 )
1015cdf0e10cSrcweir         aReplace = String( SdResId( STR_ANNOTATION_NOAUTHOR ) );
1016cdf0e10cSrcweir     aStr.SearchAndReplaceAscii("%1", aReplace);
1017cdf0e10cSrcweir     pMenu->SetItemText( SID_DELETEALLBYAUTHOR_POSTIT, aStr );
1018cdf0e10cSrcweir     pMenu->EnableItem( SID_REPLYTO_POSTIT, (sAuthor != sCurrentAuthor) && !bReadOnly );
1019cdf0e10cSrcweir     pMenu->EnableItem( SID_DELETE_POSTIT, (xAnnotation.is() && !bReadOnly) ? sal_True : sal_False );
1020cdf0e10cSrcweir     pMenu->EnableItem( SID_DELETEALLBYAUTHOR_POSTIT, !bReadOnly );
1021cdf0e10cSrcweir     pMenu->EnableItem( SID_DELETEALL_POSTIT, !bReadOnly );
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir     if( pAnnotationWindow )
1024cdf0e10cSrcweir     {
1025cdf0e10cSrcweir         if( pAnnotationWindow->IsProtected() || bReadOnly )
1026cdf0e10cSrcweir         {
1027cdf0e10cSrcweir             pMenu->EnableItem( SID_ATTR_CHAR_WEIGHT, sal_False );
1028cdf0e10cSrcweir             pMenu->EnableItem( SID_ATTR_CHAR_POSTURE, sal_False );
1029cdf0e10cSrcweir             pMenu->EnableItem( SID_ATTR_CHAR_UNDERLINE, sal_False );
1030cdf0e10cSrcweir             pMenu->EnableItem( SID_ATTR_CHAR_STRIKEOUT, sal_False );
1031cdf0e10cSrcweir             pMenu->EnableItem( SID_PASTE, sal_False );
1032cdf0e10cSrcweir         }
1033cdf0e10cSrcweir         else
1034cdf0e10cSrcweir         {
1035cdf0e10cSrcweir             SfxItemSet aSet(pAnnotationWindow->getView()->GetAttribs());
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 	        if ( aSet.GetItemState( EE_CHAR_WEIGHT ) == SFX_ITEM_ON )
1038cdf0e10cSrcweir 	        {
1039cdf0e10cSrcweir 		        if( ((const SvxWeightItem&)aSet.Get( EE_CHAR_WEIGHT )).GetWeight() == WEIGHT_BOLD )
1040cdf0e10cSrcweir 		            pMenu->CheckItem( SID_ATTR_CHAR_WEIGHT );
1041cdf0e10cSrcweir 		    }
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir 	        if ( aSet.GetItemState( EE_CHAR_ITALIC ) == SFX_ITEM_ON )
1044cdf0e10cSrcweir 	        {
1045cdf0e10cSrcweir 		        if( ((const SvxPostureItem&)aSet.Get( EE_CHAR_ITALIC )).GetPosture() != ITALIC_NONE )
1046cdf0e10cSrcweir 		            pMenu->CheckItem( SID_ATTR_CHAR_POSTURE );
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 		    }
1049cdf0e10cSrcweir 	        if ( aSet.GetItemState( EE_CHAR_UNDERLINE ) == SFX_ITEM_ON )
1050cdf0e10cSrcweir 	        {
1051cdf0e10cSrcweir 		        if( ((const SvxUnderlineItem&)aSet.Get( EE_CHAR_UNDERLINE )).GetLineStyle() != UNDERLINE_NONE )
1052cdf0e10cSrcweir 		            pMenu->CheckItem( SID_ATTR_CHAR_UNDERLINE );
1053cdf0e10cSrcweir 	        }
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 	        if ( aSet.GetItemState( EE_CHAR_STRIKEOUT ) == SFX_ITEM_ON )
1056cdf0e10cSrcweir 	        {
1057cdf0e10cSrcweir 		        if( ((const SvxCrossedOutItem&)aSet.Get( EE_CHAR_STRIKEOUT )).GetStrikeout() != STRIKEOUT_NONE )
1058cdf0e10cSrcweir 		            pMenu->CheckItem( SID_ATTR_CHAR_STRIKEOUT );
1059cdf0e10cSrcweir 	        }
1060cdf0e10cSrcweir             TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pAnnotationWindow ) );
1061cdf0e10cSrcweir             pMenu->EnableItem( SID_PASTE, aDataHelper.GetFormatCount() != 0 );
1062cdf0e10cSrcweir 	    }
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir         pMenu->EnableItem( SID_COPY, pAnnotationWindow->getView()->HasSelection() );
1065cdf0e10cSrcweir     }
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir     sal_uInt16 nId = 0;
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir     // set slot images
1070cdf0e10cSrcweir     Reference< ::com::sun::star::frame::XFrame > xFrame( mrBase.GetMainViewShell()->GetViewFrame()->GetFrame().GetFrameInterface() );
1071cdf0e10cSrcweir     if( xFrame.is() )
1072cdf0e10cSrcweir     {
1073cdf0e10cSrcweir         const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
1074cdf0e10cSrcweir         for( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
1075cdf0e10cSrcweir         {
1076cdf0e10cSrcweir             nId = pMenu->GetItemId( nPos );
1077cdf0e10cSrcweir             if( pMenu->IsItemEnabled( nId ) )
1078cdf0e10cSrcweir             {
1079cdf0e10cSrcweir                 OUString sSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
1080cdf0e10cSrcweir                 sSlotURL += OUString::valueOf( sal_Int32( nId ));
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir                 Image aImage( GetImage( xFrame, sSlotURL, false, bHighContrast ) );
1083cdf0e10cSrcweir                 if( !!aImage )
1084cdf0e10cSrcweir                     pMenu->SetItemImage( nId, aImage );
1085cdf0e10cSrcweir             }
1086cdf0e10cSrcweir         }
1087cdf0e10cSrcweir     }
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir     nId = pMenu->Execute( pParent, rContextRect, POPUPMENU_EXECUTE_DOWN|POPUPMENU_NOMOUSEUPCLOSE );
1090cdf0e10cSrcweir 	switch( nId )
1091cdf0e10cSrcweir 	{
1092cdf0e10cSrcweir     case SID_REPLYTO_POSTIT:
1093cdf0e10cSrcweir     {
1094cdf0e10cSrcweir 		const SfxUnoAnyItem aItem( SID_REPLYTO_POSTIT, Any( xAnnotation ) );
1095cdf0e10cSrcweir 		pDispatcher->Execute( SID_REPLYTO_POSTIT, SFX_CALLMODE_ASYNCHRON, &aItem, 0 );
1096cdf0e10cSrcweir         break;
1097cdf0e10cSrcweir     }
1098cdf0e10cSrcweir     case SID_DELETE_POSTIT:
1099cdf0e10cSrcweir     {
1100cdf0e10cSrcweir 		const SfxUnoAnyItem aItem( SID_DELETE_POSTIT, Any( xAnnotation ) );
1101cdf0e10cSrcweir 		pDispatcher->Execute( SID_DELETE_POSTIT, SFX_CALLMODE_ASYNCHRON, &aItem, 0 );
1102cdf0e10cSrcweir         break;
1103cdf0e10cSrcweir     }
1104cdf0e10cSrcweir     case SID_DELETEALLBYAUTHOR_POSTIT:
1105cdf0e10cSrcweir     {
1106cdf0e10cSrcweir 		const SfxStringItem aItem( SID_DELETEALLBYAUTHOR_POSTIT, sAuthor );
1107cdf0e10cSrcweir 		pDispatcher->Execute( SID_DELETEALLBYAUTHOR_POSTIT, SFX_CALLMODE_ASYNCHRON, &aItem, 0 );
1108cdf0e10cSrcweir         break;
1109cdf0e10cSrcweir     }
1110cdf0e10cSrcweir     case SID_DELETEALL_POSTIT:
1111cdf0e10cSrcweir         pDispatcher->Execute( SID_DELETEALL_POSTIT );
1112cdf0e10cSrcweir         break;
1113cdf0e10cSrcweir     case SID_COPY:
1114cdf0e10cSrcweir     case SID_PASTE:
1115cdf0e10cSrcweir     case SID_ATTR_CHAR_WEIGHT:
1116cdf0e10cSrcweir     case SID_ATTR_CHAR_POSTURE:
1117cdf0e10cSrcweir     case SID_ATTR_CHAR_UNDERLINE:
1118cdf0e10cSrcweir     case SID_ATTR_CHAR_STRIKEOUT:
1119cdf0e10cSrcweir         if( pAnnotationWindow )
1120cdf0e10cSrcweir             pAnnotationWindow->ExecuteSlot( nId );
1121cdf0e10cSrcweir         break;
1122cdf0e10cSrcweir 	}
1123cdf0e10cSrcweir }
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir // ====================================================================
1126cdf0e10cSrcweir 
GetColor(sal_uInt16 aAuthorIndex)1127cdf0e10cSrcweir Color AnnotationManagerImpl::GetColor(sal_uInt16 aAuthorIndex)
1128cdf0e10cSrcweir {
1129cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1130cdf0e10cSrcweir 	{
1131cdf0e10cSrcweir 		static const Color aArrayNormal[] = {
1132cdf0e10cSrcweir 			COL_AUTHOR1_NORMAL,		COL_AUTHOR2_NORMAL,		COL_AUTHOR3_NORMAL,
1133cdf0e10cSrcweir 			COL_AUTHOR4_NORMAL,		COL_AUTHOR5_NORMAL,		COL_AUTHOR6_NORMAL,
1134cdf0e10cSrcweir 			COL_AUTHOR7_NORMAL,		COL_AUTHOR8_NORMAL,		COL_AUTHOR9_NORMAL };
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 		return Color( aArrayNormal[ aAuthorIndex % (sizeof( aArrayNormal )/ sizeof( aArrayNormal[0] ))]);
1137cdf0e10cSrcweir 	}
1138cdf0e10cSrcweir 	else
1139cdf0e10cSrcweir 		return Color(COL_WHITE);
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir 
GetColorLight(sal_uInt16 aAuthorIndex)1142cdf0e10cSrcweir Color AnnotationManagerImpl::GetColorLight(sal_uInt16 aAuthorIndex)
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1145cdf0e10cSrcweir 	{
1146cdf0e10cSrcweir 		static const Color aArrayLight[] = {
1147cdf0e10cSrcweir 			COL_AUTHOR1_LIGHT,		COL_AUTHOR2_LIGHT,		COL_AUTHOR3_LIGHT,
1148cdf0e10cSrcweir 			COL_AUTHOR4_LIGHT,		COL_AUTHOR5_LIGHT,		COL_AUTHOR6_LIGHT,
1149cdf0e10cSrcweir 			COL_AUTHOR7_LIGHT,		COL_AUTHOR8_LIGHT,		COL_AUTHOR9_LIGHT };
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 		return Color( aArrayLight[ aAuthorIndex % (sizeof( aArrayLight )/ sizeof( aArrayLight[0] ))]);
1152cdf0e10cSrcweir 	}
1153cdf0e10cSrcweir 	else
1154cdf0e10cSrcweir 		return Color(COL_WHITE);
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
GetColorDark(sal_uInt16 aAuthorIndex)1157cdf0e10cSrcweir Color AnnotationManagerImpl::GetColorDark(sal_uInt16 aAuthorIndex)
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir 	if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1160cdf0e10cSrcweir 	{
1161cdf0e10cSrcweir 		static const Color aArrayAnkor[] = {
1162cdf0e10cSrcweir 			COL_AUTHOR1_DARK,		COL_AUTHOR2_DARK,		COL_AUTHOR3_DARK,
1163cdf0e10cSrcweir 			COL_AUTHOR4_DARK,		COL_AUTHOR5_DARK,		COL_AUTHOR6_DARK,
1164cdf0e10cSrcweir 			COL_AUTHOR7_DARK,		COL_AUTHOR8_DARK,		COL_AUTHOR9_DARK };
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 		return Color( aArrayAnkor[  aAuthorIndex % (sizeof( aArrayAnkor )	/ sizeof( aArrayAnkor[0] ))]);
1167cdf0e10cSrcweir 	}
1168cdf0e10cSrcweir 	else
1169cdf0e10cSrcweir 		return Color(COL_WHITE);
1170cdf0e10cSrcweir }
1171cdf0e10cSrcweir 
GetNextPage(SdPage * pPage,bool bForeward)1172cdf0e10cSrcweir SdPage* AnnotationManagerImpl::GetNextPage( SdPage* pPage, bool bForeward )
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir     if( pPage == 0 )
1175cdf0e10cSrcweir         return bForeward ? GetFirstPage() : GetLastPage();
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     sal_uInt16 nPageNum = (pPage->GetPageNum() - 1) >> 1;
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir     // first all non master pages
1180cdf0e10cSrcweir     if( !pPage->IsMasterPage() )
1181cdf0e10cSrcweir     {
1182cdf0e10cSrcweir         if( bForeward )
1183cdf0e10cSrcweir         {
1184cdf0e10cSrcweir             if( nPageNum >= mpDoc->GetSdPageCount(PK_STANDARD)-1 )
1185cdf0e10cSrcweir             {
1186cdf0e10cSrcweir                 // we reached end of draw pages, start with master pages (skip handout master for draw)
1187cdf0e10cSrcweir                 return mpDoc->GetMasterSdPage( (mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? 0 : 1, PK_STANDARD );
1188cdf0e10cSrcweir             }
1189cdf0e10cSrcweir             nPageNum++;
1190cdf0e10cSrcweir         }
1191cdf0e10cSrcweir         else
1192cdf0e10cSrcweir         {
1193cdf0e10cSrcweir             if( nPageNum == 0 )
1194cdf0e10cSrcweir                 return 0; // we are already on the first draw page, finished
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir             nPageNum--;
1197cdf0e10cSrcweir         }
1198cdf0e10cSrcweir         return mpDoc->GetSdPage(nPageNum, PK_STANDARD);
1199cdf0e10cSrcweir     }
1200cdf0e10cSrcweir     else
1201cdf0e10cSrcweir     {
1202cdf0e10cSrcweir         if( bForeward )
1203cdf0e10cSrcweir         {
1204cdf0e10cSrcweir             if( nPageNum >= mpDoc->GetMasterSdPageCount(PK_STANDARD)-1 )
1205cdf0e10cSrcweir             {
1206cdf0e10cSrcweir                 return 0;   // we reached the end, there is nothing more to see here
1207cdf0e10cSrcweir             }
1208cdf0e10cSrcweir             nPageNum++;
1209cdf0e10cSrcweir         }
1210cdf0e10cSrcweir         else
1211cdf0e10cSrcweir         {
1212cdf0e10cSrcweir             if( nPageNum == (mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? 0 : 1 )
1213cdf0e10cSrcweir             {
1214cdf0e10cSrcweir                 // we reached beginning of master pages, start with end if pages
1215cdf0e10cSrcweir                 return mpDoc->GetSdPage( mpDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD );
1216cdf0e10cSrcweir             }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir             nPageNum--;
1219cdf0e10cSrcweir         }
1220cdf0e10cSrcweir         return mpDoc->GetMasterSdPage(nPageNum,PK_STANDARD);
1221cdf0e10cSrcweir     }
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir 
GetFirstPage()1224cdf0e10cSrcweir SdPage* AnnotationManagerImpl::GetFirstPage()
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir     // return first drawing page
1227cdf0e10cSrcweir     return mpDoc->GetSdPage(0, PK_STANDARD );
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
GetLastPage()1230cdf0e10cSrcweir SdPage* AnnotationManagerImpl::GetLastPage()
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir     return mpDoc->GetMasterSdPage( mpDoc->GetMasterSdPageCount(PK_STANDARD) - 1, PK_STANDARD );
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
GetCurrentPage()1235cdf0e10cSrcweir SdPage* AnnotationManagerImpl::GetCurrentPage()
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir /*
1238cdf0e10cSrcweir     ::boost::shared_ptr<DrawViewShell> pDrawViewShell(::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
1239cdf0e10cSrcweir     if (pDrawViewShell.get() != NULL)
1240cdf0e10cSrcweir         return pDrawViewShell->GetActualPage();
1241cdf0e10cSrcweir */
1242cdf0e10cSrcweir     return mrBase.GetMainViewShell()->getCurrentPage();
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir // ====================================================================
1246cdf0e10cSrcweir 
AnnotationManager(ViewShellBase & rViewShellBase)1247cdf0e10cSrcweir AnnotationManager::AnnotationManager( ViewShellBase& rViewShellBase )
1248cdf0e10cSrcweir : mxImpl( new AnnotationManagerImpl( rViewShellBase ) )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir     mxImpl->init();
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir 
~AnnotationManager()1253cdf0e10cSrcweir AnnotationManager::~AnnotationManager()
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir     mxImpl->dispose();
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir 
ExecuteAnnotation(SfxRequest & rRequest)1258cdf0e10cSrcweir void AnnotationManager::ExecuteAnnotation(SfxRequest& rRequest)
1259cdf0e10cSrcweir {
1260cdf0e10cSrcweir     mxImpl->ExecuteAnnotation( rRequest );
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir 
GetAnnotationState(SfxItemSet & rItemSet)1263cdf0e10cSrcweir void AnnotationManager::GetAnnotationState(SfxItemSet& rItemSet)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir     mxImpl->GetAnnotationState(rItemSet);
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir }
1269