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 <vcl/commandevent.hxx>
22 #include <ViewShell.hxx>
23 #include <smarttag.hxx>
30 SmartTag::SmartTag( ::sd::View
& rView
)
34 SmartTagReference
xThis( this );
35 mrView
.getSmartTags().add( xThis
);
42 bool SmartTag::MouseButtonDown( const MouseEvent
&, SmartHdl
& )
47 /** returns true if the SmartTag consumes this event. */
48 bool SmartTag::KeyInput( const KeyEvent
& /*rKEvt*/ )
53 /** returns true if the SmartTag consumes this event. */
54 bool SmartTag::Command( const CommandEvent
& /*rCEvt*/ )
59 void SmartTag::addCustomHandles( SdrHdlList
& /*rHandlerList*/ )
63 void SmartTag::select()
68 void SmartTag::deselect()
73 void SmartTag::disposing()
75 SmartTagReference
xThis( this );
76 mrView
.getSmartTags().remove( xThis
);
79 bool SmartTag::getContext( SdrViewContext
& /*rContext*/ )
84 sal_Int32
SmartTag::GetMarkablePointCount() const
89 sal_Int32
SmartTag::GetMarkedPointCount() const
94 bool SmartTag::MarkPoint(SdrHdl
& /*rHdl*/, bool /*bUnmark*/ )
99 bool SmartTag::MarkPoints(const ::tools::Rectangle
* /*pRect*/, bool /*bUnmark*/ )
104 void SmartTag::CheckPossibilities()
108 SmartTagSet::SmartTagSet( View
& rView
)
113 SmartTagSet::~SmartTagSet()
117 void SmartTagSet::add( const SmartTagReference
& xTag
)
119 maSet
.insert( xTag
);
120 mrView
.InvalidateAllWin();
122 if( xTag
== mxMouseOverTag
)
123 mxMouseOverTag
.clear();
125 if( xTag
== mxSelectedTag
)
126 mxSelectedTag
.clear();
129 void SmartTagSet::remove( const SmartTagReference
& xTag
)
131 std::set
< SmartTagReference
>::iterator
aIter( maSet
.find( xTag
) );
132 if( aIter
!= maSet
.end() )
133 maSet
.erase( aIter
);
134 mrView
.InvalidateAllWin();
136 if( xTag
== mxMouseOverTag
)
137 mxMouseOverTag
.clear();
139 if( xTag
== mxSelectedTag
)
140 mxSelectedTag
.clear();
143 void SmartTagSet::Dispose()
145 std::set
< SmartTagReference
> aSet
;
147 for( auto& rxItem
: aSet
)
149 mrView
.InvalidateAllWin();
150 mxMouseOverTag
.clear();
151 mxSelectedTag
.clear();
154 void SmartTagSet::select( const SmartTagReference
& xTag
)
156 if( mxSelectedTag
== xTag
)
159 if( mxSelectedTag
.is() )
160 mxSelectedTag
->deselect();
162 mxSelectedTag
= xTag
;
163 mxSelectedTag
->select();
164 mrView
.SetPossibilitiesDirty();
165 if( mrView
.GetMarkedObjectCount() > 0 )
166 mrView
.UnmarkAllObj();
168 mrView
.updateHandles();
171 void SmartTagSet::deselect()
173 if( mxSelectedTag
.is() )
175 mxSelectedTag
->deselect();
176 mxSelectedTag
.clear();
177 mrView
.SetPossibilitiesDirty();
178 mrView
.updateHandles();
182 bool SmartTagSet::MouseButtonDown( const MouseEvent
& rMEvt
)
184 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt
.GetPosPixel() ) );
185 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
187 // check if a smart tag is selected and no handle is hit
188 if( mxSelectedTag
.is() && !pHdl
)
190 // deselect smart tag
195 // if a smart tag handle is hit, forward event to its smart tag
196 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
197 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
199 SmartTagReference
xTag( pSmartHdl
->getTag() );
200 return xTag
->MouseButtonDown( rMEvt
, *pSmartHdl
);
206 bool SmartTagSet::KeyInput( const KeyEvent
& rKEvt
)
208 if( mxSelectedTag
.is() )
209 return mxSelectedTag
->KeyInput( rKEvt
);
210 else if( rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
)
212 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( mrView
.GetHdlList().GetFocusHdl() );
215 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
216 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
225 /** returns true if the SmartTag consumes this event. */
226 bool SmartTagSet::Command( const CommandEvent
& rCEvt
)
228 if( rCEvt
.IsMouseEvent() )
230 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt
.GetMousePosPixel() ) );
231 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
235 // if a smart tag handle is hit, forward event to its smart tag
236 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
237 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
239 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
240 return xTag
->Command( rCEvt
);
246 if( mxSelectedTag
.is() )
247 return mxSelectedTag
->Command( rCEvt
);
254 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
256 for( auto& rxItem
: maSet
)
257 rxItem
->addCustomHandles( rHandlerList
);
260 /** returns true if the currently selected smart tag has
261 a special context, returned in rContext. */
262 bool SmartTagSet::getContext( SdrViewContext
& rContext
) const
264 if( mxSelectedTag
.is() )
265 return mxSelectedTag
->getContext( rContext
);
270 // support point editing
272 bool SmartTagSet::HasMarkablePoints() const
274 return GetMarkablePointCount() != 0;
277 sal_uLong
SmartTagSet::GetMarkablePointCount() const
279 if( mxSelectedTag
.is() )
280 return mxSelectedTag
->GetMarkablePointCount();
284 bool SmartTagSet::HasMarkedPoints() const
286 return GetMarkedPointCount() != 0;
289 sal_uLong
SmartTagSet::GetMarkedPointCount() const
291 if( mxSelectedTag
.is() )
292 return mxSelectedTag
->GetMarkedPointCount();
297 bool SmartTagSet::MarkPoint(SdrHdl
& rHdl
, bool bUnmark
)
299 if( mxSelectedTag
.is() )
300 return mxSelectedTag
->MarkPoint( rHdl
, bUnmark
);
305 bool SmartTagSet::MarkPoints(const ::tools::Rectangle
* pRect
, bool bUnmark
)
307 if( mxSelectedTag
.is() )
308 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
312 void SmartTagSet::CheckPossibilities()
314 if( mxSelectedTag
.is() )
315 mxSelectedTag
->CheckPossibilities();
318 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, SdrObject
* pObject
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
319 : SdrHdl( rPnt
, eNewKind
)
325 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
326 : SdrHdl( rPnt
, eNewKind
)
331 } // end of namespace sd
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */