update dev300-m58
[ooovba.git] / sd / source / ui / func / smarttag.cxx
blobf22c710942b397404fa2c5f121b4ee7d46ac3366
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: smarttag.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "ViewShell.hxx"
35 #include "smarttag.hxx"
36 #include "Window.hxx"
37 #include "View.hxx"
39 namespace sd
42 // ====================================================================
44 SmartTag::SmartTag( ::sd::View& rView )
45 : mrView( rView )
46 , mbSelected( false )
48 SmartTagReference xThis( this );
49 mrView.getSmartTags().add( xThis );
52 // --------------------------------------------------------------------
54 SmartTag::~SmartTag()
58 // --------------------------------------------------------------------
60 bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl& )
62 return false;
65 /** returns true if the SmartTag consumes this event. */
66 bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
68 return false;
71 // --------------------------------------------------------------------
73 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
77 // --------------------------------------------------------------------
79 void SmartTag::select()
81 mbSelected = true;
84 // --------------------------------------------------------------------
86 void SmartTag::deselect()
88 mbSelected = false;
91 // --------------------------------------------------------------------
93 bool SmartTag::isSelected() const
95 return mbSelected;
98 // --------------------------------------------------------------------
100 void SmartTag::disposing()
102 SmartTagReference xThis( this );
103 mrView.getSmartTags().remove( xThis );
106 // --------------------------------------------------------------------
108 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
110 return false;
113 // --------------------------------------------------------------------
115 ULONG SmartTag::GetMarkablePointCount() const
117 return 0;
120 // --------------------------------------------------------------------
122 ULONG SmartTag::GetMarkedPointCount() const
124 return 0;
127 // --------------------------------------------------------------------
129 BOOL SmartTag::MarkPoint(SdrHdl& /*rHdl*/, BOOL /*bUnmark*/ )
131 return FALSE;
134 // --------------------------------------------------------------------
136 BOOL SmartTag::MarkPoints(const Rectangle* /*pRect*/, BOOL /*bUnmark*/ )
138 return FALSE;
141 // --------------------------------------------------------------------
143 void SmartTag::CheckPossibilities()
147 // ====================================================================
149 SmartTagSet::SmartTagSet( View& rView )
150 : mrView( rView )
154 // --------------------------------------------------------------------
156 SmartTagSet::~SmartTagSet()
160 // --------------------------------------------------------------------
162 void SmartTagSet::add( const SmartTagReference& xTag )
164 maSet.insert( xTag );
167 // --------------------------------------------------------------------
169 void SmartTagSet::remove( const SmartTagReference& xTag )
171 std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
172 if( aIter != maSet.end() )
173 maSet.erase( aIter );
176 // --------------------------------------------------------------------
178 void SmartTagSet::Dispose()
180 std::set< SmartTagReference > aSet;
181 aSet.swap( maSet );
182 for( std::set< SmartTagReference >::iterator aIter( aSet.begin() ); aIter != aSet.end(); )
183 (*aIter++)->Dispose();
186 // --------------------------------------------------------------------
188 void SmartTagSet::select( const SmartTagReference& xTag )
190 if( mxSelectedTag != xTag )
192 if( mxSelectedTag.is() )
193 mxSelectedTag->deselect();
195 mxSelectedTag = xTag;
196 mxSelectedTag->select();
197 mrView.SetPossibilitiesDirty();
198 if( mrView.GetMarkedObjectCount() > 0 )
199 mrView.UnmarkAllObj();
200 else
201 mrView.updateHandles();
205 // --------------------------------------------------------------------
207 void SmartTagSet::deselect()
209 if( mxSelectedTag.is() )
211 mxSelectedTag->deselect();
212 mxSelectedTag.clear();
213 mrView.SetPossibilitiesDirty();
214 mrView.updateHandles();
218 // --------------------------------------------------------------------
220 bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
222 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
223 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
225 // check if a smart tag is selected and no handle is hit
226 if( mxSelectedTag.is() && !pHdl )
228 // deselect smart tag
229 deselect();
230 return false;
233 // if a smart tag handle is hit, foreward event to its smart tag
234 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
235 if(pSmartHdl && pSmartHdl->getTag().is() )
237 SmartTagReference xTag( pSmartHdl->getTag() );
238 return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
241 return false;
244 // --------------------------------------------------------------------
246 bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
248 if( mxSelectedTag.is() )
249 return mxSelectedTag->KeyInput( rKEvt );
250 else
251 return false;
254 // --------------------------------------------------------------------
256 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
258 if( !maSet.empty() )
260 for( std::set< SmartTagReference >::iterator aIter( maSet.begin() ); aIter != maSet.end(); )
261 (*aIter++)->addCustomHandles( rHandlerList );
265 // --------------------------------------------------------------------
267 /** returns true if the currently selected smart tag has
268 a special context, returned in rContext. */
269 bool SmartTagSet::getContext( SdrViewContext& rContext ) const
271 if( mxSelectedTag.is() )
272 return mxSelectedTag->getContext( rContext );
273 else
274 return false;
277 // --------------------------------------------------------------------
278 // support point editing
279 // --------------------------------------------------------------------
281 BOOL SmartTagSet::HasMarkablePoints() const
283 return GetMarkablePointCount() != 0 ? TRUE : FALSE;
286 // --------------------------------------------------------------------
288 ULONG SmartTagSet::GetMarkablePointCount() const
290 if( mxSelectedTag.is() )
291 return mxSelectedTag->GetMarkablePointCount();
292 return 0;
295 // --------------------------------------------------------------------
297 BOOL SmartTagSet::HasMarkedPoints() const
299 return GetMarkedPointCount() != 0 ? TRUE : FALSE;
302 // --------------------------------------------------------------------
304 ULONG SmartTagSet::GetMarkedPointCount() const
306 if( mxSelectedTag.is() )
307 return mxSelectedTag->GetMarkedPointCount();
308 else
309 return 0;
312 // --------------------------------------------------------------------
314 BOOL SmartTagSet::IsPointMarkable(const SdrHdl& rHdl) const
316 const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
318 return pSmartHdl && pSmartHdl->isMarkable();
321 // --------------------------------------------------------------------
323 BOOL SmartTagSet::MarkPoint(SdrHdl& rHdl, BOOL bUnmark )
325 if( mxSelectedTag.is() )
326 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
328 return FALSE;
331 // --------------------------------------------------------------------
333 BOOL SmartTagSet::MarkPoints(const Rectangle* pRect, BOOL bUnmark)
335 if( mxSelectedTag.is() )
336 return mxSelectedTag->MarkPoints( pRect, bUnmark );
337 return FALSE;
340 // --------------------------------------------------------------------
342 void SmartTagSet::CheckPossibilities()
344 if( mxSelectedTag.is() )
345 mxSelectedTag->CheckPossibilities();
348 // ====================================================================
350 SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
351 : SdrHdl( rPnt, eNewKind )
352 , mxTag( xTag )
354 SetObj( pObject );
357 // --------------------------------------------------------------------
359 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
360 : SdrHdl( rPnt, eNewKind )
361 , mxTag( xTag )
365 // --------------------------------------------------------------------
367 bool SmartHdl::isMarkable() const
369 return false;
372 // ====================================================================
375 SmartProxyHdl::SmartProxyHdl( const SmartTagReference& xTag, SdrHdl* pProxyHdl )
376 : SmartHdl( xTag, pProxyHdl->GetPos(), pProxyHdl->GetKind() )
377 , mpProxyHdl( pProxyHdl )
381 // --------------------------------------------------------------------
383 SmartProxyHdl::~SmartProxyHdl()
385 delete mpProxyHdl;
388 } // end of namespace sd