Update ooo320-m1
[ooovba.git] / sd / source / ui / func / smarttag.cxx
blob7b57c51b0f43f881377da535081d513ed6aebedc
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 /** returns true if the SmartTag consumes this event. */
72 bool SmartTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
74 return false;
77 /** returns true if the SmartTag consumes this event. */
78 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
80 return false;
83 // --------------------------------------------------------------------
85 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
89 // --------------------------------------------------------------------
91 void SmartTag::select()
93 mbSelected = true;
96 // --------------------------------------------------------------------
98 void SmartTag::deselect()
100 mbSelected = false;
103 // --------------------------------------------------------------------
105 bool SmartTag::isSelected() const
107 return mbSelected;
110 // --------------------------------------------------------------------
112 void SmartTag::disposing()
114 SmartTagReference xThis( this );
115 mrView.getSmartTags().remove( xThis );
118 // --------------------------------------------------------------------
120 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
122 return false;
125 // --------------------------------------------------------------------
127 ULONG SmartTag::GetMarkablePointCount() const
129 return 0;
132 // --------------------------------------------------------------------
134 ULONG SmartTag::GetMarkedPointCount() const
136 return 0;
139 // --------------------------------------------------------------------
141 BOOL SmartTag::MarkPoint(SdrHdl& /*rHdl*/, BOOL /*bUnmark*/ )
143 return FALSE;
146 // --------------------------------------------------------------------
148 BOOL SmartTag::MarkPoints(const Rectangle* /*pRect*/, BOOL /*bUnmark*/ )
150 return FALSE;
153 // --------------------------------------------------------------------
155 void SmartTag::CheckPossibilities()
159 // ====================================================================
161 SmartTagSet::SmartTagSet( View& rView )
162 : mrView( rView )
166 // --------------------------------------------------------------------
168 SmartTagSet::~SmartTagSet()
172 // --------------------------------------------------------------------
174 void SmartTagSet::add( const SmartTagReference& xTag )
176 maSet.insert( xTag );
177 mrView.InvalidateAllWin();
180 // --------------------------------------------------------------------
182 void SmartTagSet::remove( const SmartTagReference& xTag )
184 std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
185 if( aIter != maSet.end() )
186 maSet.erase( aIter );
187 mrView.InvalidateAllWin();
190 // --------------------------------------------------------------------
192 void SmartTagSet::Dispose()
194 std::set< SmartTagReference > aSet;
195 aSet.swap( maSet );
196 for( std::set< SmartTagReference >::iterator aIter( aSet.begin() ); aIter != aSet.end(); )
197 (*aIter++)->Dispose();
198 mrView.InvalidateAllWin();
201 // --------------------------------------------------------------------
203 void SmartTagSet::select( const SmartTagReference& xTag )
205 if( mxSelectedTag != xTag )
207 if( mxSelectedTag.is() )
208 mxSelectedTag->deselect();
210 mxSelectedTag = xTag;
211 mxSelectedTag->select();
212 mrView.SetPossibilitiesDirty();
213 if( mrView.GetMarkedObjectCount() > 0 )
214 mrView.UnmarkAllObj();
215 else
216 mrView.updateHandles();
220 // --------------------------------------------------------------------
222 void SmartTagSet::deselect()
224 if( mxSelectedTag.is() )
226 mxSelectedTag->deselect();
227 mxSelectedTag.clear();
228 mrView.SetPossibilitiesDirty();
229 mrView.updateHandles();
233 // --------------------------------------------------------------------
235 bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
237 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
238 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
240 // check if a smart tag is selected and no handle is hit
241 if( mxSelectedTag.is() && !pHdl )
243 // deselect smart tag
244 deselect();
245 return false;
248 // if a smart tag handle is hit, foreward event to its smart tag
249 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
250 if(pSmartHdl && pSmartHdl->getTag().is() )
252 SmartTagReference xTag( pSmartHdl->getTag() );
253 return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
256 return false;
259 // --------------------------------------------------------------------
261 bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
263 if( mxSelectedTag.is() )
264 return mxSelectedTag->KeyInput( rKEvt );
265 else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
267 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
268 if( pSmartHdl )
270 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
271 SmartTagReference xTag( pSmartHdl->getTag() );
272 select( xTag );
273 return true;
278 return false;
281 // --------------------------------------------------------------------
283 bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
285 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
286 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
288 if( pHdl )
290 // if a smart tag handle is hit, foreward event to its smart tag
291 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
292 if(pSmartHdl && pSmartHdl->getTag().is() )
294 SmartTagReference xTag( pSmartHdl->getTag() );
295 return xTag->RequestHelp( rHEvt );
299 return false;
302 // --------------------------------------------------------------------
304 /** returns true if the SmartTag consumes this event. */
305 bool SmartTagSet::Command( const CommandEvent& rCEvt )
307 if( rCEvt.IsMouseEvent() )
309 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
310 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
312 if( pHdl )
314 // if a smart tag handle is hit, foreward event to its smart tag
315 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
316 if(pSmartHdl && pSmartHdl->getTag().is() )
318 SmartTagReference xTag( pSmartHdl->getTag() );
319 return xTag->Command( rCEvt );
323 else
325 if( mxSelectedTag.is() )
326 return mxSelectedTag->Command( rCEvt );
330 return false;
333 // --------------------------------------------------------------------
335 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
337 if( !maSet.empty() )
339 for( std::set< SmartTagReference >::iterator aIter( maSet.begin() ); aIter != maSet.end(); )
340 (*aIter++)->addCustomHandles( rHandlerList );
344 // --------------------------------------------------------------------
346 /** returns true if the currently selected smart tag has
347 a special context, returned in rContext. */
348 bool SmartTagSet::getContext( SdrViewContext& rContext ) const
350 if( mxSelectedTag.is() )
351 return mxSelectedTag->getContext( rContext );
352 else
353 return false;
356 // --------------------------------------------------------------------
357 // support point editing
358 // --------------------------------------------------------------------
360 BOOL SmartTagSet::HasMarkablePoints() const
362 return GetMarkablePointCount() != 0 ? TRUE : FALSE;
365 // --------------------------------------------------------------------
367 ULONG SmartTagSet::GetMarkablePointCount() const
369 if( mxSelectedTag.is() )
370 return mxSelectedTag->GetMarkablePointCount();
371 return 0;
374 // --------------------------------------------------------------------
376 BOOL SmartTagSet::HasMarkedPoints() const
378 return GetMarkedPointCount() != 0 ? TRUE : FALSE;
381 // --------------------------------------------------------------------
383 ULONG SmartTagSet::GetMarkedPointCount() const
385 if( mxSelectedTag.is() )
386 return mxSelectedTag->GetMarkedPointCount();
387 else
388 return 0;
391 // --------------------------------------------------------------------
393 BOOL SmartTagSet::IsPointMarkable(const SdrHdl& rHdl) const
395 const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
397 return pSmartHdl && pSmartHdl->isMarkable();
400 // --------------------------------------------------------------------
402 BOOL SmartTagSet::MarkPoint(SdrHdl& rHdl, BOOL bUnmark )
404 if( mxSelectedTag.is() )
405 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
407 return FALSE;
410 // --------------------------------------------------------------------
412 BOOL SmartTagSet::MarkPoints(const Rectangle* pRect, BOOL bUnmark)
414 if( mxSelectedTag.is() )
415 return mxSelectedTag->MarkPoints( pRect, bUnmark );
416 return FALSE;
419 // --------------------------------------------------------------------
421 void SmartTagSet::CheckPossibilities()
423 if( mxSelectedTag.is() )
424 mxSelectedTag->CheckPossibilities();
427 // ====================================================================
429 SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
430 : SdrHdl( rPnt, eNewKind )
431 , mxTag( xTag )
433 SetObj( pObject );
436 // --------------------------------------------------------------------
438 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
439 : SdrHdl( rPnt, eNewKind )
440 , mxTag( xTag )
444 // --------------------------------------------------------------------
446 bool SmartHdl::isMarkable() const
448 return false;
451 // ====================================================================
454 SmartProxyHdl::SmartProxyHdl( const SmartTagReference& xTag, SdrHdl* pProxyHdl )
455 : SmartHdl( xTag, pProxyHdl->GetPos(), pProxyHdl->GetKind() )
456 , mpProxyHdl( pProxyHdl )
460 // --------------------------------------------------------------------
462 SmartProxyHdl::~SmartProxyHdl()
464 delete mpProxyHdl;
467 } // end of namespace sd