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 const SdrMarkList
& rMarkList
= mrView
.GetMarkedObjectList();
167 if( rMarkList
.GetMarkCount() > 0 )
168 mrView
.UnmarkAllObj();
170 mrView
.updateHandles();
173 void SmartTagSet::deselect()
175 if( mxSelectedTag
.is() )
177 mxSelectedTag
->deselect();
178 mxSelectedTag
.clear();
179 mrView
.SetPossibilitiesDirty();
180 mrView
.updateHandles();
184 bool SmartTagSet::MouseButtonDown( const MouseEvent
& rMEvt
)
186 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt
.GetPosPixel() ) );
187 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
189 // check if a smart tag is selected and no handle is hit
190 if( mxSelectedTag
.is() && !pHdl
)
192 // deselect smart tag
197 // if a smart tag handle is hit, forward event to its smart tag
198 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
199 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
201 SmartTagReference
xTag( pSmartHdl
->getTag() );
202 return xTag
->MouseButtonDown( rMEvt
, *pSmartHdl
);
208 bool SmartTagSet::KeyInput( const KeyEvent
& rKEvt
)
210 if( mxSelectedTag
.is() )
211 return mxSelectedTag
->KeyInput( rKEvt
);
212 else if( rKEvt
.GetKeyCode().GetCode() == KEY_SPACE
)
214 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( mrView
.GetHdlList().GetFocusHdl() );
217 const_cast< SdrHdlList
& >( mrView
.GetHdlList() ).ResetFocusHdl();
218 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
227 /** returns true if the SmartTag consumes this event. */
228 bool SmartTagSet::Command( const CommandEvent
& rCEvt
)
230 if( rCEvt
.IsMouseEvent() )
232 Point
aMDPos( mrView
.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt
.GetMousePosPixel() ) );
233 SdrHdl
* pHdl
= mrView
.PickHandle(aMDPos
);
237 // if a smart tag handle is hit, forward event to its smart tag
238 SmartHdl
* pSmartHdl
= dynamic_cast< SmartHdl
* >( pHdl
);
239 if(pSmartHdl
&& pSmartHdl
->getTag().is() )
241 const SmartTagReference
& xTag( pSmartHdl
->getTag() );
242 return xTag
->Command( rCEvt
);
248 if( mxSelectedTag
.is() )
249 return mxSelectedTag
->Command( rCEvt
);
256 void SmartTagSet::addCustomHandles( SdrHdlList
& rHandlerList
)
258 for( auto& rxItem
: maSet
)
259 rxItem
->addCustomHandles( rHandlerList
);
262 /** returns true if the currently selected smart tag has
263 a special context, returned in rContext. */
264 bool SmartTagSet::getContext( SdrViewContext
& rContext
) const
266 if( mxSelectedTag
.is() )
267 return mxSelectedTag
->getContext( rContext
);
272 // support point editing
274 bool SmartTagSet::HasMarkablePoints() const
276 return GetMarkablePointCount() != 0;
279 sal_uLong
SmartTagSet::GetMarkablePointCount() const
281 if( mxSelectedTag
.is() )
282 return mxSelectedTag
->GetMarkablePointCount();
286 bool SmartTagSet::HasMarkedPoints() const
288 return GetMarkedPointCount() != 0;
291 sal_uLong
SmartTagSet::GetMarkedPointCount() const
293 if( mxSelectedTag
.is() )
294 return mxSelectedTag
->GetMarkedPointCount();
299 bool SmartTagSet::MarkPoint(SdrHdl
& rHdl
, bool bUnmark
)
301 if( mxSelectedTag
.is() )
302 return mxSelectedTag
->MarkPoint( rHdl
, bUnmark
);
307 bool SmartTagSet::MarkPoints(const ::tools::Rectangle
* pRect
, bool bUnmark
)
309 if( mxSelectedTag
.is() )
310 return mxSelectedTag
->MarkPoints( pRect
, bUnmark
);
314 void SmartTagSet::CheckPossibilities()
316 if( mxSelectedTag
.is() )
317 mxSelectedTag
->CheckPossibilities();
320 SmartHdl::SmartHdl( SmartTagReference xTag
, SdrObject
* pObject
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
321 : SdrHdl( rPnt
, eNewKind
)
322 , mxSmartTag(std::move( xTag
))
327 SmartHdl::SmartHdl( SmartTagReference xTag
, const Point
& rPnt
, SdrHdlKind eNewKind
/*=SdrHdlKind::Move*/ )
328 : SdrHdl( rPnt
, eNewKind
)
329 , mxSmartTag(std::move( xTag
))
333 } // end of namespace sd
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */