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 <com/sun/star/util/XChangesNotifier.hpp>
31 : :
32 : : #include <vcl/help.hxx>
33 : : #include <vcl/svapp.hxx>
34 : :
35 : : #include <sfx2/viewfrm.hxx>
36 : : #include <sfx2/dispatch.hxx>
37 : :
38 : : #include <svx/sdr/overlay/overlaymanager.hxx>
39 : : #include <svx/sdr/overlay/overlayanimatedbitmapex.hxx>
40 : : #include <svx/sdr/overlay/overlaybitmapex.hxx>
41 : : #include <svx/svdpagv.hxx>
42 : : #include <svx/sdrpagewindow.hxx>
43 : : #include <svx/sdrpaintwindow.hxx>
44 : : #include <svx/svddrgmt.hxx>
45 : :
46 : : #include "View.hxx"
47 : : #include "sdresid.hxx"
48 : : #include "annotations.hrc"
49 : : #include "annotationmanagerimpl.hxx"
50 : : #include "annotationwindow.hxx"
51 : : #include "annotationtag.hxx"
52 : : #include "sdpage.hxx"
53 : : #include "ViewShell.hxx"
54 : : #include "app.hrc"
55 : : #include "Window.hxx"
56 : : #include "drawdoc.hxx"
57 : :
58 : : using ::rtl::OUString;
59 : : using namespace ::com::sun::star::uno;
60 : : using namespace ::com::sun::star::lang;
61 : : using namespace ::com::sun::star::drawing;
62 : : using namespace ::com::sun::star::office;
63 : : using namespace ::com::sun::star::geometry;
64 : :
65 : : namespace sd
66 : : {
67 : :
68 : : const sal_uInt32 SMART_TAG_HDL_NUM = SAL_MAX_UINT32;
69 : : static const int DRGPIX = 2; // Drag MinMove in Pixel
70 : :
71 : : // --------------------------------------------------------------------
72 : :
73 : 0 : static OUString getInitials( const OUString& rName )
74 : : {
75 : 0 : OUString sInitials;
76 : :
77 : 0 : const sal_Unicode * pStr = rName.getStr();
78 : 0 : sal_Int32 nLength = rName.getLength();
79 : :
80 [ # # ]: 0 : while( nLength )
81 : : {
82 : : // skip whitespace
83 [ # # ][ # # ]: 0 : while( nLength && (*pStr <= ' ') )
[ # # ]
84 : : {
85 : 0 : nLength--; pStr++;
86 : : }
87 : :
88 : : // take letter
89 [ # # ]: 0 : if( nLength )
90 : : {
91 : 0 : sInitials += OUString( *pStr );
92 : 0 : nLength--; pStr++;
93 : : }
94 : :
95 : : // skip letters until whitespace
96 [ # # ][ # # ]: 0 : while( nLength && (*pStr > ' ') )
[ # # ]
97 : : {
98 : 0 : nLength--; pStr++;
99 : : }
100 : : }
101 : :
102 : 0 : return sInitials;
103 : : }
104 : :
105 : : // --------------------------------------------------------------------
106 : :
107 : : // --------------------------------------------------------------------
108 : :
109 [ # # ][ # # ]: 0 : class AnnotationDragMove : public SdrDragMove
110 : : {
111 : : public:
112 : : AnnotationDragMove(SdrDragView& rNewView, const rtl::Reference <AnnotationTag >& xTag);
113 : : virtual bool BeginSdrDrag();
114 : : virtual bool EndSdrDrag(bool bCopy);
115 : : virtual void MoveSdrDrag(const Point& rNoSnapPnt);
116 : : virtual void CancelSdrDrag();
117 : :
118 : : private:
119 : : rtl::Reference <AnnotationTag > mxTag;
120 : : Point maOrigin;
121 : : };
122 : :
123 : 0 : AnnotationDragMove::AnnotationDragMove(SdrDragView& rNewView, const rtl::Reference <AnnotationTag >& xTag)
124 : : : SdrDragMove(rNewView)
125 [ # # ]: 0 : , mxTag( xTag )
126 : : {
127 : 0 : }
128 : :
129 : 0 : bool AnnotationDragMove::BeginSdrDrag()
130 : : {
131 : 0 : DragStat().Ref1()=GetDragHdl()->GetPos();
132 : 0 : DragStat().SetShown(!DragStat().IsShown());
133 : :
134 : 0 : maOrigin = GetDragHdl()->GetPos();
135 : 0 : DragStat().SetActionRect(Rectangle(maOrigin,maOrigin));
136 : :
137 : 0 : return true;
138 : : }
139 : :
140 : 0 : void AnnotationDragMove::MoveSdrDrag(const Point& rNoSnapPnt)
141 : : {
142 : 0 : Point aPnt(rNoSnapPnt);
143 : :
144 [ # # ][ # # ]: 0 : if (DragStat().CheckMinMoved(rNoSnapPnt))
145 : : {
146 [ # # ][ # # ]: 0 : if (aPnt!=DragStat().GetNow())
147 : : {
148 [ # # ]: 0 : Hide();
149 [ # # ]: 0 : DragStat().NextMove(aPnt);
150 [ # # ][ # # ]: 0 : GetDragHdl()->SetPos( maOrigin + Point( DragStat().GetDX(), DragStat().GetDY() ) );
[ # # ]
151 [ # # ]: 0 : Show();
152 [ # # ]: 0 : DragStat().SetActionRect(Rectangle(aPnt,aPnt));
153 : : }
154 : : }
155 : 0 : }
156 : :
157 : 0 : bool AnnotationDragMove::EndSdrDrag(bool /*bCopy*/)
158 : : {
159 : 0 : Hide();
160 [ # # ]: 0 : if( mxTag.is() )
161 : 0 : mxTag->Move( DragStat().GetDX(), DragStat().GetDY() );
162 : 0 : return sal_True;
163 : : }
164 : :
165 : 0 : void AnnotationDragMove::CancelSdrDrag()
166 : : {
167 : 0 : Hide();
168 : 0 : }
169 : :
170 : : // --------------------------------------------------------------------
171 : :
172 : : class AnnotationHdl : public SmartHdl
173 : : {
174 : : public:
175 : : AnnotationHdl( const SmartTagReference& xTag, const Reference< XAnnotation >& xAnnotation, const Point& rPnt );
176 : : virtual ~AnnotationHdl();
177 : : virtual void CreateB2dIAObject();
178 : : virtual sal_Bool IsFocusHdl() const;
179 : : virtual Pointer GetSdrDragPointer() const;
180 : : virtual bool isMarkable() const;
181 : :
182 : :
183 : : private:
184 : : Reference< XAnnotation > mxAnnotation;
185 : : rtl::Reference< AnnotationTag > mxTag;
186 : : };
187 : :
188 : : // --------------------------------------------------------------------
189 : :
190 : 0 : AnnotationHdl::AnnotationHdl( const SmartTagReference& xTag, const Reference< XAnnotation >& xAnnotation, const Point& rPnt )
191 : : : SmartHdl( xTag, rPnt )
192 : : , mxAnnotation( xAnnotation )
193 [ # # ][ # # ]: 0 : , mxTag( dynamic_cast< AnnotationTag* >( xTag.get() ) )
194 : : {
195 : 0 : }
196 : :
197 : : // --------------------------------------------------------------------
198 : :
199 [ # # ]: 0 : AnnotationHdl::~AnnotationHdl()
200 : : {
201 [ # # ]: 0 : }
202 : :
203 : : // --------------------------------------------------------------------
204 : :
205 : 0 : void AnnotationHdl::CreateB2dIAObject()
206 : : {
207 : : // first throw away old one
208 : 0 : GetRidOfIAObject();
209 : :
210 [ # # ]: 0 : if( mxAnnotation.is() )
211 : : {
212 [ # # ]: 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
213 : :
214 : 0 : const Point aTagPos( GetPos() );
215 : 0 : basegfx::B2DPoint aPosition( aTagPos.X(), aTagPos.Y() );
216 : :
217 [ # # ][ # # ]: 0 : const bool bFocused = IsFocusHdl() && pHdlList && (pHdlList->GetFocusHdl() == this);
[ # # ][ # # ]
[ # # ]
218 : :
219 [ # # ][ # # ]: 0 : BitmapEx aBitmapEx( mxTag->CreateAnnotationBitmap(mxTag->isSelected()) );
220 [ # # ]: 0 : BitmapEx aBitmapEx2;
221 [ # # ]: 0 : if( bFocused )
222 [ # # ][ # # ]: 0 : aBitmapEx2 = mxTag->CreateAnnotationBitmap(!mxTag->isSelected() );
[ # # ][ # # ]
223 : :
224 [ # # ]: 0 : if(pHdlList)
225 : : {
226 [ # # ]: 0 : SdrMarkView* pView = pHdlList->GetView();
227 : :
228 [ # # ][ # # ]: 0 : if(pView && !pView->areMarkHandlesHidden())
[ # # ]
229 : : {
230 : 0 : SdrPageView* pPageView = pView->GetSdrPageView();
231 : :
232 [ # # ]: 0 : if(pPageView)
233 : : {
234 [ # # ]: 0 : for(sal_uInt32 b = 0; b < pPageView->PageWindowCount(); b++)
235 : : {
236 : : // const SdrPageViewWinRec& rPageViewWinRec = rPageViewWinList[b];
237 [ # # ]: 0 : const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(b);
238 : :
239 : 0 : SdrPaintWindow& rPaintWindow = rPageWindow.GetPaintWindow();
240 [ # # ]: 0 : rtl::Reference< ::sdr::overlay::OverlayManager > xManager = rPageWindow.GetOverlayManager();
241 [ # # ][ # # ]: 0 : if(rPaintWindow.OutputToWindow() && xManager.is() )
[ # # ]
242 : : {
243 : 0 : ::sdr::overlay::OverlayObject* pOverlayObject = 0;
244 : :
245 : : // animate focused handles
246 [ # # ]: 0 : if(bFocused)
247 : : {
248 : 0 : const sal_uInt32 nBlinkTime = sal::static_int_cast<sal_uInt32>(rStyleSettings.GetCursorBlinkTime());
249 : :
250 [ # # ][ # # ]: 0 : pOverlayObject = new ::sdr::overlay::OverlayAnimatedBitmapEx(aPosition, aBitmapEx, aBitmapEx2, nBlinkTime, 0, 0, 0, 0 );
251 : : }
252 : : else
253 : : {
254 [ # # ][ # # ]: 0 : pOverlayObject = new ::sdr::overlay::OverlayBitmapEx( aPosition, aBitmapEx, 0, 0 );
255 : : }
256 : :
257 [ # # ]: 0 : xManager->add(*pOverlayObject);
258 [ # # ]: 0 : maOverlayGroup.append(*pOverlayObject);
259 : : }
260 [ # # ]: 0 : }
261 : : }
262 : : }
263 [ # # ][ # # ]: 0 : }
264 : : }
265 : 0 : }
266 : :
267 : : // --------------------------------------------------------------------
268 : :
269 : 0 : sal_Bool AnnotationHdl::IsFocusHdl() const
270 : : {
271 : 0 : return sal_True;
272 : : }
273 : :
274 : : // --------------------------------------------------------------------
275 : :
276 : 0 : bool AnnotationHdl::isMarkable() const
277 : : {
278 : 0 : return false;
279 : : }
280 : :
281 : : // --------------------------------------------------------------------
282 : :
283 : 0 : Pointer AnnotationHdl::GetSdrDragPointer() const
284 : : {
285 : 0 : PointerStyle eStyle = POINTER_NOTALLOWED;
286 [ # # ]: 0 : if( mxTag.is() )
287 : : {
288 [ # # ]: 0 : if( mxTag->isSelected() )
289 : : {
290 : 0 : eStyle = POINTER_MOVE;
291 : : }
292 : : else
293 : : {
294 : 0 : eStyle = POINTER_ARROW;
295 : :
296 : : }
297 : : }
298 : 0 : return Pointer( eStyle );
299 : : }
300 : :
301 : : // ====================================================================
302 : :
303 : 0 : AnnotationTag::AnnotationTag( AnnotationManagerImpl& rManager, ::sd::View& rView, const Reference< XAnnotation >& xAnnotation, Color& rColor, int nIndex, const Font& rFont )
304 : : : SmartTag( rView )
305 : : , mrManager( rManager )
306 : : , mxAnnotation( xAnnotation )
307 : : , maColor( rColor )
308 : : , mnIndex( nIndex )
309 : : , mrFont( rFont )
310 : : , mnClosePopupEvent( 0 )
311 : 0 : , mpListenWindow( 0 )
312 : : {
313 : 0 : }
314 : :
315 : : // --------------------------------------------------------------------
316 : :
317 [ # # ]: 0 : AnnotationTag::~AnnotationTag()
318 : : {
319 : : DBG_ASSERT( !mxAnnotation.is(), "sd::AnnotationTag::~AnnotationTag(), dispose me first!" );
320 [ # # ]: 0 : Dispose();
321 [ # # ]: 0 : }
322 : :
323 : : // --------------------------------------------------------------------
324 : :
325 : : /** returns true if the AnnotationTag handled the event. */
326 : 0 : bool AnnotationTag::MouseButtonDown( const MouseEvent& rMEvt, SmartHdl& /*rHdl*/ )
327 : : {
328 [ # # ]: 0 : if( !mxAnnotation.is() )
329 : 0 : return false;
330 : :
331 : 0 : bool bRet = false;
332 [ # # ]: 0 : if( !isSelected() )
333 : : {
334 [ # # ]: 0 : SmartTagReference xTag( this );
335 [ # # ]: 0 : mrView.getSmartTags().select( xTag );
336 [ # # ]: 0 : bRet = true;
337 : : }
338 : :
339 [ # # ][ # # ]: 0 : if( rMEvt.IsLeft() && !rMEvt.IsRight() )
[ # # ]
340 : : {
341 : 0 : Window* pWindow = mrView.GetViewShell()->GetActiveWindow();
342 [ # # ]: 0 : if( pWindow )
343 : : {
344 : 0 : maMouseDownPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
345 : :
346 [ # # ]: 0 : if( mpListenWindow )
347 [ # # ]: 0 : mpListenWindow->RemoveEventListener( LINK(this, AnnotationTag, WindowEventHandler));
348 : :
349 : 0 : mpListenWindow = pWindow;
350 [ # # ]: 0 : mpListenWindow->AddEventListener( LINK(this, AnnotationTag, WindowEventHandler));
351 : : }
352 : :
353 : 0 : bRet = true;
354 : : }
355 : :
356 : 0 : return bRet;
357 : : }
358 : :
359 : : // --------------------------------------------------------------------
360 : :
361 : : /** returns true if the SmartTag consumes this event. */
362 : 0 : bool AnnotationTag::KeyInput( const KeyEvent& rKEvt )
363 : : {
364 [ # # ]: 0 : if( !mxAnnotation.is() )
365 : 0 : return false;
366 : :
367 : 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
368 [ # # # # : 0 : switch( nCode )
# # ]
369 : : {
370 : : case KEY_DELETE:
371 [ # # ]: 0 : mrManager.DeleteAnnotation( mxAnnotation );
372 : 0 : return true;
373 : :
374 : : case KEY_DOWN:
375 : : case KEY_UP:
376 : : case KEY_LEFT:
377 : : case KEY_RIGHT:
378 : 0 : return OnMove( rKEvt );
379 : :
380 : : case KEY_ESCAPE:
381 : : {
382 [ # # ]: 0 : SmartTagReference xThis( this );
383 [ # # ]: 0 : mrView.getSmartTags().deselect();
384 [ # # ]: 0 : return true;
385 : : }
386 : :
387 : : case KEY_TAB:
388 : 0 : mrManager.SelectNextAnnotation(!rKEvt.GetKeyCode().IsShift());
389 : 0 : return true;
390 : :
391 : : case KEY_RETURN:
392 : : case KEY_SPACE:
393 : 0 : OpenPopup( true );
394 : 0 : return true;
395 : :
396 : : default:
397 : 0 : return false;
398 : : }
399 : : }
400 : :
401 : : /** returns true if the SmartTag consumes this event. */
402 : 0 : bool AnnotationTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
403 : : {
404 : :
405 : 0 : return false;
406 : : }
407 : :
408 : : /** returns true if the SmartTag consumes this event. */
409 : 0 : bool AnnotationTag::Command( const CommandEvent& rCEvt )
410 : : {
411 [ # # ]: 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
412 : : {
413 : 0 : ::Window* pWindow = mrView.GetViewShell()->GetActiveWindow();
414 [ # # ]: 0 : if( pWindow )
415 : : {
416 [ # # ]: 0 : Rectangle aContextRect(rCEvt.GetMousePosPixel(),Size(1,1));
417 [ # # ]: 0 : mrManager.ExecuteAnnotationContextMenu( mxAnnotation, pWindow, aContextRect );
418 : 0 : return true;
419 : : }
420 : : }
421 : :
422 : 0 : return false;
423 : : }
424 : :
425 : 0 : void AnnotationTag::Move( int nDX, int nDY )
426 : : {
427 [ # # ]: 0 : if( mxAnnotation.is() )
428 : : {
429 [ # # ][ # # ]: 0 : if( mrManager.GetDoc()->IsUndoEnabled() )
430 [ # # ][ # # ]: 0 : mrManager.GetDoc()->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_MOVE ) ) );
[ # # ][ # # ]
431 : :
432 [ # # ][ # # ]: 0 : RealPoint2D aPosition( mxAnnotation->getPosition() );
433 : 0 : aPosition.X += (double)nDX / 100.0;
434 : 0 : aPosition.Y += (double)nDY / 100.0;
435 [ # # ][ # # ]: 0 : mxAnnotation->setPosition( aPosition );
436 : :
437 [ # # ][ # # ]: 0 : if( mrManager.GetDoc()->IsUndoEnabled() )
438 [ # # ]: 0 : mrManager.GetDoc()->EndUndo();
439 : :
440 [ # # ]: 0 : mrView.updateHandles();
441 : : }
442 : 0 : }
443 : :
444 : 0 : bool AnnotationTag::OnMove( const KeyEvent& rKEvt )
445 : : {
446 : 0 : long nX = 0;
447 : 0 : long nY = 0;
448 : :
449 [ # # # # : 0 : switch( rKEvt.GetKeyCode().GetCode() )
# ]
450 : : {
451 : 0 : case KEY_UP: nY = -1; break;
452 : 0 : case KEY_DOWN: nY = 1; break;
453 : 0 : case KEY_LEFT: nX = -1; break;
454 : 0 : case KEY_RIGHT: nX = 1; break;
455 : 0 : default: break;
456 : : }
457 : :
458 [ # # ]: 0 : if(rKEvt.GetKeyCode().IsMod2())
459 : : {
460 [ # # ]: 0 : OutputDevice* pOut = mrView.GetViewShell()->GetActiveWindow();
461 [ # # ][ # # ]: 0 : Size aLogicSizeOnePixel = (pOut) ? pOut->PixelToLogic(Size(1,1)) : Size(100, 100);
[ # # ][ # # ]
462 : 0 : nX *= aLogicSizeOnePixel.Width();
463 : 0 : nY *= aLogicSizeOnePixel.Height();
464 : : }
465 : : else
466 : : {
467 : : // old, fixed move distance
468 : 0 : nX *= 100;
469 : 0 : nY *= 100;
470 : : }
471 : :
472 [ # # ][ # # ]: 0 : if( nX || nY )
473 : : {
474 : : // move the annotation
475 : 0 : Move( nX, nY );
476 : : }
477 : :
478 : 0 : return true;
479 : : }
480 : :
481 : : // --------------------------------------------------------------------
482 : :
483 : 0 : void AnnotationTag::CheckPossibilities()
484 : : {
485 : 0 : }
486 : :
487 : : // --------------------------------------------------------------------
488 : :
489 : 0 : sal_uLong AnnotationTag::GetMarkablePointCount() const
490 : : {
491 : 0 : return 0;
492 : : }
493 : :
494 : : // --------------------------------------------------------------------
495 : :
496 : 0 : sal_uLong AnnotationTag::GetMarkedPointCount() const
497 : : {
498 : 0 : return 0;
499 : : }
500 : :
501 : : // --------------------------------------------------------------------
502 : :
503 : 0 : sal_Bool AnnotationTag::MarkPoint(SdrHdl& /*rHdl*/, sal_Bool /*bUnmark*/ )
504 : : {
505 : 0 : sal_Bool bRet=sal_False;
506 : 0 : return bRet;
507 : : }
508 : :
509 : : // --------------------------------------------------------------------
510 : :
511 : 0 : sal_Bool AnnotationTag::MarkPoints(const Rectangle* /*pRect*/, sal_Bool /*bUnmark*/ )
512 : : {
513 : 0 : sal_Bool bChgd=sal_False;
514 : 0 : return bChgd;
515 : : }
516 : :
517 : : // --------------------------------------------------------------------
518 : :
519 : 0 : bool AnnotationTag::getContext( SdrViewContext& /*rContext*/ )
520 : : {
521 : 0 : return false;
522 : : }
523 : :
524 : : // --------------------------------------------------------------------
525 : :
526 : 0 : void AnnotationTag::addCustomHandles( SdrHdlList& rHandlerList )
527 : : {
528 [ # # ]: 0 : if( mxAnnotation.is() )
529 : : {
530 [ # # ]: 0 : SmartTagReference xThis( this );
531 : 0 : Point aPoint;
532 [ # # ][ # # ]: 0 : AnnotationHdl* pHdl = new AnnotationHdl( xThis, mxAnnotation, aPoint );
533 : 0 : pHdl->SetObjHdlNum( SMART_TAG_HDL_NUM );
534 : 0 : pHdl->SetPageView( mrView.GetSdrPageView() );
535 : :
536 [ # # ][ # # ]: 0 : RealPoint2D aPosition( mxAnnotation->getPosition() );
537 : 0 : Point aBasePos( static_cast<long>(aPosition.X * 100.0), static_cast<long>(aPosition.Y * 100.0) );
538 [ # # ]: 0 : pHdl->SetPos( aBasePos );
539 : :
540 [ # # ][ # # ]: 0 : rHandlerList.AddHdl( pHdl );
541 : : }
542 : 0 : }
543 : :
544 : : // --------------------------------------------------------------------
545 : :
546 : 0 : void AnnotationTag::disposing()
547 : : {
548 [ # # ]: 0 : if( mpListenWindow )
549 : : {
550 [ # # ]: 0 : mpListenWindow->RemoveEventListener( LINK(this, AnnotationTag, WindowEventHandler));
551 : : }
552 : :
553 [ # # ]: 0 : if( mnClosePopupEvent )
554 : : {
555 : 0 : Application::RemoveUserEvent( mnClosePopupEvent );
556 : 0 : mnClosePopupEvent = 0;
557 : : }
558 : :
559 : 0 : mxAnnotation.clear();
560 : 0 : ClosePopup();
561 : 0 : SmartTag::disposing();
562 : 0 : }
563 : :
564 : : // --------------------------------------------------------------------
565 : :
566 : 0 : void AnnotationTag::select()
567 : : {
568 : 0 : SmartTag::select();
569 : :
570 : 0 : mrManager.onTagSelected( *this );
571 : :
572 : 0 : Window* pWindow = mrView.GetViewShell()->GetActiveWindow();
573 [ # # ]: 0 : if( pWindow )
574 : : {
575 [ # # ][ # # ]: 0 : RealPoint2D aPosition( mxAnnotation->getPosition() );
576 : 0 : Point aPos( static_cast<long>(aPosition.X * 100.0), static_cast<long>(aPosition.Y * 100.0) );
577 : :
578 [ # # ][ # # ]: 0 : Rectangle aVisRect( aPos, pWindow->PixelToLogic(maSize) );
579 [ # # ]: 0 : mrView.MakeVisible(aVisRect, *pWindow);
580 : : }
581 : 0 : }
582 : :
583 : : // --------------------------------------------------------------------
584 : :
585 : 0 : void AnnotationTag::deselect()
586 : : {
587 : 0 : SmartTag::deselect();
588 : :
589 : 0 : ClosePopup();
590 : :
591 : 0 : mrManager.onTagDeselected( *this );
592 : 0 : }
593 : :
594 : : // --------------------------------------------------------------------
595 : :
596 : 0 : BitmapEx AnnotationTag::CreateAnnotationBitmap( bool bSelected )
597 : : {
598 [ # # ]: 0 : VirtualDevice aVDev;
599 : :
600 [ # # ][ # # ]: 0 : OUString sAuthor( getInitials( mxAnnotation->getAuthor() ) );
601 : 0 : sAuthor += OUString( sal_Unicode( ' ' ) );
602 : 0 : sAuthor += OUString::valueOf( (sal_Int32)mnIndex );
603 : :
604 [ # # ]: 0 : aVDev.SetFont( mrFont );
605 : :
606 : 0 : const int BORDER_X = 4; // pixels
607 : 0 : const int BORDER_Y = 4; // pixels
608 : :
609 [ # # ][ # # ]: 0 : maSize = Size( aVDev.GetTextWidth( sAuthor ) + 2*BORDER_X, aVDev.GetTextHeight() + 2*BORDER_Y );
[ # # ][ # # ]
610 [ # # ]: 0 : aVDev.SetOutputSizePixel( maSize, sal_False );
611 : :
612 : 0 : Color aBorderColor( maColor );
613 : :
614 [ # # ]: 0 : if( bSelected )
615 : : {
616 [ # # ]: 0 : aBorderColor.Invert();
617 : : }
618 : : else
619 : : {
620 [ # # ][ # # ]: 0 : if( maColor.IsDark() )
621 : : {
622 [ # # ]: 0 : aBorderColor.IncreaseLuminance( 32 );
623 : : }
624 : : else
625 : : {
626 [ # # ]: 0 : aBorderColor.DecreaseLuminance( 32 );
627 : : }
628 : : }
629 : :
630 : 0 : Point aPos;
631 [ # # ]: 0 : Rectangle aBorderRect( aPos, maSize );
632 [ # # ]: 0 : aVDev.SetLineColor(aBorderColor);
633 [ # # ]: 0 : aVDev.SetFillColor(maColor);
634 [ # # ]: 0 : aVDev.DrawRect( aBorderRect );
635 : :
636 [ # # ][ # # ]: 0 : aVDev.SetTextColor( maColor.IsDark() ? COL_WHITE : COL_BLACK );
[ # # ]
637 [ # # ][ # # ]: 0 : aVDev.DrawText( Point( BORDER_X, BORDER_Y ), sAuthor );
[ # # ]
638 : :
639 [ # # ][ # # ]: 0 : return aVDev.GetBitmapEx( aPos, maSize );
640 : : }
641 : :
642 : 0 : void AnnotationTag::OpenPopup( bool bEdit )
643 : : {
644 [ # # ]: 0 : if( !mxAnnotation.is() )
645 : 0 : return;
646 : :
647 [ # # ]: 0 : if( !mpAnnotationWindow.get() )
648 : : {
649 [ # # ]: 0 : ::Window* pWindow = dynamic_cast< ::Window* >( getView().GetFirstOutputDevice() );
650 [ # # ]: 0 : if( pWindow )
651 : : {
652 [ # # ][ # # ]: 0 : RealPoint2D aPosition( mxAnnotation->getPosition() );
653 [ # # ][ # # ]: 0 : Point aPos( pWindow->OutputToScreenPixel( pWindow->LogicToPixel( Point( static_cast<long>(aPosition.X * 100.0), static_cast<long>(aPosition.Y * 100.0) ) ) ) );
654 : :
655 : 0 : aPos.X() += 4; // magic!
656 : 0 : aPos.Y() += 1;
657 : :
658 [ # # ]: 0 : Rectangle aRect( aPos, maSize );
659 : :
660 [ # # ][ # # ]: 0 : mpAnnotationWindow.reset( new AnnotationWindow( mrManager, mrView.GetDocSh(), pWindow->GetWindow(WINDOW_FRAME) ) );
[ # # ]
661 [ # # ]: 0 : mpAnnotationWindow->InitControls();
662 [ # # ]: 0 : mpAnnotationWindow->setAnnotation(mxAnnotation);
663 : :
664 : 0 : sal_uInt16 nArrangeIndex = 0;
665 [ # # ]: 0 : Point aPopupPos( FloatingWindow::CalcFloatingPosition( mpAnnotationWindow.get(), aRect, FLOATWIN_POPUPMODE_RIGHT, nArrangeIndex ) );
666 : 0 : Size aPopupSize( 320, 240 );
667 : :
668 [ # # ]: 0 : mpAnnotationWindow->SetPosSizePixel( aPopupPos, aPopupSize );
669 [ # # ]: 0 : mpAnnotationWindow->DoResize();
670 : :
671 [ # # ]: 0 : mpAnnotationWindow->Show();
672 [ # # ]: 0 : mpAnnotationWindow->GrabFocus();
673 [ # # ][ # # ]: 0 : mpAnnotationWindow->AddEventListener( LINK(this, AnnotationTag, WindowEventHandler));
674 : : }
675 : : }
676 : :
677 [ # # ][ # # ]: 0 : if( bEdit && mpAnnotationWindow.get() )
[ # # ]
678 : 0 : mpAnnotationWindow->StartEdit();
679 : : }
680 : :
681 : 0 : void AnnotationTag::ClosePopup()
682 : : {
683 [ # # ]: 0 : if( mpAnnotationWindow.get() )
684 : : {
685 [ # # ]: 0 : mpAnnotationWindow->RemoveEventListener( LINK(this, AnnotationTag, WindowEventHandler));
686 : 0 : mpAnnotationWindow->Deactivate();
687 : 0 : mpAnnotationWindow.reset();
688 : : }
689 : 0 : }
690 : :
691 : 0 : IMPL_LINK(AnnotationTag, WindowEventHandler, VclWindowEvent*, pEvent)
692 : : {
693 [ # # ]: 0 : if( pEvent != NULL )
694 : : {
695 : 0 : ::Window* pWindow = pEvent->GetWindow();
696 : :
697 [ # # ]: 0 : if( pWindow )
698 : : {
699 [ # # ]: 0 : if( pWindow == mpAnnotationWindow.get() )
700 : : {
701 [ # # ]: 0 : if( pEvent->GetId() == VCLEVENT_WINDOW_DEACTIVATE )
702 : : {
703 [ # # ]: 0 : if( mnClosePopupEvent )
704 : 0 : Application::RemoveUserEvent( mnClosePopupEvent );
705 : :
706 [ # # ]: 0 : mnClosePopupEvent = Application::PostUserEvent( LINK( this, AnnotationTag, ClosePopupHdl ) );
707 : : }
708 : : }
709 [ # # ]: 0 : else if( pWindow == mpListenWindow )
710 : : {
711 [ # # # # ]: 0 : switch( pEvent->GetId() )
712 : : {
713 : : case VCLEVENT_WINDOW_MOUSEBUTTONUP:
714 : : {
715 : : // if we stop pressing the button without a mouse move we open the popup
716 [ # # ]: 0 : mpListenWindow->RemoveEventListener( LINK(this, AnnotationTag, WindowEventHandler));
717 : 0 : mpListenWindow = 0;
718 [ # # ]: 0 : if( mpAnnotationWindow.get() == 0 )
719 : 0 : OpenPopup(false);
720 : : }
721 : 0 : break;
722 : : case VCLEVENT_WINDOW_MOUSEMOVE:
723 : : {
724 : : // if we move the mouse after a button down we wan't to start draging
725 [ # # ]: 0 : mpListenWindow->RemoveEventListener( LINK(this, AnnotationTag, WindowEventHandler));
726 : 0 : mpListenWindow = 0;
727 : :
728 : 0 : SdrHdl* pHdl = mrView.PickHandle(maMouseDownPos);
729 [ # # ]: 0 : if( pHdl )
730 : : {
731 [ # # ]: 0 : mrView.BrkAction();
732 [ # # ]: 0 : const sal_uInt16 nDrgLog = (sal_uInt16)pWindow->PixelToLogic(Size(DRGPIX,0)).Width();
733 : :
734 [ # # ]: 0 : rtl::Reference< AnnotationTag > xTag( this );
735 : :
736 [ # # ][ # # ]: 0 : SdrDragMethod* pDragMethod = new AnnotationDragMove( mrView, xTag );
737 [ # # ][ # # ]: 0 : mrView.BegDragObj(maMouseDownPos, NULL, pHdl, nDrgLog, pDragMethod );
738 : : }
739 : : }
740 : 0 : break;
741 : : case VCLEVENT_OBJECT_DYING:
742 : 0 : mpListenWindow = 0;
743 : 0 : break;
744 : : }
745 : : }
746 : : }
747 : : }
748 : 0 : return sal_True;
749 : : }
750 : :
751 : 0 : IMPL_LINK_NOARG(AnnotationTag, ClosePopupHdl)
752 : : {
753 : 0 : mnClosePopupEvent = 0;
754 : 0 : ClosePopup();
755 : 0 : return 0;
756 : : }
757 : :
758 : : } // end of namespace sd
759 : :
760 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|