bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / func / smarttag.cxx
blobff53821168c96bfd976f93698e5716c3cc832f26
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 <vcl/commandevent.hxx>
22 #include <ViewShell.hxx>
23 #include <smarttag.hxx>
24 #include <Window.hxx>
25 #include <View.hxx>
27 namespace sd
30 SmartTag::SmartTag( ::sd::View& rView )
31 : mrView( rView )
32 , mbSelected( false )
34 SmartTagReference xThis( this );
35 mrView.getSmartTags().add( xThis );
38 SmartTag::~SmartTag()
42 bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl& )
44 return false;
47 /** returns true if the SmartTag consumes this event. */
48 bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
50 return false;
53 /** returns true if the SmartTag consumes this event. */
54 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
56 return false;
59 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
63 void SmartTag::select()
65 mbSelected = true;
68 void SmartTag::deselect()
70 mbSelected = false;
73 void SmartTag::disposing()
75 SmartTagReference xThis( this );
76 mrView.getSmartTags().remove( xThis );
79 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
81 return false;
84 sal_Int32 SmartTag::GetMarkablePointCount() const
86 return 0;
89 sal_Int32 SmartTag::GetMarkedPointCount() const
91 return 0;
94 bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
96 return false;
99 bool SmartTag::MarkPoints(const ::tools::Rectangle* /*pRect*/, bool /*bUnmark*/ )
101 return false;
104 void SmartTag::CheckPossibilities()
108 SmartTagSet::SmartTagSet( View& rView )
109 : mrView( rView )
113 SmartTagSet::~SmartTagSet()
117 void SmartTagSet::add( const SmartTagReference& xTag )
119 maSet.insert( xTag );
120 mrView.InvalidateAllWin();
122 if( xTag == mxMouseOverTag )
123 mxMouseOverTag.clear();
125 if( xTag == mxSelectedTag )
126 mxSelectedTag.clear();
129 void SmartTagSet::remove( const SmartTagReference& xTag )
131 std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
132 if( aIter != maSet.end() )
133 maSet.erase( aIter );
134 mrView.InvalidateAllWin();
136 if( xTag == mxMouseOverTag )
137 mxMouseOverTag.clear();
139 if( xTag == mxSelectedTag )
140 mxSelectedTag.clear();
143 void SmartTagSet::Dispose()
145 std::set< SmartTagReference > aSet;
146 aSet.swap( maSet );
147 for( auto& rxItem : aSet )
148 rxItem->Dispose();
149 mrView.InvalidateAllWin();
150 mxMouseOverTag.clear();
151 mxSelectedTag.clear();
154 void SmartTagSet::select( const SmartTagReference& xTag )
156 if( mxSelectedTag == xTag )
157 return;
159 if( mxSelectedTag.is() )
160 mxSelectedTag->deselect();
162 mxSelectedTag = xTag;
163 mxSelectedTag->select();
164 mrView.SetPossibilitiesDirty();
165 if( mrView.GetMarkedObjectCount() > 0 )
166 mrView.UnmarkAllObj();
167 else
168 mrView.updateHandles();
171 void SmartTagSet::deselect()
173 if( mxSelectedTag.is() )
175 mxSelectedTag->deselect();
176 mxSelectedTag.clear();
177 mrView.SetPossibilitiesDirty();
178 mrView.updateHandles();
182 bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
184 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
185 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
187 // check if a smart tag is selected and no handle is hit
188 if( mxSelectedTag.is() && !pHdl )
190 // deselect smart tag
191 deselect();
192 return false;
195 // if a smart tag handle is hit, forward event to its smart tag
196 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
197 if(pSmartHdl && pSmartHdl->getTag().is() )
199 SmartTagReference xTag( pSmartHdl->getTag() );
200 return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
203 return false;
206 bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
208 if( mxSelectedTag.is() )
209 return mxSelectedTag->KeyInput( rKEvt );
210 else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
212 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
213 if( pSmartHdl )
215 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
216 const SmartTagReference& xTag( pSmartHdl->getTag() );
217 select( xTag );
218 return true;
222 return false;
225 /** returns true if the SmartTag consumes this event. */
226 bool SmartTagSet::Command( const CommandEvent& rCEvt )
228 if( rCEvt.IsMouseEvent() )
230 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
231 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
233 if( pHdl )
235 // if a smart tag handle is hit, forward event to its smart tag
236 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
237 if(pSmartHdl && pSmartHdl->getTag().is() )
239 const SmartTagReference& xTag( pSmartHdl->getTag() );
240 return xTag->Command( rCEvt );
244 else
246 if( mxSelectedTag.is() )
247 return mxSelectedTag->Command( rCEvt );
251 return false;
254 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
256 for( auto& rxItem : maSet )
257 rxItem->addCustomHandles( rHandlerList );
260 /** returns true if the currently selected smart tag has
261 a special context, returned in rContext. */
262 bool SmartTagSet::getContext( SdrViewContext& rContext ) const
264 if( mxSelectedTag.is() )
265 return mxSelectedTag->getContext( rContext );
266 else
267 return false;
270 // support point editing
272 bool SmartTagSet::HasMarkablePoints() const
274 return GetMarkablePointCount() != 0;
277 sal_uLong SmartTagSet::GetMarkablePointCount() const
279 if( mxSelectedTag.is() )
280 return mxSelectedTag->GetMarkablePointCount();
281 return 0;
284 bool SmartTagSet::HasMarkedPoints() const
286 return GetMarkedPointCount() != 0;
289 sal_uLong SmartTagSet::GetMarkedPointCount() const
291 if( mxSelectedTag.is() )
292 return mxSelectedTag->GetMarkedPointCount();
293 else
294 return 0;
297 bool SmartTagSet::MarkPoint(SdrHdl& rHdl, bool bUnmark )
299 if( mxSelectedTag.is() )
300 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
302 return false;
305 bool SmartTagSet::MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark)
307 if( mxSelectedTag.is() )
308 return mxSelectedTag->MarkPoints( pRect, bUnmark );
309 return false;
312 void SmartTagSet::CheckPossibilities()
314 if( mxSelectedTag.is() )
315 mxSelectedTag->CheckPossibilities();
318 SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
319 : SdrHdl( rPnt, eNewKind )
320 , mxSmartTag( xTag )
322 SetObj( pObject );
325 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
326 : SdrHdl( rPnt, eNewKind )
327 , mxSmartTag( xTag )
331 } // end of namespace sd
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */