android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / smarttag.cxx
blobb9fdc74c9721db55a8aea6e8d495d18991214118
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 <utility>
21 #include <vcl/commandevent.hxx>
23 #include <ViewShell.hxx>
24 #include <smarttag.hxx>
25 #include <Window.hxx>
26 #include <View.hxx>
28 namespace sd
31 SmartTag::SmartTag( ::sd::View& rView )
32 : mrView( rView )
33 , mbSelected( false )
35 SmartTagReference xThis( this );
36 mrView.getSmartTags().add( xThis );
39 SmartTag::~SmartTag()
43 bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl& )
45 return false;
48 /** returns true if the SmartTag consumes this event. */
49 bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
51 return false;
54 /** returns true if the SmartTag consumes this event. */
55 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
57 return false;
60 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
64 void SmartTag::select()
66 mbSelected = true;
69 void SmartTag::deselect()
71 mbSelected = false;
74 void SmartTag::disposing()
76 SmartTagReference xThis( this );
77 mrView.getSmartTags().remove( xThis );
80 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
82 return false;
85 sal_Int32 SmartTag::GetMarkablePointCount() const
87 return 0;
90 sal_Int32 SmartTag::GetMarkedPointCount() const
92 return 0;
95 bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
97 return false;
100 bool SmartTag::MarkPoints(const ::tools::Rectangle* /*pRect*/, bool /*bUnmark*/ )
102 return false;
105 void SmartTag::CheckPossibilities()
109 SmartTagSet::SmartTagSet( View& rView )
110 : mrView( 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;
147 aSet.swap( maSet );
148 for( auto& rxItem : aSet )
149 rxItem->Dispose();
150 mrView.InvalidateAllWin();
151 mxMouseOverTag.clear();
152 mxSelectedTag.clear();
155 void SmartTagSet::select( const SmartTagReference& xTag )
157 if( mxSelectedTag == xTag )
158 return;
160 if( mxSelectedTag.is() )
161 mxSelectedTag->deselect();
163 mxSelectedTag = xTag;
164 mxSelectedTag->select();
165 mrView.SetPossibilitiesDirty();
166 if( mrView.GetMarkedObjectCount() > 0 )
167 mrView.UnmarkAllObj();
168 else
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
192 deselect();
193 return false;
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 );
204 return false;
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() );
214 if( pSmartHdl )
216 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
217 const SmartTagReference& xTag( pSmartHdl->getTag() );
218 select( xTag );
219 return true;
223 return false;
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);
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 const SmartTagReference& xTag( pSmartHdl->getTag() );
241 return xTag->Command( rCEvt );
245 else
247 if( mxSelectedTag.is() )
248 return mxSelectedTag->Command( rCEvt );
252 return false;
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 );
267 else
268 return false;
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();
282 return 0;
285 bool SmartTagSet::HasMarkedPoints() const
287 return GetMarkedPointCount() != 0;
290 sal_uLong SmartTagSet::GetMarkedPointCount() const
292 if( mxSelectedTag.is() )
293 return mxSelectedTag->GetMarkedPointCount();
294 else
295 return 0;
298 bool SmartTagSet::MarkPoint(SdrHdl& rHdl, bool bUnmark )
300 if( mxSelectedTag.is() )
301 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
303 return false;
306 bool SmartTagSet::MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark)
308 if( mxSelectedTag.is() )
309 return mxSelectedTag->MarkPoints( pRect, bUnmark );
310 return false;
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 ))
323 SetObj( pObject );
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: */