bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / smarttag.cxx
blob397c2f17f38313ee11b6d54b778506c85800823e
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::RequestHelp( const HelpEvent& /*rHEvt*/ )
56 return false;
59 /** returns true if the SmartTag consumes this event. */
60 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
62 return false;
65 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
69 void SmartTag::select()
71 mbSelected = true;
74 void SmartTag::deselect()
76 mbSelected = false;
79 void SmartTag::disposing()
81 SmartTagReference xThis( this );
82 mrView.getSmartTags().remove( xThis );
85 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
87 return false;
90 sal_Int32 SmartTag::GetMarkablePointCount() const
92 return 0;
95 sal_Int32 SmartTag::GetMarkedPointCount() const
97 return 0;
100 bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
102 return false;
105 bool SmartTag::MarkPoints(const ::tools::Rectangle* /*pRect*/, bool /*bUnmark*/ )
107 return false;
110 void SmartTag::CheckPossibilities()
114 SmartTagSet::SmartTagSet( View& rView )
115 : mrView( rView )
119 SmartTagSet::~SmartTagSet()
123 void SmartTagSet::add( const SmartTagReference& xTag )
125 maSet.insert( xTag );
126 mrView.InvalidateAllWin();
128 if( xTag == mxMouseOverTag )
129 mxMouseOverTag.clear();
131 if( xTag == mxSelectedTag )
132 mxSelectedTag.clear();
135 void SmartTagSet::remove( const SmartTagReference& xTag )
137 std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
138 if( aIter != maSet.end() )
139 maSet.erase( aIter );
140 mrView.InvalidateAllWin();
142 if( xTag == mxMouseOverTag )
143 mxMouseOverTag.clear();
145 if( xTag == mxSelectedTag )
146 mxSelectedTag.clear();
149 void SmartTagSet::Dispose()
151 std::set< SmartTagReference > aSet;
152 aSet.swap( maSet );
153 for( auto& rxItem : aSet )
154 rxItem->Dispose();
155 mrView.InvalidateAllWin();
156 mxMouseOverTag.clear();
157 mxSelectedTag.clear();
160 void SmartTagSet::select( const SmartTagReference& xTag )
162 if( mxSelectedTag == xTag )
163 return;
165 if( mxSelectedTag.is() )
166 mxSelectedTag->deselect();
168 mxSelectedTag = xTag;
169 mxSelectedTag->select();
170 mrView.SetPossibilitiesDirty();
171 if( mrView.GetMarkedObjectCount() > 0 )
172 mrView.UnmarkAllObj();
173 else
174 mrView.updateHandles();
177 void SmartTagSet::deselect()
179 if( mxSelectedTag.is() )
181 mxSelectedTag->deselect();
182 mxSelectedTag.clear();
183 mrView.SetPossibilitiesDirty();
184 mrView.updateHandles();
188 bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
190 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
191 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
193 // check if a smart tag is selected and no handle is hit
194 if( mxSelectedTag.is() && !pHdl )
196 // deselect smart tag
197 deselect();
198 return false;
201 // if a smart tag handle is hit, forward event to its smart tag
202 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
203 if(pSmartHdl && pSmartHdl->getTag().is() )
205 SmartTagReference xTag( pSmartHdl->getTag() );
206 return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
209 return false;
212 bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
214 if( mxSelectedTag.is() )
215 return mxSelectedTag->KeyInput( rKEvt );
216 else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
218 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
219 if( pSmartHdl )
221 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
222 const SmartTagReference& xTag( pSmartHdl->getTag() );
223 select( xTag );
224 return true;
228 return false;
231 bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
233 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
234 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
236 if( pHdl )
238 // if a smart tag handle is hit, forward event to its smart tag
239 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
240 if(pSmartHdl && pSmartHdl->getTag().is() )
242 const SmartTagReference& xTag( pSmartHdl->getTag() );
243 return xTag->RequestHelp( rHEvt );
247 return false;
250 /** returns true if the SmartTag consumes this event. */
251 bool SmartTagSet::Command( const CommandEvent& rCEvt )
253 if( rCEvt.IsMouseEvent() )
255 Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
256 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
258 if( pHdl )
260 // if a smart tag handle is hit, forward event to its smart tag
261 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
262 if(pSmartHdl && pSmartHdl->getTag().is() )
264 const SmartTagReference& xTag( pSmartHdl->getTag() );
265 return xTag->Command( rCEvt );
269 else
271 if( mxSelectedTag.is() )
272 return mxSelectedTag->Command( rCEvt );
276 return false;
279 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
281 for( auto& rxItem : maSet )
282 rxItem->addCustomHandles( rHandlerList );
285 /** returns true if the currently selected smart tag has
286 a special context, returned in rContext. */
287 bool SmartTagSet::getContext( SdrViewContext& rContext ) const
289 if( mxSelectedTag.is() )
290 return mxSelectedTag->getContext( rContext );
291 else
292 return false;
295 // support point editing
297 bool SmartTagSet::HasMarkablePoints() const
299 return GetMarkablePointCount() != 0;
302 sal_uLong SmartTagSet::GetMarkablePointCount() const
304 if( mxSelectedTag.is() )
305 return mxSelectedTag->GetMarkablePointCount();
306 return 0;
309 bool SmartTagSet::HasMarkedPoints() const
311 return GetMarkedPointCount() != 0;
314 sal_uLong SmartTagSet::GetMarkedPointCount() const
316 if( mxSelectedTag.is() )
317 return mxSelectedTag->GetMarkedPointCount();
318 else
319 return 0;
322 bool SmartTagSet::IsPointMarkable(const SdrHdl& rHdl)
324 const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
326 return pSmartHdl && pSmartHdl->isMarkable();
329 bool SmartTagSet::MarkPoint(SdrHdl& rHdl, bool bUnmark )
331 if( mxSelectedTag.is() )
332 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
334 return false;
337 bool SmartTagSet::MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark)
339 if( mxSelectedTag.is() )
340 return mxSelectedTag->MarkPoints( pRect, bUnmark );
341 return false;
344 void SmartTagSet::CheckPossibilities()
346 if( mxSelectedTag.is() )
347 mxSelectedTag->CheckPossibilities();
350 SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
351 : SdrHdl( rPnt, eNewKind )
352 , mxSmartTag( xTag )
354 SetObj( pObject );
357 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
358 : SdrHdl( rPnt, eNewKind )
359 , mxSmartTag( xTag )
363 bool SmartHdl::isMarkable() const
365 return false;
368 } // end of namespace sd
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */