1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2008 by Sun Microsystems, Inc. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * $RCSfile: $ 10*cdf0e10cSrcweir * $Revision: $ 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * This file is part of OpenOffice.org. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir * 18*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir * 24*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir * 29*cdf0e10cSrcweir ************************************************************************/ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 32*cdf0e10cSrcweir #include "precompiled_sd.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "sddll.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 37*cdf0e10cSrcweir #include <sfx2/imagemgr.hxx> 38*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 39*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 40*cdf0e10cSrcweir #include <sfx2/app.hxx> 41*cdf0e10cSrcweir #include <sfx2/request.hxx> 42*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <tools/rcid.h> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <vcl/help.hxx> 47*cdf0e10cSrcweir #include <vcl/imagerepository.hxx> 48*cdf0e10cSrcweir #include <vcl/lazydelete.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx> 51*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx> 52*cdf0e10cSrcweir #include <svx/sdr/overlay/overlayanimatedbitmapex.hxx> 53*cdf0e10cSrcweir #include <svx/sdr/overlay/overlaybitmapex.hxx> 54*cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanager.hxx> 55*cdf0e10cSrcweir #include <svx/svxids.hrc> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include "view/viewoverlaymanager.hxx" 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #include "res_bmp.hrc" 60*cdf0e10cSrcweir #include "DrawDocShell.hxx" 61*cdf0e10cSrcweir #include "DrawViewShell.hxx" 62*cdf0e10cSrcweir #include "DrawController.hxx" 63*cdf0e10cSrcweir #include "glob.hrc" 64*cdf0e10cSrcweir #include "strings.hrc" 65*cdf0e10cSrcweir #include "sdresid.hxx" 66*cdf0e10cSrcweir #include "EventMultiplexer.hxx" 67*cdf0e10cSrcweir #include "ViewShellManager.hxx" 68*cdf0e10cSrcweir #include "helpids.h" 69*cdf0e10cSrcweir #include "sdpage.hxx" 70*cdf0e10cSrcweir #include "drawdoc.hxx" 71*cdf0e10cSrcweir #include "smarttag.hxx" 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir using ::rtl::OUString; 74*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 75*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir namespace sd { 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir class ImageButtonHdl; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // -------------------------------------------------------------------- 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir static sal_uInt16 gButtonSlots[] = { SID_INSERT_TABLE, SID_INSERT_DIAGRAM, SID_INSERT_GRAPHIC, SID_INSERT_AVMEDIA }; 84*cdf0e10cSrcweir static sal_uInt16 gButtonToolTips[] = { STR_INSERT_TABLE, STR_INSERT_CHART, STR_INSERT_PICTURE, STR_INSERT_MOVIE }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // -------------------------------------------------------------------- 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir static BitmapEx loadImageResource( sal_uInt16 nId ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir SdResId aResId( nId ); 91*cdf0e10cSrcweir aResId.SetRT( RSC_BITMAP ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir return BitmapEx( aResId ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // -------------------------------------------------------------------- 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir static BitmapEx* getButtonImage( int index, bool large ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir static vcl::DeleteOnDeinit< BitmapEx > gSmallButtonImages[BMP_PLACEHOLDER_SMALL_END - BMP_PLACEHOLDER_SMALL_START] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 101*cdf0e10cSrcweir static vcl::DeleteOnDeinit< BitmapEx > gLargeButtonImages[BMP_PLACEHOLDER_LARGE_END - BMP_PLACEHOLDER_LARGE_START] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if( !gSmallButtonImages[0].get() ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < (BMP_PLACEHOLDER_SMALL_END-BMP_PLACEHOLDER_SMALL_START); i++ ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir gSmallButtonImages[i].set( new BitmapEx( loadImageResource( BMP_PLACEHOLDER_SMALL_START + i ) ) ); 108*cdf0e10cSrcweir gLargeButtonImages[i].set( new BitmapEx( loadImageResource( BMP_PLACEHOLDER_LARGE_START + i ) ) ); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if( large ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir return gLargeButtonImages[index].get(); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir else 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return gSmallButtonImages[index].get(); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // -------------------------------------------------------------------- 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir const sal_uInt32 SMART_TAG_HDL_NUM = SAL_MAX_UINT32; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir class ChangePlaceholderTag : public SmartTag 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir friend class ImageButtonHdl; 129*cdf0e10cSrcweir public: 130*cdf0e10cSrcweir ChangePlaceholderTag( ViewOverlayManager& rManager, ::sd::View& rView, SdrObject& rPlaceholderObj ); 131*cdf0e10cSrcweir virtual ~ChangePlaceholderTag(); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /** returns true if the SmartTag handled the event. */ 134*cdf0e10cSrcweir virtual bool MouseButtonDown( const MouseEvent&, SmartHdl& ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir /** returns true if the SmartTag consumes this event. */ 137*cdf0e10cSrcweir virtual bool KeyInput( const KeyEvent& rKEvt ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir BitmapEx createOverlayImage( int nHighlight = -1 ); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir protected: 142*cdf0e10cSrcweir virtual void addCustomHandles( SdrHdlList& rHandlerList ); 143*cdf0e10cSrcweir virtual void disposing(); 144*cdf0e10cSrcweir virtual void select(); 145*cdf0e10cSrcweir virtual void deselect(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir private: 148*cdf0e10cSrcweir ViewOverlayManager& mrManager; 149*cdf0e10cSrcweir SdrObjectWeakRef mxPlaceholderObj; 150*cdf0e10cSrcweir }; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir class ImageButtonHdl : public SmartHdl 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir public: 155*cdf0e10cSrcweir ImageButtonHdl( const SmartTagReference& xTag, /* sal_uInt16 nSID, const Image& rImage, const Image& rImageMO, */ const Point& rPnt ); 156*cdf0e10cSrcweir virtual ~ImageButtonHdl(); 157*cdf0e10cSrcweir virtual void CreateB2dIAObject(); 158*cdf0e10cSrcweir virtual sal_Bool IsFocusHdl() const; 159*cdf0e10cSrcweir virtual Pointer GetPointer() const; 160*cdf0e10cSrcweir virtual bool isMarkable() const; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir virtual void onMouseEnter(const MouseEvent& rMEvt); 163*cdf0e10cSrcweir virtual void onMouseLeave(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir int getHighlightId() const { return mnHighlightId; } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir void HideTip(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir private: 170*cdf0e10cSrcweir rtl::Reference< ChangePlaceholderTag > mxTag; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir int mnHighlightId; 173*cdf0e10cSrcweir Size maImageSize; 174*cdf0e10cSrcweir sal_uLong mnTip; 175*cdf0e10cSrcweir }; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // -------------------------------------------------------------------- 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir ImageButtonHdl::ImageButtonHdl( const SmartTagReference& xTag /*, sal_uInt16 nSID, const Image& rImage, const Image& rImageMO*/, const Point& rPnt ) 180*cdf0e10cSrcweir : SmartHdl( xTag, rPnt ) 181*cdf0e10cSrcweir , mxTag( dynamic_cast< ChangePlaceholderTag* >( xTag.get() ) ) 182*cdf0e10cSrcweir , mnHighlightId( -1 ) 183*cdf0e10cSrcweir , maImageSize( 42, 42 ) 184*cdf0e10cSrcweir , mnTip( 0 ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // -------------------------------------------------------------------- 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir ImageButtonHdl::~ImageButtonHdl() 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir HideTip(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // -------------------------------------------------------------------- 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir void ImageButtonHdl::HideTip() 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir if( mnTip ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir Help::HideTip( mnTip ); 202*cdf0e10cSrcweir mnTip = 0; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // -------------------------------------------------------------------- 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir extern ::rtl::OUString ImplRetrieveLabelFromCommand( const Reference< XFrame >& xFrame, const OUString& aCmdURL ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir void ImageButtonHdl::onMouseEnter(const MouseEvent& rMEvt) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir int nHighlightId = 0; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir if( pHdlList && pHdlList->GetView()) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir OutputDevice* pDev = pHdlList->GetView()->GetFirstOutputDevice(); 217*cdf0e10cSrcweir if( pDev == 0 ) 218*cdf0e10cSrcweir pDev = Application::GetDefaultDevice(); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Point aMDPos( rMEvt.GetPosPixel() ); 221*cdf0e10cSrcweir aMDPos -= pDev->LogicToPixel( GetPos() ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir nHighlightId += aMDPos.X() > maImageSize.Width() ? 1 : 0; 224*cdf0e10cSrcweir nHighlightId += aMDPos.Y() > maImageSize.Height() ? 2 : 0; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir if( mnHighlightId != nHighlightId ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir HideTip(); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir mnHighlightId = nHighlightId; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if( pHdlList ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir SdResId aResId( gButtonToolTips[mnHighlightId] ); 235*cdf0e10cSrcweir aResId.SetRT( RSC_STRING ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir String aHelpText( aResId ); 238*cdf0e10cSrcweir Rectangle aScreenRect( pDev->LogicToPixel( GetPos() ), maImageSize ); 239*cdf0e10cSrcweir mnTip = Help::ShowTip( static_cast< ::Window* >( pHdlList->GetView()->GetFirstOutputDevice() ), aScreenRect, aHelpText, 0 ) ; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir Touch(); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir // -------------------------------------------------------------------- 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir void ImageButtonHdl::onMouseLeave() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir mnHighlightId = -1; 251*cdf0e10cSrcweir HideTip(); 252*cdf0e10cSrcweir Touch(); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir // -------------------------------------------------------------------- 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void ImageButtonHdl::CreateB2dIAObject() 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir // first throw away old one 260*cdf0e10cSrcweir GetRidOfIAObject(); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir const Point aTagPos( GetPos() ); 263*cdf0e10cSrcweir basegfx::B2DPoint aPosition( aTagPos.X(), aTagPos.Y() ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir BitmapEx aBitmapEx( mxTag->createOverlayImage( mnHighlightId ) ); // maImageMO.GetBitmapEx() : maImage.GetBitmapEx() ); 266*cdf0e10cSrcweir maImageSize = aBitmapEx.GetSizePixel(); 267*cdf0e10cSrcweir maImageSize.Width() >>= 1; 268*cdf0e10cSrcweir maImageSize.Height() >>= 1; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if(pHdlList) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir SdrMarkView* pView = pHdlList->GetView(); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir if(pView && !pView->areMarkHandlesHidden()) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir SdrPageView* pPageView = pView->GetSdrPageView(); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if(pPageView) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir for(sal_uInt32 b = 0; b < pPageView->PageWindowCount(); b++) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(b); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir SdrPaintWindow& rPaintWindow = rPageWindow.GetPaintWindow(); 285*cdf0e10cSrcweir if(rPaintWindow.OutputToWindow() && rPageWindow.GetOverlayManager() ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir ::sdr::overlay::OverlayObject* pOverlayObject = 0; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir pOverlayObject = new ::sdr::overlay::OverlayBitmapEx( aPosition, aBitmapEx, 0, 0 ); 290*cdf0e10cSrcweir rPageWindow.GetOverlayManager()->add(*pOverlayObject); 291*cdf0e10cSrcweir maOverlayGroup.append(*pOverlayObject); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // -------------------------------------------------------------------- 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir sal_Bool ImageButtonHdl::IsFocusHdl() const 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir return false; 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // -------------------------------------------------------------------- 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir bool ImageButtonHdl::isMarkable() const 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir return false; 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir // -------------------------------------------------------------------- 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir Pointer ImageButtonHdl::GetPointer() const 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir return Pointer( POINTER_ARROW ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir // ==================================================================== 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir ChangePlaceholderTag::ChangePlaceholderTag( ViewOverlayManager& rManager, ::sd::View& rView, SdrObject& rPlaceholderObj ) 323*cdf0e10cSrcweir : SmartTag( rView ) 324*cdf0e10cSrcweir , mrManager( rManager ) 325*cdf0e10cSrcweir , mxPlaceholderObj( &rPlaceholderObj ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir // -------------------------------------------------------------------- 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir ChangePlaceholderTag::~ChangePlaceholderTag() 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir // -------------------------------------------------------------------- 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir /** returns true if the ChangePlaceholderTag handled the event. */ 338*cdf0e10cSrcweir bool ChangePlaceholderTag::MouseButtonDown( const MouseEvent& /*rMEvt*/, SmartHdl& rHdl ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir int nHighlightId = static_cast< ImageButtonHdl& >(rHdl).getHighlightId(); 341*cdf0e10cSrcweir if( nHighlightId >= 0 ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir sal_uInt16 nSID = gButtonSlots[nHighlightId]; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir if( mxPlaceholderObj.get() ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir // mark placeholder if it is not currently marked (or if also others are marked) 348*cdf0e10cSrcweir if( !mrView.IsObjMarked( mxPlaceholderObj.get() ) || (mrView.GetMarkedObjectList().GetMarkCount() != 1) ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir SdrPageView* pPV = mrView.GetSdrPageView(); 351*cdf0e10cSrcweir mrView.UnmarkAllObj(pPV ); 352*cdf0e10cSrcweir mrView.MarkObj(mxPlaceholderObj.get(), pPV, sal_False); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir mrView.GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( nSID, SFX_CALLMODE_ASYNCHRON); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir return false; 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir // -------------------------------------------------------------------- 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir /** returns true if the SmartTag consumes this event. */ 364*cdf0e10cSrcweir bool ChangePlaceholderTag::KeyInput( const KeyEvent& rKEvt ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); 367*cdf0e10cSrcweir switch( nCode ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir case KEY_DOWN: 370*cdf0e10cSrcweir case KEY_UP: 371*cdf0e10cSrcweir case KEY_LEFT: 372*cdf0e10cSrcweir case KEY_RIGHT: 373*cdf0e10cSrcweir case KEY_ESCAPE: 374*cdf0e10cSrcweir case KEY_TAB: 375*cdf0e10cSrcweir case KEY_RETURN: 376*cdf0e10cSrcweir case KEY_SPACE: 377*cdf0e10cSrcweir default: 378*cdf0e10cSrcweir return false; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir // -------------------------------------------------------------------- 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir BitmapEx ChangePlaceholderTag::createOverlayImage( int nHighlight ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir BitmapEx aRet; 387*cdf0e10cSrcweir if( mxPlaceholderObj.is() ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir SdrObject* pPlaceholder = mxPlaceholderObj.get(); 390*cdf0e10cSrcweir SmartTagReference xThis( this ); 391*cdf0e10cSrcweir const Rectangle& rSnapRect = pPlaceholder->GetSnapRect(); 392*cdf0e10cSrcweir const Point aPoint; 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir OutputDevice* pDev = mrView.GetFirstOutputDevice(); 395*cdf0e10cSrcweir if( pDev == 0 ) 396*cdf0e10cSrcweir pDev = Application::GetDefaultDevice(); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir Size aShapeSizePix = pDev->LogicToPixel(rSnapRect.GetSize()); 399*cdf0e10cSrcweir long nShapeSizePix = std::min(aShapeSizePix.Width(),aShapeSizePix.Height()); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir bool bLarge = nShapeSizePix > 250; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir Size aSize( getButtonImage( 0, bLarge )->GetSizePixel() ); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir aRet.SetSizePixel( Size( aSize.Width() << 1, aSize.Height() << 1 ) ); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir const Rectangle aRectSrc( Point( 0, 0 ), aSize ); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir aRet = *(getButtonImage((nHighlight == 0) ? 4 : 0, bLarge)); 410*cdf0e10cSrcweir aRet.Expand( aSize.Width(), aSize.Height(), NULL, sal_True ); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir aRet.CopyPixel( Rectangle( Point( aSize.Width(), 0 ), aSize ), aRectSrc, getButtonImage((nHighlight == 1) ? 5 : 1, bLarge) ); 413*cdf0e10cSrcweir aRet.CopyPixel( Rectangle( Point( 0, aSize.Height() ), aSize ), aRectSrc, getButtonImage((nHighlight == 2) ? 6 : 2, bLarge) ); 414*cdf0e10cSrcweir aRet.CopyPixel( Rectangle( Point( aSize.Width(), aSize.Height() ), aSize ), aRectSrc, getButtonImage((nHighlight == 3) ? 7 : 3, bLarge) ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir return aRet; 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void ChangePlaceholderTag::addCustomHandles( SdrHdlList& rHandlerList ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir if( mxPlaceholderObj.is() ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir SdrObject* pPlaceholder = mxPlaceholderObj.get(); 425*cdf0e10cSrcweir SmartTagReference xThis( this ); 426*cdf0e10cSrcweir const Rectangle& rSnapRect = pPlaceholder->GetSnapRect(); 427*cdf0e10cSrcweir const Point aPoint; 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir OutputDevice* pDev = mrView.GetFirstOutputDevice(); 430*cdf0e10cSrcweir if( pDev == 0 ) 431*cdf0e10cSrcweir pDev = Application::GetDefaultDevice(); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir Size aShapeSizePix = pDev->LogicToPixel(rSnapRect.GetSize()); 434*cdf0e10cSrcweir long nShapeSizePix = std::min(aShapeSizePix.Width(),aShapeSizePix.Height()); 435*cdf0e10cSrcweir if( 50 > nShapeSizePix ) 436*cdf0e10cSrcweir return; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir bool bLarge = nShapeSizePix > 250; 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir Size aButtonSize( pDev->PixelToLogic( getButtonImage(0, bLarge )->GetSizePixel()) ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir const int nColumns = 2; 443*cdf0e10cSrcweir const int nRows = 2; 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir long all_width = nColumns * aButtonSize.Width(); 446*cdf0e10cSrcweir long all_height = nRows * aButtonSize.Height(); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir Point aPos( rSnapRect.Center() ); 449*cdf0e10cSrcweir aPos.X() -= all_width >> 1; 450*cdf0e10cSrcweir aPos.Y() -= all_height >> 1; 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir ImageButtonHdl* pHdl = new ImageButtonHdl( xThis, aPoint ); 453*cdf0e10cSrcweir pHdl->SetObjHdlNum( SMART_TAG_HDL_NUM ); 454*cdf0e10cSrcweir pHdl->SetPageView( mrView.GetSdrPageView() ); 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir pHdl->SetPos( aPos ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir rHandlerList.AddHdl( pHdl ); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir // -------------------------------------------------------------------- 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir void ChangePlaceholderTag::disposing() 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir SmartTag::disposing(); 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir // -------------------------------------------------------------------- 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir void ChangePlaceholderTag::select() 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir SmartTag::select(); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir // -------------------------------------------------------------------- 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir void ChangePlaceholderTag::deselect() 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir SmartTag::deselect(); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir // -------------------------------------------------------------------- 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir ViewOverlayManager::ViewOverlayManager( ViewShellBase& rViewShellBase ) 486*cdf0e10cSrcweir : mrBase( rViewShellBase ) 487*cdf0e10cSrcweir , mnUpdateTagsEvent( 0 ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir Link aLink( LINK(this,ViewOverlayManager,EventMultiplexerListener) ); 490*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->AddEventListener(aLink, tools::EventMultiplexerEvent::EID_CURRENT_PAGE 491*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED 492*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_VIEW_ADDED 493*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_BEGIN_TEXT_EDIT 494*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_END_TEXT_EDIT ); 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir StartListening( *mrBase.GetDocShell() ); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir // -------------------------------------------------------------------- 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir ViewOverlayManager::~ViewOverlayManager() 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir Link aLink( LINK(this,ViewOverlayManager,EventMultiplexerListener) ); 504*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->RemoveEventListener( aLink ); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir if( mnUpdateTagsEvent ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir Application::RemoveUserEvent( mnUpdateTagsEvent ); 509*cdf0e10cSrcweir mnUpdateTagsEvent = 0; 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir DisposeTags(); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir // -------------------------------------------------------------------- 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir void ViewOverlayManager::Notify(SfxBroadcaster&, const SfxHint& rHint) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint); 520*cdf0e10cSrcweir if (pSimpleHint != NULL) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir if (pSimpleHint->GetId() == SFX_HINT_DOCCHANGED) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir UpdateTags(); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir void ViewOverlayManager::onZoomChanged() 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if( !maTagVector.empty() ) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir UpdateTags(); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir void ViewOverlayManager::UpdateTags() 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir if( !mnUpdateTagsEvent ) 540*cdf0e10cSrcweir mnUpdateTagsEvent = Application::PostUserEvent( LINK( this, ViewOverlayManager, UpdateTagsHdl ) ); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir IMPL_LINK(ViewOverlayManager,UpdateTagsHdl, void *, EMPTYARG) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir OSL_TRACE("ViewOverlayManager::UpdateTagsHdl"); 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir mnUpdateTagsEvent = 0; 548*cdf0e10cSrcweir bool bChanges = DisposeTags(); 549*cdf0e10cSrcweir bChanges |= CreateTags(); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir if( bChanges && mrBase.GetDrawView() ) 552*cdf0e10cSrcweir static_cast< ::sd::View* >( mrBase.GetDrawView() )->updateHandles(); 553*cdf0e10cSrcweir return 0; 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir bool ViewOverlayManager::CreateTags() 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir bool bChanges = false; 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir SdPage* pPage = mrBase.GetMainViewShell()->getCurrentPage(); 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir if( pPage && !pPage->IsMasterPage() && (pPage->GetPageKind() == PK_STANDARD) ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList(); 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir for( std::list< SdrObject* >::const_iterator iter( rShapes.begin() ); iter != rShapes.end(); iter++ ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir if( (*iter)->IsEmptyPresObj() && ((*iter)->GetObjIdentifier() == OBJ_OUTLINETEXT) && (mrBase.GetDrawView()->GetTextEditObject() != (*iter)) ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir rtl::Reference< SmartTag > xTag( new ChangePlaceholderTag( *this, *mrBase.GetMainViewShell()->GetView(), *(*iter) ) ); 571*cdf0e10cSrcweir maTagVector.push_back(xTag); 572*cdf0e10cSrcweir bChanges = true; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir return bChanges; 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir // -------------------------------------------------------------------- 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir bool ViewOverlayManager::DisposeTags() 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir if( !maTagVector.empty() ) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir ViewTagVector vec; 587*cdf0e10cSrcweir vec.swap( maTagVector ); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir ViewTagVector::iterator iter = vec.begin(); 590*cdf0e10cSrcweir do 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir (*iter++)->Dispose(); 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir while( iter != vec.end() ); 595*cdf0e10cSrcweir return true; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir return false; 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir // -------------------------------------------------------------------- 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir IMPL_LINK(ViewOverlayManager,EventMultiplexerListener, 604*cdf0e10cSrcweir tools::EventMultiplexerEvent*,pEvent) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir switch (pEvent->meEventId) 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED: 609*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_VIEW_ADDED: 610*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_BEGIN_TEXT_EDIT: 611*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_END_TEXT_EDIT: 612*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_CURRENT_PAGE: 613*cdf0e10cSrcweir UpdateTags(); 614*cdf0e10cSrcweir break; 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir return 0; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir } 620