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