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