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 .
21 #include <vcl/commandevent.hxx>
23 #include <ViewShell.hxx>
24 #include <smarttag.hxx>
31 SmartTag::SmartTag( ::sd::View
& rView
)
35 SmartTagReference
xThis( this );
36 mrView
.getSmartTags().add( xThis
);
43 bool SmartTag::MouseButtonDown( const MouseEvent
&, SmartHdl
& )
48 /** returns true if the SmartTag consumes this event. */
49 bool SmartTag::KeyInput( const KeyEvent
& /*rKEvt*/ )
54 /** returns true if the SmartTag consumes this event. */
55 bool SmartTag::Command( const CommandEvent
& /*rCEvt*/ )
60 void SmartTag::addCustomHandles( SdrHdlList
& /*rHandlerList*/ )
64 void SmartTag::select()
69 void SmartTag::deselect()
74 void SmartTag::disposing()
76 SmartTagReference
xThis( this );
77 mrView
.getSmartTags().remove( xThis
);
80 bool SmartTag::getContext( SdrViewContext
& /*rContext*/ )
85 sal_Int32
SmartTag::GetMarkablePointCount() const
90 sal_Int32
SmartTag::GetMarkedPointCount() const
95 bool SmartTag::MarkPoint(SdrHdl
& /*rHdl*/, bool /*bUnmark*/ )
100 bool SmartTag::MarkPoints(const ::tools::Rectangle
* /*pRect*/, bool /*bUnmark*/ )
105 void SmartTag::CheckPossibilities()
109 SmartTagSet::SmartTagSet( View
& rView
)
114 SmartTagSet::~SmartTagSet()
118 void SmartTagSet::add( const SmartTagReference
& xTag
)
120 maSet
.insert( xTag
);
121 mrView
.InvalidateAllWin();
123 if( xTag
== mxMouseOverTag
)
124 mxMouseOverTag
.clear();
126 if( xTag
== mxSelectedTag
)
127 mxSelectedTag
.clear();
130 void SmartTagSet::remove( const SmartTagReference
& xTag
)
132 std::set
< SmartTagReference
>::iterator
aIter( maSet
.find( xTag
) );
133 if( aIter
!= maSet
.end() )
134 maSet
.erase( aIter
);
135 mrView
.InvalidateAllWin();
137 if( xTag
== mxMouseOverTag
)
138 mxMouseOverTag
.clear();
140 if( xTag
== mxSelectedTag
)
141 mxSelectedTag
.clear();
144 void SmartTagSet::Dispose()
146 std::set
< SmartTagReference
> aSet
;
148 for( auto& rxItem
: aSet
)
150 mrView
.InvalidateAllWin();
151 mxMouseOverTag
.clear();
152 mxSelectedTag
.clear();
155 void SmartTagSet::select( const SmartTagReference
& xTag
)
157 if( mxSelectedTag
== xTag
)
160 if( mxSelectedTag
.is() )
161 mxSelectedTag
->deselect();
163 mxSelectedTag
= xTag
;
164 mxSelectedTag
->select();
165 mrView
.SetPossibilitiesDirty();
166 if( mrView
.GetMarkedObjectCount() > 0 )
167 mrView
.UnmarkAllObj();
169 mrView
.updateHandles();
172 void SmartTagSet::deselect()
174 if( mxSelectedTag
.is() )
176 mxSelectedTag
->deselect();
177 mxSelectedTag
.clear();
178 mrView
.SetPossibilitiesDirty();
179 mrView
.updateHandles();
183 bool SmartTagSet::MouseButtonDown( const MouseEvent
& rMEvt
)
185 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt
.GetPosPixel() ) );
186 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
188 // check if a smart tag is selected and no handle is hit
189 if( mxSelectedTag
.is() && !pHdl
)
191 // deselect smart tag
196 // if a smart tag handle is hit, forward event to its smart tag
197 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
198 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
200 SmartTagReference
xTag( pSmartHdl
->getTag() );
201 return xTag
->MouseButtonDown( rMEvt
, *pSmartHdl
);
207 bool SmartTagSet::KeyInput( const KeyEvent
& rKEvt
)
209 if( mxSelectedTag
.is() )
210 return mxSelectedTag
->KeyInput( rKEvt
);
211 else if( rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
)
213 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( mrView
.GetHdlList().GetFocusHdl() );
216 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
217 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
226 /** returns true if the SmartTag consumes this event. */
227 bool SmartTagSet::Command( const CommandEvent
& rCEvt
)
229 if( rCEvt
.IsMouseEvent() )
231 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt
.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 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
241 return xTag
->Command( rCEvt
);
247 if( mxSelectedTag
.is() )
248 return mxSelectedTag
->Command( rCEvt
);
255 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
257 for( auto& rxItem
: maSet
)
258 rxItem
->addCustomHandles( rHandlerList
);
261 /** returns true if the currently selected smart tag has
262 a special context, returned in rContext. */
263 bool SmartTagSet::getContext( SdrViewContext
& rContext
) const
265 if( mxSelectedTag
.is() )
266 return mxSelectedTag
->getContext( rContext
);
271 // support point editing
273 bool SmartTagSet::HasMarkablePoints() const
275 return GetMarkablePointCount() != 0;
278 sal_uLong
SmartTagSet::GetMarkablePointCount() const
280 if( mxSelectedTag
.is() )
281 return mxSelectedTag
->GetMarkablePointCount();
285 bool SmartTagSet::HasMarkedPoints() const
287 return GetMarkedPointCount() != 0;
290 sal_uLong
SmartTagSet::GetMarkedPointCount() const
292 if( mxSelectedTag
.is() )
293 return mxSelectedTag
->GetMarkedPointCount();
298 bool SmartTagSet::MarkPoint(SdrHdl
& rHdl
, bool bUnmark
)
300 if( mxSelectedTag
.is() )
301 return mxSelectedTag
->MarkPoint( rHdl
, bUnmark
);
306 bool SmartTagSet::MarkPoints(const ::tools::Rectangle
* pRect
, bool bUnmark
)
308 if( mxSelectedTag
.is() )
309 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
313 void SmartTagSet::CheckPossibilities()
315 if( mxSelectedTag
.is() )
316 mxSelectedTag
->CheckPossibilities();
319 SmartHdl::SmartHdl( SmartTagReference xTag
, SdrObject
* pObject
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
320 : SdrHdl( rPnt
, eNewKind
)
321 , mxSmartTag(std::move( xTag
))
326 SmartHdl::SmartHdl( SmartTagReference xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
327 : SdrHdl( rPnt
, eNewKind
)
328 , mxSmartTag(std::move( xTag
))
332 } // end of namespace sd
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */