LCOV - code coverage report
Current view: top level - sd/source/ui/annotations - annotationtag.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 308 0.3 %
Date: 2014-11-03 Functions: 2 43 4.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10