summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/objcont.cxx
blob: 918ea36c222d70da9517f295596263c133421e58 (plain)
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
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
/*************************************************************************
 *
 *  $RCSfile: objcont.cxx,v $
 *
 *  $Revision: 1.47 $
 *
 *  last change: $Author: rt $ $Date: 2004-09-08 15:42:59 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#include <com/sun/star/uno/Reference.hxx>

#ifndef _COM_SUN_STAR_DOCUMENT_UPDATEDOCMODE_HPP_
#include <com/sun/star/document/UpdateDocMode.hpp>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
#include <drafts/com/sun/star/frame/XLayoutManager.hpp>
#endif

#ifndef _CACHESTR_HXX //autogen
#include <tools/cachestr.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen wg. QueryBox
#include <vcl/msgbox.hxx>
#endif
#ifndef _SFXSTYLE_HXX //autogen
#include <svtools/style.hxx>
#endif
#ifndef _SV_WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif

#ifndef GCC
#pragma hdrstop
#endif

#include <svtools/stritem.hxx>
#include <svtools/intitem.hxx>
#include <svtools/rectitem.hxx>
#include <svtools/urihelper.hxx>
#include <comphelper/processfactory.hxx>

#ifndef _SFXECODE_HXX
#include <svtools/sfxecode.hxx>
#endif
#ifndef _EHDL_HXX
#include <svtools/ehdl.hxx>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif
#include <math.h>

#ifndef INCLUDED_SVTOOLS_SECURITYOPTIONS_HXX
#include <svtools/securityoptions.hxx>
#endif
#include <svtools/saveopt.hxx>
#include <svtools/useroptions.hxx>
#include <unotools/localfilehelper.hxx>

#include "sfxresid.hxx"
#include "stbmgr.hxx"
#include "dinfdlg.hxx"
#include "fltfnc.hxx"
#include "docfac.hxx"
#include "cfgmgr.hxx"
#include "viewsh.hxx"
#include "objsh.hxx"
#include "objshimp.hxx"
#include "cfgitem.hxx"
#include "evntconf.hxx"
#include "interno.hxx"
#include "sfxhelp.hxx"
#include "dispatch.hxx"
#include "urlframe.hxx"
#include "printer.hxx"
#include "topfrm.hxx"
#include "basmgr.hxx"
#include "doctempl.hxx"
#include "doc.hrc"
#include "appdata.hxx"
#include "sfxbasemodel.hxx"
#include "accmgr.hxx"
#include "mnumgr.hxx"
#include "imgmgr.hxx"
#include "tbxconf.hxx"
#include "docfile.hxx"
#include "objuno.hxx"
#include "request.hxx"

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;

//====================================================================

#define SFX_WINDOWS_STREAM "SfxWindows"
#define SFX_PREVIEW_STREAM "SfxPreview"

//====================================================================

GDIMetaFile* SfxObjectShell::GetPreviewMetaFile( sal_Bool bFullContent ) const
{
    // Nur wenn gerade nicht gedruckt wird, darf DoDraw aufgerufen
    // werden, sonst wird u.U. der Printer abgeschossen !
    SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
    if ( pFrame && pFrame->GetViewShell() &&
         pFrame->GetViewShell()->GetPrinter() &&
         pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
         return 0;

    GDIMetaFile* pFile = new GDIMetaFile;

    VirtualDevice aDevice;
    aDevice.EnableOutput( FALSE );

    SfxInPlaceObject* pInPlaceObj = GetInPlaceObject();
    DBG_ASSERT( pInPlaceObj, "Ohne Inplace Objekt keine Grafik" );
    if (pInPlaceObj)
    {
        MapMode aMode( pInPlaceObj->GetMapUnit() );
        aDevice.SetMapMode( aMode );
        pFile->SetPrefMapMode( aMode );

        Size aTmpSize;
        sal_Int8 nAspect;
        if ( bFullContent )
        {
            nAspect = ASPECT_CONTENT;
            aTmpSize = pInPlaceObj->GetVisArea( nAspect ).GetSize();
        }
        else
        {
            nAspect = ASPECT_THUMBNAIL;
            aTmpSize = ((SfxObjectShell*)this)->GetFirstPageSize();
        }

        pFile->SetPrefSize( aTmpSize );
        DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
                    "size of first page is 0, overload GetFirstPageSize or set vis-area!" );

        pFile->Record( &aDevice );
        pInPlaceObj->DoDraw(
                &aDevice, Point(0,0), aTmpSize,
                JobSetup(), nAspect );
        pFile->Stop();
    }

    return pFile;
}

FASTBOOL SfxObjectShell::SaveWindows_Impl( SvStorage &rStor ) const
{
    SvStorageStreamRef xStream = rStor.OpenStream( DEFINE_CONST_UNICODE( SFX_WINDOWS_STREAM ),
                                    STREAM_TRUNC | STREAM_STD_READWRITE);
    if ( !xStream )
        return FALSE;

    xStream->SetBufferSize(1024);
    xStream->SetVersion( rStor.GetVersion() );

    // "uber alle Fenster iterieren (aber aktives Window zuletzt)
    SfxViewFrame *pActFrame = SfxViewFrame::Current();
    if ( !pActFrame || pActFrame->GetObjectShell() != this )
        pActFrame = SfxViewFrame::GetFirst(this);

    String aActWinData;
    for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this, TYPE(SfxTopViewFrame) ); pFrame;
            pFrame = SfxViewFrame::GetNext(*pFrame, this, TYPE(SfxTopViewFrame) ) )
    {
        // Bei Dokumenten, die Outplace aktiv sind, kann beim Speichern auch schon die View weg sein!
        if ( pFrame->GetViewShell() )
        {
            SfxTopFrame* pTop = (SfxTopFrame*) pFrame->GetFrame();
            pTop->GetTopWindow_Impl();

#if SUPD<613//MUSTINI
            char cToken = SfxIniManager::GetToken();
#else
            char cToken = ',';
#endif
            const BOOL bActWin = pActFrame == pFrame;
            String aUserData;
            pFrame->GetViewShell()->WriteUserData(aUserData);

            // assemble ini-data
            String aWinData;
            aWinData += String::CreateFromInt32( pFrame->GetCurViewId() );
            aWinData += cToken;
/*
            if ( !pWin || pWin->IsMaximized() )
                aWinData += SFX_WINSIZE_MAX;
            else if ( pWin->IsMinimized() )
                aWinData += SFX_WINSIZE_MIN;
            else
*/
#if SUPD<613//MUSTINI
            aWinData += SfxIniManager::GetString( pWin->GetPosPixel(), pWin->GetSizePixel() );
#endif
            aWinData += cToken;
            aWinData += aUserData;

            // aktives kennzeichnen
            aWinData += cToken;
            aWinData += bActWin ? '1' : '0';

            // je nachdem merken oder abspeichern
            if ( bActWin  )
                aActWinData = aWinData;
            else
                xStream->WriteByteString( aWinData );
        }
    }

    // aktives Window hinterher
    xStream->WriteByteString( aActWinData );
    return !xStream->GetError();
}

//====================================================================

SfxViewFrame* SfxObjectShell::LoadWindows_Impl( SfxTopFrame *pPreferedFrame )
{
    DBG_ASSERT( pPreferedFrame, "Can't be implemented in StarPortal!" );
    if ( pImp->bLoadingWindows || !pPreferedFrame )
        return NULL;

    DBG_ASSERT( GetMedium(), "A Medium should exist here!");
    if( !GetMedium() )
        return 0;

    // get correct mode
    SFX_APP();
    SfxViewFrame *pPrefered = pPreferedFrame ? pPreferedFrame->GetCurrentViewFrame() : 0;
    SvtSaveOptions aOpt;
    BOOL bLoadDocWins = aOpt.IsSaveDocWins() && !pPrefered;
    BOOL bLoadDocView = aOpt.IsSaveDocView();

    // In a StarPortal not possible at the moment
    if ( !bLoadDocView )
        return 0;

    // try to get viewdata information for XML format
    REFERENCE < XVIEWDATASUPPLIER > xViewDataSupplier( GetModel(), ::com::sun::star::uno::UNO_QUERY );
    REFERENCE < XINDEXACCESS > xViewData;
    SvStorageStreamRef xStream;

    // get viewdata information for binary format
    SvStorage *pStor = HasName() ? GetStorage() : NULL;
    xStream = pStor ? pStor->OpenStream( DEFINE_CONST_UNICODE( SFX_WINDOWS_STREAM ), STREAM_STD_READ ) : 0;
    if ( xStream.Is() && xStream->GetError() == ERRCODE_NONE )
    {
        xStream->SetVersion( pStor->GetVersion() );
        xStream->SetBufferSize(1024);
    }
    else if ( xViewDataSupplier.is() )
    {
        xViewData = xViewDataSupplier->getViewData();
        if ( !xViewData.is() )
            return NULL;
    }
    else
        return NULL;

    BOOL bOldFormat = TRUE;             // old format : not in StarDesktop 5.x
    SfxViewFrame *pActiveFrame = 0;
    String aWinData;
    char cToken =',';
    SfxItemSet *pSet = GetMedium()->GetItemSet();

    pImp->bLoadingWindows = TRUE;
    BOOL bLoaded = FALSE;
    sal_Int32 nView = 0;

    // get saved information for all views
    while ( TRUE )
    {
        USHORT nViewId = 0;
        FASTBOOL bActive=FALSE, bMaximized=FALSE;
        String aPosSize;
        String aUserData;                   // used in the binary format
        SEQUENCE < PROPERTYVALUE > aSeq;    // used in the XML format
        if ( xViewData.is() )
        {
            // XML format
            // active view is the first view in the container
            bActive = ( nView == 0 );

            if ( nView == xViewData->getCount() )
                // finished
                break;

            // get viewdata and look for the stored ViewId
            ::com::sun::star::uno::Any aAny = xViewData->getByIndex( nView++ );
            if ( aAny >>= aSeq )
            {
                for ( sal_Int32 n=0; n<aSeq.getLength(); n++ )
                {
                    const PROPERTYVALUE& rProp = aSeq[n];
                    if ( rProp.Name.compareToAscii("ViewId") == COMPARE_EQUAL )
                    {
                        ::rtl::OUString aId;
                        rProp.Value >>= aId;
                        String aTmp( aId );
                        aTmp.Erase( 0, 4 );  // format is like in "view3"
                        nViewId = (USHORT) aTmp.ToInt32();
                        break;
                    }
                }
            }
        }
        else
        {
            // binary format
            xStream->ReadByteString( aWinData );
            if ( !aWinData.Len() )
                // reading finished
                break;

            if ( aWinData.GetToken( 0, cToken ).EqualsAscii( "TASK" ) )
            {
                // doesn't make any sense with the new task handling using system tasks or browser windows
                bOldFormat = FALSE;
                continue;
            }

            nViewId = (USHORT) aWinData.GetToken( 0, cToken ).ToInt32();
            if ( bOldFormat )
            {
                // Old format
                aPosSize = aWinData.GetToken( 1, cToken );
                aPosSize.ToLowerAscii();
                aUserData = aWinData.GetToken( 2, cToken );
                bActive = aWinData.GetToken( 3, cToken ).ToInt32();
            }
            else
            {
                // 5.0-Format, get activity state and UserData
                USHORT nPos=0;
                bActive = aWinData.GetToken( 3, cToken, nPos ).ToInt32();
                aUserData = aWinData.Copy( nPos );
            }
        }

        // load only active view, but current item is not the active one ?
        if ( !bLoadDocWins && !bActive )
        {
            if ( xViewData.is() )
                // in XML format the active view is the first one
                break;
            else
                continue;
        }

        // check for minimized/maximized/size
        if ( aPosSize.EqualsAscii( "min" ) )
            bMaximized = TRUE;
        else if ( aPosSize.EqualsAscii( "min" ) )
        {
            bMaximized = TRUE;
            bActive = FALSE;
        }
        else
            bMaximized = FALSE;

        Point aPt;
        Size aSz;
#if SUPD<613//MUSTINI
        if ( !bMaximized )
            SfxIniManager::GetPosSize( aPosSize, aPt, aSz );
#endif

        pSet->ClearItem( SID_USER_DATA );
        SfxViewFrame *pFrame = 0;
        if ( pPrefered )
        {
            // use the frame from the arguments, but don't set a window size
            pFrame = pPrefered;
            if ( pFrame->GetViewShell() || !pFrame->GetObjectShell() )
            {
                pSet->ClearItem( SID_VIEW_POS_SIZE );
                pSet->ClearItem( SID_WIN_POSSIZE );
                pSet->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );

                // avoid flickering controllers
                SfxBindings &rBind = pFrame->GetBindings();
                rBind.ENTERREGISTRATIONS();

                // set document into frame
                pPreferedFrame->InsertDocument( this );

                // restart controller updating
                rBind.LEAVEREGISTRATIONS();
            }
            else
            {
                // create new view
                pFrame->CreateView_Impl( nViewId );
            }
        }
        else
        {
            if ( bLoadDocWins )
            {
                // open in the background
                pSet->Put( SfxUInt16Item( SID_VIEW_ZOOM_MODE, 0 ) );
                if ( !bMaximized )
                    pSet->Put( SfxRectangleItem( SID_VIEW_POS_SIZE, Rectangle( aPt, aSz ) ) );
            }

            pSet->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );

            if ( pPreferedFrame )
            {
                // Frame "ubergeben, allerdings ist der noch leer
                pPreferedFrame->InsertDocument( this );
                pFrame = pPreferedFrame->GetCurrentViewFrame();
            }
            else
            {
                pFrame = SfxTopFrame::Create( this, nViewId, FALSE, pSet )->GetCurrentViewFrame();
            }

            // only temporary data, don't hold it in the itemset
            pSet->ClearItem( SID_VIEW_POS_SIZE );
            pSet->ClearItem( SID_WIN_POSSIZE );
            pSet->ClearItem( SID_VIEW_ZOOM_MODE );
        }

        bLoaded = TRUE;

        // UserData hier einlesen, da es ansonsten immer mit bBrowse=TRUE
        // aufgerufen wird, beim Abspeichern wurde aber bBrowse=FALSE verwendet
        if ( pFrame && pFrame->GetViewShell() )
        {
            if ( aUserData.Len() )
                pFrame->GetViewShell()->ReadUserData( aUserData, !bLoadDocWins );
            else if ( aSeq.getLength() )
                pFrame->GetViewShell()->ReadUserDataSequence( aSeq, !bLoadDocWins );
        }

        // perhaps there are more windows to load
        pPreferedFrame = NULL;

        if ( bActive )
            pActiveFrame = pFrame;

        if( pPrefered || !bLoadDocWins )
            // load only active window
            break;
    }

    if ( pActiveFrame )
    {
        if ( !pPrefered )
            // activate frame
            pActiveFrame->MakeActive_Impl( TRUE );
    }

    pImp->bLoadingWindows = FALSE;
    return pPrefered && bLoaded ? pPrefered : pActiveFrame;
}

//====================================================================

void SfxObjectShell::UpdateDocInfoForSave()
{
    if( !pImp->bDoNotTouchDocInfo )
    {
        SfxDocumentInfo &rDocInfo = GetDocInfo();
        rDocInfo.SetTemplateConfig( HasTemplateConfig() );

        if ( IsModified() )
        {
            // Keine Unterschiede mehr zwischen Save, SaveAs
            String aUserName = SvtUserOptions().GetFullName();
            if ( !rDocInfo.IsUseUserData() )
            {
                SfxStamp aCreated = rDocInfo.GetCreated();
                if ( aUserName == aCreated.GetName() )
                {
                    aCreated.SetName( String() );
                    rDocInfo.SetCreated( aCreated );
                }

                SfxStamp aPrinted = rDocInfo.GetPrinted();
                if ( aUserName == aPrinted.GetName() )
                {
                    aPrinted.SetName( String() );
                    rDocInfo.SetPrinted( aPrinted );
                }

                aUserName.Erase();
            }

            rDocInfo.SetChanged( aUserName );
            if ( !HasName() || pImp->bIsSaving )
                UpdateTime_Impl( rDocInfo );
        }

        if ( !pImp->bIsSaving )
            rDocInfo.SetPasswd( pImp->bPasswd );

        // clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
        if ( SvtSecurityOptions().IsOptionSet( SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
            rDocInfo.DeleteUserData( rDocInfo.IsUseUserData() );

        Broadcast( SfxDocumentInfoHint( &rDocInfo ) );
    }
}

// -----------------------------------------------------------------------

BOOL SfxObjectShell::SaveInfoAndConfig_Impl( SvStorageRef pNewStg )
{
    //Demnaechst mal gemeinsame Teile zusammenfassen
    UpdateDocInfoForSave();

#if !defined( SFX_KEY_MAXPREVIEWSIZE ) && defined( TFPLUGCOMM )
#define SFX_KEY_MAXPREVIEWSIZE SFX_KEY_ISFREE
#endif

#ifdef MI_doch_wieder_die_alte_preview
    String aMaxSize = SFX_INIMANAGER()->Get( SFX_KEY_MAXPREVIEWSIZE );
    ULONG nMaxSize = aMaxSize.Len() ? ULONG( aMaxSize ) : 50000;
#else
    ULONG nMaxSize = 0L;
#endif
    if( nMaxSize && !GetDocInfo().IsPasswd() &&
        SFX_CREATE_MODE_STANDARD == eCreateMode )
    {
        GDIMetaFile* pFile = GetPreviewMetaFile();
        if ( pFile )
        {
            SvCacheStream aStream;
            long nVer = pNewStg->GetVersion();
            aStream.SetVersion( nVer );
            aStream << *pFile;
            if( aStream.Tell() < nMaxSize )
            {
                SvStorageStreamRef xStream = pNewStg->OpenStream(
                    DEFINE_CONST_UNICODE( SFX_PREVIEW_STREAM ),
                    STREAM_TRUNC | STREAM_STD_READWRITE);
                if( xStream.Is() && !xStream->GetError() )
                {
                    long nVer = pNewStg->GetVersion();
                    xStream->SetVersion( nVer );
                    aStream.Seek( 0L );
                    *xStream << aStream;
                }
            }
            delete pFile;
        }
    }

    if( pImp->bIsSaving )
    {
        //!! kein Aufruf der Basisklasse wegen doppeltem Aufruf in Persist
        //if(!SfxObjectShell::Save())
        //  return FALSE;
        SvStorageRef aRef = GetMedium()->GetStorage();
        if ( aRef.Is() )
        {
            SfxDocumentInfo& rDocInfo = GetDocInfo();
            rDocInfo.Save(pNewStg);

            // wenn es sich um ein Dokument lokales Basic handelt, dieses
            // schreiben
            if ( pImp->pBasicMgr )
                pImp->pBasicMgr->Store( *pNewStg );
            else
            {
                String aURL;
                if( HasName() )
                    aURL = GetMedium()->GetName();
                else
                {
                    aURL = GetDocInfo().GetTemplateFileName();
                    // Bei Templates keine URL...
                    aURL = URIHelper::SmartRelToAbs( aURL );
                }
#ifndef TFPLUGCOMM
                BasicManager::CopyBasicData( GetStorage(), aURL, pNewStg );
#endif
            }

            // Windows-merken
            if ( TRUE ) HACK(aus config)
                SaveWindows_Impl( *pNewStg );

            // Konfiguration schreiben
            if ( GetConfigManager() )
            {
/* //!MBA
                if ( rDocInfo.HasTemplateConfig() )
                {
                    const String aTemplFileName( rDocInfo.GetTemplateFileName() );
                    if ( aTemplFileName.Len() )
                    {
                        INetURLObject aURL( aTemplFileName );
                        DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );

                        SvStorageRef aStor = new SvStorage( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
                        if ( SVSTREAM_OK == aStor->GetError() )
                        {
                            GetConfigManager()->StoreConfiguration(aStor);
                            if (aRef->IsStream(SfxConfigManager::GetStreamName()))
                                aRef->Remove(SfxConfigManager::GetStreamName());
                        }
                    }
                }
                else
 */
                {
//! MBA                    GetConfigManager()->SetModified( TRUE );
                    GetConfigManager()->StoreConfiguration( pNewStg );
                }
            }
        }
        return TRUE;
    }
    else
    {
        //!! kein Aufruf der Basisklasse wegen doppeltem Aufruf in Persist
        //if(!SfxObjectShell::SaveAs(pNewStg))
        //  return FALSE;
        SFX_APP();
        GetMedium();

        // alte DocInfo laden
        SfxDocumentInfo &rDocInfo = GetDocInfo();

        // DocInfo speichern
        rDocInfo.Save( pNewStg );

        // wenn es sich um ein Dokument lokales Basic handelt, dieses schreiben
        if ( pImp->pBasicMgr )
            pImp->pBasicMgr->Store( *pNewStg );
#ifndef MI_NONOS
        else
        {
            String aURL;
            if( HasName() )
                aURL = GetMedium()->GetName();
            else
            {
                aURL = GetDocInfo().GetTemplateFileName();
                // Bei Templates keine URL...
                aURL = URIHelper::SmartRelToAbs( aURL );
            }
#ifndef TFPLUGCOMM
            BasicManager::CopyBasicData( GetStorage(), aURL, pNewStg );
#endif
        }
#endif
        // Windows-merken
        if ( TRUE ) HACK(aus config)
            SaveWindows_Impl( *pNewStg );

        // Konfiguration schreiben
        if (GetConfigManager())
        {
/* //!MBA
            if ( rDocInfo.HasTemplateConfig() )
            {
                const String aTemplFileName( rDocInfo.GetTemplateFileName() );
                if ( aTemplFileName.Len() )
                {
                    INetURLObject aURL( aTemplFileName );
                    DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );

                    SvStorageRef aStor = new SvStorage( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
                    if ( SVSTREAM_OK == aStor->GetError() )
                    {
                        GetConfigManager()->StoreConfiguration(aStor);
                        if (pNewStg->IsStream(SfxConfigManager::GetStreamName()))
                            pNewStg->Remove(SfxConfigManager::GetStreamName());
                    }
                }
            }
            else
 */
            {
//!MBA                GetConfigManager()->SetModified( TRUE );
                GetConfigManager()->StoreConfiguration(pNewStg);
            }
        }

        return TRUE;
    }
}

//--------------------------------------------------------------------

// Bearbeitungszeit aktualisieren
SfxDocumentInfo& SfxObjectShell::UpdateTime_Impl(SfxDocumentInfo &rInfo)
{
    // Get old time from documentinfo
    Time aOldTime(rInfo.GetTime());

    // Initialize some local member! Its neccessary for wollow operations!
    DateTime    aNow                    ;   // Date and time at current moment
    Time        n24Time     (24,0,0,0)  ;   // Time-value for 24 hours - see follow calculation
    ULONG       nDays       = 0         ;   // Count of days between now and last editing
    Time        nAddTime    (0)         ;   // Value to add on aOldTime

    // Safe impossible cases!
    // User has changed time to the past between last editing and now ... its not possible!!!
    DBG_ASSERT( !(aNow.GetDate()<pImp->nTime.GetDate()), "Timestamp of last change is in the past ?!..." );

    // Do the follow only, if user has NOT changed time to the past.
    // Else add a time of 0 to aOldTime ... !!!
    if (aNow.GetDate()>=pImp->nTime.GetDate())
    {
        // Get count of days last editing.
        nDays = aNow.GetSecFromDateTime(pImp->nTime.GetDate())/86400 ;

        if (nDays==0)
        {
            // If no day between now and last editing - calculate time directly.
            nAddTime    =   (const Time&)aNow - (const Time&)pImp->nTime ;
        }
        else
        // If time of working without save greater then 1 month (!) ....
        // we add 0 to aOldTime!
        if (nDays<=31)
        {
            // If 1 or up to 31 days between now and last editing - calculate time indirectly.
            // nAddTime = (24h - nTime) + (nDays * 24h) + aNow
            --nDays;
             nAddTime    =  nDays*n24Time.GetTime() ;
            nAddTime    +=  n24Time-(const Time&)pImp->nTime        ;
            nAddTime    +=  aNow                    ;
        }

        aOldTime += nAddTime;
    }

    rInfo.SetTime(aOldTime.GetTime());
    pImp->nTime = aNow;
    rInfo.IncDocumentNumber();
    //! DocumentNummer
#if 0
    const String aDocNo(rInfo.GetUserKey(0).GetWord());
    const String aTitle(rInfo.GetUserKey(0).GetTitle());
    USHORT nNo = 1;
    if ( aDocNo.Len() )
    {
        nNo = (USHORT)aDocNo;
        if(nNo)
            ++nNo;
        else
            nNo = 1;
    }
    rInfo.SetUserKey(SfxDocUserKey(aTitle, nNo), 0);
#endif
    return rInfo;
}

//--------------------------------------------------------------------

void SfxObjectShell::DocInfoDlg_Impl( SfxDocumentInfo &rDocInfo )
{
    // anzuzeigenden Dokumentnamen ermitteln
    String aURL, aTitle;
    if ( HasName() && !pImp->aNewName.Len() )
    {
        aURL = GetMedium()->GetName();
        aTitle = GetTitle();
    }
    else
    {
        if ( !pImp->aNewName.Len() )
        {
            aURL = DEFINE_CONST_UNICODE( "private:factory/" );
            aURL += String::CreateFromAscii( GetFactory().GetShortName() );
            // aTitle = String( SfxResId( STR_NONAME ) );
        }
        else
        {
            aURL = DEFINE_CONST_UNICODE( "[private:factory/" );
            aURL += String::CreateFromAscii( GetFactory().GetShortName() );
            aURL += DEFINE_CONST_UNICODE( "]" );
            INetURLObject aURLObj( pImp->aNewName );
            aURL += aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
            // aTitle = aURLObj.GetBase();
        }
        aTitle = GetTitle();
    }

    // Itemset f"ur Dialog aufbereiten
    SfxDocumentInfoItem aDocInfoItem( aURL, rDocInfo );
    if ( !GetSlotState( SID_DOCTEMPLATE ) )
        aDocInfoItem.SetTemplate(FALSE);
    SfxItemSet aSet(GetPool(), SID_DOCINFO, SID_DOCINFO,
                    SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START,
                    0L );
    aSet.Put( aDocInfoItem );
    aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, aTitle ) );

    // Dialog via Factory erzeugen und ausf"uhren
    SfxDocumentInfoDialog *pDlg = CreateDocumentInfoDialog(0, aSet);
    if ( RET_OK == pDlg->Execute() )
    {
        // neue DocInfo aus Dialog holen
        const SfxPoolItem *pItem = 0;
        if ( SFX_ITEM_SET ==
             pDlg->GetOutputItemSet()->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
        {
            rDocInfo = (*(const SfxDocumentInfoItem *)pItem)();

            // ggf. den Titel des Dokuments neu setzen
            String aNewTitle = rDocInfo.GetTitle();
            aNewTitle.EraseLeadingChars();
            aNewTitle.EraseTrailingChars();
            if ( aTitle != aNewTitle && aNewTitle.Len() )
                SetTitle( aNewTitle );
        }
    }
    delete pDlg;
}

//------------------------------------------------------------------------

SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
(
    Window*             pParent,
    const SfxItemSet&   rSet
)
{
    return new SfxDocumentInfoDialog(pParent, rSet);
}

//--------------------------------------------------------------------

SvEmbeddedInfoObject* SfxObjectShell::InsertObject
(
    SvEmbeddedObject*   pObj,
    const String&       rName
)

{
    // Objekt erzeugen ist fehlgeschlagen?
    if ( !pObj )
        HACK(Fehlermeldung fehlt)
        return 0;

    String aName( rName );
    if( !aName.Len() )
    {
        aName = DEFINE_CONST_UNICODE("Object ");
        String aStr;
        USHORT i = 1;
        HACK(Wegen Storage Bug 46033)
        // for-Schleife wegen Storage Bug 46033
        for( USHORT n = 0; n < 100; n++ )
        {
            do
            {
                aStr = aName;
                aStr += String::CreateFromInt32( i );
                i++;
            } while ( Find( aStr ) );

            SvInfoObjectRef xSub = new SvEmbeddedInfoObject( pObj, aStr );
            if ( Move( xSub, aStr ) ) // Eigentuemer Uebergang
                return (SvEmbeddedInfoObject*) &xSub;
        }
    }
    else
    {
        SvInfoObjectRef xSub = new SvEmbeddedInfoObject( pObj, aName );
        if ( Move( xSub, aName ) ) // Eigentuemer Uebergang
            return (SvEmbeddedInfoObject*) &xSub;
    }
    return 0;
}

//-------------------------------------------------------------------------

SfxConfigManager* SfxObjectShell::GetConfigManager( BOOL bForceCreation )
{
    if ( !pImp->pCfgMgr )
    {
        if ( bForceCreation || HasStorage() && SfxConfigManager::HasConfiguration( *GetStorage() ) )
        {
            pImp->pCfgMgr = new SfxConfigManager( *this );
            SfxConfigItem* pItem = GetEventConfig_Impl( FALSE );
            if ( pItem && !pItem->GetConfigManager() )
                // imported binary format
                pItem->Connect( pImp->pCfgMgr );

        }
    }

    return pImp->pCfgMgr;
}

//-------------------------------------------------------------------------

void SfxObjectShell::SetConfigManager(SfxConfigManager *pMgr)
{
//    if ( pImp->pCfgMgr == SFX_CFGMANAGER() && pMgr)
//        pMgr->Activate(pImp->pCfgMgr);

    if ( pImp->pCfgMgr && pImp->pCfgMgr != pMgr )
        delete pImp->pCfgMgr;

    pImp->pCfgMgr = pMgr;
}

//-------------------------------------------------------------------------

void SfxObjectShell::SetTemplateConfig(BOOL bTplConf)
{
//    pImp->bTemplateConfig = bTplConf;
//    DBG_ASSERT(pImp->pCfgMgr || !bTplConf,"Keine Konfiguration in der Vorlage!");
}

//-------------------------------------------------------------------------

BOOL SfxObjectShell::HasTemplateConfig() const
{
//!MBA    return pImp->bTemplateConfig;
    return FALSE;
}

//-------------------------------------------------------------------------
/*
void SfxObjectShell::TransferConfig(SfxObjectShell& rObjSh)
{
    SfxConfigManager *pNewCfgMgr=0, *pOldCfgMgr=0;
    pOldCfgMgr = pImp->pCfgMgr;
    pImp->pCfgMgr = 0;

    pNewCfgMgr = rObjSh.pImp->pCfgMgr;
    rObjSh.pImp->pCfgMgr=0;

    SetConfigManager(pNewCfgMgr);
    rObjSh.SetConfigManager(pOldCfgMgr);
}
*/

//--------------------------------------------------------------------

SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
{
    return 0;
}

void SfxObjectShell::SetOrganizerSearchMask(
    SfxStyleSheetBasePool* pPool) const
{
    pPool->SetSearchMask(SFX_STYLE_FAMILY_ALL,
                         SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
}

//--------------------------------------------------------------------

USHORT SfxObjectShell::GetContentCount(USHORT nIdx1,
                                         USHORT nIdx2)
{
    switch(nIdx1)
    {
        case INDEX_IGNORE:
            return DEF_CONTENT_COUNT;
        case CONTENT_STYLE:
        {
            SfxStyleSheetBasePool *pPool = GetStyleSheetPool();
            if(!pPool)
                return 0;
            SetOrganizerSearchMask(pPool);
            return pPool->Count();
        }
        case CONTENT_MACRO:
            break;
/*
        case CONTENT_CONFIG:
            return (GetConfigManager() && !HasTemplateConfig()) ?
                        GetConfigManager()->GetItemCount() : 0;
            break;
 */
    }
    return 0;
}


//--------------------------------------------------------------------

void  SfxObjectShell::TriggerHelpPI(USHORT nIdx1, USHORT nIdx2, USHORT nIdx3)
{
    if(nIdx1==CONTENT_STYLE && nIdx2 != INDEX_IGNORE) //StyleSheets
    {
        SfxStyleSheetBasePool *pPool = GetStyleSheetPool();
        SetOrganizerSearchMask(pPool);
#ifdef WIR_KOENNEN_WIEDER_HILFE_FUER_STYLESHEETS
        SfxStyleSheetBase *pStyle = (*pPool)[nIdx2];
        if(pStyle)
        {
            String aHelpFile;
            ULONG nHelpId=pStyle->GetHelpId(aHelpFile);
            SfxHelpPI* pHelpPI = SFX_APP()->GetHelpPI();
            if ( pHelpPI && nHelpId )
                pHelpPI->LoadTopic( nHelpId );
        }
#endif
    }
}

BOOL   SfxObjectShell::CanHaveChilds(USHORT nIdx1,
                                       USHORT nIdx2)
{
    switch(nIdx1) {
    case INDEX_IGNORE:
        return TRUE;
    case CONTENT_STYLE:
        return INDEX_IGNORE == nIdx2 || !GetStyleSheetPool()? FALSE: TRUE;
    case CONTENT_MACRO:
//!!    return INDEX_IGNORE == nIdx2? FALSE: TRUE;
        return FALSE;
/*
    case CONTENT_CONFIG:
        return INDEX_IGNORE == nIdx2 ? FALSE : TRUE;
 */
    }
    return FALSE;
}

//--------------------------------------------------------------------

void SfxObjectShell::GetContent(String &rText,
                                Bitmap &rClosedBitmap,
                                Bitmap &rOpenedBitmap,
                                BOOL &bCanDel,
                                USHORT i,
                                USHORT nIdx1,
                                USHORT nIdx2 )
{
    DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
    SfxObjectShell::GetContent( rText, rClosedBitmap, rOpenedBitmap, BMP_COLOR_NORMAL, bCanDel, i, nIdx1, nIdx2 );
}

//--------------------------------------------------------------------

void   SfxObjectShell::GetContent(String &rText,
                                  Bitmap &rClosedBitmap,
                                  Bitmap &rOpenedBitmap,
                                  BmpColorMode eColorMode,
                                  BOOL &bCanDel,
                                  USHORT i,
                                  USHORT nIdx1,
                                  USHORT nIdx2 )
{
    bCanDel=TRUE;

    switch(nIdx1)
    {
        case INDEX_IGNORE:
        {
            USHORT nTextResId = 0;
            USHORT nClosedBitmapResId = 0 ; //evtl. sp"ater mal unterschiedliche
            USHORT nOpenedBitmapResId = 0; // "     "       "   "
            switch(i)
            {
                case CONTENT_STYLE:
                    nTextResId = STR_STYLES;
                    if ( eColorMode == BMP_COLOR_NORMAL )
                    {
                        nClosedBitmapResId= BMP_STYLES_CLOSED;
                        nOpenedBitmapResId= BMP_STYLES_OPENED;
                    }
                    else
                    {
                        nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
                        nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
                    }
                    break;
                case CONTENT_MACRO:
                    nTextResId = STR_MACROS;
                    if ( eColorMode == BMP_COLOR_NORMAL )
                    {
                        nClosedBitmapResId= BMP_STYLES_CLOSED;
                        nOpenedBitmapResId= BMP_STYLES_OPENED;
                    }
                    else
                    {
                        nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
                        nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
                    }
                    break;
/*
                case CONTENT_CONFIG:
                    nTextResId = STR_CONFIG;
                    nClosedBitmapResId= BMP_STYLES_CLOSED;
                    nOpenedBitmapResId= BMP_STYLES_OPENED;
                    break;
 */
            }

            if ( nTextResId )
            {
                rText  = String(SfxResId(nTextResId));
                rClosedBitmap = Bitmap(SfxResId(nClosedBitmapResId));
                rOpenedBitmap = Bitmap(SfxResId(nOpenedBitmapResId));
            }
            break;
        }

        case CONTENT_STYLE:
        {
            SfxStyleSheetBasePool *pPool = GetStyleSheetPool();
            SetOrganizerSearchMask(pPool);
            SfxStyleSheetBase *pStyle = (*pPool)[i];
            rText = pStyle->GetName();
            bCanDel=((pStyle->GetMask() & SFXSTYLEBIT_USERDEF)
                     == SFXSTYLEBIT_USERDEF);
            rClosedBitmap = rOpenedBitmap =
                GetStyleFamilyBitmap(pStyle->GetFamily(), eColorMode );
        }
            break;
        case CONTENT_MACRO:
            break;
/*
        case CONTENT_CONFIG:
            if ( GetConfigManager() && !HasTemplateConfig())
            {
                rText = GetConfigManager()->GetItem(i);
                bCanDel = GetConfigManager()->CanDelete(i);
            }
            else
                rText = String();
            rClosedBitmap = Bitmap(SfxResId(BMP_STYLES_CLOSED));
            rOpenedBitmap = Bitmap(SfxResId(BMP_STYLES_OPENED));
            break;
*/
    }
}

//--------------------------------------------------------------------
Bitmap SfxObjectShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily )
{
    DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
    return SfxObjectShell::GetStyleFamilyBitmap( eFamily, BMP_COLOR_NORMAL );
}

//--------------------------------------------------------------------

Bitmap SfxObjectShell::GetStyleFamilyBitmap(SfxStyleFamily eFamily, BmpColorMode eColorMode )
{
    USHORT nResId = 0;
    switch(eFamily)
    {
        case SFX_STYLE_FAMILY_CHAR:
            nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY1 : BMP_STYLES_FAMILY1_HC;
            break;
        case SFX_STYLE_FAMILY_PARA:
            nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY2 : BMP_STYLES_FAMILY2_HC;
            break;
        case SFX_STYLE_FAMILY_FRAME:
            nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY3 : BMP_STYLES_FAMILY3_HC;
            break;
        case SFX_STYLE_FAMILY_PAGE :
            nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY4 : BMP_STYLES_FAMILY4_HC;
            break;
        case SFX_STYLE_FAMILY_PSEUDO:
        case SFX_STYLE_FAMILY_ALL:
            break;
    }

    if ( nResId )
        return Bitmap(SfxResId(nResId));
    else
        return Bitmap();
}


//--------------------------------------------------------------------

BOOL SfxObjectShell::Insert(SfxObjectShell &rSource,
                              USHORT nSourceIdx1,
                              USHORT nSourceIdx2,
                              USHORT nSourceIdx3,
                              USHORT &nIdx1,
                              USHORT &nIdx2,
                              USHORT &nIdx3,
                              USHORT &nDeleted)
{
    BOOL bRet = FALSE;

    if (INDEX_IGNORE == nIdx1 && CONTENT_STYLE == nSourceIdx1)
        nIdx1 = CONTENT_STYLE;

    if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == nIdx1)
    {
        SfxStyleSheetBasePool* pHisPool  = rSource.GetStyleSheetPool();
        SfxStyleSheetBasePool* pMyPool   = GetStyleSheetPool();
        SetOrganizerSearchMask(pHisPool);
        SetOrganizerSearchMask(pMyPool);

        SfxStyleSheetBase* pHisSheet = (*pHisPool)[nSourceIdx2];

        // Einfuegen ist nur dann noetig, wenn ein StyleSheet
        // zwischen unterschiedlichen(!) Pools bewegt wird

        if (pMyPool != pHisPool)
        {
            if (INDEX_IGNORE == nIdx2)
            {
                nIdx2 = pMyPool->Count();
            }

            // wenn so eine Vorlage schon existiert: loeschen!
            String aOldName(pHisSheet->GetName());
            SfxStyleFamily eOldFamily = pHisSheet->GetFamily();

            SfxStyleSheetBase* pExist = pMyPool->Find(aOldName, eOldFamily);
            // USHORT nOldHelpId = pExist->GetHelpId(??? VB ueberlegt sich was);
            BOOL bUsedOrUserDefined;
            if( pExist )
            {
                bUsedOrUserDefined =
                    pExist->IsUsed() || pExist->IsUserDefined();
                if( ErrorHandler::HandleError(
                    *new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, aOldName ) )
                    != ERRCODE_BUTTON_OK )
                    return FALSE;
                else
                {
                    pMyPool->Replace( *pHisSheet, *pExist );
                    SetModified( TRUE );
                    nIdx2 = nIdx1 = INDEX_IGNORE;
                    return TRUE;
                }
            }

            SfxStyleSheetBase& rNewSheet = pMyPool->Make(
                aOldName, eOldFamily,
                pHisSheet->GetMask(), nIdx2);

            // ItemSet der neuen Vorlage fuellen
            rNewSheet.GetItemSet().Set(pHisSheet->GetItemSet());

            // wer bekommt den Neuen als Parent? wer benutzt den Neuen als Follow?
            SfxStyleSheetBase* pTestSheet = pMyPool->First();
            while (pTestSheet)
            {
                if (pTestSheet->GetFamily() == eOldFamily &&
                    pTestSheet->HasParentSupport() &&
                    pTestSheet->GetParent() == aOldName)
                {
                    pTestSheet->SetParent(aOldName);
                    // Verknuepfung neu aufbauen
                }

                if (pTestSheet->GetFamily() == eOldFamily &&
                    pTestSheet->HasFollowSupport() &&
                    pTestSheet->GetFollow() == aOldName)
                {
                    pTestSheet->SetFollow(aOldName);
                    // Verknuepfung neu aufbauen
                }

                pTestSheet = pMyPool->Next();
            }
            bUsedOrUserDefined =
                rNewSheet.IsUsed() || rNewSheet.IsUserDefined();


            // hat der Neue einen Parent? wenn ja, mit gleichem Namen bei uns suchen
            if (pHisSheet->HasParentSupport())
            {
                const String& rParentName = pHisSheet->GetParent();
                if (0 != rParentName.Len())
                {
                    SfxStyleSheetBase* pParentOfNew =
                        pMyPool->Find(rParentName, eOldFamily);
                    if (pParentOfNew)
                        rNewSheet.SetParent(rParentName);
                }
            }

            // hat der Neue einen Follow? wenn ja, mit gleichem
            // Namen bei uns suchen
            if (pHisSheet->HasFollowSupport())
            {
                const String& rFollowName = pHisSheet->GetFollow();
                if (0 != rFollowName.Len())
                {
                    SfxStyleSheetBase* pFollowOfNew =
                        pMyPool->Find(rFollowName, eOldFamily);
                    if (pFollowOfNew)
                        rNewSheet.SetFollow(rFollowName);
                }
            }

            SetModified( TRUE );
            if( !bUsedOrUserDefined ) nIdx2 = nIdx1 = INDEX_IGNORE;

            bRet = TRUE;
        }
        else
            bRet = FALSE;
    }
/*
    else if (nSourceIdx1 == CONTENT_CONFIG)
    {
        nIdx1 = CONTENT_CONFIG;

        SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
        if (!GetConfigManager() || HasTemplateConfig())
        {
            SetConfigManager(new SfxConfigManager(0, pCfgMgr));
            SetTemplateConfig(FALSE);
            if (this == Current())
                GetConfigManager()->Activate(pCfgMgr);
        }

        if (GetConfigManager()->CopyItem(
            nSourceIdx2, nIdx2, rSource.GetConfigManager()))
        {
            SetModified(TRUE);
            bRet = TRUE;
            SFX_APP()->GetDispatcher_Impl()->Update_Impl(TRUE);
        }
    }
*/
    return bRet;
}

//--------------------------------------------------------------------

BOOL SfxObjectShell::Remove
(
    USHORT nIdx1,
    USHORT nIdx2,
    USHORT nIdx3
)
{
    BOOL bRet = FALSE;

    if (CONTENT_STYLE == nIdx1)
    {
        SfxStyleSheetBasePool* pMyPool  = GetStyleSheetPool();

        SetOrganizerSearchMask(pMyPool);

        SfxStyleSheetBase* pMySheet =  (*pMyPool)[nIdx2];
        String aName(pMySheet->GetName());
        String aEmpty;
        SfxStyleFamily  eFamily = pMySheet->GetFamily();
        if (pMySheet)
        {
            pMyPool->Erase(pMySheet);
            bRet = TRUE;
        }

        SfxStyleSheetBase* pTestSheet = pMyPool->First();
        while (pTestSheet)
        {
            if (pTestSheet->GetFamily() == eFamily &&
                pTestSheet->HasParentSupport() &&
                pTestSheet->GetParent() == aName)
            {
                pTestSheet->SetParent(aEmpty); // Verknuepfung aufloesen
            }

            if (pTestSheet->GetFamily() == eFamily &&
                pTestSheet->HasFollowSupport() &&
                pTestSheet->GetFollow() == aName)
            {
                pTestSheet->SetFollow(aEmpty); // Verknuepfung aufloesen
            }

            pTestSheet = pMyPool->Next();
        }
        if(bRet)
            SetModified( TRUE );
    }
/*
    else if (nIdx1 == CONTENT_CONFIG)
    {
        if (GetConfigManager()->RemoveItem(nIdx2))
        {
            SetModified(TRUE);
            bRet = TRUE;
            SFX_APP()->GetDispatcher_Impl()->Update_Impl(TRUE);
        }
    }
*/
    return bRet;
}

//--------------------------------------------------------------------

BOOL SfxObjectShell::Print
(
    Printer&        rPrt,
    USHORT          nIdx1,
    USHORT          nIdx2,
    USHORT          nIdx3,
    const String*   pObjectName
)

/*  [Beschreibung]
*/

{
    switch(nIdx1)
    {
      case CONTENT_STYLE:
        {
            SfxStyleSheetBasePool *pPool = GetStyleSheetPool();
            SetOrganizerSearchMask(pPool);
            SfxStyleSheetIterator* pIter = pPool->CreateIterator(
                pPool->GetSearchFamily(), pPool->GetSearchMask() );
            USHORT nStyles = pIter->Count();
            SfxStyleSheetBase *pStyle = pIter->First();
            if ( !pStyle )
                return TRUE;

            if ( !rPrt.StartJob(String(SfxResId(STR_STYLES))) )
            {
                delete pIter;
                return FALSE;
            }
            if ( !rPrt.StartPage() )
            {
                delete pIter;
                return FALSE;
            }
            SfxStatusBarManager* pStbMgr = SFX_APP()->GetStatusBarManager();
            if ( pStbMgr )
                pStbMgr->StartProgressMode(String(SfxResId(STR_PRINT_STYLES)), nStyles);
            rPrt.SetMapMode(MapMode(MAP_10TH_MM));
            Font aFont( DEFINE_CONST_UNICODE( "Arial" ), Size(0, 64));   // 18pt
            aFont.SetWeight(WEIGHT_BOLD);
            rPrt.SetFont(aFont);
            const Size aPageSize(rPrt.GetOutputSize());
            const USHORT nXIndent = 200;
            USHORT nYIndent = 200;
            Point aOutPos(nXIndent, nYIndent);
            String aHeader(SfxResId(STR_PRINT_STYLES_HEADER));
            if ( pObjectName )
                aHeader += *pObjectName;
            else
                aHeader += GetTitle();
            long nTextHeight( rPrt.GetTextHeight() );
            rPrt.DrawText(aOutPos, aHeader);
            aOutPos.Y() += nTextHeight;
            aOutPos.Y() += nTextHeight/2;
            aFont.SetSize(Size(0, 35)); // 10pt
            nStyles = 1;
            while(pStyle)
            {
                if(pStbMgr)
                    pStbMgr->SetProgressState(nStyles++);
                // Ausgabe des Vorlagennamens
                String aStr(pStyle->GetName());
                aFont.SetWeight(WEIGHT_BOLD);
                rPrt.SetFont(aFont);
                nTextHeight = rPrt.GetTextHeight();
                // Seitenwechsel
                if ( aOutPos.Y() + nTextHeight*2 >
                    aPageSize.Height() - (long) nYIndent )
                {
                    rPrt.EndPage();
                    rPrt.StartPage();
                    aOutPos.Y() = nYIndent;
                }
                rPrt.DrawText(aOutPos, aStr);
                aOutPos.Y() += nTextHeight;

                // Ausgabe der Vorlagenbeschreibung
                aFont.SetWeight(WEIGHT_NORMAL);
                rPrt.SetFont(aFont);
                aStr = pStyle->GetDescription();
                const char cDelim = ' ';
                USHORT nStart = 0, nIdx = 0;

                nTextHeight = rPrt.GetTextHeight();
                // wie viele Worte passen auf eine Zeile
                while(nIdx < aStr.Len())
                {
                    USHORT  nOld = nIdx;
                    long nTextWidth;
                    nIdx = aStr.Search(cDelim, nStart);
                    nTextWidth = rPrt.GetTextWidth(aStr, nStart, nIdx-nStart);
                    while(nIdx != STRING_NOTFOUND &&
                          aOutPos.X() + nTextWidth <
                          aPageSize.Width() - (long) nXIndent)
                    {
                        nOld = nIdx;
                        nIdx = aStr.Search(cDelim, nIdx+1);
                        nTextWidth = rPrt.GetTextWidth(aStr, nStart, nIdx-nStart);
                    }
                    String aTmp(aStr, nStart, nIdx == STRING_NOTFOUND?
                                STRING_LEN :
                                nOld-nStart);
                    if ( aTmp.Len() )
                    {
                        nStart = nOld+1;    // wegen trailing space
                    }
                    else
                    {
                        USHORT nChar = 1;
                        while(
                            nStart + nChar < aStr.Len() &&
                            aOutPos.X() + rPrt.GetTextWidth(
                                aStr, nStart, nChar) <
                            aPageSize.Width() - nXIndent)
                            ++nChar;
                        aTmp = String(aStr, nStart, nChar-1);
                        nIdx = nStart + nChar;
                        nStart = nIdx;
                    }
                    if ( aOutPos.Y() + nTextHeight*2 >
                        aPageSize.Height() - nYIndent )
                    {
                        rPrt.EndPage();
                        rPrt.StartPage();
                        aOutPos.Y() = nYIndent;
                    }
                    rPrt.DrawText(aOutPos, aTmp);
                    aOutPos.Y() += rPrt.GetTextHeight();
                }
                pStyle = pIter->Next();
            }
            rPrt.EndPage();
            rPrt.EndJob();
            if ( pStbMgr )
                pStbMgr->EndProgressMode();
            delete pIter;
            break;
        }
      default:
          return FALSE;
    }
    return TRUE;
}

//--------------------------------------------------------------------

void SfxObjectShell::LoadStyles
(
    SfxObjectShell &rSource         /*  die Dokument-Vorlage, aus der
                                            die Styles geladen werden sollen */
)

/*  [Beschreibung]

    Diese Methode wird vom SFx gerufen, wenn aus einer Dokument-Vorlage
    Styles nachgeladen werden sollen. Bestehende Styles soll dabei
    "uberschrieben werden. Das Dokument mu"s daher neu formatiert werden.
    Daher werden die Applikationen in der Regel diese Methode "uberladen
    und in ihrer Implementierung die Implementierung der Basisklasse
    rufen.
*/

{
    struct Styles_Impl
    {
        SfxStyleSheetBase *pSource;
        SfxStyleSheetBase *pDest;
//      Styles_Impl () : pSource(0), pDest(0) {}
    };

    SfxStyleSheetBasePool *pSourcePool = rSource.GetStyleSheetPool();
    DBG_ASSERT(pSourcePool, "Source-DocumentShell ohne StyleSheetPool");
    SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool();
    DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool");
    pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, 0xffff);
    Styles_Impl *pFound = new Styles_Impl[pSourcePool->Count()];
    USHORT nFound = 0;

    SfxStyleSheetBase *pSource = pSourcePool->First();
    while ( pSource )
    {
        SfxStyleSheetBase *pDest =
            pMyPool->Find( pSource->GetName(), pSource->GetFamily() );
        if ( !pDest )
        {
            pDest = &pMyPool->Make( pSource->GetName(),
                    pSource->GetFamily(), pSource->GetMask());
            // Setzen des Parents, der Folgevorlage
        }
        pFound[nFound].pSource = pSource;
        pFound[nFound].pDest = pDest;
        ++nFound;
        pSource = pSourcePool->Next();
    }

    for ( USHORT i = 0; i < nFound; ++i )
    {
        pFound[i].pDest->GetItemSet().PutExtended(pFound[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
//      pFound[i].pDest->SetHelpId(pFound[i].pSource->GetHelpId());
        if(pFound[i].pSource->HasParentSupport())
            pFound[i].pDest->SetParent(pFound[i].pSource->GetParent());
        if(pFound[i].pSource->HasFollowSupport())
            pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent());
    }
    delete pFound;
}

//--------------------------------------------------------------------

void SfxObjectShell::UpdateFromTemplate_Impl(  )

/*  [Beschreibung]

    Diese interne Methode pr"uft, ob das Dokument aus einem Template
    erzeugt wurde, und ob dieses neuer ist als das Dokument. Ist dies
    der Fall, wird der Benutzer gefragt, ob die Vorlagen (StyleSheets)
    updated werden sollen. Wird dies positiv beantwortet, werden die
    StyleSheets updated.
*/

{
    // Storage-medium?
    SfxMedium *pFile = GetMedium();
    DBG_ASSERT( pFile, "cannot UpdateFromTemplate without medium" );

    if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
        // update only for documents loaded from the local file system
        return;

    // only for own storage formats
    SvStorageRef xDocStor = pFile ? pFile->GetStorage() : 0;
    if ( !xDocStor.Is() || !pFile->GetFilter() || !pFile->GetFilter()->IsOwnFormat() )
        return;

    SFX_ITEMSET_ARG( pFile->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
    sal_Int16 bCanUpdateFromTemplate = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;

    // created from template?
    SfxDocumentInfo *pInfo = &GetDocInfo();
    String aTemplName( pInfo->GetTemplateName() );
    String aTemplFileName( pInfo->GetTemplateFileName() );
    String aFoundName;
    SvStorageRef aTemplStor;
    if ( aTemplName.Len() || aTemplFileName.Len() && !IsReadOnly() )
    {
        // try to locate template, first using filename
        // this must be done because writer global document uses this "great" idea to manage the templates of all parts
        // in the master document
        // but it is NOT an error if the template filename points not to a valid file
        SfxDocumentTemplates aTempl;
        aTempl.Construct();
        if ( aTemplFileName.Len() )
        {
            String aURL;
            if( ::utl::LocalFileHelper::ConvertSystemPathToURL( aTemplFileName, GetMedium()->GetName(), aURL ) )
            {
                aTemplStor = new SvStorage( aURL, STREAM_READ|STREAM_NOCREATE|STREAM_SHARE_DENYWRITE, STORAGE_TRANSACTED );
                if ( aTemplStor->GetError() )
                    aTemplStor.Clear();
                else
                    aFoundName = aURL;
            }
        }

        if( !aFoundName.Len() && aTemplName.Len() )
            // if the template filename did not lead to success, try to get a file name for the logical template name
            aTempl.GetFull( String(), aTemplName, aFoundName );
    }

    if ( aFoundName.Len() )
    {
        // check existence of template storage
        aTemplFileName = aFoundName;
        BOOL bLoad = FALSE;
        if ( !aTemplStor.Is() )
            aTemplStor = new SvStorage( aTemplFileName,
                            STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE, STORAGE_TRANSACTED );

        // should the document checked against changes in the template ?
        if ( !aTemplStor->GetError() && pInfo->IsQueryLoadTemplate() )
        {
            // load document info of template
            BOOL bOK = FALSE;
            DateTime aTemplDate;
            Reference < document::XStandaloneDocumentInfo > xDocInfo (
                    ::comphelper::getProcessServiceFactory()->createInstance(
                        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.StandaloneDocumentInfo") ) ), UNO_QUERY );
            Reference < beans::XFastPropertySet > xSet( xDocInfo, UNO_QUERY );
            if ( xDocInfo.is() && xSet.is() )
            {
                try
                {
                    xDocInfo->loadFromURL( aTemplFileName );
                    Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED );
                    ::com::sun::star::util::DateTime aTmp;
                    if ( aAny >>= aTmp )
                    {
                        // get modify date from document info
                        aTemplDate = SfxDocumentInfoObject::impl_DateTime_Struct2Object( aTmp );
                        bOK = TRUE;
                    }
                }
                catch ( Exception& )
                {
                }
            }

            // if modify date was read successfully
            if ( bOK )
            {
                // compare modify data of template with the last check date of the document
                const DateTime aInfoDate( pInfo->GetTemplateDate(), pInfo->GetTemplateDate() );
                if ( aTemplDate > aInfoDate )
                {
                    // ask user
                    if( bCanUpdateFromTemplate == document::UpdateDocMode::QUIET_UPDATE
                     || bCanUpdateFromTemplate == document::UpdateDocMode::FULL_UPDATE )
                        bLoad = TRUE;
                    else if ( bCanUpdateFromTemplate == document::UpdateDocMode::ACCORDING_TO_CONFIG )
                    {
                        QueryBox aBox( GetDialogParent(), SfxResId(MSG_QUERY_LOAD_TEMPLATE) );
                        if ( RET_YES == aBox.Execute() )
                            bLoad = TRUE;
                    }

                    if( !bLoad )
                    {
                        // user refuses, so don't ask again for this document
                        pInfo->SetQueryLoadTemplate(FALSE);

                        if ( xDocStor->IsOLEStorage() )
                            pInfo->Save(xDocStor);
                        else
                            SetModified( TRUE );
                    }
                }
            }

            if ( bLoad )
            {
                // styles should be updated, create document in organizer mode to read in the styles
                SfxObjectShellLock xTemplDoc = GetFactory().CreateObject( SFX_CREATE_MODE_ORGANIZER );
                xTemplDoc->DoInitNew(0);
                String aOldBaseURL = INetURLObject::GetBaseURL();
                INetURLObject::SetBaseURL( INetURLObject( aTemplFileName ).GetMainURL( INetURLObject::NO_DECODE ) );
                if ( xTemplDoc->LoadFrom(aTemplStor) )
                {
                    // transfer styles from xTemplDoc to this document
                    LoadStyles(*xTemplDoc);

                    // remember date/time of check
                    pInfo->SetTemplateDate(aTemplDate);
                    pInfo->Save(xDocStor);
                }

                INetURLObject::SetBaseURL( aOldBaseURL );
            }
/*
            SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
            BOOL bConfig = pInfo->HasTemplateConfig();
            {
                SfxConfigManager *pTemplCfg = new SfxConfigManager(aTemplStor, pCfgMgr);
                SetConfigManager(pTemplCfg);
                SetTemplateConfig(TRUE);

                // Falls der gerade zerst"orte CfgMgr des Dokuments der
                // aktive war, pCfgMgr lieber neu holen
                pCfgMgr = SFX_CFGMANAGER();

                // ggf. den neuen ConfigManager aktivieren
                if ( this == SfxObjectShell::Current() )
                    pTemplCfg->Activate(pCfgMgr);
            }
*/
            // Template und Template-DocInfo werden nicht mehr gebraucht
//            delete pTemplInfo;
        }
    }
}

SfxEventConfigItem_Impl* SfxObjectShell::GetEventConfig_Impl( BOOL bForce )
{
    if ( bForce && !pImp->pEventConfig )
    {
        pImp->pEventConfig = new SfxEventConfigItem_Impl( SFX_ITEMTYPE_DOCEVENTCONFIG,
                    SFX_APP()->GetEventConfig(), this );
        if (pImp->pCfgMgr)
            pImp->pEventConfig->Connect( pImp->pCfgMgr );
        pImp->pEventConfig->Initialize();
    }

    return pImp->pEventConfig;
}

SvStorageRef SfxObjectShell::GetConfigurationStorage( SotStorage* pStor )
{
    // configuration storage shall be opened in own storage or a new storage, if the
    // document is getting stored into this storage
    if ( !pStor )
        pStor = GetStorage();

    if ( pStor->IsOLEStorage() )
                return (SvStorageRef) SotStorageRef();

    // storage is always opened in transacted mode, so changes must be commited
    SotStorageRef xStorage = pStor->OpenSotStorage( DEFINE_CONST_UNICODE("Configurations"),
                IsReadOnly() ? STREAM_STD_READ : STREAM_STD_READWRITE );
    if ( xStorage.Is() && xStorage->GetError() )
        xStorage.Clear();
        return (SvStorageRef) xStorage;
}

SotStorageStreamRef SfxObjectShell::GetConfigurationStream( const String& rName, BOOL bCreate )
{
    SotStorageStreamRef xStream;
    SvStorageRef xStorage = GetConfigurationStorage();
    if ( xStorage.Is() )
    {
        xStream = xStorage->OpenSotStream( rName,
            bCreate ? STREAM_STD_READWRITE|STREAM_TRUNC : STREAM_STD_READ );
        if ( xStream.Is() && xStream->GetError() )
            xStream.Clear();
    }

    return xStream;
}

SfxAcceleratorManager* SfxObjectShell::GetAccMgr_Impl()
{
    // already constructed ?!
    if ( pImp->pAccMgr )
        return pImp->pAccMgr;

    // get the typId ( = ResourceId )
    const ResId* pResId = GetFactory().GetAccelId();
    if ( !pResId )
        return NULL;

    if ( GetConfigManager() && pImp->pCfgMgr->HasConfigItem( pResId->GetId() ) )
    {
        // document has configuration
        pImp->pAccMgr = new SfxAcceleratorManager( *pResId, pImp->pCfgMgr );
        return pImp->pAccMgr;
    }
    else
        return GetFactory().GetAccMgr_Impl();
}

SfxMenuBarManager* SfxObjectShell::CreateMenuBarManager_Impl( SfxViewFrame* pViewFrame )
{
/*
    SfxBindings& rBindings = pViewFrame->GetBindings();
    sal_Bool bCheckPlugin = SfxApplication::IsPlugin();
    const ResId* pId = bCheckPlugin ? GetFactory().GetPluginMenuBarId() : GetFactory().GetMenuBarId();
    DBG_ASSERT( pId && pId->GetId(), "Component must have own window!" );
    if ( !pId )
        return NULL;

    SfxConfigManager *pCfgMgr = SFX_APP()->GetConfigManager_Impl();
    if ( GetConfigManager() && pImp->pCfgMgr->HasConfigItem( pId->GetId() ) )
        pCfgMgr = pImp->pCfgMgr;

    SfxMenuBarManager* pMgr = new SfxMenuBarManager( *pId, rBindings, pCfgMgr, pViewFrame->ISA( SfxInPlaceFrame ) );
    return pMgr;
*/

    const ResId* pId = GetFactory().GetMenuBarId();
    if ( pId )
    {
        Reference< com::sun::star::beans::XPropertySet > xPropSet( pViewFrame->GetBindings().GetActiveFrame(), UNO_QUERY );
        Reference< drafts::com::sun::star::frame::XLayoutManager > xLayoutManager;

        if ( xPropSet.is() )
        {
            Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
            aValue >>= xLayoutManager;
        }

        if ( xLayoutManager.is() )
        {
            rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
//            aMenuBarURL += rtl::OUString::valueOf( sal_Int32( pId->GetId() ));

            xLayoutManager->createElement( aMenuBarURL );
        }
    }

    return NULL;

}

SfxImageManager* SfxObjectShell::GetImageManager_Impl()
{
    if ( pImp->pImageManager )
        return pImp->pImageManager;

    // every document has its own ImageManager, but they may use the global configuration!
    pImp->pImageManager = new SfxImageManager( this );
    return pImp->pImageManager;
}

SfxObjectShellRef MakeObjectShellForOrganizer_Impl( const String& aTargetURL, BOOL bForWriting )
{
    // check for own format
    SfxObjectShellRef xDoc;
    SfxMedium *pMed = new SfxMedium( aTargetURL, STREAM_STD_READ, FALSE, 0 );
    const SfxFilter* pFilter = NULL;
    if( SFX_APP()->GetFilterMatcher().GuessFilter( *pMed, &pFilter ) == ERRCODE_NONE && pFilter && pFilter->IsOwnFormat() )
    {
        delete pMed;
        StreamMode nMode = bForWriting ? STREAM_STD_READWRITE : STREAM_STD_READ;
        SvStorageRef xStor = new SvStorage( aTargetURL, nMode, STORAGE_TRANSACTED );
        xStor->SetVersion( pFilter->GetVersion() );
        if ( SVSTREAM_OK == xStor->GetError() )
        {
            // create document
            xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
            if ( xDoc.Is() )
            {
                // partially load, so don't use DoLoad!
                xDoc->DoInitNew(0);
                if( !xDoc->LoadFrom( xStor ) )
                    xDoc.Clear();
                else
                {
                    // connect to storage, abandon temp. storage
                    xDoc->DoHandsOff();
                    xDoc->DoSaveCompleted( xStor );
                }
            }
        }
    }
    else
        delete pMed;

    return xDoc;
}

SfxToolBoxConfig* SfxObjectShell::GetToolBoxConfig_Impl()
{
    if ( !pImp->pTbxConfig )
    {
        pImp->pTbxConfig = new SfxToolBoxConfig(
            GetConfigManager() ? pImp->pCfgMgr : SFX_APP()->GetConfigManager_Impl() );
    }

    return pImp->pTbxConfig;
}


sal_Bool SfxObjectShell::IsHelpDocument() const
{
    const SfxFilter* pFilter = GetMedium()->GetFilter();
    return ( pFilter && pFilter->GetFilterName().CompareToAscii("writer_web_HTML_help") == COMPARE_EQUAL );
}