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