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::RequestHelp( const HelpEvent
& /*rHEvt*/ )
59 /** returns true if the SmartTag consumes this event. */
60 bool SmartTag::Command( const CommandEvent
& /*rCEvt*/ )
65 void SmartTag::addCustomHandles( SdrHdlList
& /*rHandlerList*/ )
69 void SmartTag::select()
74 void SmartTag::deselect()
79 void SmartTag::disposing()
81 SmartTagReference
xThis( this );
82 mrView
.getSmartTags().remove( xThis
);
85 bool SmartTag::getContext( SdrViewContext
& /*rContext*/ )
90 sal_Int32
SmartTag::GetMarkablePointCount() const
95 sal_Int32
SmartTag::GetMarkedPointCount() const
100 bool SmartTag::MarkPoint(SdrHdl
& /*rHdl*/, bool /*bUnmark*/ )
105 bool SmartTag::MarkPoints(const ::tools::Rectangle
* /*pRect*/, bool /*bUnmark*/ )
110 void SmartTag::CheckPossibilities()
114 SmartTagSet::SmartTagSet( View
& rView
)
119 SmartTagSet::~SmartTagSet()
123 void SmartTagSet::add( const SmartTagReference
& xTag
)
125 maSet
.insert( xTag
);
126 mrView
.InvalidateAllWin();
128 if( xTag
== mxMouseOverTag
)
129 mxMouseOverTag
.clear();
131 if( xTag
== mxSelectedTag
)
132 mxSelectedTag
.clear();
135 void SmartTagSet::remove( const SmartTagReference
& xTag
)
137 std::set
< SmartTagReference
>::iterator
aIter( maSet
.find( xTag
) );
138 if( aIter
!= maSet
.end() )
139 maSet
.erase( aIter
);
140 mrView
.InvalidateAllWin();
142 if( xTag
== mxMouseOverTag
)
143 mxMouseOverTag
.clear();
145 if( xTag
== mxSelectedTag
)
146 mxSelectedTag
.clear();
149 void SmartTagSet::Dispose()
151 std::set
< SmartTagReference
> aSet
;
153 for( auto& rxItem
: aSet
)
155 mrView
.InvalidateAllWin();
156 mxMouseOverTag
.clear();
157 mxSelectedTag
.clear();
160 void SmartTagSet::select( const SmartTagReference
& xTag
)
162 if( mxSelectedTag
== xTag
)
165 if( mxSelectedTag
.is() )
166 mxSelectedTag
->deselect();
168 mxSelectedTag
= xTag
;
169 mxSelectedTag
->select();
170 mrView
.SetPossibilitiesDirty();
171 if( mrView
.GetMarkedObjectCount() > 0 )
172 mrView
.UnmarkAllObj();
174 mrView
.updateHandles();
177 void SmartTagSet::deselect()
179 if( mxSelectedTag
.is() )
181 mxSelectedTag
->deselect();
182 mxSelectedTag
.clear();
183 mrView
.SetPossibilitiesDirty();
184 mrView
.updateHandles();
188 bool SmartTagSet::MouseButtonDown( const MouseEvent
& rMEvt
)
190 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt
.GetPosPixel() ) );
191 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
193 // check if a smart tag is selected and no handle is hit
194 if( mxSelectedTag
.is() && !pHdl
)
196 // deselect smart tag
201 // if a smart tag handle is hit, forward event to its smart tag
202 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
203 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
205 SmartTagReference
xTag( pSmartHdl
->getTag() );
206 return xTag
->MouseButtonDown( rMEvt
, *pSmartHdl
);
212 bool SmartTagSet::KeyInput( const KeyEvent
& rKEvt
)
214 if( mxSelectedTag
.is() )
215 return mxSelectedTag
->KeyInput( rKEvt
);
216 else if( rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
)
218 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( mrView
.GetHdlList().GetFocusHdl() );
221 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
222 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
231 bool SmartTagSet::RequestHelp( const HelpEvent
& rHEvt
)
233 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt
.GetMousePosPixel() ) );
234 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
238 // if a smart tag handle is hit, forward event to its smart tag
239 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
240 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
242 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
243 return xTag
->RequestHelp( rHEvt
);
250 /** returns true if the SmartTag consumes this event. */
251 bool SmartTagSet::Command( const CommandEvent
& rCEvt
)
253 if( rCEvt
.IsMouseEvent() )
255 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt
.GetMousePosPixel() ) );
256 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
260 // if a smart tag handle is hit, forward event to its smart tag
261 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
262 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
264 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
265 return xTag
->Command( rCEvt
);
271 if( mxSelectedTag
.is() )
272 return mxSelectedTag
->Command( rCEvt
);
279 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
281 for( auto& rxItem
: maSet
)
282 rxItem
->addCustomHandles( rHandlerList
);
285 /** returns true if the currently selected smart tag has
286 a special context, returned in rContext. */
287 bool SmartTagSet::getContext( SdrViewContext
& rContext
) const
289 if( mxSelectedTag
.is() )
290 return mxSelectedTag
->getContext( rContext
);
295 // support point editing
297 bool SmartTagSet::HasMarkablePoints() const
299 return GetMarkablePointCount() != 0;
302 sal_uLong
SmartTagSet::GetMarkablePointCount() const
304 if( mxSelectedTag
.is() )
305 return mxSelectedTag
->GetMarkablePointCount();
309 bool SmartTagSet::HasMarkedPoints() const
311 return GetMarkedPointCount() != 0;
314 sal_uLong
SmartTagSet::GetMarkedPointCount() const
316 if( mxSelectedTag
.is() )
317 return mxSelectedTag
->GetMarkedPointCount();
322 bool SmartTagSet::IsPointMarkable(const SdrHdl
& rHdl
)
324 const SmartHdl
* pSmartHdl
= dynamic_cast< const SmartHdl
* >( &rHdl
);
326 return pSmartHdl
&& pSmartHdl
->isMarkable();
329 bool SmartTagSet::MarkPoint(SdrHdl
& rHdl
, bool bUnmark
)
331 if( mxSelectedTag
.is() )
332 return mxSelectedTag
->MarkPoint( rHdl
, bUnmark
);
337 bool SmartTagSet::MarkPoints(const ::tools::Rectangle
* pRect
, bool bUnmark
)
339 if( mxSelectedTag
.is() )
340 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
344 void SmartTagSet::CheckPossibilities()
346 if( mxSelectedTag
.is() )
347 mxSelectedTag
->CheckPossibilities();
350 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, SdrObject
* pObject
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
351 : SdrHdl( rPnt
, eNewKind
)
357 SmartHdl::SmartHdl( const SmartTagReference
& xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
358 : SdrHdl( rPnt
, eNewKind
)
363 bool SmartHdl::isMarkable() const
368 } // end of namespace sd
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */