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