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
|
/*************************************************************************
*
* $RCSfile: dialogcontrol.cxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2003-03-27 17:03:19 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library 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 for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef TOOLKIT_DIALOG_CONTROL_HXX
#include <toolkit/controls/dialogcontrol.hxx>
#endif
#ifndef _TOOLKIT_HELPER_PROPERTY_HXX_
#include <toolkit/helper/property.hxx>
#endif
#ifndef _TOOLKIT_HELPER_UNOPROPERTYARRAYHELPER_HXX_
#include <toolkit/helper/unopropertyarrayhelper.hxx>
#endif
#ifndef _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_
#include <toolkit/controls/geometrycontrolmodel.hxx>
#endif
#ifndef _TOOLKIT_HELPER_UNOCONTROLS_HXX_
#include <toolkit/controls/unocontrols.hxx>
#endif
#include "toolkit/controls/formattedcontrol.hxx"
#ifndef _TOOLKIT_CONTROLS_STDTABCONTROLLER_HXX_
#include <toolkit/controls/stdtabcontroller.hxx>
#endif
#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
#include <com/sun/star/awt/PosSize.hpp>
#endif
#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif
#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
#include <cppuhelper/typeprovider.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_OUTDEV_HXX
#include <vcl/outdev.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#include <map>
#include <algorithm>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace toolkit;
// ----------------------------------------------------------------------------
// functor for disposing a control model
struct DisposeControlModel : public ::std::unary_function< Reference< XControlModel >, void >
{
void operator()( Reference< XControlModel >& _rxModel )
{
try
{
::comphelper::disposeComponent( _rxModel );
}
catch( const Exception& )
{
DBG_ERROR( "DisposeControlModel::(): caught an exception while disposing a component!" );
}
}
};
// ----------------------------------------------------------------------------
// functor for searching control model by name
struct FindControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, bool >
{
private:
const ::rtl::OUString& m_rName;
public:
FindControlModel( const ::rtl::OUString& _rName ) : m_rName( _rName ) { }
bool operator()( const UnoControlDialogModel::UnoControlModelHolder& _rCompare )
{
return ( _rCompare.second == m_rName ) ? true : false;
}
};
// ----------------------------------------------------------------------------
// functor for cloning a control model, and insertion into a target list
struct CloneControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, void >
{
private:
UnoControlDialogModel::UnoControlModelHolderList& m_rTargetList;
public:
CloneControlModel( UnoControlDialogModel::UnoControlModelHolderList& _rTargetList )
:m_rTargetList( _rTargetList )
{
}
void operator()( const UnoControlDialogModel::UnoControlModelHolder& _rSource )
{
// clone the source object
Reference< XCloneable > xCloneSource( _rSource.first, UNO_QUERY );
Reference< XControlModel > xClone( xCloneSource->createClone(), UNO_QUERY );
// add to target list
m_rTargetList.push_back( UnoControlDialogModel::UnoControlModelHolder( xClone, _rSource.second ) );
}
};
// ----------------------------------------------------------------------------
// functor for comparing a XControlModel with a given reference
struct CompareControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, bool >
{
private:
Reference< XControlModel > m_xReference;
public:
CompareControlModel( const Reference< XControlModel >& _rxReference ) : m_xReference( _rxReference ) { }
bool operator()( const UnoControlDialogModel::UnoControlModelHolder& _rCompare )
{
return ( _rCompare.first.get() == m_xReference.get() ) ? true : false;
}
};
// ----------------------------------------------------------------------------
static void lcl_throwIllegalArgumentException( )
{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this ....
throw IllegalArgumentException();
}
// ----------------------------------------------------------------------------
static void lcl_throwNoSuchElementException( )
{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this ....
throw NoSuchElementException();
}
// ----------------------------------------------------------------------------
static const ::rtl::OUString& getTabIndexPropertyName( )
{
static const ::rtl::OUString s_sTabIndexProperty( RTL_CONSTASCII_USTRINGPARAM( "TabIndex" ) );
return s_sTabIndexProperty;
}
// ----------------------------------------------------------------------------
static const ::rtl::OUString& getStepPropertyName( )
{
static const ::rtl::OUString s_sStepProperty( RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
return s_sStepProperty;
}
// ----------------------------------------------------
// class UnoControlDialogModel
// ----------------------------------------------------
UnoControlDialogModel::UnoControlDialogModel()
:maContainerListeners( *this )
,maChangeListeners ( GetMutex() )
,mbGroupsUpToDate( sal_False )
{
ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
// ImplRegisterProperty( BASEPROPERTY_BORDER );
ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
ImplRegisterProperty( BASEPROPERTY_ENABLED );
ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
// ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
ImplRegisterProperty( BASEPROPERTY_HELPURL );
ImplRegisterProperty( BASEPROPERTY_TITLE );
ImplRegisterProperty( BASEPROPERTY_SIZEABLE );
Any aBool;
aBool <<= (sal_Bool) sal_True;
ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
}
UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rModel )
:UnoControlModel( rModel )
,maContainerListeners( *this )
,maChangeListeners ( GetMutex() )
,mbGroupsUpToDate( sal_False )
{
}
UnoControlDialogModel::~UnoControlDialogModel()
{
maModels.clear();
mbGroupsUpToDate = sal_False;
}
Any UnoControlDialogModel::queryAggregation( const Type & rType ) throw(RuntimeException)
{
Any aRet( UnoControlDialogModel_IBase::queryInterface( rType ) );
return (aRet.hasValue() ? aRet : UnoControlDialogModel_Base::queryAggregation( rType ));
}
// XTypeProvider
IMPL_IMPLEMENTATION_ID( UnoControlDialogModel )
Sequence< Type > UnoControlDialogModel::getTypes() throw(RuntimeException)
{
return ::comphelper::concatSequences(
UnoControlDialogModel_IBase::getTypes(),
UnoControlDialogModel_Base::getTypes()
);
}
::rtl::OUString UnoControlDialogModel::getServiceName( ) throw(RuntimeException)
{
return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialogModel );
}
Any UnoControlDialogModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
{
if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
{
Any aAny;
aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialog );
return aAny;
}
return UnoControlModel::ImplGetDefaultValue( nPropId );
}
::cppu::IPropertyArrayHelper& UnoControlDialogModel::getInfoHelper()
{
static UnoPropertyArrayHelper* pHelper = NULL;
if ( !pHelper )
{
Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
pHelper = new UnoPropertyArrayHelper( aIDs );
}
return *pHelper;
}
void SAL_CALL UnoControlDialogModel::dispose( ) throw(RuntimeException)
{
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
// tell our listeners
{
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
EventObject aDisposeEvent;
aDisposeEvent.Source = static_cast< XAggregation* >( static_cast< ::cppu::OWeakAggObject* >( this ) );
maContainerListeners.disposeAndClear( aDisposeEvent );
maChangeListeners.disposeAndClear( aDisposeEvent );
}
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
// call the base class
UnoControlModel::dispose();
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
// dispose our child models
// for this, collect the models (we collect them from maModels, and this is modified when disposing children)
::std::vector< Reference< XControlModel > > aChildModels( maModels.size() );
::std::transform(
maModels.begin(), maModels.end(), // source range
aChildModels.begin(), // target location
::std::select1st< UnoControlModelHolder >( ) // operation to apply -> select the XControlModel part
);
// now dispose
::std::for_each( aChildModels.begin(), aChildModels.end(), DisposeControlModel() );
aChildModels.clear();
mbGroupsUpToDate = sal_False;
}
// XMultiPropertySet
Reference< XPropertySetInfo > UnoControlDialogModel::getPropertySetInfo( ) throw(RuntimeException)
{
static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
return xInfo;
}
UnoControlModel* UnoControlDialogModel::Clone() const
{
// clone the container itself
UnoControlDialogModel* pClone = new UnoControlDialogModel( *this );
// clone all children
::std::for_each(
maModels.begin(), maModels.end(),
CloneControlModel( pClone->maModels )
);
return pClone;
}
UnoControlDialogModel::UnoControlModelHolderList::iterator UnoControlDialogModel::ImplFindElement( const ::rtl::OUString& rName )
{
return ::std::find_if( maModels.begin(), maModels.end(), FindControlModel( rName ) );
}
// ::XMultiServiceFactory
Reference< XInterface > UnoControlDialogModel::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw(Exception, RuntimeException)
{
OGeometryControlModel_Base* pNewModel = NULL;
if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlEditModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlEditModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFormattedFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlFormattedFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFileControlModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlFileControlModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlButtonModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlButtonModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlImageControlModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlImageControlModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlRadioButtonModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlRadioButtonModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCheckBoxModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlCheckBoxModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFixedTextModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlFixedTextModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlGroupBoxModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlGroupBoxModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlListBoxModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlListBoxModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlComboBoxModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlComboBoxModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlDateFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlDateFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlTimeFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlTimeFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlNumericFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlNumericFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCurrencyFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlCurrencyFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlPatternFieldModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlPatternFieldModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlProgressBarModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlProgressBarModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlScrollBarModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlScrollBarModel >;
else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFixedLineModel ) == 0 )
pNewModel = new OGeometryControlModel< UnoControlFixedLineModel >;
Reference< XInterface > xNewModel = (::cppu::OWeakObject*)pNewModel;
return xNewModel;
}
Reference< XInterface > UnoControlDialogModel::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /* Arguments */ ) throw(Exception, RuntimeException)
{
return createInstance( ServiceSpecifier );
}
Sequence< ::rtl::OUString > UnoControlDialogModel::getAvailableServiceNames() throw(RuntimeException)
{
static Sequence< ::rtl::OUString >* pNamesSeq = NULL;
if ( !pNamesSeq )
{
pNamesSeq = new Sequence< ::rtl::OUString >( 19 );
::rtl::OUString* pNames = pNamesSeq->getArray();
pNames[0] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlEditModel );
pNames[1] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFormattedFieldModel );
pNames[2] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFileControlModel );
pNames[3] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlButtonModel );
pNames[4] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlImageControlModel );
pNames[5] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel );
pNames[6] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCheckBoxModel );
pNames[7] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedTextModel );
pNames[8] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlGroupBoxModel );
pNames[9] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlListBoxModel );
pNames[10] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlComboBoxModel );
pNames[11] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlDateFieldModel );
pNames[12] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlTimeFieldModel );
pNames[13] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlNumericFieldModel );
pNames[14] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCurrencyFieldModel );
pNames[15] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlPatternFieldModel );
pNames[16] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlProgressBarModel );
pNames[17] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlScrollBarModel );
pNames[18] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedLineModel );
}
return *pNamesSeq;
}
// XContainer
void UnoControlDialogModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
{
maContainerListeners.addInterface( l );
}
void UnoControlDialogModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
{
maContainerListeners.removeInterface( l );
}
// XElementAcces
Type UnoControlDialogModel::getElementType() throw(RuntimeException)
{
Type aType = getCppuType( ( Reference< XControlModel>* ) NULL );
return aType;
}
sal_Bool UnoControlDialogModel::hasElements() throw(RuntimeException)
{
return !maModels.empty();
}
// XNameContainer, XNameReplace, XNameAccess
void UnoControlDialogModel::replaceByName( const ::rtl::OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
{
Reference< XControlModel > xNewModel;
aElement >>= xNewModel;
if ( !xNewModel.is() )
lcl_throwIllegalArgumentException();
UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
if ( maModels.end() == aElementPos )
lcl_throwNoSuchElementException();
// stop listening at the old model
stopControlListening( aElementPos->first );
Reference< XControlModel > xReplaced( aElementPos->first );
// remember the new model, and start listening
aElementPos->first = xNewModel;
startControlListening( xNewModel );
ContainerEvent aEvent;
aEvent.Source = *this;
aEvent.Element = aElement;
aEvent.ReplacedElement <<= xReplaced;
aEvent.Accessor <<= aName;
// notify the container listener
maContainerListeners.elementReplaced( aEvent );
// our "tab controller model" has potentially changed -> notify this
implNotifyTabModelChange( aName );
}
Any UnoControlDialogModel::getByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
{
Any aElement;
UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
if ( maModels.end() != aElementPos )
aElement <<= aElementPos->first;
return aElement;
}
Sequence< ::rtl::OUString > UnoControlDialogModel::getElementNames() throw(RuntimeException)
{
Sequence< ::rtl::OUString > aNames( maModels.size() );
::std::transform(
maModels.begin(), maModels.end(), // source range
aNames.getArray(), // target range
::std::select2nd< UnoControlModelHolder >() // operator to apply: select the second element (the name)
);
return aNames;
}
sal_Bool UnoControlDialogModel::hasByName( const ::rtl::OUString& aName ) throw(RuntimeException)
{
return maModels.end() != ImplFindElement( aName );
}
void UnoControlDialogModel::insertByName( const ::rtl::OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
{
Reference< XControlModel > xM;
aElement >>= xM;
if ( !aName.getLength() || !xM.is() )
lcl_throwIllegalArgumentException();
maModels.push_back( UnoControlModelHolder( xM, aName ) );
mbGroupsUpToDate = sal_False;
startControlListening( xM );
ContainerEvent aEvent;
aEvent.Source = *this;
aEvent.Element <<= aElement;
aEvent.Accessor <<= aName;
maContainerListeners.elementInserted( aEvent );
// our "tab controller model" has potentially changed -> notify this
implNotifyTabModelChange( aName );
}
void UnoControlDialogModel::removeByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
{
UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
if ( maModels.end() != aElementPos )
{
ContainerEvent aEvent;
aEvent.Source = *this;
aEvent.Element <<= aElementPos->first;
aEvent.Accessor <<= aName;
maContainerListeners.elementRemoved( aEvent );
stopControlListening( aElementPos->first );
maModels.erase( aElementPos );
mbGroupsUpToDate = sal_False;
}
// our "tab controller model" has potentially changed -> notify this
implNotifyTabModelChange( aName );
}
// ----------------------------------------------------------------------------
sal_Bool SAL_CALL UnoControlDialogModel::getGroupControl( ) throw (RuntimeException)
{
return sal_True;
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::setGroupControl( sal_Bool GroupControl ) throw (RuntimeException)
{
DBG_ERROR( "UnoControlDialogModel::setGroupControl: explicit grouping not supported" );
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::setControlModels( const Sequence< Reference< XControlModel > >& _rControls ) throw (RuntimeException)
{
// set the tab indexes according to the order of models in the sequence
const Reference< XControlModel >* pControls = _rControls.getConstArray( );
const Reference< XControlModel >* pControlsEnd = _rControls.getConstArray( ) + _rControls.getLength();
sal_Int16 nTabIndex = 1;
for ( ; pControls != pControlsEnd; ++pControls )
{
// look up the control in our own structure. This is to prevent invalid arguments
UnoControlModelHolderList::const_iterator aPos =
::std::find_if(
maModels.begin(), maModels.end(),
CompareControlModel( *pControls )
);
if ( maModels.end() != aPos )
{
// okay, this is an existent model
// now set the TabIndex property (if applicable)
Reference< XPropertySet > xProps( aPos->first, UNO_QUERY );
Reference< XPropertySetInfo > xPSI;
if ( xProps.is() )
xPSI = xProps->getPropertySetInfo();
if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
xProps->setPropertyValue( getTabIndexPropertyName(), makeAny( nTabIndex++ ) );
}
mbGroupsUpToDate = sal_False;
}
}
typedef ::std::multimap< sal_Int32, Reference< XControlModel >, ::std::less< sal_Int32 > > MapIndexToModel;
// ----------------------------------------------------------------------------
Sequence< Reference< XControlModel > > SAL_CALL UnoControlDialogModel::getControlModels( ) throw (RuntimeException)
{
MapIndexToModel aSortedModels;
// will be the sorted container of all models which have a tab index property
::std::vector< Reference< XControlModel > > aUnindexedModels;
// will be the container of all models which do not have a tab index property
UnoControlModelHolderList::const_iterator aLoop = maModels.begin();
for ( ; aLoop != maModels.end(); ++aLoop )
{
Reference< XControlModel > xModel( aLoop->first );
// see if the model has a TabIndex property
Reference< XPropertySet > xControlProps( xModel, UNO_QUERY );
Reference< XPropertySetInfo > xPSI;
if ( xControlProps.is() )
xPSI = xControlProps->getPropertySetInfo( );
DBG_ASSERT( xPSI.is(), "UnoControlDialogModel::getControlModels: invalid child model!" );
// has it?
if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
{ // yes
sal_Int32 nTabIndex = -1;
xControlProps->getPropertyValue( getTabIndexPropertyName() ) >>= nTabIndex;
aSortedModels.insert( MapIndexToModel::value_type( nTabIndex, xModel ) );
}
else if ( xModel.is() )
// no, it hasn't, but we have to include it, anyway
aUnindexedModels.push_back( xModel );
}
// okay, here we have a container of all our models, sorted by tab index,
// plus a container of "unindexed" models
// -> merge them
Sequence< Reference< XControlModel > > aReturn( aUnindexedModels.size() + aSortedModels.size() );
::std::transform(
aSortedModels.begin(), aSortedModels.end(),
::std::copy( aUnindexedModels.begin(), aUnindexedModels.end(), aReturn.getArray() ),
::std::select2nd< MapIndexToModel::value_type >( )
);
return aReturn;
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::setGroup( const Sequence< Reference< XControlModel > >& Group, const ::rtl::OUString& GroupName ) throw (RuntimeException)
{
// not supported. We have only implicit grouping:
// We only have a sequence of control models, and we _know_ (yes, that's a HACK relying on
// implementation details) that VCL does grouping according to the order of controls automatically
// At least VCL does this for all we're interested in: Radio buttons.
DBG_ERROR( "UnoControlDialogModel::setGroup: grouping not supported" );
}
// ----------------------------------------------------------------------------
namespace
{
enum GroupingMachineState
{
eLookingForGroup,
eExpandingGroup
};
// ........................................................................
static sal_Int32 lcl_getDialogStep( const Reference< XControlModel >& _rxModel )
{
sal_Int32 nStep = 0;
try
{
Reference< XPropertySet > xModelProps( _rxModel, UNO_QUERY );
xModelProps->getPropertyValue( getStepPropertyName() ) >>= nStep;
}
catch( const Exception& )
{
DBG_ERROR( "lcl_getDialogStep: caught an exception while determining the dialog page!" );
}
return nStep;
}
}
// ----------------------------------------------------------------------------
sal_Int32 SAL_CALL UnoControlDialogModel::getGroupCount( ) throw (RuntimeException)
{
implUpdateGroupStructure();
return maGroups.size();
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::getGroup( sal_Int32 _nGroup, Sequence< Reference< XControlModel > >& _rGroup, ::rtl::OUString& _rName ) throw (RuntimeException)
{
implUpdateGroupStructure();
if ( ( _nGroup < 0 ) || ( _nGroup >= (sal_Int32)maGroups.size() ) )
{
DBG_ERROR( "UnoControlDialogModel::getGroup: invalid argument and I am not allowed to throw an exception!" );
_rGroup.realloc( 0 );
_rName = ::rtl::OUString();
}
else
{
AllGroups::const_iterator aGroupPos = maGroups.begin() + _nGroup;
_rGroup.realloc( aGroupPos->size() );
// copy the models
::std::copy( aGroupPos->begin(), aGroupPos->end(), _rGroup.getArray() );
// give the group a name
_rName = ::rtl::OUString::valueOf( _nGroup );
}
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::getGroupByName( const ::rtl::OUString& _rName, Sequence< Reference< XControlModel > >& _rGroup ) throw (RuntimeException)
{
::rtl::OUString sDummyName;
getGroup( _rName.toInt32( ), _rGroup, sDummyName );
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::addChangesListener( const Reference< XChangesListener >& _rxListener ) throw (RuntimeException)
{
maChangeListeners.addInterface( _rxListener );
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::removeChangesListener( const Reference< XChangesListener >& _rxListener ) throw (RuntimeException)
{
maChangeListeners.removeInterface( _rxListener );
}
// ----------------------------------------------------------------------------
void UnoControlDialogModel::implNotifyTabModelChange( const ::rtl::OUString& _rAccessor )
{
// multiplex to our change listeners:
// the changes event
ChangesEvent aEvent;
aEvent.Source = *this;
aEvent.Base <<= aEvent.Source; // the "base of the changes root" is also ourself
aEvent.Changes.realloc( 1 ); // exactly one change
aEvent.Changes[ 0 ].Accessor <<= _rAccessor;
Sequence< Reference< XInterface > > aChangeListeners( maChangeListeners.getElements() );
const Reference< XInterface >* pListener = aChangeListeners.getConstArray();
const Reference< XInterface >* pListenerEnd = aChangeListeners.getConstArray() + aChangeListeners.getLength();
for ( ; pListener != pListenerEnd; ++pListener )
{
if ( pListener->is() )
static_cast< XChangesListener* >( pListener->get() )->changesOccurred( aEvent );
}
}
// ----------------------------------------------------------------------------
void UnoControlDialogModel::implUpdateGroupStructure()
{
if ( mbGroupsUpToDate )
// nothing to do
return;
// conditions for a group:
// * all elements of the group are radio buttons
// * all elements of the group are on the same dialog page
// * in the overall control order (determined by the tab index), all elements are subsequent
maGroups.clear();
Sequence< Reference< XControlModel > > aControlModels = getControlModels();
const Reference< XControlModel >* pControlModels = aControlModels.getConstArray();
const Reference< XControlModel >* pControlModelsEnd = pControlModels + aControlModels.getLength();
// in extreme we have as much groups as controls
maGroups.reserve( aControlModels.getLength() );
GroupingMachineState eState = eLookingForGroup; // the current state of our machine
Reference< XServiceInfo > xModelSI; // for checking for a radion button
AllGroups::iterator aCurrentGroup = maGroups.end(); // the group which we're currently building
sal_Int32 nCurrentGroupStep = -1; // the step which all controls of the current group belong to
sal_Bool bIsRadioButton; // is it a radio button?
#ifdef DEBUG
::std::vector< ::rtl::OUString > aCurrentGroupLabels;
#endif
for ( ; pControlModels != pControlModelsEnd; ++pControlModels )
{
// we'll need this in every state
xModelSI = xModelSI.query( *pControlModels );
bIsRadioButton = xModelSI.is() && xModelSI->supportsService( ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel ) );
switch ( eState )
{
case eLookingForGroup:
{
if ( !bIsRadioButton )
// this is no radio button -> still looking for the beginning of a group
continue;
// the current model is a radio button
// -> we found the beginning of a new group
// create the place for this group
size_t nGroups = maGroups.size();
maGroups.resize( nGroups + 1 );
aCurrentGroup = maGroups.begin() + nGroups;
// and add the (only, til now) member
aCurrentGroup->push_back( *pControlModels );
// get the step which all controls of this group now have to belong to
nCurrentGroupStep = lcl_getDialogStep( *pControlModels );
// new state: looking for further members
eState = eExpandingGroup;
#ifdef DEBUG
Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
::rtl::OUString sLabel;
if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
aCurrentGroupLabels.push_back( sLabel );
#endif
}
break;
case eExpandingGroup:
{
if ( !bIsRadioButton )
{ // no radio button -> the group is done
aCurrentGroup = maGroups.end();
eState = eLookingForGroup;
#ifdef DEBUG
aCurrentGroupLabels.clear();
#endif
continue;
}
// it is a radio button - is it on the proper page?
const sal_Int32 nThisModelStep = lcl_getDialogStep( *pControlModels );
if ( ( nThisModelStep == nCurrentGroupStep ) // the current button is on the same dialog page
|| ( 0 == nThisModelStep ) // the current button appears on all pages
)
{
// -> it belongs to the same group
aCurrentGroup->push_back( *pControlModels );
// state still is eExpandingGroup - we're looking for further elements
eState = eExpandingGroup;
#ifdef DEBUG
Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
::rtl::OUString sLabel;
if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
aCurrentGroupLabels.push_back( sLabel );
#endif
continue;
}
// it's a radio button, but on a different page
// -> we open a new group for it
// close the old group
aCurrentGroup = maGroups.end();
#ifdef DEBUG
aCurrentGroupLabels.clear();
#endif
// open a new group
size_t nGroups = maGroups.size();
maGroups.resize( nGroups + 1 );
aCurrentGroup = maGroups.begin() + nGroups;
// and add the (only, til now) member
aCurrentGroup->push_back( *pControlModels );
nCurrentGroupStep = nThisModelStep;
// state is the same: we still are looking for further elements of the current group
eState = eExpandingGroup;
#ifdef DEBUG
Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
::rtl::OUString sLabel;
if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
aCurrentGroupLabels.push_back( sLabel );
#endif
}
break;
}
}
mbGroupsUpToDate = sal_True;
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException)
{
DBG_ASSERT( 0 == _rEvent.PropertyName.compareToAscii( "TabIndex" ),
"UnoControlDialogModel::propertyChange: not listening for this property!" );
// the accessor for the changed element
::rtl::OUString sAccessor;
UnoControlModelHolderList::const_iterator aPos =
::std::find_if(
maModels.begin(), maModels.end(),
CompareControlModel( Reference< XControlModel >( _rEvent.Source, UNO_QUERY ) )
);
DBG_ASSERT( maModels.end() != aPos, "UnoControlDialogModel::propertyChange: don't know this model!" );
if ( maModels.end() != aPos )
sAccessor = aPos->second;
// our groups are not up-to-date
mbGroupsUpToDate = sal_False;
// notify
implNotifyTabModelChange( sAccessor );
}
// ----------------------------------------------------------------------------
void SAL_CALL UnoControlDialogModel::disposing( const EventObject& evt ) throw (RuntimeException)
{
// TODO
}
// ----------------------------------------------------------------------------
void UnoControlDialogModel::startControlListening( const Reference< XControlModel >& _rxChildModel )
{
Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY );
Reference< XPropertySetInfo > xPSI;
if ( xModelProps.is() )
xPSI = xModelProps->getPropertySetInfo();
if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
xModelProps->addPropertyChangeListener( getTabIndexPropertyName(), this );
}
// ----------------------------------------------------------------------------
void UnoControlDialogModel::stopControlListening( const Reference< XControlModel >& _rxChildModel )
{
Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY );
Reference< XPropertySetInfo > xPSI;
if ( xModelProps.is() )
xPSI = xModelProps->getPropertySetInfo();
if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
xModelProps->removePropertyChangeListener( getTabIndexPropertyName(), this );
}
// ============================================================================
// = class UnoDialogControl
// ============================================================================
UnoDialogControl::UnoDialogControl() : maTopWindowListeners( *this )
{
maComponentInfos.nWidth = 300;
maComponentInfos.nHeight = 450;
}
::rtl::OUString UnoDialogControl::GetComponentServiceName()
{
return ::rtl::OUString::createFromAscii( "Dialog" );
}
// XInterface
Any UnoDialogControl::queryAggregation( const Type & rType ) throw(RuntimeException)
{
Any aRet( UnoDialogControl_IBase::queryInterface( rType ) );
return (aRet.hasValue() ? aRet : UnoControlContainer::queryAggregation( rType ));
}
// XTypeProvider
IMPL_IMPLEMENTATION_ID( UnoDialogControl )
Sequence< Type > UnoDialogControl::getTypes() throw(RuntimeException)
{
return ::comphelper::concatSequences(
UnoDialogControl_IBase::getTypes(),
UnoControlContainer::getTypes()
);
}
void UnoDialogControl::ImplInsertControl( Reference< XControlModel >& rxModel, const ::rtl::OUString& rName )
{
Reference< XPropertySet > xP( rxModel, UNO_QUERY );
::rtl::OUString aDefCtrl;
xP->getPropertyValue( GetPropertyName( BASEPROPERTY_DEFAULTCONTROL ) ) >>= aDefCtrl;
Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
Reference < XControl > xCtrl( xMSF->createInstance( aDefCtrl ), UNO_QUERY );
DBG_ASSERT( xCtrl.is(), "UnoDialogControl::ImplInsertControl: could not create the control!" );
if ( xCtrl.is() )
{
xCtrl->setModel( rxModel );
addControl( rName, xCtrl );
// will implicitly call addingControl, where we can add the PropertiesChangeListener to the model
// (which we formerly did herein)
// 08.01.2001 - 96008 - fs@openoffice.org
ImplSetPosSize( xCtrl );
}
}
void UnoDialogControl::ImplRemoveControl( Reference< XControlModel >& rxModel )
{
Sequence< Reference< XControl > > aControls = getControls();
Reference< XControl > xCtrl = StdTabController::FindControl( aControls, rxModel );
if ( xCtrl.is() )
removeControl( xCtrl );
}
void UnoDialogControl::ImplSetPosSize( Reference< XControl >& rxCtrl )
{
Reference< XPropertySet > xP( rxCtrl->getModel(), UNO_QUERY );
sal_Int32 nX, nY, nWidth, nHeight;
xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) ) >>= nX;
xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ) ) >>= nY;
xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ) >>= nWidth;
xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ) >>= nHeight;
// Currentley we are simply using MAP_APPFONT
OutputDevice*pOutDev = Application::GetDefaultDevice();
DBG_ASSERT( pOutDev, "Missing Default Device!" );
if ( pOutDev )
{
::Size aTmp( nX, nY );
aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT );
nX = aTmp.Width();
nY = aTmp.Height();
aTmp = ::Size( nWidth, nHeight );
aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT );
nWidth = aTmp.Width();
nHeight = aTmp.Height();
}
else
{
Reference< XWindowPeer > xPeer = ImplGetCompatiblePeer( sal_True );
Reference< XDevice > xD( xPeer, UNO_QUERY );
SimpleFontMetric aFM;
FontDescriptor aFD;
Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ) );
aVal >>= aFD;
if ( aFD.StyleName.getLength() )
{
Reference< XFont > xFont = xD->getFont( aFD );
aFM = xFont->getFontMetric();
}
else
{
Reference< XGraphics > xG = xD->createGraphics();
aFM = xG->getFontMetric();
}
sal_Int16 nH = aFM.Ascent + aFM.Descent;
sal_Int16 nW = nH/2; // calculate avarage width?!
nX *= nW;
nX /= 4;
nWidth *= nW;
nWidth /= 4;
nY *= nH;
nY /= 8;
nHeight *= nH;
nHeight /= 8;
}
Reference < XWindow > xW( rxCtrl, UNO_QUERY );
xW->setPosSize( nX, nY, nWidth, nHeight, PosSize::POSSIZE );
}
void UnoDialogControl::dispose() throw(RuntimeException)
{
EventObject aEvt;
aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
maTopWindowListeners.disposeAndClear( aEvt );
UnoControlContainer::dispose();
}
sal_Bool UnoDialogControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException)
{
// destroy the old tab controller, if existent
if ( mxTabController.is() )
{
mxTabController->setModel( NULL ); // just to be sure, should not be necessary
removeTabController( mxTabController );
::comphelper::disposeComponent( mxTabController ); // just to be sure, should not be necessary
mxTabController.clear();
}
if ( getModel().is() )
{
Sequence< Reference< XControl > > aControls = getControls();
const Reference< XControl >* pCtrls = aControls.getConstArray();
const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
removeControl( *pCtrls );
// will implicitly call removingControl, which will remove the PropertyChangeListener
// (which we formerly did herein)
// 08.01.2001 - 96008 - fs@openoffice.org
Reference< XContainer > xC( getModel(), UNO_QUERY );
if ( xC.is() )
xC->removeContainerListener( this );
Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY );
if ( xChangeNotifier.is() )
xChangeNotifier->removeChangesListener( this );
}
sal_Bool bRet = UnoControl::setModel( rxModel );
if ( getModel().is() )
{
Reference< XNameAccess > xNA( getModel(), UNO_QUERY );
if ( xNA.is() )
{
Sequence< ::rtl::OUString > aNames = xNA->getElementNames();
const ::rtl::OUString* pNames = aNames.getConstArray();
sal_uInt32 nCtrls = aNames.getLength();
Reference< XControlModel > xCtrlModel;
for( sal_uInt32 n = 0; n < nCtrls; ++n, ++pNames )
{
xNA->getByName( *pNames ) >>= xCtrlModel;
ImplInsertControl( xCtrlModel, *pNames );
}
}
Reference< XContainer > xC( getModel(), UNO_QUERY );
if ( xC.is() )
xC->addContainerListener( this );
Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY );
if ( xChangeNotifier.is() )
xChangeNotifier->addChangesListener( this );
}
Reference< XTabControllerModel > xTabbing( getModel(), UNO_QUERY );
if ( xTabbing.is() )
{
mxTabController = new StdTabController;
mxTabController->setModel( xTabbing );
addTabController( mxTabController );
}
return bRet;
}
void UnoDialogControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException)
{
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
UnoControl::setDesignMode( bOn );
Sequence< Reference< XControl > > xCtrls = getControls();
sal_Int32 nControls = xCtrls.getLength();
Reference< XControl >* pControls = xCtrls.getArray();
for ( sal_Int32 n = 0; n < nControls; n++ )
pControls[n]->setDesignMode( bOn );
}
void UnoDialogControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
{
UnoControlContainer::createPeer( rxToolkit, rParentPeer );
Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
xTW->setMenuBar( mxMenuBar );
if ( maTopWindowListeners.getLength() )
xTW->addTopWindowListener( &maTopWindowListeners );
}
void UnoDialogControl::elementInserted( const ContainerEvent& Event ) throw(RuntimeException)
{
Reference< XControlModel > xModel;
::rtl::OUString aName;
Event.Accessor >>= aName;
Event.Element >>= xModel;
ImplInsertControl( xModel, aName );
}
void UnoDialogControl::elementRemoved( const ContainerEvent& Event ) throw(RuntimeException)
{
Reference< XControlModel > xModel;
Event.Element >>= xModel;
if ( xModel.is() )
ImplRemoveControl( xModel );
}
void UnoDialogControl::elementReplaced( const ContainerEvent& Event ) throw(RuntimeException)
{
Reference< XControlModel > xModel;
Event.ReplacedElement >>= xModel;
if ( xModel.is() )
ImplRemoveControl( xModel );
::rtl::OUString aName;
Event.Accessor >>= aName;
Event.Element >>= xModel;
ImplInsertControl( xModel, aName );
}
void UnoDialogControl::addTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
{
maTopWindowListeners.addInterface( rxListener );
if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
{
Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
xTW->addTopWindowListener( &maTopWindowListeners );
}
}
void UnoDialogControl::removeTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
{
if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
{
Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
xTW->removeTopWindowListener( &maTopWindowListeners );
}
maTopWindowListeners.removeInterface( rxListener );
}
void UnoDialogControl::toFront( ) throw (RuntimeException)
{
if ( getPeer().is() )
{
Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
if( xTW.is() )
xTW->toFront();
}
}
void UnoDialogControl::toBack( ) throw (RuntimeException)
{
if ( getPeer().is() )
{
Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
if( xTW.is() )
xTW->toBack();
}
}
void UnoDialogControl::setMenuBar( const Reference< XMenuBar >& rxMenuBar ) throw (RuntimeException)
{
mxMenuBar = rxMenuBar;
if ( getPeer().is() )
{
Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
if( xTW.is() )
xTW->setMenuBar( mxMenuBar );
}
}
// XPropertiesChangeListener
void UnoDialogControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException)
{
if( !isDesignMode() && !IsUpdatingModel() && !mbCreatingCompatiblePeer )
{
::rtl::OUString s1( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) );
::rtl::OUString s2( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) );
::rtl::OUString s3( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
::rtl::OUString s4( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
sal_Int32 nLen = rEvents.getLength();
for( sal_Int32 i = 0; i < nLen; i++ )
{
const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i];
Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY );
sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get();
if ( ( rEvt.PropertyName == s1 ) || ( rEvt.PropertyName == s2 ) || ( rEvt.PropertyName == s3 ) || ( rEvt.PropertyName == s4 ) )
{
if ( bOwnModel )
{
Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY );
ImplSetPosSize( xThis );
}
else
{
Sequence<Reference<XControl> > aControlSequence(getControls());
Reference<XControl> aControlRef( StdTabController::FindControl( aControlSequence, xModel ) );
ImplSetPosSize( aControlRef );
}
break;
}
}
}
UnoControlContainer::propertiesChange( rEvents );
}
void UnoDialogControl::setTitle( const ::rtl::OUString& Title ) throw(RuntimeException)
{
Any aAny;
aAny <<= Title;
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ), aAny, sal_True );
}
::rtl::OUString UnoDialogControl::getTitle() throw(RuntimeException)
{
return ImplGetPropertyValue_UString( BASEPROPERTY_TITLE );
}
sal_Int16 UnoDialogControl::execute() throw(RuntimeException)
{
sal_Int16 nDone = -1;
if ( getPeer().is() )
{
Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
if( xDlg.is() )
{
GetComponentInfos().bVisible = sal_True;
nDone = xDlg->execute();
GetComponentInfos().bVisible = sal_False;
}
}
return nDone;
}
void UnoDialogControl::endExecute() throw(RuntimeException)
{
if ( getPeer().is() )
{
Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
if( xDlg.is() )
{
xDlg->endExecute();
GetComponentInfos().bVisible = sal_False;
}
}
}
void UnoDialogControl::addingControl( const Reference< XControl >& _rxControl )
{
UnoControlContainer::addingControl( _rxControl );
if ( _rxControl.is() )
{
Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY );
if ( xProps.is() )
{
Sequence< ::rtl::OUString > aNames( 4 );
::rtl::OUString* pNames = aNames.getArray();
*pNames++ = ::rtl::OUString::createFromAscii( "PositionX" );
*pNames++ = ::rtl::OUString::createFromAscii( "PositionY" );
*pNames++ = ::rtl::OUString::createFromAscii( "Width" );
*pNames++ = ::rtl::OUString::createFromAscii( "Height" );
xProps->addPropertiesChangeListener( aNames, this );
}
}
}
void UnoDialogControl::removingControl( const Reference< XControl >& _rxControl )
{
UnoControlContainer::removingControl( _rxControl );
if ( _rxControl.is() )
{
Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY );
if ( xProps.is() )
xProps->removePropertiesChangeListener( this );
}
}
void SAL_CALL UnoDialogControl::changesOccurred( const ChangesEvent& Event ) throw (RuntimeException)
{
// a tab controller model may have changed
if ( mxTabController.is() )
mxTabController->activateTabOrder();
}
|