xref: /trunk/main/sd/source/ui/func/smarttag.cxx (revision 86e1cf34)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "ViewShell.hxx"
28 #include "smarttag.hxx"
29 #include "Window.hxx"
30 #include "View.hxx"
31 
32 namespace sd
33 {
34 
35 // ====================================================================
36 
SmartTag(::sd::View & rView)37 SmartTag::SmartTag( ::sd::View& rView )
38 : mrView( rView )
39 , mbSelected( false )
40 {
41 	SmartTagReference xThis( this );
42 	mrView.getSmartTags().add( xThis );
43 }
44 
45 // --------------------------------------------------------------------
46 
~SmartTag()47 SmartTag::~SmartTag()
48 {
49 }
50 
51 // --------------------------------------------------------------------
52 
MouseButtonDown(const MouseEvent &,SmartHdl &)53 bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl&  )
54 {
55 	return false;
56 }
57 
58 /** returns true if the SmartTag consumes this event. */
KeyInput(const KeyEvent &)59 bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
60 {
61 	return false;
62 }
63 
64 /** returns true if the SmartTag consumes this event. */
RequestHelp(const HelpEvent &)65 bool SmartTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
66 {
67     return false;
68 }
69 
70 /** returns true if the SmartTag consumes this event. */
Command(const CommandEvent &)71 bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
72 {
73     return false;
74 }
75 
76 // --------------------------------------------------------------------
77 
addCustomHandles(SdrHdlList &)78 void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
79 {
80 }
81 
82 // --------------------------------------------------------------------
83 
select()84 void SmartTag::select()
85 {
86 	mbSelected = true;
87 }
88 
89 // --------------------------------------------------------------------
90 
deselect()91 void SmartTag::deselect()
92 {
93 	mbSelected = false;
94 }
95 
96 // --------------------------------------------------------------------
97 
isSelected() const98 bool SmartTag::isSelected() const
99 {
100 	return mbSelected;
101 }
102 
103 // --------------------------------------------------------------------
104 
disposing()105 void SmartTag::disposing()
106 {
107 	SmartTagReference xThis( this );
108 	mrView.getSmartTags().remove( xThis );
109 }
110 
111 // --------------------------------------------------------------------
112 
getContext(SdrViewContext &)113 bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
114 {
115 	return false;
116 }
117 
118 // --------------------------------------------------------------------
119 
GetMarkablePointCount() const120 sal_uLong SmartTag::GetMarkablePointCount() const
121 {
122 	return 0;
123 }
124 
125 // --------------------------------------------------------------------
126 
GetMarkedPointCount() const127 sal_uLong SmartTag::GetMarkedPointCount() const
128 {
129 	return 0;
130 }
131 
132 // --------------------------------------------------------------------
133 
MarkPoint(SdrHdl &,sal_Bool)134 sal_Bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, sal_Bool /*bUnmark*/ )
135 {
136 	return sal_False;
137 }
138 
139 // --------------------------------------------------------------------
140 
MarkPoints(const Rectangle *,sal_Bool)141 sal_Bool SmartTag::MarkPoints(const Rectangle* /*pRect*/, sal_Bool /*bUnmark*/ )
142 {
143 	return sal_False;
144 }
145 
146 // --------------------------------------------------------------------
147 
CheckPossibilities()148 void SmartTag::CheckPossibilities()
149 {
150 }
151 
152 // ====================================================================
153 
SmartTagSet(View & rView)154 SmartTagSet::SmartTagSet( View& rView )
155 : mrView( rView )
156 {
157 }
158 
159 // --------------------------------------------------------------------
160 
~SmartTagSet()161 SmartTagSet::~SmartTagSet()
162 {
163 }
164 
165 // --------------------------------------------------------------------
166 
add(const SmartTagReference & xTag)167 void SmartTagSet::add( const SmartTagReference& xTag )
168 {
169 	maSet.insert( xTag );
170 	mrView.InvalidateAllWin();
171 
172 	if( xTag == mxMouseOverTag )
173 		mxMouseOverTag.clear();
174 
175 	if( xTag == mxSelectedTag )
176 		mxSelectedTag.clear();
177 }
178 
179 // --------------------------------------------------------------------
180 
remove(const SmartTagReference & xTag)181 void SmartTagSet::remove( const SmartTagReference& xTag )
182 {
183 	std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
184 	if( aIter != maSet.end() )
185 		maSet.erase( aIter );
186 	mrView.InvalidateAllWin();
187 
188 	if( xTag == mxMouseOverTag )
189 		mxMouseOverTag.clear();
190 
191 	if( xTag == mxSelectedTag )
192 		mxSelectedTag.clear();
193 }
194 
195 // --------------------------------------------------------------------
196 
Dispose()197 void SmartTagSet::Dispose()
198 {
199 	std::set< SmartTagReference > aSet;
200 	aSet.swap( maSet );
201 	for( std::set< SmartTagReference >::iterator aIter( aSet.begin() ); aIter != aSet.end(); )
202 		(*aIter++)->Dispose();
203 	mrView.InvalidateAllWin();
204 	mxMouseOverTag.clear();
205 	mxSelectedTag.clear();
206 }
207 
208 // --------------------------------------------------------------------
209 
select(const SmartTagReference & xTag)210 void SmartTagSet::select( const SmartTagReference& xTag )
211 {
212 	if( mxSelectedTag != xTag )
213 	{
214 		if( mxSelectedTag.is() )
215 			mxSelectedTag->deselect();
216 
217 		mxSelectedTag = xTag;
218 		mxSelectedTag->select();
219 		mrView.SetPossibilitiesDirty();
220 		if( mrView.GetMarkedObjectCount() > 0 )
221 			mrView.UnmarkAllObj();
222 		else
223 			mrView.updateHandles();
224 	}
225 }
226 
227 // --------------------------------------------------------------------
228 
deselect()229 void SmartTagSet::deselect()
230 {
231 	if( mxSelectedTag.is() )
232 	{
233 		mxSelectedTag->deselect();
234 		mxSelectedTag.clear();
235 		mrView.SetPossibilitiesDirty();
236 		mrView.updateHandles();
237 	}
238 }
239 
240 // --------------------------------------------------------------------
241 
MouseButtonDown(const MouseEvent & rMEvt)242 bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
243 {
244 	Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
245 	SdrHdl* pHdl = mrView.PickHandle(aMDPos);
246 
247 	// check if a smart tag is selected and no handle is hit
248 	if( mxSelectedTag.is() && !pHdl )
249 	{
250 		// deselect smart tag
251 		deselect();
252 		return false;
253 	}
254 
255 	// if a smart tag handle is hit, foreword event to its smart tag
256 	SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
257 	if(pSmartHdl && pSmartHdl->getTag().is() )
258 	{
259 		SmartTagReference xTag( pSmartHdl->getTag() );
260 		return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
261 	}
262 
263 	return false;
264 }
265 
266 // --------------------------------------------------------------------
267 
KeyInput(const KeyEvent & rKEvt)268 bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
269 {
270 	if( mxSelectedTag.is() )
271 		return mxSelectedTag->KeyInput( rKEvt );
272 	else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
273 	{
274 	    SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
275 	    if( pSmartHdl )
276 	    {
277 	        const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
278     		SmartTagReference xTag( pSmartHdl->getTag() );
279 	        select( xTag );
280 	        return true;
281 		}
282 	}
283 
284 
285 	return false;
286 }
287 
288 // --------------------------------------------------------------------
289 
RequestHelp(const HelpEvent & rHEvt)290 bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
291 {
292 	Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
293 	SdrHdl* pHdl = mrView.PickHandle(aMDPos);
294 
295     if( pHdl )
296     {
297 	    // if a smart tag handle is hit, foreword event to its smart tag
298 	    SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
299 	    if(pSmartHdl && pSmartHdl->getTag().is() )
300 	    {
301 		    SmartTagReference xTag( pSmartHdl->getTag() );
302 		    return xTag->RequestHelp( rHEvt );
303 	    }
304 	}
305 
306 	return false;
307 }
308 
309 // --------------------------------------------------------------------
310 
311 /** returns true if the SmartTag consumes this event. */
Command(const CommandEvent & rCEvt)312 bool SmartTagSet::Command( const CommandEvent& rCEvt )
313 {
314     if( rCEvt.IsMouseEvent() )
315     {
316 	    Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
317 	    SdrHdl* pHdl = mrView.PickHandle(aMDPos);
318 
319         if( pHdl )
320         {
321 	        // if a smart tag handle is hit, foreword event to its smart tag
322 	        SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
323 	        if(pSmartHdl && pSmartHdl->getTag().is() )
324 	        {
325 		        SmartTagReference xTag( pSmartHdl->getTag() );
326 		        return xTag->Command( rCEvt );
327 	        }
328 	    }
329     }
330     else
331     {
332     	if( mxSelectedTag.is() )
333 	    	return mxSelectedTag->Command( rCEvt );
334 
335     }
336 
337     return false;
338 }
339 
340 // --------------------------------------------------------------------
341 
addCustomHandles(SdrHdlList & rHandlerList)342 void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
343 {
344 	if( !maSet.empty() )
345 	{
346 		for( std::set< SmartTagReference >::iterator aIter( maSet.begin() ); aIter != maSet.end(); )
347 			(*aIter++)->addCustomHandles( rHandlerList );
348 	}
349 }
350 
351 // --------------------------------------------------------------------
352 
353 /** returns true if the currently selected smart tag has
354 	a special context, returned in rContext. */
getContext(SdrViewContext & rContext) const355 bool SmartTagSet::getContext( SdrViewContext& rContext ) const
356 {
357 	if( mxSelectedTag.is() )
358 		return mxSelectedTag->getContext( rContext );
359 	else
360 		return false;
361 }
362 
363 // --------------------------------------------------------------------
364 // support point editing
365 // --------------------------------------------------------------------
366 
HasMarkablePoints() const367 sal_Bool SmartTagSet::HasMarkablePoints() const
368 {
369 	return GetMarkablePointCount() != 0 ? sal_True : sal_False;
370 }
371 
372 // --------------------------------------------------------------------
373 
GetMarkablePointCount() const374 sal_uLong SmartTagSet::GetMarkablePointCount() const
375 {
376 	if( mxSelectedTag.is() )
377 		return mxSelectedTag->GetMarkablePointCount();
378 	return 0;
379 }
380 
381 // --------------------------------------------------------------------
382 
HasMarkedPoints() const383 sal_Bool SmartTagSet::HasMarkedPoints() const
384 {
385 	return GetMarkedPointCount() != 0 ? sal_True : sal_False;
386 }
387 
388 // --------------------------------------------------------------------
389 
GetMarkedPointCount() const390 sal_uLong SmartTagSet::GetMarkedPointCount() const
391 {
392 	if( mxSelectedTag.is() )
393 		return mxSelectedTag->GetMarkedPointCount();
394 	else
395 		return 0;
396 }
397 
398 // --------------------------------------------------------------------
399 
IsPointMarkable(const SdrHdl & rHdl) const400 sal_Bool SmartTagSet::IsPointMarkable(const SdrHdl& rHdl) const
401 {
402 	const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
403 
404 	return pSmartHdl && pSmartHdl->isMarkable();
405 }
406 
407 // --------------------------------------------------------------------
408 
MarkPoint(SdrHdl & rHdl,sal_Bool bUnmark)409 sal_Bool SmartTagSet::MarkPoint(SdrHdl& rHdl, sal_Bool bUnmark )
410 {
411 	if( mxSelectedTag.is() )
412 		return mxSelectedTag->MarkPoint( rHdl, bUnmark );
413 
414 	return sal_False;
415 }
416 
417 // --------------------------------------------------------------------
418 
MarkPoints(const Rectangle * pRect,sal_Bool bUnmark)419 sal_Bool SmartTagSet::MarkPoints(const Rectangle* pRect, sal_Bool bUnmark)
420 {
421 	if( mxSelectedTag.is() )
422 		return mxSelectedTag->MarkPoints( pRect, bUnmark );
423 	return sal_False;
424 }
425 
426 // --------------------------------------------------------------------
427 
CheckPossibilities()428 void SmartTagSet::CheckPossibilities()
429 {
430 	if( mxSelectedTag.is() )
431 		mxSelectedTag->CheckPossibilities();
432 }
433 
434 // ====================================================================
435 
SmartHdl(const SmartTagReference & xTag,SdrObject * pObject,const Point & rPnt,SdrHdlKind eNewKind)436 SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
437 : SdrHdl( rPnt, eNewKind )
438 , mxTag( xTag )
439 {
440 	SetObj( pObject );
441 }
442 
443 // --------------------------------------------------------------------
444 
SmartHdl(const SmartTagReference & xTag,const Point & rPnt,SdrHdlKind eNewKind)445 SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
446 : SdrHdl( rPnt, eNewKind )
447 , mxTag( xTag )
448 {
449 }
450 
451 // --------------------------------------------------------------------
452 
isMarkable() const453 bool SmartHdl::isMarkable() const
454 {
455 	return false;
456 }
457 
458 // ====================================================================
459 
460 /*
461 SmartProxyHdl::SmartProxyHdl( const SmartTagReference& xTag, SdrHdl* pProxyHdl )
462 : SmartHdl( xTag, pProxyHdl->GetPos(), pProxyHdl->GetKind() )
463 , mpProxyHdl( pProxyHdl )
464 {
465 }
466 
467 // --------------------------------------------------------------------
468 
469 SmartProxyHdl::~SmartProxyHdl()
470 {
471 	delete mpProxyHdl;
472 }
473 */
474 } // end of namespace sd
475 
476