1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: smarttag.cxx,v $
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"
42 // ====================================================================
44 SmartTag::SmartTag( ::sd::View
& rView
)
48 SmartTagReference
xThis( this );
49 mrView
.getSmartTags().add( xThis
);
52 // --------------------------------------------------------------------
58 // --------------------------------------------------------------------
60 bool SmartTag::MouseButtonDown( const MouseEvent
&, SmartHdl
& )
65 /** returns true if the SmartTag consumes this event. */
66 bool SmartTag::KeyInput( const KeyEvent
& /*rKEvt*/ )
71 /** returns true if the SmartTag consumes this event. */
72 bool SmartTag::RequestHelp( const HelpEvent
& /*rHEvt*/ )
77 /** returns true if the SmartTag consumes this event. */
78 bool SmartTag::Command( const CommandEvent
& /*rCEvt*/ )
83 // --------------------------------------------------------------------
85 void SmartTag::addCustomHandles( SdrHdlList
& /*rHandlerList*/ )
89 // --------------------------------------------------------------------
91 void SmartTag::select()
96 // --------------------------------------------------------------------
98 void SmartTag::deselect()
103 // --------------------------------------------------------------------
105 bool SmartTag::isSelected() const
110 // --------------------------------------------------------------------
112 void SmartTag::disposing()
114 SmartTagReference
xThis( this );
115 mrView
.getSmartTags().remove( xThis
);
118 // --------------------------------------------------------------------
120 bool SmartTag::getContext( SdrViewContext
& /*rContext*/ )
125 // --------------------------------------------------------------------
127 ULONG
SmartTag::GetMarkablePointCount() const
132 // --------------------------------------------------------------------
134 ULONG
SmartTag::GetMarkedPointCount() const
139 // --------------------------------------------------------------------
141 BOOL
SmartTag::MarkPoint(SdrHdl
& /*rHdl*/, BOOL
/*bUnmark*/ )
146 // --------------------------------------------------------------------
148 BOOL
SmartTag::MarkPoints(const Rectangle
* /*pRect*/, BOOL
/*bUnmark*/ )
153 // --------------------------------------------------------------------
155 void SmartTag::CheckPossibilities()
159 // ====================================================================
161 SmartTagSet::SmartTagSet( View
& 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
;
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();
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
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
);
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() );
270 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
271 SmartTagReference
xTag( pSmartHdl
->getTag() );
281 // --------------------------------------------------------------------
283 bool SmartTagSet::RequestHelp( const HelpEvent
& rHEvt
)
285 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt
.GetMousePosPixel() ) );
286 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
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
);
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
);
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
);
325 if( mxSelectedTag
.is() )
326 return mxSelectedTag
->Command( rCEvt
);
333 // --------------------------------------------------------------------
335 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
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
);
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();
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();
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
);
410 // --------------------------------------------------------------------
412 BOOL
SmartTagSet::MarkPoints(const Rectangle
* pRect
, BOOL bUnmark
)
414 if( mxSelectedTag
.is() )
415 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
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
)
436 // --------------------------------------------------------------------
438 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=HDL_MOVE*/ )
439 : SdrHdl( rPnt
, eNewKind
)
444 // --------------------------------------------------------------------
446 bool SmartHdl::isMarkable() const
451 // ====================================================================
454 SmartProxyHdl::SmartProxyHdl( const SmartTagReference& xTag, SdrHdl* pProxyHdl )
455 : SmartHdl( xTag, pProxyHdl->GetPos(), pProxyHdl->GetKind() )
456 , mpProxyHdl( pProxyHdl )
460 // --------------------------------------------------------------------
462 SmartProxyHdl::~SmartProxyHdl()
467 } // end of namespace sd