1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: SelectionHelper.cxx,v $
* $Revision: 1.11.68.1 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_chart2.hxx"
#include "SelectionHelper.hxx"
#include "ObjectIdentifier.hxx"
//for C2U
#include "macros.hxx"
#include "DiagramHelper.hxx"
#include "ChartModelHelper.hxx"
// header for class SdrObjList
#include <svx/svdpage.hxx>
#include <svx/svditer.hxx>
#include "svx/obj3d.hxx"
// header for class SdrPathObj
#include <svx/svdopath.hxx>
#include <vcl/svapp.hxx>
#include <vos/mutex.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
//.............................................................................
namespace chart
{
//.............................................................................
using namespace ::com::sun::star;
//using namespace ::com::sun::star::chart2;
namespace
{
rtl::OUString lcl_getObjectName( SdrObject* pObj )
{
if(pObj)
return pObj->GetName();
return rtl::OUString();
}
void impl_selectObject( SdrObject* pObjectToSelect, DrawViewWrapper& rDrawViewWrapper )
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
if(pObjectToSelect)
{
SelectionHelper aSelectionHelper( pObjectToSelect );
SdrObject* pMarkObj = aSelectionHelper.getObjectToMark();
rDrawViewWrapper.setMarkHandleProvider(&aSelectionHelper);
rDrawViewWrapper.MarkObject(pMarkObj);
rDrawViewWrapper.setMarkHandleProvider(NULL);
}
}
}//anonymous namespace
bool Selection::hasSelection()
{
return m_aSelectedObjectCID.getLength() || m_xSelectAdditionalShape.is();
}
rtl::OUString Selection::getSelectedCID()
{
return m_aSelectedObjectCID;
}
uno::Reference< drawing::XShape > Selection::getSelectedAdditionalShape()
{
return m_xSelectAdditionalShape;
}
bool Selection::setSelection( const ::rtl::OUString& rCID )
{
if( !rCID.equals( m_aSelectedObjectCID ) )
{
m_aSelectedObjectCID = rCID;
m_xSelectAdditionalShape.set(0);
return true;
}
return false;
}
bool Selection::setSelection( const uno::Reference< drawing::XShape >& xShape )
{
if( !(m_xSelectAdditionalShape==xShape) )
{
clearSelection();
m_xSelectAdditionalShape = xShape;
return true;
}
return false;
}
void Selection::clearSelection()
{
m_aSelectedObjectCID = m_aSelectedObjectCID_beforeMouseDown
= m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = rtl::OUString();
m_xSelectAdditionalShape.set(0);
}
bool Selection::maybeSwitchSelectionAfterSingleClickWasEnsured()
{
if( m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing.getLength()
&& !m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing.equals(m_aSelectedObjectCID) )
{
m_aSelectedObjectCID = m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing;
m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = C2U("");
return true;
}
return false;
}
void Selection::resetPossibleSelectionAfterSingleClickWasEnsured()
{
if( m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing.getLength() )
m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = C2U("");
}
void Selection::remindSelectionBeforeMouseDown()
{
m_aSelectedObjectCID_beforeMouseDown = m_aSelectedObjectCID;
}
bool Selection::isSelectionDifferentFromBeforeMouseDown()
{
return !ObjectIdentifier::areIdenticalObjects( m_aSelectedObjectCID, m_aSelectedObjectCID_beforeMouseDown );
}
void Selection::applySelection( DrawViewWrapper* pDrawViewWrapper )
{
if( pDrawViewWrapper )
{
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
pDrawViewWrapper->UnmarkAll();
}
SdrObject* pObjectToSelect = 0;
if( m_aSelectedObjectCID.getLength() )
pObjectToSelect = pDrawViewWrapper->getNamedSdrObject( m_aSelectedObjectCID );
else if( m_xSelectAdditionalShape.is() )
pObjectToSelect = DrawViewWrapper::getSdrObject( m_xSelectAdditionalShape );
impl_selectObject( pObjectToSelect, *pDrawViewWrapper );
}
}
void Selection::adaptSelectionToNewPos( const Point& rMousePos, DrawViewWrapper* pDrawViewWrapper
, bool bIsRightMouse, bool bWaitingForDoubleClick )
{
if( pDrawViewWrapper )
{
//do not toggel multiclick selection if right clicked on the selected object or waiting for double click
bool bAllowMultiClickSelectionChange = !bIsRightMouse && !bWaitingForDoubleClick;
const rtl::OUString aNameOfLastSelectedObject( m_aSelectedObjectCID );
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
//bAllowMultiClickSelectionChange==true -> a second click on the same object can lead to a changed selection (e.g. series -> single data point)
//get object to select:
SdrObject* pNewObj = 0;
{
m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = C2U("");
m_xSelectAdditionalShape.set(0);
//the search for the object to select starts with the hit object deepest in the grouping hierarchy (a leaf in the tree)
//further we travel along the grouping hierarchy from child to parent
pNewObj = pDrawViewWrapper->getHitObject(rMousePos);
m_aSelectedObjectCID = lcl_getObjectName( pNewObj );//name of pNewObj
rtl::OUString aTestFirstHit = m_aSelectedObjectCID;
//ignore handle only objects for hit test
while( pNewObj && m_aSelectedObjectCID.match(C2U("HandlesOnly")) )
{
pNewObj->SetMarkProtect(true);
pNewObj = pDrawViewWrapper->getHitObject(rMousePos);
m_aSelectedObjectCID = lcl_getObjectName( pNewObj );
}
//accept only named objects while searching for the object to select
//this call may change m_aSelectedObjectCID
if( SelectionHelper::findNamedParent( pNewObj, m_aSelectedObjectCID, true ) )
{
//if the so far found object is a multi click object further steps are necessary
while( ObjectIdentifier::isMultiClickObject( m_aSelectedObjectCID ) )
{
bool bSameObjectAsLastSelected = ObjectIdentifier::areIdenticalObjects( aNameOfLastSelectedObject, m_aSelectedObjectCID );
if( bSameObjectAsLastSelected )
{
//if the same child is clicked again don't go up further
break;
}
if( ObjectIdentifier::areSiblings(aNameOfLastSelectedObject,m_aSelectedObjectCID) )
{
//if a sibling of the last selected object is clicked don't go up further
break;
}
SdrObject* pLastChild = pNewObj;
rtl::OUString aLastChildName = m_aSelectedObjectCID;
if(!SelectionHelper::findNamedParent( pNewObj, m_aSelectedObjectCID, false ))
{
//take the one found so far
break;
}
//if the last selected object is found don't go up further
//but take the last child if selection change is allowed
if( ObjectIdentifier::areIdenticalObjects( aNameOfLastSelectedObject, m_aSelectedObjectCID ) )
{
if( bAllowMultiClickSelectionChange )
{
pNewObj = pLastChild;
m_aSelectedObjectCID = aLastChildName;
}
else
m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = aLastChildName;
break;
}
}
DBG_ASSERT(pNewObj && m_aSelectedObjectCID.getLength(),"somehow lost selected object");
}
else
{
//maybe an additional shape was hit
m_aSelectedObjectCID = rtl::OUString();
if( pNewObj )
{
m_xSelectAdditionalShape = uno::Reference< drawing::XShape >( pNewObj->getUnoShape(), uno::UNO_QUERY);
}
}
if(!m_xSelectAdditionalShape.is())
{
rtl::OUString aPageCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, rtl::OUString() ) );//@todo read CID from model
if( !m_aSelectedObjectCID.getLength() )
m_aSelectedObjectCID = aPageCID;
//check wether the diagram was hit but not selected (e.g. because it has no filling):
rtl::OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ) );//@todo read CID from model
if( m_aSelectedObjectCID.equals( aPageCID ) || m_aSelectedObjectCID.equals( aWallCID ) || !m_aSelectedObjectCID.getLength() )
{
rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) );
//todo: if more than one diagram is available in future do chack the list of all diagrams here
SdrObject* pDiagram = pDrawViewWrapper->getNamedSdrObject( aDiagramCID );
if( pDiagram )
{
if( pDrawViewWrapper->IsObjectHit( pDiagram, rMousePos ) )
{
m_aSelectedObjectCID = aDiagramCID;
pNewObj = pDiagram;
}
}
}
}
}
if( bIsRightMouse && m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing.getLength() )
m_aSelectedObjectCID_selectOnlyIfNoDoubleClickIsFollowing = C2U("");
}
}
bool Selection::isResizeableObjectSelected()
{
ObjectType eObjectType = ObjectIdentifier::getObjectType( m_aSelectedObjectCID );
switch( eObjectType )
{
case OBJECTTYPE_DIAGRAM:
case OBJECTTYPE_DIAGRAM_WALL:
return true;
default:
return false;
}
return false;
}
bool Selection::isRotateableObjectSelected( const uno::Reference< frame::XModel >& xChartModel )
{
return SelectionHelper::isRotateableObject( m_aSelectedObjectCID, xChartModel );
}
bool Selection::isDragableObjectSelected()
{
if( m_aSelectedObjectCID.getLength() )
return ObjectIdentifier::isDragableObject( m_aSelectedObjectCID );
return m_xSelectAdditionalShape.is();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//static
bool SelectionHelper::findNamedParent( SdrObject*& pInOutObject
, rtl::OUString& rOutName
, bool bGivenObjectMayBeResult )
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
//find the deepest named group
SdrObject* pObj = pInOutObject;
rtl::OUString aName;
if( bGivenObjectMayBeResult )
aName = lcl_getObjectName( pObj );
while( pObj && !ObjectIdentifier::isCID( aName ) )
{
SdrObjList* pObjList = pObj->GetObjList();
if( !pObjList )
return false;;
SdrObject* pOwner = pObjList->GetOwnerObj();
if( !pOwner )
return false;
pObj = pOwner;
aName = lcl_getObjectName( pObj );
}
if(!pObj)
return false;
if(!aName.getLength())
return false;
pInOutObject = pObj;
rOutName = aName;
return true;
}
//static
bool SelectionHelper::isDragableObjectHitTwice( const Point& rMPos
, const rtl::OUString& rNameOfSelectedObject
, const DrawViewWrapper& rDrawViewWrapper )
{
if(!rNameOfSelectedObject.getLength())
return false;
if( !ObjectIdentifier::isDragableObject(rNameOfSelectedObject) )
return false;
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
SdrObject* pObj = rDrawViewWrapper.getNamedSdrObject( rNameOfSelectedObject );
if( !rDrawViewWrapper.IsObjectHit( pObj, rMPos ) )
return false;
return true;
}
/*
rtl::OUString lcl_getObjectCIDToSelect( const Point& rMPos
, const rtl::OUString& rNameOfLastSelectedObject
, DrawViewWrapper& rDrawViewWrapper
, bool bAllowMultiClickSelectionChange
, rtl::OUString& rObjectToSelectIfNoDoubleClickIsFollowing //out parameter only
)
{
rtl::OUString aRet;
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
//bAllowMultiClickSelectionChange==true -> a second click on the same object can lead to a changed selection (e.g. series -> single data point)
//get object to select:
SdrObject* pNewObj = 0;
{
rObjectToSelectIfNoDoubleClickIsFollowing = C2U("");
//the search for the object to select starts with the hit object deepest in the grouping hierarchy (a leaf in the tree)
//further we travel along the grouping hierarchy from child to parent
pNewObj = rDrawViewWrapper.getHitObject(rMPos);
aRet = lcl_getObjectName( pNewObj );//name of pNewObj
rtl::OUString aTestFirstHit = aRet;
//ignore handle only objects for hit test
while( pNewObj && aRet.match(C2U("HandlesOnly")) )
{
pNewObj->SetMarkProtect(true);
pNewObj = rDrawViewWrapper.getHitObject(rMPos);
aRet = lcl_getObjectName( pNewObj );
}
//accept only named objects while searching for the object to select
//this call may change aRet
if( !findNamedParent( pNewObj, aRet, true ) )
{
return C2U("");
}
//if the so far found object is a multi click object further steps are necessary
while( ObjectIdentifier::isMultiClickObject( aRet ) )
{
bool bSameObjectAsLastSelected = ObjectIdentifier::areIdenticalObjects( rNameOfLastSelectedObject, aRet );
if( bSameObjectAsLastSelected )
{
//if the same child is clicked again don't go up further
break;
}
if( ObjectIdentifier::areSiblings(rNameOfLastSelectedObject,aRet) )
{
//if a sibling of the last selected object is clicked don't go up further
break;
}
SdrObject* pLastChild = pNewObj;
rtl::OUString aLastChildName = aRet;
if(!findNamedParent( pNewObj, aRet, false ))
{
//take the one found so far
break;
}
//if the last selected object is found don't go up further
//but take the last child if selection change is allowed
if( ObjectIdentifier::areIdenticalObjects( rNameOfLastSelectedObject, aRet ) )
{
if( bAllowMultiClickSelectionChange )
{
pNewObj = pLastChild;
aRet = aLastChildName;
}
else
rObjectToSelectIfNoDoubleClickIsFollowing = aLastChildName;
break;
}
}
//check wether the diagram was hit but not selected:
rtl::OUString aPageCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, rtl::OUString() ) );//@todo read CID from model
rtl::OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ) );//@todo read CID from model
if( aRet.equals( aPageCID ) || aRet.equals( aWallCID ) || !aRet.getLength() )
{
rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) );
//todo: if more than one diagram is available in future do chack the list of all diagrams here
SdrObject* pDiagram = rDrawViewWrapper.getNamedSdrObject( aDiagramCID );
if( pDiagram )
{
if( rDrawViewWrapper.IsObjectHit( pDiagram, rMPos ) )
{
aRet = aDiagramCID;
pNewObj = pDiagram;
}
}
}
DBG_ASSERT(pNewObj && aRet.getLength(),"somehow lost selected object");
}
return aRet;
}
*/
// static
::rtl::OUString SelectionHelper::getHitObjectCID(
const Point& rMPos,
DrawViewWrapper& rDrawViewWrapper,
bool bGetDiagramInsteadOf_Wall )
{
// //- solar mutex
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
rtl::OUString aRet;
SdrObject* pNewObj = rDrawViewWrapper.getHitObject(rMPos);
aRet = lcl_getObjectName( pNewObj );//name of pNewObj
//ignore handle only objects for hit test
while( pNewObj && aRet.match(C2U("HandlesOnly")) )
{
pNewObj->SetMarkProtect(true);
pNewObj = rDrawViewWrapper.getHitObject(rMPos);
aRet = lcl_getObjectName( pNewObj );
}
//accept only named objects while searching for the object to select
if( !findNamedParent( pNewObj, aRet, true ) )
{
aRet = ::rtl::OUString();
}
rtl::OUString aPageCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, rtl::OUString() ) );//@todo read CID from model
//get page when nothing was hit
if( aRet.getLength() == 0 && !pNewObj )
{
aRet = aPageCID;
}
//get diagram instead wall or page if hit inside diagram
if( aRet.getLength() != 0 )
{
if( aRet.equals( aPageCID ) )
{
rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) );
//todo: if more than one diagram is available in future do chack the list of all diagrams here
SdrObject* pDiagram = rDrawViewWrapper.getNamedSdrObject( aDiagramCID );
if( pDiagram )
{
if( rDrawViewWrapper.IsObjectHit( pDiagram, rMPos ) )
{
aRet = aDiagramCID;
}
}
}
else if( bGetDiagramInsteadOf_Wall )
{
rtl::OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ) );//@todo read CID from model
if( aRet.equals( aWallCID ) )
{
rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) );
aRet = aDiagramCID;
}
}
}
return aRet;
// \\- solar mutex
}
//static
bool SelectionHelper::isRotateableObject( const ::rtl::OUString& rCID
, const uno::Reference< frame::XModel >& xChartModel )
{
if( !ObjectIdentifier::isRotateableObject( rCID ) )
return false;
sal_Int32 nDimensionCount = DiagramHelper::getDimension( ChartModelHelper::findDiagram( xChartModel ) );
if( nDimensionCount == 3 )
return true;
return false;
}
SelectionHelper::SelectionHelper( SdrObject* pSelectedObj )
: m_pSelectedObj( pSelectedObj )
{
}
SelectionHelper::~SelectionHelper()
{
}
//virtual
bool SelectionHelper::getFrameDragSingles()
{
bool bFrameDragSingles = true;//true == green == surrounding handles
if( m_pSelectedObj && m_pSelectedObj->ISA(E3dObject) )
bFrameDragSingles = false;
return bFrameDragSingles;
}
//static
SdrObject* SelectionHelper::getMarkHandlesObject( SdrObject* pObj )
{
if(!pObj)
return 0;
rtl::OUString aName( lcl_getObjectName( pObj ) );
if( aName.match(C2U("MarkHandles")) || aName.match(C2U("HandlesOnly")) )
return pObj;
if( aName.getLength() )//dont't get the markhandles of a different object
return 0;
//search for a child with name "MarkHandles" or "HandlesOnly"
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
SdrObjList* pSubList = pObj->GetSubList();
if(pSubList)
{
SdrObjListIter aIterator(*pSubList, IM_FLAT);
while (aIterator.IsMore())
{
SdrObject* pMarkHandles = SelectionHelper::getMarkHandlesObject( aIterator.Next() );
if( pMarkHandles )
return pMarkHandles;
}
}
return 0;
}
SdrObject* SelectionHelper::getObjectToMark()
{
//return the selected object itself
//or a specific other object if that exsists
SdrObject* pObj = m_pSelectedObj;
m_pMarkObj = pObj;
//search for a child with name "MarkHandles" or "HandlesOnly"
if(pObj)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
SdrObjList* pSubList = pObj->GetSubList();
if(pSubList)
{
SdrObjListIter aIterator(*pSubList, IM_FLAT);
while (aIterator.IsMore())
{
SdrObject* pMarkHandles = SelectionHelper::getMarkHandlesObject( aIterator.Next() );
if( pMarkHandles )
{
m_pMarkObj = pMarkHandles;
break;
}
}
}
}
return m_pMarkObj;
}
//static
E3dScene* SelectionHelper::getSceneToRotate( SdrObject* pObj )
{
//search wether the object or one of its children is a 3D object
//if so, return the accessory 3DScene
E3dObject* pRotateable = 0;
if(pObj)
{
pRotateable = dynamic_cast<E3dObject*>(pObj);
if( !pRotateable )
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
SdrObjList* pSubList = pObj->GetSubList();
if(pSubList)
{
SdrObjListIter aIterator(*pSubList, IM_DEEPWITHGROUPS);
while( aIterator.IsMore() && !pRotateable )
{
SdrObject* pSubObj = aIterator.Next();
pRotateable = dynamic_cast<E3dObject*>(pSubObj);
}
}
}
}
E3dScene* pScene = 0;
if(pRotateable)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
pScene = pRotateable->GetScene();
}
return pScene;
}
//virtual
bool SelectionHelper::getMarkHandles( SdrHdlList& rHdlList )
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex());
//@todo -> more flexible handle creation
//2 scenarios possible:
//1. add an additional invisible shape as a child to the selected object
//this child needs to be named somehow and handles need to be generated therefrom ...
//or 2. offer a central service per view where renderer and so can register for handle creation for a special shape
//.. or 3. feature from drawinglayer to create handles for each shape ... (bad performance ... ?) ?
//scenario 1 is now used:
//if a child with name MarkHandles exsists
//this child is marked instead of the logical selected object
/*
//if a special mark object was found
//that object should be used for marking only
if( m_pMarkObj != m_pSelectedObj)
return false;
*/
//if a special mark object was found
//that object should be used to create handles from
if( m_pMarkObj && m_pMarkObj != m_pSelectedObj)
{
rHdlList.Clear();
if( m_pMarkObj->ISA(SdrPathObj) )
{
//if th object is a polygon
//from each point a handle is generated
const ::basegfx::B2DPolyPolygon& rPolyPolygon = ((SdrPathObj*)m_pMarkObj)->GetPathPoly();
for( sal_uInt32 nN = 0L; nN < rPolyPolygon.count(); nN++)
{
const ::basegfx::B2DPolygon aPolygon(rPolyPolygon.getB2DPolygon(nN));
for( sal_uInt32 nM = 0L; nM < aPolygon.count(); nM++)
{
const ::basegfx::B2DPoint aPoint(aPolygon.getB2DPoint(nM));
SdrHdl* pHdl = new SdrHdl(Point(basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY())), HDL_POLY);
rHdlList.AddHdl(pHdl);
}
}
return true;
}
else
return false; //use the special MarkObject for marking
}
//@todo:
//add and document good marking defaults ...
rHdlList.Clear();
SdrObject* pObj = m_pSelectedObj;
if(!pObj)
return false;
SdrObjList* pSubList = pObj->GetSubList();
if( !pSubList )//no group object !pObj->IsGroupObject()
return false;
rtl::OUString aName( lcl_getObjectName( pObj ) );
ObjectType eObjectType( ObjectIdentifier::getObjectType( aName ) );
if( OBJECTTYPE_DATA_POINT == eObjectType
|| OBJECTTYPE_DATA_LABEL == eObjectType
|| OBJECTTYPE_LEGEND_ENTRY == eObjectType
|| OBJECTTYPE_AXIS_UNITLABEL == eObjectType )
{
return false;
}
SdrObjListIter aIterator(*pSubList, IM_FLAT);
while (aIterator.IsMore())
{
SdrObject* pSubObj = aIterator.Next();
if( OBJECTTYPE_DATA_SERIES == eObjectType )
{
rtl::OUString aSubName( lcl_getObjectName( pSubObj ) );
ObjectType eSubObjectType( ObjectIdentifier::getObjectType( aSubName ) );
if( eSubObjectType!=OBJECTTYPE_DATA_POINT )
return false;
}
Point aPos = pSubObj->GetCurrentBoundRect().Center();
SdrHdl* pHdl = new SdrHdl(aPos,HDL_POLY);
rHdlList.AddHdl(pHdl);
}
return true;
}
//.............................................................................
} //namespace chart
//.............................................................................
|