Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / smarttag.cxx
blobd63f7a096eda176794398cc9dc9f49eb7222f4e2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <Window.hxx>
23 #include <View.hxx>
25 namespace sd
28 SmartTag::SmartTag( ::sd::View& rView )
29 : mrView( rView )
30 , mbSelected( false )
32 SmartTagReference xThis( this );
33 mrView.getSmartTags().add( xThis );
36 SmartTag::~SmartTag()
40 bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl& )
42 return false;
45 /** returns true if the SmartTag consumes this event. */
46 bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
48 return false;
51 /** returns true if the SmartTag consumes this event. */
52 bool SmartTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
54 return false;
57 /** returns true if the SmartTag consumes this event. */
58 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
60 return false;
63 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
67 void SmartTag::select()
69 mbSelected = true;
72 void SmartTag::deselect()
74 mbSelected = false;
77 void SmartTag::disposing()
79 SmartTagReference xThis( this );
80 mrView.getSmartTags().remove( xThis );
83 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
85 return false;
88 sal_Int32 SmartTag::GetMarkablePointCount() const
90 return 0;
93 sal_Int32 SmartTag::GetMarkedPointCount() const
95 return 0;
98 bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
100 return false;
103 bool SmartTag::MarkPoints(const ::tools::Rectangle* /*pRect*/, bool /*bUnmark*/ )
105 return false;
108 void SmartTag::CheckPossibilities()
112 SmartTagSet::SmartTagSet( View& rView )
113 : mrView( 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;
150 aSet.swap( maSet );
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();
170 else
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
195 deselect();
196 return false;
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 );
207 return false;
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() );
217 if( pSmartHdl )
219 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
220 SmartTagReference xTag( pSmartHdl->getTag() );
221 select( xTag );
222 return true;
226 return false;
229 bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
231 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
232 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
234 if( pHdl )
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 );
245 return false;
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);
256 if( pHdl )
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 );
267 else
269 if( mxSelectedTag.is() )
270 return mxSelectedTag->Command( rCEvt );
274 return false;
277 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
279 if( !maSet.empty() )
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 );
292 else
293 return false;
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();
307 return 0;
310 bool SmartTagSet::HasMarkedPoints() const
312 return GetMarkedPointCount() != 0;
315 sal_uLong SmartTagSet::GetMarkedPointCount() const
317 if( mxSelectedTag.is() )
318 return mxSelectedTag->GetMarkedPointCount();
319 else
320 return 0;
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 );
335 return false;
338 bool SmartTagSet::MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark)
340 if( mxSelectedTag.is() )
341 return mxSelectedTag->MarkPoints( pRect, bUnmark );
342 return false;
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 )
353 , mxSmartTag( xTag )
355 SetObj( pObject );
358 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
359 : SdrHdl( rPnt, eNewKind )
360 , mxSmartTag( xTag )
364 bool SmartHdl::isMarkable() const
366 return false;
369 } // end of namespace sd
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */