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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* 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.
*
************************************************************************/
#include "precompiled_reportdesign.hxx"
#include "ViewsWindow.hxx"
#include "ScrollHelper.hxx"
#include "UndoActions.hxx"
#include "ReportWindow.hxx"
#include "DesignView.hxx"
#include <svtools/colorcfg.hxx>
#include "ReportController.hxx"
#include "UITools.hxx"
#include "RptDef.hxx"
#include "RptResId.hrc"
#include "SectionView.hxx"
#include "ReportSection.hxx"
#include "uistrings.hrc"
#include "rptui_slotid.hrc"
#include "dlgedclip.hxx"
#include "ColorChanger.hxx"
#include "RptObject.hxx"
#include "RptObject.hxx"
#include "ModuleHelper.hxx"
#include "EndMarker.hxx"
#include <svx/svdpagv.hxx>
#include <svx/unoshape.hxx>
#include <vcl/svapp.hxx>
#include <boost/bind.hpp>
#include "helpids.hrc"
#include <svx/svdundo.hxx>
#include <toolkit/helper/convert.hxx>
#include <algorithm>
#include <numeric>
namespace rptui
{
#define DEFAUL_MOVE_SIZE 100
using namespace ::com::sun::star;
using namespace ::comphelper;
// -----------------------------------------------------------------------------
bool lcl_getNewRectSize(const Rectangle& _aObjRect,long& _nXMov, long& _nYMov,SdrObject* _pObj,SdrView* _pView,sal_Int32 _nControlModification, bool _bBoundRects)
{
bool bMoveAllowed = _nXMov != 0 || _nYMov != 0;
if ( bMoveAllowed )
{
Rectangle aNewRect = _aObjRect;
SdrObject* pOverlappedObj = NULL;
do
{
aNewRect = _aObjRect;
switch(_nControlModification)
{
case ControlModification::HEIGHT_GREATEST:
case ControlModification::WIDTH_GREATEST:
aNewRect.setWidth(_nXMov);
aNewRect.setHeight(_nYMov);
break;
default:
aNewRect.Move(_nXMov,_nYMov);
break;
}
if ( dynamic_cast<OUnoObject*>(_pObj) )
{
pOverlappedObj = isOver(aNewRect,*_pObj->GetPage(),*_pView,true,_pObj);
if ( pOverlappedObj && _pObj != pOverlappedObj )
{
Rectangle aOverlappingRect = (_bBoundRects ? pOverlappedObj->GetCurrentBoundRect() : pOverlappedObj->GetSnapRect());
sal_Int32 nXTemp = _nXMov;
sal_Int32 nYTemp = _nYMov;
switch(_nControlModification)
{
case ControlModification::LEFT:
nXTemp += aOverlappingRect.Right() - aNewRect.Left();
bMoveAllowed = _nXMov != nXTemp;
break;
case ControlModification::RIGHT:
nXTemp += aOverlappingRect.Left() - aNewRect.Right();
bMoveAllowed = _nXMov != nXTemp;
break;
case ControlModification::TOP:
nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
bMoveAllowed = _nYMov != nYTemp;
break;
case ControlModification::BOTTOM:
nYTemp += aOverlappingRect.Top() - aNewRect.Bottom();
bMoveAllowed = _nYMov != nYTemp;
break;
case ControlModification::CENTER_HORIZONTAL:
if ( _aObjRect.Left() < aOverlappingRect.Left() )
nXTemp += aOverlappingRect.Left() - aNewRect.Left() - aNewRect.getWidth();
else
nXTemp += aOverlappingRect.Right() - aNewRect.Left();
bMoveAllowed = _nXMov != nXTemp;
break;
case ControlModification::CENTER_VERTICAL:
if ( _aObjRect.Top() < aOverlappingRect.Top() )
nYTemp += aOverlappingRect.Top() - aNewRect.Top() - aNewRect.getHeight();
else
nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
bMoveAllowed = _nYMov != nYTemp;
break;
case ControlModification::HEIGHT_GREATEST:
case ControlModification::WIDTH_GREATEST:
{
Rectangle aIntersectionRect = aNewRect.GetIntersection(aOverlappingRect);
if ( !aIntersectionRect.IsEmpty() )
{
if ( _nControlModification == ControlModification::WIDTH_GREATEST )
{
if ( aNewRect.Left() < aIntersectionRect.Left() )
{
aNewRect.Right() = aIntersectionRect.Left();
}
else if ( aNewRect.Left() < aIntersectionRect.Right() )
{
aNewRect.Left() = aIntersectionRect.Right();
}
}
else if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
{
if ( aNewRect.Top() < aIntersectionRect.Top() )
{
aNewRect.Bottom() = aIntersectionRect.Top();
}
else if ( aNewRect.Top() < aIntersectionRect.Bottom() )
{
aNewRect.Top() = aIntersectionRect.Bottom();
}
}
nYTemp = aNewRect.getHeight();
bMoveAllowed = _nYMov != nYTemp;
nXTemp = aNewRect.getWidth();
bMoveAllowed = bMoveAllowed && _nXMov != nXTemp;
}
}
break;
default:
break;
}
_nXMov = nXTemp;
_nYMov = nYTemp;
}
else
pOverlappedObj = NULL;
}
}
while ( pOverlappedObj && bMoveAllowed );
}
return bMoveAllowed;
}
// -----------------------------------------------------------------------------
DBG_NAME( rpt_OViewsWindow );
OViewsWindow::OViewsWindow( OReportWindow* _pReportWindow)
: Window( _pReportWindow,WB_DIALOGCONTROL)
,m_pParent(_pReportWindow)
,m_bInUnmark(sal_False)
{
DBG_CTOR( rpt_OViewsWindow,NULL);
SetPaintTransparent(TRUE);
SetUniqueId(UID_RPT_VIEWSWINDOW);
SetMapMode( MapMode( MAP_100TH_MM ) );
m_aColorConfig.AddListener(this);
ImplInitSettings();
}
// -----------------------------------------------------------------------------
OViewsWindow::~OViewsWindow()
{
m_aColorConfig.RemoveListener(this);
m_aSections.clear();
DBG_DTOR( rpt_OViewsWindow,NULL);
}
// -----------------------------------------------------------------------------
void OViewsWindow::initialize()
{
}
// -----------------------------------------------------------------------------
void OViewsWindow::impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet)
{
const uno::Reference< report::XSection> xSection = _rSectionWindow.getReportSection().getSection();
Size aSectionSize = _rSectionWindow.LogicToPixel( Size( 0,xSection->getHeight() ) );
aSectionSize.Width() = getView()->GetTotalWidth();
const sal_Int32 nMinHeight = _rSectionWindow.getStartMarker().getMinHeight();
if ( _rSectionWindow.getStartMarker().isCollapsed() || nMinHeight > aSectionSize.Height() )
{
aSectionSize.Height() = nMinHeight;
}
const StyleSettings& rSettings = GetSettings().GetStyleSettings();
aSectionSize.Height() += (long)(rSettings.GetSplitSize() * (double)_rSectionWindow.GetMapMode().GetScaleY());
if ( _bSet )
_rSectionWindow.SetPosSizePixel(_rStartPoint,aSectionSize);
_rStartPoint.Y() += aSectionSize.Height();
}
// -----------------------------------------------------------------------------
void OViewsWindow::resize(const OSectionWindow& _rSectionWindow)
{
bool bSet = false;
Point aStartPoint;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
if ( pSectionWindow.get() == &_rSectionWindow )
{
aStartPoint = pSectionWindow->GetPosPixel();
bSet = true;
} // if ( pSectionWindow.get() == &_rSectionWindow )
if ( bSet )
{
impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,bSet);
pSectionWindow->Invalidate(INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
pSectionWindow->getStartMarker().Invalidate(INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT );
}
} // for (;aIter != aEnd ; ++aIter,++nPos)
Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
aStartWidth *= GetMapMode().GetScaleX();
Size aOut = GetOutputSizePixel();
aOut.Width() = aStartWidth;
aOut = PixelToLogic(aOut);
m_pParent->notifySizeChanged();
Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
Invalidate(aRect,INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
}
//------------------------------------------------------------------------------
void OViewsWindow::Resize()
{
Window::Resize();
if ( !m_aSections.empty() )
{
const Point aOffset(m_pParent->getThumbPos());
Point aStartPoint(0,-aOffset.Y());
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (USHORT nPos=0;aIter != aEnd ; ++aIter,++nPos)
{
const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,true);
} // for (;aIter != aEnd ; ++aIter)
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::Paint( const Rectangle& rRect )
{
Window::Paint( rRect );
Size aOut = GetOutputSizePixel();
Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
aStartWidth *= GetMapMode().GetScaleX();
aOut.Width() -= (long)aStartWidth;
aOut = PixelToLogic(aOut);
Rectangle aRect(PixelToLogic(Point(aStartWidth,0)),aOut);
Wallpaper aWall( m_aColorConfig.GetColorValue(::svtools::APPBACKGROUND).nColor );
DrawWallpaper(aRect,aWall);
}
//------------------------------------------------------------------------------
void OViewsWindow::ImplInitSettings()
{
// SetBackground( Wallpaper( COL_LIGHTBLUE ));
SetBackground( );
SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
SetTextFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
}
//-----------------------------------------------------------------------------
void OViewsWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
Window::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
(rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
ImplInitSettings();
Invalidate();
}
}
//----------------------------------------------------------------------------
void OViewsWindow::addSection(const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry,USHORT _nPosition)
{
::boost::shared_ptr<OSectionWindow> pSectionWindow( new OSectionWindow(this,_xSection,_sColorEntry) );
m_aSections.insert(getIteratorAtPos(_nPosition) , TSectionsMap::value_type(pSectionWindow));
m_pParent->setMarked(&pSectionWindow->getReportSection().getSectionView(),m_aSections.size() == 1);
Resize();
}
//----------------------------------------------------------------------------
void OViewsWindow::removeSection(USHORT _nPosition)
{
if ( _nPosition < m_aSections.size() )
{
TSectionsMap::iterator aPos = getIteratorAtPos(_nPosition);
TSectionsMap::iterator aNew = getIteratorAtPos(_nPosition == 0 ? _nPosition+1: _nPosition - 1);
m_pParent->getReportView()->UpdatePropertyBrowserDelayed((*aNew)->getReportSection().getSectionView());
m_aSections.erase(aPos);
Resize();
} // if ( _nPosition < m_aSections.size() )
}
//------------------------------------------------------------------------------
void OViewsWindow::toggleGrid(BOOL _bVisible)
{
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OReportSection::SetGridVisible,_1,_bVisible),TReportPairHelper()));
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OReportSection::Window::Invalidate,_1,INVALIDATE_NOERASE),TReportPairHelper()));
}
//------------------------------------------------------------------------------
sal_Int32 OViewsWindow::getTotalHeight() const
{
sal_Int32 nHeight = 0;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
nHeight += (*aIter)->GetSizePixel().Height();
}
return nHeight;
}
//----------------------------------------------------------------------------
USHORT OViewsWindow::getSectionCount() const
{
return static_cast<USHORT>(m_aSections.size());
}
//----------------------------------------------------------------------------
void OViewsWindow::SetInsertObj( USHORT eObj,const ::rtl::OUString& _sShapeType )
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
(*aIter)->getReportSection().getSectionView().SetCurrentObj( eObj, ReportInventor );
m_sShapeType = _sShapeType;
}
//----------------------------------------------------------------------------
rtl::OUString OViewsWindow::GetInsertObjString() const
{
return m_sShapeType;
}
//------------------------------------------------------------------------------
void OViewsWindow::SetMode( DlgEdMode eNewMode )
{
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OReportSection::SetMode,_1,eNewMode),TReportPairHelper()));
}
//----------------------------------------------------------------------------
BOOL OViewsWindow::HasSelection()
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd && !(*aIter)->getReportSection().getSectionView().AreObjectsMarked(); ++aIter)
;
return aIter != aEnd;
}
//----------------------------------------------------------------------------
void OViewsWindow::Delete()
{
m_bInUnmark = sal_True;
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::mem_fn(&OReportSection::Delete),TReportPairHelper()));
m_bInUnmark = sal_False;
}
//----------------------------------------------------------------------------
void OViewsWindow::Copy()
{
uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OReportSection::Copy,_1,::boost::ref(aAllreadyCopiedObjects)),TReportPairHelper()));
//TSectionsMap::iterator aIter = m_aSections.begin();
//TSectionsMap::iterator aEnd = m_aSections.end();
//for (; aIter != aEnd; ++aIter)
// (*aIter)->getReportSection().Copy(aAllreadyCopiedObjects);
OReportExchange* pCopy = new OReportExchange(aAllreadyCopiedObjects);
uno::Reference< datatransfer::XTransferable> aEnsureDelete = pCopy;
pCopy->CopyToClipboard(this);
}
//----------------------------------------------------------------------------
void OViewsWindow::Paste()
{
TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(this));
OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aTransferData);
if ( aCopies.getLength() > 1 )
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OReportSection::Paste,_1,aCopies,false),TReportPairHelper()));
else
{
::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
if ( pMarkedSection )
pMarkedSection->getReportSection().Paste(aCopies,true);
}
}
// ---------------------------------------------------------------------------
::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const uno::Reference< report::XSection>& _xSection) const
{
OSL_ENSURE(_xSection.is(),"Section is NULL!");
::boost::shared_ptr<OSectionWindow> pSectionWindow;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
{
if ((*aIter)->getReportSection().getSection() == _xSection)
{
pSectionWindow = (*aIter);
break;
}
}
return pSectionWindow;
}
//----------------------------------------------------------------------------
::boost::shared_ptr<OSectionWindow> OViewsWindow::getMarkedSection(NearSectionAccess nsa) const
{
::boost::shared_ptr<OSectionWindow> pRet;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
sal_uInt32 nCurrentPosition = 0;
for (; aIter != aEnd ; ++aIter)
{
if ( (*aIter)->getStartMarker().isMarked() )
{
if (nsa == CURRENT)
{
pRet = (*aIter);
break;
}
else if ( nsa == PREVIOUS )
{
if (nCurrentPosition > 0)
{
pRet = (*(--aIter));
if (pRet == NULL)
{
pRet = (*m_aSections.begin());
}
}
else
{
// if we are out of bounds return the first one
pRet = (*m_aSections.begin());
}
break;
}
else if ( nsa == POST )
{
sal_uInt32 nSize = m_aSections.size();
if ((nCurrentPosition + 1) < nSize)
{
pRet = *(++aIter);
if (pRet == NULL)
{
pRet = (*(--aEnd));
}
}
else
{
// if we are out of bounds return the last one
pRet = (*(--aEnd));
}
break;
}
} // ( (*aIter).second->isMarked() )
++nCurrentPosition;
} // for (; aIter != aEnd ; ++aIter)
return pRet;
}
// -------------------------------------------------------------------------
void OViewsWindow::markSection(const sal_uInt16 _nPos)
{
if ( _nPos < m_aSections.size() )
m_pParent->setMarked(m_aSections[_nPos]->getReportSection().getSection(),sal_True);
}
//----------------------------------------------------------------------------
BOOL OViewsWindow::IsPasteAllowed()
{
TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(this));
return aTransferData.HasFormat(OReportExchange::getDescriptorFormatId());
}
//-----------------------------------------------------------------------------
void OViewsWindow::SelectAll(const sal_uInt16 _nObjectType)
{
m_bInUnmark = sal_True;
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(::boost::mem_fn(&OReportSection::SelectAll),_1,_nObjectType),TReportPairHelper()));
m_bInUnmark = sal_False;
}
//-----------------------------------------------------------------------------
void OViewsWindow::unmarkAllObjects(OSectionView* _pSectionView)
{
if ( !m_bInUnmark )
{
m_bInUnmark = sal_True;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
{
if ( &(*aIter)->getReportSection().getSectionView() != _pSectionView )
{
(*aIter)->getReportSection().deactivateOle();
(*aIter)->getReportSection().getSectionView().UnmarkAllObj();
}
} // for (; aIter != aEnd ; ++aIter)
m_bInUnmark = sal_False;
}
}
//-----------------------------------------------------------------------------
/*
::boost::shared_ptr<OSectionWindow> OViewsWindow::getReportSection(const uno::Reference< report::XSection >& _xSection)
{
OSL_ENSURE(_xSection.is(),"Section is NULL!");
::boost::shared_ptr<OSectionWindow> pRet;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
{
if ( (*aIter)->getReportSection().getSection() == _xSection )
{
pRet = (*aIter);
break;
} // if ( (*aIter)->getSection() == _xSection )
} // for (; aIter != aEnd ; ++aIter)
return pRet;
}
*/
// -----------------------------------------------------------------------
void OViewsWindow::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32)
{
ImplInitSettings();
Invalidate();
}
// -----------------------------------------------------------------------------
void OViewsWindow::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( rMEvt.IsLeft() )
{
GrabFocus();
const uno::Sequence< beans::PropertyValue> aArgs;
getView()->getReportView()->getController().executeChecked(SID_SELECT_REPORT,aArgs);
}
Window::MouseButtonDown(rMEvt);
}
//----------------------------------------------------------------------------
void OViewsWindow::showRuler(sal_Bool _bShow)
{
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OStartMarker::showRuler,_1,_bShow),TStartMarkerHelper()));
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::bind(&OStartMarker::Window::Invalidate,_1,USHORT(INVALIDATE_NOERASE)),TStartMarkerHelper()));
}
//----------------------------------------------------------------------------
void OViewsWindow::MouseButtonUp( const MouseEvent& rMEvt )
{
if ( rMEvt.IsLeft() )
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
if ( (*aIter)->getReportSection().getSectionView().AreObjectsMarked() )
{
(*aIter)->getReportSection().MouseButtonUp(rMEvt);
break;
}
}
// remove special insert mode
for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
{
(*aIter)->getReportSection().getPage()->resetSpecialMode();
}
}
}
//------------------------------------------------------------------------------
sal_Bool OViewsWindow::handleKeyEvent(const KeyEvent& _rEvent)
{
sal_Bool bRet = sal_False;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
//if ( (*aIter).getReportSection().getSectionView().->AreObjectsMarked() )
if ( (*aIter)->getStartMarker().isMarked() )
{
bRet = (*aIter)->getReportSection().handleKeyEvent(_rEvent);
}
}
return bRet;
}
//----------------------------------------------------------------------------
OViewsWindow::TSectionsMap::iterator OViewsWindow::getIteratorAtPos(USHORT _nPos)
{
TSectionsMap::iterator aRet = m_aSections.end();
if ( _nPos < m_aSections.size() )
aRet = m_aSections.begin() + _nPos;
return aRet;
}
//------------------------------------------------------------------------
void OViewsWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
{
OSL_ENSURE(_pSectionView != NULL,"SectionView is NULL!");
if ( _pSectionView )
setMarked(_pSectionView->getReportSection()->getSection(),_bMark);
}
//------------------------------------------------------------------------
void OViewsWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
{
if ( (*aIter)->getReportSection().getSection() != _xSection )
{
(*aIter)->setMarked(sal_False);
}
else if ( (*aIter)->getStartMarker().isMarked() != _bMark )
{
(*aIter)->setMarked(_bMark);
}
}
}
//------------------------------------------------------------------------
void OViewsWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _aShapes,sal_Bool _bMark)
{
bool bFirst = true;
const uno::Reference< report::XReportComponent>* pIter = _aShapes.getConstArray();
const uno::Reference< report::XReportComponent>* pEnd = pIter + _aShapes.getLength();
for(;pIter != pEnd;++pIter)
{
const uno::Reference< report::XSection> xSection = (*pIter)->getSection();
if ( xSection.is() )
{
if ( bFirst )
{
bFirst = false;
m_pParent->setMarked(xSection,_bMark);
}
::boost::shared_ptr<OSectionWindow> pSectionWindow = getSectionWindow(xSection);
if ( pSectionWindow )
{
SvxShape* pShape = SvxShape::getImplementation( *pIter );
SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
OSL_ENSURE( pObject, "OViewsWindow::setMarked: no SdrObject for the shape!" );
if ( pObject )
pSectionWindow->getReportSection().getSectionView().MarkObj( pObject, pSectionWindow->getReportSection().getSectionView().GetSdrPageView(), !_bMark );
}
}
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::collectRectangles(TRectangleMap& _rSortRectangles, bool _bBoundRects)
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
{
OSectionView& rView = (*aIter)->getReportSection().getSectionView();
if ( rView.AreObjectsMarked() )
{
rView.SortMarkedObjects();
const sal_uInt32 nCount = rView.GetMarkedObjectCount();
for (sal_uInt32 i=0; i < nCount; ++i)
{
const SdrMark* pM = rView.GetSdrMarkByIndex(i);
SdrObject* pObj = pM->GetMarkedSdrObj();
Rectangle aObjRect(_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
_rSortRectangles.insert(TRectangleMap::value_type(aObjRect,TRectangleMap::mapped_type(pObj,&rView)));
}
}
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::collectBoundResizeRect(const TRectangleMap& _rSortRectangles,sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects,Rectangle& _rBound,Rectangle& _rResize)
{
bool bOnlyOnce = false;
TRectangleMap::const_iterator aRectIter = _rSortRectangles.begin();
TRectangleMap::const_iterator aRectEnd = _rSortRectangles.end();
for (;aRectIter != aRectEnd ; ++aRectIter)
{
Rectangle aObjRect = aRectIter->first;
if ( _rResize.IsEmpty() )
_rResize = aObjRect;
switch(_nControlModification)
{
case ControlModification::WIDTH_SMALLEST:
if ( _rResize.getWidth() > aObjRect.getWidth() )
_rResize = aObjRect;
break;
case ControlModification::HEIGHT_SMALLEST:
if ( _rResize.getHeight() > aObjRect.getHeight() )
_rResize = aObjRect;
break;
case ControlModification::WIDTH_GREATEST:
if ( _rResize.getWidth() < aObjRect.getWidth() )
_rResize = aObjRect;
break;
case ControlModification::HEIGHT_GREATEST:
if ( _rResize.getHeight() < aObjRect.getHeight() )
_rResize = aObjRect;
break;
}
SdrObjTransformInfoRec aInfo;
const SdrObject* pObj = aRectIter->second.first;
pObj->TakeObjInfo(aInfo);
BOOL bHasFixed = !aInfo.bMoveAllowed || pObj->IsMoveProtect();
if ( bHasFixed )
_rBound.Union(aObjRect);
else
{
if ( _bAlignAtSection || _rSortRectangles.size() == 1 )
{ // einzelnes Obj an der Seite ausrichten
if ( ! bOnlyOnce )
{
bOnlyOnce = true;
OReportSection* pReportSection = aRectIter->second.second->getReportSection();
const uno::Reference< report::XSection> xSection = pReportSection->getSection();
try
{
uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
_rBound.Union(Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
xSection->getHeight()));
}
catch(uno::Exception){}
}
}
else
{
if (_bBoundRects)
_rBound.Union(aRectIter->second.second->GetMarkedObjBoundRect());
else
_rBound.Union(aRectIter->second.second->GetMarkedObjRect());
}
}
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects)
{
if ( _nControlModification == ControlModification::NONE )
return;
Point aRefPoint;
RectangleLess::CompareMode eCompareMode = RectangleLess::POS_LEFT;
switch (_nControlModification)
{
case ControlModification::TOP : eCompareMode = RectangleLess::POS_UPPER; break;
case ControlModification::BOTTOM: eCompareMode = RectangleLess::POS_DOWN; break;
case ControlModification::LEFT : eCompareMode = RectangleLess::POS_LEFT; break;
case ControlModification::RIGHT : eCompareMode = RectangleLess::POS_RIGHT; break;
case ControlModification::CENTER_HORIZONTAL :
case ControlModification::CENTER_VERTICAL :
{
eCompareMode = (ControlModification::CENTER_VERTICAL == _nControlModification) ? RectangleLess::POS_CENTER_VERTICAL : RectangleLess::POS_CENTER_HORIZONTAL;
uno::Reference<report::XSection> xSection = (*m_aSections.begin())->getReportSection().getSection();
uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
aRefPoint = Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
xSection->getHeight()).Center();
}
break;
default: break;
}
RectangleLess aCompare(eCompareMode,aRefPoint);
TRectangleMap aSortRectangles(aCompare);
collectRectangles(aSortRectangles,_bBoundRects);
Rectangle aBound;
Rectangle aResize;
collectBoundResizeRect(aSortRectangles,_nControlModification,_bAlignAtSection,_bBoundRects,aBound,aResize);
bool bMove = true;
::std::mem_fun_t<long&,Rectangle> aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
::std::mem_fun_t<long&,Rectangle> aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
TRectangleMap::iterator aRectIter = aSortRectangles.begin();
TRectangleMap::iterator aRectEnd = aSortRectangles.end();
for (;aRectIter != aRectEnd ; ++aRectIter)
{
Rectangle aObjRect = aRectIter->first;
SdrObject* pObj = aRectIter->second.first;
SdrView* pView = aRectIter->second.second;
Point aCenter(aBound.Center());
SdrObjTransformInfoRec aInfo;
pObj->TakeObjInfo(aInfo);
if (aInfo.bMoveAllowed && !pObj->IsMoveProtect())
{
long nXMov = 0;
long nYMov = 0;
long* pValue = &nXMov;
switch(_nControlModification)
{
case ControlModification::TOP :
aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
pValue = &nYMov;
break;
case ControlModification::BOTTOM:
// defaults are already set
pValue = &nYMov;
break;
case ControlModification::CENTER_VERTICAL:
nYMov = aCenter.Y() - aObjRect.Center().Y();
pValue = &nYMov;
bMove = false;
break;
case ControlModification::RIGHT :
aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
break;
case ControlModification::CENTER_HORIZONTAL:
nXMov = aCenter.X() - aObjRect.Center().X();
bMove = false;
break;
case ControlModification::LEFT :
aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
break;
default:
bMove = false;
break;
}
if ( bMove )
{
Rectangle aTest = aObjRect;
aGetFun(&aTest) = aGetFun(&aBound);
TRectangleMap::iterator aInterSectRectIter = aSortRectangles.begin();
for (; aInterSectRectIter != aRectIter; ++aInterSectRectIter)
{
if ( pView == aInterSectRectIter->second.second && dynamic_cast<OUnoObject*>(aInterSectRectIter->second.first) )
{
SdrObject* pPreviousObj = aInterSectRectIter->second.first;
Rectangle aIntersectRect = aTest.GetIntersection(_bBoundRects ? pPreviousObj->GetCurrentBoundRect() : pPreviousObj->GetSnapRect());
if ( !aIntersectRect.IsEmpty() && (aIntersectRect.Left() != aIntersectRect.Right() && aIntersectRect.Top() != aIntersectRect.Bottom() ) )
{
*pValue = aRefFun(&aIntersectRect) - aGetFun(&aObjRect);
break;
}
}
}
if ( aInterSectRectIter == aRectIter )
*pValue = aGetFun(&aBound) - aGetFun(&aObjRect);
}
if ( lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects) )
{
const Size aSize(nXMov,nYMov);
pView->AddUndo(pView->GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pObj,aSize));
pObj->Move(aSize);
aObjRect = (_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
}
// resizing control
if ( !aResize.IsEmpty() && aObjRect != aResize )
{
nXMov = aResize.getWidth();
nYMov = aResize.getHeight();
switch(_nControlModification)
{
case ControlModification::WIDTH_GREATEST:
case ControlModification::HEIGHT_GREATEST:
if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
nXMov = aObjRect.getWidth();
else if ( _nControlModification == ControlModification::WIDTH_GREATEST )
nYMov = aObjRect.getHeight();
lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects);
// run through
case ControlModification::WIDTH_SMALLEST:
case ControlModification::HEIGHT_SMALLEST:
pView->AddUndo( pView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
{
OObjectBase* pObjBase = dynamic_cast<OObjectBase*>(pObj);
OSL_ENSURE(pObjBase,"Where comes this object from?");
if ( pObjBase )
{
if ( _nControlModification == ControlModification::WIDTH_SMALLEST || _nControlModification == ControlModification::WIDTH_GREATEST )
pObjBase->getReportComponent()->setSize(awt::Size(nXMov,aObjRect.getHeight()));
//pObj->Resize(aObjRect.TopLeft(),Fraction(nXMov,aObjRect.getWidth()),Fraction(1,1));
else if ( _nControlModification == ControlModification::HEIGHT_GREATEST || _nControlModification == ControlModification::HEIGHT_SMALLEST )
pObjBase->getReportComponent()->setSize(awt::Size(aObjRect.getWidth(),nYMov));
//pObj->Resize(aObjRect.TopLeft(),Fraction(1,1),Fraction(nYMov,aObjRect.getHeight()));
}
}
break;
default:
break;
}
}
}
pView->AdjustMarkHdl();
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::createDefault()
{
::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
if ( pMarkedSection )
pMarkedSection->getReportSection().createDefault(m_sShapeType);
}
// -----------------------------------------------------------------------------
void OViewsWindow::setGridSnap(BOOL bOn)
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
{
(*aIter)->getReportSection().getSectionView().SetGridSnap(bOn);
(*aIter)->getReportSection().Invalidate();
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::setDragStripes(BOOL bOn)
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter)
(*aIter)->getReportSection().getSectionView().SetDragStripes(bOn);
}
// -----------------------------------------------------------------------------
USHORT OViewsWindow::getPosition(const OSectionWindow* _pSectionWindow) const
{
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
USHORT nPosition = 0;
for (; aIter != aEnd ; ++aIter)
{
if ( _pSectionWindow == (*aIter).get() )
{
break;
}
++nPosition;
}
return nPosition;
}
// -----------------------------------------------------------------------------
::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const USHORT _nPos) const
{
::boost::shared_ptr<OSectionWindow> aReturn;
if ( _nPos < m_aSections.size() )
aReturn = m_aSections[_nPos];
return aReturn;
}
// -----------------------------------------------------------------------------
namespace
{
enum SectionViewAction
{
eEndDragObj,
eEndAction,
eMoveAction,
eMarkAction,
eForceToAnotherPage,
eBreakAction
};
class ApplySectionViewAction : public ::std::unary_function< OViewsWindow::TSectionsMap::value_type, void >
{
private:
SectionViewAction m_eAction;
sal_Bool m_bCopy;
Point m_aPoint;
public:
ApplySectionViewAction( sal_Bool _bCopy ) : m_eAction( eEndDragObj ), m_bCopy( _bCopy ) { }
ApplySectionViewAction(SectionViewAction _eAction = eEndAction ) : m_eAction( _eAction ) { }
ApplySectionViewAction( const Point& _rPoint, SectionViewAction _eAction = eMoveAction ) : m_eAction( _eAction ), m_bCopy( sal_False ), m_aPoint( _rPoint ) { }
void operator() ( const OViewsWindow::TSectionsMap::value_type& _rhs )
{
OSectionView& rView( _rhs->getReportSection().getSectionView() );
switch ( m_eAction )
{
case eEndDragObj:
rView.EndDragObj( m_bCopy );
break;
case eEndAction:
if ( rView.IsAction() )
rView.EndAction ( );
break;
case eMoveAction:
rView.MovAction ( m_aPoint );
break;
case eMarkAction:
rView.BegMarkObj ( m_aPoint );
break;
case eForceToAnotherPage:
rView.ForceMarkedToAnotherPage();
break;
case eBreakAction:
if ( rView.IsAction() )
rView.BrkAction ( );
break;
// default:
}
}
};
}
// -----------------------------------------------------------------------------
void OViewsWindow::BrkAction()
{
EndDragObj_removeInvisibleObjects();
::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eBreakAction) );
}
// -----------------------------------------------------------------------------
void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const Rectangle& _aRect, const OSectionView& _rSection)
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
Point aNewPos(0,0);
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
rReportSection.getPage()->setSpecialMode();
OSectionView& rView = rReportSection.getSectionView();
if ( &rView != &_rSection )
{
// SdrRectObj *pNewObj = new SdrRectObj(OBJ_RECT, _aRect);
// SdrObject *pNewObj = new SdrUnoObj(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Temp Label")));
SdrObject *pNewObj = new SdrUnoObj(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText")));
if (pNewObj)
{
pNewObj->SetLogicRect(_aRect);
// pNewObj->SetSize(_aRect.GetSize());
// pNewObj->Move(Size(_aRect.Left(), _aRect.Top()));
pNewObj->Move(Size(0, aNewPos.Y()));
BOOL bChanged = rView.GetModel()->IsChanged();
rReportSection.getPage()->InsertObject(pNewObj);
rView.GetModel()->SetChanged(bChanged);
m_aBegDragTempList.push_back(pNewObj);
Rectangle aRect = pNewObj->GetLogicRect();
// pNewObj->SetText(String::CreateFromAscii("Drag helper"));
rView.MarkObj( pNewObj, rView.GetSdrPageView() );
}
}
const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aNewPos.Y() -= nSectionHeight;
// aNewPos.Y() -= PixelToLogic(aIter->second.second->GetSizePixel()).Height();
}
}
// -----------------------------------------------------------------------------
bool OViewsWindow::isObjectInMyTempList(SdrObject *_pObj)
{
return ::std::find(m_aBegDragTempList.begin(),m_aBegDragTempList.end(),_pObj) != m_aBegDragTempList.end();
}
// -----------------------------------------------------------------------------
void OViewsWindow::BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection)
{
OSL_TRACE("BegDragObj Clickpoint X:%d Y:%d\n", _aPnt.X(), _aPnt.Y() );
m_aBegDragTempList.clear();
// Calculate the absolute clickpoint in the views
Point aAbsolutePnt = _aPnt;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
OSectionView* pView = &rReportSection.getSectionView();
if (pView == _pSection)
break;
const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aAbsolutePnt.Y() += nSectionHeight;
}
m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
OSL_TRACE("BegDragObj Absolute X:%d Y:%d\n", aAbsolutePnt.X(), aAbsolutePnt.Y() );
// Create drag lines over all viewable Views
// Therefore we need to identify the marked objects
// and create temporary objects on all other views at the same position
// relative to its occurance.
OSL_TRACE("BegDragObj createInvisible Objects\n" );
int nViewCount = 0;
Point aNewObjPos(0,0);
Point aLeftTop = Point(SAL_MAX_INT32, SAL_MAX_INT32);
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
OSectionView& rView = rReportSection.getSectionView();
if ( rView.AreObjectsMarked() )
{
const sal_uInt32 nCount = rView.GetMarkedObjectCount();
for (sal_uInt32 i=0; i < nCount; ++i)
{
const SdrMark* pM = rView.GetSdrMarkByIndex(i);
SdrObject* pObj = pM->GetMarkedSdrObj();
if (!isObjectInMyTempList(pObj))
{
Rectangle aRect( pObj->GetCurrentBoundRect() );
aRect.Move(0, aNewObjPos.Y());
aLeftTop.X() = ::std::min( aRect.Left(), aLeftTop.X() );
aLeftTop.Y() = ::std::min( aRect.Top(), aLeftTop.Y() );
OSL_TRACE("BegDragObj createInvisible X:%d Y:%d on View #%d\n", aRect.Left(), aRect.Top(), nViewCount );
BegDragObj_createInvisibleObjectAtPosition(aRect, rView);
// calculate the clickpoint
// const sal_Int32 nDeltaX = abs(aRect.Left() - aAbsolutePnt.X());
// const sal_Int32 nDeltaY = abs(aRect.Top() - aAbsolutePnt.Y());
// if (m_aDragDelta.X() > nDeltaX)
// m_aDragDelta.X() = nDeltaX;
// if (m_aDragDelta.Y() > nDeltaY)
// m_aDragDelta.Y() = nDeltaY;
}
}
}
++nViewCount;
Rectangle aClipRect = rView.GetWorkArea();
aClipRect.Top() = -aNewObjPos.Y();
rView.SetWorkArea( aClipRect );
const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aNewObjPos.Y() += nSectionHeight;
// don't subtract the height of the lines between the views
// aNewObjPos.Y() -= PixelToLogic(aIter->second.second->GetSizePixel()).Height();
}
const sal_Int32 nDeltaX = abs(aLeftTop.X() - aAbsolutePnt.X());
const sal_Int32 nDeltaY = abs(aLeftTop.Y() - aAbsolutePnt.Y());
m_aDragDelta.X() = nDeltaX;
m_aDragDelta.Y() = nDeltaY;
Point aNewPos = aAbsolutePnt;
// for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
// {
// OReportSection& rReportSection = (*aIter)->getReportSection();
// if ( &rReportSection.getSectionView() == _pSection )
// break;
// aNewPos.Y() += rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
// }
const short nDrgLog = static_cast<short>(PixelToLogic(Size(3,0)).Width());
// long nLastSectionHeight = 0;
// bool bAdd = true;
nViewCount = 0;
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
// if ( &rReportSection.getSectionView() == _pSection )
// {
// bAdd = false;
// aNewPos = _aPnt;
// }
// else if ( bAdd )
// {
// const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
// aNewPos.Y() += nSectionHeight;
// }
// else
// {
// aNewPos.Y() -= nLastSectionHeight;
// }
//?
SdrHdl* pHdl = _pHdl;
if ( pHdl )
{
if ( &rReportSection.getSectionView() != _pSection )
{
const SdrHdlList& rHdlList = rReportSection.getSectionView().GetHdlList();
pHdl = rHdlList.GetHdl(_pHdl->GetKind());
}
}
OSL_TRACE("BegDragObj X:%d Y:%d on View#%d\n", aNewPos.X(), aNewPos.Y(), nViewCount++ );
rReportSection.getSectionView().BegDragObj(aNewPos, (OutputDevice*)NULL, pHdl, nDrgLog, NULL);
const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aNewPos.Y() -= nSectionHeight;
// subtract the height between the views, because they are visible but not from interest here.
// aNewPos.Y() -= PixelToLogic(aIter->second.second->GetSizePixel()).Height();
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::ForceMarkedToAnotherPage()
{
::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eForceToAnotherPage ) );
}
// -----------------------------------------------------------------------------
void OViewsWindow::BegMarkObj(const Point& _aPnt,const OSectionView* _pSection)
{
bool bAdd = true;
Point aNewPos = _aPnt;
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
long nLastSectionHeight = 0;
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
if ( &rReportSection.getSectionView() == _pSection )
{
bAdd = false;
aNewPos = _aPnt; // 2,2
}
else if ( bAdd )
{
const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aNewPos.Y() += nSectionHeight;
}
else
{
aNewPos.Y() -= nLastSectionHeight;
}
rReportSection.getSectionView().BegMarkObj ( aNewPos );
nLastSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
// aNewPos.Y() -= PixelToLogic(aIter->second.second->GetSizePixel()).Height();
}
//::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction( _aPnt , eMarkAction) );
}
// -----------------------------------------------------------------------------
OSectionView* OViewsWindow::getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt)
{
OSectionView* pSection = NULL;
sal_Int32 nCount = 0;
TSectionsMap::iterator aIter = m_aSections.begin();
const TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd ; ++aIter,++nCount)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
if ( &rReportSection.getSectionView() == _pSection)
break;
}
OSL_ENSURE(aIter != aEnd,"This can never happen!");
if ( _rPnt.Y() < 0 )
{
if ( nCount )
--aIter;
for (; nCount && (_rPnt.Y() < 0); --nCount)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
const sal_Int32 nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
_rPnt.Y() += nHeight;
if ( (nCount -1) > 0 && (_rPnt.Y() < 0) )
--aIter;
}
if ( nCount == 0 )
pSection = &(*m_aSections.begin())->getReportSection().getSectionView();
else
pSection = &(*aIter)->getReportSection().getSectionView();
}
else
{
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
const long nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
if ( (_rPnt.Y() - nHeight) < 0 )
break;
_rPnt.Y() -= nHeight;
}
if ( aIter != aEnd )
pSection = &(*aIter)->getReportSection().getSectionView();
else
pSection = &(*(aEnd-1))->getReportSection().getSectionView();
}
return pSection;
}
// -----------------------------------------------------------------------------
void OViewsWindow::EndDragObj_removeInvisibleObjects()
{
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
rReportSection.getPage()->resetSpecialMode();
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::EndDragObj(BOOL _bControlKeyPressed, const OSectionView* _pSection,const Point& _aPnt)
{
const String sUndoAction = String((ModuleRes(RID_STR_UNDO_CHANGEPOSITION)));
UndoManagerListAction aListAction(*getView()->getReportView()->getController().getUndoMgr(),sUndoAction);
Point aNewPos = _aPnt;
OSectionView* pInSection = getSectionRelativeToPosition(_pSection, aNewPos);
if (!_bControlKeyPressed &&
(_pSection && ( _pSection->IsDragResize() == false ) ) && /* Not in resize mode */
_pSection != pInSection)
{
EndDragObj_removeInvisibleObjects();
// we need to manipulate the current clickpoint, we substract the old delta from BeginDrag
// OSectionView* pInSection = getSectionRelativeToPosition(_pSection, aPnt);
// aNewPos.X() -= m_aDragDelta.X();
// aNewPos.Y() -= m_aDragDelta.Y();
aNewPos -= m_aDragDelta;
uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
TSectionsMap::iterator aIter = m_aSections.begin();
const TSectionsMap::iterator aEnd = m_aSections.end();
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
if ( pInSection != &rReportSection.getSectionView() )
{
rReportSection.getSectionView().BrkAction();
rReportSection.Copy(aAllreadyCopiedObjects,true);
}
else
pInSection->EndDragObj(FALSE);
} // for (; aIter != aEnd; ++aIter)
if ( aAllreadyCopiedObjects.getLength() )
{
beans::NamedValue* pIter = aAllreadyCopiedObjects.getArray();
const beans::NamedValue* pEnd = pIter + aAllreadyCopiedObjects.getLength();
try
{
uno::Reference<report::XReportDefinition> xReportDefinition = getView()->getReportView()->getController().getReportDefinition();
const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
if ( aNewPos.X() < nLeftMargin )
aNewPos.X() = nLeftMargin;
if ( aNewPos.Y() < 0 )
aNewPos.Y() = 0;
Point aPrevious;
for (; pIter != pEnd; ++pIter)
{
uno::Sequence< uno::Reference<report::XReportComponent> > aClones;
pIter->Value >>= aClones;
uno::Reference<report::XReportComponent>* pColIter = aClones.getArray();
const uno::Reference<report::XReportComponent>* pColEnd = pColIter + aClones.getLength();
// move the cloned Components to new positions
for (; pColIter != pColEnd; ++pColIter)
{
uno::Reference< report::XReportComponent> xRC(*pColIter);
aPrevious = VCLPoint(xRC->getPosition());
awt::Size aSize = xRC->getSize();
if ( aNewPos.X() < nLeftMargin )
{
aNewPos.X() = nLeftMargin;
}
else if ( (aNewPos.X() + aSize.Width) > (nPaperWidth - nRightMargin) )
{
aNewPos.X() = nPaperWidth - nRightMargin - aSize.Width;
}
if ( aNewPos.Y() < 0 )
{
aNewPos.Y() = 0;
}
if ( aNewPos.X() < 0 )
{
aSize.Width += aNewPos.X();
aNewPos.X()= 0;
xRC->setSize(aSize);
}
xRC->setPosition(AWTPoint(aNewPos));
if ( (pColIter+1) != pColEnd )
{
// bring aNewPos to the position of the next object
uno::Reference< report::XReportComponent> xRCNext(*(pColIter + 1),uno::UNO_QUERY);
Point aNextPosition = VCLPoint(xRCNext->getPosition());
aNewPos += (aNextPosition - aPrevious);
}
}
}
}
catch(uno::Exception&)
{
}
pInSection->getReportSection()->Paste(aAllreadyCopiedObjects,true);
}
}
else
{
::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction( FALSE ) );
EndDragObj_removeInvisibleObjects();
}
m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
}
// -----------------------------------------------------------------------------
void OViewsWindow::EndAction()
{
::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction() );
}
// -----------------------------------------------------------------------------
void OViewsWindow::MovAction(const Point& _aPnt,const OSectionView* _pSection,bool _bMove, bool _bControlKeySet)
{
(void)_bMove;
Point aRealMousePos = _aPnt;
Point aCurrentSectionPos;
OSL_TRACE("MovAction X:%d Y:%d\n", aRealMousePos.X(), aRealMousePos.Y() );
Point aHdlPos;
SdrHdl* pHdl = _pSection->GetDragHdl();
if ( pHdl )
{
aHdlPos = pHdl->GetPos();
}
TSectionsMap::iterator aIter/* = m_aSections.begin() */;
TSectionsMap::iterator aEnd = m_aSections.end();
//if ( _bMove )
//{
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
if ( &rReportSection.getSectionView() == _pSection )
break;
const long nSectionHeight = (*aIter)->PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
aCurrentSectionPos.Y() += nSectionHeight;
} // for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
//}
aRealMousePos += aCurrentSectionPos;
// If control key is pressed the work area is limited to the section with the current selection.
Point aPosForWorkArea(0,0);
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
OSectionView& rView = rReportSection.getSectionView();
const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
if (_bControlKeySet)
{
Rectangle aClipRect = rView.GetWorkArea();
aClipRect.Top() = aCurrentSectionPos.Y() - aPosForWorkArea.Y();
// if (aClipRect.Top() < 0) aClipRect.Top() = 0;
aClipRect.Bottom() = aClipRect.Top() + nSectionHeight;
rView.SetWorkArea( aClipRect );
}
else
{
Rectangle aClipRect = rView.GetWorkArea();
aClipRect.Top() = -aPosForWorkArea.Y();
rView.SetWorkArea( aClipRect );
}
aPosForWorkArea.Y() += nSectionHeight;
// aNewPos.Y() += PixelToLogic(aIter->second.second->GetSizePixel()).Height();
}
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
SdrHdl* pCurrentHdl = rReportSection.getSectionView().GetDragHdl();
if ( pCurrentHdl )
{
if ( aRealMousePos.Y() > 0 )
aRealMousePos = _aPnt + pCurrentHdl->GetPos() - aHdlPos;
}
rReportSection.getSectionView().MovAction ( aRealMousePos );
const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
aRealMousePos.Y() -= nSectionHeight;
}
#if 0
#if OSL_DEBUG_LEVEL > 0
// TEST TEST TEST TEST
// Ich versuche gerade rauszubekommen, ob ich ein Object bewege oder nur resize.
// TEST TEST TEST TEST
for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
OSectionView& rView = rReportSection.getSectionView();
if ( rView.AreObjectsMarked() )
{
rView.SortMarkedObjects();
const sal_uInt32 nCount = rView.GetMarkedObjectCount();
for (sal_uInt32 i=0; i < nCount; ++i)
{
const SdrMark* pM = rView.GetSdrMarkByIndex(i);
SdrObject* pObj = pM->GetMarkedSdrObj();
(void)pObj;
int dummy = 0;
(void)dummy;
}
}
/*
OReportSection& rReportSection = (*aIter)->getReportSection();
OSectionView& rView = rReportSection.getSectionView();
const SdrHdlList& rHdlList = rView.GetHdlList();
SdrHdl* pHdl2 = rHdlList.GetFocusHdl();
if ( pHdl2 != 0 )
{
SdrHdlKind eKind = pHdl->GetKind();
int dummy = 0;
switch(eKind)
{
case HDL_UPLFT: // Oben links
case HDL_UPPER: // Oben
case HDL_UPRGT: // Oben rechts
case HDL_LEFT: // Links
case HDL_RIGHT: // Rechts
case HDL_LWLFT: // Unten links
case HDL_LOWER: // Unten
case HDL_LWRGT: // Unten rechts
dummy = 1;
break;
default:
dummy = 0;
}
}
*/
}
// TEST TEST TEST TEST
#endif
#endif
}
// -----------------------------------------------------------------------------
BOOL OViewsWindow::IsAction() const
{
BOOL bAction = FALSE;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (; !bAction && aIter != aEnd; ++aIter)
bAction = (*aIter)->getReportSection().getSectionView().IsAction();
return bAction;
}
// -----------------------------------------------------------------------------
BOOL OViewsWindow::IsDragObj() const
{
BOOL bAction = FALSE;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (; !bAction && aIter != aEnd; ++aIter)
bAction = (*aIter)->getReportSection().getSectionView().IsAction();
return bAction;
}
// -----------------------------------------------------------------------------
sal_uInt32 OViewsWindow::getMarkedObjectCount() const
{
sal_uInt32 nCount = 0;
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (; aIter != aEnd; ++aIter)
nCount += (*aIter)->getReportSection().getSectionView().GetMarkedObjectCount();
return nCount;
}
// -----------------------------------------------------------------------------
void OViewsWindow::handleKey(const KeyCode& _rCode)
{
const USHORT nCode = _rCode.GetCode();
if ( _rCode.IsMod1() )
{
// scroll page
OScrollWindowHelper* pScrollWindow = getView()->getScrollWindow();
ScrollBar* pScrollBar = ( nCode == KEY_LEFT || nCode == KEY_RIGHT ) ? pScrollWindow->GetHScroll() : pScrollWindow->GetVScroll();
if ( pScrollBar && pScrollBar->IsVisible() )
pScrollBar->DoScrollAction(( nCode == KEY_RIGHT || nCode == KEY_UP ) ? SCROLL_LINEUP : SCROLL_LINEDOWN );
return;
}
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (; aIter != aEnd; ++aIter)
{
OReportSection& rReportSection = (*aIter)->getReportSection();
long nX = 0;
long nY = 0;
if ( nCode == KEY_UP )
nY = -1;
else if ( nCode == KEY_DOWN )
nY = 1;
else if ( nCode == KEY_LEFT )
nX = -1;
else if ( nCode == KEY_RIGHT )
nX = 1;
if ( rReportSection.getSectionView().AreObjectsMarked() )
{
if ( _rCode.IsMod2() )
{
// move in 1 pixel distance
const Size aPixelSize = rReportSection.PixelToLogic( Size( 1, 1 ) );
nX *= aPixelSize.Width();
nY *= aPixelSize.Height();
}
else
{
// move in 1 mm distance
nX *= DEFAUL_MOVE_SIZE;
nY *= DEFAUL_MOVE_SIZE;
}
OSectionView& rView = rReportSection.getSectionView();
const SdrHdlList& rHdlList = rView.GetHdlList();
SdrHdl* pHdl = rHdlList.GetFocusHdl();
if ( pHdl == 0 )
{
// no handle selected
if ( rView.IsMoveAllowed() )
{
// restrict movement to work area
Rectangle rWorkArea = rView.GetWorkArea();
if ( !rWorkArea.IsEmpty() )
{
if ( rWorkArea.Top() < 0 )
rWorkArea.Top() = 0;
Rectangle aMarkRect( rView.GetMarkedObjRect() );
aMarkRect.Move( nX, nY );
if ( !rWorkArea.IsInside( aMarkRect ) )
{
if ( aMarkRect.Left() < rWorkArea.Left() )
nX += rWorkArea.Left() - aMarkRect.Left();
if ( aMarkRect.Right() > rWorkArea.Right() )
nX -= aMarkRect.Right() - rWorkArea.Right();
if ( aMarkRect.Top() < rWorkArea.Top() )
nY += rWorkArea.Top() - aMarkRect.Top();
if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
}
bool bCheck = false;
const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
{
SdrMark* pMark = rMarkList.GetMark(i);
bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL;
}
if ( bCheck && isOver(aMarkRect,*rReportSection.getPage(),rView) )
break;
}
if ( nX != 0 || nY != 0 )
{
rView.MoveAllMarked( Size( nX, nY ) );
rView.MakeVisible( rView.GetAllMarkedRect(), rReportSection);
}
}
}
else
{
// move the handle
if ( pHdl && ( nX || nY ) )
{
const Point aStartPoint( pHdl->GetPos() );
const Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
const SdrDragStat& rDragStat = rView.GetDragStat();
// start dragging
rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
if ( rView.IsDragObj() )
{
const FASTBOOL bWasNoSnap = rDragStat.IsNoSnap();
const BOOL bWasSnapEnabled = rView.IsSnapEnabled();
// switch snapping off
if ( !bWasNoSnap )
((SdrDragStat&)rDragStat).SetNoSnap( TRUE );
if ( bWasSnapEnabled )
rView.SetSnapEnabled( FALSE );
Rectangle aNewRect;
bool bCheck = false;
const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
{
SdrMark* pMark = rMarkList.GetMark(i);
bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL;
if ( bCheck )
aNewRect.Union(pMark->GetMarkedSdrObj()->GetLastBoundRect());
}
switch(pHdl->GetKind())
{
case HDL_LEFT:
case HDL_UPLFT:
case HDL_LWLFT:
case HDL_UPPER:
aNewRect.Left() += nX;
aNewRect.Top() += nY;
break;
case HDL_UPRGT:
case HDL_RIGHT:
case HDL_LWRGT:
case HDL_LOWER:
aNewRect.setWidth(aNewRect.getWidth() + nX);
aNewRect.setHeight(aNewRect.getHeight() + nY);
break;
default:
break;
}
if ( !(bCheck && isOver(aNewRect,*rReportSection.getPage(),rView)) )
rView.MovAction(aEndPoint);
rView.EndDragObj();
// restore snap
if ( !bWasNoSnap )
((SdrDragStat&)rDragStat).SetNoSnap( bWasNoSnap );
if ( bWasSnapEnabled )
rView.SetSnapEnabled( bWasSnapEnabled );
}
// make moved handle visible
const Rectangle aVisRect( aEndPoint - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
rView.MakeVisible( aVisRect, rReportSection);
}
}
rView.AdjustMarkHdl();
}
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::stopScrollTimer()
{
::std::for_each(m_aSections.begin(),m_aSections.end(),
::std::compose1(::boost::mem_fn(&OReportSection::stopScrollTimer),TReportPairHelper()));
}
// -----------------------------------------------------------------------------
void OViewsWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
{
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for (sal_uInt16 i = 0;aIter != aEnd ; ++aIter,++i)
{
if ( (*aIter)->getStartMarker().isCollapsed() )
_rCollapsedPositions.push_back(i);
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::collapseSections(const uno::Sequence< beans::PropertyValue>& _aCollpasedSections)
{
const beans::PropertyValue* pIter = _aCollpasedSections.getConstArray();
const beans::PropertyValue* pEnd = pIter + _aCollpasedSections.getLength();
for (; pIter != pEnd; ++pIter)
{
sal_uInt16 nPos = sal_uInt16(-1);
if ( (pIter->Value >>= nPos) && nPos < m_aSections.size() )
{
m_aSections[nPos]->setCollapsed(sal_True);
}
}
}
// -----------------------------------------------------------------------------
void OViewsWindow::zoom(const Fraction& _aZoom)
{
const MapMode& aMapMode = GetMapMode();
Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
if ( _aZoom < aMapMode.GetScaleX() )
aStartWidth *= aMapMode.GetScaleX();
else
aStartWidth *= _aZoom;
setZoomFactor(_aZoom,*this);
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
(*aIter)->zoom(_aZoom);
} // for (;aIter != aEnd ; ++aIter)
Resize();
Size aOut = GetOutputSizePixel();
aOut.Width() = aStartWidth;
aOut = PixelToLogic(aOut);
Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
Invalidate(aRect,/*INVALIDATE_NOERASE | */INVALIDATE_NOCHILDREN /*| INVALIDATE_TRANSPARENT*/);
}
//----------------------------------------------------------------------------
void OViewsWindow::scrollChildren(const Point& _aThumbPos)
{
const Point aPos(PixelToLogic(_aThumbPos));
{
MapMode aMapMode = GetMapMode();
const Point aOld = aMapMode.GetOrigin();
aMapMode.SetOrigin(m_pParent->GetMapMode().GetOrigin());
const Point aPosY(m_pParent->PixelToLogic(_aThumbPos,aMapMode));
aMapMode.SetOrigin( Point(aOld.X() , - aPosY.Y()));
SetMapMode( aMapMode );
//OWindowPositionCorrector aCorrector(this,0,-( aOld.Y() + aPosY.Y()));
Scroll(0, -( aOld.Y() + aPosY.Y()),SCROLL_CHILDREN);
Resize();
Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_TRANSPARENT);
}
TSectionsMap::iterator aIter = m_aSections.begin();
TSectionsMap::iterator aEnd = m_aSections.end();
for (;aIter != aEnd ; ++aIter)
{
(*aIter)->scrollChildren(aPos.X());
} // for (;aIter != aEnd ; ++aIter)
}
// -----------------------------------------------------------------------------
void OViewsWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
{
TSectionsMap::const_iterator aIter = m_aSections.begin();
TSectionsMap::const_iterator aEnd = m_aSections.end();
for(;aIter != aEnd; ++aIter)
{
(*aIter)->getReportSection().fillControlModelSelection(_rSelection);
}
}
//==============================================================================
} // rptui
//==============================================================================
|