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