1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ViewShell.hxx>
21 #include <smarttag.hxx>
28 SmartTag::SmartTag( ::sd::View
& rView
)
32 SmartTagReference
xThis( this );
33 mrView
.getSmartTags().add( xThis
);
40 bool SmartTag::MouseButtonDown( const MouseEvent
&, SmartHdl
& )
45 /** returns true if the SmartTag consumes this event. */
46 bool SmartTag::KeyInput( const KeyEvent
& /*rKEvt*/ )
51 /** returns true if the SmartTag consumes this event. */
52 bool SmartTag::RequestHelp( const HelpEvent
& /*rHEvt*/ )
57 /** returns true if the SmartTag consumes this event. */
58 bool SmartTag::Command( const CommandEvent
& /*rCEvt*/ )
63 void SmartTag::addCustomHandles( SdrHdlList
& /*rHandlerList*/ )
67 void SmartTag::select()
72 void SmartTag::deselect()
77 void SmartTag::disposing()
79 SmartTagReference
xThis( this );
80 mrView
.getSmartTags().remove( xThis
);
83 bool SmartTag::getContext( SdrViewContext
& /*rContext*/ )
88 sal_Int32
SmartTag::GetMarkablePointCount() const
93 sal_Int32
SmartTag::GetMarkedPointCount() const
98 bool SmartTag::MarkPoint(SdrHdl
& /*rHdl*/, bool /*bUnmark*/ )
103 bool SmartTag::MarkPoints(const ::tools::Rectangle
* /*pRect*/, bool /*bUnmark*/ )
108 void SmartTag::CheckPossibilities()
112 SmartTagSet::SmartTagSet( View
& rView
)
117 SmartTagSet::~SmartTagSet()
121 void SmartTagSet::add( const SmartTagReference
& xTag
)
123 maSet
.insert( xTag
);
124 mrView
.InvalidateAllWin();
126 if( xTag
== mxMouseOverTag
)
127 mxMouseOverTag
.clear();
129 if( xTag
== mxSelectedTag
)
130 mxSelectedTag
.clear();
133 void SmartTagSet::remove( const SmartTagReference
& xTag
)
135 std::set
< SmartTagReference
>::iterator
aIter( maSet
.find( xTag
) );
136 if( aIter
!= maSet
.end() )
137 maSet
.erase( aIter
);
138 mrView
.InvalidateAllWin();
140 if( xTag
== mxMouseOverTag
)
141 mxMouseOverTag
.clear();
143 if( xTag
== mxSelectedTag
)
144 mxSelectedTag
.clear();
147 void SmartTagSet::Dispose()
149 std::set
< SmartTagReference
> aSet
;
151 for( std::set
< SmartTagReference
>::iterator
aIter( aSet
.begin() ); aIter
!= aSet
.end(); )
152 (*aIter
++)->Dispose();
153 mrView
.InvalidateAllWin();
154 mxMouseOverTag
.clear();
155 mxSelectedTag
.clear();
158 void SmartTagSet::select( const SmartTagReference
& xTag
)
160 if( mxSelectedTag
!= xTag
)
162 if( mxSelectedTag
.is() )
163 mxSelectedTag
->deselect();
165 mxSelectedTag
= xTag
;
166 mxSelectedTag
->select();
167 mrView
.SetPossibilitiesDirty();
168 if( mrView
.GetMarkedObjectCount() > 0 )
169 mrView
.UnmarkAllObj();
171 mrView
.updateHandles();
175 void SmartTagSet::deselect()
177 if( mxSelectedTag
.is() )
179 mxSelectedTag
->deselect();
180 mxSelectedTag
.clear();
181 mrView
.SetPossibilitiesDirty();
182 mrView
.updateHandles();
186 bool SmartTagSet::MouseButtonDown( const MouseEvent
& rMEvt
)
188 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt
.GetPosPixel() ) );
189 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
191 // check if a smart tag is selected and no handle is hit
192 if( mxSelectedTag
.is() && !pHdl
)
194 // deselect smart tag
199 // if a smart tag handle is hit, forward event to its smart tag
200 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
201 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
203 SmartTagReference
xTag( pSmartHdl
->getTag() );
204 return xTag
->MouseButtonDown( rMEvt
, *pSmartHdl
);
210 bool SmartTagSet::KeyInput( const KeyEvent
& rKEvt
)
212 if( mxSelectedTag
.is() )
213 return mxSelectedTag
->KeyInput( rKEvt
);
214 else if( rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
)
216 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( mrView
.GetHdlList().GetFocusHdl() );
219 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
220 SmartTagReference
xTag( pSmartHdl
->getTag() );
229 bool SmartTagSet::RequestHelp( const HelpEvent
& rHEvt
)
231 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt
.GetMousePosPixel() ) );
232 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
236 // if a smart tag handle is hit, forward event to its smart tag
237 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
238 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
240 SmartTagReference
xTag( pSmartHdl
->getTag() );
241 return xTag
->RequestHelp( rHEvt
);
248 /** returns true if the SmartTag consumes this event. */
249 bool SmartTagSet::Command( const CommandEvent
& rCEvt
)
251 if( rCEvt
.IsMouseEvent() )
253 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt
.GetMousePosPixel() ) );
254 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
258 // if a smart tag handle is hit, forward event to its smart tag
259 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
260 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
262 SmartTagReference
xTag( pSmartHdl
->getTag() );
263 return xTag
->Command( rCEvt
);
269 if( mxSelectedTag
.is() )
270 return mxSelectedTag
->Command( rCEvt
);
277 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
281 for( std::set
< SmartTagReference
>::iterator
aIter( maSet
.begin() ); aIter
!= maSet
.end(); )
282 (*aIter
++)->addCustomHandles( rHandlerList
);
286 /** returns true if the currently selected smart tag has
287 a special context, returned in rContext. */
288 bool SmartTagSet::getContext( SdrViewContext
& rContext
) const
290 if( mxSelectedTag
.is() )
291 return mxSelectedTag
->getContext( rContext
);
296 // support point editing
298 bool SmartTagSet::HasMarkablePoints() const
300 return GetMarkablePointCount() != 0;
303 sal_uLong
SmartTagSet::GetMarkablePointCount() const
305 if( mxSelectedTag
.is() )
306 return mxSelectedTag
->GetMarkablePointCount();
310 bool SmartTagSet::HasMarkedPoints() const
312 return GetMarkedPointCount() != 0;
315 sal_uLong
SmartTagSet::GetMarkedPointCount() const
317 if( mxSelectedTag
.is() )
318 return mxSelectedTag
->GetMarkedPointCount();
323 bool SmartTagSet::IsPointMarkable(const SdrHdl
& rHdl
)
325 const SmartHdl
* pSmartHdl
= dynamic_cast< const SmartHdl
* >( &rHdl
);
327 return pSmartHdl
&& pSmartHdl
->isMarkable();
330 bool SmartTagSet::MarkPoint(SdrHdl
& rHdl
, bool bUnmark
)
332 if( mxSelectedTag
.is() )
333 return mxSelectedTag
->MarkPoint( rHdl
, bUnmark
);
338 bool SmartTagSet::MarkPoints(const ::tools::Rectangle
* pRect
, bool bUnmark
)
340 if( mxSelectedTag
.is() )
341 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
345 void SmartTagSet::CheckPossibilities()
347 if( mxSelectedTag
.is() )
348 mxSelectedTag
->CheckPossibilities();
351 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, SdrObject
* pObject
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
352 : SdrHdl( rPnt
, eNewKind
)
358 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
359 : SdrHdl( rPnt
, eNewKind
)
364 bool SmartHdl::isMarkable() const
369 } // end of namespace sd
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */