Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "ViewShell.hxx"
22 : : #include "smarttag.hxx"
23 : : #include "Window.hxx"
24 : : #include "View.hxx"
25 : :
26 : : namespace sd
27 : : {
28 : :
29 : : // ====================================================================
30 : :
31 : 0 : SmartTag::SmartTag( ::sd::View& rView )
32 : : : mrView( rView )
33 : 0 : , mbSelected( false )
34 : : {
35 [ # # ]: 0 : SmartTagReference xThis( this );
36 [ # # ][ # # ]: 0 : mrView.getSmartTags().add( xThis );
37 : 0 : }
38 : :
39 : : // --------------------------------------------------------------------
40 : :
41 : 0 : SmartTag::~SmartTag()
42 : : {
43 [ # # ]: 0 : }
44 : :
45 : : // --------------------------------------------------------------------
46 : :
47 : 0 : bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl& )
48 : : {
49 : 0 : return false;
50 : : }
51 : :
52 : : /** returns true if the SmartTag consumes this event. */
53 : 0 : bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
54 : : {
55 : 0 : return false;
56 : : }
57 : :
58 : : /** returns true if the SmartTag consumes this event. */
59 : 0 : bool SmartTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
60 : : {
61 : 0 : return false;
62 : : }
63 : :
64 : : /** returns true if the SmartTag consumes this event. */
65 : 0 : bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
66 : : {
67 : 0 : return false;
68 : : }
69 : :
70 : : // --------------------------------------------------------------------
71 : :
72 : 0 : void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
73 : : {
74 : 0 : }
75 : :
76 : : // --------------------------------------------------------------------
77 : :
78 : 0 : void SmartTag::select()
79 : : {
80 : 0 : mbSelected = true;
81 : 0 : }
82 : :
83 : : // --------------------------------------------------------------------
84 : :
85 : 0 : void SmartTag::deselect()
86 : : {
87 : 0 : mbSelected = false;
88 : 0 : }
89 : :
90 : : // --------------------------------------------------------------------
91 : :
92 : 0 : bool SmartTag::isSelected() const
93 : : {
94 : 0 : return mbSelected;
95 : : }
96 : :
97 : : // --------------------------------------------------------------------
98 : :
99 : 0 : void SmartTag::disposing()
100 : : {
101 [ # # ]: 0 : SmartTagReference xThis( this );
102 [ # # ][ # # ]: 0 : mrView.getSmartTags().remove( xThis );
103 : 0 : }
104 : :
105 : : // --------------------------------------------------------------------
106 : :
107 : 0 : bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
108 : : {
109 : 0 : return false;
110 : : }
111 : :
112 : : // --------------------------------------------------------------------
113 : :
114 : 0 : sal_uLong SmartTag::GetMarkablePointCount() const
115 : : {
116 : 0 : return 0;
117 : : }
118 : :
119 : : // --------------------------------------------------------------------
120 : :
121 : 0 : sal_uLong SmartTag::GetMarkedPointCount() const
122 : : {
123 : 0 : return 0;
124 : : }
125 : :
126 : : // --------------------------------------------------------------------
127 : :
128 : 0 : sal_Bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, sal_Bool /*bUnmark*/ )
129 : : {
130 : 0 : return sal_False;
131 : : }
132 : :
133 : : // --------------------------------------------------------------------
134 : :
135 : 0 : sal_Bool SmartTag::MarkPoints(const Rectangle* /*pRect*/, sal_Bool /*bUnmark*/ )
136 : : {
137 : 0 : return sal_False;
138 : : }
139 : :
140 : : // --------------------------------------------------------------------
141 : :
142 : 0 : void SmartTag::CheckPossibilities()
143 : : {
144 : 0 : }
145 : :
146 : : // ====================================================================
147 : :
148 : 390 : SmartTagSet::SmartTagSet( View& rView )
149 : 390 : : mrView( rView )
150 : : {
151 : 390 : }
152 : :
153 : : // --------------------------------------------------------------------
154 : :
155 [ + - ][ + - ]: 390 : SmartTagSet::~SmartTagSet()
156 : : {
157 : 390 : }
158 : :
159 : : // --------------------------------------------------------------------
160 : :
161 : 0 : void SmartTagSet::add( const SmartTagReference& xTag )
162 : : {
163 : 0 : maSet.insert( xTag );
164 : 0 : mrView.InvalidateAllWin();
165 : :
166 [ # # ]: 0 : if( xTag == mxMouseOverTag )
167 : 0 : mxMouseOverTag.clear();
168 : :
169 [ # # ]: 0 : if( xTag == mxSelectedTag )
170 : 0 : mxSelectedTag.clear();
171 : 0 : }
172 : :
173 : : // --------------------------------------------------------------------
174 : :
175 : 0 : void SmartTagSet::remove( const SmartTagReference& xTag )
176 : : {
177 [ # # ]: 0 : std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
178 [ # # ]: 0 : if( aIter != maSet.end() )
179 [ # # ]: 0 : maSet.erase( aIter );
180 [ # # ]: 0 : mrView.InvalidateAllWin();
181 : :
182 [ # # ]: 0 : if( xTag == mxMouseOverTag )
183 [ # # ]: 0 : mxMouseOverTag.clear();
184 : :
185 [ # # ]: 0 : if( xTag == mxSelectedTag )
186 [ # # ]: 0 : mxSelectedTag.clear();
187 : 0 : }
188 : :
189 : : // --------------------------------------------------------------------
190 : :
191 : 390 : void SmartTagSet::Dispose()
192 : : {
193 [ + - ]: 390 : std::set< SmartTagReference > aSet;
194 [ + - ]: 390 : aSet.swap( maSet );
195 [ - + ]: 390 : for( std::set< SmartTagReference >::iterator aIter( aSet.begin() ); aIter != aSet.end(); )
196 [ # # ]: 0 : (*aIter++)->Dispose();
197 [ + - ]: 390 : mrView.InvalidateAllWin();
198 [ + - ]: 390 : mxMouseOverTag.clear();
199 [ + - ]: 390 : mxSelectedTag.clear();
200 : 390 : }
201 : :
202 : : // --------------------------------------------------------------------
203 : :
204 : 0 : void SmartTagSet::select( const SmartTagReference& xTag )
205 : : {
206 [ # # ]: 0 : if( mxSelectedTag != xTag )
207 : : {
208 [ # # ]: 0 : if( mxSelectedTag.is() )
209 : 0 : mxSelectedTag->deselect();
210 : :
211 : 0 : mxSelectedTag = xTag;
212 : 0 : mxSelectedTag->select();
213 : 0 : mrView.SetPossibilitiesDirty();
214 [ # # ]: 0 : if( mrView.GetMarkedObjectCount() > 0 )
215 : 0 : mrView.UnmarkAllObj();
216 : : else
217 : 0 : mrView.updateHandles();
218 : : }
219 : 0 : }
220 : :
221 : : // --------------------------------------------------------------------
222 : :
223 : 2 : void SmartTagSet::deselect()
224 : : {
225 [ - + ]: 2 : if( mxSelectedTag.is() )
226 : : {
227 : 0 : mxSelectedTag->deselect();
228 : 0 : mxSelectedTag.clear();
229 : 0 : mrView.SetPossibilitiesDirty();
230 : 0 : mrView.updateHandles();
231 : : }
232 : 2 : }
233 : :
234 : : // --------------------------------------------------------------------
235 : :
236 : 0 : bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
237 : : {
238 [ # # ][ # # ]: 0 : Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
239 [ # # ]: 0 : SdrHdl* pHdl = mrView.PickHandle(aMDPos);
240 : :
241 : : // check if a smart tag is selected and no handle is hit
242 [ # # ][ # # ]: 0 : if( mxSelectedTag.is() && !pHdl )
[ # # ]
243 : : {
244 : : // deselect smart tag
245 [ # # ]: 0 : deselect();
246 : 0 : return false;
247 : : }
248 : :
249 : : // if a smart tag handle is hit, foreward event to its smart tag
250 [ # # ]: 0 : SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
251 [ # # ][ # # ]: 0 : if(pSmartHdl && pSmartHdl->getTag().is() )
[ # # ]
252 : : {
253 [ # # ]: 0 : SmartTagReference xTag( pSmartHdl->getTag() );
254 [ # # ][ # # ]: 0 : return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
255 : : }
256 : :
257 : 0 : return false;
258 : : }
259 : :
260 : : // --------------------------------------------------------------------
261 : :
262 : 0 : bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
263 : : {
264 [ # # ]: 0 : if( mxSelectedTag.is() )
265 : 0 : return mxSelectedTag->KeyInput( rKEvt );
266 [ # # ]: 0 : else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
267 : : {
268 [ # # ]: 0 : SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
269 [ # # ]: 0 : if( pSmartHdl )
270 : : {
271 [ # # ]: 0 : const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
272 [ # # ]: 0 : SmartTagReference xTag( pSmartHdl->getTag() );
273 [ # # ]: 0 : select( xTag );
274 [ # # ]: 0 : return true;
275 : : }
276 : : }
277 : :
278 : :
279 : 0 : return false;
280 : : }
281 : :
282 : : // --------------------------------------------------------------------
283 : :
284 : 0 : bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
285 : : {
286 [ # # ][ # # ]: 0 : Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
[ # # ]
287 [ # # ]: 0 : SdrHdl* pHdl = mrView.PickHandle(aMDPos);
288 : :
289 [ # # ]: 0 : if( pHdl )
290 : : {
291 : : // if a smart tag handle is hit, foreward event to its smart tag
292 [ # # ]: 0 : SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
293 [ # # ][ # # ]: 0 : if(pSmartHdl && pSmartHdl->getTag().is() )
[ # # ]
294 : : {
295 [ # # ]: 0 : SmartTagReference xTag( pSmartHdl->getTag() );
296 [ # # ][ # # ]: 0 : return xTag->RequestHelp( rHEvt );
297 : : }
298 : : }
299 : :
300 : 0 : return false;
301 : : }
302 : :
303 : : // --------------------------------------------------------------------
304 : :
305 : : /** returns true if the SmartTag consumes this event. */
306 : 0 : bool SmartTagSet::Command( const CommandEvent& rCEvt )
307 : : {
308 [ # # ]: 0 : if( rCEvt.IsMouseEvent() )
309 : : {
310 [ # # ][ # # ]: 0 : Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
311 [ # # ]: 0 : SdrHdl* pHdl = mrView.PickHandle(aMDPos);
312 : :
313 [ # # ]: 0 : if( pHdl )
314 : : {
315 : : // if a smart tag handle is hit, foreward event to its smart tag
316 [ # # ]: 0 : SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
317 [ # # ][ # # ]: 0 : if(pSmartHdl && pSmartHdl->getTag().is() )
[ # # ]
318 : : {
319 [ # # ]: 0 : SmartTagReference xTag( pSmartHdl->getTag() );
320 [ # # ][ # # ]: 0 : return xTag->Command( rCEvt );
321 : : }
322 : : }
323 : : }
324 : : else
325 : : {
326 [ # # ]: 0 : if( mxSelectedTag.is() )
327 : 0 : return mxSelectedTag->Command( rCEvt );
328 : :
329 : : }
330 : :
331 : 0 : return false;
332 : : }
333 : :
334 : : // --------------------------------------------------------------------
335 : :
336 : 909 : void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
337 : : {
338 [ - + ]: 909 : if( !maSet.empty() )
339 : : {
340 [ # # ]: 0 : for( std::set< SmartTagReference >::iterator aIter( maSet.begin() ); aIter != maSet.end(); )
341 [ # # ]: 0 : (*aIter++)->addCustomHandles( rHandlerList );
342 : : }
343 : 909 : }
344 : :
345 : : // --------------------------------------------------------------------
346 : :
347 : : /** returns true if the currently selected smart tag has
348 : : a special context, returned in rContext. */
349 : 1044 : bool SmartTagSet::getContext( SdrViewContext& rContext ) const
350 : : {
351 [ - + ]: 1044 : if( mxSelectedTag.is() )
352 : 0 : return mxSelectedTag->getContext( rContext );
353 : : else
354 : 1044 : return false;
355 : : }
356 : :
357 : : // --------------------------------------------------------------------
358 : : // support point editing
359 : : // --------------------------------------------------------------------
360 : :
361 : 1449 : sal_Bool SmartTagSet::HasMarkablePoints() const
362 : : {
363 [ - + ]: 1449 : return GetMarkablePointCount() != 0 ? sal_True : sal_False;
364 : : }
365 : :
366 : : // --------------------------------------------------------------------
367 : :
368 : 1449 : sal_uLong SmartTagSet::GetMarkablePointCount() const
369 : : {
370 [ - + ]: 1449 : if( mxSelectedTag.is() )
371 : 0 : return mxSelectedTag->GetMarkablePointCount();
372 : 1449 : return 0;
373 : : }
374 : :
375 : : // --------------------------------------------------------------------
376 : :
377 : 1 : sal_Bool SmartTagSet::HasMarkedPoints() const
378 : : {
379 [ - + ]: 1 : return GetMarkedPointCount() != 0 ? sal_True : sal_False;
380 : : }
381 : :
382 : : // --------------------------------------------------------------------
383 : :
384 : 1 : sal_uLong SmartTagSet::GetMarkedPointCount() const
385 : : {
386 [ - + ]: 1 : if( mxSelectedTag.is() )
387 : 0 : return mxSelectedTag->GetMarkedPointCount();
388 : : else
389 : 1 : return 0;
390 : : }
391 : :
392 : : // --------------------------------------------------------------------
393 : :
394 : 16 : sal_Bool SmartTagSet::IsPointMarkable(const SdrHdl& rHdl) const
395 : : {
396 [ - + ]: 16 : const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
397 : :
398 [ - + ][ # # ]: 16 : return pSmartHdl && pSmartHdl->isMarkable();
399 : : }
400 : :
401 : : // --------------------------------------------------------------------
402 : :
403 : 0 : sal_Bool SmartTagSet::MarkPoint(SdrHdl& rHdl, sal_Bool bUnmark )
404 : : {
405 [ # # ]: 0 : if( mxSelectedTag.is() )
406 : 0 : return mxSelectedTag->MarkPoint( rHdl, bUnmark );
407 : :
408 : 0 : return sal_False;
409 : : }
410 : :
411 : : // --------------------------------------------------------------------
412 : :
413 : 130 : sal_Bool SmartTagSet::MarkPoints(const Rectangle* pRect, sal_Bool bUnmark)
414 : : {
415 [ - + ]: 130 : if( mxSelectedTag.is() )
416 : 0 : return mxSelectedTag->MarkPoints( pRect, bUnmark );
417 : 130 : return sal_False;
418 : : }
419 : :
420 : : // --------------------------------------------------------------------
421 : :
422 : 9573 : void SmartTagSet::CheckPossibilities()
423 : : {
424 [ - + ]: 9573 : if( mxSelectedTag.is() )
425 : 0 : mxSelectedTag->CheckPossibilities();
426 : 9573 : }
427 : :
428 : : // ====================================================================
429 : :
430 : 0 : SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
431 : : : SdrHdl( rPnt, eNewKind )
432 [ # # ]: 0 : , mxTag( xTag )
433 : : {
434 [ # # ]: 0 : SetObj( pObject );
435 : 0 : }
436 : :
437 : : // --------------------------------------------------------------------
438 : :
439 : 0 : SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
440 : : : SdrHdl( rPnt, eNewKind )
441 [ # # ]: 0 : , mxTag( xTag )
442 : : {
443 : 0 : }
444 : :
445 : : // --------------------------------------------------------------------
446 : :
447 : 0 : bool SmartHdl::isMarkable() const
448 : : {
449 : 0 : return false;
450 : : }
451 : :
452 : : } // end of namespace sd
453 : :
454 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|